summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/css/cssom/CSSStyleSheet-constructable-duplicate.html
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
commit26a029d407be480d791972afb5975cf62c9360a6 (patch)
treef435a8308119effd964b339f76abb83a57c29483 /testing/web-platform/tests/css/cssom/CSSStyleSheet-constructable-duplicate.html
parentInitial commit. (diff)
downloadfirefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz
firefox-26a029d407be480d791972afb5975cf62c9360a6.zip
Adding upstream version 124.0.1.upstream/124.0.1
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.html84
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>