Skip to content

Truly independent web browser

3.0 KB
Raw Blame
<!DOCTYPE html>
<meta charset="utf-8">
<script src="include.js"></script>
<script src="work-test.js"></script>
<style>
    body { margin: 0; }
    #spacer { width: 100px; height: 50px; }
    #cached {
        width: 300px;
        overflow: hidden;
        background-color: yellow;
    }
    #inner { width: 120px; height: 40px; position: relative; left: 3px; text-transform: uppercase; }
</style>
<div id="spacer"></div>
<div id="cached">
    <div id="inner">straße אבג café words that wrap</div>
</div>
<script>
    let range, selected;
    layoutTest({
        setup: () => {
            range = document.createRange();
            range.setStart(inner.firstChild, 1);
            range.setEnd(inner.firstChild, inner.firstChild.length - 2);
            getSelection().addRange(range);
            internals.dumpDisplayList();
        },
        steps: [
            {
                name: "paint-only changes preserve the cached run and selection",
                mutate: () => {
                    cached.style.backgroundColor = "lime";
                    spacer.style.height = "80px";
                },
                expect: `
                    layout FULL
                      @viewport/block RUN (cache=bypass)
                        BlockContainer<HTML>/block RUN (cache=miss)
                          BlockContainer<DIV>#cached/block REUSE SUBTREE
                `,
                check: equal => {
                    selected = internals.dumpDisplayList();
                    getSelection().removeAllRanges();
                    const unselected = internals.dumpDisplayList();
                    getSelection().addRange(range);
                    const reselected = internals.dumpDisplayList();
                    equal(unselected !== selected, true, "clearing selection changes paint");
                    equal(reselected, selected, "restoring selection restores paint");
                },
            },
            {
                name: "cached selection matches fresh layout",
                mutate: () => {
                    cached.style.width = "301px";
                    internals.updateLayoutForTesting();
                    cached.style.width = "300px";
                },
                expect: `
                    layout FULL
                      @viewport/block RUN (cache=bypass)
                        BlockContainer<HTML>/block RUN (cache=miss)
                          BlockContainer<DIV>#spacer REUSE IN-FLOW SUBTREE
                          BlockContainer<DIV>#cached/block RUN (cache=miss)
                    layout FULL
                      @viewport/block RUN (cache=bypass)
                        BlockContainer<HTML>/block RUN (cache=miss)
                          BlockContainer<DIV>#spacer REUSE IN-FLOW SUBTREE
                          BlockContainer<DIV>#cached/block RUN (cache=miss)
                `,
                check: equal => {
                    equal(internals.dumpDisplayList(), selected, "cached selection matches fresh layout");
                },
            },
        ],
    });
</script>