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

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

Issue 8833008: Add unittest for updating mozc candidates. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Remove suppression entry 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 // 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
10 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "ui/views/test/views_test_base.h"
11 #include "ui/views/widget/widget.h"
12
13 typedef views::ViewsTestBase CandidateWindowViewTest;
11 14
12 namespace chromeos { 15 namespace chromeos {
13 namespace input_method { 16 namespace input_method {
14 17
15 namespace { 18 namespace {
16 19
17 void ClearInputMethodLookupTable(InputMethodLookupTable* table) { 20 void ClearInputMethodLookupTable(InputMethodLookupTable* table) {
18 table->visible = false; 21 table->visible = false;
19 table->cursor_absolute_index = 0; 22 table->cursor_absolute_index = 0;
20 table->page_size = 10; 23 table->page_size = 10;
(...skipping 29 matching lines...) Expand all
50 void AppendCandidateIntoMozcCandidates(InputMethodLookupTable* table, 53 void AppendCandidateIntoMozcCandidates(InputMethodLookupTable* table,
51 std::string value) { 54 std::string value) {
52 mozc::commands::Candidates::Candidate *candidate = 55 mozc::commands::Candidates::Candidate *candidate =
53 table->mozc_candidates.add_candidate(); 56 table->mozc_candidates.add_candidate();
54 57
55 int current_entry_count = table->mozc_candidates.candidate_size(); 58 int current_entry_count = table->mozc_candidates.candidate_size();
56 candidate->set_index(current_entry_count); 59 candidate->set_index(current_entry_count);
57 candidate->set_value(value); 60 candidate->set_value(value);
58 candidate->set_id(current_entry_count); 61 candidate->set_id(current_entry_count);
59 candidate->set_information_id(current_entry_count); 62 candidate->set_information_id(current_entry_count);
60
61
62 } 63 }
63 64
64 } // namespace 65 } // namespace
65 66
66 TEST(CandidateWindowViewTest, ShouldUpdateCandidateViewsTest) { 67 TEST_F(CandidateWindowViewTest, ShouldUpdateCandidateViewsTest) {
67 // This test verifies the process of judging update lookup-table or not. 68 // This test verifies the process of judging update lookup-table or not.
68 // This judgement is handled by ShouldUpdateCandidateViews, which returns true 69 // This judgement is handled by ShouldUpdateCandidateViews, which returns true
69 // if update is necessary and vice versa. 70 // if update is necessary and vice versa.
70 const char* kSampleCandidate1 = "Sample Candidate 1"; 71 const char* kSampleCandidate1 = "Sample Candidate 1";
71 const char* kSampleCandidate2 = "Sample Candidate 2"; 72 const char* kSampleCandidate2 = "Sample Candidate 2";
72 const char* kSampleCandidate3 = "Sample Candidate 3"; 73 const char* kSampleCandidate3 = "Sample Candidate 3";
73 74
74 const char* kSampleAnnotation1 = "Sample Annotation 1"; 75 const char* kSampleAnnotation1 = "Sample Annotation 1";
75 const char* kSampleAnnotation2 = "Sample Annotation 2"; 76 const char* kSampleAnnotation2 = "Sample Annotation 2";
76 const char* kSampleAnnotation3 = "Sample Annotation 3"; 77 const char* kSampleAnnotation3 = "Sample Annotation 3";
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 new_table)); 170 new_table));
170 new_table.annotations.clear(); 171 new_table.annotations.clear();
171 EXPECT_TRUE(CandidateWindowView::ShouldUpdateCandidateViews(old_table, 172 EXPECT_TRUE(CandidateWindowView::ShouldUpdateCandidateViews(old_table,
172 new_table)); 173 new_table));
173 new_table.annotations.push_back(kSampleAnnotation2); 174 new_table.annotations.push_back(kSampleAnnotation2);
174 old_table.annotations.clear(); 175 old_table.annotations.clear();
175 EXPECT_TRUE(CandidateWindowView::ShouldUpdateCandidateViews(old_table, 176 EXPECT_TRUE(CandidateWindowView::ShouldUpdateCandidateViews(old_table,
176 new_table)); 177 new_table));
177 } 178 }
178 179
179 TEST(CandidateWindowViewTest, MozcSuggestWindowShouldUpdateTest) { 180 TEST_F(CandidateWindowViewTest, MozcSuggestWindowShouldUpdateTest) {
180 // ShouldUpdateCandidateViews method should also judge with consideration of 181 // ShouldUpdateCandidateViews method should also judge with consideration of
181 // the mozc specific candidate information. Following tests verify them. 182 // the mozc specific candidate information. Following tests verify them.
182 const char* kSampleCandidate1 = "Sample Candidate 1"; 183 const char* kSampleCandidate1 = "Sample Candidate 1";
183 const char* kSampleCandidate2 = "Sample Candidate 2"; 184 const char* kSampleCandidate2 = "Sample Candidate 2";
184 185
185 const int kCaretPositionX1 = 10; 186 const int kCaretPositionX1 = 10;
186 const int kCaretPositionY1 = 20; 187 const int kCaretPositionY1 = 20;
187 const int kCaretPositionWidth1 = 30; 188 const int kCaretPositionWidth1 = 30;
188 const int kCaretPositionHeight1 = 40; 189 const int kCaretPositionHeight1 = 40;
189 190
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 mozc::commands::Candidates::COMPOSITION, 325 mozc::commands::Candidates::COMPOSITION,
325 kCaretPositionX2, 326 kCaretPositionX2,
326 kCaretPositionY2, 327 kCaretPositionY2,
327 kCaretPositionWidth2, 328 kCaretPositionWidth2,
328 kCaretPositionHeight2); 329 kCaretPositionHeight2);
329 330
330 EXPECT_TRUE(CandidateWindowView::ShouldUpdateCandidateViews(old_table, 331 EXPECT_TRUE(CandidateWindowView::ShouldUpdateCandidateViews(old_table,
331 new_table)); 332 new_table));
332 } 333 }
333 334
335 TEST_F(CandidateWindowViewTest, MozcUpdateCandidateTest) {
336 // This test verifies whether UpdateCandidates function updates window mozc
337 // specific candidate position correctly on the correct condition.
338
339 // For testing, we have to prepare empty widget.
340 // We should NOT manually free widget by default, otherwise double free will
341 // be occurred. So, we should instantiate widget class with "new" operation.
342 views::Widget* widget = new views::Widget;
343 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
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
410 // We should call CloseNow method, otherwise this test will leak memory.
411 widget->CloseNow();
412 }
334 } // namespace input_method 413 } // namespace input_method
335 } // namespace chromeos 414 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/input_method/candidate_window_view.h ('k') | tools/heapcheck/suppressions.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698