imperative-slot-fallback-clear.html (1480B)
1 <!DOCTYPE html> 2 <title>Imperative Slot API: fallback should be cleared after slot assignment</title> 3 <link rel="author" href="mailto:xiaochengh@chromium.org"> 4 <link rel="help" href="https://bugs.chromium.org/p/chromium/issues/detail?id=1292292"> 5 <script src="/resources/testharness.js"></script> 6 <script src="/resources/testharnessreport.js"></script> 7 8 <div> 9 <div id="host1"><span></span></div> 10 <div id="host2"><span></span></div> 11 </div> 12 13 <script> 14 test(() => { 15 const host = document.getElementById('host1'); 16 const shadow = host.attachShadow({mode: 'open', slotAssignment: 'manual'}); 17 shadow.innerHTML = '<slot>fallback</slot>'; 18 host.offsetHeight; // Force layout 19 const slot = shadow.firstChild; 20 slot.assign(host.firstChild); 21 assert_array_equals(slot.assignedNodes(), [host.firstChild]); 22 assert_equals(host.offsetHeight, 0, 'Fallback content should not be rendered'); 23 }, 'Text node fallback should be cleared in a subsequently layout'); 24 25 test(() => { 26 const host = document.getElementById('host2'); 27 const shadow = host.attachShadow({mode: 'open', slotAssignment: 'manual'}); 28 shadow.innerHTML = '<slot><span>fallback</span></slot>'; 29 host.offsetHeight; // Force layout 30 const slot = shadow.firstChild; 31 slot.assign(host.firstChild); 32 assert_array_equals(slot.assignedNodes(), [host.firstChild]); 33 assert_equals(host.offsetHeight, 0, 'Fallback content should not be rendered'); 34 }, 'Element fallback should be cleared in a subsequent layout'); 35 </script>