LibWeb: Wait for the iframe load before completing the beforeunload test

This test caused some flakiness due to the about:blank load it triggers.
It causes headless-browser to receive a load event for about:blank. If
we have moved onto the next test before that event arrived, that test
would ultimately time out, as its own load will have been dropped while
the about:blank load is still ongoing.

This patch makes us wait for that iframe load event before completing
the test.

We may want to consider never sending subframe load events to the UI
process as well. We really only care about top-level page loads in the
receivers of that event.
This commit is contained in:
Timothy Flynn 2024-10-07 14:47:31 -04:00 committed by Tim Flynn
parent d0008ae5e0
commit be9071834e
Notes: github-actions[bot] 2024-10-07 20:04:42 +00:00
2 changed files with 7 additions and 0 deletions

View file

@ -1,2 +1,3 @@
Before unload event fired
Default prevented: true
iframe load: about:blank

View file

@ -3,12 +3,18 @@
asyncTest(done => {
const iframe = document.createElement("iframe");
document.body.appendChild(iframe);
iframe.contentWindow.addEventListener("beforeunload", e => {
println("Before unload event fired");
e.preventDefault();
println(`Default prevented: ${e.defaultPrevented}`);
});
iframe.addEventListener("load", e => {
println(`iframe load: ${e.target.src}`);
done();
});
iframe.src = "about:blank";
});
</script>