blob: 7e4135f21fe1d11353527cb45ce230937a82bbf9 [file] [log] [blame]
<html>
<head>
<script src="../../http/tests/inspector/inspector-test.js"></script>
<script src="editor-test.js"></script>
<script>
function codeSnippet() {
return document.getElementById("codeSnippet").textContent;
}
function test()
{
function testFunction()
{
var a = 100;
var b = 200;
var c = (a + b) / 2;
console.log(a);
console.log(b);
console.log(c);
if (a > b) {
console.log(a);
}
return c;
}
var textEditor = InspectorTest.createTestEditor();
textEditor.setMimeType("text/javascript");
textEditor.setReadOnly(false);
textEditor.element.focus();
InspectorTest.runTestSuite([
function testEnterInTheLineEnd(next)
{
textEditor.setText(testFunction.toString());
var line = textEditor.line(2);
textEditor.setSelection(WebInspector.TextRange.createFromLocation(2, line.length));
hitEnterDumpTextAndNext(next);
},
function testEnterAfterOpenCurlyBrace(next)
{
textEditor.setText(testFunction.toString());
var line = textEditor.line(1);
textEditor.setSelection(WebInspector.TextRange.createFromLocation(1, line.length));
hitEnterDumpTextAndNext(next);
},
function testEnterInTheMiddleOfLine(next)
{
textEditor.setText(testFunction.toString());
var line = textEditor.line(2);
textEditor.setSelection(WebInspector.TextRange.createFromLocation(2, line.length / 2));
hitEnterDumpTextAndNext(next);
},
function testEnterInTheBeginningOfTheLine(next)
{
textEditor.setText(testFunction.toString());
textEditor.setSelection(WebInspector.TextRange.createFromLocation(2, 0));
hitEnterDumpTextAndNext(next);
},
function testEnterWithTheSelection(next)
{
textEditor.setText(testFunction.toString());
textEditor.setSelection(new WebInspector.TextRange(2, 2, 2, 4));
hitEnterDumpTextAndNext(next);
},
function testEnterWithReversedSelection(next)
{
textEditor.setText(testFunction.toString());
textEditor.setSelection(new WebInspector.TextRange(2, 4, 2, 2));
hitEnterDumpTextAndNext(next);
},
function testEnterWithTheMultiLineSelection(next)
{
textEditor.setText(testFunction.toString());
textEditor.setSelection(new WebInspector.TextRange(2, 0, 8, 4));
hitEnterDumpTextAndNext(next);
},
function testEnterWithFullLineSelection(next)
{
textEditor.setText(testFunction.toString());
textEditor.setSelection(new WebInspector.TextRange(2, 0, 3, 0));
hitEnterDumpTextAndNext(next);
},
function testEnterBeforeOpenBrace(next)
{
textEditor.setText(testFunction.toString());
textEditor.setSelection(new WebInspector.TextRange(8, 0, 8, 0));
hitEnterDumpTextAndNext(next);
},
function testEnterMultiCursor(next)
{
textEditor.setText(testFunction.toString());
InspectorTest.setLineSelections(textEditor, [
{ line: 3, column: 0 },
{ line: 5, column: 1 },
{ line: 6, column: 2 },
]);
hitEnterDumpTextAndNext(next);
}
]);
function hitEnterDumpTextAndNext(next)
{
InspectorTest.fakeKeyEvent(textEditor, "enter", null, step2);
function step2()
{
InspectorTest.dumpTextWithSelection(textEditor, true);
next();
}
}
}
</script>
</head>
<body onload="runTest();">
<p>
This test checks text editor enter behaviour.
</p>
</body>
</html>