summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/css/css-color/parsing/color-computed-lab.html
blob: c1c6b662e10e3d8235c30ff869cfbd54a777b947 (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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>CSS Color Level 4: Computation of colors using Lab notation</title>
<link rel="help" href="https://drafts.csswg.org/css-color-4/#lab-colors">
<link rel="help" href="https://drafts.csswg.org/css-color-4/#resolving-lab-lch-values">
<link rel="help" href="https://drafts.csswg.org/css-color-4/#resolving-oklab-oklch-values">
<link rel="help" href="https://drafts.csswg.org/css-color-4/#serializing-lab-lch">
<link rel="help" href="https://drafts.csswg.org/css-color-4/#serializing-oklab-oklch">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/css/support/computed-testcommon.js"></script>
</head>
<body>
<div id="container">
  <div id="target"></div>
</div>
<style>
  #container {
    color: rgb(255, 0, 0);
  }
</style>
<script>

// lab()
test_computed_value("color", "lab(0 0 0)", "lab(0 0 0)");
test_computed_value("color", "lab(0 0 0 / 1)", "lab(0 0 0)");
test_computed_value("color", "lab(0 0 0 / 0.5)", "lab(0 0 0 / 0.5)");
test_computed_value("color", "lab(20 0 10/0.5)", "lab(20 0 10 / 0.5)");
test_computed_value("color", "lab(20 0 10/50%)", "lab(20 0 10 / 0.5)");
test_computed_value("color", "lab(400 0 10/50%)", "lab(100 0 10 / 0.5)");
test_computed_value("color", "lab(50 -160 160)", "lab(50 -160 160)");
test_computed_value("color", "lab(50 -200 200)", "lab(50 -200 200)");
test_computed_value("color", "lab(0 0 0 / -10%)", "lab(0 0 0 / 0)");
test_computed_value("color", "lab(0 0 0 / 110%)", "lab(0 0 0)");
test_computed_value("color", "lab(0 0 0 / 300%)", "lab(0 0 0)");
test_computed_value("color", "lab(-40 0 0)", "lab(0 0 0)");
test_computed_value("color", "lab(50 -20 0)", "lab(50 -20 0)");
test_computed_value("color", "lab(50 0 -20)", "lab(50 0 -20)");
test_computed_value("color", "lab(calc(50 * 3) calc(0.5 - 1) calc(1.5) / calc(-0.5 + 1))", "lab(100 -0.5 1.5 / 0.5)");
test_computed_value("color", "lab(calc(-50 * 3) calc(0.5 + 1) calc(-1.5) / calc(-0.5 * 2))", "lab(0 1.5 -1.5 / 0)");

test_computed_value("color", "lab(none none none / none)", "lab(none none none / none)");
test_computed_value("color", "lab(none none none)", "lab(none none none)");
test_computed_value("color", "lab(20 none none / none)", "lab(20 none none / none)");
test_computed_value("color", "lab(none none none / 0.5)", "lab(none none none / 0.5)");
test_computed_value("color", "lab(0 0 0 / none)", "lab(0 0 0 / none)");

test_computed_value("color", "lab(calc(NaN) 0 0)", "lab(0 0 0)");
test_computed_value("color", "lab(calc(0 / 0) 0 0)", "lab(0 0 0)");

