Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(184)

Side by Side Diff: chrome/browser/sync/test/integration/wifi_credentials_helper_chromeos.cc

Issue 843483004: sync: add more integration tests for wifi_sync (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@submit-4.3-syncable-service
Patch Set: address feedback from pneubeck, on PS6 Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/sync/test/integration/wifi_credentials_helper_chromeos. h" 5 #include "chrome/browser/sync/test/integration/wifi_credentials_helper_chromeos. h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/bind.h"
9 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
10 #include "base/logging.h" 11 #include "base/logging.h"
11 #include "chrome/browser/profiles/profile.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "base/strings/stringprintf.h"
14 #include "base/values.h"
15 #include "chromeos/dbus/dbus_thread_manager.h"
16 #include "chromeos/dbus/shill_profile_client.h"
17 #include "chromeos/network/managed_network_configuration_handler.h"
12 #include "chromeos/network/network_handler.h" 18 #include "chromeos/network/network_handler.h"
13 #include "chromeos/network/network_state.h"
14 #include "chromeos/network/network_state_handler.h" 19 #include "chromeos/network/network_state_handler.h"
20 #include "components/onc/onc_constants.h"
15 #include "components/wifi_sync/network_state_helper_chromeos.h" 21 #include "components/wifi_sync/network_state_helper_chromeos.h"
16 #include "components/wifi_sync/wifi_security_class.h" 22 #include "components/wifi_sync/wifi_credential_syncable_service_factory.h"
23 #include "content/public/browser/browser_context.h"
24
25 using wifi_sync::WifiCredential;
17 26
18 using WifiCredentialSet = wifi_sync::WifiCredential::CredentialSet; 27 using WifiCredentialSet = wifi_sync::WifiCredential::CredentialSet;
19 28
20 namespace wifi_credentials_helper { 29 namespace wifi_credentials_helper {
21 30
22 namespace { 31 namespace {
23 32
24 const char kProfilePrefix[] = "/profile/"; 33 const char kProfilePrefix[] = "/profile/";
25 34
35 void LogCreateConfigurationFailure(
36 const std::string& debug_hint,
37 const std::string& /* network_config_error_message */,
38 scoped_ptr<base::DictionaryValue> /* network_config_error_data */) {
39 LOG(FATAL) << debug_hint;
40 }
41
26 std::string ChromeOsUserHashForBrowserContext( 42 std::string ChromeOsUserHashForBrowserContext(
27 const content::BrowserContext& context) { 43 const content::BrowserContext& context) {
28 return context.GetPath().BaseName().value(); 44 return context.GetPath().BaseName().value();
29 } 45 }
30 46
31 std::string ShillProfilePathForBrowserContext( 47 std::string ShillProfilePathForBrowserContext(
32 const content::BrowserContext& context) { 48 const content::BrowserContext& context) {
33 return kProfilePrefix + ChromeOsUserHashForBrowserContext(context); 49 return kProfilePrefix + ChromeOsUserHashForBrowserContext(context);
34 } 50 }
35 51
36 chromeos::NetworkStateHandler* GetNetworkStateHandler() { 52 ::chromeos::ShillProfileClient::TestInterface*
37 DCHECK(chromeos::NetworkHandler::Get()->network_state_handler()); 53 GetShillProfileClientTestInterface() {
38 return chromeos::NetworkHandler::Get()->network_state_handler(); 54 DCHECK(::chromeos::DBusThreadManager::Get()->GetShillProfileClient());
55 DCHECK(::chromeos::DBusThreadManager::Get()->GetShillProfileClient()
56 ->GetTestInterface());
57 return ::chromeos::DBusThreadManager::Get()->GetShillProfileClient()
58 ->GetTestInterface();
59 }
60
61 ::chromeos::ManagedNetworkConfigurationHandler*
62 GetManagedNetworkConfigurationHandler() {
63 DCHECK(::chromeos::NetworkHandler::Get()
64 ->managed_network_configuration_handler());
65 return ::chromeos::NetworkHandler::Get()
66 ->managed_network_configuration_handler();
67 }
68
69 ::chromeos::NetworkStateHandler* GetNetworkStateHandler() {
70 DCHECK(::chromeos::NetworkHandler::Get()->network_state_handler());
71 return ::chromeos::NetworkHandler::Get()->network_state_handler();
39 } 72 }
40 73
41 } // namespace 74 } // namespace
42 75
43 WifiCredentialSet GetWifiCredentialsForProfileChromeOs(const Profile* profile) { 76 namespace chromeos {
44 DCHECK(profile); 77
45 return wifi_sync::GetWifiCredentialsForShillProfile( 78 void SetUpChromeOs() {
46 GetNetworkStateHandler(), ShillProfilePathForBrowserContext(*profile)); 79 wifi_sync::WifiCredentialSyncableServiceFactory::GetInstance()
80 ->IgnoreLoginStateForTest();
47 } 81 }
48 82
83 bool SetupClientForProfileChromeOs(
84 const content::BrowserContext* browser_context) {
85 DCHECK(browser_context);
86 GetShillProfileClientTestInterface()
87 ->AddProfile(ShillProfilePathForBrowserContext(*browser_context),
88 ChromeOsUserHashForBrowserContext(*browser_context));
89
90 const base::ListValue policy_network_configs;
91 const base::DictionaryValue policy_global_config;
92 GetManagedNetworkConfigurationHandler()
93 ->SetPolicy(onc::ONC_SOURCE_UNKNOWN,
94 ChromeOsUserHashForBrowserContext(*browser_context),
95 policy_network_configs,
96 policy_global_config);
97
98 return true;
99 }
100
101 void AddWifiCredentialToProfileChromeOs(
102 const content::BrowserContext* browser_context,
103 const WifiCredential& credential) {
104 DCHECK(browser_context);
105 scoped_ptr<base::DictionaryValue> onc_properties =
106 credential.ToOncProperties();
107 CHECK(onc_properties) << "Failed to generate ONC properties for "
108 << credential.ToString();
109 GetManagedNetworkConfigurationHandler()
110 ->CreateConfiguration(
111 ChromeOsUserHashForBrowserContext(*browser_context),
112 *onc_properties,
113 ::chromeos::network_handler::StringResultCallback(),
114 base::Bind(LogCreateConfigurationFailure,
115 base::StringPrintf("Failed to add credential %s",
116 credential.ToString().c_str())));
117 }
118
119 WifiCredentialSet GetWifiCredentialsForProfileChromeOs(
120 const content::BrowserContext* browser_context) {
121 DCHECK(browser_context);
122 return wifi_sync::GetWifiCredentialsForShillProfile(
123 GetNetworkStateHandler(),
124 ShillProfilePathForBrowserContext(*browser_context));
125 }
126
127 } // namespace chromeos
128
49 } // namespace wifi_credentials_helper 129 } // namespace wifi_credentials_helper
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698