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