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");
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");
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");
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");
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
));
72 ok(window
.formname
=== 1, "window.formname = " + window
.formname
);
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");
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
;
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() {
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");
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
);
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");
206 input
.setAttribute("tagName", "xxx");
210 ok(b
, "Expected exception on setAttribute(tagName)");
214 input
.setAttribute("parentElement", "xxx");
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
);
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() {
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
; };
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() {
292 document
.body
.innerHTML
= '<a id="aid"></a>';
294 for(var x
in document
.getElementById("aid")) {
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
);
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
);
339 ok(elem
.language
=== "1", "elem.language = " + elem
.language
);
342 var globalVar
= false;
344 function runTests() {
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
);
354 test_createDocumentFragment();
355 test_document_name_as_index();
356 test_remove_style_attribute();
359 test_attribute_collection();
361 test_override_functions();
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
);
376 ok(false, "got exception " + e
.message
);
379 external
.reportSuccess();
382 <body onload=
"runTest();">
383 <div id=
"divid"></div>
385 <option>opt1
</option>
386 <option>opt2
</option>