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
const eventPrepWork = options . eventPrepWork ;
25
26
promise_test ( async t => {
@@ -30,8 +31,8 @@ const testSoftNavigation =
30
31
const firstClick = ( i === 0 ) ;
31
32
let paint_entries_promise =
32
33
waitOnPaintEntriesPromise ( expectLCP && firstClick ) ;
33
- clicked = false ;
34
- click ( link ) ;
34
+ interacted = false ;
35
+ interact ( link , interactionType ) ;
35
36
36
37
await new Promise ( resolve => {
37
38
( new PerformanceObserver ( ( ) => resolve ( ) ) ) . observe ( {
@@ -62,7 +63,7 @@ const testNavigationApi = (testName, navigateEventHandler, link) => {
62
63
await waitInitialLCP ( ) ;
63
64
const preClickLcp = await getLcpEntries ( ) ;
64
65
let paint_entries_promise = waitOnPaintEntriesPromise ( ) ;
65
- click ( link ) ;
66
+ interact ( link ) ;
66
67
await new Promise ( resolve => {
67
68
( new PerformanceObserver ( ( ) => resolve ( ) ) ) . observe ( {
68
69
type : 'soft-navigation'
@@ -81,7 +82,7 @@ const testSoftNavigationNotDetected = options => {
81
82
promise_test ( async t => {
82
83
const preClickLcp = await getLcpEntries ( ) ;
83
84
options . eventTarget . addEventListener ( options . eventName , options . eventHandler ) ;
84
- click ( options . link ) ;
85
+ interact ( options . link ) ;
85
86
await new Promise ( ( resolve , reject ) => {
86
87
( new PerformanceObserver ( ( ) =>
87
88
reject ( "Soft navigation should not be triggered" ) ) ) . observe ( {
@@ -129,16 +130,21 @@ const runEntryValidations =
129
130
}
130
131
} ;
131
132
132
- const click = link => {
133
- if ( test_driver ) {
134
- test_driver . click ( link ) ;
135
- timestamps [ counter ] = { "syncPostClick" : performance . now ( ) } ;
136
- }
137
- }
133
+ const interact =
134
+ ( link , interactionType = 'click' ) => {
135
+ if ( test_driver ) {
136
+ if ( interactionType == 'click' ) {
137
+ test_driver . click ( link ) ;
138
+ } else {
139
+ test_driver . send_keys ( link , 'j' ) ;
140
+ }
141
+ timestamps [ counter ] = { "syncPostInteraction" : performance . now ( ) } ;
142
+ }
143
+ }
138
144
139
145
const setEvent = ( t , button , pushState , addContent , pushUrl , eventType , prepWork ) => {
140
- const eventObject = ( eventType == "click" ) ? button : window ;
141
-
146
+ const eventObject =
147
+ ( eventType == 'click' || eventType == 'keydown' ) ? button : window ;
142
148
eventObject . addEventListener ( eventType , async e => {
143
149
if ( prepWork && ! prepWork ( t ) ) {
144
150
return ;
@@ -163,7 +169,7 @@ const setEvent = (t, button, pushState, addContent, pushUrl, eventType, prepWork
163
169
await addContent ( url ) ;
164
170
++ counter ;
165
171
166
- clicked = true ;
172
+ interacted = true ;
167
173
} ) ;
168
174
} ;
169
175
@@ -183,7 +189,7 @@ const validateSoftNavigationEntry = async (clicks, extraValidations,
183
189
assert_true ( entry . name . includes ( pushUrl ? URL : document . location . href ) ,
184
190
"The soft navigation name is properly set" ) ;
185
191
const entryTimestamp = entry . startTime ;
186
- assert_less_than_equal ( timestamps [ i ] [ "syncPostClick " ] , entryTimestamp ) ;
192
+ assert_less_than_equal ( timestamps [ i ] [ "syncPostInteraction " ] , entryTimestamp ) ;
187
193
assert_greater_than_equal (
188
194
timestamps [ i ] [ 'eventStart' ] , entryTimestamp ,
189
195
'Event start timestamp matches' ) ;
0 commit comments