Skip to content

Commit

Permalink
DOM: Enable moveBefore() inside ShadowRoot DocumentFragments
Browse files Browse the repository at this point in the history
This CL enables moveBefore() inside connected ShadowRoot
DocumentFragments, as the general only-Element-node target parent
pre-condition was too strict, and disabled this case, despite it being
a pretty valid one.

This was discussed in
whatwg/dom#1307 (comment).

[email protected]

Bug: 40150299
Change-Id: Ie9c6e31400b75b2b5d10d095c059012056a440da
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6012161
Commit-Queue: Dominic Farolino <[email protected]>
Reviewed-by: Noam Rosenthal <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1381208}
  • Loading branch information
domfarolino authored and chromium-wpt-export-bot committed Nov 11, 2024
1 parent d675a64 commit ff0b14e
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions dom/nodes/moveBefore/tentative/moveBefore-shadow-root.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!DOCTYPE html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>

<body>
<div id=shadowTarget></div>
</body>

<script>
test(() => {
shadowTarget.attachShadow({mode: 'open'});
const child1 = document.createElement('p');
child1.textContent = 'Child1';
const child2 = document.createElement('p');
child2.textContent = 'Child2';

shadowTarget.shadowRoot.append(child1, child2);
shadowTarget.shadowRoot.moveBefore(child2, child1);
assert_equals(shadowTarget.shadowRoot.firstChild, child2, "Original lastChild is now firstChild");
assert_equals(shadowTarget.shadowRoot.lastChild, child1, "Original firstChild is now lastChild");
}, "moveBefore() is allowed in ShadowRoots (i.e., connected DocumentFragments)");
</script>

0 comments on commit ff0b14e

Please sign in to comment.