Truly independent web browser
Tests: Import WPT tests for input type=color
Andreas Kling747eda99923c
diff --git a/Tests/LibWeb/Text/expected/wpt-import/html/semantics/forms/the-input-element/color-attributes.window.txt b/Tests/LibWeb/Text/expected/wpt-import/html/semantics/forms/the-input-element/color-attributes.window.txtnew file mode 100644index 00000000000..4304895694d--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/html/semantics/forms/the-input-element/color-attributes.window.txt@@ -0,0 +1,7 @@+Harness status: OK++Found 2 tests++2 Fail+Fail <input type=color>: alpha attribute+Fail <input type=color>: colorspace attribute\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/html/semantics/forms/the-input-element/color.txt b/Tests/LibWeb/Text/expected/wpt-import/html/semantics/forms/the-input-element/color.txtnew file mode 100644index 00000000000..07f176102d6--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/html/semantics/forms/the-input-element/color.txt@@ -0,0 +1,33 @@+Harness status: OK++Found 27 tests++15 Pass+12 Fail+Pass Empty value should return #000000+Pass Missing value should return #000000+Pass Valid simple color: should return #ffffff+Pass Valid simple color (containing LATIN CAPITAL LETTERS): should return #ffffff (converted to ASCII lowercase)+Pass Zero-padding+Fail Valid simple color: 4 characters long+Pass Invalid simple color: 8 characters long+Pass Invalid simple color: no starting # sign+Pass Invalid simple color: non ASCII hex digits+Pass Invalid simple color: foobar+Pass Invalid color: trailing Null (U+0000)+Pass Invalid color: trailing ;+Fail Valid color: leading space+Fail Valid color: trailing space+Fail Valid color: leading+trailing spaces+Fail Valid color: keyword crimson+Fail Valid color: keyword bisque+Pass Valid color: currentColor+Pass Invalid color: keyword transparent+Pass Invalid color: keyword inherit+Fail Valid color: rgb(1,1,1)+Fail Valid color: rgb(1,1,1,1)+Pass Invalid color: PILE OF POO (U+1F4A9)+Fail Valid color: hsl(150deg 100 53.5)+Fail Valid color: color(display-p3 .5 0 0)+Fail Valid color: color(display-p3 1 0 0)+Fail System colors are parsed\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/html/semantics/forms/the-input-element/color.window.txt b/Tests/LibWeb/Text/expected/wpt-import/html/semantics/forms/the-input-element/color.window.txtnew file mode 100644index 00000000000..eaeb5d1e886Binary files /dev/null and b/Tests/LibWeb/Text/expected/wpt-import/html/semantics/forms/the-input-element/color.window.txt differdiff --git a/Tests/LibWeb/Text/input/wpt-import/html/semantics/forms/the-input-element/color-attributes.window.html b/Tests/LibWeb/Text/input/wpt-import/html/semantics/forms/the-input-element/color-attributes.window.htmlnew file mode 100644index 00000000000..a7ce714d61f--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/html/semantics/forms/the-input-element/color-attributes.window.html@@ -0,0 +1,8 @@+<!doctype html>+<meta charset=utf-8>++<script src="../../../../resources/testharness.js"></script>+<script src="../../../../resources/testharnessreport.js"></script>++<div id=log></div>+<script src="../../../../html/semantics/forms/the-input-element/color-attributes.window.js"></script>diff --git a/Tests/LibWeb/Text/input/wpt-import/html/semantics/forms/the-input-element/color-attributes.window.js b/Tests/LibWeb/Text/input/wpt-import/html/semantics/forms/the-input-element/color-attributes.window.jsnew file mode 100644index 00000000000..7e2acb50803--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/html/semantics/forms/the-input-element/color-attributes.window.js@@ -0,0 +1,29 @@+test(() => {+ const input = document.createElement("input");+ input.type = "color";+ input.setAttribute("alpha", "blah");+ assert_equals(input.getAttribute("alpha"), "blah");+ assert_true(input.alpha);+ input.alpha = false;+ assert_false(input.hasAttribute("alpha"));+ input.alpha = "blah";+ assert_true(input.alpha);+ assert_equals(input.getAttribute("alpha"), "");+}, "<input type=color>: alpha attribute");++test(() => {+ const input = document.createElement("input");+ input.type = "color";+ input.setAttribute("colorspace", "blah");+ assert_equals(input.getAttribute("colorspace"), "blah");+ assert_equals(input.colorSpace, "limited-srgb");+ input.colorSpace = null;+ assert_equals(input.getAttribute("colorspace"), "null");+ assert_equals(input.colorSpace, "limited-srgb");+ input.colorSpace = "DISPLAY-P3";+ assert_equals(input.getAttribute("colorspace"), "DISPLAY-P3");+ assert_equals(input.colorSpace, "display-p3");+ input.colorSpace = "DıSPLAY-P3";+ assert_equals(input.getAttribute("colorspace"), "DıSPLAY-P3");+ assert_equals(input.colorSpace, "limited-srgb");+}, "<input type=color>: colorspace attribute");diff --git a/Tests/LibWeb/Text/input/wpt-import/html/semantics/forms/the-input-element/color.html b/Tests/LibWeb/Text/input/wpt-import/html/semantics/forms/the-input-element/color.htmlnew file mode 100644index 00000000000..4038724fd2c--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/html/semantics/forms/the-input-element/color.html@@ -0,0 +1,55 @@+<!DOCTYPE html>+<meta charset=utf-8>+<title>Form input type=color (HTML compatible)</title>+<link rel="author" title="Denis Ah-Kang" href="mailto:[email protected]">+<link rel="help" href="https://html.spec.whatwg.org/multipage/states-of-the-type-attribute.html#color-state-(type=color)">+<link rel="help" href="https://drafts.csswg.org/css-color/#parse-color">+<script src="../../../../resources/testharness.js"></script>+<script src="../../../../resources/testharnessreport.js"></script>+<div id="log"></div>+<script>+ var colors = [+ {value: "", expected: "#000000", testname: "Empty value should return #000000"},+ {expected: "#000000", testname: "Missing value should return #000000"},+ {value: "#ffffff", expected: "#ffffff", testname: "Valid simple color: should return #ffffff"},+ {value: "#FFFFFF", expected: "#ffffff", testname: "Valid simple color (containing LATIN CAPITAL LETTERS): should return #ffffff (converted to ASCII lowercase)"},+ {value: "#0F0F0F", expected: "#0f0f0f", testname: "Zero-padding"},+ {value: "#fff", expected: "#ffffff", testname: "Valid simple color: 4 characters long"},+ {value: "#fffffff", expected: "#000000", testname: "Invalid simple color: 8 characters long"},+ {value: "fffffff", expected: "#000000", testname: "Invalid simple color: no starting # sign"},+ {value: "#gggggg", expected: "#000000", testname: "Invalid simple color: non ASCII hex digits"},+ {value: "foobar", expected: "#000000", testname: "Invalid simple color: foobar"},+ {value: "#ffffff\u0000", expected: "#000000", testname: "Invalid color: trailing Null (U+0000)"},+ {value: "#ffffff;", expected: "#000000", testname: "Invalid color: trailing ;"},+ {value: " #ffffff", expected: "#ffffff", testname: "Valid color: leading space"},+ {value: "#ffffff ", expected: "#ffffff", testname: "Valid color: trailing space"},+ {value: " #ffffff ", expected: "#ffffff", testname: "Valid color: leading+trailing spaces"},+ {value: "crimson", expected: "#dc143c", testname: "Valid color: keyword crimson"},+ {value: "bisque", expected: "#ffe4c4", testname: "Valid color: keyword bisque"},+ {value: "currentColor", expected: "#000000", testname: "Valid color: currentColor"},+ {value: "transparent", expected: "#000000", testname: "Invalid color: keyword transparent"},+ {value: "inherit", expected: "#000000", testname: "Invalid color: keyword inherit"},+ {value: "rgb(1,1,1)", expected: "#010101", testname: "Valid color: rgb(1,1,1)"},+ {value: "rgb(1,1,1,1)", expected: "#010101", testname: "Valid color: rgb(1,1,1,1)"},+ {value: "#FFFFF\u1F4A9", expected: "#000000", testname: "Invalid color: PILE OF POO (U+1F4A9)"},+ {value: "hsl(150deg 100 53.5)", expected: "#12ff88", testname: "Valid color: hsl(150deg 100 53.5)"},+ {value: "color(display-p3 .5 0 0)", expected: "#8c0000", testname: "Valid color: color(display-p3 .5 0 0)"},+ {value: "color(display-p3 1 0 0)", expected: "#ff0000", testname: "Valid color: color(display-p3 1 0 0)"},+ ];+ for (var i = 0; i < colors.length; i++) {+ var w = colors[i];+ test(function() {+ var input = document.createElement("input");+ input.type = "color";+ input.value = w.value;+ assert_equals(input.value, w.expected);+ }, w.testname);+ }+ test(() => {+ const input = document.createElement("input");+ input.type = "color";+ assert_equals(input.value, "#000000");+ input.value = "ActiveBorder";+ assert_not_equals(input.value, "#000000");+ }, "System colors are parsed");+</script>diff --git a/Tests/LibWeb/Text/input/wpt-import/html/semantics/forms/the-input-element/color.window.html b/Tests/LibWeb/Text/input/wpt-import/html/semantics/forms/the-input-element/color.window.htmlnew file mode 100644index 00000000000..b77cef363bd--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/html/semantics/forms/the-input-element/color.window.html@@ -0,0 +1,8 @@+<!doctype html>+<meta charset=utf-8>++<script src="../../../../resources/testharness.js"></script>+<script src="../../../../resources/testharnessreport.js"></script>+<script src="../../../../css/support/color-testcommon.js"></script>+<div id=log></div>+<script src="../../../../html/semantics/forms/the-input-element/color.window.js"></script>diff --git a/Tests/LibWeb/Text/input/wpt-import/html/semantics/forms/the-input-element/color.window.js b/Tests/LibWeb/Text/input/wpt-import/html/semantics/forms/the-input-element/color.window.jsnew file mode 100644index 00000000000..95e39f5c9b9--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/html/semantics/forms/the-input-element/color.window.js@@ -0,0 +1,279 @@+// META: script=/css/support/color-testcommon.js++// While assert_equals is fine for hex, it's not for hexalpha, p3, and p3alpha. We use the default+// epsilon of 0.0001.+const assert_colors = set_up_fuzzy_color_test();++[+ {+ value: "",+ hex: "#000000",+ hexalpha: "color(srgb 0 0 0)",+ p3: "color(display-p3 0 0 0)",+ p3alpha: "color(display-p3 0 0 0)"+ },+ {+ hex: "#000000",+ hexalpha: "color(srgb 0 0 0)",+ p3: "color(display-p3 0 0 0)",+ p3alpha: "color(display-p3 0 0 0)"+ },+ {+ value: "#ffffff",+ hex: "#ffffff",+ hexalpha: "color(srgb 1 1 1)",+ p3: "color(display-p3 1 1 1)",+ p3alpha: "color(display-p3 1 1 1)"+ },+ {+ value: "#ffffff08",+ hex: "#ffffff",+ hexalpha: "color(srgb 1 1 1 / 0.031373)",+ p3: "color(display-p3 1 1 1)",+ p3alpha: "color(display-p3 1 1 1 / 0.031373)"+ },+ {+ value: "#FFFFFF",+ hex: "#ffffff",+ hexalpha: "color(srgb 1 1 1)",+ p3: "color(display-p3 1 1 1)",+ p3alpha: "color(display-p3 1 1 1)"+ },+ {+ value: "#0F0F0F",+ hex: "#0f0f0f",+ hexalpha: "color(srgb 0.058824 0.058824 0.058824)",+ p3: "color(display-p3 0.058824 0.058824 0.058824)",+ p3alpha: "color(display-p3 0.058824 0.058824 0.058824)"+ },+ {+ value: "#fff",+ hex: "#ffffff",+ hexalpha: "color(srgb 1 1 1)",+ p3: "color(display-p3 1 1 1)",+ p3alpha: "color(display-p3 1 1 1)"+ },+ {+ value: "fffffff",+ hex: "#000000",+ hexalpha: "color(srgb 0 0 0)",+ p3: "color(display-p3 0 0 0)",+ p3alpha: "color(display-p3 0 0 0)"+ },+ {+ value: "#gggggg",+ hex: "#000000",+ hexalpha: "color(srgb 0 0 0)",+ p3: "color(display-p3 0 0 0)",+ p3alpha: "color(display-p3 0 0 0)"+ },+ {+ value: "foobar",+ hex: "#000000",+ hexalpha: "color(srgb 0 0 0)",+ p3: "color(display-p3 0 0 0)",+ p3alpha: "color(display-p3 0 0 0)"+ },+ {+ value: "#ffffff\u0000",+ hex: "#000000",+ hexalpha: "color(srgb 0 0 0)",+ p3: "color(display-p3 0 0 0)",+ p3alpha: "color(display-p3 0 0 0)"+ },+ {+ value: "#ffffff;",+ hex: "#000000",+ hexalpha: "color(srgb 0 0 0)",+ p3: "color(display-p3 0 0 0)",+ p3alpha: "color(display-p3 0 0 0)"+ },+ {+ value: " #ffffff",+ hex: "#ffffff",+ hexalpha: "color(srgb 1 1 1)",+ p3: "color(display-p3 1 1 1)",+ p3alpha: "color(display-p3 1 1 1)"+ },+ {+ value: "#ffffff ",+ hex: "#ffffff",+ hexalpha: "color(srgb 1 1 1)",+ p3: "color(display-p3 1 1 1)",+ p3alpha: "color(display-p3 1 1 1)"+ },+ {+ value: " #ffffff ",+ hex: "#ffffff",+ hexalpha: "color(srgb 1 1 1)",+ p3: "color(display-p3 1 1 1)",+ p3alpha: "color(display-p3 1 1 1)"+ },+ {+ value: "crimson",+ hex: "#dc143c",+ hexalpha: "color(srgb 0.862745 0.078431 0.235294)",+ p3: "color(display-p3 0.791711 0.191507 0.257367)",+ p3alpha: "color(display-p3 0.791711 0.191507 0.257367)"+ },+ {+ value: "bisque",+ hex: "#ffe4c4",+ hexalpha: "color(srgb 1 0.894118 0.768627)",+ p3: "color(display-p3 0.982297 0.8979 0.783276)",+ p3alpha: "color(display-p3 0.982297 0.8979 0.783276)"+ },+ {+ value: "currentColor",+ hex: "#000000",+ hexalpha: "color(srgb 0 0 0)",+ p3: "color(display-p3 0 0 0)",+ p3alpha: "color(display-p3 0 0 0)"+ },+ {+ value: "transparent",+ hex: "#000000",+ hexalpha: "color(srgb 0 0 0 / 0)",+ p3: "color(display-p3 0 0 0)",+ p3alpha: "color(display-p3 0 0 0 / 0)"+ },+ {+ value: "inherit",+ hex: "#000000",+ hexalpha: "color(srgb 0 0 0)",+ p3: "color(display-p3 0 0 0)",+ p3alpha: "color(display-p3 0 0 0)"+ },+ {+ value: "rgb(1,1,1)",+ hex: "#010101",+ hexalpha: "color(srgb 0.003922 0.003922 0.003922)",+ p3: "color(display-p3 0.003922 0.003922 0.003922)",+ p3alpha: "color(display-p3 0.003922 0.003922 0.003922)"+ },+ {+ value: "rgb(1,1,1,1)",+ hex: "#010101",+ hexalpha: "color(srgb 0.003922 0.003922 0.003922)",+ p3: "color(display-p3 0.003922 0.003922 0.003922)",+ p3alpha: "color(display-p3 0.003922 0.003922 0.003922)"+ },+ {+ value: "rgb(1,1,1,0.5)",+ hex: "#010101",+ hexalpha: "color(srgb 0.003922 0.003922 0.003922 / 0.501961)",+ p3: "color(display-p3 0.003922 0.003922 0.003922)",+ p3alpha: "color(display-p3 0.003922 0.003922 0.003922 / 0.501961)"+ },+ {+ value: "#FFFFF\u1F4A9",+ hex: "#000000",+ hexalpha: "color(srgb 0 0 0)",+ p3: "color(display-p3 0 0 0)",+ p3alpha: "color(display-p3 0 0 0)"+ }+].forEach(({ value, hex, hexalpha, p3, p3alpha }) => {+ ["limited-srgb", "display-p3"].forEach(colorSpace => {+ [false, true].forEach(alpha => {+ const nameValue = value === "" ? "the empty string" : value === undefined ? "no value" : "'" + value + "'";+ test(() => {+ const input = document.createElement("input");+ input.type = "color";+ if (value !== undefined) {+ input.setAttribute("value", value);+ }+ assert_equals(input.value, hex, "value is hex");+ input.colorSpace = colorSpace;+ assert_equals(input.colorSpace, colorSpace, "color space");+ if (colorSpace === "limited-srgb") {+ assert_equals(input.value, hex, "value is hex");+ } else {+ assert_colors(input.value, p3);+ }+ input.alpha = alpha;+ assert_equals(input.alpha, alpha, "alpha");+ if (colorSpace === "limited-srgb" && !alpha) {+ assert_equals(input.value, hex, "value is hex");+ } else if (colorSpace === "limited-srgb" && alpha) {+ assert_colors(input.value, hexalpha);+ } else if (colorSpace === "display-p3" && !alpha) {+ assert_colors(input.value, p3);+ } else {+ assert_colors(input.value, p3alpha);+ }+ }, `Testing ${nameValue} with color space '${colorSpace}' and ${alpha ? 'with' : ' without'} alpha (setAttribute("value"))`);++ test(() => {+ const input = document.createElement("input");+ input.type = "color";+ // In this test we set alpha before we set value to avoid the value sanitization algorithm+ // taking away the alpha channel from the input.+ input.alpha = true;+ if (value !== undefined) {+ input.value = value;+ }+ assert_colors(input.value, hexalpha);+ input.colorSpace = colorSpace;+ assert_equals(input.colorSpace, colorSpace, "color space");+ if (colorSpace === "limited-srgb") {+ assert_colors(input.value, hexalpha);+ } else {+ assert_colors(input.value, p3alpha);+ }+ input.alpha = alpha;+ assert_equals(input.alpha, alpha, "alpha");+ if (colorSpace === "limited-srgb" && !alpha) {+ assert_equals(input.value, hex, "value is hex");+ } else if (colorSpace === "limited-srgb" && alpha) {+ assert_colors(input.value, hexalpha);+ } else if (colorSpace === "display-p3" && !alpha) {+ assert_colors(input.value, p3);+ } else {+ assert_colors(input.value, p3alpha);+ }+ }, `Testing ${nameValue} with color space '${colorSpace}' and ${alpha ? 'with' : ' without'} alpha (value)`);+ });+ });+});++test(() => {+ const input = document.createElement("input");+ input.type = "color";+ input.alpha = true;+ input.colorSpace = "display-p3";+ input.value = "color(display-p3 3 none .2 / .6)";+ assert_equals(input.value, "color(display-p3 3 0 0.2 / 0.6)");+}, "Display P3 colors can be out-of-bounds");++test(() => {+ const input = document.createElement("input");+ input.type = "color";+ input.value = "white";+ input.setAttribute("colorspace", "display-p3");+ assert_equals(input.value, "color(display-p3 1 1 1)");+}, "Setting colorspace by setAttribute should update the value");++test(() => {+ const input = document.createElement("input");+ input.type = "color";+ input.value = "blue";+ input.setAttribute("alpha", "");+ assert_equals(input.value, "color(srgb 0 0 1)");+}, "Setting alpha by setAttribute should update the value");++// When the value is not dirty, changing colorspace/alpha re-sanitizes from the+// original `value` content attribute rather than the current value, so+// information dropped under the previous attributes (such as an alpha channel)+// is recovered. See https://github.com/whatwg/html/issues/12057.+test(() => {+ const input = document.createElement("input");+ input.type = "color";+ // Setting the content attribute (rather than the IDL value) leaves the value+ // non-dirty. Without the alpha attribute the value sanitizes to opaque.+ input.setAttribute("value", "#ffffff08");+ assert_equals(input.value, "#ffffff");+ input.setAttribute("alpha", "");+ // Reparsing the original "#ffffff08" recovers the alpha channel; reparsing the+ // now-opaque current value would instead give "color(srgb 1 1 1)".+ assert_colors(input.value, "color(srgb 1 1 1 / 0.031373)");+}, "Adding alpha reparses the original value attribute for a non-dirty value");