content/base/test/test_bug588990.html

Thu, 15 Jan 2015 21:03:48 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 21:03:48 +0100
branch
TOR_BUG_9701
changeset 11
deefc01c0e14
permissions
-rw-r--r--

Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)

michael@0 1 <html>
michael@0 2 <!--
michael@0 3 https://bugzilla.mozilla.org/show_bug.cgi?id=588990
michael@0 4 -->
michael@0 5 <head>
michael@0 6 <title>Test for Bug 588990</title>
michael@0 7 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
michael@0 8 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
michael@0 9 </head>
michael@0 10 <body>
michael@0 11 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=588990">Mozilla Bug 588990</a>
michael@0 12 <!-- DOM to muck around with for tests -->
michael@0 13 <p id="root">
michael@0 14 <img name="n1">
michael@0 15 <img name="n2">
michael@0 16 <img name="n2">
michael@0 17 <img name="n3">
michael@0 18 <img name="n3">
michael@0 19 <img name="n3">
michael@0 20 </p>
michael@0 21
michael@0 22 <pre id="test">
michael@0 23 <script class="testbody" type="text/javascript">
michael@0 24
michael@0 25 root = $('root');
michael@0 26 i1_1 = root.children[0];
michael@0 27 i2_1 = root.children[1];
michael@0 28 i2_2 = root.children[2];
michael@0 29 i3_1 = root.children[3];
michael@0 30 i3_2 = root.children[4];
michael@0 31 i3_3 = root.children[5];
michael@0 32
michael@0 33 function checkHasName(test) {
michael@0 34 // Check name first to avoid flushes from hiding problems
michael@0 35 checkHasNameNoDocProp(test);
michael@0 36
michael@0 37 is(document.n1, i1_1, "i1_1 doc.name " + test);
michael@0 38 is(document.n2[0], i2_1, "i2_1 doc.name " + test);
michael@0 39 is(document.n2[1], i2_2, "i2_2 doc.name " + test);
michael@0 40 is(document.n2.length, 2, "doc.name.length " + test);
michael@0 41 is(document.n3[0], i3_1, "i3_1 doc.name " + test);
michael@0 42 is(document.n3[1], i3_2, "i3_2 doc.name " + test);
michael@0 43 is(document.n3[2], i3_3, "i3_3 doc.name " + test);
michael@0 44 is(document.n3.length, 3, "doc.name.length " + test);
michael@0 45 }
michael@0 46
michael@0 47 function checkHasNameNoDocProp(test) {
michael@0 48 is(i1_1.name, "n1", "i1_1 name " + test);
michael@0 49 is(i2_1.name, "n2", "i2_1 name " + test);
michael@0 50 is(i2_2.name, "n2", "i2_2 name " + test);
michael@0 51 is(i3_1.name, "n3", "i3_1 name " + test);
michael@0 52 is(i3_2.name, "n3", "i3_2 name " + test);
michael@0 53 is(i3_3.name, "n3", "i3_3 name " + test);
michael@0 54 }
michael@0 55
michael@0 56 function checkHasNoName(removed, test) {
michael@0 57 is(i1_1.name, "", "i1_1 name " + test);
michael@0 58 is(i2_1.name, "", "i2_1 name " + test);
michael@0 59 is(i2_2.name, "", "i2_2 name " + test);
michael@0 60 is(i3_1.name, "", "i3_1 name " + test);
michael@0 61 is(i3_2.name, "", "i3_2 name " + test);
michael@0 62 is(i3_3.name, "", "i3_3 name " + test);
michael@0 63
michael@0 64 var attrValue = removed ? null : "";
michael@0 65 is(i1_1.getAttribute("name"), attrValue, "i1_1 getAttribute " + test);
michael@0 66 is(i2_1.getAttribute("name"), attrValue, "i2_1 getAttribute " + test);
michael@0 67 is(i2_2.getAttribute("name"), attrValue, "i2_2 getAttribute " + test);
michael@0 68 is(i3_1.getAttribute("name"), attrValue, "i3_1 getAttribute " + test);
michael@0 69 is(i3_2.getAttribute("name"), attrValue, "i3_2 getAttribute " + test);
michael@0 70 is(i3_3.getAttribute("name"), attrValue, "i3_3 getAttribute " + test);
michael@0 71
michael@0 72 is(document.n1, undefined, "doc.n1 " + test);
michael@0 73 is(document.n2, undefined, "doc.n2 " + test);
michael@0 74 is(document.n3, undefined, "doc.n3 " + test);
michael@0 75 }
michael@0 76
michael@0 77 // Check that dynamic modifications of attribute work
michael@0 78
michael@0 79 checkHasName("in markup");
michael@0 80
michael@0 81 i1_1.name = "";
michael@0 82 i2_1.name = "";
michael@0 83 i2_2.name = "";
michael@0 84 i3_1.name = "";
michael@0 85 i3_2.name = "";
michael@0 86 i3_3.name = "";
michael@0 87
michael@0 88 checkHasNoName(false, "set to empty");
michael@0 89
michael@0 90 i1_1.name = "n1";
michael@0 91 i2_1.name = "n2";
michael@0 92 i2_2.name = "n2";
michael@0 93 i3_1.name = "n3";
michael@0 94 i3_2.name = "n3";
michael@0 95 i3_3.name = "n3";
michael@0 96
michael@0 97 checkHasName("set using .name");
michael@0 98
michael@0 99 i1_1.setAttribute("name", "");
michael@0 100 i2_1.setAttribute("name", "");
michael@0 101 i2_2.setAttribute("name", "");
michael@0 102 i3_1.setAttribute("name", "");
michael@0 103 i3_2.setAttribute("name", "");
michael@0 104 i3_3.setAttribute("name", "");
michael@0 105
michael@0 106 checkHasNoName(false, "setAttribute to empty");
michael@0 107
michael@0 108 i1_1.name = "n1";
michael@0 109 i2_1.name = "n2";
michael@0 110 i2_2.name = "n2";
michael@0 111 i3_1.name = "n3";
michael@0 112 i3_2.name = "n3";
michael@0 113 i3_3.name = "n3";
michael@0 114
michael@0 115 checkHasName("set again using .name");
michael@0 116
michael@0 117 i1_1.removeAttribute("name");
michael@0 118 i2_1.removeAttribute("name");
michael@0 119 i2_2.removeAttribute("name");
michael@0 120 i3_1.removeAttribute("name");
michael@0 121 i3_2.removeAttribute("name");
michael@0 122 i3_3.removeAttribute("name");
michael@0 123
michael@0 124 checkHasNoName(true, "removed attribute");
michael@0 125
michael@0 126 i1_1.setAttribute("name", "n1");
michael@0 127 i2_1.setAttribute("name", "n2");
michael@0 128 i2_2.setAttribute("name", "n2");
michael@0 129 i3_1.setAttribute("name", "n3");
michael@0 130 i3_2.setAttribute("name", "n3");
michael@0 131 i3_3.setAttribute("name", "n3");
michael@0 132
michael@0 133 checkHasName("set using setAttribute");
michael@0 134
michael@0 135 t1 = document.createElement("img");
michael@0 136 t1.name = "n1";
michael@0 137 t2 = document.createElement("img");
michael@0 138 t2.name = "n2";
michael@0 139 t3 = document.createElement("img");
michael@0 140 t3.name = "n2";
michael@0 141 t4 = document.createElement("img");
michael@0 142 t4.name = "n3";
michael@0 143 t5 = document.createElement("img");
michael@0 144 t5.name = "n3";
michael@0 145 t6 = document.createElement("img");
michael@0 146 t6.name = "n3";
michael@0 147
michael@0 148 // Check that inserting elements before/after existing work
michael@0 149
michael@0 150 function insertAfter(newChild, existing) {
michael@0 151 existing.parentNode.insertBefore(newChild, existing.nextSibling);
michael@0 152 }
michael@0 153 function insertBefore(newChild, existing) {
michael@0 154 existing.parentNode.insertBefore(newChild, existing);
michael@0 155 }
michael@0 156 function removeNode(child) {
michael@0 157 child.parentNode.removeChild(child);
michael@0 158 }
michael@0 159
michael@0 160 insertAfter(t1, i1_1);
michael@0 161 insertAfter(t2, i2_1);
michael@0 162 insertAfter(t3, i2_2);
michael@0 163 insertAfter(t4, i3_1);
michael@0 164 insertAfter(t5, i3_2);
michael@0 165 insertAfter(t6, i3_3);
michael@0 166
michael@0 167 checkHasNameNoDocProp("inserted after");
michael@0 168 is(document.n1[0], i1_1, "i1_1 doc.name inserted after");
michael@0 169 is(document.n1[1], t1, "t1 doc.name inserted after");
michael@0 170 is(document.n1.length, 2, "doc.name1.length inserted after");
michael@0 171 is(document.n2[0], i2_1, "i2_1 doc.name inserted after");
michael@0 172 todo_is(document.n2[1], t2, "This is where t2 should show up. The elements in here should be in order-in-document rather than order-of-insertion");
michael@0 173 is(document.n2[1], i2_2, "i2_2 doc.name inserted after");
michael@0 174 is(document.n2[2], t2, "t2 doc.name inserted after");
michael@0 175 is(document.n2[3], t3, "t3 doc.name inserted after");
michael@0 176 is(document.n2.length, 4, "doc.name2.length inserted after");
michael@0 177 is(document.n3[0], i3_1, "i3_1 doc.name inserted after");
michael@0 178 is(document.n3[1], i3_2, "i3_3 doc.name inserted after");
michael@0 179 is(document.n3[2], i3_3, "i3_2 doc.name inserted after");
michael@0 180 is(document.n3[3], t4, "t4 doc.name inserted after");
michael@0 181 is(document.n3[4], t5, "t5 doc.name inserted after");
michael@0 182 is(document.n3[5], t6, "t6 doc.name inserted after");
michael@0 183 is(document.n3.length, 6, "doc.name3.length inserted after");
michael@0 184
michael@0 185
michael@0 186 insertBefore(t1, i1_1);
michael@0 187 insertBefore(t2, i2_1);
michael@0 188 insertBefore(t3, i2_2);
michael@0 189 insertBefore(t4, i3_1);
michael@0 190 insertBefore(t5, i3_2);
michael@0 191 insertBefore(t6, i3_3);
michael@0 192
michael@0 193 checkHasNameNoDocProp("inserted before");
michael@0 194 is(document.n1[0], i1_1, "i1_1 doc.name inserted before");
michael@0 195 is(document.n1[1], t1, "t1 doc.name inserted before");
michael@0 196 is(document.n1.length, 2, "doc.name1.length inserted before");
michael@0 197 is(document.n2[0], i2_1, "i2_1 doc.name inserted before");
michael@0 198 is(document.n2[1], i2_2, "i2_2 doc.name inserted before");
michael@0 199 is(document.n2[2], t2, "t2 doc.name inserted before");
michael@0 200 is(document.n2[3], t3, "t3 doc.name inserted before");
michael@0 201 is(document.n2.length, 4, "doc.name2.length inserted before");
michael@0 202 is(document.n3[0], i3_1, "i3_1 doc.name inserted before");
michael@0 203 is(document.n3[1], i3_2, "i3_3 doc.name inserted before");
michael@0 204 is(document.n3[2], i3_3, "i3_2 doc.name inserted before");
michael@0 205 is(document.n3[3], t4, "t4 doc.name inserted before");
michael@0 206 is(document.n3[4], t5, "t5 doc.name inserted before");
michael@0 207 is(document.n3[5], t6, "t6 doc.name inserted before");
michael@0 208 is(document.n3.length, 6, "doc.name3.length inserted before");
michael@0 209
michael@0 210 t1.removeAttribute("name");
michael@0 211 t2.removeAttribute("name");
michael@0 212 t3.removeAttribute("name");
michael@0 213 t4.removeAttribute("name");
michael@0 214 t5.removeAttribute("name");
michael@0 215 t6.removeAttribute("name");
michael@0 216
michael@0 217 checkHasName("removed tx attribute");
michael@0 218
michael@0 219 t1.setAttribute("name", "n1");
michael@0 220 t2.setAttribute("name", "n2");
michael@0 221 t3.setAttribute("name", "n2");
michael@0 222 t4.setAttribute("name", "n3");
michael@0 223 t5.setAttribute("name", "n3");
michael@0 224 t6.setAttribute("name", "n3");
michael@0 225
michael@0 226 checkHasNameNoDocProp("inserted before");
michael@0 227 is(document.n1[0], i1_1, "i1_1 doc.name inserted before");
michael@0 228 is(document.n1[1], t1, "t1 doc.name inserted before");
michael@0 229 is(document.n1.length, 2, "doc.name1.length inserted before");
michael@0 230 is(document.n2[0], i2_1, "i2_1 doc.name inserted before");
michael@0 231 is(document.n2[1], i2_2, "i2_2 doc.name inserted before");
michael@0 232 is(document.n2[2], t2, "t2 doc.name inserted before");
michael@0 233 is(document.n2[3], t3, "t3 doc.name inserted before");
michael@0 234 is(document.n2.length, 4, "doc.name2.length inserted before");
michael@0 235 is(document.n3[0], i3_1, "i3_1 doc.name inserted before");
michael@0 236 is(document.n3[1], i3_2, "i3_3 doc.name inserted before");
michael@0 237 is(document.n3[2], i3_3, "i3_2 doc.name inserted before");
michael@0 238 is(document.n3[3], t4, "t4 doc.name inserted before");
michael@0 239 is(document.n3[4], t5, "t5 doc.name inserted before");
michael@0 240 is(document.n3[5], t6, "t6 doc.name inserted before");
michael@0 241 is(document.n3.length, 6, "doc.name3.length inserted before");
michael@0 242
michael@0 243 removeNode(t1);
michael@0 244 removeNode(t2);
michael@0 245 removeNode(t3);
michael@0 246 removeNode(t4);
michael@0 247 removeNode(t5);
michael@0 248 removeNode(t6);
michael@0 249
michael@0 250 checkHasName("removed temporaries");
michael@0 251
michael@0 252 removeNode(i1_1);
michael@0 253 removeNode(i2_1);
michael@0 254 removeNode(i2_2);
michael@0 255 removeNode(i3_1);
michael@0 256 removeNode(i3_2);
michael@0 257 removeNode(i3_3);
michael@0 258
michael@0 259 checkHasNameNoDocProp("removed node");
michael@0 260
michael@0 261 // Check that removing an element during UnsetAttr works
michael@0 262 is(i1_1.name, "n1", "i1_1 has name set");
michael@0 263 var mutateFired = false;
michael@0 264 root.appendChild(i1_1);
michael@0 265 i1_1.addEventListener("DOMAttrModified", function(e) {
michael@0 266 i1_1.removeEventListener("DOMAttrModified", arguments.callee, false);
michael@0 267 is(e.target, i1_1, "target is i1_1");
michael@0 268 is(i1_1.name, "", "i1_1 no longer has name");
michael@0 269 is(i1_1.getAttribute("name"), null, "i1_1 no longer has name attr");
michael@0 270 removeNode(i1_1);
michael@0 271 is(i1_1.parentNode, null, "i1_1 was removed");
michael@0 272 mutateFired = true;
michael@0 273 }, false);
michael@0 274 i1_1.removeAttribute("name");
michael@0 275 ok(mutateFired, "mutation event fired");
michael@0 276 SpecialPowers.gc();
michael@0 277
michael@0 278 // Check that removing an element during SetAttr works
michael@0 279 i2_1.name = "";
michael@0 280 mutateFired = false;
michael@0 281 root.appendChild(i2_1);
michael@0 282 i2_1.addEventListener("DOMAttrModified", function(e) {
michael@0 283 i2_1.removeEventListener("DOMAttrModified", arguments.callee, false);
michael@0 284 is(e.target, i2_1, "target is i2_1");
michael@0 285 is(i2_1.name, "n2", "i2_1 no longer has name");
michael@0 286 is(i2_1.getAttribute("name"), "n2", "i2_1 no longer has name attr");
michael@0 287 removeNode(i2_1);
michael@0 288 is(i2_1.parentNode, null, "i2_1 was removed");
michael@0 289 mutateFired = true;
michael@0 290 }, false);
michael@0 291 i2_1.name = "n2";
michael@0 292 ok(mutateFired, "mutation event fired");
michael@0 293 SpecialPowers.gc();
michael@0 294
michael@0 295 // Re-add the name inside a mutation event on a HTML element
michael@0 296 is(i2_2.name, "n2", "i2_2 has name set");
michael@0 297 root.appendChild(i2_2);
michael@0 298 mutateFired = false;
michael@0 299 root.appendChild(i2_2);
michael@0 300 i2_2.addEventListener("DOMAttrModified", function(e) {
michael@0 301 i2_2.removeEventListener("DOMAttrModified", arguments.callee, false);
michael@0 302 is(e.target, i2_2, "target is i2_2");
michael@0 303 is(i2_2.name, "", "i2_2 no longer has name");
michael@0 304 is(i2_2.getAttribute("name"), "", "i2_2 has empty name attr");
michael@0 305 i2_2.name = "n2";
michael@0 306 mutateFired = true;
michael@0 307 }, false);
michael@0 308 i2_2.name = "";
michael@0 309 ok(mutateFired, "mutation event fired");
michael@0 310 is(document.n2, i2_2, "named was readded during mutation");
michael@0 311 removeNode(i2_2);
michael@0 312 SpecialPowers.gc();
michael@0 313
michael@0 314 // Re-remove the name inside a mutation event on a HTML element
michael@0 315 i3_1.name = "";
michael@0 316 root.appendChild(i3_1);
michael@0 317 mutateFired = false;
michael@0 318 root.appendChild(i3_1);
michael@0 319 i3_1.addEventListener("DOMAttrModified", function(e) {
michael@0 320 i3_1.removeEventListener("DOMAttrModified", arguments.callee, false);
michael@0 321 is(e.target, i3_1, "target is i3_1");
michael@0 322 is(i3_1.name, "n3", "i3_1 no longer has name");
michael@0 323 is(i3_1.getAttribute("name"), "n3", "i3_1 has empty name attr");
michael@0 324 i3_1.removeAttribute("name");
michael@0 325 mutateFired = true;
michael@0 326 }, false);
michael@0 327 i3_1.name = "n3";
michael@0 328 ok(mutateFired, "mutation event fired");
michael@0 329 is(document.n3, undefined, "named was readded during mutation");
michael@0 330 removeNode(i3_1);
michael@0 331 SpecialPowers.gc();
michael@0 332
michael@0 333 </script>
michael@0 334 </pre>
michael@0 335 </body>
michael@0 336 </html>

mercurial