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