Reimplement RequestHiddenWifiNetworkProperties and RequestVirtualNetworkProperties without Libcros

BUG=chromium-os:16557
TEST=unit_tests --gtest_filter="CrosNetworkFunctions*"

Review URL: https://chromiumcodereview.appspot.com/10164026

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@133629 0039d316-1c4b-4281-b951-d872f2087c98
parent 8e66881e
...@@ -211,6 +211,18 @@ void RunCallbackWithDictionaryValue(const NetworkPropertiesCallback& callback, ...@@ -211,6 +211,18 @@ void RunCallbackWithDictionaryValue(const NetworkPropertiesCallback& callback,
callback.Run(path, call_status == DBUS_METHOD_CALL_SUCCESS ? &value : NULL); callback.Run(path, call_status == DBUS_METHOD_CALL_SUCCESS ? &value : NULL);
} }
// Used as a callback for FlimflamManagerClient::GetService
void OnGetService(const NetworkPropertiesCallback& callback,
DBusMethodCallStatus call_status,
const dbus::ObjectPath& service_path) {
if (call_status == DBUS_METHOD_CALL_SUCCESS) {
DBusThreadManager::Get()->GetFlimflamServiceClient()->GetProperties(
service_path, base::Bind(&RunCallbackWithDictionaryValue,
callback,
service_path.value()));
}
}
// Used as a callback for chromeos::ConfigureService. // Used as a callback for chromeos::ConfigureService.
void OnConfigureService(void* object, void OnConfigureService(void* object,
const char* service_path, const char* service_path,
...@@ -465,12 +477,34 @@ void CrosRequestHiddenWifiNetworkProperties( ...@@ -465,12 +477,34 @@ void CrosRequestHiddenWifiNetworkProperties(
const std::string& ssid, const std::string& ssid,
const std::string& security, const std::string& security,
const NetworkPropertiesCallback& callback) { const NetworkPropertiesCallback& callback) {
// The newly allocated callback will be deleted in OnRequestNetworkProperties. if (g_libcros_network_functions_enabled) {
chromeos::RequestHiddenWifiNetworkProperties( // The newly allocated callback will be deleted in
ssid.c_str(), // OnRequestNetworkProperties.
security.c_str(), chromeos::RequestHiddenWifiNetworkProperties(
&OnRequestNetworkProperties, ssid.c_str(),
new OnRequestNetworkPropertiesCallback(callback)); security.c_str(),
&OnRequestNetworkProperties,
new OnRequestNetworkPropertiesCallback(callback));
} else {
base::DictionaryValue properties;
properties.SetWithoutPathExpansion(
flimflam::kModeProperty,
base::Value::CreateStringValue(flimflam::kModeManaged));
properties.SetWithoutPathExpansion(
flimflam::kTypeProperty,
base::Value::CreateStringValue(flimflam::kTypeWifi));
properties.SetWithoutPathExpansion(
flimflam::kSSIDProperty,
base::Value::CreateStringValue(ssid));
properties.SetWithoutPathExpansion(
flimflam::kSecurityProperty,
base::Value::CreateStringValue(security));
// flimflam.Manger.GetService() will apply the property changes in
// |properties| and return a new or existing service to OnGetService().
// OnGetService will then call GetProperties which will then call callback.
DBusThreadManager::Get()->GetFlimflamManagerClient()->GetService(
properties, base::Bind(&OnGetService, callback));
}
} }
void CrosRequestVirtualNetworkProperties( void CrosRequestVirtualNetworkProperties(
...@@ -478,13 +512,40 @@ void CrosRequestVirtualNetworkProperties( ...@@ -478,13 +512,40 @@ void CrosRequestVirtualNetworkProperties(
const std::string& server_hostname, const std::string& server_hostname,
const std::string& provider_type, const std::string& provider_type,
const NetworkPropertiesCallback& callback) { const NetworkPropertiesCallback& callback) {
// The newly allocated callback will be deleted in OnRequestNetworkProperties. if (g_libcros_network_functions_enabled) {
chromeos::RequestVirtualNetworkProperties( // The newly allocated callback will be deleted in
service_name.c_str(), // OnRequestNetworkProperties.
server_hostname.c_str(), chromeos::RequestVirtualNetworkProperties(
provider_type.c_str(), service_name.c_str(),
&OnRequestNetworkProperties, server_hostname.c_str(),
new OnRequestNetworkPropertiesCallback(callback)); provider_type.c_str(),
&OnRequestNetworkProperties,
new OnRequestNetworkPropertiesCallback(callback));
} else {
base::DictionaryValue properties;
properties.SetWithoutPathExpansion(
flimflam::kTypeProperty,
base::Value::CreateStringValue(flimflam::kTypeVPN));
properties.SetWithoutPathExpansion(
flimflam::kProviderNameProperty,
base::Value::CreateStringValue(service_name));
properties.SetWithoutPathExpansion(
flimflam::kProviderHostProperty,
base::Value::CreateStringValue(server_hostname));
properties.SetWithoutPathExpansion(
flimflam::kProviderTypeProperty,
base::Value::CreateStringValue(provider_type));
// The actual value of Domain does not matter, so just use service_name.
properties.SetWithoutPathExpansion(
flimflam::kVPNDomainProperty,
base::Value::CreateStringValue(service_name));
// flimflam.Manger.GetService() will apply the property changes in
// |properties| and pass a new or existing service to OnGetService().
// OnGetService will then call GetProperties which will then call callback.
DBusThreadManager::Get()->GetFlimflamManagerClient()->GetService(
properties, base::Bind(&OnGetService, callback));
}
} }
void CrosRequestNetworkServiceDisconnect(const std::string& service_path) { void CrosRequestNetworkServiceDisconnect(const std::string& service_path) {
......
...@@ -976,6 +976,98 @@ TEST_F(CrosNetworkFunctionsTest, CrosRequestNetworkProfileEntryProperties) { ...@@ -976,6 +976,98 @@ TEST_F(CrosNetworkFunctionsTest, CrosRequestNetworkProfileEntryProperties) {
result)); result));
} }
TEST_F(CrosNetworkFunctionsTest, CrosRequestHiddenWifiNetworkProperties) {
const std::string ssid = "ssid";
const std::string security = "security";
const std::string key1 = "key1";
const std::string value1 = "value1";
const std::string key2 = "key.2.";
const std::string value2 = "value2";
// Create result value.
base::DictionaryValue result;
result.SetWithoutPathExpansion(key1, base::Value::CreateStringValue(value1));
result.SetWithoutPathExpansion(key2, base::Value::CreateStringValue(value2));
dictionary_value_result_ = &result;
// Create expected argument to FlimflamManagerClient::GetService.
base::DictionaryValue properties;
properties.SetWithoutPathExpansion(
flimflam::kModeProperty,
base::Value::CreateStringValue(flimflam::kModeManaged));
properties.SetWithoutPathExpansion(
flimflam::kTypeProperty,
base::Value::CreateStringValue(flimflam::kTypeWifi));
properties.SetWithoutPathExpansion(
flimflam::kSSIDProperty,
base::Value::CreateStringValue(ssid));
properties.SetWithoutPathExpansion(
flimflam::kSecurityProperty,
base::Value::CreateStringValue(security));
// Set expectations.
const dbus::ObjectPath service_path("/service/path");
FlimflamClientHelper::ObjectPathCallback callback;
EXPECT_CALL(*mock_manager_client_, GetService(IsEqualTo(&properties), _))
.WillOnce(SaveArg<1>(&callback));
EXPECT_CALL(*mock_service_client_,
GetProperties(service_path, _)).WillOnce(
Invoke(this, &CrosNetworkFunctionsTest::OnGetProperties));
// Call function.
CrosRequestHiddenWifiNetworkProperties(
ssid, security,
MockNetworkPropertiesCallback::CreateCallback(service_path.value(),
result));
// Run callback to invoke GetProperties.
callback.Run(DBUS_METHOD_CALL_SUCCESS, service_path);
}
TEST_F(CrosNetworkFunctionsTest, CrosRequestVirtualNetworkProperties) {
const std::string service_name = "service name";
const std::string server_hostname = "server hostname";
const std::string provider_type = "provider type";
const std::string key1 = "key1";
const std::string value1 = "value1";
const std::string key2 = "key.2.";
const std::string value2 = "value2";
// Create result value.
base::DictionaryValue result;
result.SetWithoutPathExpansion(key1, base::Value::CreateStringValue(value1));
result.SetWithoutPathExpansion(key2, base::Value::CreateStringValue(value2));
dictionary_value_result_ = &result;
// Create expected argument to FlimflamManagerClient::GetService.
base::DictionaryValue properties;
properties.SetWithoutPathExpansion(
flimflam::kTypeProperty, base::Value::CreateStringValue("vpn"));
properties.SetWithoutPathExpansion(
flimflam::kProviderNameProperty,
base::Value::CreateStringValue(service_name));
properties.SetWithoutPathExpansion(
flimflam::kProviderHostProperty,
base::Value::CreateStringValue(server_hostname));
properties.SetWithoutPathExpansion(
flimflam::kProviderTypeProperty,
base::Value::CreateStringValue(provider_type));
properties.SetWithoutPathExpansion(
flimflam::kVPNDomainProperty,
base::Value::CreateStringValue(service_name));
// Set expectations.
const dbus::ObjectPath service_path("/service/path");
FlimflamClientHelper::ObjectPathCallback callback;
EXPECT_CALL(*mock_manager_client_, GetService(IsEqualTo(&properties), _))
.WillOnce(SaveArg<1>(&callback));
EXPECT_CALL(*mock_service_client_,
GetProperties(service_path, _)).WillOnce(
Invoke(this, &CrosNetworkFunctionsTest::OnGetProperties));
// Call function.
CrosRequestVirtualNetworkProperties(
service_name, server_hostname, provider_type,
MockNetworkPropertiesCallback::CreateCallback(service_path.value(),
result));
// Run callback to invoke GetProperties.
callback.Run(DBUS_METHOD_CALL_SUCCESS, service_path);
}
TEST_F(CrosNetworkFunctionsTest, CrosRequestNetworkServiceDisconnect) { TEST_F(CrosNetworkFunctionsTest, CrosRequestNetworkServiceDisconnect) {
const std::string service_path = "/service/path"; const std::string service_path = "/service/path";
EXPECT_CALL(*mock_service_client_, EXPECT_CALL(*mock_service_client_,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment