Skip to content

Truly independent web browser

2.3 KB
Raw Blame
<!DOCTYPE html>
<script src="../include.js"></script>
<style>
    .box {
        width: 20px;
        height: 20px;
    }
</style>
<div class="box" id="stale"></div>
<script>
    asyncTest(async done => {
        const stale = document.getElementById("stale");
        const nextFrame = () => new Promise(requestAnimationFrame);

        for (let i = 0; i < 1051; ++i) {
            const child = document.createElement("div");
            child.className = "box";
            stale.append(child);
        }
        const dummy = document.createElement("div");
        dummy.className = "box";
        stale.append(dummy);
        document.elementFromPoint(0, 0);

        const target = stale.children[stale.children.length - 2];
        target.id = "target";
        target.scrollIntoView();
        const staleChildren = [...stale.children].filter(child => child !== target && child !== dummy);
        const staleAnimations = staleChildren.map(child => child.animate([{ opacity: 1 }, { opacity: 0 }], { duration: 100000 }));
        target.animate([{ backgroundColor: "rgb(255, 0, 0)" }, { backgroundColor: "rgb(0, 0, 255)" }], { duration: 100000 });

        await nextFrame();
        internals.updateCompositorAnimations();
        document.elementFromPoint(0, 0);
        internals.updateCompositorAnimations();
        document.elementFromPoint(0, 0);

        const ownsEffectsNode = child => /^\[e\d+\]/m.test(internals.dumpVisualContextNodes(child));
        const staleEffectsFrame = staleChildren.every(ownsEffectsNode);
        for (const animation of staleAnimations)
            animation.cancel();
        internals.forceVisualContextTreeRebuildOnNextCompositorAnimationUpdateForTesting();
        internals.updateCompositorAnimations();

        const compositorAnimations = internals.dumpCompositorAnimations();
        const staleEffectsFrameRemoved = !staleChildren.some(ownsEffectsNode);

        println(`stale animation creates an effects frame: ${staleEffectsFrame}`);
        println(`stale effects frame is removed: ${staleEffectsFrameRemoved}`);
        println("compositor animations after the rebuild:");
        for (const line of compositorAnimations.split("\n").filter(Boolean))
            println(`  ${line}`);

        for (const animation of document.getAnimations())
            animation.cancel();
        done();
    });
</script>