Skip to content

Truly independent web browser

LibWeb: Test inertness of elements moved with moveBefore()

Andreas Kling86c9b2ff5942
diff --git a/Tests/LibWeb/Text/expected/HTML/inert-follows-move-before.txt b/Tests/LibWeb/Text/expected/HTML/inert-follows-move-before.txt
new file mode 100644
index 00000000000..eb71e88f290
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/HTML/inert-follows-move-before.txt
@@ -0,0 +1,10 @@
+in an inert element: read-write false, focusable false
+moved into an editing host: read-write false, focusable false
+moved into an inert editing host: read-write false, focusable false
+moved out: read-write false, focusable false
+moved from an inert element into the shadow tree of an inert host: read-write false
+moved into the shadow tree of an inert host: read-write true
+inserted into the shadow tree of an inert host: read-write true
+inserted into the shadow tree of a host: read-write true
+host made inert: read-write true
+host no longer inert: read-write true
diff --git a/Tests/LibWeb/Text/input/HTML/inert-follows-move-before.html b/Tests/LibWeb/Text/input/HTML/inert-follows-move-before.html
new file mode 100644
index 00000000000..d990d7f0972
--- /dev/null
+++ b/Tests/LibWeb/Text/input/HTML/inert-follows-move-before.html
@@ -0,0 +1,54 @@
+<!DOCTYPE html>
+<script src="../include.js"></script>
+<div id="inert" inert><span id="span"></span><button id="button"></button></div>
+<div id="editor" contenteditable=""></div>
+<div id="inert-editor" inert contenteditable=""></div>
+<div id="plain"></div>
+<div id="inert-shadow-parent" inert><div id="from-inert" contenteditable=""><span></span></div></div>
+<div id="from-plain" contenteditable=""><span></span></div>
+<div id="inert-host" inert></div>
+<div id="host"></div>
+<script>
+ test(() => {
+ const report = label => {
+ button.focus();
+ println(`${label}: read-write ${span.matches(":read-write")}, focusable ${document.activeElement === button}`);
+ button.blur();
+ };
+ const moveTo = parent => {
+ parent.moveBefore(span, null);
+ parent.moveBefore(button, null);
+ };
+
+ report("in an inert element");
+ moveTo(editor);
+ report("moved into an editing host");
+ moveTo(document.getElementById("inert-editor"));
+ report("moved into an inert editing host");
+ moveTo(plain);
+ report("moved out");
+
+ const readWrite = (label, editor) => println(`${label}: read-write ${editor.firstChild.matches(":read-write")}`);
+ const shadowRoot = document.getElementById("inert-host").attachShadow({ mode: "open" });
+ const fromInert = document.getElementById("from-inert");
+ const fromPlain = document.getElementById("from-plain");
+ shadowRoot.moveBefore(fromInert, null);
+ readWrite("moved from an inert element into the shadow tree of an inert host", fromInert);
+ shadowRoot.moveBefore(fromPlain, null);
+ readWrite("moved into the shadow tree of an inert host", fromPlain);
+
+ const inserted = document.createElement("div");
+ inserted.setAttribute("contenteditable", "");
+ inserted.append(document.createElement("span"));
+ shadowRoot.append(inserted);
+ readWrite("inserted into the shadow tree of an inert host", inserted);
+
+ const host = document.getElementById("host");
+ host.attachShadow({ mode: "open" }).append(inserted);
+ readWrite("inserted into the shadow tree of a host", inserted);
+ host.setAttribute("inert", "");
+ readWrite("host made inert", inserted);
+ host.removeAttribute("inert");
+ readWrite("host no longer inert", inserted);
+ });
+</script>