diff options
Diffstat (limited to 'tests/wpt/web-platform-tests/css/cssom/CSSStyleSheet-constructable-duplicate.html')
-rw-r--r-- | tests/wpt/web-platform-tests/css/cssom/CSSStyleSheet-constructable-duplicate.html | 76 |
1 files changed, 70 insertions, 6 deletions
diff --git a/tests/wpt/web-platform-tests/css/cssom/CSSStyleSheet-constructable-duplicate.html b/tests/wpt/web-platform-tests/css/cssom/CSSStyleSheet-constructable-duplicate.html index 30a3ed1d09b..579f5d0fced 100644 --- a/tests/wpt/web-platform-tests/css/cssom/CSSStyleSheet-constructable-duplicate.html +++ b/tests/wpt/web-platform-tests/css/cssom/CSSStyleSheet-constructable-duplicate.html @@ -4,17 +4,81 @@ <link rel="help" href="https://wicg.github.io/construct-stylesheets/"> <script src = '/resources/testharness.js'></script> <script src = '/resources/testharnessreport.js'></script> -<div></div> +<div id="target"></div> <script> -test(function() { - let sheets = []; - for (let i = 0; i < 2; ++i) { +function attachShadowDiv(host) { + const shadowRoot = host.attachShadow({mode: 'open'}); + const shadowDiv = document.createElement("div"); + shadowRoot.appendChild(shadowDiv); + return shadowDiv; +} + +function blueSheetsWithIncreasingZIndex(n) { + let sheets = []; + for (let i = 0; i < n; ++i) { sheets.push(new CSSStyleSheet()); - sheets[i].replaceSync("div { z-index: " + i + " }"); + sheets[i].replaceSync("div { z-index: " + i + "; color: blue; }"); } + return sheets; +} + +let sheets = []; + +test(function() { + sheets = blueSheetsWithIncreasingZIndex(2); document.adoptedStyleSheets = [sheets[1], sheets[0], sheets[1]]; assert_equals(getComputedStyle(document.querySelector("div")).zIndex, "1", "duplicate stylesheet should take right position in the cascade"); -}); + + document.adoptedStyleSheets = []; +}, "Duplicate stylesheets have the right cascade position in the Document"); + +test(function() { + sheets = blueSheetsWithIncreasingZIndex(2); + + const sheet = new CSSStyleSheet(); + sheet.replaceSync("div { color: red; }"); + + document.adoptedStyleSheets = [sheets[1], sheets[0]]; + assert_equals(getComputedStyle(document.querySelector("div")).zIndex, "0", "backmost stylesheet should take precedence"); + assert_equals(getComputedStyle(document.querySelector("div")).color, "rgb(0, 0, 255)", "backmost stylesheet should take precedence"); + + document.adoptedStyleSheets = [sheets[1], sheets[0], sheets[1], sheet]; + assert_equals(getComputedStyle(document.querySelector("div")).zIndex, "1", "duplicate stylesheet should take the right position in the cascade"); + assert_equals(getComputedStyle(document.querySelector("div")).color, "rgb(255, 0, 0)", "backmost stylesheet should take precedence"); + + document.adoptedStyleSheets = []; +}, "Appending duplicate stylesheets yields the correct cascade position in the Document"); + +test(function() { + sheets = blueSheetsWithIncreasingZIndex(2); + + const span = document.createElement("span"); + target.appendChild(span); + attachShadowDiv(span); + + span.shadowRoot.adoptedStyleSheets = [sheets[1], sheets[0], sheets[1]]; + assert_equals(getComputedStyle(span.shadowRoot.querySelector("div")).zIndex, "1", "duplicate stylesheet should take right position in the cascade"); +}, "Duplicate stylesheets have the right cascade position in the ShadowRoot"); + +test(function() { + sheets = blueSheetsWithIncreasingZIndex(2); + + const sheet = new CSSStyleSheet(); + sheet.replaceSync("div { color: red; }"); + + const span = document.createElement("span"); + target.appendChild(span); + attachShadowDiv(span); + + span.shadowRoot.adoptedStyleSheets = [sheets[1], sheets[0]]; + assert_equals(getComputedStyle(span.shadowRoot.querySelector("div")).zIndex, "0", "backmost stylesheet should take precedence"); + assert_equals(getComputedStyle(span.shadowRoot.querySelector("div")).color, "rgb(0, 0, 255)", "backmost stylesheet should take precedence"); + + span.shadowRoot.adoptedStyleSheets = [sheets[1], sheets[0], sheets[1], sheet]; + assert_equals(getComputedStyle(span.shadowRoot.querySelector("div")).zIndex, "1", "duplicate stylesheet should take right position in the cascade"); + assert_equals(getComputedStyle(span.shadowRoot.querySelector("div")).color, "rgb(255, 0, 0)", "backmost stylesheet should take precedence"); +}, "Appending duplicate stylesheets yields the correct cascade position in the ShadowRoot"); + </script> |