Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(257)

Side by Side Diff: chrome/browser/chromeos/input_method/candidate_window_view_unittest.cc

Issue 8505051: Support mozc suggest window on ChromeOS. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Apply latest mozc repository. Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/chromeos/input_method/candidate_window_view.h" 5 #include "chrome/browser/chromeos/input_method/candidate_window_view.h"
6 6
7 #include <string>
Yusuke Sato 2011/11/30 13:38:20 nit: space between line 7&8
Seigo Nonaka 2011/12/01 07:10:01 Done.
7 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
8 9
9 namespace chromeos { 10 namespace chromeos {
10 namespace input_method { 11 namespace input_method {
11 12
13 namespace {
14 void ClearInputMethodLookupTable(InputMethodLookupTable* table) {
15 table->visible = false;
16 table->cursor_absolute_index = 0;
17 table->page_size = 10;
18 table->candidates.clear();
19 table->orientation = InputMethodLookupTable::kVertical;
20 table->labels.clear();
21 table->annotations.clear();
22 table->mozc_candidates.Clear();
23 }
24
25 void InitializeMozcCandidates(InputMethodLookupTable* table) {
26 table->mozc_candidates.Clear();
27 table->mozc_candidates.set_position(0);
28 table->mozc_candidates.set_size(0);
29 }
30
31 void SetCaretRectIntoMozcCandidates(
32 InputMethodLookupTable* table,
33 mozc::commands::Candidates::CandidateWindowLocation location,
34 int x,
35 int y,
36 int width,
37 int height) {
38 table->mozc_candidates.set_window_location(location);
39 mozc::commands::Rectangle *rect =
40 table->mozc_candidates.mutable_composition_rectangle();
41 rect->set_x(x);
42 rect->set_y(y);
43 rect->set_width(width);
44 rect->set_height(height);
45 }
46
47 void AppendCandidateIntoMozcCandidates(InputMethodLookupTable* table,
48 std::string value) {
49 mozc::commands::Candidates::Candidate *candidate =
50 table->mozc_candidates.add_candidate();
51
52 int current_entry_count = table->mozc_candidates.candidate_size();
53 candidate->set_index(current_entry_count);
54 candidate->set_value(value);
55 candidate->set_id(current_entry_count);
56 candidate->set_information_id(current_entry_count);
57
58
59 }
60 } // namespace
61
12 TEST(CandidateWindowViewTest, ShouldUpdateCandidateViewsTest) { 62 TEST(CandidateWindowViewTest, ShouldUpdateCandidateViewsTest) {
13 // This test verifies the process of judging update lookup-table or not. 63 // This test verifies the process of judging update lookup-table or not.
14 // This judgement is handled by ShouldUpdateCandidateViews, which returns true 64 // This judgement is handled by ShouldUpdateCandidateViews, which returns true
15 // if update is necessary and vice versa. 65 // if update is necessary and vice versa.
16 const char* kSampleCandidate1 = "Sample Candidate 1"; 66 const char* kSampleCandidate1 = "Sample Candidate 1";
17 const char* kSampleCandidate2 = "Sample Candidate 2"; 67 const char* kSampleCandidate2 = "Sample Candidate 2";
18 const char* kSampleCandidate3 = "Sample Candidate 3"; 68 const char* kSampleCandidate3 = "Sample Candidate 3";
19 69
20 const char* kSampleAnnotation1 = "Sample Annotation 1"; 70 const char* kSampleAnnotation1 = "Sample Annotation 1";
21 const char* kSampleAnnotation2 = "Sample Annotation 2"; 71 const char* kSampleAnnotation2 = "Sample Annotation 2";
22 const char* kSampleAnnotation3 = "Sample Annotation 3"; 72 const char* kSampleAnnotation3 = "Sample Annotation 3";
23 73
24 const char* kSampleLabel1 = "Sample Label 1"; 74 const char* kSampleLabel1 = "Sample Label 1";
25 const char* kSampleLabel2 = "Sample Label 2"; 75 const char* kSampleLabel2 = "Sample Label 2";
26 const char* kSampleLabel3 = "Sample Label 3"; 76 const char* kSampleLabel3 = "Sample Label 3";
27 77
28 InputMethodLookupTable old_table; 78 InputMethodLookupTable old_table;
29 InputMethodLookupTable new_table; 79 InputMethodLookupTable new_table;
30 80
81 ClearInputMethodLookupTable(&old_table);
82 ClearInputMethodLookupTable(&new_table);
83
31 old_table.visible = true; 84 old_table.visible = true;
32 old_table.cursor_absolute_index = 0; 85 old_table.cursor_absolute_index = 0;
33 old_table.page_size = 1; 86 old_table.page_size = 1;
34 old_table.candidates.clear(); 87 old_table.candidates.clear();
35 old_table.orientation = InputMethodLookupTable::kVertical; 88 old_table.orientation = InputMethodLookupTable::kVertical;
36 old_table.labels.clear(); 89 old_table.labels.clear();
37 old_table.annotations.clear(); 90 old_table.annotations.clear();
38 91
39 new_table = old_table; 92 new_table = old_table;
40 93
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 new_table)); 165 new_table));
113 new_table.annotations.clear(); 166 new_table.annotations.clear();
114 EXPECT_TRUE(CandidateWindowView::ShouldUpdateCandidateViews(old_table, 167 EXPECT_TRUE(CandidateWindowView::ShouldUpdateCandidateViews(old_table,
115 new_table)); 168 new_table));
116 new_table.annotations.push_back(kSampleAnnotation2); 169 new_table.annotations.push_back(kSampleAnnotation2);
117 old_table.annotations.clear(); 170 old_table.annotations.clear();
118 EXPECT_TRUE(CandidateWindowView::ShouldUpdateCandidateViews(old_table, 171 EXPECT_TRUE(CandidateWindowView::ShouldUpdateCandidateViews(old_table,
119 new_table)); 172 new_table));
120 } 173 }
121 174
175 TEST(CandidateWindowViewTest, MozcSuggestWindowShouldUpdateTest) {
176 // This test verifies the process of judging update lookup-table or not with
Yusuke Sato 2011/11/30 13:38:20 I couldn't parse this sentence..
Seigo Nonaka 2011/12/01 07:10:01 Done.
177 // mozc candidates.
178 const char* kSampleCandidate1 = "Sample Candidate 1";
179 const char* kSampleCandidate2 = "Sample Candidate 2";
180
181 const int kCaretPositionX1 = 10;
182 const int kCaretPositionY1 = 20;
183 const int kCaretPositionWidth1 = 30;
184 const int kCaretPositionHeight1 = 40;
185
186 const int kCaretPositionX2 = 15;
187 const int kCaretPositionY2 = 25;
188 const int kCaretPositionWidth2 = 35;
189 const int kCaretPositionHeight2 = 45;
190
191 InputMethodLookupTable old_table;
192 InputMethodLookupTable new_table;
193
194 // State chagne from non-Mozc candidate to Mozc candidate.
Yusuke Sato 2011/11/30 13:38:20 be consistent: Mozc or mozc. You're using the lat
Seigo Nonaka 2011/12/01 07:10:01 Done.
195 ClearInputMethodLookupTable(&old_table);
196 ClearInputMethodLookupTable(&new_table);
197
198 old_table.candidates.push_back(kSampleCandidate1);
199 InitializeMozcCandidates(&new_table);
200 AppendCandidateIntoMozcCandidates(&new_table, kSampleCandidate1);
201 SetCaretRectIntoMozcCandidates(&new_table,
202 mozc::commands::Candidates::CARET,
203 kCaretPositionX1,
204 kCaretPositionY1,
205 kCaretPositionWidth1,
206 kCaretPositionHeight1);
207
208 EXPECT_TRUE(CandidateWindowView::ShouldUpdateCandidateViews(old_table,
209 new_table));
210
211 // State change from Mozc candidate to non-Mozc candidate
212 ClearInputMethodLookupTable(&old_table);
213 ClearInputMethodLookupTable(&new_table);
214
215 InitializeMozcCandidates(&old_table);
216 AppendCandidateIntoMozcCandidates(&old_table, kSampleCandidate1);
217 SetCaretRectIntoMozcCandidates(&old_table,
218 mozc::commands::Candidates::CARET,
219 kCaretPositionX1,
220 kCaretPositionY1,
221 kCaretPositionWidth1,
222 kCaretPositionHeight1);
223
224 new_table.candidates.push_back(kSampleCandidate1);
225
226 EXPECT_TRUE(CandidateWindowView::ShouldUpdateCandidateViews(old_table,
227 new_table));
228
229 // State change from Mozc candidate to Mozc candidate
230
231 // No change
232 ClearInputMethodLookupTable(&old_table);
233 ClearInputMethodLookupTable(&new_table);
234
235 InitializeMozcCandidates(&old_table);
236 AppendCandidateIntoMozcCandidates(&old_table, kSampleCandidate1);
237 SetCaretRectIntoMozcCandidates(&old_table,
238 mozc::commands::Candidates::CARET,
239 kCaretPositionX1,
240 kCaretPositionY1,
241 kCaretPositionWidth1,
242 kCaretPositionHeight1);
243
244 InitializeMozcCandidates(&new_table);
245 AppendCandidateIntoMozcCandidates(&new_table, kSampleCandidate1);
246 SetCaretRectIntoMozcCandidates(&new_table,
247 mozc::commands::Candidates::CARET,
248 kCaretPositionX1,
249 kCaretPositionY1,
250 kCaretPositionWidth1,
251 kCaretPositionHeight1);
252
253 EXPECT_FALSE(CandidateWindowView::ShouldUpdateCandidateViews(old_table,
254 new_table));
255 // Position change only
256 ClearInputMethodLookupTable(&old_table);
257 ClearInputMethodLookupTable(&new_table);
258
259 InitializeMozcCandidates(&old_table);
260 AppendCandidateIntoMozcCandidates(&old_table, kSampleCandidate1);
261 SetCaretRectIntoMozcCandidates(&old_table,
262 mozc::commands::Candidates::CARET,
263 kCaretPositionX1,
264 kCaretPositionY1,
265 kCaretPositionWidth1,
266 kCaretPositionHeight1);
267
268 InitializeMozcCandidates(&new_table);
269 AppendCandidateIntoMozcCandidates(&new_table, kSampleCandidate1);
270 SetCaretRectIntoMozcCandidates(&new_table,
271 mozc::commands::Candidates::CARET,
272 kCaretPositionX2,
273 kCaretPositionY2,
274 kCaretPositionWidth2,
275 kCaretPositionHeight2);
276
277 EXPECT_TRUE(CandidateWindowView::ShouldUpdateCandidateViews(old_table,
278 new_table));
279 // Candidate contents only
280 ClearInputMethodLookupTable(&old_table);
281 ClearInputMethodLookupTable(&new_table);
282
283 InitializeMozcCandidates(&old_table);
284 AppendCandidateIntoMozcCandidates(&old_table, kSampleCandidate1);
285 SetCaretRectIntoMozcCandidates(&old_table,
286 mozc::commands::Candidates::CARET,
287 kCaretPositionX1,
288 kCaretPositionY1,
289 kCaretPositionWidth1,
290 kCaretPositionHeight1);
291
292 InitializeMozcCandidates(&new_table);
293 AppendCandidateIntoMozcCandidates(&new_table, kSampleCandidate2);
294 SetCaretRectIntoMozcCandidates(&new_table,
295 mozc::commands::Candidates::CARET,
296 kCaretPositionX1,
297 kCaretPositionY1,
298 kCaretPositionWidth1,
299 kCaretPositionHeight1);
300
301 EXPECT_TRUE(CandidateWindowView::ShouldUpdateCandidateViews(old_table,
302 new_table));
303
304 // Both candidate and position
305 ClearInputMethodLookupTable(&old_table);
306 ClearInputMethodLookupTable(&new_table);
307
308 InitializeMozcCandidates(&old_table);
309 AppendCandidateIntoMozcCandidates(&old_table, kSampleCandidate1);
310 SetCaretRectIntoMozcCandidates(&old_table,
311 mozc::commands::Candidates::CARET,
312 kCaretPositionX1,
313 kCaretPositionY1,
314 kCaretPositionWidth1,
315 kCaretPositionHeight1);
316
317 InitializeMozcCandidates(&new_table);
318 AppendCandidateIntoMozcCandidates(&new_table, kSampleCandidate2);
319 SetCaretRectIntoMozcCandidates(&new_table,
320 mozc::commands::Candidates::CARET,
321 kCaretPositionX2,
322 kCaretPositionY2,
323 kCaretPositionWidth2,
324 kCaretPositionHeight2);
325
326 EXPECT_TRUE(CandidateWindowView::ShouldUpdateCandidateViews(old_table,
327 new_table));
328 }
329
122 } // namespace input_method 330 } // namespace input_method
123 } // namespace chromeos 331 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698