Skip to content

Truly independent web browser

1.9 KB
Raw Blame
<!DOCTYPE html>
<script src="../include.js"></script>
<script src="../work-test.js"></script>
<div id="target" style="width: 20px; height: 20px; background: red"></div>
<script>
function printCompositorAnimations(title) {
    println(title);
    for (const line of internals.dumpCompositorAnimations().split("\n").filter(Boolean))
        println(`  ${line}`);
}

asyncTest(async done => {
    internals.updateStyle();
    const frame = document.createElement("iframe");
    frame.style.display = "none";
    frame.srcdoc = "<!DOCTYPE html><body>Hidden document";
    const loaded = new Promise(resolve => frame.addEventListener("load", resolve, { once: true }));
    document.body.appendChild(frame);
    await loaded;
    frame.contentWindow.internals.updateStyle();
    const target = document.getElementById("target");
    const timeline = internals.createInternalAnimationTimeline();
    const animation = new Animation(new KeyframeEffect(target,
        [{ opacity: 1 }, { opacity: 0 }], { duration: 1000, iterations: Infinity }), timeline);
    // Establish the opacity layer at an explicit phase before checking compositor handoff.
    timeline.setTime(250);
    animation.play();
    animation.startTime = 0;
    getComputedStyle(target).opacity;
    for (let i = 0; i < 4; ++i)
        await new Promise(requestAnimationFrame);
    printCompositorAnimations("compositor animations:");
    internals.beginStyleTrace();
    timeline.setTime(500);
    for (let i = 0; i < 4; ++i)
        await new Promise(requestAnimationFrame);
    const sampled = parseStyleTrace(internals.takeStyleTrace()).filter(event => event.outcome?.startsWith("sampled"));
    println(`child rendering samples: [${sampled.map(event => event.element).join(", ")}]`);
    timeline.setTimeForObservation(500);
    println(`explicit style observation remains current: ${getComputedStyle(target).opacity === "0.5"}`);
    animation.cancel();
    done();
});
</script>