3 <script src=
"../../http/tests/inspector/inspector-test.js"></script>
4 <script src=
"editor-test.js"></script>
8 function testFunction(foo
, bar
)
10 someFunctionCall(bar
);
12 return a
=== 1 ? true : false;
15 function testMyCamelMove(foo
, bar
)
17 /* HelloWorld.TestSTRIng */
23 var textEditor
= InspectorTest
.createTestEditor();
24 textEditor
.setMimeType("text/javascript");
25 textEditor
.setReadOnly(false);
26 textEditor
.setText(testFunction
.toString());
27 textEditor
.element
.focus();
29 InspectorTest
.addResult(textEditor
.text());
30 const wordJumpModifier
= WebInspector
.isMac() ? "altKey" : "ctrlKey";
31 const camelJumpModifier
= WebInspector
.isMac() ? "ctrlKey" : "altKey";
33 function dumpEditorSelection()
35 var selection
= textEditor
.selection();
36 if (selection
.isEmpty()) {
37 var line
= textEditor
.line(selection
.startLine
);
38 InspectorTest
.addResult(line
.substring(0, selection
.startColumn
) + "|" + line
.substring(selection
.startColumn
));
40 InspectorTest
.addResult(">>" + textEditor
.copyRange(selection
.normalize()) + "<<");
45 function setCursorAtBeginning()
47 textEditor
.setSelection(WebInspector
.TextRange
.createFromLocation(0, 0));
50 function setCursorAtEnd()
52 var lastLine
= textEditor
.linesCount
- 1;
53 var lastColumn
= textEditor
.line(lastLine
).length
;
54 textEditor
.setSelection(WebInspector
.TextRange
.createFromLocation(lastLine
, lastColumn
));
57 function fireEventWhileSelectionChanges(eventType
, modifiers
, callback
)
59 var oldSelection
= textEditor
.selection();
61 function eventCallback()
63 var selection
= dumpEditorSelection();
64 if (selection
.collapseToEnd().compareTo(oldSelection
.collapseToEnd()) !== 0) {
65 oldSelection
= selection
;
66 InspectorTest
.fakeKeyEvent(textEditor
, eventType
, modifiers
, eventCallback
);
71 InspectorTest
.fakeKeyEvent(textEditor
, eventType
, modifiers
, eventCallback
);
74 InspectorTest
.runTestSuite([
75 function testCtrlRightArrow(next
)
77 setCursorAtBeginning();
78 dumpEditorSelection();
79 fireEventWhileSelectionChanges("rightArrow", [wordJumpModifier
], next
);
82 function testCtrlLeftArrow(next
)
85 dumpEditorSelection();
86 fireEventWhileSelectionChanges("leftArrow", [wordJumpModifier
], next
);
89 function testCtrlShiftRightArrow(next
)
91 setCursorAtBeginning();
92 dumpEditorSelection();
93 fireEventWhileSelectionChanges("rightArrow", [wordJumpModifier
, "shiftKey"], next
);
96 function testCtrlShiftLeftArrow(next
)
99 var selection
= dumpEditorSelection();
100 fireEventWhileSelectionChanges("leftArrow", [wordJumpModifier
, "shiftKey"], next
);
103 function testCtrlBackspace(next
)
106 InspectorTest
.addResult("===============");
107 InspectorTest
.addResult(textEditor
.text());
108 function eventCallback()
110 InspectorTest
.addResult("===============");
111 InspectorTest
.addResult(textEditor
.text() + "<<");
112 if (textEditor
.text() !== "")
113 InspectorTest
.fakeKeyEvent(textEditor
, "\b", [wordJumpModifier
], eventCallback
);
117 InspectorTest
.fakeKeyEvent(textEditor
, "\b", [wordJumpModifier
], eventCallback
);
120 function testAltRight(next
)
122 InspectorTest
.addResult("====== CAMEL CASE MOVEMENTS ======");
123 textEditor
.setText(testMyCamelMove
.toString());
124 setCursorAtBeginning();
125 dumpEditorSelection();
126 fireEventWhileSelectionChanges("rightArrow", [camelJumpModifier
], next
);
129 function testAltLeft(next
)
132 dumpEditorSelection();
133 fireEventWhileSelectionChanges("leftArrow", [camelJumpModifier
], next
);
136 function testAltShiftRight(next
)
138 setCursorAtBeginning();
139 dumpEditorSelection();
140 fireEventWhileSelectionChanges("rightArrow", [camelJumpModifier
, "shiftKey"], next
);
143 function testAltShiftLeft(next
)
146 dumpEditorSelection();
147 fireEventWhileSelectionChanges("leftArrow", [camelJumpModifier
, "shiftKey"], next
);
156 <body onload=
"runTest();">
158 This test checks how text editor handles different movements: ctrl-left, ctrl-right, ctrl-shift-left, ctrl-backspace, alt-left, alt-right, alt-shift-left, alt-shift-right.