2008-11-04 Anders Carlsson <andersca@apple.com>
[webkit/qt.git] / LayoutTests / traversal / hixie-node-iterator / 010.xml
blob5c671357be8556f15cfddfd1395ae9d45420ce33
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       if (window.layoutTestController) layoutTestController.dumpAsText();
7       var iterator = document.createNodeIterator(document, NodeFilter.SHOW_ALL, testFilter, false);
8       // skips text nodes and body element
9       var expected = new Array(9, // document
10                                1, // html
11                                1, // head
12                                1, // title
13                                1, 4, // script and CDATA block
14                                // body (skipped)
15                                1, // pre
16                                // </body>
17                                8, // <!-- -->
18                                // PI skipped
19                                4); // CDATA
20       var found = new Array();
22       // walk document
23       var node;
24       while (node = iterator.nextNode())
25         found.push(node.nodeType);
27       // check results
28       var errors = 0;
29       var s = '';
30       var length = (found.length > expected.length) ? found.length : expected.length;
31       s += 'EXPECTED  FOUND\n';
32       for (var i = 0; i < length; i += 1) {
33         s += '  ' + (expected[i] ? expected[i] : '-') +
34       '         ' + (found[i] ? found[i] : '-');
35         if (found[i] != expected[i]) {
36           s += '      MISMATCH';
37           errors += 1;
38         }
39         s += '\n';
40       }
41       var p = document.getElementsByTagNameNS('http://www.w3.org/1999/xhtml', 'pre')[0];
42       if (errors)
43         p.firstChild.data = 'FAIL: ' + errors + ' errors found:\n\n' + s;
44       else
45         p.firstChild.data = 'PASS';
46     }
48     function testFilter(n) {
49       if (n.nodeType == 3) {
50         return NodeFilter.FILTER_SKIP;
51       } else if (n.nodeName == 'body') {
52         return NodeFilter.FILTER_REJECT; // same as _SKIP
53       }
54       return 1; // FILTER_ACCEPT
55     }
57   ]]></script>
58  </head>
59  <body onload="doTest()">
60   <pre id="result">FAIL: Script failed to run.</pre>
61  </body>
62  <!-- some more nodes to test this: -->
63  <?body test?>
64  <![CDATA[ ]]>
65 </html>