Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / fast / xpath / py-dom-xpath / nodetests.html
blob9e72bdd0c8d296bfcd4b3b455f12c924ac743623
1 <html>
2 <head>
3 <script src="../../../resources/js-test.js"></script>
4 <script src="../xpath-test-pre.js"></script>
5 </head>
6 <body>
7 <div id="console"></div>
9 <script>
10 var doc = (new DOMParser).parseFromString(
11 '<doc>' +
12 '<item id="1" color="red" />' +
13 '<chapter id="c1">' +
14 '<item id="2" color="blue" />' +
15 '</chapter>' +
16 '</doc>',
17 'application/xml');
19 var ROOT = doc.documentElement;
20 var DI1 = ROOT.firstChild;
21 var DC1 = DI1.nextSibling;
22 var DI2 = DC1.firstChild;
24 var docns = (new DOMParser).parseFromString(
25 '<doc xmlns="http://a.example.com" xmlns:b="http://b.example.com">' +
26 '<item id="1" color="red"/>' +
27 '<a:item id="2" xmlns:a="http://a.example.com" a:color="orange"/>' +
28 '<b:item id="3" color="yellow" />' +
29 '<item id="4" xmlns="http://a.example.com" color="green"/>' +
30 '<chapter id="c1" xmlns="http://b.example.com">' +
31 '<item id="5" color="blue" />' +
32 '<b:item id="6" b:color="indigo"/>' +
33 '</chapter>' +
34 '<chapter id="c2" xmlns="http://b.example.com" xmlns:b="http://a.example.com">' +
35 '<item id="7" b:color="violet"/>' +
36 '<b:item id="8" a:color="brown" xmlns:a="http://b.example.com"/>' +
37 '</chapter>' +
38 '</doc>',
39 'application/xml');
41 var XROOT = docns.firstChild;
42 var XI1 = XROOT.firstChild;
43 var XI2 = XI1.nextSibling;
44 var XI3 = XI2.nextSibling;
45 var XI4 = XI3.nextSibling;
46 var XC1 = XI4.nextSibling;
47 var XI5 = XC1.firstChild;
48 var XI6 = XI5.nextSibling;
49 var XC2 = XC1.nextSibling;
50 var XI7 = XC2.firstChild;
51 var XI8 = XI7.nextSibling;
53 function nsResolver(prefix)
55 if (prefix == "b")
56 return "http://b.example.com";
57 if (prefix == "a")
58 return "http://a.example.com";
59 return null;
62 // Some of these tests originally used a default namespace, which is not available in JavaScript XPathEvaluator.
63 test(doc, doc, '/descendant::item', [DI1, DI2]);
64 test(docns, docns, '/descendant::a:item', [XI1, XI2, XI4, XI8], nsResolver);
65 test(docns, docns, '/descendant::b:*', [XI3, XC1, XI5, XI6, XC2, XI7], nsResolver);
66 shouldThrow('docns.evaluate("//x:*", docns, nsResolver, XPathResult.ANY_TYPE, null)');
67 test(doc, doc, 'doc/child::*', [DI1, DC1]);
68 test(docns, docns, 'a:doc/child::*', [XI1, XI2, XI3, XI4, XC1, XC2], nsResolver);
69 test(doc, doc, '//attribute::color', [DI1.getAttributeNode("color"), DI2.getAttributeNode("color")]);
70 test(docns, docns, '//attribute::color', [XI1.getAttributeNode("color"), XI3.getAttributeNode("color"), XI4.getAttributeNode("color"), XI5.getAttributeNode("color")], nsResolver);
71 test(docns, docns, '//attribute::b:*', [XI6.getAttributeNodeNS("http://b.example.com", "color"), XI8.getAttributeNodeNS("http://b.example.com", "color")], nsResolver);
72 test(doc, doc, '//attribute::*', [DI1.getAttributeNode("id"), DI1.getAttributeNode("color"), DC1.getAttributeNode("id"), DI2.getAttributeNode("id"), DI2.getAttributeNode("color")]);
73 test(docns, docns, 'count(//attribute::*)', 18, nsResolver);
76 var doc = (new DOMParser).parseFromString(
77 '<doc><element />text<?one pi?><?two pi?><!--comment--></doc>',
78 'application/xml');
80 var ROOT = doc.documentElement;
81 var TEXT = ROOT.firstChild.nextSibling;
82 var COMMENT = ROOT.lastChild;
83 var PI1 = TEXT.nextSibling;
84 var PI2 = PI1.nextSibling;
86 test(doc, doc, 'doc/child::text()', [TEXT]);
87 test(doc, doc, 'doc/child::comment()', [COMMENT]);
88 test(doc, doc, 'doc/child::processing-instruction()', [PI1, PI2]);
89 test(doc, doc, 'doc/child::processing-instruction("one")', [PI1]);
91 </script>
92 </body>
93 </html>