2 <title>Test serialization of specified CSS variable values
</title>
3 <script src=
"/MochiKit/MochiKit.js"></script>
4 <script src=
"/tests/SimpleTest/SimpleTest.js"></script>
5 <link rel=
"stylesheet" href=
"/tests/SimpleTest/test.css" type=
"text/css">
7 <style id=style1
>#test { }
</style>
8 <style id=style2
></style>
11 // Values that should be serialized back to the same string.
12 var values_with_unchanged_specified_value_serialization
= [
21 "something 3px url(whereever) calc(var(--a) + 1px)",
24 "var(--a, var(--b, var(--c, black)))",
37 // Values that serialize differently, due to additional implied closing
39 var values_with_changed_specified_value_serialization
= [
40 ["var(--a", "var(--a)"],
41 ["var(--a , ", "var(--a , )"],
42 ["var(--a, ", "var(--a, )"],
43 ["var(--a, var(--b", "var(--a, var(--b))"],
44 ["var(--a /* unclosed comment", "var(--a /* unclosed comment*/)"],
45 ["var(--a /* unclosed comment *", "var(--a /* unclosed comment */)"],
46 ["[{(((var(--a", "[{(((var(--a))))}]"],
47 ["var(--a, \"unclosed string", "var(--a, \"unclosed string\")"],
48 ["var(--a, 'unclosed string", "var(--a, 'unclosed string')"],
49 ["var(--a) \"unclosed string\\", "var(--a) \"unclosed string\""],
50 ["var(--a) 'unclosed string\\", "var(--a) 'unclosed string'"],
51 ["var(--a) \\", "var(--a) \\\ufffd"],
52 ["var(--a) url(unclosedurl", "var(--a) url(unclosedurl)"],
53 ["var(--a) url('unclosedurl", "var(--a) url('unclosedurl')"],
54 ["var(--a) url(\"unclosedurl", "var(--a) url(\"unclosedurl\")"],
55 ["var(--a) url(unclosedurl\\", "var(--a) url(unclosedurl\\\ufffd)"],
56 ["var(--a) url('unclosedurl\\", "var(--a) url('unclosedurl')"],
57 ["var(--a) url(\"unclosedurl\\", "var(--a) url(\"unclosedurl\")"],
60 var style1
= document
.getElementById("style1");
61 var style2
= document
.getElementById("style2");
63 var decl
= style1
.sheet
.cssRules
[0].style
;
65 function test_specified_value_serialization(value
, expected
) {
66 // Test setting value on a custom property with setProperty.
67 decl
.setProperty("--test", value
, "");
68 is(decl
.getPropertyValue("--test"), expected
,
69 "value with identical serialization set on custom property with setProperty");
71 // Test setting value on a custom property via style sheet parsing.
72 style2
.textContent
= "#test { --test:" + value
;
73 is(style2
.sheet
.cssRules
[0].style
.getPropertyValue("--test"), expected
,
74 "value with identical serialization set on custom property via parsing");
76 // Test setting value on a non-custom longhand property with setProperty.
77 decl
.setProperty("color", value
, "");
78 is(decl
.getPropertyValue("color"), expected
,
79 "value with identical serialization set on non-custom longhand property with setProperty");
81 // Test setting value on a non-custom longhand property via style sheet parsing.
82 style2
.textContent
= "#test { color:" + value
;
83 is(style2
.sheet
.cssRules
[0].style
.getPropertyValue("color"), expected
,
84 "value with identical serialization set on non-custom longhand property via parsing");
86 // Test setting value on a non-custom shorthand property with setProperty.
87 decl
.setProperty("margin", value
, "");
88 is(decl
.getPropertyValue("margin"), expected
,
89 "value with identical serialization set on non-custom shorthand property with setProperty");
91 // Test setting value on a non-custom shorthand property via style sheet parsing.
92 style2
.textContent
= "#test { margin:" + value
;
93 is(style2
.sheet
.cssRules
[0].style
.getPropertyValue("margin"), expected
,
94 "value with identical serialization set on non-custom shorthand property via parsing");
97 decl
.removeProperty("--test");
98 decl
.removeProperty("color");
99 decl
.removeProperty("margin");
103 values_with_unchanged_specified_value_serialization
.forEach(function(value
) {
104 test_specified_value_serialization(value
, value
);
107 values_with_changed_specified_value_serialization
.forEach(function(pair
) {
108 test_specified_value_serialization(pair
[0], pair
[1]);
114 SimpleTest
.waitForExplicitFinish();