1<html> 2<head> 3<script> 4function ok(b,m) { 5 return external.ok(b, m); 6} 7 8function broken(expr) { 9 return external.broken(expr); 10} 11 12function test_removeAttribute(e) { 13 ok(e.removeAttribute('nonexisting') === false, "removeAttribute('nonexisting') didn't return false"); 14 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"); 19 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"); 24 25} 26 27function test_select_index() { 28 var s = document.getElementById("sel"); 29 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]); 36} 37 38function test_createDocumentFragment() { 39 var fragment = document.createDocumentFragment(); 40 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); 44 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); 48} 49 50function 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"); 54 55 ok(document.formname === e, "document.formname != getElementById('formname')"); 56 ok("formname" in document, "formname' is not in document"); 57 58 document.body.removeChild(e); 59 60 ok(document.formname === undefined, "document.formname is not undefined"); 61 ok(!("formname" in document), "formname' is in document"); 62 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"); 67 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); 75 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"); 82} 83 84function test_remove_style_attribute() { 85 var s = document.body.style, b; 86 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"); 92} 93 94function test_clone_node() { 95 var elem, cloned; 96 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); 100 101 cloned = elem.cloneNode(true); 102 ok(cloned.style.filter === "alpha(opacity=50)", "cloned.style.filter = " + cloned.style.filter); 103} 104 105function test_attrs() { 106 var input, s, x, f, b; 107 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); 113 114 input.setAttribute("checked", "test"); 115 ok(input.checked === true, "input.checked = " + input.checked); 116 117 input.setAttribute("checked", 0); 118 ok(input.checked === false, "input.checked = " + input.checked); 119 120 input.setAttribute("checked", ""); 121 ok(input.checked === false, "input.checked = " + input.checked); 122 123 input.setAttribute("Checked", 1, 0); 124 ok(input.checked === true, "input.checked = " + input.checked); 125 ok(!("Checked" in input), "Checked added to input"); 126 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); 132 133 input.removeAttribute("Checked", 1); 134 ok(!("Checked" in input), "Checked is still in input"); 135 ok(input.checked === false, "input.checked = " + input.checked); 136 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); 142 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); 147 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); 153 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); 161 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); 172 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); 179 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); 184 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); 191 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"); 203 204 b = false; 205 try { 206 input.setAttribute("tagName", "xxx"); 207 }catch(e) { 208 b = true; 209 } 210 ok(b, "Expected exception on setAttribute(tagName)"); 211 212 b = false; 213 try { 214 input.setAttribute("parentElement", "xxx"); 215 }catch(e) { 216 b = true; 217 } 218 ok(b, "Expected exception on setAttribute(parentElement)"); 219 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); 227 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); 232} 233 234function test_attribute_collection() { 235 var div, attr; 236 237 document.body.innerHTML = '<div id="divid" class="test"></div>'; 238 div = document.getElementById("divid"); 239 240 attr = div.attributes["dir"]; 241 ok(attr === div.attributes["dir"], "attr !== div.attributes['dir']"); 242} 243 244function test_getter_call() { 245 document.body.innerHTML = '<div id="divid"></div>'; 246 247 var e = document.getElementById("divid"); 248 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); 252 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); 256 257 ok(document.all("divid").tagName === "DIV", "document.all('divid').tagName = " + document.all("divid").tagName); 258} 259 260function test_arg_conv() { 261 /* this call would throw if the argument wasn't converted by JScript */ 262 window.clearInterval(""); 263 264 navigator.javaEnabled(); 265} 266 267function test_override_functions() { 268 function override_func() { return "test"; } 269 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)); 274 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)); 281 282 var tmp = div.addBehavior(); 283 ok(tmp === "test", "div.addBehavior() = " + tmp); 284 285 tmp = String(div.attachEvent); 286 ok(tmp == "\nfunction attachEvent() {\n [native code]\n}\n", "String(div.attachEvent) = " + tmp); 287} 288 289function test_forin() { 290 var cnt=0; 291 292 document.body.innerHTML = '<a id="aid"></a>'; 293 294 for(var x in document.getElementById("aid")) { 295 cnt++; 296 } 297 298 ok(cnt > 100, "cnt = " + cnt); 299} 300 301function test_customtag() { 302 document.body.innerHTML = 'test<unk><br>'; 303 304 var children = document.body.childNodes; 305 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); 310} 311 312function test_whitespace_nodes() { 313 document.body.innerHTML = '<table id="tid"> <tr> \t<td>\n \t<div></div> </td>\n </tr> </table>'; 314 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); 318 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); 322 323 var cell = row.cells[0]; 324 ok(cell.childNodes.length === 1, "cell.childNodes.length = " + cell.childNodes.length); 325 326 327 document.body.innerHTML = '<table id="tid"> x<tr> \tx<td>\n \tx<div></div> </td>\n </tr> </table>'; 328 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); 332} 333 334function 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); 340} 341 342function test_text_node() { 343 document.body.innerHTML = 'testing text'; 344 var text = document.body.childNodes[0], text2; 345 ok(text.data == "testing text", "text.data = " + text.data); 346 347 text2 = text.splitText(7); 348 ok(text.data == "testing", "text.data = " + text.data); 349 ok(text2.data == " text", "text2.data = " + text2.data); 350 ok(text.nextSibling === text2, "text.nextSibling !== text2"); 351 352 text2 = text.splitText(0); 353 ok(text.data == "", "text.data = " + text.data); 354 ok(text2.data == "testing", "text2.data = " + text2.data); 355} 356 357var globalVar = false; 358 359function runTests() { 360 obj = new Object(); 361 ok(obj === window.obj, "obj !== window.obj"); 362 363 ok(typeof(divid) === "object", "typeof(divid) = " + typeof(divid)); 364 365 test_removeAttribute(document.getElementById("divid")); 366 test_removeAttribute(document.body); 367 test_select_index(); 368 test_clone_node(); 369 test_createDocumentFragment(); 370 test_document_name_as_index(); 371 test_remove_style_attribute(); 372 test_getter_call(); 373 test_attrs(); 374 test_attribute_collection(); 375 test_arg_conv(); 376 test_override_functions(); 377 test_forin(); 378 test_customtag(); 379 test_whitespace_nodes(); 380 test_language_attribute(); 381 test_text_node(); 382 383 var r = window.execScript("globalVar = true;"); 384 ok(r === undefined, "execScript returned " + r); 385 ok(globalVar === true, "globalVar = " + globalVar); 386} 387 388function runTest() { 389 try { 390 runTests(); 391 }catch(e) { 392 ok(false, "got exception " + e.message); 393 } 394 395 external.reportSuccess(); 396} 397</script> 398<body onload="runTest();"> 399<div id="divid"></div> 400<select id="sel"> 401<option>opt1</option> 402<option>opt2</option> 403</select> 404</body> 405</html> 406