mshtml/tests: Skip some tests if native XMLHTTP support is missing or disabled.
[wine.git] / dlls / mshtml / tests / jstest.html
blob164593ee0d399c8fae617a764fe826de223027d2
1 <html>
2 <head>
3 <script src="winetest.js" type="text/javascript"></script>
4 </head>
5 <head>
6 <script>
7 function broken(expr) {
8 return external.broken(expr);
11 function test_removeAttribute(e) {
12 ok(e.removeAttribute('nonexisting') === false, "removeAttribute('nonexisting') didn't return false");
14 e.title = "title";
15 ok(e.removeAttribute('title') === true, "removeAttribute('title') didn't return true");
16 ok(e.title === "", "e.title = " + e.title);
17 ok(("title" in e) === true, "title is not in e");
19 e["myattr"] = "test";
20 ok(e.removeAttribute('myattr') === true, "removeAttribute('myattr') didn't return true");
21 ok(e["myattr"] === undefined, "e['myattr'] = " + e['myattr']);
22 ok(("myattr" in e) === false, "myattr is in e");
26 function test_select_index() {
27 var s = document.getElementById("sel");
29 ok("0" in s, "'0' is not in s");
30 ok(s[0].text === "opt1", "s[0].text = " + s[0].text);
31 ok("1" in s, "'1 is not in s");
32 ok(s[1].text === "opt2", "s[1].text = " + s[1].text);
33 ok("2" in s, "'2' is in s");
34 ok(s[2] === null, "s[2] = " + s[2]);
37 function test_createDocumentFragment() {
38 var fragment = document.createDocumentFragment();
40 ok(typeof(fragment) === "object", "typeof(fragmend) = " + typeof(fragment));
41 ok(fragment.nodeType === 11, "fragment.nodeType = " + fragment.nodeType);
42 ok(fragment.nodeName === "#document-fragment", "fragment.nodeName = " + fragment.nodeName);
44 var cloned = fragment.cloneNode(true);
45 ok(cloned.nodeType === 11, "cloned.nodeType = " + cloned.nodeType);
46 ok(cloned.nodeName === "#document-fragment", "cloned.nodeName = " + cloned.nodeName);
49 function test_document_name_as_index() {
50 document.body.innerHTML = '<form name="formname"></form>';
51 var e = document.getElementById("formname");
52 ok(!!e, "e is null");
54 ok(document.formname === e, "document.formname != getElementById('formname')");
55 ok("formname" in document, "formname' is not in document");
57 document.body.removeChild(e);
59 ok(document.formname === undefined, "document.formname is not undefined");
60 ok(!("formname" in document), "formname' is in document");
62 document.body.innerHTML = '<form id="formid"></form>';
63 var e = document.getElementById("formid");
64 ok(!!e, "e is null");
65 ok(!("formid" in document), "formid is in document");
67 document.body.innerHTML = '<form name="formname"></form>';
68 ok("formname" in window, "formname' is not in window");
69 ok(typeof(window.formname) === "object", "typeof(window.formname) = " + typeof(window.formname));
70 window.formname = 1;
71 ok(window.formname === 1, "window.formname = " + window.formname);
72 formname = 2;
73 ok(window.formname === 2, "window.formname = " + window.formname);
75 document.body.innerHTML = '<iframe id="iframeid"></iframe>';
76 ok("iframeid" in window, "iframeid is not in window");
77 e = document.getElementById("iframeid");
78 ok(!!e, "e is null");
79 ok(iframeid != e, "iframeid == e");
80 ok(iframeid.frameElement === e, "frameid != e.contentWindow");
83 function test_remove_style_attribute() {
84 var s = document.body.style, b;
86 s.somevar = "test";
87 b = s.removeAttribute("somevar", 1);
88 ok(b, "removeAttribute returned " + b + " expected true");
89 b = s.removeAttribute("somevar", 1);
90 ok(b === false, "removeAttribute returned " + b + " expected false");
93 function test_clone_node() {
94 var elem, cloned;
96 elem = document.getElementById("divid");
97 elem.style.filter = "alpha(opacity=50)";
98 ok(elem.style.filter === "alpha(opacity=50)", "elem.style.filter = " + elem.style.filter);
100 cloned = elem.cloneNode(true);
101 ok(cloned.style.filter === "alpha(opacity=50)", "cloned.style.filter = " + cloned.style.filter);
104 function test_attrs() {
105 var input, s, x, f, b;
107 document.body.innerHTML = '<input id="inputid"></input>';
108 input = document.getElementById("inputid");
109 s = input.style;
110 f = input.fireEvent;
111 ok(input.checked === false, "input.checked = " + input.checked);
113 input.setAttribute("checked", "test");
114 ok(input.checked === true, "input.checked = " + input.checked);
116 input.setAttribute("checked", 0);
117 ok(input.checked === false, "input.checked = " + input.checked);
119 input.setAttribute("checked", "");
120 ok(input.checked === false, "input.checked = " + input.checked);
122 input.setAttribute("Checked", 1, 0);
123 ok(input.checked === true, "input.checked = " + input.checked);
124 ok(!("Checked" in input), "Checked added to input");
126 input.setAttribute("checked", 0, 0);
127 input.setAttribute("Checked", 1, 1);
128 ok(input.checked === false, "input.checked = " + input.checked);
129 ok("Checked" in input, "checked not added to input");
130 ok(input.Checked === 1, "input.Checked = " + input.Checked);
132 input.removeAttribute("Checked", 1);
133 ok(!("Checked" in input), "Checked is still in input");
134 ok(input.checked === false, "input.checked = " + input.checked);
136 input.setAttribute("checked", 1, 0);
137 input.setAttribute("Checked", 0);
138 ok(input.checked === true, "input.checked = " + input.checked);
139 ok("Checked" in input, "checked not added to input");
140 ok(input.Checked === 0, "input.Checked = " + input.Checked);
142 input.setAttribute("Checked", 2, 2);
143 ok(input.Checked === 0, "input.Checked = " + input.Checked);
144 input.setAttribute("Checked", 3, 3);
145 ok(input.Checked === 3, "input.Checked = " + input.Checked);
147 x = input.getAttribute("style");
148 ok(x === s, "getAttribute('style') = " + x);
149 ok(s.cssText === "", "s.cssText = " + s.cssText);
150 x = input.getAttribute("style", 2);
151 ok(x === "", "getAttribute('style') = " + x);
153 input.setAttribute("style", "display: none");
154 x = input.getAttribute("style");
155 ok(x === s, "getAttribute('style') = " + x);
156 ok(s.cssText === "", "s.cssText = " + s.cssText);
157 ok(s.display === "", "s.display = " + s.display);
158 x = input.getAttribute("style", 2);
159 ok(x === "", "getAttribute('style') = " + x);
161 s.display = "none";
162 ok(s.cssText != "", "s.cssText = " + s.cssText);
163 ok(s.display === "none", "s.display = " + s.display);
164 input.setAttribute("style", "");
165 x = input.getAttribute("style");
166 ok(x === s, "getAttribute('style') = " + x);
167 ok(s.cssText != "", "s.cssText = " + s.cssText);
168 ok(s.display === "none", "s.display = " + s.display);
169 x = input.getAttribute("style", 2);
170 ok(x === "", "getAttribute('style') = " + x);
172 input.setAttribute("style", null);
173 x = input.getAttribute("style");
174 ok(input.style === s, "input.style = " + input.style);
175 ok(x === s, "getAttribute('style') = " + x);
176 ok(s.cssText != "", "s.cssText = " + s.cssText);
177 ok(s.display === "none", "s.display = " + s.display);
179 x = input.getAttribute("fireEvent");
180 ok(x === input.fireEvent, "input.getAttribute('fireEvent') = " + x);
181 x = input.getAttribute("fireEvent", 2);
182 ok(x === "", "getAttribute('fireEvent') = " + x);
184 input.setAttribute("fireEvent", 3);
185 ok(input.fireEvent === 3, "input.fireEvent = " + input.fireEvent);
186 x = input.getAttribute("fireEvent");
187 ok(x === 3, "input.getAttribute('fireEvent') = " + x);
188 x = input.getAttribute("fireEvent", 2);
189 ok(x === "3", "getAttribute('fireEvent') = " + x);
191 b = input.removeAttribute("style");
192 ok(b === true, "removeAttribute('style') failed");
193 ok(input.style === s, "input.style = " + input.style);
194 x = input.getAttribute("style");
195 ok(x === s, "getAttribute('style') = " + x);
196 ok(s.display === "", "s.display = " + s.display);
197 ok(s.cssText === "", "s.cssText = " + s.cssText);
198 x = input.getAttribute("style", 2);
199 ok(x === "", "getAttribute('style') = " + x);
200 b = input.removeAttribute("style");
201 ok(b === true, "removeAttribute('style') failed");
203 b = false;
204 try {
205 input.setAttribute("tagName", "xxx");
206 }catch(e) {
207 b = true;
209 ok(b, "Expected exception on setAttribute(tagName)");
211 b = false;
212 try {
213 input.setAttribute("parentElement", "xxx");
214 }catch(e) {
215 b = true;
217 ok(b, "Expected exception on setAttribute(parentElement)");
219 b = input.removeAttribute("fireEvent");
220 ok(b === true, "removeAttribute(fireEvent) failed");
221 ok(input.fireEvent === f, "input.fireEvent = " + input.fireEvent);
222 x = input.getAttribute("fireEvent");
223 ok(x === f, "input.getAttribute('fireEvent') = " + x);
224 b = input.removeAttribute("fireEvent");
225 ok(b === false || broken(b === true), "removeAttribute(fireEvent) returned " + b);
227 input.fireEvent = 3;
228 x = input.getAttribute("fireEvent");
229 ok(x === 3, "input.getAttribute('fireEvent') = " + x);
230 ok(input.fireEvent === 3, "input.fireEvent' = " + input.fireEvent);
233 function test_attribute_collection() {
234 var div, attr;
236 document.body.innerHTML = '<div id="divid" class="test"></div>';
237 div = document.getElementById("divid");
239 attr = div.attributes["dir"];
240 ok(attr === div.attributes["dir"], "attr !== div.attributes['dir']");
243 function test_getter_call() {
244 document.body.innerHTML = '<div id="divid"></div>';
246 var e = document.getElementById("divid");
248 e.myfunc = function(x) { this.myfunc_called = x; };
249 e.myfunc("test");
250 ok(e.myfunc_called === "test", "e.myfunc_called = " + e.myfunc_called);
252 e.onmousedown = function(x) { this.onmousedown_called = x; };
253 e.onmousedown("test");
254 ok(e.onmousedown_called === "test", "e.onmousedown_called = " + e.onmousedown_called);
256 ok(document.all("divid").tagName === "DIV", "document.all('divid').tagName = " + document.all("divid").tagName);
259 function test_arg_conv() {
260 /* this call would throw if the argument wasn't converted by JScript */
261 window.clearInterval("");
263 navigator.javaEnabled();
266 function test_override_functions() {
267 function override_func() { return "test"; }
269 ok(typeof(window.showModalDialog) === "object", "typeof(window.showModalDialog) = " + typeof(window.showModalDialog));
270 window.showModalDialog = override_func;
271 ok(window.showModalDialog === override_func, "window.showModalDialog != override_func");
272 ok(typeof(window.showModalDialog) === "function", "typeof(window.showModalDialog) = " + typeof(window.showModalDialog));
274 document.body.innerHTML = '<div id="divid"></div>';
275 var div = document.getElementById("divid");
276 ok(typeof(div.addBehavior) === "object", "typeof(div.addBehavior) = " + typeof(div.addBehavior));
277 div.addBehavior = override_func;
278 ok(div.addBehavior === override_func, "div.addBehavior != override_func");
279 ok(typeof(div.addBehavior) === "function", "typeof(div.addBehavior) = " + typeof(div.addBehavior));
281 var tmp = div.addBehavior();
282 ok(tmp === "test", "div.addBehavior() = " + tmp);
284 tmp = String(div.attachEvent);
285 ok(tmp == "\nfunction attachEvent() {\n [native code]\n}\n", "String(div.attachEvent) = " + tmp);
288 function test_forin() {
289 var cnt=0;
291 document.body.innerHTML = '<a id="aid"></a>';
293 for(var x in document.getElementById("aid")) {
294 cnt++;
297 ok(cnt > 100, "cnt = " + cnt);
300 function test_customtag() {
301 document.body.innerHTML = 'test<unk><br>';
303 var children = document.body.childNodes;
305 ok(children.length === 3, "children.length = " + children.length);
306 ok(children[0].data === "test", "children[0].data = " + children[0].data);
307 ok(children[1].tagName === "UNK", "children[1].tagName = " + children[1].tagName);
308 ok(children[2].tagName === "BR", "children[2].tagName = " + children[2].tagName);
311 function test_whitespace_nodes() {
312 document.body.innerHTML = '<table id="tid"> <tr> \t<td>\n \t<div></div> </td>\n </tr> </table>';
314 var t = document.getElementById("tid");
315 ok(t.childNodes.length === 1, "t.childNodes.length = " + t.childNodes.length);
316 ok(t.childNodes[0].tagName === "TBODY", "t.childNodes[0].tagName = " + t.childNodes[0].tagName);
318 var row = t.rows[0];
319 ok(row.childNodes.length === 1, "row.childNodes.length = " + row.childNodes.length);
320 ok(row.childNodes[0].tagName === "TD", "row.childNodes[0].tagName = " + row.childNodes[0].tagName);
322 var cell = row.cells[0];
323 ok(cell.childNodes.length === 1, "cell.childNodes.length = " + cell.childNodes.length);
326 document.body.innerHTML = '<table id="tid"> x<tr> \tx<td>\n \tx<div></div> </td>\n </tr> </table>';
328 t = document.getElementById("tid");
329 ok(t.rows[0].cells[0].childNodes.length === 2,
330 "t.rows[0].cells[0].childNodes.length = " + t.rows[0].cells[0].childNodes.length);
333 function test_language_attribute() {
334 document.body.innerHTML = '<div id="did" language="test"></div>';
335 var elem = document.getElementById("did");
336 ok(elem.language === "test", "elem.language = " + elem.language);
337 elem.language = 1;
338 ok(elem.language === "1", "elem.language = " + elem.language);
341 function test_text_node() {
342 document.body.innerHTML = 'testing text';
343 var text = document.body.childNodes[0], text2;
344 ok(text.data == "testing text", "text.data = " + text.data);
346 text2 = text.splitText(7);
347 ok(text.data == "testing", "text.data = " + text.data);
348 ok(text2.data == " text", "text2.data = " + text2.data);
349 ok(text.nextSibling === text2, "text.nextSibling !== text2");
351 text2 = text.splitText(0);
352 ok(text.data == "", "text.data = " + text.data);
353 ok(text2.data == "testing", "text2.data = " + text2.data);
356 function test_xhr() {
357 ok("XMLHttpRequest" in window, "XMLHttpRequest not found in window object\n");
359 if (typeof(XMLHttpRequest) != "object") {
360 win_skip("XMLHTTPRequest is not available or disabled");
361 return;
364 var xhr = new XMLHttpRequest();
365 ok(typeof(xhr) === "object", "typeof(xhr) = " + typeof(xhr));
368 function test_postMessage() {
369 if(!("postMessage" in window)) {
370 win_skip("postMessage not available");
371 return;
374 var onmessage_called = false;
375 window.onmessage = function() {
376 onmessage_called = true;
378 window.postMessage("test", "*");
379 ok(onmessage_called, "onmessage not called");
382 var globalVar = false;
384 function runTests() {
385 obj = new Object();
386 ok(obj === window.obj, "obj !== window.obj");
388 ok(typeof(divid) === "object", "typeof(divid) = " + typeof(divid));
390 test_removeAttribute(document.getElementById("divid"));
391 test_removeAttribute(document.body);
392 test_select_index();
393 test_clone_node();
394 test_createDocumentFragment();
395 test_document_name_as_index();
396 test_remove_style_attribute();
397 test_getter_call();
398 test_attrs();
399 test_attribute_collection();
400 test_arg_conv();
401 test_override_functions();
402 test_forin();
403 test_customtag();
404 test_whitespace_nodes();
405 test_language_attribute();
406 test_text_node();
407 test_xhr();
408 test_postMessage();
410 var r = window.execScript("globalVar = true;");
411 ok(r === undefined, "execScript returned " + r);
412 ok(globalVar === true, "globalVar = " + globalVar);
414 /* Call setTimeout without specified time. */
415 window.setTimeout(function() { external.reportSuccess(); });
418 function runTest() {
419 try {
420 runTests();
421 }catch(e) {
422 ok(false, "got exception " + e.message);
425 </script>
426 <body onload="runTest();">
427 <div id="divid"></div>
428 <select id="sel">
429 <option>opt1</option>
430 <option>opt2</option>
431 </select>
432 </body>
433 </html>