summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/css/css-color/parsing/color-valid-hsl.html
blob: 7ab1274176fd9fbbaed10d1644d18c2eb05b41e3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>CSS Color Level 4: Parsing and serialization of colors using valid HSL notation</title>
<link rel="help" href="https://drafts.csswg.org/css-color-4/#the-hsl-notation">
<link rel="help" href="https://drafts.csswg.org/css-color-4/#resolving-sRGB-values">
<link rel="help" href="https://drafts.csswg.org/css-color-4/#serializing-sRGB-values">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/css/support/parsing-testcommon.js"></script>
</head>
<body>
<script>
test_valid_value("color", "hsl(120 30% 50%)", "rgb(89, 166, 89)");
test_valid_value("color", "hsl(120 30% 50% / 0.5)", "rgba(89, 166, 89, 0.5)");
test_valid_value("color", "hsl(none none none)", "rgb(0, 0, 0)");
test_valid_value("color", "hsl(0 0% 0%)", "rgb(0, 0, 0)");
test_valid_value("color", "hsl(none none none / none)", "rgba(0, 0, 0, 0)");
test_valid_value("color", "hsl(0 0% 0% / 0)", "rgba(0, 0, 0, 0)");
test_valid_value("color", "hsla(none none none)", "rgb(0, 0, 0)");
test_valid_value("color", "hsla(0 0% 0%)", "rgb(0, 0, 0)");
test_valid_value("color", "hsla(none none none / none)", "rgba(0, 0, 0, 0)");
test_valid_value("color", "hsla(0 0% 0% / 0)", "rgba(0, 0, 0, 0)");
test_valid_value("color", "hsl(120 none none)", "rgb(0, 0, 0)");
test_valid_value("color", "hsl(120 0% 0%)", "rgb(0, 0, 0)");
test_valid_value("color", "hsl(120 80% none)", "rgb(0, 0, 0)");
test_valid_value("color", "hsl(120 80% 0%)", "rgb(0, 0, 0)");
test_valid_value("color", "hsl(120 none 50%)", "rgb(128, 128, 128)");
test_valid_value("color", "hsl(120 0% 50%)", "rgb(128, 128, 128)");
test_valid_value("color", "hsl(120 100% 50% / none)", "rgba(0, 255, 0, 0)");
test_valid_value("color", "hsl(120 100% 50% / 0)", "rgba(0, 255, 0, 0)");
test_valid_value("color", "hsl(none 100% 50%)", "rgb(255, 0, 0)");
test_valid_value("color", "hsl(0 100% 50%)", "rgb(255, 0, 0)");

// Test with number components.
test_valid_value("color", "hsl(120 30 50)", "rgb(89, 166, 89)");
test_valid_value("color", "hsl(120 30 50 / 0.5)", "rgba(89, 166, 89, 0.5)");
test_valid_value("color", "hsl(120 30% 50)", "rgb(89, 166, 89)");
test_valid_value("color", "hsl(120 30% 50 / 0.5)", "rgba(89, 166, 89, 0.5)");
test_valid_value("color", "hsl(120 30 50%)", "rgb(89, 166, 89)");
test_valid_value("color", "hsl(120 30 50% / 0.5)", "rgba(89, 166, 89, 0.5)");
test_valid_value("color", "hsl(120 none 50)", "rgb(128, 128, 128)");
test_valid_value("color", "hsl(120 none 50 / 0.5)", "rgba(128, 128, 128, 0.5)");
test_valid_value("color", "hsl(120 30 none)", "rgb(0, 0, 0)");
test_valid_value("color", "hsl(120 30 none / 0.5)", "rgba(0, 0, 0, 0.5)");
test_valid_value("color", "hsl(120 30 50 / none)", "rgba(89, 166, 89, 0)");

// Test non-finite values. calc(infinity) goes to upper bound while calc(-infinity) and NaN go to the lower bound.
// See: https://github.com/w3c/csswg-drafts/issues/8629
test_valid_value("color", "hsl(calc(infinity) 100% 50%)", "rgb(255, 0, 0)"); // hsl(360 100% 50%)
test_valid_value("color", "hsl(calc(-infinity) 100% 50%)", "rgb(255, 0, 0)"); // hsl(0 100% 50%)
test_valid_value("color", "hsl(calc(0 / 0) 100% 50%)", "rgb(255, 0, 0)"); // hsl(0 100% 50%)
test_valid_value("color", "hsl(90 50% 50% / calc(infinity))", "rgb(128, 191, 64)"); // hsl(90 50% 50%)
test_valid_value("color", "hsl(90 50% 50% / calc(-infinity))", "rgba(128, 191, 64, 0)"); // hsl(90 50% 50% / 0)
test_valid_value("color", "hsl(90 50% 50% / calc(0 / 0))", "rgba(128, 191, 64, 0)"); // hsl(90 50% 50% / 0)
</script>
</body>
</html>