Skip to content

Truly independent web browser

1.3 KB
Raw Blame
<!DOCTYPE html>
<meta charset="utf-8">
<script src="../../include.js"></script>
<script src="../../work-test.js"></script>
<script src="structural-matrix.js"></script>
<script>
    test(() => {
        const style = addStyle(document.head, `.leaf { ${MATCH_DECLARATION} }`);

        const box = makeElement("section");
        for (let i = 0; i < 10; i++) box.appendChild(makeElement("div", { className: "leaf" }));
        document.body.append(box);
        internals.updateStyle();

        // The ten leaves have each computed a style once and none of them declares an animation or a
        // transition. Recomputing them all decides the same thing about each, so one of them derives
        // a style and the other nine take it, exactly as on their first pass.
        let second;
        const work = styleWork(() => (second = addStyle(document.head, `.leaf { color: rgb(1, 2, 3); }`)));
        const leaves = work.events.filter(event => event.event === "restyle" && event.element.includes(".leaf"));
        println(`recomputed siblings: ${["computed", "shared", "reused"].map(outcome => `${outcome} ${leaves.filter(event => event.outcome === outcome).length}`).join(", ")}`);
        assertEqual("the shared style is the matched one", readProbe(box.firstChild), MATCH);

        box.remove();
        style.remove();
        second.remove();
    });
</script>