Truly independent web browser
<!DOCTYPE html>
<script src="../../include.js"></script>
<script src="../../work-test.js"></script>
<script src="plan.js"></script>
<style>
.item { color: green }
</style>
<style>
#reader { height: var(--vh) }
</style>
<div id="guard">
<span id="item" class="item"></span>
<span id="sibling" class="item"></span>
</div>
<table id="table"><tr><td id="cell">x</td></tr></table>
<svg id="svg"><circle id="circle" cx="5" cy="5" r="4"></circle></svg>
<div id="reader"></div>
<script>
test(() => {
const item = document.getElementById("item");
// A declaration sourced from the element changes what wins on that element and nothing
// else. There is no selector to transpose, so the region is the element itself, however
// many rules the document has.
plan("gain an inline style", () => item.setAttribute("style", "color: red"));
plan("edit that inline style", () => item.style.color = "blue");
plan("add a property through the CSSOM", () => item.style.fontWeight = "bold");
plan("lose the inline style", () => item.removeAttribute("style"));
// A presentational hint is a declaration too, and reaches only its element.
plan("gain a presentational hint", () => document.getElementById("table").setAttribute("bgcolor", "red"));
plan("lose it", () => document.getElementById("table").removeAttribute("bgcolor"));
// An SVG presentation attribute is a third kind of element-sourced declaration, with its own
// cascade placement and the same reach: the element it is written on.
const circle = document.getElementById("circle");
plan("gain an SVG presentation attribute", () => circle.setAttribute("fill", "red"));
plan("change it", () => circle.setAttribute("fill", "blue"));
plan("lose it", () => circle.removeAttribute("fill"));
// Removing one property of an inline block is the same input as replacing the block.
plan("remove one inline property through the CSSOM", () => {
item.style.color = "red";
item.style.removeProperty("color");
});
// An empty declaration block is still a declaration change. Empty vectors cross the FFI
// boundary with null data pointers, so the property count carries their meaning.
plan("remove the last property from a stylesheet rule", () =>
document.styleSheets[0].cssRules[0].style.removeProperty("color"));
// Writing the same declarations again moves nothing, so nothing is restyled.
item.setAttribute("style", "color: red");
const rewrite = styleWork(() => item.setAttribute("style", "color: red"));
println(`rewrite the same inline style: [${rewrite.restyled().map(shortStyleName).join(", ")}]`);
const root = document.documentElement;
root.style.setProperty("--vh", "9px");
plan("set a root custom property to the value it has", () => root.style.setProperty("--vh", "9px"));
const moved = styleWork(() => root.style.setProperty("--vh", "10px"));
println(`move a root custom property one element reads: computed [${moved.restyled().map(shortStyleName).join(", ")}]`);
println(` reader height: ${getComputedStyle(document.getElementById("reader")).height}`);
});
</script>