Bug 470455 - test_database_sync_embed_visits.js leaks, r=sdwilsh
[wine-gecko.git] / layout / style / test / test_initial_computation.html
blob30f5e69a10da58700536603993e2f1e79c5e3299
1 <!DOCTYPE HTML>
2 <html>
3 <!--
4 -->
5 <head>
6 <title>Test for computation of CSS '-moz-initial'</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 CSS '-moz-initial' **/
38 var gBrokenInitial = {
41 function xfail_initial(property) {
42 return property in gBrokenInitial;
45 var gElementN = document.getElementById("elementn");
46 var gElementF = document.getElementById("elementf");
47 var gStyleSheet = document.getElementById("stylesheet").sheet;
48 var gRule1 = gStyleSheet.cssRules[gStyleSheet.insertRule("#elementn, #elementf {}", gStyleSheet.cssRules.length)];
49 var gRule2 = gStyleSheet.cssRules[gStyleSheet.insertRule("#elementn, #elementf {}", gStyleSheet.cssRules.length)];
51 var gInitialValuesN;
52 var gInitialValuesF;
53 var gInitialPrereqsRuleN;
54 var gInitialPrereqsRuleF;
56 function setup_initial_values(id, ivalprop, prereqprop) {
57 var iframe = document.getElementById(id);
58 window[ivalprop] = iframe.contentWindow.getComputedStyle(
59 iframe.contentDocument.documentElement.firstChild, "");
60 var sheet = iframe.contentDocument.styleSheets[0];
61 window[prereqprop] = sheet.cssRules[sheet.insertRule(":root > * {}", sheet.cssRules.length)];
64 function test_property(property)
66 var info = gCSSProperties[property];
67 if (info.backend_only)
68 return;
70 if ("prerequisites" in info) {
71 var prereqs = info.prerequisites;
72 for (var prereq in prereqs) {
73 gRule1.style.setProperty(prereq, prereqs[prereq], "");
74 gInitialPrereqsRuleN.style.setProperty(prereq, prereqs[prereq], "");
75 gInitialPrereqsRuleF.style.setProperty(prereq, prereqs[prereq], "");
78 if (info.inherited) {
79 gElementN.parentNode.style.setProperty(property, info.other_values[0], "");
80 gElementF.parentNode.style.setProperty(property, info.other_values[0], "");
83 var initial_computed_n = get_computed_value(gInitialValuesN, property);
84 var initial_computed_f = get_computed_value(gInitialValuesF, property);
85 gRule1.style.setProperty(property, info.other_values[0], "");
86 var other_computed_n = get_computed_value(getComputedStyle(gElementN, ""), property);
87 var other_computed_f = get_computed_value(getComputedStyle(gElementF, ""), property);
88 isnot(other_computed_n, initial_computed_n,
89 "should be testing with values that compute to different things " +
90 "for '" + property + "'");
91 isnot(other_computed_f, initial_computed_f,
92 "should be testing with values that compute to different things " +
93 "for '" + property + "'");
94 // It's important (given the current design of nsRuleNode) that we're
95 // modifying the most specific rule that matches the element, and that
96 // we've already requested style while that rule was empty. This
97 // means we'll have a cached aStartStruct from the parent in the rule
98 // tree (caching the "other" value), so we'll make sure we don't get
99 // the initial value from the luck of default-initialization.
100 // This means that it's important that we set the prereqs on
101 // gRule1.style rather than on gElement.style.
102 gRule2.style.setProperty(property, "-moz-initial", "");
103 var initial_val_computed_n = get_computed_value(getComputedStyle(gElementN, ""), property);
104 var initial_val_computed_f = get_computed_value(getComputedStyle(gElementF, ""), property);
105 (xfail_initial(property) ? todo_is : is)(
106 initial_val_computed_n, initial_computed_n,
107 "-moz-initial should cause initial value for '" + property + "'");
108 (xfail_initial(property) ? todo_is : is)(
109 initial_val_computed_f, initial_computed_f,
110 "-moz-initial should cause initial value for '" + property + "'");
111 gRule1.style.removeProperty(property);
112 gRule2.style.removeProperty(property);
114 if ("prerequisites" in info) {
115 var prereqs = info.prerequisites;
116 for (var prereq in prereqs) {
117 gRule1.style.removeProperty(prereq);
118 gInitialPrereqsRuleN.style.removeProperty(prereq);
119 gInitialPrereqsRuleF.style.removeProperty(prereq);
122 if (info.inherited) {
123 gElementN.parentNode.style.removeProperty(property);
124 gElementF.parentNode.style.removeProperty(property);
128 function run_tests() {
129 setup_initial_values("unstyledn", "gInitialValuesN", "gInitialPrereqsRuleN");
130 setup_initial_values("unstyledf", "gInitialValuesF", "gInitialPrereqsRuleF");
131 for (var prop in gCSSProperties)
132 test_property(prop);
133 SimpleTest.finish();
136 load_done();
138 </script>
139 </pre>
140 </body>
141 </html>