tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_nsIHTMLEditor_getSelectedElement.html (46735B)


      1 <!DOCTYPE>
      2 <html>
      3 <head>
      4  <title>Test for nsIHTMLEditor.getSelectedElement()</title>
      5  <script src="/tests/SimpleTest/SimpleTest.js"></script>
      6  <script src="/tests/SimpleTest/EventUtils.js"></script>
      7  <link rel="stylesheet" href="/tests/SimpleTest/test.css">
      8 </head>
      9 <body>
     10 <div id="display">
     11 </div>
     12 <div id="content" contenteditable></div>
     13 <img src="green.png"><!-- necessary to load this image before start testing -->
     14 <pre id="test">
     15 </pre>
     16 
     17 <script class="testbody" type="application/javascript">
     18 
     19 SimpleTest.waitForExplicitFinish();
     20 SimpleTest.waitForFocus(async function() {
     21  let editor = document.getElementById("content");
     22  let selection = window.getSelection();
     23 
     24  // nsIHTMLEditor.getSelectedElement() is probably designed to retrieve
     25  // a[href]:not([href=""]), a[name]:not([name=""]), or void element like
     26  // <img> element.  When user selects usual inline elements with dragging,
     27  // double-clicking, Gecko sets start and/or end to point in text nodes
     28  // as far as possible.  Therefore, this API users don't expect that this
     29  // returns usual inline elements like <b> element.
     30 
     31  // So, we need to check user's operation works fine.
     32  for (let eatSpaceToNextWord of [true, false]) {
     33    await SpecialPowers.pushPrefEnv({"set": [["layout.word_select.eat_space_to_next_word", eatSpaceToNextWord]]});
     34 
     35    editor.innerHTML = "<p>This <b>is</b> an <i>example </i>text.<br></p>" +
     36                       "<p>and an image <img src=\"green.png\"> is here.</p>" +
     37                       "<p>An anchor with href attr <a href=\"about:blank\">is</a> here.</p>";
     38    editor.focus();
     39    editor.scrollTop; // flush layout.
     40 
     41    let b = editor.firstChild.firstChild.nextSibling;
     42    let i = b.nextSibling.nextSibling;
     43    let img = editor.firstChild.nextSibling.firstChild.nextSibling;
     44    let href = editor.firstChild.nextSibling.nextSibling.firstChild.nextSibling;
     45 
     46    // double clicking usual inline element shouldn't cause "selecting" the element.
     47    synthesizeMouseAtCenter(b, {clickCount: 1});
     48    synthesizeMouseAtCenter(b, {clickCount: 2});
     49    is(selection.getRangeAt(0).startContainer, b.previousSibling,
     50       `#0-1 Double-clicking in <b> element should set start of selection to end of previous text node (eat_space_to_next_word: ${eatSpaceToNextWord})`);
     51    is(selection.getRangeAt(0).startOffset, b.previousSibling.length,
     52       `#0-1 Double-clicking in <b> element should set start of selection to end of previous text node (eat_space_to_next_word: ${eatSpaceToNextWord})`);
     53    is(selection.getRangeAt(0).endContainer, b.nextSibling,
     54       `#0-1 Double-clicking in <b> element should set end of selection to start of next text node (eat_space_to_next_word: ${eatSpaceToNextWord})`);
     55    is(selection.getRangeAt(0).endOffset, eatSpaceToNextWord ? 1 : 0,
     56       `#0-1 Double-clicking in <b> element should set end of selection to start of next text node (eat_space_to_next_word: ${eatSpaceToNextWord})`);
     57 
     58    is(SpecialPowers.unwrap(getHTMLEditor().getSelectedElement("")),
     59       null,
     60       `#0-1 nsIHTMLEditor::getSelectedElement(\"\") should return null after double-clicking in <b> element (eat_space_to_next_word: ${eatSpaceToNextWord})`);
     61 
     62    synthesizeMouseAtCenter(i, {clickCount: 1});
     63    synthesizeMouseAtCenter(i, {clickCount: 2});
     64    is(selection.getRangeAt(0).startContainer, i.previousSibling,
     65       `#0-2 Double-clicking in <i> element should set start of selection to end of previous text node (eat_space_to_next_word: ${eatSpaceToNextWord})`);
     66    is(selection.getRangeAt(0).startOffset, i.previousSibling.length,
     67       `#0-2 Double-clicking in <i> element should set start of selection to end of previous text node (eat_space_to_next_word: ${eatSpaceToNextWord})`);
     68    if (eatSpaceToNextWord) {
     69      is(selection.getRangeAt(0).endContainer, i.nextSibling,
     70         "#0-2 Double-clicking in <i> element should set end of selection to start of next text node (eat_space_to_next_word: true)");
     71      is(selection.getRangeAt(0).endOffset, 0,
     72         "#0-2 Double-clicking in <i> element should set end of selection to start of next text node (eat_space_to_next_word: true)");
     73    } else {
     74      is(selection.getRangeAt(0).endContainer, i.firstChild,
     75         "#0-2 Double-clicking in <i> element should set end of selection to end of the word in <i> (eat_space_to_next_word: false)");
     76      is(selection.getRangeAt(0).endOffset, "example".length,
     77         "#0-2 Double-clicking in <i> element should set end of selection to end of the word in <i> (eat_space_to_next_word: false)");
     78    }
     79 
     80    is(SpecialPowers.unwrap(getHTMLEditor().getSelectedElement("")),
     81       null,
     82       `#0-2 nsIHTMLEditor::getSelectedElement(\"\") should return null after double-clicking in <b> element (eat_space_to_next_word: ${eatSpaceToNextWord})`);
     83 
     84    // Both clicking and double-clicking on <img> element should "select" it.
     85    synthesizeMouseAtCenter(img, {clickCount: 1});
     86    is(selection.getRangeAt(0).startContainer, img.parentElement,
     87       `#0-3 Clicking in <img> element should set start of selection to the <img> element (eat_space_to_next_word: ${eatSpaceToNextWord})`);
     88    is(selection.getRangeAt(0).startOffset, 1,
     89       `#0-3 Clicking in <img> element should set start of selection to the <img> element (eat_space_to_next_word: ${eatSpaceToNextWord})`);
     90    is(selection.getRangeAt(0).endContainer, img.parentElement,
     91       `#0-3 Clicking in <img> element should set end of selection to start of next text node (eat_space_to_next_word: ${eatSpaceToNextWord})`);
     92    is(selection.getRangeAt(0).endOffset, 2,
     93       `#0-3 Clicking in <img> element should set end of selection to start of next text node (eat_space_to_next_word: ${eatSpaceToNextWord})`);
     94 
     95    is(SpecialPowers.unwrap(getHTMLEditor().getSelectedElement("")),
     96       img,
     97       `#0-3 nsIHTMLEditor::getSelectedElement(\"\") should return the <img> element after clicking in it (eat_space_to_next_word: ${eatSpaceToNextWord})`);
     98 
     99    synthesizeMouseAtCenter(img, {clickCount: 1});
    100    synthesizeMouseAtCenter(img, {clickCount: 2});
    101    is(selection.getRangeAt(0).startContainer, img.parentElement,
    102       `#0-4 Double-clicking in <img> element should set start of selection to the <img> element (eat_space_to_next_word: ${eatSpaceToNextWord})`);
    103    is(selection.getRangeAt(0).startOffset, 1,
    104       `#0-4 Double-clicking in <img> element should set start of selection to the <img> element (eat_space_to_next_word: ${eatSpaceToNextWord})`);
    105    is(selection.getRangeAt(0).endContainer, img.parentElement,
    106       `#0-4 Double-clicking in <img> element should set end of selection to start of next text node (eat_space_to_next_word: ${eatSpaceToNextWord})`);
    107    is(selection.getRangeAt(0).endOffset, 2,
    108       `#0-4 Double-clicking in <img> element should set end of selection to start of next text node (eat_space_to_next_word: ${eatSpaceToNextWord})`);
    109 
    110    is(SpecialPowers.unwrap(getHTMLEditor().getSelectedElement("")),
    111       img,
    112       `#0-4 nsIHTMLEditor::getSelectedElement(\"\") should return the <img> element after double-clicking in it (eat_space_to_next_word: ${eatSpaceToNextWord})`);
    113 
    114    // Puts caret into the <a href> element.
    115    synthesizeMouseAtCenter(href, {clickCount: 1});
    116    is(selection.getRangeAt(0).startContainer, href.firstChild,
    117       `#0-5 Clicking in <a href> element should set start of selection to the text node in it (eat_space_to_next_word: ${eatSpaceToNextWord})`);
    118    is(selection.isCollapsed, true,
    119       `#0-5 Clicking in <a href> element should cause collapsing Selection (eat_space_to_next_word: ${eatSpaceToNextWord})`);
    120 
    121    is(SpecialPowers.unwrap(getHTMLEditor().getSelectedElement("")),
    122       null,
    123       `#0-5 nsIHTMLEditor::getSelectedElement(\"\") should return null after clicking in the <a href> element (eat_space_to_next_word: ${eatSpaceToNextWord})`);
    124    is(SpecialPowers.unwrap(getHTMLEditor().getSelectedElement("href")),
    125       href,
    126       `#0-5 nsIHTMLEditor::getSelectedElement(\"href\") should return the <a href> element after clicking in it (eat_space_to_next_word: ${eatSpaceToNextWord})`);
    127 
    128    // Selects the <a href> element with a triple-click.
    129    synthesizeMouseAtCenter(href, {clickCount: 1});
    130    synthesizeMouseAtCenter(href, {clickCount: 2});
    131    synthesizeMouseAtCenter(href, {clickCount: 3});
    132    is(selection.getRangeAt(0).startContainer, href.parentElement,
    133       `#0-6 Triple-clicking in <a href> element should set start of selection to the element (eat_space_to_next_word: ${eatSpaceToNextWord})`);
    134    is(selection.getRangeAt(0).startOffset, 1,
    135       `#0-6 Triple-clicking in <a href> element should set start of selection to the element (eat_space_to_next_word: ${eatSpaceToNextWord})`);
    136    is(selection.getRangeAt(0).endContainer, href.parentElement,
    137       `#0-6 Triple-clicking in <a href> element should set end of selection to start of next <br> element (eat_space_to_next_word: ${eatSpaceToNextWord})`);
    138    is(selection.getRangeAt(0).endOffset, 2,
    139       `#0-6 Triple-clicking in <a href> element should set end of selection to start of next <br> element (eat_space_to_next_word: ${eatSpaceToNextWord})`);
    140 
    141    is(SpecialPowers.unwrap(getHTMLEditor().getSelectedElement("")),
    142       href,
    143       `#0-6 nsIHTMLEditor::getSelectedElement(\"\") should return the <a href> element after double-clicking in it (eat_space_to_next_word: ${eatSpaceToNextWord})`);
    144    is(SpecialPowers.unwrap(getHTMLEditor().getSelectedElement("href")),
    145       href,
    146       `#0-6 nsIHTMLEditor::getSelectedElement(\"href\") should return the <a href> element after double-clicking in it (eat_space_to_next_word: ${eatSpaceToNextWord})`);
    147  }
    148 
    149  editor.innerHTML = "<p>p1<b>b1</b><i>i1</i></p>";
    150  editor.focus();
    151 
    152  // <p>[]p1...
    153  let range = document.createRange();
    154  range.setStart(editor.firstChild.firstChild, 0);
    155  range.setEnd(editor.firstChild.firstChild, 0);
    156  selection.removeAllRanges();
    157  selection.addRange(range);
    158 
    159  is(SpecialPowers.unwrap(getHTMLEditor().getSelectedElement("")),
    160     null,
    161     "#1-1 nsIHTMLEditor::getSelectedElement(\"\") should return null when selection is collapsed in a text node");
    162 
    163  // <p>[p1]<b>...
    164  range = document.createRange();
    165  range.setStart(editor.firstChild.firstChild, 0);
    166  range.setEnd(editor.firstChild.firstChild, 2);
    167  selection.removeAllRanges();
    168  selection.addRange(range);
    169 
    170  is(SpecialPowers.unwrap(getHTMLEditor().getSelectedElement("")),
    171     null,
    172     "#1-2 nsIHTMLEditor::getSelectedElement(\"\") should return null when selection ends in a text node");
    173 
    174  // <p>[p1<b>]b1</b>...
    175  range = document.createRange();
    176  range.setStart(editor.firstChild.firstChild, 0);
    177  range.setEnd(editor.firstChild.firstChild.nextSibling.firstChild, 0);
    178  selection.removeAllRanges();
    179  selection.addRange(range);
    180 
    181  is(SpecialPowers.unwrap(getHTMLEditor().getSelectedElement("")),
    182     null,
    183     "#1-3 nsIHTMLEditor::getSelectedElement(\"\") should return null when Selection ends at start of text node in <b> element");
    184  is(SpecialPowers.unwrap(getHTMLEditor().getSelectedElement("b")),
    185     null,
    186     "#1-3 nsIHTMLEditor::getSelectedElement(\"b\") should return null when Selection ends at start of text node in <b> element");
    187  is(SpecialPowers.unwrap(getHTMLEditor().getSelectedElement("i")),
    188     editor.firstChild.nextSibling,
    189     "#1-3 nsIHTMLEditor::getSelectedElement(\"i\") should return the <b> element when Selection ends at start of text node in <b> element");
    190 
    191  // <p>[p1<b>b1]</b>...
    192  range = document.createRange();
    193  range.setStart(editor.firstChild.firstChild, 0);
    194  range.setEnd(editor.firstChild.firstChild.nextSibling.firstChild, 2);
    195  selection.removeAllRanges();
    196  selection.addRange(range);
    197 
    198  is(SpecialPowers.unwrap(getHTMLEditor().getSelectedElement("")),
    199     null,
    200     "#1-4 nsIHTMLEditor::getSelectedElement(\"\") should return null when Selection ends at end of text node in a text node");
    201  is(SpecialPowers.unwrap(getHTMLEditor().getSelectedElement("b")),
    202     null,
    203     "#1-4 nsIHTMLEditor::getSelectedElement(\"b\") should return null when Selection ends at end of text node in a text node");
    204  is(SpecialPowers.unwrap(getHTMLEditor().getSelectedElement("i")),
    205     editor.firstChild.nextSibling,
    206     "#1-4 nsIHTMLEditor::getSelectedElement(\"i\") should return the <b> element when Selection ends at end of text node in <b> element");
    207 
    208  // <p>[p1}<b>b1...
    209  range = document.createRange();
    210  range.setStart(editor.firstChild.firstChild, 0);
    211  range.setEnd(editor.firstChild.firstChild.nextSibling, 0);
    212  selection.removeAllRanges();
    213  selection.addRange(range);
    214 
    215  is(SpecialPowers.unwrap(getHTMLEditor().getSelectedElement("")),
    216     null,
    217     "#1-5 nsIHTMLEditor::getSelectedElement(\"\") should return null when Selection ends at text node and there are no elements");
    218  is(SpecialPowers.unwrap(getHTMLEditor().getSelectedElement("b")),
    219     null,
    220     "#1-5 nsIHTMLEditor::getSelectedElement(\"b\") should return null when Selection ends at text node and there are no elements");
    221  is(SpecialPowers.unwrap(getHTMLEditor().getSelectedElement("i")),
    222     null,
    223     "#1-5 nsIHTMLEditor::getSelectedElement(\"i\") should return null when Selection ends at text node and there are no elements");
    224 
    225  // <p>p1<b>{b1}</b>...
    226  range = document.createRange();
    227  range.setStart(editor.firstChild.firstChild.nextSibling, 0);
    228  range.setEnd(editor.firstChild.firstChild.nextSibling, 1);
    229  selection.removeAllRanges();
    230  selection.addRange(range);
    231 
    232  is(SpecialPowers.unwrap(getHTMLEditor().getSelectedElement("")),
    233     null,
    234     "#1-6 nsIHTMLEditor::getSelectedElement(\"\") should return null when Selection only selects a text node");
    235  is(SpecialPowers.unwrap(getHTMLEditor().getSelectedElement("b")),
    236     null,
    237     "#1-6 nsIHTMLEditor::getSelectedElement(\"b\") should return null when Selection only selects a text node");
    238  is(SpecialPowers.unwrap(getHTMLEditor().getSelectedElement("i")),
    239     null,
    240     "#1-6 nsIHTMLEditor::getSelectedElement(\"i\") should return null when Selection only selects a text node");
    241 
    242  // <p>[p1<b>b1</b>}<i>...
    243  range = document.createRange();
    244  range.setStart(editor.firstChild.firstChild, 0);
    245  range.setEnd(editor.firstChild, 2);
    246  selection.removeAllRanges();
    247  selection.addRange(range);
    248 
    249  is(SpecialPowers.unwrap(getHTMLEditor().getSelectedElement("")),
    250     null,
    251     "#1-7 nsIHTMLEditor::getSelectedElement(\"\") should return null when Selection ends the <b> element but starts from the previous text node");
    252  is(SpecialPowers.unwrap(getHTMLEditor().getSelectedElement("b")),
    253     null,
    254     "#1-7 nsIHTMLEditor::getSelectedElement(\"b\") should return null when Selection ends the <b> element but starts from the previous text node");
    255  is(SpecialPowers.unwrap(getHTMLEditor().getSelectedElement("i")),
    256     null,
    257     "#1-7 nsIHTMLEditor::getSelectedElement(\"i\") should return null when Selection ends the <b> element but starts from the previous text node");
    258  is(SpecialPowers.unwrap(getHTMLEditor().getSelectedElement("href")),
    259     null,
    260     "#1-7 nsIHTMLEditor::getSelectedElement(\"href\") should return null when Selection ends the <b> element but starts from the previous text node");
    261  is(SpecialPowers.unwrap(getHTMLEditor().getSelectedElement("anchor")),
    262     null,
    263     "#1-7 nsIHTMLEditor::getSelectedElement(\"anchor\") should return null when Selection ends the <b> element but starts from the previous text node");
    264  is(SpecialPowers.unwrap(getHTMLEditor().getSelectedElement("namedanchor")),
    265     null,
    266     "#1-7 nsIHTMLEditor::getSelectedElement(\"namedanchor\") should return null when Selection ends the <b> element but starts from the previous text node");
    267 
    268  // <p>[p1<b>b1</b><i>i1</i>}...
    269  range = document.createRange();
    270  range.setStart(editor.firstChild.firstChild, 0);
    271  range.setEnd(editor.firstChild, 3);
    272  selection.removeAllRanges();
    273  selection.addRange(range);
    274 
    275  is(SpecialPowers.unwrap(getHTMLEditor().getSelectedElement("")),
    276     null,
    277     "#1-8 nsIHTMLEditor::getSelectedElement(\"\") should return null when Selection includes 2 elements and starts from previous text node");
    278  is(SpecialPowers.unwrap(getHTMLEditor().getSelectedElement("b")),
    279     null,
    280     "#1-8 nsIHTMLEditor::getSelectedElement(\"b\") should return null when Selection includes 2 elements and starts from previous text node");
    281  is(SpecialPowers.unwrap(getHTMLEditor().getSelectedElement("i")),
    282     null,
    283     "#1-8 nsIHTMLEditor::getSelectedElement(\"i\") should return null when Selection includes 2 elements and starts from previous text node");
    284  is(SpecialPowers.unwrap(getHTMLEditor().getSelectedElement("href")),
    285     null,
    286     "#1-8 nsIHTMLEditor::getSelectedElement(\"href\") should null when Selection includes 2 elements and starts from previous text node");
    287  is(SpecialPowers.unwrap(getHTMLEditor().getSelectedElement("anchor")),
    288     null,
    289     "#1-8 nsIHTMLEditor::getSelectedElement(\"anchor\") should return null when Selection includes 2 elements and starts from previous text node");
    290  is(SpecialPowers.unwrap(getHTMLEditor().getSelectedElement("namedanchor")),
    291     null,
    292     "#1-8 nsIHTMLEditor::getSelectedElement(\"namedanchor\") should return null when Selection includes 2 elements and starts from previous text node");
    293 
    294  // <p>p1{<b>b1</b>}<i>i1</i>...
    295  // Note that this won't happen with user operation since Gecko sets
    296  // start and end of Selection to points in text nodes as far as possible.
    297  range = document.createRange();
    298  range.setStart(editor.firstChild, 1);
    299  range.setEnd(editor.firstChild, 2);
    300  selection.removeAllRanges();
    301  selection.addRange(range);
    302 
    303  is(SpecialPowers.unwrap(getHTMLEditor().getSelectedElement("")),
    304     editor.firstChild.firstChild.nextSibling,
    305     "#1-9 nsIHTMLEditor::getSelectedElement(\"\") should return <b> element when only it is selected and matched");
    306  is(SpecialPowers.unwrap(getHTMLEditor().getSelectedElement("b")),
    307     editor.firstChild.firstChild.nextSibling,
    308     "#1-9 nsIHTMLEditor::getSelectedElement(\"b\") should return <b> element when only it is selected and matched");
    309  is(SpecialPowers.unwrap(getHTMLEditor().getSelectedElement("i")),
    310     null,
    311     "#1-9 nsIHTMLEditor::getSelectedElement(\"i\") should return null when only a <b> element is selected but it is unmatched");
    312  is(SpecialPowers.unwrap(getHTMLEditor().getSelectedElement("href")),
    313     null,
    314     "#1-9 nsIHTMLEditor::getSelectedElement(\"href\") should return null when only a <b> element is selected but it is unmatched");
    315  is(SpecialPowers.unwrap(getHTMLEditor().getSelectedElement("anchor")),
    316     null,
    317     "#1-9 nsIHTMLEditor::getSelectedElement(\"anchor\") should return null when only a <b> element is selected but it is unmatched");
    318  is(SpecialPowers.unwrap(getHTMLEditor().getSelectedElement("namedanchor")),
    319     null,
    320     "#1-9 nsIHTMLEditor::getSelectedElement(\"namedanchor\") should return when only a <b> element is selected but it is unmatched");
    321 
    322  // <p>p1<b>b1</b>{<i>i1</i>}</p>...
    323  range = document.createRange();
    324  range.setStart(editor.firstChild, 2);
    325  range.setEnd(editor.firstChild, 3);
    326  selection.removeAllRanges();
    327  selection.addRange(range);
    328 
    329  is(SpecialPowers.unwrap(getHTMLEditor().getSelectedElement("")),
    330     editor.firstChild.firstChild.nextSibling.nextSibling,
    331     "#1-10 nsIHTMLEditor::getSelectedElement(\"\") should return <i> element when only it is selected and matched");
    332  is(SpecialPowers.unwrap(getHTMLEditor().getSelectedElement("b")),
    333     null,
    334     "#1-10 nsIHTMLEditor::getSelectedElement(\"b\") should return null when only an <i> element is selected but it is unmatched");
    335  is(SpecialPowers.unwrap(getHTMLEditor().getSelectedElement("i")),
    336     editor.firstChild.firstChild.nextSibling.nextSibling,
    337     "#1-10 nsIHTMLEditor::getSelectedElement(\"i\") should return <i> element when only it is selected and matched");
    338  is(SpecialPowers.unwrap(getHTMLEditor().getSelectedElement("href")),
    339     null,
    340     "#1-10 nsIHTMLEditor::getSelectedElement(\"href\") should return null when only an <i> element is selected but it is unmatched");
    341  is(SpecialPowers.unwrap(getHTMLEditor().getSelectedElement("anchor")),
    342     null,
    343     "#1-10 nsIHTMLEditor::getSelectedElement(\"anchor\") should return null when only an <i> element is selected but it is unmatched");
    344  is(SpecialPowers.unwrap(getHTMLEditor().getSelectedElement("namedanchor")),
    345     null,
    346     "#1-10 nsIHTMLEditor::getSelectedElement(\"namedanchor\") should return null when only an <i> element is selected but it is unmatched");
    347 
    348  // <p>{p1}<b>b1</b><i>...
    349  range = document.createRange();
    350  range.setStart(editor.firstChild, 0);
    351  range.setEnd(editor.firstChild, 1);
    352  selection.removeAllRanges();
    353  selection.addRange(range);
    354 
    355  is(SpecialPowers.unwrap(getHTMLEditor().getSelectedElement("")),
    356     null,
    357     "#1-11 nsIHTMLEditor::getSelectedElement(\"\") should return null when only a text node is selected");
    358  is(SpecialPowers.unwrap(getHTMLEditor().getSelectedElement("b")),
    359     null,
    360     "#1-11 nsIHTMLEditor::getSelectedElement(\"b\") should return null when only a text node is selected");
    361  is(SpecialPowers.unwrap(getHTMLEditor().getSelectedElement("i")),
    362     null,
    363     "#1-11 nsIHTMLEditor::getSelectedElement(\"i\") should return null when only a text node is selected");
    364  is(SpecialPowers.unwrap(getHTMLEditor().getSelectedElement("href")),
    365     null,
    366     "#1-11 nsIHTMLEditor::getSelectedElement(\"href\") should return null when only a text node is selected");
    367  is(SpecialPowers.unwrap(getHTMLEditor().getSelectedElement("anchor")),
    368     null,
    369     "#1-11 nsIHTMLEditor::getSelectedElement(\"anchor\") should return null when only a text node is selected");
    370  is(SpecialPowers.unwrap(getHTMLEditor().getSelectedElement("namedanchor")),
    371     null,
    372     "#1-11 nsIHTMLEditor::getSelectedElement(\"namedanchor\") should return null when only a text node is selected");
    373 
    374  editor.innerHTML = "<p>p1<b>b1</b><b>b2</b><b>b3</b></p>";
    375  editor.focus();
    376 
    377  // <p>p1<b>b[1</b><b>b2</b><b>b]3</b>...
    378  range = document.createRange();
    379  range.setStart(editor.firstChild.firstChild.nextSibling.firstChild, 1);
    380  range.setEnd(editor.firstChild.firstChild.nextSibling.nextSibling.nextSibling.firstChild, 1);
    381  selection.removeAllRanges();
    382  selection.addRange(range);
    383 
    384  is(SpecialPowers.unwrap(getHTMLEditor().getSelectedElement("")),
    385     null,
    386     "#2-1 nsIHTMLEditor::getSelectedElement(\"\") should return null when Selection is across 3 <b> elements");
    387  is(SpecialPowers.unwrap(getHTMLEditor().getSelectedElement("b")),
    388     null,
    389     "#2-1 nsIHTMLEditor::getSelectedElement(\"b\") should return null when Selection is across 3 <b> elements");
    390  is(SpecialPowers.unwrap(getHTMLEditor().getSelectedElement("i")),
    391     null,
    392     "#2-1 nsIHTMLEditor::getSelectedElement(\"i\") should return null when Selection is across 3 <b> elements");
    393 
    394  // <p>p[1<b>b1</b><b>b2</b><b>b]3</b>...
    395  range = document.createRange();
    396  range.setStart(editor.firstChild.firstChild, 1);
    397  range.setEnd(editor.firstChild.firstChild.nextSibling.nextSibling.nextSibling.firstChild, 1);
    398  selection.removeAllRanges();
    399  selection.addRange(range);
    400 
    401  is(SpecialPowers.unwrap(getHTMLEditor().getSelectedElement("")),
    402     null,
    403     "#2-2 nsIHTMLEditor::getSelectedElement(\"\") should return null when Selection is across 3 <b> elements and previous text node");
    404  is(SpecialPowers.unwrap(getHTMLEditor().getSelectedElement("b")),
    405     null,
    406     "#2-2 nsIHTMLEditor::getSelectedElement(\"b\") should return null when Selection is across 3 <b> elements and previous text node");
    407  is(SpecialPowers.unwrap(getHTMLEditor().getSelectedElement("i")),
    408     null,
    409     "#2-2 nsIHTMLEditor::getSelectedElement(\"i\") should return null when Selection is across 3 <b> elements and previous text node");
    410 
    411  editor.innerHTML = "<p>p1<b>b1<b>b2<b>b3</b></b></b>p2</p>";
    412  editor.focus();
    413 
    414  // <p>p1<b>b[1<b>b1-2<b>b]1-3</b>...
    415  range = document.createRange();
    416  range.setStart(editor.firstChild.firstChild.nextSibling.firstChild, 1);
    417  range.setEnd(editor.firstChild.firstChild.nextSibling.firstChild.nextSibling.firstChild.nextSibling.firstChild, 1);
    418  selection.removeAllRanges();
    419  selection.addRange(range);
    420 
    421  is(SpecialPowers.unwrap(getHTMLEditor().getSelectedElement("")),
    422     null,
    423     "#3-1 nsIHTMLEditor::getSelectedElement(\"\") should return null when Selection is across 3 <b> elements which are nested");
    424  is(SpecialPowers.unwrap(getHTMLEditor().getSelectedElement("b")),
    425     null,
    426     "#3-1 nsIHTMLEditor::getSelectedElement(\"b\") should return null when Selection is across 3 <b> elements which are nested");
    427  is(SpecialPowers.unwrap(getHTMLEditor().getSelectedElement("i")),
    428     null,
    429     "#3-1 nsIHTMLEditor::getSelectedElement(\"i\") should return null when Selection is across 3 <b> elements which are nested");
    430 
    431  // <p>p[1<b>b1<b>b1-2<b>b]1-3</b>...
    432  range = document.createRange();
    433  range.setStart(editor.firstChild.firstChild, 1);
    434  range.setEnd(editor.firstChild.firstChild.nextSibling.firstChild.nextSibling.firstChild.nextSibling.firstChild, 1);
    435  selection.removeAllRanges();
    436  selection.addRange(range);
    437 
    438  is(SpecialPowers.unwrap(getHTMLEditor().getSelectedElement("")),
    439     null,
    440     "#3-2 nsIHTMLEditor::getSelectedElement(\"\") should return null when Selection is across a text node and 3 <b> elements which are nested");
    441  is(SpecialPowers.unwrap(getHTMLEditor().getSelectedElement("b")),
    442     null,
    443     "#3-2 nsIHTMLEditor::getSelectedElement(\"b\") should return null when Selection is across a text node and 3 <b> elements which are nested");
    444  is(SpecialPowers.unwrap(getHTMLEditor().getSelectedElement("i")),
    445     null,
    446     "#3-2 nsIHTMLEditor::getSelectedElement(\"i\") should return null when Selection is across a text node and 3 <b> elements which are nested");
    447 
    448  // <p>p1<b>b1<b>b1-2<b>b[1-3</b></b></b>p]2...
    449  range = document.createRange();
    450  range.setStart(editor.firstChild.firstChild.nextSibling.firstChild.nextSibling.firstChild.nextSibling.firstChild, 1);
    451  range.setEnd(editor.firstChild.firstChild.nextSibling.nextSibling, 1);
    452  selection.removeAllRanges();
    453  selection.addRange(range);
    454 
    455  is(SpecialPowers.unwrap(getHTMLEditor().getSelectedElement("")),
    456     null,
    457     "#3-3 nsIHTMLEditor::getSelectedElement(\"\") should return null when Selection is across 3 <b> elements which are nested and following text node");
    458  is(SpecialPowers.unwrap(getHTMLEditor().getSelectedElement("b")),
    459     null,
    460     "#3-3 nsIHTMLEditor::getSelectedElement(\"b\") should return null when Selection is across 3 <b> elements which are nested and following text node");
    461  is(SpecialPowers.unwrap(getHTMLEditor().getSelectedElement("i")),
    462     null,
    463     "#3-3 nsIHTMLEditor::getSelectedElement(\"i\") should return null when Selection is across 3 <b> elements which are nested and following text node");
    464 
    465  editor.innerHTML = "<p><b>b1</b><a href=\"about:blank\">a1</a><a href=\"about:blank\">a2</a><a name=\"foo\">a3</a><b>b2</b></p>";
    466  editor.focus();
    467 
    468  // <p><b>b1</b>{<a href="...">a1</a>}<a href="...">a2...
    469  // Note that this won't happen with user operation since Gecko sets
    470  // start and end of Selection to points in text nodes as far as possible.
    471  range = document.createRange();
    472  range.setStart(editor.firstChild, 1);
    473  range.setEnd(editor.firstChild, 2);
    474  selection.removeAllRanges();
    475  selection.addRange(range);
    476 
    477  is(SpecialPowers.unwrap(getHTMLEditor().getSelectedElement("")),
    478     editor.firstChild.firstChild.nextSibling,
    479     "#4-1 nsIHTMLEditor::getSelectedElement(\"\") should return the first <a> element when only it is selected and matched");
    480  is(SpecialPowers.unwrap(getHTMLEditor().getSelectedElement("href")),
    481     editor.firstChild.firstChild.nextSibling,
    482     "#4-1 nsIHTMLEditor::getSelectedElement(\"href\") should return the first <a> element when only it is selected and matched");
    483  is(SpecialPowers.unwrap(getHTMLEditor().getSelectedElement("anchor")),
    484     null,
    485     "#4-1 nsIHTMLEditor::getSelectedElement(\"anchor\") should return null when the first <a> element is selected but it is unmatched");
    486  is(SpecialPowers.unwrap(getHTMLEditor().getSelectedElement("namedanchor")),
    487     null,
    488     "#4-1 nsIHTMLEditor::getSelectedElement(\"namedanchor\") should return null when the first <a> element is selected but it is unmatched");
    489 
    490  // <p><b>b1</b><a href="...">a[]1</a><a href="...">a2...
    491  range = document.createRange();
    492  range.setStart(editor.firstChild.firstChild.nextSibling.firstChild, 1);
    493  range.setEnd(editor.firstChild.firstChild.nextSibling.firstChild, 1);
    494  selection.removeAllRanges();
    495  selection.addRange(range);
    496 
    497  is(SpecialPowers.unwrap(getHTMLEditor().getSelectedElement("")),
    498     null,
    499     "#4-2 nsIHTMLEditor::getSelectedElement(\"\") should return null when Selection is collapsed");
    500  is(SpecialPowers.unwrap(getHTMLEditor().getSelectedElement("href")),
    501     editor.firstChild.firstChild.nextSibling,
    502     "#4-2 nsIHTMLEditor::getSelectedElement(\"href\") should return the first <a> element when Selection is collapsed in the element");
    503  is(SpecialPowers.unwrap(getHTMLEditor().getSelectedElement("anchor")),
    504     null,
    505     "#4-2 nsIHTMLEditor::getSelectedElement(\"anchor\") should return null when Selection is collapsed");
    506  is(SpecialPowers.unwrap(getHTMLEditor().getSelectedElement("namedanchor")),
    507     null,
    508     "#4-2 nsIHTMLEditor::getSelectedElement(\"namedanchor\") should return null when Selection is collapsed");
    509 
    510  // <p><b>b1</b><a href="...">a[1]</a><a href="...">a2...
    511  range = document.createRange();
    512  range.setStart(editor.firstChild.firstChild.nextSibling.firstChild, 1);
    513  range.setEnd(editor.firstChild.firstChild.nextSibling.firstChild, 2);
    514  selection.removeAllRanges();
    515  selection.addRange(range);
    516 
    517  is(SpecialPowers.unwrap(getHTMLEditor().getSelectedElement("")),
    518     null,
    519     "#4-3 nsIHTMLEditor::getSelectedElement(\"\") should return null when Selection is in a text node");
    520  is(SpecialPowers.unwrap(getHTMLEditor().getSelectedElement("href")),
    521     editor.firstChild.firstChild.nextSibling,
    522     "#4-3 nsIHTMLEditor::getSelectedElement(\"href\") should return the first <a> element when Selection is in the element");
    523  is(SpecialPowers.unwrap(getHTMLEditor().getSelectedElement("anchor")),
    524     null,
    525     "#4-3 nsIHTMLEditor::getSelectedElement(\"anchor\") should return null when Selection is in a text node");
    526  is(SpecialPowers.unwrap(getHTMLEditor().getSelectedElement("namedanchor")),
    527     null,
    528     "#4-3 nsIHTMLEditor::getSelectedElement(\"namedanchor\") should return null when Selection is in a text node");
    529 
    530  // <p><b>b1</b><a href="...">a[1</a><a href="...">a]2...
    531  range = document.createRange();
    532  range.setStart(editor.firstChild.firstChild.nextSibling.firstChild, 1);
    533  range.setEnd(editor.firstChild.firstChild.nextSibling.nextSibling.firstChild, 1);
    534  selection.removeAllRanges();
    535  selection.addRange(range);
    536 
    537  is(SpecialPowers.unwrap(getHTMLEditor().getSelectedElement("")),
    538     null,
    539     "#4-4 nsIHTMLEditor::getSelectedElement(\"\") should return null when Selection crosses 2 <a> elements");
    540  is(SpecialPowers.unwrap(getHTMLEditor().getSelectedElement("href")),
    541     null,
    542     "#4-4 nsIHTMLEditor::getSelectedElement(\"href\") should return null when Selection crosses 2 <a> elements");
    543  is(SpecialPowers.unwrap(getHTMLEditor().getSelectedElement("anchor")),
    544     null,
    545     "#4-4 nsIHTMLEditor::getSelectedElement(\"anchor\") should return null when Selection crosses 2 <a> elements");
    546  is(SpecialPowers.unwrap(getHTMLEditor().getSelectedElement("namedanchor")),
    547     null,
    548     "#4-4 nsIHTMLEditor::getSelectedElement(\"namedanchor\") should return null when Selection crosses 2 <a> elements");
    549 
    550  // <p><b>b1</b><a href="...">a1</a><a href="...">a2</a>{<a name="...">a3</a>}<b>b2</b></p>
    551  // Note that this won't happen with user operation since Gecko sets
    552  // start and end of Selection to points in text nodes as far as possible.
    553  range = document.createRange();
    554  range.setStart(editor.firstChild, 3);
    555  range.setEnd(editor.firstChild, 4);
    556  selection.removeAllRanges();
    557  selection.addRange(range);
    558 
    559  is(SpecialPowers.unwrap(getHTMLEditor().getSelectedElement("")),
    560     editor.firstChild.firstChild.nextSibling.nextSibling.nextSibling,
    561     "#4-5 nsIHTMLEditor::getSelectedElement(\"\") should return the third <a> element when only it is selected and matched");
    562  is(SpecialPowers.unwrap(getHTMLEditor().getSelectedElement("href")),
    563     null,
    564     "#4-5 nsIHTMLEditor::getSelectedElement(\"href\") should return null when the third <a> element is selected but it is unmatched");
    565  is(SpecialPowers.unwrap(getHTMLEditor().getSelectedElement("anchor")),
    566     editor.firstChild.firstChild.nextSibling.nextSibling.nextSibling,
    567     "#4-5 nsIHTMLEditor::getSelectedElement(\"anchor\") should return the third <a> element when only it is selected and matched");
    568  is(SpecialPowers.unwrap(getHTMLEditor().getSelectedElement("namedanchor")),
    569     null,
    570     "#4-5 nsIHTMLEditor::getSelectedElement(\"namedanchor\") should return null when the third <a> element is selected but it is unmatched");
    571 
    572  // <p><b>b1</b><a href="...">a1</a><a href="...">a2</a><a name="...">a[]3</a><b>b2</b></p>
    573  range = document.createRange();
    574  range.setStart(editor.firstChild.firstChild.nextSibling.nextSibling.nextSibling.firstChild, 1);
    575  range.setEnd(editor.firstChild.firstChild.nextSibling.nextSibling.nextSibling.firstChild, 1);
    576  selection.removeAllRanges();
    577  selection.addRange(range);
    578 
    579  is(SpecialPowers.unwrap(getHTMLEditor().getSelectedElement("")),
    580     null,
    581     "#4-6 nsIHTMLEditor::getSelectedElement(\"\") should return null when Selection is collapsed in a text node even in named anchor element");
    582  is(SpecialPowers.unwrap(getHTMLEditor().getSelectedElement("href")),
    583     null,
    584     "#4-6 nsIHTMLEditor::getSelectedElement(\"href\") should return null when Selection is collapsed in a text node even in named anchor element");
    585  is(SpecialPowers.unwrap(getHTMLEditor().getSelectedElement("anchor")),
    586     null,
    587     "#4-6 nsIHTMLEditor::getSelectedElement(\"anchor\") should return null when Selection is collapsed in a text node even in named anchor element");
    588  is(SpecialPowers.unwrap(getHTMLEditor().getSelectedElement("namedanchor")),
    589     null,
    590     "#4-6 nsIHTMLEditor::getSelectedElement(\"namedanchor\") should return null when Selection is collapsed in a text node even in named anchor element");
    591 
    592  editor.innerHTML = "<p>p1<b>b1</b>p1</p>";
    593  editor.focus();
    594 
    595  // <p>p1[<b>b1</b>]p1</p>
    596  // This is usual case that user selects <b> element with dragging or double-clicking.
    597  range = document.createRange();
    598  range.setStart(editor.firstChild.firstChild, 2);
    599  range.setEnd(editor.firstChild.firstChild.nextSibling.nextSibling, 0);
    600  selection.removeAllRanges();
    601  selection.addRange(range);
    602 
    603  is(SpecialPowers.unwrap(getHTMLEditor().getSelectedElement("")),
    604     null,
    605     "#5-1 nsIHTMLEditor::getSelectedElement(\"\") should return null even when Selection starts from end of preceding text node and ends at start or following text node of <b> element");
    606  is(SpecialPowers.unwrap(getHTMLEditor().getSelectedElement("href")),
    607     null,
    608     "#5-1 nsIHTMLEditor::getSelectedElement(\"href\") should return null even when Selection starts from end of preceding text node and ends at start or following text node of <b> element");
    609  is(SpecialPowers.unwrap(getHTMLEditor().getSelectedElement("anchor")),
    610     null,
    611     "#5-1 nsIHTMLEditor::getSelectedElement(\"anchor\") should return null even when Selection starts from end of preceding text node and ends at start or following text node of <b> element");
    612 
    613  // <p>p[1<b>b1</b>]p1</p>
    614  range = document.createRange();
    615  range.setStart(editor.firstChild.firstChild, 1);
    616  range.setEnd(editor.firstChild.firstChild.nextSibling.nextSibling, 0);
    617  selection.removeAllRanges();
    618  selection.addRange(range);
    619 
    620  is(SpecialPowers.unwrap(getHTMLEditor().getSelectedElement("")),
    621     null,
    622     "#5-2 nsIHTMLEditor::getSelectedElement(\"\") should return null when Selection ends at start of following text node of <b> element");
    623  is(SpecialPowers.unwrap(getHTMLEditor().getSelectedElement("href")),
    624     null,
    625     "#5-2 nsIHTMLEditor::getSelectedElement(\"href\") should return null when Selection ends at start of following text node of <b> element");
    626  is(SpecialPowers.unwrap(getHTMLEditor().getSelectedElement("anchor")),
    627     null,
    628     "#5-2 nsIHTMLEditor::getSelectedElement(\"anchor\") should return null when Selection ends at start of following text node of <b> element");
    629 
    630  // <p>p1[<b>b1</b>p]1</p>
    631  range = document.createRange();
    632  range.setStart(editor.firstChild.firstChild, 2);
    633  range.setEnd(editor.firstChild.firstChild.nextSibling.nextSibling, 1);
    634  selection.removeAllRanges();
    635  selection.addRange(range);
    636 
    637  is(SpecialPowers.unwrap(getHTMLEditor().getSelectedElement("")),
    638     null,
    639     "#5-3 nsIHTMLEditor::getSelectedElement(\"\") should return null when Selection starts from end of following text node of <b> element");
    640  is(SpecialPowers.unwrap(getHTMLEditor().getSelectedElement("href")),
    641     null,
    642     "#5-3 nsIHTMLEditor::getSelectedElement(\"href\") should return null when Selection starts from at end of following text node of <b> element");
    643  is(SpecialPowers.unwrap(getHTMLEditor().getSelectedElement("anchor")),
    644     null,
    645     "#5-3 nsIHTMLEditor::getSelectedElement(\"anchor\") should return null when Selection starts from end of following text node of <b> element");
    646 
    647  // <p>p1<b>[b1</b>]p1</p>
    648  range = document.createRange();
    649  range.setStart(editor.firstChild.firstChild.nextSibling.firstChild, 0);
    650  range.setEnd(editor.firstChild.firstChild.nextSibling.nextSibling, 0);
    651  selection.removeAllRanges();
    652  selection.addRange(range);
    653 
    654  is(SpecialPowers.unwrap(getHTMLEditor().getSelectedElement("")),
    655     null,
    656     "#5-4 nsIHTMLEditor::getSelectedElement(\"\") should return null when Selection starts from start of text node in <b> element and ends at start of following text node of <b> element");
    657  is(SpecialPowers.unwrap(getHTMLEditor().getSelectedElement("href")),
    658     null,
    659     "#5-4 nsIHTMLEditor::getSelectedElement(\"href\") should return null when Selection starts from start of text node in <b> element and ends at start of following text node of <b> element");
    660  is(SpecialPowers.unwrap(getHTMLEditor().getSelectedElement("anchor")),
    661     null,
    662     "#5-4 nsIHTMLEditor::getSelectedElement(\"anchor\") should return null when Selection starts from start of text node in <b> element and ends at start of following text node of <b> element");
    663 
    664  // <p>p1[<b>b1]</b>p1</p>
    665  range = document.createRange();
    666  range.setStart(editor.firstChild.firstChild, 2);
    667  range.setEnd(editor.firstChild.firstChild.nextSibling.firstChild, 2);
    668  selection.removeAllRanges();
    669  selection.addRange(range);
    670 
    671  is(SpecialPowers.unwrap(getHTMLEditor().getSelectedElement("")),
    672     null,
    673     "#5-5 nsIHTMLEditor::getSelectedElement(\"\") should return null when Selection starts from end of preceding text node of <b> element and ends at end of text node in <b> element");
    674  is(SpecialPowers.unwrap(getHTMLEditor().getSelectedElement("href")),
    675     null,
    676     "#5-5 nsIHTMLEditor::getSelectedElement(\"href\") should return null when Selection starts from end of preceding text node of <b> element and ends at end of text node in <b> element");
    677  is(SpecialPowers.unwrap(getHTMLEditor().getSelectedElement("anchor")),
    678     null,
    679     "#5-5 nsIHTMLEditor::getSelectedElement(\"anchor\") should return null when Selection starts from end of preceding text node of <b> element and ends at end of text node in <b> element");
    680 
    681  // <p>p1<b>b[1</b>}p1</p>
    682  range = document.createRange();
    683  range.setStart(editor.firstChild.firstChild.nextSibling.firstChild, 1);
    684  range.setEnd(editor.firstChild, 2);
    685  selection.removeAllRanges();
    686  selection.addRange(range);
    687 
    688  is(SpecialPowers.unwrap(getHTMLEditor().getSelectedElement("")),
    689     editor.firstChild.firstChild.nextSibling,
    690     "#5-6 nsIHTMLEditor::getSelectedElement(\"\") should the <b> element when Selection starts from in the <b> element's text node and end of preceding text node of <b> element and ends at end of the <b> element");
    691  is(SpecialPowers.unwrap(getHTMLEditor().getSelectedElement("href")),
    692     null,
    693     "#5-6 nsIHTMLEditor::getSelectedElement(\"href\") should return null when Selection starts from in the <b> element's text node and end of preceding text node of <b> element and ends at end of the <b> element");
    694  is(SpecialPowers.unwrap(getHTMLEditor().getSelectedElement("anchor")),
    695     null,
    696     "#5-6 nsIHTMLEditor::getSelectedElement(\"anchor\") should return null when Selection starts from in the <b> element's text node and end of preceding text node of <b> element and ends at end of the <b> element");
    697 
    698  editor.innerHTML = "<p>p1<b>b1</b></p>";
    699  editor.focus();
    700 
    701  // <p>p1[<b>b1</b>}</p>
    702  // This is usual case of double-clicking in the <b> element.
    703  range = document.createRange();
    704  range.setStart(editor.firstChild.firstChild, 2);
    705  range.setEnd(editor.firstChild, 2);
    706  selection.removeAllRanges();
    707  selection.addRange(range);
    708 
    709  is(SpecialPowers.unwrap(getHTMLEditor().getSelectedElement("")),
    710     null,
    711     "#6-1 nsIHTMLEditor::getSelectedElement(\"\") should return null when Selection starts from previous text node of <b> element and end at end of <b> element");
    712  is(SpecialPowers.unwrap(getHTMLEditor().getSelectedElement("href")),
    713     null,
    714     "#6-1 nsIHTMLEditor::getSelectedElement(\"href\") should return null when Selection starts from previous text node of <b> element and end at end of <b> element");
    715  is(SpecialPowers.unwrap(getHTMLEditor().getSelectedElement("anchor")),
    716     null,
    717     "#6-1 nsIHTMLEditor::getSelectedElement(\"anchor\") should return null when Selection starts from previous text node of <b> element and end at end of <b> element");
    718 
    719  editor.innerHTML = "<p><b>b1</b>p1</p>";
    720  editor.focus();
    721 
    722  // <p><b>[b1</b>]p1</p>
    723  // This is usual case of double-clicking in the <b> element.
    724  range = document.createRange();
    725  range.setStart(editor.firstChild.firstChild.firstChild, 0);
    726  range.setEnd(editor.firstChild.firstChild.nextSibling, 0);
    727  selection.removeAllRanges();
    728  selection.addRange(range);
    729 
    730  is(SpecialPowers.unwrap(getHTMLEditor().getSelectedElement("")),
    731     null,
    732     "#7-1 nsIHTMLEditor::getSelectedElement(\"\") should return null when Selection starts from a text node in <b> element and ends at start of following text node");
    733  is(SpecialPowers.unwrap(getHTMLEditor().getSelectedElement("href")),
    734     null,
    735     "#7-1 nsIHTMLEditor::getSelectedElement(\"href\") should return null when Selection starts from a text node in <b> element and ends at start of following text node");
    736  is(SpecialPowers.unwrap(getHTMLEditor().getSelectedElement("anchor")),
    737     null,
    738     "#7-1 nsIHTMLEditor::getSelectedElement(\"anchor\") should return null when Selection starts from a text node in <b> element and ends at start of following text node");
    739 
    740  editor.innerHTML = "<p>p1<b>b1</b><br></p>";
    741  editor.focus();
    742 
    743  // <p>p1[<b>b1</b>}<br></p>
    744  // This is usual case of double-clicking in the <b> element.
    745  range = document.createRange();
    746  range.setStart(editor.firstChild.firstChild, 2);
    747  range.setEnd(editor.firstChild, 2);
    748  selection.removeAllRanges();
    749  selection.addRange(range);
    750 
    751  is(SpecialPowers.unwrap(getHTMLEditor().getSelectedElement("")),
    752     null,
    753     "#8-1 nsIHTMLEditor::getSelectedElement(\"\") should return null when Selection starts from previous text node of <b> element and ends before the following <br> element");
    754  is(SpecialPowers.unwrap(getHTMLEditor().getSelectedElement("href")),
    755     null,
    756     "#8-1 nsIHTMLEditor::getSelectedElement(\"href\") should return null when Selection starts from previous text node of <b> element and ends before the following <br> element");
    757  is(SpecialPowers.unwrap(getHTMLEditor().getSelectedElement("anchor")),
    758     null,
    759     "#8-1 nsIHTMLEditor::getSelectedElement(\"anchor\") should return null when Selection starts from previous text node of <b> element and ends before the following <br> element");
    760 
    761 
    762  editor.innerHTML = "<p><b>b1</b><br></p>";
    763  editor.focus();
    764 
    765  // <p><b>[b1</b>}<br></p>
    766  // This is usual case of double-clicking in the <b> element.
    767  range = document.createRange();
    768  range.setStart(editor.firstChild.firstChild.firstChild, 0);
    769  range.setEnd(editor.firstChild, 1);
    770  selection.removeAllRanges();
    771  selection.addRange(range);
    772 
    773  is(SpecialPowers.unwrap(getHTMLEditor().getSelectedElement("")),
    774     null,
    775     "#9-1 nsIHTMLEditor::getSelectedElement(\"\") should return null when Selection starts from a text node in <b> element and ends before the following <br> element");
    776  is(SpecialPowers.unwrap(getHTMLEditor().getSelectedElement("href")),
    777     null,
    778     "#9-1 nsIHTMLEditor::getSelectedElement(\"href\") should return null when Selection starts from a text node in <b> element and ends before the following <br> element");
    779  is(SpecialPowers.unwrap(getHTMLEditor().getSelectedElement("anchor")),
    780     null,
    781     "#9-1 nsIHTMLEditor::getSelectedElement(\"anchor\") should return null when Selection starts from a text node in <b> element and ends before the following <br> element");
    782 
    783  editor.innerHTML = "<p><b>b1</b><b><br></b><b>b2</b></p>";
    784  editor.focus();
    785 
    786  // <p><b>[b1</b><b>}<br></b><b>b2</b></p>
    787  // This is usual case of double-clicking in the first <b> element.
    788  range = document.createRange();
    789  range.setStart(editor.firstChild.firstChild.firstChild, 0);
    790  range.setEnd(editor.firstChild.firstChild.nextSibling, 0);
    791  selection.removeAllRanges();
    792  selection.addRange(range);
    793 
    794  is(SpecialPowers.unwrap(getHTMLEditor().getSelectedElement("")),
    795     null,
    796     "#10-1 nsIHTMLEditor::getSelectedElement(\"\") should return null when Selection starts from a text node in <b> element and ends before the following <br> element in another <b> element");
    797  is(SpecialPowers.unwrap(getHTMLEditor().getSelectedElement("href")),
    798     null,
    799     "#10-1 nsIHTMLEditor::getSelectedElement(\"href\") should return null when Selection starts from a text node in <b> element and ends before the following <br> element in another <b> element");
    800  is(SpecialPowers.unwrap(getHTMLEditor().getSelectedElement("anchor")),
    801     null,
    802     "#10-1 nsIHTMLEditor::getSelectedElement(\"anchor\") should return null when Selection starts from a text node in <b> element and ends before the following <br> element in another <b> element");
    803 
    804  SimpleTest.finish();
    805 });
    806 
    807 function getHTMLEditor() {
    808  var Ci = SpecialPowers.Ci;
    809  var editingSession = SpecialPowers.wrap(window).docShell.editingSession;
    810  return editingSession.getEditorForWindow(window).QueryInterface(Ci.nsIHTMLEditor);
    811 }
    812 
    813 </script>
    814 </body>
    815 
    816 </html>