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 // TODO(nona): Add unittests for UpdateCandidates. | |
5 | 4 |
6 #include "chrome/browser/chromeos/input_method/candidate_window_view.h" | 5 #include "chrome/browser/chromeos/input_method/candidate_window_view.h" |
7 | 6 |
8 #include <string> | 7 #include <string> |
9 | 8 |
9 #include "base/message_loop.h" | |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
11 #include "ui/views/widget/widget.h" | |
11 | 12 |
12 namespace chromeos { | 13 namespace chromeos { |
13 namespace input_method { | 14 namespace input_method { |
14 | 15 |
15 namespace { | 16 namespace { |
16 | 17 |
17 void ClearInputMethodLookupTable(InputMethodLookupTable* table) { | 18 void ClearInputMethodLookupTable(InputMethodLookupTable* table) { |
18 table->visible = false; | 19 table->visible = false; |
19 table->cursor_absolute_index = 0; | 20 table->cursor_absolute_index = 0; |
20 table->page_size = 10; | 21 table->page_size = 10; |
(...skipping 29 matching lines...) Expand all Loading... | |
50 void AppendCandidateIntoMozcCandidates(InputMethodLookupTable* table, | 51 void AppendCandidateIntoMozcCandidates(InputMethodLookupTable* table, |
51 std::string value) { | 52 std::string value) { |
52 mozc::commands::Candidates::Candidate *candidate = | 53 mozc::commands::Candidates::Candidate *candidate = |
53 table->mozc_candidates.add_candidate(); | 54 table->mozc_candidates.add_candidate(); |
54 | 55 |
55 int current_entry_count = table->mozc_candidates.candidate_size(); | 56 int current_entry_count = table->mozc_candidates.candidate_size(); |
56 candidate->set_index(current_entry_count); | 57 candidate->set_index(current_entry_count); |
57 candidate->set_value(value); | 58 candidate->set_value(value); |
58 candidate->set_id(current_entry_count); | 59 candidate->set_id(current_entry_count); |
59 candidate->set_information_id(current_entry_count); | 60 candidate->set_information_id(current_entry_count); |
60 | |
61 | |
62 } | 61 } |
63 | 62 |
64 } // namespace | 63 } // namespace |
65 | 64 |
66 TEST(CandidateWindowViewTest, ShouldUpdateCandidateViewsTest) { | 65 class CandidateWindowViewTest: public testing::Test { |
66 private: | |
67 MessageLoopForUI message_loop_; | |
Hiro Komatsu
2011/12/08 02:14:57
I guess this is not explicitly used, but needed to
Seigo Nonaka
2011/12/08 02:31:21
Done.
| |
68 }; | |
69 | |
70 TEST_F(CandidateWindowViewTest, ShouldUpdateCandidateViewsTest) { | |
67 // This test verifies the process of judging update lookup-table or not. | 71 // This test verifies the process of judging update lookup-table or not. |
68 // This judgement is handled by ShouldUpdateCandidateViews, which returns true | 72 // This judgement is handled by ShouldUpdateCandidateViews, which returns true |
69 // if update is necessary and vice versa. | 73 // if update is necessary and vice versa. |
70 const char* kSampleCandidate1 = "Sample Candidate 1"; | 74 const char* kSampleCandidate1 = "Sample Candidate 1"; |
71 const char* kSampleCandidate2 = "Sample Candidate 2"; | 75 const char* kSampleCandidate2 = "Sample Candidate 2"; |
72 const char* kSampleCandidate3 = "Sample Candidate 3"; | 76 const char* kSampleCandidate3 = "Sample Candidate 3"; |
73 | 77 |
74 const char* kSampleAnnotation1 = "Sample Annotation 1"; | 78 const char* kSampleAnnotation1 = "Sample Annotation 1"; |
75 const char* kSampleAnnotation2 = "Sample Annotation 2"; | 79 const char* kSampleAnnotation2 = "Sample Annotation 2"; |
76 const char* kSampleAnnotation3 = "Sample Annotation 3"; | 80 const char* kSampleAnnotation3 = "Sample Annotation 3"; |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
169 new_table)); | 173 new_table)); |
170 new_table.annotations.clear(); | 174 new_table.annotations.clear(); |
171 EXPECT_TRUE(CandidateWindowView::ShouldUpdateCandidateViews(old_table, | 175 EXPECT_TRUE(CandidateWindowView::ShouldUpdateCandidateViews(old_table, |
172 new_table)); | 176 new_table)); |
173 new_table.annotations.push_back(kSampleAnnotation2); | 177 new_table.annotations.push_back(kSampleAnnotation2); |
174 old_table.annotations.clear(); | 178 old_table.annotations.clear(); |
175 EXPECT_TRUE(CandidateWindowView::ShouldUpdateCandidateViews(old_table, | 179 EXPECT_TRUE(CandidateWindowView::ShouldUpdateCandidateViews(old_table, |
176 new_table)); | 180 new_table)); |
177 } | 181 } |
178 | 182 |
179 TEST(CandidateWindowViewTest, MozcSuggestWindowShouldUpdateTest) { | 183 TEST_F(CandidateWindowViewTest, MozcSuggestWindowShouldUpdateTest) { |
180 // ShouldUpdateCandidateViews method should also judge with consideration of | 184 // ShouldUpdateCandidateViews method should also judge with consideration of |
181 // the mozc specific candidate information. Following tests verify them. | 185 // the mozc specific candidate information. Following tests verify them. |
182 const char* kSampleCandidate1 = "Sample Candidate 1"; | 186 const char* kSampleCandidate1 = "Sample Candidate 1"; |
183 const char* kSampleCandidate2 = "Sample Candidate 2"; | 187 const char* kSampleCandidate2 = "Sample Candidate 2"; |
184 | 188 |
185 const int kCaretPositionX1 = 10; | 189 const int kCaretPositionX1 = 10; |
186 const int kCaretPositionY1 = 20; | 190 const int kCaretPositionY1 = 20; |
187 const int kCaretPositionWidth1 = 30; | 191 const int kCaretPositionWidth1 = 30; |
188 const int kCaretPositionHeight1 = 40; | 192 const int kCaretPositionHeight1 = 40; |
189 | 193 |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
324 mozc::commands::Candidates::COMPOSITION, | 328 mozc::commands::Candidates::COMPOSITION, |
325 kCaretPositionX2, | 329 kCaretPositionX2, |
326 kCaretPositionY2, | 330 kCaretPositionY2, |
327 kCaretPositionWidth2, | 331 kCaretPositionWidth2, |
328 kCaretPositionHeight2); | 332 kCaretPositionHeight2); |
329 | 333 |
330 EXPECT_TRUE(CandidateWindowView::ShouldUpdateCandidateViews(old_table, | 334 EXPECT_TRUE(CandidateWindowView::ShouldUpdateCandidateViews(old_table, |
331 new_table)); | 335 new_table)); |
332 } | 336 } |
333 | 337 |
338 TEST_F(CandidateWindowViewTest, MozcUpdateCandidateTest) { | |
339 // This test verifies whether UpdateCandidates function updates window mozc | |
340 // specific candidate position correctly on the correct condition. | |
341 views::Widget widget; | |
342 views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP); | |
343 params.bounds = gfx::Rect(0, 0, 100, 100); | |
344 widget.Init(params); | |
345 | |
346 CandidateWindowView candidate_window_view(&widget); | |
347 candidate_window_view.Init(); | |
348 | |
349 const int kCaretPositionX1 = 10; | |
350 const int kCaretPositionY1 = 20; | |
351 const int kCaretPositionWidth1 = 30; | |
352 const int kCaretPositionHeight1 = 40; | |
353 | |
354 const int kCaretPositionX2 = 15; | |
355 const int kCaretPositionY2 = 25; | |
356 const int kCaretPositionWidth2 = 35; | |
357 const int kCaretPositionHeight2 = 45; | |
358 | |
359 InputMethodLookupTable new_table; | |
360 ClearInputMethodLookupTable(&new_table); | |
361 InitializeMozcCandidates(&new_table); | |
362 | |
363 // If window location is CARET, use default position. So | |
364 // is_suggestion_window_location_available_ should be false. | |
365 SetCaretRectIntoMozcCandidates(&new_table, | |
366 mozc::commands::Candidates::CARET, | |
367 kCaretPositionX1, | |
368 kCaretPositionY1, | |
369 kCaretPositionWidth1, | |
370 kCaretPositionHeight1); | |
371 candidate_window_view.UpdateCandidates(new_table); | |
372 EXPECT_FALSE(candidate_window_view.is_suggestion_window_location_available_); | |
373 | |
374 // If window location is COMPOSITION, update position and set | |
375 // is_suggestion_window_location_available_ as true. | |
376 SetCaretRectIntoMozcCandidates(&new_table, | |
377 mozc::commands::Candidates::COMPOSITION, | |
378 kCaretPositionX1, | |
379 kCaretPositionY1, | |
380 kCaretPositionWidth1, | |
381 kCaretPositionHeight1); | |
382 candidate_window_view.UpdateCandidates(new_table); | |
383 EXPECT_TRUE(candidate_window_view.is_suggestion_window_location_available_); | |
384 EXPECT_EQ(kCaretPositionX1, | |
385 candidate_window_view.suggestion_window_location_.x()); | |
386 EXPECT_EQ(kCaretPositionY1, | |
387 candidate_window_view.suggestion_window_location_.y()); | |
388 EXPECT_EQ(kCaretPositionWidth1, | |
389 candidate_window_view.suggestion_window_location_.width()); | |
390 EXPECT_EQ(kCaretPositionHeight1, | |
391 candidate_window_view.suggestion_window_location_.height()); | |
392 | |
393 SetCaretRectIntoMozcCandidates(&new_table, | |
394 mozc::commands::Candidates::COMPOSITION, | |
395 kCaretPositionX2, | |
396 kCaretPositionY2, | |
397 kCaretPositionWidth2, | |
398 kCaretPositionHeight2); | |
399 candidate_window_view.UpdateCandidates(new_table); | |
400 EXPECT_TRUE(candidate_window_view.is_suggestion_window_location_available_); | |
401 EXPECT_EQ(kCaretPositionX2, | |
402 candidate_window_view.suggestion_window_location_.x()); | |
403 EXPECT_EQ(kCaretPositionY2, | |
404 candidate_window_view.suggestion_window_location_.y()); | |
405 EXPECT_EQ(kCaretPositionWidth2, | |
406 candidate_window_view.suggestion_window_location_.width()); | |
407 EXPECT_EQ(kCaretPositionHeight2, | |
408 candidate_window_view.suggestion_window_location_.height()); | |
409 } | |
334 } // namespace input_method | 410 } // namespace input_method |
335 } // namespace chromeos | 411 } // namespace chromeos |
OLD | NEW |