4 <title>Test for nsITableEditor.insertTableCell()
</title>
5 <script src=
"/tests/SimpleTest/SimpleTest.js"></script>
6 <link rel=
"stylesheet" href=
"/tests/SimpleTest/test.css">
11 <div id=
"content" contenteditable
>out of table
<table><tr><td>default content
</td></tr></table></div>
15 <script class=
"testbody" type=
"application/javascript">
18 SimpleTest.waitForExplicitFinish();
19 SimpleTest.waitForFocus(() =
> {
20 let editor = document.getElementById(
"content");
21 let selection = document.getSelection();
22 let selectionRanges = [];
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}`);
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}`);
54 is(targetRanges.length,
0,
55 `getTargetRanges() of
"${aEvent.type}" event should return empty array ${aDescription}`);
59 let beforeInputEvents = [];
61 function onBeforeInput(aEvent) {
62 beforeInputEvents.push(aEvent);
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});
70 function onInput(aEvent) {
71 inputEvents.push(aEvent);
73 editor.addEventListener(
"beforeinput", onBeforeInput);
74 editor.addEventListener(
"input", onInput);
76 beforeInputEvents = [];
78 selection.collapse(editor.firstChild,
0);
79 getTableEditor().insertTableCell(
1, false);
80 is(editor.innerHTML,
"out of table<table><tbody><tr><td>default content</td></tr></tbody></table>",
81 "nsITableEditor.insertTableCell(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.insertTableCell(
1, false) even though it will do nothing');
84 checkInputEvent(beforeInputEvents[
0],
"when selection collapsed outside table element (nsITableEditor.insertTableCell(1, false))");
85 is(inputEvents.length,
0,
86 'No
"input" event should be fired when a call of nsITableEditor.insertTableCell(
1, false) does nothing');
88 beforeInputEvents = [];
90 getTableEditor().insertTableCell(
1, true);
91 is(editor.innerHTML,
"out of table<table><tbody><tr><td>default content</td></tr></tbody></table>",
92 "nsITableEditor.insertTableCell(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.insertTableCell(
1, true) even though it will do nothing');
95 checkInputEvent(beforeInputEvents[
0],
"when selection is collapsed outside table element (nsITableEditor.insertTableCell(1, true))");
96 is(inputEvents.length,
0,
97 'No
"input" event should be fired when a call of nsITableEditor.insertTableCell(
1, true) does nothing');
99 selection.removeAllRanges();
101 beforeInputEvents = [];
103 getTableEditor().insertTableCell(
1, false);
104 ok(false,
"getTableEditor().insertTableCell(1, false) without selection ranges should throw exception");
106 ok(true,
"getTableEditor().insertTableCell(1, false) without selection ranges should throw exception");
107 is(beforeInputEvents.length,
0,
108 'No
"beforeinput" event should be fired when nsITableEditor.insertTableCell(
1, false) causes exception due to no selection range');
109 is(inputEvents.length,
0,
110 'No
"input" event should be fired when nsITableEditor.insertTableCell(
1, false) causes exception due to no selection range');
113 beforeInputEvents = [];
115 getTableEditor().insertTableCell(
1, true);
116 ok(false,
"getTableEditor().insertTableCell(1, true) without selection ranges should throw exception");
118 ok(true,
"getTableEditor().insertTableCell(1, true) without selection ranges should throw exception");
119 is(beforeInputEvents.length,
0,
120 'No
"beforeinput" event should be fired when nsITableEditor.insertTableCell(
1, true) causes exception due to no selection range');
121 is(inputEvents.length,
0,
122 'No
"input" event should be fired when nsITableEditor.insertTableCell(
1, true) causes exception due to no selection range');
125 (function testInsertZeroCellsBefore() {
126 selection.removeAllRanges();
129 "<tr><td>cell1-1</td><td>cell1-2</td></tr>" +
130 '
<tr><td id=
"select">cell2-
1</td><td>cell2-
2</td></tr>' +
131 "<tr><td>cell3-1</td><td>cell3-2</td></tr>" +
134 beforeInputEvents = [];
136 selection.setBaseAndExtent(
137 document.getElementById(
"select").firstChild,
139 document.getElementById(
"select").firstChild,
142 getTableEditor().insertTableCell(
0, false);
146 "<tr><td>cell1-1</td><td>cell1-2</td></tr>" +
147 '
<tr><td id=
"select">cell2-
1</td><td>cell2-
2</td></tr>' +
148 "<tr><td>cell3-1</td><td>cell3-2</td></tr>" +
150 "testInsertZeroCellsBefore: nsITableEditor.insertTableCell(0, false) should do nothing without throwing exception"
153 beforeInputEvents.length,
155 'testInsertZeroCellsBefore: No
"beforeinput" event should be fired'
160 'testInsertZeroCellsBefore: No
"input" event should be fired'
164 (function testInsertZeroCellsAfter() {
165 selection.removeAllRanges();
168 "<tr><td>cell1-1</td><td>cell1-2</td></tr>" +
169 '
<tr><td id=
"select">cell2-
1</td><td>cell2-
2</td></tr>' +
170 "<tr><td>cell3-1</td><td>cell3-2</td></tr>" +
173 beforeInputEvents = [];
175 selection.setBaseAndExtent(
176 document.getElementById(
"select").firstChild,
178 document.getElementById(
"select").firstChild,
181 getTableEditor().insertTableCell(
0, true);
185 "<tr><td>cell1-1</td><td>cell1-2</td></tr>" +
186 '
<tr><td id=
"select">cell2-
1</td><td>cell2-
2</td></tr>' +
187 "<tr><td>cell3-1</td><td>cell3-2</td></tr>" +
189 "testInsertZeroCellsAfter: nsITableEditor.insertTableCell(0, true) should do nothing without throwing exception"
192 beforeInputEvents.length,
194 'testInsertZeroCellsAfter: No
"beforeinput" event should be fired'
199 'testInsertZeroCellsAfter: No
"input" event should be fired'
203 selection.removeAllRanges();
204 editor.innerHTML =
"<table>" +
205 "<tr><td>cell1-1</td><td>cell1-2</td></tr>" +
206 '
<tr><td id=
"select">cell2-
1</td><td>cell2-
2</td></tr>' +
207 "<tr><td>cell3-1</td><td>cell3-2</td></tr>" +
210 beforeInputEvents = [];
212 selection.setBaseAndExtent(document.getElementById(
"select").firstChild,
0,
213 document.getElementById(
"select").firstChild,
0);
214 getTableEditor().insertTableCell(
1, false);
215 is(editor.innerHTML,
"<table><tbody>" +
216 "<tr><td>cell1-1</td><td>cell1-2</td></tr>" +
217 '
<tr><td valign=
"top"><br></td><td id=
"select">cell2-
1</td><td>cell2-
2</td></tr>' +
218 "<tr><td>cell3-1</td><td>cell3-2</td></tr>" +
220 "nsITableEditor.insertTableCell(1, false) should insert a cell before the cell containing selection");
221 is(beforeInputEvents.length,
1,
222 'Only one
"beforeinput" event should be fired when selection collapsed in a cell in middle row (before)');
223 checkInputEvent(beforeInputEvents[
0],
"when selection collapsed in a cell in middle row (before)");
224 is(inputEvents.length,
1,
225 'Only one
"input" event should be fired when selection collapsed in a cell in middle row (before)');
226 checkInputEvent(inputEvents[
0],
"when selection collapsed in a cell in middle row (before)");
228 selection.removeAllRanges();
229 editor.innerHTML =
"<table>" +
230 "<tr><td>cell1-1</td><td>cell1-2</td></tr>" +
231 '
<tr><td id=
"select">cell2-
1</td><td>cell2-
2</td></tr>' +
232 "<tr><td>cell3-1</td><td>cell3-2</td></tr>" +
235 beforeInputEvents = [];
237 selection.setBaseAndExtent(document.getElementById(
"select").firstChild,
0,
238 document.getElementById(
"select").firstChild,
0);
239 getTableEditor().insertTableCell(
1, true);
240 is(editor.innerHTML,
"<table><tbody>" +
241 "<tr><td>cell1-1</td><td>cell1-2</td></tr>" +
242 '
<tr><td id=
"select">cell2-
1</td><td valign=
"top"><br></td><td>cell2-
2</td></tr>' +
243 "<tr><td>cell3-1</td><td>cell3-2</td></tr>" +
245 "nsITableEditor.insertTableCell(1, true) should insert a cell after the cell containing selection");
246 is(beforeInputEvents.length,
1,
247 'Only one
"beforeinput" event should be fired when selection collapsed in a cell in middle row (after)');
248 checkInputEvent(beforeInputEvents[
0],
"when selection collapsed in a cell in middle row (after)");
249 is(inputEvents.length,
1,
250 'Only one
"input" event should be fired when selection collapsed in a cell in middle row (after)');
251 checkInputEvent(inputEvents[
0],
"when selection collapsed in a cell in middle row (after)");
253 (function testInsertBeforeCellFollowingTextNode() {
254 selection.removeAllRanges();
257 "<tr><td>cell1-1</td> <td>cell1-2</td> <td>cell1-3</td></tr>" +
258 '
<tr><td>cell2-
1</td> <td id=
"select">cell2-
2</td> <td>cell2-
3</tr>' +
259 "<tr><td>cell3-1</td> <td>cell3-2</td> <td>cell3-3</td></tr>" +
262 beforeInputEvents = [];
264 selection.setBaseAndExtent(
265 document.getElementById(
"select").firstChild,
267 document.getElementById(
"select").firstChild,
270 getTableEditor().insertTableCell(
1, false);
274 "<tr><td>cell1-1</td> <td>cell1-2</td> <td>cell1-3</td></tr>" +
275 '
<tr><td>cell2-
1</td> <td valign=
"top"><br></td><td id=
"select">cell2-
2</td> <td>cell2-
3</td></tr>' +
276 "<tr><td>cell3-1</td> <td>cell3-2</td> <td>cell3-3</td></tr>" +
278 "testInsertBeforeCellFollowingTextNode: nsITableEditor.insertTableCell(1, false) should insert a cell before the cell containing selection"
281 beforeInputEvents.length,
283 'testInsertBeforeCellFollowingTextNode: Only one
"beforeinput" event should be fired'
286 beforeInputEvents[
0],
287 "when selection collapsed in a cell following a text node (testInsertBeforeCellFollowingTextNode)"
292 'testInsertBeforeCellFollowingTextNode: Only one
"input" event should be fired'
296 "when selection collapsed in a cell following a text node (testInsertBeforeCellFollowingTextNode)"
300 (function testInsertAfterCellFollowedByTextNode() {
301 selection.removeAllRanges();
304 "<tr><td>cell1-1</td> <td>cell1-2</td> <td>cell1-3</td></tr>" +
305 '
<tr><td>cell2-
1</td> <td id=
"select">cell2-
2</td> <td>cell2-
3</tr>' +
306 "<tr><td>cell3-1</td> <td>cell3-2</td> <td>cell3-3</td></tr>" +
309 beforeInputEvents = [];
311 selection.setBaseAndExtent(
312 document.getElementById(
"select").firstChild,
314 document.getElementById(
"select").firstChild,
317 getTableEditor().insertTableCell(
1, true);
321 "<tr><td>cell1-1</td> <td>cell1-2</td> <td>cell1-3</td></tr>" +
322 '
<tr><td>cell2-
1</td> <td id=
"select">cell2-
2</td><td valign=
"top"><br></td> <td>cell2-
3</td></tr>' +
323 "<tr><td>cell3-1</td> <td>cell3-2</td> <td>cell3-3</td></tr>" +
325 "testInsertAfterCellFollowedByTextNode: nsITableEditor.insertTableCell(1, true) should insert a cell after the cell containing selection"
328 beforeInputEvents.length,
330 'testInsertAfterCellFollowedByTextNode: Only one
"beforeinput" event should be fired'
333 beforeInputEvents[
0],
334 "when selection collapsed in a cell followed by a text node (testInsertAfterCellFollowedByTextNode)"
339 'testInsertAfterCellFollowedByTextNode: Only one
"input" event should be fired'
343 "when selection collapsed in a cell followed by a text node (testInsertAfterCellFollowedByTextNode)"
349 // Odd case. This puts the cell containing selection moves right of row-spanning cell.
350 selection.removeAllRanges();
351 editor.innerHTML =
"<table>" +
352 '
<tr><td>cell1-
1</td><td rowspan=
"2">cell1-
2</td></tr>' +
353 '
<tr><td id=
"select">cell2-
1</td></tr>' +
354 "<tr><td>cell3-1</td><td>cell3-2</td></tr>" +
357 beforeInputEvents = [];
359 selection.setBaseAndExtent(document.getElementById(
"select").firstChild,
0,
360 document.getElementById(
"select").firstChild,
0);
361 getTableEditor().insertTableCell(
1, false);
362 is(editor.innerHTML,
"<table><tbody>" +
363 '
<tr><td>cell1-
1</td><td rowspan=
"2">cell1-
2</td></tr>' +
364 '
<tr><td valign=
"top"><br></td><td id=
"select">cell2-
1</td></tr>' +
365 "<tr><td>cell3-1</td><td>cell3-2</td></tr>" +
367 "nsITableEditor.insertTableCell(1, false) should insert a cell before the cell containing selection and moves the cell to right of the row-spanning cell element");
368 is(beforeInputEvents.length,
1,
369 'Only one
"beforeinput" event should be fired when selection collapsed in a cell in middle row and it has row-spanned cell (before)');
370 checkInputEvent(beforeInputEvents[
0],
"when selection collapsed in a cell in middle row and it has row-spanned cell (before)");
371 is(inputEvents.length,
1,
372 'Only one
"input" event should be fired when selection collapsed in a cell in middle row and it has row-spanned cell (before)');
373 checkInputEvent(inputEvents[
0],
"when selection collapsed in a cell in middle row and it has row-spanned cell (before)");
375 selection.removeAllRanges();
376 editor.innerHTML =
"<table>" +
377 '
<tr><td>cell1-
1</td><td rowspan=
"3">cell1-
2</td></tr>' +
378 '
<tr><td id=
"select">cell2-
1</td></tr>' +
379 "<tr><td>cell3-1</td></tr>" +
382 beforeInputEvents = [];
384 selection.setBaseAndExtent(document.getElementById(
"select").firstChild,
0,
385 document.getElementById(
"select").firstChild,
0);
386 getTableEditor().insertTableCell(
1, true);
387 is(editor.innerHTML,
"<table><tbody>" +
388 '
<tr><td>cell1-
1</td><td rowspan=
"3">cell1-
2</td></tr>' +
389 '
<tr><td id=
"select">cell2-
1</td><td valign=
"top"><br></td></tr>' +
390 "<tr><td>cell3-1</td></tr>" +
392 "nsITableEditor.insertTableCell(1, true) should insert a cell after the cell containing selection and moves the cell to right of the row-spanning cell element");
393 is(beforeInputEvents.length,
1,
394 'Only one
"beforeinput" event should be fired when selection collapsed in a cell in middle row and it has row-spanned cell (after)');
395 checkInputEvent(beforeInputEvents[
0],
"when selection collapsed in a cell in middle row and it has row-spanned cell (after)");
396 is(inputEvents.length,
1,
397 'Only one
"input" event should be fired when selection collapsed in a cell in middle row and it has row-spanned cell (after)');
398 checkInputEvent(inputEvents[
0],
"when selection collapsed in a cell in middle row and it has row-spanned cell (after)");
400 selection.removeAllRanges();
401 editor.innerHTML =
"<table>" +
402 '
<tr><td>cell1-
1</td><td id=
"select" rowspan=
"2">cell1-
2</td></tr>' +
403 "<tr><td>cell2-1</td></tr>" +
404 "<tr><td>cell3-1</td><td>cell3-2</td></tr>" +
407 beforeInputEvents = [];
409 selection.setBaseAndExtent(document.getElementById(
"select").firstChild,
0,
410 document.getElementById(
"select").firstChild,
1);
411 getTableEditor().insertTableCell(
2, false);
412 is(editor.innerHTML,
"<table><tbody>" +
413 '
<tr><td>cell1-
1</td><td valign=
"top"><br></td><td valign=
"top"><br></td><td id=
"select" rowspan=
"2">cell1-
2</td></tr>' +
414 "<tr><td>cell2-1</td></tr>" +
415 "<tr><td>cell3-1</td><td>cell3-2</td></tr>" +
417 "nsITableEditor.insertTableCell(2, false) should insert 2 cells before the row-spanning cell containing selection");
418 is(beforeInputEvents.length,
1,
419 'Only one
"beforeinput" event should be fired when selection collapsed in a cell in row-spanning (before)');
420 checkInputEvent(beforeInputEvents[
0],
"when selection collapsed in a cell in row-spanning (before)");
421 is(inputEvents.length,
1,
422 'Only one
"input" event should be fired when selection collapsed in a cell in row-spanning (before)');
423 checkInputEvent(inputEvents[
0],
"when selection collapsed in a cell in row-spanning (before)");
425 selection.removeAllRanges();
426 editor.innerHTML =
"<table>" +
427 '
<tr><td>cell1-
1</td><td id=
"select" rowspan=
"2">cell1-
2</td></tr>' +
428 "<tr><td>cell2-1</td></tr>" +
429 "<tr><td>cell3-1</td><td>cell3-2</td></tr>" +
432 beforeInputEvents = [];
434 selection.setBaseAndExtent(document.getElementById(
"select").firstChild,
0,
435 document.getElementById(
"select").firstChild,
1);
436 getTableEditor().insertTableCell(
2, true);
437 is(editor.innerHTML,
"<table><tbody>" +
438 '
<tr><td>cell1-
1</td><td id=
"select" rowspan=
"2">cell1-
2</td><td valign=
"top"><br></td><td valign=
"top"><br></td></tr>' +
439 "<tr><td>cell2-1</td></tr>" +
440 "<tr><td>cell3-1</td><td>cell3-2</td></tr>" +
442 "nsITableEditor.insertTableCell(2, false) should insert 2 cells after the row-spanning cell containing selection");
443 is(beforeInputEvents.length,
1,
444 'Only one
"beforeinput" event should be fired when selection collapsed in a cell in row-spanning (after)');
445 checkInputEvent(beforeInputEvents[
0],
"when selection collapsed in a cell in row-spanning (after)");
446 is(inputEvents.length,
1,
447 'Only one
"input" event should be fired when selection collapsed in a cell in row-spanning (after)');
448 checkInputEvent(inputEvents[
0],
"when selection collapsed in a cell in row-spanning (after)");
452 selection.removeAllRanges();
453 editor.innerHTML =
"<table>" +
454 '
<tr><td>cell1-
1</td><td id=
"select">cell1-
2</td><td>cell1-
3</td></tr>' +
455 '
<tr><td colspan=
"2">cell2-
1</td><td>cell2-
3</td></tr>' +
458 beforeInputEvents = [];
460 selection.setBaseAndExtent(document.getElementById(
"select").firstChild,
0,
461 document.getElementById(
"select").firstChild,
0);
462 getTableEditor().insertTableCell(
1, false);
463 is(editor.innerHTML,
"<table><tbody>" +
464 '
<tr><td>cell1-
1</td><td valign=
"top"><br></td><td id=
"select">cell1-
2</td><td>cell1-
3</td></tr>' +
465 '
<tr><td colspan=
"2">cell2-
1</td><td>cell2-
3</td></tr>' +
467 "nsITableEditor.insertTableCell(1, false) should insert a cell before the cell containing selection but do not modify col-spanning cell");
468 is(beforeInputEvents.length,
1,
469 'Only one
"beforeinput" event should be fired when selection collapsed in a cell whose next row cell is col-spanned (before)');
470 checkInputEvent(beforeInputEvents[
0],
"when selection collapsed in a cell whose next row cell is col-spanned (before)");
471 is(inputEvents.length,
1,
472 'Only one
"input" event should be fired when selection collapsed in a cell whose next row cell is col-spanned (before)');
473 checkInputEvent(inputEvents[
0],
"when selection collapsed in a cell whose next row cell is col-spanned (before)");
475 selection.removeAllRanges();
476 editor.innerHTML =
"<table>" +
477 '
<tr><td>cell1-
1</td><td id=
"select">cell1-
2</td><td>cell1-
3</td></tr>' +
478 '
<tr><td colspan=
"3">cell2-
1</td></tr>' +
481 beforeInputEvents = [];
483 selection.setBaseAndExtent(document.getElementById(
"select").firstChild,
0,
484 document.getElementById(
"select").firstChild,
0);
485 getTableEditor().insertTableCell(
1, true);
486 is(editor.innerHTML,
"<table><tbody>" +
487 '
<tr><td>cell1-
1</td><td id=
"select">cell1-
2</td><td valign=
"top"><br></td><td>cell1-
3</td></tr>' +
488 '
<tr><td colspan=
"3">cell2-
1</td></tr>' +
490 "nsITableEditor.insertTableCell(1, true) should insert a cell after the cell containing selection but do not modify col-spanning cell");
491 is(beforeInputEvents.length,
1,
492 'Only one
"beforeinput" event should be fired when selection collapsed in a cell whose next row cell is col-spanned (after)');
493 checkInputEvent(beforeInputEvents[
0],
"when selection collapsed in a cell whose next row cell is col-spanned (after)");
494 is(inputEvents.length,
1,
495 'Only one
"input" event should be fired when selection collapsed in a cell whose next row cell is col-spanned (after)');
496 checkInputEvent(inputEvents[
0],
"when selection collapsed in a cell whose next row cell is col-spanned (after)");
498 selection.removeAllRanges();
499 editor.innerHTML =
"<table>" +
500 "<tr><td>cell1-1</td><td>cell1-2</td><td>cell1-3</td></tr>" +
501 '
<tr><td id=
"select" colspan=
"2">cell2-
1</td><td>cell2-
3</td></tr>' +
504 beforeInputEvents = [];
506 selection.setBaseAndExtent(document.getElementById(
"select").firstChild,
0,
507 document.getElementById(
"select").firstChild,
1);
508 getTableEditor().insertTableCell(
2, false);
509 is(editor.innerHTML,
"<table><tbody>" +
510 "<tr><td>cell1-1</td><td>cell1-2</td><td>cell1-3</td></tr>" +
511 '
<tr><td valign=
"top"><br></td><td valign=
"top"><br></td><td id=
"select" colspan=
"2">cell2-
1</td><td>cell2-
3</td></tr>' +
513 "nsITableEditor.insertTableCell(2, false) should insert 2 cells before the col-spanning cell containing selection");
514 is(beforeInputEvents.length,
1,
515 'Only one
"beforeinput" event should be fired when selection collapsed in a cell which is col-spanning (before)');
516 checkInputEvent(beforeInputEvents[
0],
"when selection collapsed in a cell which is col-spanning (before)");
517 is(inputEvents.length,
1,
518 'Only one
"input" event should be fired when selection collapsed in a cell which is col-spanning (before)');
519 checkInputEvent(inputEvents[
0],
"when selection collapsed in a cell which is col-spanning (before)");
521 selection.removeAllRanges();
522 editor.innerHTML =
"<table>" +
523 "<tr><td>cell1-1</td><td>cell1-2</td><td>cell1-3</td></tr>" +
524 '
<tr><td id=
"select" colspan=
"2">cell2-
1</td><td>cell2-
3</td></tr>' +
527 beforeInputEvents = [];
529 selection.setBaseAndExtent(document.getElementById(
"select").firstChild,
0,
530 document.getElementById(
"select").firstChild,
1);
531 getTableEditor().insertTableCell(
2, true);
532 is(editor.innerHTML,
"<table><tbody>" +
533 "<tr><td>cell1-1</td><td>cell1-2</td><td>cell1-3</td></tr>" +
534 '
<tr><td id=
"select" colspan=
"2">cell2-
1</td><td valign=
"top"><br></td><td valign=
"top"><br></td><td>cell2-
3</td></tr>' +
536 "nsITableEditor.insertTableCell(2, false) should insert 2 cells after the col-spanning cell containing selection");
537 is(beforeInputEvents.length,
1,
538 'Only one
"beforeinput" event should be fired when selection collapsed in a cell which is col-spanning (after)');
539 checkInputEvent(beforeInputEvents[
0],
"when selection collapsed in a cell which is col-spanning (after)");
540 is(inputEvents.length,
1,
541 'Only one
"input" event should be fired when selection collapsed in a cell which is col-spanning (after)');
542 checkInputEvent(inputEvents[
0],
"when selection collapsed in a cell which is col-spanning (after)");
544 editor.removeEventListener(
"beforeinput", onBeforeInput);
545 editor.removeEventListener(
"input", onInput);
550 function getTableEditor() {
551 var editingSession = SpecialPowers.wrap(window).docShell.editingSession;
552 return editingSession.getEditorForWindow(window).QueryInterface(SpecialPowers.Ci.nsITableEditor);