blob: 32c746cb566856f1f2338bf8a9a42df65f16418f [file] [log] [blame]
<html>
<head>
<script src="../../http/tests/inspector/inspector-test.js"></script>
<script src="editor-test.js"></script>
<script>
function test()
{
function testFunction(foo, bar)
{
someFunctionCall(bar);
var b = 42;
return a === 1 ? true : false;
}
var textEditor = InspectorTest.createTestEditor();
textEditor.overrideViewportForTest(0, undefined, 3);
textEditor.mimeType = "text/javascript";
textEditor.setReadOnly(false);
textEditor.setText(testFunction.toString());
textEditor.element.focus();
InspectorTest.addResult(textEditor.text());
const wordJumpModifier = WebInspector.isMac() ? "altKey" : "ctrlKey";
function dumpEditorSelection()
{
var selection = textEditor.selection();
if (selection.isEmpty()) {
var line = textEditor.line(selection.startLine);
InspectorTest.addResult(line.substring(0, selection.startColumn) + "|" + line.substring(selection.startColumn));
} else {
InspectorTest.addResult(">>" + textEditor._textModel.copyRange(selection.normalize()) + "<<");
}
return selection;
}
function setCursorAtBeginning()
{
textEditor.setSelection(WebInspector.TextRange.createFromLocation(0, 0));
}
function setCursorAtEnd()
{
var lastLine = textEditor._textModel.linesCount - 1;
var lastColumn = textEditor._textModel.line(lastLine).length;
textEditor.setSelection(WebInspector.TextRange.createFromLocation(lastLine, lastColumn));
}
InspectorTest.runTestSuite([
function testCtrlRightArrow(next)
{
setCursorAtBeginning();
var selection = dumpEditorSelection();
var oldSelection;
do {
oldSelection = selection;
eventSender.keyDown("rightArrow", [wordJumpModifier]);
selection = dumpEditorSelection();
} while (selection.compareTo(oldSelection) !== 0);
next();
},
function testCtrlLeftArrow(next)
{
setCursorAtEnd();
var selection = dumpEditorSelection();
var oldSelection;
do {
oldSelection = selection;
eventSender.keyDown("leftArrow", [wordJumpModifier]);
selection = dumpEditorSelection();
} while (selection.compareTo(oldSelection) !== 0);
next();
},
function testCtrlShiftRightArrow(next)
{
setCursorAtBeginning();
var selection = dumpEditorSelection();
var oldSelection;
do {
oldSelection = selection;
eventSender.keyDown("rightArrow", [wordJumpModifier, "shiftKey"]);
selection = dumpEditorSelection();
} while (selection.collapseToEnd().compareTo(oldSelection.collapseToEnd()) !== 0);
next();
},
function testCtrlShiftLeftArrow(next)
{
setCursorAtEnd();
var selection = dumpEditorSelection();
var oldSelection;
do {
oldSelection = selection;
eventSender.keyDown("leftArrow", [wordJumpModifier, "shiftKey"]);
selection = dumpEditorSelection();
} while (selection.collapseToEnd().compareTo(oldSelection.collapseToEnd()) !== 0);
next();
},
function testCtrlBackspace(next)
{
setCursorAtEnd();
InspectorTest.addResult("===============");
InspectorTest.addResult(textEditor.text());
do {
eventSender.keyDown("\b", [wordJumpModifier]);
InspectorTest.addResult("===============");
InspectorTest.addResult(textEditor.text() + "<<");
} while (textEditor.text() !== "");
textEditor.setText(testFunction.toString());
next();
}
]);
}
</script>
</head>
<body onload="runTest();">
<p>
This test checks how text editor handles different ctrl-based movements, i.e. ctrl-left, ctrl-right, ctrl-shift-left, ctrl-backspace.
</p>
</body>
</html>