Chromium Code Reviews| 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> |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 212 | 212 |
| 213 // Wait for initial sync cycle to be completed. | 213 // Wait for initial sync cycle to be completed. |
| 214 if (!AwaitSyncSetupCompletion()) { | 214 if (!AwaitSyncSetupCompletion()) { |
| 215 LOG(ERROR) << "Initial sync cycle timed out."; | 215 LOG(ERROR) << "Initial sync cycle timed out."; |
| 216 return false; | 216 return false; |
| 217 } | 217 } |
| 218 | 218 |
| 219 return true; | 219 return true; |
| 220 } | 220 } |
| 221 | 221 |
| 222 bool ProfileSyncServiceHarness::SetupSyncForClear() { | |
| 223 bool result = SetupSyncForClear(syncer::UserSelectableTypes()); | |
| 224 if (result == false) { | |
| 225 std::string status = GetServiceStatus(); | |
| 226 LOG(ERROR) << profile_debug_name_ | |
| 227 << ": SetupSyncForClear failed. Syncer status:\n" | |
| 228 << status; | |
| 229 } else { | |
| 230 DVLOG(1) << profile_debug_name_ << ": SetupSyncForClear successful."; | |
| 231 } | |
| 232 return result; | |
| 233 } | |
| 234 | |
| 235 bool ProfileSyncServiceHarness::SetupSyncForClear( | |
|
pavely
2017/03/07 07:26:15
This function is awfully similar to SetupSync(). I
skym
2017/03/07 18:38:22
+1
wylieb
2017/03/07 19:52:22
Well that depends. If they want to change the the
| |
| 236 syncer::ModelTypeSet synced_datatypes) { | |
| 237 DCHECK(!profile_->IsLegacySupervised()) | |
| 238 << "SetupSync should not be used for legacy supervised users."; | |
| 239 | |
| 240 // Initialize the sync client's profile sync service object. | |
| 241 if (service() == nullptr) { | |
| 242 LOG(ERROR) << "SetupSync(): service() is null."; | |
| 243 return false; | |
| 244 } | |
| 245 | |
| 246 // Tell the sync service that setup is in progress so we don't start syncing | |
| 247 // until we've finished configuration. | |
| 248 sync_blocker_ = service()->GetSetupInProgressHandle(); | |
| 249 | |
| 250 DCHECK(!username_.empty()); | |
| 251 if (signin_type_ == SigninType::UI_SIGNIN) { | |
| 252 Browser* browser = chrome::FindBrowserWithProfile(profile_); | |
| 253 DCHECK(browser); | |
| 254 if (!login_ui_test_utils::SignInWithUI(browser, username_, password_)) { | |
| 255 LOG(ERROR) << "Could not sign in to GAIA servers."; | |
| 256 return false; | |
| 257 } | |
| 258 } else if (signin_type_ == SigninType::FAKE_SIGNIN) { | |
| 259 // Authenticate sync client using GAIA credentials. | |
| 260 std::string gaia_id = GetGaiaIdForUsername(username_); | |
| 261 service()->signin()->SetAuthenticatedAccountInfo(gaia_id, username_); | |
| 262 std::string account_id = service()->signin()->GetAuthenticatedAccountId(); | |
| 263 service()->GoogleSigninSucceeded(account_id, username_, password_); | |
| 264 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_) | |
| 265 ->UpdateCredentials(account_id, GenerateFakeOAuth2RefreshTokenString()); | |
| 266 } else { | |
| 267 LOG(ERROR) << "Unsupported profile signin type."; | |
| 268 } | |
| 269 | |
| 270 // Now that auth is completed, request that sync actually start. | |
| 271 service()->RequestStart(); | |
| 272 | |
| 273 if (!AwaitEngineInitializationForClear()) { | |
| 274 return false; | |
| 275 } | |
| 276 | |
| 277 // Choose the datatypes to be synced. If all datatypes are to be synced, | |
| 278 // set sync_everything to true; otherwise, set it to false. | |
| 279 bool sync_everything = (synced_datatypes == syncer::UserSelectableTypes()); | |
| 280 service()->OnUserChoseDatatypes(sync_everything, synced_datatypes); | |
| 281 | |
| 282 // Notify ProfileSyncService that we are done with configuration. | |
| 283 FinishSyncSetup(); | |
| 284 | |
| 285 if ((signin_type_ == SigninType::UI_SIGNIN) && | |
| 286 !login_ui_test_utils::DismissSyncConfirmationDialog( | |
| 287 chrome::FindBrowserWithProfile(profile_), | |
| 288 base::TimeDelta::FromSeconds(30))) { | |
| 289 LOG(ERROR) << "Failed to dismiss sync confirmation dialog."; | |
| 290 return false; | |
| 291 } | |
| 292 | |
| 293 // Wait for initial sync cycle to be completed. | |
| 294 if (!AwaitSyncSetupCompletionForClear()) { | |
| 295 LOG(ERROR) << "Initial sync cycle timed out."; | |
| 296 return false; | |
| 297 } | |
| 298 | |
| 299 return true; | |
| 300 } | |
| 301 | |
| 302 bool ProfileSyncServiceHarness::RestartSyncService() { | |
| 303 std::unique_ptr<syncer::SyncSetupInProgressHandle> blocker = | |
|
skym
2017/03/07 18:38:22
Is there a reason that |sync_blocker_| isn't used?
wylieb
2017/03/07 19:52:22
Done.
| |
| 304 service()->GetSetupInProgressHandle(); | |
| 305 | |
|
skym
2017/03/07 18:38:22
So
wylieb
2017/03/07 19:52:22
Ok
| |
| 306 DVLOG(1) << "Requesting stop for service."; | |
| 307 | |
|
skym
2017/03/07 18:38:22
many
wylieb
2017/03/07 19:52:22
I
| |
| 308 service()->RequestStop(ProfileSyncService::CLEAR_DATA); | |
| 309 | |
|
skym
2017/03/07 18:38:22
new
wylieb
2017/03/07 19:52:22
Fixed
| |
| 310 DVLOG(1) << "Requesting start for service"; | |
| 311 | |
|
skym
2017/03/07 18:38:22
lines
wylieb
2017/03/07 19:52:22
It
| |
| 312 service()->RequestStart(); | |
| 313 if (!AwaitEngineInitialization()) { | |
|
skym
2017/03/07 18:38:22
We should also always require a passphrase, right?
wylieb
2017/03/07 19:52:22
Done.
| |
| 314 LOG(ERROR) << "AwaitEngineInitialization failed."; | |
| 315 return false; | |
| 316 } | |
| 317 | |
| 318 DVLOG(1) << "Releasing blocker and setting first setup complete"; | |
| 319 | |
| 320 blocker.reset(); | |
| 321 service()->SetFirstSetupComplete(); | |
| 322 | |
| 323 return true; | |
| 324 } | |
| 325 | |
| 222 bool ProfileSyncServiceHarness::AwaitMutualSyncCycleCompletion( | 326 bool ProfileSyncServiceHarness::AwaitMutualSyncCycleCompletion( |
| 223 ProfileSyncServiceHarness* partner) { | 327 ProfileSyncServiceHarness* partner) { |
| 224 std::vector<ProfileSyncServiceHarness*> harnesses; | 328 std::vector<ProfileSyncServiceHarness*> harnesses; |
| 225 harnesses.push_back(this); | 329 harnesses.push_back(this); |
| 226 harnesses.push_back(partner); | 330 harnesses.push_back(partner); |
| 227 return AwaitQuiescence(harnesses); | 331 return AwaitQuiescence(harnesses); |
| 228 } | 332 } |
| 229 | 333 |
| 230 bool ProfileSyncServiceHarness::AwaitGroupSyncCycleCompletion( | 334 bool ProfileSyncServiceHarness::AwaitGroupSyncCycleCompletion( |
| 231 const std::vector<ProfileSyncServiceHarness*>& partners) { | 335 const std::vector<ProfileSyncServiceHarness*>& partners) { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 265 } | 369 } |
| 266 | 370 |
| 267 if (HasAuthError(service())) { | 371 if (HasAuthError(service())) { |
| 268 LOG(ERROR) << "Credentials were rejected. Sync cannot proceed."; | 372 LOG(ERROR) << "Credentials were rejected. Sync cannot proceed."; |
| 269 return false; | 373 return false; |
| 270 } | 374 } |
| 271 | 375 |
| 272 return true; | 376 return true; |
| 273 } | 377 } |
| 274 | 378 |
| 379 bool ProfileSyncServiceHarness::AwaitEngineInitializationForClear() { | |
| 380 if (!EngineInitializeChecker(service()).Wait()) { | |
| 381 LOG(ERROR) << "EngineInitializeChecker timed out."; | |
| 382 return false; | |
| 383 } | |
| 384 | |
| 385 if (!service()->IsEngineInitialized()) { | |
| 386 LOG(ERROR) << "Service engine not initialized."; | |
| 387 return false; | |
| 388 } | |
| 389 | |
| 390 if (HasAuthError(service())) { | |
| 391 LOG(ERROR) << "Credentials were rejected. Sync cannot proceed."; | |
| 392 return false; | |
| 393 } | |
| 394 | |
| 395 return true; | |
| 396 } | |
| 397 | |
| 275 bool ProfileSyncServiceHarness::AwaitSyncSetupCompletion() { | 398 bool ProfileSyncServiceHarness::AwaitSyncSetupCompletion() { |
|
skym
2017/03/07 18:38:22
Do you understand why this method even exists? As
skym
2017/03/07 18:47:44
Oooh, I missed that the first check was significan
wylieb
2017/03/07 19:52:22
Done.
wylieb
2017/03/07 19:52:22
Done.
| |
| 276 if (!SyncSetupChecker(service()).Wait()) { | 399 if (!SyncSetupChecker(service()).Wait()) { |
| 277 LOG(ERROR) << "SyncSetupChecker timed out."; | 400 LOG(ERROR) << "SyncSetupChecker timed out."; |
| 278 return false; | 401 return false; |
| 279 } | 402 } |
| 280 | 403 |
| 281 // Make sure that initial sync wasn't blocked by a missing passphrase. | 404 // Make sure that initial sync wasn't blocked by a missing passphrase. |
| 282 if (service()->passphrase_required_reason() == syncer::REASON_DECRYPTION) { | 405 if (service()->passphrase_required_reason() == syncer::REASON_DECRYPTION) { |
| 283 LOG(ERROR) << "A passphrase is required for decryption. Sync cannot proceed" | 406 LOG(ERROR) << "A passphrase is required for decryption. Sync cannot proceed" |
| 284 " until SetDecryptionPassphrase is called."; | 407 " until SetDecryptionPassphrase is called."; |
| 285 return false; | 408 return false; |
| 286 } | 409 } |
| 287 | 410 |
| 288 if (HasAuthError(service())) { | 411 if (HasAuthError(service())) { |
| 289 LOG(ERROR) << "Credentials were rejected. Sync cannot proceed."; | 412 LOG(ERROR) << "Credentials were rejected. Sync cannot proceed."; |
| 290 return false; | 413 return false; |
| 291 } | 414 } |
| 292 | 415 |
| 293 return true; | 416 return true; |
| 294 } | 417 } |
| 295 | 418 |
| 419 bool ProfileSyncServiceHarness::AwaitSyncSetupCompletionForClear() { | |
| 420 if (!SyncSetupChecker(service()).Wait()) { | |
| 421 LOG(ERROR) << "SyncSetupChecker timed out."; | |
| 422 return false; | |
| 423 } | |
| 424 | |
| 425 if (HasAuthError(service())) { | |
| 426 LOG(ERROR) << "Credentials were rejected. Sync cannot proceed."; | |
| 427 return false; | |
| 428 } | |
| 429 | |
| 430 return true; | |
| 431 } | |
| 432 | |
| 296 std::string ProfileSyncServiceHarness::GenerateFakeOAuth2RefreshTokenString() { | 433 std::string ProfileSyncServiceHarness::GenerateFakeOAuth2RefreshTokenString() { |
| 297 return base::StringPrintf("oauth2_refresh_token_%d", | 434 return base::StringPrintf("oauth2_refresh_token_%d", |
| 298 ++oauth2_refesh_token_number_); | 435 ++oauth2_refesh_token_number_); |
| 299 } | 436 } |
| 300 | 437 |
| 301 bool ProfileSyncServiceHarness::IsSyncDisabled() const { | 438 bool ProfileSyncServiceHarness::IsSyncDisabled() const { |
| 302 return !service()->IsSetupInProgress() && !service()->IsFirstSetupComplete(); | 439 return !service()->IsSetupInProgress() && !service()->IsFirstSetupComplete(); |
| 303 } | 440 } |
| 304 | 441 |
| 305 void ProfileSyncServiceHarness::FinishSyncSetup() { | 442 void ProfileSyncServiceHarness::FinishSyncSetup() { |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 476 | 613 |
| 477 std::string ProfileSyncServiceHarness::GetServiceStatus() { | 614 std::string ProfileSyncServiceHarness::GetServiceStatus() { |
| 478 std::unique_ptr<base::DictionaryValue> value( | 615 std::unique_ptr<base::DictionaryValue> value( |
| 479 syncer::sync_ui_util::ConstructAboutInformation( | 616 syncer::sync_ui_util::ConstructAboutInformation( |
| 480 service(), service()->signin(), chrome::GetChannel())); | 617 service(), service()->signin(), chrome::GetChannel())); |
| 481 std::string service_status; | 618 std::string service_status; |
| 482 base::JSONWriter::WriteWithOptions( | 619 base::JSONWriter::WriteWithOptions( |
| 483 *value, base::JSONWriter::OPTIONS_PRETTY_PRINT, &service_status); | 620 *value, base::JSONWriter::OPTIONS_PRETTY_PRINT, &service_status); |
| 484 return service_status; | 621 return service_status; |
| 485 } | 622 } |
| OLD | NEW |