Tests: Add getElementById mutation and shadow-root routing tests

Add focused coverage for the ElementByIdMap that is easy to regress
while optimizing lookup paths.

The dynamic mutations test verifies duplicate id tree order semantics
remain correct after reordering, id changes, removals, and
reintroduction.

The shadow root routing test verifies lookups stay routed to the correct
scope when an element with an id is removed and moved across shadow
roots and into the document.
This commit is contained in:
Aliaksandr Kalenik
2026-02-21 12:38:45 +01:00
committed by Andreas Kling
parent 7cc973fa77
commit a0768e9bac
Notes: github-actions[bot] 2026-02-21 12:56:57 +00:00
4 changed files with 67 additions and 0 deletions

View File

@@ -0,0 +1,32 @@
<!DOCTYPE html>
<script src="../include.js"></script>
<script>
test(() => {
let host1 = document.createElement("div");
let host2 = document.createElement("div");
document.body.append(host1, host2);
let shadow1 = host1.attachShadow({ mode: "open" });
let shadow2 = host2.attachShadow({ mode: "open" });
let node = document.createElement("span");
node.id = "foo";
shadow1.append(node);
shadow1.getElementById("foo");
println(`shadow1 has foo initially: ${shadow1.getElementById("foo") === node}`);
node.remove();
println(`shadow1 has foo after remove: ${shadow1.getElementById("foo") === null}`);
shadow2.append(node);
println(`shadow1 has foo after move: ${shadow1.getElementById("foo") === null}`);
println(`shadow2 has foo after move: ${shadow2.getElementById("foo") === node}`);
println(`document has foo while in shadow: ${document.getElementById("foo") === null}`);
document.body.append(node);
println(`shadow2 has foo after moving to document: ${shadow2.getElementById("foo") === null}`);
println(`document has foo after move: ${document.getElementById("foo") === node}`);
});
</script>