|
103 | 103 | await slotChangePromise;
|
104 | 104 | }
|
105 | 105 | }, "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"); |
106 | 139 | </script>
|
0 commit comments