diff options
author | nona@chromium.org <nona@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-11-28 12:12:32 +0000 |
---|---|---|
committer | nona@chromium.org <nona@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-11-28 12:12:32 +0000 |
commit | 8ab8fcc088e7ffb1042c582a15b06b739f3e0748 (patch) | |
tree | 999125604d03d89b013a75338d3e7d82088e810d /chromeos | |
parent | 9564c15073453dd32b1d2522a209ca8312a6dcd0 (diff) | |
download | chromium_src-8ab8fcc088e7ffb1042c582a15b06b739f3e0748.zip chromium_src-8ab8fcc088e7ffb1042c582a15b06b739f3e0748.tar.gz chromium_src-8ab8fcc088e7ffb1042c582a15b06b739f3e0748.tar.bz2 |
Extends IBusPanelService to handle Property operation.
The reason why I introduced two different interfaces is that CandidateWindow and Property controllers are separated in Chrome.
CandidateWindowHandler is(will be) implemented by CandidateWindowController and PropertyHandler is(will be) implemented by IBusController.
BUG=158265
TEST=ran chromeos_unittests
Review URL: https://chromiumcodereview.appspot.com/11416172
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@169904 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chromeos')
-rw-r--r-- | chromeos/dbus/ibus/ibus_constants.h | 2 | ||||
-rw-r--r-- | chromeos/dbus/ibus/ibus_panel_service.cc | 122 | ||||
-rw-r--r-- | chromeos/dbus/ibus/ibus_panel_service.h | 36 | ||||
-rw-r--r-- | chromeos/dbus/ibus/ibus_panel_service_unittest.cc | 164 | ||||
-rw-r--r-- | chromeos/dbus/ibus/mock_ibus_panel_service.cc | 8 | ||||
-rw-r--r-- | chromeos/dbus/ibus/mock_ibus_panel_service.h | 5 |
6 files changed, 287 insertions, 50 deletions
diff --git a/chromeos/dbus/ibus/ibus_constants.h b/chromeos/dbus/ibus/ibus_constants.h index 87e31ff..77f4e81 100644 --- a/chromeos/dbus/ibus/ibus_constants.h +++ b/chromeos/dbus/ibus/ibus_constants.h @@ -77,6 +77,8 @@ const char kUpdateAuxiliaryTextMethod[] = "UpdateAuxiliaryText"; const char kHideAuxiliaryTextMethod[] = "HideAuxiliaryText"; const char kUpdatePreeditTextMethod[] = "UpdatePreeditText"; const char kHidePreeditTextMethod[] = "HidePreeditText"; +const char kRegisterPropertiesMethod[] = "RegisterProperties"; +const char kUpdatePropertiesMethod[] = "UpdateProperties"; const char kCandidateClickedSignal[] = "CandidateClicked"; const char kCursorUpSignal[] = "CursorUp"; const char kCursorDownSignal[] = "CursorDown"; diff --git a/chromeos/dbus/ibus/ibus_panel_service.cc b/chromeos/dbus/ibus/ibus_panel_service.cc index aa03a73..55b3d73 100644 --- a/chromeos/dbus/ibus/ibus_panel_service.cc +++ b/chromeos/dbus/ibus/ibus_panel_service.cc @@ -25,7 +25,8 @@ class IBusPanelServiceImpl : public IBusPanelService { public: explicit IBusPanelServiceImpl(dbus::Bus* bus) : bus_(bus), - panel_handler_(NULL), + candidate_window_handler_(NULL), + property_handler_(NULL), weak_ptr_factory_(this) { exported_object_ = bus->GetExportedObject( dbus::ObjectPath(ibus::panel::kServicePath)); @@ -77,6 +78,22 @@ class IBusPanelServiceImpl : public IBusPanelService { weak_ptr_factory_.GetWeakPtr()), base::Bind(&IBusPanelServiceImpl::OnMethodExported, weak_ptr_factory_.GetWeakPtr())); + + exported_object_->ExportMethod( + ibus::panel::kServiceInterface, + ibus::panel::kRegisterPropertiesMethod, + base::Bind(&IBusPanelServiceImpl::RegisterProperties, + weak_ptr_factory_.GetWeakPtr()), + base::Bind(&IBusPanelServiceImpl::OnMethodExported, + weak_ptr_factory_.GetWeakPtr())); + + exported_object_->ExportMethod( + ibus::panel::kServiceInterface, + ibus::panel::kUpdatePropertiesMethod, + base::Bind(&IBusPanelServiceImpl::UpdateProperties, + weak_ptr_factory_.GetWeakPtr()), + base::Bind(&IBusPanelServiceImpl::OnMethodExported, + weak_ptr_factory_.GetWeakPtr())); } virtual ~IBusPanelServiceImpl() { @@ -85,13 +102,17 @@ class IBusPanelServiceImpl : public IBusPanelService { } // IBusPanelService override. - virtual void Initialize(IBusPanelHandlerInterface* handler) OVERRIDE { + virtual void SetUpCandidateWindowHandler( + IBusPanelCandidateWindowHandlerInterface* handler) { DCHECK(handler); - if (panel_handler_ == NULL) { - panel_handler_ = handler; - } else { - LOG(ERROR) << "Already initialized."; - } + candidate_window_handler_ = handler; + } + + // IBusPanelService override. + virtual void SetUpPropertyHandler( + IBusPanelPropertyHandlerInterface* handler) { + DCHECK(handler); + property_handler_ = handler; } // IBusPanelService override. @@ -139,7 +160,9 @@ class IBusPanelServiceImpl : public IBusPanelService { // Handles UpdateLookupTable method call from ibus-daemon. void UpdateLookupTable(dbus::MethodCall* method_call, dbus::ExportedObject::ResponseSender response_sender) { - DCHECK(panel_handler_); + if (!candidate_window_handler_) + return; + dbus::MessageReader reader(method_call); ibus::IBusLookupTable table; if (!ibus::PopIBusLookupTable(&reader, &table)) { @@ -153,7 +176,7 @@ class IBusPanelServiceImpl : public IBusPanelService { << method_call->ToString(); return; } - panel_handler_->UpdateLookupTable(table, visible); + candidate_window_handler_->UpdateLookupTable(table, visible); dbus::Response* response = dbus::Response::FromMethodCall(method_call); response_sender.Run(response); } @@ -161,8 +184,10 @@ class IBusPanelServiceImpl : public IBusPanelService { // Handles HideLookupTable method call from ibus-daemon. void HideLookupTable(dbus::MethodCall* method_call, dbus::ExportedObject::ResponseSender response_sender) { - DCHECK(panel_handler_); - panel_handler_->HideLookupTable(); + if (!candidate_window_handler_) + return; + + candidate_window_handler_->HideLookupTable(); dbus::Response* response = dbus::Response::FromMethodCall(method_call); response_sender.Run(response); } @@ -171,7 +196,9 @@ class IBusPanelServiceImpl : public IBusPanelService { void UpdateAuxiliaryText( dbus::MethodCall* method_call, dbus::ExportedObject::ResponseSender response_sender) { - DCHECK(panel_handler_); + if (!candidate_window_handler_) + return; + dbus::MessageReader reader(method_call); std::string text; if (!ibus::PopStringFromIBusText(&reader, &text)) { @@ -185,7 +212,7 @@ class IBusPanelServiceImpl : public IBusPanelService { << method_call->ToString(); return; } - panel_handler_->UpdateAuxiliaryText(text, visible); + candidate_window_handler_->UpdateAuxiliaryText(text, visible); dbus::Response* response = dbus::Response::FromMethodCall(method_call); response_sender.Run(response); } @@ -193,8 +220,10 @@ class IBusPanelServiceImpl : public IBusPanelService { // Handles HideAuxiliaryText method call from ibus-daemon. void HideAuxiliaryText(dbus::MethodCall* method_call, dbus::ExportedObject::ResponseSender response_sender) { - DCHECK(panel_handler_); - panel_handler_->HideAuxiliaryText(); + if (!candidate_window_handler_) + return; + + candidate_window_handler_->HideAuxiliaryText(); dbus::Response* response = dbus::Response::FromMethodCall(method_call); response_sender.Run(response); } @@ -202,7 +231,9 @@ class IBusPanelServiceImpl : public IBusPanelService { // Handles UpdatePreeditText method call from ibus-daemon. void UpdatePreeditText(dbus::MethodCall* method_call, dbus::ExportedObject::ResponseSender response_sender) { - DCHECK(panel_handler_); + if (!candidate_window_handler_) + return; + dbus::MessageReader reader(method_call); std::string text; if (!ibus::PopStringFromIBusText(&reader, &text)) { @@ -222,7 +253,7 @@ class IBusPanelServiceImpl : public IBusPanelService { << method_call->ToString(); return; } - panel_handler_->UpdatePreeditText(text, cursor_pos, visible); + candidate_window_handler_->UpdatePreeditText(text, cursor_pos, visible); dbus::Response* response = dbus::Response::FromMethodCall(method_call); response_sender.Run(response); } @@ -230,8 +261,49 @@ class IBusPanelServiceImpl : public IBusPanelService { // Handles HidePreeditText method call from ibus-daemon. void HidePreeditText(dbus::MethodCall* method_call, dbus::ExportedObject::ResponseSender response_sender) { - DCHECK(panel_handler_); - panel_handler_->HidePreeditText(); + if (!candidate_window_handler_) + return; + + candidate_window_handler_->HidePreeditText(); + dbus::Response* response = dbus::Response::FromMethodCall(method_call); + response_sender.Run(response); + } + + // Handles RegisterProperties method call from ibus-daemon. + void RegisterProperties( + dbus::MethodCall* method_call, + dbus::ExportedObject::ResponseSender response_sender) { + if (!property_handler_) + return; + + dbus::MessageReader reader(method_call); + ibus::IBusPropertyList properties; + if (!ibus::PopIBusPropertyList(&reader, &properties)) { + DLOG(WARNING) << "RegisterProperties called with incorrect parameters:" + << method_call->ToString(); + return; + } + property_handler_->RegisterProperties(properties); + + dbus::Response* response = dbus::Response::FromMethodCall(method_call); + response_sender.Run(response); + } + + // Handles UpdateProperties method call from ibus-daemon. + void UpdateProperties(dbus::MethodCall* method_call, + dbus::ExportedObject::ResponseSender response_sender) { + if (!property_handler_) + return; + + dbus::MessageReader reader(method_call); + ibus::IBusPropertyList properties; + if (!ibus::PopIBusPropertyList(&reader, &properties)) { + DLOG(WARNING) << "RegisterProperties called with incorrect parameters:" + << method_call->ToString(); + return; + } + property_handler_->UpdateProperties(properties); + dbus::Response* response = dbus::Response::FromMethodCall(method_call); response_sender.Run(response); } @@ -247,8 +319,11 @@ class IBusPanelServiceImpl : public IBusPanelService { // D-Bus bus object used for unregistering exported methods in dtor. dbus::Bus* bus_; - // All incoming method calls are passed on to the |panel_handler_|. - IBusPanelHandlerInterface* panel_handler_; + // All incoming method calls are passed on to the |candidate_window_handler_| + // or |property_handler|. This class does not take ownership of following + // handlers. + IBusPanelCandidateWindowHandlerInterface* candidate_window_handler_; + IBusPanelPropertyHandlerInterface* property_handler_; scoped_refptr<dbus::ExportedObject> exported_object_; base::WeakPtrFactory<IBusPanelServiceImpl> weak_ptr_factory_; @@ -261,7 +336,10 @@ class IBusPanelServiceStubImpl : public IBusPanelService { IBusPanelServiceStubImpl() {} virtual ~IBusPanelServiceStubImpl() {} // IBusPanelService overrides. - virtual void Initialize(IBusPanelHandlerInterface* handler) OVERRIDE {} + virtual void SetUpCandidateWindowHandler( + IBusPanelCandidateWindowHandlerInterface* handler) {} + virtual void SetUpPropertyHandler( + IBusPanelPropertyHandlerInterface* handler) {} virtual void CandidateClicked(uint32 index, ibus::IBusMouseButton button, uint32 state) OVERRIDE {} diff --git a/chromeos/dbus/ibus/ibus_panel_service.h b/chromeos/dbus/ibus/ibus_panel_service.h index 96c7f68..0ecb1f7 100644 --- a/chromeos/dbus/ibus/ibus_panel_service.h +++ b/chromeos/dbus/ibus/ibus_panel_service.h @@ -27,10 +27,10 @@ class IBusProperty; class IBusText; typedef ScopedVector<IBusProperty> IBusPropertyList; -// A interface to handle the panel client method call. -class CHROMEOS_EXPORT IBusPanelHandlerInterface { +// A interface to handle the candidate window related method call. +class CHROMEOS_EXPORT IBusPanelCandidateWindowHandlerInterface { public: - virtual ~IBusPanelHandlerInterface() {} + virtual ~IBusPanelCandidateWindowHandlerInterface() {} // Called when the IME updates the lookup table. virtual void UpdateLookupTable(const ibus::IBusLookupTable& table, @@ -55,7 +55,22 @@ class CHROMEOS_EXPORT IBusPanelHandlerInterface { virtual void HidePreeditText() = 0; protected: - IBusPanelHandlerInterface() {} + IBusPanelCandidateWindowHandlerInterface() {} +}; + +// A interface to handle the property related method call. +class CHROMEOS_EXPORT IBusPanelPropertyHandlerInterface { + public: + virtual ~IBusPanelPropertyHandlerInterface() {} + + // Called when a new property is registered. + virtual void RegisterProperties(const ibus::IBusPropertyList& properties) = 0; + + // Called when current property is updated. + virtual void UpdateProperties(const ibus::IBusPropertyList& properties) = 0; + + protected: + IBusPanelPropertyHandlerInterface() {} }; // A class to make the actual DBus method call handling for IBusPanel service. @@ -66,8 +81,17 @@ class CHROMEOS_EXPORT IBusPanelService { public: virtual ~IBusPanelService(); - // Initializes Panel service with |handler|, which must not be NULL. - virtual void Initialize(IBusPanelHandlerInterface* handler) = 0; + // Sets up candidate window panel service with |handler|. This function can be + // called multiple times and also can be passed |handler| as NULL. Caller must + // release |handler|. + virtual void SetUpCandidateWindowHandler( + IBusPanelCandidateWindowHandlerInterface* handler) = 0; + + // Sets up property panel service with |handler|. This function can be called + // multiple times and also can be passed |handler| as NULL. Caller must + // release |handler|. + virtual void SetUpPropertyHandler( + IBusPanelPropertyHandlerInterface* handler) = 0; // Emits CandidateClicked signal. virtual void CandidateClicked(uint32 index, diff --git a/chromeos/dbus/ibus/ibus_panel_service_unittest.cc b/chromeos/dbus/ibus/ibus_panel_service_unittest.cc index 8f73e12..6f4de19 100644 --- a/chromeos/dbus/ibus/ibus_panel_service_unittest.cc +++ b/chromeos/dbus/ibus/ibus_panel_service_unittest.cc @@ -30,9 +30,10 @@ namespace ibus { namespace { -class MockIBusPanelHandler : public IBusPanelHandlerInterface { +class MockIBusPanelCandidateWindowHandler + : public IBusPanelCandidateWindowHandlerInterface { public: - MockIBusPanelHandler() {} + MockIBusPanelCandidateWindowHandler() {} MOCK_METHOD2(UpdateLookupTable, void(const ibus::IBusLookupTable& table, bool visible)); MOCK_METHOD0(HideLookupTable, void()); @@ -45,7 +46,19 @@ class MockIBusPanelHandler : public IBusPanelHandlerInterface { MOCK_METHOD0(HidePreeditText, void()); private: - DISALLOW_COPY_AND_ASSIGN(MockIBusPanelHandler); + DISALLOW_COPY_AND_ASSIGN(MockIBusPanelCandidateWindowHandler); +}; + +class MockIBusPanelPropertyHandler : public IBusPanelPropertyHandlerInterface { + public: + MockIBusPanelPropertyHandler() {} + MOCK_METHOD1(RegisterProperties, + void(const ibus::IBusPropertyList& properties)); + MOCK_METHOD1(UpdateProperties, + void(const ibus::IBusPropertyList& properties)); + + private: + DISALLOW_COPY_AND_ASSIGN(MockIBusPanelPropertyHandler); }; class MockResponseSender { @@ -149,6 +162,27 @@ class UpdateLookupTableVerifier { DISALLOW_COPY_AND_ASSIGN(UpdateLookupTableVerifier); }; +// This class is used to verify that a method call which has a PropertyList +// object. This class verifies a method call has correct arguments based on +// checking given |keys|. +class PropertyListVerifier { + public: + explicit PropertyListVerifier(const std::vector<std::string>& expected_keys) + : expected_keys_(expected_keys) { + } + + // Verifies the given |resposne| has IBusPropertyList. + void Verify(const ibus::IBusPropertyList& properties) { + ASSERT_EQ(expected_keys_.size(), properties.size()); + for (size_t i = 0; i < properties.size(); ++i) { + EXPECT_EQ(expected_keys_[i], properties[i]->key()); + } + } + + private: + const std::vector<std::string> expected_keys_; +}; + } // namespace class IBusPanelServiceTest : public testing::Test { @@ -173,37 +207,49 @@ class IBusPanelServiceTest : public testing::Test { EXPECT_CALL(*mock_exported_object_, ExportMethod( ibus::panel::kServiceInterface, - ibus::panel::kUpdateLookupTableMethod , _, _)) + ibus::panel::kUpdateLookupTableMethod, _, _)) + .WillRepeatedly( + Invoke(this, &IBusPanelServiceTest::OnMethodExported)); + + EXPECT_CALL(*mock_exported_object_, ExportMethod( + ibus::panel::kServiceInterface, + ibus::panel::kHideLookupTableMethod, _, _)) + .WillRepeatedly( + Invoke(this, &IBusPanelServiceTest::OnMethodExported)); + + EXPECT_CALL(*mock_exported_object_, ExportMethod( + ibus::panel::kServiceInterface, + ibus::panel::kUpdateAuxiliaryTextMethod, _, _)) .WillRepeatedly( Invoke(this, &IBusPanelServiceTest::OnMethodExported)); EXPECT_CALL(*mock_exported_object_, ExportMethod( ibus::panel::kServiceInterface, - ibus::panel::kHideLookupTableMethod , _, _)) + ibus::panel::kHideAuxiliaryTextMethod, _, _)) .WillRepeatedly( Invoke(this, &IBusPanelServiceTest::OnMethodExported)); EXPECT_CALL(*mock_exported_object_, ExportMethod( ibus::panel::kServiceInterface, - ibus::panel::kUpdateAuxiliaryTextMethod , _, _)) + ibus::panel::kUpdatePreeditTextMethod, _, _)) .WillRepeatedly( Invoke(this, &IBusPanelServiceTest::OnMethodExported)); EXPECT_CALL(*mock_exported_object_, ExportMethod( ibus::panel::kServiceInterface, - ibus::panel::kHideAuxiliaryTextMethod , _, _)) + ibus::panel::kHidePreeditTextMethod, _, _)) .WillRepeatedly( Invoke(this, &IBusPanelServiceTest::OnMethodExported)); EXPECT_CALL(*mock_exported_object_, ExportMethod( ibus::panel::kServiceInterface, - ibus::panel::kUpdatePreeditTextMethod , _, _)) + ibus::panel::kRegisterPropertiesMethod, _, _)) .WillRepeatedly( Invoke(this, &IBusPanelServiceTest::OnMethodExported)); EXPECT_CALL(*mock_exported_object_, ExportMethod( ibus::panel::kServiceInterface, - ibus::panel::kHidePreeditTextMethod , _, _)) + ibus::panel::kUpdatePropertiesMethod, _, _)) .WillRepeatedly( Invoke(this, &IBusPanelServiceTest::OnMethodExported)); @@ -218,15 +264,20 @@ class IBusPanelServiceTest : public testing::Test { mock_bus_.get())); // Set panel handler. - panel_handler_.reset(new MockIBusPanelHandler()); - service_->Initialize(panel_handler_.get()); + candidate_window_handler_.reset(new MockIBusPanelCandidateWindowHandler()); + service_->SetUpCandidateWindowHandler(candidate_window_handler_.get()); + property_handler_.reset(new MockIBusPanelPropertyHandler()); + service_->SetUpPropertyHandler(property_handler_.get()); } protected: // The service to be tested. scoped_ptr<IBusPanelService> service_; - // The mock panel handler. Do not free, this is owned by IBusPanelService. - scoped_ptr<MockIBusPanelHandler> panel_handler_; + // The mock candidate window panel handler. Do not free, this is owned by + // IBusPanelService. + scoped_ptr<MockIBusPanelCandidateWindowHandler> candidate_window_handler_; + // The mock property handler. Do not free, this is owned by IBusPanelService. + scoped_ptr<MockIBusPanelPropertyHandler> property_handler_; // The mock bus. scoped_refptr<dbus::MockBus> mock_bus_; // The mock exported object. @@ -256,7 +307,7 @@ class IBusPanelServiceTest : public testing::Test { TEST_F(IBusPanelServiceTest, HideLookupTableTest) { // Set expectations. const uint32 kSerialNo = 1; - EXPECT_CALL(*panel_handler_, HideLookupTable()); + EXPECT_CALL(*candidate_window_handler_, HideLookupTable()); MockResponseSender response_sender; EmptyResponseVerifier response_expectation(kSerialNo); EXPECT_CALL(response_sender, Run(_)) @@ -280,7 +331,7 @@ TEST_F(IBusPanelServiceTest, HideLookupTableTest) { TEST_F(IBusPanelServiceTest, HideAuxiliaryTextTest) { // Set expectations. const uint32 kSerialNo = 1; - EXPECT_CALL(*panel_handler_, HideAuxiliaryText()); + EXPECT_CALL(*candidate_window_handler_, HideAuxiliaryText()); MockResponseSender response_sender; EmptyResponseVerifier response_expectation(kSerialNo); EXPECT_CALL(response_sender, Run(_)) @@ -304,7 +355,7 @@ TEST_F(IBusPanelServiceTest, HideAuxiliaryTextTest) { TEST_F(IBusPanelServiceTest, HidePreeditTextTest) { // Set expectations. const uint32 kSerialNo = 1; - EXPECT_CALL(*panel_handler_, HidePreeditText()); + EXPECT_CALL(*candidate_window_handler_, HidePreeditText()); MockResponseSender response_sender; EmptyResponseVerifier response_expectation(kSerialNo); EXPECT_CALL(response_sender, Run(_)) @@ -335,7 +386,7 @@ TEST_F(IBusPanelServiceTest, UpdateLookupTableTest) { UpdateLookupTableVerifier evaluator(table, kVisible); - EXPECT_CALL(*panel_handler_, UpdateLookupTable(_, _)) + EXPECT_CALL(*candidate_window_handler_, UpdateLookupTable(_, _)) .WillOnce(Invoke(&evaluator, &UpdateLookupTableVerifier::Verify)); MockResponseSender response_sender; @@ -367,7 +418,7 @@ TEST_F(IBusPanelServiceTest, UpdateAuxiliaryTextTest) { const std::string text = "Sample text"; const bool kVisible = false; - EXPECT_CALL(*panel_handler_, UpdateAuxiliaryText(text, kVisible)); + EXPECT_CALL(*candidate_window_handler_, UpdateAuxiliaryText(text, kVisible)); MockResponseSender response_sender; EmptyResponseVerifier response_expectation(kSerialNo); EXPECT_CALL(response_sender, Run(_)) @@ -398,7 +449,8 @@ TEST_F(IBusPanelServiceTest, UpdatePreeditTextTest) { const uint32 kCursorPos = 4; const bool kVisible = false; - EXPECT_CALL(*panel_handler_, UpdatePreeditText(text, kCursorPos, kVisible)); + EXPECT_CALL(*candidate_window_handler_, + UpdatePreeditText(text, kCursorPos, kVisible)); MockResponseSender response_sender; EmptyResponseVerifier response_expectation(kSerialNo); EXPECT_CALL(response_sender, Run(_)) @@ -463,5 +515,79 @@ TEST_F(IBusPanelServiceTest, PageDownTest) { service_->PageDown(); } +TEST_F(IBusPanelServiceTest, RegisterPropertiesTest) { + // Set expectations. + std::vector<std::string> keys; + keys.push_back("key1"); + keys.push_back("key2"); + keys.push_back("key3"); + ibus::IBusPropertyList properties; + for (size_t i = 0; i < keys.size(); ++i) { + ibus::IBusProperty* property = new ibus::IBusProperty; + property->set_key(keys[i]); + properties.push_back(property); + } + + PropertyListVerifier response_expectation(keys); + EXPECT_CALL(*property_handler_, RegisterProperties(_)) + .WillOnce(Invoke(&response_expectation, + &PropertyListVerifier::Verify)); + + MockResponseSender response_sender; + EXPECT_CALL(response_sender, Run(_)); + + // Create method call; + dbus::MethodCall method_call(ibus::panel::kServiceInterface, + ibus::panel::kRegisterPropertiesMethod); + method_call.SetSerial(1UL); + dbus::MessageWriter writer(&method_call); + ibus::AppendIBusPropertyList(properties, &writer); + + // Call exported function. + EXPECT_NE(method_callback_map_.find(ibus::panel::kRegisterPropertiesMethod), + method_callback_map_.end()); + method_callback_map_[ibus::panel::kRegisterPropertiesMethod].Run( + &method_call, + base::Bind(&MockResponseSender::Run, + base::Unretained(&response_sender))); +} + +TEST_F(IBusPanelServiceTest, UpdatePropertiesTest) { + // Set expectations. + std::vector<std::string> keys; + keys.push_back("key1"); + keys.push_back("key2"); + keys.push_back("key3"); + ibus::IBusPropertyList properties; + for (size_t i = 0; i < keys.size(); ++i) { + ibus::IBusProperty* property = new ibus::IBusProperty; + property->set_key(keys[i]); + properties.push_back(property); + } + + PropertyListVerifier response_expectation(keys); + EXPECT_CALL(*property_handler_, UpdateProperties(_)) + .WillOnce(Invoke(&response_expectation, + &PropertyListVerifier::Verify)); + + MockResponseSender response_sender; + EXPECT_CALL(response_sender, Run(_)); + + // Create method call; + dbus::MethodCall method_call(ibus::panel::kServiceInterface, + ibus::panel::kUpdatePropertiesMethod); + method_call.SetSerial(1UL); + dbus::MessageWriter writer(&method_call); + ibus::AppendIBusPropertyList(properties, &writer); + + // Call exported function. + EXPECT_NE(method_callback_map_.find(ibus::panel::kUpdatePropertiesMethod), + method_callback_map_.end()); + method_callback_map_[ibus::panel::kUpdatePropertiesMethod].Run( + &method_call, + base::Bind(&MockResponseSender::Run, + base::Unretained(&response_sender))); +} + } // namespace ibus } // namespace chromeos diff --git a/chromeos/dbus/ibus/mock_ibus_panel_service.cc b/chromeos/dbus/ibus/mock_ibus_panel_service.cc index 436192d..be65feb 100644 --- a/chromeos/dbus/ibus/mock_ibus_panel_service.cc +++ b/chromeos/dbus/ibus/mock_ibus_panel_service.cc @@ -12,8 +12,12 @@ MockIBusPanelService::MockIBusPanelService() { MockIBusPanelService::~MockIBusPanelService() { } -void MockIBusPanelService::Initialize( - ibus::IBusPanelHandlerInterface* handler) { +void MockIBusPanelService::SetUpCandidateWindowHandler( + ibus::IBusPanelCandidateWindowHandlerInterface* handler) { +} + +void MockIBusPanelService::SetUpPropertyHandler( + ibus::IBusPanelPropertyHandlerInterface* handler) { } void MockIBusPanelService::CandidateClicked(uint32 index, diff --git a/chromeos/dbus/ibus/mock_ibus_panel_service.h b/chromeos/dbus/ibus/mock_ibus_panel_service.h index 4d38784..bf02498 100644 --- a/chromeos/dbus/ibus/mock_ibus_panel_service.h +++ b/chromeos/dbus/ibus/mock_ibus_panel_service.h @@ -15,7 +15,10 @@ class MockIBusPanelService : public ibus::IBusPanelService { virtual ~MockIBusPanelService(); // IBusPanelService overrides. - virtual void Initialize(ibus::IBusPanelHandlerInterface* handler) OVERRIDE; + virtual void SetUpCandidateWindowHandler( + ibus::IBusPanelCandidateWindowHandlerInterface* handler) OVERRIDE; + virtual void SetUpPropertyHandler( + ibus::IBusPanelPropertyHandlerInterface* handler) OVERRIDE; virtual void CandidateClicked(uint32 index, ibus::IBusMouseButton button, uint32 state) OVERRIDE; |