OLD | NEW |
| (Empty) |
1 <!DOCTYPE HTML> | |
2 <html> | |
3 <head> | |
4 <script src="../../../resources/js-test.js"></script> | |
5 </head> | |
6 <body id="a"> | |
7 <script> | |
8 | |
9 description("Test that different ways of changing an element's id all work prope
rly."); | |
10 | |
11 debug("\n1. Check id after parsing."); | |
12 shouldBe('document.getElementById("a")', 'document.body'); | |
13 shouldBe('document.body.id', '"a"'); | |
14 shouldBe('document.body.getAttributeNode("id").value', '"a"'); | |
15 | |
16 debug("\n2. Change Attr.value."); | |
17 document.body.getAttributeNode("id").value = "b"; | |
18 shouldBe('document.getElementById("a")', 'null'); | |
19 shouldBe('document.getElementById("b")', 'document.body'); | |
20 shouldBe('document.body.getAttributeNode("id").value', '"b"'); | |
21 | |
22 debug("\n3. Change HTMLElement.id."); | |
23 document.body.id = "c"; | |
24 shouldBe('document.getElementById("b")', 'null'); | |
25 shouldBe('document.getElementById("c")', 'document.body'); | |
26 shouldBe('document.body.getAttributeNode("id").value', '"c"'); | |
27 | |
28 debug("\n4. Change id attribute via setAttribute()."); | |
29 document.body.setAttribute("id", "d"); | |
30 shouldBe('document.getElementById("c")', 'null'); | |
31 shouldBe('document.getElementById("d")', 'document.body'); | |
32 shouldBe('document.body.getAttributeNode("id").value', '"d"'); | |
33 | |
34 debug("\n5. Change id attribute via setAttributeNS()."); | |
35 document.body.setAttributeNS(null, "id", "e"); | |
36 shouldBe('document.getElementById("d")', 'null'); | |
37 shouldBe('document.getElementById("e")', 'document.body'); | |
38 shouldBe('document.body.getAttributeNode("id").value', '"e"'); | |
39 | |
40 var attrNode = document.body.getAttributeNode("id"); | |
41 | |
42 debug("\n6. Change Attr.nodeValue."); | |
43 document.body.getAttributeNode("id").nodeValue = "f"; | |
44 shouldBe('document.getElementById("e")', 'null'); | |
45 shouldBe('document.getElementById("f")', 'document.body'); | |
46 shouldBe('document.body.id', '"f"'); | |
47 shouldBe('document.body.getAttribute("id")', '"f"'); | |
48 shouldBe('attrNode.value', '"f"'); | |
49 | |
50 debug("\n12. Chnaging Attr.value."); | |
51 attrNode.value = "hi"; | |
52 shouldBe('document.getElementById("i")', 'null'); | |
53 shouldBe('document.getElementById("hi")', 'document.body'); | |
54 shouldBe('document.body.id', '"hi"'); | |
55 shouldBe('document.body.getAttribute("id")', '"hi"'); | |
56 shouldBe('attrNode.value', '"hi"'); | |
57 | |
58 debug("\n21. Remove an Attr node."); | |
59 document.body.removeAttributeNode(attrNode); | |
60 shouldBe('document.body.id', '""'); | |
61 shouldBe('document.getElementById("mn")', 'null'); | |
62 shouldBe('document.body.getAttribute("id")', 'null'); | |
63 shouldBe('document.body.getAttributeNode("id")', 'null'); | |
64 | |
65 debug("\n22. Add an Attr node."); | |
66 var attrNode = document.createAttribute("id"); | |
67 attrNode.value = "o"; | |
68 document.body.setAttributeNode(attrNode); | |
69 shouldBe('document.getElementById("o")', 'document.body'); | |
70 shouldBe('document.body.id', '"o"'); | |
71 shouldBe('document.body.getAttribute("id")', '"o"'); | |
72 | |
73 debug("\n23. Add an Attr node over an existing one."); | |
74 var attrNode = document.createAttribute("id"); | |
75 attrNode.value = "p"; | |
76 document.body.setAttributeNode(attrNode); | |
77 shouldBe('document.getElementById("o")', 'null'); | |
78 shouldBe('document.getElementById("p")', 'document.body'); | |
79 shouldBe('document.body.id', '"p"'); | |
80 shouldBe('document.body.getAttribute("id")', '"p"'); | |
81 </script> | |
82 </body> | |
83 </html> | |
OLD | NEW |