File: text-html-elements.html

package info (click to toggle)
firefox 145.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,653,344 kB
  • sloc: cpp: 7,594,932; javascript: 6,459,612; ansic: 3,752,905; python: 1,403,433; xml: 629,811; asm: 438,677; java: 186,421; sh: 67,287; makefile: 19,169; objc: 13,086; perl: 12,982; yacc: 4,583; cs: 3,846; pascal: 3,448; lex: 1,720; ruby: 1,003; exp: 762; php: 436; lisp: 258; awk: 247; sql: 66; sed: 54; csh: 10
file content (87 lines) | stat: -rw-r--r-- 2,660 bytes parent folder | download | duplicates (13)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
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>