Files
firefox/editor/libeditor/tests/test_nsITableEditor_insertTableColumn.html
T
Masayuki Nakano acbbacb6e3 Bug 998941 - part 2-2: Make HTMLEditor set InputEvent.dataTransfer when InputEvent.inputType is "insertFromPaste", "insertFromDrop" or "insertReplacementText" r=smaug,m_kato
InputEvent.dataTransfer should be set to non-null when InputEvent.inputType
is "insertFromPaste", "insertFromDrop" or "insertReplacementText" and
editor is an HTMLEditor instance:
https://rawgit.com/w3c/input-events/v1/index.html#dfn-data
https://w3c.github.io/input-events/#dfn-data

("insertTranspose" and "insertFromYank" are not currently supported on Gecko.)

This patch makes nsContentUtils::DispatchInputEvent() take dataTransfer value
and EditorBase set it via AutoEditActionDataSetter like data value.

However, we need to create other constructors of DataTransfer to create its
read-only instances initialized with nsITransferable or nsAString.  This will
be implemented by the following patch.

Differential Revision: https://phabricator.services.mozilla.com/D19297
2019-02-19 06:33:42 +00:00

212 lines
11 KiB
HTML

<!DOCTYPE>
<html>
<head>
<title>Test for nsITableEditor.insertTableColumn()</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">
SimpleTest.waitForExplicitFinish();
SimpleTest.waitForFocus(function() {
let editor = document.getElementById("content");
let selection = document.getSelection();
function checkInputEvent(aEvent, aDescription) {
ok(aEvent instanceof InputEvent,
`"input" event should be dispatched with InputEvent interface ${aDescription}`);
is(aEvent.cancelable, false,
`"input" event should be never cancelable ${aDescription}`);
is(aEvent.bubbles, true,
`"input" event should always bubble ${aDescription}`);
is(aEvent.inputType, "",
`inputType should be empty string ${aDescription}`);
is(aEvent.data, null,
`data should be null ${aDescription}`);
is(aEvent.dataTransfer, null,
`data should be null ${aDescription}`);
}
let inputEvents = [];
function onInput(aEvent) {
inputEvents.push(aEvent);
}
editor.addEventListener("input", onInput);
inputEvents = [];
selection.collapse(editor.firstChild, 0);
getTableEditor().insertTableColumn(1, false);
is(editor.innerHTML, "out of table<table><tbody><tr><td>default content</td></tr></tbody></table>",
"nsITableEditor.insertTableColumn(1, false) should do nothing if selection is not in <table>");
is(inputEvents.length, 0,
'No "input" event should be fired when a call of nsITableEditor.insertTableColumn(1, false) does nothing');
inputEvents = [];
getTableEditor().insertTableColumn(1, true);
is(editor.innerHTML, "out of table<table><tbody><tr><td>default content</td></tr></tbody></table>",
"nsITableEditor.insertTableColumn(1, true) should do nothing if selection is not in <table>");
is(inputEvents.length, 0,
'No "input" event should be fired when a call of nsITableEditor.insertTableColumn(1, true) does nothing');
selection.removeAllRanges();
try {
inputEvents = [];
getTableEditor().insertTableColumn(1, false);
ok(false, "getTableEditor().insertTableColumn(1, false) without selection ranges should throw exception");
} catch (e) {
ok(true, "getTableEditor().insertTableColumn(1, false) without selection ranges should throw exception");
is(inputEvents.length, 0,
'No "input" event should be fired when nsITableEditor.insertTableColumn(1, false) causes exception due to no selection range');
}
try {
inputEvents = [];
getTableEditor().insertTableColumn(1, true);
ok(false, "getTableEditor().insertTableColumn(1, true) without selection ranges should throw exception");
} catch (e) {
ok(true, "getTableEditor().insertTableColumn(1, true) without selection ranges should throw exception");
is(inputEvents.length, 0,
'No "input" event should be fired when nsITableEditor.insertTableColumn(1, true) causes exception due to no selection range');
}
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>";
editor.focus();
editor.scrollTop; // layout information required.
inputEvents = [];
selection.setBaseAndExtent(document.getElementById("select").firstChild, 0,
document.getElementById("select").firstChild, 0);
getTableEditor().insertTableColumn(1, false);
is(editor.innerHTML, "<table><tbody>" +
'<tr><td>cell1-1</td><td valign="top"><br></td><td id="select">cell1-2</td><td>cell1-3</td></tr>' +
'<tr><td>cell2-1</td><td valign="top"><br></td><td>cell2-2</td><td>cell2-3</td></tr>' +
"</tbody></table>",
"nsITableEditor.insertTableColumn(1, false) should insert a column to left of the second column");
is(inputEvents.length, 1,
'Only one "input" event should be fired when selection is collapsed in a cell in second column (before)');
checkInputEvent(inputEvents[0], "when selection is collapsed in a cell in second column (before)");
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>";
editor.focus();
editor.scrollTop; // layout information required.
inputEvents = [];
selection.setBaseAndExtent(document.getElementById("select").firstChild, 0,
document.getElementById("select").firstChild, 0);
getTableEditor().insertTableColumn(1, true);
is(editor.innerHTML, "<table><tbody>" +
'<tr><td>cell1-1</td><td id="select">cell1-2</td><td valign="top"><br></td><td>cell1-3</td></tr>' +
'<tr><td>cell2-1</td><td>cell2-2</td><td valign="top"><br></td><td>cell2-3</td></tr>' +
"</tbody></table>",
"nsITableEditor.insertTableColumn(1, false) should insert a column to right of the second column");
is(inputEvents.length, 1,
'Only one "input" event should be fired when selection is collapsed in a cell in second column (after)');
checkInputEvent(inputEvents[0], "when selection is collapsed in a cell in second column (after)");
selection.removeAllRanges();
editor.innerHTML = "<table>" +
'<tr><td>cell1-1</td><td id="select">cell1-2</td><td>cell1-3</td></tr>' +
'<tr><td colspan="2">cell2-1</td><td>cell2-3</td></tr>' +
"</table>";
editor.focus();
editor.scrollTop; // layout information required.
inputEvents = [];
selection.setBaseAndExtent(document.getElementById("select").firstChild, 0,
document.getElementById("select").firstChild, 0);
getTableEditor().insertTableColumn(1, false);
is(editor.innerHTML, "<table><tbody>" +
'<tr><td>cell1-1</td><td valign="top"><br></td><td id="select">cell1-2</td><td>cell1-3</td></tr>' +
'<tr><td colspan="3">cell2-1</td><td>cell2-3</td></tr>' +
"</tbody></table>",
"nsITableEditor.insertTableColumn(1, false) should insert a column to left of the second column and colspan in the first column should be increased");
is(inputEvents.length, 1,
'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)');
checkInputEvent(inputEvents[0], "when selection is collapsed in a cell in second column whose next row cell is col-spanned (before)");
selection.removeAllRanges();
editor.innerHTML = "<table>" +
'<tr><td>cell1-1</td><td id="select">cell1-2</td><td>cell1-3</td></tr>' +
'<tr><td colspan="3">cell2-1</td></tr>' +
"</table>";
editor.focus();
editor.scrollTop; // layout information required.
inputEvents = [];
selection.setBaseAndExtent(document.getElementById("select").firstChild, 0,
document.getElementById("select").firstChild, 0);
getTableEditor().insertTableColumn(1, true);
is(editor.innerHTML, "<table><tbody>" +
'<tr><td>cell1-1</td><td id="select">cell1-2</td><td valign="top"><br></td><td>cell1-3</td></tr>' +
'<tr><td colspan="4">cell2-1</td></tr>' +
"</tbody></table>",
"nsITableEditor.insertTableColumn(1, true) should insert a column to right of the second column and colspan in the first column should be increased");
is(inputEvents.length, 1,
'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)');
checkInputEvent(inputEvents[0], "when selection is collapsed in a cell in second column whose next row cell is col-spanned (after)");
selection.removeAllRanges();
editor.innerHTML = "<table>" +
"<tr><td>cell1-1</td><td>cell1-2</td><td>cell1-3</td></tr>" +
'<tr><td id="select" colspan="2">cell2-1</td><td>cell2-3</td></tr>' +
"</table>";
editor.focus();
editor.scrollTop; // layout information required.
inputEvents = [];
selection.setBaseAndExtent(document.getElementById("select").firstChild, 0,
document.getElementById("select").firstChild, 1);
getTableEditor().insertTableColumn(2, false);
is(editor.innerHTML, "<table><tbody>" +
'<tr><td valign="top"><br></td><td valign="top"><br></td><td>cell1-1</td><td>cell1-2</td><td>cell1-3</td></tr>' +
'<tr><td valign="top"><br></td><td valign="top"><br></td><td id="select" colspan="2">cell2-1</td><td>cell2-3</td></tr>' +
"</tbody></table>",
"nsITableEditor.insertTableColumn(2, false) should insert 2 columns to left of the first column");
is(inputEvents.length, 1,
'Only one "input" event should be fired when selection is collapsed in a cell which is col-spanning (before)');
checkInputEvent(inputEvents[0], "when selection is collapsed in a cell which is col-spanning (before)");
selection.removeAllRanges();
editor.innerHTML = "<table>" +
"<tr><td>cell1-1</td><td>cell1-2</td><td>cell1-3</td></tr>" +
'<tr><td id="select" colspan="2">cell2-1</td><td>cell2-3</td></tr>' +
"</table>";
editor.focus();
editor.scrollTop; // layout information required.
inputEvents = [];
selection.setBaseAndExtent(document.getElementById("select").firstChild, 0,
document.getElementById("select").firstChild, 1);
getTableEditor().insertTableColumn(2, true);
is(editor.innerHTML, "<table><tbody>" +
'<tr><td>cell1-1</td><td>cell1-2</td><td valign="top"><br></td><td valign="top"><br></td><td>cell1-3</td></tr>' +
'<tr><td id="select" colspan="2">cell2-1</td><td valign="top"><br></td><td valign="top"><br></td><td>cell2-3</td></tr>' +
"</tbody></table>",
"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");
is(inputEvents.length, 1,
'Only one "input" event should be fired when selection is collapsed in a cell which is col-spanning (after)');
checkInputEvent(inputEvents[0], "when selection is collapsed in a cell which is col-spanning (after)");
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>