Upstream version 5.34.98.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / LayoutTests / fast / forms / old-names.html
1 <html>
2 <head>
3 <script src="../../resources/js-test.js"></script>
4 <script>
5 function runTest()
6 {
7     description("This tests accessing form elements by name. "
8         + "IE only lets you look up names under the first name the element had and "
9         + "does not respond to name changes. Firefox remembers every name item has been "
10         + "accessed with, but forgets items that have not been accessed. "
11         + "This test has been written to expect the Firefox behavior.");
12
13     form = document.getElementById('form');
14     a = document.getElementById('a');
15     b = document.getElementById('b');
16
17     shouldBe('form.length', '2');
18     shouldBe('form.original', 'a');
19     shouldBe('form.originalB', 'b');
20     shouldBe('form.second', 'undefined');
21     shouldBe('form.third', 'undefined');
22     shouldBe('form.elements.original', 'a');
23     shouldBe('form.elements.originalB', 'b');
24     shouldBe('form.elements.second', 'undefined');
25     shouldBe('form.elements.third', 'undefined');
26
27     debug('');   
28     debug("change the form item a's name to thisWillBeRemembered");
29     debug('');   
30     a.name="thisWillBeRemembered";
31     debug("get the variable value through form element");
32     shouldBe('form.thisWillBeRemembered', 'a');
33     debug('');   
34     debug("now change the form item a's name to thisWillBeRememberedToo");
35     debug("access it in boolean context");
36     a.name="thisWillBeRememberedToo";
37     debug('');   
38     if (form.thisWillBeRememberedToo)
39         debug('accessed form.thisWillBeRememberedToo');
40     debug('');   
41     debug("now change the form item a's name to thisWillBeForgotten");
42     debug('');   
43     a.name="thisWillBeForgotten";
44     debug("get the variable value through collection");
45     shouldBe('form.elements.thisWillBeForgotten', 'a');
46     debug('');   
47     debug("now change the form item a's name to thisWillBeForgottenToo, but don't access it afterwards");
48     a.name="thisWillBeForgottenToo";
49         
50     debug('');    
51     debug("now change the form item a's name to second");
52     debug('');
53     a.name="second";
54     
55     shouldBe('form.length', '2');
56     shouldBe('form.original', 'a');
57     shouldBe('form.originalB', 'b');
58     shouldBe('form.second', 'a');
59     shouldBe('form.third', 'undefined');
60     shouldBe('form.elements.original', 'undefined');
61     shouldBe('form.elements.originalB', 'b');
62     shouldBe('form.elements.second', 'a');
63     shouldBe('form.elements.third', 'undefined');
64
65     debug('');
66     debug("now change the form item a's name to third");
67     debug('');
68
69     a.name="third";
70
71     shouldBe('form.length', '2');
72     shouldBe('form.original', 'a');
73     shouldBe('form.originalB', 'b');
74     shouldBe('form.second', 'a');
75     shouldBe('form.third', 'a');
76     shouldBe('form.elements.original', 'undefined');
77     shouldBe('form.elements.originalB', 'b');
78     shouldBe('form.elements.second', 'undefined');
79     shouldBe('form.elements.third', 'a');
80
81     debug('');
82     debug("now change form item b's name to second");
83     debug('');
84
85     b.name="second";
86
87     shouldBe('form.length', '2');
88     shouldBe('form.original', 'a');
89     shouldBe('form.originalB', 'b');
90     shouldBe('form.second', 'b');
91     shouldBe('form.elements.original', 'undefined');
92     shouldBe('form.elements.originalB', 'undefined');
93     shouldBe('form.elements.second', 'b');
94
95     debug('');
96     debug("now change a form item b's name to third");
97     debug('');
98
99     form.originalB.name="third";
100
101     shouldBe('form.length', '2');
102     shouldBe('form.original', 'a');
103     shouldBe('form.originalB', 'b');
104     shouldBe('form.second', 'b');
105     shouldBe('form.third.length', '2');
106     shouldBe('form.third[0]', 'a');
107     shouldBe('form.third[1]', 'b');
108     shouldBe('form.elements.original', 'undefined');
109     shouldBe('form.elements.originalB', 'undefined');
110     shouldBe('form.elements.second', 'undefined');
111     shouldBe('form.elements.third.length', '2');
112     shouldBe('form.elements.third[0]', 'a');
113     shouldBe('form.elements.third[1]', 'b');
114     
115     debug('');
116     debug("now change a form item b's name to fourth");
117     debug('');
118
119     form.originalB.name="fourth";
120     
121     shouldBe('form.third', 'a');
122     shouldBe('form.third.length', 'undefined');
123     shouldBe('form.elements.third', 'a');
124     shouldBe('form.elements.third.length', 'undefined');
125
126     debug('');
127     debug("now remove element a");
128     debug('');
129
130     form.removeChild(a);
131
132     shouldBe('form.length', '1');
133     shouldBeUndefined('form.original', 'a');
134     shouldBe('form.originalB', 'b');
135     shouldBe('form.second', 'b');
136     shouldBeUndefined('form.third', 'a');
137     shouldBe('form.fourth', 'b');
138     shouldBe('form.elements.original', 'undefined');
139     shouldBe('form.elements.originalB', 'undefined');
140     shouldBe('form.elements.second', 'undefined');
141     shouldBe('form.elements.third', 'undefined');
142     shouldBe('form.elements.fourth', 'b');
143  
144     debug('');
145     debug("check that we no longer remember the past names of a");
146     debug('');
147
148     shouldBe('form.thisWillBeForgotten', 'undefined');
149     shouldBe('form.thisWillBeForgottenToo', 'undefined');
150     shouldBeUndefined('form.thisWillBeRemembered');
151     shouldBeUndefined('form.thisWillBeRememberedToo');
152     debug('');
153 }
154 </script>
155 </head>
156 <body>
157 <form id='form'>
158 <input type='hidden' id='a' name='original'>
159 <input type='hidden' id='b' name='originalB'>
160 </form>
161
162 <form id="form1"><input name="foo" id="input3"></form>
163 <form id="form2"></form>
164
165 <form id="form4"><input name="foo"><input name="bar"><input name="bar"></form>
166
167 <p id="description"></p>
168 <div id="console"></div>
169 <script>
170 runTest();
171
172 debug('Ensures elements are removed from the past names map of a form element once they are no longer associated with the form element.');
173 var form1 = document.querySelector("#form1");
174 var input3 = document.querySelector("#input3");
175 shouldBe("form1['foo']", "input3");
176 shouldBeUndefined("form2.appendChild(form1.firstChild); form1['foo']");
177
178 shouldBe("form2['foo']", "input3");
179 shouldBeUndefined("form2.removeChild(input3); form2['foo']");
180
181 shouldBe("form1.appendChild(input3); form1['foo']", "input3");
182 // input3 will be an orphan. So form content attribute doesn't work.
183 shouldBeUndefined("input3.setAttribute('form', 'form1'); form1.removeChild(input3); input3.appendChild(form1); form1['foo']");
184 shouldNotBe("form1['foo']", "input3");
185
186 debug("");
187 debug("Don't add the element from the past names map if we've found elements of the given name.");
188 var form4 = document.querySelector("#form4");
189 shouldBe("form4['foo']", "form4.childNodes[0]");
190 shouldBe("form4['bar'][0]", "form4.childNodes[1]");
191 shouldBe("form4['bar'][1]", "form4.childNodes[2]");
192 shouldBe("form4.childNodes[0].name = 'bar'; form4.childNodes[1].name = form4.childNodes[2].name = 'foo'; form4['foo'].length", "2");
193 </script>
194 </body>
195 </html>