selection.html (1981B)
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta name='author' title='weizman' href='https://www.weizmangal.com'> 5 <meta name='assert' content='Shadow DOM should not leak via Selection API'> 6 <link rel='help' href='https://w3c.github.io/webcomponents/spec/shadow/'> 7 <script src='/resources/testharness.js'></script> 8 <script src='/resources/testharnessreport.js'></script> 9 <script src="/resources/testdriver.js"></script> 10 <script src="/resources/testdriver-actions.js"></script> 11 <script src="/resources/testdriver-vendor.js"></script> 12 </head> 13 <body> 14 <div id='log'></div> 15 <div id='container'></div> 16 </body> 17 <script> 18 'use strict'; 19 20 const container = document.getElementById('container'); 21 22 function reset(text) { 23 const host = container.appendChild(document.createElement('div')); 24 const shadow = host.attachShadow({mode: 'closed'}); 25 const child = shadow.appendChild(document.createElement('span')); 26 child.textContent = text; 27 return host; 28 } 29 30 async function select(t, target) { 31 const event_watcher = new EventWatcher(t, target, ["mouseup"]); 32 const actions_promise = new test_driver.Actions() 33 .pointerMove(0, 0, {origin: target}) 34 .pointerDown() 35 .pointerMove(100, 0, {origin: target}) 36 .pointerUp() 37 .send(); 38 t.add_cleanup(() => actions_promise); 39 const event = await event_watcher.wait_for(["mouseup"]); 40 assert_equals(event.type, "mouseup"); 41 assert_equals(event.target, target); 42 } 43 44 promise_test(async (t) => { 45 const text = 'text_inside_shadow'; 46 const host = reset(text); 47 await select(t, host); 48 const node = getSelection().anchorNode; 49 assert_equals(node, container, 'getSelection().anchorNode should return the host of the shadow'); 50 assert_not_equals(node.textContent, text, 'getSelection().anchorNode textContent should not be the text contents of an element inside the shadow root'); 51 }, 'selection API should not leak nodes in Shadow DOM.'); 52 </script> 53 </html>