1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/layout/style/test/test_bug73586.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,192 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html> 1.6 +<!-- 1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=73586 1.8 +--> 1.9 +<head> 1.10 + <title>Test for Bug 73586</title> 1.11 + <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> 1.12 + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> 1.13 + <style type="text/css"> 1.14 + 1.15 + span { background: white; color: black; border: medium solid black; } 1.16 + 1.17 + </style> 1.18 +</head> 1.19 +<body> 1.20 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=73586">Mozilla Bug 73586</a> 1.21 +<div id="display"></div> 1.22 + 1.23 +<div id="content" style="display: none"> 1.24 + 1.25 +</div> 1.26 +<pre id="test"> 1.27 +<script class="testbody" type="text/javascript"> 1.28 + 1.29 +/** Test for Bug 73586 **/ 1.30 + 1.31 +const GREEN = "rgb(0, 128, 0)"; 1.32 +const LIME = "rgb(0, 255, 0)"; 1.33 +const BLACK = "rgb(0, 0, 0)"; 1.34 +const WHITE = "rgb(255, 255, 255)"; 1.35 + 1.36 +function cs(elt) { return getComputedStyle(elt, ""); } 1.37 + 1.38 +function check_children(p, check_cb) { 1.39 + var len = p.childNodes.length; 1.40 + var elts = 0; 1.41 + var i, elt, child; 1.42 + for (i = 0; i < len; ++i) { 1.43 + if (p.childNodes[i].nodeType == Node.ELEMENT_NODE) 1.44 + ++elts; 1.45 + } 1.46 + 1.47 + elt = 0; 1.48 + for (i = 0; i < len; ++i) { 1.49 + child = p.childNodes[i]; 1.50 + if (child.nodeType != Node.ELEMENT_NODE) 1.51 + continue; 1.52 + check_cb(child, elt, elts, i, len); 1.53 + ++elt; 1.54 + } 1.55 +} 1.56 + 1.57 +var display = document.getElementById("display"); 1.58 + 1.59 +function run_series(check_cb) { 1.60 + var display = document.getElementById("display"); 1.61 + // Use a new parent node every time since the optimizations cause 1.62 + // bits to be set (permanently) on the parent. 1.63 + var p = document.createElement("p"); 1.64 + display.appendChild(p); 1.65 + p.innerHTML = "x<span></span><span></span>"; 1.66 + 1.67 + check_children(p, check_cb); 1.68 + var text = p.removeChild(p.childNodes[0]); 1.69 + check_children(p, check_cb); 1.70 + var span = p.removeChild(p.childNodes[0]); 1.71 + check_children(p, check_cb); 1.72 + p.appendChild(span); 1.73 + check_children(p, check_cb); 1.74 + p.removeChild(span); 1.75 + check_children(p, check_cb); 1.76 + p.insertBefore(span, p.childNodes[0]); 1.77 + check_children(p, check_cb); 1.78 + p.removeChild(span); 1.79 + check_children(p, check_cb); 1.80 + p.insertBefore(span, null); 1.81 + check_children(p, check_cb); 1.82 + p.appendChild(document.createElement("span")); 1.83 + check_children(p, check_cb); 1.84 + p.insertBefore(document.createElement("span"), p.childNodes[2]); 1.85 + check_children(p, check_cb); 1.86 + p.appendChild(text); 1.87 + check_children(p, check_cb); 1.88 + 1.89 + display.removeChild(p); 1.90 +} 1.91 + 1.92 +var style = document.createElement("style"); 1.93 +style.setAttribute("type", "text/css"); 1.94 +var styleText = document.createTextNode(""); 1.95 +style.appendChild(styleText); 1.96 +document.getElementsByTagName("head")[0].appendChild(style); 1.97 + 1.98 +styleText.data = "span:first-child { background: lime; }"; 1.99 +run_series(function(child, elt, elts, node, nodes) { 1.100 + is(cs(child).backgroundColor, (elt == 0) ? LIME : WHITE, 1.101 + "child " + node + " should " + ((elt == 0) ? "" : "NOT ") + 1.102 + " match :first-child"); 1.103 + }); 1.104 + 1.105 +styleText.data = "span:last-child { color: green; }"; 1.106 +run_series(function(child, elt, elts, node, nodes) { 1.107 + is(cs(child).color, (elt == elts - 1) ? GREEN : BLACK, 1.108 + "child " + node + " should " + ((elt == elts - 1) ? "" : "NOT ") + 1.109 + " match :last-child"); 1.110 + }); 1.111 + 1.112 +styleText.data = "span:only-child { border: medium solid green; }"; 1.113 +run_series(function(child, elt, elts, node, nodes) { 1.114 + is(cs(child).borderTopColor, (elts == 1) ? GREEN : BLACK, 1.115 + "child " + node + " should " + ((elts == 1) ? "" : "NOT ") + 1.116 + " match :only-child"); 1.117 + }); 1.118 + 1.119 +styleText.data = "span:-moz-first-node { text-decoration: underline; }"; 1.120 +run_series(function(child, elt, elts, node, nodes) { 1.121 + is(cs(child).textDecoration, (node == 0) ? "underline" : "none", 1.122 + "child " + node + " should " + ((node == 0) ? "" : "NOT ") + 1.123 + " match :-moz-first-node"); 1.124 + }); 1.125 + 1.126 +styleText.data = "span:-moz-last-node { visibility: hidden; }"; 1.127 +run_series(function(child, elt, elts, node, nodes) { 1.128 + is(cs(child).visibility, (node == nodes - 1) ? "hidden" : "visible", 1.129 + "child " + node + " should " + ((node == nodes - 1) ? "" : "NOT ") + 1.130 + " match :-moz-last-node"); 1.131 + }); 1.132 + 1.133 +styleText.data = "span:nth-child(1) { background: lime; }"; 1.134 +run_series(function(child, elt, elts, node, nodes) { 1.135 + var matches = elt == 0; 1.136 + is(cs(child).backgroundColor, matches ? LIME : WHITE, 1.137 + "child " + node + " should " + (matches ? "" : "NOT ") + 1.138 + " match " + styleText.data); 1.139 + }); 1.140 + 1.141 +styleText.data = "span:nth-last-child(0n+2) { color: green; }"; 1.142 +run_series(function(child, elt, elts, node, nodes) { 1.143 + var matches = (elt == elts - 2); 1.144 + is(cs(child).color, matches ? GREEN : BLACK, 1.145 + "child " + node + " should " + (matches ? "" : "NOT ") + 1.146 + " match " + styleText.data); 1.147 + }); 1.148 + 1.149 +styleText.data = "span:nth-of-type(2n+3) { color: green; }"; 1.150 +run_series(function(child, elt, elts, node, nodes) { 1.151 + var nidx = elt + 1; 1.152 + var matches = nidx % 2 == 1 && nidx >= 3; 1.153 + is(cs(child).color, matches ? GREEN : BLACK, 1.154 + "child " + node + " should " + (matches ? "" : "NOT ") + 1.155 + " match " + styleText.data); 1.156 + }); 1.157 + 1.158 +styleText.data = "span:nth-last-of-type(-2n+5) { color: green; }"; 1.159 +run_series(function(child, elt, elts, node, nodes) { 1.160 + var nlidx = elts - elt; 1.161 + var matches = nlidx % 2 == 1 && nlidx <= 5; 1.162 + is(cs(child).color, matches ? GREEN : BLACK, 1.163 + "child " + node + " should " + (matches ? "" : "NOT ") + 1.164 + " match " + styleText.data); 1.165 + }); 1.166 + 1.167 +styleText.data = "span:first-of-type { color: green; }"; 1.168 +run_series(function(child, elt, elts, node, nodes) { 1.169 + var matches = (elt == 0); 1.170 + is(cs(child).color, matches ? GREEN : BLACK, 1.171 + "child " + node + " should " + (matches ? "" : "NOT ") + 1.172 + " match " + styleText.data); 1.173 + }); 1.174 + 1.175 +styleText.data = "span:last-of-type { color: green; }"; 1.176 +run_series(function(child, elt, elts, node, nodes) { 1.177 + var matches = (elt == elts - 1); 1.178 + is(cs(child).color, matches ? GREEN : BLACK, 1.179 + "child " + node + " should " + (matches ? "" : "NOT ") + 1.180 + " match " + styleText.data); 1.181 + }); 1.182 + 1.183 +styleText.data = "span:only-of-type { color: green; }"; 1.184 +run_series(function(child, elt, elts, node, nodes) { 1.185 + var matches = elts == 1; 1.186 + is(cs(child).color, matches ? GREEN : BLACK, 1.187 + "child " + node + " should " + (matches ? "" : "NOT ") + 1.188 + " match " + styleText.data); 1.189 + }); 1.190 + 1.191 +</script> 1.192 +</pre> 1.193 +</body> 1.194 +</html> 1.195 +