content/base/test/test_treewalker_nextsibling.xml

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:d80ddb5696ca
1 <?xml-stylesheet type="text/css" href="/tests/SimpleTest/test.css" ?>
2 <root>
3 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js" xmlns="http://www.w3.org/1999/xhtml"/>
4
5 <body xmlns="http://www.w3.org/1999/xhtml">
6 <p id="display"></p>
7 <div id="content" style="display: none;"></div>
8 <textarea id="test" style="height: 300px; max-width: 800px; overflow: scroll;"
9 rows="10" cols="160" readonly="readonly"/>
10 </body>
11
12 <pre id="test" xmlns="http://www.w3.org/1999/xhtml">
13 <script class="testbody" type="text/javascript" xmlns="http://www.w3.org/1999/xhtml">
14 <![CDATA[
15 var passedNodes = new WeakMap();
16 function setPass(aNode) {
17 passedNodes.set(aNode, true);
18 }
19
20 SimpleTest.waitForExplicitFinish();
21
22 window.addEventListener("load", function() {
23 const nsIDOMNodeFilter = SpecialPowers.Ci.nsIDOMNodeFilter;
24 var walker = document.createTreeWalker(
25 document,
26 nsIDOMNodeFilter.SHOW_TEXT | nsIDOMNodeFilter.SHOW_DOCUMENT,
27 null
28 );
29 setPass(walker.firstChild());
30 while (walker.nextSibling()) {
31 setPass(walker.currentNode);
32 }
33
34 /*
35 From http://www.w3.org/TR/2000/REC-DOM-Level-2-Traversal-Range-20001113/traversal.html#Traversal-TreeWalker
36 Omitting nodes from the logical view of a subtree can result in a structure that
37 is substantially different from the same subtree in the complete, unfiltered
38 document. Nodes that are siblings in the TreeWalker view may be children of
39 different, widely separated nodes in the original view. For instance, consider a
40 NodeFilter that skips all nodes except for Text nodes and the root node of a
41 document. In the logical view that results, all text nodes will be siblings and
42 appear as direct children of the root node, no matter how deeply nested the
43 structure of the original document.
44 */
45
46 walker2 = document.createTreeWalker(document, nsIDOMNodeFilter.SHOW_TEXT, null);
47 while (walker2.nextNode()) {
48 var cNode = walker2.currentNode;
49 ok(passedNodes.get(cNode), "Every text node should appear: " + walker2.currentNode.nodeValue);
50 walker.currentNode = cNode;
51 var parent = walker.parentNode();
52 is(parent, document, "parent of text node should be document");
53
54 // Check nextSibling's previousSibling.
55 walker.currentNode = cNode;
56 if (walker.nextSibling()) {
57 is(cNode, walker.previousSibling(), "nextSibling.previousSibling should be consistent");
58 }
59
60 // Check previousSibling's nextSibling.
61 walker.currentNode = cNode;
62 if (walker.previousSibling()) {
63 is(cNode, walker.nextSibling(), "previousSibling.nextSibling should be consistent");
64 }
65 }
66 SimpleTest.finish();
67 }, true);
68 ]]>
69 </script>
70 </pre>
71
72 <test>
73 zero
74 <one>
75 one-A
76 <two>
77 two-A
78 </two>
79 <two>
80 two-B
81 </two>
82 one-B
83 </one>
84 <one>
85 one-C
86 <two>
87 two-D
88 </two>
89 <two>
90 two-E
91 </two>
92 one-F
93 </one>
94 zero
95 </test>
96 </root>
97

mercurial