@@ -37,13 +37,7 @@ func TestLifecycleWaitForLoadStateLoad(t *testing.T) {
37
37
})
38
38
39
39
withPingHandler (t , tb , time .Millisecond * 100 , nil )
40
-
41
- tb .withHandler ("/ping.js" , func (w http.ResponseWriter , _ * http.Request ) {
42
- fmt .Fprintf (w , `
43
- var pingJSTextOutput = document.getElementById("pingJSText");
44
- pingJSTextOutput.innerText = "ping.js loaded from server";
45
- ` )
46
- })
40
+ withPingJSHandler (t , tb , false , nil )
47
41
48
42
waitUntil := common .LifecycleEventLoad
49
43
assertHome (t , tb , p , waitUntil , func () {
@@ -81,15 +75,7 @@ func TestLifecycleWaitForLoadStateDOMContentLoaded(t *testing.T) {
81
75
})
82
76
83
77
withPingHandler (t , tb , time .Millisecond * 100 , nil )
84
-
85
- tb .withHandler ("/ping.js" , func (w http.ResponseWriter , _ * http.Request ) {
86
- fmt .Fprintf (w , `
87
- await new Promise(resolve => setTimeout(resolve, 1000));
88
-
89
- var pingJSTextOutput = document.getElementById("pingJSText");
90
- pingJSTextOutput.innerText = "ping.js loaded from server";
91
- ` )
92
- })
78
+ withPingJSHandler (t , tb , true , nil )
93
79
94
80
waitUntil := common .LifecycleEventDOMContentLoad
95
81
assertHome (t , tb , p , waitUntil , func () {
@@ -125,13 +111,7 @@ func TestLifecycleWaitForLoadStateNetworkIdle(t *testing.T) {
125
111
})
126
112
127
113
withPingHandler (t , tb , 0 , nil )
128
-
129
- tb .withHandler ("/ping.js" , func (w http.ResponseWriter , _ * http.Request ) {
130
- fmt .Fprintf (w , `
131
- var pingJSTextOutput = document.getElementById("pingJSText");
132
- pingJSTextOutput.innerText = "ping.js loaded from server";
133
- ` )
134
- })
114
+ withPingJSHandler (t , tb , false , nil )
135
115
136
116
waitUntil := common .LifecycleEventNetworkIdle
137
117
assertHome (t , tb , p , waitUntil , func () {
@@ -166,13 +146,7 @@ func TestLifecycleWaitForLoadStateDOMContentLoadedThenNetworkIdle(t *testing.T)
166
146
})
167
147
168
148
withPingHandler (t , tb , time .Millisecond * 100 , nil )
169
-
170
- tb .withHandler ("/ping.js" , func (w http.ResponseWriter , _ * http.Request ) {
171
- fmt .Fprintf (w , `
172
- var pingJSTextOutput = document.getElementById("pingJSText");
173
- pingJSTextOutput.innerText = "ping.js loaded from server";
174
- ` )
175
- })
149
+ withPingJSHandler (t , tb , false , nil )
176
150
177
151
assertHome (t , tb , p , common .LifecycleEventDOMContentLoad , func () {
178
152
p .WaitForLoadState (common .LifecycleEventNetworkIdle .String (), nil )
@@ -195,13 +169,7 @@ func TestLifecycleReloadLoad(t *testing.T) {
195
169
})
196
170
197
171
withPingHandler (t , tb , time .Millisecond * 100 , nil )
198
-
199
- tb .withHandler ("/ping.js" , func (w http.ResponseWriter , _ * http.Request ) {
200
- fmt .Fprintf (w , `
201
- var pingJSTextOutput = document.getElementById("pingJSText");
202
- pingJSTextOutput.innerText = "ping.js loaded from server";
203
- ` )
204
- })
172
+ withPingJSHandler (t , tb , false , nil )
205
173
206
174
waitUntil := common .LifecycleEventLoad
207
175
assertHome (t , tb , p , waitUntil , func () {
@@ -235,15 +203,7 @@ func TestLifecycleReloadDOMContentLoaded(t *testing.T) {
235
203
})
236
204
237
205
withPingHandler (t , tb , time .Millisecond * 100 , nil )
238
-
239
- tb .withHandler ("/ping.js" , func (w http.ResponseWriter , _ * http.Request ) {
240
- fmt .Fprintf (w , `
241
- await new Promise(resolve => setTimeout(resolve, 1000));
242
-
243
- var pingJSTextOutput = document.getElementById("pingJSText");
244
- pingJSTextOutput.innerText = "ping.js loaded from server";
245
- ` )
246
- })
206
+ withPingJSHandler (t , tb , true , nil )
247
207
248
208
waitUntil := common .LifecycleEventDOMContentLoad
249
209
assertHome (t , tb , p , waitUntil , func () {
@@ -277,13 +237,7 @@ func TestLifecycleReloadNetworkIdle(t *testing.T) {
277
237
})
278
238
279
239
withPingHandler (t , tb , 0 , nil )
280
-
281
- tb .withHandler ("/ping.js" , func (w http.ResponseWriter , _ * http.Request ) {
282
- fmt .Fprintf (w , `
283
- var pingJSTextOutput = document.getElementById("pingJSText");
284
- pingJSTextOutput.innerText = "ping.js loaded from server";
285
- ` )
286
- })
240
+ withPingJSHandler (t , tb , false , nil )
287
241
288
242
waitUntil := common .LifecycleEventNetworkIdle
289
243
assertHome (t , tb , p , waitUntil , func () {
@@ -327,12 +281,7 @@ func TestLifecycleNetworkIdle(t *testing.T) {
327
281
` )
328
282
})
329
283
330
- tb .withHandler ("/ping.js" , func (w http.ResponseWriter , _ * http.Request ) {
331
- fmt .Fprintf (w , `
332
- var pingJSTextOutput = document.getElementById("pingJSText");
333
- pingJSTextOutput.innerText = "ping.js loaded from server";
334
- ` )
335
- })
284
+ withPingJSHandler (t , tb , false , nil )
336
285
337
286
assertHome (t , tb , p , common .LifecycleEventNetworkIdle , func () {
338
287
result := p .TextContent ("#pingJSText" , nil )
@@ -351,14 +300,7 @@ func TestLifecycleNetworkIdle(t *testing.T) {
351
300
352
301
ch := make (chan bool )
353
302
withPingHandler (t , tb , time .Millisecond * 50 , ch )
354
-
355
- tb .withHandler ("/ping.js" , func (w http.ResponseWriter , _ * http.Request ) {
356
- fmt .Fprintf (w , `
357
- var pingJSTextOutput = document.getElementById("pingJSText");
358
- pingJSTextOutput.innerText = "ping.js loaded from server";
359
- ` )
360
- close (ch )
361
- })
303
+ withPingJSHandler (t , tb , false , ch )
362
304
363
305
assertHome (t , tb , p , common .LifecycleEventNetworkIdle , func () {
364
306
result := p .TextContent ("#pingRequestText" , nil )
@@ -407,6 +349,28 @@ func withPingHandler(t *testing.T, tb *testBrowser, slow time.Duration, ch chan
407
349
})
408
350
}
409
351
352
+ func withPingJSHandler (t * testing.T , tb * testBrowser , slow bool , ch chan bool ) {
353
+ t .Helper ()
354
+
355
+ tb .withHandler ("/ping.js" , func (w http.ResponseWriter , _ * http.Request ) {
356
+ script := `
357
+ var pingJSTextOutput = document.getElementById("pingJSText");
358
+ pingJSTextOutput.innerText = "ping.js loaded from server";
359
+ `
360
+ if slow {
361
+ script = `
362
+ await new Promise(resolve => setTimeout(resolve, 1000));
363
+
364
+ ` + script
365
+ }
366
+ fmt .Fprint (w , script )
367
+
368
+ if ch != nil {
369
+ close (ch )
370
+ }
371
+ })
372
+ }
373
+
410
374
func assertHome (
411
375
t * testing.T ,
412
376
tb * testBrowser ,
0 commit comments