Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / LayoutTests / inspector / editor / text-editor-ctrl-d.html
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 nextOccurrence(times)
26     {
27         for (var i = 0; i < times; ++i)
28             textEditor._selectNextOccurrenceController.selectNextOccurrence();
29     }
30
31     function undoLastSelection()
32     {
33         textEditor._selectNextOccurrenceController.undoLastSelection();
34     }
35
36     function lineSelection(line, from, to)
37     {
38         if (typeof to !== "number")
39             to = from;
40         lineSelections([
41             { line: line, from: from, to: to }
42         ]);
43     }
44
45     function lineSelections(selections)
46     {
47         var coords = [];
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;
53             }
54             coords.push(new WebInspector.TextRange(selection.line, selection.from, selection.line, selection.to));
55         }
56         textEditor.setSelections(coords);
57     }
58
59     function dumpSelectionStats()
60     {
61         var listHashMap = {};
62         var sortedKeys = [];
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);
70             } else {
71                 ++listHashMap[text];
72             }
73         }
74         for (var i = 0; i < sortedKeys.length; ++i) {
75             var keyName = sortedKeys[i];
76             if (!keyName.length)
77                 keyName = "<Empty string>";
78             else
79                 keyName = "'" + keyName + "'";
80             InspectorTest.addResult(keyName + ": " + listHashMap[sortedKeys[i]]);
81         }
82     }
83
84     var testSuite = [
85         function testNextFullWord(next)
86         {
87             lineSelection(0, 3);
88             nextOccurrence(3);
89             dumpSelectionStats();
90             next();
91         },
92
93         function testOccurrencesOnTheSameLine(next)
94         {
95             lineSelection(2, 13);
96             nextOccurrence(3);
97             dumpSelectionStats();
98             next();
99         },
100
101         function testUndoLastAddedSelection(next)
102         {
103             lineSelection(2, 13);
104             nextOccurrence(3);
105             undoLastSelection();
106             dumpSelectionStats();
107             next();
108         },
109
110         function testUndoSelectionPreservesFullWordState(next)
111         {
112             lineSelection(2, 51);
113             nextOccurrence(3);
114             undoLastSelection();
115             nextOccurrence(1);
116             dumpSelectionStats();
117             var lastSelection = textEditor.selections().pop();
118             InspectorTest.addResult("Last selection: " + lastSelection.toString());
119             next();
120         },
121
122         function testUndoSelectionPreservesPartialSelection(next)
123         {
124             lineSelection(2, 48, 52);
125             nextOccurrence(2);
126             undoLastSelection();
127             nextOccurrence(1);
128             dumpSelectionStats();
129             var lastSelection = textEditor.selections().pop();
130             InspectorTest.addResult("Last selection: " + lastSelection.toString());
131             next();
132         },
133
134         function testTwoCloseWords(next)
135         {
136             lineSelection(17, 45);
137             nextOccurrence(5);
138             dumpSelectionStats();
139             next();
140         },
141
142         function testCursorInTheWordStart(next)
143         {
144             lineSelection(8, 0);
145             nextOccurrence(1);
146             dumpSelectionStats();
147             next();
148         },
149
150         function testCursorInTheWordEnd(next)
151         {
152             lineSelection(8, 8);
153             nextOccurrence(1);
154             dumpSelectionStats();
155             next();
156         },
157
158         function testNonWordSelection(next)
159         {
160             lineSelection(18, 12, 14);
161             nextOccurrence(8);
162             dumpSelectionStats();
163             next();
164         },
165
166         function testNonWordSelection2(next)
167         {
168             lineSelection(17, 30, 33);
169             nextOccurrence(8);
170             dumpSelectionStats();
171             next();
172         },
173
174         function testNonWordSelection3(next)
175         {
176             lineSelections([
177                 { line: 14, from: 15, to: 25 },
178                 { line: 16, column: 21 },
179                 { line: 17, from: 42, to: 47 },
180             ]);
181             var selections = textEditor.selections();
182             nextOccurrence(3);
183             dumpSelectionStats();
184             next();
185         },
186
187         function testNonWordSelection4(next)
188         {
189             lineSelections([
190                 { line: 14, from: 15, to: 25 },
191                 { line: 16, from: 21, to: 23 },
192                 { line: 17, from: 42, to: 47 },
193             ]);
194             var selections = textEditor.selections();
195             nextOccurrence(3);
196             dumpSelectionStats();
197             next();
198         },
199
200         function testTriggerWordSearchInMixedCase(next)
201         {
202             lineSelections([
203                 { line: 9, from: 10, to: 25 },
204                 { line: 14, column: 33 }
205             ]);
206             nextOccurrence(5);
207             dumpSelectionStats();
208             next();
209         },
210
211     ];
212 }
213
214 </script>
215 </head>
216
217 <body onload="runTest();">
218 <p>
219 This test verifies Ctrl-D functionality, which selects next occurrence of word.
220 </p>
221
222 <pre id="codeSnippet">
223 function wordData() {
224     return {
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; })
228     };
229 }
230
231 function submitWord(url) {
232     var stub = new App.Stub($(".content"));
233     $.post(url, wordData())
234     .done(function() {
235         var callback = $("meta[data-callback]").attr("data-callback");
236         if (callback) {
237             window.location = callback;
238         } else {
239             stub.success();
240             $(".entry.original > .input").text("").focus();
241             $(".entry.translation > .input").text("");
242         }
243     })
244     .fail(function(obj, err, errDescr) {
245         stub.failure("Error: " + errDescr);
246     })
247 }
248 </pre>
249
250 </body>
251 </html>