has-slotted-functional-changing-003.tentative.html (2158B)
1 <!DOCTYPE HTML> 2 <html> 3 4 <head> 5 <meta charset="utf-8"> 6 <title>Changing content targetting :has-slotted(...) and :has-slotted through multiple shadow roots</title> 7 <link rel="help" href="https://github.com/w3c/csswg-drafts/pull/10586"> 8 <script src="/resources/testharness.js"></script> 9 <script src="/resources/testharnessreport.js"></script> 10 <script src="/resources/testdriver.js"></script> 11 <script src="/resources/testdriver-vendor.js"></script> 12 <script src="/resources/testdriver-actions.js"></script> 13 </head> 14 15 <body> 16 17 <div id="test"><template shadowrootmode="open"><div id="inner"><template shadowrootmode="open"> 18 <slot></slot> 19 <p id="target">This text will be styled.</p> 20 <style> 21 p { 22 color: rgb(0 255 0); 23 } 24 slot:not(:has-slotted) + p { 25 color: rgb(0 0 255); 26 } 27 slot:not(:has-slotted(div)) + p { 28 color: rgb(255 0 255); 29 } 30 </style> 31 </template><slot></slot></div></template></div> 32 33 34 <script> 35 const blue = 'rgb(0, 0, 255)'; 36 const green = 'rgb(0, 255, 0)'; 37 const fuchsia = 'rgb(255, 0, 255)'; 38 test(function () { 39 const test = document.getElementById('test'); 40 const inner = test.shadowRoot.getElementById('inner'); 41 const target = inner.shadowRoot.getElementById('target'); 42 let styles = getComputedStyle(target); 43 assert_equals(styles.getPropertyValue('color'), green); 44 const node = document.createTextNode(' '); 45 test.replaceChildren(node); 46 styles = getComputedStyle(target); 47 assert_equals(styles.getPropertyValue('color'), blue); 48 node.remove(); 49 styles = getComputedStyle(target); 50 assert_equals(styles.getPropertyValue('color'), green); 51 test.innerHTML = '<div></div>'; 52 styles = getComputedStyle(target); 53 assert_equals(styles.getPropertyValue('color'), fuchsia); 54 test.appendChild(node); 55 styles = getComputedStyle(target); 56 assert_equals(styles.getPropertyValue('color'), blue); 57 test.textContent = ''; 58 styles = getComputedStyle(target); 59 assert_equals(styles.getPropertyValue('color'), green); 60 }); 61 </script> 62 </body> 63 64 </html>