summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/css/css-variables/variable-substitution-basic.html
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:47:29 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:47:29 +0000
commit0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d (patch)
treea31f07c9bcca9d56ce61e9a1ffd30ef350d513aa /testing/web-platform/tests/css/css-variables/variable-substitution-basic.html
parentInitial commit. (diff)
downloadfirefox-esr-0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d.tar.xz
firefox-esr-0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d.zip
Adding upstream version 115.8.0esr.upstream/115.8.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/css/css-variables/variable-substitution-basic.html')
-rw-r--r--testing/web-platform/tests/css/css-variables/variable-substitution-basic.html124
1 files changed, 124 insertions, 0 deletions
diff --git a/testing/web-platform/tests/css/css-variables/variable-substitution-basic.html b/testing/web-platform/tests/css/css-variables/variable-substitution-basic.html
new file mode 100644
index 0000000000..e1c0a11aad
--- /dev/null
+++ b/testing/web-platform/tests/css/css-variables/variable-substitution-basic.html
@@ -0,0 +1,124 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <title>test basic variable substitution</title>
+
+ <meta rel="author" title="Kevin Babbitt">
+ <meta rel="author" title="Greg Whitworth">
+ <link rel="author" title="Microsoft Corporation" href="http://microsoft.com" />
+ <link rel="help" href="http://www.w3.org/TR/css-variables-1/#defining-variables">
+
+ <script src="/resources/testharness.js"></script>
+ <script src="/resources/testharnessreport.js"></script>
+ <style>
+ #testArea {
+ color: orange;
+ }
+ #testArea > div {
+ width: 50px !important;
+ }
+ </style>
+</head>
+<body>
+ <div id="log"></div>
+ <div id="testArea"></div>
+ <script type="text/javascript">
+ "use strict";
+
+ let templates = [
+ {
+ testName:"Simple substitution test",
+ propertyName:"border-spacing",
+ expectedValue:"20px 20px",
+ style:"--gap: 20px;border-spacing: var(--gap);"
+ },
+ {
+ testName:"You can't build up a single token where part of it is provided by a variable",
+ propertyName:"border-spacing",
+ expectedValue:"0px 0px",
+ style:"--gap: 20;border-spacing: var(--gap)px;"
+ },
+ {
+ testName:"You can't build up a single token where part of it is provided by a variable (percentages)",
+ propertyName:"text-indent",
+ expectedValue:"0px",
+ style:"--v: 20;text-indent: var(--v)%;"
+ },
+ {
+ testName:"Multiple variable references in a single property",
+ propertyName:"border-spacing",
+ expectedValue:"19px 47px",
+ style:"--gap1: 19px;--gap2: 47px;border-spacing: var(--gap1) var(--gap2);"
+ },
+ {
+ testName:"Multiple variable references in a single property (no spaces)",
+ propertyName:"border-spacing",
+ expectedValue:"23px 59px",
+ style:"--gap1:23px;--gap2:59px;border-spacing:var(--gap1)var(--gap2);"
+ },
+ {
+ testName:"Fallback value",
+ propertyName:"border-spacing",
+ expectedValue:"11px 11px",
+ style:"border-spacing:var(--gap,11px);"
+ },
+ {
+ testName:"Fallback value which is also a variable reference",
+ propertyName:"border-spacing",
+ expectedValue:"27px 27px",
+ style:"--gap2: 27px; border-spacing:var(--gap,var(--gap2));"
+ },
+ {
+ testName:"Multiple var references in fallback value",
+ propertyName:"border-spacing",
+ expectedValue:"66px 92px",
+ style:"--gap2: 66px; --gap3: 92px; border-spacing:var(--gap,var(--gap2)var(--gap3));"
+ },
+ {
+ testName:"Multiple nested fallbacks",
+ propertyName:"border-spacing",
+ expectedValue:"98px 18px",
+ style:"--gap4: 98px 18px; border-spacing:var(--gap1,var(--gap2,var(--gap3,var(--gap4,var(--gap5)))));"
+ },
+ {
+ testName:"Bad variable reference that should inherit by default",
+ propertyName:"color",
+ expectedValue:"rgb(255, 165, 0)",
+ style:"color: var(--colorVar) pink;"
+ },
+ {
+ testName:"Test that var reference doesn’t overwrite !important",
+ propertyName:"width",
+ expectedValue:"50px",
+ style:"--varWidth: 28px; width: var(--varWidth);"
+ },
+ {
+ testName:"Test that !important on a property that has a variable reference can overwrite !important",
+ propertyName:"width",
+ expectedValue:"28px",
+ style:"--varWidth: 28px; width: var(--varWidth) !important;"
+ },
+ {
+ testName:"Test that !important inside of var reference can't overwrite !important on property",
+ propertyName:"width",
+ expectedValue:"50px",
+ style:"--varWidth: 28px !important; width: var(--varWidth);"
+ },
+ ];
+
+ let testArea = document.getElementById("testArea");
+
+ templates.forEach(function (template) {
+ test( function () {
+ let div = document.createElement("div");
+ div.style.cssText = template.style;
+ testArea.appendChild(div);
+ let computedStyle = window.getComputedStyle(div);
+ let value = computedStyle.getPropertyValue(template.propertyName);
+ assert_equals(value, template.expectedValue, "Expected Value should match actual value");
+ testArea.removeChild(div);
+ }, template.testName);
+ });
+ </script>
+</body>
+</html>