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

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

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

Powered by Google App Engine
This is Rietveld 408576698