Reviewed by Darin.
[WebKit-https.git] / LayoutTests / fast / xpath / 4XPath / Core / test_node_test.html
1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
2 <html>
3 <head>
4 <link rel="stylesheet" href="../../../js/resources/js-test-style.css">
5 <script src="../../../js/resources/js-test-pre.js"></script>
6 <script src="test.js"></script>
7 </head>
8 <body>
9 <div id="console"></div>
10
11 <script>
12     function nsResolver(prefix) {
13         if (prefix == 'bar')
14             return 'http://foo.com';
15         return null;
16     }
17
18     function nodeInResult(node, result) {
19         for (i=0; i < result.snapshotLength; ++i)
20             if (result.snapshotItem(i) == node)
21                 return true;
22         return false;
23     }
24
25     result = DOM.evaluate("//*", ROOT, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
26     shouldBe("nodeInResult(ROOT, result)", "true");
27
28     result = DOM.evaluate("//bar:CHILD3", ROOT, nsResolver, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
29     shouldBe("nodeInResult(ROOT, result)", "false");
30     shouldBe("nodeInResult(CHILD1, result)", "false");
31     shouldBe("nodeInResult(CHILD3, result)", "true");
32
33     result = DOM.evaluate("//bar:*", ROOT, nsResolver, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
34     shouldBe("nodeInResult(ROOT, result)", "false");
35     shouldBe("nodeInResult(CHILD1, result)", "false");
36     shouldBe("nodeInResult(CHILD3, result)", "true");
37
38     result = DOM.evaluate("//node()", ROOT, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
39     shouldBe("nodeInResult(ROOT, result)", "true");
40     shouldBe("nodeInResult(TEXT1, result)", "true");
41
42     result = DOM.evaluate("//text()", ROOT, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
43     shouldBe("nodeInResult(ROOT, result)", "false");
44     shouldBe("nodeInResult(TEXT1, result)", "true");
45
46     result = DOM.evaluate("//comment()", ROOT, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
47     shouldBe("nodeInResult(ROOT, result)", "false");
48     shouldBe("nodeInResult(COMMENT, result)", "true");
49
50     result = DOM.evaluate("//processing-instruction()", ROOT, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
51     shouldBe("nodeInResult(ROOT, result)", "false");
52     shouldBe("nodeInResult(PI, result)", "true");
53
54     result = DOM.evaluate("//processing-instruction('xml-stylesheet')", ROOT, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
55     shouldBe("nodeInResult(PI, result)", "true");
56     shouldBe("nodeInResult(PI2, result)", "false");
57
58     var successfullyParsed = true;
59
60 </script>
61 <script src="../../../js/resources/js-test-post.js"></script>
62 </body>
63 </html>