mshtml: Added support for flag 2 in getAttribute.
[wine.git] / dlls / mshtml / tests / jstest.html
blob2b3634e5e0efcf064c22401bdc21e0717575eed8
1 <html>
2 <head>
3 <script>
4 function ok(b,m) {
5 return external.ok(b, m);
8 function broken(expr) {
9 return external.broken(expr);
12 function test_removeAttribute(e) {
13 ok(e.removeAttribute('nonexisting') === false, "removeAttribute('nonexisting') didn't return false");
15 e.title = "title";
16 ok(e.removeAttribute('title') === true, "removeAttribute('title') didn't return true");
17 ok(e.title === "", "e.title = " + e.title);
18 ok(("title" in e) === true, "title is not in e");
20 e["myattr"] = "test";
21 ok(e.removeAttribute('myattr') === true, "removeAttribute('myattr') didn't return true");
22 ok(e["myattr"] === undefined, "e['myattr'] = " + e['myattr']);
23 ok(("myattr" in e) === false, "myattr is in e");
27 function test_select_index() {
28 var s = document.getElementById("sel");
30 ok("0" in s, "'0' is not in s");
31 ok(s[0].text === "opt1", "s[0].text = " + s[0].text);
32 ok("1" in s, "'1 is not in s");
33 ok(s[1].text === "opt2", "s[1].text = " + s[1].text);
34 ok("2" in s, "'2' is in s");
35 ok(s[2] === null, "s[2] = " + s[2]);
38 function test_createDocumentFragment() {
39 var fragment = document.createDocumentFragment();
41 ok(typeof(fragment) === "object", "typeof(fragmend) = " + typeof(fragment));
42 ok(fragment.nodeType === 11, "fragment.nodeType = " + fragment.nodeType);
43 ok(fragment.nodeName === "#document-fragment", "fragment.nodeName = " + fragment.nodeName);
45 var cloned = fragment.cloneNode(true);
46 ok(cloned.nodeType === 11, "cloned.nodeType = " + cloned.nodeType);
47 ok(cloned.nodeName === "#document-fragment", "cloned.nodeName = " + cloned.nodeName);
50 function test_document_name_as_index() {
51 document.body.innerHTML = '<form name="formname"></form>';
52 var e = document.getElementById("formname");
53 ok(!!e, "e is null");
55 ok(document.formname === e, "document.formname != getElementById('formname')");
56 ok("formname" in document, "formname' is not in document");
58 document.body.removeChild(e);
60 ok(document.formname === undefined, "document.formname is not undefined");
61 ok(!("formname" in document), "formname' is in document");
63 document.body.innerHTML = '<form id="formid"></form>';
64 var e = document.getElementById("formid");
65 ok(!!e, "e is null");
66 ok(!("formid" in document), "formid is in document");
68 document.body.innerHTML = '<form name="formname"></form>';
69 ok("formname" in window, "formname' is not in window");
70 ok(typeof(window.formname) === "object", "typeof(window.formname) = " + typeof(window.formname));
71 window.formname = 1;
72 ok(window.formname === 1, "window.formname = " + window.formname);
73 formname = 2;
74 ok(window.formname === 2, "window.formname = " + window.formname);
76 document.body.innerHTML = '<iframe id="iframeid"></iframe>';
77 ok("iframeid" in window, "iframeid is not in window");
78 e = document.getElementById("iframeid");
79 ok(!!e, "e is null");
80 ok(iframeid != e, "iframeid == e");
81 ok(iframeid.frameElement === e, "frameid != e.contentWindow");
84 function test_remove_style_attribute() {
85 var s = document.body.style, b;
87 s.somevar = "test";
88 b = s.removeAttribute("somevar", 1);
89 ok(b, "removeAttribute returned " + b + " expected true");
90 b = s.removeAttribute("somevar", 1);
91 ok(b === false, "removeAttribute returned " + b + " expected false");
94 function test_clone_node() {
95 var elem, cloned;
97 elem = document.getElementById("divid");
98 elem.style.filter = "alpha(opacity=50)";
99 ok(elem.style.filter === "alpha(opacity=50)", "elem.style.filter = " + elem.style.filter);
101 cloned = elem.cloneNode(true);
102 ok(cloned.style.filter === "alpha(opacity=50)", "cloned.style.filter = " + cloned.style.filter);
105 function test_attrs() {
106 var input, s, x, f, b;
108 document.body.innerHTML = '<input id="inputid"></input>';
109 input = document.getElementById("inputid");
110 s = input.style;
111 f = input.fireEvent;
112 ok(input.checked === false, "input.checked = " + input.checked);
114 input.setAttribute("checked", "test");
115 ok(input.checked === true, "input.checked = " + input.checked);
117 input.setAttribute("checked", 0);
118 ok(input.checked === false, "input.checked = " + input.checked);
120 input.setAttribute("checked", "");
121 ok(input.checked === false, "input.checked = " + input.checked);
123 input.setAttribute("Checked", 1, 0);
124 ok(input.checked === true, "input.checked = " + input.checked);
125 ok(!("Checked" in input), "Checked added to input");
127 input.setAttribute("checked", 0, 0);
128 input.setAttribute("Checked", 1, 1);
129 ok(input.checked === false, "input.checked = " + input.checked);
130 ok("Checked" in input, "checked not added to input");
131 ok(input.Checked === 1, "input.Checked = " + input.Checked);
133 input.removeAttribute("Checked", 1);
134 ok(!("Checked" in input), "Checked is still in input");
135 ok(input.checked === false, "input.checked = " + input.checked);
137 input.setAttribute("checked", 1, 0);
138 input.setAttribute("Checked", 0);
139 ok(input.checked === true, "input.checked = " + input.checked);
140 ok("Checked" in input, "checked not added to input");
141 ok(input.Checked === 0, "input.Checked = " + input.Checked);
143 input.setAttribute("Checked", 2, 2);
144 ok(input.Checked === 0, "input.Checked = " + input.Checked);
145 input.setAttribute("Checked", 3, 3);
146 ok(input.Checked === 3, "input.Checked = " + input.Checked);
148 x = input.getAttribute("style");
149 ok(x === s, "getAttribute('style') = " + x);
150 ok(s.cssText === "", "s.cssText = " + s.cssText);
151 x = input.getAttribute("style", 2);
152 ok(x === "", "getAttribute('style') = " + x);
154 input.setAttribute("style", "display: none");
155 x = input.getAttribute("style");
156 ok(x === s, "getAttribute('style') = " + x);
157 ok(s.cssText === "", "s.cssText = " + s.cssText);
158 ok(s.display === "", "s.display = " + s.display);
159 x = input.getAttribute("style", 2);
160 ok(x === "", "getAttribute('style') = " + x);
162 s.display = "none";
163 ok(s.cssText != "", "s.cssText = " + s.cssText);
164 ok(s.display === "none", "s.display = " + s.display);
165 input.setAttribute("style", "");
166 x = input.getAttribute("style");
167 ok(x === s, "getAttribute('style') = " + x);
168 ok(s.cssText != "", "s.cssText = " + s.cssText);
169 ok(s.display === "none", "s.display = " + s.display);
170 x = input.getAttribute("style", 2);
171 ok(x === "", "getAttribute('style') = " + x);
173 input.setAttribute("style", null);
174 x = input.getAttribute("style");
175 ok(input.style === s, "input.style = " + input.style);
176 ok(x === s, "getAttribute('style') = " + x);
177 ok(s.cssText != "", "s.cssText = " + s.cssText);
178 ok(s.display === "none", "s.display = " + s.display);
180 x = input.getAttribute("fireEvent");
181 ok(x === input.fireEvent, "input.getAttribute('fireEvent') = " + x);
182 x = input.getAttribute("fireEvent", 2);
183 ok(x === "", "getAttribute('fireEvent') = " + x);
185 input.setAttribute("fireEvent", 3);
186 ok(input.fireEvent === 3, "input.fireEvent = " + input.fireEvent);
187 x = input.getAttribute("fireEvent");
188 ok(x === 3, "input.getAttribute('fireEvent') = " + x);
189 x = input.getAttribute("fireEvent", 2);
190 ok(x === "3", "getAttribute('fireEvent') = " + x);
192 b = input.removeAttribute("style");
193 ok(b === true, "removeAttribute('style') failed");
194 ok(input.style === s, "input.style = " + input.style);
195 x = input.getAttribute("style");
196 ok(x === s, "getAttribute('style') = " + x);
197 ok(s.display === "", "s.display = " + s.display);
198 ok(s.cssText === "", "s.cssText = " + s.cssText);
199 x = input.getAttribute("style", 2);
200 ok(x === "", "getAttribute('style') = " + x);
201 b = input.removeAttribute("style");
202 ok(b === true, "removeAttribute('style') failed");
204 b = false;
205 try {
206 input.setAttribute("tagName", "xxx");
207 }catch(e) {
208 b = true;
210 ok(b, "Expected exception on setAttribute(tagName)");
212 b = false;
213 try {
214 input.setAttribute("parentElement", "xxx");
215 }catch(e) {
216 b = true;
218 ok(b, "Expected exception on setAttribute(parentElement)");
220 b = input.removeAttribute("fireEvent");
221 ok(b === true, "removeAttribute(fireEvent) failed");
222 ok(input.fireEvent === f, "input.fireEvent = " + input.fireEvent);
223 x = input.getAttribute("fireEvent");
224 ok(x === f, "input.getAttribute('fireEvent') = " + x);
225 b = input.removeAttribute("fireEvent");
226 ok(b === false || broken(b === true), "removeAttribute(fireEvent) returned " + b);
228 input.fireEvent = 3;
229 x = input.getAttribute("fireEvent");
230 ok(x === 3, "input.getAttribute('fireEvent') = " + x);
231 ok(input.fireEvent === 3, "input.fireEvent' = " + input.fireEvent);
234 function test_attribute_collection() {
235 var div, attr;
237 document.body.innerHTML = '<div id="divid" class="test"></div>';
238 div = document.getElementById("divid");
240 attr = div.attributes["dir"];
241 ok(attr === div.attributes["dir"], "attr !== div.attributes['dir']");
244 function test_getter_call() {
245 document.body.innerHTML = '<div id="divid"></div>';
247 var e = document.getElementById("divid");
249 e.myfunc = function(x) { this.myfunc_called = x; };
250 e.myfunc("test");
251 ok(e.myfunc_called === "test", "e.myfunc_called = " + e.myfunc_called);
253 e.onmousedown = function(x) { this.onmousedown_called = x; };
254 e.onmousedown("test");
255 ok(e.onmousedown_called === "test", "e.onmousedown_called = " + e.onmousedown_called);
257 ok(document.all("divid").tagName === "DIV", "document.all('divid').tagName = " + document.all("divid").tagName);
260 function test_arg_conv() {
261 /* this call would throw if the argument wasn't converted by JScript */
262 window.clearInterval("");
264 navigator.javaEnabled();
267 function test_override_functions() {
268 function override_func() { return "test"; }
270 ok(typeof(window.showModalDialog) === "object", "typeof(window.showModalDialog) = " + typeof(window.showModalDialog));
271 window.showModalDialog = override_func;
272 ok(window.showModalDialog === override_func, "window.showModalDialog != override_func");
273 ok(typeof(window.showModalDialog) === "function", "typeof(window.showModalDialog) = " + typeof(window.showModalDialog));
275 document.body.innerHTML = '<div id="divid"></div>';
276 var div = document.getElementById("divid");
277 ok(typeof(div.addBehavior) === "object", "typeof(div.addBehavior) = " + typeof(div.addBehavior));
278 div.addBehavior = override_func;
279 ok(div.addBehavior === override_func, "div.addBehavior != override_func");
280 ok(typeof(div.addBehavior) === "function", "typeof(div.addBehavior) = " + typeof(div.addBehavior));
282 var tmp = div.addBehavior();
283 ok(tmp === "test", "div.addBehavior() = " + tmp);
285 tmp = String(div.attachEvent);
286 ok(tmp == "\nfunction attachEvent() {\n [native code]\n}\n", "String(div.attachEvent) = " + tmp);
289 function test_forin() {
290 var cnt=0;
292 document.body.innerHTML = '<a id="aid"></a>';
294 for(var x in document.getElementById("aid")) {
295 cnt++;
298 ok(cnt > 100, "cnt = " + cnt);
301 function test_customtag() {
302 document.body.innerHTML = 'test<unk><br>';
304 var children = document.body.childNodes;
306 ok(children.length === 3, "children.length = " + children.length);
307 ok(children[0].data === "test", "children[0].data = " + children[0].data);
308 ok(children[1].tagName === "UNK", "children[1].tagName = " + children[1].tagName);
309 ok(children[2].tagName === "BR", "children[2].tagName = " + children[2].tagName);
312 function test_whitespace_nodes() {
313 document.body.innerHTML = '<table id="tid"> <tr> \t<td>\n \t<div></div> </td>\n </tr> </table>';
315 var t = document.getElementById("tid");
316 ok(t.childNodes.length === 1, "t.childNodes.length = " + t.childNodes.length);
317 ok(t.childNodes[0].tagName === "TBODY", "t.childNodes[0].tagName = " + t.childNodes[0].tagName);
319 var row = t.rows[0];
320 ok(row.childNodes.length === 1, "row.childNodes.length = " + row.childNodes.length);
321 ok(row.childNodes[0].tagName === "TD", "row.childNodes[0].tagName = " + row.childNodes[0].tagName);
323 var cell = row.cells[0];
324 ok(cell.childNodes.length === 1, "cell.childNodes.length = " + cell.childNodes.length);
327 document.body.innerHTML = '<table id="tid"> x<tr> \tx<td>\n \tx<div></div> </td>\n </tr> </table>';
329 t = document.getElementById("tid");
330 ok(t.rows[0].cells[0].childNodes.length === 2,
331 "t.rows[0].cells[0].childNodes.length = " + t.rows[0].cells[0].childNodes.length);
334 function test_language_attribute() {
335 document.body.innerHTML = '<div id="did" language="test"></div>';
336 var elem = document.getElementById("did");
337 ok(elem.language === "test", "elem.language = " + elem.language);
338 elem.language = 1;
339 ok(elem.language === "1", "elem.language = " + elem.language);
342 var globalVar = false;
344 function runTests() {
345 obj = new Object();
346 ok(obj === window.obj, "obj !== window.obj");
348 ok(typeof(divid) === "object", "typeof(divid) = " + typeof(divid));
350 test_removeAttribute(document.getElementById("divid"));
351 test_removeAttribute(document.body);
352 test_select_index();
353 test_clone_node();
354 test_createDocumentFragment();
355 test_document_name_as_index();
356 test_remove_style_attribute();
357 test_getter_call();
358 test_attrs();
359 test_attribute_collection();
360 test_arg_conv();
361 test_override_functions();
362 test_forin();
363 test_customtag();
364 test_whitespace_nodes();
365 test_language_attribute();
367 var r = window.execScript("globalVar = true;");
368 ok(r === undefined, "execScript returned " + r);
369 ok(globalVar === true, "globalVar = " + globalVar);
372 function runTest() {
373 try {
374 runTests();
375 }catch(e) {
376 ok(false, "got exception " + e.message);
379 external.reportSuccess();
381 </script>
382 <body onload="runTest();">
383 <div id="divid"></div>
384 <select id="sel">
385 <option>opt1</option>
386 <option>opt2</option>
387 </select>
388 </body>
389 </html>