Skip to content

Truly independent web browser

1.7 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 whose only rule's rightmost compound is :hover
        // should be targeted to the hovered element, of which there are at
        // most a handful at any moment. Without an interaction-state pseudo
        // optimization, the walk falls back to a whole-subtree invalidation
        // that recomputes every element.
        // Nothing, not even the arriving style element, as nothing is hovered.
        dumpWork(":hover-only sheet add", () => {
            const hoverStyle = document.createElement("style");
            hoverStyle.textContent = ":hover { color: rgb(0, 128, 0); }";
            document.head.appendChild(hoverStyle);
            getComputedStyle(trigger).color;
        });
    });
</script>