Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / fast / xpath / py-dom-xpath / paths.html
blob874415b69a1892be669fc212f7203edd1af016a1
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 '<para id="1" />' +
13 '<div id="2" />' +
14 '<para id="3" />' +
15 '</doc>',
16 'application/xml');
17 test(doc, doc.documentElement, 'child::para', [doc.getElementsByTagName("para")[0], doc.getElementsByTagName("para")[1]]);
18 test(doc, doc.documentElement, 'child::*', [doc.documentElement.firstChild, doc.documentElement.firstChild.nextSibling, doc.documentElement.lastChild]);
20 var doc = (new DOMParser).parseFromString(
21 '<doc>This is <i>some</i> text.</doc>',
22 'application/xml');
23 test(doc, doc.documentElement, 'child::text()', [doc.documentElement.firstChild, doc.documentElement.lastChild]);
24 test(doc, doc.documentElement, 'child::node()', [doc.documentElement.firstChild, doc.documentElement.firstChild.nextSibling, doc.documentElement.lastChild]);
26 var doc = (new DOMParser).parseFromString(
27 '<doc name="foo" value="bar" />',
28 'application/xml');
29 test(doc, doc.documentElement, 'attribute::name', [doc.documentElement.getAttributeNode("name")]);
30 test(doc, doc.documentElement, 'attribute::*', [doc.documentElement.getAttributeNode("name"), doc.documentElement.getAttributeNode("value")]);
32 var doc = (new DOMParser).parseFromString(
33 '<doc>' +
34 '<para id="1">' +
35 '<div id="2" />' +
36 '<para id="3" />' +
37 '</para>' +
38 '</doc>',
39 'application/xml');
40 test(doc, doc.documentElement, 'descendant::para', [doc.getElementsByTagName("para")[0], doc.getElementsByTagName("para")[1]]);
42 var doc = (new DOMParser).parseFromString(
43 '<doc>' +
44 '<div id="1">' +
45 '<div id="2">' +
46 '<context />' +
47 '</div>' +
48 '<div id="3" />' +
49 '</div>' +
50 '<div id="4" />' +
51 '</doc>',
52 'application/xml');
53 test(doc, '//context', 'ancestor::div', [doc.getElementsByTagName("div")[0], doc.getElementsByTagName("div")[1]]);
55 var doc = (new DOMParser).parseFromString(
56 '<doc>' +
57 '<div id="1">' +
58 '<div id="2" />' +
59 '<div id="3" />' +
60 '</div>' +
61 '<div id="4" />' +
62 '</doc>',
63 'application/xml');
64 test(doc, '//div[@id="3"]', 'ancestor-or-self::div', [doc.getElementsByTagName("div")[0], doc.getElementsByTagName("div")[2]]);
66 var doc = (new DOMParser).parseFromString(
67 '<para id="0">' +
68 '<div id="1" />' +
69 '<para id="2">' +
70 '<para id="3" />' +
71 '</para>' +
72 '</para>',
73 'application/xml');
74 test(doc, doc.documentElement, 'descendant-or-self::para', [doc.getElementsByTagName("para")[0], doc.getElementsByTagName("para")[1], doc.getElementsByTagName("para")[2]]);
76 var doc = (new DOMParser).parseFromString(
77 '<doc>' +
78 '<para />' +
79 '</doc>',
80 'application/xml');
81 test(doc, doc.documentElement, 'self::para', []);
82 test(doc, 'para', 'self::para', [doc.documentElement.firstChild]);
84 var doc = (new DOMParser).parseFromString(
85 '<doc>' +
86 '<chapter><para id="1" /><para id="2" /></chapter>' +
87 '<chapter><section><para id="3" /></section></chapter>' +
88 '<para id="4" />' +
89 '</doc>',
90 'application/xml');
91 test(doc, doc.documentElement, 'child::chapter/descendant::para', [doc.getElementsByTagName("para")[0], doc.getElementsByTagName("para")[1], doc.getElementsByTagName("para")[2]]);
93 var doc = (new DOMParser).parseFromString(
94 '<doc>' +
95 '<chapter><para id="1" /><para id="2" /></chapter>' +
96 '<section><para id="3" /><sub><para id="4" /></sub></section>' +
97 '<para id="4" />' +
98 '</doc>',
99 'application/xml');
100 test(doc, doc.documentElement, 'child::*/child::para', [doc.getElementsByTagName("para")[0], doc.getElementsByTagName("para")[1], doc.getElementsByTagName("para")[2]]);
102 var doc = (new DOMParser).parseFromString(
103 '<doc><a><b><context /></b></a></doc>',
104 'application/xml');
105 test(doc, '//context', '/', [doc]);
107 var doc = (new DOMParser).parseFromString(
108 '<doc>' +
109 '<para id="1"><context /></para>' +
110 '<para id="2" />' +
111 '</doc>',
112 'application/xml');
113 test(doc, '//context', '/descendant::para', [doc.getElementsByTagName("para")[0], doc.getElementsByTagName("para")[1]]);
115 var doc = (new DOMParser).parseFromString(
116 '<doc>' +
117 '<item id="1">' +
118 '<context />' +
119 '<olist><item id="2" /></olist>' +
120 '</item>' +
121 '<olist><item id="3" /></olist>' +
122 '</doc>',
123 'application/xml');
124 test(doc, '//context', '/descendant::olist/child::item', [doc.getElementsByTagName("item")[1], doc.getElementsByTagName("item")[2]]);
126 var doc = (new DOMParser).parseFromString(
127 '<doc>' +
128 '<div id="1" />' +
129 '<para id="2" />' +
130 '<para id="3" />' +
131 '</doc>',
132 'application/xml');
133 test(doc, doc.documentElement, 'child::para[position()=1]', [doc.getElementsByTagName("para")[0]]);
135 var doc = (new DOMParser).parseFromString(
136 '<doc>' +
137 '<para id="1" />' +
138 '<para id="2" />' +
139 '<div id="3" />' +
140 '</doc>',
141 'application/xml');
142 test(doc, doc.documentElement, 'child::para[position()=last()]', [doc.getElementsByTagName("para")[1]]);
144 var doc = (new DOMParser).parseFromString(
145 '<doc>' +
146 '<para id="1" />' +
147 '<para id="2" />' +
148 '<para id="3" />' +
149 '<div id="4" />' +
150 '</doc>',
151 'application/xml');
152 test(doc, doc.documentElement, 'child::para[position()=last()-1]', [doc.getElementsByTagName("para")[1]]);
154 var doc = (new DOMParser).parseFromString(
155 '<doc>' +
156 '<div id="1" /><para id="2" />' +
157 '<div id="3" /><para id="4" />' +
158 '<div id="5" /><para id="6" />' +
159 '</doc>',
160 'application/xml');
161 test(doc, doc.documentElement, 'child::para[position()>1]', [doc.getElementsByTagName("para")[1], doc.getElementsByTagName("para")[2]]);
163 var doc = (new DOMParser).parseFromString(
164 '<doc>' +
165 '<chapter id="1" /><chapter id="2" />' +
166 '<context />' +
167 '<chapter id="3" /><chapter id="4" />' +
168 '</doc>',
169 'application/xml');
170 test(doc, '//context', 'following-sibling::chapter[position()=1]', [doc.getElementsByTagName("chapter")[2]]);
171 test(doc, '//context', 'preceding-sibling::chapter[position()=1]', [doc.getElementsByTagName("chapter")[1]]);
173 var xml = "<doc>"
174 for (i = 1; i <= 10; ++i) {
175 for (j = 1; j <= 10; ++j)
176 xml += '<figure id="' + ((i*10)+j) + '%d">';
177 for (j = 1; j <= 10; ++j)
178 xml += '</figure>';
180 xml += "</doc>"
181 var doc = (new DOMParser).parseFromString(xml, 'application/xml');
182 test(doc, doc.documentElement, '/descendant::figure[position()=42]', [doc.getElementsByTagName("figure")[41]]);
184 var doc = (new DOMParser).parseFromString(
185 '<doc>' +
186 '<chapter id="1" /><chapter id="2" /><chapter id="3" />' +
187 '<chapter id="4">' +
188 '<section id="4.1" /><section id="4.2" /><section id="4.3" />' +
189 '</chapter>' +
190 '<chapter id="5">' +
191 '<section id="5.1" /><section id="5.2" /><section id="5.3" />' +
192 '</chapter>' +
193 '</doc>',
194 'application/xml');
195 test(doc, doc.documentElement, '/child::doc/child::chapter[position()=5]/child::section[position()=2]', [doc.getElementsByTagName("section")[4]]);
197 var doc = (new DOMParser).parseFromString(
198 '<doc>' +
199 '<para id="1" type="info" />' +
200 '<para id="2" type="warning" />' +
201 '<para id="3" type="warning" />' +
202 '<para id="4" type="warning" />' +
203 '<para id="5" type="error" />' +
204 '<para id="6" type="warning" />' +
205 '<para id="7" type="warning" />' +
206 '</doc>',
207 'application/xml');
208 test(doc, doc.documentElement, 'child::para[attribute::type="warning"][position()=5]', [doc.getElementsByTagName("para")[6]]);
209 test(doc, doc.documentElement, 'child::para[position()=5][attribute::type="warning"]', []);
211 var doc = (new DOMParser).parseFromString(
212 '<doc>' +
213 '<chapter id="1" />' +
214 '<chapter id="2"><title>Introduction</title></chapter>' +
215 '<chapter id="3"><title>Body</title></chapter>' +
216 '<chapter id="4">' +
217 '<title>Another</title>' +
218 '<title>Introduction</title>' +
219 '</chapter>' +
220 '</doc>',
221 'application/xml');
222 test(doc, doc.documentElement, "child::chapter[child::title='Introduction']", [doc.getElementsByTagName("chapter")[1], doc.getElementsByTagName("chapter")[3]]);
224 var doc = (new DOMParser).parseFromString(
225 '<doc>' +
226 '<chapter id="1" />' +
227 '<chapter id="2"><title /></chapter>' +
228 '<chapter id="3"><title /><title /></chapter>' +
229 '</doc>',
230 'application/xml');
231 test(doc, doc.documentElement, "child::chapter[child::title]", [doc.getElementsByTagName("chapter")[1], doc.getElementsByTagName("chapter")[2]]);
233 var doc = (new DOMParser).parseFromString(
234 '<doc>' +
235 '<chapter id="1" />' +
236 '<appendix id="2" />' +
237 '<para id="3" />' +
238 '<chapter id="4" />' +
239 '</doc>',
240 'application/xml');
241 test(doc, doc.documentElement, "child::*[self::chapter or self::appendix]", [doc.getElementsByTagName("chapter")[0], doc.getElementsByTagName("appendix")[0], doc.getElementsByTagName("chapter")[1]]);
243 var doc = (new DOMParser).parseFromString(
244 '<doc>' +
245 '<chapter id="1" />' +
246 '<appendix id="2" />' +
247 '<para id="3" />' +
248 '<chapter id="4" />' +
249 '<para id="5" />' +
250 '</doc>',
251 'application/xml');
252 test(doc, doc.documentElement, "child::*[self::chapter or self::appendix][position()=last()]", [doc.getElementsByTagName("chapter")[1]]);
254 </script>
255 </body>
256 </html>