Bug 1883912: Enable Intl.ListFormat test for "unit" style. r=spidermonkey-reviewers...
[gecko.git] / editor / libeditor / tests / test_nsIHTMLEditor_getElementOrParentByTagName.html
blobc78ec6763d2436944a44abcb7abf0f863c5e05fe
1 <!DOCTYPE>
2 <html>
3 <head>
4 <title>Test for nsIHTMLEditor.getElementOrParentByTagName()</title>
5 <script src="/tests/SimpleTest/SimpleTest.js"></script>
6 <link rel="stylesheet" href="/tests/SimpleTest/test.css">
7 </head>
8 <body>
9 <section>
10 <div id="display">
11 </div>
12 <div id="content" contenteditable></div>
13 </section>
14 <pre id="test">
15 </pre>
17 <script class="testbody" type="application/javascript">
19 SimpleTest.waitForExplicitFinish();
20 SimpleTest.waitForFocus(async function() {
21 let section = document.querySelector("section");
22 let editor = document.querySelector("[contenteditable]");
23 let selection = window.getSelection();
24 let element;
26 // Make sure that each test can run without previous tests for making each test
27 // debuggable with commenting out the unrelated tests.
29 try {
30 editor.focus();
31 element = SpecialPowers.unwrap(getHTMLEditor().getElementOrParentByTagName("", null));
32 ok(false, "nsIHTMLEditor.getElementOrParentByTagName(\"\", null) should throw an exception");
33 } catch {
34 ok(true, "nsIHTMLEditor.getElementOrParentByTagName(\"\", null) should throw an exception");
37 try {
38 editor.focus();
39 element = SpecialPowers.unwrap(getHTMLEditor().getElementOrParentByTagName(null, null));
40 ok(false, "nsIHTMLEditor.getElementOrParentByTagName(null, null) should throw an exception");
41 } catch {
42 ok(true, "nsIHTMLEditor.getElementOrParentByTagName(null, null) should throw an exception");
45 try {
46 editor.focus();
47 element = SpecialPowers.unwrap(getHTMLEditor().getElementOrParentByTagName(undefined, null));
48 ok(false, "nsIHTMLEditor.getElementOrParentByTagName(undefined, null) should throw an exception");
49 } catch {
50 ok(true, "nsIHTMLEditor.getElementOrParentByTagName(undefined, null) should throw an exception");
53 editor.focus();
54 element = SpecialPowers.unwrap(getHTMLEditor().getElementOrParentByTagName("undefinedtagname", null));
55 is(element, null,
56 "nsIHTMLEditor.getElementOrParentByTagName(\"undefinedtagname\", null) should return null");
58 editor.blur();
59 selection.collapse(document.getElementById("display"), 0);
60 element = SpecialPowers.unwrap(getHTMLEditor().getElementOrParentByTagName("section", null));
61 is(element, section,
62 "nsIHTMLEditor.getElementOrParentByTagName(\"section\", null) should return the <section> when selection is in the it (HTML editor does not have focus)");
64 editor.focus();
65 element = SpecialPowers.unwrap(getHTMLEditor().getElementOrParentByTagName("section", null));
66 is(element, section,
67 "nsIHTMLEditor.getElementOrParentByTagName(\"section\", null) should return the <section> when selection is in the it (HTML editor has focus)");
69 editor.focus();
70 selection.removeAllRanges();
71 element = SpecialPowers.unwrap(getHTMLEditor().getElementOrParentByTagName("section", null));
72 is(element, null,
73 "nsIHTMLEditor.getElementOrParentByTagName(\"section\", null) should return null when there is no selection");
75 editor.blur();
76 selection.collapse(document.getElementById("display"), 0);
77 element = SpecialPowers.unwrap(getHTMLEditor().getElementOrParentByTagName("body", null));
78 is(element, null,
79 "nsIHTMLEditor.getElementOrParentByTagName(\"body\", null) should return null when it reaches the <body>");
81 editor.blur();
82 selection.collapse(document.getElementById("display"), 0);
83 element = SpecialPowers.unwrap(getHTMLEditor().getElementOrParentByTagName("div", editor));
84 is(element, editor,
85 "nsIHTMLEditor.getElementOrParentByTagName(\"div\", editor) should return editor even when selection is outside of it");
87 editor.innerHTML = "<p>first</p><p>second</p>";
88 editor.focus();
89 selection.setBaseAndExtent(editor.firstChild.firstChild, 0, editor.firstChild.nextSibling.firstChild, 3);
90 element = SpecialPowers.unwrap(getHTMLEditor().getElementOrParentByTagName("p", null));
91 is(element, editor.firstChild,
92 "nsIHTMLEditor.getElementOrParentByTagName(\"p\", null) should return first <p> element when selection anchor is in it");
94 editor.innerHTML = "<table><tr><td>cell</td></tr></table>";
95 editor.focus();
96 selection.collapse(editor.querySelector("td").firstChild, 2);
97 element = SpecialPowers.unwrap(getHTMLEditor().getElementOrParentByTagName("td", null));
98 is(element, editor.querySelector("td"),
99 "nsIHTMLEditor.getElementOrParentByTagName(\"td\", null) should return the <td> when selection is collapsed in it");
101 editor.innerHTML = "<table><tr><td>cell</td></tr></table>";
102 editor.focus();
103 selection.collapse(editor.querySelector("td").firstChild, 2);
104 element = SpecialPowers.unwrap(getHTMLEditor().getElementOrParentByTagName("th", null));
105 is(element, null,
106 "nsIHTMLEditor.getElementOrParentByTagName(\"th\", null) should return null when selection is collapsed in <td>");
108 editor.innerHTML = "<table><tr><td>cell</td></tr></table>";
109 editor.focus();
110 selection.setBaseAndExtent(editor.querySelector("tr"), 0, editor.querySelector("tr"), 1);
111 element = SpecialPowers.unwrap(getHTMLEditor().getElementOrParentByTagName("td", null));
112 is(element, editor.querySelector("td"),
113 "nsIHTMLEditor.getElementOrParentByTagName(\"td\", null) should return the <td> when it's selected");
115 editor.innerHTML = "<table><tr><th>cell</th></tr></table>";
116 editor.focus();
117 selection.collapse(editor.querySelector("th").firstChild, 2);
118 element = SpecialPowers.unwrap(getHTMLEditor().getElementOrParentByTagName("td", null));
119 is(element, editor.querySelector("th"),
120 "nsIHTMLEditor.getElementOrParentByTagName(\"td\", null) should return the <th> when selection is collapsed in it");
122 editor.innerHTML = "<table><tr><th>cell</th></tr></table>";
123 editor.focus();
124 selection.collapse(editor.querySelector("th").firstChild, 2);
125 element = SpecialPowers.unwrap(getHTMLEditor().getElementOrParentByTagName("th", null));
126 is(element, editor.querySelector("th"),
127 "nsIHTMLEditor.getElementOrParentByTagName(\"th\", null) should return the <th> when selection is collapsed in it");
129 editor.innerHTML = "<table><tr><th>cell</th></tr></table>";
130 editor.focus();
131 selection.setBaseAndExtent(editor.querySelector("tr"), 0, editor.querySelector("tr"), 1);
132 element = SpecialPowers.unwrap(getHTMLEditor().getElementOrParentByTagName("td", null));
133 is(element, editor.querySelector("th"),
134 "nsIHTMLEditor.getElementOrParentByTagName(\"td\", null) should return the <th> when it's selected");
136 editor.innerHTML = "<table><tr><th>cell</th></tr></table>";
137 editor.focus();
138 selection.setBaseAndExtent(editor.querySelector("tr"), 0, editor.querySelector("tr"), 1);
139 element = SpecialPowers.unwrap(getHTMLEditor().getElementOrParentByTagName("th", null));
140 is(element, editor.querySelector("th"),
141 "nsIHTMLEditor.getElementOrParentByTagName(\"th\", null) should return the <th> when it's selected");
143 editor.innerHTML = "<ul><li>listitem</li></ul>";
144 editor.focus();
145 selection.collapse(editor.querySelector("li").firstChild, 4);
146 element = SpecialPowers.unwrap(getHTMLEditor().getElementOrParentByTagName("ul", null));
147 is(element, editor.querySelector("ul"),
148 "nsIHTMLEditor.getElementOrParentByTagName(\"ul\", null) should return the <ul> when selection is collapsed in its <li>");
150 editor.innerHTML = "<ul><li>listitem</li></ul>";
151 editor.focus();
152 selection.collapse(editor.querySelector("li").firstChild, 4);
153 element = SpecialPowers.unwrap(getHTMLEditor().getElementOrParentByTagName("list", null));
154 is(element, editor.querySelector("ul"),
155 "nsIHTMLEditor.getElementOrParentByTagName(\"list\", null) should return the <ul> when selection is collapsed in its <li>");
157 editor.innerHTML = "<ul><li>listitem</li></ul>";
158 editor.focus();
159 selection.collapse(editor.querySelector("li").firstChild, 4);
160 element = SpecialPowers.unwrap(getHTMLEditor().getElementOrParentByTagName("ol", null));
161 is(element, null,
162 "nsIHTMLEditor.getElementOrParentByTagName(\"ol\", null) should return null when selection is collapsed in <ul>");
164 editor.innerHTML = "<ol><li>listitem</li></ol>";
165 editor.focus();
166 selection.collapse(editor.querySelector("li").firstChild, 4);
167 element = SpecialPowers.unwrap(getHTMLEditor().getElementOrParentByTagName("ol", null));
168 is(element, editor.querySelector("ol"),
169 "nsIHTMLEditor.getElementOrParentByTagName(\"ol\", null) should return the <ol> when selection is collapsed in its <li>");
171 editor.innerHTML = "<ol><li>listitem</li></ol>";
172 editor.focus();
173 selection.collapse(editor.querySelector("li").firstChild, 4);
174 element = SpecialPowers.unwrap(getHTMLEditor().getElementOrParentByTagName("list", null));
175 is(element, editor.querySelector("ol"),
176 "nsIHTMLEditor.getElementOrParentByTagName(\"list\", null) should return the <ol> when selection is collapsed in its <li>");
178 editor.innerHTML = "<ol><li>listitem</li></ol>";
179 editor.focus();
180 selection.collapse(editor.querySelector("li").firstChild, 4);
181 element = SpecialPowers.unwrap(getHTMLEditor().getElementOrParentByTagName("ul", null));
182 is(element, null,
183 "nsIHTMLEditor.getElementOrParentByTagName(\"ol\", null) should return null when selection is collapsed in <ol>");
185 editor.innerHTML = "<dl><dt>listitem</dt></dl>";
186 editor.focus();
187 selection.collapse(editor.querySelector("dt").firstChild, 4);
188 element = SpecialPowers.unwrap(getHTMLEditor().getElementOrParentByTagName("dl", null));
189 is(element, editor.querySelector("dl"),
190 "nsIHTMLEditor.getElementOrParentByTagName(\"dl\", null) should return the <dl> when selection is collapsed in its <dt>");
192 editor.innerHTML = "<dl><dt>listitem</dt></dl>";
193 editor.focus();
194 selection.collapse(editor.querySelector("dt").firstChild, 4);
195 element = SpecialPowers.unwrap(getHTMLEditor().getElementOrParentByTagName("list", null));
196 is(element, editor.querySelector("dl"),
197 "nsIHTMLEditor.getElementOrParentByTagName(\"list\", null) should return the <dl> when selection is collapsed in its <dt>");
199 editor.innerHTML = "<dl><dd>listitem</dd></dl>";
200 editor.focus();
201 selection.collapse(editor.querySelector("dd").firstChild, 4);
202 element = SpecialPowers.unwrap(getHTMLEditor().getElementOrParentByTagName("dl", null));
203 is(element, editor.querySelector("dl"),
204 "nsIHTMLEditor.getElementOrParentByTagName(\"dl\", null) should return the <dl> when selection is collapsed in its <dd>");
206 editor.innerHTML = "<dl><dd>listitem</dd></dl>";
207 editor.focus();
208 selection.collapse(editor.querySelector("dd").firstChild, 4);
209 element = SpecialPowers.unwrap(getHTMLEditor().getElementOrParentByTagName("list", null));
210 is(element, editor.querySelector("dl"),
211 "nsIHTMLEditor.getElementOrParentByTagName(\"list\", null) should return the <dl> when selection is collapsed in its <dd>");
213 editor.innerHTML = "<ul><ol><li>listitem</li></ol></ul>";
214 editor.focus();
215 selection.collapse(editor.querySelector("li").firstChild, 4);
216 element = SpecialPowers.unwrap(getHTMLEditor().getElementOrParentByTagName("list", null));
217 is(element, editor.querySelector("ol"),
218 "nsIHTMLEditor.getElementOrParentByTagName(\"list\", null) should return the <ol> (sublist) when selection is collapsed in its <li>");
220 editor.innerHTML = "<ul><ol><li>listitem</li></ol></ul>";
221 editor.focus();
222 selection.collapse(editor.querySelector("li").firstChild, 4);
223 element = SpecialPowers.unwrap(getHTMLEditor().getElementOrParentByTagName("ol", null));
224 is(element, editor.querySelector("ol"),
225 "nsIHTMLEditor.getElementOrParentByTagName(\"ol\", null) should return the <ol> (sublist) when selection is collapsed in its <li>");
227 editor.innerHTML = "<ul><ol><li>listitem</li></ol></ul>";
228 editor.focus();
229 selection.collapse(editor.querySelector("li").firstChild, 4);
230 element = SpecialPowers.unwrap(getHTMLEditor().getElementOrParentByTagName("ul", null));
231 is(element, editor.querySelector("ul"),
232 "nsIHTMLEditor.getElementOrParentByTagName(\"ul\", null) should return the <ul> when selection is collapsed in its sublist's <li>");
234 editor.innerHTML = "<ol><ul><li>listitem</li></ul></ol>";
235 editor.focus();
236 selection.collapse(editor.querySelector("li").firstChild, 4);
237 element = SpecialPowers.unwrap(getHTMLEditor().getElementOrParentByTagName("list", null));
238 is(element, editor.querySelector("ul"),
239 "nsIHTMLEditor.getElementOrParentByTagName(\"list\", null) should return the <ul> (sublist) when selection is collapsed in its <li>");
241 editor.innerHTML = "<ol><ul><li>listitem</li></ul></ol>";
242 editor.focus();
243 selection.collapse(editor.querySelector("li").firstChild, 4);
244 element = SpecialPowers.unwrap(getHTMLEditor().getElementOrParentByTagName("ul", null));
245 is(element, editor.querySelector("ul"),
246 "nsIHTMLEditor.getElementOrParentByTagName(\"ul\", null) should return the <ul> (sublist) when selection is collapsed in its <li>");
248 editor.innerHTML = "<ol><ul><li>listitem</li></ul></ol>";
249 editor.focus();
250 selection.collapse(editor.querySelector("li").firstChild, 4);
251 element = SpecialPowers.unwrap(getHTMLEditor().getElementOrParentByTagName("ol", null));
252 is(element, editor.querySelector("ol"),
253 "nsIHTMLEditor.getElementOrParentByTagName(\"ol\", null) should return the <ol> when selection is collapsed in its sublist's <li>");
255 editor.innerHTML = "<p><a href=\"about:config\">anchor</a></p>";
256 editor.focus();
257 selection.collapse(editor.querySelector("a").firstChild, 3);
258 element = SpecialPowers.unwrap(getHTMLEditor().getElementOrParentByTagName("a", null));
259 is(element, editor.querySelector("a"),
260 "nsIHTMLEditor.getElementOrParentByTagName(\"a\", null) should return the <a href=\"about:config\"> when selection is collapsed in it");
262 editor.innerHTML = "<p><a href=\"about:config\">anchor</a></p>";
263 editor.focus();
264 selection.setBaseAndExtent(editor.firstChild, 0, editor.firstChild, 1);
265 element = SpecialPowers.unwrap(getHTMLEditor().getElementOrParentByTagName("a", null));
266 is(element, editor.querySelector("a"),
267 "nsIHTMLEditor.getElementOrParentByTagName(\"a\", null) should return the <a href=\"about:config\"> when it's selected");
269 editor.innerHTML = "<p><a href=\"about:config\">anchor</a></p>";
270 editor.focus();
271 selection.collapse(editor.querySelector("a").firstChild, 3);
272 element = SpecialPowers.unwrap(getHTMLEditor().getElementOrParentByTagName("href", null));
273 is(element, editor.querySelector("a"),
274 "nsIHTMLEditor.getElementOrParentByTagName(\"href\", null) should return the <a href=\"about:config\"> when selection is collapsed in it");
276 editor.innerHTML = "<p><a href=\"about:config\">anchor</a></p>";
277 editor.focus();
278 selection.setBaseAndExtent(editor.firstChild, 0, editor.firstChild, 1);
279 element = SpecialPowers.unwrap(getHTMLEditor().getElementOrParentByTagName("href", null));
280 is(element, editor.querySelector("a"),
281 "nsIHTMLEditor.getElementOrParentByTagName(\"href\", null) should return the <a href=\"about:config\"> when it's selected");
283 editor.innerHTML = "<p><a href=\"about:config\">anchor</a></p>";
284 editor.focus();
285 selection.collapse(editor.querySelector("a").firstChild, 3);
286 element = SpecialPowers.unwrap(getHTMLEditor().getElementOrParentByTagName("anchor", null));
287 is(element, null,
288 "nsIHTMLEditor.getElementOrParentByTagName(\"anchor\", null) should return null when selection is collapsed in the <a href=\"about:config\">");
290 editor.innerHTML = "<p><a href=\"about:config\">anchor</a></p>";
291 editor.focus();
292 selection.setBaseAndExtent(editor.firstChild, 0, editor.firstChild, 1);
293 element = SpecialPowers.unwrap(getHTMLEditor().getElementOrParentByTagName("anchor", null));
294 is(element, null,
295 "nsIHTMLEditor.getElementOrParentByTagName(\"anchor\", null) should return null when the <a href=\"about:config\"> is selected");
297 editor.innerHTML = "<p><a href=\"\">anchor</a></p>";
298 editor.focus();
299 selection.collapse(editor.querySelector("a").firstChild, 3);
300 element = SpecialPowers.unwrap(getHTMLEditor().getElementOrParentByTagName("a", null));
301 is(element, editor.querySelector("a"),
302 "nsIHTMLEditor.getElementOrParentByTagName(\"a\", null) should return the <a href=\"\"> when selection is collapsed in it");
304 editor.innerHTML = "<p><a href=\"\">anchor</a></p>";
305 editor.focus();
306 selection.setBaseAndExtent(editor.firstChild, 0, editor.firstChild, 1);
307 element = SpecialPowers.unwrap(getHTMLEditor().getElementOrParentByTagName("a", null));
308 is(element, editor.querySelector("a"),
309 "nsIHTMLEditor.getElementOrParentByTagName(\"a\", null) should return the <a href=\"\"> when it's selected");
311 editor.innerHTML = "<p><a href=\"\">anchor</a></p>";
312 editor.focus();
313 selection.collapse(editor.querySelector("a").firstChild, 3);
314 element = SpecialPowers.unwrap(getHTMLEditor().getElementOrParentByTagName("href", null));
315 is(element, editor.querySelector("a"),
316 "nsIHTMLEditor.getElementOrParentByTagName(\"href\", null) should return the <a href=\"\"> when selection is collapsed in it");
318 editor.innerHTML = "<p><a href=\"\">anchor</a></p>";
319 editor.focus();
320 selection.setBaseAndExtent(editor.firstChild, 0, editor.firstChild, 1);
321 element = SpecialPowers.unwrap(getHTMLEditor().getElementOrParentByTagName("href", null));
322 is(element, editor.querySelector("a"),
323 "nsIHTMLEditor.getElementOrParentByTagName(\"href\", null) should return the <a href=\"\"> when it's selected");
325 editor.innerHTML = "<p><a name=\"foo\">anchor</a></p>";
326 editor.focus();
327 selection.collapse(editor.querySelector("a").firstChild, 3);
328 element = SpecialPowers.unwrap(getHTMLEditor().getElementOrParentByTagName("a", null));
329 is(element, editor.querySelector("a"),
330 "nsIHTMLEditor.getElementOrParentByTagName(\"a\", null) should return the <a name=\"foo\"> when selection is collapsed in it");
332 editor.innerHTML = "<p><a name=\"foo\">anchor</a></p>";
333 editor.focus();
334 selection.setBaseAndExtent(editor.firstChild, 0, editor.firstChild, 1);
335 element = SpecialPowers.unwrap(getHTMLEditor().getElementOrParentByTagName("a", null));
336 is(element, editor.querySelector("a"),
337 "nsIHTMLEditor.getElementOrParentByTagName(\"a\", null) should return the <a name=\"foo\"> when it's selected");
339 editor.innerHTML = "<p><a name=\"foo\">anchor</a></p>";
340 editor.focus();
341 selection.collapse(editor.querySelector("a").firstChild, 3);
342 element = SpecialPowers.unwrap(getHTMLEditor().getElementOrParentByTagName("href", null));
343 is(element, null,
344 "nsIHTMLEditor.getElementOrParentByTagName(\"href\", null) should return null when selection is collapsed in the <a name=\"foo\">");
346 editor.innerHTML = "<p><a name=\"foo\">anchor</a></p>";
347 editor.focus();
348 selection.setBaseAndExtent(editor.firstChild, 0, editor.firstChild, 1);
349 element = SpecialPowers.unwrap(getHTMLEditor().getElementOrParentByTagName("href", null));
350 is(element, null,
351 "nsIHTMLEditor.getElementOrParentByTagName(\"href\", null) should return null when the <a name=\"foo\"> is selected");
353 editor.innerHTML = "<p><a name=\"foo\">anchor</a></p>";
354 editor.focus();
355 selection.collapse(editor.querySelector("a").firstChild, 3);
356 element = SpecialPowers.unwrap(getHTMLEditor().getElementOrParentByTagName("anchor", null));
357 is(element, editor.querySelector("a"),
358 "nsIHTMLEditor.getElementOrParentByTagName(\"anchor\", null) should return the <a name=\"foo\"> when selection is collapsed in it");
360 editor.innerHTML = "<p><a name=\"foo\">anchor</a></p>";
361 editor.focus();
362 selection.setBaseAndExtent(editor.firstChild, 0, editor.firstChild, 1);
363 element = SpecialPowers.unwrap(getHTMLEditor().getElementOrParentByTagName("anchor", null));
364 is(element, editor.querySelector("a"),
365 "nsIHTMLEditor.getElementOrParentByTagName(\"anchor\", null) should return the <a name=\"foo\"> when it's selected");
367 editor.innerHTML = "<p><a name=\"\">anchor</a></p>";
368 editor.focus();
369 selection.collapse(editor.querySelector("a").firstChild, 3);
370 element = SpecialPowers.unwrap(getHTMLEditor().getElementOrParentByTagName("a", null));
371 is(element, editor.querySelector("a"),
372 "nsIHTMLEditor.getElementOrParentByTagName(\"a\", null) should return the <a name=\"\"> when selection is collapsed in it");
374 editor.innerHTML = "<p><a name=\"\">anchor</a></p>";
375 editor.focus();
376 selection.setBaseAndExtent(editor.firstChild, 0, editor.firstChild, 1);
377 element = SpecialPowers.unwrap(getHTMLEditor().getElementOrParentByTagName("a", null));
378 is(element, editor.querySelector("a"),
379 "nsIHTMLEditor.getElementOrParentByTagName(\"a\", null) should return the <a name=\"\"> when it's selected");
381 editor.innerHTML = "<p><a name=\"\">anchor</a></p>";
382 editor.focus();
383 selection.collapse(editor.querySelector("a").firstChild, 3);
384 element = SpecialPowers.unwrap(getHTMLEditor().getElementOrParentByTagName("anchor", null));
385 is(element, null,
386 "nsIHTMLEditor.getElementOrParentByTagName(\"anchor\", null) should return null when selection is collapsed in the <a name=\"\">");
388 editor.innerHTML = "<p><a name=\"\">anchor</a></p>";
389 editor.focus();
390 selection.setBaseAndExtent(editor.firstChild, 0, editor.firstChild, 1);
391 element = SpecialPowers.unwrap(getHTMLEditor().getElementOrParentByTagName("anchor", null));
392 is(element, null,
393 "nsIHTMLEditor.getElementOrParentByTagName(\"anchor\", null) should return null when the <a name=\"\"> is selected");
395 editor.innerHTML = "<p><a>anchor</a></p>";
396 editor.focus();
397 selection.collapse(editor.querySelector("a").firstChild, 3);
398 element = SpecialPowers.unwrap(getHTMLEditor().getElementOrParentByTagName("a", null));
399 is(element, editor.querySelector("a"),
400 "nsIHTMLEditor.getElementOrParentByTagName(\"a\", null) should return the <a> when selection is collapsed in it");
402 editor.innerHTML = "<p><a>anchor</a></p>";
403 editor.focus();
404 selection.collapse(editor.querySelector("a").firstChild, 3);
405 element = SpecialPowers.unwrap(getHTMLEditor().getElementOrParentByTagName("href", null));
406 is(element, null,
407 "nsIHTMLEditor.getElementOrParentByTagName(\"href\", null) should return null when selection is collapsed in the <a>");
409 editor.innerHTML = "<p><a>anchor</a></p>";
410 editor.focus();
411 selection.collapse(editor.querySelector("a").firstChild, 3);
412 element = SpecialPowers.unwrap(getHTMLEditor().getElementOrParentByTagName("anchor", null));
413 is(element, null,
414 "nsIHTMLEditor.getElementOrParentByTagName(\"anchor\", null) should return null when selection is collapsed in the <a>");
416 editor.innerHTML = "<p><a>anchor</a></p>";
417 editor.focus();
418 selection.setBaseAndExtent(editor.firstChild, 0, editor.firstChild, 1);
419 element = SpecialPowers.unwrap(getHTMLEditor().getElementOrParentByTagName("a", null));
420 is(element, editor.querySelector("a"),
421 "nsIHTMLEditor.getElementOrParentByTagName(\"a\", null) should return the <a> when it's selected");
423 editor.innerHTML = "<p><a>anchor</a></p>";
424 editor.focus();
425 selection.setBaseAndExtent(editor.firstChild, 0, editor.firstChild, 1);
426 element = SpecialPowers.unwrap(getHTMLEditor().getElementOrParentByTagName("href", null));
427 is(element, null,
428 "nsIHTMLEditor.getElementOrParentByTagName(\"href\", null) should return null when the <a> is selected");
430 editor.innerHTML = "<p><a>anchor</a></p>";
431 editor.focus();
432 selection.setBaseAndExtent(editor.firstChild, 0, editor.firstChild, 1);
433 element = SpecialPowers.unwrap(getHTMLEditor().getElementOrParentByTagName("anchor", null));
434 is(element, null,
435 "nsIHTMLEditor.getElementOrParentByTagName(\"anchor\", null) should return the <a> is selected");
437 SimpleTest.finish();
440 function getHTMLEditor() {
441 var Ci = SpecialPowers.Ci;
442 var editingSession = SpecialPowers.wrap(window).docShell.editingSession;
443 return editingSession.getEditorForWindow(window).QueryInterface(Ci.nsIHTMLEditor);
446 </script>
447 </body>
449 </html>