2008-02-18 22:17:07 -08:00
|
|
|
<!DOCTYPE HTML>
|
|
|
|
<html>
|
|
|
|
<!--
|
|
|
|
https://bugzilla.mozilla.org/show_bug.cgi?id=73586
|
|
|
|
-->
|
|
|
|
<head>
|
|
|
|
<title>Test for Bug 73586</title>
|
|
|
|
<script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
|
|
|
|
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
|
|
|
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
|
|
|
<style type="text/css">
|
|
|
|
|
|
|
|
span { background: white; color: black; border: medium solid black; }
|
|
|
|
|
|
|
|
</style>
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=73586">Mozilla Bug 73586</a>
|
2008-03-08 14:41:47 -08:00
|
|
|
<div id="display"></div>
|
|
|
|
|
2008-02-18 22:17:07 -08:00
|
|
|
<div id="content" style="display: none">
|
|
|
|
|
|
|
|
</div>
|
|
|
|
<pre id="test">
|
|
|
|
<script class="testbody" type="text/javascript">
|
|
|
|
|
|
|
|
/** Test for Bug 73586 **/
|
|
|
|
|
|
|
|
const GREEN = "rgb(0, 128, 0)";
|
|
|
|
const LIME = "rgb(0, 255, 0)";
|
|
|
|
const BLACK = "rgb(0, 0, 0)";
|
|
|
|
const WHITE = "rgb(255, 255, 255)";
|
|
|
|
|
|
|
|
function cs(elt) { return getComputedStyle(elt, ""); }
|
|
|
|
|
2008-03-08 14:41:47 -08:00
|
|
|
function check_children(p, check_cb) {
|
2008-02-18 22:17:07 -08:00
|
|
|
var len = p.childNodes.length;
|
|
|
|
var elts = 0;
|
|
|
|
var i, elt, child;
|
|
|
|
for (i = 0; i < len; ++i) {
|
|
|
|
if (p.childNodes[i].nodeType == Node.ELEMENT_NODE)
|
|
|
|
++elts;
|
|
|
|
}
|
|
|
|
|
|
|
|
elt = 0;
|
|
|
|
for (i = 0; i < len; ++i) {
|
|
|
|
child = p.childNodes[i];
|
2008-03-08 14:22:09 -08:00
|
|
|
if (child.nodeType != Node.ELEMENT_NODE)
|
2008-02-18 22:17:07 -08:00
|
|
|
continue;
|
2008-03-08 14:41:47 -08:00
|
|
|
check_cb(child, elt, elts, i, len);
|
|
|
|
++elt;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var display = document.getElementById("display");
|
|
|
|
|
|
|
|
function run_series(check_cb) {
|
|
|
|
var display = document.getElementById("display");
|
|
|
|
// Use a new parent node every time since the optimizations cause
|
|
|
|
// bits to be set (permanently) on the parent.
|
|
|
|
var p = document.createElement("p");
|
|
|
|
display.appendChild(p);
|
|
|
|
p.innerHTML = "x<span></span><span></span>";
|
|
|
|
|
|
|
|
check_children(p, check_cb);
|
|
|
|
var text = p.removeChild(p.childNodes[0]);
|
|
|
|
check_children(p, check_cb);
|
|
|
|
var span = p.removeChild(p.childNodes[0]);
|
|
|
|
check_children(p, check_cb);
|
|
|
|
p.appendChild(span);
|
|
|
|
check_children(p, check_cb);
|
|
|
|
p.removeChild(span);
|
|
|
|
check_children(p, check_cb);
|
|
|
|
p.insertBefore(span, p.childNodes[0]);
|
|
|
|
check_children(p, check_cb);
|
|
|
|
p.removeChild(span);
|
|
|
|
check_children(p, check_cb);
|
|
|
|
p.insertBefore(span, null);
|
|
|
|
check_children(p, check_cb);
|
|
|
|
p.appendChild(document.createElement("span"));
|
|
|
|
check_children(p, check_cb);
|
|
|
|
p.insertBefore(document.createElement("span"), p.childNodes[2]);
|
|
|
|
check_children(p, check_cb);
|
|
|
|
p.appendChild(text);
|
|
|
|
check_children(p, check_cb);
|
|
|
|
|
|
|
|
display.removeChild(p);
|
|
|
|
}
|
|
|
|
|
|
|
|
var style = document.createElement("style");
|
|
|
|
style.setAttribute("type", "text/css");
|
|
|
|
var styleText = document.createTextNode("");
|
|
|
|
style.appendChild(styleText);
|
|
|
|
document.getElementsByTagName("head")[0].appendChild(style);
|
|
|
|
|
|
|
|
styleText.data = "span:first-child { background: lime; }";
|
|
|
|
run_series(function(child, elt, elts, node, nodes) {
|
2008-02-18 22:17:07 -08:00
|
|
|
is(cs(child).backgroundColor, (elt == 0) ? LIME : WHITE,
|
2008-03-08 14:41:47 -08:00
|
|
|
"child " + node + " should " + ((elt == 0) ? "" : "NOT ") +
|
2008-02-18 22:17:07 -08:00
|
|
|
" match :first-child");
|
2008-03-08 14:41:47 -08:00
|
|
|
});
|
|
|
|
|
|
|
|
styleText.data = "span:last-child { color: green; }";
|
|
|
|
run_series(function(child, elt, elts, node, nodes) {
|
2008-02-18 22:17:07 -08:00
|
|
|
is(cs(child).color, (elt == elts - 1) ? GREEN : BLACK,
|
2008-03-08 14:41:47 -08:00
|
|
|
"child " + node + " should " + ((elt == elts - 1) ? "" : "NOT ") +
|
2008-02-18 22:17:07 -08:00
|
|
|
" match :last-child");
|
2008-03-08 14:41:47 -08:00
|
|
|
});
|
|
|
|
|
|
|
|
styleText.data = "span:only-child { border: medium solid green; }";
|
|
|
|
run_series(function(child, elt, elts, node, nodes) {
|
2008-02-18 22:17:07 -08:00
|
|
|
is(cs(child).borderTopColor, (elts == 1) ? GREEN : BLACK,
|
2008-03-08 14:41:47 -08:00
|
|
|
"child " + node + " should " + ((elts == 1) ? "" : "NOT ") +
|
2008-02-18 22:17:07 -08:00
|
|
|
" match :only-child");
|
2008-03-08 14:41:47 -08:00
|
|
|
});
|
2008-02-18 22:17:07 -08:00
|
|
|
|
2008-03-08 14:41:47 -08:00
|
|
|
styleText.data = "span:-moz-first-node { text-decoration: underline; }";
|
|
|
|
run_series(function(child, elt, elts, node, nodes) {
|
|
|
|
is(cs(child).textDecoration, (node == 0) ? "underline" : "none",
|
|
|
|
"child " + node + " should " + ((node == 0) ? "" : "NOT ") +
|
2008-02-18 22:17:07 -08:00
|
|
|
" match :-moz-first-node");
|
2008-03-08 14:41:47 -08:00
|
|
|
});
|
2008-02-18 22:17:07 -08:00
|
|
|
|
2008-03-08 14:41:47 -08:00
|
|
|
styleText.data = "span:-moz-last-node { visibility: hidden; }";
|
|
|
|
run_series(function(child, elt, elts, node, nodes) {
|
|
|
|
is(cs(child).visibility, (node == nodes - 1) ? "hidden" : "visible",
|
|
|
|
"child " + node + " should " + ((node == nodes - 1) ? "" : "NOT ") +
|
|
|
|
" match :-moz-last-node");
|
|
|
|
});
|
2008-02-18 22:17:07 -08:00
|
|
|
|
2008-06-02 20:17:35 -07:00
|
|
|
styleText.data = "span:nth-child(1) { background: lime; }";
|
|
|
|
run_series(function(child, elt, elts, node, nodes) {
|
|
|
|
var matches = elt == 0;
|
|
|
|
is(cs(child).backgroundColor, matches ? LIME : WHITE,
|
|
|
|
"child " + node + " should " + (matches ? "" : "NOT ") +
|
|
|
|
" match " + styleText.data);
|
|
|
|
});
|
|
|
|
|
|
|
|
styleText.data = "span:nth-last-child(0n+2) { color: green; }";
|
|
|
|
run_series(function(child, elt, elts, node, nodes) {
|
|
|
|
var matches = (elt == elts - 2);
|
|
|
|
is(cs(child).color, matches ? GREEN : BLACK,
|
|
|
|
"child " + node + " should " + (matches ? "" : "NOT ") +
|
|
|
|
" match " + styleText.data);
|
|
|
|
});
|
|
|
|
|
|
|
|
styleText.data = "span:nth-of-type(2n+3) { color: green; }";
|
|
|
|
run_series(function(child, elt, elts, node, nodes) {
|
|
|
|
var nidx = elt + 1;
|
|
|
|
var matches = nidx % 2 == 1 && nidx >= 3;
|
|
|
|
is(cs(child).color, matches ? GREEN : BLACK,
|
|
|
|
"child " + node + " should " + (matches ? "" : "NOT ") +
|
|
|
|
" match " + styleText.data);
|
|
|
|
});
|
|
|
|
|
|
|
|
styleText.data = "span:nth-last-of-type(-2n+5) { color: green; }";
|
|
|
|
run_series(function(child, elt, elts, node, nodes) {
|
|
|
|
var nlidx = elts - elt;
|
|
|
|
var matches = nlidx % 2 == 1 && nlidx <= 5;
|
|
|
|
is(cs(child).color, matches ? GREEN : BLACK,
|
|
|
|
"child " + node + " should " + (matches ? "" : "NOT ") +
|
|
|
|
" match " + styleText.data);
|
|
|
|
});
|
|
|
|
|
2008-06-02 20:17:35 -07:00
|
|
|
styleText.data = "span:first-of-type { color: green; }";
|
|
|
|
run_series(function(child, elt, elts, node, nodes) {
|
|
|
|
var matches = (elt == 0);
|
|
|
|
is(cs(child).color, matches ? GREEN : BLACK,
|
|
|
|
"child " + node + " should " + (matches ? "" : "NOT ") +
|
|
|
|
" match " + styleText.data);
|
|
|
|
});
|
|
|
|
|
|
|
|
styleText.data = "span:last-of-type { color: green; }";
|
|
|
|
run_series(function(child, elt, elts, node, nodes) {
|
|
|
|
var matches = (elt == elts - 1);
|
|
|
|
is(cs(child).color, matches ? GREEN : BLACK,
|
|
|
|
"child " + node + " should " + (matches ? "" : "NOT ") +
|
|
|
|
" match " + styleText.data);
|
|
|
|
});
|
|
|
|
|
|
|
|
styleText.data = "span:only-of-type { color: green; }";
|
|
|
|
run_series(function(child, elt, elts, node, nodes) {
|
|
|
|
var matches = elts == 1;
|
|
|
|
is(cs(child).color, matches ? GREEN : BLACK,
|
|
|
|
"child " + node + " should " + (matches ? "" : "NOT ") +
|
|
|
|
" match " + styleText.data);
|
|
|
|
});
|
|
|
|
|
2008-02-18 22:17:07 -08:00
|
|
|
</script>
|
|
|
|
</pre>
|
|
|
|
</body>
|
|
|
|
</html>
|
|
|
|
|