Skip to content

Truly independent web browser

3.1 KB
Raw Blame
<!DOCTYPE html>
<script src="../include.js"></script>
<script src="../work-test.js"></script>
<style>
    html, body {
        margin: 0;
    }
    body {
        height: 100px;
        overflow: hidden;
    }
    #overflowing {
        position: relative;
        top: 150px;
        width: 50px;
        height: 50px;
    }
</style>
<body><div id="overflowing"></div></body>
<script>
    test(() => {
        const html = document.documentElement;
        const body = document.body;
        const overflowing = document.getElementById("overflowing");

        function describeHit() {
            const hit = document.elementFromPoint(25, 175);
            if (!hit) return "null";
            return hit === overflowing ? hit.id : hit.nodeName.toLowerCase();
        }

        html.id = "tracked-html";
        body.id = "tracked-body";

        function runCase(name, mutate) {
            const [htmlTransition, bodyTransition, childTransition] = layoutTreeBuildWork(mutate, { tracked: [html, body, overflowing] }).transitions();
            println(`${name}: html=${htmlTransition}, body=${bodyTransition}, child=${childTransition}`);
            println(`${name}: hit at overflowing child=${describeHit()}`);
            println(`${name}: tree matches full rebuild=${internals.compareLayoutTreeWithFullRebuild().matches}`);
        }

        println(`initial: hit at overflowing child=${describeHit()}`);

        // With html overflow visible, body's overflow goes to the viewport and body itself does not clip.
        runCase("html visible -> hidden (body starts clipping)", () => {
            html.style.overflow = "hidden";
        });
        runCase("html hidden -> visible (body stops clipping)", () => {
            html.style.overflow = "";
        });
        runCase("body hidden -> visible while propagating", () => {
            body.style.overflow = "visible";
        });
        runCase("body visible -> scroll while propagating", () => {
            body.style.overflow = "scroll";
        });

        html.style.overflow = "hidden";
        body.style.overflow = "";
        runCase("body hidden -> visible while html propagates", () => {
            body.style.overflow = "visible";
        });
        runCase("body visible -> clip while html propagates", () => {
            body.style.overflow = "clip";
        });
        runCase("html overflow-x only hidden -> auto", () => {
            html.style.overflow = "";
            html.style.overflowX = "auto";
        });

        // A positioned body can be a partial relayout boundary of its own. Its overflow must still reach the viewport
        // instead of clipping the body.
        html.style.overflowX = "";
        body.style.overflow = "visible";
        body.style.position = "absolute";
        runCase("absolutely positioned body visible -> hidden while propagating", () => {
            body.style.overflow = "hidden";
        });
        body.style.overflow = "visible";
        body.style.position = "fixed";
        runCase("fixed positioned body visible -> hidden while propagating", () => {
            body.style.overflow = "hidden";
        });
    });
</script>