4 <title>Test for nsIHTMLEditor.getElementOrParentByTagName()
</title>
5 <script src=
"/tests/SimpleTest/SimpleTest.js"></script>
6 <link rel=
"stylesheet" href=
"/tests/SimpleTest/test.css">
12 <div id=
"content" contenteditable
></div>
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();
26 // Make sure that each test can run without previous tests for making each test
27 // debuggable with commenting out the unrelated tests.
31 element = SpecialPowers.unwrap(getHTMLEditor().getElementOrParentByTagName(
"", null));
32 ok(false,
"nsIHTMLEditor.getElementOrParentByTagName(\"\
", null) should throw an exception");
34 ok(true,
"nsIHTMLEditor.getElementOrParentByTagName(\"\
", null) should throw an exception");
39 element = SpecialPowers.unwrap(getHTMLEditor().getElementOrParentByTagName(null, null));
40 ok(false,
"nsIHTMLEditor.getElementOrParentByTagName(null, null) should throw an exception");
42 ok(true,
"nsIHTMLEditor.getElementOrParentByTagName(null, null) should throw an exception");
47 element = SpecialPowers.unwrap(getHTMLEditor().getElementOrParentByTagName(undefined, null));
48 ok(false,
"nsIHTMLEditor.getElementOrParentByTagName(undefined, null) should throw an exception");
50 ok(true,
"nsIHTMLEditor.getElementOrParentByTagName(undefined, null) should throw an exception");
54 element = SpecialPowers.unwrap(getHTMLEditor().getElementOrParentByTagName(
"undefinedtagname", null));
56 "nsIHTMLEditor.getElementOrParentByTagName(\"undefinedtagname\
", null) should return null");
59 selection.collapse(document.getElementById(
"display"),
0);
60 element = SpecialPowers.unwrap(getHTMLEditor().getElementOrParentByTagName(
"section", null));
62 "nsIHTMLEditor.getElementOrParentByTagName(\"section\
", null) should return the <section> when selection is in the it (HTML editor does not have focus)");
65 element = SpecialPowers.unwrap(getHTMLEditor().getElementOrParentByTagName(
"section", null));
67 "nsIHTMLEditor.getElementOrParentByTagName(\"section\
", null) should return the <section> when selection is in the it (HTML editor has focus)");
70 selection.removeAllRanges();
71 element = SpecialPowers.unwrap(getHTMLEditor().getElementOrParentByTagName(
"section", null));
73 "nsIHTMLEditor.getElementOrParentByTagName(\"section\
", null) should return null when there is no selection");
76 selection.collapse(document.getElementById(
"display"),
0);
77 element = SpecialPowers.unwrap(getHTMLEditor().getElementOrParentByTagName(
"body", null));
79 "nsIHTMLEditor.getElementOrParentByTagName(\"body\
", null) should return null when it reaches the <body>");
82 selection.collapse(document.getElementById(
"display"),
0);
83 element = SpecialPowers.unwrap(getHTMLEditor().getElementOrParentByTagName(
"div", 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>";
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>";
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>";
103 selection.collapse(editor.querySelector(
"td").firstChild,
2);
104 element = SpecialPowers.unwrap(getHTMLEditor().getElementOrParentByTagName(
"th", 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>";
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>";
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>";
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>";
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>";
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>";
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>";
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>";
159 selection.collapse(editor.querySelector(
"li").firstChild,
4);
160 element = SpecialPowers.unwrap(getHTMLEditor().getElementOrParentByTagName(
"ol", null));
162 "nsIHTMLEditor.getElementOrParentByTagName(\"ol\
", null) should return null when selection is collapsed in <ul>");
164 editor.innerHTML =
"<ol><li>listitem</li></ol>";
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>";
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>";
180 selection.collapse(editor.querySelector(
"li").firstChild,
4);
181 element = SpecialPowers.unwrap(getHTMLEditor().getElementOrParentByTagName(
"ul", null));
183 "nsIHTMLEditor.getElementOrParentByTagName(\"ol\
", null) should return null when selection is collapsed in <ol>");
185 editor.innerHTML =
"<dl><dt>listitem</dt></dl>";
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>";
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>";
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>";
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>";
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>";
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>";
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>";
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>";
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>";
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>";
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>";
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>";
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>";
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>";
285 selection.collapse(editor.querySelector(
"a").firstChild,
3);
286 element = SpecialPowers.unwrap(getHTMLEditor().getElementOrParentByTagName(
"anchor", 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>";
292 selection.setBaseAndExtent(editor.firstChild,
0, editor.firstChild,
1);
293 element = SpecialPowers.unwrap(getHTMLEditor().getElementOrParentByTagName(
"anchor", 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>";
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>";
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>";
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>";
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>";
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>";
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>";
341 selection.collapse(editor.querySelector(
"a").firstChild,
3);
342 element = SpecialPowers.unwrap(getHTMLEditor().getElementOrParentByTagName(
"href", 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>";
348 selection.setBaseAndExtent(editor.firstChild,
0, editor.firstChild,
1);
349 element = SpecialPowers.unwrap(getHTMLEditor().getElementOrParentByTagName(
"href", 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>";
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>";
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>";
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>";
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>";
383 selection.collapse(editor.querySelector(
"a").firstChild,
3);
384 element = SpecialPowers.unwrap(getHTMLEditor().getElementOrParentByTagName(
"anchor", 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>";
390 selection.setBaseAndExtent(editor.firstChild,
0, editor.firstChild,
1);
391 element = SpecialPowers.unwrap(getHTMLEditor().getElementOrParentByTagName(
"anchor", null));
393 "nsIHTMLEditor.getElementOrParentByTagName(\"anchor\
", null) should return null when the <a name=\"\
"> is selected");
395 editor.innerHTML =
"<p><a>anchor</a></p>";
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>";
404 selection.collapse(editor.querySelector(
"a").firstChild,
3);
405 element = SpecialPowers.unwrap(getHTMLEditor().getElementOrParentByTagName(
"href", null));
407 "nsIHTMLEditor.getElementOrParentByTagName(\"href\
", null) should return null when selection is collapsed in the <a>");
409 editor.innerHTML =
"<p><a>anchor</a></p>";
411 selection.collapse(editor.querySelector(
"a").firstChild,
3);
412 element = SpecialPowers.unwrap(getHTMLEditor().getElementOrParentByTagName(
"anchor", null));
414 "nsIHTMLEditor.getElementOrParentByTagName(\"anchor\
", null) should return null when selection is collapsed in the <a>");
416 editor.innerHTML =
"<p><a>anchor</a></p>";
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>";
425 selection.setBaseAndExtent(editor.firstChild,
0, editor.firstChild,
1);
426 element = SpecialPowers.unwrap(getHTMLEditor().getElementOrParentByTagName(
"href", null));
428 "nsIHTMLEditor.getElementOrParentByTagName(\"href\
", null) should return null when the <a> is selected");
430 editor.innerHTML =
"<p><a>anchor</a></p>";
432 selection.setBaseAndExtent(editor.firstChild,
0, editor.firstChild,
1);
433 element = SpecialPowers.unwrap(getHTMLEditor().getElementOrParentByTagName(
"anchor", null));
435 "nsIHTMLEditor.getElementOrParentByTagName(\"anchor\
", null) should return the <a> is selected");
440 function getHTMLEditor() {
441 var Ci = SpecialPowers.Ci;
442 var editingSession = SpecialPowers.wrap(window).docShell.editingSession;
443 return editingSession.getEditorForWindow(window).QueryInterface(Ci.nsIHTMLEditor);