Bug 1772588 [wpt PR 34302] - [wpt] Add test for block-in-inline offsetParent., a...
[gecko.git] / editor / libeditor / tests / test_nsITableEditor_insertTableCell.html
blobccd8ed5c7e37a89e24d56bc0b03bcf7f077a70b3
1 <!DOCTYPE>
2 <html>
3 <head>
4 <title>Test for nsITableEditor.insertTableCell()</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>
15 <script class="testbody" type="application/javascript">
16 "use strict";
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}`);
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}`);
53 } else {
54 is(targetRanges.length, 0,
55 `getTargetRanges() of "${aEvent.type}" event should return empty array ${aDescription}`);
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});
70 function onInput(aEvent) {
71 inputEvents.push(aEvent);
73 editor.addEventListener("beforeinput", onBeforeInput);
74 editor.addEventListener("input", onInput);
76 beforeInputEvents = [];
77 inputEvents = [];
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 = [];
89 inputEvents = [];
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();
100 try {
101 beforeInputEvents = [];
102 inputEvents = [];
103 getTableEditor().insertTableCell(1, false);
104 ok(false, "getTableEditor().insertTableCell(1, false) without selection ranges should throw exception");
105 } catch (e) {
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');
112 try {
113 beforeInputEvents = [];
114 inputEvents = [];
115 getTableEditor().insertTableCell(1, true);
116 ok(false, "getTableEditor().insertTableCell(1, true) without selection ranges should throw exception");
117 } catch (e) {
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();
127 editor.innerHTML =
128 "<table>" +
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>" +
132 "</table>";
133 editor.focus();
134 beforeInputEvents = [];
135 inputEvents = [];
136 selection.setBaseAndExtent(
137 document.getElementById("select").firstChild,
139 document.getElementById("select").firstChild,
142 getTableEditor().insertTableCell(0, false);
144 editor.innerHTML,
145 "<table><tbody>" +
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>" +
149 "</tbody></table>",
150 "testInsertZeroCellsBefore: nsITableEditor.insertTableCell(0, false) should do nothing without throwing exception"
153 beforeInputEvents.length,
155 'testInsertZeroCellsBefore: No "beforeinput" event should be fired'
158 inputEvents.length,
160 'testInsertZeroCellsBefore: No "input" event should be fired'
162 })();
164 (function testInsertZeroCellsAfter() {
165 selection.removeAllRanges();
166 editor.innerHTML =
167 "<table>" +
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>" +
171 "</table>";
172 editor.focus();
173 beforeInputEvents = [];
174 inputEvents = [];
175 selection.setBaseAndExtent(
176 document.getElementById("select").firstChild,
178 document.getElementById("select").firstChild,
181 getTableEditor().insertTableCell(0, true);
183 editor.innerHTML,
184 "<table><tbody>" +
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>" +
188 "</tbody></table>",
189 "testInsertZeroCellsAfter: nsITableEditor.insertTableCell(0, true) should do nothing without throwing exception"
192 beforeInputEvents.length,
194 'testInsertZeroCellsAfter: No "beforeinput" event should be fired'
197 inputEvents.length,
199 'testInsertZeroCellsAfter: No "input" event should be fired'
201 })();
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>" +
208 "</table>";
209 editor.focus();
210 beforeInputEvents = [];
211 inputEvents = [];
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>" +
219 "</tbody></table>",
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>" +
233 "</table>";
234 editor.focus();
235 beforeInputEvents = [];
236 inputEvents = [];
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>" +
244 "</tbody></table>",
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();
255 editor.innerHTML =
256 "<table>" +
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>" +
260 "</table>";
261 editor.focus();
262 beforeInputEvents = [];
263 inputEvents = [];
264 selection.setBaseAndExtent(
265 document.getElementById("select").firstChild,
267 document.getElementById("select").firstChild,
270 getTableEditor().insertTableCell(1, false);
272 editor.innerHTML,
273 "<table><tbody>" +
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>" +
277 "</tbody></table>",
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'
285 checkInputEvent(
286 beforeInputEvents[0],
287 "when selection collapsed in a cell following a text node (testInsertBeforeCellFollowingTextNode)"
290 inputEvents.length,
292 'testInsertBeforeCellFollowingTextNode: Only one "input" event should be fired'
294 checkInputEvent(
295 inputEvents[0],
296 "when selection collapsed in a cell following a text node (testInsertBeforeCellFollowingTextNode)"
298 })();
300 (function testInsertAfterCellFollowedByTextNode() {
301 selection.removeAllRanges();
302 editor.innerHTML =
303 "<table>" +
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>" +
307 "</table>";
308 editor.focus();
309 beforeInputEvents = [];
310 inputEvents = [];
311 selection.setBaseAndExtent(
312 document.getElementById("select").firstChild,
314 document.getElementById("select").firstChild,
317 getTableEditor().insertTableCell(1, true);
319 editor.innerHTML,
320 "<table><tbody>" +
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>" +
324 "</tbody></table>",
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'
332 checkInputEvent(
333 beforeInputEvents[0],
334 "when selection collapsed in a cell followed by a text node (testInsertAfterCellFollowedByTextNode)"
337 inputEvents.length,
339 'testInsertAfterCellFollowedByTextNode: Only one "input" event should be fired'
341 checkInputEvent(
342 inputEvents[0],
343 "when selection collapsed in a cell followed by a text node (testInsertAfterCellFollowedByTextNode)"
345 })();
347 // with rowspan.
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>" +
355 "</table>";
356 editor.focus();
357 beforeInputEvents = [];
358 inputEvents = [];
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>" +
366 "</tbody></table>",
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>" +
380 "</table>";
381 editor.focus();
382 beforeInputEvents = [];
383 inputEvents = [];
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>" +
391 "</tbody></table>",
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>" +
405 "</table>";
406 editor.focus();
407 beforeInputEvents = [];
408 inputEvents = [];
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>" +
416 "</tbody></table>",
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>" +
430 "</table>";
431 editor.focus();
432 beforeInputEvents = [];
433 inputEvents = [];
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>" +
441 "</tbody></table>",
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)");
450 // with colspan
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>' +
456 "</table>";
457 editor.focus();
458 beforeInputEvents = [];
459 inputEvents = [];
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>' +
466 "</tbody></table>",
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>' +
479 "</table>";
480 editor.focus();
481 beforeInputEvents = [];
482 inputEvents = [];
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>' +
489 "</tbody></table>",
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>' +
502 "</table>";
503 editor.focus();
504 beforeInputEvents = [];
505 inputEvents = [];
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>' +
512 "</tbody></table>",
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>' +
525 "</table>";
526 editor.focus();
527 beforeInputEvents = [];
528 inputEvents = [];
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>' +
535 "</tbody></table>",
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);
547 SimpleTest.finish();
550 function getTableEditor() {
551 var editingSession = SpecialPowers.wrap(window).docShell.editingSession;
552 return editingSession.getEditorForWindow(window).QueryInterface(SpecialPowers.Ci.nsITableEditor);
555 </script>
556 </body>
558 </html>