OLD | NEW |
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.h" | 5 #include "chrome/browser/sync/test/integration/wifi_credentials_helper.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
10 #include "chrome/browser/sync/test/integration/sync_datatype_helper.h" | 10 #include "chrome/browser/sync/test/integration/sync_datatype_helper.h" |
11 #include "chrome/browser/sync/test/integration/sync_test.h" | 11 #include "chrome/browser/sync/test/integration/sync_test.h" |
12 #include "components/wifi_sync/wifi_credential.h" | 12 #include "components/wifi_sync/wifi_credential.h" |
| 13 #include "components/wifi_sync/wifi_credential_syncable_service.h" |
| 14 #include "components/wifi_sync/wifi_credential_syncable_service_factory.h" |
13 #include "components/wifi_sync/wifi_security_class.h" | 15 #include "components/wifi_sync/wifi_security_class.h" |
14 | 16 |
15 #if defined(OS_CHROMEOS) | 17 #if defined(OS_CHROMEOS) |
16 #include "chrome/browser/sync/test/integration/wifi_credentials_helper_chromeos.
h" | 18 #include "chrome/browser/sync/test/integration/wifi_credentials_helper_chromeos.
h" |
17 #endif | 19 #endif |
18 | 20 |
19 using wifi_sync::WifiCredential; | 21 using wifi_sync::WifiCredential; |
| 22 using wifi_sync::WifiCredentialSyncableService; |
| 23 using wifi_sync::WifiCredentialSyncableServiceFactory; |
20 using sync_datatype_helper::test; | 24 using sync_datatype_helper::test; |
21 | 25 |
22 using WifiCredentialSet = wifi_sync::WifiCredential::CredentialSet; | 26 using WifiCredentialSet = wifi_sync::WifiCredential::CredentialSet; |
23 | 27 |
24 namespace wifi_credentials_helper { | 28 namespace wifi_credentials_helper { |
25 | 29 |
26 namespace { | 30 namespace { |
| 31 bool SetupClientForProfile(Profile* profile) { |
| 32 #if defined(OS_CHROMEOS) |
| 33 return SetupClientForProfileChromeOs(profile); |
| 34 #else |
| 35 NOTIMPLEMENTED(); |
| 36 return false; |
| 37 #endif |
| 38 } |
| 39 |
| 40 WifiCredentialSyncableService* GetServiceForBrowserContext( |
| 41 content::BrowserContext* context) { |
| 42 return WifiCredentialSyncableServiceFactory::GetForBrowserContext( |
| 43 context); |
| 44 } |
| 45 |
| 46 WifiCredentialSyncableService* GetServiceForProfile(int profile_index) { |
| 47 return GetServiceForBrowserContext(test()->GetProfile(profile_index)); |
| 48 } |
| 49 |
| 50 void AddWifiCredentialToProfile( |
| 51 Profile* profile, const WifiCredential& credential) { |
| 52 #if defined(OS_CHROMEOS) |
| 53 AddWifiCredentialToProfileChromeOs(profile, credential); |
| 54 #else |
| 55 NOTIMPLEMENTED(); |
| 56 #endif |
| 57 } |
27 | 58 |
28 WifiCredentialSet GetWifiCredentialsForProfile(const Profile* profile) { | 59 WifiCredentialSet GetWifiCredentialsForProfile(const Profile* profile) { |
29 #if defined(OS_CHROMEOS) | 60 #if defined(OS_CHROMEOS) |
30 return GetWifiCredentialsForProfileChromeOs(profile); | 61 return GetWifiCredentialsForProfileChromeOs(profile); |
31 #else | 62 #else |
32 NOTIMPLEMENTED(); | 63 NOTIMPLEMENTED(); |
33 return WifiCredential::MakeSet(); | 64 return WifiCredential::MakeSet(); |
34 #endif | 65 #endif |
35 } | 66 } |
36 | 67 |
(...skipping 17 matching lines...) Expand all Loading... |
54 << " Passphrase: " << credential.passphrase(); | 85 << " Passphrase: " << credential.passphrase(); |
55 return false; | 86 return false; |
56 } | 87 } |
57 } | 88 } |
58 | 89 |
59 return true; | 90 return true; |
60 } | 91 } |
61 | 92 |
62 } // namespace | 93 } // namespace |
63 | 94 |
| 95 void SetUp() { |
| 96 #if defined(OS_CHROMEOS) |
| 97 return SetUpChromeOs(); |
| 98 #else |
| 99 NOTIMPLEMENTED(); |
| 100 #endif |
| 101 } |
| 102 |
| 103 bool SetupClients() { |
| 104 if (!SetupClientForProfile(test()->verifier())) { |
| 105 return false; |
| 106 } |
| 107 |
| 108 for (int i = 0; i < test()->num_clients(); ++i) { |
| 109 if (!SetupClientForProfile(test()->GetProfile(i))) { |
| 110 return false; |
| 111 } |
| 112 } |
| 113 return true; |
| 114 } |
| 115 |
64 bool VerifierIsEmpty() { | 116 bool VerifierIsEmpty() { |
65 return GetWifiCredentialsForProfile(test()->verifier()).empty(); | 117 return GetWifiCredentialsForProfile(test()->verifier()).empty(); |
66 } | 118 } |
67 | 119 |
68 bool ProfileMatchesVerifier(int profile_index) { | 120 bool ProfileMatchesVerifier(int profile_index) { |
69 WifiCredentialSet verifier_credentials = | 121 WifiCredentialSet verifier_credentials = |
70 GetWifiCredentialsForProfile(test()->verifier()); | 122 GetWifiCredentialsForProfile(test()->verifier()); |
71 WifiCredentialSet other_credentials = | 123 WifiCredentialSet other_credentials = |
72 GetWifiCredentialsForProfile(test()->GetProfile(profile_index)); | 124 GetWifiCredentialsForProfile(test()->GetProfile(profile_index)); |
73 return CredentialsMatch(verifier_credentials, other_credentials); | 125 return CredentialsMatch(verifier_credentials, other_credentials); |
(...skipping 11 matching lines...) Expand all Loading... |
85 WifiCredentialSet other_profile_credentials = | 137 WifiCredentialSet other_profile_credentials = |
86 GetWifiCredentialsForProfile(test()->GetProfile(i)); | 138 GetWifiCredentialsForProfile(test()->GetProfile(i)); |
87 if (!CredentialsMatch(profile0_credentials, other_profile_credentials)) { | 139 if (!CredentialsMatch(profile0_credentials, other_profile_credentials)) { |
88 LOG(ERROR) << "Profile " << i << " " << "does not match with profile 0."; | 140 LOG(ERROR) << "Profile " << i << " " << "does not match with profile 0."; |
89 return false; | 141 return false; |
90 } | 142 } |
91 } | 143 } |
92 return true; | 144 return true; |
93 } | 145 } |
94 | 146 |
| 147 void AddWifiCredential(int profile_index, |
| 148 const std::string& sync_id, |
| 149 const WifiCredential& credential) { |
| 150 AddWifiCredentialToProfile(test()->GetProfile(profile_index), credential); |
| 151 if (test()->use_verifier()) |
| 152 AddWifiCredentialToProfile(test()->verifier(), credential); |
| 153 |
| 154 // TODO(quiche): Remove this, once we have plumbing to route |
| 155 // NetworkConfigurationObserver events to |
| 156 // WifiCredentialSyncableService instances. |
| 157 GetServiceForProfile(profile_index) |
| 158 ->AddToSyncedNetworks(sync_id, credential); |
| 159 } |
| 160 |
95 } // namespace wifi_credentials_helper | 161 } // namespace wifi_credentials_helper |
OLD | NEW |