3 <script src="../../http/tests/inspector/inspector-test.js"></script>
4 <script src="editor-test.js"></script>
6 function codeSnippet() {
7 return document.getElementById("codeSnippet").textContent;
12 var textEditor = InspectorTest.createTestEditor();
13 textEditor.setMimeType("text/javascript");
14 textEditor.setReadOnly(false);
15 textEditor.element.focus();
16 InspectorTest.evaluateInPage("codeSnippet();", onCodeSnippet);
18 function onCodeSnippet(result)
20 var codeLines = result.value;
21 textEditor.setText(codeLines);
22 InspectorTest.runTestSuite(testSuite);
25 function nextOccurrence(times)
27 for (var i = 0; i < times; ++i)
28 textEditor._selectNextOccurrenceController.selectNextOccurrence();
31 function undoLastSelection()
33 textEditor._selectNextOccurrenceController.undoLastSelection();
36 function lineSelection(line, from, to)
38 if (typeof to !== "number")
41 { line: line, from: from, to: to }
45 function lineSelections(selections)
48 for (var i = 0; i < selections.length; ++i) {
49 var selection = selections[i];
50 if (selection.column) {
51 selection.from = selection.column;
52 selection.to = selection.column;
54 coords.push(new WebInspector.TextRange(selection.line, selection.from, selection.line, selection.to));
56 textEditor.setSelections(coords);
59 function dumpSelectionStats()
63 var selections = textEditor.selections();
64 for (var i = 0; i < selections.length; ++i) {
65 var selection = selections[i];
66 var text = textEditor.copyRange(selection);
67 if (!listHashMap[text]) {
68 listHashMap[text] = 1;
69 sortedKeys.push(text);
74 for (var i = 0; i < sortedKeys.length; ++i) {
75 var keyName = sortedKeys[i];
77 keyName = "<Empty string>";
79 keyName = "'" + keyName + "'";
80 InspectorTest.addResult(keyName + ": " + listHashMap[sortedKeys[i]]);
85 function testNextFullWord(next)
93 function testOccurrencesOnTheSameLine(next)
101 function testUndoLastAddedSelection(next)
103 lineSelection(2, 13);
106 dumpSelectionStats();
110 function testUndoSelectionPreservesFullWordState(next)
112 lineSelection(2, 51);
116 dumpSelectionStats();
117 var lastSelection = textEditor.selections().pop();
118 InspectorTest.addResult("Last selection: " + lastSelection.toString());
122 function testUndoSelectionPreservesPartialSelection(next)
124 lineSelection(2, 48, 52);
128 dumpSelectionStats();
129 var lastSelection = textEditor.selections().pop();
130 InspectorTest.addResult("Last selection: " + lastSelection.toString());
134 function testTwoCloseWords(next)
136 lineSelection(17, 45);
138 dumpSelectionStats();
142 function testCursorInTheWordStart(next)
146 dumpSelectionStats();
150 function testCursorInTheWordEnd(next)
154 dumpSelectionStats();
158 function testNonWordSelection(next)
160 lineSelection(18, 12, 14);
162 dumpSelectionStats();
166 function testNonWordSelection2(next)
168 lineSelection(17, 30, 33);
170 dumpSelectionStats();
174 function testNonWordSelection3(next)
177 { line: 14, from: 15, to: 25 },
178 { line: 16, column: 21 },
179 { line: 17, from: 42, to: 47 },
181 var selections = textEditor.selections();
183 dumpSelectionStats();
187 function testNonWordSelection4(next)
190 { line: 14, from: 15, to: 25 },
191 { line: 16, from: 21, to: 23 },
192 { line: 17, from: 42, to: 47 },
194 var selections = textEditor.selections();
196 dumpSelectionStats();
200 function testTriggerWordSearchInMixedCase(next)
203 { line: 9, from: 10, to: 25 },
204 { line: 14, column: 33 }
207 dumpSelectionStats();
217 <body onload="runTest();">
219 This test verifies Ctrl-D functionality, which selects next occurrence of word.
222 <pre id="codeSnippet">
223 function wordData() {
225 original: $(".entry.original > .input").text(),
226 translation: $(".entry.translation > .input").text(),
227 tags: $(".active-tags > .tagcloud > .tag").toArray().map(function(value) { return value.textContent; })
231 function submitWord(url) {
232 var stub = new App.Stub($(".content"));
233 $.post(url, wordData())
235 var callback = $("meta[data-callback]").attr("data-callback");
237 window.location = callback;
240 $(".entry.original > .input").text("").focus();
241 $(".entry.translation > .input").text("");
244 .fail(function(obj, err, errDescr) {
245 stub.failure("Error: " + errDescr);