Index: chrome/browser/sync/test/integration/wifi_credentials_helper_chromeos.cc |
diff --git a/chrome/browser/sync/test/integration/wifi_credentials_helper_chromeos.cc b/chrome/browser/sync/test/integration/wifi_credentials_helper_chromeos.cc |
index 8e5400247c21808abee5edcbbdf3b236208d1440..aaf0ea675b2c039a0d4fa9ce2aec3929ee0c2357 100644 |
--- a/chrome/browser/sync/test/integration/wifi_credentials_helper_chromeos.cc |
+++ b/chrome/browser/sync/test/integration/wifi_credentials_helper_chromeos.cc |
@@ -6,14 +6,23 @@ |
#include <string> |
+#include "base/bind.h" |
#include "base/files/file_path.h" |
#include "base/logging.h" |
+#include "base/memory/scoped_ptr.h" |
+#include "base/strings/stringprintf.h" |
+#include "base/values.h" |
#include "chrome/browser/profiles/profile.h" |
+#include "chromeos/dbus/dbus_thread_manager.h" |
+#include "chromeos/dbus/shill_profile_client.h" |
+#include "chromeos/network/managed_network_configuration_handler.h" |
#include "chromeos/network/network_handler.h" |
-#include "chromeos/network/network_state.h" |
#include "chromeos/network/network_state_handler.h" |
+#include "components/onc/onc_constants.h" |
#include "components/wifi_sync/network_state_helper_chromeos.h" |
-#include "components/wifi_sync/wifi_security_class.h" |
+#include "components/wifi_sync/wifi_credential_syncable_service_factory.h" |
+ |
+using wifi_sync::WifiCredential; |
using WifiCredentialSet = wifi_sync::WifiCredential::CredentialSet; |
@@ -23,6 +32,13 @@ namespace { |
const char kProfilePrefix[] = "/profile/"; |
+void LogCreateConfigurationFailure( |
+ const std::string& debug_hint, |
+ const std::string& /* network_config_error_message */, |
+ scoped_ptr<base::DictionaryValue> /* network_config_error_data */) { |
+ LOG(FATAL) << debug_hint; |
+} |
+ |
std::string ChromeOsUserHashForBrowserContext( |
const content::BrowserContext& context) { |
return context.GetPath().BaseName().value(); |
@@ -33,6 +49,23 @@ std::string ShillProfilePathForBrowserContext( |
return kProfilePrefix + ChromeOsUserHashForBrowserContext(context); |
} |
+chromeos::ShillProfileClient::TestInterface* |
+GetShillProfileClientTestInterface() { |
+ DCHECK(chromeos::DBusThreadManager::Get()->GetShillProfileClient()); |
+ DCHECK(chromeos::DBusThreadManager::Get()->GetShillProfileClient() |
+ ->GetTestInterface()); |
+ return chromeos::DBusThreadManager::Get()->GetShillProfileClient() |
+ ->GetTestInterface(); |
+} |
+ |
+chromeos::ManagedNetworkConfigurationHandler* |
+GetManagedNetworkConfigurationHandler() { |
+ DCHECK(chromeos::NetworkHandler::Get() |
+ ->managed_network_configuration_handler()); |
+ return chromeos::NetworkHandler::Get() |
+ ->managed_network_configuration_handler(); |
+} |
+ |
chromeos::NetworkStateHandler* GetNetworkStateHandler() { |
DCHECK(chromeos::NetworkHandler::Get()->network_state_handler()); |
return chromeos::NetworkHandler::Get()->network_state_handler(); |
@@ -40,6 +73,47 @@ chromeos::NetworkStateHandler* GetNetworkStateHandler() { |
} // namespace |
+void SetUpChromeOs() { |
+ wifi_sync::WifiCredentialSyncableServiceFactory::GetInstance() |
+ ->IgnoreLoginStateForTest(); |
+} |
+ |
+bool SetupClientForProfileChromeOs(const Profile* profile) { |
+ DCHECK(profile); |
+ GetShillProfileClientTestInterface() |
+ ->AddProfile(ShillProfilePathForBrowserContext(*profile), |
+ ChromeOsUserHashForBrowserContext(*profile)); |
+ |
+ const base::ListValue policy_network_configs; |
+ const base::DictionaryValue policy_global_config; |
+ GetManagedNetworkConfigurationHandler() |
+ ->SetPolicy(onc::ONC_SOURCE_UNKNOWN, |
+ ChromeOsUserHashForBrowserContext(*profile), |
+ policy_network_configs, |
+ policy_global_config); |
+ |
+ return true; |
+} |
+ |
+void AddWifiCredentialToProfileChromeOs( |
+ Profile* profile, const WifiCredential& credential) { |
+ DCHECK(profile); |
+ scoped_ptr<base::DictionaryValue> onc_properties = |
+ credential.ToOncProperties(); |
+ if (!onc_properties) { |
+ LOG(FATAL) << "Failed to generate ONC properties for " |
+ << credential.ToString(); |
+ } |
+ GetManagedNetworkConfigurationHandler() |
+ ->CreateConfiguration( |
+ ChromeOsUserHashForBrowserContext(*profile), |
+ *onc_properties, |
+ chromeos::network_handler::StringResultCallback(), |
+ base::Bind(LogCreateConfigurationFailure, |
+ base::StringPrintf("Failed to add credential %s", |
+ credential.ToString().c_str()))); |
+} |
+ |
WifiCredentialSet GetWifiCredentialsForProfileChromeOs(const Profile* profile) { |
DCHECK(profile); |
return wifi_sync::GetWifiCredentialsForShillProfile( |