@@ -126,11 +126,14 @@ func TestLifecycleWaitForLoadState(t *testing.T) {
126
126
withPingJSHandler (t , tb , tt .pingJSSlow , nil )
127
127
128
128
if tt .assertFunc != nil {
129
- assertHome (t , tb , p , tt .waitUntil , func () { tt .assertFunc (p ) })
129
+ assertHome (t , tb , p , tt .waitUntil , func () testPromise {
130
+ tt .assertFunc (p )
131
+ return testPromise {}
132
+ }, nil )
130
133
return
131
134
}
132
135
133
- assertHome (t , tb , p , tt .waitUntil , func () {
136
+ assertHome (t , tb , p , tt .waitUntil , func () testPromise {
134
137
result := p .TextContent ("#pingRequestText" , nil )
135
138
tt .pingRequestTextAssert (result )
136
139
@@ -139,7 +142,9 @@ func TestLifecycleWaitForLoadState(t *testing.T) {
139
142
140
143
// This shouldn't block and return after calling hasLifecycleEventFired.
141
144
p .WaitForLoadState (tt .waitUntil .String (), nil )
142
- })
145
+
146
+ return testPromise {}
147
+ }, nil )
143
148
})
144
149
}
145
150
}
@@ -212,7 +217,7 @@ func TestLifecycleReload(t *testing.T) {
212
217
withPingHandler (t , tb , tt .pingSlowness , nil )
213
218
withPingJSHandler (t , tb , tt .pingJSSlow , nil )
214
219
215
- assertHome (t , tb , p , tt .waitUntil , func () {
220
+ assertHome (t , tb , p , tt .waitUntil , func () testPromise {
216
221
result := p .TextContent ("#pingRequestText" , nil )
217
222
tt .pingRequestTextAssert (result , 10 )
218
223
@@ -230,7 +235,9 @@ func TestLifecycleReload(t *testing.T) {
230
235
231
236
result = p .TextContent ("#pingJSText" , nil )
232
237
tt .pingJSTextAssert (result )
233
- })
238
+
239
+ return testPromise {}
240
+ }, nil )
234
241
})
235
242
}
236
243
}
@@ -304,13 +311,15 @@ func TestLifecycleGotoWithSubFrame(t *testing.T) {
304
311
withPingHandler (t , tb , tt .pingSlowness , nil )
305
312
withPingJSSubFrameHandler (t , tb , tt .pingJSSlow , nil )
306
313
307
- assertHome (t , tb , p , tt .waitUntil , func () {
314
+ assertHome (t , tb , p , tt .waitUntil , func () testPromise {
308
315
result := p .TextContent ("#subFramePingRequestText" , nil )
309
316
tt .pingRequestTextAssert (result )
310
317
311
318
result = p .TextContent ("#subFramePingJSText" , nil )
312
319
tt .pingJSTextAssert (result )
313
- })
320
+
321
+ return testPromise {}
322
+ }, nil )
314
323
})
315
324
}
316
325
}
@@ -370,13 +379,15 @@ func TestLifecycleGoto(t *testing.T) {
370
379
withPingHandler (t , tb , tt .pingSlowness , nil )
371
380
withPingJSHandler (t , tb , tt .pingJSSlow , nil )
372
381
373
- assertHome (t , tb , p , tt .waitUntil , func () {
382
+ assertHome (t , tb , p , tt .waitUntil , func () testPromise {
374
383
result := p .TextContent ("#pingRequestText" , nil )
375
384
tt .pingRequestTextAssert (result )
376
385
377
386
result = p .TextContent ("#pingJSText" , nil )
378
387
tt .pingJSTextAssert (result )
379
- })
388
+
389
+ return testPromise {}
390
+ }, nil )
380
391
})
381
392
}
382
393
}
@@ -403,10 +414,12 @@ func TestLifecycleGotoNetworkIdle(t *testing.T) {
403
414
404
415
withPingJSHandler (t , tb , false , nil )
405
416
406
- assertHome (t , tb , p , common .LifecycleEventNetworkIdle , func () {
417
+ assertHome (t , tb , p , common .LifecycleEventNetworkIdle , func () testPromise {
407
418
result := p .TextContent ("#pingJSText" , nil )
408
419
assert .EqualValues (t , "ping.js loaded from server" , result )
409
- })
420
+
421
+ return testPromise {}
422
+ }, nil )
410
423
})
411
424
412
425
t .Run ("doesn't unblock wait for networkIdle too early" , func (t * testing.T ) {
@@ -420,13 +433,15 @@ func TestLifecycleGotoNetworkIdle(t *testing.T) {
420
433
withPingHandler (t , tb , time .Millisecond * 50 , ch )
421
434
withPingJSHandler (t , tb , false , ch )
422
435
423
- assertHome (t , tb , p , common .LifecycleEventNetworkIdle , func () {
436
+ assertHome (t , tb , p , common .LifecycleEventNetworkIdle , func () testPromise {
424
437
result := p .TextContent ("#pingRequestText" , nil )
425
438
assert .EqualValues (t , "Waiting... pong 4 - for loop complete" , result )
426
439
427
440
result = p .TextContent ("#pingJSText" , nil )
428
441
assert .EqualValues (t , "ping.js loaded from server" , result )
429
- })
442
+
443
+ return testPromise {}
444
+ }, nil )
430
445
})
431
446
432
447
t .Run ("doesn't unblock wait on networkIdle early when load and domcontentloaded complete at once" , func (t * testing.T ) {
@@ -438,10 +453,12 @@ func TestLifecycleGotoNetworkIdle(t *testing.T) {
438
453
withHomeHandler (t , tb , "prolonged_network_idle_10.html" )
439
454
withPingHandler (t , tb , time .Millisecond * 50 , nil )
440
455
441
- assertHome (t , tb , p , common .LifecycleEventNetworkIdle , func () {
456
+ assertHome (t , tb , p , common .LifecycleEventNetworkIdle , func () testPromise {
442
457
result := p .TextContent ("#pingRequestText" , nil )
443
458
assert .EqualValues (t , "Waiting... pong 10 - for loop complete" , result )
444
- })
459
+
460
+ return testPromise {}
461
+ }, nil )
445
462
})
446
463
}
447
464
@@ -530,10 +547,9 @@ func withPingJSSubFrameHandler(t *testing.T, tb *testBrowser, slow bool, ch chan
530
547
531
548
func assertHome (
532
549
t * testing.T ,
533
- tb * testBrowser ,
534
- p api.Page ,
550
+ tb * testBrowser , p api.Page ,
535
551
waitUntil common.LifecycleEvent ,
536
- check func (),
552
+ check func () testPromise , secondCheck func () ,
537
553
) {
538
554
t .Helper ()
539
555
@@ -543,15 +559,20 @@ func assertHome(
543
559
WaitUntil : waitUntil ,
544
560
Timeout : 30 * time .Second ,
545
561
})
546
- tb .promise (p .Goto (tb .URL ("/home" ), opts )).then (
547
- func () {
548
- check ()
562
+ prm := tb .promise (p .Goto (tb .URL ("/home" ), opts )).then (
563
+ func () testPromise {
549
564
resolved = true
565
+ return check ()
550
566
},
551
567
func () {
552
568
rejected = true
553
569
},
554
570
)
571
+ if secondCheck != nil {
572
+ prm .then (func () {
573
+ secondCheck ()
574
+ })
575
+ }
555
576
556
577
return nil
557
578
})
0 commit comments