Truly independent web browser
<!doctype html>
<script src="../include.js"></script>
<script src="../work-test.js"></script>
<script>
asyncTest(async done => {
const server = httpTestServer();
const token = crypto.randomUUID();
const bytes = new Uint8Array(await (await fetch("../../../Assets/HashSans.woff")).arrayBuffer());
const url = await server.createEcho("GET", "/stable-display-period.woff", {
status: 200,
headers: { "Content-Type": "font/woff", "Access-Control-Allow-Origin": "*" },
body: btoa(String.fromCharCode(...bytes)),
body_encoding: "base64",
wait_for_unblock: token,
});
const face = new FontFace("StableDisplayPeriod", `url("${url}")`, { display: "block" });
internals.setFontDisplayTime(face, 0);
document.fonts.add(face);
const target = document.body.appendChild(document.createElement("span"));
target.style.cssText = "display: inline-block; font: 20px StableDisplayPeriod, monospace; width: 10ch";
target.textContent = "AAAA";
const fallbackWidth = target.getBoundingClientRect().width;
const results = [`selected face is loading: ${face.status === "loading"}`];
internals.updateStyle();
const layoutPasses = work => work.passes().join(" | ") || "(no layout)";
let work = layoutWork(() => {
target.style.color = "red";
target.getBoundingClientRect();
});
results.push(`layout after paint change while pending: ${layoutPasses(work)}`);
const displayWork = styleWork(() => {
face.display = "swap";
target.getBoundingClientRect();
});
results.push(`display transition style work: passes [${displayWork.passes().join(", ")}], restyled [${displayWork.restyled().map(shortStyleName).join(", ")}]`);
results.push(`display transition keeps fallback metrics: ${target.getBoundingClientRect().width === fallbackWidth}`);
work = layoutWork(() => {
target.style.color = "blue";
target.getBoundingClientRect();
});
results.push(`layout after paint change with visible fallback: ${layoutPasses(work)}`);
await fetch(`${server.baseURL}/unblock/${token}`);
await face.loaded;
results.push(`loaded face changes metrics: ${target.getBoundingClientRect().width !== fallbackWidth}`);
work = layoutWork(() => {
target.style.color = "green";
target.getBoundingClientRect();
});
results.push(`layout after paint change with loaded face: ${layoutPasses(work)}`);
for (const result of results)
println(result);
done();
});
</script>