content/base/test/test_bug564863.xhtml

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 <!DOCTYPE html [
michael@0 2 <!ATTLIST ns:x id ID #REQUIRED>
michael@0 3 <!ATTLIST ns2:x id_2 ID #REQUIRED>
michael@0 4 ]>
michael@0 5 <html xmlns="http://www.w3.org/1999/xhtml"
michael@0 6 xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
michael@0 7 xmlns:svg="http://www.w3.org/2000/svg"
michael@0 8 xmlns:ns="urn:namespace"
michael@0 9 xmlns:ns2="urn:namespace">
michael@0 10 <!--
michael@0 11 https://bugzilla.mozilla.org/show_bug.cgi?id=564863
michael@0 12 -->
michael@0 13 <head>
michael@0 14 <title>Test for Bug 564863</title>
michael@0 15 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
michael@0 16 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
michael@0 17 <style>
michael@0 18 * {
michael@0 19 color: rgb(0, 0, 0);
michael@0 20 }
michael@0 21 #div_id {
michael@0 22 color: rgb(10, 10, 10);
michael@0 23 }
michael@0 24 #a_id {
michael@0 25 color: rgb(20, 20, 20);
michael@0 26 }
michael@0 27 #xul_id {
michael@0 28 color: rgb(30, 30, 30);
michael@0 29 }
michael@0 30 #svg_id {
michael@0 31 color: rgb(40, 40, 40);
michael@0 32 }
michael@0 33 #ns_id {
michael@0 34 color: rgb(50, 50, 50);
michael@0 35 }
michael@0 36 #ns2_id {
michael@0 37 color: rgb(60, 60, 60);
michael@0 38 }
michael@0 39 </style>
michael@0 40 </head>
michael@0 41 <body>
michael@0 42 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=564863">Mozilla Bug 564863</a>
michael@0 43 <!-- Elements to ensure we have nodeinfos with id-attribute set -->
michael@0 44 <div><ns:x id="ns-holder"/><ns2:x id_2="ns2-holder"/></div>
michael@0 45
michael@0 46 <!-- DOM to muck around with for tests -->
michael@0 47 <p id="root">
michael@0 48 <div id="div_id" />
michael@0 49 <a id="a_id" />
michael@0 50 <xul:button id="xul_id" />
michael@0 51 <svg:svg><svg:g id="svg_id" /></svg:svg>
michael@0 52 <ns:x id="ns_id" />
michael@0 53 </p>
michael@0 54
michael@0 55 <pre id="test">
michael@0 56 <script class="testbody" type="text/javascript">
michael@0 57 <![CDATA[
michael@0 58
michael@0 59 root = $('root');
michael@0 60 div = root.children[0];
michael@0 61 a = root.children[1];
michael@0 62 xul = root.children[2];
michael@0 63 svg = root.children[3].firstChild;
michael@0 64 nsx = root.children[4];
michael@0 65
michael@0 66 var div_cs = getComputedStyle(div, "");
michael@0 67 var a_cs = getComputedStyle(a, "");
michael@0 68 var xul_cs = getComputedStyle(xul, "");
michael@0 69 var svg_cs = getComputedStyle(svg, "");
michael@0 70 var nsx_cs = getComputedStyle(nsx, "");
michael@0 71
michael@0 72 function checkHasId(test) {
michael@0 73 // Check computed style first to avoid flushes from hiding problems
michael@0 74 checkHasIdNoGEBI(test);
michael@0 75
michael@0 76 is($("div_id"), div, "div getElementById " + test);
michael@0 77 is($("a_id"), a, "a getElementById " + test);
michael@0 78 is($("xul_id"), xul, "xul getElementById " + test);
michael@0 79 is($("svg_id"), svg, "svg getElementById " + test);
michael@0 80 is($("ns_id"), nsx, "ns getElementById " + test);
michael@0 81 }
michael@0 82
michael@0 83 function checkHasIdNoGEBI(test) {
michael@0 84 is(div_cs.color, "rgb(10, 10, 10)", "div color " + test);
michael@0 85 is(a_cs.color, "rgb(20, 20, 20)", "a color " + test);
michael@0 86 is(xul_cs.color, "rgb(30, 30, 30)", "xul color " + test);
michael@0 87 is(svg_cs.color, "rgb(40, 40, 40)", "svg color " + test);
michael@0 88 is(nsx_cs.color, "rgb(50, 50, 50)", "nsx color " + test);
michael@0 89
michael@0 90 is(div.id, "div_id", "div id " + test);
michael@0 91 is(a.id, "a_id", "a id " + test);
michael@0 92 is(xul.id, "xul_id", "xul id " + test);
michael@0 93 is(svg.id, "svg_id", "svg id " + test);
michael@0 94 is (nsx.getAttribute("id"), "ns_id", "ns id " + test);
michael@0 95 }
michael@0 96
michael@0 97 function checkHasNoId(removed, test) {
michael@0 98 is(div_cs.color, "rgb(0, 0, 0)", "div color " + test);
michael@0 99 is(a_cs.color, "rgb(0, 0, 0)", "a color " + test);
michael@0 100 is(xul_cs.color, "rgb(0, 0, 0)", "xul color " + test);
michael@0 101 is(svg_cs.color, "rgb(0, 0, 0)", "svg color " + test);
michael@0 102 is(nsx_cs.color, "rgb(0, 0, 0)", "nsx color " + test);
michael@0 103
michael@0 104 attrValue = removed ? null : "";
michael@0 105
michael@0 106 is(div.id, "", "div id " + test);
michael@0 107 is(a.id, "", "a id " + test);
michael@0 108 is(xul.id, "", "xul id " + test);
michael@0 109 is(svg.id, "", "svg id " + test);
michael@0 110
michael@0 111 is(div.getAttribute("id"), attrValue, "div getAttribute " + test);
michael@0 112 is(a.getAttribute("id"), attrValue, "a getAttribute " + test);
michael@0 113 is(xul.getAttribute("id"), "", "xul getAttribute " + test);
michael@0 114 is(svg.getAttribute("id"), attrValue, "svg getAttribute " + test);
michael@0 115 is(nsx.getAttribute("id"), attrValue, "ns getAttribute " + test);
michael@0 116
michael@0 117 is($("div_id"), null, "div getElementById " + test);
michael@0 118 is($("a_id"), null, "a getElementById " + test);
michael@0 119 is($("xul_id"), null, "xul getElementById " + test);
michael@0 120 is($("svg_id"), null, "svg getElementById " + test);
michael@0 121 is($("ns_id"), null, "ns getElementById " + test);
michael@0 122 }
michael@0 123
michael@0 124 // Check that dynamic modifications of attribute work
michael@0 125
michael@0 126 checkHasId("in markup");
michael@0 127
michael@0 128 div.id = "";
michael@0 129 a.id = "";
michael@0 130 xul.id = "";
michael@0 131 svg.id = "";
michael@0 132 nsx.setAttribute("id", "");
michael@0 133
michael@0 134 checkHasNoId(false, "set to empty");
michael@0 135
michael@0 136 div.id = "div_id";
michael@0 137 a.id = "a_id";
michael@0 138 xul.id = "xul_id";
michael@0 139 svg.id = "svg_id";
michael@0 140 nsx.setAttribute("id", "ns_id");
michael@0 141
michael@0 142 checkHasId("set using .id");
michael@0 143
michael@0 144 div.setAttribute("id", "");
michael@0 145 a.setAttribute("id", "");
michael@0 146 xul.setAttribute("id", "");
michael@0 147 svg.setAttribute("id", "");
michael@0 148 nsx.setAttribute("id", "");
michael@0 149
michael@0 150 checkHasNoId(false, "setAttribute to empty");
michael@0 151
michael@0 152 div.id = "div_id";
michael@0 153 a.id = "a_id";
michael@0 154 xul.id = "xul_id";
michael@0 155 svg.id = "svg_id";
michael@0 156 nsx.setAttribute("id", "ns_id");
michael@0 157
michael@0 158 checkHasId("set again using .id");
michael@0 159
michael@0 160 div.removeAttribute("id");
michael@0 161 a.removeAttribute("id");
michael@0 162 xul.removeAttribute("id");
michael@0 163 svg.removeAttribute("id");
michael@0 164 nsx.removeAttribute("id");
michael@0 165
michael@0 166 checkHasNoId(true, "removed attribute");
michael@0 167
michael@0 168 div.setAttribute("id", "div_id");
michael@0 169 a.setAttribute("id", "a_id");
michael@0 170 xul.setAttribute("id", "xul_id");
michael@0 171 svg.setAttribute("id", "svg_id");
michael@0 172 nsx.setAttribute("id", "ns_id");
michael@0 173
michael@0 174 checkHasId("set using setAttribute");
michael@0 175
michael@0 176 t1 = document.createElement("div");
michael@0 177 t1.id = "div_id";
michael@0 178 t2 = document.createElement("a");
michael@0 179 t2.id = "a_id";
michael@0 180 t3 = document.createElementNS("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul", "button");
michael@0 181 t3.id = "xul_id";
michael@0 182 t4 = document.createElementNS("http://www.w3.org/2000/svg", "g");
michael@0 183 t4.id = "svg_id";
michael@0 184 t5 = document.createElementNS("urn:namespace", "ns:x");
michael@0 185 t5.setAttribute("id", "ns_id");
michael@0 186
michael@0 187 // Check that inserting elements before/after existing work
michael@0 188
michael@0 189 function insertAfter(newChild, existing) {
michael@0 190 existing.parentNode.insertBefore(newChild, existing.nextSibling);
michael@0 191 }
michael@0 192 function insertBefore(newChild, existing) {
michael@0 193 existing.parentNode.insertBefore(newChild, existing);
michael@0 194 }
michael@0 195 function removeNode(child) {
michael@0 196 child.parentNode.removeChild(child);
michael@0 197 }
michael@0 198
michael@0 199 insertAfter(t1, div);
michael@0 200 insertAfter(t2, a);
michael@0 201 insertAfter(t3, xul);
michael@0 202 insertAfter(t4, svg);
michael@0 203 insertAfter(t5, nsx);
michael@0 204
michael@0 205 checkHasId("inserted after");
michael@0 206
michael@0 207 insertBefore(t1, div);
michael@0 208 insertBefore(t2, a);
michael@0 209 insertBefore(t3, xul);
michael@0 210 insertBefore(t4, svg);
michael@0 211 insertBefore(t5, nsx);
michael@0 212
michael@0 213 checkHasIdNoGEBI("inserted before");
michael@0 214 is($("div_id"), t1, "div getElementById inserted before");
michael@0 215 is($("a_id"), t2, "a getElementById inserted before");
michael@0 216 is($("xul_id"), t3, "xul getElementById inserted before");
michael@0 217 is($("svg_id"), t4, "svg getElementById inserted before");
michael@0 218 is($("ns_id"), t5, "ns getElementById inserted before");
michael@0 219
michael@0 220 t1.removeAttribute("id");
michael@0 221 t2.removeAttribute("id");
michael@0 222 t3.removeAttribute("id");
michael@0 223 t4.removeAttribute("id");
michael@0 224 t5.removeAttribute("id");
michael@0 225
michael@0 226 checkHasId("removed tx attribute");
michael@0 227
michael@0 228 t1.setAttribute("id", "div_id");
michael@0 229 t2.setAttribute("id", "a_id");
michael@0 230 t3.setAttribute("id", "xul_id");
michael@0 231 t4.setAttribute("id", "svg_id");
michael@0 232 t5.setAttribute("id", "ns_id");
michael@0 233
michael@0 234 checkHasIdNoGEBI("setAttribute before");
michael@0 235 is($("div_id"), t1, "div getElementById setAttribute before");
michael@0 236 is($("a_id"), t2, "a getElementById setAttribute before");
michael@0 237 is($("xul_id"), t3, "xul getElementById setAttribute before");
michael@0 238 is($("svg_id"), t4, "svg getElementById setAttribute before");
michael@0 239 is($("ns_id"), t5, "ns getElementById setAttribute before");
michael@0 240
michael@0 241 removeNode(t1);
michael@0 242 removeNode(t2);
michael@0 243 removeNode(t3);
michael@0 244 removeNode(t4);
michael@0 245 removeNode(t5);
michael@0 246
michael@0 247 checkHasId("removed temporaries");
michael@0 248
michael@0 249 removeNode(div);
michael@0 250 removeNode(a);
michael@0 251 removeNode(xul);
michael@0 252 removeNode(svg);
michael@0 253 removeNode(nsx);
michael@0 254
michael@0 255 checkHasIdNoGEBI("removed node");
michael@0 256
michael@0 257 // Check that removing an element during UnsetAttr works
michael@0 258 is(div.id, "div_id", "div still has id set");
michael@0 259 var mutateFired = false;
michael@0 260 root.appendChild(div);
michael@0 261 div.addEventListener("DOMAttrModified", function(e) {
michael@0 262 div.removeEventListener("DOMAttrModified", arguments.callee, false);
michael@0 263 is(e.target, div, "target is div");
michael@0 264 is(div.id, "", "div no longer has id");
michael@0 265 is(div.getAttribute("id"), null, "div no longer has id attr");
michael@0 266 removeNode(div);
michael@0 267 is(div.parentNode, null, "div was removed");
michael@0 268 mutateFired = true;
michael@0 269 }, false);
michael@0 270 div.removeAttribute("id");
michael@0 271 ok(mutateFired, "mutation event fired");
michael@0 272
michael@0 273 // Check same for XML elements
michael@0 274 is(nsx.getAttribute("id"), "ns_id", "nsx still has id set");
michael@0 275 mutateFired = false;
michael@0 276 root.appendChild(nsx);
michael@0 277 nsx.addEventListener("DOMAttrModified", function(e) {
michael@0 278 nsx.removeEventListener("DOMAttrModified", arguments.callee, false);
michael@0 279 is(e.target, nsx, "target is nsx");
michael@0 280 is(nsx.getAttribute("id"), null, "nsx no longer has id attr");
michael@0 281 removeNode(nsx);
michael@0 282 is(nsx.parentNode, null, "nsx was removed");
michael@0 283 mutateFired = true;
michael@0 284 }, false);
michael@0 285 nsx.removeAttribute("id");
michael@0 286 ok(mutateFired, "mutation event fired");
michael@0 287
michael@0 288
michael@0 289 // Re-add the id inside a mutation event on a XML element
michael@0 290 is($("ns_id"), null, "no nsx");
michael@0 291 is($("ns2_id"), null, "no nsx");
michael@0 292 nsx = document.createElementNS("urn:namespace", "ns:x");
michael@0 293 nsx.setAttribute("id", "ns_id");
michael@0 294 root.appendChild(nsx);
michael@0 295 is($("ns_id"), nsx, "new nsx is set up");
michael@0 296 mutateFired = false;
michael@0 297 nsx.addEventListener("DOMAttrModified", function(e) {
michael@0 298 nsx.removeEventListener("DOMAttrModified", arguments.callee, false);
michael@0 299 is(e.target, nsx, "target is nsx");
michael@0 300 is(nsx.getAttribute("id"), null, "nsx no longer has id attr");
michael@0 301 nsx.setAttribute("id", "other_id");
michael@0 302 mutateFired = true;
michael@0 303 }, false);
michael@0 304 nsx.removeAttribute("id");
michael@0 305 ok(mutateFired, "mutation event fired");
michael@0 306 is($("ns_id"), null, "ns_id was removed from table");
michael@0 307 is($("other_id"), nsx, "other_id was added");
michael@0 308 removeNode(nsx);
michael@0 309 is($("other_id"), null, "other_id was removed");
michael@0 310
michael@0 311 // Re-add the id inside a mutation event on a HTML element
michael@0 312 is($("div_id"), null, "no div");
michael@0 313 div = document.createElement("div");
michael@0 314 div.id = "div_id";
michael@0 315 root.appendChild(div);
michael@0 316 is($("div_id"), div, "new div is set up");
michael@0 317 mutateFired = false;
michael@0 318 div.addEventListener("DOMAttrModified", function(e) {
michael@0 319 div.removeEventListener("DOMAttrModified", arguments.callee, false);
michael@0 320 is(e.target, div, "target is div");
michael@0 321 is(div.getAttribute("id"), null, "div no longer has id attr");
michael@0 322 is(div.id, "", "div no longer has id");
michael@0 323 div.id = "other_div_id";
michael@0 324 mutateFired = true;
michael@0 325 }, false);
michael@0 326 div.removeAttribute("id");
michael@0 327 ok(mutateFired, "mutation event fired");
michael@0 328 is($("div_id"), null, "div_id was removed from table");
michael@0 329 is($("other_div_id"), div, "other_div_id was added");
michael@0 330 removeNode(div);
michael@0 331 is($("other_div_id"), null, "other_div_id was removed");
michael@0 332
michael@0 333 // Re-add the id inside a mutation event on a XUL element
michael@0 334 is($("xul_id"), null, "no xul");
michael@0 335 xul = document.createElementNS("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul", "button");
michael@0 336 xul.id = "xul_id";
michael@0 337 root.appendChild(xul);
michael@0 338 is($("xul_id"), xul, "new xul is set up");
michael@0 339 mutateFired = false;
michael@0 340 xul.addEventListener("DOMAttrModified", function(e) {
michael@0 341 xul.removeEventListener("DOMAttrModified", arguments.callee, false);
michael@0 342 is(e.target, xul, "target is xul");
michael@0 343 is(xul.getAttribute("id"), "", "xul no longer has id attr");
michael@0 344 is(xul.id, "", "xul no longer has id");
michael@0 345 xul.id = "other_xul_id";
michael@0 346 mutateFired = true;
michael@0 347 }, false);
michael@0 348 xul.removeAttribute("id");
michael@0 349 ok(mutateFired, "mutation event fired");
michael@0 350 is($("xul_id"), null, "xul_id was removed from table");
michael@0 351 is($("other_xul_id"), xul, "other_xul_id was added");
michael@0 352 removeNode(xul);
michael@0 353 is($("other_xul_id"), null, "other_xul_id was removed");
michael@0 354
michael@0 355 ]]>
michael@0 356 </script>
michael@0 357 </pre>
michael@0 358 </body>
michael@0 359 </html>

mercurial