summaryrefslogtreecommitdiffstats
path: root/chromeos
diff options
context:
space:
mode:
authorhashimoto@chromium.org <hashimoto@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-04-17 04:40:13 +0000
committerhashimoto@chromium.org <hashimoto@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-04-17 04:40:13 +0000
commit0e589042d7e17a5dbf5f7bbeb79fd18ea17e8377 (patch)
tree36fc005c9c0fb1805136c3213d7d3c9e377a162a /chromeos
parent65208a08fd10dc98b4c21676d5113359303a12a6 (diff)
downloadchromium_src-0e589042d7e17a5dbf5f7bbeb79fd18ea17e8377.zip
chromium_src-0e589042d7e17a5dbf5f7bbeb79fd18ea17e8377.tar.gz
chromium_src-0e589042d7e17a5dbf5f7bbeb79fd18ea17e8377.tar.bz2
Add FlimflamDeviceClient
BUG=chromium-os:16557 TEST=chromeos_unittests --gtest_filter="FlimflamDeviceClientTest.*" Review URL: http://codereview.chromium.org/10095004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@132538 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chromeos')
-rw-r--r--chromeos/chromeos.gyp5
-rw-r--r--chromeos/dbus/dbus_thread_manager.cc10
-rw-r--r--chromeos/dbus/dbus_thread_manager.h6
-rw-r--r--chromeos/dbus/flimflam_device_client.cc309
-rw-r--r--chromeos/dbus/flimflam_device_client.h130
-rw-r--r--chromeos/dbus/flimflam_device_client_unittest.cc273
-rw-r--r--chromeos/dbus/mock_dbus_thread_manager.cc4
-rw-r--r--chromeos/dbus/mock_dbus_thread_manager.h6
-rw-r--r--chromeos/dbus/mock_flimflam_device_client.cc13
-rw-r--r--chromeos/dbus/mock_flimflam_device_client.h61
10 files changed, 817 insertions, 0 deletions
diff --git a/chromeos/chromeos.gyp b/chromeos/chromeos.gyp
index 1bdf2bc..98da48b 100644
--- a/chromeos/chromeos.gyp
+++ b/chromeos/chromeos.gyp
@@ -53,6 +53,8 @@
'dbus/flimflam_ipconfig_client.h',
'dbus/flimflam_client_helper.cc',
'dbus/flimflam_client_helper.h',
+ 'dbus/flimflam_device_client.cc',
+ 'dbus/flimflam_device_client.h',
'dbus/flimflam_manager_client.cc',
'dbus/flimflam_manager_client.h',
'dbus/flimflam_network_client.cc',
@@ -105,6 +107,8 @@
'dbus/mock_dbus_thread_manager.h',
'dbus/mock_debug_daemon_client.cc',
'dbus/mock_debug_daemon_client.h',
+ 'dbus/mock_flimflam_device_client.cc',
+ 'dbus/mock_flimflam_device_client.h',
'dbus/mock_flimflam_ipconfig_client.cc',
'dbus/mock_flimflam_ipconfig_client.h',
'dbus/mock_flimflam_manager_client.cc',
@@ -146,6 +150,7 @@
'dbus/blocking_method_caller_unittest.cc',
'dbus/flimflam_client_unittest_base.cc',
'dbus/flimflam_client_unittest_base.h',
+ 'dbus/flimflam_device_client_unittest.cc',
'dbus/flimflam_manager_client_unittest.cc',
'dbus/flimflam_network_client_unittest.cc',
'dbus/flimflam_profile_client_unittest.cc',
diff --git a/chromeos/dbus/dbus_thread_manager.cc b/chromeos/dbus/dbus_thread_manager.cc
index d446ed4..2316788 100644
--- a/chromeos/dbus/dbus_thread_manager.cc
+++ b/chromeos/dbus/dbus_thread_manager.cc
@@ -16,6 +16,7 @@
#include "chromeos/dbus/cryptohome_client.h"
#include "chromeos/dbus/dbus_client_implementation_type.h"
#include "chromeos/dbus/debug_daemon_client.h"
+#include "chromeos/dbus/flimflam_device_client.h"
#include "chromeos/dbus/flimflam_ipconfig_client.h"
#include "chromeos/dbus/flimflam_manager_client.h"
#include "chromeos/dbus/flimflam_network_client.h"
@@ -77,6 +78,9 @@ class DBusThreadManagerImpl : public DBusThreadManager {
// Create the debugdaemon client.
debugdaemon_client_.reset(
DebugDaemonClient::Create(client_type, system_bus_.get()));
+ // Create the Flimflam Device client.
+ flimflam_device_client_.reset(
+ FlimflamDeviceClient::Create(client_type, system_bus_.get()));
// Create the Flimflam IPConfig client.
flimflam_ipconfig_client_.reset(
FlimflamIPConfigClient::Create(client_type, system_bus_.get()));
@@ -169,6 +173,11 @@ class DBusThreadManagerImpl : public DBusThreadManager {
}
// DBusThreadManager override.
+ virtual FlimflamDeviceClient* GetFlimflamDeviceClient() OVERRIDE {
+ return flimflam_device_client_.get();
+ }
+
+ // DBusThreadManager override.
virtual FlimflamIPConfigClient* GetFlimflamIPConfigClient() OVERRIDE {
return flimflam_ipconfig_client_.get();
}
@@ -229,6 +238,7 @@ class DBusThreadManagerImpl : public DBusThreadManager {
scoped_ptr<CrosDisksClient> cros_disks_client_;
scoped_ptr<CryptohomeClient> cryptohome_client_;
scoped_ptr<DebugDaemonClient> debugdaemon_client_;
+ scoped_ptr<FlimflamDeviceClient> flimflam_device_client_;
scoped_ptr<FlimflamIPConfigClient> flimflam_ipconfig_client_;
scoped_ptr<FlimflamManagerClient> flimflam_manager_client_;
scoped_ptr<FlimflamNetworkClient> flimflam_network_client_;
diff --git a/chromeos/dbus/dbus_thread_manager.h b/chromeos/dbus/dbus_thread_manager.h
index 6b0245c..ee7770f 100644
--- a/chromeos/dbus/dbus_thread_manager.h
+++ b/chromeos/dbus/dbus_thread_manager.h
@@ -30,6 +30,7 @@ class CashewClient;
class CrosDisksClient;
class CryptohomeClient;
class DebugDaemonClient;
+class FlimflamDeviceClient;
class FlimflamIPConfigClient;
class FlimflamManagerClient;
class FlimflamNetworkClient;
@@ -126,6 +127,11 @@ class CHROMEOS_EXPORT DBusThreadManager {
// down.
virtual DebugDaemonClient* GetDebugDaemonClient() = 0;
+ // Returns the Flimflam Device client, owned by DBusThreadManager.
+ // Do not cache this pointer and use it after DBusThreadManager is shut
+ // down.
+ virtual FlimflamDeviceClient* GetFlimflamDeviceClient() = 0;
+
// Returns the Flimflam IPConfig client, owned by DBusThreadManager.
// Do not cache this pointer and use it after DBusThreadManager is shut
// down.
diff --git a/chromeos/dbus/flimflam_device_client.cc b/chromeos/dbus/flimflam_device_client.cc
new file mode 100644
index 0000000..d9e0907
--- /dev/null
+++ b/chromeos/dbus/flimflam_device_client.cc
@@ -0,0 +1,309 @@
+// 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_device_client.h"
+
+#include "base/bind.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_path.h"
+#include "dbus/object_proxy.h"
+#include "dbus/values_util.h"
+#include "third_party/cros_system_api/dbus/service_constants.h"
+
+namespace chromeos {
+
+namespace {
+
+// The FlimflamDeviceClient implementation.
+class FlimflamDeviceClientImpl : public FlimflamDeviceClient {
+ public:
+ explicit FlimflamDeviceClientImpl(dbus::Bus* bus)
+ : bus_(bus),
+ helpers_deleter_(&helpers_) {
+ }
+
+ // FlimflamProfileClient override.
+ virtual void SetPropertyChangedHandler(
+ const dbus::ObjectPath& device_path,
+ const PropertyChangedHandler& handler) OVERRIDE {
+ GetHelper(device_path)->SetPropertyChangedHandler(handler);
+ }
+
+ // FlimflamProfileClient override.
+ virtual void ResetPropertyChangedHandler(
+ const dbus::ObjectPath& device_path) OVERRIDE {
+ GetHelper(device_path)->ResetPropertyChangedHandler();
+ }
+
+ // FlimflamProfileClient override.
+ virtual void GetProperties(const dbus::ObjectPath& device_path,
+ const DictionaryValueCallback& callback) OVERRIDE {
+ dbus::MethodCall method_call(flimflam::kFlimflamDeviceInterface,
+ flimflam::kGetPropertiesFunction);
+ GetHelper(device_path)->CallDictionaryValueMethod(&method_call, callback);
+ }
+
+ // FlimflamProfileClient override.
+ virtual void ProposeScan(const dbus::ObjectPath& device_path,
+ const VoidCallback& callback) OVERRIDE {
+ dbus::MethodCall method_call(flimflam::kFlimflamDeviceInterface,
+ flimflam::kProposeScanFunction);
+ GetHelper(device_path)->CallVoidMethod(&method_call, callback);
+ }
+
+ // FlimflamProfileClient override.
+ virtual void SetProperty(const dbus::ObjectPath& device_path,
+ const std::string& name,
+ const base::Value& value,
+ const VoidCallback& callback) OVERRIDE {
+ dbus::MethodCall method_call(flimflam::kFlimflamDeviceInterface,
+ flimflam::kSetPropertyFunction);
+ dbus::MessageWriter writer(&method_call);
+ writer.AppendString(name);
+ FlimflamClientHelper::AppendValueDataAsVariant(&writer, value);
+ GetHelper(device_path)->CallVoidMethod(&method_call, callback);
+ }
+
+ // FlimflamProfileClient override.
+ virtual void ClearProperty(const dbus::ObjectPath& device_path,
+ const std::string& name,
+ const VoidCallback& callback) OVERRIDE {
+ dbus::MethodCall method_call(flimflam::kFlimflamDeviceInterface,
+ flimflam::kClearPropertyFunction);
+ dbus::MessageWriter writer(&method_call);
+ writer.AppendString(name);
+ GetHelper(device_path)->CallVoidMethod(&method_call, callback);
+ }
+
+ // FlimflamProfileClient override.
+ virtual void AddIPConfig(const dbus::ObjectPath& device_path,
+ const std::string& method,
+ const ObjectPathCallback& callback) OVERRIDE {
+ dbus::MethodCall method_call(flimflam::kFlimflamDeviceInterface,
+ flimflam::kAddIPConfigFunction);
+ dbus::MessageWriter writer(&method_call);
+ writer.AppendString(method);
+ GetHelper(device_path)->CallObjectPathMethod(&method_call, callback);
+ }
+
+ // FlimflamProfileClient override.
+ virtual void RequirePin(const dbus::ObjectPath& device_path,
+ const std::string& pin,
+ bool require,
+ const VoidCallback& callback) OVERRIDE {
+ dbus::MethodCall method_call(flimflam::kFlimflamDeviceInterface,
+ flimflam::kRequirePinFunction);
+ dbus::MessageWriter writer(&method_call);
+ writer.AppendString(pin);
+ writer.AppendBool(require);
+ GetHelper(device_path)->CallVoidMethod(&method_call, callback);
+ }
+
+ // FlimflamProfileClient override.
+ virtual void EnterPin(const dbus::ObjectPath& device_path,
+ const std::string& pin,
+ const VoidCallback& callback) OVERRIDE {
+ dbus::MethodCall method_call(flimflam::kFlimflamDeviceInterface,
+ flimflam::kEnterPinFunction);
+ dbus::MessageWriter writer(&method_call);
+ writer.AppendString(pin);
+ GetHelper(device_path)->CallVoidMethod(&method_call, callback);
+ }
+
+ // FlimflamProfileClient override.
+ virtual void UnblockPin(const dbus::ObjectPath& device_path,
+ const std::string& puk,
+ const std::string& pin,
+ const VoidCallback& callback) OVERRIDE {
+ dbus::MethodCall method_call(flimflam::kFlimflamDeviceInterface,
+ flimflam::kUnblockPinFunction);
+ dbus::MessageWriter writer(&method_call);
+ writer.AppendString(puk);
+ writer.AppendString(pin);
+ GetHelper(device_path)->CallVoidMethod(&method_call, callback);
+ }
+
+ // FlimflamProfileClient override.
+ virtual void ChangePin(const dbus::ObjectPath& device_path,
+ const std::string& old_pin,
+ const std::string& new_pin,
+ const VoidCallback& callback) OVERRIDE {
+ dbus::MethodCall method_call(flimflam::kFlimflamDeviceInterface,
+ flimflam::kChangePinFunction);
+ dbus::MessageWriter writer(&method_call);
+ writer.AppendString(old_pin);
+ writer.AppendString(new_pin);
+ GetHelper(device_path)->CallVoidMethod(&method_call, callback);
+ }
+
+ // FlimflamProfileClient override.
+ virtual void Register(const dbus::ObjectPath& device_path,
+ const std::string& network_id,
+ const VoidCallback& callback) OVERRIDE {
+ dbus::MethodCall method_call(flimflam::kFlimflamDeviceInterface,
+ flimflam::kRegisterFunction);
+ dbus::MessageWriter writer(&method_call);
+ writer.AppendString(network_id);
+ GetHelper(device_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& device_path) {
+ HelperMap::iterator it = helpers_.find(device_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, device_path);
+ FlimflamClientHelper* helper = new FlimflamClientHelper(object_proxy);
+ helper->MonitorPropertyChanged(flimflam::kFlimflamDeviceInterface);
+ helpers_.insert(HelperMap::value_type(device_path.value(), helper));
+ return helper;
+ }
+
+ dbus::Bus* bus_;
+ HelperMap helpers_;
+ STLValueDeleter<HelperMap> helpers_deleter_;
+
+ DISALLOW_COPY_AND_ASSIGN(FlimflamDeviceClientImpl);
+};
+
+// A stub implementation of FlimflamDeviceClient.
+class FlimflamDeviceClientStubImpl : public FlimflamDeviceClient {
+ public:
+ FlimflamDeviceClientStubImpl() : weak_ptr_factory_(this) {}
+
+ virtual ~FlimflamDeviceClientStubImpl() {}
+
+ // FlimflamDeviceClient override.
+ virtual void SetPropertyChangedHandler(
+ const dbus::ObjectPath& device_path,
+ const PropertyChangedHandler& handler) OVERRIDE {}
+
+ // FlimflamDeviceClient override.
+ virtual void ResetPropertyChangedHandler(
+ const dbus::ObjectPath& device_path) OVERRIDE {}
+
+ // FlimflamDeviceClient override.
+ virtual void GetProperties(const dbus::ObjectPath& device_path,
+ const DictionaryValueCallback& callback) OVERRIDE {
+ MessageLoop::current()->PostTask(
+ FROM_HERE,
+ base::Bind(&FlimflamDeviceClientStubImpl::PassEmptyDictionaryValue,
+ weak_ptr_factory_.GetWeakPtr(),
+ callback));
+ }
+
+ // FlimflamProfileClient override.
+ virtual void ProposeScan(const dbus::ObjectPath& device_path,
+ const VoidCallback& callback) OVERRIDE {
+ PostSuccessVoidCallback(callback);
+ }
+
+ // FlimflamDeviceClient override.
+ virtual void SetProperty(const dbus::ObjectPath& device_path,
+ const std::string& name,
+ const base::Value& value,
+ const VoidCallback& callback) OVERRIDE {
+ PostSuccessVoidCallback(callback);
+ }
+
+ // FlimflamDeviceClient override.
+ virtual void ClearProperty(const dbus::ObjectPath& device_path,
+ const std::string& name,
+ const VoidCallback& callback) OVERRIDE {
+ PostSuccessVoidCallback(callback);
+ }
+
+ // FlimflamDeviceClient override.
+ virtual void AddIPConfig(const dbus::ObjectPath& device_path,
+ const std::string& method,
+ const ObjectPathCallback& callback) OVERRIDE {
+ MessageLoop::current()->PostTask(FROM_HERE,
+ base::Bind(callback,
+ DBUS_METHOD_CALL_SUCCESS,
+ dbus::ObjectPath()));
+ }
+
+ // FlimflamDeviceClient override.
+ virtual void RequirePin(const dbus::ObjectPath& device_path,
+ const std::string& pin,
+ bool require,
+ const VoidCallback& callback) OVERRIDE {
+ PostSuccessVoidCallback(callback);
+ }
+
+ // FlimflamDeviceClient override.
+ virtual void EnterPin(const dbus::ObjectPath& device_path,
+ const std::string& pin,
+ const VoidCallback& callback) OVERRIDE {
+ PostSuccessVoidCallback(callback);
+ }
+
+ // FlimflamDeviceClient override.
+ virtual void UnblockPin(const dbus::ObjectPath& device_path,
+ const std::string& puk,
+ const std::string& pin,
+ const VoidCallback& callback) OVERRIDE {
+ PostSuccessVoidCallback(callback);
+ }
+
+ // FlimflamDeviceClient override.
+ virtual void ChangePin(const dbus::ObjectPath& device_path,
+ const std::string& old_pin,
+ const std::string& new_pin,
+ const VoidCallback& callback) OVERRIDE {
+ PostSuccessVoidCallback(callback);
+ }
+
+ // FlimflamDeviceClient override.
+ virtual void Register(const dbus::ObjectPath& device_path,
+ const std::string& network_id,
+ 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<FlimflamDeviceClientStubImpl> weak_ptr_factory_;
+
+ DISALLOW_COPY_AND_ASSIGN(FlimflamDeviceClientStubImpl);
+};
+
+} // namespace
+
+FlimflamDeviceClient::FlimflamDeviceClient() {}
+
+FlimflamDeviceClient::~FlimflamDeviceClient() {}
+
+// static
+FlimflamDeviceClient* FlimflamDeviceClient::Create(
+ DBusClientImplementationType type,
+ dbus::Bus* bus) {
+ if (type == REAL_DBUS_CLIENT_IMPLEMENTATION)
+ return new FlimflamDeviceClientImpl(bus);
+ DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type);
+ return new FlimflamDeviceClientStubImpl();
+}
+
+} // namespace chromeos
diff --git a/chromeos/dbus/flimflam_device_client.h b/chromeos/dbus/flimflam_device_client.h
new file mode 100644
index 0000000..722f0c3
--- /dev/null
+++ b/chromeos/dbus/flimflam_device_client.h
@@ -0,0 +1,130 @@
+// 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_DEVICE_CLIENT_H_
+#define CHROMEOS_DBUS_FLIMFLAM_DEVICE_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 {
+
+// FlimflamDeviceClient is used to communicate with the Flimflam Device service.
+// All methods should be called from the origin thread which initializes the
+// DBusThreadManager instance.
+class CHROMEOS_EXPORT FlimflamDeviceClient {
+ public:
+ typedef FlimflamClientHelper::PropertyChangedHandler PropertyChangedHandler;
+ typedef FlimflamClientHelper::VoidCallback VoidCallback;
+ typedef FlimflamClientHelper::ObjectPathCallback ObjectPathCallback;
+ typedef FlimflamClientHelper::DictionaryValueCallback DictionaryValueCallback;
+
+ virtual ~FlimflamDeviceClient();
+
+ // Factory function, creates a new instance which is owned by the caller.
+ // For normal usage, access the singleton via DBusThreadManager::Get().
+ static FlimflamDeviceClient* Create(DBusClientImplementationType type,
+ dbus::Bus* bus);
+
+ // Sets PropertyChanged signal handler.
+ virtual void SetPropertyChangedHandler(
+ const dbus::ObjectPath& device_path,
+ const PropertyChangedHandler& handler) = 0;
+
+ // Resets PropertyChanged signal handler.
+ virtual void ResetPropertyChangedHandler(
+ const dbus::ObjectPath& device_path) = 0;
+
+ // Calls GetProperties method.
+ // |callback| is called after the method call finishes.
+ virtual void GetProperties(const dbus::ObjectPath& device_path,
+ const DictionaryValueCallback& callback) = 0;
+
+ // Calls ProposeScan method.
+ // |callback| is called after the method call finishes.
+ virtual void ProposeScan(const dbus::ObjectPath& device_path,
+ const VoidCallback& callback) = 0;
+
+ // Calls SetProperty method.
+ // |callback| is called after the method call finishes.
+ virtual void SetProperty(const dbus::ObjectPath& device_path,
+ const std::string& name,
+ const base::Value& value,
+ const VoidCallback& callback) = 0;
+
+ // Calls ClearProperty method.
+ // |callback| is called after the method call finishes.
+ virtual void ClearProperty(const dbus::ObjectPath& device_path,
+ const std::string& name,
+ const VoidCallback& callback) = 0;
+
+ // Calls AddIPConfig method.
+ // |callback| is called after the method call finishes.
+ virtual void AddIPConfig(const dbus::ObjectPath& device_path,
+ const std::string& method,
+ const ObjectPathCallback& callback) = 0;
+
+ // Calls RequirePin method.
+ // |callback| is called after the method call finishes.
+ virtual void RequirePin(const dbus::ObjectPath& device_path,
+ const std::string& pin,
+ bool require,
+ const VoidCallback& callback) = 0;
+
+ // Calls EnterPin method.
+ // |callback| is called after the method call finishes.
+ virtual void EnterPin(const dbus::ObjectPath& device_path,
+ const std::string& pin,
+ const VoidCallback& callback) = 0;
+
+ // Calls UnblockPin method.
+ // |callback| is called after the method call finishes.
+ virtual void UnblockPin(const dbus::ObjectPath& device_path,
+ const std::string& puk,
+ const std::string& pin,
+ const VoidCallback& callback) = 0;
+
+ // Calls ChangePin method.
+ // |callback| is called after the method call finishes.
+ virtual void ChangePin(const dbus::ObjectPath& device_path,
+ const std::string& old_pin,
+ const std::string& new_pin,
+ const VoidCallback& callback) = 0;
+
+ // Calls Register method.
+ // |callback| is called after the method call finishes.
+ virtual void Register(const dbus::ObjectPath& device_path,
+ const std::string& network_id,
+ const VoidCallback& callback) = 0;
+
+ protected:
+ // Create() should be used instead.
+ FlimflamDeviceClient();
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(FlimflamDeviceClient);
+};
+
+} // namespace chromeos
+
+#endif // CHROMEOS_DBUS_FLIMFLAM_DEVICE_CLIENT_H_
diff --git a/chromeos/dbus/flimflam_device_client_unittest.cc b/chromeos/dbus/flimflam_device_client_unittest.cc
new file mode 100644
index 0000000..516ceb4
--- /dev/null
+++ b/chromeos/dbus/flimflam_device_client_unittest.cc
@@ -0,0 +1,273 @@
+// 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_device_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 kExampleDevicePath[] = "/foo/bar";
+
+// Expects the reader to have a string and a bool.
+void ExpectStringAndBoolArguments(const std::string& expected_string,
+ bool expected_bool,
+ dbus::MessageReader* reader) {
+ std::string arg1;
+ ASSERT_TRUE(reader->PopString(&arg1));
+ EXPECT_EQ(expected_string, arg1);
+ bool arg2 = false;
+ ASSERT_TRUE(reader->PopBool(&arg2));
+ EXPECT_EQ(expected_bool, arg2);
+ EXPECT_FALSE(reader->HasMoreData());
+}
+
+// Expects the reader to have two strings.
+void ExpectTwoStringArguments(const std::string& expected_string1,
+ const std::string& expected_string2,
+ dbus::MessageReader* reader) {
+ std::string arg1;
+ ASSERT_TRUE(reader->PopString(&arg1));
+ EXPECT_EQ(expected_string1, arg1);
+ std::string arg2;
+ ASSERT_TRUE(reader->PopString(&arg2));
+ EXPECT_EQ(expected_string2, arg2);
+ EXPECT_FALSE(reader->HasMoreData());
+}
+
+} // namespace
+
+class FlimflamDeviceClientTest : public FlimflamClientUnittestBase {
+ public:
+ FlimflamDeviceClientTest()
+ : FlimflamClientUnittestBase(flimflam::kFlimflamDeviceInterface,
+ dbus::ObjectPath(kExampleDevicePath)) {
+ }
+
+ virtual void SetUp() {
+ FlimflamClientUnittestBase::SetUp();
+ // Create a client with the mock bus.
+ client_.reset(FlimflamDeviceClient::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<FlimflamDeviceClient> client_;
+};
+
+TEST_F(FlimflamDeviceClientTest, PropertyChanged) {
+ const bool kValue = true;
+ // Create a signal.
+ dbus::Signal signal(flimflam::kFlimflamDeviceInterface,
+ flimflam::kMonitorPropertyChanged);
+ dbus::MessageWriter writer(&signal);
+ writer.AppendString(flimflam::kCellularAllowRoamingProperty);
+ writer.AppendVariantOfBool(kValue);
+
+ // Set expectations.
+ const base::FundamentalValue value(kValue);
+ client_->SetPropertyChangedHandler(
+ dbus::ObjectPath(kExampleDevicePath),
+ base::Bind(&ExpectPropertyChanged,
+ flimflam::kCellularAllowRoamingProperty,
+ &value));
+ // Run the signal callback.
+ SendPropertyChangedSignal(&signal);
+
+ // Reset the handler.
+ client_->ResetPropertyChangedHandler(dbus::ObjectPath(kExampleDevicePath));
+}
+
+TEST_F(FlimflamDeviceClientTest, GetProperties) {
+ const bool kValue = true;
+ // 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::kCellularAllowRoamingProperty);
+ entry_writer.AppendVariantOfBool(kValue);
+ array_writer.CloseContainer(&entry_writer);
+ writer.CloseContainer(&array_writer);
+
+ // Set expectations.
+ base::DictionaryValue value;
+ value.SetWithoutPathExpansion(flimflam::kCellularAllowRoamingProperty,
+ base::Value::CreateBooleanValue(kValue));
+ PrepareForMethodCall(flimflam::kGetPropertiesFunction,
+ base::Bind(&ExpectNoArgument),
+ response.get());
+ // Call method.
+ client_->GetProperties(dbus::ObjectPath(kExampleDevicePath),
+ base::Bind(&ExpectDictionaryValueResult, &value));
+ // Run the message loop.
+ message_loop_.RunAllPending();
+}
+
+TEST_F(FlimflamDeviceClientTest, ProposeScan) {
+ // Create response.
+ scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
+
+ // Set expectations.
+ PrepareForMethodCall(flimflam::kProposeScanFunction,
+ base::Bind(&ExpectNoArgument),
+ response.get());
+ // Call method.
+ client_->ProposeScan(dbus::ObjectPath(kExampleDevicePath),
+ base::Bind(&ExpectNoResultValue));
+ // Run the message loop.
+ message_loop_.RunAllPending();
+}
+
+TEST_F(FlimflamDeviceClientTest, SetProperty) {
+ const bool kValue = true;
+ // Create response.
+ scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
+
+ // Set expectations.
+ const base::FundamentalValue value(kValue);
+ PrepareForMethodCall(flimflam::kSetPropertyFunction,
+ base::Bind(&ExpectStringAndValueArguments,
+ flimflam::kCellularAllowRoamingProperty,
+ &value),
+ response.get());
+ // Call method.
+ client_->SetProperty(dbus::ObjectPath(kExampleDevicePath),
+ flimflam::kCellularAllowRoamingProperty,
+ value,
+ base::Bind(&ExpectNoResultValue));
+ // Run the message loop.
+ message_loop_.RunAllPending();
+}
+
+TEST_F(FlimflamDeviceClientTest, ClearProperty) {
+ // Create response.
+ scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
+
+ // Set expectations.
+ PrepareForMethodCall(flimflam::kClearPropertyFunction,
+ base::Bind(&ExpectStringArgument,
+ flimflam::kCellularAllowRoamingProperty),
+ response.get());
+ // Call method.
+ client_->ClearProperty(dbus::ObjectPath(kExampleDevicePath),
+ flimflam::kCellularAllowRoamingProperty,
+ base::Bind(&ExpectNoResultValue));
+ // Run the message loop.
+ message_loop_.RunAllPending();
+}
+
+TEST_F(FlimflamDeviceClientTest, RequirePin) {
+ const char kPin[] = "123456";
+ const bool kRequired = true;
+ // Create response.
+ scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
+
+ // Set expectations.
+ PrepareForMethodCall(flimflam::kRequirePinFunction,
+ base::Bind(&ExpectStringAndBoolArguments,
+ kPin,
+ kRequired),
+ response.get());
+ // Call method.
+ client_->RequirePin(dbus::ObjectPath(kExampleDevicePath),
+ kPin,
+ kRequired,
+ base::Bind(&ExpectNoResultValue));
+ // Run the message loop.
+ message_loop_.RunAllPending();
+}
+
+TEST_F(FlimflamDeviceClientTest, EnterPin) {
+ const char kPin[] = "123456";
+ // Create response.
+ scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
+
+ // Set expectations.
+ PrepareForMethodCall(flimflam::kEnterPinFunction,
+ base::Bind(&ExpectStringArgument,
+ kPin),
+ response.get());
+ // Call method.
+ client_->EnterPin(dbus::ObjectPath(kExampleDevicePath),
+ kPin,
+ base::Bind(&ExpectNoResultValue));
+ // Run the message loop.
+ message_loop_.RunAllPending();
+}
+
+TEST_F(FlimflamDeviceClientTest, UnblockPin) {
+ const char kPuk[] = "987654";
+ const char kPin[] = "123456";
+ // Create response.
+ scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
+
+ // Set expectations.
+ PrepareForMethodCall(flimflam::kUnblockPinFunction,
+ base::Bind(&ExpectTwoStringArguments, kPuk, kPin),
+ response.get());
+ // Call method.
+ client_->UnblockPin(dbus::ObjectPath(kExampleDevicePath),
+ kPuk,
+ kPin,
+ base::Bind(&ExpectNoResultValue));
+ // Run the message loop.
+ message_loop_.RunAllPending();
+}
+
+TEST_F(FlimflamDeviceClientTest, ChangePin) {
+ const char kOldPin[] = "123456";
+ const char kNewPin[] = "234567";
+ // Create response.
+ scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
+
+ // Set expectations.
+ PrepareForMethodCall(flimflam::kChangePinFunction,
+ base::Bind(&ExpectTwoStringArguments,
+ kOldPin,
+ kNewPin),
+ response.get());
+ // Call method.
+ client_->ChangePin(dbus::ObjectPath(kExampleDevicePath),
+ kOldPin,
+ kNewPin,
+ base::Bind(&ExpectNoResultValue));
+ // Run the message loop.
+ message_loop_.RunAllPending();
+}
+
+TEST_F(FlimflamDeviceClientTest, Register) {
+ const char kNetworkId[] = "networkid";
+ // Create response.
+ scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
+
+ // Set expectations.
+ PrepareForMethodCall(flimflam::kRegisterFunction,
+ base::Bind(&ExpectStringArgument, kNetworkId),
+ response.get());
+ // Call method.
+ client_->Register(dbus::ObjectPath(kExampleDevicePath),
+ kNetworkId,
+ 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 54a731c..e268f66 100644
--- a/chromeos/dbus/mock_dbus_thread_manager.cc
+++ b/chromeos/dbus/mock_dbus_thread_manager.cc
@@ -13,6 +13,7 @@
#include "chromeos/dbus/mock_cros_disks_client.h"
#include "chromeos/dbus/mock_cryptohome_client.h"
#include "chromeos/dbus/mock_debug_daemon_client.h"
+#include "chromeos/dbus/mock_flimflam_device_client.h"
#include "chromeos/dbus/mock_flimflam_ipconfig_client.h"
#include "chromeos/dbus/mock_flimflam_manager_client.h"
#include "chromeos/dbus/mock_flimflam_network_client.h"
@@ -40,6 +41,7 @@ MockDBusThreadManager::MockDBusThreadManager()
mock_cros_disks_client_(new MockCrosDisksClient),
mock_cryptohome_client_(new MockCryptohomeClient),
mock_debugdaemon_client_(new MockDebugDaemonClient),
+ mock_flimflam_device_client_(new MockFlimflamDeviceClient),
mock_flimflam_ipconfig_client_(new MockFlimflamIPConfigClient),
mock_flimflam_manager_client_(new MockFlimflamManagerClient),
mock_flimflam_network_client_(new MockFlimflamNetworkClient),
@@ -68,6 +70,8 @@ MockDBusThreadManager::MockDBusThreadManager()
.WillRepeatedly(Return(mock_cryptohome_client()));
EXPECT_CALL(*this, GetDebugDaemonClient())
.WillRepeatedly(Return(mock_debugdaemon_client()));
+ EXPECT_CALL(*this, GetFlimflamDeviceClient())
+ .WillRepeatedly(Return(mock_flimflam_device_client()));
EXPECT_CALL(*this, GetFlimflamIPConfigClient())
.WillRepeatedly(Return(mock_flimflam_ipconfig_client()));
EXPECT_CALL(*this, GetFlimflamManagerClient())
diff --git a/chromeos/dbus/mock_dbus_thread_manager.h b/chromeos/dbus/mock_dbus_thread_manager.h
index 8caa4c1..cf9b3b1 100644
--- a/chromeos/dbus/mock_dbus_thread_manager.h
+++ b/chromeos/dbus/mock_dbus_thread_manager.h
@@ -27,6 +27,7 @@ class MockCashewClient;
class MockCrosDisksClient;
class MockCryptohomeClient;
class MockDebugDaemonClient;
+class MockFlimflamDeviceClient;
class MockFlimflamIPConfigClient;
class MockFlimflamManagerClient;
class MockFlimflamNetworkClient;
@@ -56,6 +57,7 @@ class MockDBusThreadManager : public DBusThreadManager {
MOCK_METHOD0(GetCrosDisksClient, CrosDisksClient*(void));
MOCK_METHOD0(GetCryptohomeClient, CryptohomeClient*(void));
MOCK_METHOD0(GetDebugDaemonClient, DebugDaemonClient*(void));
+ MOCK_METHOD0(GetFlimflamDeviceClient, FlimflamDeviceClient*(void));
MOCK_METHOD0(GetFlimflamIPConfigClient, FlimflamIPConfigClient*(void));
MOCK_METHOD0(GetFlimflamManagerClient, FlimflamManagerClient*(void));
MOCK_METHOD0(GetFlimflamNetworkClient, FlimflamNetworkClient*(void));
@@ -94,6 +96,9 @@ class MockDBusThreadManager : public DBusThreadManager {
MockDebugDaemonClient* mock_debugdaemon_client() {
return mock_debugdaemon_client_.get();
}
+ MockFlimflamDeviceClient* mock_flimflam_device_client() {
+ return mock_flimflam_device_client_.get();
+ }
MockFlimflamIPConfigClient* mock_flimflam_ipconfig_client() {
return mock_flimflam_ipconfig_client_.get();
}
@@ -135,6 +140,7 @@ class MockDBusThreadManager : public DBusThreadManager {
scoped_ptr<MockCrosDisksClient> mock_cros_disks_client_;
scoped_ptr<MockCryptohomeClient> mock_cryptohome_client_;
scoped_ptr<MockDebugDaemonClient> mock_debugdaemon_client_;
+ scoped_ptr<MockFlimflamDeviceClient> mock_flimflam_device_client_;
scoped_ptr<MockFlimflamIPConfigClient> mock_flimflam_ipconfig_client_;
scoped_ptr<MockFlimflamManagerClient> mock_flimflam_manager_client_;
scoped_ptr<MockFlimflamNetworkClient> mock_flimflam_network_client_;
diff --git a/chromeos/dbus/mock_flimflam_device_client.cc b/chromeos/dbus/mock_flimflam_device_client.cc
new file mode 100644
index 0000000..b26517b
--- /dev/null
+++ b/chromeos/dbus/mock_flimflam_device_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_device_client.h"
+
+namespace chromeos {
+
+MockFlimflamDeviceClient::MockFlimflamDeviceClient() {}
+
+MockFlimflamDeviceClient::~MockFlimflamDeviceClient() {}
+
+} // namespace chromeos
diff --git a/chromeos/dbus/mock_flimflam_device_client.h b/chromeos/dbus/mock_flimflam_device_client.h
new file mode 100644
index 0000000..278c1c8
--- /dev/null
+++ b/chromeos/dbus/mock_flimflam_device_client.h
@@ -0,0 +1,61 @@
+// 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_DEVICE_CLIENT_H_
+#define CHROMEOS_DBUS_MOCK_FLIMFLAM_DEVICE_CLIENT_H_
+
+#include "base/values.h"
+#include "chromeos/dbus/flimflam_device_client.h"
+#include "dbus/object_path.h"
+#include "testing/gmock/include/gmock/gmock.h"
+
+namespace chromeos {
+
+class MockFlimflamDeviceClient : public FlimflamDeviceClient {
+ public:
+ MockFlimflamDeviceClient();
+ virtual ~MockFlimflamDeviceClient();
+
+ MOCK_METHOD2(SetPropertyChangedHandler,
+ void(const dbus::ObjectPath& device_path,
+ const PropertyChangedHandler& handler));
+ MOCK_METHOD1(ResetPropertyChangedHandler,
+ void(const dbus::ObjectPath& device_path));
+ MOCK_METHOD2(GetProperties, void(const dbus::ObjectPath& device_path,
+ const DictionaryValueCallback& callback));
+ MOCK_METHOD2(ProposeScan, void(const dbus::ObjectPath& device_path,
+ const VoidCallback& callback));
+ MOCK_METHOD4(SetProperty, void(const dbus::ObjectPath& device_path,
+ const std::string& name,
+ const base::Value& value,
+ const VoidCallback& callback));
+ MOCK_METHOD3(ClearProperty, void(const dbus::ObjectPath& device_path,
+ const std::string& name,
+ const VoidCallback& callback));
+ MOCK_METHOD3(AddIPConfig, void(const dbus::ObjectPath& device_path,
+ const std::string& method,
+ const ObjectPathCallback& callback));
+ MOCK_METHOD4(RequirePin, void(const dbus::ObjectPath& device_path,
+ const std::string& pin,
+ bool require,
+ const VoidCallback& callback));
+ MOCK_METHOD3(EnterPin, void(const dbus::ObjectPath& device_path,
+ const std::string& pin,
+ const VoidCallback& callback));
+ MOCK_METHOD4(UnblockPin, void(const dbus::ObjectPath& device_path,
+ const std::string& puk,
+ const std::string& pin,
+ const VoidCallback& callback));
+ MOCK_METHOD4(ChangePin, void(const dbus::ObjectPath& device_path,
+ const std::string& old_pin,
+ const std::string& new_pin,
+ const VoidCallback& callback));
+ MOCK_METHOD3(Register, void(const dbus::ObjectPath& device_path,
+ const std::string& network_id,
+ const VoidCallback& callback));
+};
+
+} // namespace chromeos
+
+#endif // CHROMEOS_DBUS_MOCK_FLIMFLAM_DEVICE_CLIENT_H_