summaryrefslogtreecommitdiffstats
path: root/LayoutTests/fast/xpath/xpath-namespaces.html
diff options
context:
space:
mode:
Diffstat (limited to 'LayoutTests/fast/xpath/xpath-namespaces.html')
-rw-r--r--LayoutTests/fast/xpath/xpath-namespaces.html46
1 files changed, 46 insertions, 0 deletions
diff --git a/LayoutTests/fast/xpath/xpath-namespaces.html b/LayoutTests/fast/xpath/xpath-namespaces.html
new file mode 100644
index 0000000..79dc6d3
--- /dev/null
+++ b/LayoutTests/fast/xpath/xpath-namespaces.html
@@ -0,0 +1,46 @@
+<html>
+<head>
+<link rel="stylesheet" href="../js/resources/js-test-style.css">
+<script src="../js/resources/js-test-pre.js"></script>
+<script src="xpath-test-pre.js"></script>
+</head>
+<body>
+<p>This tests that XPath expressions with prefixes work correctly.</p>
+<div id="console"></div>
+<script>
+ var xmlString = '<ns:foo xmlns:ns="http://www.example.org" xmlns:foo="urn:foobar"/>';
+
+ var doc = (new DOMParser()).parseFromString(xmlString, "text/xml");
+ var contextNode = doc.documentElement;
+ var nsResolver = document.createNSResolver(contextNode);
+
+ var expr = doc.createExpression("/ns:foo", nsResolver);
+ var result = expr.evaluate(contextNode, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
+ checkSnapshot("/ns:foo", result, [doc.documentElement]);
+
+ var expr = doc.createExpression("/ns:*", nsResolver);
+ var result = expr.evaluate(contextNode, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
+ checkSnapshot("/ns:*", result, [doc.documentElement]);
+
+ var expr = doc.createExpression("/foo:*", nsResolver);
+ var result = expr.evaluate(contextNode, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
+ checkSnapshot("/foo:*", result, []);
+
+ // Now try a resolver originating from the function
+ var namespaces = { xmpl: "http://www.example.org" };
+ var mapResolver = function(prefix) { return namespaces[prefix]; };
+
+ var expr = doc.createExpression("/xmpl:*", mapResolver);
+ var result = expr.evaluate(contextNode, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
+ checkSnapshot("/xmpl:*", result, [doc.documentElement]);
+
+ var evaluator = new XPathEvaluator();
+ var result = evaluator.evaluate("/xmpl:*", doc, mapResolver, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
+ checkSnapshot("/xmpl:*", result, [doc.documentElement]);
+
+ var successfullyParsed = true;
+
+</script>
+<script src="../js/resources/js-test-post.js"></script>
+</body>
+</html>