OLD | NEW |
(Empty) | |
| 1 <!doctype html> |
| 2 <title>Node assorted property tests</title> |
| 3 <link rel=author title="Aryeh Gregor" href=ayg@aryeh.name> |
| 4 <meta charset=utf-8> |
| 5 <div id=log></div> |
| 6 <script src=../../../../resources/testharness.js></script> |
| 7 <script src=../../../../resources/testharnessreport.js></script> |
| 8 <script src=../common.js></script> |
| 9 <script> |
| 10 "use strict"; |
| 11 /** |
| 12 * First we define a data structure to tell us what tests to run. The keys |
| 13 * will be eval()ed, and are mostly global variables defined in common.js. The |
| 14 * values are objects, which maps properties to expected values. So |
| 15 * |
| 16 * foo: { |
| 17 * bar: "baz", |
| 18 * quz: 7, |
| 19 * }, |
| 20 * |
| 21 * will test that eval("foo.bar") === "baz" and eval("foo.quz") === 7. "foo" |
| 22 * and "bar" could thus be expressions, like "document.documentElement" and |
| 23 * "childNodes[4]" respectively. |
| 24 * |
| 25 * To avoid repetition, some values are automatically added based on others. |
| 26 * For instance, if we specify nodeType: Node.TEXT_NODE, we'll automatically |
| 27 * also test nodeName: "#text". This is handled by code after this variable is |
| 28 * defined. |
| 29 */ |
| 30 var expected = { |
| 31 testDiv: { |
| 32 // Node |
| 33 nodeType: Node.ELEMENT_NODE, |
| 34 ownerDocument: document, |
| 35 parentNode: document.body, |
| 36 parentElement: document.body, |
| 37 "childNodes.length": 6, |
| 38 "childNodes[0]": paras[0], |
| 39 "childNodes[1]": paras[1], |
| 40 "childNodes[2]": paras[2], |
| 41 "childNodes[3]": paras[3], |
| 42 "childNodes[4]": paras[4], |
| 43 "childNodes[5]": comment, |
| 44 previousSibling: null, |
| 45 nextSibling: document.getElementById("log"), |
| 46 textContent: "A\u0308b\u0308c\u0308d\u0308e\u0308f\u0308g\u0308h\u0308\n
Ijklmnop\nQrstuvwxYzabcdefGhijklmn", |
| 47 |
| 48 // Element |
| 49 namespaceURI: "http://www.w3.org/1999/xhtml", |
| 50 prefix: null, |
| 51 localName: "div", |
| 52 tagName: "DIV", |
| 53 id: "test", |
| 54 "children[0]": paras[0], |
| 55 "children[1]": paras[1], |
| 56 "children[2]": paras[2], |
| 57 "children[3]": paras[3], |
| 58 "children[4]": paras[4], |
| 59 previousElementSibling: null, |
| 60 // nextSibling isn't explicitly set |
| 61 //nextElementSibling: , |
| 62 childElementCount: 5, |
| 63 }, |
| 64 detachedDiv: { |
| 65 // Node |
| 66 nodeType: Node.ELEMENT_NODE, |
| 67 ownerDocument: document, |
| 68 parentNode: null, |
| 69 parentElement: null, |
| 70 "childNodes.length": 2, |
| 71 "childNodes[0]": detachedPara1, |
| 72 "childNodes[1]": detachedPara2, |
| 73 previousSibling: null, |
| 74 nextSibling: null, |
| 75 textContent: "OpqrstuvWxyzabcd", |
| 76 |
| 77 // Element |
| 78 namespaceURI: "http://www.w3.org/1999/xhtml", |
| 79 prefix: null, |
| 80 localName: "div", |
| 81 tagName: "DIV", |
| 82 "children[0]": detachedPara1, |
| 83 "children[1]": detachedPara2, |
| 84 previousElementSibling: null, |
| 85 nextElementSibling: null, |
| 86 childElementCount: 2, |
| 87 }, |
| 88 detachedPara1: { |
| 89 // Node |
| 90 nodeType: Node.ELEMENT_NODE, |
| 91 ownerDocument: document, |
| 92 parentNode: detachedDiv, |
| 93 parentElement: detachedDiv, |
| 94 "childNodes.length": 1, |
| 95 previousSibling: null, |
| 96 nextSibling: detachedPara2, |
| 97 textContent: "Opqrstuv", |
| 98 |
| 99 // Element |
| 100 namespaceURI: "http://www.w3.org/1999/xhtml", |
| 101 prefix: null, |
| 102 localName: "p", |
| 103 tagName: "P", |
| 104 previousElementSibling: null, |
| 105 nextElementSibling: detachedPara2, |
| 106 childElementCount: 0, |
| 107 }, |
| 108 detachedPara2: { |
| 109 // Node |
| 110 nodeType: Node.ELEMENT_NODE, |
| 111 ownerDocument: document, |
| 112 parentNode: detachedDiv, |
| 113 parentElement: detachedDiv, |
| 114 "childNodes.length": 1, |
| 115 previousSibling: detachedPara1, |
| 116 nextSibling: null, |
| 117 textContent: "Wxyzabcd", |
| 118 |
| 119 // Element |
| 120 namespaceURI: "http://www.w3.org/1999/xhtml", |
| 121 prefix: null, |
| 122 localName: "p", |
| 123 tagName: "P", |
| 124 previousElementSibling: detachedPara1, |
| 125 nextElementSibling: null, |
| 126 childElementCount: 0, |
| 127 }, |
| 128 document: { |
| 129 // Node |
| 130 nodeType: Node.DOCUMENT_NODE, |
| 131 "childNodes.length": 2, |
| 132 "childNodes[0]": document.doctype, |
| 133 "childNodes[1]": document.documentElement, |
| 134 |
| 135 // Document |
| 136 URL: String(location), |
| 137 compatMode: "CSS1Compat", |
| 138 characterSet: "UTF-8", |
| 139 contentType: "text/html", |
| 140 doctype: doctype, |
| 141 //documentElement: , |
| 142 }, |
| 143 foreignDoc: { |
| 144 // Node |
| 145 nodeType: Node.DOCUMENT_NODE, |
| 146 "childNodes.length": 3, |
| 147 "childNodes[0]": foreignDoc.doctype, |
| 148 "childNodes[1]": foreignDoc.documentElement, |
| 149 "childNodes[2]": foreignComment, |
| 150 |
| 151 // Document |
| 152 URL: "about:blank", |
| 153 compatMode: "CSS1Compat", |
| 154 characterSet: "UTF-8", |
| 155 contentType: "text/html", |
| 156 //doctype: , |
| 157 //documentElement: , |
| 158 }, |
| 159 foreignPara1: { |
| 160 // Node |
| 161 nodeType: Node.ELEMENT_NODE, |
| 162 ownerDocument: foreignDoc, |
| 163 parentNode: foreignDoc.body, |
| 164 parentElement: foreignDoc.body, |
| 165 "childNodes.length": 1, |
| 166 previousSibling: null, |
| 167 nextSibling: foreignPara2, |
| 168 textContent: "Efghijkl", |
| 169 |
| 170 // Element |
| 171 namespaceURI: "http://www.w3.org/1999/xhtml", |
| 172 prefix: null, |
| 173 localName: "p", |
| 174 tagName: "P", |
| 175 previousElementSibling: null, |
| 176 nextElementSibling: foreignPara2, |
| 177 childElementCount: 0, |
| 178 }, |
| 179 foreignPara2: { |
| 180 // Node |
| 181 nodeType: Node.ELEMENT_NODE, |
| 182 ownerDocument: foreignDoc, |
| 183 parentNode: foreignDoc.body, |
| 184 parentElement: foreignDoc.body, |
| 185 "childNodes.length": 1, |
| 186 previousSibling: foreignPara1, |
| 187 nextSibling: foreignTextNode, |
| 188 textContent: "Mnopqrst", |
| 189 |
| 190 // Element |
| 191 namespaceURI: "http://www.w3.org/1999/xhtml", |
| 192 prefix: null, |
| 193 localName: "p", |
| 194 tagName: "P", |
| 195 previousElementSibling: foreignPara1, |
| 196 nextElementSibling: null, |
| 197 childElementCount: 0, |
| 198 }, |
| 199 xmlDoc: { |
| 200 // Node |
| 201 nodeType: Node.DOCUMENT_NODE, |
| 202 "childNodes.length": 4, |
| 203 "childNodes[0]": xmlDoctype, |
| 204 "childNodes[1]": xmlElement, |
| 205 "childNodes[2]": processingInstruction, |
| 206 "childNodes[3]": xmlComment, |
| 207 |
| 208 // Document |
| 209 URL: "about:blank", |
| 210 compatMode: "CSS1Compat", |
| 211 characterSet: "UTF-8", |
| 212 contentType: "application/xml", |
| 213 //doctype: , |
| 214 //documentElement: , |
| 215 }, |
| 216 xmlElement: { |
| 217 // Node |
| 218 nodeType: Node.ELEMENT_NODE, |
| 219 ownerDocument: xmlDoc, |
| 220 parentNode: xmlDoc, |
| 221 parentElement: null, |
| 222 "childNodes.length": 1, |
| 223 "childNodes[0]": xmlTextNode, |
| 224 previousSibling: xmlDoctype, |
| 225 nextSibling: processingInstruction, |
| 226 textContent: "do re mi fa so la ti", |
| 227 |
| 228 // Element |
| 229 namespaceURI: "http://www.w3.org/1999/xhtml", |
| 230 prefix: null, |
| 231 localName: "igiveuponcreativenames", |
| 232 tagName: "igiveuponcreativenames", |
| 233 previousElementSibling: null, |
| 234 nextElementSibling: null, |
| 235 childElementCount: 0, |
| 236 }, |
| 237 detachedXmlElement: { |
| 238 // Node |
| 239 nodeType: Node.ELEMENT_NODE, |
| 240 ownerDocument: xmlDoc, |
| 241 parentNode: null, |
| 242 parentElement: null, |
| 243 "childNodes.length": 0, |
| 244 previousSibling: null, |
| 245 nextSibling: null, |
| 246 textContent: "", |
| 247 |
| 248 // Element |
| 249 namespaceURI: "http://www.w3.org/1999/xhtml", |
| 250 prefix: null, |
| 251 localName: "everyone-hates-hyphenated-element-names", |
| 252 tagName: "everyone-hates-hyphenated-element-names", |
| 253 previousElementSibling: null, |
| 254 nextElementSibling: null, |
| 255 childElementCount: 0, |
| 256 }, |
| 257 detachedTextNode: { |
| 258 // Node |
| 259 nodeType: Node.TEXT_NODE, |
| 260 ownerDocument: document, |
| 261 parentNode: null, |
| 262 parentElement: null, |
| 263 previousSibling: null, |
| 264 nextSibling: null, |
| 265 nodeValue: "Uvwxyzab", |
| 266 |
| 267 // Text |
| 268 wholeText: "Uvwxyzab", |
| 269 }, |
| 270 foreignTextNode: { |
| 271 // Node |
| 272 nodeType: Node.TEXT_NODE, |
| 273 ownerDocument: foreignDoc, |
| 274 parentNode: foreignDoc.body, |
| 275 parentElement: foreignDoc.body, |
| 276 previousSibling: foreignPara2, |
| 277 nextSibling: null, |
| 278 nodeValue: "I admit that I harbor doubts about whether we really need so
many things to test, but it's too late to stop now.", |
| 279 |
| 280 // Text |
| 281 wholeText: "I admit that I harbor doubts about whether we really need so
many things to test, but it's too late to stop now.", |
| 282 }, |
| 283 detachedForeignTextNode: { |
| 284 // Node |
| 285 nodeType: Node.TEXT_NODE, |
| 286 ownerDocument: foreignDoc, |
| 287 parentNode: null, |
| 288 parentElement: null, |
| 289 previousSibling: null, |
| 290 nextSibling: null, |
| 291 nodeValue: "Cdefghij", |
| 292 |
| 293 // Text |
| 294 wholeText: "Cdefghij", |
| 295 }, |
| 296 xmlTextNode: { |
| 297 // Node |
| 298 nodeType: Node.TEXT_NODE, |
| 299 ownerDocument: xmlDoc, |
| 300 parentNode: xmlElement, |
| 301 parentElement: xmlElement, |
| 302 previousSibling: null, |
| 303 nextSibling: null, |
| 304 nodeValue: "do re mi fa so la ti", |
| 305 |
| 306 // Text |
| 307 wholeText: "do re mi fa so la ti", |
| 308 }, |
| 309 detachedXmlTextNode: { |
| 310 // Node |
| 311 nodeType: Node.TEXT_NODE, |
| 312 ownerDocument: xmlDoc, |
| 313 parentNode: null, |
| 314 parentElement: null, |
| 315 previousSibling: null, |
| 316 nextSibling: null, |
| 317 nodeValue: "Klmnopqr", |
| 318 |
| 319 // Text |
| 320 wholeText: "Klmnopqr", |
| 321 }, |
| 322 processingInstruction: { |
| 323 // Node |
| 324 nodeType: Node.PROCESSING_INSTRUCTION_NODE, |
| 325 ownerDocument: xmlDoc, |
| 326 parentNode: xmlDoc, |
| 327 parentElement: null, |
| 328 previousSibling: xmlElement, |
| 329 nextSibling: xmlComment, |
| 330 nodeValue: 'Did you know that ":syn sync fromstart" is very useful when
using vim to edit large amounts of JavaScript embedded in HTML?', |
| 331 |
| 332 // ProcessingInstruction |
| 333 target: "somePI", |
| 334 }, |
| 335 detachedProcessingInstruction: { |
| 336 // Node |
| 337 nodeType: Node.PROCESSING_INSTRUCTION_NODE, |
| 338 ownerDocument: xmlDoc, |
| 339 parentNode: null, |
| 340 parentElement: null, |
| 341 previousSibling: null, |
| 342 nextSibling: null, |
| 343 nodeValue: "chirp chirp chirp", |
| 344 |
| 345 // ProcessingInstruction |
| 346 target: "whippoorwill", |
| 347 }, |
| 348 comment: { |
| 349 // Node |
| 350 nodeType: Node.COMMENT_NODE, |
| 351 ownerDocument: document, |
| 352 parentNode: testDiv, |
| 353 parentElement: testDiv, |
| 354 previousSibling: paras[4], |
| 355 nextSibling: null, |
| 356 nodeValue: "Alphabet soup?", |
| 357 }, |
| 358 detachedComment: { |
| 359 // Node |
| 360 nodeType: Node.COMMENT_NODE, |
| 361 ownerDocument: document, |
| 362 parentNode: null, |
| 363 parentElement: null, |
| 364 previousSibling: null, |
| 365 nextSibling: null, |
| 366 nodeValue: "Stuvwxyz", |
| 367 }, |
| 368 foreignComment: { |
| 369 // Node |
| 370 nodeType: Node.COMMENT_NODE, |
| 371 ownerDocument: foreignDoc, |
| 372 parentNode: foreignDoc, |
| 373 parentElement: null, |
| 374 previousSibling: foreignDoc.documentElement, |
| 375 nextSibling: null, |
| 376 nodeValue: '"Commenter" and "commentator" mean different things. I\'ve
seen non-native speakers trip up on this.', |
| 377 }, |
| 378 detachedForeignComment: { |
| 379 // Node |
| 380 nodeType: Node.COMMENT_NODE, |
| 381 ownerDocument: foreignDoc, |
| 382 parentNode: null, |
| 383 parentElement: null, |
| 384 previousSibling: null, |
| 385 nextSibling: null, |
| 386 nodeValue: "אריה יהודה", |
| 387 }, |
| 388 xmlComment: { |
| 389 // Node |
| 390 nodeType: Node.COMMENT_NODE, |
| 391 ownerDocument: xmlDoc, |
| 392 parentNode: xmlDoc, |
| 393 parentElement: null, |
| 394 previousSibling: processingInstruction, |
| 395 nextSibling: null, |
| 396 nodeValue: "I maliciously created a comment that will break incautious X
ML serializers, but Firefox threw an exception, so all I got was this lousy T-sh
irt", |
| 397 }, |
| 398 detachedXmlComment: { |
| 399 // Node |
| 400 nodeType: Node.COMMENT_NODE, |
| 401 ownerDocument: xmlDoc, |
| 402 parentNode: null, |
| 403 parentElement: null, |
| 404 previousSibling: null, |
| 405 nextSibling: null, |
| 406 nodeValue: "בן חיים אליעזר", |
| 407 }, |
| 408 docfrag: { |
| 409 // Node |
| 410 nodeType: Node.DOCUMENT_FRAGMENT_NODE, |
| 411 ownerDocument: document, |
| 412 "childNodes.length": 0, |
| 413 textContent: "", |
| 414 }, |
| 415 foreignDocfrag: { |
| 416 // Node |
| 417 nodeType: Node.DOCUMENT_FRAGMENT_NODE, |
| 418 ownerDocument: foreignDoc, |
| 419 "childNodes.length": 0, |
| 420 textContent: "", |
| 421 }, |
| 422 xmlDocfrag: { |
| 423 // Node |
| 424 nodeType: Node.DOCUMENT_FRAGMENT_NODE, |
| 425 ownerDocument: xmlDoc, |
| 426 "childNodes.length": 0, |
| 427 textContent: "", |
| 428 }, |
| 429 doctype: { |
| 430 // Node |
| 431 nodeType: Node.DOCUMENT_TYPE_NODE, |
| 432 ownerDocument: document, |
| 433 parentNode: document, |
| 434 previousSibling: null, |
| 435 nextSibling: document.documentElement, |
| 436 |
| 437 // DocumentType |
| 438 name: "html", |
| 439 publicId: "", |
| 440 systemId: "", |
| 441 }, |
| 442 foreignDoctype: { |
| 443 // Node |
| 444 nodeType: Node.DOCUMENT_TYPE_NODE, |
| 445 ownerDocument: foreignDoc, |
| 446 parentNode: foreignDoc, |
| 447 previousSibling: null, |
| 448 nextSibling: foreignDoc.documentElement, |
| 449 |
| 450 // DocumentType |
| 451 name: "html", |
| 452 publicId: "", |
| 453 systemId: "", |
| 454 }, |
| 455 xmlDoctype: { |
| 456 // Node |
| 457 nodeType: Node.DOCUMENT_TYPE_NODE, |
| 458 ownerDocument: xmlDoc, |
| 459 parentNode: xmlDoc, |
| 460 previousSibling: null, |
| 461 nextSibling: xmlElement, |
| 462 |
| 463 // DocumentType |
| 464 name: "qorflesnorf", |
| 465 publicId: "abcde", |
| 466 systemId: "x\"'y", |
| 467 }, |
| 468 "paras[0]": { |
| 469 // Node |
| 470 nodeType: Node.ELEMENT_NODE, |
| 471 ownerDocument: document, |
| 472 parentNode: testDiv, |
| 473 parentElement: testDiv, |
| 474 "childNodes.length": 1, |
| 475 previousSibling: null, |
| 476 nextSibling: paras[1], |
| 477 textContent: "A\u0308b\u0308c\u0308d\u0308e\u0308f\u0308g\u0308h\u0308\n
", |
| 478 |
| 479 // Element |
| 480 namespaceURI: "http://www.w3.org/1999/xhtml", |
| 481 prefix: null, |
| 482 localName: "p", |
| 483 tagName: "P", |
| 484 id: "a", |
| 485 previousElementSibling: null, |
| 486 nextElementSibling: paras[1], |
| 487 childElementCount: 0, |
| 488 }, |
| 489 "paras[1]": { |
| 490 // Node |
| 491 nodeType: Node.ELEMENT_NODE, |
| 492 ownerDocument: document, |
| 493 parentNode: testDiv, |
| 494 parentElement: testDiv, |
| 495 "childNodes.length": 1, |
| 496 previousSibling: paras[0], |
| 497 nextSibling: paras[2], |
| 498 textContent: "Ijklmnop\n", |
| 499 |
| 500 // Element |
| 501 namespaceURI: "http://www.w3.org/1999/xhtml", |
| 502 prefix: null, |
| 503 localName: "p", |
| 504 tagName: "P", |
| 505 id: "b", |
| 506 previousElementSibling: paras[0], |
| 507 nextElementSibling: paras[2], |
| 508 childElementCount: 0, |
| 509 }, |
| 510 "paras[2]": { |
| 511 // Node |
| 512 nodeType: Node.ELEMENT_NODE, |
| 513 ownerDocument: document, |
| 514 parentNode: testDiv, |
| 515 parentElement: testDiv, |
| 516 "childNodes.length": 1, |
| 517 previousSibling: paras[1], |
| 518 nextSibling: paras[3], |
| 519 textContent: "Qrstuvwx", |
| 520 |
| 521 // Element |
| 522 namespaceURI: "http://www.w3.org/1999/xhtml", |
| 523 prefix: null, |
| 524 localName: "p", |
| 525 tagName: "P", |
| 526 id: "c", |
| 527 previousElementSibling: paras[1], |
| 528 nextElementSibling: paras[3], |
| 529 childElementCount: 0, |
| 530 }, |
| 531 "paras[3]": { |
| 532 // Node |
| 533 nodeType: Node.ELEMENT_NODE, |
| 534 ownerDocument: document, |
| 535 parentNode: testDiv, |
| 536 parentElement: testDiv, |
| 537 "childNodes.length": 1, |
| 538 previousSibling: paras[2], |
| 539 nextSibling: paras[4], |
| 540 textContent: "Yzabcdef", |
| 541 |
| 542 // Element |
| 543 namespaceURI: "http://www.w3.org/1999/xhtml", |
| 544 prefix: null, |
| 545 localName: "p", |
| 546 tagName: "P", |
| 547 id: "d", |
| 548 previousElementSibling: paras[2], |
| 549 nextElementSibling: paras[4], |
| 550 childElementCount: 0, |
| 551 }, |
| 552 "paras[4]": { |
| 553 // Node |
| 554 nodeType: Node.ELEMENT_NODE, |
| 555 ownerDocument: document, |
| 556 parentNode: testDiv, |
| 557 parentElement: testDiv, |
| 558 "childNodes.length": 1, |
| 559 previousSibling: paras[3], |
| 560 nextSibling: comment, |
| 561 textContent: "Ghijklmn", |
| 562 |
| 563 // Element |
| 564 namespaceURI: "http://www.w3.org/1999/xhtml", |
| 565 prefix: null, |
| 566 localName: "p", |
| 567 tagName: "P", |
| 568 id: "e", |
| 569 previousElementSibling: paras[3], |
| 570 nextElementSibling: null, |
| 571 childElementCount: 0, |
| 572 }, |
| 573 }; |
| 574 |
| 575 for (var node in expected) { |
| 576 // Now we set various default values by node type. |
| 577 switch (expected[node].nodeType) { |
| 578 case Node.ELEMENT_NODE: |
| 579 expected[node].nodeName = expected[node].tagName; |
| 580 expected[node].nodeValue = null; |
| 581 expected[node]["children.length"] = expected[node].childElementCount; |
| 582 |
| 583 if (expected[node].id === undefined) { |
| 584 expected[node].id = ""; |
| 585 } |
| 586 if (expected[node].className === undefined) { |
| 587 expected[node].className = ""; |
| 588 } |
| 589 |
| 590 var len = expected[node].childElementCount; |
| 591 if (len === 0) { |
| 592 expected[node].firstElementChild = |
| 593 expected[node].lastElementChild = null; |
| 594 } else { |
| 595 // If we have expectations for the first/last child in children, |
| 596 // use those. Otherwise, at least check that .firstElementChild == |
| 597 // .children[0] and .lastElementChild == .children[len - 1], even |
| 598 // if we aren't sure what they should be. |
| 599 expected[node].firstElementChild = expected[node]["children[0]"] |
| 600 ? expected[node]["children[0]"] |
| 601 : eval(node).children[0]; |
| 602 expected[node].lastElementChild = |
| 603 expected[node]["children[" + (len - 1) + "]"] |
| 604 ? expected[node]["children[" + (len - 1) + "]"] |
| 605 : eval(node).children[len - 1]; |
| 606 } |
| 607 break; |
| 608 |
| 609 case Node.TEXT_NODE: |
| 610 expected[node].nodeName = "#text"; |
| 611 expected[node]["childNodes.length"] = 0; |
| 612 expected[node].textContent = expected[node].data = |
| 613 expected[node].nodeValue; |
| 614 expected[node].length = expected[node].nodeValue.length; |
| 615 break; |
| 616 |
| 617 case Node.PROCESSING_INSTRUCTION_NODE: |
| 618 expected[node].nodeName = expected[node].target; |
| 619 expected[node]["childNodes.length"] = 0; |
| 620 expected[node].textContent = expected[node].data = |
| 621 expected[node].nodeValue; |
| 622 expected[node].length = expected[node].nodeValue.length; |
| 623 break; |
| 624 |
| 625 case Node.COMMENT_NODE: |
| 626 expected[node].nodeName = "#comment"; |
| 627 expected[node]["childNodes.length"] = 0; |
| 628 expected[node].textContent = expected[node].data = |
| 629 expected[node].nodeValue; |
| 630 expected[node].length = expected[node].nodeValue.length; |
| 631 break; |
| 632 |
| 633 case Node.DOCUMENT_NODE: |
| 634 expected[node].nodeName = "#document"; |
| 635 expected[node].ownerDocument = expected[node].parentNode = |
| 636 expected[node].parentElement = expected[node].previousSibling = |
| 637 expected[node].nextSibling = expected[node].nodeValue = |
| 638 expected[node].textContent = null; |
| 639 expected[node].documentURI = expected[node].URL; |
| 640 expected[node].charset = expected[node].inputEncoding = |
| 641 expected[node].characterSet; |
| 642 break; |
| 643 |
| 644 case Node.DOCUMENT_TYPE_NODE: |
| 645 expected[node].nodeName = expected[node].name; |
| 646 expected[node]["childNodes.length"] = 0; |
| 647 expected[node].parentElement = expected[node].nodeValue = |
| 648 expected[node].textContent = null; |
| 649 break; |
| 650 |
| 651 case Node.DOCUMENT_FRAGMENT_NODE: |
| 652 expected[node].nodeName = "#document-fragment"; |
| 653 expected[node].parentNode = expected[node].parentElement = |
| 654 expected[node].previousSibling = expected[node].nextSibling = |
| 655 expected[node].nodeValue = null; |
| 656 break; |
| 657 } |
| 658 |
| 659 // Now we set some further default values that are independent of node |
| 660 // type. |
| 661 var len = expected[node]["childNodes.length"]; |
| 662 if (len === 0) { |
| 663 expected[node].firstChild = expected[node].lastChild = null; |
| 664 } else { |
| 665 // If we have expectations for the first/last child in childNodes, use |
| 666 // those. Otherwise, at least check that .firstChild == .childNodes[0] |
| 667 // and .lastChild == .childNodes[len - 1], even if we aren't sure what |
| 668 // they should be. |
| 669 expected[node].firstChild = expected[node]["childNodes[0]"] |
| 670 ? expected[node]["childNodes[0]"] |
| 671 : eval(node).childNodes[0]; |
| 672 expected[node].lastChild = |
| 673 expected[node]["childNodes[" + (len - 1) + "]"] |
| 674 ? expected[node]["childNodes[" + (len - 1) + "]"] |
| 675 : eval(node).childNodes[len - 1]; |
| 676 } |
| 677 expected[node]["hasChildNodes()"] = !!expected[node]["childNodes.length"]; |
| 678 |
| 679 // Finally, we test! |
| 680 for (var prop in expected[node]) { |
| 681 test(function() { |
| 682 assert_equals(eval(node + "." + prop), expected[node][prop]); |
| 683 }, node + "." + prop); |
| 684 } |
| 685 } |
| 686 |
| 687 testDiv.parentNode.removeChild(testDiv); |
| 688 </script> |
OLD | NEW |