test-001.html (2229B)
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <title>Shadow DOM Test: A_07_01_01</title> 5 <link rel="author" title="Sergey G. Grekhov" href="mailto:sgrekhov@unipro.ru"> 6 <link rel="help" href="http://www.w3.org/TR/2013/WD-shadow-dom-20130514/#ranges-and-selection"> 7 <meta name="assert" content="User Interaction: Selection, returned by the window.getSelection() method must never return a selection within a shadow tree"> 8 <script src="/resources/testharness.js"></script> 9 <script src="/resources/testharnessreport.js"></script> 10 <script src="../../../../html/resources/common.js"></script> 11 <script src="../../../resources/shadow-dom-utils.js"></script> 12 </head> 13 <body> 14 <div id="log"></div> 15 <script> 16 test(unit(function (ctx) { 17 var d = newRenderedHTMLDocument(ctx); 18 19 var host = d.createElement('div'); 20 d.body.appendChild(host); 21 var s = host.attachShadow({mode: 'open'}); 22 23 var span = d.createElement('span'); 24 span.innerHTML = 'Some text'; 25 s.appendChild(span); 26 27 var range = d.createRange(); 28 range.setStart(span.firstChild, 0); 29 range.setEnd(span.firstChild, 3); 30 31 var selection = window.getSelection(); 32 selection.removeAllRanges(); 33 selection.addRange(range); 34 35 var sl = window.getSelection(); 36 assert_equals(sl.toString(), '', 'window.getSelection() method must never return a selection ' + 37 'within a shadow tree'); 38 39 }), 'A_07_07_01_T01'); 40 41 42 // test distributed nodes 43 test(unit(function (ctx) { 44 var d = newRenderedHTMLDocument(ctx); 45 46 var host = d.createElement('div'); 47 d.body.appendChild(host); 48 49 var span = d.createElement('span'); 50 span.innerHTML = 'Some text'; 51 span.setAttribute('slot', 'span'); 52 host.appendChild(span); 53 54 var s = host.attachShadow({mode: 'open'}); 55 s.innerHTML = '<slot name="span"></slot>'; 56 57 var range = d.createRange(); 58 range.setStart(span.firstChild, 0); 59 range.setEnd(span.firstChild, 3); 60 61 var selection = window.getSelection(); 62 selection.removeAllRanges(); 63 selection.addRange(range); 64 65 var sl = window.getSelection(); 66 assert_equals(sl.toString(), '', 'window.getSelection() method must never return a selection ' + 67 'within a shadow tree'); 68 69 }), 'A_07_07_01_T02'); 70 </script> 71 </body> 72 </html>