[REACTOS]
[reactos.git] / rostests / winetests / mshtml / jstest.html
1 <html>
2 <head>
3 <script>
4 function ok(b,m) {
5 return external.ok(b, m);
6 }
7
8 function test_removeAttribute(e) {
9 ok(e.removeAttribute('nonexisting') === false, "removeAttribute('nonexisting') didn't return false");
10
11 e.title = "title";
12 ok(e.removeAttribute('title') === true, "removeAttribute('title') didn't return true");
13 ok(e.title === "", "e.title = " + e.title);
14 ok(("title" in e) === true, "title is not in e");
15
16 e["myattr"] = "test";
17 ok(e.removeAttribute('myattr') === true, "removeAttribute('myattr') didn't return true");
18 ok(e["myattr"] === undefined, "e['myattr'] = " + e['myattr']);
19 ok(("myattr" in e) === false, "myattr is in e");
20
21 }
22
23 function test_select_index() {
24 var s = document.getElementById("sel");
25
26 ok("0" in s, "'0' is not in s");
27 ok(s[0].text === "opt1", "s[0].text = " + s[0].text);
28 ok("1" in s, "'1 is not in s");
29 ok(s[1].text === "opt2", "s[1].text = " + s[1].text);
30 ok("2" in s, "'2' is in s");
31 ok(s[2] === null, "s[2] = " + s[2]);
32 }
33
34 function test_createDocumentFragment() {
35 var fragment = document.createDocumentFragment();
36
37 ok(typeof(fragment) === "object", "typeof(fragmend) = " + typeof(fragment));
38 ok(fragment.nodeType === 11, "fragment.nodeType = " + fragment.nodeType);
39 ok(fragment.nodeName === "#document-fragment", "fragment.nodeName = " + fragment.nodeName);
40
41 var cloned = fragment.cloneNode(true);
42 ok(cloned.nodeType === 11, "cloned.nodeType = " + cloned.nodeType);
43 ok(cloned.nodeName === "#document-fragment", "cloned.nodeName = " + cloned.nodeName);
44 }
45
46 function test_document_name_as_index() {
47 document.body.innerHTML = '<form name="formname"></form>';
48 var e = document.getElementById("formname");
49 ok(!!e, "e is null");
50
51 ok(document.formname === e, "document.formname != getElementById('formname')");
52 ok("formname" in document, "formname' is not in document");
53
54 document.body.removeChild(e);
55
56 ok(document.formname === undefined, "document.formname is not undefined");
57 ok(!("formname" in document), "formname' is in document");
58
59 document.body.innerHTML = '<form id="formid"></form>';
60 var e = document.getElementById("formid");
61 ok(!!e, "e is null");
62 ok(!("formid" in document), "formid is in document");
63
64 document.body.innerHTML = '<form name="formname"></form>';
65 ok("formname" in window, "formname' is not in window");
66 ok(typeof(window.formname) === "object", "typeof(window.formname) = " + typeof(window.formname));
67 window.formname = 1;
68 ok(window.formname === 1, "window.formname = " + window.formname);
69 formname = 2;
70 ok(window.formname === 2, "window.formname = " + window.formname);
71
72 document.body.innerHTML = '<iframe id="iframeid"></iframe>';
73 ok("iframeid" in window, "iframeid is not in window");
74 e = document.getElementById("iframeid");
75 ok(!!e, "e is null");
76 ok(iframeid != e, "iframeid == e");
77 ok(iframeid.frameElement === e, "frameid != e.contentWindow");
78 }
79
80 function test_remove_style_attribute() {
81 var s = document.body.style, b;
82
83 s.somevar = "test";
84 b = s.removeAttribute("somevar", 1);
85 ok(b, "removeAttribute returned " + b + " expected true");
86 b = s.removeAttribute("somevar", 1);
87 ok(b === false, "removeAttribute returned " + b + " expected false");
88 }
89
90 function test_clone_node() {
91 var elem, cloned;
92
93 elem = document.getElementById("divid");
94 elem.style.filter = "alpha(opacity=50)";
95 ok(elem.style.filter === "alpha(opacity=50)", "elem.style.filter = " + elem.style.filter);
96
97 cloned = elem.cloneNode(true);
98 ok(cloned.style.filter === "alpha(opacity=50)", "cloned.style.filter = " + cloned.style.filter);
99 }
100
101 function test_setAttribute() {
102 var input;
103
104 document.body.innerHTML = '<input id="inputid"></input>';
105 input = document.getElementById("inputid");
106 ok(input.checked === false, "input.checked = " + input.checked);
107
108 input.setAttribute("checked", "test");
109 ok(input.checked === true, "input.checked = " + input.checked);
110
111 input.setAttribute("checked", 0);
112 ok(input.checked === false, "input.checked = " + input.checked);
113
114 input.setAttribute("checked", "");
115 ok(input.checked === false, "input.checked = " + input.checked);
116 }
117
118 function test_attribute_collection() {
119 var div, attr;
120
121 document.body.innerHTML = '<div id="divid" class="test"></div>';
122 div = document.getElementById("divid");
123
124 attr = div.attributes["dir"];
125 ok(attr === div.attributes["dir"], "attr !== div.attributes['dir']");
126 }
127
128 function test_getter_call() {
129 document.body.innerHTML = '<div id="divid"></div>';
130
131 var e = document.getElementById("divid");
132
133 e.myfunc = function(x) { this.myfunc_called = x; };
134 e.myfunc("test");
135 ok(e.myfunc_called === "test", "e.myfunc_called = " + e.myfunc_called);
136
137 e.onmousedown = function(x) { this.onmousedown_called = x; };
138 e.onmousedown("test");
139 ok(e.onmousedown_called === "test", "e.onmousedown_called = " + e.onmousedown_called);
140
141 ok(document.all("divid").tagName === "DIV", "document.all('divid').tagName = " + document.all("divid").tagName);
142 }
143
144 function test_arg_conv() {
145 /* this call would throw if the argument wasn't converted by JScript */
146 window.clearInterval("");
147
148 navigator.javaEnabled();
149 }
150
151 function test_override_functions() {
152 function override_func() { return "test"; }
153
154 ok(typeof(window.showModalDialog) === "object", "typeof(window.showModalDialog) = " + typeof(window.showModalDialog));
155 window.showModalDialog = override_func;
156 ok(window.showModalDialog === override_func, "window.showModalDialog != override_func");
157 ok(typeof(window.showModalDialog) === "function", "typeof(window.showModalDialog) = " + typeof(window.showModalDialog));
158
159 document.body.innerHTML = '<div id="divid"></div>';
160 var div = document.getElementById("divid");
161 ok(typeof(div.addBehavior) === "object", "typeof(div.addBehavior) = " + typeof(div.addBehavior));
162 div.addBehavior = override_func;
163 ok(div.addBehavior === override_func, "div.addBehavior != override_func");
164 ok(typeof(div.addBehavior) === "function", "typeof(div.addBehavior) = " + typeof(div.addBehavior));
165
166 var tmp = div.addBehavior();
167 ok(tmp === "test", "div.addBehavior() = " + tmp);
168 }
169
170 function test_forin() {
171 var cnt=0;
172
173 document.body.innerHTML = '<a id="aid"></a>';
174
175 for(var x in document.getElementById("aid")) {
176 cnt++;
177 }
178
179 ok(cnt > 100, "cnt = " + cnt);
180 }
181
182 function test_customtag() {
183 document.body.innerHTML = 'test<unk><br>';
184
185 var children = document.body.childNodes;
186
187 ok(children.length === 3, "children.length = " + children.length);
188 ok(children[0].data === "test", "children[0].data = " + children[0].data);
189 ok(children[1].tagName === "UNK", "children[1].tagName = " + children[1].tagName);
190 ok(children[2].tagName === "BR", "children[2].tagName = " + children[2].tagName);
191 }
192
193 function test_whitespace_nodes() {
194 document.body.innerHTML = '<table id="tid"> <tr> \t<td>\n \t<div></div> </td>\n </tr> </table>';
195
196 var t = document.getElementById("tid");
197 ok(t.childNodes.length === 1, "t.childNodes.length = " + t.childNodes.length);
198 ok(t.childNodes[0].tagName === "TBODY", "t.childNodes[0].tagName = " + t.childNodes[0].tagName);
199
200 var row = t.rows[0];
201 ok(row.childNodes.length === 1, "row.childNodes.length = " + row.childNodes.length);
202 ok(row.childNodes[0].tagName === "TD", "row.childNodes[0].tagName = " + row.childNodes[0].tagName);
203
204 var cell = row.cells[0];
205 ok(cell.childNodes.length === 1, "cell.childNodes.length = " + cell.childNodes.length);
206
207
208 document.body.innerHTML = '<table id="tid"> x<tr> \tx<td>\n \tx<div></div> </td>\n </tr> </table>';
209
210 t = document.getElementById("tid");
211 ok(t.rows[0].cells[0].childNodes.length === 2,
212 "t.rows[0].cells[0].childNodes.length = " + t.rows[0].cells[0].childNodes.length);
213 }
214
215 var globalVar = false;
216
217 function runTests() {
218 obj = new Object();
219 ok(obj === window.obj, "obj !== window.obj");
220
221 ok(typeof(divid) === "object", "typeof(divid) = " + typeof(divid));
222
223 test_removeAttribute(document.getElementById("divid"));
224 test_removeAttribute(document.body);
225 test_select_index();
226 test_clone_node();
227 test_createDocumentFragment();
228 test_document_name_as_index();
229 test_remove_style_attribute();
230 test_getter_call();
231 test_setAttribute();
232 test_attribute_collection();
233 test_arg_conv();
234 test_override_functions();
235 test_forin();
236 test_customtag();
237 test_whitespace_nodes();
238
239 var r = window.execScript("globalVar = true;");
240 ok(r === undefined, "execScript returned " + r);
241 ok(globalVar === true, "globalVar = " + globalVar);
242 }
243
244 function runTest() {
245 try {
246 runTests();
247 }catch(e) {
248 ok(false, "got exception");
249 }
250
251 external.reportSuccess();
252 }
253 </script>
254 <body onload="runTest();">
255 <div id="divid"></div>
256 <select id="sel">
257 <option>opt1</option>
258 <option>opt2</option>
259 </select>
260 </body>
261 </html>