Skip to content

Truly independent web browser

2.2 KB
Raw Blame
<!DOCTYPE html>
<script src="include.js"></script>
<style>
    body {
        font: 16px/20px SerenitySans;
    }
</style>
<!-- After each change that moves or rewraps text without touching the text node or its parent's style, the text's
     geometry reflects it: a narrower container, earlier text on the same line growing, and content above it growing. -->
<div id="root">
    <div id="above">above</div>
    <div id="container" style="width: 400px">
        <p><span id="first">short</span> <span>the text that follows it on the same line, long enough to wrap</span></p>
    </div>
</div>
<script>
    test(() => {
        internals.setAccessibilityInterested();
        const root = document.getElementById("root");
        // Printing adds to the DOM, so the output waits until the last step: Otherwise, each step's change would include
        // the previous step's output.
        const output = [];
        const step = (label, change) => {
            change();
            // The change tracker comes first, so that it builds the tree the way publishing does: before anything else
            // keeps what changed.
            const tracking = internals.accessibilityChangeTrackingMismatches();
            const changeSize = internals.accessibilityLastChangeSize();
            const dump = internals.dumpAccessibilityNodeData(root);
            const stale = internals.accessibilityCachedTextMismatches() + internals.accessibilityCachedRecordMismatches() + internals.accessibilityCachedGeometryMismatches() + tracking;
            output.push(`== ${label} (${changeSize})`, dump);
            if (stale)
                output.push(`stale cached data:\n${stale}`);
        };

        step("initial", () => {});
        step("unchanged", () => {});
        step("container narrowed", () => document.getElementById("container").style.width = "250px");
        step("earlier text on the line grew", () => document.getElementById("first").firstChild.data = "much longer than before");
        step("content above grew", () => document.getElementById("above").append(document.createElement("br"), "and more"));
        for (const line of output)
            println(line);
    });
</script>