summaryrefslogtreecommitdiffstats
path: root/chromeos
diff options
context:
space:
mode:
authorgspencer@chromium.org <gspencer@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-11-17 00:08:34 +0000
committergspencer@chromium.org <gspencer@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-11-17 00:08:34 +0000
commit24e4732f6e68edd9b655023a13121a1c8116052f (patch)
tree9cf2ec2999ea7d1aa47165ced2e322b5d44888e7 /chromeos
parent573950e6933485a561f375eef45d15d852271600 (diff)
downloadchromium_src-24e4732f6e68edd9b655023a13121a1c8116052f.zip
chromium_src-24e4732f6e68edd9b655023a13121a1c8116052f.tar.gz
chromium_src-24e4732f6e68edd9b655023a13121a1c8116052f.tar.bz2
Adding network configuration handler class
that will eventually replace the NetworkLibrary method of configuring networks. BUG=none TEST=none Review URL: https://chromiumcodereview.appspot.com/11260047 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@168338 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chromeos')
-rw-r--r--chromeos/chromeos.gyp3
-rw-r--r--chromeos/network/network_configuration_handler.cc221
-rw-r--r--chromeos/network/network_configuration_handler.h124
-rw-r--r--chromeos/network/network_configuration_handler_unittest.cc364
4 files changed, 712 insertions, 0 deletions
diff --git a/chromeos/chromeos.gyp b/chromeos/chromeos.gyp
index b396819..3cbb1c6 100644
--- a/chromeos/chromeos.gyp
+++ b/chromeos/chromeos.gyp
@@ -126,6 +126,8 @@
'network/device_state.h',
'network/managed_state.cc',
'network/managed_state.h',
+ 'network/network_configuration_handler.cc',
+ 'network/network_configuration_handler.h',
'network/network_sms_handler.cc',
'network/network_sms_handler.h',
'network/network_state.cc',
@@ -286,6 +288,7 @@
'dbus/introspectable_client_unittest.cc',
'dbus/modem_messaging_client_unittest.cc',
'disks/disk_mount_manager_unittest.cc',
+ 'network/network_configuration_handler_unittest.cc',
'network/network_sms_handler_unittest.cc',
'network/network_state_handler_unittest.cc',
'network/shill_property_handler_unittest.cc',
diff --git a/chromeos/network/network_configuration_handler.cc b/chromeos/network/network_configuration_handler.cc
new file mode 100644
index 0000000..8fb6832
--- /dev/null
+++ b/chromeos/network/network_configuration_handler.cc
@@ -0,0 +1,221 @@
+// 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/network/network_configuration_handler.h"
+
+#include <string>
+#include <vector>
+
+#include "base/bind.h"
+#include "base/logging.h"
+#include "base/memory/ref_counted.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/values.h"
+#include "chromeos/dbus/dbus_method_call_status.h"
+#include "chromeos/dbus/dbus_thread_manager.h"
+#include "chromeos/dbus/shill_manager_client.h"
+#include "chromeos/dbus/shill_service_client.h"
+#include "dbus/object_path.h"
+
+namespace chromeos {
+
+namespace {
+
+// None of these error messages are user-facing: they should only appear in
+// logs.
+const char kErrorsListTag[] = "errors";
+const char kClearPropertiesFailedError[] = "Error.ClearPropertiesFailed";
+const char kClearPropertiesFailedErrorMessage[] = "Clear properties failed";
+const char kDBusFailedError[] = "Error.DBusFailed";
+const char kDBusFailedErrorMessage[] = "DBus call failed.";
+
+// These are names of fields in the error data returned through the error
+// callbacks.
+const char kErrorName[] = "errorName";
+const char kErrorMessage[] = "errorMessage";
+const char kServicePath[] = "servicePath";
+
+base::DictionaryValue* CreateErrorData(const std::string& service_path,
+ const std::string& error_name,
+ const std::string& error_message) {
+ scoped_ptr<base::DictionaryValue> error_data(new base::DictionaryValue);
+ error_data->SetString(kErrorName, error_name);
+ error_data->SetString(kErrorMessage, error_message);
+ if (!service_path.empty())
+ error_data->SetString(kServicePath, service_path);
+ LOG(ERROR) << "NetworkConfigurationHandler Received an error("
+ << error_name << ") for service path '" << service_path << "':"
+ << error_message;
+ return error_data.release();
+}
+
+void ClearPropertiesCallback(
+ const std::vector<std::string>& names,
+ const std::string& service_path,
+ const base::Closure& callback,
+ const NetworkHandlerErrorCallback& error_callback,
+ const base::ListValue& result) {
+ bool some_failed = false;
+ for (size_t i = 0; i < result.GetSize(); ++i) {
+ bool success;
+ if (result.GetBoolean(i, &success)) {
+ if (!success) {
+ some_failed = true;
+ break;
+ }
+ } else {
+ NOTREACHED() << "Result garbled from ClearProperties";
+ }
+ }
+
+ if (some_failed) {
+ DCHECK(names.size() == result.GetSize())
+ << "Result wrong size from ClearProperties.";
+ scoped_ptr<base::DictionaryValue> error_data(
+ CreateErrorData(service_path,
+ kClearPropertiesFailedError,
+ kClearPropertiesFailedErrorMessage));
+ error_data->Set("errors", result.DeepCopy());
+ scoped_ptr<base::ListValue> name_list(new base::ListValue);
+ name_list->AppendStrings(names);
+ error_data->Set("names", name_list.release());
+ error_callback.Run(kClearPropertiesFailedError, error_data.Pass());
+ } else {
+ callback.Run();
+ }
+}
+
+void ClearPropertiesErrorCallback(
+ const std::string& service_path,
+ const NetworkHandlerErrorCallback& error_callback,
+ const std::string& error_name,
+ const std::string& error_message) {
+ // Add a new error.
+ scoped_ptr<base::DictionaryValue> error_data(
+ CreateErrorData(service_path, error_name, error_message));
+ error_callback.Run(kClearPropertiesFailedError, error_data.Pass());
+}
+
+// Used to translate the dbus dictionary callback into one that calls
+// the error callback if we have a failure.
+void RunCallbackWithDictionaryValue(
+ const NetworkHandlerDictionaryResultCallback& callback,
+ const NetworkHandlerErrorCallback& error_callback,
+ const std::string& service_path,
+ DBusMethodCallStatus call_status,
+ const base::DictionaryValue& value) {
+ if (call_status != DBUS_METHOD_CALL_SUCCESS) {
+ scoped_ptr<base::DictionaryValue> error_data(
+ CreateErrorData(service_path,
+ kDBusFailedError,
+ kDBusFailedErrorMessage));
+ error_callback.Run(kDBusFailedError, error_data.Pass());
+ } else {
+ callback.Run(service_path, value);
+ }
+}
+
+void RunErrorCallback(const std::string& service_path,
+ const NetworkHandlerErrorCallback& error_callback,
+ const std::string& error_name,
+ const std::string& error_message) {
+ scoped_ptr<base::DictionaryValue> error_dict(
+ CreateErrorData(service_path, error_name, error_message));
+ error_callback.Run(error_name, error_dict.Pass());
+}
+
+void RunCreateNetworkCallback(
+ const NetworkHandlerStringResultCallback& callback,
+ const dbus::ObjectPath& service_path) {
+ callback.Run(service_path.value());
+}
+
+} // namespace
+
+NetworkConfigurationHandler::NetworkConfigurationHandler() {
+}
+
+NetworkConfigurationHandler::~NetworkConfigurationHandler() {
+}
+
+void NetworkConfigurationHandler::GetProperties(
+ const std::string& service_path,
+ const NetworkHandlerDictionaryResultCallback& callback,
+ const NetworkHandlerErrorCallback& error_callback) const {
+ DBusThreadManager::Get()->GetShillServiceClient()->GetProperties(
+ dbus::ObjectPath(service_path),
+ base::Bind(&RunCallbackWithDictionaryValue,
+ callback,
+ error_callback,
+ service_path));
+}
+
+void NetworkConfigurationHandler::SetProperties(
+ const std::string& service_path,
+ const base::DictionaryValue& properties,
+ const base::Closure& callback,
+ const NetworkHandlerErrorCallback& error_callback) const {
+ DBusThreadManager::Get()->GetShillManagerClient()->ConfigureService(
+ properties,
+ callback,
+ base::Bind(&RunErrorCallback, service_path, error_callback));
+}
+
+void NetworkConfigurationHandler::ClearProperties(
+ const std::string& service_path,
+ const std::vector<std::string>& names,
+ const base::Closure& callback,
+ const NetworkHandlerErrorCallback& error_callback) {
+ DBusThreadManager::Get()->GetShillServiceClient()->ClearProperties(
+ dbus::ObjectPath(service_path),
+ names,
+ base::Bind(&ClearPropertiesCallback,
+ names,
+ service_path,
+ callback,
+ error_callback),
+ base::Bind(&ClearPropertiesErrorCallback, service_path, error_callback));
+}
+
+void NetworkConfigurationHandler::Connect(
+ const std::string& service_path,
+ const base::Closure& callback,
+ const NetworkHandlerErrorCallback& error_callback) const {
+ DBusThreadManager::Get()->GetShillServiceClient()->Connect(
+ dbus::ObjectPath(service_path),
+ callback,
+ base::Bind(&RunErrorCallback, service_path, error_callback));
+}
+
+void NetworkConfigurationHandler::Disconnect(
+ const std::string& service_path,
+ const base::Closure& callback,
+ const NetworkHandlerErrorCallback& error_callback) const {
+ DBusThreadManager::Get()->GetShillServiceClient()->Disconnect(
+ dbus::ObjectPath(service_path),
+ callback,
+ base::Bind(&RunErrorCallback, service_path, error_callback));
+}
+
+void NetworkConfigurationHandler::CreateConfiguration(
+ const base::DictionaryValue& properties,
+ const NetworkHandlerStringResultCallback& callback,
+ const NetworkHandlerErrorCallback& error_callback) const {
+ DBusThreadManager::Get()->GetShillManagerClient()->GetService(
+ properties,
+ base::Bind(&RunCreateNetworkCallback, callback),
+ base::Bind(&RunErrorCallback, "", error_callback));
+}
+
+void NetworkConfigurationHandler::RemoveConfiguration(
+ const std::string& service_path,
+ const base::Closure& callback,
+ const NetworkHandlerErrorCallback& error_callback) const {
+ DBusThreadManager::Get()->GetShillServiceClient()->Remove(
+ dbus::ObjectPath(service_path),
+ callback,
+ base::Bind(&RunErrorCallback, service_path, error_callback));
+}
+
+} // namespace chromeos
diff --git a/chromeos/network/network_configuration_handler.h b/chromeos/network/network_configuration_handler.h
new file mode 100644
index 0000000..bac54c5
--- /dev/null
+++ b/chromeos/network/network_configuration_handler.h
@@ -0,0 +1,124 @@
+// 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_NETWORK_NETWORK_CONFIGURATION_HANDLER_H_
+#define CHROMEOS_NETWORK_NETWORK_CONFIGURATION_HANDLER_H_
+
+#include <string>
+#include <vector>
+
+#include "base/basictypes.h"
+#include "base/callback.h"
+#include "base/gtest_prod_util.h"
+#include "chromeos/chromeos_export.h"
+
+namespace base {
+class DictionaryValue;
+}
+
+namespace chromeos {
+
+// An error callback used by both the configuration handler and the state
+// handler to receive error results from the API.
+// TODO(gspencer): move to a common header.
+typedef base::Callback<
+ void(const std::string& error_name,
+ const scoped_ptr<base::DictionaryValue> error_data)>
+ NetworkHandlerErrorCallback;
+
+typedef base::Callback<
+ void(const std::string& service_path,
+ const base::DictionaryValue& dictionary)>
+ NetworkHandlerDictionaryResultCallback;
+
+typedef base::Callback<void(const std::string& service_path)>
+ NetworkHandlerStringResultCallback;
+
+// The NetworkConfigurationHandler class is used to create and configure
+// networks in ChromeOS. It mostly calls through to the Shill service API, and
+// most calls are asynchronous for that reason. No calls will block on DBus
+// calls.
+//
+// This is owned and it's lifetime managed by aura::Shell.
+//
+// For accessing lists of remembered networks, and other state information, see
+// the class NetworkStateHandler.
+//
+// Note on callbacks: Because all the functions here are meant to be
+// asynchronous, they all take a |callback| of some type, and an
+// |error_callback|. When the operation succeeds, |callback| will be called, and
+// when it doesn't, |error_callback| will be called with information about the
+// error, including a symbolic name for the error and often some error message
+// that is suitable for logging. None of the error message text is meant for
+// user consumption.
+
+class CHROMEOS_EXPORT NetworkConfigurationHandler {
+ public:
+ NetworkConfigurationHandler();
+ ~NetworkConfigurationHandler();
+
+ // Gets the properties of the network with id |service_path|. See note on
+ // |callback| and |error_callback|, in class description above.
+ void GetProperties(const std::string& service_path,
+ const NetworkHandlerDictionaryResultCallback& callback,
+ const NetworkHandlerErrorCallback& error_callback) const;
+
+ // Sets the properties of the network with id |service_path|. This means the
+ // given properties will be merged with the existing settings, and it won't
+ // clear any existing properties. See note on |callback| and |error_callback|,
+ // in class description above.
+ void SetProperties(const std::string& service_path,
+ const base::DictionaryValue& properties,
+ const base::Closure& callback,
+ const NetworkHandlerErrorCallback& error_callback) const;
+
+ // Removes the properties with the given property paths. If any of them are
+ // unable to be cleared, the |error_callback| will only be run once with
+ // accumulated information about all of the errors as a list attached to the
+ // "errors" key of the error data, and the |callback| will not be run, even
+ // though some of the properties may have been cleared. If there are no
+ // errors, |callback| will be run.
+ void ClearProperties(const std::string& service_path,
+ const std::vector<std::string>& property_paths,
+ const base::Closure& callback,
+ const NetworkHandlerErrorCallback& error_callback);
+
+ // Initiates a connection with network that has id |service_path|. See note on
+ // |callback| and |error_callback|, in class description above.
+ void Connect(const std::string& service_path,
+ const base::Closure& callback,
+ const NetworkHandlerErrorCallback& error_callback) const;
+
+ // Initiates a disconnect with the network at |service_path|. See note on
+ // |callback| and |error_callback|, in class description above.
+ void Disconnect(const std::string& service_path,
+ const base::Closure& callback,
+ const NetworkHandlerErrorCallback& error_callback) const;
+
+
+ // Creates a network with the given properties in the active Shill profile,
+ // and returns the properties to |callback| if successful, along with the new
+ // service_path. See note on |callback| and |error_callback|, in class
+ // description above.
+ void CreateConfiguration(
+ const base::DictionaryValue& properties,
+ const NetworkHandlerStringResultCallback& callback,
+ const NetworkHandlerErrorCallback& error_callback) const;
+
+ // Removes the network |service_path| from the remembered network list in the
+ // active Shill profile. The network may still show up in the visible networks
+ // after this, but no profile configuration will remain. See note on
+ // |callback| and |error_callback|, in class description above.
+ void RemoveConfiguration(
+ const std::string& service_path,
+ const base::Closure& callback,
+ const NetworkHandlerErrorCallback& error_callback) const;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(NetworkConfigurationHandler);
+};
+
+} // namespace chromeos
+
+#endif // CHROMEOS_NETWORK_NETWORK_CONFIGURATION_HANDLER_H_
diff --git a/chromeos/network/network_configuration_handler_unittest.cc b/chromeos/network/network_configuration_handler_unittest.cc
new file mode 100644
index 0000000..4727cea
--- /dev/null
+++ b/chromeos/network/network_configuration_handler_unittest.cc
@@ -0,0 +1,364 @@
+// 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/json/json_writer.h"
+#include "base/message_loop.h"
+#include "base/string_piece.h"
+#include "base/values.h"
+#include "chromeos/dbus/dbus_thread_manager.h"
+#include "chromeos/dbus/mock_dbus_thread_manager.h"
+#include "chromeos/dbus/mock_shill_manager_client.h"
+#include "chromeos/dbus/mock_shill_service_client.h"
+#include "chromeos/network/network_configuration_handler.h"
+#include "testing/gmock/include/gmock/gmock.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+using ::testing::_;
+using ::testing::Invoke;
+using ::testing::Pointee;
+using ::testing::Return;
+using ::testing::SaveArg;
+using ::testing::StrEq;
+
+// Matcher to match base::Value.
+MATCHER_P(IsEqualTo, value, "") { return arg.Equals(value); }
+
+namespace chromeos {
+
+namespace {
+
+static std::string PrettyJson(const base::DictionaryValue& value) {
+ std::string pretty;
+ base::JSONWriter::WriteWithOptions(&value,
+ base::JSONWriter::OPTIONS_PRETTY_PRINT,
+ &pretty);
+ return pretty;
+}
+
+void DictionaryValueCallback(
+ const std::string& expected_id,
+ const std::string& expected_json,
+ const std::string& service_path,
+ const base::DictionaryValue& dictionary) {
+ std::string dict_str = PrettyJson(dictionary);
+ EXPECT_EQ(expected_json, dict_str);
+ EXPECT_EQ(expected_id, service_path);
+}
+
+void ErrorCallback(bool error_expected,
+ const std::string& expected_id,
+ const std::string& error_name,
+ const scoped_ptr<base::DictionaryValue> error_data) {
+ EXPECT_TRUE(error_expected) << "Unexpected error: " << error_name
+ << " with associated data: \n"
+ << PrettyJson(*error_data);
+}
+
+void StringResultCallback(const std::string& expected_result,
+ const std::string& result) {
+ EXPECT_EQ(expected_result, result);
+}
+
+void DBusErrorCallback(const std::string& error_name,
+ const std::string& error_message) {
+ EXPECT_TRUE(false) << "DBus Error: " << error_name << "("
+ << error_message << ")";
+}
+
+} // namespace
+
+class NetworkConfigurationHandlerTest : public testing::Test {
+ public:
+ NetworkConfigurationHandlerTest()
+ : mock_manager_client_(NULL),
+ mock_service_client_(NULL),
+ dictionary_value_result_(NULL) {}
+ virtual ~NetworkConfigurationHandlerTest() {}
+
+ virtual void SetUp() OVERRIDE {
+ MockDBusThreadManager* mock_dbus_thread_manager = new MockDBusThreadManager;
+ EXPECT_CALL(*mock_dbus_thread_manager, GetSystemBus())
+ .WillRepeatedly(Return(reinterpret_cast<dbus::Bus*>(NULL)));
+ DBusThreadManager::InitializeForTesting(mock_dbus_thread_manager);
+ mock_manager_client_ =
+ mock_dbus_thread_manager->mock_shill_manager_client();
+ mock_service_client_ =
+ mock_dbus_thread_manager->mock_shill_service_client();
+
+ // Initialize DBusThreadManager with a stub implementation.
+ configuration_handler_.reset(new NetworkConfigurationHandler);
+ message_loop_.RunUntilIdle();
+ }
+
+ virtual void TearDown() OVERRIDE {
+ configuration_handler_.reset();
+ DBusThreadManager::Shutdown();
+ }
+
+ // Handles responses for GetProperties method calls.
+ void OnGetProperties(
+ const dbus::ObjectPath& path,
+ const ShillClientHelper::DictionaryValueCallback& callback) {
+ callback.Run(DBUS_METHOD_CALL_SUCCESS, *dictionary_value_result_);
+ }
+
+ // Handles responses for SetProperties method calls.
+ void OnSetProperties(const base::DictionaryValue& properties,
+ const base::Closure& callback,
+ const ShillClientHelper::ErrorCallback& error_callback) {
+ callback.Run();
+ }
+
+ // Handles responses for ClearProperties method calls.
+ void OnClearProperties(
+ const dbus::ObjectPath& service_path,
+ const std::vector<std::string>& names,
+ const ShillClientHelper::ListValueCallback& callback,
+ const ShillClientHelper::ErrorCallback& error_callback) {
+ base::ListValue result;
+ result.AppendBoolean(true);
+ callback.Run(result);
+ }
+
+ // Handles responses for ClearProperties method calls, and simulates an error
+ // result.
+ void OnClearPropertiesError(
+ const dbus::ObjectPath& service_path,
+ const std::vector<std::string>& names,
+ const ShillClientHelper::ListValueCallback& callback,
+ const ShillClientHelper::ErrorCallback& error_callback) {
+ base::ListValue result;
+ result.AppendBoolean(false);
+ callback.Run(result);
+ }
+
+ void OnConnect(const dbus::ObjectPath& service_path,
+ const base::Closure& callback,
+ const ShillClientHelper::ErrorCallback& error_callback) {
+ callback.Run();
+ }
+
+ void OnDisconnect(const dbus::ObjectPath& service_path,
+ const base::Closure& callback,
+ const ShillClientHelper::ErrorCallback& error_callback) {
+ callback.Run();
+ }
+
+ void OnGetService(const base::DictionaryValue& properties,
+ const ObjectPathCallback& callback,
+ const ShillClientHelper::ErrorCallback& error_callback) {
+ callback.Run(dbus::ObjectPath("/service/2"));
+ }
+
+ void OnRemove(const dbus::ObjectPath& service_path,
+ const base::Closure& callback,
+ const ShillClientHelper::ErrorCallback& error_callback) {
+ callback.Run();
+ }
+
+ protected:
+ scoped_ptr<NetworkConfigurationHandler> configuration_handler_;
+ MockShillManagerClient* mock_manager_client_;
+ MockShillServiceClient* mock_service_client_;
+ MessageLoop message_loop_;
+ base::DictionaryValue* dictionary_value_result_;
+};
+
+TEST_F(NetworkConfigurationHandlerTest, GetProperties) {
+ std::string service_path = "/service/1";
+ std::string expected_json = "{\n \"SSID\": \"MyNetwork\"\n}\n";
+ std::string networkName = "MyNetwork";
+ std::string key = "SSID";
+ scoped_ptr<base::StringValue> networkNameValue(
+ base::Value::CreateStringValue(networkName));
+
+ base::DictionaryValue value;
+ value.Set(key, base::Value::CreateStringValue(networkName));
+ dictionary_value_result_ = &value;
+ EXPECT_CALL(*mock_service_client_,
+ SetProperty(dbus::ObjectPath(service_path), key,
+ IsEqualTo(networkNameValue.get()), _, _)).Times(1);
+ DBusThreadManager::Get()->GetShillServiceClient()->SetProperty(
+ dbus::ObjectPath(service_path), key, *networkNameValue,
+ base::Bind(&base::DoNothing),
+ base::Bind(&DBusErrorCallback));
+ message_loop_.RunUntilIdle();
+
+ ShillServiceClient::DictionaryValueCallback get_properties_callback;
+ EXPECT_CALL(*mock_service_client_,
+ GetProperties(_, _)).WillOnce(
+ Invoke(this,
+ &NetworkConfigurationHandlerTest::OnGetProperties));
+ configuration_handler_->GetProperties(
+ service_path,
+ base::Bind(&DictionaryValueCallback,
+ service_path,
+ expected_json),
+ base::Bind(&ErrorCallback, false, service_path));
+ message_loop_.RunUntilIdle();
+}
+
+TEST_F(NetworkConfigurationHandlerTest, SetProperties) {
+ std::string service_path = "/service/1";
+ std::string networkName = "MyNetwork";
+ std::string key = "SSID";
+ scoped_ptr<base::StringValue> networkNameValue(
+ base::Value::CreateStringValue(networkName));
+
+ base::DictionaryValue value;
+ value.Set(key, base::Value::CreateStringValue(networkName));
+ dictionary_value_result_ = &value;
+ EXPECT_CALL(*mock_manager_client_,
+ ConfigureService(_, _, _)).WillOnce(
+ Invoke(this,
+ &NetworkConfigurationHandlerTest::OnSetProperties));
+ configuration_handler_->SetProperties(
+ service_path,
+ value,
+ base::Bind(&base::DoNothing),
+ base::Bind(&ErrorCallback, false, service_path));
+ message_loop_.RunUntilIdle();
+}
+
+TEST_F(NetworkConfigurationHandlerTest, ClearProperties) {
+ std::string service_path = "/service/1";
+ std::string networkName = "MyNetwork";
+ std::string key = "SSID";
+ scoped_ptr<base::StringValue> networkNameValue(
+ base::Value::CreateStringValue(networkName));
+
+ // First set up a value to clear.
+ base::DictionaryValue value;
+ value.Set(key, base::Value::CreateStringValue(networkName));
+ dictionary_value_result_ = &value;
+ EXPECT_CALL(*mock_manager_client_,
+ ConfigureService(_, _, _)).WillOnce(
+ Invoke(this,
+ &NetworkConfigurationHandlerTest::OnSetProperties));
+ configuration_handler_->SetProperties(
+ service_path,
+ value,
+ base::Bind(&base::DoNothing),
+ base::Bind(&ErrorCallback, false, service_path));
+ message_loop_.RunUntilIdle();
+
+ // Now clear it.
+ std::vector<std::string> values_to_clear;
+ values_to_clear.push_back(key);
+ EXPECT_CALL(*mock_service_client_,
+ ClearProperties(_, _, _, _)).WillOnce(
+ Invoke(this,
+ &NetworkConfigurationHandlerTest::OnClearProperties));
+ configuration_handler_->ClearProperties(
+ service_path,
+ values_to_clear,
+ base::Bind(&base::DoNothing),
+ base::Bind(&ErrorCallback, false, service_path));
+ message_loop_.RunUntilIdle();
+}
+
+TEST_F(NetworkConfigurationHandlerTest, ClearPropertiesError) {
+ std::string service_path = "/service/1";
+ std::string networkName = "MyNetwork";
+ std::string key = "SSID";
+ scoped_ptr<base::StringValue> networkNameValue(
+ base::Value::CreateStringValue(networkName));
+
+ // First set up a value to clear.
+ base::DictionaryValue value;
+ value.Set(key, base::Value::CreateStringValue(networkName));
+ dictionary_value_result_ = &value;
+ EXPECT_CALL(*mock_manager_client_,
+ ConfigureService(_, _, _)).WillOnce(
+ Invoke(this,
+ &NetworkConfigurationHandlerTest::OnSetProperties));
+ configuration_handler_->SetProperties(
+ service_path,
+ value,
+ base::Bind(&base::DoNothing),
+ base::Bind(&ErrorCallback, false, service_path));
+ message_loop_.RunUntilIdle();
+
+ // Now clear it.
+ std::vector<std::string> values_to_clear;
+ values_to_clear.push_back(key);
+ EXPECT_CALL(
+ *mock_service_client_,
+ ClearProperties(_, _, _, _)).WillOnce(
+ Invoke(this,
+ &NetworkConfigurationHandlerTest::OnClearPropertiesError));
+ configuration_handler_->ClearProperties(
+ service_path,
+ values_to_clear,
+ base::Bind(&base::DoNothing),
+ base::Bind(&ErrorCallback, true, service_path));
+ message_loop_.RunUntilIdle();
+}
+
+TEST_F(NetworkConfigurationHandlerTest, Connect) {
+ std::string service_path = "/service/1";
+
+ EXPECT_CALL(*mock_service_client_,
+ Connect(_, _, _)).WillOnce(
+ Invoke(this,
+ &NetworkConfigurationHandlerTest::OnConnect));
+ configuration_handler_->Connect(
+ service_path,
+ base::Bind(&base::DoNothing),
+ base::Bind(&ErrorCallback, false, service_path));
+ message_loop_.RunUntilIdle();
+}
+
+TEST_F(NetworkConfigurationHandlerTest, Disconnect) {
+ std::string service_path = "/service/1";
+
+ EXPECT_CALL(*mock_service_client_,
+ Disconnect(_, _, _)).WillOnce(
+ Invoke(this,
+ &NetworkConfigurationHandlerTest::OnDisconnect));
+ configuration_handler_->Disconnect(
+ service_path,
+ base::Bind(&base::DoNothing),
+ base::Bind(&ErrorCallback, false, service_path));
+ message_loop_.RunUntilIdle();
+}
+
+TEST_F(NetworkConfigurationHandlerTest, CreateConfiguration) {
+ std::string expected_json = "{\n \"SSID\": \"MyNetwork\"\n}\n";
+ std::string networkName = "MyNetwork";
+ std::string key = "SSID";
+ scoped_ptr<base::StringValue> networkNameValue(
+ base::Value::CreateStringValue(networkName));
+ base::DictionaryValue value;
+ value.Set(key, base::Value::CreateStringValue(networkName));
+
+ EXPECT_CALL(
+ *mock_manager_client_,
+ GetService(_, _, _)).WillOnce(
+ Invoke(this,
+ &NetworkConfigurationHandlerTest::OnGetService));
+ configuration_handler_->CreateConfiguration(
+ value,
+ base::Bind(&StringResultCallback, std::string("/service/2")),
+ base::Bind(&ErrorCallback, false, std::string("")));
+ message_loop_.RunUntilIdle();
+}
+
+TEST_F(NetworkConfigurationHandlerTest, RemoveConfiguration) {
+ std::string service_path = "/service/1";
+
+ EXPECT_CALL(
+ *mock_service_client_,
+ Remove(_, _, _)).WillOnce(
+ Invoke(this,
+ &NetworkConfigurationHandlerTest::OnRemove));
+ configuration_handler_->RemoveConfiguration(
+ service_path,
+ base::Bind(&base::DoNothing),
+ base::Bind(&ErrorCallback, false, service_path));
+ message_loop_.RunUntilIdle();
+}
+
+} // namespace chromeos