Skip to content

Commit 8e9f916

Browse files
committed
Test box-shadow serialization
Following w3c/csswg-drafts#2305, the canonical serialization for box-shadow was changed from inset? && <length>{2,4} && <color>? to <color>? && <length>{2,4} && inset?. Convert an existing box-shadow text into a testharness.js test in order to test serialization as well.
1 parent 08bc228 commit 8e9f916

3 files changed

Lines changed: 118 additions & 147 deletions

File tree

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
<!DOCTYPE html>
2+
<title>CSS Test: Box Shadow Syntax: Reordering Components</title>
3+
<link rel="author" title="Elika J. Etemad" href="http://fantasai.inkedblade.net/contact"/>
4+
<link rel="help" href="http://www.w3.org/TR/css3-background/#the-box-shadow"/>
5+
<meta name="assert" content="Box shadow color, inset, and length parameters can be mixed in any order, but lengths must stay adjacent." />
6+
<script src="/resources/testharness.js"></script>
7+
<script src="/resources/testharnessreport.js"></script>
8+
<script src="resources/parsing-testcommon.js"></script>
9+
<script>
10+
// color only
11+
test_valid_value("box-shadow", "4px 4px green", "green 4px 4px");
12+
test_valid_value("box-shadow", "green -4px 4px", "green -4px 4px");
13+
test_valid_value("box-shadow", "-4px 4px 0 green", "green -4px 4px 0px");
14+
test_valid_value("box-shadow", "green -4px 4px 0", "green -4px 4px 0px");
15+
test_valid_value("box-shadow", "-4px 4px 0 0 green", "green -4px 4px 0px 0px");
16+
test_valid_value("box-shadow", "green -4px 4px 0 0", "green -4px 4px 0px 0px");
17+
18+
// inset only
19+
test_valid_value("box-shadow", "4px -4px inset", "4px -4px inset");
20+
test_valid_value("box-shadow", "inset 4px -4px", "4px -4px inset");
21+
test_valid_value("box-shadow", "4px -4px 0 inset", "4px -4px 0px inset");
22+
test_valid_value("box-shadow", "inset 4px -4px 0", "4px -4px 0px inset");
23+
test_valid_value("box-shadow", "4px -4px 0 0 inset", "4px -4px 0px 0px inset");
24+
test_valid_value("box-shadow", "inset 4px -4px 0 0", "4px -4px 0px 0px inset");
25+
26+
// color and inset
27+
test_valid_value("box-shadow", "4px -4px green inset", "green 4px -4px inset");
28+
test_valid_value("box-shadow", "4px -4px inset green", "green 4px -4px inset");
29+
test_valid_value("box-shadow", "inset green 4px -4px", "green 4px -4px inset");
30+
test_valid_value("box-shadow", "green inset 4px -4px", "green 4px -4px inset");
31+
test_valid_value("box-shadow", "green 4px -4px inset", "green 4px -4px inset");
32+
test_valid_value("box-shadow", "inset 4px -4px green", "green 4px -4px inset");
33+
test_valid_value("box-shadow", "inset green 4px -4px 0", "green 4px -4px 0px inset");
34+
test_valid_value("box-shadow", "green inset 4px -4px 0", "green 4px -4px 0px inset");
35+
test_valid_value("box-shadow", "4px -4px 0 green inset", "green 4px -4px 0px inset");
36+
test_valid_value("box-shadow", "4px -4px 0 inset green", "green 4px -4px 0px inset");
37+
test_valid_value("box-shadow", "green 4px -4px 0 inset", "green 4px -4px 0px inset");
38+
test_valid_value("box-shadow", "inset 4px -4px 0 green", "green 4px -4px 0px inset");
39+
test_valid_value("box-shadow", "inset green 4px -4px 0 0", "green 4px -4px 0px 0px inset");
40+
test_valid_value("box-shadow", "green inset 4px -4px 0 0", "green 4px -4px 0px 0px inset");
41+
test_valid_value("box-shadow", "4px -4px 0 0 green inset", "green 4px -4px 0px 0px inset");
42+
test_valid_value("box-shadow", "4px -4px 0 0 inset green", "green 4px -4px 0px 0px inset");
43+
test_valid_value("box-shadow", "green 4px -4px 0 0 inset", "green 4px -4px 0px 0px inset");
44+
test_valid_value("box-shadow", "inset 4px -4px 0 0 green", "green 4px -4px 0px 0px inset");
45+
46+
test_invalid_value("box-shadow", "red");
47+
test_invalid_value("box-shadow", "4px red");
48+
test_invalid_value("box-shadow", "red 4px");
49+
test_invalid_value("box-shadow", "-4px red 4px");
50+
test_invalid_value("box-shadow", "red -4px 4px red");
51+
test_invalid_value("box-shadow", "-4px 4px red 0");
52+
test_invalid_value("box-shadow", "-4px 4px 0 red 0");
53+
test_invalid_value("box-shadow", "inset");
54+
test_invalid_value("box-shadow", "inset 4px");
55+
test_invalid_value("box-shadow", "4px inset");
56+
test_invalid_value("box-shadow", "4px inset -4px");
57+
test_invalid_value("box-shadow", "inset 4px -4px inset");
58+
test_invalid_value("box-shadow", "4px -4px inset 0");
59+
test_invalid_value("box-shadow", "4px -4px 0 inset 0");
60+
test_invalid_value("box-shadow", "red inset");
61+
test_invalid_value("box-shadow", "inset red");
62+
test_invalid_value("box-shadow", "4px red inset");
63+
test_invalid_value("box-shadow", "red inset 4px");
64+
test_invalid_value("box-shadow", "4px inset red");
65+
test_invalid_value("box-shadow", "inset red 4px");
66+
test_invalid_value("box-shadow", "4px red inset -4px");
67+
test_invalid_value("box-shadow", "4px inset red -4px");
68+
test_invalid_value("box-shadow", "inset 4px red -4px");
69+
test_invalid_value("box-shadow", "4px red 4px inset");
70+
test_invalid_value("box-shadow", "red 4px inset -4px");
71+
test_invalid_value("box-shadow", "4px inset -4px red");
72+
test_invalid_value("box-shadow", "4px -4px red inset 0");
73+
test_invalid_value("box-shadow", "4px -4px inset red 0");
74+
test_invalid_value("box-shadow", "inset 4px -4px red 0");
75+
test_invalid_value("box-shadow", "4px -4px red 0 inset");
76+
test_invalid_value("box-shadow", "red 4px -4px inset 0");
77+
test_invalid_value("box-shadow", "4px -4px inset 0 red");
78+
</script>
79+
</html>

