Skip to content

Truly independent web browser

2.2 KB
Raw Blame
<!DOCTYPE html>
<script src="../include.js"></script>
<script src="../work-test.js"></script>
<style>
    #box { width: 50px; height: 50px; transform: translateX(5px); }
</style>
<div id="box"></div>
<script>
    const steps = [
        {
            name: "propagated body background",
            mutate: () => { document.body.style.background = "orange"; },
            check: equal => equal(box.getBoundingClientRect().x, 13, "rect x"),
            expect: ``,
        },
        {
            name: "propagation stops",
            mutate: () => { document.documentElement.style.background = "white"; },
            check: equal => equal(box.getBoundingClientRect().x, 13, "rect x"),
            expect: ``,
        },
        {
            name: "propagation restored",
            mutate: () => { document.documentElement.style.background = ""; },
            check: equal => equal(box.getBoundingClientRect().x, 13, "rect x"),
            expect: ``,
        },
    ];
    for (const [element, label] of [[document.body, "body"], [box, "box"]]) {
        for (const attachment of ["fixed", "local", "scroll"]) {
            steps.push(
                {
                    name: `${attachment} ${label} background image`,
                    mutate: () => {
                        element.style.backgroundImage = "linear-gradient(red, blue)";
                        element.style.backgroundAttachment = attachment;
                    },
                    expect: ``,
                },
                {
                    name: `${attachment} ${label} background image with a root background`,
                    mutate: () => { document.documentElement.style.backgroundColor = "white"; },
                    expect: ``,
                },
                {
                    name: `${attachment} ${label} background image without a root background`,
                    mutate: () => { document.documentElement.style.backgroundColor = "transparent"; },
                    expect: ``,
                });
        }
        steps.push({
            name: `${label} background image removed`,
            mutate: () => { element.style.backgroundImage = "none"; },
            expect: ``,
        });
    }
    visualContextTest({ steps });
</script>