layout/style/test/test_property_syntax_errors.html

branch
TOR_BUG_9701
changeset 11
deefc01c0e14
equal deleted inserted replaced
-1:000000000000 0:8bbf089ebfb1
1 <!DOCTYPE HTML>
2 <html>
3 <!--
4 -->
5 <head>
6 <title>Test that we reject syntax errors listed in property_database.js</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 onload="run()">
12 <p id="display"></p>
13 <iframe id="quirks" src="data:text/html,<div id='testnode'></div>"></iframe>
14 <div id="content" style="display: none">
15
16 <div id="testnode"></div>
17
18 </div>
19 <pre id="test">
20 <script class="testbody" type="text/javascript">
21
22 SimpleTest.waitForExplicitFinish();
23
24 function check_not_accepted(decl, property, info, badval)
25 {
26 decl.setProperty(property, badval, "");
27
28 is(decl.getPropertyValue(property), "",
29 "invalid value '" + badval + "' not accepted for '" + property +
30 "' property");
31
32 if ("subproperties" in info) {
33 for (var sidx in info.subproperties) {
34 var subprop = info.subproperties[sidx];
35 is(decl.getPropertyValue(subprop), "",
36 "invalid value '" + badval + "' not accepted for '" + property +
37 "' property when testing subproperty '" + subprop + "'");
38 }
39 }
40
41 decl.removeProperty(property);
42 }
43
44 function check_value_balanced(decl, property, badval)
45 {
46 var goodProp =
47 (property == "background-color") ? "color" : "background-color";
48 decl.cssText = goodProp + ": red; " + property + ": " + badval + "; " +
49 goodProp + ": green";
50 is(decl.getPropertyValue(goodProp), "green",
51 "invalid value '" + property + ": " + badval +
52 "' is balanced and does not lead to parsing errors afterwards");
53 decl.cssText = "";
54 }
55
56 function check_value_unbalanced(decl, property, badval)
57 {
58 var goodProp =
59 (property == "background-color") ? "color" : "background-color";
60 decl.cssText = goodProp + ": green; " + property + ": " + badval + "; " +
61 goodProp + ": red";
62 is(decl.getPropertyValue(goodProp), "green",
63 "invalid value '" + property + ": " + badval +
64 "' is unbalanced and absorbs what follows it");
65 decl.cssText = "";
66 }
67
68 function check_empty_value_rejected(decl, emptyval, property)
69 {
70 var goodProp =
71 (property == "background-color") ? "color" : "background-color";
72 decl.cssText = goodProp + ": red; " + property + ":" + emptyval + "; " +
73 goodProp + ": green";
74 is(decl.length, 1,
75 "empty value '" + property + ":" + emptyval +
76 "' is not accepted");
77 is(decl.getPropertyValue(goodProp), "green",
78 "empty value '" + property + ":" + emptyval +
79 "' is balanced and does not lead to parsing errors afterwards");
80 decl.cssText = "";
81 }
82
83 function run()
84 {
85 var gDeclaration = document.getElementById("testnode").style;
86 var gQuirksDeclaration = document.getElementById("quirks").contentDocument
87 .getElementById("testnode").style;
88
89 for (var property in gCSSProperties) {
90 var info = gCSSProperties[property];
91
92 check_empty_value_rejected(gDeclaration, "", property);
93 check_empty_value_rejected(gDeclaration, " ", property);
94
95 for (var idx in info.invalid_values) {
96 check_not_accepted(gDeclaration, property, info,
97 info.invalid_values[idx]);
98 check_not_accepted(gQuirksDeclaration, property, info,
99 info.invalid_values[idx]);
100 check_value_balanced(gDeclaration, property,
101 info.invalid_values[idx]);
102 }
103
104 if ("quirks_values" in info) {
105 for (var quirkval in info.quirks_values) {
106 var standardval = info.quirks_values[quirkval];
107 check_not_accepted(gDeclaration, property, info, quirkval);
108 check_value_balanced(gDeclaration, property, quirkval);
109
110 gQuirksDeclaration.setProperty(property, quirkval, "");
111 gDeclaration.setProperty(property, standardval, "");
112 var quirkret = gQuirksDeclaration.getPropertyValue(property);
113 var standardret = gDeclaration.getPropertyValue(property);
114 isnot(quirkret, "", property + ": " + quirkval +
115 " should be accepted in quirks mode");
116 is(quirkret, standardret, property + ": " + quirkval + " result");
117
118 if ("subproperties" in info) {
119 for (var sidx in info.subproperties) {
120 var subprop = info.subproperties[sidx];
121 var quirksub = gQuirksDeclaration.getPropertyValue(subprop);
122 var standardsub = gDeclaration.getPropertyValue(subprop);
123 isnot(quirksub, "", property + ": " + quirkval +
124 " should be accepted in quirks mode" +
125 " when testing subproperty " + subprop);
126 is(quirksub, standardsub, property + ": " + quirkval + " result" +
127 " when testing subproperty " + subprop);
128 }
129 }
130
131 gQuirksDeclaration.removeProperty(property);
132 gDeclaration.removeProperty(property);
133 }
134 }
135
136 for (var idx in info.unbalanced_values) {
137 check_not_accepted(gDeclaration, property, info,
138 info.invalid_values[idx]);
139 check_not_accepted(gQuirksDeclaration, property, info,
140 info.invalid_values[idx]);
141 check_value_unbalanced(gDeclaration, property,
142 info.unbalanced_values[idx]);
143 }
144 }
145
146 SimpleTest.finish();
147 }
148
149 </script>
150 </pre>
151 </body>
152 </html>

mercurial