summaryrefslogtreecommitdiffstats
path: root/layout/inspector/tests/test_is_valid_css_color.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 /layout/inspector/tests/test_is_valid_css_color.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 'layout/inspector/tests/test_is_valid_css_color.html')
-rw-r--r--layout/inspector/tests/test_is_valid_css_color.html99
1 files changed, 99 insertions, 0 deletions
diff --git a/layout/inspector/tests/test_is_valid_css_color.html b/layout/inspector/tests/test_is_valid_css_color.html
new file mode 100644
index 0000000000..d18a9ee384
--- /dev/null
+++ b/layout/inspector/tests/test_is_valid_css_color.html
@@ -0,0 +1,99 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+ <meta charset="utf-8">
+ <title>Test InspectorUtils::isValidCSSColor</title>
+ <script src="/tests/SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+ <script type="application/javascript">
+ const InspectorUtils = SpecialPowers.InspectorUtils;
+
+ // Color names
+ // XXX getCSSValuesForProperty no longer returns the complete color
+ // keyword list, so skip it for now.
+ if (false) {
+ let colors = InspectorUtils.getCSSValuesForProperty("color");
+ let notColor = ["hsl", "hsla", "inherit", "initial", "rgb", "rgba",
+ "unset", "transparent", "currentColor"];
+ for (let color of colors) {
+ if (notColor.includes(color)) {
+ continue;
+ }
+ ok(InspectorUtils.isValidCSSColor(color), color + " is a valid color");
+ ok(!InspectorUtils.isValidCSSColor("xxx" + color), "xxx" + color + " is not a valid color");
+ }
+ }
+
+ // rgb(a)
+ for (let i = 0; i <= 265; i++) {
+ ok(InspectorUtils.isValidCSSColor("rgb(" + i + ",0,0)"), "rgb(" + i + ",0,0) is a valid color");
+ ok(InspectorUtils.isValidCSSColor("rgb(0," + i + ",0)"), "rgb(0," + i + ",0) is a valid color");
+ ok(InspectorUtils.isValidCSSColor("rgb(0,0," + i + ")"), "rgb(0,0," + i + ") is a valid color");
+ ok(InspectorUtils.isValidCSSColor("rgba(" + i + ",0,0,0.2)"), "rgba(" + i + ",0,0,0.2) is a valid color");
+ ok(InspectorUtils.isValidCSSColor("rgba(0," + i + ",0,0.5)"), "rgba(0," + i + ",0,0.5) is a valid color");
+ ok(InspectorUtils.isValidCSSColor("rgba(0,0," + i + ",0.7)"), "rgba(0,0," + i + ",0.7) is a valid color");
+
+ ok(!InspectorUtils.isValidCSSColor("rgbxxx(" + i + ",0,0)"), "rgbxxx(" + i + ",0,0) is not a valid color");
+ ok(!InspectorUtils.isValidCSSColor("rgbxxx(0," + i + ",0)"), "rgbxxx(0," + i + ",0) is not a valid color");
+ ok(!InspectorUtils.isValidCSSColor("rgbxxx(0,0," + i + ")"), "rgbxxx(0,0," + i + ") is not a valid color");
+ }
+
+ // rgb(a) (%)
+ for (let i = 0; i <= 110; i++) {
+ ok(InspectorUtils.isValidCSSColor("rgb(" + i + "%,0%,0%)"), "rgb(" + i + "%,0%,0%) is a valid color");
+ ok(InspectorUtils.isValidCSSColor("rgb(0%," + i + "%,0%)"), "rgb(0%," + i + "%,0%) is a valid color");
+ ok(InspectorUtils.isValidCSSColor("rgb(0%,0%," + i + "%)"), "rgb(0%,0%," + i + "%) is a valid color");
+ ok(InspectorUtils.isValidCSSColor("rgba(" + i + "%,0%,0%,0.2)"), "rgba(" + i + "%,0%,0%,0.2) is a valid color");
+ ok(InspectorUtils.isValidCSSColor("rgba(0%," + i + "%,0%,0.5)"), "rgba(0%," + i + "%,0%,0.5) is a valid color");
+ ok(InspectorUtils.isValidCSSColor("rgba(0%,0%," + i + "%,0.7)"), "rgba(0%,0%," + i + "%,0.7) is a valid color");
+
+ ok(!InspectorUtils.isValidCSSColor("rgbaxxx(" + i + "%,0%,0%,0.2)"), "rgbaxxx(" + i + "%,0%,0%,0.2) is not a valid color");
+ ok(!InspectorUtils.isValidCSSColor("rgbaxxx(0%," + i + "%,0%,0.5)"), "rgbaxxx(0%," + i + "%,0%,0.5) is not a valid color");
+ ok(!InspectorUtils.isValidCSSColor("rgbaxxx(0%,0%," + i + "%,0.7)"), "rgbaxxx(0%,0%," + i + "%,0.7) is not a valid color");
+ }
+
+ // hsl(a)
+ for (let i = 0; i <= 370; i++) {
+ ok(InspectorUtils.isValidCSSColor("hsl(" + i + ",30%,10%)"), "rgb(" + i + ",30%,10%) is a valid color");
+ ok(InspectorUtils.isValidCSSColor("hsla(" + i + ",60%,70%,0.2)"), "rgba(" + i + ",60%,70%,0.2) is a valid color");
+ }
+ for (let i = 0; i <= 110; i++) {
+ ok(InspectorUtils.isValidCSSColor("hsl(100," + i + "%,20%)"), "hsl(100," + i + "%,20%) is a valid color");
+ ok(InspectorUtils.isValidCSSColor("hsla(100,20%," + i + "%,0.6)"), "hsla(100,20%," + i + "%,0.6) is a valid color");
+ }
+
+ // hex
+ for (let i = 0; i <= 255; i++) {
+ let hex = (i).toString(16);
+ if (hex.length === 1) {
+ hex = 0 + hex;
+ }
+ ok(InspectorUtils.isValidCSSColor("#" + hex + "7777"), "#" + hex + "7777 is a valid color");
+ ok(InspectorUtils.isValidCSSColor("#77" + hex + "77"), "#77" + hex + "77 is a valid color");
+ ok(InspectorUtils.isValidCSSColor("#7777" + hex), "#7777" + hex + " is a valid color");
+ }
+ ok(!InspectorUtils.isValidCSSColor("#kkkkkk"), "#kkkkkk is not a valid color");
+
+ // short hex
+ for (let i = 0; i <= 16; i++) {
+ let hex = (i).toString(16);
+ ok(InspectorUtils.isValidCSSColor("#" + hex + hex + hex), "#" + hex + hex + hex + " is a valid color");
+ }
+ ok(!InspectorUtils.isValidCSSColor("#ggg"), "#ggg is not a valid color");
+
+ // named
+ ok(InspectorUtils.isValidCSSColor("red"), "red is a valid color");
+ ok(InspectorUtils.isValidCSSColor("transparent"), "transparent is a valid color");
+ ok(InspectorUtils.isValidCSSColor("currentColor"), "currentColor is a valid color");
+ </script>
+</head>
+<body>
+<h1>Test InspectorUtils::isValidCSSColor</h1>
+<p id="display"></p>
+<div id="content" style="display: none">
+
+</div>
+<pre id="test">
+</pre>
+</body>
+</html>