1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/content/base/test/test_bug564863.xhtml Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,359 @@ 1.4 +<!DOCTYPE html [ 1.5 +<!ATTLIST ns:x id ID #REQUIRED> 1.6 +<!ATTLIST ns2:x id_2 ID #REQUIRED> 1.7 +]> 1.8 +<html xmlns="http://www.w3.org/1999/xhtml" 1.9 + xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" 1.10 + xmlns:svg="http://www.w3.org/2000/svg" 1.11 + xmlns:ns="urn:namespace" 1.12 + xmlns:ns2="urn:namespace"> 1.13 +<!-- 1.14 +https://bugzilla.mozilla.org/show_bug.cgi?id=564863 1.15 +--> 1.16 +<head> 1.17 + <title>Test for Bug 564863</title> 1.18 + <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> 1.19 + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> 1.20 +<style> 1.21 +* { 1.22 + color: rgb(0, 0, 0); 1.23 +} 1.24 +#div_id { 1.25 + color: rgb(10, 10, 10); 1.26 +} 1.27 +#a_id { 1.28 + color: rgb(20, 20, 20); 1.29 +} 1.30 +#xul_id { 1.31 + color: rgb(30, 30, 30); 1.32 +} 1.33 +#svg_id { 1.34 + color: rgb(40, 40, 40); 1.35 +} 1.36 +#ns_id { 1.37 + color: rgb(50, 50, 50); 1.38 +} 1.39 +#ns2_id { 1.40 + color: rgb(60, 60, 60); 1.41 +} 1.42 +</style> 1.43 +</head> 1.44 +<body> 1.45 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=564863">Mozilla Bug 564863</a> 1.46 +<!-- Elements to ensure we have nodeinfos with id-attribute set --> 1.47 +<div><ns:x id="ns-holder"/><ns2:x id_2="ns2-holder"/></div> 1.48 + 1.49 +<!-- DOM to muck around with for tests --> 1.50 +<p id="root"> 1.51 +<div id="div_id" /> 1.52 +<a id="a_id" /> 1.53 +<xul:button id="xul_id" /> 1.54 +<svg:svg><svg:g id="svg_id" /></svg:svg> 1.55 +<ns:x id="ns_id" /> 1.56 +</p> 1.57 + 1.58 +<pre id="test"> 1.59 +<script class="testbody" type="text/javascript"> 1.60 +<![CDATA[ 1.61 + 1.62 +root = $('root'); 1.63 +div = root.children[0]; 1.64 +a = root.children[1]; 1.65 +xul = root.children[2]; 1.66 +svg = root.children[3].firstChild; 1.67 +nsx = root.children[4]; 1.68 + 1.69 +var div_cs = getComputedStyle(div, ""); 1.70 +var a_cs = getComputedStyle(a, ""); 1.71 +var xul_cs = getComputedStyle(xul, ""); 1.72 +var svg_cs = getComputedStyle(svg, ""); 1.73 +var nsx_cs = getComputedStyle(nsx, ""); 1.74 + 1.75 +function checkHasId(test) { 1.76 + // Check computed style first to avoid flushes from hiding problems 1.77 + checkHasIdNoGEBI(test); 1.78 + 1.79 + is($("div_id"), div, "div getElementById " + test); 1.80 + is($("a_id"), a, "a getElementById " + test); 1.81 + is($("xul_id"), xul, "xul getElementById " + test); 1.82 + is($("svg_id"), svg, "svg getElementById " + test); 1.83 + is($("ns_id"), nsx, "ns getElementById " + test); 1.84 +} 1.85 + 1.86 +function checkHasIdNoGEBI(test) { 1.87 + is(div_cs.color, "rgb(10, 10, 10)", "div color " + test); 1.88 + is(a_cs.color, "rgb(20, 20, 20)", "a color " + test); 1.89 + is(xul_cs.color, "rgb(30, 30, 30)", "xul color " + test); 1.90 + is(svg_cs.color, "rgb(40, 40, 40)", "svg color " + test); 1.91 + is(nsx_cs.color, "rgb(50, 50, 50)", "nsx color " + test); 1.92 + 1.93 + is(div.id, "div_id", "div id " + test); 1.94 + is(a.id, "a_id", "a id " + test); 1.95 + is(xul.id, "xul_id", "xul id " + test); 1.96 + is(svg.id, "svg_id", "svg id " + test); 1.97 + is (nsx.getAttribute("id"), "ns_id", "ns id " + test); 1.98 +} 1.99 + 1.100 +function checkHasNoId(removed, test) { 1.101 + is(div_cs.color, "rgb(0, 0, 0)", "div color " + test); 1.102 + is(a_cs.color, "rgb(0, 0, 0)", "a color " + test); 1.103 + is(xul_cs.color, "rgb(0, 0, 0)", "xul color " + test); 1.104 + is(svg_cs.color, "rgb(0, 0, 0)", "svg color " + test); 1.105 + is(nsx_cs.color, "rgb(0, 0, 0)", "nsx color " + test); 1.106 + 1.107 + attrValue = removed ? null : ""; 1.108 + 1.109 + is(div.id, "", "div id " + test); 1.110 + is(a.id, "", "a id " + test); 1.111 + is(xul.id, "", "xul id " + test); 1.112 + is(svg.id, "", "svg id " + test); 1.113 + 1.114 + is(div.getAttribute("id"), attrValue, "div getAttribute " + test); 1.115 + is(a.getAttribute("id"), attrValue, "a getAttribute " + test); 1.116 + is(xul.getAttribute("id"), "", "xul getAttribute " + test); 1.117 + is(svg.getAttribute("id"), attrValue, "svg getAttribute " + test); 1.118 + is(nsx.getAttribute("id"), attrValue, "ns getAttribute " + test); 1.119 + 1.120 + is($("div_id"), null, "div getElementById " + test); 1.121 + is($("a_id"), null, "a getElementById " + test); 1.122 + is($("xul_id"), null, "xul getElementById " + test); 1.123 + is($("svg_id"), null, "svg getElementById " + test); 1.124 + is($("ns_id"), null, "ns getElementById " + test); 1.125 +} 1.126 + 1.127 +// Check that dynamic modifications of attribute work 1.128 + 1.129 +checkHasId("in markup"); 1.130 + 1.131 +div.id = ""; 1.132 +a.id = ""; 1.133 +xul.id = ""; 1.134 +svg.id = ""; 1.135 +nsx.setAttribute("id", ""); 1.136 + 1.137 +checkHasNoId(false, "set to empty"); 1.138 + 1.139 +div.id = "div_id"; 1.140 +a.id = "a_id"; 1.141 +xul.id = "xul_id"; 1.142 +svg.id = "svg_id"; 1.143 +nsx.setAttribute("id", "ns_id"); 1.144 + 1.145 +checkHasId("set using .id"); 1.146 + 1.147 +div.setAttribute("id", ""); 1.148 +a.setAttribute("id", ""); 1.149 +xul.setAttribute("id", ""); 1.150 +svg.setAttribute("id", ""); 1.151 +nsx.setAttribute("id", ""); 1.152 + 1.153 +checkHasNoId(false, "setAttribute to empty"); 1.154 + 1.155 +div.id = "div_id"; 1.156 +a.id = "a_id"; 1.157 +xul.id = "xul_id"; 1.158 +svg.id = "svg_id"; 1.159 +nsx.setAttribute("id", "ns_id"); 1.160 + 1.161 +checkHasId("set again using .id"); 1.162 + 1.163 +div.removeAttribute("id"); 1.164 +a.removeAttribute("id"); 1.165 +xul.removeAttribute("id"); 1.166 +svg.removeAttribute("id"); 1.167 +nsx.removeAttribute("id"); 1.168 + 1.169 +checkHasNoId(true, "removed attribute"); 1.170 + 1.171 +div.setAttribute("id", "div_id"); 1.172 +a.setAttribute("id", "a_id"); 1.173 +xul.setAttribute("id", "xul_id"); 1.174 +svg.setAttribute("id", "svg_id"); 1.175 +nsx.setAttribute("id", "ns_id"); 1.176 + 1.177 +checkHasId("set using setAttribute"); 1.178 + 1.179 +t1 = document.createElement("div"); 1.180 +t1.id = "div_id"; 1.181 +t2 = document.createElement("a"); 1.182 +t2.id = "a_id"; 1.183 +t3 = document.createElementNS("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul", "button"); 1.184 +t3.id = "xul_id"; 1.185 +t4 = document.createElementNS("http://www.w3.org/2000/svg", "g"); 1.186 +t4.id = "svg_id"; 1.187 +t5 = document.createElementNS("urn:namespace", "ns:x"); 1.188 +t5.setAttribute("id", "ns_id"); 1.189 + 1.190 +// Check that inserting elements before/after existing work 1.191 + 1.192 +function insertAfter(newChild, existing) { 1.193 + existing.parentNode.insertBefore(newChild, existing.nextSibling); 1.194 +} 1.195 +function insertBefore(newChild, existing) { 1.196 + existing.parentNode.insertBefore(newChild, existing); 1.197 +} 1.198 +function removeNode(child) { 1.199 + child.parentNode.removeChild(child); 1.200 +} 1.201 + 1.202 +insertAfter(t1, div); 1.203 +insertAfter(t2, a); 1.204 +insertAfter(t3, xul); 1.205 +insertAfter(t4, svg); 1.206 +insertAfter(t5, nsx); 1.207 + 1.208 +checkHasId("inserted after"); 1.209 + 1.210 +insertBefore(t1, div); 1.211 +insertBefore(t2, a); 1.212 +insertBefore(t3, xul); 1.213 +insertBefore(t4, svg); 1.214 +insertBefore(t5, nsx); 1.215 + 1.216 +checkHasIdNoGEBI("inserted before"); 1.217 +is($("div_id"), t1, "div getElementById inserted before"); 1.218 +is($("a_id"), t2, "a getElementById inserted before"); 1.219 +is($("xul_id"), t3, "xul getElementById inserted before"); 1.220 +is($("svg_id"), t4, "svg getElementById inserted before"); 1.221 +is($("ns_id"), t5, "ns getElementById inserted before"); 1.222 + 1.223 +t1.removeAttribute("id"); 1.224 +t2.removeAttribute("id"); 1.225 +t3.removeAttribute("id"); 1.226 +t4.removeAttribute("id"); 1.227 +t5.removeAttribute("id"); 1.228 + 1.229 +checkHasId("removed tx attribute"); 1.230 + 1.231 +t1.setAttribute("id", "div_id"); 1.232 +t2.setAttribute("id", "a_id"); 1.233 +t3.setAttribute("id", "xul_id"); 1.234 +t4.setAttribute("id", "svg_id"); 1.235 +t5.setAttribute("id", "ns_id"); 1.236 + 1.237 +checkHasIdNoGEBI("setAttribute before"); 1.238 +is($("div_id"), t1, "div getElementById setAttribute before"); 1.239 +is($("a_id"), t2, "a getElementById setAttribute before"); 1.240 +is($("xul_id"), t3, "xul getElementById setAttribute before"); 1.241 +is($("svg_id"), t4, "svg getElementById setAttribute before"); 1.242 +is($("ns_id"), t5, "ns getElementById setAttribute before"); 1.243 + 1.244 +removeNode(t1); 1.245 +removeNode(t2); 1.246 +removeNode(t3); 1.247 +removeNode(t4); 1.248 +removeNode(t5); 1.249 + 1.250 +checkHasId("removed temporaries"); 1.251 + 1.252 +removeNode(div); 1.253 +removeNode(a); 1.254 +removeNode(xul); 1.255 +removeNode(svg); 1.256 +removeNode(nsx); 1.257 + 1.258 +checkHasIdNoGEBI("removed node"); 1.259 + 1.260 +// Check that removing an element during UnsetAttr works 1.261 +is(div.id, "div_id", "div still has id set"); 1.262 +var mutateFired = false; 1.263 +root.appendChild(div); 1.264 +div.addEventListener("DOMAttrModified", function(e) { 1.265 + div.removeEventListener("DOMAttrModified", arguments.callee, false); 1.266 + is(e.target, div, "target is div"); 1.267 + is(div.id, "", "div no longer has id"); 1.268 + is(div.getAttribute("id"), null, "div no longer has id attr"); 1.269 + removeNode(div); 1.270 + is(div.parentNode, null, "div was removed"); 1.271 + mutateFired = true; 1.272 +}, false); 1.273 +div.removeAttribute("id"); 1.274 +ok(mutateFired, "mutation event fired"); 1.275 + 1.276 +// Check same for XML elements 1.277 +is(nsx.getAttribute("id"), "ns_id", "nsx still has id set"); 1.278 +mutateFired = false; 1.279 +root.appendChild(nsx); 1.280 +nsx.addEventListener("DOMAttrModified", function(e) { 1.281 + nsx.removeEventListener("DOMAttrModified", arguments.callee, false); 1.282 + is(e.target, nsx, "target is nsx"); 1.283 + is(nsx.getAttribute("id"), null, "nsx no longer has id attr"); 1.284 + removeNode(nsx); 1.285 + is(nsx.parentNode, null, "nsx was removed"); 1.286 + mutateFired = true; 1.287 +}, false); 1.288 +nsx.removeAttribute("id"); 1.289 +ok(mutateFired, "mutation event fired"); 1.290 + 1.291 + 1.292 +// Re-add the id inside a mutation event on a XML element 1.293 +is($("ns_id"), null, "no nsx"); 1.294 +is($("ns2_id"), null, "no nsx"); 1.295 +nsx = document.createElementNS("urn:namespace", "ns:x"); 1.296 +nsx.setAttribute("id", "ns_id"); 1.297 +root.appendChild(nsx); 1.298 +is($("ns_id"), nsx, "new nsx is set up"); 1.299 +mutateFired = false; 1.300 +nsx.addEventListener("DOMAttrModified", function(e) { 1.301 + nsx.removeEventListener("DOMAttrModified", arguments.callee, false); 1.302 + is(e.target, nsx, "target is nsx"); 1.303 + is(nsx.getAttribute("id"), null, "nsx no longer has id attr"); 1.304 + nsx.setAttribute("id", "other_id"); 1.305 + mutateFired = true; 1.306 +}, false); 1.307 +nsx.removeAttribute("id"); 1.308 +ok(mutateFired, "mutation event fired"); 1.309 +is($("ns_id"), null, "ns_id was removed from table"); 1.310 +is($("other_id"), nsx, "other_id was added"); 1.311 +removeNode(nsx); 1.312 +is($("other_id"), null, "other_id was removed"); 1.313 + 1.314 +// Re-add the id inside a mutation event on a HTML element 1.315 +is($("div_id"), null, "no div"); 1.316 +div = document.createElement("div"); 1.317 +div.id = "div_id"; 1.318 +root.appendChild(div); 1.319 +is($("div_id"), div, "new div is set up"); 1.320 +mutateFired = false; 1.321 +div.addEventListener("DOMAttrModified", function(e) { 1.322 + div.removeEventListener("DOMAttrModified", arguments.callee, false); 1.323 + is(e.target, div, "target is div"); 1.324 + is(div.getAttribute("id"), null, "div no longer has id attr"); 1.325 + is(div.id, "", "div no longer has id"); 1.326 + div.id = "other_div_id"; 1.327 + mutateFired = true; 1.328 +}, false); 1.329 +div.removeAttribute("id"); 1.330 +ok(mutateFired, "mutation event fired"); 1.331 +is($("div_id"), null, "div_id was removed from table"); 1.332 +is($("other_div_id"), div, "other_div_id was added"); 1.333 +removeNode(div); 1.334 +is($("other_div_id"), null, "other_div_id was removed"); 1.335 + 1.336 +// Re-add the id inside a mutation event on a XUL element 1.337 +is($("xul_id"), null, "no xul"); 1.338 +xul = document.createElementNS("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul", "button"); 1.339 +xul.id = "xul_id"; 1.340 +root.appendChild(xul); 1.341 +is($("xul_id"), xul, "new xul is set up"); 1.342 +mutateFired = false; 1.343 +xul.addEventListener("DOMAttrModified", function(e) { 1.344 + xul.removeEventListener("DOMAttrModified", arguments.callee, false); 1.345 + is(e.target, xul, "target is xul"); 1.346 + is(xul.getAttribute("id"), "", "xul no longer has id attr"); 1.347 + is(xul.id, "", "xul no longer has id"); 1.348 + xul.id = "other_xul_id"; 1.349 + mutateFired = true; 1.350 +}, false); 1.351 +xul.removeAttribute("id"); 1.352 +ok(mutateFired, "mutation event fired"); 1.353 +is($("xul_id"), null, "xul_id was removed from table"); 1.354 +is($("other_xul_id"), xul, "other_xul_id was added"); 1.355 +removeNode(xul); 1.356 +is($("other_xul_id"), null, "other_xul_id was removed"); 1.357 + 1.358 +]]> 1.359 +</script> 1.360 +</pre> 1.361 +</body> 1.362 +</html>