Skip to content

Truly independent web browser

1.9 KB
Raw Blame
<!DOCTYPE html>
<script src="../include.js"></script>
<script src="../work-test.js"></script>
<style>
    #wrapper { font-size: 20px; }
    .item { color: green; }
</style>
<div id="wrapper"><canvas id="canvas"></canvas></div>
<div id="items"></div>
<script>
    test(() => {
        // Shadow roots and siblings, so that a pass reaching past the canvas shows up in the counts.
        for (let i = 0; i < 10; i++) {
            const host = document.createElement("div");
            host.attachShadow({ mode: "open" }).innerHTML = `<style>span { color: blue; }</style><span>Shadow ${i}</span>`;
            items.appendChild(host);
        }
        for (let i = 0; i < 50; i++)
            items.insertAdjacentHTML("beforeend", `<div class="item"><span>Item ${i}</span></div>`);

        const context = canvas.getContext("2d");

        const fonts = [];
        const work = styleWork(() => {
            for (let i = 0; i < 10; i++) {
                context.font = `${1 + i / 10}em serif`;
                fonts.push(context.font);
            }
        }, internals, { flush: false });

        println(`fonts: ${fonts.join(", ")}`);
        println(`font reads: passes [${work.passes().join(", ")}], restyled [${work.restyled().map(shortStyleName).join(", ")}]`);

        // The font follows a change of the canvas's own style.
        wrapper.style.fontSize = "25px";
        context.font = "2em serif";
        println(`restyled: ${context.font}`);

        // A canvas that a pending change puts below display:none still resolves its font against the style it would
        // have.
        wrapper.style.display = "none";
        wrapper.style.fontSize = "30px";
        context.font = "2em serif";
        println(`hidden: ${context.font}`);
        wrapper.style.fontSize = "35px";
        context.font = "2em serif";
        println(`still hidden: ${context.font}`);
    });
</script>