Skip to content
This repository was archived by the owner on Jan 30, 2025. It is now read-only.

Commit 0f7aff7

Browse files
committed
Add a test for WaitForLoadState domcontentloaded
This test will ensure that when WaitForLoadState with waitUntil domcontentloaded is called, that it doesn't block for the lifecycle event if that event has already fired, and so using the frame's internal state to unblock quickly.
1 parent 7f4ce9f commit 0f7aff7

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

tests/lifecycle_wait_test.go

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,62 @@ func TestLifecycleWaitForLoadStateLoad(t *testing.T) {
6868
})
6969
}
7070

71+
func TestLifecycleWaitForLoadStateDOMContentLoaded(t *testing.T) {
72+
// Test description
73+
//
74+
// 1. goto /home and wait for the domcontentloaded lifecycle event.
75+
// 2. use WaitForLoadState with domcontentloaded to ensure that
76+
// domcontentloaded lifecycle event has already fired.
77+
//
78+
// Success criteria: We don't wait for all network requests or the
79+
// async scripts to complete, and we're only
80+
// interested in the html file being loaded. We
81+
// also want to ensure that the domcontentloaded
82+
// event is stored internally, and we don't block
83+
// on WaitForLoadState.
84+
85+
t.Parallel()
86+
87+
tb := newTestBrowser(t, withFileServer())
88+
p := tb.NewPage(nil)
89+
tb.withHandler("/home", func(w http.ResponseWriter, r *http.Request) {
90+
http.Redirect(w, r, tb.staticURL("wait_for_nav_lifecycle.html"), http.StatusMovedPermanently)
91+
})
92+
93+
var counter int64
94+
var counterMu sync.Mutex
95+
tb.withHandler("/ping", func(w http.ResponseWriter, _ *http.Request) {
96+
counterMu.Lock()
97+
defer counterMu.Unlock()
98+
99+
time.Sleep(time.Millisecond * 100)
100+
101+
counter++
102+
fmt.Fprintf(w, "pong %d", counter)
103+
})
104+
105+
tb.withHandler("/ping.js", func(w http.ResponseWriter, _ *http.Request) {
106+
fmt.Fprintf(w, `
107+
await new Promise(resolve => setTimeout(resolve, 1000));
108+
109+
var pingJSTextOutput = document.getElementById("pingJSText");
110+
pingJSTextOutput.innerText = "ping.js loaded from server";
111+
`)
112+
})
113+
114+
waitUntil := common.LifecycleEventDOMContentLoad
115+
assertHome(t, tb, p, waitUntil, func() {
116+
result := p.TextContent("#pingRequestText", nil)
117+
assert.NotEqualValues(t, "Waiting... pong 10 - for loop complete", result)
118+
119+
result = p.TextContent("#pingJSText", nil)
120+
assert.EqualValues(t, "Waiting...", result)
121+
122+
// This shouldn't block and return after calling hasLifecycleEventFired.
123+
p.WaitForLoadState(waitUntil.String(), nil)
124+
})
125+
}
126+
71127
func TestLifecycleReloadLoad(t *testing.T) {
72128
t.Parallel()
73129

0 commit comments

Comments
 (0)