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_security_class.h" | 13 #include "components/wifi_sync/wifi_credential_syncable_service.h" |
14 #include "components/wifi_sync/wifi_credential_syncable_service_factory.h" | |
14 | 15 |
15 #if defined(OS_CHROMEOS) | 16 #if defined(OS_CHROMEOS) |
16 #include "chrome/browser/sync/test/integration/wifi_credentials_helper_chromeos. h" | 17 #include "chrome/browser/sync/test/integration/wifi_credentials_helper_chromeos. h" |
17 #endif | 18 #endif |
18 | 19 |
19 using wifi_sync::WifiCredential; | 20 using wifi_sync::WifiCredential; |
21 using wifi_sync::WifiCredentialSyncableService; | |
22 using wifi_sync::WifiCredentialSyncableServiceFactory; | |
23 using wifi_sync::WifiSecurityClass; | |
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 { |
27 | 31 |
32 bool SetupClientForProfile(Profile* profile) { | |
33 #if defined(OS_CHROMEOS) | |
34 return | |
35 wifi_credentials_helper::chromeos::SetupClientForProfileChromeOs(profile); | |
36 #else | |
37 NOTREACHED(); | |
pneubeck (no reviews)
2015/01/30 14:38:45
note that this does not crash on release builds (t
mukesh agrawal
2015/01/30 22:28:14
Thanks for the info. I wasn't aware of that, but I
| |
38 return false; | |
39 #endif | |
40 } | |
41 | |
42 WifiCredentialSyncableService* GetServiceForBrowserContext( | |
43 content::BrowserContext* context) { | |
44 return WifiCredentialSyncableServiceFactory::GetForBrowserContext( | |
45 context); | |
46 } | |
47 | |
48 WifiCredentialSyncableService* GetServiceForProfile(int profile_index) { | |
49 return GetServiceForBrowserContext(test()->GetProfile(profile_index)); | |
50 } | |
51 | |
52 void AddWifiCredentialToProfile( | |
53 Profile* profile, const WifiCredential& credential) { | |
54 #if defined(OS_CHROMEOS) | |
55 wifi_credentials_helper::chromeos::AddWifiCredentialToProfileChromeOs( | |
56 profile, credential); | |
57 #else | |
58 NOTREACHED(); | |
59 #endif | |
60 } | |
61 | |
28 WifiCredentialSet GetWifiCredentialsForProfile(const Profile* profile) { | 62 WifiCredentialSet GetWifiCredentialsForProfile(const Profile* profile) { |
29 #if defined(OS_CHROMEOS) | 63 #if defined(OS_CHROMEOS) |
30 return GetWifiCredentialsForProfileChromeOs(profile); | 64 return wifi_credentials_helper::chromeos:: |
65 GetWifiCredentialsForProfileChromeOs(profile); | |
31 #else | 66 #else |
32 NOTIMPLEMENTED(); | 67 NOTREACHED(); |
33 return WifiCredential::MakeSet(); | 68 return WifiCredential::MakeSet(); |
34 #endif | 69 #endif |
35 } | 70 } |
36 | 71 |
37 bool CredentialsMatch(const WifiCredentialSet& a_credentials, | 72 bool CredentialsMatch(const WifiCredentialSet& a_credentials, |
38 const WifiCredentialSet& b_credentials) { | 73 const WifiCredentialSet& b_credentials) { |
39 if (a_credentials.size() != b_credentials.size()) { | 74 if (a_credentials.size() != b_credentials.size()) { |
40 LOG(ERROR) << "CredentialSets a and b do not match in size: " | 75 LOG(ERROR) << "CredentialSets a and b do not match in size: " |
41 << a_credentials.size() | 76 << a_credentials.size() |
42 << " vs " << b_credentials.size() << " respectively."; | 77 << " vs " << b_credentials.size() << " respectively."; |
43 return false; | 78 return false; |
44 } | 79 } |
45 | 80 |
46 for (const auto &credential : a_credentials) { | 81 for (const WifiCredential& credential : a_credentials) { |
47 if (b_credentials.find(credential) == b_credentials.end()) { | 82 if (b_credentials.find(credential) == b_credentials.end()) { |
48 LOG(ERROR) | 83 LOG(ERROR) |
49 << "Network from a not found in b. " | 84 << "Network from a not found in b. " |
50 << "SSID (hex): " | 85 << "SSID (hex): " |
51 << base::HexEncode(credential.ssid().data(), | 86 << base::HexEncode(credential.ssid().data(), |
52 credential.ssid().size()).c_str() | 87 credential.ssid().size()).c_str() |
53 << " SecurityClass: " << credential.security_class() | 88 << " SecurityClass: " << credential.security_class() |
54 << " Passphrase: " << credential.passphrase(); | 89 << " Passphrase: " << credential.passphrase(); |
55 return false; | 90 return false; |
56 } | 91 } |
57 } | 92 } |
58 | 93 |
59 return true; | 94 return true; |
60 } | 95 } |
61 | 96 |
62 } // namespace | 97 } // namespace |
63 | 98 |
99 void SetUp() { | |
100 #if defined(OS_CHROMEOS) | |
101 return wifi_credentials_helper::chromeos::SetUpChromeOs(); | |
102 #else | |
103 NOTREACHED(); | |
104 #endif | |
105 } | |
106 | |
107 bool SetupClients() { | |
108 if (!SetupClientForProfile(test()->verifier())) | |
109 return false; | |
110 | |
111 for (int i = 0; i < test()->num_clients(); ++i) { | |
112 if (!SetupClientForProfile(test()->GetProfile(i))) | |
113 return false; | |
114 } | |
115 | |
116 return true; | |
117 } | |
118 | |
64 bool VerifierIsEmpty() { | 119 bool VerifierIsEmpty() { |
65 return GetWifiCredentialsForProfile(test()->verifier()).empty(); | 120 return GetWifiCredentialsForProfile(test()->verifier()).empty(); |
66 } | 121 } |
67 | 122 |
68 bool ProfileMatchesVerifier(int profile_index) { | 123 bool ProfileMatchesVerifier(int profile_index) { |
69 WifiCredentialSet verifier_credentials = | 124 WifiCredentialSet verifier_credentials = |
70 GetWifiCredentialsForProfile(test()->verifier()); | 125 GetWifiCredentialsForProfile(test()->verifier()); |
71 WifiCredentialSet other_credentials = | 126 WifiCredentialSet other_credentials = |
72 GetWifiCredentialsForProfile(test()->GetProfile(profile_index)); | 127 GetWifiCredentialsForProfile(test()->GetProfile(profile_index)); |
73 return CredentialsMatch(verifier_credentials, other_credentials); | 128 return CredentialsMatch(verifier_credentials, other_credentials); |
(...skipping 11 matching lines...) Expand all Loading... | |
85 WifiCredentialSet other_profile_credentials = | 140 WifiCredentialSet other_profile_credentials = |
86 GetWifiCredentialsForProfile(test()->GetProfile(i)); | 141 GetWifiCredentialsForProfile(test()->GetProfile(i)); |
87 if (!CredentialsMatch(profile0_credentials, other_profile_credentials)) { | 142 if (!CredentialsMatch(profile0_credentials, other_profile_credentials)) { |
88 LOG(ERROR) << "Profile " << i << " " << "does not match with profile 0."; | 143 LOG(ERROR) << "Profile " << i << " " << "does not match with profile 0."; |
89 return false; | 144 return false; |
90 } | 145 } |
91 } | 146 } |
92 return true; | 147 return true; |
93 } | 148 } |
94 | 149 |
150 scoped_ptr<WifiCredential> MakeWifiCredential(const std::string& ssid, | |
151 WifiSecurityClass security_class, | |
152 const std::string& passphrase) { | |
153 return WifiCredential::Create(WifiCredential::MakeSsidBytesForTest(ssid), | |
154 security_class, | |
155 passphrase); | |
156 } | |
157 | |
158 void AddWifiCredential(int profile_index, | |
159 const std::string& sync_id, | |
160 const WifiCredential& credential) { | |
161 AddWifiCredentialToProfile(test()->GetProfile(profile_index), credential); | |
162 if (test()->use_verifier()) | |
163 AddWifiCredentialToProfile(test()->verifier(), credential); | |
164 | |
165 // TODO(quiche): Remove this, once we have plumbing to route | |
166 // NetworkConfigurationObserver events to | |
167 // WifiCredentialSyncableService instances. | |
168 GetServiceForProfile(profile_index) | |
169 ->AddToSyncedNetworks(sync_id, credential); | |
170 } | |
171 | |
95 } // namespace wifi_credentials_helper | 172 } // namespace wifi_credentials_helper |
OLD | NEW |