| OLD | NEW |
| 1 <!DOCTYPE HTML> | 1 <!DOCTYPE HTML> |
| 2 <html> | 2 <html> |
| 3 <head> | 3 <head> |
| 4 <script src="../../../resources/js-test.js"></script> | 4 <script src="../../../resources/js-test.js"></script> |
| 5 </head> | 5 </head> |
| 6 <body id="a"> | 6 <body id="a"> |
| 7 <script> | 7 <script> |
| 8 | 8 |
| 9 description("Test that different ways of changing an element's id all work prope
rly."); | 9 description("Test that different ways of changing an element's id all work prope
rly."); |
| 10 | 10 |
| 11 debug("\n1. Check id after parsing."); | 11 debug("\n1. Check id after parsing."); |
| 12 shouldBe('document.getElementById("a")', 'document.body'); | 12 shouldBe('document.getElementById("a")', 'document.body'); |
| 13 shouldBe('document.body.id', '"a"'); | 13 shouldBe('document.body.id', '"a"'); |
| 14 shouldBe('document.body.getAttributeNode("id").textContent', '"a"'); | 14 shouldBe('document.body.getAttributeNode("id").value', '"a"'); |
| 15 | 15 |
| 16 debug("\n2. Change Attr.value."); | 16 debug("\n2. Change Attr.value."); |
| 17 document.body.getAttributeNode("id").value = "b"; | 17 document.body.getAttributeNode("id").value = "b"; |
| 18 shouldBe('document.getElementById("a")', 'null'); | 18 shouldBe('document.getElementById("a")', 'null'); |
| 19 shouldBe('document.getElementById("b")', 'document.body'); | 19 shouldBe('document.getElementById("b")', 'document.body'); |
| 20 shouldBe('document.body.getAttributeNode("id").textContent', '"b"'); | 20 shouldBe('document.body.getAttributeNode("id").value', '"b"'); |
| 21 | 21 |
| 22 debug("\n3. Change HTMLElement.id."); | 22 debug("\n3. Change HTMLElement.id."); |
| 23 document.body.id = "c"; | 23 document.body.id = "c"; |
| 24 shouldBe('document.getElementById("b")', 'null'); | 24 shouldBe('document.getElementById("b")', 'null'); |
| 25 shouldBe('document.getElementById("c")', 'document.body'); | 25 shouldBe('document.getElementById("c")', 'document.body'); |
| 26 shouldBe('document.body.getAttributeNode("id").textContent', '"c"'); | 26 shouldBe('document.body.getAttributeNode("id").value', '"c"'); |
| 27 | 27 |
| 28 debug("\n4. Change id attribute via setAttribute()."); | 28 debug("\n4. Change id attribute via setAttribute()."); |
| 29 document.body.setAttribute("id", "d"); | 29 document.body.setAttribute("id", "d"); |
| 30 shouldBe('document.getElementById("c")', 'null'); | 30 shouldBe('document.getElementById("c")', 'null'); |
| 31 shouldBe('document.getElementById("d")', 'document.body'); | 31 shouldBe('document.getElementById("d")', 'document.body'); |
| 32 shouldBe('document.body.getAttributeNode("id").textContent', '"d"'); | 32 shouldBe('document.body.getAttributeNode("id").value', '"d"'); |
| 33 | 33 |
| 34 debug("\n5. Change id attribute via setAttributeNS()."); | 34 debug("\n5. Change id attribute via setAttributeNS()."); |
| 35 document.body.setAttributeNS(null, "id", "e"); | 35 document.body.setAttributeNS(null, "id", "e"); |
| 36 shouldBe('document.getElementById("d")', 'null'); | 36 shouldBe('document.getElementById("d")', 'null'); |
| 37 shouldBe('document.getElementById("e")', 'document.body'); | 37 shouldBe('document.getElementById("e")', 'document.body'); |
| 38 shouldBe('document.body.getAttributeNode("id").textContent', '"e"'); | 38 shouldBe('document.body.getAttributeNode("id").value', '"e"'); |
| 39 | 39 |
| 40 var attrNode = document.body.getAttributeNode("id"); | 40 var attrNode = document.body.getAttributeNode("id"); |
| 41 | 41 |
| 42 debug("\n6. Change Attr.nodeValue."); | 42 debug("\n6. Change Attr.nodeValue."); |
| 43 document.body.getAttributeNode("id").nodeValue = "f"; | 43 document.body.getAttributeNode("id").nodeValue = "f"; |
| 44 shouldBe('document.getElementById("e")', 'null'); | 44 shouldBe('document.getElementById("e")', 'null'); |
| 45 shouldBe('document.getElementById("f")', 'document.body'); | 45 shouldBe('document.getElementById("f")', 'document.body'); |
| 46 shouldBe('document.body.id', '"f"'); | 46 shouldBe('document.body.id', '"f"'); |
| 47 shouldBe('document.body.getAttribute("id")', '"f"'); | 47 shouldBe('document.body.getAttribute("id")', '"f"'); |
| 48 shouldBe('attrNode.textContent', '"f"'); | 48 shouldBe('attrNode.value', '"f"'); |
| 49 shouldBe('attrNode.childNodes.length', '1'); | 49 shouldBe('attrNode.childNodes.length', '1'); |
| 50 | 50 |
| 51 // Firefox doesn't support these for Attr nodes. | 51 // Firefox doesn't support these for Attr nodes. |
| 52 debug("\n7. Attr.replaceChild()."); | 52 debug("\n7. Attr.replaceChild()."); |
| 53 try { | 53 try { |
| 54 attrNode.replaceChild(document.createTextNode("g"), attrNode.firstChild); | 54 attrNode.replaceChild(document.createTextNode("g"), attrNode.firstChild); |
| 55 shouldBe('document.getElementById("f")', 'null'); | 55 shouldBe('document.getElementById("f")', 'null'); |
| 56 shouldBe('document.getElementById("g")', 'document.body'); | 56 shouldBe('document.getElementById("g")', 'document.body'); |
| 57 shouldBe('document.body.id', '"g"'); | 57 shouldBe('document.body.id', '"g"'); |
| 58 shouldBe('document.body.getAttribute("id")', '"g"'); | 58 shouldBe('document.body.getAttribute("id")', '"g"'); |
| 59 shouldBe('attrNode.textContent', '"g"'); | 59 shouldBe('attrNode.value', '"g"'); |
| 60 shouldBe('attrNode.childNodes.length', '1'); | 60 shouldBe('attrNode.childNodes.length', '1'); |
| 61 } catch (ex) { | 61 } catch (ex) { |
| 62 debug(ex); | 62 debug(ex); |
| 63 } | 63 } |
| 64 | 64 |
| 65 debug("\n8. Attr.insertBefore()."); | 65 debug("\n8. Attr.insertBefore()."); |
| 66 try { | 66 try { |
| 67 attrNode.insertBefore(document.createTextNode("0"), attrNode.firstChild); | 67 attrNode.insertBefore(document.createTextNode("0"), attrNode.firstChild); |
| 68 shouldBe('document.getElementById("g")', 'null'); | 68 shouldBe('document.getElementById("g")', 'null'); |
| 69 shouldBe('document.getElementById("0g")', 'document.body'); | 69 shouldBe('document.getElementById("0g")', 'document.body'); |
| 70 shouldBe('document.body.id', '"0g"'); | 70 shouldBe('document.body.id', '"0g"'); |
| 71 shouldBe('document.body.getAttribute("id")', '"0g"'); | 71 shouldBe('document.body.getAttribute("id")', '"0g"'); |
| 72 shouldBe('attrNode.textContent', '"0g"'); | 72 shouldBe('attrNode.value', '"0g"'); |
| 73 shouldBe('attrNode.childNodes.length', '2'); | 73 shouldBe('attrNode.childNodes.length', '2'); |
| 74 } catch (ex) { | 74 } catch (ex) { |
| 75 debug(ex); | 75 debug(ex); |
| 76 } | 76 } |
| 77 | 77 |
| 78 debug("\n9. attr.appendChild()."); | 78 debug("\n9. attr.appendChild()."); |
| 79 try { | 79 try { |
| 80 attrNode.appendChild(document.createTextNode("2")); | 80 attrNode.appendChild(document.createTextNode("2")); |
| 81 shouldBe('document.getElementById("0g")', 'null'); | 81 shouldBe('document.getElementById("0g")', 'null'); |
| 82 shouldBe('document.getElementById("0g2")', 'document.body'); | 82 shouldBe('document.getElementById("0g2")', 'document.body'); |
| 83 shouldBe('document.body.id', '"0g2"'); | 83 shouldBe('document.body.id', '"0g2"'); |
| 84 shouldBe('document.body.getAttribute("id")', '"0g2"'); | 84 shouldBe('document.body.getAttribute("id")', '"0g2"'); |
| 85 shouldBe('attrNode.textContent', '"0g2"'); | 85 shouldBe('attrNode.value', '"0g2"'); |
| 86 shouldBe('attrNode.childNodes.length', '3'); | 86 shouldBe('attrNode.childNodes.length', '3'); |
| 87 } catch (ex) { | 87 } catch (ex) { |
| 88 debug(ex); | 88 debug(ex); |
| 89 } | 89 } |
| 90 | 90 |
| 91 debug("\n10. Attr.removeChild()"); | 91 debug("\n10. Attr.removeChild()"); |
| 92 attrNode.nodeValue = "h"; | 92 attrNode.nodeValue = "h"; |
| 93 attrNode.removeChild(attrNode.firstChild); | 93 attrNode.removeChild(attrNode.firstChild); |
| 94 shouldBe('document.body.getAttributeNode("id").childNodes.length', '0'); | 94 shouldBe('document.body.getAttributeNode("id").childNodes.length', '0'); |
| 95 shouldBe('document.getElementById("h")', 'null'); | 95 shouldBe('document.getElementById("h")', 'null'); |
| 96 shouldBe('document.getElementById("")', 'null'); | 96 shouldBe('document.getElementById("")', 'null'); |
| 97 shouldBe('document.body.id', '""'); | 97 shouldBe('document.body.id', '""'); |
| 98 shouldBe('document.body.getAttribute("id")', '""'); | 98 shouldBe('document.body.getAttribute("id")', '""'); |
| 99 shouldBe('document.body.getAttributeNode("id").textContent', '""'); | 99 shouldBe('document.body.getAttributeNode("id").value', '""'); |
| 100 | 100 |
| 101 debug("\n11. Changing Text.nodeValue."); | 101 debug("\n11. Changing Text.nodeValue."); |
| 102 attrNode.nodeValue = "h"; | 102 attrNode.nodeValue = "h"; |
| 103 attrNode.firstChild.nodeValue = "i"; | 103 attrNode.firstChild.nodeValue = "i"; |
| 104 shouldBe('attrNode.firstChild.nodeValue', '"i"'); | 104 shouldBe('attrNode.firstChild.nodeValue', '"i"'); |
| 105 shouldBe('document.getElementById("i")', 'document.body'); | 105 shouldBe('document.getElementById("i")', 'document.body'); |
| 106 shouldBe('document.body.id', '"i"'); | 106 shouldBe('document.body.id', '"i"'); |
| 107 shouldBe('document.body.getAttribute("id")', '"i"'); | 107 shouldBe('document.body.getAttribute("id")', '"i"'); |
| 108 shouldBe('attrNode.textContent', '"i"'); | 108 shouldBe('attrNode.value', '"i"'); |
| 109 shouldBe('attrNode.childNodes.length', '1'); | 109 shouldBe('attrNode.childNodes.length', '1'); |
| 110 | 110 |
| 111 debug("\n12. Chnaging Attr.textContent."); | 111 debug("\n12. Chnaging Attr.value."); |
| 112 attrNode.textContent = "hi"; | 112 attrNode.value = "hi"; |
| 113 shouldBe('document.getElementById("i")', 'null'); | 113 shouldBe('document.getElementById("i")', 'null'); |
| 114 shouldBe('document.getElementById("hi")', 'document.body'); | 114 shouldBe('document.getElementById("hi")', 'document.body'); |
| 115 shouldBe('document.body.id', '"hi"'); | 115 shouldBe('document.body.id', '"hi"'); |
| 116 shouldBe('document.body.getAttribute("id")', '"hi"'); | 116 shouldBe('document.body.getAttribute("id")', '"hi"'); |
| 117 shouldBe('attrNode.textContent', '"hi"'); | 117 shouldBe('attrNode.value', '"hi"'); |
| 118 shouldBe('attrNode.childNodes.length', '1'); | 118 shouldBe('attrNode.childNodes.length', '1'); |
| 119 | 119 |
| 120 debug("\n13. Text.splitText()."); | 120 debug("\n13. Text.splitText()."); |
| 121 attrNode.firstChild.splitText(1); | 121 attrNode.firstChild.splitText(1); |
| 122 shouldBe('document.getElementById("hi")', 'document.body'); | 122 shouldBe('document.getElementById("hi")', 'document.body'); |
| 123 shouldBe('document.body.id', '"hi"'); | 123 shouldBe('document.body.id', '"hi"'); |
| 124 shouldBe('document.body.getAttribute("id")', '"hi"'); | 124 shouldBe('document.body.getAttribute("id")', '"hi"'); |
| 125 shouldBe('document.body.getAttributeNode("id").textContent', '"hi"'); | 125 shouldBe('document.body.getAttributeNode("id").value', '"hi"'); |
| 126 shouldBe('document.body.getAttributeNode("id").childNodes.length', '2'); | 126 shouldBe('document.body.getAttributeNode("id").childNodes.length', '2'); |
| 127 | 127 |
| 128 debug("\n14. Node.normalize(), joining text nodes."); | 128 debug("\n14. Node.normalize(), joining text nodes."); |
| 129 attrNode.normalize(); | 129 attrNode.normalize(); |
| 130 shouldBe('document.getElementById("hi")', 'document.body'); | 130 shouldBe('document.getElementById("hi")', 'document.body'); |
| 131 shouldBe('document.body.id', '"hi"'); | 131 shouldBe('document.body.id', '"hi"'); |
| 132 shouldBe('document.body.getAttribute("id")', '"hi"'); | 132 shouldBe('document.body.getAttribute("id")', '"hi"'); |
| 133 shouldBe('document.body.getAttributeNode("id").textContent', '"hi"'); | 133 shouldBe('document.body.getAttributeNode("id").value', '"hi"'); |
| 134 shouldBe('document.body.getAttributeNode("id").childNodes.length', '1'); | 134 shouldBe('document.body.getAttributeNode("id").childNodes.length', '1'); |
| 135 | 135 |
| 136 debug("\n15. Changing Attr.nodeValue."); | 136 debug("\n15. Changing Attr.nodeValue."); |
| 137 attrNode.nodeValue = "foo"; | 137 attrNode.nodeValue = "foo"; |
| 138 attrNode.firstChild.replaceWholeText("j"); | 138 attrNode.firstChild.replaceWholeText("j"); |
| 139 shouldBe('document.getElementById("hi")', 'null'); | 139 shouldBe('document.getElementById("hi")', 'null'); |
| 140 shouldBe('document.getElementById("j")', 'document.body'); | 140 shouldBe('document.getElementById("j")', 'document.body'); |
| 141 shouldBe('document.body.id', '"j"'); | 141 shouldBe('document.body.id', '"j"'); |
| 142 shouldBe('document.body.getAttribute("id")', '"j"'); | 142 shouldBe('document.body.getAttribute("id")', '"j"'); |
| 143 shouldBe('attrNode.textContent', '"j"'); | 143 shouldBe('attrNode.value', '"j"'); |
| 144 shouldBe('attrNode.childNodes.length', '1'); | 144 shouldBe('attrNode.childNodes.length', '1'); |
| 145 | 145 |
| 146 debug("\n16. Changing Text.data."); | 146 debug("\n16. Changing Text.data."); |
| 147 attrNode.firstChild.data = "k"; | 147 attrNode.firstChild.data = "k"; |
| 148 shouldBe('document.getElementById("j")', 'null'); | 148 shouldBe('document.getElementById("j")', 'null'); |
| 149 shouldBe('document.getElementById("k")', 'document.body'); | 149 shouldBe('document.getElementById("k")', 'document.body'); |
| 150 shouldBe('document.body.id', '"k"'); | 150 shouldBe('document.body.id', '"k"'); |
| 151 shouldBe('document.body.getAttribute("id")', '"k"'); | 151 shouldBe('document.body.getAttribute("id")', '"k"'); |
| 152 shouldBe('attrNode.textContent', '"k"'); | 152 shouldBe('attrNode.value', '"k"'); |
| 153 shouldBe('attrNode.childNodes.length', '1'); | 153 shouldBe('attrNode.childNodes.length', '1'); |
| 154 | 154 |
| 155 debug("\n17. Changing text child with appendData()."); | 155 debug("\n17. Changing text child with appendData()."); |
| 156 attrNode.firstChild.appendData("l"); | 156 attrNode.firstChild.appendData("l"); |
| 157 shouldBe('document.getElementById("k")', 'null'); | 157 shouldBe('document.getElementById("k")', 'null'); |
| 158 shouldBe('document.getElementById("kl")', 'document.body'); | 158 shouldBe('document.getElementById("kl")', 'document.body'); |
| 159 shouldBe('document.body.id', '"kl"'); | 159 shouldBe('document.body.id', '"kl"'); |
| 160 shouldBe('document.body.getAttribute("id")', '"kl"'); | 160 shouldBe('document.body.getAttribute("id")', '"kl"'); |
| 161 shouldBe('attrNode.textContent', '"kl"'); | 161 shouldBe('attrNode.value', '"kl"'); |
| 162 shouldBe('attrNode.childNodes.length', '1'); | 162 shouldBe('attrNode.childNodes.length', '1'); |
| 163 | 163 |
| 164 debug("\n18. Changing text child with insertData()."); | 164 debug("\n18. Changing text child with insertData()."); |
| 165 attrNode.firstChild.insertData(1, "1"); | 165 attrNode.firstChild.insertData(1, "1"); |
| 166 shouldBe('document.getElementById("kl")', 'null'); | 166 shouldBe('document.getElementById("kl")', 'null'); |
| 167 shouldBe('document.getElementById("k1l")', 'document.body'); | 167 shouldBe('document.getElementById("k1l")', 'document.body'); |
| 168 shouldBe('document.body.id', '"k1l"'); | 168 shouldBe('document.body.id', '"k1l"'); |
| 169 shouldBe('document.body.getAttribute("id")', '"k1l"'); | 169 shouldBe('document.body.getAttribute("id")', '"k1l"'); |
| 170 shouldBe('attrNode.textContent', '"k1l"'); | 170 shouldBe('attrNode.value', '"k1l"'); |
| 171 shouldBe('attrNode.childNodes.length', '1'); | 171 shouldBe('attrNode.childNodes.length', '1'); |
| 172 | 172 |
| 173 debug("\n19. Changing text child with deleteData()."); | 173 debug("\n19. Changing text child with deleteData()."); |
| 174 attrNode.firstChild.deleteData(0, 2); | 174 attrNode.firstChild.deleteData(0, 2); |
| 175 shouldBe('document.getElementById("k1l")', 'null'); | 175 shouldBe('document.getElementById("k1l")', 'null'); |
| 176 shouldBe('document.getElementById("l")', 'document.body'); | 176 shouldBe('document.getElementById("l")', 'document.body'); |
| 177 shouldBe('document.body.id', '"l"'); | 177 shouldBe('document.body.id', '"l"'); |
| 178 shouldBe('document.body.getAttribute("id")', '"l"'); | 178 shouldBe('document.body.getAttribute("id")', '"l"'); |
| 179 shouldBe('attrNode.textContent', '"l"'); | 179 shouldBe('attrNode.value', '"l"'); |
| 180 shouldBe('attrNode.childNodes.length', '1'); | 180 shouldBe('attrNode.childNodes.length', '1'); |
| 181 | 181 |
| 182 debug("\n20. Changing text child with replaceData()."); | 182 debug("\n20. Changing text child with replaceData()."); |
| 183 attrNode.firstChild.replaceData(0, 1, "mn"); | 183 attrNode.firstChild.replaceData(0, 1, "mn"); |
| 184 shouldBe('document.getElementById("l")', 'null'); | 184 shouldBe('document.getElementById("l")', 'null'); |
| 185 shouldBe('document.getElementById("mn")', 'document.body'); | 185 shouldBe('document.getElementById("mn")', 'document.body'); |
| 186 shouldBe('document.body.id', '"mn"'); | 186 shouldBe('document.body.id', '"mn"'); |
| 187 shouldBe('document.body.getAttribute("id")', '"mn"'); | 187 shouldBe('document.body.getAttribute("id")', '"mn"'); |
| 188 shouldBe('attrNode.textContent', '"mn"'); | 188 shouldBe('attrNode.value', '"mn"'); |
| 189 shouldBe('attrNode.childNodes.length', '1'); | 189 shouldBe('attrNode.childNodes.length', '1'); |
| 190 | 190 |
| 191 debug("\n21. Remove an Attr node."); | 191 debug("\n21. Remove an Attr node."); |
| 192 document.body.removeAttributeNode(attrNode); | 192 document.body.removeAttributeNode(attrNode); |
| 193 shouldBe('document.body.id', '""'); | 193 shouldBe('document.body.id', '""'); |
| 194 shouldBe('document.getElementById("mn")', 'null'); | 194 shouldBe('document.getElementById("mn")', 'null'); |
| 195 shouldBe('document.body.getAttribute("id")', 'null'); | 195 shouldBe('document.body.getAttribute("id")', 'null'); |
| 196 shouldBe('document.body.getAttributeNode("id")', 'null'); | 196 shouldBe('document.body.getAttributeNode("id")', 'null'); |
| 197 | 197 |
| 198 debug("\n22. Add an Attr node."); | 198 debug("\n22. Add an Attr node."); |
| 199 var attrNode = document.createAttribute("id"); | 199 var attrNode = document.createAttribute("id"); |
| 200 attrNode.value = "o"; | 200 attrNode.value = "o"; |
| 201 document.body.setAttributeNode(attrNode); | 201 document.body.setAttributeNode(attrNode); |
| 202 shouldBe('document.getElementById("o")', 'document.body'); | 202 shouldBe('document.getElementById("o")', 'document.body'); |
| 203 shouldBe('document.body.id', '"o"'); | 203 shouldBe('document.body.id', '"o"'); |
| 204 shouldBe('document.body.getAttribute("id")', '"o"'); | 204 shouldBe('document.body.getAttribute("id")', '"o"'); |
| 205 | 205 |
| 206 debug("\n23. Add an Attr node over an existing one."); | 206 debug("\n23. Add an Attr node over an existing one."); |
| 207 var attrNode = document.createAttribute("id"); | 207 var attrNode = document.createAttribute("id"); |
| 208 attrNode.value = "p"; | 208 attrNode.value = "p"; |
| 209 document.body.setAttributeNode(attrNode); | 209 document.body.setAttributeNode(attrNode); |
| 210 shouldBe('document.getElementById("o")', 'null'); | 210 shouldBe('document.getElementById("o")', 'null'); |
| 211 shouldBe('document.getElementById("p")', 'document.body'); | 211 shouldBe('document.getElementById("p")', 'document.body'); |
| 212 shouldBe('document.body.id', '"p"'); | 212 shouldBe('document.body.id', '"p"'); |
| 213 shouldBe('document.body.getAttribute("id")', '"p"'); | 213 shouldBe('document.body.getAttribute("id")', '"p"'); |
| 214 </script> | 214 </script> |
| 215 </body> | 215 </body> |
| 216 </html> | 216 </html> |
| OLD | NEW |