Skip to content

Truly independent web browser

2.9 KB
Raw Blame
<!DOCTYPE html>
<script src="../../include.js"></script>
<script src="../../work-test.js"></script>
<style>
    .random { width: random(1px, 100px); }
    .shared-random { width: random(--shared-test element-shared, 1px, 100px); }
    .fixed-random { width: random(fixed 0.5, 1px, 100px); }
    .image { background-image: url("context-image.png"); }
</style>
<div id="randomRoot"></div>
<div id="sharedRandomRoot"></div>
<div id="fixedRandomRoot"></div>
<div id="imageRoot"></div>
<script>
    test(() => {
        const outcomes = work => work.events.filter(event => event.event === "restyle").map(event => `${event.element} ${event.outcome}`).join(", ");
        let randomNodes;
        const randomWork = styleWork(() => {
            randomNodes = Array.from({ length: 8 }, () => {
                const node = document.createElement("div");
                node.className = "random";
                randomRoot.append(node);
                return node;
            });
        });
        println(`random() computations: ${outcomes(randomWork)}`);
        const widths = randomNodes.map(node => getComputedStyle(node).width);
        randomRoot.style.color = "red";
        println(`random values survive inherited changes: ${randomNodes.every((node, index) => getComputedStyle(node).width === widths[index])}`);

        for (const [holder, className] of [[sharedRandomRoot, "shared-random"], [fixedRandomRoot, "fixed-random"]]) {
            let nodes;
            const work = styleWork(() => {
                nodes = Array.from({ length: 8 }, () => {
                    const node = document.createElement("div");
                    node.className = className;
                    holder.append(node);
                    return node;
                });
            });
            // FIXME: Elements with an element-shared or fixed random() should share records, but the style engine
            //        shares none of the records of elements computing random().
            println(`${className} computations: ${outcomes(work)}`);
            const width = getComputedStyle(nodes[0]).width;
            println(`${className} computations agree: ${nodes.every(node => getComputedStyle(node).width === width)}`);
        }

        const imageNodes = Array.from({ length: 8 }, () => {
            const node = document.createElement("div");
            node.className = "image";
            imageRoot.append(node);
            return node;
        });
        internals.updateStyle();
        for (const node of imageNodes)
            node.style.backgroundImage = 'url("context-image.png")';
        const reference = document.createElement("div");
        reference.style.backgroundImage = 'url("context-image.png")';
        imageRoot.append(reference);
        const expected = getComputedStyle(reference).backgroundImage;
        println(`image declaration contexts agree: ${imageNodes.every(node => getComputedStyle(node).backgroundImage === expected)}`);
    });
</script>