‎css/css-backgrounds/box-shadow-syntax-001.xht‎

Lines changed: 0 additions & 147 deletions
This file was deleted.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
'use strict';
2+
3+
// serializedValue can be the expected serialization of value,
4+
// or an array of permitted serializations,
5+
// or omitted if value should serialize as value.
6+
function test_valid_value(property, value, serializedValue) {
7+
if (arguments.length < 3)
8+
serializedValue = value;
9+
10+
var stringifiedValue = JSON.stringify(value);
11+
12+
test(function(){
13+
var div = document.createElement('div');
14+
div.style[property] = value;
15+
assert_not_equals(div.style[property], "", "property should be set");
16+
17+
var div = document.createElement('div');
18+
div.style[property] = value;
19+
var readValue = div.style[property];
20+
if (serializedValue instanceof Array)
21+
assert_true(serializedValue.includes(readValue), "serialization should be sound");
22+
else
23+
assert_equals(readValue, serializedValue, "serialization should be canonical");
24+
25+
div.style[property] = readValue;
26+
assert_equals(div.style[property], readValue, "serialization should round-trip");
27+
28+
}, "e.style['" + property + "'] = " + stringifiedValue + " should set the property value");
29+
}
30+
31+
function test_invalid_value(property, value) {
32+
var stringifiedValue = JSON.stringify(value);
33+
34+
test(function(){
35+
var div = document.createElement('div');
36+
div.style[property] = value;
37+
assert_equals(div.style[property], "");
38+
}, "e.style['" + property + "'] = " + stringifiedValue + " should not set the property value");
39+
}

0 commit comments

Comments
 (0)