Bug 470455 - test_database_sync_embed_visits.js leaks, r=sdwilsh
[wine-gecko.git] / layout / style / test / test_value_computation.html
blob9f871c69f545c290dece971a9c91479ffd45e30d
1 <!DOCTYPE HTML>
2 <html>
3 <!--
4 -->
5 <head>
6 <title>Test for computation of values in property database</title>
7 <script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
8 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
9 <script type="text/javascript" src="property_database.js"></script>
10 <style type="text/css" id="stylesheet"></style>
11 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
12 <script type="text/javascript">
13 SimpleTest.waitForExplicitFinish();
15 var load_count = 0;
16 function load_done() {
17 if (++load_count == 3)
18 run_tests();
20 </script>
21 </head>
22 <body>
23 <p id="display"><span><span id="elementf"></span></span>
24 <iframe id="unstyledn" src="unstyled.xml" height="10" width="10" onload="load_done()"></iframe>
25 <iframe id="unstyledf" src="unstyled-frame.xml" height="10" width="10" onload="load_done()"></iframe>
26 </p>
27 <div id="content" style="display: none">
29 <div><span id="elementn"></span></div>
32 </div>
33 <pre id="test">
34 <script class="testbody" type="text/javascript">
36 /** Test for computation of values in property database **/
38 var gNotAccepted = {
39 "-moz-column-width": [ "50%" ],
40 "list-style": [ "none disc outside" ],
43 var gBadComputed = {
44 // NS_STYLE_COLUMN_COUNT_AUTO is 0
45 "-moz-column-count": [ "0" ],
47 "clip": [ "rect(auto,auto,auto,auto)" ],
49 // The 'medium' keyword should be computing to '3px', not 'medium'.
50 "outline-width": [ "3px" ],
52 // 'normal' should compute to 0
53 "word-spacing": [ "0", "0px", "-0em" ],
55 // These values are treated as auto.
56 "page-break-after": [ "avoid" ],
57 "page-break-before": [ "avoid" ],
59 // These are probably bogus tests...
60 "-moz-outline-radius": [ "0%" ],
61 "-moz-outline-radius-bottomleft": [ "0%" ],
62 "-moz-outline-radius-bottomright": [ "0%" ],
63 "-moz-outline-radius-topleft": [ "0%" ],
64 "-moz-outline-radius-topright": [ "0%" ],
65 // These are probably bogus tests... (why not just when no frame?)
66 "-moz-margin-end": [ "0%" ],
67 "-moz-margin-start": [ "0%" ],
68 "-moz-padding-end": [ "0%" ],
69 "-moz-padding-start": [ "0%" ],
72 var gBadComputedNoFrame = {
73 // These are probably bogus tests...
74 "margin": [ "0% 0px 0em 0pt" ],
75 "margin-bottom": [ "0%" ],
76 "margin-left": [ "0%" ],
77 "margin-right": [ "0%" ],
78 "margin-top": [ "0%" ],
79 "padding": [ "0% 0px 0em 0pt" ],
80 "padding-bottom": [ "0%" ],
81 "padding-left": [ "0%" ],
82 "padding-right": [ "0%" ],
83 "padding-top": [ "0%" ],
86 function xfail_value(property, value, is_initial, has_frame) {
87 if ((property in gNotAccepted) &&
88 gNotAccepted[property].indexOf(value) != -1)
89 return true;
91 if ((property in gBadComputed) &&
92 gBadComputed[property].indexOf(value) != -1)
93 return true;
95 if (!has_frame && (property in gBadComputedNoFrame) &&
96 gBadComputedNoFrame[property].indexOf(value) != -1)
97 return true;
99 return false;
102 var gElementN = document.getElementById("elementn");
103 var gElementF = document.getElementById("elementf");
104 var gStyleSheet = document.getElementById("stylesheet").sheet;
105 var gRule1 = gStyleSheet.cssRules[gStyleSheet.insertRule("#elementn, #elementf {}", gStyleSheet.cssRules.length)];
106 var gRule2 = gStyleSheet.cssRules[gStyleSheet.insertRule("#elementn, #elementf {}", gStyleSheet.cssRules.length)];
108 var gInitialValuesN;
109 var gInitialValuesF;
110 var gInitialPrereqsRuleN;
111 var gInitialPrereqsRuleF;
113 function setup_initial_values(id, ivalprop, prereqprop) {
114 var iframe = document.getElementById(id);
115 window[ivalprop] = iframe.contentWindow.getComputedStyle(
116 iframe.contentDocument.documentElement.firstChild, "");
117 var sheet = iframe.contentDocument.styleSheets[0];
118 window[prereqprop] = sheet.cssRules[sheet.insertRule(":root > * {}", sheet.cssRules.length)];
121 function test_value(property, val, is_initial)
123 var info = gCSSProperties[property];
124 if (info.backend_only)
125 return;
127 if ("prerequisites" in info) {
128 var prereqs = info.prerequisites;
129 for (var prereq in prereqs) {
130 gRule1.style.setProperty(prereq, prereqs[prereq], "");
131 gInitialPrereqsRuleN.style.setProperty(prereq, prereqs[prereq], "");
132 gInitialPrereqsRuleF.style.setProperty(prereq, prereqs[prereq], "");
135 if (info.inherited && is_initial) {
136 gElementN.parentNode.style.setProperty(property, info.other_values[0], "");
137 gElementF.parentNode.style.setProperty(property, info.other_values[0], "");
140 var initial_computed_n = get_computed_value(gInitialValuesN, property);
141 var initial_computed_f = get_computed_value(gInitialValuesF, property);
142 if (is_initial) {
143 gRule1.style.setProperty(property, info.other_values[0], "");
144 var other_computed_n = get_computed_value(getComputedStyle(gElementN, ""), property);
145 var other_computed_f = get_computed_value(getComputedStyle(gElementF, ""), property);
146 isnot(other_computed_n, initial_computed_n,
147 "should be testing with values that compute to different things " +
148 "for '" + property + "'");
149 isnot(other_computed_f, initial_computed_f,
150 "should be testing with values that compute to different things " +
151 "for '" + property + "'");
153 // It's important for values that are supposed to compute to the
154 // initial value (given the current design of nsRuleNode) that we're
155 // modifying the most specific rule that matches the element, and that
156 // we've already requested style while that rule was empty. This
157 // means we'll have a cached aStartStruct from the parent in the rule
158 // tree (caching the "other" value), so we'll make sure we don't get
159 // the initial value from the luck of default-initialization.
160 // This means that it's important that we set the prereqs on
161 // gRule1.style rather than on gElement.style.
162 gRule2.style.setProperty(property, val, "");
163 var val_computed_n = get_computed_value(getComputedStyle(gElementN, ""), property);
164 var val_computed_f = get_computed_value(getComputedStyle(gElementF, ""), property);
165 isnot(val_computed_n, "",
166 "should not get empty value for '" + property + ":" + val + "'");
167 isnot(val_computed_f, "",
168 "should not get empty value for '" + property + ":" + val + "'");
169 if (is_initial) {
170 (xfail_value(property, val, is_initial, false) ? todo_is : is)(
171 val_computed_n, initial_computed_n,
172 "should get initial value for '" + property + ":" + val + "'");
173 (xfail_value(property, val, is_initial, true) ? todo_is : is)(
174 val_computed_f, initial_computed_f,
175 "should get initial value for '" + property + ":" + val + "'");
176 } else {
177 (xfail_value(property, val, is_initial, false) ? todo_isnot : isnot)(
178 val_computed_n, initial_computed_n,
179 "should not get initial value for '" + property + ":" + val + "'");
180 (xfail_value(property, val, is_initial, true) ? todo_isnot : isnot)(
181 val_computed_f, initial_computed_f,
182 "should not get initial value for '" + property + ":" + val + "'");
184 if (is_initial)
185 gRule1.style.removeProperty(property);
186 gRule2.style.removeProperty(property);
188 if ("prerequisites" in info) {
189 var prereqs = info.prerequisites;
190 for (var prereq in prereqs) {
191 gRule1.style.removeProperty(prereq);
192 gInitialPrereqsRuleN.style.removeProperty(prereq);
193 gInitialPrereqsRuleF.style.removeProperty(prereq);
196 if (info.inherited && is_initial) {
197 gElementN.parentNode.style.removeProperty(property);
198 gElementF.parentNode.style.removeProperty(property);
202 function test_property(prop) {
203 var info = gCSSProperties[prop];
204 for (var idx in info.initial_values)
205 test_value(prop, info.initial_values[idx], true);
206 for (var idx in info.other_values)
207 test_value(prop, info.other_values[idx], false);
210 function run_tests() {
211 setup_initial_values("unstyledn", "gInitialValuesN", "gInitialPrereqsRuleN");
212 setup_initial_values("unstyledf", "gInitialValuesF", "gInitialPrereqsRuleF");
213 var props = [];
214 for (var prop in gCSSProperties)
215 props.push(prop);
216 props = props.reverse();
217 function do_one(l) {
218 if (l.length == 0) {
219 // SimpleTest.finish() is really slow, so we have to disable the
220 // slow script dialog for this part
221 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
222 var prefService = Components.classes["@mozilla.org/preferences-service;1"].
223 getService(Components.interfaces.nsIPrefService);
224 var domBranch = prefService.getBranch("dom.");
225 var oldVal = domBranch.getIntPref("max_script_run_time");
226 domBranch.setIntPref("max_script_run_time", 0);
228 SimpleTest.finish();
230 domBranch.setIntPref("max_script_run_time", oldVal);
232 return;
234 test_property(l.pop());
235 setTimeout(do_one, 0, l);
237 setTimeout(do_one, 0, props);
240 load_done();
242 </script>
243 </pre>
244 </body>
245 </html>