Commit 5ca4959f authored by nona@chromium.org's avatar nona@chromium.org

Add unittest for updating mozc candidates.

BUG=chromium-os:23640
TEST=run unit_tests


Review URL: http://codereview.chromium.org/8833008

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@113601 0039d316-1c4b-4281-b951-d872f2087c98
parent f1346b7f
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#ifndef CHROME_BROWSER_CHROMEOS_INPUT_METHOD_CANDIDATE_WINDOW_VIEW_H_ #ifndef CHROME_BROWSER_CHROMEOS_INPUT_METHOD_CANDIDATE_WINDOW_VIEW_H_
#define CHROME_BROWSER_CHROMEOS_INPUT_METHOD_CANDIDATE_WINDOW_VIEW_H_ #define CHROME_BROWSER_CHROMEOS_INPUT_METHOD_CANDIDATE_WINDOW_VIEW_H_
#include "base/gtest_prod_util.h"
#include "chrome/browser/chromeos/input_method/ibus_ui_controller.h" #include "chrome/browser/chromeos/input_method/ibus_ui_controller.h"
#include "ui/views/view.h" #include "ui/views/view.h"
...@@ -133,6 +134,8 @@ class CandidateWindowView : public views::View { ...@@ -133,6 +134,8 @@ class CandidateWindowView : public views::View {
virtual void OnBoundsChanged(const gfx::Rect& previous_bounds) OVERRIDE; virtual void OnBoundsChanged(const gfx::Rect& previous_bounds) OVERRIDE;
private: private:
FRIEND_TEST_ALL_PREFIXES(CandidateWindowViewTest, MozcUpdateCandidateTest);
// Initializes the candidate views if needed. // Initializes the candidate views if needed.
void MaybeInitializeCandidateViews( void MaybeInitializeCandidateViews(
const InputMethodLookupTable& lookup_table); const InputMethodLookupTable& lookup_table);
......
// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// TODO(nona): Add unittests for UpdateCandidates.
#include "chrome/browser/chromeos/input_method/candidate_window_view.h" #include "chrome/browser/chromeos/input_method/candidate_window_view.h"
#include <string> #include <string>
#include "base/message_loop.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "ui/views/widget/widget.h"
namespace chromeos { namespace chromeos {
namespace input_method { namespace input_method {
...@@ -57,13 +58,18 @@ void AppendCandidateIntoMozcCandidates(InputMethodLookupTable* table, ...@@ -57,13 +58,18 @@ void AppendCandidateIntoMozcCandidates(InputMethodLookupTable* table,
candidate->set_value(value); candidate->set_value(value);
candidate->set_id(current_entry_count); candidate->set_id(current_entry_count);
candidate->set_information_id(current_entry_count); candidate->set_information_id(current_entry_count);
} }
} // namespace } // namespace
TEST(CandidateWindowViewTest, ShouldUpdateCandidateViewsTest) { class CandidateWindowViewTest: public testing::Test {
private:
// This message loop is not explicitly used, but necessary for views control
// testings.
MessageLoopForUI message_loop_;
};
TEST_F(CandidateWindowViewTest, ShouldUpdateCandidateViewsTest) {
// This test verifies the process of judging update lookup-table or not. // This test verifies the process of judging update lookup-table or not.
// This judgement is handled by ShouldUpdateCandidateViews, which returns true // This judgement is handled by ShouldUpdateCandidateViews, which returns true
// if update is necessary and vice versa. // if update is necessary and vice versa.
...@@ -176,7 +182,7 @@ TEST(CandidateWindowViewTest, ShouldUpdateCandidateViewsTest) { ...@@ -176,7 +182,7 @@ TEST(CandidateWindowViewTest, ShouldUpdateCandidateViewsTest) {
new_table)); new_table));
} }
TEST(CandidateWindowViewTest, MozcSuggestWindowShouldUpdateTest) { TEST_F(CandidateWindowViewTest, MozcSuggestWindowShouldUpdateTest) {
// ShouldUpdateCandidateViews method should also judge with consideration of // ShouldUpdateCandidateViews method should also judge with consideration of
// the mozc specific candidate information. Following tests verify them. // the mozc specific candidate information. Following tests verify them.
const char* kSampleCandidate1 = "Sample Candidate 1"; const char* kSampleCandidate1 = "Sample Candidate 1";
...@@ -331,5 +337,77 @@ TEST(CandidateWindowViewTest, MozcSuggestWindowShouldUpdateTest) { ...@@ -331,5 +337,77 @@ TEST(CandidateWindowViewTest, MozcSuggestWindowShouldUpdateTest) {
new_table)); new_table));
} }
TEST_F(CandidateWindowViewTest, MozcUpdateCandidateTest) {
// This test verifies whether UpdateCandidates function updates window mozc
// specific candidate position correctly on the correct condition.
views::Widget widget;
views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP);
params.bounds = gfx::Rect(0, 0, 100, 100);
widget.Init(params);
CandidateWindowView candidate_window_view(&widget);
candidate_window_view.Init();
const int kCaretPositionX1 = 10;
const int kCaretPositionY1 = 20;
const int kCaretPositionWidth1 = 30;
const int kCaretPositionHeight1 = 40;
const int kCaretPositionX2 = 15;
const int kCaretPositionY2 = 25;
const int kCaretPositionWidth2 = 35;
const int kCaretPositionHeight2 = 45;
InputMethodLookupTable new_table;
ClearInputMethodLookupTable(&new_table);
InitializeMozcCandidates(&new_table);
// If window location is CARET, use default position. So
// is_suggestion_window_location_available_ should be false.
SetCaretRectIntoMozcCandidates(&new_table,
mozc::commands::Candidates::CARET,
kCaretPositionX1,
kCaretPositionY1,
kCaretPositionWidth1,
kCaretPositionHeight1);
candidate_window_view.UpdateCandidates(new_table);
EXPECT_FALSE(candidate_window_view.is_suggestion_window_location_available_);
// If window location is COMPOSITION, update position and set
// is_suggestion_window_location_available_ as true.
SetCaretRectIntoMozcCandidates(&new_table,
mozc::commands::Candidates::COMPOSITION,
kCaretPositionX1,
kCaretPositionY1,
kCaretPositionWidth1,
kCaretPositionHeight1);
candidate_window_view.UpdateCandidates(new_table);
EXPECT_TRUE(candidate_window_view.is_suggestion_window_location_available_);
EXPECT_EQ(kCaretPositionX1,
candidate_window_view.suggestion_window_location_.x());
EXPECT_EQ(kCaretPositionY1,
candidate_window_view.suggestion_window_location_.y());
EXPECT_EQ(kCaretPositionWidth1,
candidate_window_view.suggestion_window_location_.width());
EXPECT_EQ(kCaretPositionHeight1,
candidate_window_view.suggestion_window_location_.height());
SetCaretRectIntoMozcCandidates(&new_table,
mozc::commands::Candidates::COMPOSITION,
kCaretPositionX2,
kCaretPositionY2,
kCaretPositionWidth2,
kCaretPositionHeight2);
candidate_window_view.UpdateCandidates(new_table);
EXPECT_TRUE(candidate_window_view.is_suggestion_window_location_available_);
EXPECT_EQ(kCaretPositionX2,
candidate_window_view.suggestion_window_location_.x());
EXPECT_EQ(kCaretPositionY2,
candidate_window_view.suggestion_window_location_.y());
EXPECT_EQ(kCaretPositionWidth2,
candidate_window_view.suggestion_window_location_.width());
EXPECT_EQ(kCaretPositionHeight2,
candidate_window_view.suggestion_window_location_.height());
}
} // namespace input_method } // namespace input_method
} // namespace chromeos } // namespace chromeos
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment