Skip to content

Truly independent web browser

1.8 KB
Raw Blame
<!DOCTYPE html>
<meta charset="utf-8">
<style>
    @keyframes probe { from { opacity: 0.5; } to { opacity: 0.5; } }
</style>
<script src="../../include.js"></script>
<script src="../../work-test.js"></script>
<div id="plainHost"></div>
<div id="sheetHost"></div>
<script>
    test(() => {
        // One shadow tree uses the document's sheets, the other holds one of its own.
        const plainRoot = plainHost.attachShadow({ mode: "open" });
        plainRoot.innerHTML = `<div id="plainReader" class="reader">x</div><div id="plainOther">x</div><div id="plainAnimated" style="animation: probe 1s paused">x</div>`;
        const sheetRoot = sheetHost.attachShadow({ mode: "open" });
        const sheet = new CSSStyleSheet();
        sheet.replaceSync(".other { width: 10px; }");
        sheetRoot.adoptedStyleSheets = [sheet];
        sheetRoot.innerHTML = `<div id="sheetReader" class="reader">x</div><div id="sheetOther" class="other">x</div>`;
        const element = id => plainRoot.getElementById(id) || sheetRoot.getElementById(id);
        const report = (label, work) => {
            println(`${label}: restyled [${work.restyled().map(shortStyleName).join(", ")}]`);
            println(`${label}: readers ${getComputedStyle(element("plainReader")).color} ${getComputedStyle(element("sheetReader")).color}, animated opacity=${getComputedStyle(element("plainAnimated")).opacity}`);
        };

        // A user rule reaches the shadow trees' elements it matches, and its keyframes the
        // animations naming them, while the other elements keep their styles.
        report("with a user style", styleWork(() => internals.setUserStyle(".reader { color: rgb(1, 2, 3); } @keyframes probe { from { opacity: 0.25; } to { opacity: 0.25; } }")));

        report("after the user style", styleWork(() => internals.setUserStyle("")));
    });
</script>