2008-11-04 Anders Carlsson <andersca@apple.com>
[webkit/qt.git] / LayoutTests / traversal / hixie-node-iterator / 002.xml
blob35f22ad2e96d0fdb61c6718d1973d41671b9da2a
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       if (window.layoutTestController) layoutTestController.dumpAsText();
7       var iterator = document.createNodeIterator(document, NodeFilter.SHOW_ALL, null, false);
8       var expected = new Array(9, // document
9                                1, // html
10                                3, 1, // head
11                                3, 1, 3, // title
12                                3, 1, 3, 4, // script and CDATA block
13                                3, 3, 1, // body
14                                3, 1, 3, // pre
15                                3, // </body>
16                                3, 8, // <!-- -->
17                                3, 7, // <? ?>,
18                                3, 4, 3); // CDATA
19       var found = new Array();
21       // walk document
22       var node;
23       while (node = iterator.nextNode());
24       while (node = iterator.previousNode())
25         found.unshift(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     }
47   ]]></script>
48  </head>
49  <body onload="doTest()">
50   <pre id="result">FAIL: Script failed to run.</pre>
51  </body>
52  <!-- some more nodes to test this: -->
53  <?test node?>
54  <![CDATA[ ]]>
55 </html>