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();
16 function load_done() {
17 if (++load_count
== 3)
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>
27 <div id=
"content" style=
"display: none">
29 <div><span id=
"elementn"></span></div>
34 <script class=
"testbody" type=
"text/javascript">
36 /** Test for computation of values in property database **/
39 "-moz-column-width": [
"50%" ],
40 "list-style": [
"none disc outside" ],
44 // NS_STYLE_COLUMN_COUNT_AUTO is
0
45 "-moz-column-count": [
"0" ],
47 "clip": [
"rect(auto,auto,auto,auto)" ],
49 // No idea what's happening for these two either
50 "border-top": [
"thin" ],
51 "border-right": [
"thin" ],
52 "border-bottom": [
"thin" ],
53 "border-left": [
"thin" ],
54 "-moz-border-start": [
"thin" ],
55 "-moz-border-end": [
"thin" ],
56 "outline-width": [
"3px" ],
58 // 'normal' should compute to
0
59 "word-spacing": [
"0",
"0px",
"-0em" ],
61 // These values are treated as auto.
62 "page-break-after": [
"avoid" ],
63 "page-break-before": [
"avoid" ],
65 // These are probably bogus tests...
66 "-moz-outline-radius": [
"0%" ],
67 "-moz-outline-radius-bottomleft": [
"0%" ],
68 "-moz-outline-radius-bottomright": [
"0%" ],
69 "-moz-outline-radius-topleft": [
"0%" ],
70 "-moz-outline-radius-topright": [
"0%" ],
71 // These are probably bogus tests... (why not just when no frame?)
72 "-moz-margin-end": [
"0%" ],
73 "-moz-margin-start": [
"0%" ],
74 "-moz-padding-end": [
"0%" ],
75 "-moz-padding-start": [
"0%" ],
78 var gBadComputedNoFrame = {
79 // These are probably bogus tests...
80 "margin": [
"0% 0px 0em 0pt" ],
81 "margin-bottom": [
"0%" ],
82 "margin-left": [
"0%" ],
83 "margin-right": [
"0%" ],
84 "margin-top": [
"0%" ],
85 "padding": [
"0% 0px 0em 0pt" ],
86 "padding-bottom": [
"0%" ],
87 "padding-left": [
"0%" ],
88 "padding-right": [
"0%" ],
89 "padding-top": [
"0%" ],
92 function xfail_value(property, value, is_initial, has_frame) {
93 if ((property in gNotAccepted) &&
94 gNotAccepted[property].indexOf(value) != -
1)
97 if ((property in gBadComputed) &&
98 gBadComputed[property].indexOf(value) != -
1)
101 if (!has_frame && (property in gBadComputedNoFrame) &&
102 gBadComputedNoFrame[property].indexOf(value) != -
1)
108 var gElementN = document.getElementById(
"elementn");
109 var gElementF = document.getElementById(
"elementf");
110 var gStyleSheet = document.getElementById(
"stylesheet").sheet;
111 var gRule1 = gStyleSheet.cssRules[gStyleSheet.insertRule(
"#elementn, #elementf {}", gStyleSheet.cssRules.length)];
112 var gRule2 = gStyleSheet.cssRules[gStyleSheet.insertRule(
"#elementn, #elementf {}", gStyleSheet.cssRules.length)];
116 var gInitialPrereqsRuleN;
117 var gInitialPrereqsRuleF;
119 function setup_initial_values(id, ivalprop, prereqprop) {
120 var iframe = document.getElementById(id);
121 window[ivalprop] = iframe.contentWindow.getComputedStyle(
122 iframe.contentDocument.documentElement.firstChild,
"");
123 var sheet = iframe.contentDocument.styleSheets[
0];
124 window[prereqprop] = sheet.cssRules[sheet.insertRule(
":root > * {}", sheet.cssRules.length)];
127 function test_value(property, val, is_initial)
129 var info = gCSSProperties[property];
130 if (info.backend_only)
133 if (
"prerequisites" in info) {
134 var prereqs = info.prerequisites;
135 for (var prereq in prereqs) {
136 gRule1.style.setProperty(prereq, prereqs[prereq],
"");
137 gInitialPrereqsRuleN.style.setProperty(prereq, prereqs[prereq],
"");
138 gInitialPrereqsRuleF.style.setProperty(prereq, prereqs[prereq],
"");
141 if (info.inherited && is_initial) {
142 gElementN.parentNode.style.setProperty(property, info.other_values[
0],
"");
143 gElementF.parentNode.style.setProperty(property, info.other_values[
0],
"");
146 var initial_computed_n = get_computed_value(gInitialValuesN, property);
147 var initial_computed_f = get_computed_value(gInitialValuesF, property);
149 gRule1.style.setProperty(property, info.other_values[
0],
"");
150 var other_computed_n = get_computed_value(getComputedStyle(gElementN,
""), property);
151 var other_computed_f = get_computed_value(getComputedStyle(gElementF,
""), property);
152 isnot(other_computed_n, initial_computed_n,
153 "should be testing with values that compute to different things " +
154 "for '" + property +
"'");
155 isnot(other_computed_f, initial_computed_f,
156 "should be testing with values that compute to different things " +
157 "for '" + property +
"'");
159 // It's important for values that are supposed to compute to the
160 // initial value (given the current design of nsRuleNode) that we're
161 // modifying the most specific rule that matches the element, and that
162 // we've already requested style while that rule was empty. This
163 // means we'll have a cached aStartStruct from the parent in the rule
164 // tree (caching the
"other" value), so we'll make sure we don't get
165 // the initial value from the luck of default-initialization.
166 // This means that it's important that we set the prereqs on
167 // gRule1.style rather than on gElement.style.
168 gRule2.style.setProperty(property, val,
"");
169 var val_computed_n = get_computed_value(getComputedStyle(gElementN,
""), property);
170 var val_computed_f = get_computed_value(getComputedStyle(gElementF,
""), property);
171 isnot(val_computed_n,
"",
172 "should not get empty value for '" + property +
":" + val +
"'");
173 isnot(val_computed_f,
"",
174 "should not get empty value for '" + property +
":" + val +
"'");
176 (xfail_value(property, val, is_initial, false) ? todo_is : is)(
177 val_computed_n, initial_computed_n,
178 "should get initial value for '" + property +
":" + val +
"'");
179 (xfail_value(property, val, is_initial, true) ? todo_is : is)(
180 val_computed_f, initial_computed_f,
181 "should get initial value for '" + property +
":" + val +
"'");
183 (xfail_value(property, val, is_initial, false) ? todo_isnot : isnot)(
184 val_computed_n, initial_computed_n,
185 "should not get initial value for '" + property +
":" + val +
"'");
186 (xfail_value(property, val, is_initial, true) ? todo_isnot : isnot)(
187 val_computed_f, initial_computed_f,
188 "should not get initial value for '" + property +
":" + val +
"'");
191 gRule1.style.removeProperty(property);
192 gRule2.style.removeProperty(property);
194 if (
"prerequisites" in info) {
195 var prereqs = info.prerequisites;
196 for (var prereq in prereqs) {
197 gRule1.style.removeProperty(prereq);
198 gInitialPrereqsRuleN.style.removeProperty(prereq);
199 gInitialPrereqsRuleF.style.removeProperty(prereq);
202 if (info.inherited && is_initial) {
203 gElementN.parentNode.style.removeProperty(property);
204 gElementF.parentNode.style.removeProperty(property);
208 function test_property(prop) {
209 var info = gCSSProperties[prop];
210 for (var idx in info.initial_values)
211 test_value(prop, info.initial_values[idx], true);
212 for (var idx in info.other_values)
213 test_value(prop, info.other_values[idx], false);
216 function run_tests() {
217 setup_initial_values(
"unstyledn",
"gInitialValuesN",
"gInitialPrereqsRuleN");
218 setup_initial_values(
"unstyledf",
"gInitialValuesF",
"gInitialPrereqsRuleF");
220 for (var prop in gCSSProperties)
222 props = props.reverse();
225 // SimpleTest.finish() is really slow, so we have to disable the
226 // slow script dialog for this part
227 netscape.security.PrivilegeManager.enablePrivilege(
"UniversalXPConnect");
228 var prefService = Components.classes[
"@mozilla.org/preferences-service;1"].
229 getService(Components.interfaces.nsIPrefService);
230 var domBranch = prefService.getBranch(
"dom.");
231 var oldVal = domBranch.getIntPref(
"max_script_run_time");
232 domBranch.setIntPref(
"max_script_run_time",
0);
236 domBranch.setIntPref(
"max_script_run_time", oldVal);
240 test_property(l.pop());
241 setTimeout(do_one,
0, l);
243 setTimeout(do_one,
0, props);