Wed, 31 Dec 2014 13:27:57 +0100
Ignore runtime configuration files generated during quality assurance.
1 <!DOCTYPE HTML>
2 <html>
3 <!--
4 -->
5 <head>
6 <title>Test for computation of CSS 'initial' on all properties and 'unset' on reset properties</title>
7 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
8 <script type="text/javascript" src="property_database.js"></script>
9 <style type="text/css" id="stylesheet"></style>
10 <style type="text/css">
11 /* For 'width', 'height', etc., need a constant size container. */
12 #display { width: 500px; height: 200px }
13 </style>
14 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
15 <script type="text/javascript">
16 SimpleTest.waitForExplicitFinish();
18 var load_count = 0;
19 function load_done() {
20 if (++load_count == 3)
21 run_tests();
22 }
23 </script>
24 </head>
25 <body>
26 <p id="display"><span><span id="elementf"></span></span>
27 <iframe id="unstyledn" src="unstyled.xml" height="10" width="10" onload="load_done()"></iframe>
28 <iframe id="unstyledf" src="unstyled-frame.xml" height="10" width="10" onload="load_done()"></iframe>
29 </p>
30 <div id="content" style="display: none">
32 <div><span id="elementn"></span></div>
35 </div>
36 <pre id="test">
37 <script class="testbody" type="text/javascript">
39 /** Test for computation of CSS 'initial' on all properties and 'unset' on
40 reset properties **/
42 var gBrokenInitial = {
43 };
45 function xfail_initial(property) {
46 return property in gBrokenInitial;
47 }
49 var gElementN = document.getElementById("elementn");
50 var gElementF = document.getElementById("elementf");
51 var gStyleSheet = document.getElementById("stylesheet").sheet;
52 var gRule1 = gStyleSheet.cssRules[gStyleSheet.insertRule("#elementn, #elementf {}", gStyleSheet.cssRules.length)];
53 var gRule2 = gStyleSheet.cssRules[gStyleSheet.insertRule("#elementn, #elementf {}", gStyleSheet.cssRules.length)];
55 var gInitialValuesN;
56 var gInitialValuesF;
57 var gInitialPrereqsRuleN;
58 var gInitialPrereqsRuleF;
60 var gTestUnset = SpecialPowers.getBoolPref("layout.css.unset-value.enabled");
62 function setup_initial_values(id, ivalprop, prereqprop) {
63 var iframe = document.getElementById(id);
64 window[ivalprop] = iframe.contentWindow.getComputedStyle(
65 iframe.contentDocument.documentElement.firstChild, "");
66 var sheet = iframe.contentDocument.styleSheets[0];
67 // For 'width', 'height', etc., need a constant size container.
68 sheet.insertRule(":root { height: 200px; width: 500px }", sheet.cssRules.length);
70 window[prereqprop] = sheet.cssRules[sheet.insertRule(":root > * {}", sheet.cssRules.length)];
71 }
73 function test_property(property)
74 {
75 var info = gCSSProperties[property];
76 if (info.backend_only)
77 return;
79 var keywords = ["initial"];
80 if (!info.inherited && gTestUnset)
81 keywords.push("unset");
83 keywords.forEach(function(keyword) {
84 if ("prerequisites" in info) {
85 var prereqs = info.prerequisites;
86 for (var prereq in prereqs) {
87 gRule1.style.setProperty(prereq, prereqs[prereq], "");
88 gInitialPrereqsRuleN.style.setProperty(prereq, prereqs[prereq], "");
89 gInitialPrereqsRuleF.style.setProperty(prereq, prereqs[prereq], "");
90 }
91 }
92 if (info.inherited) {
93 gElementN.parentNode.style.setProperty(property, info.other_values[0], "");
94 gElementF.parentNode.style.setProperty(property, info.other_values[0], "");
95 }
97 var initial_computed_n = get_computed_value(gInitialValuesN, property);
98 var initial_computed_f = get_computed_value(gInitialValuesF, property);
99 gRule1.style.setProperty(property, info.other_values[0], "");
100 var other_computed_n = get_computed_value(getComputedStyle(gElementN, ""), property);
101 var other_computed_f = get_computed_value(getComputedStyle(gElementF, ""), property);
102 isnot(other_computed_n, initial_computed_n,
103 "should be testing with values that compute to different things " +
104 "for '" + property + "'");
105 isnot(other_computed_f, initial_computed_f,
106 "should be testing with values that compute to different things " +
107 "for '" + property + "'");
108 // It's important (given the current design of nsRuleNode) that we're
109 // modifying the most specific rule that matches the element, and that
110 // we've already requested style while that rule was empty. This
111 // means we'll have a cached aStartStruct from the parent in the rule
112 // tree (caching the "other" value), so we'll make sure we don't get
113 // the initial value from the luck of default-initialization.
114 // This means that it's important that we set the prereqs on
115 // gRule1.style rather than on gElement.style.
116 gRule2.style.setProperty(property, keyword, "");
117 var initial_val_computed_n = get_computed_value(getComputedStyle(gElementN, ""), property);
118 var initial_val_computed_f = get_computed_value(getComputedStyle(gElementF, ""), property);
119 (xfail_initial(property) ? todo_is : is)(
120 initial_val_computed_n, initial_computed_n,
121 keyword + " should cause initial value for '" + property + "'");
122 (xfail_initial(property) ? todo_is : is)(
123 initial_val_computed_f, initial_computed_f,
124 keyword + " should cause initial value for '" + property + "'");
125 gRule1.style.removeProperty(property);
126 gRule2.style.removeProperty(property);
128 if ("prerequisites" in info) {
129 var prereqs = info.prerequisites;
130 for (var prereq in prereqs) {
131 gRule1.style.removeProperty(prereq);
132 gInitialPrereqsRuleN.style.removeProperty(prereq);
133 gInitialPrereqsRuleF.style.removeProperty(prereq);
134 }
135 }
136 if (info.inherited) {
137 gElementN.parentNode.style.removeProperty(property);
138 gElementF.parentNode.style.removeProperty(property);
139 }
141 // FIXME: Something (maybe with the -moz-binding values in
142 // test_value_computation.html, but may as well do it here to match)
143 // causes gElementF's frame to get lost. Force it to get recreated
144 // after each property.
145 gElementF.parentNode.style.display = "none";
146 get_computed_value(getComputedStyle(gElementF, ""), "width");
147 gElementF.parentNode.style.display = "";
148 get_computed_value(getComputedStyle(gElementF, ""), "width");
149 });
150 }
152 function run_tests() {
153 setup_initial_values("unstyledn", "gInitialValuesN", "gInitialPrereqsRuleN");
154 setup_initial_values("unstyledf", "gInitialValuesF", "gInitialPrereqsRuleF");
155 for (var prop in gCSSProperties)
156 test_property(prop);
157 SimpleTest.finish();
158 }
160 load_done();
162 </script>
163 </pre>
164 </body>
165 </html>