test_bug73586.html (6518B)
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 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 function run_series(check_cb) { 55 var display = document.getElementById("display"); 56 // Use a new parent node every time since the optimizations cause 57 // bits to be set (permanently) on the parent. 58 var p = document.createElement("p"); 59 display.appendChild(p); 60 p.innerHTML = "x<span></span><span></span>"; 61 62 check_children(p, check_cb); 63 var text = p.removeChild(p.childNodes[0]); 64 check_children(p, check_cb); 65 var span = p.removeChild(p.childNodes[0]); 66 check_children(p, check_cb); 67 p.appendChild(span); 68 check_children(p, check_cb); 69 p.removeChild(span); 70 check_children(p, check_cb); 71 p.insertBefore(span, p.childNodes[0]); 72 check_children(p, check_cb); 73 p.removeChild(span); 74 check_children(p, check_cb); 75 p.insertBefore(span, null); 76 check_children(p, check_cb); 77 p.appendChild(document.createElement("span")); 78 check_children(p, check_cb); 79 p.insertBefore(document.createElement("span"), p.childNodes[2]); 80 check_children(p, check_cb); 81 p.appendChild(text); 82 check_children(p, check_cb); 83 84 display.removeChild(p); 85 } 86 87 var style = document.createElement("style"); 88 style.setAttribute("type", "text/css"); 89 var styleText = document.createTextNode(""); 90 style.appendChild(styleText); 91 document.getElementsByTagName("head")[0].appendChild(style); 92 93 styleText.data = "span:first-child { background: lime; }"; 94 run_series(function(child, elt, elts, node, nodes) { 95 is(cs(child).backgroundColor, (elt == 0) ? LIME : WHITE, 96 "child " + node + " should " + ((elt == 0) ? "" : "NOT ") + 97 " match :first-child"); 98 }); 99 100 styleText.data = "span:last-child { color: green; }"; 101 run_series(function(child, elt, elts, node, nodes) { 102 is(cs(child).color, (elt == elts - 1) ? GREEN : BLACK, 103 "child " + node + " should " + ((elt == elts - 1) ? "" : "NOT ") + 104 " match :last-child"); 105 }); 106 107 styleText.data = "span:only-child { border: medium solid green; }"; 108 run_series(function(child, elt, elts, node, nodes) { 109 is(cs(child).borderTopColor, (elts == 1) ? GREEN : BLACK, 110 "child " + node + " should " + ((elts == 1) ? "" : "NOT ") + 111 " match :only-child"); 112 }); 113 114 styleText.data = "span:-moz-first-node { text-decoration-line: underline; }"; 115 run_series(function(child, elt, elts, node, nodes) { 116 is(cs(child).textDecorationLine, (node == 0) ? "underline" : "none", 117 "child " + node + " should " + ((node == 0) ? "" : "NOT ") + 118 " match :-moz-first-node"); 119 }); 120 121 styleText.data = "span:-moz-last-node { visibility: hidden; }"; 122 run_series(function(child, elt, elts, node, nodes) { 123 is(cs(child).visibility, (node == nodes - 1) ? "hidden" : "visible", 124 "child " + node + " should " + ((node == nodes - 1) ? "" : "NOT ") + 125 " match :-moz-last-node"); 126 }); 127 128 styleText.data = "span:nth-child(1) { background: lime; }"; 129 run_series(function(child, elt, elts, node, nodes) { 130 var matches = elt == 0; 131 is(cs(child).backgroundColor, matches ? LIME : WHITE, 132 "child " + node + " should " + (matches ? "" : "NOT ") + 133 " match " + styleText.data); 134 }); 135 136 styleText.data = "span:nth-last-child(0n+2) { color: green; }"; 137 run_series(function(child, elt, elts, node, nodes) { 138 var matches = (elt == elts - 2); 139 is(cs(child).color, matches ? GREEN : BLACK, 140 "child " + node + " should " + (matches ? "" : "NOT ") + 141 " match " + styleText.data); 142 }); 143 144 styleText.data = "span:nth-of-type(2n+3) { color: green; }"; 145 run_series(function(child, elt, elts, node, nodes) { 146 var nidx = elt + 1; 147 var matches = nidx % 2 == 1 && nidx >= 3; 148 is(cs(child).color, matches ? GREEN : BLACK, 149 "child " + node + " should " + (matches ? "" : "NOT ") + 150 " match " + styleText.data); 151 }); 152 153 styleText.data = "span:nth-last-of-type(-2n+5) { color: green; }"; 154 run_series(function(child, elt, elts, node, nodes) { 155 var nlidx = elts - elt; 156 var matches = nlidx % 2 == 1 && nlidx <= 5; 157 is(cs(child).color, matches ? GREEN : BLACK, 158 "child " + node + " should " + (matches ? "" : "NOT ") + 159 " match " + styleText.data); 160 }); 161 162 styleText.data = "span:first-of-type { color: green; }"; 163 run_series(function(child, elt, elts, node, nodes) { 164 var matches = (elt == 0); 165 is(cs(child).color, matches ? GREEN : BLACK, 166 "child " + node + " should " + (matches ? "" : "NOT ") + 167 " match " + styleText.data); 168 }); 169 170 styleText.data = "span:last-of-type { color: green; }"; 171 run_series(function(child, elt, elts, node, nodes) { 172 var matches = (elt == elts - 1); 173 is(cs(child).color, matches ? GREEN : BLACK, 174 "child " + node + " should " + (matches ? "" : "NOT ") + 175 " match " + styleText.data); 176 }); 177 178 styleText.data = "span:only-of-type { color: green; }"; 179 run_series(function(child, elt, elts, node, nodes) { 180 var matches = elts == 1; 181 is(cs(child).color, matches ? GREEN : BLACK, 182 "child " + node + " should " + (matches ? "" : "NOT ") + 183 " match " + styleText.data); 184 }); 185 186 </script> 187 </pre> 188 </body> 189 </html>