has-slotted-functional-changing-001.tentative.html (2057B)
1 <!DOCTYPE HTML> 2 <html> 3 4 <head> 5 <meta charset="utf-8"> 6 <title>Changing content targetting :has-slotted(...) and :has-slotted through a single shadow root</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"> 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></div> 32 33 <script> 34 const blue = 'rgb(0, 0, 255)'; 35 const green = 'rgb(0, 255, 0)'; 36 const fuchsia = 'rgb(255, 0, 255)'; 37 test(function () { 38 const test = document.getElementById('test'); 39 const target = test.shadowRoot.getElementById('target'); 40 let styles = getComputedStyle(target); 41 assert_equals(styles.getPropertyValue('color'), green); 42 test.innerHTML = ' '; 43 styles = getComputedStyle(target); 44 assert_equals(styles.getPropertyValue('color'), blue); 45 test.replaceChildren();; 46 styles = getComputedStyle(target); 47 assert_equals(styles.getPropertyValue('color'), green); 48 const div = document.createElement('div'); 49 test.append(div); 50 styles = getComputedStyle(target); 51 assert_equals(styles.getPropertyValue('color'), fuchsia); 52 const node = document.createTextNode(' '); 53 test.replaceChildren(node); 54 styles = getComputedStyle(target); 55 assert_equals(styles.getPropertyValue('color'), blue); 56 test.innerHTML = ''; 57 styles = getComputedStyle(target); 58 assert_equals(styles.getPropertyValue('color'), green); 59 }); 60 </script> 61 </body> 62 63 </html>