4 https://bugzilla.mozilla.org/show_bug.cgi?id=73586
7 <title>Test for Bug
73586</title>
8 <script type=
"text/javascript" src=
"/MochiKit/MochiKit.js"></script>
9 <script type=
"text/javascript" src=
"/tests/SimpleTest/SimpleTest.js"></script>
10 <link rel=
"stylesheet" type=
"text/css" href=
"/tests/SimpleTest/test.css" />
11 <style type=
"text/css">
13 span
{ background: white
; color: black
; border: medium solid black
; }
18 <a target=
"_blank" href=
"https://bugzilla.mozilla.org/show_bug.cgi?id=73586">Mozilla Bug
73586</a>
19 <div id=
"display"></div>
21 <div id=
"content" style=
"display: none">
25 <script class=
"testbody" type=
"text/javascript">
27 /** Test for Bug
73586 **/
29 const GREEN =
"rgb(0, 128, 0)";
30 const LIME =
"rgb(0, 255, 0)";
31 const BLACK =
"rgb(0, 0, 0)";
32 const WHITE =
"rgb(255, 255, 255)";
34 function cs(elt) { return getComputedStyle(elt,
""); }
36 function check_children(p, check_cb) {
37 var len = p.childNodes.length;
40 for (i =
0; i < len; ++i) {
41 if (p.childNodes[i].nodeType == Node.ELEMENT_NODE)
46 for (i =
0; i < len; ++i) {
47 child = p.childNodes[i];
48 if (child.nodeType != Node.ELEMENT_NODE)
50 check_cb(child, elt, elts, i, len);
55 var display = document.getElementById(
"display");
57 function run_series(check_cb) {
58 var display = document.getElementById(
"display");
59 // Use a new parent node every time since the optimizations cause
60 // bits to be set (permanently) on the parent.
61 var p = document.createElement(
"p");
62 display.appendChild(p);
63 p.innerHTML =
"x<span></span><span></span>";
65 check_children(p, check_cb);
66 var text = p.removeChild(p.childNodes[
0]);
67 check_children(p, check_cb);
68 var span = p.removeChild(p.childNodes[
0]);
69 check_children(p, check_cb);
71 check_children(p, check_cb);
73 check_children(p, check_cb);
74 p.insertBefore(span, p.childNodes[
0]);
75 check_children(p, check_cb);
77 check_children(p, check_cb);
78 p.insertBefore(span, null);
79 check_children(p, check_cb);
80 p.appendChild(document.createElement(
"span"));
81 check_children(p, check_cb);
82 p.insertBefore(document.createElement(
"span"), p.childNodes[
2]);
83 check_children(p, check_cb);
85 check_children(p, check_cb);
87 display.removeChild(p);
90 var style = document.createElement(
"style");
91 style.setAttribute(
"type",
"text/css");
92 var styleText = document.createTextNode(
"");
93 style.appendChild(styleText);
94 document.getElementsByTagName(
"head")[
0].appendChild(style);
96 styleText.data =
"span:first-child { background: lime; }";
97 run_series(function(child, elt, elts, node, nodes) {
98 is(cs(child).backgroundColor, (elt ==
0) ? LIME : WHITE,
99 "child " + node +
" should " + ((elt ==
0) ?
"" :
"NOT ") +
100 " match :first-child");
103 styleText.data =
"span:last-child { color: green; }";
104 run_series(function(child, elt, elts, node, nodes) {
105 is(cs(child).color, (elt == elts -
1) ? GREEN : BLACK,
106 "child " + node +
" should " + ((elt == elts -
1) ?
"" :
"NOT ") +
107 " match :last-child");
110 styleText.data =
"span:only-child { border: medium solid green; }";
111 run_series(function(child, elt, elts, node, nodes) {
112 is(cs(child).borderTopColor, (elts ==
1) ? GREEN : BLACK,
113 "child " + node +
" should " + ((elts ==
1) ?
"" :
"NOT ") +
114 " match :only-child");
117 styleText.data =
"span:-moz-first-node { text-decoration: underline; }";
118 run_series(function(child, elt, elts, node, nodes) {
119 is(cs(child).textDecoration, (node ==
0) ?
"underline" :
"none",
120 "child " + node +
" should " + ((node ==
0) ?
"" :
"NOT ") +
121 " match :-moz-first-node");
124 styleText.data =
"span:-moz-last-node { visibility: hidden; }";
125 run_series(function(child, elt, elts, node, nodes) {
126 is(cs(child).visibility, (node == nodes -
1) ?
"hidden" :
"visible",
127 "child " + node +
" should " + ((node == nodes -
1) ?
"" :
"NOT ") +
128 " match :-moz-last-node");
131 styleText.data =
"span:nth-child(1) { background: lime; }";
132 run_series(function(child, elt, elts, node, nodes) {
133 var matches = elt ==
0;
134 is(cs(child).backgroundColor, matches ? LIME : WHITE,
135 "child " + node +
" should " + (matches ?
"" :
"NOT ") +
136 " match " + styleText.data);
139 styleText.data =
"span:nth-last-child(0n+2) { color: green; }";
140 run_series(function(child, elt, elts, node, nodes) {
141 var matches = (elt == elts -
2);
142 is(cs(child).color, matches ? GREEN : BLACK,
143 "child " + node +
" should " + (matches ?
"" :
"NOT ") +
144 " match " + styleText.data);
147 styleText.data =
"span:nth-of-type(2n+3) { color: green; }";
148 run_series(function(child, elt, elts, node, nodes) {
150 var matches = nidx %
2 ==
1 && nidx
>=
3;
151 is(cs(child).color, matches ? GREEN : BLACK,
152 "child " + node +
" should " + (matches ?
"" :
"NOT ") +
153 " match " + styleText.data);
156 styleText.data =
"span:nth-last-of-type(-2n+5) { color: green; }";
157 run_series(function(child, elt, elts, node, nodes) {
158 var nlidx = elts - elt;
159 var matches = nlidx %
2 ==
1 && nlidx <=
5;
160 is(cs(child).color, matches ? GREEN : BLACK,
161 "child " + node +
" should " + (matches ?
"" :
"NOT ") +
162 " match " + styleText.data);
165 styleText.data =
"span:first-of-type { color: green; }";
166 run_series(function(child, elt, elts, node, nodes) {
167 var matches = (elt ==
0);
168 is(cs(child).color, matches ? GREEN : BLACK,
169 "child " + node +
" should " + (matches ?
"" :
"NOT ") +
170 " match " + styleText.data);
173 styleText.data =
"span:last-of-type { color: green; }";
174 run_series(function(child, elt, elts, node, nodes) {
175 var matches = (elt == elts -
1);
176 is(cs(child).color, matches ? GREEN : BLACK,
177 "child " + node +
" should " + (matches ?
"" :
"NOT ") +
178 " match " + styleText.data);
181 styleText.data =
"span:only-of-type { color: green; }";
182 run_series(function(child, elt, elts, node, nodes) {
183 var matches = elts ==
1;
184 is(cs(child).color, matches ? GREEN : BLACK,
185 "child " + node +
" should " + (matches ?
"" :
"NOT ") +
186 " match " + styleText.data);