Skip to content

Truly independent web browser

1.6 KB
Raw Blame
<!DOCTYPE html>
<meta charset="utf-8">
<script src="../../include.js"></script>
<script src="../../work-test.js"></script>
<div id="trigger"></div>
<script>
    function settle(triggerElement) {
        getComputedStyle(triggerElement).color;
        getComputedStyle(triggerElement).color;
        internals.updateStyle();
    }

    function addBystanders(parent, count) {
        for (let i = 0; i < count; ++i) {
            const bystander = document.createElement("div");
            bystander.textContent = `bystander ${i}`;
            parent.appendChild(bystander);
        }
    }

    function dumpWork(label, mutate) {
        const work = styleWork(mutate);
        const fullPass = work.passes().includes("FULL") ? " (full pass)" : "";
        println(`${label}: restyled [${work.restyled().map(shortStyleName).join(", ")}]${fullPass}`);
    }

    test(() => {
        const trigger = document.getElementById("trigger");
        addBystanders(document.body, 25);
        settle(trigger);

        // Adding a sheet that only declares @font-face does not change any
        // element's computed style at the at-rule's declaration time. The font
        // resource takes effect later, via CSSFontLoaded.
        // Nothing, not even the arriving style element.
        dumpWork("@font-face only sheet add", () => {
            const fontFaceStyle = document.createElement("style");
            fontFaceStyle.textContent = `@font-face { font-family: "test-font"; src: url(/test-font.woff); }`;
            document.head.appendChild(fontFaceStyle);
            getComputedStyle(trigger).color;
        });
    });
</script>