Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / LayoutTests / fast / dom / Attr / change-id-via-attr-node-value.html
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 properly.");
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 shouldBe('attrNode.childNodes.length', '1');
50
51 // Firefox doesn't support these for Attr nodes.
52 debug("\n7. Attr.replaceChild().");
53 try {
54     attrNode.replaceChild(document.createTextNode("g"), attrNode.firstChild);
55     shouldBe('document.getElementById("f")', 'null');
56     shouldBe('document.getElementById("g")', 'document.body');
57     shouldBe('document.body.id', '"g"');
58     shouldBe('document.body.getAttribute("id")', '"g"');
59     shouldBe('attrNode.value', '"g"');
60     shouldBe('attrNode.childNodes.length', '1');
61 } catch (ex) {
62     debug(ex);
63 }
64
65 debug("\n8. Attr.insertBefore().");
66 try {
67     attrNode.insertBefore(document.createTextNode("0"), attrNode.firstChild);
68     shouldBe('document.getElementById("g")', 'null');
69     shouldBe('document.getElementById("0g")', 'document.body');
70     shouldBe('document.body.id', '"0g"');
71     shouldBe('document.body.getAttribute("id")', '"0g"');
72     shouldBe('attrNode.value', '"0g"');
73     shouldBe('attrNode.childNodes.length', '2');
74 } catch (ex) {
75     debug(ex);
76 }
77
78 debug("\n9. attr.appendChild().");
79 try {
80     attrNode.appendChild(document.createTextNode("2"));
81     shouldBe('document.getElementById("0g")', 'null');
82     shouldBe('document.getElementById("0g2")', 'document.body');
83     shouldBe('document.body.id', '"0g2"');
84     shouldBe('document.body.getAttribute("id")', '"0g2"');
85     shouldBe('attrNode.value', '"0g2"');
86     shouldBe('attrNode.childNodes.length', '3');
87 } catch (ex) {
88     debug(ex);
89 }
90
91 debug("\n10. Attr.removeChild()");
92 attrNode.nodeValue = "h";
93 attrNode.removeChild(attrNode.firstChild);
94 shouldBe('document.body.getAttributeNode("id").childNodes.length', '0');
95 shouldBe('document.getElementById("h")', 'null');
96 shouldBe('document.getElementById("")', 'null');
97 shouldBe('document.body.id', '""');
98 shouldBe('document.body.getAttribute("id")', '""');
99 shouldBe('document.body.getAttributeNode("id").value', '""');
100
101 debug("\n11. Changing Text.nodeValue.");
102 attrNode.nodeValue = "h";
103 attrNode.firstChild.nodeValue = "i";
104 shouldBe('attrNode.firstChild.nodeValue', '"i"');
105 shouldBe('document.getElementById("i")', 'document.body');
106 shouldBe('document.body.id', '"i"');
107 shouldBe('document.body.getAttribute("id")', '"i"');
108 shouldBe('attrNode.value', '"i"');
109 shouldBe('attrNode.childNodes.length', '1');
110
111 debug("\n12. Chnaging Attr.value.");
112 attrNode.value = "hi";
113 shouldBe('document.getElementById("i")', 'null');
114 shouldBe('document.getElementById("hi")', 'document.body');
115 shouldBe('document.body.id', '"hi"');
116 shouldBe('document.body.getAttribute("id")', '"hi"');
117 shouldBe('attrNode.value', '"hi"');
118 shouldBe('attrNode.childNodes.length', '1');
119
120 debug("\n13. Text.splitText().");
121 attrNode.firstChild.splitText(1);
122 shouldBe('document.getElementById("hi")', 'document.body');
123 shouldBe('document.body.id', '"hi"');
124 shouldBe('document.body.getAttribute("id")', '"hi"');
125 shouldBe('document.body.getAttributeNode("id").value', '"hi"');
126 shouldBe('document.body.getAttributeNode("id").childNodes.length', '2');
127
128 debug("\n14. Node.normalize(), joining text nodes.");
129 attrNode.normalize();
130 shouldBe('document.getElementById("hi")', 'document.body');
131 shouldBe('document.body.id', '"hi"');
132 shouldBe('document.body.getAttribute("id")', '"hi"');
133 shouldBe('document.body.getAttributeNode("id").value', '"hi"');
134 shouldBe('document.body.getAttributeNode("id").childNodes.length', '1');
135
136 debug("\n15. Changing Attr.nodeValue.");
137 attrNode.nodeValue = "foo";
138 attrNode.firstChild.replaceWholeText("j");
139 shouldBe('document.getElementById("hi")', 'null');
140 shouldBe('document.getElementById("j")', 'document.body');
141 shouldBe('document.body.id', '"j"');
142 shouldBe('document.body.getAttribute("id")', '"j"');
143 shouldBe('attrNode.value', '"j"');
144 shouldBe('attrNode.childNodes.length', '1');
145
146 debug("\n16. Changing Text.data.");
147 attrNode.firstChild.data = "k";
148 shouldBe('document.getElementById("j")', 'null');
149 shouldBe('document.getElementById("k")', 'document.body');
150 shouldBe('document.body.id', '"k"');
151 shouldBe('document.body.getAttribute("id")', '"k"');
152 shouldBe('attrNode.value', '"k"');
153 shouldBe('attrNode.childNodes.length', '1');
154
155 debug("\n17. Changing text child with appendData().");
156 attrNode.firstChild.appendData("l");
157 shouldBe('document.getElementById("k")', 'null');
158 shouldBe('document.getElementById("kl")', 'document.body');
159 shouldBe('document.body.id', '"kl"');
160 shouldBe('document.body.getAttribute("id")', '"kl"');
161 shouldBe('attrNode.value', '"kl"');
162 shouldBe('attrNode.childNodes.length', '1');
163
164 debug("\n18. Changing text child with insertData().");
165 attrNode.firstChild.insertData(1, "1");
166 shouldBe('document.getElementById("kl")', 'null');
167 shouldBe('document.getElementById("k1l")', 'document.body');
168 shouldBe('document.body.id', '"k1l"');
169 shouldBe('document.body.getAttribute("id")', '"k1l"');
170 shouldBe('attrNode.value', '"k1l"');
171 shouldBe('attrNode.childNodes.length', '1');
172
173 debug("\n19. Changing text child with deleteData().");
174 attrNode.firstChild.deleteData(0, 2);
175 shouldBe('document.getElementById("k1l")', 'null');
176 shouldBe('document.getElementById("l")', 'document.body');
177 shouldBe('document.body.id', '"l"');
178 shouldBe('document.body.getAttribute("id")', '"l"');
179 shouldBe('attrNode.value', '"l"');
180 shouldBe('attrNode.childNodes.length', '1');
181
182 debug("\n20. Changing text child with replaceData().");
183 attrNode.firstChild.replaceData(0, 1, "mn");
184 shouldBe('document.getElementById("l")', 'null');
185 shouldBe('document.getElementById("mn")', 'document.body');
186 shouldBe('document.body.id', '"mn"');
187 shouldBe('document.body.getAttribute("id")', '"mn"');
188 shouldBe('attrNode.value', '"mn"');
189 shouldBe('attrNode.childNodes.length', '1');
190
191 debug("\n21. Remove an Attr node.");
192 document.body.removeAttributeNode(attrNode);
193 shouldBe('document.body.id', '""');
194 shouldBe('document.getElementById("mn")', 'null');
195 shouldBe('document.body.getAttribute("id")', 'null');
196 shouldBe('document.body.getAttributeNode("id")', 'null');
197
198 debug("\n22. Add an Attr node.");
199 var attrNode = document.createAttribute("id");
200 attrNode.value = "o";
201 document.body.setAttributeNode(attrNode);
202 shouldBe('document.getElementById("o")', 'document.body');
203 shouldBe('document.body.id', '"o"');
204 shouldBe('document.body.getAttribute("id")', '"o"');
205
206 debug("\n23. Add an Attr node over an existing one.");
207 var attrNode = document.createAttribute("id");
208 attrNode.value = "p";
209 document.body.setAttributeNode(attrNode);
210 shouldBe('document.getElementById("o")', 'null');
211 shouldBe('document.getElementById("p")', 'document.body');
212 shouldBe('document.body.id', '"p"');
213 shouldBe('document.body.getAttribute("id")', '"p"');
214 </script>
215 </body>
216 </html>