summaryrefslogtreecommitdiffstats
path: root/chromeos
diff options
context:
space:
mode:
authorstevenjb@chromium.org <stevenjb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-02-15 03:48:51 +0000
committerstevenjb@chromium.org <stevenjb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-02-15 03:48:51 +0000
commitabb833ee12957986bb4c9a82ae639cae2ee8dd26 (patch)
treeb6bea97ef0a509dabea7555d964649670b25f254 /chromeos
parent1953e60788f6435720eab65709d4d44753993d3d (diff)
downloadchromium_src-abb833ee12957986bb4c9a82ae639cae2ee8dd26.zip
chromium_src-abb833ee12957986bb4c9a82ae639cae2ee8dd26.tar.gz
chromium_src-abb833ee12957986bb4c9a82ae639cae2ee8dd26.tar.bz2
Implement networkingPrivate.setWifiTDLSEnabledState
BUG=329738 Review URL: https://codereview.chromium.org/156353002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@251501 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chromeos')
-rw-r--r--chromeos/dbus/fake_shill_device_client.cc34
-rw-r--r--chromeos/dbus/fake_shill_device_client.h11
-rw-r--r--chromeos/dbus/fake_shill_manager_client.cc10
-rw-r--r--chromeos/dbus/shill_device_client.cc15
-rw-r--r--chromeos/dbus/shill_device_client.h13
-rw-r--r--chromeos/network/fake_network_device_handler.cc11
-rw-r--r--chromeos/network/fake_network_device_handler.h11
-rw-r--r--chromeos/network/network_device_handler.cc2
-rw-r--r--chromeos/network/network_device_handler.h17
-rw-r--r--chromeos/network/network_device_handler_impl.cc160
-rw-r--r--chromeos/network/network_device_handler_impl.h13
-rw-r--r--chromeos/network/network_device_handler_unittest.cc98
12 files changed, 372 insertions, 23 deletions
diff --git a/chromeos/dbus/fake_shill_device_client.cc b/chromeos/dbus/fake_shill_device_client.cc
index ca6e027..9f987bb 100644
--- a/chromeos/dbus/fake_shill_device_client.cc
+++ b/chromeos/dbus/fake_shill_device_client.cc
@@ -32,15 +32,17 @@ void ErrorFunction(const std::string& device_path,
void PostDeviceNotFoundError(
const ShillDeviceClient::ErrorCallback& error_callback) {
- std::string error_name("org.chromium.flimflam.Error.Failure");
std::string error_message("Failed");
base::MessageLoop::current()->PostTask(
- FROM_HERE, base::Bind(error_callback, error_name, error_message));
+ FROM_HERE,
+ base::Bind(error_callback, shill::kErrorResultNotFound, error_message));
}
} // namespace
-FakeShillDeviceClient::FakeShillDeviceClient() : weak_ptr_factory_(this) {
+FakeShillDeviceClient::FakeShillDeviceClient()
+ : tdls_busy_count_(0),
+ weak_ptr_factory_(this) {
}
FakeShillDeviceClient::~FakeShillDeviceClient() {
@@ -202,6 +204,32 @@ void FakeShillDeviceClient::Reset(const dbus::ObjectPath& device_path,
base::MessageLoop::current()->PostTask(FROM_HERE, callback);
}
+void FakeShillDeviceClient::PerformTDLSOperation(
+ const dbus::ObjectPath& device_path,
+ const std::string& operation,
+ const std::string& peer,
+ const StringCallback& callback,
+ const ErrorCallback& error_callback) {
+ if (!stub_devices_.HasKey(device_path.value())) {
+ PostDeviceNotFoundError(error_callback);
+ return;
+ }
+ if (tdls_busy_count_) {
+ --tdls_busy_count_;
+ std::string error_message("In-Progress");
+ base::MessageLoop::current()->PostTask(
+ FROM_HERE,
+ base::Bind(error_callback,
+ shill::kErrorResultInProgress, error_message));
+ return;
+ }
+ std::string result;
+ if (operation == shill::kTDLSStatusOperation)
+ result = shill::kTDLSConnectedState;
+ base::MessageLoop::current()->PostTask(FROM_HERE,
+ base::Bind(callback, result));
+}
+
ShillDeviceClient::TestInterface* FakeShillDeviceClient::GetTestInterface() {
return this;
}
diff --git a/chromeos/dbus/fake_shill_device_client.h b/chromeos/dbus/fake_shill_device_client.h
index cb5b859..ac8f565 100644
--- a/chromeos/dbus/fake_shill_device_client.h
+++ b/chromeos/dbus/fake_shill_device_client.h
@@ -76,6 +76,13 @@ class CHROMEOS_EXPORT FakeShillDeviceClient
virtual void Reset(const dbus::ObjectPath& device_path,
const base::Closure& callback,
const ErrorCallback& error_callback) OVERRIDE;
+ virtual void PerformTDLSOperation(
+ const dbus::ObjectPath& device_path,
+ const std::string& operation,
+ const std::string& peer,
+ const StringCallback& callback,
+ const ErrorCallback& error_callback) OVERRIDE;
+
virtual ShillDeviceClient::TestInterface* GetTestInterface() OVERRIDE;
// ShillDeviceClient::TestInterface overrides.
@@ -89,6 +96,8 @@ class CHROMEOS_EXPORT FakeShillDeviceClient
const base::Value& value) OVERRIDE;
virtual std::string GetDevicePathForType(const std::string& type) OVERRIDE;
+ void set_tdls_busy_count(int count) { tdls_busy_count_ = count; }
+
private:
typedef ObserverList<ShillPropertyChangedObserver> PropertyObserverList;
@@ -110,6 +119,8 @@ class CHROMEOS_EXPORT FakeShillDeviceClient
// Observer list for each device.
std::map<dbus::ObjectPath, PropertyObserverList*> observer_list_;
+ int tdls_busy_count_; // Number of times to return InProgress for TDLS.
+
// Note: This should remain the last member so it'll be destroyed and
// invalidate its weak pointers before any other members are destroyed.
base::WeakPtrFactory<FakeShillDeviceClient> weak_ptr_factory_;
diff --git a/chromeos/dbus/fake_shill_manager_client.cc b/chromeos/dbus/fake_shill_manager_client.cc
index 95486b5..d3ad566 100644
--- a/chromeos/dbus/fake_shill_manager_client.cc
+++ b/chromeos/dbus/fake_shill_manager_client.cc
@@ -536,6 +536,16 @@ void FakeShillManagerClient::NotifyObserversPropertyChanged(
OnPropertyChanged(property, *(services.get())));
return;
}
+ if (property == shill::kDevicesProperty) {
+ base::ListValue* devices = NULL;
+ if (stub_properties_.GetListWithoutPathExpansion(
+ shill::kDevicesProperty, &devices)) {
+ FOR_EACH_OBSERVER(ShillPropertyChangedObserver,
+ observer_list_,
+ OnPropertyChanged(property, *devices));
+ }
+ return;
+ }
base::Value* value = NULL;
if (!stub_properties_.GetWithoutPathExpansion(property, &value)) {
LOG(ERROR) << "Notify for unknown property: " << property;
diff --git a/chromeos/dbus/shill_device_client.cc b/chromeos/dbus/shill_device_client.cc
index 94934b4..40946ef 100644
--- a/chromeos/dbus/shill_device_client.cc
+++ b/chromeos/dbus/shill_device_client.cc
@@ -191,6 +191,21 @@ class ShillDeviceClientImpl : public ShillDeviceClient {
&method_call, callback, error_callback);
}
+ virtual void PerformTDLSOperation(
+ const dbus::ObjectPath& device_path,
+ const std::string& operation,
+ const std::string& peer,
+ const StringCallback& callback,
+ const ErrorCallback& error_callback) OVERRIDE {
+ dbus::MethodCall method_call(shill::kFlimflamDeviceInterface,
+ shill::kPerformTDLSOperationFunction);
+ dbus::MessageWriter writer(&method_call);
+ writer.AppendString(operation);
+ writer.AppendString(peer);
+ GetHelper(device_path)->CallStringMethodWithErrorCallback(
+ &method_call, callback, error_callback);
+ }
+
virtual TestInterface* GetTestInterface() OVERRIDE {
return NULL;
}
diff --git a/chromeos/dbus/shill_device_client.h b/chromeos/dbus/shill_device_client.h
index 92e1762..afee457 100644
--- a/chromeos/dbus/shill_device_client.h
+++ b/chromeos/dbus/shill_device_client.h
@@ -37,6 +37,7 @@ class CHROMEOS_EXPORT ShillDeviceClient : public DBusClient {
public:
typedef ShillClientHelper::PropertyChangedHandler PropertyChangedHandler;
typedef ShillClientHelper::DictionaryValueCallback DictionaryValueCallback;
+ typedef ShillClientHelper::StringCallback StringCallback;
typedef ShillClientHelper::ErrorCallback ErrorCallback;
// Interface for setting up devices for testing.
@@ -151,8 +152,16 @@ class CHROMEOS_EXPORT ShillDeviceClient : public DBusClient {
// Calls the Reset method.
// |callback| is called after the method call finishes.
virtual void Reset(const dbus::ObjectPath& device_path,
- const base::Closure& callback,
- const ErrorCallback& error_callback) = 0;
+ const base::Closure& callback,
+ const ErrorCallback& error_callback) = 0;
+
+ // Calls the PerformTDLSOperation method.
+ // |callback| is called after the method call finishes.
+ virtual void PerformTDLSOperation(const dbus::ObjectPath& device_path,
+ const std::string& operation,
+ const std::string& peer,
+ const StringCallback& callback,
+ const ErrorCallback& error_callback) = 0;
// Returns an interface for testing (stub only), or returns NULL.
virtual TestInterface* GetTestInterface() = 0;
diff --git a/chromeos/network/fake_network_device_handler.cc b/chromeos/network/fake_network_device_handler.cc
index dd737ac..bd6df3c 100644
--- a/chromeos/network/fake_network_device_handler.cc
+++ b/chromeos/network/fake_network_device_handler.cc
@@ -73,4 +73,15 @@ void FakeNetworkDeviceHandler::ChangePin(
void FakeNetworkDeviceHandler::SetCellularAllowRoaming(bool allow_roaming) {}
+void FakeNetworkDeviceHandler::SetWifiTDLSEnabled(
+ const std::string& ip_or_mac_address,
+ bool enabled,
+ const network_handler::StringResultCallback& callback,
+ const network_handler::ErrorCallback& error_callback) {}
+
+void FakeNetworkDeviceHandler::GetWifiTDLSStatus(
+ const std::string& ip_or_mac_address,
+ const network_handler::StringResultCallback& callback,
+ const network_handler::ErrorCallback& error_callback) {}
+
} // namespace chromeos
diff --git a/chromeos/network/fake_network_device_handler.h b/chromeos/network/fake_network_device_handler.h
index f3bf145..ea0d143 100644
--- a/chromeos/network/fake_network_device_handler.h
+++ b/chromeos/network/fake_network_device_handler.h
@@ -83,6 +83,17 @@ class CHROMEOS_EXPORT FakeNetworkDeviceHandler : public NetworkDeviceHandler {
virtual void SetCellularAllowRoaming(bool allow_roaming) OVERRIDE;
+ virtual void SetWifiTDLSEnabled(
+ const std::string& ip_or_mac_address,
+ bool enabled,
+ const network_handler::StringResultCallback& callback,
+ const network_handler::ErrorCallback& error_callback) OVERRIDE;
+
+ virtual void GetWifiTDLSStatus(
+ const std::string& ip_or_mac_address,
+ const network_handler::StringResultCallback& callback,
+ const network_handler::ErrorCallback& error_callback) OVERRIDE;
+
private:
DISALLOW_COPY_AND_ASSIGN(FakeNetworkDeviceHandler);
};
diff --git a/chromeos/network/network_device_handler.cc b/chromeos/network/network_device_handler.cc
index 813cf661..0aaadfe 100644
--- a/chromeos/network/network_device_handler.cc
+++ b/chromeos/network/network_device_handler.cc
@@ -6,11 +6,13 @@
namespace chromeos {
+const char NetworkDeviceHandler::kErrorDeviceMissing[] = "device-missing";
const char NetworkDeviceHandler::kErrorFailure[] = "failure";
const char NetworkDeviceHandler::kErrorIncorrectPin[] = "incorrect-pin";
const char NetworkDeviceHandler::kErrorNotSupported[] = "not-supported";
const char NetworkDeviceHandler::kErrorPinBlocked[] = "pin-blocked";
const char NetworkDeviceHandler::kErrorPinRequired[] = "pin-required";
+const char NetworkDeviceHandler::kErrorTimeout[] = "timeout";
const char NetworkDeviceHandler::kErrorUnknown[] = "unknown";
NetworkDeviceHandler::NetworkDeviceHandler() {
diff --git a/chromeos/network/network_device_handler.h b/chromeos/network/network_device_handler.h
index 9b69399..c1333a3 100644
--- a/chromeos/network/network_device_handler.h
+++ b/chromeos/network/network_device_handler.h
@@ -33,12 +33,14 @@ namespace chromeos {
class CHROMEOS_EXPORT NetworkDeviceHandler {
public:
// Constants for |error_name| from |error_callback|.
+ static const char kErrorDeviceMissing[];
static const char kErrorFailure[];
static const char kErrorIncorrectPin[];
static const char kErrorNotFound[];
static const char kErrorNotSupported[];
static const char kErrorPinBlocked[];
static const char kErrorPinRequired[];
+ static const char kErrorTimeout[];
static const char kErrorUnknown[];
NetworkDeviceHandler();
@@ -192,6 +194,21 @@ class CHROMEOS_EXPORT NetworkDeviceHandler {
// available in the future.
virtual void SetCellularAllowRoaming(bool allow_roaming) = 0;
+ // Attempts to enable or disable TDLS for the specified IP or MAC address for
+ // the active wifi device.
+ virtual void SetWifiTDLSEnabled(
+ const std::string& ip_or_mac_address,
+ bool enabled,
+ const network_handler::StringResultCallback& callback,
+ const network_handler::ErrorCallback& error_callback) = 0;
+
+ // Returns the TDLS status for the specified IP or MAC address for
+ // the active wifi device.
+ virtual void GetWifiTDLSStatus(
+ const std::string& ip_or_mac_address,
+ const network_handler::StringResultCallback& callback,
+ const network_handler::ErrorCallback& error_callback) = 0;
+
private:
DISALLOW_COPY_AND_ASSIGN(NetworkDeviceHandler);
};
diff --git a/chromeos/network/network_device_handler_impl.cc b/chromeos/network/network_device_handler_impl.cc
index 6728546..ce0d787 100644
--- a/chromeos/network/network_device_handler_impl.cc
+++ b/chromeos/network/network_device_handler_impl.cc
@@ -6,6 +6,8 @@
#include "base/bind.h"
#include "base/location.h"
+#include "base/message_loop/message_loop_proxy.h"
+#include "base/time/time.h"
#include "base/values.h"
#include "chromeos/dbus/dbus_thread_manager.h"
#include "chromeos/dbus/shill_device_client.h"
@@ -33,6 +35,8 @@ std::string GetErrorNameForShillError(const std::string& shill_error_name) {
return NetworkDeviceHandler::kErrorPinBlocked;
if (shill_error_name == shill::kErrorResultPinRequired)
return NetworkDeviceHandler::kErrorPinRequired;
+ if (shill_error_name == shill::kErrorResultNotFound)
+ return NetworkDeviceHandler::kErrorDeviceMissing;
return NetworkDeviceHandler::kErrorUnknown;
}
@@ -134,6 +138,118 @@ void SetDevicePropertyInternal(
base::Bind(&HandleShillCallFailure, device_path, error_callback));
}
+// Struct containing TDLS Operation parameters.
+struct TDLSOperationParams {
+ TDLSOperationParams() : retry_count(0) {}
+ std::string operation;
+ std::string ip_or_mac_address;
+ int retry_count;
+};
+
+// Forward declare for PostDelayedTask.
+void CallPerformTDLSOperation(
+ const std::string& device_path,
+ const TDLSOperationParams& params,
+ const network_handler::StringResultCallback& callback,
+ const network_handler::ErrorCallback& error_callback);
+
+void TDLSSuccessCallback(
+ const std::string& device_path,
+ const TDLSOperationParams& params,
+ const network_handler::StringResultCallback& callback,
+ const network_handler::ErrorCallback& error_callback,
+ const std::string& result) {
+ std::string event_desc = "TDLSSuccessCallback: " + params.operation;
+ if (!result.empty())
+ event_desc += ": " + result;
+ NET_LOG_EVENT(event_desc, device_path);
+ if (params.operation != shill::kTDLSSetupOperation) {
+ if (!callback.is_null())
+ callback.Run(result);
+ return;
+ }
+
+ if (!result.empty())
+ NET_LOG_ERROR("Unexpected TDLS result: " + result, device_path);
+
+ // Send a delayed Status request after a successful Setup call.
+ TDLSOperationParams status_params;
+ status_params.operation = shill::kTDLSStatusOperation;
+ status_params.ip_or_mac_address = params.ip_or_mac_address;
+
+ const int64 kRequestStatusDelayMs = 500;
+ base::TimeDelta request_delay;
+ if (!DBusThreadManager::Get()->GetShillDeviceClient()->GetTestInterface())
+ request_delay = base::TimeDelta::FromMilliseconds(kRequestStatusDelayMs);
+
+ base::MessageLoopProxy::current()->PostDelayedTask(
+ FROM_HERE,
+ base::Bind(&CallPerformTDLSOperation,
+ device_path, status_params, callback, error_callback),
+ request_delay);
+}
+
+void TDLSErrorCallback(
+ const std::string& device_path,
+ const TDLSOperationParams& params,
+ const network_handler::StringResultCallback& callback,
+ const network_handler::ErrorCallback& error_callback,
+ const std::string& dbus_error_name,
+ const std::string& dbus_error_message) {
+ // If a Setup operation receives an InProgress error, retry.
+ const int kMaxRetries = 5;
+ if (params.operation == shill::kTDLSSetupOperation &&
+ dbus_error_name == shill::kErrorResultInProgress &&
+ params.retry_count < kMaxRetries) {
+ TDLSOperationParams retry_params = params;
+ ++retry_params.retry_count;
+ NET_LOG_EVENT(base::StringPrintf("TDLS Retry: %d", params.retry_count),
+ device_path);
+ const int64 kReRequestDelayMs = 1000;
+ base::TimeDelta request_delay;
+ if (!DBusThreadManager::Get()->GetShillDeviceClient()->GetTestInterface())
+ request_delay = base::TimeDelta::FromMilliseconds(kReRequestDelayMs);
+
+ base::MessageLoopProxy::current()->PostDelayedTask(
+ FROM_HERE,
+ base::Bind(&CallPerformTDLSOperation,
+ device_path, retry_params, callback, error_callback),
+ request_delay);
+ return;
+ }
+
+ NET_LOG_ERROR("TDLS Error:" + dbus_error_name + ":" + dbus_error_message,
+ device_path);
+ if (error_callback.is_null())
+ return;
+
+ const std::string error_name =
+ dbus_error_name == shill::kErrorResultInProgress ?
+ NetworkDeviceHandler::kErrorTimeout : NetworkDeviceHandler::kErrorUnknown;
+ const std::string& error_detail = params.ip_or_mac_address;
+ scoped_ptr<base::DictionaryValue> error_data(
+ network_handler::CreateDBusErrorData(
+ device_path, error_name, error_detail,
+ dbus_error_name, dbus_error_message));
+ error_callback.Run(error_name, error_data.Pass());
+}
+
+void CallPerformTDLSOperation(
+ const std::string& device_path,
+ const TDLSOperationParams& params,
+ const network_handler::StringResultCallback& callback,
+ const network_handler::ErrorCallback& error_callback) {
+ NET_LOG_EVENT("CallPerformTDLSOperation: " + params.operation, device_path);
+ DBusThreadManager::Get()->GetShillDeviceClient()->PerformTDLSOperation(
+ dbus::ObjectPath(device_path),
+ params.operation,
+ params.ip_or_mac_address,
+ base::Bind(&TDLSSuccessCallback,
+ device_path, params, callback, error_callback),
+ base::Bind(&TDLSErrorCallback,
+ device_path, params, callback, error_callback));
+}
+
} // namespace
NetworkDeviceHandlerImpl::~NetworkDeviceHandlerImpl() {
@@ -278,6 +394,50 @@ void NetworkDeviceHandlerImpl::SetCellularAllowRoaming(
ApplyCellularAllowRoamingToShill();
}
+void NetworkDeviceHandlerImpl::SetWifiTDLSEnabled(
+ const std::string& ip_or_mac_address,
+ bool enabled,
+ const network_handler::StringResultCallback& callback,
+ const network_handler::ErrorCallback& error_callback) {
+ const DeviceState* device_state =
+ network_state_handler_->GetDeviceStateByType(NetworkTypePattern::WiFi());
+ if (!device_state) {
+ if (error_callback.is_null())
+ return;
+ scoped_ptr<base::DictionaryValue> error_data(new base::DictionaryValue);
+ error_data->SetString(network_handler::kErrorName, kErrorDeviceMissing);
+ error_callback.Run(kErrorDeviceMissing, error_data.Pass());
+ return;
+ }
+ TDLSOperationParams params;
+ params.operation = enabled ? shill::kTDLSSetupOperation
+ : shill::kTDLSTeardownOperation;
+ params.ip_or_mac_address = ip_or_mac_address;
+ CallPerformTDLSOperation(
+ device_state->path(), params, callback, error_callback);
+}
+
+void NetworkDeviceHandlerImpl::GetWifiTDLSStatus(
+ const std::string& ip_or_mac_address,
+ const network_handler::StringResultCallback& callback,
+ const network_handler::ErrorCallback& error_callback) {
+ const DeviceState* device_state =
+ network_state_handler_->GetDeviceStateByType(NetworkTypePattern::WiFi());
+ if (!device_state) {
+ if (error_callback.is_null())
+ return;
+ scoped_ptr<base::DictionaryValue> error_data(new base::DictionaryValue);
+ error_data->SetString(network_handler::kErrorName, kErrorDeviceMissing);
+ error_callback.Run(kErrorDeviceMissing, error_data.Pass());
+ return;
+ }
+ TDLSOperationParams params;
+ params.operation = shill::kTDLSStatusOperation;
+ params.ip_or_mac_address = ip_or_mac_address;
+ CallPerformTDLSOperation(
+ device_state->path(), params, callback, error_callback);
+}
+
void NetworkDeviceHandlerImpl::DeviceListChanged() {
ApplyCellularAllowRoamingToShill();
}
diff --git a/chromeos/network/network_device_handler_impl.h b/chromeos/network/network_device_handler_impl.h
index 226e7a9..3db410b 100644
--- a/chromeos/network/network_device_handler_impl.h
+++ b/chromeos/network/network_device_handler_impl.h
@@ -5,6 +5,7 @@
#ifndef CHROMEOS_NETWORK_NETWORK_DEVICE_HANDLER_IMPL_H_
#define CHROMEOS_NETWORK_NETWORK_DEVICE_HANDLER_IMPL_H_
+#include <map>
#include <string>
#include "base/basictypes.h"
@@ -90,6 +91,17 @@ class CHROMEOS_EXPORT NetworkDeviceHandlerImpl
virtual void SetCellularAllowRoaming(bool allow_roaming) OVERRIDE;
+ virtual void SetWifiTDLSEnabled(
+ const std::string& ip_or_mac_address,
+ bool enabled,
+ const network_handler::StringResultCallback& callback,
+ const network_handler::ErrorCallback& error_callback) OVERRIDE;
+
+ virtual void GetWifiTDLSStatus(
+ const std::string& ip_or_mac_address,
+ const network_handler::StringResultCallback& callback,
+ const network_handler::ErrorCallback& error_callback) OVERRIDE;
+
// NetworkStateHandlerObserver overrides
virtual void DeviceListChanged() OVERRIDE;
@@ -106,7 +118,6 @@ class CHROMEOS_EXPORT NetworkDeviceHandlerImpl
void ApplyCellularAllowRoamingToShill();
NetworkStateHandler* network_state_handler_;
-
bool cellular_allow_roaming_;
DISALLOW_COPY_AND_ASSIGN(NetworkDeviceHandlerImpl);
diff --git a/chromeos/network/network_device_handler_unittest.cc b/chromeos/network/network_device_handler_unittest.cc
index 60a264b..fb1fc29 100644
--- a/chromeos/network/network_device_handler_unittest.cc
+++ b/chromeos/network/network_device_handler_unittest.cc
@@ -39,22 +39,14 @@ class NetworkDeviceHandlerTest : public testing::Test {
scoped_ptr<ShillDeviceClient>(fake_device_client_));
DBusThreadManager::InitializeForTesting(dbus_manager);
- ShillDeviceClient::TestInterface* device_test =
- fake_device_client_->GetTestInterface();
- device_test->AddDevice(
- kDefaultCellularDevicePath, shill::kTypeCellular, "cellular1");
- device_test->AddDevice(kDefaultWifiDevicePath, shill::kTypeWifi, "wifi1");
-
- base::ListValue test_ip_configs;
- test_ip_configs.AppendString("ip_config1");
- device_test->SetDeviceProperty(
- kDefaultWifiDevicePath, shill::kIPConfigsProperty, test_ip_configs);
-
success_callback_ = base::Bind(&NetworkDeviceHandlerTest::SuccessCallback,
base::Unretained(this));
properties_success_callback_ =
base::Bind(&NetworkDeviceHandlerTest::PropertiesSuccessCallback,
base::Unretained(this));
+ string_success_callback_ =
+ base::Bind(&NetworkDeviceHandlerTest::StringSuccessCallback,
+ base::Unretained(this));
error_callback_ = base::Bind(&NetworkDeviceHandlerTest::ErrorCallback,
base::Unretained(this));
@@ -62,6 +54,20 @@ class NetworkDeviceHandlerTest : public testing::Test {
NetworkDeviceHandlerImpl* device_handler = new NetworkDeviceHandlerImpl;
device_handler->Init(network_state_handler_.get());
network_device_handler_.reset(device_handler);
+
+ // Add devices after handlers have been initialized.
+ ShillDeviceClient::TestInterface* device_test =
+ fake_device_client_->GetTestInterface();
+ device_test->AddDevice(
+ kDefaultCellularDevicePath, shill::kTypeCellular, "cellular1");
+ device_test->AddDevice(kDefaultWifiDevicePath, shill::kTypeWifi, "wifi1");
+
+ base::ListValue test_ip_configs;
+ test_ip_configs.AppendString("ip_config1");
+ device_test->SetDeviceProperty(
+ kDefaultWifiDevicePath, shill::kIPConfigsProperty, test_ip_configs);
+
+ message_loop_.RunUntilIdle();
}
virtual void TearDown() OVERRIDE {
@@ -72,6 +78,7 @@ class NetworkDeviceHandlerTest : public testing::Test {
void ErrorCallback(const std::string& error_name,
scoped_ptr<base::DictionaryValue> error_data) {
+ LOG(ERROR) << "ErrorCallback: " << error_name;
result_ = error_name;
}
@@ -85,6 +92,11 @@ class NetworkDeviceHandlerTest : public testing::Test {
properties_.reset(properties.DeepCopy());
}
+ void StringSuccessCallback(const std::string& result) {
+ LOG(ERROR) << "StringSuccessCallback: " << result;
+ result_ = kResultSuccess;
+ }
+
protected:
std::string result_;
@@ -94,6 +106,7 @@ class NetworkDeviceHandlerTest : public testing::Test {
base::MessageLoopForUI message_loop_;
base::Closure success_callback_;
network_handler::DictionaryResultCallback properties_success_callback_;
+ network_handler::StringResultCallback string_success_callback_;
network_handler::ErrorCallback error_callback_;
scoped_ptr<base::DictionaryValue> properties_;
@@ -158,7 +171,7 @@ TEST_F(NetworkDeviceHandlerTest, SetDeviceProperty) {
success_callback_,
error_callback_);
message_loop_.RunUntilIdle();
- EXPECT_EQ(NetworkDeviceHandler::kErrorFailure, result_);
+ EXPECT_EQ(NetworkDeviceHandler::kErrorDeviceMissing, result_);
// Setting a owner-protected device property through SetDeviceProperty must
// fail.
@@ -209,6 +222,57 @@ TEST_F(NetworkDeviceHandlerTest, CellularAllowRoaming) {
EXPECT_FALSE(allow_roaming);
}
+TEST_F(NetworkDeviceHandlerTest, SetWifiTDLSEnabled) {
+ // We add a wifi device by default, initial call should succeed.
+ network_device_handler_->SetWifiTDLSEnabled(
+ "fake_ip_address", true, string_success_callback_, error_callback_);
+ message_loop_.RunUntilIdle();
+ EXPECT_EQ(kResultSuccess, result_);
+}
+
+TEST_F(NetworkDeviceHandlerTest, SetWifiTDLSEnabledMissing) {
+ // Remove the wifi device. Call should fail with "device missing" error.
+ fake_device_client_->GetTestInterface()->RemoveDevice(kDefaultWifiDevicePath);
+ message_loop_.RunUntilIdle();
+ network_device_handler_->SetWifiTDLSEnabled(
+ "fake_ip_address", true, string_success_callback_, error_callback_);
+ message_loop_.RunUntilIdle();
+ EXPECT_EQ(NetworkDeviceHandler::kErrorDeviceMissing, result_);
+}
+
+TEST_F(NetworkDeviceHandlerTest, SetWifiTDLSEnabledBusy) {
+ // Set the busy count, call should succeed after repeat attempt.
+ fake_device_client_->set_tdls_busy_count(1);
+ network_device_handler_->SetWifiTDLSEnabled(
+ "fake_ip_address", true, string_success_callback_, error_callback_);
+ message_loop_.RunUntilIdle();
+ EXPECT_EQ(kResultSuccess, result_);
+
+ // Set the busy count to a large number, call should fail after max number
+ // of repeat attempt.
+ fake_device_client_->set_tdls_busy_count(100000);
+ network_device_handler_->SetWifiTDLSEnabled(
+ "fake_ip_address", true, string_success_callback_, error_callback_);
+ message_loop_.RunUntilIdle();
+ EXPECT_EQ(NetworkDeviceHandler::kErrorTimeout, result_);
+}
+
+TEST_F(NetworkDeviceHandlerTest, GetWifiTDLSStatus) {
+ // We add a wifi device by default, initial call should succeed.
+ network_device_handler_->GetWifiTDLSStatus(
+ "fake_ip_address", string_success_callback_, error_callback_);
+ message_loop_.RunUntilIdle();
+ EXPECT_EQ(kResultSuccess, result_);
+
+ // Remove the wifi device. Call should fail with "device missing" error.
+ fake_device_client_->GetTestInterface()->RemoveDevice(kDefaultWifiDevicePath);
+ message_loop_.RunUntilIdle();
+ network_device_handler_->GetWifiTDLSStatus(
+ "fake_ip_address", string_success_callback_, error_callback_);
+ message_loop_.RunUntilIdle();
+ EXPECT_EQ(NetworkDeviceHandler::kErrorDeviceMissing, result_);
+}
+
TEST_F(NetworkDeviceHandlerTest, RequestRefreshIPConfigs) {
network_device_handler_->RequestRefreshIPConfigs(
kDefaultWifiDevicePath, success_callback_, error_callback_);
@@ -231,7 +295,7 @@ TEST_F(NetworkDeviceHandlerTest, SetCarrier) {
network_device_handler_->SetCarrier(
kUnknownCellularDevicePath, kCarrier, success_callback_, error_callback_);
message_loop_.RunUntilIdle();
- EXPECT_EQ(NetworkDeviceHandler::kErrorFailure, result_);
+ EXPECT_EQ(NetworkDeviceHandler::kErrorDeviceMissing, result_);
}
TEST_F(NetworkDeviceHandlerTest, RequirePin) {
@@ -253,7 +317,7 @@ TEST_F(NetworkDeviceHandlerTest, RequirePin) {
success_callback_,
error_callback_);
message_loop_.RunUntilIdle();
- EXPECT_EQ(NetworkDeviceHandler::kErrorFailure, result_);
+ EXPECT_EQ(NetworkDeviceHandler::kErrorDeviceMissing, result_);
}
TEST_F(NetworkDeviceHandlerTest, EnterPin) {
@@ -269,7 +333,7 @@ TEST_F(NetworkDeviceHandlerTest, EnterPin) {
network_device_handler_->EnterPin(
kUnknownCellularDevicePath, kPin, success_callback_, error_callback_);
message_loop_.RunUntilIdle();
- EXPECT_EQ(NetworkDeviceHandler::kErrorFailure, result_);
+ EXPECT_EQ(NetworkDeviceHandler::kErrorDeviceMissing, result_);
}
TEST_F(NetworkDeviceHandlerTest, UnblockPin) {
@@ -292,7 +356,7 @@ TEST_F(NetworkDeviceHandlerTest, UnblockPin) {
success_callback_,
error_callback_);
message_loop_.RunUntilIdle();
- EXPECT_EQ(NetworkDeviceHandler::kErrorFailure, result_);
+ EXPECT_EQ(NetworkDeviceHandler::kErrorDeviceMissing, result_);
}
TEST_F(NetworkDeviceHandlerTest, ChangePin) {
@@ -315,7 +379,7 @@ TEST_F(NetworkDeviceHandlerTest, ChangePin) {
success_callback_,
error_callback_);
message_loop_.RunUntilIdle();
- EXPECT_EQ(NetworkDeviceHandler::kErrorFailure, result_);
+ EXPECT_EQ(NetworkDeviceHandler::kErrorDeviceMissing, result_);
}
} // namespace chromeos