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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
|
<!DOCTYPE html>
<title>Image set parsing</title>
<link rel="author" title="Noam Rosenthal" href="mailto:noam.j.rosenthal@gmail.com">
<link rel="author" title="Traian Captan" href="mailto:tcaptan@chromium.org">
<link rel="help" href="https://drafts.csswg.org/css-images-4/#image-set-notation">
<meta name="assert" content="General image-set parsing follows CSS Images 4 rules.">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/css/support/parsing-testcommon.js"></script>
<body>
<script>
function test_valid_value_variants(property, value, serializedValue) {
if (!serializedValue) serializedValue = value;
test_valid_value(property, value, serializedValue);
// The '-webkit-' prefixed 'image-set' is expected to serialize to the same
// value as standard 'image-set'.
// https://drafts.csswg.org/css-images-4/#deprecated
// "Implementations must accept -webkit-image-set() as a parse-time alias of
// image-set(). (It’s a valid value, with identical arguments to image-set(),
// and is turned into image-set() during parsing.)"
test_valid_value(property, "-webkit-" + value, serializedValue);
}
function test_invalid_value_variants(property, value) {
test_invalid_value(property, value);
test_invalid_value(property, "-webkit-" + value);
}
function test_default_resolution_parsing() {
// Based on the spec, the resolution is optional and should default
// to 1x if not specified.
// This set of tests verify this expectation.
// Test when the only image is missing it's resolution
test_valid_value_variants(
'background-image',
'image-set(url(foo))',
'image-set(url("foo") 1x)'
);
// Test when the 1st of 2 images is missing it's resolution
test_valid_value_variants(
'background-image',
'image-set(url(foo), url(bar) 1x)',
'image-set(url("foo") 1x, url("bar") 1x)'
);
// Test when the 2nd of 2 images is missing it's resolution
test_valid_value_variants(
'background-image',
'image-set(url(foo) 1x, url(bar))',
'image-set(url("foo") 1x, url("bar") 1x)'
);
// Test when both images are missing their resolutions
test_valid_value_variants(
'background-image',
'image-set(url(foo), url(bar))',
'image-set(url("foo") 1x, url("bar") 1x)'
);
// Test when the middle of 3 images is missing it's resolution
test_valid_value_variants(
'background-image',
'image-set(url(foo) 1x, url(bar), url(baz) 2x)',
'image-set(url("foo") 1x, url("bar") 1x, url("baz") 2x)'
);
}
function test_resolution_units_parsing() {
test_valid_value_variants(
'background-image',
'image-set(url("example.png") 1x)'
);
test_valid_value_variants(
'background-image',
'image-set(url("example.png") calc(2x * 3))',
'image-set(url("example.png") calc(6dppx))'
);
test_valid_value_variants(
'background-image',
'image-set(url("example.png") 1dppx)'
);
test_valid_value_variants(
'background-image',
'image-set(url("example.png") calc(1dppx * 1))',
'image-set(url("example.png") calc(1dppx))'
);
test_valid_value_variants(
'background-image',
'image-set(url("example.png") 1dpi)'
);
test_valid_value_variants(
'background-image',
'image-set(url("example.png") calc(96dpi * 2))',
'image-set(url("example.png") calc(2dppx))'
);
test_valid_value_variants(
'background-image',
'image-set(url("example.png") 1dpcm)'
);
test_valid_value_variants(
'background-image',
'image-set(url("example.png") calc(1dpcm * 96/2.54))',
'image-set(url("example.png") calc(1dppx))'
);
test_valid_value_variants(
'background-image',
'image-set(url("example.png") 1x, url("example.png") 2dppx, "example.png" 250dpi, "example.png" 1dpcm)',
'image-set(url("example.png") 1x, url("example.png") 2dppx, url("example.png") 250dpi, url("example.png") 1dpcm)'
);
test_valid_value_variants(
'content',
'image-set(url("example.png") 1dpi)'
);
test_valid_value_variants(
'content',
'image-set(url("example.png") calc(1 * 96dpi))',
'image-set(url("example.png") calc(1dppx))'
);
test_invalid_value_variants(
'background-image',
'image-set(url("example.png") 1invalidResUnit)'
);
test_invalid_value_variants(
'background-image',
'image-set(url("example.png") calc(3 * 4))'
);
test_invalid_value_variants(
'background-image',
'image-set(url("example.png") calc(2 - 1))'
);
test_invalid_value_variants(
'background-image',
'image-set(url("example.png") calc(2x - 1))'
);
test_invalid_value_variants(
'background-image',
'image-set(url("example.png") calc(1 + 4dpi))'
);
}
function test_non_positive_resolutions_parsing() {
test_valid_value_variants(
'background-image',
'image-set(url("example.png") 0x)'
);
test_valid_value_variants(
'background-image',
'image-set(url("example.png") 0dppx)'
);
test_valid_value_variants(
'background-image',
'image-set(url("example.png") 0dpi)'
);
test_valid_value_variants(
'background-image',
'image-set(url("example.png") 0dpcm)'
);
test_invalid_value_variants(
'background-image',
'image-set(url("example.png") -1x)'
);
test_invalid_value_variants(
'background-image',
'image-set(url("example.png") -3dppx)'
);
test_invalid_value_variants(
'background-image',
'image-set(url("example.png") -96dpi)'
);
test_invalid_value_variants(
'background-image',
'image-set(url("example.png") -113dpcm)'
);
}
function test_gradient_images_parsing() {
test_valid_value_variants(
'background-image',
"image-set(linear-gradient(black, white) 1x)"
);
test_valid_value_variants(
'background-image',
"image-set(repeating-linear-gradient(red, blue 25%) 1x)"
);
test_valid_value_variants(
'background-image',
"image-set(radial-gradient(black, white) 1x)"
);
test_valid_value_variants(
'background-image',
"image-set(repeating-radial-gradient(red, blue 25%) 1x)"
);
test_valid_value_variants(
'background-image',
"image-set(conic-gradient(black, white) 1x)"
);
test_valid_value_variants(
'background-image',
"image-set(repeating-conic-gradient(red, blue 25%) 1x)"
);
test_valid_value_variants(
'content',
'image-set(linear-gradient(black, white) 1x, url("example.png") 4x)'
);
test_valid_value_variants(
'content',
'image-set(url("example.png") 192dpi, linear-gradient(black, white) 1x)'
);
test_invalid_value_variants(
'cursor',
"image-set(linear-gradient(black, white) 1x)"
);
test_invalid_value_variants(
'background-image',
"image-set(linear-gradient(red) 1x)"
);
}
function test_image_type_parsing() {
test_valid_value_variants(
'background-image',
'image-set(url("example.png") 1x type("image/png"))'
);
test_valid_value_variants(
'background-image',
"image-set(url(example.png) type('image/png'))",
'image-set(url("example.png") 1x type("image/png"))'
);
test_valid_value_variants(
'background-image',
"image-set(url(example.png) type('image/png') 1x)",
'image-set(url("example.png") 1x type("image/png"))'
);
test_valid_value_variants(
'background-image',
"image-set(url(example.png) 1x type('image/jpeg'))",
'image-set(url("example.png") 1x type("image/jpeg"))'
);
test_invalid_value_variants(
'background-image',
"image-set(url(example.png) type(image/png))"
);
test_invalid_value_variants(
'background-image',
"image-set(url(example.png) type('image/png') type('image/png'))"
);
test_invalid_value_variants(
'background-image',
"image-set(url(example.png) type('image/png' 'image/png'))"
);
test_invalid_value_variants(
'background-image',
"image-set(url(example.png) type(url('image/png')))"
);
test_invalid_value_variants(
'background-image',
"image-set(url(example.png) 1xtype('image/png'))"
);
test_invalid_value_variants(
'background-image',
"image-set(type('image/png') url(example.png) 1x)"
);
}
function test_no_images_set_nesting() {
// Spec definition:
// "The image-set() function can not be nested inside of itself,
// either directly or indirectly (as an argument to another <image> type)."
// Direct nesting
test_invalid_value_variants(
'background-image',
"image-set(image-set(url(example.png)) 2x)"
);
// Indirect nesting
test_invalid_value_variants(
'background-image',
"image-set(image(image-set(url(example.png)) 2x) 2x)"
);
}
function test_image_set_parsing() {
test_valid_value_variants('background-image', "image-set(url(example.png) 1x)", 'image-set(url("example.png") 1x)');
test_valid_value_variants('background-image', "image-set('example.jpg' 1x)", 'image-set(url("example.jpg") 1x)');
test_valid_value_variants('background-image', "image-set(url(example.png) 1x, 'example.png' 2x)", 'image-set(url("example.png") 1x, url("example.png") 2x)');
test_valid_value_variants('background-image', "image-set(url(example.png) 1dpcm, 'example.png' 2x)", 'image-set(url("example.png") 1dpcm, url("example.png") 2x)');
test_valid_value_variants('background-image', "image-set('example.jpeg' 222dpi, url(example.png) 3.5x)", 'image-set(url("example.jpeg") 222dpi, url("example.png") 3.5x)');
test_valid_value_variants('background-image', 'image-set(url("example.png") 0x)');
test_valid_value_variants('background-image', 'image-set(url("example.png") -20x)');
test_valid_value_variants('content', 'image-set(url("example.png") 1x)', 'image-set(url("example.png") 1x)');
test_valid_value_variants('content', 'image-set(url("example.png") 1x, "example.png" 3x)', 'image-set(url("example.png") 1x, url("example.png") 3x)');
test_valid_value_variants('border-image-source', 'image-set(url("example.png") 1x)', 'image-set(url("example.png") 1x)');
test_valid_value_variants('border-image-source', 'image-set(url("example.png") 1x, "example.png" 3x)', 'image-set(url("example.png") 1x, url("example.png") 3x)');
test_invalid_value_variants('background-image', "image-set(none, url(example.png) 1x)");
test_invalid_value_variants('background-image', "image-set()");
test_invalid_value_variants('background-image', "image-set('example.jpeg' 92pid url(example.png) 1x)");
test_invalid_value_variants('background-image', "image-set(url(example.png) 1x url(example.jpeg))");
test_invalid_value_variants('background-image', "image-set(url(example.png) 1x 2x)");
test_default_resolution_parsing();
test_resolution_units_parsing();
test_non_positive_resolutions_parsing();
test_gradient_images_parsing();
test_image_type_parsing();
test_no_images_set_nesting();
}
test_image_set_parsing();
</script>
|