OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/profile_sync_service_harness.h" | 5 #include "chrome/browser/sync/test/integration/profile_sync_service_harness.h" |
6 | 6 |
7 #include <cstddef> | 7 #include <cstddef> |
8 #include <iterator> | 8 #include <iterator> |
9 #include <ostream> | 9 #include <ostream> |
10 #include <sstream> | 10 #include <sstream> |
11 | 11 |
12 #include "base/json/json_writer.h" | 12 #include "base/json/json_writer.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "base/strings/stringprintf.h" | 14 #include "base/strings/stringprintf.h" |
15 | |
pavely
2017/03/10 21:08:20
No new line here. base is part of chromium project
| |
15 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
16 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 17 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
17 #include "chrome/browser/sync/profile_sync_service_factory.h" | 18 #include "chrome/browser/sync/profile_sync_service_factory.h" |
18 #include "chrome/browser/sync/test/integration/quiesce_status_change_checker.h" | 19 #include "chrome/browser/sync/test/integration/quiesce_status_change_checker.h" |
19 #include "chrome/browser/sync/test/integration/single_client_status_change_check er.h" | 20 #include "chrome/browser/sync/test/integration/single_client_status_change_check er.h" |
20 #include "chrome/browser/ui/browser.h" | 21 #include "chrome/browser/ui/browser.h" |
21 #include "chrome/browser/ui/browser_finder.h" | 22 #include "chrome/browser/ui/browser_finder.h" |
23 #include "chrome/browser/ui/webui/signin/login_ui_service.h" | |
24 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" | |
22 #include "chrome/browser/ui/webui/signin/login_ui_test_utils.h" | 25 #include "chrome/browser/ui/webui/signin/login_ui_test_utils.h" |
23 #include "chrome/common/channel_info.h" | 26 #include "chrome/common/channel_info.h" |
24 #include "chrome/common/chrome_switches.h" | 27 #include "chrome/common/chrome_switches.h" |
25 #include "components/browser_sync/profile_sync_service.h" | 28 #include "components/browser_sync/profile_sync_service.h" |
26 #include "components/invalidation/impl/p2p_invalidation_service.h" | 29 #include "components/invalidation/impl/p2p_invalidation_service.h" |
27 #include "components/signin/core/browser/profile_oauth2_token_service.h" | 30 #include "components/signin/core/browser/profile_oauth2_token_service.h" |
28 #include "components/signin/core/browser/signin_manager_base.h" | 31 #include "components/signin/core/browser/signin_manager_base.h" |
29 #include "components/sync/base/progress_marker_map.h" | 32 #include "components/sync/base/progress_marker_map.h" |
30 #include "components/sync/driver/about_sync_util.h" | 33 #include "components/sync/driver/about_sync_util.h" |
31 #include "components/sync/engine/sync_string_conversions.h" | 34 #include "components/sync/engine/sync_string_conversions.h" |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
123 | 126 |
124 ProfileSyncServiceHarness::~ProfileSyncServiceHarness() { } | 127 ProfileSyncServiceHarness::~ProfileSyncServiceHarness() { } |
125 | 128 |
126 void ProfileSyncServiceHarness::SetCredentials(const std::string& username, | 129 void ProfileSyncServiceHarness::SetCredentials(const std::string& username, |
127 const std::string& password) { | 130 const std::string& password) { |
128 username_ = username; | 131 username_ = username; |
129 password_ = password; | 132 password_ = password; |
130 } | 133 } |
131 | 134 |
132 bool ProfileSyncServiceHarness::SetupSync() { | 135 bool ProfileSyncServiceHarness::SetupSync() { |
133 bool result = SetupSync(syncer::UserSelectableTypes()); | 136 bool result = SetupSync(syncer::UserSelectableTypes(), false); |
134 if (result == false) { | 137 if (!result) { |
135 std::string status = GetServiceStatus(); | 138 LOG(ERROR) << profile_debug_name_ << ": SetupSync failed. Syncer status:\n" |
136 LOG(ERROR) << profile_debug_name_ | 139 << GetServiceStatus(); |
137 << ": SetupSync failed. Syncer status:\n" << status; | |
138 } else { | 140 } else { |
139 DVLOG(1) << profile_debug_name_ << ": SetupSync successful."; | 141 DVLOG(1) << profile_debug_name_ << ": SetupSync successful."; |
140 } | 142 } |
141 return result; | 143 return result; |
142 } | 144 } |
143 | 145 |
144 bool ProfileSyncServiceHarness::SetupSync( | 146 bool ProfileSyncServiceHarness::SetupSyncForClearingServerData() { |
145 syncer::ModelTypeSet synced_datatypes) { | 147 bool result = SetupSync(syncer::UserSelectableTypes(), true); |
148 if (!result) { | |
149 LOG(ERROR) << profile_debug_name_ | |
150 << ": SetupSyncForClear failed. Syncer status:\n" | |
151 << GetServiceStatus(); | |
152 } else { | |
153 DVLOG(1) << profile_debug_name_ << ": SetupSyncForClear successful."; | |
154 } | |
155 return result; | |
156 } | |
157 | |
158 bool ProfileSyncServiceHarness::SetupSync(syncer::ModelTypeSet synced_datatypes, | |
159 bool skip_passphrase_verification) { | |
146 DCHECK(!profile_->IsLegacySupervised()) | 160 DCHECK(!profile_->IsLegacySupervised()) |
147 << "SetupSync should not be used for legacy supervised users."; | 161 << "SetupSync should not be used for legacy supervised users."; |
148 | 162 |
149 // Initialize the sync client's profile sync service object. | 163 // Initialize the sync client's profile sync service object. |
150 if (service() == nullptr) { | 164 if (service() == nullptr) { |
151 LOG(ERROR) << "SetupSync(): service() is null."; | 165 LOG(ERROR) << "SetupSync(): service() is null."; |
152 return false; | 166 return false; |
153 } | 167 } |
154 | 168 |
155 // Tell the sync service that setup is in progress so we don't start syncing | 169 // Tell the sync service that setup is in progress so we don't start syncing |
(...skipping 16 matching lines...) Expand all Loading... | |
172 service()->GoogleSigninSucceeded(account_id, username_, password_); | 186 service()->GoogleSigninSucceeded(account_id, username_, password_); |
173 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_)-> | 187 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_)-> |
174 UpdateCredentials(account_id, GenerateFakeOAuth2RefreshTokenString()); | 188 UpdateCredentials(account_id, GenerateFakeOAuth2RefreshTokenString()); |
175 } else { | 189 } else { |
176 LOG(ERROR) << "Unsupported profile signin type."; | 190 LOG(ERROR) << "Unsupported profile signin type."; |
177 } | 191 } |
178 | 192 |
179 // Now that auth is completed, request that sync actually start. | 193 // Now that auth is completed, request that sync actually start. |
180 service()->RequestStart(); | 194 service()->RequestStart(); |
181 | 195 |
182 if (!AwaitEngineInitialization()) { | 196 if (!AwaitEngineInitialization(skip_passphrase_verification)) { |
183 return false; | 197 return false; |
184 } | 198 } |
185 | |
186 // Choose the datatypes to be synced. If all datatypes are to be synced, | 199 // Choose the datatypes to be synced. If all datatypes are to be synced, |
187 // set sync_everything to true; otherwise, set it to false. | 200 // set sync_everything to true; otherwise, set it to false. |
188 bool sync_everything = (synced_datatypes == syncer::UserSelectableTypes()); | 201 bool sync_everything = (synced_datatypes == syncer::UserSelectableTypes()); |
189 service()->OnUserChoseDatatypes(sync_everything, synced_datatypes); | 202 service()->OnUserChoseDatatypes(sync_everything, synced_datatypes); |
190 | 203 |
191 // Notify ProfileSyncService that we are done with configuration. | 204 // Notify ProfileSyncService that we are done with configuration. |
192 FinishSyncSetup(); | 205 if (skip_passphrase_verification) { |
206 sync_blocker_.reset(); | |
207 } else { | |
208 FinishSyncSetup(); | |
209 } | |
193 | 210 |
194 if ((signin_type_ == SigninType::UI_SIGNIN) && | 211 if ((signin_type_ == SigninType::UI_SIGNIN) && |
195 !login_ui_test_utils::DismissSyncConfirmationDialog( | 212 !login_ui_test_utils::DismissSyncConfirmationDialog( |
196 chrome::FindBrowserWithProfile(profile_), | 213 chrome::FindBrowserWithProfile(profile_), |
197 base::TimeDelta::FromSeconds(30))) { | 214 base::TimeDelta::FromSeconds(30))) { |
198 LOG(ERROR) << "Failed to dismiss sync confirmation dialog."; | 215 LOG(ERROR) << "Failed to dismiss sync confirmation dialog."; |
199 return false; | 216 return false; |
200 } | 217 } |
201 | 218 |
219 // OneClickSigninSyncStarter observer is created with a real user sign in. | |
220 // It is deleted on certain conditions which are not satisfied by our tests, | |
221 // and this causes the SigninTracker observer to stay hanging at shutdown. | |
222 // Calling LoginUIService::SyncConfirmationUIClosed forces the observer to | |
223 // be removed. http://crbug.com/484388 | |
224 if (signin_type_ == SigninType::UI_SIGNIN) { | |
225 LoginUIServiceFactory::GetForProfile(profile_)->SyncConfirmationUIClosed( | |
pavely
2017/03/10 21:08:20
This call is copy/pasted from SyncTest::SetupSync.
wylieb
2017/03/10 21:16:30
No, I moved it here because it was causing timeout
| |
226 LoginUIService::SYNC_WITH_DEFAULT_SETTINGS); | |
227 } | |
228 | |
229 if (skip_passphrase_verification) { | |
pavely
2017/03/10 21:08:20
From this line till the end of the function refere
wylieb
2017/03/10 21:16:30
I think you're right. I removed the argument, and
| |
230 return true; | |
231 } | |
232 | |
202 // Set an implicit passphrase for encryption if an explicit one hasn't already | 233 // Set an implicit passphrase for encryption if an explicit one hasn't already |
203 // been set. If an explicit passphrase has been set, immediately return false, | 234 // been set. If an explicit passphrase has been set, immediately return false, |
204 // since a decryption passphrase is required. | 235 // since a decryption passphrase is required. |
236 if (!skip_passphrase_verification && | |
237 !service()->IsUsingSecondaryPassphrase()) { | |
238 service()->SetEncryptionPassphrase(password_, ProfileSyncService::IMPLICIT); | |
239 } else if (!skip_passphrase_verification) { | |
240 LOG(ERROR) << "A passphrase is required for decryption. Sync cannot proceed" | |
241 " until SetDecryptionPassphrase is called."; | |
242 return false; | |
243 } | |
244 | |
245 // Wait for initial sync cycle to be completed. | |
246 if (!AwaitSyncSetupCompletion(skip_passphrase_verification)) { | |
247 return false; | |
248 } | |
249 | |
250 return true; | |
251 } | |
252 | |
253 bool ProfileSyncServiceHarness::RestartSyncService() { | |
254 DVLOG(1) << "Requesting stop for service."; | |
255 service()->RequestStop(ProfileSyncService::CLEAR_DATA); | |
256 | |
257 std::unique_ptr<syncer::SyncSetupInProgressHandle> blocker = | |
258 service()->GetSetupInProgressHandle(); | |
259 DVLOG(1) << "Requesting start for service"; | |
260 service()->RequestStart(); | |
261 | |
262 if (!AwaitEngineInitialization()) { | |
263 LOG(ERROR) << "AwaitEngineInitialization failed."; | |
264 return false; | |
265 } | |
266 DVLOG(1) << "Engine Initialized successfully."; | |
267 | |
268 // This passphrase should be implicit because ClearServerData should be called | |
269 // prior. | |
205 if (!service()->IsUsingSecondaryPassphrase()) { | 270 if (!service()->IsUsingSecondaryPassphrase()) { |
206 service()->SetEncryptionPassphrase(password_, ProfileSyncService::IMPLICIT); | 271 service()->SetEncryptionPassphrase(password_, ProfileSyncService::IMPLICIT); |
207 } else { | 272 } else { |
208 LOG(ERROR) << "A passphrase is required for decryption. Sync cannot proceed" | 273 LOG(ERROR) << "A passphrase is required for decryption. Sync cannot proceed" |
209 " until SetDecryptionPassphrase is called."; | 274 " until SetDecryptionPassphrase is called."; |
210 return false; | 275 return false; |
211 } | 276 } |
277 DVLOG(1) << "Passphrase decryption success."; | |
212 | 278 |
213 // Wait for initial sync cycle to be completed. | 279 blocker.reset(); |
280 service()->SetFirstSetupComplete(); | |
281 | |
214 if (!AwaitSyncSetupCompletion()) { | 282 if (!AwaitSyncSetupCompletion()) { |
215 LOG(ERROR) << "Initial sync cycle timed out."; | 283 LOG(FATAL) << "AwaitSyncSetupCompletion failed."; |
216 return false; | 284 return false; |
217 } | 285 } |
218 | 286 |
219 return true; | 287 return true; |
220 } | 288 } |
221 | 289 |
222 bool ProfileSyncServiceHarness::AwaitMutualSyncCycleCompletion( | 290 bool ProfileSyncServiceHarness::AwaitMutualSyncCycleCompletion( |
223 ProfileSyncServiceHarness* partner) { | 291 ProfileSyncServiceHarness* partner) { |
224 std::vector<ProfileSyncServiceHarness*> harnesses; | 292 std::vector<ProfileSyncServiceHarness*> harnesses; |
225 harnesses.push_back(this); | 293 harnesses.push_back(this); |
(...skipping 13 matching lines...) Expand all Loading... | |
239 if (clients.empty()) { | 307 if (clients.empty()) { |
240 return true; | 308 return true; |
241 } | 309 } |
242 | 310 |
243 for (const ProfileSyncServiceHarness* harness : clients) { | 311 for (const ProfileSyncServiceHarness* harness : clients) { |
244 services.push_back(harness->service()); | 312 services.push_back(harness->service()); |
245 } | 313 } |
246 return QuiesceStatusChangeChecker(services).Wait(); | 314 return QuiesceStatusChangeChecker(services).Wait(); |
247 } | 315 } |
248 | 316 |
249 bool ProfileSyncServiceHarness::AwaitEngineInitialization() { | 317 bool ProfileSyncServiceHarness::AwaitEngineInitialization( |
318 bool skip_passphrase_verification) { | |
250 if (!EngineInitializeChecker(service()).Wait()) { | 319 if (!EngineInitializeChecker(service()).Wait()) { |
251 LOG(ERROR) << "EngineInitializeChecker timed out."; | 320 LOG(ERROR) << "EngineInitializeChecker timed out."; |
252 return false; | 321 return false; |
253 } | 322 } |
254 | 323 |
255 if (!service()->IsEngineInitialized()) { | 324 if (!service()->IsEngineInitialized()) { |
256 LOG(ERROR) << "Service engine not initialized."; | 325 LOG(ERROR) << "Service engine not initialized."; |
257 return false; | 326 return false; |
258 } | 327 } |
259 | 328 |
260 // Make sure that initial sync wasn't blocked by a missing passphrase. | 329 // Make sure that initial sync wasn't blocked by a missing passphrase. |
261 if (service()->passphrase_required_reason() == syncer::REASON_DECRYPTION) { | 330 if (!skip_passphrase_verification && |
331 service()->passphrase_required_reason() == syncer::REASON_DECRYPTION) { | |
262 LOG(ERROR) << "A passphrase is required for decryption. Sync cannot proceed" | 332 LOG(ERROR) << "A passphrase is required for decryption. Sync cannot proceed" |
263 " until SetDecryptionPassphrase is called."; | 333 " until SetDecryptionPassphrase is called."; |
264 return false; | 334 return false; |
265 } | 335 } |
266 | 336 |
267 if (HasAuthError(service())) { | 337 if (HasAuthError(service())) { |
268 LOG(ERROR) << "Credentials were rejected. Sync cannot proceed."; | 338 LOG(ERROR) << "Credentials were rejected. Sync cannot proceed."; |
269 return false; | 339 return false; |
270 } | 340 } |
271 | 341 |
272 return true; | 342 return true; |
273 } | 343 } |
274 | 344 |
275 bool ProfileSyncServiceHarness::AwaitSyncSetupCompletion() { | 345 bool ProfileSyncServiceHarness::AwaitSyncSetupCompletion( |
346 bool skip_passphrase_verification) { | |
276 if (!SyncSetupChecker(service()).Wait()) { | 347 if (!SyncSetupChecker(service()).Wait()) { |
277 LOG(ERROR) << "SyncSetupChecker timed out."; | 348 LOG(ERROR) << "SyncSetupChecker timed out."; |
278 return false; | 349 return false; |
279 } | 350 } |
280 | 351 |
281 // Make sure that initial sync wasn't blocked by a missing passphrase. | 352 // Make sure that initial sync wasn't blocked by a missing passphrase. |
282 if (service()->passphrase_required_reason() == syncer::REASON_DECRYPTION) { | 353 if (!skip_passphrase_verification && |
354 service()->passphrase_required_reason() == syncer::REASON_DECRYPTION) { | |
283 LOG(ERROR) << "A passphrase is required for decryption. Sync cannot proceed" | 355 LOG(ERROR) << "A passphrase is required for decryption. Sync cannot proceed" |
284 " until SetDecryptionPassphrase is called."; | 356 " until SetDecryptionPassphrase is called."; |
285 return false; | 357 return false; |
286 } | 358 } |
287 | 359 |
288 if (HasAuthError(service())) { | 360 if (HasAuthError(service())) { |
289 LOG(ERROR) << "Credentials were rejected. Sync cannot proceed."; | 361 LOG(ERROR) << "Credentials were rejected. Sync cannot proceed."; |
290 return false; | 362 return false; |
291 } | 363 } |
292 | 364 |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
476 | 548 |
477 std::string ProfileSyncServiceHarness::GetServiceStatus() { | 549 std::string ProfileSyncServiceHarness::GetServiceStatus() { |
478 std::unique_ptr<base::DictionaryValue> value( | 550 std::unique_ptr<base::DictionaryValue> value( |
479 syncer::sync_ui_util::ConstructAboutInformation( | 551 syncer::sync_ui_util::ConstructAboutInformation( |
480 service(), service()->signin(), chrome::GetChannel())); | 552 service(), service()->signin(), chrome::GetChannel())); |
481 std::string service_status; | 553 std::string service_status; |
482 base::JSONWriter::WriteWithOptions( | 554 base::JSONWriter::WriteWithOptions( |
483 *value, base::JSONWriter::OPTIONS_PRETTY_PRINT, &service_status); | 555 *value, base::JSONWriter::OPTIONS_PRETTY_PRINT, &service_status); |
484 return service_status; | 556 return service_status; |
485 } | 557 } |
OLD | NEW |