Skip to content

Truly independent web browser

LibWeb: Test inline style held by a declaration block

Andreas Kling8d4a8dc9b738
diff --git a/Tests/LibWeb/Text/expected/css/style-engine/inline-style-held-by-block.txt b/Tests/LibWeb/Text/expected/css/style-engine/inline-style-held-by-block.txt
new file mode 100644
index 00000000000..b3b804578ef
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/css/style-engine/inline-style-held-by-block.txt
@@ -0,0 +1,17 @@
+same text: 11px 11px
+one edited: 12px 11px
+written back: 11px 11px
+one removed: 11px 784px
+custom: 21px
+custom rewritten: 22px
+custom gone: 23px []
+custom back: 24px
+custom removed: []
+round 0: 31px
+round 1: 784px
+round 2: 784px
+in: 41px
+back: 42px
+attr: 51px
+attr moved: 52px
+transitions: 1
diff --git a/Tests/LibWeb/Text/input/css/style-engine/inline-style-held-by-block.html b/Tests/LibWeb/Text/input/css/style-engine/inline-style-held-by-block.html
new file mode 100644
index 00000000000..223ebcec606
--- /dev/null
+++ b/Tests/LibWeb/Text/input/css/style-engine/inline-style-held-by-block.html
@@ -0,0 +1,78 @@
+<!DOCTYPE html>
+<script src="../../include.js"></script>
+<div id="host"></div>
+<script>
+ function add(style) {
+ const element = document.createElement("div");
+ if (style !== undefined)
+ element.setAttribute("style", style);
+ host.appendChild(element);
+ return element;
+ }
+
+ function width(element) {
+ return getComputedStyle(element).width;
+ }
+
+ test(() => {
+ // Elements writing the same text hold one block, which an edit through the CSSOM leaves to the other.
+ const first = add("width: 11px");
+ const second = add("width: 11px");
+ println(`same text: ${width(first)} ${width(second)}`);
+ first.style.width = "12px";
+ println(`one edited: ${width(first)} ${width(second)}`);
+ first.setAttribute("style", "width: 11px");
+ println(`written back: ${width(first)} ${width(second)}`);
+ second.removeAttribute("style");
+ println(`one removed: ${width(first)} ${width(second)}`);
+ host.textContent = "";
+
+ // The custom properties of a block come and go with it.
+ const custom = add("--size: 21px; width: var(--size)");
+ println(`custom: ${width(custom)}`);
+ custom.setAttribute("style", "--size: 22px; width: var(--size)");
+ println(`custom rewritten: ${width(custom)}`);
+ custom.setAttribute("style", "width: var(--size, 23px)");
+ println(`custom gone: ${width(custom)} [${getComputedStyle(custom).getPropertyValue("--size")}]`);
+ custom.setAttribute("style", "--size: 24px; width: var(--size)");
+ println(`custom back: ${width(custom)}`);
+ custom.removeAttribute("style");
+ println(`custom removed: [${getComputedStyle(custom).getPropertyValue("--size")}]`);
+ host.textContent = "";
+
+ // A new element that takes the identity of one that left holds none of its declarations.
+ for (let round = 0; round < 3; ++round) {
+ const held = add(round == 0 ? "width: 31px" : undefined);
+ println(`round ${round}: ${width(held)}`);
+ held.remove();
+ width(host);
+ }
+
+ // An element holds a block through leaving the tree and coming back.
+ const moved = add("width: 41px");
+ println(`in: ${width(moved)}`);
+ moved.remove();
+ width(host);
+ moved.style.width = "42px";
+ host.appendChild(moved);
+ println(`back: ${width(moved)}`);
+ host.textContent = "";
+
+ // What a block reads of its element is noted as it is handed over.
+ const reading = add("width: attr(data-width px)");
+ reading.setAttribute("data-width", "51");
+ println(`attr: ${width(reading)}`);
+ reading.setAttribute("data-width", "52");
+ println(`attr moved: ${width(reading)}`);
+ host.textContent = "";
+
+ // Whether a block can define a transition is said as it is handed over.
+ const transitioning = add("width: 61px");
+ width(transitioning);
+ transitioning.setAttribute("style", "width: 62px; transition: width 100s");
+ width(transitioning);
+ transitioning.setAttribute("style", "width: 63px; transition: width 100s");
+ println(`transitions: ${transitioning.getAnimations().length}`);
+ transitioning.remove();
+ });
+</script>