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>
<div style="display: none"><span id="hidden">hidden</span></div>
<style>
    #contents::before { content: "x"; }
</style>
<div id="contents" style="display: contents"><span>contents</span></div>
<div id="box" style="width: 10px; height: 0px; background: green"></div>
<script>
    // The lane ticks an animation beside those of elements whose boxes show nothing of what they animate: an element
    // under `display: none`, and a `display: contents` element whose animation its children do not inherit. It also
    // ticks it beside an animation of a `display: contents` element that its children inherit, or of its
    // pseudo-element, which the host samples: the boxes that show those hold what the host's frame showed.
    async function laneBeside(animateOther) {
        return whileLaneAnimates(() => {
            const other = animateOther();
            const animation = box.animate([{ height: "0px" }, { height: "100px" }], { duration: 10000, easing: "linear" });
            animation.other = other;
            return animation;
        }, (frameTime, animation) => {
            internals.injectClockTick(frameTime + 1000);
            const result = `${internals.clockLaneState(document)}, presented by ${internals.lastFramePresentedBy(document)}`;
            animation.cancel();
            animation.other.cancel();
            return result;
        });
    }

    asyncTest(async done => {
        const options = { duration: 10000, easing: "linear" };
        println(`beside an element under display: none: ${await laneBeside(() => hidden.animate([{ color: "black" }, { color: "blue" }], options))}`);
        println(`beside display: contents, not inherited: ${await laneBeside(() => contents.animate([{ opacity: 1 }, { opacity: 0 }], options))}`);
        println(`beside display: contents, inherited: ${await laneBeside(() => contents.animate([{ color: "black" }, { color: "blue" }], options))}`);
        println(`beside display: contents, its ::before: ${await laneBeside(() => contents.animate([{ marginLeft: "0px" }, { marginLeft: "10px" }], { ...options, pseudoElement: "::before" }))}`);
        done();
    });
</script>