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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chromeos/input_method/ibus_controller_base_unittest.cc
diff --git a/chrome/browser/chromeos/input_method/ibus_controller_base_unittest.cc b/chrome/browser/chromeos/input_method/ibus_controller_base_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..a44aabff7e00b639dc7332b932f295537d8f5f18
--- /dev/null
+++ b/chrome/browser/chromeos/input_method/ibus_controller_base_unittest.cc
@@ -0,0 +1,200 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/logging.h"
+#include "base/memory/scoped_ptr.h"
+#include "chrome/browser/chromeos/input_method/ibus_controller_base.h"
+#include "chrome/browser/chromeos/input_method/input_method_config.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace chromeos {
+namespace input_method {
+
+namespace {
+
+// A mock class for testing SetInputMethodConfig(), AddObserver(), and
+// RemoveObserver() methods in IBusControllerBase.
+class TestIBusController : public IBusControllerBase {
+ public:
+ TestIBusController()
+ : set_input_method_config_internal_count_(0),
+ set_input_method_config_internal_return_(true) {
+ }
+ virtual ~TestIBusController() {
+ }
+
+ // IBusController overrides:
+ virtual bool Start() OVERRIDE {
+ return true;
+ }
+ virtual bool Stop() OVERRIDE {
+ return true;
+ }
+ virtual bool ChangeInputMethod(const std::string& id) OVERRIDE {
+ return true;
+ }
+ virtual bool ActivateInputMethodProperty(const std::string& key) OVERRIDE {
+ return true;
+ }
+#if defined(USE_VIRTUAL_KEYBOARD)
+ virtual void SendHandwritingStroke(const HandwritingStroke& stroke) OVERRIDE {
+ }
+ virtual void CancelHandwriting(int n_strokes) OVERRIDE {
+ }
+#endif
+
+ size_t GetObserverCount() const {
+ return observers_.size();
+ }
+
+ int set_input_method_config_internal_count() const {
+ return set_input_method_config_internal_count_;
+ }
+ void set_set_input_method_config_internal_return(bool new_value) {
+ set_input_method_config_internal_return_ = new_value;
+ }
+ const ConfigKeyType& last_key() const { return last_key_; }
+
+ protected:
+ virtual bool SetInputMethodConfigInternal(
+ const ConfigKeyType& key,
+ const InputMethodConfigValue& value) OVERRIDE {
+ ++set_input_method_config_internal_count_;
+ last_key_ = key;
+ return set_input_method_config_internal_return_;
+ }
+
+ private:
+ int set_input_method_config_internal_count_;
+ bool set_input_method_config_internal_return_;
+ ConfigKeyType last_key_;
+
+ DISALLOW_COPY_AND_ASSIGN(TestIBusController);
+};
+
+class TestObserver : public IBusController::Observer {
+ public:
+ // IBusController::Observer overrides:
+ virtual void PropertyChanged() OVERRIDE {}
+};
+
+class IBusControllerBaseTest : public testing::Test {
+ public:
+ virtual void SetUp() {
+ controller_.reset(new TestIBusController);
+ }
+ virtual void TearDown() {
+ controller_.reset();
+ }
+
+ protected:
+ scoped_ptr<TestIBusController> controller_;
+};
+
+} // namespace
+
+TEST_F(IBusControllerBaseTest, TestSetInputMethodConfig) {
+ InputMethodConfigValue value_set;
+ InputMethodConfigValue value_get;
+ EXPECT_FALSE(controller_->GetInputMethodConfigForTesting("section",
+ "name",
+ &value_get));
+ EXPECT_EQ(0, controller_->set_input_method_config_internal_count());
+
+ // Set a value.
+ value_set.type = InputMethodConfigValue::kValueTypeInt;
+ value_set.int_value = 12345;
+ EXPECT_TRUE(controller_->SetInputMethodConfig("section",
+ "name",
+ value_set));
+ EXPECT_EQ(1, controller_->set_input_method_config_internal_count());
+ EXPECT_EQ("section", controller_->last_key().first);
+ EXPECT_EQ("name", controller_->last_key().second);
+
+ // Get the value.
+ EXPECT_TRUE(controller_->GetInputMethodConfigForTesting("section",
+ "name",
+ &value_get));
+ EXPECT_EQ(value_set.type, value_get.type);
+ EXPECT_EQ(value_set.int_value, value_get.int_value);
+
+ // Set another value.
+ value_set.type = InputMethodConfigValue::kValueTypeBool;
+ value_set.bool_value = true;
+ EXPECT_TRUE(controller_->SetInputMethodConfig("section/2",
+ "name2",
+ value_set));
+ EXPECT_EQ(2, controller_->set_input_method_config_internal_count());
+ EXPECT_EQ("section/2", controller_->last_key().first);
+ EXPECT_EQ("name2", controller_->last_key().second);
+
+ // Overwrite the first value.
+ value_set.type = InputMethodConfigValue::kValueTypeInt;
+ value_set.int_value = 54321;
+ EXPECT_TRUE(controller_->SetInputMethodConfig("section",
+ "name",
+ value_set));
+ EXPECT_EQ(3, controller_->set_input_method_config_internal_count());
+ EXPECT_EQ("section", controller_->last_key().first);
+ EXPECT_EQ("name", controller_->last_key().second);
+
+ // Get the value.
+ EXPECT_TRUE(controller_->GetInputMethodConfigForTesting("section",
+ "name",
+ &value_get));
+ EXPECT_EQ(value_set.type, value_get.type);
+ EXPECT_EQ(value_set.int_value, value_get.int_value);
+
+ // Get a non existent value.
+ EXPECT_FALSE(controller_->GetInputMethodConfigForTesting("sectionX",
+ "name",
+ &value_get));
+ EXPECT_FALSE(controller_->GetInputMethodConfigForTesting("section",
+ "nameX",
+ &value_get));
+}
+
+TEST_F(IBusControllerBaseTest, TestSetInputMethodConfigInternal) {
+ InputMethodConfigValue value_set;
+ InputMethodConfigValue value_get;
+ // Set a value. In this case, SetInputMethodConfigInternal returns false.
+ controller_->set_set_input_method_config_internal_return(false);
+ value_set.type = InputMethodConfigValue::kValueTypeInt;
+ value_set.int_value = 12345;
+ EXPECT_FALSE(controller_->SetInputMethodConfig("section",
+ "name",
+ value_set));
+ EXPECT_EQ(1, controller_->set_input_method_config_internal_count());
+
+ // Getting the value should fail.
+ EXPECT_FALSE(controller_->GetInputMethodConfigForTesting("section",
+ "name",
+ &value_get));
+}
+
+TEST_F(IBusControllerBaseTest, TestAddRemoveObserver) {
+ TestObserver observer1;
+ TestObserver observer2;
+ TestObserver observer3;
+ EXPECT_EQ(0U, controller_->GetObserverCount());
+ controller_->AddObserver(&observer1);
+ EXPECT_EQ(1U, controller_->GetObserverCount());
+ controller_->AddObserver(&observer2);
+ EXPECT_EQ(2U, controller_->GetObserverCount());
+ controller_->RemoveObserver(&observer3); // nop
+ EXPECT_EQ(2U, controller_->GetObserverCount());
+ controller_->RemoveObserver(&observer1);
+ EXPECT_EQ(1U, controller_->GetObserverCount());
+ controller_->RemoveObserver(&observer1); // nop
+ EXPECT_EQ(1U, controller_->GetObserverCount());
+ controller_->RemoveObserver(&observer2);
+ EXPECT_EQ(0U, controller_->GetObserverCount());
+}
+
+TEST_F(IBusControllerBaseTest, TestGetCurrentProperties) {
+ EXPECT_EQ(0U, controller_->GetCurrentProperties().size());
+}
+
+} // namespace input_method
+} // namespace chromeos

Powered by Google App Engine
This is Rietveld 408576698