tor-browser

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

002.xml (1895B)


      1 <html xmlns="http://www.w3.org/1999/xhtml">
      2 <head>
      3  <title>DOM Traversal: NodeIterator: Basics Backwards</title>
      4  <script type="text/javascript"> <![CDATA[
      5    function doTest() {
      6      var iterator = document.createNodeIterator(document, NodeFilter.SHOW_ALL, null, false);
      7      var expected = new Array(9, // document
      8                               1, // html
      9                               3, 1, // head
     10                               3, 1, 3, // title
     11                               3, 1, 3, 4, // script and CDATA block
     12                               3, 3, 1, // body
     13                               3, 1, 3, // pre
     14                               3, // </body>
     15                               3, 8, // <!-- -->
     16                               3, 7, // <? ?>,
     17                               3, 4, 3); // CDATA
     18      var found = new Array();
     19 
     20      // walk document
     21      var node;
     22      while (node = iterator.nextNode());
     23      while (node = iterator.previousNode())
     24        found.unshift(node.nodeType);
     25 
     26      // check results
     27      var errors = 0;
     28      var s = '';
     29      var length = (found.length > expected.length) ? found.length : expected.length;
     30      s += 'EXPECTED  FOUND\n';
     31      for (var i = 0; i < length; i += 1) {
     32        s += '  ' + (expected[i] ? expected[i] : '-') +
     33      '         ' + (found[i] ? found[i] : '-');
     34        if (found[i] != expected[i]) {
     35          s += '      MISMATCH';
     36          errors += 1;
     37        }
     38        s += '\n';
     39      }
     40      var p = document.getElementsByTagNameNS('http://www.w3.org/1999/xhtml', 'pre')[0];
     41      if (errors)
     42        p.firstChild.data = 'FAIL: ' + errors + ' errors found:\n\n' + s;
     43      else
     44        p.firstChild.data = 'PASS';
     45    }
     46  ]]></script>
     47 </head>
     48 <body onload="doTest()">
     49  <pre id="result">FAIL: Script failed to run.</pre>
     50 </body>
     51 <!-- some more nodes to test this: -->
     52 <?test node?>
     53 <![CDATA[]]>
     54 </html>