Truly independent web browser
<!doctype html>
<script src="../include.js"></script>
<script src="../work-test.js"></script>
<style>
.parent { width: 200px; position: relative; }
.block { height: 10px; }
svg { width: 30px; height: 20px; }
</style>
<div id="fixture"></div>
<script>
test(() => {
const results = [];
for (const [display, children] of [["block", "mixed"], ["block", "inline"], ["inline-block", "inline"], ["flex", "mixed"], ["grid", "mixed"]]) {
for (const insertion of ["append", "middle", "prepend"]) {
for (const style of ["display: block", "display: inline", "position: absolute", "float: left"]) {
fixture.innerHTML = '<div class="parent">text<div class="block"></div><span>inline</span></div>';
const parent = fixture.firstElementChild;
if (children === "inline")
parent.querySelector(".block").remove();
parent.style.display = display;
const tracked = [parent, ...parent.children];
tracked.forEach((element, index) => (element.id = `tracked-${index}`));
const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
svg.style.cssText = style;
svg.innerHTML = '<rect width="10" height="10"/><foreignObject x="10" width="20" height="20"><div xmlns="http://www.w3.org/1999/xhtml">text</div></foreignObject>';
const work = layoutTreeBuildWork(() => {
if (insertion === "middle")
parent.insertBefore(svg, parent.lastElementChild);
else if (insertion === "prepend")
parent.prepend(svg);
else
parent.append(svg);
}, { tracked });
const preserved = work.transitions().every(transition => transition === "PRESERVED");
const geometry = () => [...tracked, svg].map(element => {
const rect = element.getBoundingClientRect();
return [rect.x, rect.y, rect.width, rect.height];
});
const incrementalGeometry = JSON.stringify(geometry());
const comparison = internals.compareLayoutTreeWithFullRebuild();
results.push(`${display} ${children}, ${insertion}, ${style}: boxes preserved=${preserved}, tree matches=${comparison.matches}, geometry matches=${JSON.stringify(geometry()) === incrementalGeometry}`);
}
}
}
for (const result of results)
println(result);
});
</script>