Revision 1210ab069bb287d634efc6cd1f7192c17238d482 authored by Masatoshi Kimura on 09 June 2016, 10:52:47 UTC, committed by James Graham on 09 June 2016, 12:53:50 UTC
Upstreamed from https://bugzilla.mozilla.org/show_bug.cgi?id=1278381
1 parent 7d18584
001.html
<!doctype html>
<meta charset="utf8">
<title>XPath in text/html: elements</title>
<link rel="help" href="http://www.w3.org/TR/DOM-Level-3-XPath/xpath.html#Interfaces">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<body>
<div id="log"><span></span></div>
<div><span></span></div>
<dØdd></dØdd>
<svg>
<path />
<path />
</svg>
<script>
function test_xpath_succeeds(path, expected, resolver) {
resolver = resolver ? resolver : null;
var res = document.evaluate(path, document, resolver, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
actual = [];
for (var i=0;;i++) {
var node = res.snapshotItem(i);
if (node === null) {
break;
}
actual.push(node);
}
assert_array_equals(actual, expected);
}
function test_xpath_throws(path, error_code, resolver) {
resolver = resolver ? resolver : null;
assert_throws(error_code, function() {document.evaluate(path, document, resolver, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null)})
}
function ns_resolver(x) {
map = {"html":"http://www.w3.org/1999/xhtml",
"svg":"http://www.w3.org/2000/svg",
"math":"http://www.w3.org/1998/Math/MathML"};
var rv = map.hasOwnProperty(x) ? map[x] : null;
return rv;
}
generate_tests(test_xpath_succeeds,[
["HTML elements no namespace prefix", "//div", document.getElementsByTagName("div")],
["HTML elements namespace prefix", "//html:div", document.getElementsByTagName("div"), ns_resolver],
["HTML elements mixed use of prefix", "//html:div/span", document.getElementsByTagName("span"), ns_resolver],
["SVG elements no namespace prefix", "//path", []],
["SVG elements namespace prefix", "//svg:path", document.getElementsByTagName("path"), ns_resolver],
["HTML elements mixed case", "//DiV", document.getElementsByTagName("div")],
["SVG elements mixed case selector", "//svg:PatH", [], ns_resolver],
["Non-ascii HTML element", "//dØdd", document.getElementsByTagName("dØdd"), ns_resolver],
["Non-ascii HTML element2", "//dødd", [], ns_resolver],
["Non-ascii HTML element3", "//DØDD", document.getElementsByTagName("dØdd"), ns_resolver]
])
generate_tests(test_xpath_throws, [
["Throw with invalid prefix", "//invalid:path", "NAMESPACE_ERR"],
])
</script>
![swh spinner](/static/img/swh-spinner.gif)
Computing file changes ...