Skip to content

Truly independent web browser

2.2 KB
Raw Blame
<!DOCTYPE html>
<script src="../../include.js"></script>
<script src="frame-in-flight.js"></script>
<style>
    @keyframes tint {
        from { background-color: white; }
        to { background-color: lavender; }
    }
    @keyframes grow {
        from { width: 0px; }
        to { width: 100px; }
    }
    body {
        animation: tint linear both;
        animation-timeline: scroll(root);
    }
    #bar::before {
        content: "";
        display: block;
        height: 4px;
        background: blue;
        animation: grow linear both;
        animation-timeline: scroll(root);
    }
    #spacer {
        height: 2000px;
    }
</style>
<div id="bar"></div>
<div id="indicator" style="height: 4px; background: blue"></div>
<div id="box" style="width: 10px; height: 0px; background: green"></div>
<div id="spacer"></div>
<script>
    // A long task should not freeze the box's animation just because the page also has scroll-driven animations that
    // the render clock cannot sample. Here those are on the body, on a pseudo-element, and one that plays in reverse.
    promiseTest(async () => {
        const result = await whileLaneAnimates(() => {
            const reversed = indicator.animate([{ width: "0px" }, { width: "100px" }], { timeline: new ScrollTimeline({ source: document.documentElement }) });
            reversed.playbackRate = -1;
            return box.animate([{ height: "0px" }, { height: "100px" }], { duration: 10000, easing: "linear" });
        }, (frameTime, animation) => {
            internals.injectClockTick(frameTime + 1000);
            const lane = internals.clockLaneState(document);
            const expectedHeight = (frameTime + 1000 - animation.startTime) / 100;
            const presented = internals.presentedBorderBox(box);
            return {
                lane,
                presentedHeightIsTheTicks: presented !== null && Math.abs(presented.height - expectedHeight) < 0.02,
                presentedBy: internals.lastFramePresentedBy(document),
            };
        });
        println(`lane after the tick: ${result.lane}`);
        println(`the presented height is the animation's at the tick: ${result.presentedHeightIsTheTicks}`);
        println(`last frame presented by: ${result.presentedBy}`);
    });
</script>