tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

is-where-shadow.html (2467B)


      1 <!DOCTYPE html>
      2 <title>:is() inside shadow pseudos</title>
      3 <script src="/resources/testharness.js"></script>
      4 <script src="/resources/testharnessreport.js"></script>
      5 <link rel="help" href="https://drafts.csswg.org/selectors-4/#matches">
      6 <link rel="help" href="https://drafts.csswg.org/css-scoping/#host-selector">
      7 <link rel="help" href="https://drafts.csswg.org/css-scoping/#slotted-pseudo">
      8 <div class="parent1"><div id="host1" class=a><p class=e>::slotted</p></div></div>
      9 <div class="parent2"><div id="host2" class=b><p class=d>::slotted</p></div></div>
     10 <div class="parent3"><div id="host3" class=c><p class=f>::slotted</p></div></div>
     11 </div>
     12 <script>
     13  let shadow1 = host1.attachShadow({ mode: 'open' });
     14  let shadow2 = host2.attachShadow({ mode: 'open' });
     15  let shadow3 = host3.attachShadow({ mode: 'open' });
     16 
     17  const html = `
     18    <style>
     19      * { color: blue; }
     20      :host(:is(.a, .b)) b { color: green; }
     21      :host-context(:is(.parent1, .parent2)) i { color: green; }
     22      ::slotted(:is(.e, .f)) { color: green; }
     23 
     24      /* The following should not match: */
     25      :host(:is(.z)) b { color: red; }
     26      :host(:is(.a + .b)) b { color: red; }
     27      :host-context(:is(.z)) i { color: red; }
     28      :host-context(:is(.parent1 .parent2)) i { color: red; }
     29      ::slotted(:is(.z)) { color: red; }
     30      ::slotted(:is(.a > .b)) { color: red; }
     31    </style>
     32    <b>:host</b>
     33    <i>:host-context</i>
     34    <slot></slot>
     35  `;
     36 
     37  shadow1.innerHTML = html;
     38  shadow2.innerHTML = html;
     39  shadow3.innerHTML = html;
     40 
     41  const getComputedColor = e => getComputedStyle(e).color;
     42  const green = 'rgb(0, 128, 0)';
     43  const blue = 'rgb(0, 0, 255)';
     44 
     45  test(function() {
     46    assert_equals(getComputedColor(shadow1.querySelector('b')), green);
     47    assert_equals(getComputedColor(shadow2.querySelector('b')), green);
     48    assert_equals(getComputedColor(shadow3.querySelector('b')), blue);
     49  }, ':is() inside :host()');
     50 
     51  test(function() {
     52    assert_equals(getComputedColor(shadow1.querySelector('i')), green);
     53    assert_equals(getComputedColor(shadow2.querySelector('i')), green);
     54    assert_equals(getComputedColor(shadow3.querySelector('i')), blue);
     55  }, ':is() inside :host-context()');
     56 
     57  test(function() {
     58    assert_equals(getComputedColor(document.querySelector('.e')), green);
     59    assert_equals(getComputedColor(document.querySelector('.d')), blue);
     60    assert_equals(getComputedColor(document.querySelector('.f')), green);
     61  }, ':is() inside ::slotted()');
     62 </script>