tor-browser

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

010.xml (2097B)


      1 <html xmlns="http://www.w3.org/1999/xhtml">
      2 <head>
      3  <title>DOM Traversal: NodeIterator: Filters</title>
      4  <script type="text/javascript"> <![CDATA[
      5    function doTest() {
      6      var iterator = document.createNodeIterator(document, NodeFilter.SHOW_ALL, testFilter, false);
      7      // skips text nodes and body element
      8      var expected = new Array(9, // document
      9                               1, // html
     10                               1, // head
     11                               1, // title
     12                               1, 4, // script and CDATA block
     13                               // body (skipped)
     14                               1, // pre
     15                               // </body>
     16                               8, // <!-- -->
     17                               // PI skipped
     18                               4); // CDATA
     19      var found = new Array();
     20 
     21      // walk document
     22      var node;
     23      while (node = iterator.nextNode())
     24        found.push(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 
     47    function testFilter(n) {
     48      if (n.nodeType == 3) {
     49        return NodeFilter.FILTER_SKIP;
     50      } else if (n.nodeName == 'body') {
     51        return NodeFilter.FILTER_REJECT; // same as _SKIP
     52      }
     53      return 1; // FILTER_ACCEPT
     54    }
     55 
     56  ]]></script>
     57 </head>
     58 <body onload="doTest()">
     59  <pre id="result">FAIL: Script failed to run.</pre>
     60 </body>
     61 <!-- some more nodes to test this: -->
     62 <?body test?>
     63 <![CDATA[]]>
     64 </html>