1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/content/base/test/test_treewalker_nextsibling.xml Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,97 @@ 1.4 +<?xml-stylesheet type="text/css" href="/tests/SimpleTest/test.css" ?> 1.5 +<root> 1.6 + <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js" xmlns="http://www.w3.org/1999/xhtml"/> 1.7 + 1.8 + <body xmlns="http://www.w3.org/1999/xhtml"> 1.9 + <p id="display"></p> 1.10 + <div id="content" style="display: none;"></div> 1.11 + <textarea id="test" style="height: 300px; max-width: 800px; overflow: scroll;" 1.12 + rows="10" cols="160" readonly="readonly"/> 1.13 + </body> 1.14 + 1.15 +<pre id="test" xmlns="http://www.w3.org/1999/xhtml"> 1.16 +<script class="testbody" type="text/javascript" xmlns="http://www.w3.org/1999/xhtml"> 1.17 +<![CDATA[ 1.18 +var passedNodes = new WeakMap(); 1.19 +function setPass(aNode) { 1.20 + passedNodes.set(aNode, true); 1.21 +} 1.22 + 1.23 +SimpleTest.waitForExplicitFinish(); 1.24 + 1.25 +window.addEventListener("load", function() { 1.26 + const nsIDOMNodeFilter = SpecialPowers.Ci.nsIDOMNodeFilter; 1.27 + var walker = document.createTreeWalker( 1.28 + document, 1.29 + nsIDOMNodeFilter.SHOW_TEXT | nsIDOMNodeFilter.SHOW_DOCUMENT, 1.30 + null 1.31 + ); 1.32 + setPass(walker.firstChild()); 1.33 + while (walker.nextSibling()) { 1.34 + setPass(walker.currentNode); 1.35 + } 1.36 + 1.37 +/* 1.38 +From http://www.w3.org/TR/2000/REC-DOM-Level-2-Traversal-Range-20001113/traversal.html#Traversal-TreeWalker 1.39 +Omitting nodes from the logical view of a subtree can result in a structure that 1.40 +is substantially different from the same subtree in the complete, unfiltered 1.41 +document. Nodes that are siblings in the TreeWalker view may be children of 1.42 +different, widely separated nodes in the original view. For instance, consider a 1.43 +NodeFilter that skips all nodes except for Text nodes and the root node of a 1.44 +document. In the logical view that results, all text nodes will be siblings and 1.45 +appear as direct children of the root node, no matter how deeply nested the 1.46 +structure of the original document. 1.47 +*/ 1.48 + 1.49 + walker2 = document.createTreeWalker(document, nsIDOMNodeFilter.SHOW_TEXT, null); 1.50 + while (walker2.nextNode()) { 1.51 + var cNode = walker2.currentNode; 1.52 + ok(passedNodes.get(cNode), "Every text node should appear: " + walker2.currentNode.nodeValue); 1.53 + walker.currentNode = cNode; 1.54 + var parent = walker.parentNode(); 1.55 + is(parent, document, "parent of text node should be document"); 1.56 + 1.57 + // Check nextSibling's previousSibling. 1.58 + walker.currentNode = cNode; 1.59 + if (walker.nextSibling()) { 1.60 + is(cNode, walker.previousSibling(), "nextSibling.previousSibling should be consistent"); 1.61 + } 1.62 + 1.63 + // Check previousSibling's nextSibling. 1.64 + walker.currentNode = cNode; 1.65 + if (walker.previousSibling()) { 1.66 + is(cNode, walker.nextSibling(), "previousSibling.nextSibling should be consistent"); 1.67 + } 1.68 + } 1.69 + SimpleTest.finish(); 1.70 +}, true); 1.71 +]]> 1.72 +</script> 1.73 +</pre> 1.74 + 1.75 + <test> 1.76 + zero 1.77 + <one> 1.78 + one-A 1.79 + <two> 1.80 + two-A 1.81 + </two> 1.82 + <two> 1.83 + two-B 1.84 + </two> 1.85 + one-B 1.86 + </one> 1.87 + <one> 1.88 + one-C 1.89 + <two> 1.90 + two-D 1.91 + </two> 1.92 + <two> 1.93 + two-E 1.94 + </two> 1.95 + one-F 1.96 + </one> 1.97 + zero 1.98 + </test> 1.99 +</root> 1.100 +