Truly independent web browser
LibWeb: Start font display test loads after harness readiness
Andreas Kling58a66c3a941d
diff --git a/Tests/LibWeb/Ref/input/font-display-periods.html b/Tests/LibWeb/Ref/input/font-display-periods.htmlindex 1e74c9c506e..f6466502ef2 100644--- a/Tests/LibWeb/Ref/input/font-display-periods.html+++ b/Tests/LibWeb/Ref/input/font-display-periods.html@@ -10,37 +10,45 @@ body { margin: 0; }</style><body><script>-addEventListener("load", async () => {- const server = httpTestServer();- const token = crypto.randomUUID();- const url = await server.createEcho("GET", "/font-display-periods.woff", {- status: 404,- headers: { "Access-Control-Allow-Origin": "*" },- wait_for_unblock: token,- });- document.getElementById("reference").href += `?unblock=${token}`;- for (const display of ["auto", "block", "swap", "fallback", "optional"]) {- for (const elapsed of [0, 99, 100, 2999, 3000, 3099, 3100]) {- const family = `${display}-${elapsed}`;- const style = document.createElement("style");- style.textContent = `@font-face { font-family: "${family}"; src: url("${url}"); font-display: ${display}; unicode-range: U+0041; }`;- document.head.append(style);- const face = [...document.fonts].find(face => face.family === family);- internals.setFontDisplayTime(face, 0);- const row = document.createElement("div");- row.className = "row";- row.append(`${family.padEnd(14)} `);- const sample = document.createElement("span");- sample.className = "sample";- sample.style.fontFamily = `"${family}", monospace`;- sample.textContent = "AB";- row.append(sample);- document.body.append(row);- row.getBoundingClientRect();- internals.setFontDisplayTime(face, elapsed);+// NB: Start the pending font loads after the harness has checked font readiness+// and installed its completion observer.+addEventListener("TestRendered", async () => {+ try {+ const server = httpTestServer();+ const token = crypto.randomUUID();+ const url = await server.createEcho("GET", "/font-display-periods.woff", {+ status: 404,+ headers: { "Access-Control-Allow-Origin": "*" },+ wait_for_unblock: token,+ });+ document.getElementById("reference").href += `?unblock=${token}`;+ for (const display of ["auto", "block", "swap", "fallback", "optional"]) {+ for (const elapsed of [0, 99, 100, 2999, 3000, 3099, 3100]) {+ const family = `${display}-${elapsed}`;+ const style = document.createElement("style");+ style.textContent = `@font-face { font-family: "${family}"; src: url("${url}"); font-display: ${display}; unicode-range: U+0041; }`;+ document.head.append(style);+ const face = [...document.fonts].find(face => face.family === family);+ internals.setFontDisplayTime(face, 0);+ const row = document.createElement("div");+ row.className = "row";+ row.append(`${family.padEnd(14)} `);+ const sample = document.createElement("span");+ sample.className = "sample";+ sample.style.fontFamily = `"${family}", monospace`;+ sample.textContent = "AB";+ row.append(sample);+ document.body.append(row);+ row.getBoundingClientRect();+ internals.setFontDisplayTime(face, elapsed);+ }}+ } catch (error) {+ // NB: Fail the comparison clearly instead of timing out.+ console.error(`font-display-periods failed: ${error}`);+ } finally {+ document.documentElement.className = "";}- document.documentElement.className = "";});</script></html>