|
1 <!DOCTYPE HTML> |
|
2 <html> |
|
3 <!-- |
|
4 --> |
|
5 <head> |
|
6 <title>Test for computation of CSS 'inherit' on all properties and 'unset' on inherited 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 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> |
|
11 </head> |
|
12 <body> |
|
13 <p id="display"><span id="fparent"><span id="fchild"></span></span></p> |
|
14 <div id="content" style="display: none"> |
|
15 |
|
16 <div id="testnode"><span id="nparent"><span id="nchild"></span></span></div> |
|
17 |
|
18 </div> |
|
19 <pre id="test"> |
|
20 <script class="testbody" type="text/javascript"> |
|
21 |
|
22 /** Test for computation of CSS 'inherit' on all properties and 'unset' on |
|
23 inherited properties **/ |
|
24 |
|
25 // elements without a frame |
|
26 var gNParent = document.getElementById("nparent"); |
|
27 var gNChild = document.getElementById("nchild"); |
|
28 // elements with a frame |
|
29 var gFParent = document.getElementById("fparent"); |
|
30 var gFChild = document.getElementById("fchild"); |
|
31 |
|
32 var gStyleSheet = document.getElementById("stylesheet").sheet; |
|
33 var gChildRule1 = gStyleSheet.cssRules[gStyleSheet.insertRule("#nchild, #fchild {}", gStyleSheet.cssRules.length)]; |
|
34 var gChildRule2 = gStyleSheet.cssRules[gStyleSheet.insertRule("#nchild, #fchild {}", gStyleSheet.cssRules.length)]; |
|
35 var gChildRule3 = gStyleSheet.cssRules[gStyleSheet.insertRule("#nchild.allother, #fchild.allother {}", gStyleSheet.cssRules.length)]; |
|
36 var gChildRuleTop = gStyleSheet.cssRules[gStyleSheet.insertRule("#nchild, #nchild.allother, #fchild, #fchild.allother {}", gStyleSheet.cssRules.length)]; |
|
37 var gParentRuleTop = gStyleSheet.cssRules[gStyleSheet.insertRule("#nparent, #fparent {}", gStyleSheet.cssRules.length)]; |
|
38 |
|
39 var gTestUnset = SpecialPowers.getBoolPref("layout.css.unset-value.enabled"); |
|
40 |
|
41 function get_computed_value_node(node, property) |
|
42 { |
|
43 var cs = getComputedStyle(node, ""); |
|
44 return get_computed_value(cs, property); |
|
45 } |
|
46 |
|
47 function test_property(property) |
|
48 { |
|
49 var info = gCSSProperties[property]; |
|
50 if (info.backend_only) |
|
51 return; |
|
52 |
|
53 var keywords = ["inherit"]; |
|
54 if (info.inherited && gTestUnset) |
|
55 keywords.push("unset"); |
|
56 |
|
57 keywords.forEach(function(keyword) { |
|
58 if ("prerequisites" in info) { |
|
59 var prereqs = info.prerequisites; |
|
60 for (var prereq in prereqs) { |
|
61 gParentRuleTop.style.setProperty(prereq, prereqs[prereq], ""); |
|
62 gChildRuleTop.style.setProperty(prereq, prereqs[prereq], ""); |
|
63 } |
|
64 } |
|
65 |
|
66 if (info.inherited) { |
|
67 gParentRuleTop.style.setProperty(property, info.initial_values[0], ""); |
|
68 var initial_computed_n = get_computed_value_node(gNChild, property); |
|
69 var initial_computed_f = get_computed_value_node(gFChild, property); |
|
70 gChildRule1.style.setProperty(property, info.other_values[0], ""); |
|
71 var other_computed_n = get_computed_value_node(gNChild, property); |
|
72 var other_computed_f = get_computed_value_node(gFChild, property); |
|
73 isnot(other_computed_n, initial_computed_n, |
|
74 "should be testing with values that compute to different things " + |
|
75 "for '" + property + "'"); |
|
76 isnot(other_computed_f, initial_computed_f, |
|
77 "should be testing with values that compute to different things " + |
|
78 "for '" + property + "'"); |
|
79 gChildRule3.style.setProperty(property, keyword, ""); |
|
80 gFChild.className="allother"; |
|
81 gNChild.className="allother"; |
|
82 var inherit_initial_computed_n = get_computed_value_node(gNChild, property); |
|
83 var inherit_initial_computed_f = get_computed_value_node(gFChild, property); |
|
84 is(inherit_initial_computed_n, initial_computed_n, |
|
85 keyword + " should cause inheritance of initial value for '" + |
|
86 property + "'"); |
|
87 is(inherit_initial_computed_f, initial_computed_f, |
|
88 keyword + " should cause inheritance of initial value for '" + |
|
89 property + "'"); |
|
90 gParentRuleTop.style.setProperty(property, info.other_values[0], ""); |
|
91 var inherit_other_computed_n = get_computed_value_node(gNChild, property); |
|
92 var inherit_other_computed_f = get_computed_value_node(gFChild, property); |
|
93 is(inherit_other_computed_n, other_computed_n, |
|
94 keyword + " should cause inheritance of other value for '" + |
|
95 property + "'"); |
|
96 is(inherit_other_computed_f, other_computed_f, |
|
97 keyword + " should cause inheritance of other value for '" + |
|
98 property + "'"); |
|
99 gParentRuleTop.style.removeProperty(property); |
|
100 gChildRule1.style.removeProperty(property); |
|
101 gChildRule3.style.setProperty(property, info.other_values[0], ""); |
|
102 gFChild.className=""; |
|
103 gNChild.className=""; |
|
104 } else { |
|
105 gParentRuleTop.style.setProperty(property, info.other_values[0], ""); |
|
106 var initial_computed_n = get_computed_value_node(gNChild, property); |
|
107 var initial_computed_f = get_computed_value_node(gFChild, property); |
|
108 var other_computed_n = get_computed_value_node(gNParent, property); |
|
109 var other_computed_f = get_computed_value_node(gFParent, property); |
|
110 isnot(other_computed_n, initial_computed_n, |
|
111 "should be testing with values that compute to different things " + |
|
112 "for '" + property + "'"); |
|
113 isnot(other_computed_f, initial_computed_f, |
|
114 "should be testing with values that compute to different things " + |
|
115 "for '" + property + "'"); |
|
116 gChildRule2.style.setProperty(property, keyword, ""); |
|
117 var inherit_other_computed_n = get_computed_value_node(gNChild, property); |
|
118 var inherit_other_computed_f = get_computed_value_node(gFChild, property); |
|
119 is(inherit_other_computed_n, other_computed_n, |
|
120 keyword + " should cause inheritance of other value for '" + |
|
121 property + "'"); |
|
122 is(inherit_other_computed_f, other_computed_f, |
|
123 keyword + " should cause inheritance of other value for '" + |
|
124 property + "'"); |
|
125 gParentRuleTop.style.removeProperty(property); |
|
126 gChildRule1.style.setProperty(property, info.other_values[0], ""); |
|
127 var inherit_initial_computed_n = get_computed_value_node(gNChild, property); |
|
128 var inherit_initial_computed_f = get_computed_value_node(gFChild, property); |
|
129 is(inherit_initial_computed_n, initial_computed_n, |
|
130 keyword + " should cause inheritance of initial value for '" + |
|
131 property + "'"); |
|
132 is(inherit_initial_computed_f, initial_computed_f, |
|
133 keyword + " should cause inheritance of initial value for '" + |
|
134 property + "'"); |
|
135 gParentRuleTop.style.removeProperty(property); |
|
136 gChildRule1.style.removeProperty(property); |
|
137 gChildRule2.style.removeProperty(property); |
|
138 } |
|
139 |
|
140 if ("prerequisites" in info) { |
|
141 var prereqs = info.prerequisites; |
|
142 for (var prereq in prereqs) { |
|
143 gParentRuleTop.style.removeProperty(prereq); |
|
144 gChildRuleTop.style.removeProperty(prereq); |
|
145 } |
|
146 } |
|
147 }); |
|
148 } |
|
149 |
|
150 for (var prop in gCSSProperties) { |
|
151 var info = gCSSProperties[prop]; |
|
152 gChildRule3.style.setProperty(prop, info.other_values[0], ""); |
|
153 } |
|
154 |
|
155 for (var prop in gCSSProperties) |
|
156 test_property(prop); |
|
157 |
|
158 </script> |
|
159 </pre> |
|
160 </body> |
|
161 </html> |