test_bug564863-2.xhtml (4358B)
1 <?xml version="1.0"?> 2 <html xmlns="http://www.w3.org/1999/xhtml" 3 xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> 4 <!-- 5 https://bugzilla.mozilla.org/show_bug.cgi?id=564863 6 --> 7 <head> 8 <title>Test for Bug 564863</title> 9 <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/> 10 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> 11 <style> 12 * { 13 color: rgb(0, 0, 0); 14 } 15 #xul_id { 16 color: rgb(30, 30, 30); 17 } 18 </style> 19 </head> 20 <body> 21 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=564863">Mozilla Bug 564863</a> 22 23 <!-- DOM to muck around with for tests --> 24 <p id="root"> 25 <xul:button id="xul_id" /> 26 </p> 27 28 <pre id="test"> 29 <script type="application/javascript"> 30 <![CDATA[ 31 SimpleTest.waitForExplicitFinish(); 32 33 (async function runTests() { 34 root = $('root'); 35 xul = root.children[0]; 36 37 var xul_cs = getComputedStyle(xul, ""); 38 39 function checkHasId(test) { 40 // Check computed style first to avoid flushes from hiding problems 41 checkHasIdNoGEBI(test); 42 43 is($("xul_id"), xul, "xul getElementById " + test); 44 } 45 46 function checkHasIdNoGEBI(test) { 47 const connected = test != "removed node"; 48 is(xul_cs.color, connected ? "rgb(30, 30, 30)" : "", "xul color " + test); 49 50 is(xul.id, "xul_id", "xul id " + test); 51 } 52 53 function checkHasNoId(removed, test) { 54 // XXX This fails for some reason when this is run as a Mochitest chrome, but 55 // not when run as a Mochitest plain. 56 //is(xul_cs.color, "rgb(0, 0, 0)", "xul color " + test); 57 58 let attrValue = removed ? null : ""; 59 60 is(xul.id, "", "xul id " + test); 61 62 is(xul.getAttribute("id"), attrValue, "xul getAttribute " + test); 63 64 is($("xul_id"), null, "xul getElementById " + test); 65 } 66 67 // Check that dynamic modifications of attribute work 68 69 checkHasId("in markup"); 70 71 xul.id = ""; 72 73 checkHasNoId(false, "set to empty"); 74 75 xul.id = "xul_id"; 76 77 checkHasId("set using .id"); 78 79 xul.setAttribute("id", ""); 80 81 checkHasNoId(false, "setAttribute to empty"); 82 83 xul.id = "xul_id"; 84 85 checkHasId("set again using .id"); 86 87 xul.removeAttribute("id"); 88 89 checkHasNoId(true, "removed attribute"); 90 91 xul.setAttribute("id", "xul_id"); 92 93 checkHasId("set using setAttribute"); 94 95 t3 = document.createElementNS("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul", "button"); 96 t3.id = "xul_id"; 97 98 // Check that inserting elements before/after existing work 99 100 function insertAfter(newChild, existing) { 101 existing.parentNode.insertBefore(newChild, existing.nextSibling); 102 } 103 function insertBefore(newChild, existing) { 104 existing.parentNode.insertBefore(newChild, existing); 105 } 106 function removeNode(child) { 107 child.remove(); 108 } 109 110 insertAfter(t3, xul); 111 112 checkHasId("inserted after"); 113 114 insertBefore(t3, xul); 115 116 checkHasIdNoGEBI("inserted before"); 117 is($("xul_id"), t3, "xul getElementById inserted before"); 118 119 t3.removeAttribute("id"); 120 121 checkHasId("removed tx attribute"); 122 123 t3.setAttribute("id", "xul_id"); 124 125 checkHasIdNoGEBI("setAttribute before"); 126 is($("xul_id"), t3, "xul getElementById setAttribute before"); 127 128 removeNode(t3); 129 130 checkHasId("removed temporaries"); 131 132 removeNode(xul); 133 134 checkHasIdNoGEBI("removed node"); 135 136 // Re-add the id inside a mutation event on a XUL element 137 is($("xul_id"), null, "no xul"); 138 xul = document.createElementNS("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul", "button"); 139 xul.id = "xul_id"; 140 root.appendChild(xul); 141 is($("xul_id"), xul, "new xul is set up"); 142 let mutation; 143 const observer = new MutationObserver((aMutationList, aObserver) => { 144 mutation = aMutationList[0]; 145 aObserver.disconnect(); 146 }); 147 observer.observe(xul, { attributes: true }); 148 xul.removeAttribute("id"); 149 await new Promise(SimpleTest.executeSoon); 150 if (mutation) { 151 is(mutation.target, xul, "target is xul"); 152 is(xul.getAttribute("id"), null, "xul no longer has id attr"); 153 is(xul.id, "", "xul no longer has id"); 154 xul.id = "other_xul_id"; 155 } else { 156 observer.disconnect(); 157 ok(false, "mutation should've occurred"); 158 } 159 is($("xul_id"), null, "xul_id was removed from table"); 160 is($("other_xul_id"), xul, "other_xul_id was added"); 161 removeNode(xul); 162 is($("other_xul_id"), null, "other_xul_id was removed"); 163 164 SimpleTest.finish(); 165 })(); 166 ]]> 167 </script> 168 </pre> 169 </body> 170 </html>