|
1 <!DOCTYPE HTML> |
|
2 <html> |
|
3 <!-- |
|
4 https://bugzilla.mozilla.org/show_bug.cgi?id=375363 |
|
5 --> |
|
6 <head> |
|
7 <title>Test for cloning of CSS property values (including 'inherit', 'initial' and 'unset')</title> |
|
8 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
|
9 <script type="text/javascript" src="property_database.js"></script> |
|
10 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> |
|
11 </head> |
|
12 <body> |
|
13 <p id="display"><iframe id="iframe" src="about:blank"></iframe></p> |
|
14 <pre id="test"> |
|
15 <script class="testbody" type="text/javascript"> |
|
16 |
|
17 /** Test for cloning of CSS property values (including 'inherit', 'initial' and 'unset') **/ |
|
18 var gTestUnset = SpecialPowers.getBoolPref("layout.css.unset-value.enabled"); |
|
19 var test_queue = []; |
|
20 var iframe = document.getElementById("iframe"); |
|
21 |
|
22 SimpleTest.waitForExplicitFinish(); |
|
23 |
|
24 for (var prop in gCSSProperties) { |
|
25 var info = gCSSProperties[prop]; |
|
26 |
|
27 test_queue.push({ prop: prop, value: "inherit", |
|
28 inherited_value: info.initial_values[0] }); |
|
29 test_queue.push({ prop: prop, value: "inherit", |
|
30 inherited_value: info.other_values[0] }); |
|
31 test_queue.push({ prop: prop, value: "initial" }); |
|
32 if (gTestUnset) { |
|
33 if (info.inherited) { |
|
34 test_queue.push({ prop: prop, value: "unset", |
|
35 inherited_value: info.initial_values[0] }); |
|
36 test_queue.push({ prop: prop, value: "unset", |
|
37 inherited_value: info.other_values[0] }); |
|
38 } else { |
|
39 test_queue.push({ prop: prop, value: "unset" }); |
|
40 } |
|
41 } |
|
42 for (var idx in info.initial_values) { |
|
43 test_queue.push({ prop: prop, value: info.initial_values[idx] }); |
|
44 } |
|
45 for (var idx in info.other_values) { |
|
46 test_queue.push({ prop: prop, value: info.other_values[idx] }); |
|
47 } |
|
48 } |
|
49 |
|
50 test_queue.reverse(); |
|
51 |
|
52 doTest(); |
|
53 |
|
54 function doTest() |
|
55 { |
|
56 var sheet_data = ""; |
|
57 |
|
58 for (var idx = 0; idx < test_queue.length; ++idx) { |
|
59 var current_item = test_queue[idx]; |
|
60 |
|
61 var info = gCSSProperties[current_item.prop]; |
|
62 |
|
63 sheet_data += "#parent"+idx+", #test"+idx+" { "; |
|
64 for (var prereq in info.prereqs) { |
|
65 sheet_data += prereq + ": " + info.prereqs[prereq] + ";"; |
|
66 } |
|
67 sheet_data += " }"; |
|
68 |
|
69 sheet_data += "#parent"+idx+" { "; |
|
70 if ("inherited_value" in current_item) { |
|
71 sheet_data += current_item.prop + ": " + current_item.inherited_value; |
|
72 } |
|
73 sheet_data += "}"; |
|
74 |
|
75 sheet_data += "#test"+idx+" { "; |
|
76 sheet_data += current_item.prop + ": " + current_item.value; |
|
77 sheet_data += "}"; |
|
78 } |
|
79 |
|
80 var sheet_url = "data:text/css," + escape(sheet_data); |
|
81 |
|
82 var doc_data = |
|
83 "<!DOCTYPE HTML>\n" + |
|
84 "<link rel='stylesheet' type='text/css' href='" + sheet_url + "'>\n" + |
|
85 "<link rel='stylesheet' type='text/css' href='" + sheet_url + "'>\n" + |
|
86 "<body>\n"; |
|
87 |
|
88 |
|
89 for (var idx = 0; idx < test_queue.length; ++idx) { |
|
90 var current_item = test_queue[idx]; |
|
91 |
|
92 if ("inherited_value" in current_item) { |
|
93 doc_data += "<span id='parent"+idx+"'>"; |
|
94 } |
|
95 doc_data += "<span id='test"+idx+"'></span>"; |
|
96 if ("inherited_value" in current_item) { |
|
97 doc_data += "</span>"; |
|
98 } |
|
99 } |
|
100 |
|
101 var doc_url = "data:text/html," + escape(doc_data); |
|
102 iframe.onload = iframe_loaded; |
|
103 iframe.src = doc_url; |
|
104 } |
|
105 |
|
106 function iframe_loaded(event) |
|
107 { |
|
108 if (event.target != iframe) |
|
109 return; |
|
110 |
|
111 var start_ser = []; |
|
112 var start_compute = []; |
|
113 var test_cs = []; |
|
114 var ifdoc = iframe.contentDocument; |
|
115 |
|
116 for (var idx = 0; idx < test_queue.length; ++idx) { |
|
117 var current_item = test_queue[idx]; |
|
118 var info = gCSSProperties[current_item.prop]; |
|
119 |
|
120 var test = ifdoc.getElementById("test" + idx); |
|
121 var cur_cs = iframe.contentWindow.getComputedStyle(test, ""); |
|
122 test_cs.push(cur_cs); |
|
123 var cur_ser = ifdoc.styleSheets[0].cssRules[3*idx+2].style.getPropertyValue(current_item.prop); |
|
124 if (cur_ser == "") { |
|
125 isnot(cur_ser, "", |
|
126 "serialization should be nonempty for " + |
|
127 current_item.prop + ": " + current_item.value); |
|
128 } |
|
129 start_ser.push(cur_ser); |
|
130 |
|
131 var cur_compute; |
|
132 if (!("backend_only" in info)) { |
|
133 cur_compute = get_computed_value(cur_cs, current_item.prop); |
|
134 if (cur_compute == "") { |
|
135 isnot(cur_compute, "", |
|
136 "computed value should be nonempty for " + |
|
137 current_item.prop + ": " + current_item.value); |
|
138 } |
|
139 } else { |
|
140 cur_compute = undefined; |
|
141 } |
|
142 start_compute.push(cur_compute); |
|
143 } |
|
144 |
|
145 // In case the above access didn't force a clone already (though it |
|
146 // currently does), clone the second style sheet's inner and then |
|
147 // remove the first. |
|
148 ifdoc.styleSheets[1].insertRule("#nonexistent { color: red }", 0); |
|
149 var firstlink = ifdoc.getElementsByTagName("link")[0]; |
|
150 firstlink.parentNode.removeChild(firstlink); |
|
151 |
|
152 // Force a flush |
|
153 ifdoc.body.style.display="none"; |
|
154 var ow = ifdoc.body.offsetWidth; |
|
155 ifdoc.body.style.display=""; |
|
156 |
|
157 for (var idx = 0; idx < test_queue.length; ++idx) { |
|
158 var current_item = test_queue[idx]; |
|
159 var info = gCSSProperties[current_item.prop]; |
|
160 |
|
161 var end_ser = |
|
162 ifdoc.styleSheets[0].cssRules[3*idx+3].style.getPropertyValue(current_item.prop); |
|
163 is(end_ser, start_ser[idx], |
|
164 "serialization should match when cloning " + |
|
165 current_item.prop + ": " + current_item.value); |
|
166 |
|
167 if (!("backend_only" in info)) { |
|
168 var end_compute = get_computed_value(test_cs[idx], current_item.prop); |
|
169 // Output computed values only when the test failed. |
|
170 // Computed values may be very long. |
|
171 if (end_compute == start_compute[idx]) { |
|
172 ok(true, |
|
173 "computed values should match when cloning " + |
|
174 current_item.prop + ": " + current_item.value); |
|
175 } else { |
|
176 is(end_compute, start_compute[idx], |
|
177 "computed values should match when cloning " + |
|
178 current_item.prop + ": " + current_item.value); |
|
179 } |
|
180 } |
|
181 } |
|
182 |
|
183 SimpleTest.finish(); |
|
184 } |
|
185 |
|
186 </script> |
|
187 </pre> |
|
188 </body> |
|
189 </html> |