@@ -103,7 +103,7 @@ func TestLifecycleWaitForNavigation(t *testing.T) {
103
103
104
104
withHomeHandler (t , tb , "wait_for_nav_lifecycle.html" )
105
105
withPingHandler (t , tb , tt .pingSlowness , nil )
106
- withPingJSHandler (t , tb , tt .pingJSSlow , nil )
106
+ withPingJSHandler (t , tb , tt .pingJSSlow , nil , false )
107
107
108
108
if tt .assertFunc != nil {
109
109
assertHome (t , tb , p , tt .waitUntil , func () testPromise {
@@ -284,7 +284,7 @@ func TestLifecycleWaitForLoadState(t *testing.T) {
284
284
285
285
withHomeHandler (t , tb , "wait_for_nav_lifecycle.html" )
286
286
withPingHandler (t , tb , tt .pingSlowness , nil )
287
- withPingJSHandler (t , tb , tt .pingJSSlow , nil )
287
+ withPingJSHandler (t , tb , tt .pingJSSlow , nil , false )
288
288
289
289
if tt .assertFunc != nil {
290
290
assertHome (t , tb , p , tt .waitUntil , func () testPromise {
@@ -376,7 +376,7 @@ func TestLifecycleReload(t *testing.T) {
376
376
377
377
withHomeHandler (t , tb , "reload_lifecycle.html" )
378
378
withPingHandler (t , tb , tt .pingSlowness , nil )
379
- withPingJSHandler (t , tb , tt .pingJSSlow , nil )
379
+ withPingJSHandler (t , tb , tt .pingJSSlow , nil , false )
380
380
381
381
assertHome (t , tb , p , tt .waitUntil , func () testPromise {
382
382
result := p .TextContent ("#pingRequestText" , nil )
@@ -470,7 +470,7 @@ func TestLifecycleGotoWithSubFrame(t *testing.T) {
470
470
withHomeHandler (t , tb , "lifecycle_main_frame.html" )
471
471
withSubHandler (t , tb , "lifecycle_subframe.html" )
472
472
withPingHandler (t , tb , tt .pingSlowness , nil )
473
- withPingJSSubFrameHandler (t , tb , tt .pingJSSlow , nil )
473
+ withPingJSHandler (t , tb , tt .pingJSSlow , nil , true )
474
474
475
475
assertHome (t , tb , p , tt .waitUntil , func () testPromise {
476
476
result := p .TextContent ("#subFramePingRequestText" , nil )
@@ -538,7 +538,7 @@ func TestLifecycleGoto(t *testing.T) {
538
538
539
539
withHomeHandler (t , tb , "wait_for_nav_lifecycle.html" )
540
540
withPingHandler (t , tb , tt .pingSlowness , nil )
541
- withPingJSHandler (t , tb , tt .pingJSSlow , nil )
541
+ withPingJSHandler (t , tb , tt .pingJSSlow , nil , false )
542
542
543
543
assertHome (t , tb , p , tt .waitUntil , func () testPromise {
544
544
result := p .TextContent ("#pingRequestText" , nil )
@@ -573,7 +573,7 @@ func TestLifecycleGotoNetworkIdle(t *testing.T) {
573
573
` )
574
574
})
575
575
576
- withPingJSHandler (t , tb , false , nil )
576
+ withPingJSHandler (t , tb , false , nil , false )
577
577
578
578
assertHome (t , tb , p , common .LifecycleEventNetworkIdle , func () testPromise {
579
579
result := p .TextContent ("#pingJSText" , nil )
@@ -592,7 +592,7 @@ func TestLifecycleGotoNetworkIdle(t *testing.T) {
592
592
withHomeHandler (t , tb , "prolonged_network_idle.html" )
593
593
ch := make (chan bool )
594
594
withPingHandler (t , tb , time .Millisecond * 50 , ch )
595
- withPingJSHandler (t , tb , false , ch )
595
+ withPingJSHandler (t , tb , false , ch , false )
596
596
597
597
assertHome (t , tb , p , common .LifecycleEventNetworkIdle , func () testPromise {
598
598
result := p .TextContent ("#pingRequestText" , nil )
@@ -659,39 +659,21 @@ func withPingHandler(t *testing.T, tb *testBrowser, slow time.Duration, ch chan
659
659
})
660
660
}
661
661
662
- func withPingJSHandler (t * testing.T , tb * testBrowser , slow bool , ch chan bool ) {
662
+ func withPingJSHandler (t * testing.T , tb * testBrowser , slow bool , ch chan bool , withSubFrame bool ) {
663
663
t .Helper ()
664
664
665
665
tb .withHandler ("/ping.js" , func (w http.ResponseWriter , _ * http.Request ) {
666
666
script := `
667
667
var pingJSTextOutput = document.getElementById("pingJSText");
668
668
pingJSTextOutput.innerText = "ping.js loaded from server";
669
669
`
670
- if slow {
671
- script = `
672
- await new Promise(resolve => setTimeout(resolve, 1000));
670
+ if withSubFrame {
671
+ script += `
673
672
674
- ` + script
675
- }
676
- fmt .Fprint (w , script )
677
-
678
- if ch != nil {
679
- close (ch )
680
- }
681
- })
682
- }
683
-
684
- func withPingJSSubFrameHandler (t * testing.T , tb * testBrowser , slow bool , ch chan bool ) {
685
- t .Helper ()
686
-
687
- tb .withHandler ("/ping.js" , func (w http.ResponseWriter , _ * http.Request ) {
688
- script := `
689
- var pingJSTextOutput = document.getElementById("pingJSText");
690
673
var parentOutputServerMsg = window.parent.document.getElementById('subFramePingJSText');
691
-
692
- pingJSTextOutput.innerText = "ping.js loaded from server";
693
674
parentOutputServerMsg.innerText = pingJSTextOutput.innerText;
694
- `
675
+ `
676
+ }
695
677
if slow {
696
678
script = `
697
679
await new Promise(resolve => setTimeout(resolve, 1000));
0 commit comments