Skip to content

Commit

Permalink
Bug 1950487 [wpt PR 50945] - DOM: Add slotchange test for moveBefore(…
Browse files Browse the repository at this point in the history
…), a=testonly

Automatic update from web-platform-tests
DOM: Add slotchange test for moveBefore()

This CL adds a test to ensure that the 'slotchange' event is fired when
slots themselves are moved in and out of a custom element, and their
assigned nodes change.

This addresses
whatwg/dom#1307 (comment).

R=nrosenthal

Bug: 40150299
Change-Id: I93ee04294e5ab3e6d9f75c48705cdc77ce0a1df3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6298941
Commit-Queue: Dominic Farolino <domchromium.org>
Reviewed-by: Noam Rosenthal <nrosenthalchromium.org>
Cr-Commit-Position: refs/heads/main{#1424746}

--

wpt-commits: cd2cfbab2d2157b1c409be1631ff7e42c3ae7f6f
wpt-pr: 50945

UltraBlame original commit: 4a6a1072a3e50a2172f5d712305e8a77f170e452
  • Loading branch information
marco-c committed Mar 1, 2025
1 parent 18fd623 commit 470bf75
Showing 1 changed file with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,37 @@
await slotChangePromise;
}
}, "Moving a slottable into and out out of a custom element fires 'slotchange' event");

promise_test(async t => {
const customElement = document.body.appendChild(document.createElement('custom-element'));
const slot = customElement.shadowRoot.children[0];
t.add_cleanup(() => customElement.remove());

const p = document.createElement('p');
p.slot = 'content';
p.textContent = 'The content';
customElement.appendChild(p);

// See the above tests that do the same thing, for implementations that do not fire `slotchange`
// at this phase.
await new Promise(resolve => t.step_timeout(() => resolve()));

assert_array_equals(slot.assignedNodes(), [p]);
document.body.moveBefore(slot, null);

await new Promise((resolve, reject) => {
slot.addEventListener('slotchange', e => resolve(), {once: true});
t.step_timeout(() => reject('Timeout; slotchange was not fired2'), 1500);
});

assert_array_equals(slot.assignedNodes(), []);
customElement.shadowRoot.moveBefore(slot, null);

await new Promise((resolve, reject) => {
slot.addEventListener('slotchange', e => resolve(), {once: true});
t.step_timeout(() => reject('Timeout; slotchange was not fired3'), 1500);
});

assert_array_equals(slot.assignedNodes(), [p]);
}, "Moving a slot runs the assign slottables algorithm");
</script>

0 comments on commit 470bf75

Please # to comment.