Skip to content

Truly independent web browser

Tests/LibWeb: Poll for conditions through waitForCondition()

Jelle Raaijmakers325af8c9220b
diff --git a/Tests/LibWeb/Text/input/SiteIsolation/iframe/autofocus-does-not-cross-an-isolated-iframe.html b/Tests/LibWeb/Text/input/SiteIsolation/iframe/autofocus-does-not-cross-an-isolated-iframe.html
index cc50d834412..72f1eebd24f 100644
--- a/Tests/LibWeb/Text/input/SiteIsolation/iframe/autofocus-does-not-cross-an-isolated-iframe.html
+++ b/Tests/LibWeb/Text/input/SiteIsolation/iframe/autofocus-does-not-cross-an-isolated-iframe.html
@@ -38,11 +38,7 @@
const received = [];
window.addEventListener("message", event => received.push(event.data));
- const waitFor = async what => {
- for (let attempt = 0; attempt < 200 && !received.includes(what); ++attempt)
- await timeout(25);
- return received.includes(what);
- };
+ const waitFor = what => waitForCondition(() => received.includes(what));
const iframe = document.createElement("iframe");
iframe.src = childUrl;
diff --git a/Tests/LibWeb/Text/input/SiteIsolation/iframe/messages-reach-a-same-site-grandchild-through-an-isolated-iframe.html b/Tests/LibWeb/Text/input/SiteIsolation/iframe/messages-reach-a-same-site-grandchild-through-an-isolated-iframe.html
index 3a7de7f94c2..10f61b7ff38 100644
--- a/Tests/LibWeb/Text/input/SiteIsolation/iframe/messages-reach-a-same-site-grandchild-through-an-isolated-iframe.html
+++ b/Tests/LibWeb/Text/input/SiteIsolation/iframe/messages-reach-a-same-site-grandchild-through-an-isolated-iframe.html
@@ -55,8 +55,7 @@
frames[0].postMessage("ping", "*");
println(`round trip through the isolated iframe: ${(await pong) === "pong"}`);
- for (let attempt = 0; attempt < 400 && !iframeLoaded; ++attempt)
- await timeout(25);
+ await waitForCondition(() => iframeLoaded);
println(`iframe load event fired: ${iframeLoaded}`);
println(internals.dumpSiteIsolationProcessTree().trimEnd());
});
diff --git a/Tests/LibWeb/Text/input/SiteIsolation/iframe/rendering-continues-with-a-hosted-grandchild.html b/Tests/LibWeb/Text/input/SiteIsolation/iframe/rendering-continues-with-a-hosted-grandchild.html
index ae2fbd38224..66b4122a43c 100644
--- a/Tests/LibWeb/Text/input/SiteIsolation/iframe/rendering-continues-with-a-hosted-grandchild.html
+++ b/Tests/LibWeb/Text/input/SiteIsolation/iframe/rendering-continues-with-a-hosted-grandchild.html
@@ -12,9 +12,7 @@
const animationFrameFires = async () => {
let fired = false;
requestAnimationFrame(() => (fired = true));
- for (let attempt = 0; attempt < 200 && !fired; ++attempt)
- await timeout(25);
- return fired;
+ return waitForCondition(() => fired);
};
const addFrame = async url => {
diff --git a/Tests/LibWeb/Text/input/css/font-face-unused-face-not-fetched.html b/Tests/LibWeb/Text/input/css/font-face-unused-face-not-fetched.html
index 51c9c044490..73d75c08c93 100644
--- a/Tests/LibWeb/Text/input/css/font-face-unused-face-not-fetched.html
+++ b/Tests/LibWeb/Text/input/css/font-face-unused-face-not-fetched.html
@@ -50,8 +50,7 @@
await face.loaded;
// The resource-timing entry lands in a separately queued task; poll until it appears.
// Bounded, so a missing entry fails with a diff rather than hanging until the harness timeout.
- for (let attempt = 0; attempt < 200 && fontRequestCount() === 0; ++attempt)
- await new Promise(resolve => setTimeout(resolve, 10));
+ await waitForCondition(() => fontRequestCount() !== 0, 200, 10);
println(`Used face status: ${face.status}`);
println(`Font requests after use: ${fontRequestCount()}`);
});