tor-browser

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

slotted-nested.html (1640B)


      1 <!doctype html>
      2 <link rel="href" href="https://mozilla.org" title="Mozilla">
      3 <link rel="author" href="mailto:emilio@crisal.io" title="Emilio Cobos Álvarez">
      4 <link rel="help" href="https://drafts.csswg.org/css-scoping/#slotted-pseudo">
      5 <script src="/resources/testharness.js"></script>
      6 <script src="/resources/testharnessreport.js"></script>
      7 <div id="host"><p>This text should be green</p></div>
      8 <script>
      9  let shadow = host.attachShadow({ mode: "open" });
     10  shadow.innerHTML = `
     11    <style>
     12      /* This is not expected to match */
     13      .container ::slotted(p) {
     14        color: red !important;
     15      }
     16 
     17      /* This _is_ expected to match */
     18      #nested ::slotted(p) {
     19        background-color: green;
     20      }
     21    </style>
     22    <div id="nested"><slot></slot></div>
     23  `;
     24 
     25  let nested = shadow.querySelector("#nested").attachShadow({ mode: "open" });
     26  nested.innerHTML = `
     27    <style>
     28      .container ::slotted(p) {
     29        color: green;
     30      }
     31    </style>
     32    <div class="container">
     33      <slot></slot>
     34    </div>
     35  `;
     36 
     37  let p = document.querySelector("p");
     38  test(function() {
     39    assert_equals(getComputedStyle(p).color, "rgb(0, 128, 0)");
     40    assert_equals(getComputedStyle(p).backgroundColor, "rgb(0, 128, 0)");
     41  }, "Slotted matches rules against the slot in the right tree");
     42  test(function() {
     43    nested.querySelector(".container").classList.remove("container");
     44    assert_not_equals(getComputedStyle(p).color, "rgb(0, 128, 0)");
     45 
     46    nested.host.removeAttribute("id");
     47    assert_not_equals(getComputedStyle(p).backgroundColor, "rgb(0, 128, 0)");
     48  }, "Style invalidation works correctly for nested slots");
     49 </script>