OLD | NEW |
---|---|
(Empty) | |
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 codeSnippet() { | |
7 return document.getElementById("codeSnippet").textContent; | |
8 } | |
9 | |
10 function test() | |
11 { | |
12 var textEditor = InspectorTest.createTestEditor(); | |
13 textEditor.setMimeType("text/javascript"); | |
14 textEditor.setReadOnly(false); | |
15 textEditor.element.focus(); | |
16 InspectorTest.evaluateInPage("codeSnippet();", onCodeSnippet); | |
17 | |
18 function onCodeSnippet(result) | |
19 { | |
20 var codeLines = result.value; | |
21 textEditor.setText(codeLines); | |
22 InspectorTest.runTestSuite(testSuite); | |
23 } | |
24 | |
25 function nextOccurence(times) | |
apavlov
2014/04/01 08:24:58
"occurrence" here and elsewhere
| |
26 { | |
27 for (var i = 0; i < times; ++i) | |
28 textEditor._selectNextOccurenceController.selectNextOccurence(); | |
29 } | |
30 | |
31 function lineSelection(line, from, to) | |
32 { | |
33 if (typeof to !== "number") | |
34 to = from; | |
35 lineSelections([ | |
36 { line: line, from: from, to: to } | |
37 ]); | |
38 } | |
39 | |
40 function lineSelections(selections) | |
41 { | |
42 var coords = []; | |
43 for (var i = 0; i < selections.length; ++i) { | |
44 var selection = selections[i]; | |
45 if (selection.column) { | |
46 selection.from = selection.column; | |
47 selection.to = selection.column; | |
48 } | |
49 coords.push(new WebInspector.TextRange(selection.line, selection.fro m, selection.line, selection.to)); | |
50 } | |
51 textEditor.setSelections(coords); | |
52 } | |
53 | |
54 function dumpSelectionStats() | |
55 { | |
56 var listHashMap = {}; | |
57 var sortedKeys = []; | |
58 var selections = textEditor.selections(); | |
59 for (var i = 0; i < selections.length; ++i) { | |
60 var selection = selections[i]; | |
61 var text = textEditor.copyRange(selection); | |
62 if (!listHashMap[text]) { | |
63 listHashMap[text] = 1; | |
64 sortedKeys.push(text); | |
65 } else { | |
66 ++listHashMap[text]; | |
67 } | |
68 } | |
69 for (var i = 0; i < sortedKeys.length; ++i) { | |
70 var keyName = sortedKeys[i]; | |
71 if (!keyName.length) | |
72 keyName = "<Empty string>"; | |
73 else | |
74 keyName = "'" + keyName + "'"; | |
75 InspectorTest.addResult(keyName + ": " + listHashMap[sortedKeys[i]]) ; | |
76 } | |
77 } | |
78 | |
79 var testSuite = [ | |
80 function testNextFullWord(next) | |
81 { | |
82 lineSelection(0, 3); | |
83 nextOccurence(3); | |
84 dumpSelectionStats(); | |
85 next(); | |
86 }, | |
87 | |
88 function testOccurencesOnTheSameLine(next) | |
89 { | |
90 lineSelection(2, 13); | |
91 nextOccurence(3); | |
92 dumpSelectionStats(); | |
93 next(); | |
94 }, | |
95 | |
96 function testTwoCloseWords(next) | |
97 { | |
98 lineSelection(17, 45); | |
99 nextOccurence(5); | |
100 dumpSelectionStats(); | |
101 next(); | |
102 }, | |
103 | |
104 function testCursorInTheWordStart(next) | |
105 { | |
106 lineSelection(8, 0); | |
107 nextOccurence(1); | |
108 dumpSelectionStats(); | |
109 next(); | |
110 }, | |
111 | |
112 function testCursorInTheWordEnd(next) | |
113 { | |
114 lineSelection(8, 8); | |
115 nextOccurence(1); | |
116 dumpSelectionStats(); | |
117 next(); | |
118 }, | |
119 | |
120 function testNonWordSelection(next) | |
121 { | |
122 lineSelection(18, 12, 14); | |
123 nextOccurence(8); | |
124 dumpSelectionStats(); | |
125 next(); | |
126 }, | |
127 | |
128 function testNonWordSelection2(next) | |
129 { | |
130 lineSelection(17, 30, 33); | |
131 nextOccurence(8); | |
132 dumpSelectionStats(); | |
133 next(); | |
134 }, | |
135 | |
136 function testNonWordSelection3(next) | |
137 { | |
138 lineSelections([ | |
139 { line: 14, from: 15, to: 25 }, | |
140 { line: 16, column: 21 }, | |
141 { line: 17, from: 42, to: 47 }, | |
142 ]); | |
143 var selections = textEditor.selections(); | |
144 nextOccurence(3); | |
145 dumpSelectionStats(); | |
146 next(); | |
147 }, | |
148 | |
149 function testNonWordSelection4(next) | |
150 { | |
151 lineSelections([ | |
152 { line: 14, from: 15, to: 25 }, | |
153 { line: 16, from: 21, to: 23 }, | |
154 { line: 17, from: 42, to: 47 }, | |
155 ]); | |
156 var selections = textEditor.selections(); | |
157 nextOccurence(3); | |
158 dumpSelectionStats(); | |
159 next(); | |
160 }, | |
161 | |
162 function testTriggerWordSearchInMixedCase(next) | |
163 { | |
164 lineSelections([ | |
165 { line: 9, from: 10, to: 25 }, | |
166 { line: 14, column: 33 } | |
167 ]); | |
168 nextOccurence(5); | |
169 dumpSelectionStats(); | |
170 next(); | |
171 }, | |
172 | |
173 ]; | |
174 } | |
175 | |
176 </script> | |
177 </head> | |
178 | |
179 <body onload="runTest();"> | |
180 <p> | |
181 This test verifies Ctrl-D functionality, which selects next occurence of word. | |
182 </p> | |
183 | |
184 <pre id="codeSnippet"> | |
185 function wordData() { | |
186 return { | |
187 original: $(".entry.original > .input").text(), | |
188 translation: $(".entry.translation > .input").text(), | |
189 tags: $(".active-tags > .tagcloud > .tag").toArray().map(function(value) { return value.textContent; }) | |
190 }; | |
191 } | |
192 | |
193 function submitWord(url) { | |
194 var stub = new App.Stub($(".content")); | |
195 $.post(url, wordData()) | |
196 .done(function() { | |
197 var callback = $("meta[data-callback]").attr("data-callback"); | |
198 if (callback) { | |
199 window.location = callback; | |
200 } else { | |
201 stub.success(); | |
202 $(".entry.original > .input").text("").focus(); | |
203 $(".entry.translation > .input").text(""); | |
204 } | |
205 }) | |
206 .fail(function(obj, err, errDescr) { | |
207 stub.failure("Error: " + errDescr); | |
208 }) | |
209 } | |
210 </pre> | |
211 | |
212 </body> | |
213 </html> | |
OLD | NEW |