test_bug564863.xhtml (6548B)
1 <!DOCTYPE html [ 2 <!ATTLIST ns:x id ID #REQUIRED> 3 <!ATTLIST ns2:x id_2 ID #REQUIRED> 4 ]> 5 <html xmlns="http://www.w3.org/1999/xhtml" 6 xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" 7 xmlns:svg="http://www.w3.org/2000/svg" 8 xmlns:ns="urn:namespace" 9 xmlns:ns2="urn:namespace"> 10 <!-- 11 https://bugzilla.mozilla.org/show_bug.cgi?id=564863 12 --> 13 <head> 14 <title>Test for Bug 564863</title> 15 <script src="/tests/SimpleTest/SimpleTest.js"></script> 16 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> 17 <style> 18 * { 19 color: rgb(0, 0, 0); 20 } 21 #div_id { 22 color: rgb(10, 10, 10); 23 } 24 #a_id { 25 color: rgb(20, 20, 20); 26 } 27 #svg_id { 28 color: rgb(40, 40, 40); 29 } 30 #ns_id { 31 color: rgb(50, 50, 50); 32 } 33 #ns2_id { 34 color: rgb(60, 60, 60); 35 } 36 </style> 37 </head> 38 <body> 39 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=564863">Mozilla Bug 564863</a> 40 <!-- Elements to ensure we have nodeinfos with id-attribute set --> 41 <div><ns:x id="ns-holder"/><ns2:x id_2="ns2-holder"/></div> 42 43 <!-- DOM to muck around with for tests --> 44 <p id="root"> 45 <div id="div_id" /> 46 <a id="a_id" /> 47 <svg:svg><svg:g id="svg_id" /></svg:svg> 48 <ns:x id="ns_id" /> 49 </p> 50 51 <pre id="test"> 52 <script class="testbody" type="text/javascript"> 53 <![CDATA[ 54 55 function test() { 56 root = $('root'); 57 div = root.children[0]; 58 a = root.children[1]; 59 svg = root.children[2].firstChild; 60 nsx = root.children[3]; 61 62 var div_cs = getComputedStyle(div, ""); 63 var a_cs = getComputedStyle(a, ""); 64 var svg_cs = getComputedStyle(svg, ""); 65 var nsx_cs = getComputedStyle(nsx, ""); 66 67 function checkHasId(test) { 68 // Check computed style first to avoid flushes from hiding problems 69 checkHasIdNoGEBI(test); 70 71 is($("div_id"), div, "div getElementById " + test); 72 is($("a_id"), a, "a getElementById " + test); 73 is($("svg_id"), svg, "svg getElementById " + test); 74 is($("ns_id"), nsx, "ns getElementById " + test); 75 } 76 77 function checkHasIdNoGEBI(test) { 78 const connected = test != "removed node"; 79 is(div_cs.color, connected ? "rgb(10, 10, 10)" : "", "div color " + test); 80 is(a_cs.color, connected ? "rgb(20, 20, 20)" : "", "a color " + test); 81 is(svg_cs.color, connected ? "rgb(40, 40, 40)" : "", "svg color " + test); 82 is(nsx_cs.color, connected ? "rgb(50, 50, 50)" : "", "nsx color " + test); 83 84 is(div.id, "div_id", "div id " + test); 85 is(a.id, "a_id", "a id " + test); 86 is(svg.id, "svg_id", "svg id " + test); 87 is (nsx.getAttribute("id"), "ns_id", "ns id " + test); 88 } 89 90 function checkHasNoId(removed, test) { 91 is(div_cs.color, "rgb(0, 0, 0)", "div color " + test); 92 is(a_cs.color, "rgb(0, 0, 0)", "a color " + test); 93 is(svg_cs.color, "rgb(0, 0, 0)", "svg color " + test); 94 is(nsx_cs.color, "rgb(0, 0, 0)", "nsx color " + test); 95 96 attrValue = removed ? null : ""; 97 98 is(div.id, "", "div id " + test); 99 is(a.id, "", "a id " + test); 100 is(svg.id, "", "svg id " + test); 101 102 is(div.getAttribute("id"), attrValue, "div getAttribute " + test); 103 is(a.getAttribute("id"), attrValue, "a getAttribute " + test); 104 is(svg.getAttribute("id"), attrValue, "svg getAttribute " + test); 105 is(nsx.getAttribute("id"), attrValue, "ns getAttribute " + test); 106 107 is($("div_id"), null, "div getElementById " + test); 108 is($("a_id"), null, "a getElementById " + test); 109 is($("svg_id"), null, "svg getElementById " + test); 110 is($("ns_id"), null, "ns getElementById " + test); 111 } 112 113 // Check that dynamic modifications of attribute work 114 115 checkHasId("in markup"); 116 117 div.id = ""; 118 a.id = ""; 119 svg.id = ""; 120 nsx.setAttribute("id", ""); 121 122 checkHasNoId(false, "set to empty"); 123 124 div.id = "div_id"; 125 a.id = "a_id"; 126 svg.id = "svg_id"; 127 nsx.setAttribute("id", "ns_id"); 128 129 checkHasId("set using .id"); 130 131 div.setAttribute("id", ""); 132 a.setAttribute("id", ""); 133 svg.setAttribute("id", ""); 134 nsx.setAttribute("id", ""); 135 136 checkHasNoId(false, "setAttribute to empty"); 137 138 div.id = "div_id"; 139 a.id = "a_id"; 140 svg.id = "svg_id"; 141 nsx.setAttribute("id", "ns_id"); 142 143 checkHasId("set again using .id"); 144 145 div.removeAttribute("id"); 146 a.removeAttribute("id"); 147 svg.removeAttribute("id"); 148 nsx.removeAttribute("id"); 149 150 checkHasNoId(true, "removed attribute"); 151 152 div.setAttribute("id", "div_id"); 153 a.setAttribute("id", "a_id"); 154 svg.setAttribute("id", "svg_id"); 155 nsx.setAttribute("id", "ns_id"); 156 157 checkHasId("set using setAttribute"); 158 159 t1 = document.createElement("div"); 160 t1.id = "div_id"; 161 t2 = document.createElement("a"); 162 t2.id = "a_id"; 163 t4 = document.createElementNS("http://www.w3.org/2000/svg", "g"); 164 t4.id = "svg_id"; 165 t5 = document.createElementNS("urn:namespace", "ns:x"); 166 t5.setAttribute("id", "ns_id"); 167 168 // Check that inserting elements before/after existing work 169 170 function insertAfter(newChild, existing) { 171 existing.parentNode.insertBefore(newChild, existing.nextSibling); 172 } 173 function insertBefore(newChild, existing) { 174 existing.parentNode.insertBefore(newChild, existing); 175 } 176 function removeNode(child) { 177 child.remove(); 178 } 179 180 insertAfter(t1, div); 181 insertAfter(t2, a); 182 insertAfter(t4, svg); 183 insertAfter(t5, nsx); 184 185 checkHasId("inserted after"); 186 187 insertBefore(t1, div); 188 insertBefore(t2, a); 189 insertBefore(t4, svg); 190 insertBefore(t5, nsx); 191 192 checkHasIdNoGEBI("inserted before"); 193 is($("div_id"), t1, "div getElementById inserted before"); 194 is($("a_id"), t2, "a getElementById inserted before"); 195 is($("svg_id"), t4, "svg getElementById inserted before"); 196 is($("ns_id"), t5, "ns getElementById inserted before"); 197 198 t1.removeAttribute("id"); 199 t2.removeAttribute("id"); 200 t4.removeAttribute("id"); 201 t5.removeAttribute("id"); 202 203 checkHasId("removed tx attribute"); 204 205 t1.setAttribute("id", "div_id"); 206 t2.setAttribute("id", "a_id"); 207 t4.setAttribute("id", "svg_id"); 208 t5.setAttribute("id", "ns_id"); 209 210 checkHasIdNoGEBI("setAttribute before"); 211 is($("div_id"), t1, "div getElementById setAttribute before"); 212 is($("a_id"), t2, "a getElementById setAttribute before"); 213 is($("svg_id"), t4, "svg getElementById setAttribute before"); 214 is($("ns_id"), t5, "ns getElementById setAttribute before"); 215 216 removeNode(t1); 217 removeNode(t2); 218 removeNode(t4); 219 removeNode(t5); 220 221 checkHasId("removed temporaries"); 222 223 removeNode(div); 224 removeNode(a); 225 removeNode(svg); 226 removeNode(nsx); 227 228 checkHasIdNoGEBI("removed node"); 229 230 SimpleTest.finish(); 231 } 232 233 SimpleTest.waitForExplicitFinish(); 234 SimpleTest.executeSoon(test); 235 236 ]]> 237 </script> 238 </pre> 239 </body> 240 </html>