Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / inspector / editor / text-editor-word-jumps.html
blobe38696b8e52b9da3f673668ef62b29a6ed2baf1d
1 <html>
2 <head>
3 <script src="../../http/tests/inspector/inspector-test.js"></script>
4 <script src="editor-test.js"></script>
5 <script>
6 function test()
8 function testFunction(foo, bar)
10 someFunctionCall(bar);
11 var b = 42;
12 return a === 1 ? true : false;
15 function testMyCamelMove(foo, bar)
17 /* HelloWorld.TestSTRIng */
19 var a = e === 2;
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));
39 } else {
40 InspectorTest.addResult(">>" + textEditor.copyRange(selection.normalize()) + "<<");
42 return selection;
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);
67 } else {
68 callback();
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)
84 setCursorAtEnd();
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)
98 setCursorAtEnd();
99 var selection = dumpEditorSelection();
100 fireEventWhileSelectionChanges("leftArrow", [wordJumpModifier, "shiftKey"], next);
103 function testCtrlBackspace(next)
105 setCursorAtEnd();
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);
114 else
115 next();
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)
131 setCursorAtEnd();
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)
145 setCursorAtEnd();
146 dumpEditorSelection();
147 fireEventWhileSelectionChanges("leftArrow", [camelJumpModifier, "shiftKey"], next);
153 </script>
154 </head>
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.
159 </p>
161 </body>
162 </html>