Truly independent web browser
<!DOCTYPE html>
<script src="../include.js"></script>
<script src="../work-test.js"></script>
<iframe srcdoc="<script>internals.beginStyleTrace()</script><p>x</p>"></iframe>
<script>
// Have the style engine own this document, which builds its rule index before the frame's.
internals.updateStyle();
asyncTest(done => {
const iframe = document.querySelector("iframe");
iframe.onload = () => {
// This document was styled first, so the user-agent selectors were compiled and indexed for it. The frame's
// rule index shares the user-agent rule index this document built, which needs no selector compiled again.
const frameInternals = iframe.contentWindow.internals;
const p = iframe.contentDocument.querySelector("p");
println(`margin-top from the user-agent sheet: ${iframe.contentWindow.getComputedStyle(p).marginTop}`);
frameInternals.updateStyle();
const program = parseStyleTrace(frameInternals.takeStyleTrace()).filter(event => event.event === "program");
println(`what the frame did to its rules: [${program.map(event => (event.times > 1 ? `${event.name} x${event.times}` : event.name)).join(", ")}]`);
// A rule the frame adds compiles its own selectors, and only those.
const added = styleWork(() => {
const style = iframe.contentDocument.createElement("style");
style.textContent = ".compiled-once-per-process-a, .compiled-once-per-process-b > p { color: green; }";
iframe.contentDocument.head.appendChild(style);
}, frameInternals);
println(`what the added rule did to the rule index: [${added.program().filter(event => /^(rule index|user agent rule index|selectors)/.test(event)).join(", ")}]`);
done();
};
});
</script>