Truly independent web browser
Tests/LibWeb: Add a test for replacing an abspos box's contents
Andreas Klingf2d181e2376d
diff --git a/Tests/LibWeb/Text/expected/Layout/abspos-box-lays-out-alone-after-replacing-its-contents.txt b/Tests/LibWeb/Text/expected/Layout/abspos-box-lays-out-alone-after-replacing-its-contents.txtnew file mode 100644index 00000000000..5f28b618808--- /dev/null+++ b/Tests/LibWeb/Text/expected/Layout/abspos-box-lays-out-alone-after-replacing-its-contents.txt@@ -0,0 +1,3 @@+textContent: layout FULL, the box grew: true+innerHTML: layout FULL, the box grew: true+shadow root innerHTML: layout FULL, the box grew: truediff --git a/Tests/LibWeb/Text/input/Layout/abspos-box-lays-out-alone-after-replacing-its-contents.html b/Tests/LibWeb/Text/input/Layout/abspos-box-lays-out-alone-after-replacing-its-contents.htmlnew file mode 100644index 00000000000..0860e869d99--- /dev/null+++ b/Tests/LibWeb/Text/input/Layout/abspos-box-lays-out-alone-after-replacing-its-contents.html@@ -0,0 +1,30 @@+<!DOCTYPE html>+<script src="../include.js"></script>+<style>+ body { margin: 0; }+ .host { position: relative; display: inline-block; overflow: hidden; }+ .measure { position: absolute; left: 0; top: 0; font: 20px/20px monospace; white-space: nowrap; }+</style>+<div><span class="host">visible<span class="measure" id="text"></span></span></div>+<div><span class="host">visible<span class="measure" id="markup"></span></span></div>+<div id="shadow-host" class="measure" style="top: 100px"></div>+<script>+ // Replacing all the contents of an absolutely positioned box changes nothing around it, so the box lays out alone.+ test(() => {+ const shadowRoot = document.getElementById("shadow-host").attachShadow({ mode: "open" });+ const cases = [+ ["textContent", document.getElementById("text"), (target, text) => { target.textContent = text; }],+ ["innerHTML", document.getElementById("markup"), (target, text) => { target.innerHTML = `<b>${text}</b>`; }],+ ["shadow root innerHTML", document.getElementById("shadow-host"), (target, text) => { shadowRoot.innerHTML = `<b>${text}</b>`; }],+ ];+ for (const [name, target, replace] of cases) {+ replace(target, "ab");+ const widthBefore = target.offsetWidth;+ internals.beginLayoutTrace();+ replace(target, "abcde");+ const widthAfter = target.offsetWidth;+ const pass = internals.takeLayoutTrace().split("\n")[0].replace(/ BlockContainer.*/, "");+ println(`${name}: ${pass}, the box grew: ${widthBefore > 0 && widthAfter > widthBefore}`);+ }+ });+</script>