tor-browser

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

test_nsITableEditor_insertTableColumn.html (25538B)


      1 <!DOCTYPE>
      2 <html>
      3 <head>
      4  <title>Test for nsITableEditor.insertTableColumn()</title>
      5  <script src="/tests/SimpleTest/SimpleTest.js"></script>
      6  <link rel="stylesheet" href="/tests/SimpleTest/test.css">
      7 </head>
      8 <body>
      9 <div id="display">
     10 </div>
     11 <div id="content" contenteditable>out of table<table><tr><td>default content</td></tr></table></div>
     12 <pre id="test">
     13 </pre>
     14 
     15 <script class="testbody" type="application/javascript">
     16 "use strict";
     17 
     18 SimpleTest.waitForExplicitFinish();
     19 SimpleTest.waitForFocus(() => {
     20  let editor = document.getElementById("content");
     21  let selection = document.getSelection();
     22  let selectionRanges = [];
     23 
     24  function checkInputEvent(aEvent, aDescription) {
     25    ok(aEvent instanceof InputEvent,
     26       `"${aEvent.type}" event should be dispatched with InputEvent interface ${aDescription}`);
     27    is(aEvent.cancelable, false,
     28       `"${aEvent.type}" event should be never cancelable ${aDescription}`);
     29    is(aEvent.bubbles, true,
     30       `"${aEvent.type}" event should always bubble ${aDescription}`);
     31    is(aEvent.inputType, "",
     32       `inputType of "${aEvent.type}" event should be empty string ${aDescription}`);
     33    is(aEvent.data, null,
     34       `data of "${aEvent.type}" event should be null ${aDescription}`);
     35    is(aEvent.dataTransfer, null,
     36       `dataTransfer of "${aEvent.type}" event should be null ${aDescription}`);
     37    let targetRanges = aEvent.getTargetRanges();
     38    if (aEvent.type === "beforeinput") {
     39      is(targetRanges.length, selectionRanges.length,
     40         `getTargetRanges() of "beforeinput" event should return selection ranges ${aDescription}`);
     41      if (targetRanges.length === selectionRanges.length) {
     42        for (let i = 0; i < selectionRanges.length; i++) {
     43          is(targetRanges[i].startContainer, selectionRanges[i].startContainer,
     44             `startContainer of getTargetRanges()[${i}] of "beforeinput" event does not match ${aDescription}`);
     45          is(targetRanges[i].startOffset, selectionRanges[i].startOffset,
     46             `startOffset of getTargetRanges()[${i}] of "beforeinput" event does not match ${aDescription}`);
     47          is(targetRanges[i].endContainer, selectionRanges[i].endContainer,
     48             `endContainer of getTargetRanges()[${i}] of "beforeinput" event does not match ${aDescription}`);
     49          is(targetRanges[i].endOffset, selectionRanges[i].endOffset,
     50             `endOffset of getTargetRanges()[${i}] of "beforeinput" event does not match ${aDescription}`);
     51        }
     52      }
     53    } else {
     54      is(targetRanges.length, 0,
     55         `getTargetRanges() of "${aEvent.type}" event should return empty array ${aDescription}`);
     56    }
     57  }
     58 
     59  let beforeInputEvents = [];
     60  let inputEvents = [];
     61  function onBeforeInput(aEvent) {
     62    beforeInputEvents.push(aEvent);
     63    selectionRanges = [];
     64    for (let i = 0; i < selection.rangeCount; i++) {
     65      let range = selection.getRangeAt(i);
     66      selectionRanges.push({startContainer: range.startContainer, startOffset: range.startOffset,
     67                            endContainer: range.endContainer, endOffset: range.endOffset});
     68    }
     69  }
     70  function onInput(aEvent) {
     71    inputEvents.push(aEvent);
     72  }
     73  editor.addEventListener("beforeinput", onBeforeInput);
     74  editor.addEventListener("input", onInput);
     75 
     76  beforeInputEvents = [];
     77  inputEvents = [];
     78  selection.collapse(editor.firstChild, 0);
     79  getTableEditor().insertTableColumn(1, false);
     80  is(editor.innerHTML, "out of table<table><tbody><tr><td>default content</td></tr></tbody></table>",
     81     "nsITableEditor.insertTableColumn(1, false) should do nothing if selection is not in <table>");
     82  is(beforeInputEvents.length, 1,
     83     'beforeinput" event should be fired when a call of nsITableEditor.insertTableColumn(1, false) even though it will do nothing');
     84  checkInputEvent(beforeInputEvents[0], "when selection is collapsed outside table element (nsITableEditor.insertTableColumn(1, false))");
     85  is(inputEvents.length, 0,
     86     'No "input" event should be fired when a call of nsITableEditor.insertTableColumn(1, false) does nothing');
     87 
     88  beforeInputEvents = [];
     89  inputEvents = [];
     90  getTableEditor().insertTableColumn(1, true);
     91  is(editor.innerHTML, "out of table<table><tbody><tr><td>default content</td></tr></tbody></table>",
     92     "nsITableEditor.insertTableColumn(1, true) should do nothing if selection is not in <table>");
     93  is(beforeInputEvents.length, 1,
     94     '"beforeinput" event should be fired when a call of nsITableEditor.insertTableColumn(1, true) even though it will do nothing');
     95  checkInputEvent(beforeInputEvents[0], "when selection is collapsed outside table element (nsITableEditor.insertTableColumn(1, true))");
     96  is(inputEvents.length, 0,
     97     'No "input" event should be fired when a call of nsITableEditor.insertTableColumn(1, true) does nothing');
     98 
     99  selection.removeAllRanges();
    100  try {
    101    beforeInputEvents = [];
    102    inputEvents = [];
    103    getTableEditor().insertTableColumn(1, false);
    104    ok(false, "getTableEditor().insertTableColumn(1, false) without selection ranges should throw exception");
    105  } catch (e) {
    106    ok(true, "getTableEditor().insertTableColumn(1, false) without selection ranges should throw exception");
    107    is(beforeInputEvents.length, 0,
    108       'No "beforeinput" event should be fired when nsITableEditor.insertTableColumn(1, false) causes exception due to no selection range');
    109    is(inputEvents.length, 0,
    110       'No "input" event should be fired when nsITableEditor.insertTableColumn(1, false) causes exception due to no selection range');
    111  }
    112  try {
    113    beforeInputEvents = [];
    114    inputEvents = [];
    115    getTableEditor().insertTableColumn(1, true);
    116    ok(false, "getTableEditor().insertTableColumn(1, true) without selection ranges should throw exception");
    117  } catch (e) {
    118    ok(true, "getTableEditor().insertTableColumn(1, true) without selection ranges should throw exception");
    119    is(beforeInputEvents.length, 0,
    120       'No "beforeinput" event should be fired when nsITableEditor.insertTableColumn(1, true) causes exception due to no selection range');
    121    is(inputEvents.length, 0,
    122       'No "input" event should be fired when nsITableEditor.insertTableColumn(1, true) causes exception due to no selection range');
    123  }
    124 
    125  (function testInsertBeforeFirstColumn() {
    126    selection.removeAllRanges();
    127    editor.innerHTML =
    128      "<table>" +
    129        '<tr><td id="select">cell1-1</td><td>cell1-2</td><td>cell1-3</td></tr>' +
    130        "<tr><td>cell2-1</td><td>cell2-2</td><td>cell2-3</td></tr>" +
    131      "</table>";
    132    editor.focus();
    133    beforeInputEvents = [];
    134    inputEvents = [];
    135    selection.setBaseAndExtent(
    136      document.getElementById("select").firstChild,
    137      0,
    138      document.getElementById("select").firstChild,
    139      0
    140    );
    141    getTableEditor().insertTableColumn(1, false);
    142    is(
    143      editor.innerHTML,
    144      "<table><tbody>" +
    145        '<tr><td valign="top"><br></td><td id="select">cell1-1</td><td>cell1-2</td><td>cell1-3</td></tr>' +
    146        '<tr><td valign="top"><br></td><td>cell2-1</td><td>cell2-2</td><td>cell2-3</td></tr>' +
    147      "</tbody></table>",
    148      "testInsertBeforeFirstColumn: nsITableEditor.insertTableColumn(1, false) should insert a column before the first column"
    149    );
    150    is(
    151      beforeInputEvents.length,
    152      1,
    153      'testInsertBeforeFirstColumn: Only one "beforeinput" event should be fired'
    154    );
    155    checkInputEvent(
    156      beforeInputEvents[0],
    157      "when selection is collapsed in the first column (testInsertBeforeFirstColumn)"
    158    );
    159    is(
    160      inputEvents.length,
    161      1,
    162      'testInsertBeforeFirstColumn: Only one "input" event should be fired'
    163    );
    164    checkInputEvent(
    165      inputEvents[0],
    166      "when selection is collapsed in the first column (testInsertBeforeFirstColumn)"
    167    );
    168  })();
    169 
    170  (function testInsertAfterLastColumn() {
    171    selection.removeAllRanges();
    172    editor.innerHTML =
    173      "<table>" +
    174        '<tr><td>cell1-1</td><td>cell1-2</td><td id="select">cell1-3</td></tr>' +
    175        "<tr><td>cell2-1</td><td>cell2-2</td><td>cell2-3</td></tr>" +
    176      "</table>";
    177    editor.focus();
    178    beforeInputEvents = [];
    179    inputEvents = [];
    180    selection.setBaseAndExtent(
    181      document.getElementById("select").firstChild,
    182      0,
    183      document.getElementById("select").firstChild,
    184      0
    185    );
    186    getTableEditor().insertTableColumn(1, true);
    187    is(
    188      editor.innerHTML,
    189      "<table><tbody>" +
    190        '<tr><td>cell1-1</td><td>cell1-2</td><td id="select">cell1-3</td><td valign="top"><br></td></tr>' +
    191        '<tr><td>cell2-1</td><td>cell2-2</td><td>cell2-3</td><td valign="top"><br></td></tr>' +
    192      "</tbody></table>",
    193      "testInsertAfterLastColumn: nsITableEditor.insertTableColumn(1, true) should insert a column after the last column"
    194    );
    195    is(
    196      beforeInputEvents.length,
    197      1,
    198      'testInsertAfterLastColumn: Only one "beforeinput" event should be fired'
    199    );
    200    checkInputEvent(
    201      beforeInputEvents[0],
    202      "when selection is collapsed in the last column (testInsertAfterLastColumn)"
    203    );
    204    is(
    205      inputEvents.length,
    206      1,
    207      'testInsertAfterLastColumn: One "input" event should be fired'
    208    );
    209    checkInputEvent(
    210      inputEvents[0],
    211      "when selection is collapsed in the last column (testInsertAfterLastColumn)"
    212    );
    213  })();
    214 
    215  selection.removeAllRanges();
    216  editor.innerHTML = "<table>" +
    217                       '<tr><td>cell1-1</td><td id="select">cell1-2</td><td>cell1-3</td></tr>' +
    218                       "<tr><td>cell2-1</td><td>cell2-2</td><td>cell2-3</td></tr>" +
    219                     "</table>";
    220  editor.focus();
    221  beforeInputEvents = [];
    222  inputEvents = [];
    223  selection.setBaseAndExtent(document.getElementById("select").firstChild, 0,
    224                             document.getElementById("select").firstChild, 0);
    225  getTableEditor().insertTableColumn(1, false);
    226  is(editor.innerHTML, "<table><tbody>" +
    227                         '<tr><td>cell1-1</td><td valign="top"><br></td><td id="select">cell1-2</td><td>cell1-3</td></tr>' +
    228                         '<tr><td>cell2-1</td><td valign="top"><br></td><td>cell2-2</td><td>cell2-3</td></tr>' +
    229                       "</tbody></table>",
    230     "nsITableEditor.insertTableColumn(1, false) should insert a column to left of the second column");
    231  is(beforeInputEvents.length, 1,
    232     'Only one "beforeinput" event should be fired when selection is collapsed in a cell in second column (before)');
    233  checkInputEvent(beforeInputEvents[0], "when selection is collapsed in a cell in second column (before)");
    234  is(inputEvents.length, 1,
    235     'Only one "input" event should be fired when selection is collapsed in a cell in second column (before)');
    236  checkInputEvent(inputEvents[0], "when selection is collapsed in a cell in second column (before)");
    237 
    238  selection.removeAllRanges();
    239  editor.innerHTML = "<table>" +
    240                       '<tr><td>cell1-1</td><td id="select">cell1-2</td><td>cell1-3</td></tr>' +
    241                       "<tr><td>cell2-1</td><td>cell2-2</td><td>cell2-3</td></tr>" +
    242                     "</table>";
    243  editor.focus();
    244  beforeInputEvents = [];
    245  inputEvents = [];
    246  selection.setBaseAndExtent(document.getElementById("select").firstChild, 0,
    247                             document.getElementById("select").firstChild, 0);
    248  getTableEditor().insertTableColumn(1, true);
    249  is(editor.innerHTML, "<table><tbody>" +
    250                         '<tr><td>cell1-1</td><td id="select">cell1-2</td><td valign="top"><br></td><td>cell1-3</td></tr>' +
    251                         '<tr><td>cell2-1</td><td>cell2-2</td><td valign="top"><br></td><td>cell2-3</td></tr>' +
    252                       "</tbody></table>",
    253     "nsITableEditor.insertTableColumn(1, false) should insert a column to right of the second column");
    254  is(beforeInputEvents.length, 1,
    255     'Only one "beforeinput" event should be fired when selection is collapsed in a cell in second column (after)');
    256  checkInputEvent(beforeInputEvents[0], "when selection is collapsed in a cell in second column (after)");
    257  is(inputEvents.length, 1,
    258     'Only one "input" event should be fired when selection is collapsed in a cell in second column (after)');
    259  checkInputEvent(inputEvents[0], "when selection is collapsed in a cell in second column (after)");
    260 
    261  selection.removeAllRanges();
    262  editor.innerHTML = "<table>" +
    263                       '<tr><td>cell1-1</td><td id="select">cell1-2</td><td>cell1-3</td></tr>' +
    264                       '<tr><td colspan="2">cell2-1</td><td>cell2-3</td></tr>' +
    265                     "</table>";
    266  editor.focus();
    267  beforeInputEvents = [];
    268  inputEvents = [];
    269  selection.setBaseAndExtent(document.getElementById("select").firstChild, 0,
    270                             document.getElementById("select").firstChild, 0);
    271  getTableEditor().insertTableColumn(1, false);
    272  is(editor.innerHTML, "<table><tbody>" +
    273                         '<tr><td>cell1-1</td><td valign="top"><br></td><td id="select">cell1-2</td><td>cell1-3</td></tr>' +
    274                         '<tr><td colspan="3">cell2-1</td><td>cell2-3</td></tr>' +
    275                       "</tbody></table>",
    276     "nsITableEditor.insertTableColumn(1, false) should insert a column to left of the second column and colspan in the first column should be increased");
    277  is(beforeInputEvents.length, 1,
    278     'Only one "beforeinput" event should be fired when selection is collapsed in a cell in second column whose next row cell is col-spanned (before)');
    279  checkInputEvent(beforeInputEvents[0], "when selection is collapsed in a cell in second column whose next row cell is col-spanned (before)");
    280  is(inputEvents.length, 1,
    281     'Only one "input" event should be fired when selection is collapsed in a cell in second column whose next row cell is col-spanned (before)');
    282  checkInputEvent(inputEvents[0], "when selection is collapsed in a cell in second column whose next row cell is col-spanned (before)");
    283 
    284  selection.removeAllRanges();
    285  editor.innerHTML = "<table>" +
    286                       '<tr><td>cell1-1</td><td id="select">cell1-2</td><td>cell1-3</td></tr>' +
    287                       '<tr><td colspan="3">cell2-1</td></tr>' +
    288                     "</table>";
    289  editor.focus();
    290  beforeInputEvents = [];
    291  inputEvents = [];
    292  selection.setBaseAndExtent(document.getElementById("select").firstChild, 0,
    293                             document.getElementById("select").firstChild, 0);
    294  getTableEditor().insertTableColumn(1, true);
    295  is(editor.innerHTML, "<table><tbody>" +
    296                         '<tr><td>cell1-1</td><td id="select">cell1-2</td><td valign="top"><br></td><td>cell1-3</td></tr>' +
    297                         '<tr><td colspan="4">cell2-1</td></tr>' +
    298                       "</tbody></table>",
    299     "nsITableEditor.insertTableColumn(1, true) should insert a column to right of the second column and colspan in the first column should be increased");
    300  is(beforeInputEvents.length, 1,
    301     'Only one "beforeinput" event should be fired when selection is collapsed in a cell in second column whose next row cell is col-spanned (after)');
    302  checkInputEvent(beforeInputEvents[0], "when selection is collapsed in a cell in second column whose next row cell is col-spanned (after)");
    303  is(inputEvents.length, 1,
    304     'Only one "input" event should be fired when selection is collapsed in a cell in second column whose next row cell is col-spanned (after)');
    305  checkInputEvent(inputEvents[0], "when selection is collapsed in a cell in second column whose next row cell is col-spanned (after)");
    306 
    307  selection.removeAllRanges();
    308  editor.innerHTML = "<table>" +
    309                       "<tr><td>cell1-1</td><td>cell1-2</td><td>cell1-3</td></tr>" +
    310                       '<tr><td id="select" colspan="2">cell2-1</td><td>cell2-3</td></tr>' +
    311                     "</table>";
    312  editor.focus();
    313  beforeInputEvents = [];
    314  inputEvents = [];
    315  selection.setBaseAndExtent(document.getElementById("select").firstChild, 0,
    316                             document.getElementById("select").firstChild, 1);
    317  getTableEditor().insertTableColumn(2, false);
    318  is(editor.innerHTML, "<table><tbody>" +
    319                         '<tr><td valign="top"><br></td><td valign="top"><br></td><td>cell1-1</td><td>cell1-2</td><td>cell1-3</td></tr>' +
    320                         '<tr><td valign="top"><br></td><td valign="top"><br></td><td id="select" colspan="2">cell2-1</td><td>cell2-3</td></tr>' +
    321                       "</tbody></table>",
    322     "nsITableEditor.insertTableColumn(2, false) should insert 2 columns to left of the first column");
    323  is(beforeInputEvents.length, 1,
    324     'Only one "beforeinput" event should be fired when selection is collapsed in a cell which is col-spanning (before)');
    325  checkInputEvent(beforeInputEvents[0], "when selection is collapsed in a cell which is col-spanning (before)");
    326  is(inputEvents.length, 1,
    327     'Only one "input" event should be fired when selection is collapsed in a cell which is col-spanning (before)');
    328  checkInputEvent(inputEvents[0], "when selection is collapsed in a cell which is col-spanning (before)");
    329 
    330  selection.removeAllRanges();
    331  editor.innerHTML = "<table>" +
    332                       "<tr><td>cell1-1</td><td>cell1-2</td><td>cell1-3</td></tr>" +
    333                       '<tr><td id="select" colspan="2">cell2-1</td><td>cell2-3</td></tr>' +
    334                     "</table>";
    335  editor.focus();
    336  beforeInputEvents = [];
    337  inputEvents = [];
    338  selection.setBaseAndExtent(document.getElementById("select").firstChild, 0,
    339                             document.getElementById("select").firstChild, 1);
    340  getTableEditor().insertTableColumn(2, true);
    341  is(editor.innerHTML, "<table><tbody>" +
    342                         '<tr><td>cell1-1</td><td>cell1-2</td><td valign="top"><br></td><td valign="top"><br></td><td>cell1-3</td></tr>' +
    343                         '<tr><td id="select" colspan="2">cell2-1</td><td valign="top"><br></td><td valign="top"><br></td><td>cell2-3</td></tr>' +
    344                       "</tbody></table>",
    345     "nsITableEditor.insertTableColumn(2, false) should insert 2 columns to right of the second column (i.e., right of the right-most column of the column-spanning cell");
    346  is(beforeInputEvents.length, 1,
    347     'Only one "beforeinput" event should be fired when selection is collapsed in a cell which is col-spanning (after)');
    348  checkInputEvent(beforeInputEvents[0], "when selection is collapsed in a cell which is col-spanning (after)");
    349  is(inputEvents.length, 1,
    350     'Only one "input" event should be fired when selection is collapsed in a cell which is col-spanning (after)');
    351  checkInputEvent(inputEvents[0], "when selection is collapsed in a cell which is col-spanning (after)");
    352 
    353  (function testInsertBeforeFirstColumnFollowingTextNode() {
    354    selection.removeAllRanges();
    355    editor.innerHTML =
    356      "<table>" +
    357        '<tr> <td id="select">cell1-1</td><td>cell1-2</td><td>cell1-3</td> </tr>' +
    358        "<tr> <td>cell2-1</td><td>cell2-2</td><td>cell2-3</td> </tr>" +
    359      "</table>";
    360    editor.focus();
    361    beforeInputEvents = [];
    362    inputEvents = [];
    363    selection.setBaseAndExtent(
    364      document.getElementById("select").firstChild,
    365      0,
    366      document.getElementById("select").firstChild,
    367      0
    368    );
    369    getTableEditor().insertTableColumn(1, false);
    370    is(
    371      editor.innerHTML,
    372      "<table><tbody>" +
    373        '<tr> <td valign="top"><br></td><td id="select">cell1-1</td><td>cell1-2</td><td>cell1-3</td> </tr>' +
    374        '<tr> <td valign="top"><br></td><td>cell2-1</td><td>cell2-2</td><td>cell2-3</td> </tr>' +
    375      "</tbody></table>",
    376      "testInsertBeforeFirstColumnFollowingTextNode: nsITableEditor.insertTableColumn(1, false) should insert a column before the first column"
    377    );
    378    is(
    379      beforeInputEvents.length,
    380      1,
    381      'testInsertBeforeFirstColumnFollowingTextNode: Only one "beforeinput" event should be fired'
    382    );
    383    checkInputEvent(
    384      beforeInputEvents[0],
    385      "when selection is collapsed in the first column (testInsertBeforeFirstColumnFollowingTextNode)"
    386    );
    387    is(
    388      inputEvents.length,
    389      1,
    390      'testInsertBeforeFirstColumnFollowingTextNode: Only one "input" event should be fired'
    391    );
    392    checkInputEvent(
    393      inputEvents[0],
    394      "when selection is collapsed in the first column (testInsertBeforeFirstColumnFollowingTextNode)"
    395    );
    396  })();
    397 
    398  (function testInsertAfterLastColumnFollowedByTextNode() {
    399    selection.removeAllRanges();
    400    editor.innerHTML =
    401      "<table>" +
    402        '<tr> <td>cell1-1</td><td>cell1-2</td><td id="select">cell1-3</td> </tr>' +
    403        "<tr> <td>cell2-1</td><td>cell2-2</td><td>cell2-3</td> </tr>" +
    404      "</table>";
    405    editor.focus();
    406    beforeInputEvents = [];
    407    inputEvents = [];
    408    selection.setBaseAndExtent(
    409      document.getElementById("select").firstChild,
    410      0,
    411      document.getElementById("select").firstChild,
    412      0
    413    );
    414    getTableEditor().insertTableColumn(1, true);
    415    is(
    416      editor.innerHTML,
    417      "<table><tbody>" +
    418        '<tr> <td>cell1-1</td><td>cell1-2</td><td id="select">cell1-3</td><td valign="top"><br></td> </tr>' +
    419        '<tr> <td>cell2-1</td><td>cell2-2</td><td>cell2-3</td><td valign="top"><br></td> </tr>' +
    420      "</tbody></table>",
    421      "testInsertAfterLastColumnFollowedByTextNode: nsITableEditor.insertTableColumn(1, true) should insert a column after the last column"
    422    );
    423    is(
    424      beforeInputEvents.length,
    425      1,
    426      'testInsertAfterLastColumnFollowedByTextNode: Only one "beforeinput" event should be fired'
    427    );
    428    checkInputEvent(
    429      beforeInputEvents[0],
    430      "when selection is collapsed in the last column (testInsertAfterLastColumnFollowedByTextNode)"
    431    );
    432    is(
    433      inputEvents.length,
    434      1,
    435      'testInsertAfterLastColumnFollowedByTextNode: One "input" event should be fired'
    436    );
    437    checkInputEvent(
    438      inputEvents[0],
    439      "when selection is collapsed in the last column (testInsertAfterLastColumnFollowedByTextNode)"
    440    );
    441  })();
    442 
    443  (function testInsertBeforeColumnFollowingTextNode() {
    444    selection.removeAllRanges();
    445    editor.innerHTML =
    446      "<table>" +
    447        '<tr><td>cell1-1</td> <td id="select">cell1-2</td> <td>cell1-3</td></tr>' +
    448        "<tr><td>cell2-1</td> <td>cell2-2</td> <td>cell2-3</td></tr>" +
    449      "</table>";
    450    editor.focus();
    451    beforeInputEvents = [];
    452    inputEvents = [];
    453    selection.setBaseAndExtent(
    454      document.getElementById("select").firstChild,
    455      0,
    456      document.getElementById("select").firstChild,
    457      0
    458    );
    459    getTableEditor().insertTableColumn(1, false);
    460    is(
    461      editor.innerHTML,
    462      "<table><tbody>" +
    463        '<tr><td>cell1-1</td> <td valign="top"><br></td><td id="select">cell1-2</td> <td>cell1-3</td></tr>' +
    464        '<tr><td>cell2-1</td> <td valign="top"><br></td><td>cell2-2</td> <td>cell2-3</td></tr>' +
    465      "</tbody></table>",
    466      "testInsertBeforeColumnFollowingTextNode: nsITableEditor.insertTableColumn(1, false) should insert a column before the first column"
    467    );
    468    is(
    469      beforeInputEvents.length,
    470      1,
    471      'testInsertBeforeColumnFollowingTextNode: Only one "beforeinput" event should be fired'
    472    );
    473    checkInputEvent(
    474      beforeInputEvents[0],
    475      "when selection is collapsed in the column following a text node (testInsertBeforeColumnFollowingTextNode)"
    476    );
    477    is(
    478      inputEvents.length,
    479      1,
    480      'testInsertBeforeColumnFollowingTextNode: Only one "input" event should be fired'
    481    );
    482    checkInputEvent(
    483      inputEvents[0],
    484      "when selection is collapsed in the column following a text node (testInsertBeforeColumnFollowingTextNode)"
    485    );
    486  })();
    487 
    488  (function testInsertAfterColumnFollowedByTextNode() {
    489    selection.removeAllRanges();
    490    editor.innerHTML =
    491      "<table>" +
    492        '<tr><td>cell1-1</td> <td id="select">cell1-2</td> <td>cell1-3</td></tr>' +
    493        "<tr><td>cell2-1</td> <td>cell2-2</td> <td>cell2-3</td></tr>" +
    494      "</table>";
    495    editor.focus();
    496    beforeInputEvents = [];
    497    inputEvents = [];
    498    selection.setBaseAndExtent(
    499      document.getElementById("select").firstChild,
    500      0,
    501      document.getElementById("select").firstChild,
    502      0
    503    );
    504    getTableEditor().insertTableColumn(1, true);
    505    is(
    506      editor.innerHTML,
    507      "<table><tbody>" +
    508        '<tr><td>cell1-1</td> <td id="select">cell1-2</td><td valign="top"><br></td> <td>cell1-3</td></tr>' +
    509        '<tr><td>cell2-1</td> <td>cell2-2</td><td valign="top"><br></td> <td>cell2-3</td></tr>' +
    510      "</tbody></table>",
    511      "testInsertAfterColumnFollowedByTextNode: nsITableEditor.insertTableColumn(1, true) should insert a column before the first column"
    512    );
    513    is(
    514      beforeInputEvents.length,
    515      1,
    516      'testInsertAfterColumnFollowedByTextNode: Only one "beforeinput" event should be fired'
    517    );
    518    checkInputEvent(
    519      beforeInputEvents[0],
    520      "when selection is collapsed in the column followed by a text node (testInsertAfterColumnFollowedByTextNode)"
    521    );
    522    is(
    523      inputEvents.length,
    524      1,
    525      'testInsertAfterColumnFollowedByTextNode: Only one "input" event should be fired'
    526    );
    527    checkInputEvent(
    528      inputEvents[0],
    529      "when selection is collapsed in the column followed by a text node (testInsertAfterColumnFollowedByTextNode)"
    530    );
    531  })();
    532 
    533  editor.removeEventListener("beforeinput", onBeforeInput);
    534  editor.removeEventListener("input", onInput);
    535 
    536  SimpleTest.finish();
    537 });
    538 
    539 function getTableEditor() {
    540  var editingSession = SpecialPowers.wrap(window).docShell.editingSession;
    541  return editingSession.getEditorForWindow(window).QueryInterface(SpecialPowers.Ci.nsITableEditor);
    542 }
    543 
    544 </script>
    545 </body>
    546 
    547 </html>