Skip to content

Truly independent web browser

2.0 KB
Raw Blame
<!DOCTYPE html>
<script src="../../include.js"></script>
<style>
    #parent.active { color: rgb(0, 128, 0); }
    #subject.direct { background-color: rgb(0, 0, 255); }
    .changed { outline-width: 3px; }
</style>
<div id="holding">
    <div id="subject">
        <span id="leaf">leaf</span>
    </div>
</div>
<section id="parent"></section>
<div id="early"></div>
<div id="late"></div>
<script>
    test(() => {
        const parent = document.getElementById("parent");
        const subject = document.getElementById("subject");
        const leaf = document.getElementById("leaf");
        const early = document.getElementById("early");
        const late = document.getElementById("late");

        // Every node takes its identity as style first observes it, which a rendering update may or may
        // not have done yet. Settle first, so the moves below retire identities the nodes already have.
        internals.updateStyle();

        // Move the subject under the ancestor whose inherited style will change, then settle the
        // move before the changes below.
        parent.append(subject);
        internals.updateStyle();

        // Reinsert the later-identity sibling before the earlier one. This makes identity order
        // disagree with document order without introducing an inheritance dependency.
        early.before(late);
        internals.updateStyle();
        early.classList.add("changed");
        late.classList.add("changed");
        early.classList.remove("changed");
        late.classList.remove("changed");
        internals.updateStyle();

        parent.classList.add("active");
        subject.classList.add("direct");
        early.classList.add("changed");
        late.classList.add("changed");
        internals.updateStyle();

        println(`subject color: ${getComputedStyle(subject).color}`);
        println(`subject background: ${getComputedStyle(subject).backgroundColor}`);
        println(`leaf color: ${getComputedStyle(leaf).color}`);
    });
</script>