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

Side by Side Diff: chrome/browser/sync/test/integration/wifi_credentials_helper.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: rebase 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.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/memory/scoped_ptr.h"
8 #include "base/strings/string_number_conversions.h" 9 #include "base/strings/string_number_conversions.h"
9 #include "chrome/browser/profiles/profile.h" 10 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/sync/test/integration/sync_datatype_helper.h" 11 #include "chrome/browser/sync/test/integration/sync_datatype_helper.h"
11 #include "chrome/browser/sync/test/integration/sync_test.h" 12 #include "chrome/browser/sync/test/integration/sync_test.h"
12 #include "components/wifi_sync/wifi_credential.h" 13 #include "components/wifi_sync/wifi_credential.h"
13 #include "components/wifi_sync/wifi_security_class.h" 14 #include "components/wifi_sync/wifi_credential_syncable_service.h"
15 #include "components/wifi_sync/wifi_credential_syncable_service_factory.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;
24 using wifi_sync::WifiSecurityClass;
20 using sync_datatype_helper::test; 25 using sync_datatype_helper::test;
21 26
22 using WifiCredentialSet = wifi_sync::WifiCredential::CredentialSet; 27 using WifiCredentialSet = wifi_sync::WifiCredential::CredentialSet;
23 28
24 namespace wifi_credentials_helper { 29 namespace wifi_credentials_helper {
25 30
26 namespace { 31 namespace {
stevenjb 2015/01/28 21:29:43 WS
mukesh agrawal 2015/01/28 22:55:11 Done.
32 bool SetupClientForProfile(Profile* profile) {
33 #if defined(OS_CHROMEOS)
34 return SetupClientForProfileChromeOs(profile);
35 #else
36 NOTREACHED();
37 return false;
38 #endif
39 }
40
41 WifiCredentialSyncableService* GetServiceForBrowserContext(
42 content::BrowserContext* context) {
43 return WifiCredentialSyncableServiceFactory::GetForBrowserContext(
44 context);
45 }
46
47 WifiCredentialSyncableService* GetServiceForProfile(int profile_index) {
48 return GetServiceForBrowserContext(test()->GetProfile(profile_index));
49 }
50
51 void AddWifiCredentialToProfile(
52 Profile* profile, const WifiCredential& credential) {
53 #if defined(OS_CHROMEOS)
54 AddWifiCredentialToProfileChromeOs(profile, credential);
55 #else
56 NOTREACHED();
57 #endif
58 }
27 59
28 WifiCredentialSet GetWifiCredentialsForProfile(const Profile* profile) { 60 WifiCredentialSet GetWifiCredentialsForProfile(const Profile* profile) {
29 #if defined(OS_CHROMEOS) 61 #if defined(OS_CHROMEOS)
30 return GetWifiCredentialsForProfileChromeOs(profile); 62 return GetWifiCredentialsForProfileChromeOs(profile);
31 #else 63 #else
32 NOTIMPLEMENTED(); 64 NOTREACHED();
33 return WifiCredential::MakeSet(); 65 return WifiCredential::MakeSet();
34 #endif 66 #endif
35 } 67 }
36 68
37 bool CredentialsMatch(const WifiCredentialSet& a_credentials, 69 bool CredentialsMatch(const WifiCredentialSet& a_credentials,
38 const WifiCredentialSet& b_credentials) { 70 const WifiCredentialSet& b_credentials) {
39 if (a_credentials.size() != b_credentials.size()) { 71 if (a_credentials.size() != b_credentials.size()) {
40 LOG(ERROR) << "CredentialSets a and b do not match in size: " 72 LOG(ERROR) << "CredentialSets a and b do not match in size: "
41 << a_credentials.size() 73 << a_credentials.size()
42 << " vs " << b_credentials.size() << " respectively."; 74 << " vs " << b_credentials.size() << " respectively.";
43 return false; 75 return false;
44 } 76 }
45 77
46 for (const auto &credential : a_credentials) { 78 for (const WifiCredential& credential : a_credentials) {
47 if (b_credentials.find(credential) == b_credentials.end()) { 79 if (b_credentials.find(credential) == b_credentials.end()) {
48 LOG(ERROR) 80 LOG(ERROR)
49 << "Network from a not found in b. " 81 << "Network from a not found in b. "
50 << "SSID (hex): " 82 << "SSID (hex): "
51 << base::HexEncode(credential.ssid().data(), 83 << base::HexEncode(credential.ssid().data(),
52 credential.ssid().size()).c_str() 84 credential.ssid().size()).c_str()
53 << " SecurityClass: " << credential.security_class() 85 << " SecurityClass: " << credential.security_class()
54 << " Passphrase: " << credential.passphrase(); 86 << " Passphrase: " << credential.passphrase();
55 return false; 87 return false;
56 } 88 }
57 } 89 }
58 90
59 return true; 91 return true;
60 } 92 }
61 93
62 } // namespace 94 } // namespace
63 95
96 void SetUp() {
97 #if defined(OS_CHROMEOS)
98 return SetUpChromeOs();
stevenjb 2015/01/28 21:29:43 This is a little confusing since it is not defined
mukesh agrawal 2015/01/28 22:55:11 Done.
99 #else
100 NOTREACHED();
101 #endif
102 }
103
104 bool SetupClients() {
105 if (!SetupClientForProfile(test()->verifier()))
106 return false;
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
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 WifiCredential MakeWifiCredential(const std::string& ssid,
148 WifiSecurityClass security_class,
149 const std::string& passphrase) {
150 scoped_ptr<WifiCredential> credential =
151 WifiCredential::Create(
152 WifiCredential::MakeSsidBytesForTest(ssid),
153 security_class,
154 passphrase);
155 CHECK(credential);
156 return *credential;
stevenjb 2015/01/28 21:29:43 The implict copy here is confusing. I would have M
mukesh agrawal 2015/01/28 22:55:11 Done.
157 }
158
159 void AddWifiCredential(int profile_index,
160 const std::string& sync_id,
161 const WifiCredential& credential) {
162 AddWifiCredentialToProfile(test()->GetProfile(profile_index), credential);
163 if (test()->use_verifier())
164 AddWifiCredentialToProfile(test()->verifier(), credential);
165
166 // TODO(quiche): Remove this, once we have plumbing to route
167 // NetworkConfigurationObserver events to
168 // WifiCredentialSyncableService instances.
169 GetServiceForProfile(profile_index)
170 ->AddToSyncedNetworks(sync_id, credential);
171 }
172
95 } // namespace wifi_credentials_helper 173 } // namespace wifi_credentials_helper
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698