Range-in-shadow-after-the-shadow-removed.html (1763B)
1 <!doctype html> 2 <html> 3 <head> 4 <meta charset="utf-8"> 5 <meta name="variant" content="?mode=closed"> 6 <meta name="variant" content="?mode=open"> 7 <title>Range in shadow after removing the shadow</title> 8 <script src=/resources/testharness.js></script> 9 <script src=/resources/testharnessreport.js></script> 10 <script> 11 "use strict"; 12 13 addEventListener("load", () => { 14 const mode = (new URLSearchParams(document.location.search)).get("mode"); 15 test(() => { 16 const host = document.createElement("div"); 17 host.id = "host"; 18 const root = host.attachShadow({mode}); 19 root.innerHTML = '<div id="in-shadow">ABC</div>'; 20 document.body.appendChild(host); 21 const range = document.createRange(); 22 range.setStart(root.firstChild, 1); 23 host.remove(); 24 assert_equals(range.startContainer, root.firstChild, "startContainer should not be changed"); 25 assert_equals(range.startOffset, 1, "startOffset should not be changed"); 26 }, "Range in shadow should stay in the shadow after the host is removed"); 27 28 test(() => { 29 const wrapper = document.createElement("div"); 30 wrapper.id = "wrapper"; 31 const host = document.createElement("div"); 32 host.id = "host"; 33 const root = host.attachShadow({mode}); 34 root.innerHTML = '<div id="in-shadow">ABC</div>'; 35 wrapper.appendChild(host); 36 document.body.appendChild(wrapper); 37 const range = document.createRange(); 38 range.setStart(root.firstChild, 1); 39 wrapper.remove(); 40 assert_equals(range.startContainer, root.firstChild, "startContainer should not be changed"); 41 assert_equals(range.startOffset, 1, "startOffset should not be changed"); 42 }, "Range in shadow should stay in the shadow after the host parent is removed"); 43 }, {once: true}); 44 </script> 45 </head> 46 <body></body> 47 </html>