Skip to content

Truly independent web browser

3.0 KB
Raw Blame
<!DOCTYPE html>
<script src="../../include.js"></script>
<style>
    #target {
        color: rgb(0, 0, 0);
        opacity: 1;
        font-size: 10px;
        border: 1px solid currentcolor;
        transition: color 1000s linear, opacity 1000s linear;
    }
    #target.changed { color: rgb(100, 100, 100); opacity: 0; }
    #child { background-color: inherit; }
    #target::before { content: "pseudo"; }
</style>
<div id="target"><span id="child">child</span></div>
<script>
    test(() => {
        const target = document.getElementById("target");
        const child = document.getElementById("child");
        internals.updateStyle();
        target.classList.add("changed");
        internals.updateStyle();
        const animations = target.getAnimations();
        for (const animation of animations) {
            animation.pause();
            animation.currentTime = 500000;
        }
        internals.updateStyle();
        target.style.backgroundColor = "red";
        internals.updateStyle();
        println(`transition objects survive: ${target.getAnimations().every(animation => animations.includes(animation))}`);
        println(`transition color: ${getComputedStyle(target).color}`);
        println(`transition opacity: ${getComputedStyle(target).opacity}`);
        println(`background change: ${getComputedStyle(target).backgroundColor}`);
        println(`child background inherits base change: ${getComputedStyle(child).backgroundColor}`);
        println(`child color inherits sample: ${getComputedStyle(child).color}`);
        println(`pseudo color inherits sample: ${getComputedStyle(target, "::before").color}`);
        println(`border follows sampled currentcolor: ${getComputedStyle(target).borderTopColor}`);

        target.style.fontSize = "20px";
        target.style.marginLeft = "2em";
        internals.updateStyle();
        println(`font-dependent value after full drive: ${getComputedStyle(target).marginLeft}`);
        println(`sample survives font change: ${getComputedStyle(target).color}`);

        target.style.color = "rgb(200, 200, 200)";
        internals.updateStyle();
        const colorTransition = target.getAnimations().find(animation => animation.transitionProperty === "color");
        colorTransition.pause();
        colorTransition.currentTime = 500000;
        internals.updateStyle();
        println(`retargeted color midpoint: ${getComputedStyle(target).color}`);
        println(`child inherits retargeted sample: ${getComputedStyle(child).color}`);
        println(`opacity sample survives retargeting: ${getComputedStyle(target).opacity}`);

        target.style.transition = "none";
        internals.updateStyle();
        println(`transitions removed: ${target.getAnimations().length === 0}`);
        println(`underlying color restored: ${getComputedStyle(target).color}`);
        println(`underlying opacity restored: ${getComputedStyle(target).opacity}`);
        println(`unrelated background retained: ${getComputedStyle(target).backgroundColor}`);
    });
</script>