mirror of
https://github.com/HeyPuter/firefox.git
synced 2026-11-28 04:39:07 -10:00
It's difficult to create new test which checks "input" events caused by all edit operations especially when text is inserted from our UI. Therefore, this adds "input" event type checks into existing tests. Additionally, this adds new test for MozEditableElement.setUserInput() whose behavior needs to be fixed in this bug. Currently, InputEvent interface should be used only on text controls or contenteditable editor when dispatching "input" event. https://w3c.github.io/input-events/#events-inputevents You may feel odd to use different event interface for same "input" events. However, other browsers also use InputEvent interface only in the cases. So, we should follow them for now. Differential Revision: https://phabricator.services.mozilla.com/D12243
206 lines
11 KiB
HTML
206 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}`);
|
|
}
|
|
|
|
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>
|