@@ -235,6 +235,86 @@ func TestLifecycleReload(t *testing.T) {
235
235
}
236
236
}
237
237
238
+ func TestLifecycleGotoWithSubFrame (t * testing.T ) {
239
+ t .Parallel ()
240
+
241
+ // Test description
242
+ //
243
+ // 1. goto /home (with iframe to /sub) and wait for the specified lifecycle event.
244
+ //
245
+ // Success criteria: The web page (all frames) is in the expected state
246
+ // once we receive the specified lifecycle event from
247
+ // the browser.
248
+
249
+ tests := []struct {
250
+ name string
251
+ pingSlowness time.Duration
252
+ pingJSSlow bool
253
+ waitUntil common.LifecycleEvent
254
+ pingRequestTextAssert func (result string )
255
+ pingJSTextAssert func (result string )
256
+ }{
257
+ {
258
+ name : "load" ,
259
+ pingSlowness : time .Millisecond * 100 ,
260
+ pingJSSlow : false ,
261
+ waitUntil : common .LifecycleEventLoad ,
262
+ pingRequestTextAssert : func (result string ) {
263
+ assert .NotEqualValues (t , "Waiting... pong 10 - for loop complete" , result )
264
+ },
265
+ pingJSTextAssert : func (result string ) {
266
+ assert .EqualValues (t , "ping.js loaded from server" , result )
267
+ },
268
+ },
269
+ {
270
+ name : "domcontentloaded" ,
271
+ pingSlowness : time .Millisecond * 100 ,
272
+ pingJSSlow : true ,
273
+ waitUntil : common .LifecycleEventDOMContentLoad ,
274
+ pingRequestTextAssert : func (result string ) {
275
+ assert .NotEqualValues (t , "Waiting... pong 10 - for loop complete" , result )
276
+ },
277
+ pingJSTextAssert : func (result string ) {
278
+ assert .EqualValues (t , "Waiting..." , result )
279
+ },
280
+ },
281
+ {
282
+ name : "networkidle" ,
283
+ pingSlowness : 0 ,
284
+ pingJSSlow : false ,
285
+ waitUntil : common .LifecycleEventNetworkIdle ,
286
+ pingRequestTextAssert : func (result string ) {
287
+ assert .EqualValues (t , "Waiting... pong 10 - for loop complete" , result )
288
+ },
289
+ pingJSTextAssert : func (result string ) {
290
+ assert .EqualValues (t , "ping.js loaded from server" , result )
291
+ },
292
+ },
293
+ }
294
+
295
+ for _ , tt := range tests {
296
+ t .Run (tt .name , func (t * testing.T ) {
297
+ t .Parallel ()
298
+
299
+ tb := newTestBrowser (t , withFileServer ())
300
+ p := tb .NewPage (nil )
301
+
302
+ withHomeHandler (t , tb , "lifecycle_main_frame.html" )
303
+ withSubHandler (t , tb , "lifecycle_subframe.html" )
304
+ withPingHandler (t , tb , tt .pingSlowness , nil )
305
+ withPingJSSubFrameHandler (t , tb , tt .pingJSSlow , nil )
306
+
307
+ assertHome (t , tb , p , tt .waitUntil , func () {
308
+ result := p .TextContent ("#subFramePingRequestText" , nil )
309
+ tt .pingRequestTextAssert (result )
310
+
311
+ result = p .TextContent ("#subFramePingJSText" , nil )
312
+ tt .pingJSTextAssert (result )
313
+ })
314
+ })
315
+ }
316
+ }
317
+
238
318
func TestLifecycleGoto (t * testing.T ) {
239
319
t .Parallel ()
240
320
@@ -373,6 +453,14 @@ func withHomeHandler(t *testing.T, tb *testBrowser, htmlFile string) {
373
453
})
374
454
}
375
455
456
+ func withSubHandler (t * testing.T , tb * testBrowser , htmlFile string ) {
457
+ t .Helper ()
458
+
459
+ tb .withHandler ("/sub" , func (w http.ResponseWriter , r * http.Request ) {
460
+ http .Redirect (w , r , tb .staticURL (htmlFile ), http .StatusMovedPermanently )
461
+ })
462
+ }
463
+
376
464
func withPingHandler (t * testing.T , tb * testBrowser , slow time.Duration , ch chan bool ) {
377
465
t .Helper ()
378
466
@@ -415,6 +503,31 @@ func withPingJSHandler(t *testing.T, tb *testBrowser, slow bool, ch chan bool) {
415
503
})
416
504
}
417
505
506
+ func withPingJSSubFrameHandler (t * testing.T , tb * testBrowser , slow bool , ch chan bool ) {
507
+ t .Helper ()
508
+
509
+ tb .withHandler ("/ping.js" , func (w http.ResponseWriter , _ * http.Request ) {
510
+ script := `
511
+ var pingJSTextOutput = document.getElementById("pingJSText");
512
+ var parentOutputServerMsg = window.parent.document.getElementById('subFramePingJSText');
513
+
514
+ pingJSTextOutput.innerText = "ping.js loaded from server";
515
+ parentOutputServerMsg.innerText = pingJSTextOutput.innerText;
516
+ `
517
+ if slow {
518
+ script = `
519
+ await new Promise(resolve => setTimeout(resolve, 1000));
520
+
521
+ ` + script
522
+ }
523
+ fmt .Fprint (w , script )
524
+
525
+ if ch != nil {
526
+ close (ch )
527
+ }
528
+ })
529
+ }
530
+
418
531
func assertHome (
419
532
t * testing.T ,
420
533
tb * testBrowser ,
0 commit comments