tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_treewalker_nextsibling.xml (2865B)


      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  var walker = document.createTreeWalker(
     24    document,
     25    NodeFilter.SHOW_TEXT | NodeFilter.SHOW_DOCUMENT,
     26    null
     27  );
     28  setPass(walker.firstChild());
     29  while (walker.nextSibling()) {
     30    setPass(walker.currentNode);
     31  }
     32 
     33 /*
     34 From http://www.w3.org/TR/2000/REC-DOM-Level-2-Traversal-Range-20001113/traversal.html#Traversal-TreeWalker
     35 Omitting nodes from the logical view of a subtree can result in a structure that
     36 is substantially different from the same subtree in the complete, unfiltered
     37 document. Nodes that are siblings in the TreeWalker view may be children of
     38 different, widely separated nodes in the original view. For instance, consider a
     39 NodeFilter that skips all nodes except for Text nodes and the root node of a
     40 document. In the logical view that results, all text nodes will be siblings and
     41 appear as direct children of the root node, no matter how deeply nested the
     42 structure of the original document.
     43 */
     44 
     45  walker2 = document.createTreeWalker(document, NodeFilter.SHOW_TEXT, null);
     46  while (walker2.nextNode()) {
     47    var cNode = walker2.currentNode;
     48    ok(passedNodes.get(cNode), "Every text node should appear: " + walker2.currentNode.nodeValue);
     49    walker.currentNode = cNode;
     50    var parent = walker.parentNode();
     51    is(parent, document, "parent of text node should be document");
     52 
     53    // Check nextSibling's previousSibling.
     54    walker.currentNode = cNode;
     55    if (walker.nextSibling()) {
     56      is(cNode, walker.previousSibling(), "nextSibling.previousSibling should be consistent");
     57    }
     58 
     59    // Check previousSibling's nextSibling.
     60    walker.currentNode = cNode;
     61    if (walker.previousSibling()) {
     62      is(cNode, walker.nextSibling(), "previousSibling.nextSibling should be consistent");
     63    }
     64  }
     65  SimpleTest.finish();
     66 }, true);
     67 ]]>
     68 </script>
     69 </pre>
     70 
     71  <test>
     72    zero
     73    <one>
     74      one-A
     75      <two>
     76        two-A
     77      </two>
     78      <two>
     79        two-B
     80      </two>
     81      one-B
     82    </one>
     83    <one>
     84      one-C
     85      <two>
     86        two-D
     87      </two>
     88      <two>
     89        two-E
     90      </two>
     91      one-F
     92    </one>
     93    zero
     94  </test>
     95 </root>