diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
commit | 43a97878ce14b72f0981164f87f2e35e14151312 (patch) | |
tree | 620249daf56c0258faa40cbdcf9cfba06de2a846 /testing/web-platform/tests/css/cssom/CSSStyleSheet-constructable-duplicate.html | |
parent | Initial commit. (diff) | |
download | firefox-43a97878ce14b72f0981164f87f2e35e14151312.tar.xz firefox-43a97878ce14b72f0981164f87f2e35e14151312.zip |
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/css/cssom/CSSStyleSheet-constructable-duplicate.html')
-rw-r--r-- | testing/web-platform/tests/css/cssom/CSSStyleSheet-constructable-duplicate.html | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/testing/web-platform/tests/css/cssom/CSSStyleSheet-constructable-duplicate.html b/testing/web-platform/tests/css/cssom/CSSStyleSheet-constructable-duplicate.html new file mode 100644 index 0000000000..579f5d0fce --- /dev/null +++ b/testing/web-platform/tests/css/cssom/CSSStyleSheet-constructable-duplicate.html @@ -0,0 +1,84 @@ +<!doctype html> +<title>Cascade order of a stylesheet for duplicate sheets.</title> +<link rel="author" title="Emilio Cobos Álvarez" href="mailto:emilio@crisal.io"> +<link rel="help" href="https://wicg.github.io/construct-stylesheets/"> +<script src = '/resources/testharness.js'></script> +<script src = '/resources/testharnessreport.js'></script> +<div id="target"></div> +<script> + +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 + "; 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> |