diff options
author | hashimoto@chromium.org <hashimoto@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-18 06:10:38 +0000 |
---|---|---|
committer | hashimoto@chromium.org <hashimoto@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-18 06:10:38 +0000 |
commit | d4c6bf05147f7622cd6ea34cbeec6d323f6c8ff8 (patch) | |
tree | 3f7a2ccb87d9ce958950c8b3586ee9b46a006f14 /chromeos/dbus | |
parent | 77367c76f57968653c6f9921aec85e434f248952 (diff) | |
download | chromium_src-d4c6bf05147f7622cd6ea34cbeec6d323f6c8ff8.zip chromium_src-d4c6bf05147f7622cd6ea34cbeec6d323f6c8ff8.tar.gz chromium_src-d4c6bf05147f7622cd6ea34cbeec6d323f6c8ff8.tar.bz2 |
Add FlimflamServiceClient
BUG=chromium-os:16557
TEST=chromeos_unittests --gtest_filter="FlimflamServiceClientTest.*"
Review URL: http://codereview.chromium.org/9956164
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@132756 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chromeos/dbus')
-rw-r--r-- | chromeos/dbus/dbus_thread_manager.cc | 10 | ||||
-rw-r--r-- | chromeos/dbus/dbus_thread_manager.h | 6 | ||||
-rw-r--r-- | chromeos/dbus/flimflam_service_client.cc | 234 | ||||
-rw-r--r-- | chromeos/dbus/flimflam_service_client.h | 107 | ||||
-rw-r--r-- | chromeos/dbus/flimflam_service_client_unittest.cc | 198 | ||||
-rw-r--r-- | chromeos/dbus/mock_dbus_thread_manager.cc | 4 | ||||
-rw-r--r-- | chromeos/dbus/mock_dbus_thread_manager.h | 6 | ||||
-rw-r--r-- | chromeos/dbus/mock_flimflam_service_client.cc | 13 | ||||
-rw-r--r-- | chromeos/dbus/mock_flimflam_service_client.h | 47 |
9 files changed, 625 insertions, 0 deletions
diff --git a/chromeos/dbus/dbus_thread_manager.cc b/chromeos/dbus/dbus_thread_manager.cc index 2316788..3f46ce8 100644 --- a/chromeos/dbus/dbus_thread_manager.cc +++ b/chromeos/dbus/dbus_thread_manager.cc @@ -21,6 +21,7 @@ #include "chromeos/dbus/flimflam_manager_client.h" #include "chromeos/dbus/flimflam_network_client.h" #include "chromeos/dbus/flimflam_profile_client.h" +#include "chromeos/dbus/flimflam_service_client.h" #include "chromeos/dbus/image_burner_client.h" #include "chromeos/dbus/introspectable_client.h" #include "chromeos/dbus/power_manager_client.h" @@ -93,6 +94,9 @@ class DBusThreadManagerImpl : public DBusThreadManager { // Create the Flimflam Profile client. flimflam_profile_client_.reset( FlimflamProfileClient::Create(client_type, system_bus_.get())); + // Create the Flimflam Service client. + flimflam_service_client_.reset( + FlimflamServiceClient::Create(client_type, system_bus_.get())); // Create the image burner client. image_burner_client_.reset(ImageBurnerClient::Create(client_type, system_bus_.get())); @@ -198,6 +202,11 @@ class DBusThreadManagerImpl : public DBusThreadManager { } // DBusThreadManager override. + virtual FlimflamServiceClient* GetFlimflamServiceClient() OVERRIDE { + return flimflam_service_client_.get(); + } + + // DBusThreadManager override. virtual ImageBurnerClient* GetImageBurnerClient() OVERRIDE { return image_burner_client_.get(); } @@ -243,6 +252,7 @@ class DBusThreadManagerImpl : public DBusThreadManager { scoped_ptr<FlimflamManagerClient> flimflam_manager_client_; scoped_ptr<FlimflamNetworkClient> flimflam_network_client_; scoped_ptr<FlimflamProfileClient> flimflam_profile_client_; + scoped_ptr<FlimflamServiceClient> flimflam_service_client_; scoped_ptr<ImageBurnerClient> image_burner_client_; scoped_ptr<IntrospectableClient> introspectable_client_; scoped_ptr<PowerManagerClient> power_manager_client_; diff --git a/chromeos/dbus/dbus_thread_manager.h b/chromeos/dbus/dbus_thread_manager.h index ee7770f..09190b3 100644 --- a/chromeos/dbus/dbus_thread_manager.h +++ b/chromeos/dbus/dbus_thread_manager.h @@ -35,6 +35,7 @@ class FlimflamIPConfigClient; class FlimflamManagerClient; class FlimflamNetworkClient; class FlimflamProfileClient; +class FlimflamServiceClient; class ImageBurnerClient; class IntrospectableClient; class PowerManagerClient; @@ -152,6 +153,11 @@ class CHROMEOS_EXPORT DBusThreadManager { // down. virtual FlimflamProfileClient* GetFlimflamProfileClient() = 0; + // Returns the Flimflam Service client, owned by DBusThreadManager. + // Do not cache this pointer and use it after DBusThreadManager is shut + // down. + virtual FlimflamServiceClient* GetFlimflamServiceClient() = 0; + // Returns the image burner client, owned by DBusThreadManager. // Do not cache this pointer and use it after DBusThreadManger is shut // down. diff --git a/chromeos/dbus/flimflam_service_client.cc b/chromeos/dbus/flimflam_service_client.cc new file mode 100644 index 0000000..86e719a --- /dev/null +++ b/chromeos/dbus/flimflam_service_client.cc @@ -0,0 +1,234 @@ +// 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 "chromeos/dbus/flimflam_service_client.h" + +#include "base/bind.h" +#include "base/chromeos/chromeos_version.h" +#include "base/message_loop.h" +#include "base/stl_util.h" +#include "base/values.h" +#include "dbus/bus.h" +#include "dbus/message.h" +#include "dbus/object_proxy.h" +#include "third_party/cros_system_api/dbus/service_constants.h" + +namespace chromeos { + +namespace { + +// The FlimflamServiceClient implementation. +class FlimflamServiceClientImpl : public FlimflamServiceClient { + public: + explicit FlimflamServiceClientImpl(dbus::Bus* bus) + : bus_(bus), + helpers_deleter_(&helpers_) { + } + + // FlimflamServiceClient override. + virtual void SetPropertyChangedHandler( + const dbus::ObjectPath& service_path, + const PropertyChangedHandler& handler) OVERRIDE { + GetHelper(service_path)->SetPropertyChangedHandler(handler); + } + + // FlimflamServiceClient override. + virtual void ResetPropertyChangedHandler( + const dbus::ObjectPath& service_path) OVERRIDE { + GetHelper(service_path)->ResetPropertyChangedHandler(); + } + + // FlimflamServiceClient override. + virtual void GetProperties(const dbus::ObjectPath& service_path, + const DictionaryValueCallback& callback) OVERRIDE { + dbus::MethodCall method_call(flimflam::kFlimflamServiceInterface, + flimflam::kGetPropertiesFunction); + GetHelper(service_path)->CallDictionaryValueMethod(&method_call, callback); + } + + // FlimflamServiceClient override. + virtual void SetProperty(const dbus::ObjectPath& service_path, + const std::string& name, + const base::Value& value, + const VoidCallback& callback) OVERRIDE { + dbus::MethodCall method_call(flimflam::kFlimflamServiceInterface, + flimflam::kSetPropertyFunction); + dbus::MessageWriter writer(&method_call); + writer.AppendString(name); + FlimflamClientHelper::AppendValueDataAsVariant(&writer, value); + GetHelper(service_path)->CallVoidMethod(&method_call, callback); + } + + // FlimflamServiceClient override. + virtual void ClearProperty(const dbus::ObjectPath& service_path, + const std::string& name, + const VoidCallback& callback) OVERRIDE { + dbus::MethodCall method_call(flimflam::kFlimflamServiceInterface, + flimflam::kClearPropertyFunction); + dbus::MessageWriter writer(&method_call); + writer.AppendString(name); + GetHelper(service_path)->CallVoidMethod(&method_call, callback); + } + + // FlimflamServiceClient override. + virtual void Connect(const dbus::ObjectPath& service_path, + const VoidCallback& callback) OVERRIDE { + dbus::MethodCall method_call(flimflam::kFlimflamServiceInterface, + flimflam::kConnectFunction); + GetHelper(service_path)->CallVoidMethod(&method_call, callback); + } + + // FlimflamServiceClient override. + virtual void Disconnect(const dbus::ObjectPath& service_path, + const VoidCallback& callback) OVERRIDE { + dbus::MethodCall method_call(flimflam::kFlimflamServiceInterface, + flimflam::kDisconnectFunction); + GetHelper(service_path)->CallVoidMethod(&method_call, callback); + } + + // FlimflamServiceClient override. + virtual void Remove(const dbus::ObjectPath& service_path, + const VoidCallback& callback) OVERRIDE { + dbus::MethodCall method_call(flimflam::kFlimflamServiceInterface, + flimflam::kRemoveServiceFunction); + GetHelper(service_path)->CallVoidMethod(&method_call, callback); + } + + // FlimflamServiceClient override. + virtual void ActivateCellularModem(const dbus::ObjectPath& service_path, + const std::string& carrier, + const VoidCallback& callback) OVERRIDE { + dbus::MethodCall method_call(flimflam::kFlimflamServiceInterface, + flimflam::kActivateCellularModemFunction); + dbus::MessageWriter writer(&method_call); + writer.AppendString(carrier); + GetHelper(service_path)->CallVoidMethod(&method_call, callback); + } + + private: + typedef std::map<std::string, FlimflamClientHelper*> HelperMap; + + // Returns the corresponding FlimflamClientHelper for the profile. + FlimflamClientHelper* GetHelper(const dbus::ObjectPath& service_path) { + HelperMap::iterator it = helpers_.find(service_path.value()); + if (it != helpers_.end()) + return it->second; + + // There is no helper for the profile, create it. + dbus::ObjectProxy* object_proxy = + bus_->GetObjectProxy(flimflam::kFlimflamServiceName, service_path); + FlimflamClientHelper* helper = new FlimflamClientHelper(object_proxy); + helper->MonitorPropertyChanged(flimflam::kFlimflamServiceInterface); + helpers_.insert(HelperMap::value_type(service_path.value(), helper)); + return helper; + } + + dbus::Bus* bus_; + HelperMap helpers_; + STLValueDeleter<HelperMap> helpers_deleter_; + + DISALLOW_COPY_AND_ASSIGN(FlimflamServiceClientImpl); +}; + +// A stub implementation of FlimflamServiceClient. +class FlimflamServiceClientStubImpl : public FlimflamServiceClient { + public: + FlimflamServiceClientStubImpl() : weak_ptr_factory_(this) {} + + virtual ~FlimflamServiceClientStubImpl() {} + + // FlimflamServiceClient override. + virtual void SetPropertyChangedHandler( + const dbus::ObjectPath& service_path, + const PropertyChangedHandler& handler) OVERRIDE {} + + // FlimflamServiceClient override. + virtual void ResetPropertyChangedHandler( + const dbus::ObjectPath& service_path) OVERRIDE {} + + // FlimflamServiceClient override. + virtual void GetProperties(const dbus::ObjectPath& service_path, + const DictionaryValueCallback& callback) OVERRIDE { + MessageLoop::current()->PostTask( + FROM_HERE, + base::Bind(&FlimflamServiceClientStubImpl::PassEmptyDictionaryValue, + weak_ptr_factory_.GetWeakPtr(), + callback)); + } + + // FlimflamServiceClient override. + virtual void SetProperty(const dbus::ObjectPath& service_path, + const std::string& name, + const base::Value& value, + const VoidCallback& callback) OVERRIDE { + PostSuccessVoidCallback(callback); + } + + // FlimflamServiceClient override. + virtual void ClearProperty(const dbus::ObjectPath& service_path, + const std::string& name, + const VoidCallback& callback) OVERRIDE { + PostSuccessVoidCallback(callback); + } + + // FlimflamServiceClient override. + virtual void Connect(const dbus::ObjectPath& service_path, + const VoidCallback& callback) OVERRIDE { + PostSuccessVoidCallback(callback); + } + + // FlimflamServiceClient override. + virtual void Disconnect(const dbus::ObjectPath& service_path, + const VoidCallback& callback) OVERRIDE { + PostSuccessVoidCallback(callback); + } + + // FlimflamServiceClient override. + virtual void Remove(const dbus::ObjectPath& service_path, + const VoidCallback& callback) OVERRIDE { + PostSuccessVoidCallback(callback); + } + + // FlimflamServiceClient override. + virtual void ActivateCellularModem(const dbus::ObjectPath& service_path, + const std::string& carrier, + const VoidCallback& callback) OVERRIDE { + PostSuccessVoidCallback(callback); + } + + private: + void PassEmptyDictionaryValue(const DictionaryValueCallback& callback) const { + base::DictionaryValue dictionary; + callback.Run(DBUS_METHOD_CALL_SUCCESS, dictionary); + } + + // Posts a task to run a void callback with success status code. + void PostSuccessVoidCallback(const VoidCallback& callback) { + MessageLoop::current()->PostTask(FROM_HERE, + base::Bind(callback, + DBUS_METHOD_CALL_SUCCESS)); + } + + base::WeakPtrFactory<FlimflamServiceClientStubImpl> weak_ptr_factory_; + + DISALLOW_COPY_AND_ASSIGN(FlimflamServiceClientStubImpl); +}; + +} // namespace + +FlimflamServiceClient::FlimflamServiceClient() {} + +FlimflamServiceClient::~FlimflamServiceClient() {} + +// static +FlimflamServiceClient* FlimflamServiceClient::Create( + DBusClientImplementationType type, + dbus::Bus* bus) { + if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) + return new FlimflamServiceClientImpl(bus); + DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); + return new FlimflamServiceClientStubImpl(); +} + +} // namespace chromeos diff --git a/chromeos/dbus/flimflam_service_client.h b/chromeos/dbus/flimflam_service_client.h new file mode 100644 index 0000000..081816a --- /dev/null +++ b/chromeos/dbus/flimflam_service_client.h @@ -0,0 +1,107 @@ +// 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. + +#ifndef CHROMEOS_DBUS_FLIMFLAM_SERVICE_CLIENT_H_ +#define CHROMEOS_DBUS_FLIMFLAM_SERVICE_CLIENT_H_ + +#include <string> + +#include "base/basictypes.h" +#include "base/callback.h" +#include "chromeos/chromeos_export.h" +#include "chromeos/dbus/dbus_client_implementation_type.h" +#include "chromeos/dbus/flimflam_client_helper.h" + +namespace base { + +class Value; +class DictionaryValue; + +} // namespace base + +namespace dbus { + +class Bus; +class ObjectPath; + +} // namespace dbus + +namespace chromeos { + +// FlimflamServiceClient is used to communicate with the Flimflam Service +// service. +// All methods should be called from the origin thread which initializes the +// DBusThreadManager instance. +class CHROMEOS_EXPORT FlimflamServiceClient { + public: + typedef FlimflamClientHelper::PropertyChangedHandler PropertyChangedHandler; + typedef FlimflamClientHelper::VoidCallback VoidCallback; + typedef FlimflamClientHelper::DictionaryValueCallback DictionaryValueCallback; + + virtual ~FlimflamServiceClient(); + + // Factory function, creates a new instance which is owned by the caller. + // For normal usage, access the singleton via DBusThreadManager::Get(). + static FlimflamServiceClient* Create(DBusClientImplementationType type, + dbus::Bus* bus); + + // Sets PropertyChanged signal handler. + virtual void SetPropertyChangedHandler( + const dbus::ObjectPath& service_path, + const PropertyChangedHandler& handler) = 0; + + // Resets PropertyChanged signal handler. + virtual void ResetPropertyChangedHandler( + const dbus::ObjectPath& service_path) = 0; + + // Calls GetProperties method. + // |callback| is called after the method call succeeds. + virtual void GetProperties(const dbus::ObjectPath& service_path, + const DictionaryValueCallback& callback) = 0; + + // Calls SetProperty method. + // |callback| is called after the method call succeeds. + virtual void SetProperty(const dbus::ObjectPath& service_path, + const std::string& name, + const base::Value& value, + const VoidCallback& callback) = 0; + + // Calls ClearProperty method. + // |callback| is called after the method call succeeds. + virtual void ClearProperty(const dbus::ObjectPath& service_path, + const std::string& name, + const VoidCallback& callback) = 0; + + // Calls Connect method. + // |callback| is called after the method call succeeds. + virtual void Connect(const dbus::ObjectPath& service_path, + const VoidCallback& callback) = 0; + + // Calls Disconnect method. + // |callback| is called after the method call succeeds. + virtual void Disconnect(const dbus::ObjectPath& service_path, + const VoidCallback& callback) = 0; + + // Calls Remove method. + // |callback| is called after the method call succeeds. + virtual void Remove(const dbus::ObjectPath& service_path, + const VoidCallback& callback) = 0; + + // Calls ActivateCellularModem method. + // |callback| is called after the method call succeeds. + virtual void ActivateCellularModem(const dbus::ObjectPath& service_path, + const std::string& carrier, + const VoidCallback& callback) = 0; + + protected: + // Create() should be used instead. + FlimflamServiceClient(); + + private: + DISALLOW_COPY_AND_ASSIGN(FlimflamServiceClient); +}; + +} // namespace chromeos + +#endif // CHROMEOS_DBUS_FLIMFLAM_SERVICE_CLIENT_H_ diff --git a/chromeos/dbus/flimflam_service_client_unittest.cc b/chromeos/dbus/flimflam_service_client_unittest.cc new file mode 100644 index 0000000..92b802e --- /dev/null +++ b/chromeos/dbus/flimflam_service_client_unittest.cc @@ -0,0 +1,198 @@ +// 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/bind.h" +#include "base/values.h" +#include "chromeos/dbus/flimflam_client_unittest_base.h" +#include "chromeos/dbus/flimflam_service_client.h" +#include "dbus/message.h" +#include "dbus/object_path.h" +#include "dbus/values_util.h" +#include "testing/gtest/include/gtest/gtest.h" +#include "third_party/cros_system_api/dbus/service_constants.h" + +namespace chromeos { + +namespace { + +const char kExampleServicePath[] = "/foo/bar"; + +} // namespace + +class FlimflamServiceClientTest : public FlimflamClientUnittestBase { + public: + FlimflamServiceClientTest() + : FlimflamClientUnittestBase(flimflam::kFlimflamServiceInterface, + dbus::ObjectPath(kExampleServicePath)) { + } + + virtual void SetUp() { + FlimflamClientUnittestBase::SetUp(); + // Create a client with the mock bus. + client_.reset(FlimflamServiceClient::Create(REAL_DBUS_CLIENT_IMPLEMENTATION, + mock_bus_)); + // Run the message loop to run the signal connection result callback. + message_loop_.RunAllPending(); + } + + virtual void TearDown() { + FlimflamClientUnittestBase::TearDown(); + } + + protected: + scoped_ptr<FlimflamServiceClient> client_; +}; + +TEST_F(FlimflamServiceClientTest, PropertyChanged) { + const int kValue = 42; + // Create a signal. + dbus::Signal signal(flimflam::kFlimflamServiceInterface, + flimflam::kMonitorPropertyChanged); + dbus::MessageWriter writer(&signal); + writer.AppendString(flimflam::kSignalStrengthProperty); + writer.AppendVariantOfByte(kValue); + + // Set expectations. + const base::FundamentalValue value(kValue); + client_->SetPropertyChangedHandler( + dbus::ObjectPath(kExampleServicePath), + base::Bind(&ExpectPropertyChanged, + flimflam::kSignalStrengthProperty, + &value)); + // Run the signal callback. + SendPropertyChangedSignal(&signal); + + // Reset the handler. + client_->ResetPropertyChangedHandler(dbus::ObjectPath(kExampleServicePath)); +} + +TEST_F(FlimflamServiceClientTest, GetProperties) { + const int kValue = 42; + // Create response. + scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); + dbus::MessageWriter writer(response.get()); + dbus::MessageWriter array_writer(NULL); + writer.OpenArray("{sv}", &array_writer); + dbus::MessageWriter entry_writer(NULL); + array_writer.OpenDictEntry(&entry_writer); + entry_writer.AppendString(flimflam::kSignalStrengthProperty); + entry_writer.AppendVariantOfByte(kValue); + array_writer.CloseContainer(&entry_writer); + writer.CloseContainer(&array_writer); + + // Set expectations. + base::DictionaryValue value; + value.SetWithoutPathExpansion(flimflam::kSignalStrengthProperty, + base::Value::CreateIntegerValue(kValue)); + PrepareForMethodCall(flimflam::kGetPropertiesFunction, + base::Bind(&ExpectNoArgument), + response.get()); + // Call method. + client_->GetProperties(dbus::ObjectPath(kExampleServicePath), + base::Bind(&ExpectDictionaryValueResult, &value)); + // Run the message loop. + message_loop_.RunAllPending(); +} + +TEST_F(FlimflamServiceClientTest, SetProperty) { + const char kValue[] = "passphrase"; + // Create response. + scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); + + // Set expectations. + const base::StringValue value(kValue); + PrepareForMethodCall(flimflam::kSetPropertyFunction, + base::Bind(&ExpectStringAndValueArguments, + flimflam::kPassphraseProperty, + &value), + response.get()); + // Call method. + client_->SetProperty(dbus::ObjectPath(kExampleServicePath), + flimflam::kPassphraseProperty, + value, + base::Bind(&ExpectNoResultValue)); + // Run the message loop. + message_loop_.RunAllPending(); +} + +TEST_F(FlimflamServiceClientTest, ClearProperty) { + // Create response. + scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); + + // Set expectations. + PrepareForMethodCall(flimflam::kClearPropertyFunction, + base::Bind(&ExpectStringArgument, + flimflam::kPassphraseProperty), + response.get()); + // Call method. + client_->ClearProperty(dbus::ObjectPath(kExampleServicePath), + flimflam::kPassphraseProperty, + base::Bind(&ExpectNoResultValue)); + // Run the message loop. + message_loop_.RunAllPending(); +} + +TEST_F(FlimflamServiceClientTest, Connect) { + // Create response. + scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); + + // Set expectations. + PrepareForMethodCall(flimflam::kConnectFunction, + base::Bind(&ExpectNoArgument), + response.get()); + // Call method. + client_->Connect(dbus::ObjectPath(kExampleServicePath), + base::Bind(&ExpectNoResultValue)); + // Run the message loop. + message_loop_.RunAllPending(); +} + +TEST_F(FlimflamServiceClientTest, Disconnect) { + // Create response. + scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); + + // Set expectations. + PrepareForMethodCall(flimflam::kDisconnectFunction, + base::Bind(&ExpectNoArgument), + response.get()); + // Call method. + client_->Disconnect(dbus::ObjectPath(kExampleServicePath), + base::Bind(&ExpectNoResultValue)); + // Run the message loop. + message_loop_.RunAllPending(); +} + +TEST_F(FlimflamServiceClientTest, Remove) { + // Create response. + scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); + + // Set expectations. + PrepareForMethodCall(flimflam::kRemoveServiceFunction, + base::Bind(&ExpectNoArgument), + response.get()); + // Call method. + client_->Remove(dbus::ObjectPath(kExampleServicePath), + base::Bind(&ExpectNoResultValue)); + // Run the message loop. + message_loop_.RunAllPending(); +} + +TEST_F(FlimflamServiceClientTest, ActivateCellularModem) { + const char kCarrier[] = "carrier"; + // Create response. + scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); + + // Set expectations. + PrepareForMethodCall(flimflam::kActivateCellularModemFunction, + base::Bind(&ExpectStringArgument, kCarrier), + response.get()); + // Call method. + client_->ActivateCellularModem(dbus::ObjectPath(kExampleServicePath), + kCarrier, + base::Bind(&ExpectNoResultValue)); + // Run the message loop. + message_loop_.RunAllPending(); +} + +} // namespace chromeos diff --git a/chromeos/dbus/mock_dbus_thread_manager.cc b/chromeos/dbus/mock_dbus_thread_manager.cc index e268f66..26fca25 100644 --- a/chromeos/dbus/mock_dbus_thread_manager.cc +++ b/chromeos/dbus/mock_dbus_thread_manager.cc @@ -18,6 +18,7 @@ #include "chromeos/dbus/mock_flimflam_manager_client.h" #include "chromeos/dbus/mock_flimflam_network_client.h" #include "chromeos/dbus/mock_flimflam_profile_client.h" +#include "chromeos/dbus/mock_flimflam_service_client.h" #include "chromeos/dbus/mock_image_burner_client.h" #include "chromeos/dbus/mock_introspectable_client.h" #include "chromeos/dbus/mock_power_manager_client.h" @@ -46,6 +47,7 @@ MockDBusThreadManager::MockDBusThreadManager() mock_flimflam_manager_client_(new MockFlimflamManagerClient), mock_flimflam_network_client_(new MockFlimflamNetworkClient), mock_flimflam_profile_client_(new MockFlimflamProfileClient), + mock_flimflam_service_client_(new MockFlimflamServiceClient), mock_image_burner_client_(new MockImageBurnerClient), mock_introspectable_client_(new MockIntrospectableClient), mock_power_manager_client_(new MockPowerManagerClient), @@ -80,6 +82,8 @@ MockDBusThreadManager::MockDBusThreadManager() .WillRepeatedly(Return(mock_flimflam_network_client())); EXPECT_CALL(*this, GetFlimflamProfileClient()) .WillRepeatedly(Return(mock_flimflam_profile_client())); + EXPECT_CALL(*this, GetFlimflamServiceClient()) + .WillRepeatedly(Return(mock_flimflam_service_client())); EXPECT_CALL(*this, GetImageBurnerClient()) .WillRepeatedly(Return(mock_image_burner_client())); EXPECT_CALL(*this, GetIntrospectableClient()) diff --git a/chromeos/dbus/mock_dbus_thread_manager.h b/chromeos/dbus/mock_dbus_thread_manager.h index cf9b3b1..0e9e64f 100644 --- a/chromeos/dbus/mock_dbus_thread_manager.h +++ b/chromeos/dbus/mock_dbus_thread_manager.h @@ -32,6 +32,7 @@ class MockFlimflamIPConfigClient; class MockFlimflamManagerClient; class MockFlimflamNetworkClient; class MockFlimflamProfileClient; +class MockFlimflamServiceClient; class MockImageBurnerClient; class MockIntrospectableClient; class MockPowerManagerClient; @@ -62,6 +63,7 @@ class MockDBusThreadManager : public DBusThreadManager { MOCK_METHOD0(GetFlimflamManagerClient, FlimflamManagerClient*(void)); MOCK_METHOD0(GetFlimflamNetworkClient, FlimflamNetworkClient*(void)); MOCK_METHOD0(GetFlimflamProfileClient, FlimflamProfileClient*(void)); + MOCK_METHOD0(GetFlimflamServiceClient, FlimflamServiceClient*(void)); MOCK_METHOD0(GetImageBurnerClient, ImageBurnerClient*(void)); MOCK_METHOD0(GetIntrospectableClient, IntrospectableClient*(void)); MOCK_METHOD0(GetPowerManagerClient, PowerManagerClient*(void)); @@ -111,6 +113,9 @@ class MockDBusThreadManager : public DBusThreadManager { MockFlimflamProfileClient* mock_flimflam_profile_client() { return mock_flimflam_profile_client_.get(); } + MockFlimflamServiceClient* mock_flimflam_service_client() { + return mock_flimflam_service_client_.get(); + } MockImageBurnerClient* mock_image_burner_client() { return mock_image_burner_client_.get(); } @@ -145,6 +150,7 @@ class MockDBusThreadManager : public DBusThreadManager { scoped_ptr<MockFlimflamManagerClient> mock_flimflam_manager_client_; scoped_ptr<MockFlimflamNetworkClient> mock_flimflam_network_client_; scoped_ptr<MockFlimflamProfileClient> mock_flimflam_profile_client_; + scoped_ptr<MockFlimflamServiceClient> mock_flimflam_service_client_; scoped_ptr<MockImageBurnerClient> mock_image_burner_client_; scoped_ptr<MockIntrospectableClient> mock_introspectable_client_; scoped_ptr<MockPowerManagerClient> mock_power_manager_client_; diff --git a/chromeos/dbus/mock_flimflam_service_client.cc b/chromeos/dbus/mock_flimflam_service_client.cc new file mode 100644 index 0000000..72f24d7 --- /dev/null +++ b/chromeos/dbus/mock_flimflam_service_client.cc @@ -0,0 +1,13 @@ +// 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 "chromeos/dbus/mock_flimflam_service_client.h" + +namespace chromeos { + +MockFlimflamServiceClient::MockFlimflamServiceClient() {} + +MockFlimflamServiceClient::~MockFlimflamServiceClient() {} + +} // namespace chromeos diff --git a/chromeos/dbus/mock_flimflam_service_client.h b/chromeos/dbus/mock_flimflam_service_client.h new file mode 100644 index 0000000..4a67b4b --- /dev/null +++ b/chromeos/dbus/mock_flimflam_service_client.h @@ -0,0 +1,47 @@ +// 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. + +#ifndef CHROMEOS_DBUS_MOCK_FLIMFLAM_SERVICE_CLIENT_H_ +#define CHROMEOS_DBUS_MOCK_FLIMFLAM_SERVICE_CLIENT_H_ + +#include "base/values.h" +#include "chromeos/dbus/flimflam_service_client.h" +#include "dbus/object_path.h" +#include "testing/gmock/include/gmock/gmock.h" + +namespace chromeos { + +class MockFlimflamServiceClient : public FlimflamServiceClient { + public: + MockFlimflamServiceClient(); + virtual ~MockFlimflamServiceClient(); + + MOCK_METHOD2(SetPropertyChangedHandler, + void(const dbus::ObjectPath& service_path, + const PropertyChangedHandler& handler)); + MOCK_METHOD1(ResetPropertyChangedHandler, + void(const dbus::ObjectPath& service_path)); + MOCK_METHOD2(GetProperties, void(const dbus::ObjectPath& service_path, + const DictionaryValueCallback& callback)); + MOCK_METHOD4(SetProperty, void(const dbus::ObjectPath& service_path, + const std::string& name, + const base::Value& value, + const VoidCallback& callback)); + MOCK_METHOD3(ClearProperty, void(const dbus::ObjectPath& service_path, + const std::string& name, + const VoidCallback& callback)); + MOCK_METHOD2(Connect, void(const dbus::ObjectPath& service_path, + const VoidCallback& callback)); + MOCK_METHOD2(Disconnect, void(const dbus::ObjectPath& service_path, + const VoidCallback& callback)); + MOCK_METHOD2(Remove, void(const dbus::ObjectPath& service_path, + const VoidCallback& callback)); + MOCK_METHOD3(ActivateCellularModem, void(const dbus::ObjectPath& service_path, + const std::string& carrier, + const VoidCallback& callback)); +}; + +} // namespace chromeos + +#endif // CHROMEOS_DBUS_MOCK_FLIMFLAM_SERVICE_CLIENT_H_ |