diff options
author | nona@chromium.org <nona@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-06-26 19:08:39 +0000 |
---|---|---|
committer | nona@chromium.org <nona@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-06-26 19:08:39 +0000 |
commit | 489f6a6293d929e9e7bf5a51479d2f99ee8bfa38 (patch) | |
tree | 39d7e399368cd92a14e100e0242f62de41ebf2a4 /chromeos | |
parent | 68b48df0bd62c5bc8193b5a33c6052ad4c3a94f4 (diff) | |
download | chromium_src-489f6a6293d929e9e7bf5a51479d2f99ee8bfa38.zip chromium_src-489f6a6293d929e9e7bf5a51479d2f99ee8bfa38.tar.gz chromium_src-489f6a6293d929e9e7bf5a51479d2f99ee8bfa38.tar.bz2 |
Change InputMethodIBus unittests to IBusClient free one.
Before removing the IBusClient, remove IBusClient dependency from InputMethodIBusUnittests.
BUG=126947
TEST=ran ui_unittests
Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=144101
Review URL: https://chromiumcodereview.appspot.com/10668012
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@144226 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chromeos')
-rw-r--r-- | chromeos/dbus/ibus/ibus_input_context_client.cc | 4 | ||||
-rw-r--r-- | chromeos/dbus/ibus/ibus_input_context_client.h | 6 | ||||
-rw-r--r-- | chromeos/dbus/ibus/ibus_input_context_client_unittest.cc | 4 | ||||
-rw-r--r-- | chromeos/dbus/ibus/mock_ibus_client.cc | 7 | ||||
-rw-r--r-- | chromeos/dbus/ibus/mock_ibus_client.h | 24 | ||||
-rw-r--r-- | chromeos/dbus/ibus/mock_ibus_input_context_client.cc | 27 | ||||
-rw-r--r-- | chromeos/dbus/ibus/mock_ibus_input_context_client.h | 48 | ||||
-rw-r--r-- | chromeos/dbus/mock_dbus_thread_manager_without_gmock.cc | 7 | ||||
-rw-r--r-- | chromeos/dbus/mock_dbus_thread_manager_without_gmock.h | 6 |
9 files changed, 120 insertions, 13 deletions
diff --git a/chromeos/dbus/ibus/ibus_input_context_client.cc b/chromeos/dbus/ibus/ibus_input_context_client.cc index 10e7d6f..8083f8c 100644 --- a/chromeos/dbus/ibus/ibus_input_context_client.cc +++ b/chromeos/dbus/ibus/ibus_input_context_client.cc @@ -67,7 +67,7 @@ class IBusInputContextClientImpl : public IBusInputContextClient { } // IBusInputContextClient override. - virtual bool IsConnected() const OVERRIDE { + virtual bool IsObjectProxyReady() const OVERRIDE { return proxy_ != NULL; } @@ -374,7 +374,7 @@ class IBusInputContextClientStubImpl : public IBusInputContextClient { // IBusInputContextClient override. virtual void ResetObjectProxy() OVERRIDE {} // IBusInputContextClient override. - virtual bool IsConnected() const OVERRIDE { + virtual bool IsObjectProxyReady() const OVERRIDE { return true; } // IBusInputContextClient overrides. diff --git a/chromeos/dbus/ibus/ibus_input_context_client.h b/chromeos/dbus/ibus/ibus_input_context_client.h index 3b543f2..7edc577 100644 --- a/chromeos/dbus/ibus/ibus_input_context_client.h +++ b/chromeos/dbus/ibus/ibus_input_context_client.h @@ -52,9 +52,9 @@ class CHROMEOS_EXPORT IBusInputContextClient { // Initialize function again. virtual void ResetObjectProxy() = 0; - // Returns true if connected to target input context path, otherwise return - // false. - virtual bool IsConnected() const = 0; + // Returns true if the object proxy is ready to communicate with ibus-daemon, + // otherwise return false. + virtual bool IsObjectProxyReady() const = 0; // Signal handler accessors. Setting function can be called multiple times. If // you call setting function multiple times, previous callback will be diff --git a/chromeos/dbus/ibus/ibus_input_context_client_unittest.cc b/chromeos/dbus/ibus/ibus_input_context_client_unittest.cc index c4429b1..d01b3a5 100644 --- a/chromeos/dbus/ibus/ibus_input_context_client_unittest.cc +++ b/chromeos/dbus/ibus/ibus_input_context_client_unittest.cc @@ -147,9 +147,9 @@ class IBusInputContextClientTest : public testing::Test { } virtual void TearDown() OVERRIDE { - EXPECT_TRUE(client_->IsConnected()); + EXPECT_TRUE(client_->IsObjectProxyReady()); client_->ResetObjectProxy(); - EXPECT_FALSE(client_->IsConnected()); + EXPECT_FALSE(client_->IsObjectProxyReady()); } // Handles FocusIn method call. diff --git a/chromeos/dbus/ibus/mock_ibus_client.cc b/chromeos/dbus/ibus/mock_ibus_client.cc index bf97086..d185f5f 100644 --- a/chromeos/dbus/ibus/mock_ibus_client.cc +++ b/chromeos/dbus/ibus/mock_ibus_client.cc @@ -6,7 +6,9 @@ namespace chromeos { -MockIBusClient::MockIBusClient() {} +MockIBusClient::MockIBusClient() + : create_input_context_call_count_(0) { +} MockIBusClient::~MockIBusClient() {} @@ -14,6 +16,9 @@ void MockIBusClient::CreateInputContext( const std::string& client_name, const CreateInputContextCallback& callback, const ErrorCallback& error_callback) { + create_input_context_call_count_ ++; + if (!create_input_context_handler_.is_null()) + create_input_context_handler_.Run(client_name, callback, error_callback); } } // namespace chromeos diff --git a/chromeos/dbus/ibus/mock_ibus_client.h b/chromeos/dbus/ibus/mock_ibus_client.h index 756fe22a..b14c7c4 100644 --- a/chromeos/dbus/ibus/mock_ibus_client.h +++ b/chromeos/dbus/ibus/mock_ibus_client.h @@ -7,6 +7,7 @@ #pragma once #include <string> +#include "base/callback.h" #include "chromeos/dbus/ibus/ibus_client.h" namespace chromeos { @@ -16,9 +17,32 @@ class MockIBusClient : public IBusClient { MockIBusClient(); virtual ~MockIBusClient(); + typedef base::Callback<void(const std::string& client_name, + const CreateInputContextCallback& callback, + const ErrorCallback& error_callback)> + CreateInputContextHandler; + virtual void CreateInputContext(const std::string& client_name, const CreateInputContextCallback& callback, const ErrorCallback& error_callback) OVERRIDE; + + // Function handler for CreateInputContext. The CreateInputContext function + // invokes |create_input_context_handler_| unless it's not null. + void set_create_input_context_handler( + const CreateInputContextHandler& handler) { + create_input_context_handler_ = handler; + } + + // Represents call count of CreateInputContext. + int create_input_context_call_count() const { + return create_input_context_call_count_; + } + + private: + CreateInputContextHandler create_input_context_handler_; + int create_input_context_call_count_; + + DISALLOW_COPY_AND_ASSIGN(MockIBusClient); }; } // namespace chromeos diff --git a/chromeos/dbus/ibus/mock_ibus_input_context_client.cc b/chromeos/dbus/ibus/mock_ibus_input_context_client.cc index 53b9ea4..edfa702 100644 --- a/chromeos/dbus/ibus/mock_ibus_input_context_client.cc +++ b/chromeos/dbus/ibus/mock_ibus_input_context_client.cc @@ -6,19 +6,36 @@ namespace chromeos { -MockIBusInputContextClient::MockIBusInputContextClient() {} +MockIBusInputContextClient::MockIBusInputContextClient() + : initialize_call_count_(0), + is_initialized_(false), + reset_object_proxy_call_caount_(0), + set_capabilities_call_count_(0), + focus_in_call_count_(0), + focus_out_call_count_(0), + reset_call_count_(0), + set_cursor_location_call_count_(0), + process_key_event_call_count_(0) { +} MockIBusInputContextClient::~MockIBusInputContextClient() {} void MockIBusInputContextClient::Initialize( dbus::Bus* bus, const dbus::ObjectPath& object_path) { + initialize_call_count_++; + is_initialized_ = true; } void MockIBusInputContextClient::ResetObjectProxy() { + reset_object_proxy_call_caount_++; + is_initialized_ = false; } -bool MockIBusInputContextClient::IsConnected() const { +bool MockIBusInputContextClient::IsObjectProxyReady() const { + if (is_initialized_) return true; + else + return false; } void MockIBusInputContextClient::SetCommitTextHandler( @@ -57,19 +74,24 @@ void MockIBusInputContextClient::UnsetHidePreeditTextHandler() { } void MockIBusInputContextClient::SetCapabilities(uint32 capabilities) { + set_capabilities_call_count_++; } void MockIBusInputContextClient::FocusIn() { + focus_in_call_count_++; } void MockIBusInputContextClient::FocusOut() { + focus_out_call_count_++; } void MockIBusInputContextClient::Reset() { + reset_call_count_++; } void MockIBusInputContextClient::SetCursorLocation( int32 x, int32 y, int32 w, int32 h) { + set_cursor_location_call_count_++; } void MockIBusInputContextClient::ProcessKeyEvent( @@ -77,6 +99,7 @@ void MockIBusInputContextClient::ProcessKeyEvent( uint32 keycode, uint32 state, const ProcessKeyEventCallback& callback) { + process_key_event_call_count_++; } } // namespace chromeos diff --git a/chromeos/dbus/ibus/mock_ibus_input_context_client.h b/chromeos/dbus/ibus/mock_ibus_input_context_client.h index 1e2a58c..38944f1 100644 --- a/chromeos/dbus/ibus/mock_ibus_input_context_client.h +++ b/chromeos/dbus/ibus/mock_ibus_input_context_client.h @@ -5,6 +5,7 @@ #ifndef CHROMEOS_DBUS_IBUS_MOCK_IBUS_INPUT_CONTEXT_CLIENT_H_ #define CHROMEOS_DBUS_IBUS_MOCK_IBUS_INPUT_CONTEXT_CLIENT_H_ +#include "base/basictypes.h" #include "chromeos/dbus/ibus/ibus_input_context_client.h" namespace chromeos { @@ -16,7 +17,7 @@ class MockIBusInputContextClient : public IBusInputContextClient { virtual void Initialize(dbus::Bus* bus, const dbus::ObjectPath& object_path) OVERRIDE; virtual void ResetObjectProxy() OVERRIDE; - virtual bool IsConnected() const OVERRIDE; + virtual bool IsObjectProxyReady() const OVERRIDE; virtual void SetCommitTextHandler( const CommitTextHandler& commit_text_handler) OVERRIDE; virtual void SetForwardKeyEventHandler( @@ -39,6 +40,51 @@ class MockIBusInputContextClient : public IBusInputContextClient { virtual void SetCursorLocation(int32 x, int32 y, int32 w, int32 h) OVERRIDE; virtual void ProcessKeyEvent(uint32 keyval, uint32 keycode, uint32 state, const ProcessKeyEventCallback& callback) OVERRIDE; + + // Call count of Initialize(). + int initialize_call_count() const { return initialize_call_count_; } + + // Call count of ResetObjectProxy(). + int reset_object_proxy_call_caount() const { + return reset_object_proxy_call_caount_; + } + + // Call count of SetCapabilities(). + int set_capabilities_call_count() const { + return set_capabilities_call_count_; + } + + // Call count of FocusIn(). + int focus_in_call_count() const { return focus_in_call_count_; } + + // Call count of FocusOut(). + int focus_out_call_count() const { return focus_out_call_count_; } + + // Call count of Reset(). + int reset_call_count() const { return reset_call_count_; } + + // Call count of SetCursorLocation(). + int set_cursor_location_call_count() const { + return set_cursor_location_call_count_; + } + + // Call count of ProcessKeyEvent(). + int process_key_event_call_count() const { + return process_key_event_call_count_; + } + + private: + int initialize_call_count_; + bool is_initialized_; + int reset_object_proxy_call_caount_; + int set_capabilities_call_count_; + int focus_in_call_count_; + int focus_out_call_count_; + int reset_call_count_; + int set_cursor_location_call_count_; + int process_key_event_call_count_; + + DISALLOW_COPY_AND_ASSIGN(MockIBusInputContextClient); }; } // namespace chromeos diff --git a/chromeos/dbus/mock_dbus_thread_manager_without_gmock.cc b/chromeos/dbus/mock_dbus_thread_manager_without_gmock.cc index 4d5c327..ab6dad2 100644 --- a/chromeos/dbus/mock_dbus_thread_manager_without_gmock.cc +++ b/chromeos/dbus/mock_dbus_thread_manager_without_gmock.cc @@ -11,13 +11,16 @@ namespace chromeos { MockDBusThreadManagerWithoutGMock::MockDBusThreadManagerWithoutGMock() : mock_ibus_client_(new MockIBusClient), - mock_ibus_input_context_client_(new MockIBusInputContextClient) { + mock_ibus_input_context_client_(new MockIBusInputContextClient), + ibus_bus_(NULL) { } MockDBusThreadManagerWithoutGMock::~MockDBusThreadManagerWithoutGMock() {} void MockDBusThreadManagerWithoutGMock::InitIBusBus( const std::string& ibus_address) { + // Non-null bus address is used to ensure the connection to ibus-daemon. + ibus_bus_ = reinterpret_cast<dbus::Bus*>(0xdeadbeef); } dbus::Bus* MockDBusThreadManagerWithoutGMock::GetSystemBus() { @@ -25,7 +28,7 @@ dbus::Bus* MockDBusThreadManagerWithoutGMock::GetSystemBus() { } dbus::Bus* MockDBusThreadManagerWithoutGMock::GetIBusBus() { - return NULL; + return ibus_bus_; } BluetoothAdapterClient* diff --git a/chromeos/dbus/mock_dbus_thread_manager_without_gmock.h b/chromeos/dbus/mock_dbus_thread_manager_without_gmock.h index 9bde865..36e6893 100644 --- a/chromeos/dbus/mock_dbus_thread_manager_without_gmock.h +++ b/chromeos/dbus/mock_dbus_thread_manager_without_gmock.h @@ -64,14 +64,20 @@ class MockDBusThreadManagerWithoutGMock : public DBusThreadManager { MockIBusClient* mock_ibus_client() { return mock_ibus_client_.get(); } + MockIBusInputContextClient* mock_ibus_input_context_client() { return mock_ibus_input_context_client_.get(); } + void set_ibus_bus(dbus::Bus* ibus_bus) { + ibus_bus_ = ibus_bus; + } + private: scoped_ptr<MockIBusClient> mock_ibus_client_; scoped_ptr<MockIBusInputContextClient> mock_ibus_input_context_client_; + dbus::Bus* ibus_bus_; DISALLOW_COPY_AND_ASSIGN(MockDBusThreadManagerWithoutGMock); }; |