Source code

Revision control

Other Tools

Test Info:

<!DOCTYPE>
<html>
<head>
<title>Test for nsITableEditor.deleteTableCell()</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" href="/tests/SimpleTest/test.css">
</head>
<body>
<div id="display">
</div>
<div id="content" contenteditable>out of table<table><tr><td>default content</td></tr></table></div>
<pre id="test">
</pre>
<script class="testbody" type="application/javascript">
"use strict";
SimpleTest.waitForExplicitFinish();
SimpleTest.waitForFocus(() => {
let editor = document.getElementById("content");
let selection = document.getSelection();
let selectionRanges = [];
function checkInputEvent(aEvent, aDescription) {
ok(aEvent instanceof InputEvent,
`"${aEvent.type}" event should be dispatched with InputEvent interface ${aDescription}`);
is(aEvent.cancelable, aEvent.type === "beforeinput",
`"${aEvent.type}" event should be ${aEvent.type === "beforeinput" ? "be" : "never cancelable"} ${aDescription}`);
is(aEvent.bubbles, true,
`"${aEvent.type}" event should always bubble ${aDescription}`);
is(aEvent.inputType, "deleteContent",
`inputType of "${aEvent.type}" event should be "deleteContent" ${aDescription}`);
is(aEvent.data, null,
`data of "${aEvent.type}" event should be null ${aDescription}`);
is(aEvent.dataTransfer, null,
`dataTransfer of "${aEvent.type}" event should be null ${aDescription}`);
let targetRanges = aEvent.getTargetRanges();
if (aEvent.type === "beforeinput") {
is(targetRanges.length, selectionRanges.length,
`getTargetRanges() of "beforeinput" event should return selection ranges ${aDescription}`);
if (targetRanges.length === selectionRanges.length) {
for (let i = 0; i < selectionRanges.length; i++) {
is(targetRanges[i].startContainer, selectionRanges[i].startContainer,
`startContainer of getTargetRanges()[${i}] of "beforeinput" event does not match ${aDescription}`);
is(targetRanges[i].startOffset, selectionRanges[i].startOffset,
`startOffset of getTargetRanges()[${i}] of "beforeinput" event does not match ${aDescription}`);
is(targetRanges[i].endContainer, selectionRanges[i].endContainer,
`endContainer of getTargetRanges()[${i}] of "beforeinput" event does not match ${aDescription}`);
is(targetRanges[i].endOffset, selectionRanges[i].endOffset,
`endOffset of getTargetRanges()[${i}] of "beforeinput" event does not match ${aDescription}`);
}
}
} else {
is(targetRanges.length, 0,
`getTargetRanges() of "${aEvent.type}" event should return empty array ${aDescription}`);
}
}
let beforeInputEvents = [];
let inputEvents = [];
function onBeforeInput(aEvent) {
beforeInputEvents.push(aEvent);
selectionRanges = [];
for (let i = 0; i < selection.rangeCount; i++) {
let range = selection.getRangeAt(i);
selectionRanges.push({startContainer: range.startContainer, startOffset: range.startOffset,
endContainer: range.endContainer, endOffset: range.endOffset});
}
}
function onInput(aEvent) {
inputEvents.push(aEvent);
}
editor.addEventListener("beforeinput", onBeforeInput);
editor.addEventListener("input", onInput);
beforeInputEvents = [];
inputEvents = [];
selection.collapse(editor.firstChild, 0);
getTableEditor().deleteTableCell(1);
is(editor.innerHTML, "out of table<table><tbody><tr><td>default content</td></tr></tbody></table>",
"nsITableEditor.deleteTableCell(1) should do nothing if selection is not in <table>");
// If there were specific inputType value for this API, we should dispatch cancelable "beforeinput", though.
is(beforeInputEvents.length, 1,
'"beforeinput" event should be fired when a call of nsITableEditor.deleteTableCell(1) even though it will do nothing');
checkInputEvent(beforeInputEvents[0], "when selection is collapsed outside table element");
is(inputEvents.length, 0,
'No "input" event should be fired when a call of nsITableEditor.deleteTableCell(1) does nothing');
selection.removeAllRanges();
try {
beforeInputEvents = [];
inputEvents = [];
getTableEditor().deleteTableCell(1);
ok(false, "getTableEditor().deleteTableCell(1) without selection ranges should throw exception");
} catch (e) {
ok(true, "getTableEditor().deleteTableCell(1) without selection ranges should throw exception");
is(beforeInputEvents.length, 0,
'No "beforeinput" event should be fired when nsITableEditor.deleteTableCell(1) causes exception due to no selection range');
is(inputEvents.length, 0,
'No "input" event should be fired when nsITableEditor.deleteTableCell(1) causes exception due to no selection range');
}
selection.removeAllRanges();
editor.innerHTML = "<table>" +
'<tr><td id="select">cell1-1</td><td>cell1-2</td><td>cell1-3</td></tr>' +
"<tr><td>cell2-1</td><td>cell2-2</td><td>cell2-3</td></tr>" +
"</table>";
beforeInputEvents = [];
inputEvents = [];
let range = document.createRange();
range.selectNode(document.getElementById("select"));
selection.addRange(range);
getTableEditor().deleteTableCell(1);
is(editor.innerHTML, "<table><tbody>" +
"<tr><td>cell1-2</td><td>cell1-3</td></tr>" +
"<tr><td>cell2-1</td><td>cell2-2</td><td>cell2-3</td></tr>" +
"</tbody></table>",
"nsITableEditor.deleteTableCellContents(1) should remove only selected cell when only one cell is selected #1-1");
is(beforeInputEvents.length, 1,
'Only one "beforeinput" event should be fired when only one cell is selected #1-1');
checkInputEvent(beforeInputEvents[0], "when only one cell is selected #1-1");
is(inputEvents.length, 1,
'Only one "input" event should be fired when only one cell is selected #1-1');
checkInputEvent(inputEvents[0], "when only one cell is selected #1-1");
selection.removeAllRanges();
editor.innerHTML = "<table>" +
'<tr><td>cell1-1</td><td id="select">cell1-2</td><td>cell1-3</td></tr>' +
"<tr><td>cell2-1</td><td>cell2-2</td><td>cell2-3</td></tr>" +
"</table>";
beforeInputEvents = [];
inputEvents = [];
range = document.createRange();
range.selectNode(document.getElementById("select"));
selection.addRange(range);
getTableEditor().deleteTableCell(1);
is(editor.innerHTML, "<table><tbody>" +
"<tr><td>cell1-1</td><td>cell1-3</td></tr>" +
"<tr><td>cell2-1</td><td>cell2-2</td><td>cell2-3</td></tr>" +
"</tbody></table>",
"nsITableEditor.deleteTableCellContents(1) should remove only selected cell when only one cell is selected #1-2");
is(beforeInputEvents.length, 1,
'Only one "beforeinput" event should be fired when only one cell is selected #1-2');
checkInputEvent(beforeInputEvents[0], "when only one cell is selected #1-2");
is(inputEvents.length, 1,
'Only one "input" event should be fired when only one cell is selected #1-2');
checkInputEvent(inputEvents[0], "when only one cell is selected #1-2");
selection.removeAllRanges();
editor.innerHTML = "<table>" +
'<tr><td>cell1-1</td><td>cell1-2</td><td id="select">cell1-3</td></tr>' +
"<tr><td>cell2-1</td><td>cell2-2</td><td>cell2-3</td></tr>" +
"</table>";
beforeInputEvents = [];
inputEvents = [];
range = document.createRange();
range.selectNode(document.getElementById("select"));
selection.addRange(range);
getTableEditor().deleteTableCell(1);
is(editor.innerHTML, "<table><tbody>" +
"<tr><td>cell1-1</td><td>cell1-2</td></tr>" +
"<tr><td>cell2-1</td><td>cell2-2</td><td>cell2-3</td></tr>" +
"</tbody></table>",
"nsITableEditor.deleteTableCellContents(1) should remove only selected cell when only one cell is selected #1-3");
is(beforeInputEvents.length, 1,
'Only one "beforeinput" event should be fired when only one cell is selected #1-3');
checkInputEvent(beforeInputEvents[0], "when only one cell is selected #1-3");
is(inputEvents.length, 1,
'Only one "input" event should be fired when only one cell is selected #1-3');
checkInputEvent(inputEvents[0], "when only one cell is selected #1-3");
// When only one cell element is selected, the argument should be used.
selection.removeAllRanges();
editor.innerHTML = "<table>" +
'<tr><td id="select">cell1-1</td><td>cell1-2</td><td>cell1-3</td></tr>' +
"<tr><td>cell2-1</td><td>cell2-2</td><td>cell2-3</td></tr>" +
"</table>";
beforeInputEvents = [];
inputEvents = [];
range = document.createRange();
range.selectNode(document.getElementById("select"));
selection.addRange(range);
getTableEditor().deleteTableCell(2);
is(editor.innerHTML, "<table><tbody>" +
"<tr><td>cell1-3</td></tr>" +
"<tr><td>cell2-1</td><td>cell2-2</td><td>cell2-3</td></tr>" +
"</tbody></table>",
"nsITableEditor.deleteTableCellContents(2) should remove selected cell element and next cell element in same row #1-4");
is(beforeInputEvents.length, 1,
'Only one "beforeinput" event should be fired when only one cell is selected #1-4');
checkInputEvent(beforeInputEvents[0], "when only one cell is selected #1-4");
is(inputEvents.length, 1,
'Only one "input" event should be fired when only one cell is selected #1-4');
checkInputEvent(inputEvents[0], "when only one cell is selected #1-4");
// When the argument is larger than remaining cell elements from selected
// cell element, the behavior is really buggy.
selection.removeAllRanges();
editor.innerHTML = "<table>" +
'<tr><td>cell1-1</td><td>cell1-2</td><td id="select">cell1-3</td></tr>' +
"<tr><td>cell2-1</td><td>cell2-2</td><td>cell2-3</td></tr>" +
"</table>";
beforeInputEvents = [];
inputEvents = [];
range = document.createRange();
range.selectNode(document.getElementById("select"));
selection.addRange(range);
getTableEditor().deleteTableCell(2);
is(editor.innerHTML, "<table><tbody>" +
"<tr><td>cell1-1</td></tr>" +
"<tr><td>cell2-1</td><td>cell2-2</td><td>cell2-3</td></tr>" +
"</tbody></table>",
"nsITableEditor.deleteTableCellContents(2) should remove selected cell element and its previous cell element when it reaches the last cell element in the row");
is(beforeInputEvents.length, 1,
'Only one "beforeinput" event should be fired when the argument is larger than remaining cell elements from selected cell element');
checkInputEvent(beforeInputEvents[0], "when the argument is larger than remaining cell elements from selected cell element");
is(inputEvents.length, 1,
'Only one "input" event should be fired when the argument is larger than remaining cell elements from selected cell element');
checkInputEvent(inputEvents[0], "when the argument is larger than remaining cell elements from selected cell element");
// XXX If the former case is expected, first row should be removed in this
// case, but it removes only selected cell and its previous cell.
selection.removeAllRanges();
editor.innerHTML = "<table>" +
'<tr><td>cell1-1</td><td>cell1-2</td><td id="select">cell1-3</td></tr>' +
"<tr><td>cell2-1</td><td>cell2-2</td><td>cell2-3</td></tr>" +
"</table>";
beforeInputEvents = [];
inputEvents = [];
range = document.createRange();
range.selectNode(document.getElementById("select"));
selection.addRange(range);
getTableEditor().deleteTableCell(4);
todo_is(editor.innerHTML, "<table><tbody>" +
"<tr><td>cell2-1</td><td>cell2-2</td><td>cell2-3</td></tr>" +
"</tbody></table>",
"nsITableEditor.deleteTableCellContents(4) should remove the first row when a cell in it is selected and the argument is larger than number of cells in the row");
is(beforeInputEvents.length, 1,
'Only one "beforeinput" event should be fired when the argument is larger than number of cells in the row');
checkInputEvent(beforeInputEvents[0], "when the argument is larger than number of cells in the row");
is(inputEvents.length, 1,
'Only one "input" event should be fired when the argument is larger than number of cells in the row');
checkInputEvent(inputEvents[0], "when the argument is larger than number of cells in the row");
// If 2 or more cells are selected, the argument should be ignored.
selection.removeAllRanges();
editor.innerHTML = "<table>" +
'<tr><td id="select1">cell1-1</td><td>cell1-2</td><td>cell1-3</td></tr>' +
'<tr><td>cell2-1</td><td id="select2">cell2-2</td><td>cell2-3</td></tr>' +
"</table>";
beforeInputEvents = [];
inputEvents = [];
range = document.createRange();
range.selectNode(document.getElementById("select1"));
selection.addRange(range);
range = document.createRange();
range.selectNode(document.getElementById("select2"));
selection.addRange(range);
getTableEditor().deleteTableCell(1);
is(editor.innerHTML, "<table><tbody>" +
"<tr><td>cell1-2</td><td>cell1-3</td></tr>" +
"<tr><td>cell2-1</td><td>cell2-3</td></tr>" +
"</tbody></table>",
"nsITableEditor.deleteTableCellContents(1) should remove selected cell elements even if the argument is smaller than number of selected cells");
is(beforeInputEvents.length, 1,
'Only one "beforeinput" event should be fired even if the argument is smaller than number of selected cells');
checkInputEvent(beforeInputEvents[0], "even if the argument is smaller than number of selected cells");
is(inputEvents.length, 1,
'Only one "input" event should be fired even if the argument is smaller than number of selected cells');
checkInputEvent(inputEvents[0], "even if the argument is smaller than number of selected cells");
// If all cells in a row are selected, the <tr> element should also be removed.
selection.removeAllRanges();
editor.innerHTML = "<table>" +
'<tr><td id="select1">cell1-1</td><td id="select2">cell1-2</td><td id="select3">cell1-3</td></tr>' +
"<tr><td>cell2-1</td><td>cell2-2</td><td>cell2-3</td></tr>" +
"</table>";
beforeInputEvents = [];
inputEvents = [];
range = document.createRange();
range.selectNode(document.getElementById("select1"));
selection.addRange(range);
range = document.createRange();
range.selectNode(document.getElementById("select2"));
selection.addRange(range);
range = document.createRange();
range.selectNode(document.getElementById("select3"));
selection.addRange(range);
getTableEditor().deleteTableCell(1);
is(editor.innerHTML, "<table><tbody>" +
"<tr><td>cell2-1</td><td>cell2-2</td><td>cell2-3</td></tr>" +
"</tbody></table>",
"nsITableEditor.deleteTableCellContents(1) should remove also <tr> element when all cell elements in a row is selected");
is(beforeInputEvents.length, 1,
'Only one "beforeinput" event should be fired when all cell elements in a row is selected');
checkInputEvent(beforeInputEvents[0], "when all cell elements in a row is selected");
is(inputEvents.length, 1,
'Only one "input" event should be fired when all cell elements in a row is selected');
checkInputEvent(inputEvents[0], "when all cell elements in a row is selected");
selection.removeAllRanges();
editor.innerHTML = "<table>" +
'<tr><td id="select">cell1-1</td></tr>' +
"<tr><td>cell2-1</td></tr>" +
"</table>";
beforeInputEvents = [];
inputEvents = [];
range = document.createRange();
range.selectNode(document.getElementById("select"));
selection.addRange(range);
getTableEditor().deleteTableCell(1);
is(editor.innerHTML, "<table><tbody>" +
"<tr><td>cell2-1</td></tr>" +
"</tbody></table>",
"nsITableEditor.deleteTableCellContents(1) should remove also <tr> element when a cell element which is only child of a row is selected");
is(beforeInputEvents.length, 1,
'Only one "beforeinput" event should be fired when a cell element which is only child of a row is selected');
checkInputEvent(beforeInputEvents[0], "when a cell element which is only child of a row is selected");
is(inputEvents.length, 1,
'Only one "input" event should be fired when a cell element which is only child of a row is selected');
checkInputEvent(inputEvents[0], "when a cell element which is only child of a row is selected");
// If all cells are removed, the <table> element should be removed.
selection.removeAllRanges();
editor.innerHTML = "<table>" +
'<tr><td id="select1">cell1-1</td><td id="select2">cell1-2</td></tr>' +
'<tr><td id="select3">cell2-1</td><td id="select4">cell2-2</td></tr>' +
"</table>";
beforeInputEvents = [];
inputEvents = [];
range = document.createRange();
range.selectNode(document.getElementById("select1"));
selection.addRange(range);
range = document.createRange();
range.selectNode(document.getElementById("select2"));
selection.addRange(range);
range = document.createRange();
range.selectNode(document.getElementById("select3"));
selection.addRange(range);
range = document.createRange();
range.selectNode(document.getElementById("select4"));
selection.addRange(range);
getTableEditor().deleteTableCell(1);
is(editor.innerHTML, "",
"nsITableEditor.deleteTableCellContents(1) should remove also <table> element when all cell elements are selected");
is(beforeInputEvents.length, 1,
'Only one "beforeinput" event should be fired when all cell elements are selected');
checkInputEvent(beforeInputEvents[0], "when all cell elements are selected");
is(inputEvents.length, 1,
'Only one "input" event should be fired when all cell elements are selected');
checkInputEvent(inputEvents[0], "when all cell elements are selected");
selection.removeAllRanges();
editor.innerHTML = "<table>" +
'<tr><td id="select">cell1-1</td></tr>' +
"</table>";
beforeInputEvents = [];
inputEvents = [];
range = document.createRange();
range.selectNode(document.getElementById("select"));
selection.addRange(range);
getTableEditor().deleteTableCell(1);
is(editor.innerHTML, "",
"nsITableEditor.deleteTableCellContents(1) should remove also <table> element when a cell element which is only child of <table> is selected");
is(beforeInputEvents.length, 1,
'Only one "beforeinput" event should be fired when a cell element which is only child of <table> is selected');
checkInputEvent(beforeInputEvents[0], "when a cell element which is only child of <table> is selected");
is(inputEvents.length, 1,
'Only one "input" event should be fired when a cell element which is only child of <table> is selected');
checkInputEvent(inputEvents[0], "when a cell element which is only child of <table> is selected");
// rowspan
selection.removeAllRanges();
editor.innerHTML = "<table>" +
'<tr><td id="select" rowspan="2">cell1-1</td><td>cell1-2</td></tr>' +
"<tr><td>cell2-2</td></tr>" +
"<tr><td>cell3-1</td><td>cell3-2</td></tr>" +
"</table>";
beforeInputEvents = [];
inputEvents = [];
range = document.createRange();
range.selectNode(document.getElementById("select"));
selection.addRange(range);
getTableEditor().deleteTableCell(1);
is(editor.innerHTML, "<table><tbody>" +
"<tr><td>cell1-2</td></tr>" +
"<tr><td>cell2-2</td></tr>" +
"<tr><td>cell3-1</td><td>cell3-2</td></tr>" +
"</tbody></table>",
"nsITableEditor.deleteTableCellContents(1) should just remove the cell spanning rows");
is(beforeInputEvents.length, 1,
'Only one "beforeinput" event should be fired when removing the cell spanning rows');
checkInputEvent(beforeInputEvents[0], "when removing the cell spanning rows");
is(inputEvents.length, 1,
'Only one "input" event should be fired when removing the cell spanning rows');
checkInputEvent(inputEvents[0], "when removing the cell spanning rows");
// XXX cell3-1 is also removed even though it's not selected.
selection.removeAllRanges();
editor.innerHTML = "<table>" +
'<tr><td id="select1" rowspan="2">cell1-1</td><td>cell1-2</td></tr>' +
"<tr><td>cell2-2</td></tr>" +
'<tr><td>cell3-1</td><td id="select2">cell3-2</td></tr>' +
"</table>";
beforeInputEvents = [];
inputEvents = [];
range = document.createRange();
range.selectNode(document.getElementById("select1"));
selection.addRange(range);
range = document.createRange();
range.selectNode(document.getElementById("select2"));
selection.addRange(range);
getTableEditor().deleteTableCell(1);
todo_is(editor.innerHTML, "<table><tbody>" +
"<tr><td>cell1-2</td></tr>" +
"<tr><td>cell2-2</td></tr>" +
"<tr><td>cell3-1</td></tr>" +
"</tbody></table>",
"nsITableEditor.deleteTableCellContents(1) should just remove the cell spanning rows (when 2 cell elements are selected)");
is(beforeInputEvents.length, 1,
'Only one "beforeinput" event should be fired when removing the cell spanning rows (when 2 cell elements are selected)');
checkInputEvent(beforeInputEvents[0], "when removing the cell spanning rows (when 2 cell elements are selected)");
is(inputEvents.length, 1,
'Only one "input" event should be fired when removing the cell spanning rows (when 2 cell elements are selected)');
checkInputEvent(inputEvents[0], "when removing the cell spanning rows (when 2 cell elements are selected)");
selection.removeAllRanges();
editor.innerHTML = "<table>" +
'<tr><td rowspan="2">cell1-1</td><td>cell1-2</td></tr>' +
'<tr><td id="select">cell2-2</td></tr>' +
"<tr><td>cell3-1</td><td>cell3-2</td></tr>" +
"</table>";
beforeInputEvents = [];
inputEvents = [];
range = document.createRange();
range.selectNode(document.getElementById("select"));
selection.addRange(range);
getTableEditor().deleteTableCell(1);
is(editor.innerHTML, "<table><tbody>" +
'<tr><td rowspan="1">cell1-1</td><td>cell1-2</td></tr>' +
"<tr><td>cell3-1</td><td>cell3-2</td></tr>" +
"</tbody></table>",
"nsITableEditor.deleteTableCellContents(1) should adjust rowspan when spanned <tr>'s last child cell element is removed");
is(beforeInputEvents.length, 1,
'Only one "beforeinput" event should be fired when spanned <tr>\'s last child cell element is removed');
checkInputEvent(beforeInputEvents[0], "when spanned <tr>'s last child cell element is removed");
is(inputEvents.length, 1,
'Only one "input" event should be fired when spanned <tr>\'s last child cell element is removed');
checkInputEvent(inputEvents[0], "when spanned <tr>'s last child cell element is removed");
// XXX broken case, the second row isn't removed.
selection.removeAllRanges();
editor.innerHTML = "<table>" +
'<tr><td rowspan="2">cell1-1</td><td>cell1-2</td></tr>' +
'<tr><td id="select1">cell2-2</td></tr>' +
'<tr><td>cell3-1</td><td id="select2">cell3-2</td></tr>' +
"</table>";
beforeInputEvents = [];
inputEvents = [];
range = document.createRange();
range.selectNode(document.getElementById("select1"));
selection.addRange(range);
range = document.createRange();
range.selectNode(document.getElementById("select2"));
selection.addRange(range);
getTableEditor().deleteTableCell(1);
todo_is(editor.innerHTML, "<table><tbody>" +
'<tr><td rowspan="1">cell1-1</td><td>cell1-2</td></tr>' +
"<tr><td>cell3-1</td></tr>" +
"</tbody></table>",
"nsITableEditor.deleteTableCellContents(1) should adjust rowspan when spanned <tr>'s last child cell element is removed (when 2 cell elements are selected)");
is(beforeInputEvents.length, 1,
'Only one "beforeinput" event should be fired when spanned <tr>\'s last child cell element is removed (when 2 cell elements are selected)');
checkInputEvent(beforeInputEvents[0], "when spanned <tr>'s last child cell element is removed (when 2 cell elements are selected)");
is(inputEvents.length, 1,
'Only one "input" event should be fired when spanned <tr>\'s last child cell element is removed (when 2 cell elements are selected)');
checkInputEvent(inputEvents[0], "when spanned <tr>'s last child cell element is removed (when 2 cell elements are selected)");
// XXX broken case, neither the selected cell nor the second row is removed.
selection.removeAllRanges();
editor.innerHTML = "<table>" +
'<tr><td rowspan="3">cell1-1</td><td>cell1-2</td></tr>' +
'<tr><td id="select">cell2-2</td></tr>' +
"<tr><td>cell3-1</td><td>cell3-2</td></tr>" +
"</table>";
beforeInputEvents = [];
inputEvents = [];
range = document.createRange();
range.selectNode(document.getElementById("select"));
selection.addRange(range);
getTableEditor().deleteTableCell(1);
todo_is(editor.innerHTML, "<table><tbody>" +
'<tr><td rowspan="2">cell1-1</td><td>cell1-2</td></tr>' +
"<tr><td>cell3-2</td></tr>" +
"</tbody></table>",
"nsITableEditor.deleteTableCellContents(1) should adjust rowspan when spanned <tr>'s last child cell element is removed (removing middle row)");
is(beforeInputEvents.length, 1,
'Only one "beforeinput" event should be fired when spanned <tr>\'s last child cell element is removed (removing middle row)');
checkInputEvent(beforeInputEvents[0], "when spanned <tr>'s last child cell element is removed (removing middle row)");
todo_is(inputEvents.length, 1,
'Only one "input" event should be fired when spanned <tr>\'s last child cell element is removed (removing middle row)');
if (inputEvents.length > 0) {
checkInputEvent(inputEvents[0], "when spanned <tr>'s last child cell element is removed (removing middle row)");
}
selection.removeAllRanges();
editor.innerHTML = "<table>" +
'<tr><td rowspan="3">cell1-1</td><td>cell1-2</td></tr>' +
'<tr><td id="select1">cell2-2</td></tr>' +
'<tr><td>cell3-1</td><td id="select2">cell3-2</td></tr>' +
"</table>";
beforeInputEvents = [];
inputEvents = [];
range = document.createRange();
range.selectNode(document.getElementById("select1"));
selection.addRange(range);
range = document.createRange();
range.selectNode(document.getElementById("select2"));
selection.addRange(range);
getTableEditor().deleteTableCell(1);
todo_is(editor.innerHTML, "<table><tbody>" +
'<tr><td rowspan="2">cell1-1</td><td>cell1-2</td></tr>' +
"</tbody></table>",
"nsITableEditor.deleteTableCellContents(1) should adjust rowspan when spanned <tr>'s last child cell element and remove the last row");
is(beforeInputEvents.length, 1,
'Only one "beforeinput" event should be fired when spanned <tr>\'s last child cell element and remove the last row');
checkInputEvent(beforeInputEvents[0], "when spanned <tr>'s last child cell element and remove the last row");
is(inputEvents.length, 1,
'Only one "input" event should be fired when spanned <tr>\'s last child cell element and remove the last row');
checkInputEvent(inputEvents[0], "when spanned <tr>'s last child cell element and remove the last row");
// colspan
selection.removeAllRanges();
editor.innerHTML = "<table>" +
'<tr><td id="select" colspan="2">cell1-1</td><td>cell1-3</td></tr>' +
"<tr><td>cell2-1</td><td>cell2-2</td><td>cell2-3</td></tr>" +
"</table>";
beforeInputEvents = [];
inputEvents = [];
range = document.createRange();
range.selectNode(document.getElementById("select"));
selection.addRange(range);
getTableEditor().deleteTableCell(1);
is(editor.innerHTML, "<table><tbody>" +
"<tr><td>cell1-3</td></tr>" +
"<tr><td>cell2-1</td><td>cell2-2</td><td>cell2-3</td></tr>" +
"</tbody></table>",
"nsITableEditor.deleteTableCellContents(1) should just remove the cell spanning columns");
is(beforeInputEvents.length, 1,
'Only one "beforeinput" event should be fired when removing the cell spanning columns');
checkInputEvent(beforeInputEvents[0], "when removing the cell spanning columns");
is(inputEvents.length, 1,
'Only one "input" event should be fired when removing the cell spanning columns');
checkInputEvent(inputEvents[0], "when removing the cell spanning columns");
selection.removeAllRanges();
editor.innerHTML = "<table>" +
'<tr><td id="select1" colspan="2">cell1-1</td><td>cell1-3</td></tr>' +
'<tr><td>cell2-1</td><td id="select2">cell2-2</td><td>cell2-3</td></tr>' +
"</table>";
beforeInputEvents = [];
inputEvents = [];
range = document.createRange();
range.selectNode(document.getElementById("select1"));
selection.addRange(range);
range = document.createRange();
range.selectNode(document.getElementById("select2"));
selection.addRange(range);
getTableEditor().deleteTableCell(1);
is(editor.innerHTML, "<table><tbody>" +
"<tr><td>cell1-3</td></tr>" +
"<tr><td>cell2-1</td><td>cell2-3</td></tr>" +
"</tbody></table>",
"nsITableEditor.deleteTableCellContents(1) should just remove the cell spanning columns and the other selected cell element");
is(beforeInputEvents.length, 1,
'Only one "beforeinput" event should be fired when removing the cell spanning columns and the other selected cell element');
checkInputEvent(beforeInputEvents[0], "when removing the cell spanning columns and the other selected cell element");
is(inputEvents.length, 1,
'Only one "input" event should be fired when removing the cell spanning columns and the other selected cell element');
checkInputEvent(inputEvents[0], "when removing the cell spanning columns and the other selected cell element");
// XXX broken case, colspan is not adjusted.
selection.removeAllRanges();
editor.innerHTML = "<table>" +
'<tr><td colspan="2">cell1-1</td><td>cell1-3</td></tr>' +
'<tr><td>cell2-1</td><td id="select">cell2-2</td><td>cell2-3</td></tr>' +
"</table>";
beforeInputEvents = [];
inputEvents = [];
range = document.createRange();
range.selectNode(document.getElementById("select"));
selection.addRange(range);
getTableEditor().deleteTableCell(1);
todo_is(editor.innerHTML, "<table><tbody>" +
'<tr><td colspan="1">cell1-1</td><td>cell1-3</td></tr>' +
"<tr><td>cell2-1</td><td>cell2-3</td></tr>" +
"</tbody></table>",
"nsITableEditor.deleteTableCellContents(1) should adjust different row's colspan when corresponding cell element is removed");
is(beforeInputEvents.length, 1,
'Only one "beforeinput" event should be fired when corresponding cell element is removed');
checkInputEvent(beforeInputEvents[0], "when corresponding cell element is removed");
is(inputEvents.length, 1,
'Only one "input" event should be fired when corresponding cell element is removed');
checkInputEvent(inputEvents[0], "when corresponding cell element is removed");
selection.removeAllRanges();
editor.innerHTML = "<table>" +
'<tr><td colspan="2">cell1-1</td><td>cell1-3</td></tr>' +
'<tr><td>cell2-1</td><td id="select1">cell2-2</td><td id="select2">cell2-3</td></tr>' +
"</table>";
beforeInputEvents = [];
inputEvents = [];
range = document.createRange();
range.selectNode(document.getElementById("select1"));
selection.addRange(range);
range = document.createRange();
range.selectNode(document.getElementById("select2"));
selection.addRange(range);
getTableEditor().deleteTableCell(1);
todo_is(editor.innerHTML, "<table><tbody>" +
'<tr><td colspan="1">cell1-1</td><td>cell1-3</td></tr>' +
"<tr><td>cell2-1</td></tr>" +
"</tbody></table>",
"nsITableEditor.deleteTableCellContents(1) should adjust different row's colspan when corresponding cell element is removed (when 2 cell elements are selected)");
is(beforeInputEvents.length, 1,
'Only one "beforeinput" event should be fired when corresponding cell element is removed (when 2 cell elements are selected)');
checkInputEvent(beforeInputEvents[0], "when corresponding cell element is removed (when 2 cell elements are selected)");
is(inputEvents.length, 1,
'Only one "input" event should be fired when corresponding cell element is removed (when 2 cell elements are selected)');
checkInputEvent(inputEvents[0], "when corresponding cell element is removed (when 2 cell elements are selected)");
selection.removeAllRanges();
editor.innerHTML = "<table>" +
'<tr><td>cell1-1</td><td id="select1">cell1-2</td><td>cell1-4</td></tr>' +
'<tr><td id="select2" colspan="2">cell2-1</td><td>cell2-3</td><td>cell2-4</td></tr>' +
"</table>";
beforeInputEvents = [];
inputEvents = [];
range = document.createRange();
range.selectNode(document.getElementById("select1"));
selection.addRange(range);
range = document.createRange();
range.selectNode(document.getElementById("select2"));
selection.addRange(range);
getTableEditor().deleteTableCell(1);
is(editor.innerHTML, "<table><tbody>" +
"<tr><td>cell1-1</td><td>cell1-4</td></tr>" +
"<tr><td>cell2-3</td><td>cell2-4</td></tr>" +
"</tbody></table>",
"nsITableEditor.deleteTableCellContents(1) should adjust different row's colspan when corresponding cell element is removed (when 2 cell elements are selected)");
is(beforeInputEvents.length, 1,
'Only one "beforeinput" event should be fired when corresponding cell element is removed (when 2 cell elements are selected)');
checkInputEvent(beforeInputEvents[0], "when corresponding cell element is removed (when 2 cell elements are selected)");
is(inputEvents.length, 1,
'Only one "input" event should be fired when corresponding cell element is removed (when 2 cell elements are selected)');
checkInputEvent(inputEvents[0], "when corresponding cell element is removed (when 2 cell elements are selected)");
// When a cell contains first selection range, it should be removed.
selection.removeAllRanges();
editor.innerHTML = "<table>" +
'<tr><td id="select">cell1-1</td><td>cell1-2</td><td>cell1-3</td></tr>' +
"<tr><td>cell2-1</td><td>cell2-2</td><td>cell2-3</td></tr>" +
"</table>";
editor.scrollTop; // requires layout information.
beforeInputEvents = [];
inputEvents = [];
selection.setBaseAndExtent(document.getElementById("select").firstChild, 0,
document.getElementById("select").firstChild, 1);
getTableEditor().deleteTableCell(1);
is(editor.innerHTML, "<table><tbody>" +
"<tr><td>cell1-2</td><td>cell1-3</td></tr>" +
"<tr><td>cell2-1</td><td>cell2-2</td><td>cell2-3</td></tr>" +
"</tbody></table>",
"nsITableEditor.deleteTableCellContents(1) should remove only a cell containing first selection range when there is no selected cell element");
is(beforeInputEvents.length, 1,
'Only one "beforeinput" event should be fired when there is no selected cell element');
checkInputEvent(beforeInputEvents[0], "when there is no selected cell element");
is(inputEvents.length, 1,
'Only one "input" event should be fired when there is no selected cell element');
checkInputEvent(inputEvents[0], "when there is no selected cell element");
selection.removeAllRanges();
editor.innerHTML = "<table>" +
'<tr><td id="select">cell1-1</td><td>cell1-2</td><td>cell1-3</td></tr>' +
"<tr><td>cell2-1</td><td>cell2-2</td><td>cell2-3</td></tr>" +
"</table>";
editor.scrollTop; // requires layout information.
beforeInputEvents = [];
inputEvents = [];
selection.setBaseAndExtent(document.getElementById("select").firstChild, 0,
document.getElementById("select").firstChild, 1);
getTableEditor().deleteTableCell(2);
is(editor.innerHTML, "<table><tbody>" +
"<tr><td>cell1-3</td></tr>" +
"<tr><td>cell2-1</td><td>cell2-2</td><td>cell2-3</td></tr>" +
"</tbody></table>",
"nsITableEditor.deleteTableCellContents(2) should remove only 2 cell elements starting from a cell containing first selection range when there is no selected cell element");
is(beforeInputEvents.length, 1,
'Only one "beforeinput" event should be fired when there is no selected cell element');
checkInputEvent(beforeInputEvents[0], "when there is no selected cell element");
is(inputEvents.length, 1,
'Only one "input" event should be fired when there is no selected cell element');
checkInputEvent(inputEvents[0], "when there is no selected cell element");
editor.removeEventListener("input", onInput);
SimpleTest.finish();
});
function getTableEditor() {
var editingSession = SpecialPowers.wrap(window).docShell.editingSession;
return editingSession.getEditorForWindow(window).QueryInterface(SpecialPowers.Ci.nsITableEditor);
}
</script>
</body>
</html>