Skip to content

Commit

Permalink
Rename domxpath/{001,002}.html to something meaningful and avoid gene…
Browse files Browse the repository at this point in the history
…rate_tests (web-platform-tests#42716)
  • Loading branch information
gsnedders authored Oct 25, 2023
1 parent b2a38f9 commit 0af481e
Show file tree
Hide file tree
Showing 5 changed files with 189 additions and 122 deletions.
60 changes: 0 additions & 60 deletions domxpath/001.html

This file was deleted.

60 changes: 0 additions & 60 deletions domxpath/002.html

This file was deleted.

102 changes: 102 additions & 0 deletions domxpath/text-html-attributes.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
<!doctype html>
<meta charset="utf8">
<title>XPath in text/html: attributes</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" nonÄsciiAttribute><span></span></div>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<path id="a" refx />
<path id="b" nonÄscii xlink:href />
</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_dom(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",
"xlink":"http://www.w3.org/1999/xlink"};
var rv = map.hasOwnProperty(x) ? map[x] : null;
return rv;
}

test(function() {
test_xpath_succeeds("//div[@id='log']", [document.getElementById("log")]);
}, "Select html element based on attribute");

test(function() {
test_xpath_succeeds("//div[@Id='log']", [document.getElementById("log")]);
}, "Select html element based on attribute mixed case");

test(function() {
test_xpath_succeeds("//*[@id]", [document.getElementById("log")].concat(Array.prototype.slice.call(document.getElementsByTagName("path"))));
}, "Select both HTML and SVG elements based on attribute");

test(function() {
test_xpath_succeeds("//*[@nonÄsciiattribute]", [document.getElementById("log")]);
}, "Select HTML element with non-ascii attribute 1");

test(function() {
test_xpath_succeeds("//*[@nonäsciiattribute]", []);
}, "Select HTML element with non-ascii attribute 2");

test(function() {
test_xpath_succeeds("//*[@nonÄsciiAttribute]", [document.getElementById("log")]);
}, "Select HTML element with non-ascii attribute 3");

test(function() {
test_xpath_succeeds("//svg:path[@Id]", [], ns_resolver);
}, "Select SVG element based on mixed case attribute");

test(function() {
test_xpath_succeeds("//*[@Id]", [document.getElementById("log")]);
}, "Select both HTML and SVG elements based on mixed case attribute");

test(function() {
test_xpath_succeeds("//*[@refX]", [document.getElementById("a")]);
}, "Select SVG elements with refX attribute");

test(function() {
test_xpath_succeeds("//*[@Refx]", []);
}, "Select SVG elements with refX attribute incorrect case");

test(function() {
test_xpath_succeeds("//*[@refx]", []);
}, "Select SVG elements with refX attribute lowercase");

test(function() {
test_xpath_succeeds("//*[@nonÄscii]", [document.getElementById("b")]);
}, "Select SVG element with non-ascii attribute 1");

test(function() {
test_xpath_succeeds("//*[@nonäscii]", []);
}, "Select SVG element with non-ascii attribute 2");

test(function() {
test_xpath_succeeds("//*[@xmlns]", []);
}, "xmlns attribute");

test(function() {
test_xpath_succeeds("//*[@xlink:href]", [document.getElementById("b")], ns_resolver);
}, "svg element with XLink attribute");
</script>
87 changes: 87 additions & 0 deletions domxpath/text-html-elements.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<!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_dom(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;
}

test(function() {
test_xpath_succeeds("//div", document.getElementsByTagName("div"));
}, "HTML elements no namespace prefix");

test(function() {
test_xpath_succeeds("//html:div", document.getElementsByTagName("div"), ns_resolver);
}, "HTML elements namespace prefix");

test(function() {
test_xpath_succeeds("//html:div/span", document.getElementsByTagName("span"), ns_resolver);
}, "HTML elements mixed use of prefix");

test(function() {
test_xpath_succeeds("//path", []);
}, "SVG elements no namespace prefix");

test(function() {
test_xpath_succeeds("//svg:path", document.getElementsByTagName("path"), ns_resolver);
}, "SVG elements namespace prefix");

test(function() {
test_xpath_succeeds("//DiV", document.getElementsByTagName("div"));
}, "HTML elements mixed case");

test(function() {
test_xpath_succeeds("//svg:PatH", [], ns_resolver);
}, "SVG elements mixed case selector");

test(function() {
test_xpath_succeeds("//dØdd", document.getElementsByTagName("dØdd"), ns_resolver);
}, "Non-ascii HTML element");

test(function() {
test_xpath_succeeds("//dødd", [], ns_resolver);
}, "Non-ascii HTML element2");

test(function() {
test_xpath_succeeds("//DØDD", document.getElementsByTagName("dØdd"), ns_resolver);
}, "Non-ascii HTML element3");

test(function() {
test_xpath_throws("//invalid:path", "NAMESPACE_ERR");
}, "Throw with invalid prefix");
</script>
2 changes: 0 additions & 2 deletions lint.ignore
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,6 @@ GENERATE_TESTS: dom/ranges/Range-selectNode.html
GENERATE_TESTS: dom/ranges/Range-set.html
GENERATE_TESTS: dom/traversal/TreeWalker.html
GENERATE_TESTS: domparsing/createContextualFragment.html
GENERATE_TESTS: domxpath/001.html
GENERATE_TESTS: domxpath/002.html
GENERATE_TESTS: mediacapture-image/MediaStreamTrack-applyConstraints-reject.https.html
GENERATE_TESTS: mediacapture-image/MediaStreamTrack-getCapabilities.https.html
GENERATE_TESTS: mediacapture-image/MediaStreamTrack-getConstraints.https.html
Expand Down

0 comments on commit 0af481e

Please sign in to comment.