Skip to content

Commit 470bf75

Browse files
committed
Bug 1950487 [wpt PR 50945] - DOM: Add slotchange test for moveBefore(), 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
1 parent 18fd623 commit 470bf75

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

testing/web-platform/tests/dom/nodes/moveBefore/tentative/slotchange-events.html

+33
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,37 @@
103103
await slotChangePromise;
104104
}
105105
}, "Moving a slottable into and out out of a custom element fires 'slotchange' event");
106+
107+
promise_test(async t => {
108+
const customElement = document.body.appendChild(document.createElement('custom-element'));
109+
const slot = customElement.shadowRoot.children[0];
110+
t.add_cleanup(() => customElement.remove());
111+
112+
const p = document.createElement('p');
113+
p.slot = 'content';
114+
p.textContent = 'The content';
115+
customElement.appendChild(p);
116+
117+
// See the above tests that do the same thing, for implementations that do not fire `slotchange`
118+
// at this phase.
119+
await new Promise(resolve => t.step_timeout(() => resolve()));
120+
121+
assert_array_equals(slot.assignedNodes(), [p]);
122+
document.body.moveBefore(slot, null);
123+
124+
await new Promise((resolve, reject) => {
125+
slot.addEventListener('slotchange', e => resolve(), {once: true});
126+
t.step_timeout(() => reject('Timeout; slotchange was not fired2'), 1500);
127+
});
128+
129+
assert_array_equals(slot.assignedNodes(), []);
130+
customElement.shadowRoot.moveBefore(slot, null);
131+
132+
await new Promise((resolve, reject) => {
133+
slot.addEventListener('slotchange', e => resolve(), {once: true});
134+
t.step_timeout(() => reject('Timeout; slotchange was not fired3'), 1500);
135+
});
136+
137+
assert_array_equals(slot.assignedNodes(), [p]);
138+
}, "Moving a slot runs the assign slottables algorithm");
106139
</script>

0 commit comments

Comments
 (0)