// oklab()
test_computed_value("color", "oklab(0 0 0)", "oklab(0 0 0)");
test_computed_value("color", "oklab(0 0 0 / 1)", "oklab(0 0 0)");
test_computed_value("color", "oklab(0 0 0 / 0.5)", "oklab(0 0 0 / 0.5)");
test_computed_value("color", "oklab(0.2 0 0.1/0.5)", "oklab(0.2 0 0.1 / 0.5)");
test_computed_value("color", "oklab(0.2 0 0.1/50%)", "oklab(0.2 0 0.1 / 0.5)");
test_computed_value("color", "oklab(4 0 0.1/50%)", "oklab(1 0 0.1 / 0.5)");
test_computed_value("color", "oklab(0.5 -1.6 1.6)", "oklab(0.5 -1.6 1.6)");
test_computed_value("color", "oklab(0.5 -2 2)", "oklab(0.5 -2 2)");
test_computed_value("color", "oklab(0 0 0 / -10%)", "oklab(0 0 0 / 0)");
test_computed_value("color", "oklab(0 0 0 / 110%)", "oklab(0 0 0)");
test_computed_value("color", "oklab(0 0 0 / 300%)", "oklab(0 0 0)");
test_computed_value("color", "oklab(-0.4 0 0)", "oklab(0 0 0)");
test_computed_value("color", "oklab(0.5 -0.2 0)", "oklab(0.5 -0.2 0)");
test_computed_value("color", "oklab(0.5 0 -0.2)", "oklab(0.5 0 -0.2)");
test_computed_value("color", "oklab(calc(0.5 * 3) calc(0.5 - 1) calc(1.5) / calc(-0.5 + 1))", "oklab(1 -0.5 1.5 / 0.5)");
test_computed_value("color", "oklab(calc(-0.5 * 3) calc(0.5 + 1) calc(-1.5) / calc(-0.5 * 2))", "oklab(0 1.5 -1.5 / 0)");

test_computed_value("color", "oklab(none none none / none)", "oklab(none none none / none)");
test_computed_value("color", "oklab(none none none)", "oklab(none none none)");
test_computed_value("color", "oklab(0.2 none none / none)", "oklab(0.2 none none / none)");
test_computed_value("color", "oklab(none none none / 0.5)", "oklab(none none none / 0.5)");
test_computed_value("color", "oklab(0 0 0 / none)", "oklab(0 0 0 / none)");

// These tests validate the ranges of lab() vs. oklab() components
test_computed_value("color", "lab(20% -50% 90%/0.5)", "lab(20 -62.5 112.5 / 0.5)");
test_computed_value("color", "oklab(20% 70% -80%/0.5)", "oklab(0.2 0.28 -0.32 / 0.5)");

test_computed_value("color", "oklab(calc(NaN) 0 0)", "oklab(0 0 0)");
test_computed_value("color", "oklab(calc(0 / 0) 0 0)", "oklab(0 0 0)");

// lch()
test_computed_value("color", "lch(0 0 0deg)", "lch(0 0 0)");
test_computed_value("color", "lch(0 0 0deg / 1)", "lch(0 0 0)");
test_computed_value("color", "lch(0 0 0deg / 0.5)", "lch(0 0 0 / 0.5)");
test_computed_value("color", "lch(100 230 0deg / 0.5)", "lch(100 230 0 / 0.5)");
test_computed_value("color", "lch(20 50 20deg/0.5)", "lch(20 50 20 / 0.5)");
test_computed_value("color", "lch(20 50 20deg/50%)", "lch(20 50 20 / 0.5)");
test_computed_value("color", "lch(10 20 20deg / -10%)", "lch(10 20 20 / 0)");
test_computed_value("color", "lch(10 20 20deg / 110%)", "lch(10 20 20)");
test_computed_value("color", "lch(10 20 1.28rad)", "lch(10 20 73.3386)");
test_computed_value("color", "lch(10 20 380deg)", "lch(10 20 20)");
test_computed_value("color", "lch(10 20 -340deg)", "lch(10 20 20)");
test_computed_value("color", "lch(10 20 740deg)", "lch(10 20 20)");
test_computed_value("color", "lch(10 20 -700deg)", "lch(10 20 20)");
test_computed_value("color", "lch(-40 0 0)", "lch(0 0 0)");
test_computed_value("color", "lch(20 -20 0)", "lch(20 0 0)");
test_computed_value("color", "lch(0 0 0 / 0.5)", "lch(0 0 0 / 0.5)");
test_computed_value("color", "lch(10 20 20 / 110%)", "lch(10 20 20)");
test_computed_value("color", "lch(10 20 -700)", "lch(10 20 20)");
test_computed_value("color", "lch(calc(50 * 3) calc(0.5 - 1) calc(20deg * 2) / calc(-0.5 + 1))", "lch(100 0 40 / 0.5)");
test_computed_value("color", "lch(calc(-50 * 3) calc(0.5 + 1) calc(-20deg * 2) / calc(-0.5 * 2))", "lch(0 1.5 320 / 0)");

