Files
ladybird/Tests/LibWeb/Text/input/DOM/getElementById-dynamic-mutations.html
Aliaksandr Kalenik a0768e9bac 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.
2026-02-21 13:56:00 +01:00

24 lines
745 B
HTML

<!DOCTYPE html>
<script src="../include.js"></script>
<div id="foo" data-name="first"></div>
<div id="foo" data-name="second"></div>
<script>
test(() => {
let [first, second] = document.querySelectorAll("[id='foo']");
println(`initial: ${document.getElementById("foo").dataset.name}`);
document.body.insertBefore(second, first);
println(`after reorder: ${document.getElementById("foo").dataset.name}`);
first.id = "bar";
println(`after first id change: ${document.getElementById("foo").dataset.name}`);
second.remove();
println(`after removing second: ${document.getElementById("foo")}`);
first.id = "foo";
println(`after restoring first: ${document.getElementById("foo") === first}`);
});
</script>