tor-browser

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

CSSStyleSheet-constructable-duplicate.html (3704B)


      1 <!doctype html>
      2 <title>Cascade order of a stylesheet for duplicate sheets.</title>
      3 <link rel="author" title="Emilio Cobos Álvarez" href="mailto:emilio@crisal.io">
      4 <link rel="help" href="https://wicg.github.io/construct-stylesheets/">
      5 <script src = '/resources/testharness.js'></script>
      6 <script src = '/resources/testharnessreport.js'></script>
      7 <div id="target"></div>
      8 <script>
      9 
     10 function attachShadowDiv(host) {
     11  const shadowRoot = host.attachShadow({mode: 'open'});
     12  const shadowDiv = document.createElement("div");
     13  shadowRoot.appendChild(shadowDiv);
     14  return shadowDiv;
     15 }
     16 
     17 function blueSheetsWithIncreasingZIndex(n) {
     18  let sheets = [];
     19  for (let i = 0; i < n; ++i) {
     20    sheets.push(new CSSStyleSheet());
     21    sheets[i].replaceSync("div { z-index: " + i + "; color: blue; }");
     22  }
     23  return sheets;
     24 }
     25 
     26 let sheets = [];
     27 
     28 test(function() {
     29  sheets = blueSheetsWithIncreasingZIndex(2);
     30 
     31  document.adoptedStyleSheets = [sheets[1], sheets[0], sheets[1]];
     32  assert_equals(getComputedStyle(document.querySelector("div")).zIndex, "1", "duplicate stylesheet should take right position in the cascade");
     33 
     34  document.adoptedStyleSheets = [];
     35 }, "Duplicate stylesheets have the right cascade position in the Document");
     36 
     37 test(function() {
     38  sheets = blueSheetsWithIncreasingZIndex(2);
     39 
     40  const sheet = new CSSStyleSheet();
     41  sheet.replaceSync("div { color: red; }");
     42 
     43  document.adoptedStyleSheets = [sheets[1], sheets[0]];
     44  assert_equals(getComputedStyle(document.querySelector("div")).zIndex, "0", "backmost stylesheet should take precedence");
     45  assert_equals(getComputedStyle(document.querySelector("div")).color, "rgb(0, 0, 255)", "backmost stylesheet should take precedence");
     46 
     47  document.adoptedStyleSheets = [sheets[1], sheets[0], sheets[1], sheet];
     48  assert_equals(getComputedStyle(document.querySelector("div")).zIndex, "1", "duplicate stylesheet should take the right position in the cascade");
     49  assert_equals(getComputedStyle(document.querySelector("div")).color, "rgb(255, 0, 0)", "backmost stylesheet should take precedence");
     50 
     51  document.adoptedStyleSheets = [];
     52 }, "Appending duplicate stylesheets yields the correct cascade position in the Document");
     53 
     54 test(function() {
     55  sheets = blueSheetsWithIncreasingZIndex(2);
     56 
     57  const span = document.createElement("span");
     58  target.appendChild(span);
     59  attachShadowDiv(span);
     60 
     61  span.shadowRoot.adoptedStyleSheets = [sheets[1], sheets[0], sheets[1]];
     62  assert_equals(getComputedStyle(span.shadowRoot.querySelector("div")).zIndex, "1", "duplicate stylesheet should take right position in the cascade");
     63 }, "Duplicate stylesheets have the right cascade position in the ShadowRoot");
     64 
     65 test(function() {
     66  sheets = blueSheetsWithIncreasingZIndex(2);
     67 
     68  const sheet = new CSSStyleSheet();
     69  sheet.replaceSync("div { color: red; }");
     70 
     71  const span = document.createElement("span");
     72  target.appendChild(span);
     73  attachShadowDiv(span);
     74 
     75  span.shadowRoot.adoptedStyleSheets = [sheets[1], sheets[0]];
     76  assert_equals(getComputedStyle(span.shadowRoot.querySelector("div")).zIndex, "0", "backmost stylesheet should take precedence");
     77  assert_equals(getComputedStyle(span.shadowRoot.querySelector("div")).color, "rgb(0, 0, 255)", "backmost stylesheet should take precedence");
     78 
     79  span.shadowRoot.adoptedStyleSheets = [sheets[1], sheets[0], sheets[1], sheet];
     80  assert_equals(getComputedStyle(span.shadowRoot.querySelector("div")).zIndex, "1", "duplicate stylesheet should take right position in the cascade");
     81  assert_equals(getComputedStyle(span.shadowRoot.querySelector("div")).color, "rgb(255, 0, 0)", "backmost stylesheet should take precedence");
     82 }, "Appending duplicate stylesheets yields the correct cascade position in the ShadowRoot");
     83 
     84 </script>