|
1 <!DOCTYPE HTML> |
|
2 <html> |
|
3 <!-- |
|
4 --> |
|
5 <head> |
|
6 <title>Test handling of garbage at the end of CSS declarations</title> |
|
7 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
|
8 <script type="text/javascript" src="property_database.js"></script> |
|
9 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> |
|
10 </head> |
|
11 <body> |
|
12 <p id="display"></p> |
|
13 <div id="content" style="display: none"> |
|
14 |
|
15 <div id="testnode"></div> |
|
16 |
|
17 </div> |
|
18 <pre id="test"> |
|
19 <script class="testbody" type="text/javascript"> |
|
20 |
|
21 /** Test for correct ExpectEndProperty calls in CSS parser **/ |
|
22 |
|
23 /* |
|
24 * Inspired by review comments on bug 378217. |
|
25 * |
|
26 * The original idea was to test that ExpectEndProperty calls are made |
|
27 * in the correct places in the CSS parser so that we don't accept |
|
28 * garbage at the end of property values. |
|
29 * |
|
30 * However, there's actually other code (in ParseDeclaration) that |
|
31 * ensures that we don't accept garbage. |
|
32 * |
|
33 * Despite that, I'm checking it in anyway, since it caught an infinite |
|
34 * loop in the patch for bug 435441. |
|
35 */ |
|
36 |
|
37 var gElement = document.getElementById("testnode"); |
|
38 var gDeclaration = gElement.style; |
|
39 |
|
40 /* |
|
41 * This lists properties where garbage identifiers are allowed at the |
|
42 * end, with values in property_database.js that are exceptions that |
|
43 * should be tested anyway. "inherit", "initial" and "unset" are always |
|
44 * tested. |
|
45 */ |
|
46 var gAllowsExtra = { |
|
47 "counter-increment": { "none": true }, |
|
48 "counter-reset": { "none": true }, |
|
49 "font-family": {}, |
|
50 "font": { "caption": true, "icon": true, "menu": true, "message-box": true, |
|
51 "small-caption": true, "status-bar": true }, |
|
52 "voice-family": {}, |
|
53 }; |
|
54 |
|
55 /* These are the reverse of the above list; they're the unusual values |
|
56 that do allow extra keywords afterwards */ |
|
57 var gAllowsExtraUnusual = { |
|
58 "transition": { "all": true, "0s": true, "0s 0s": true, "ease": true, |
|
59 "1s 2s linear": true, "1s linear 2s": true, |
|
60 "linear 1s 2s": true, "linear 1s": true, |
|
61 "1s linear": true, "1s 2s": true, "2s 1s": true, |
|
62 "linear": true, "1s": true, "2s": true, |
|
63 "ease-in-out": true, "2s ease-in": true, |
|
64 "ease-out 2s": true, "1s width, 2s": true }, |
|
65 "animation": { "none": true, "0s": true, "ease": true, |
|
66 "normal": true, "running": true, "1.0": true, |
|
67 "1s 2s linear": true, "1s linear 2s": true, |
|
68 "linear 1s 2s": true, "linear 1s": true, |
|
69 "1s linear": true, "1s 2s": true, "2s 1s": true, |
|
70 "linear": true, "1s": true, "2s": true, |
|
71 "ease-in-out": true, "2s ease-in": true, |
|
72 "ease-out 2s": true, "1s bounce, 2s": true, |
|
73 "1s bounce, 2s none": true }, |
|
74 "font-family": { "inherit": true, "initial": true, "unset": true } |
|
75 }; |
|
76 |
|
77 gAllowsExtraUnusual["-moz-transition"] = gAllowsExtraUnusual["transition"]; |
|
78 gAllowsExtraUnusual["-moz-animation"] = gAllowsExtraUnusual["animation"]; |
|
79 |
|
80 function test_property(property) |
|
81 { |
|
82 var info = gCSSProperties[property]; |
|
83 |
|
84 function test_value(value) { |
|
85 if (property in gAllowsExtra && |
|
86 value != "inherit" && value != "initial" && value != "unset" && |
|
87 !(value in gAllowsExtra[property])) { |
|
88 return; |
|
89 } |
|
90 if (property in gAllowsExtraUnusual && |
|
91 value in gAllowsExtraUnusual[property]) { |
|
92 return; |
|
93 } |
|
94 |
|
95 // Include non-identifier characters in the garbage |
|
96 // in case |value| would also be valid with a <custom-ident> added. |
|
97 gElement.setAttribute("style", property + ": " + value + " +blah/"); |
|
98 if ("subproperties" in info) { |
|
99 for (idx in info.subproperties) { |
|
100 var subprop = info.subproperties[idx]; |
|
101 is(gDeclaration.getPropertyValue(subprop), "", |
|
102 ["expected garbage ignored after '", property, ": ", value, |
|
103 "' when looking at subproperty '", subprop, "'"].join("")); |
|
104 } |
|
105 } else { |
|
106 is(gDeclaration.getPropertyValue(property), "", |
|
107 ["expected garbage ignored after '", property, ": ", value, |
|
108 "'"].join("")); |
|
109 } |
|
110 } |
|
111 |
|
112 var idx; |
|
113 test_value("inherit"); |
|
114 test_value("initial"); |
|
115 if (SpecialPowers.getBoolPref("layout.css.unset-value.enabled")) |
|
116 test_value("unset"); |
|
117 for (idx in info.initial_values) |
|
118 test_value(info.initial_values[idx]); |
|
119 for (idx in info.other_values) |
|
120 test_value(info.other_values[idx]); |
|
121 } |
|
122 |
|
123 // To avoid triggering the slow script dialog, we have to test one |
|
124 // property at a time. |
|
125 SimpleTest.waitForExplicitFinish(); |
|
126 var props = []; |
|
127 for (var prop in gCSSProperties) |
|
128 props.push(prop); |
|
129 props = props.reverse(); |
|
130 function do_one() { |
|
131 if (props.length == 0) { |
|
132 SimpleTest.finish(); |
|
133 return; |
|
134 } |
|
135 test_property(props.pop()); |
|
136 SimpleTest.executeSoon(do_one); |
|
137 } |
|
138 SimpleTest.executeSoon(do_one); |
|
139 |
|
140 </script> |
|
141 </pre> |
|
142 </body> |
|
143 </html> |