|
1 <!DOCTYPE HTML> |
|
2 <html> |
|
3 <!-- |
|
4 https://bugzilla.mozilla.org/show_bug.cgi?id=73586 |
|
5 --> |
|
6 <head> |
|
7 <title>Test for Bug 73586</title> |
|
8 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
|
9 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> |
|
10 <style type="text/css"> |
|
11 |
|
12 span { background: white; color: black; border: medium solid black; } |
|
13 |
|
14 </style> |
|
15 </head> |
|
16 <body> |
|
17 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=73586">Mozilla Bug 73586</a> |
|
18 <div id="display"></div> |
|
19 |
|
20 <div id="content" style="display: none"> |
|
21 |
|
22 </div> |
|
23 <pre id="test"> |
|
24 <script class="testbody" type="text/javascript"> |
|
25 |
|
26 /** Test for Bug 73586 **/ |
|
27 |
|
28 const GREEN = "rgb(0, 128, 0)"; |
|
29 const LIME = "rgb(0, 255, 0)"; |
|
30 const BLACK = "rgb(0, 0, 0)"; |
|
31 const WHITE = "rgb(255, 255, 255)"; |
|
32 |
|
33 function cs(elt) { return getComputedStyle(elt, ""); } |
|
34 |
|
35 function check_children(p, check_cb) { |
|
36 var len = p.childNodes.length; |
|
37 var elts = 0; |
|
38 var i, elt, child; |
|
39 for (i = 0; i < len; ++i) { |
|
40 if (p.childNodes[i].nodeType == Node.ELEMENT_NODE) |
|
41 ++elts; |
|
42 } |
|
43 |
|
44 elt = 0; |
|
45 for (i = 0; i < len; ++i) { |
|
46 child = p.childNodes[i]; |
|
47 if (child.nodeType != Node.ELEMENT_NODE) |
|
48 continue; |
|
49 check_cb(child, elt, elts, i, len); |
|
50 ++elt; |
|
51 } |
|
52 } |
|
53 |
|
54 var display = document.getElementById("display"); |
|
55 |
|
56 function run_series(check_cb) { |
|
57 var display = document.getElementById("display"); |
|
58 // Use a new parent node every time since the optimizations cause |
|
59 // bits to be set (permanently) on the parent. |
|
60 var p = document.createElement("p"); |
|
61 display.appendChild(p); |
|
62 p.innerHTML = "x<span></span><span></span>"; |
|
63 |
|
64 check_children(p, check_cb); |
|
65 var text = p.removeChild(p.childNodes[0]); |
|
66 check_children(p, check_cb); |
|
67 var span = p.removeChild(p.childNodes[0]); |
|
68 check_children(p, check_cb); |
|
69 p.appendChild(span); |
|
70 check_children(p, check_cb); |
|
71 p.removeChild(span); |
|
72 check_children(p, check_cb); |
|
73 p.insertBefore(span, p.childNodes[0]); |
|
74 check_children(p, check_cb); |
|
75 p.removeChild(span); |
|
76 check_children(p, check_cb); |
|
77 p.insertBefore(span, null); |
|
78 check_children(p, check_cb); |
|
79 p.appendChild(document.createElement("span")); |
|
80 check_children(p, check_cb); |
|
81 p.insertBefore(document.createElement("span"), p.childNodes[2]); |
|
82 check_children(p, check_cb); |
|
83 p.appendChild(text); |
|
84 check_children(p, check_cb); |
|
85 |
|
86 display.removeChild(p); |
|
87 } |
|
88 |
|
89 var style = document.createElement("style"); |
|
90 style.setAttribute("type", "text/css"); |
|
91 var styleText = document.createTextNode(""); |
|
92 style.appendChild(styleText); |
|
93 document.getElementsByTagName("head")[0].appendChild(style); |
|
94 |
|
95 styleText.data = "span:first-child { background: lime; }"; |
|
96 run_series(function(child, elt, elts, node, nodes) { |
|
97 is(cs(child).backgroundColor, (elt == 0) ? LIME : WHITE, |
|
98 "child " + node + " should " + ((elt == 0) ? "" : "NOT ") + |
|
99 " match :first-child"); |
|
100 }); |
|
101 |
|
102 styleText.data = "span:last-child { color: green; }"; |
|
103 run_series(function(child, elt, elts, node, nodes) { |
|
104 is(cs(child).color, (elt == elts - 1) ? GREEN : BLACK, |
|
105 "child " + node + " should " + ((elt == elts - 1) ? "" : "NOT ") + |
|
106 " match :last-child"); |
|
107 }); |
|
108 |
|
109 styleText.data = "span:only-child { border: medium solid green; }"; |
|
110 run_series(function(child, elt, elts, node, nodes) { |
|
111 is(cs(child).borderTopColor, (elts == 1) ? GREEN : BLACK, |
|
112 "child " + node + " should " + ((elts == 1) ? "" : "NOT ") + |
|
113 " match :only-child"); |
|
114 }); |
|
115 |
|
116 styleText.data = "span:-moz-first-node { text-decoration: underline; }"; |
|
117 run_series(function(child, elt, elts, node, nodes) { |
|
118 is(cs(child).textDecoration, (node == 0) ? "underline" : "none", |
|
119 "child " + node + " should " + ((node == 0) ? "" : "NOT ") + |
|
120 " match :-moz-first-node"); |
|
121 }); |
|
122 |
|
123 styleText.data = "span:-moz-last-node { visibility: hidden; }"; |
|
124 run_series(function(child, elt, elts, node, nodes) { |
|
125 is(cs(child).visibility, (node == nodes - 1) ? "hidden" : "visible", |
|
126 "child " + node + " should " + ((node == nodes - 1) ? "" : "NOT ") + |
|
127 " match :-moz-last-node"); |
|
128 }); |
|
129 |
|
130 styleText.data = "span:nth-child(1) { background: lime; }"; |
|
131 run_series(function(child, elt, elts, node, nodes) { |
|
132 var matches = elt == 0; |
|
133 is(cs(child).backgroundColor, matches ? LIME : WHITE, |
|
134 "child " + node + " should " + (matches ? "" : "NOT ") + |
|
135 " match " + styleText.data); |
|
136 }); |
|
137 |
|
138 styleText.data = "span:nth-last-child(0n+2) { color: green; }"; |
|
139 run_series(function(child, elt, elts, node, nodes) { |
|
140 var matches = (elt == elts - 2); |
|
141 is(cs(child).color, matches ? GREEN : BLACK, |
|
142 "child " + node + " should " + (matches ? "" : "NOT ") + |
|
143 " match " + styleText.data); |
|
144 }); |
|
145 |
|
146 styleText.data = "span:nth-of-type(2n+3) { color: green; }"; |
|
147 run_series(function(child, elt, elts, node, nodes) { |
|
148 var nidx = elt + 1; |
|
149 var matches = nidx % 2 == 1 && nidx >= 3; |
|
150 is(cs(child).color, matches ? GREEN : BLACK, |
|
151 "child " + node + " should " + (matches ? "" : "NOT ") + |
|
152 " match " + styleText.data); |
|
153 }); |
|
154 |
|
155 styleText.data = "span:nth-last-of-type(-2n+5) { color: green; }"; |
|
156 run_series(function(child, elt, elts, node, nodes) { |
|
157 var nlidx = elts - elt; |
|
158 var matches = nlidx % 2 == 1 && nlidx <= 5; |
|
159 is(cs(child).color, matches ? GREEN : BLACK, |
|
160 "child " + node + " should " + (matches ? "" : "NOT ") + |
|
161 " match " + styleText.data); |
|
162 }); |
|
163 |
|
164 styleText.data = "span:first-of-type { color: green; }"; |
|
165 run_series(function(child, elt, elts, node, nodes) { |
|
166 var matches = (elt == 0); |
|
167 is(cs(child).color, matches ? GREEN : BLACK, |
|
168 "child " + node + " should " + (matches ? "" : "NOT ") + |
|
169 " match " + styleText.data); |
|
170 }); |
|
171 |
|
172 styleText.data = "span:last-of-type { color: green; }"; |
|
173 run_series(function(child, elt, elts, node, nodes) { |
|
174 var matches = (elt == elts - 1); |
|
175 is(cs(child).color, matches ? GREEN : BLACK, |
|
176 "child " + node + " should " + (matches ? "" : "NOT ") + |
|
177 " match " + styleText.data); |
|
178 }); |
|
179 |
|
180 styleText.data = "span:only-of-type { color: green; }"; |
|
181 run_series(function(child, elt, elts, node, nodes) { |
|
182 var matches = elts == 1; |
|
183 is(cs(child).color, matches ? GREEN : BLACK, |
|
184 "child " + node + " should " + (matches ? "" : "NOT ") + |
|
185 " match " + styleText.data); |
|
186 }); |
|
187 |
|
188 </script> |
|
189 </pre> |
|
190 </body> |
|
191 </html> |
|
192 |