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

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

Issue 9999018: chrome/browser/chromeos/input_method/ refactoring [part 6 of 6] (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 8 years, 8 months 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
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "base/logging.h"
6 #include "base/memory/scoped_ptr.h"
7 #include "chrome/browser/chromeos/input_method/ibus_controller_base.h"
8 #include "chrome/browser/chromeos/input_method/input_method_config.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10
11 namespace chromeos {
12 namespace input_method {
13
14 namespace {
15
16 // A mock class for testing SetInputMethodConfig(), AddObserver(), and
17 // RemoveObserver() methods in IBusControllerBase.
18 class TestIBusController : public IBusControllerBase {
19 public:
20 TestIBusController()
21 : set_input_method_config_internal_count_(0),
22 set_input_method_config_internal_return_(true) {
23 }
24 virtual ~TestIBusController() {
25 }
26
27 // IBusController overrides:
28 virtual bool Start() OVERRIDE {
29 return true;
30 }
31 virtual bool Stop() OVERRIDE {
32 return true;
33 }
34 virtual bool ChangeInputMethod(const std::string& id) OVERRIDE {
35 return true;
36 }
37 virtual bool ActivateInputMethodProperty(const std::string& key) OVERRIDE {
38 return true;
39 }
40 #if defined(USE_VIRTUAL_KEYBOARD)
41 virtual void SendHandwritingStroke(const HandwritingStroke& stroke) OVERRIDE {
42 }
43 virtual void CancelHandwriting(int n_strokes) OVERRIDE {
44 }
45 #endif
46
47 size_t GetObserverCount() const {
48 return observers_.size();
49 }
50
51 int set_input_method_config_internal_count() const {
52 return set_input_method_config_internal_count_;
53 }
54 void set_set_input_method_config_internal_return(bool new_value) {
55 set_input_method_config_internal_return_ = new_value;
56 }
57 const ConfigKeyType& last_key() const { return last_key_; }
58
59 protected:
60 virtual bool SetInputMethodConfigInternal(
61 const ConfigKeyType& key,
62 const InputMethodConfigValue& value) OVERRIDE {
63 ++set_input_method_config_internal_count_;
64 last_key_ = key;
65 return set_input_method_config_internal_return_;
66 }
67
68 private:
69 int set_input_method_config_internal_count_;
70 bool set_input_method_config_internal_return_;
71 ConfigKeyType last_key_;
72
73 DISALLOW_COPY_AND_ASSIGN(TestIBusController);
74 };
75
76 class TestObserver : public IBusController::Observer {
77 public:
78 // IBusController::Observer overrides:
79 virtual void PropertyChanged() OVERRIDE {}
80 };
81
82 class IBusControllerBaseTest : public testing::Test {
83 public:
84 virtual void SetUp() {
85 controller_.reset(new TestIBusController);
86 }
87 virtual void TearDown() {
88 controller_.reset();
89 }
90
91 protected:
92 scoped_ptr<TestIBusController> controller_;
93 };
94
95 } // namespace
96
97 TEST_F(IBusControllerBaseTest, TestSetInputMethodConfig) {
98 InputMethodConfigValue value_set;
99 InputMethodConfigValue value_get;
100 EXPECT_FALSE(controller_->GetInputMethodConfigForTesting("section",
101 "name",
102 &value_get));
103 EXPECT_EQ(0, controller_->set_input_method_config_internal_count());
104
105 // Set a value.
106 value_set.type = InputMethodConfigValue::kValueTypeInt;
107 value_set.int_value = 12345;
108 EXPECT_TRUE(controller_->SetInputMethodConfig("section",
109 "name",
110 value_set));
111 EXPECT_EQ(1, controller_->set_input_method_config_internal_count());
112 EXPECT_EQ("section", controller_->last_key().first);
113 EXPECT_EQ("name", controller_->last_key().second);
114
115 // Get the value.
116 EXPECT_TRUE(controller_->GetInputMethodConfigForTesting("section",
117 "name",
118 &value_get));
119 EXPECT_EQ(value_set.type, value_get.type);
120 EXPECT_EQ(value_set.int_value, value_get.int_value);
121
122 // Set another value.
123 value_set.type = InputMethodConfigValue::kValueTypeBool;
124 value_set.bool_value = true;
125 EXPECT_TRUE(controller_->SetInputMethodConfig("section/2",
126 "name2",
127 value_set));
128 EXPECT_EQ(2, controller_->set_input_method_config_internal_count());
129 EXPECT_EQ("section/2", controller_->last_key().first);
130 EXPECT_EQ("name2", controller_->last_key().second);
131
132 // Overwrite the first value.
133 value_set.type = InputMethodConfigValue::kValueTypeInt;
134 value_set.int_value = 54321;
135 EXPECT_TRUE(controller_->SetInputMethodConfig("section",
136 "name",
137 value_set));
138 EXPECT_EQ(3, controller_->set_input_method_config_internal_count());
139 EXPECT_EQ("section", controller_->last_key().first);
140 EXPECT_EQ("name", controller_->last_key().second);
141
142 // Get the value.
143 EXPECT_TRUE(controller_->GetInputMethodConfigForTesting("section",
144 "name",
145 &value_get));
146 EXPECT_EQ(value_set.type, value_get.type);
147 EXPECT_EQ(value_set.int_value, value_get.int_value);
148
149 // Get a non existent value.
150 EXPECT_FALSE(controller_->GetInputMethodConfigForTesting("sectionX",
151 "name",
152 &value_get));
153 EXPECT_FALSE(controller_->GetInputMethodConfigForTesting("section",
154 "nameX",
155 &value_get));
156 }
157
158 TEST_F(IBusControllerBaseTest, TestSetInputMethodConfigInternal) {
159 InputMethodConfigValue value_set;
160 InputMethodConfigValue value_get;
161 // Set a value. In this case, SetInputMethodConfigInternal returns false.
162 controller_->set_set_input_method_config_internal_return(false);
163 value_set.type = InputMethodConfigValue::kValueTypeInt;
164 value_set.int_value = 12345;
165 EXPECT_FALSE(controller_->SetInputMethodConfig("section",
166 "name",
167 value_set));
168 EXPECT_EQ(1, controller_->set_input_method_config_internal_count());
169
170 // Getting the value should fail.
171 EXPECT_FALSE(controller_->GetInputMethodConfigForTesting("section",
172 "name",
173 &value_get));
174 }
175
176 TEST_F(IBusControllerBaseTest, TestAddRemoveObserver) {
177 TestObserver observer1;
178 TestObserver observer2;
179 TestObserver observer3;
180 EXPECT_EQ(0U, controller_->GetObserverCount());
181 controller_->AddObserver(&observer1);
182 EXPECT_EQ(1U, controller_->GetObserverCount());
183 controller_->AddObserver(&observer2);
184 EXPECT_EQ(2U, controller_->GetObserverCount());
185 controller_->RemoveObserver(&observer3); // nop
186 EXPECT_EQ(2U, controller_->GetObserverCount());
187 controller_->RemoveObserver(&observer1);
188 EXPECT_EQ(1U, controller_->GetObserverCount());
189 controller_->RemoveObserver(&observer1); // nop
190 EXPECT_EQ(1U, controller_->GetObserverCount());
191 controller_->RemoveObserver(&observer2);
192 EXPECT_EQ(0U, controller_->GetObserverCount());
193 }
194
195 TEST_F(IBusControllerBaseTest, TestGetCurrentProperties) {
196 EXPECT_EQ(0U, controller_->GetCurrentProperties().size());
197 }
198
199 } // namespace input_method
200 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698