summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/dom/traversal/unfinished/010.xml
blob: 63263a5fd7306824890f6e6eae0a9818c28b8884 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<html xmlns="http://www.w3.org/1999/xhtml">
 <head>
  <title>DOM Traversal: NodeIterator: Filters</title>
  <script type="text/javascript"> <![CDATA[
    function doTest() {
      var iterator = document.createNodeIterator(document, NodeFilter.SHOW_ALL, testFilter, false);
      // skips text nodes and body element
      var expected = new Array(9, // document
                               1, // html
                               1, // head
                               1, // title
                               1, 4, // script and CDATA block
                               // body (skipped)
                               1, // pre
                               // </body>
                               8, // <!-- -->
                               // PI skipped
                               4); // CDATA
      var found = new Array();

      // walk document
      var node;
      while (node = iterator.nextNode())
        found.push(node.nodeType);

      // check results
      var errors = 0;
      var s = '';
      var length = (found.length > expected.length) ? found.length : expected.length;
      s += 'EXPECTED  FOUND\n';
      for (var i = 0; i < length; i += 1) {
        s += '  ' + (expected[i] ? expected[i] : '-') +
      '         ' + (found[i] ? found[i] : '-');
        if (found[i] != expected[i]) {
          s += '      MISMATCH';
          errors += 1;
        }
        s += '\n';
      }
      var p = document.getElementsByTagNameNS('http://www.w3.org/1999/xhtml', 'pre')[0];
      if (errors)
        p.firstChild.data = 'FAIL: ' + errors + ' errors found:\n\n' + s;
      else
        p.firstChild.data = 'PASS';
    }

    function testFilter(n) {
      if (n.nodeType == 3) {
        return NodeFilter.FILTER_SKIP;
      } else if (n.nodeName == 'body') {
        return NodeFilter.FILTER_REJECT; // same as _SKIP
      }
      return 1; // FILTER_ACCEPT
    }

  ]]></script>
 </head>
 <body onload="doTest()">
  <pre id="result">FAIL: Script failed to run.</pre>
 </body>
 <!-- some more nodes to test this: -->
 <?body test?>
 <![CDATA[]]>
</html>