1
1
var counter = 0 ;
2
- var clicked ;
2
+ var interacted ;
3
3
var timestamps = [ ]
4
4
const MAX_CLICKS = 50 ;
5
5
// Entries for one hard navigation + 50 soft navigations.
@@ -20,6 +20,7 @@ const testSoftNavigation =
20
20
const testName = options . testName ;
21
21
const pushUrl = readValue ( options . pushUrl , true ) ;
22
22
const eventType = readValue ( options . eventType , "click" ) ;
23
+ const interactionType = readValue ( options . interactionType , 'click' ) ;
23
24
const expectLCP = options . validate != 'no-lcp' ;
24
25
promise_test ( async t => {
25
26
await waitInitialLCP ( ) ;
@@ -29,8 +30,8 @@ const testSoftNavigation =
29
30
const firstClick = ( i === 0 ) ;
30
31
let paint_entries_promise =
31
32
waitOnPaintEntriesPromise ( expectLCP && firstClick ) ;
32
- clicked = false ;
33
- click ( link ) ;
33
+ interacted = false ;
34
+ interact ( link , interactionType ) ;
34
35
35
36
await new Promise ( resolve => {
36
37
( new PerformanceObserver ( ( ) => resolve ( ) ) ) . observe ( {
@@ -61,7 +62,7 @@ const testNavigationApi = (testName, navigateEventHandler, link) => {
61
62
await waitInitialLCP ( ) ;
62
63
const preClickLcp = await getLcpEntries ( ) ;
63
64
let paint_entries_promise = waitOnPaintEntriesPromise ( ) ;
64
- click ( link ) ;
65
+ interact ( link ) ;
65
66
await new Promise ( resolve => {
66
67
( new PerformanceObserver ( ( ) => resolve ( ) ) ) . observe ( {
67
68
type : 'soft-navigation'
@@ -80,7 +81,7 @@ const testSoftNavigationNotDetected = options => {
80
81
promise_test ( async t => {
81
82
const preClickLcp = await getLcpEntries ( ) ;
82
83
options . eventTarget . addEventListener ( options . eventName , options . eventHandler ) ;
83
- click ( options . link ) ;
84
+ interact ( options . link ) ;
84
85
await new Promise ( ( resolve , reject ) => {
85
86
( new PerformanceObserver ( ( ) =>
86
87
reject ( "Soft navigation should not be triggered" ) ) ) . observe ( {
@@ -128,15 +129,21 @@ const runEntryValidations =
128
129
}
129
130
} ;
130
131
131
- const click = link => {
132
- if ( test_driver ) {
133
- test_driver . click ( link ) ;
134
- timestamps [ counter ] = { "syncPostClick" : performance . now ( ) } ;
135
- }
136
- }
132
+ const interact =
133
+ ( link , interactionType = 'click' ) => {
134
+ if ( test_driver ) {
135
+ if ( interactionType == 'click' ) {
136
+ test_driver . click ( link ) ;
137
+ } else {
138
+ test_driver . send_keys ( link , 'j' ) ;
139
+ }
140
+ timestamps [ counter ] = { "syncPostInteraction" : performance . now ( ) } ;
141
+ }
142
+ }
137
143
138
144
const setEvent = ( t , button , pushState , addContent , pushUrl , eventType ) => {
139
- const eventObject = ( eventType == "click" ) ? button : window ;
145
+ const eventObject =
146
+ ( eventType == 'click' || eventType == 'keydown' ) ? button : window ;
140
147
eventObject . addEventListener ( eventType , async e => {
141
148
timestamps [ counter ] [ "eventStart" ] = performance . now ( ) ;
142
149
// Jump through a task, to ensure task tracking is working properly.
@@ -158,7 +165,7 @@ const setEvent = (t, button, pushState, addContent, pushUrl, eventType) => {
158
165
await addContent ( url ) ;
159
166
++ counter ;
160
167
161
- clicked = true ;
168
+ interacted = true ;
162
169
} ) ;
163
170
} ;
164
171
@@ -178,7 +185,7 @@ const validateSoftNavigationEntry = async (clicks, extraValidations,
178
185
assert_true ( entry . name . includes ( pushUrl ? URL : document . location . href ) ,
179
186
"The soft navigation name is properly set" ) ;
180
187
const entryTimestamp = entry . startTime ;
181
- assert_less_than_equal ( timestamps [ i ] [ "syncPostClick " ] , entryTimestamp ) ;
188
+ assert_less_than_equal ( timestamps [ i ] [ "syncPostInteraction " ] , entryTimestamp ) ;
182
189
assert_greater_than_equal (
183
190
timestamps [ i ] [ 'eventStart' ] , entryTimestamp ,
184
191
'Event start timestamp matches' ) ;
0 commit comments