Skip to content

Truly independent web browser

2.0 KB
Raw Blame
<!DOCTYPE html>
<script src="../include.js"></script>
<script src="../work-test.js"></script>
<style>
    @keyframes spin { to { transform: rotate(360deg); } }
    svg { width: 16px; height: 16px; animation: spin 1000s linear infinite; }
</style>
<svg id="spinner" viewBox="0 0 16 16"><path d="M15 8A7 7 0 0 0 8 1" fill="none" stroke="black" /></svg>
<script>
    function printCompositorAnimations(title) {
        println(title);
        for (const line of internals.dumpCompositorAnimations().split("\n").filter(Boolean))
            println(`  ${line}`);
    }

    asyncTest(async done => {
        internals.updateStyle();
        const spinner = document.getElementById("spinner");
        const animation = spinner.getAnimations()[0];
        const timeline = internals.createInternalAnimationTimeline();
        animation.timeline = timeline;
        animation.startTime = 0;
        timeline.setTime(0);
        timeline.setTimeForObservation(0);
        for (let i = 0; i < 4; ++i)
            await new Promise(requestAnimationFrame);
        printCompositorAnimations("synthesized transform endpoint uses compositor:");
        internals.beginStyleTrace();
        for (let i = 0; i < 4; ++i)
            await new Promise(requestAnimationFrame);
        const sampled = parseStyleTrace(internals.takeStyleTrace()).filter(event => event.outcome?.startsWith("sampled"));
        println(`main-thread samples: [${sampled.map(event => event.element).join(", ")}]`);

        spinner.style.transform = "rotate(90deg)";
        for (let i = 0; i < 2; ++i)
            await new Promise(requestAnimationFrame);
        printCompositorAnimations("underlying style change preserves handoff:");
        timeline.setTimeForObservation(500000);
        const matrix = new DOMMatrix(getComputedStyle(spinner).transform);
        println(`synthesized endpoint follows underlying style: ${Math.abs(matrix.a + Math.SQRT1_2) < 0.001 && Math.abs(matrix.b + Math.SQRT1_2) < 0.001}`);
        animation.cancel();
        done();
    });
</script>