test_computed_value("color", "lch(none none none / none)", "lch(none none none / none)");
test_computed_value("color", "lch(none none none)", "lch(none none none)");
test_computed_value("color", "lch(20 none none / none)", "lch(20 none none / none)");
test_computed_value("color", "lch(none none none / 0.5)", "lch(none none none / 0.5)");
test_computed_value("color", "lch(0 0 0 / none)", "lch(0 0 0 / none)");

test_computed_value("color", "lch(calc(NaN) 0 0)", "lch(0 0 0)");
test_computed_value("color", "lch(calc(0 / 0) 0 0)", "lch(0 0 0)");

// oklch()
test_computed_value("color", "oklch(0 0 0deg)", "oklch(0 0 0)");
test_computed_value("color", "oklch(0 0 0deg / 1)", "oklch(0 0 0)");
test_computed_value("color", "oklch(0 0 0deg / 0.5)", "oklch(0 0 0 / 0.5)");
test_computed_value("color", "oklch(1 2.3 0deg / 0.5)", "oklch(1 2.3 0 / 0.5)");
test_computed_value("color", "oklch(0.2 0.5 20deg/0.5)", "oklch(0.2 0.5 20 / 0.5)");
test_computed_value("color", "oklch(0.2 0.5 20deg/50%)", "oklch(0.2 0.5 20 / 0.5)");
test_computed_value("color", "oklch(0.1 0.2 20deg / -10%)", "oklch(0.1 0.2 20 / 0)");
test_computed_value("color", "oklch(0.1 0.2 20deg / 110%)", "oklch(0.1 0.2 20)");
test_computed_value("color", "oklch(0.1 0.2 1.28rad)", "oklch(0.1 0.2 73.3386)");
test_computed_value("color", "oklch(0.1 0.2 380deg)", "oklch(0.1 0.2 20)");
test_computed_value("color", "oklch(0.1 0.2 -340deg)", "oklch(0.1 0.2 20)");
test_computed_value("color", "oklch(0.1 0.2 740deg)", "oklch(0.1 0.2 20)");
test_computed_value("color", "oklch(0.1 0.2 -700deg)", "oklch(0.1 0.2 20)");
test_computed_value("color", "oklch(-0.4 0 0)", "oklch(0 0 0)");
test_computed_value("color", "oklch(0.2 -0.2 0)", "oklch(0.2 0 0)");
test_computed_value("color", "oklch(0 0 0 / 0.5)", "oklch(0 0 0 / 0.5)");
test_computed_value("color", "oklch(0.1 0.2 20 / 110%)", "oklch(0.1 0.2 20)");
test_computed_value("color", "oklch(0.1 0.2 -700)", "oklch(0.1 0.2 20)");
test_computed_value("color", "oklch(calc(0.5 * 3) calc(0.5 - 1) calc(20deg * 2) / calc(-0.5 + 1))", "oklch(1 0 40 / 0.5)");
test_computed_value("color", "oklch(calc(-0.5 * 3) calc(0.5 + 1) calc(-20deg * 2) / calc(-0.5 * 2))", "oklch(0 1.5 320 / 0)");

test_computed_value("color", "oklch(none none none / none)", "oklch(none none none / none)");
test_computed_value("color", "oklch(none none none)", "oklch(none none none)");
test_computed_value("color", "oklch(0.2 none none / none)", "oklch(0.2 none none / none)");
test_computed_value("color", "oklch(none none none / 0.5)", "oklch(none none none / 0.5)");
test_computed_value("color", "oklch(0 0 0 / none)", "oklch(0 0 0 / none)");

// These tests validate the ranges of lch() vs. oklch() lightness and chroma
test_computed_value("color", "lch(20% 80% 10/0.5)", "lch(20 120 10 / 0.5)");
test_computed_value("color", "oklch(20% 60% 10/0.5)", "oklch(0.2 0.24 10 / 0.5)");

test_computed_value("color", "oklch(calc(NaN) 0 0)", "oklch(0 0 0)");
test_computed_value("color", "oklch(calc(0 / 0) 0 0)", "oklch(0 0 0)");

</script>
</body>
</html>