Skip to content

Truly independent web browser

2.1 KB
Raw Blame
<!DOCTYPE html>
<script src="include.js"></script>
<style>
    iframe { width: 300px; height: 100px; }
</style>

<script>
    asyncTest(async done => {
        const frame = document.createElement("iframe");
        const loaded = new Promise(resolve => frame.onload = resolve);
        frame.srcdoc = `
    <style>
        @media (max-width: 100px) { #narrow-hidden { display: none; } }
    </style>
    <input id='a'><input id='b'><input id='narrow-hidden'>
    <span id='label'>label</span>
`;
        document.body.appendChild(frame);
        await loaded;
        const frameDocument = frame.contentDocument;
        const label = frameDocument.getElementById("label");

        // Focusing an element in a frame brings the style of its embedding document up to date first. When that
        // document has nothing pending, it starts no style update of its own.
        document.body.offsetWidth;
        const styleUpdatesOfFocus = [];
        for (let i = 0; i < 10; ++i) {
            label.textContent = `label ${i}`;
            internals.beginRenderingTrace();
            frameDocument.getElementById(i % 2 ? "a" : "b").focus();
            const updates = internals.takeRenderingTrace().split("\n").filter(line => /^(style stabilization epoch|provisional style pass)/.test(line));
            styleUpdatesOfFocus.push(`[${updates.join(", ")}]`);
        }
        println(`style updates of the focus entering the frame: ${styleUpdatesOfFocus[0]}`);
        println(`style updates of later focuses: ${[...new Set(styleUpdatesOfFocus.slice(1))].join(" or ")}`);
        println(`focused: ${frameDocument.activeElement.id}`);

        // An embedding document that has changed the frame's size is brought up to date, so the frame's media queries
        // see the new viewport.
        frame.style.width = "50px";
        frameDocument.getElementById("narrow-hidden").focus();
        println(`focused after narrowing: ${frameDocument.activeElement.id}`);

        frame.style.width = "300px";
        frameDocument.getElementById("narrow-hidden").focus();
        println(`focused after widening: ${frameDocument.activeElement.id}`);
        done();
    });
</script>