Element Traversal is not just Elements anymore
[WebKit-https.git] / LayoutTests / fast / dom / element-traversal-on-document.html
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <meta charset="utf-8">
5 <script src="../../resources/js-test-pre.js"></script>
6 </head>
7 <body>
8 <script>
9
10 description("This test checks the implementation of the element traversal APIs on Document as part of the ParentNode interface.");
11
12 function createEmptyDocument()
13 {
14     var doc = document.implementation.createHTMLDocument();
15     while (doc.firstChild) {
16         doc.removeChild(doc.firstChild);
17     }
18     return doc;
19 }
20
21 debug('Test with no children');
22 var noChildren = createEmptyDocument();
23 shouldBe("noChildren.firstElementChild", "null");
24 shouldBe("noChildren.lastElementChild", "null");
25 shouldBe("noChildren.childElementCount", "0");
26
27 debug('Test with no element children');
28 var noElementChildren = createEmptyDocument();
29 noElementChildren.appendChild(document.createComment("comment but not an element"));
30
31 shouldBe("noElementChildren.firstElementChild", "null");
32 shouldBe("noElementChildren.lastElementChild", "null");
33 shouldBe("noElementChildren.childElementCount", "0");
34
35 debug('Test with elements');
36 var children = createEmptyDocument();
37 children.appendChild(document.createComment("first comment"));
38 var child = document.createElement('p');
39 children.appendChild(child);
40 children.appendChild(document.createComment("a comment"));
41
42 shouldBe("children.firstElementChild", "child");
43 shouldBe("children.lastElementChild", "child");
44 shouldBe("children.childElementCount", "1");
45
46 </script>
47 <script src="../../resources/js-test-post.js"></script>
48 </body>
49 </html>