Skip to content

Truly independent web browser

9.4 KB
Raw Blame
<!doctype html>
<html id="html">
<script src="../include.js"></script>
<script src="../work-test.js"></script>
<style>
    body { margin: 0; font: 16px/20px monospace; }
    #target { width: 200px; height: 40px; background: silver; }
    #inline { position: relative; }
    canvas { display: block; width: 100px; height: 20px; background: green; }
</style>
<body id="body">
<div id="target"><span id="inline">Original</span></div>
<canvas id="trigger" width="100" height="20"></canvas>
<script>
displayListTest({
    setup: removeBodyWhitespace,
    steps: [
        {
            name: "identical inline output survives full relayout",
            mutate: () => {
                trigger.width = trigger.width;
            },
            check: equal => {
                equal(document.elementFromPoint(5, 10).id, "inline", "inline hit target");
            },
            expect: {
                layout: `
                    layout FULL
                      @viewport/block RUN (cache=bypass)
                        BlockContainer<HTML>#html/block RUN (cache=miss)
                          BlockContainer<DIV>#target REUSE IN-FLOW SUBTREE
                          CanvasBox<CANVAS>#trigger/internal-replaced RUN (cache=bypass)
                `,
                displayList: `
                    @canvas RECORD (empty)
                    @viewport COPY
                `,
            },
        },
        {
            name: "different text at the same size records new paint",
            mutate: () => { document.getElementById("inline").firstChild.data = "Changed!"; },
            check: equal => { equal(target.getBoundingClientRect().height, 40, "unchanged target height"); },
            expect: `
                @canvas RECORD (empty)
                @viewport ASSEMBLE
                  @viewport/preamble COPY
                  @viewport/scroll-metadata COPY
                  @viewport/background COPY
                  @viewport/border COPY
                  BlockContainer<HTML>#html/descendants(background-and-borders) ASSEMBLE
                  @viewport/foreground COPY
                  BlockContainer<HTML>#html/descendants(foreground) ASSEMBLE
                  BlockContainer<HTML>#html ASSEMBLE
                    BlockContainer<HTML>#html/preamble COPY
                    BlockContainer<HTML>#html/scroll-metadata COPY
                    BlockContainer<HTML>#html/background COPY
                    BlockContainer<HTML>#html/border COPY
                    BlockContainer<BODY>#body/descendants(background-and-borders) ASSEMBLE
                      BlockContainer<BODY>#body/scroll-metadata COPY
                      BlockContainer<BODY>#body/background COPY
                      BlockContainer<BODY>#body/border COPY
                      BlockContainer<DIV>#target/descendants(background-and-borders) ASSEMBLE
                        BlockContainer<DIV>#target/scroll-metadata RECORD (empty)
                        BlockContainer<DIV>#target/background RECORD
                        BlockContainer<DIV>#target/border SKIP
                        InlineNode<SPAN>#inline/descendants(background-and-borders) RECORD
                      CanvasBox<CANVAS>#trigger/descendants(background-and-borders) COPY
                    BlockContainer<BODY>#body/descendants(inline-background-and-borders) ASSEMBLE
                      BlockContainer<DIV>#target/descendants(inline-background-and-borders) ASSEMBLE
                        InlineNode<SPAN>#inline/descendants(inline-background-and-borders) RECORD
                      CanvasBox<CANVAS>#trigger/descendants(inline-background-and-borders) COPY
                    BlockContainer<HTML>#html/foreground COPY
                    BlockContainer<BODY>#body/descendants(foreground) ASSEMBLE
                      BlockContainer<BODY>#body/foreground COPY
                      BlockContainer<DIV>#target/descendants(foreground) ASSEMBLE
                        BlockContainer<DIV>#target/foreground RECORD (empty)
                        InlineNode<SPAN>#inline/descendants(foreground) RECORD
                        BlockContainer<DIV>#target/outline SKIP
                        BlockContainer<DIV>#target/overlay SKIP
                      CanvasBox<CANVAS>#trigger/descendants(foreground) COPY
                      BlockContainer<BODY>#body/outline COPY
                      BlockContainer<BODY>#body/overlay COPY
                    InlineNode<SPAN>#inline RECORD
                      InlineNode<SPAN>#inline/scroll-metadata RECORD (empty)
                      InlineNode<SPAN>#inline/background SKIP
                      InlineNode<SPAN>#inline/border SKIP
                      InlineNode<SPAN>#inline/inline-piece RECORD (empty)
                      InlineNode<SPAN>#inline/text-fragment RECORD
                      InlineNode<SPAN>#inline/foreground RECORD (empty)
                      InlineNode<SPAN>#inline/outline SKIP
                      InlineNode<SPAN>#inline/overlay SKIP
                    BlockContainer<HTML>#html/outline SKIP
                  @viewport/outline COPY
            `,
        },
        {
            name: "relayout preserves pending style paint invalidation",
            mutate: () => {
                document.getElementById("inline").style.color = "red";
                trigger.width = trigger.width;
            },
            check: equal => {
                equal(getComputedStyle(document.getElementById("inline")).color, "rgb(255, 0, 0)", "new text color");
            },
            expect: {
                layout: `
                    layout FULL
                      @viewport/block RUN (cache=bypass)
                        BlockContainer<HTML>#html/block RUN (cache=miss)
                          BlockContainer<DIV>#target REUSE IN-FLOW SUBTREE
                          CanvasBox<CANVAS>#trigger/internal-replaced RUN (cache=bypass)
                `,
                displayList: `
                    @canvas RECORD (empty)
                    @viewport ASSEMBLE
                      @viewport/preamble COPY
                      @viewport/scroll-metadata COPY
                      @viewport/background COPY
                      @viewport/border COPY
                      BlockContainer<HTML>#html/descendants(background-and-borders) ASSEMBLE
                      @viewport/foreground COPY
                      BlockContainer<HTML>#html/descendants(foreground) ASSEMBLE
                      BlockContainer<HTML>#html ASSEMBLE
                        BlockContainer<HTML>#html/preamble COPY
                        BlockContainer<HTML>#html/scroll-metadata COPY
                        BlockContainer<HTML>#html/background COPY
                        BlockContainer<HTML>#html/border COPY
                        BlockContainer<BODY>#body/descendants(background-and-borders) ASSEMBLE
                          BlockContainer<BODY>#body/scroll-metadata COPY
                          BlockContainer<BODY>#body/background COPY
                          BlockContainer<BODY>#body/border COPY
                          BlockContainer<DIV>#target/descendants(background-and-borders) ASSEMBLE
                            BlockContainer<DIV>#target/scroll-metadata RECORD (empty)
                            BlockContainer<DIV>#target/background RECORD
                            BlockContainer<DIV>#target/border SKIP
                            InlineNode<SPAN>#inline/descendants(background-and-borders) RECORD
                          CanvasBox<CANVAS>#trigger/descendants(background-and-borders) COPY
                        BlockContainer<BODY>#body/descendants(inline-background-and-borders) ASSEMBLE
                          BlockContainer<DIV>#target/descendants(inline-background-and-borders) ASSEMBLE
                            InlineNode<SPAN>#inline/descendants(inline-background-and-borders) RECORD
                          CanvasBox<CANVAS>#trigger/descendants(inline-background-and-borders) COPY
                        BlockContainer<HTML>#html/foreground COPY
                        BlockContainer<BODY>#body/descendants(foreground) ASSEMBLE
                          BlockContainer<BODY>#body/foreground COPY
                          BlockContainer<DIV>#target/descendants(foreground) ASSEMBLE
                            BlockContainer<DIV>#target/foreground RECORD (empty)
                            InlineNode<SPAN>#inline/descendants(foreground) RECORD
                            BlockContainer<DIV>#target/outline SKIP
                            BlockContainer<DIV>#target/overlay SKIP
                          CanvasBox<CANVAS>#trigger/descendants(foreground) COPY
                          BlockContainer<BODY>#body/outline COPY
                          BlockContainer<BODY>#body/overlay COPY
                        InlineNode<SPAN>#inline RECORD
                          InlineNode<SPAN>#inline/scroll-metadata RECORD (empty)
                          InlineNode<SPAN>#inline/background SKIP
                          InlineNode<SPAN>#inline/border SKIP
                          InlineNode<SPAN>#inline/inline-piece RECORD (empty)
                          InlineNode<SPAN>#inline/text-fragment RECORD
                          InlineNode<SPAN>#inline/foreground RECORD (empty)
                          InlineNode<SPAN>#inline/outline SKIP
                          InlineNode<SPAN>#inline/overlay SKIP
                        BlockContainer<HTML>#html/outline SKIP
                      @viewport/outline COPY
                `,
            },
        },
    ],
});
</script>