OLD | NEW |
---|---|
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> | |
8 | |
7 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
8 | 10 |
9 namespace chromeos { | 11 namespace chromeos { |
10 namespace input_method { | 12 namespace input_method { |
11 | 13 |
14 namespace { | |
Yusuke Sato
2011/12/01 07:45:28
nit: space between line 14 and 15
Seigo Nonaka
2011/12/01 08:11:49
Done.
| |
15 void ClearInputMethodLookupTable(InputMethodLookupTable* table) { | |
16 table->visible = false; | |
17 table->cursor_absolute_index = 0; | |
18 table->page_size = 10; | |
19 table->candidates.clear(); | |
20 table->orientation = InputMethodLookupTable::kVertical; | |
21 table->labels.clear(); | |
22 table->annotations.clear(); | |
23 table->mozc_candidates.Clear(); | |
24 } | |
25 | |
26 void InitializeMozcCandidates(InputMethodLookupTable* table) { | |
27 table->mozc_candidates.Clear(); | |
28 table->mozc_candidates.set_position(0); | |
29 table->mozc_candidates.set_size(0); | |
30 } | |
31 | |
32 void SetCaretRectIntoMozcCandidates( | |
33 InputMethodLookupTable* table, | |
34 mozc::commands::Candidates::CandidateWindowLocation location, | |
35 int x, | |
36 int y, | |
37 int width, | |
38 int height) { | |
39 table->mozc_candidates.set_window_location(location); | |
40 mozc::commands::Rectangle *rect = | |
41 table->mozc_candidates.mutable_composition_rectangle(); | |
42 rect->set_x(x); | |
43 rect->set_y(y); | |
44 rect->set_width(width); | |
45 rect->set_height(height); | |
46 } | |
47 | |
48 void AppendCandidateIntoMozcCandidates(InputMethodLookupTable* table, | |
49 std::string value) { | |
50 mozc::commands::Candidates::Candidate *candidate = | |
51 table->mozc_candidates.add_candidate(); | |
52 | |
53 int current_entry_count = table->mozc_candidates.candidate_size(); | |
54 candidate->set_index(current_entry_count); | |
55 candidate->set_value(value); | |
56 candidate->set_id(current_entry_count); | |
57 candidate->set_information_id(current_entry_count); | |
58 | |
59 | |
60 } | |
Yusuke Sato
2011/12/01 07:45:28
vertical space
Seigo Nonaka
2011/12/01 08:11:49
Done.
| |
61 } // namespace | |
62 | |
12 TEST(CandidateWindowViewTest, ShouldUpdateCandidateViewsTest) { | 63 TEST(CandidateWindowViewTest, ShouldUpdateCandidateViewsTest) { |
13 // This test verifies the process of judging update lookup-table or not. | 64 // This test verifies the process of judging update lookup-table or not. |
14 // This judgement is handled by ShouldUpdateCandidateViews, which returns true | 65 // This judgement is handled by ShouldUpdateCandidateViews, which returns true |
15 // if update is necessary and vice versa. | 66 // if update is necessary and vice versa. |
16 const char* kSampleCandidate1 = "Sample Candidate 1"; | 67 const char* kSampleCandidate1 = "Sample Candidate 1"; |
17 const char* kSampleCandidate2 = "Sample Candidate 2"; | 68 const char* kSampleCandidate2 = "Sample Candidate 2"; |
18 const char* kSampleCandidate3 = "Sample Candidate 3"; | 69 const char* kSampleCandidate3 = "Sample Candidate 3"; |
19 | 70 |
20 const char* kSampleAnnotation1 = "Sample Annotation 1"; | 71 const char* kSampleAnnotation1 = "Sample Annotation 1"; |
21 const char* kSampleAnnotation2 = "Sample Annotation 2"; | 72 const char* kSampleAnnotation2 = "Sample Annotation 2"; |
22 const char* kSampleAnnotation3 = "Sample Annotation 3"; | 73 const char* kSampleAnnotation3 = "Sample Annotation 3"; |
23 | 74 |
24 const char* kSampleLabel1 = "Sample Label 1"; | 75 const char* kSampleLabel1 = "Sample Label 1"; |
25 const char* kSampleLabel2 = "Sample Label 2"; | 76 const char* kSampleLabel2 = "Sample Label 2"; |
26 const char* kSampleLabel3 = "Sample Label 3"; | 77 const char* kSampleLabel3 = "Sample Label 3"; |
27 | 78 |
28 InputMethodLookupTable old_table; | 79 InputMethodLookupTable old_table; |
29 InputMethodLookupTable new_table; | 80 InputMethodLookupTable new_table; |
30 | 81 |
82 ClearInputMethodLookupTable(&old_table); | |
83 ClearInputMethodLookupTable(&new_table); | |
84 | |
31 old_table.visible = true; | 85 old_table.visible = true; |
32 old_table.cursor_absolute_index = 0; | 86 old_table.cursor_absolute_index = 0; |
33 old_table.page_size = 1; | 87 old_table.page_size = 1; |
34 old_table.candidates.clear(); | 88 old_table.candidates.clear(); |
35 old_table.orientation = InputMethodLookupTable::kVertical; | 89 old_table.orientation = InputMethodLookupTable::kVertical; |
36 old_table.labels.clear(); | 90 old_table.labels.clear(); |
37 old_table.annotations.clear(); | 91 old_table.annotations.clear(); |
38 | 92 |
39 new_table = old_table; | 93 new_table = old_table; |
40 | 94 |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
112 new_table)); | 166 new_table)); |
113 new_table.annotations.clear(); | 167 new_table.annotations.clear(); |
114 EXPECT_TRUE(CandidateWindowView::ShouldUpdateCandidateViews(old_table, | 168 EXPECT_TRUE(CandidateWindowView::ShouldUpdateCandidateViews(old_table, |
115 new_table)); | 169 new_table)); |
116 new_table.annotations.push_back(kSampleAnnotation2); | 170 new_table.annotations.push_back(kSampleAnnotation2); |
117 old_table.annotations.clear(); | 171 old_table.annotations.clear(); |
118 EXPECT_TRUE(CandidateWindowView::ShouldUpdateCandidateViews(old_table, | 172 EXPECT_TRUE(CandidateWindowView::ShouldUpdateCandidateViews(old_table, |
119 new_table)); | 173 new_table)); |
120 } | 174 } |
121 | 175 |
176 TEST(CandidateWindowViewTest, MozcSuggestWindowShouldUpdateTest) { | |
177 // ShouldUpdateCandidateViews method should also judge with consideration of | |
178 // the mozc specific candidate information. Following tests verify them. | |
179 const char* kSampleCandidate1 = "Sample Candidate 1"; | |
180 const char* kSampleCandidate2 = "Sample Candidate 2"; | |
181 | |
182 const int kCaretPositionX1 = 10; | |
183 const int kCaretPositionY1 = 20; | |
184 const int kCaretPositionWidth1 = 30; | |
185 const int kCaretPositionHeight1 = 40; | |
186 | |
187 const int kCaretPositionX2 = 15; | |
188 const int kCaretPositionY2 = 25; | |
189 const int kCaretPositionWidth2 = 35; | |
190 const int kCaretPositionHeight2 = 45; | |
191 | |
192 InputMethodLookupTable old_table; | |
193 InputMethodLookupTable new_table; | |
194 | |
195 // State chagne from using non-mozc candidate to mozc candidate. | |
196 ClearInputMethodLookupTable(&old_table); | |
197 ClearInputMethodLookupTable(&new_table); | |
198 | |
199 old_table.candidates.push_back(kSampleCandidate1); | |
200 InitializeMozcCandidates(&new_table); | |
201 AppendCandidateIntoMozcCandidates(&new_table, kSampleCandidate1); | |
202 SetCaretRectIntoMozcCandidates(&new_table, | |
203 mozc::commands::Candidates::CARET, | |
Yusuke Sato
2011/12/01 07:45:28
not sure but you mean COMPOSITION?
Seigo Nonaka
2011/12/01 08:11:49
Done.
| |
204 kCaretPositionX1, | |
205 kCaretPositionY1, | |
206 kCaretPositionWidth1, | |
207 kCaretPositionHeight1); | |
208 | |
209 EXPECT_TRUE(CandidateWindowView::ShouldUpdateCandidateViews(old_table, | |
210 new_table)); | |
211 | |
212 // State change from using mozc candidate to non-mozc candidate | |
213 ClearInputMethodLookupTable(&old_table); | |
214 ClearInputMethodLookupTable(&new_table); | |
215 | |
216 InitializeMozcCandidates(&old_table); | |
217 AppendCandidateIntoMozcCandidates(&old_table, kSampleCandidate1); | |
218 SetCaretRectIntoMozcCandidates(&old_table, | |
219 mozc::commands::Candidates::CARET, | |
220 kCaretPositionX1, | |
221 kCaretPositionY1, | |
222 kCaretPositionWidth1, | |
223 kCaretPositionHeight1); | |
224 | |
225 new_table.candidates.push_back(kSampleCandidate1); | |
226 | |
227 EXPECT_TRUE(CandidateWindowView::ShouldUpdateCandidateViews(old_table, | |
228 new_table)); | |
229 | |
230 // State change from using mozc candidate to mozc candidate | |
231 | |
232 // No change | |
233 ClearInputMethodLookupTable(&old_table); | |
234 ClearInputMethodLookupTable(&new_table); | |
235 | |
236 InitializeMozcCandidates(&old_table); | |
237 AppendCandidateIntoMozcCandidates(&old_table, kSampleCandidate1); | |
238 SetCaretRectIntoMozcCandidates(&old_table, | |
239 mozc::commands::Candidates::CARET, | |
240 kCaretPositionX1, | |
241 kCaretPositionY1, | |
242 kCaretPositionWidth1, | |
243 kCaretPositionHeight1); | |
244 | |
245 InitializeMozcCandidates(&new_table); | |
246 AppendCandidateIntoMozcCandidates(&new_table, kSampleCandidate1); | |
247 SetCaretRectIntoMozcCandidates(&new_table, | |
248 mozc::commands::Candidates::CARET, | |
249 kCaretPositionX1, | |
250 kCaretPositionY1, | |
251 kCaretPositionWidth1, | |
252 kCaretPositionHeight1); | |
253 | |
254 EXPECT_FALSE(CandidateWindowView::ShouldUpdateCandidateViews(old_table, | |
255 new_table)); | |
256 // Position change only | |
257 ClearInputMethodLookupTable(&old_table); | |
258 ClearInputMethodLookupTable(&new_table); | |
259 | |
260 InitializeMozcCandidates(&old_table); | |
261 AppendCandidateIntoMozcCandidates(&old_table, kSampleCandidate1); | |
262 SetCaretRectIntoMozcCandidates(&old_table, | |
263 mozc::commands::Candidates::CARET, | |
264 kCaretPositionX1, | |
265 kCaretPositionY1, | |
266 kCaretPositionWidth1, | |
267 kCaretPositionHeight1); | |
268 | |
269 InitializeMozcCandidates(&new_table); | |
270 AppendCandidateIntoMozcCandidates(&new_table, kSampleCandidate1); | |
271 SetCaretRectIntoMozcCandidates(&new_table, | |
272 mozc::commands::Candidates::CARET, | |
273 kCaretPositionX2, | |
274 kCaretPositionY2, | |
275 kCaretPositionWidth2, | |
276 kCaretPositionHeight2); | |
277 | |
278 EXPECT_TRUE(CandidateWindowView::ShouldUpdateCandidateViews(old_table, | |
279 new_table)); | |
280 // Candidate contents only | |
281 ClearInputMethodLookupTable(&old_table); | |
282 ClearInputMethodLookupTable(&new_table); | |
283 | |
284 InitializeMozcCandidates(&old_table); | |
285 AppendCandidateIntoMozcCandidates(&old_table, kSampleCandidate1); | |
286 SetCaretRectIntoMozcCandidates(&old_table, | |
287 mozc::commands::Candidates::CARET, | |
288 kCaretPositionX1, | |
289 kCaretPositionY1, | |
290 kCaretPositionWidth1, | |
291 kCaretPositionHeight1); | |
292 | |
293 InitializeMozcCandidates(&new_table); | |
294 AppendCandidateIntoMozcCandidates(&new_table, kSampleCandidate2); | |
295 SetCaretRectIntoMozcCandidates(&new_table, | |
296 mozc::commands::Candidates::CARET, | |
297 kCaretPositionX1, | |
298 kCaretPositionY1, | |
299 kCaretPositionWidth1, | |
300 kCaretPositionHeight1); | |
301 | |
302 EXPECT_TRUE(CandidateWindowView::ShouldUpdateCandidateViews(old_table, | |
303 new_table)); | |
304 | |
305 // Both candidate and position | |
306 ClearInputMethodLookupTable(&old_table); | |
307 ClearInputMethodLookupTable(&new_table); | |
308 | |
309 InitializeMozcCandidates(&old_table); | |
310 AppendCandidateIntoMozcCandidates(&old_table, kSampleCandidate1); | |
311 SetCaretRectIntoMozcCandidates(&old_table, | |
312 mozc::commands::Candidates::CARET, | |
313 kCaretPositionX1, | |
314 kCaretPositionY1, | |
315 kCaretPositionWidth1, | |
316 kCaretPositionHeight1); | |
317 | |
318 InitializeMozcCandidates(&new_table); | |
319 AppendCandidateIntoMozcCandidates(&new_table, kSampleCandidate2); | |
320 SetCaretRectIntoMozcCandidates(&new_table, | |
321 mozc::commands::Candidates::CARET, | |
322 kCaretPositionX2, | |
323 kCaretPositionY2, | |
324 kCaretPositionWidth2, | |
325 kCaretPositionHeight2); | |
326 | |
327 EXPECT_TRUE(CandidateWindowView::ShouldUpdateCandidateViews(old_table, | |
328 new_table)); | |
329 } | |
330 | |
122 } // namespace input_method | 331 } // namespace input_method |
123 } // namespace chromeos | 332 } // namespace chromeos |
OLD | NEW |