Index: chrome/browser/sync/test/integration/profile_sync_service_harness.cc |
diff --git a/chrome/browser/sync/test/integration/profile_sync_service_harness.cc b/chrome/browser/sync/test/integration/profile_sync_service_harness.cc |
index 97f45645a54a9bc05db265383cc7f7fa1849b5c1..c89ee553144a4af58f5c0246a4e33b78014530cf 100644 |
--- a/chrome/browser/sync/test/integration/profile_sync_service_harness.cc |
+++ b/chrome/browser/sync/test/integration/profile_sync_service_harness.cc |
@@ -12,6 +12,7 @@ |
#include "base/json/json_writer.h" |
#include "base/logging.h" |
#include "base/strings/stringprintf.h" |
+ |
pavely
2017/03/10 21:08:20
No new line here. base is part of chromium project
|
#include "chrome/browser/profiles/profile.h" |
#include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
#include "chrome/browser/sync/profile_sync_service_factory.h" |
@@ -19,6 +20,8 @@ |
#include "chrome/browser/sync/test/integration/single_client_status_change_checker.h" |
#include "chrome/browser/ui/browser.h" |
#include "chrome/browser/ui/browser_finder.h" |
+#include "chrome/browser/ui/webui/signin/login_ui_service.h" |
+#include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" |
#include "chrome/browser/ui/webui/signin/login_ui_test_utils.h" |
#include "chrome/common/channel_info.h" |
#include "chrome/common/chrome_switches.h" |
@@ -130,19 +133,30 @@ void ProfileSyncServiceHarness::SetCredentials(const std::string& username, |
} |
bool ProfileSyncServiceHarness::SetupSync() { |
- bool result = SetupSync(syncer::UserSelectableTypes()); |
- if (result == false) { |
- std::string status = GetServiceStatus(); |
- LOG(ERROR) << profile_debug_name_ |
- << ": SetupSync failed. Syncer status:\n" << status; |
+ bool result = SetupSync(syncer::UserSelectableTypes(), false); |
+ if (!result) { |
+ LOG(ERROR) << profile_debug_name_ << ": SetupSync failed. Syncer status:\n" |
+ << GetServiceStatus(); |
} else { |
DVLOG(1) << profile_debug_name_ << ": SetupSync successful."; |
} |
return result; |
} |
-bool ProfileSyncServiceHarness::SetupSync( |
- syncer::ModelTypeSet synced_datatypes) { |
+bool ProfileSyncServiceHarness::SetupSyncForClearingServerData() { |
+ bool result = SetupSync(syncer::UserSelectableTypes(), true); |
+ if (!result) { |
+ LOG(ERROR) << profile_debug_name_ |
+ << ": SetupSyncForClear failed. Syncer status:\n" |
+ << GetServiceStatus(); |
+ } else { |
+ DVLOG(1) << profile_debug_name_ << ": SetupSyncForClear successful."; |
+ } |
+ return result; |
+} |
+ |
+bool ProfileSyncServiceHarness::SetupSync(syncer::ModelTypeSet synced_datatypes, |
+ bool skip_passphrase_verification) { |
DCHECK(!profile_->IsLegacySupervised()) |
<< "SetupSync should not be used for legacy supervised users."; |
@@ -179,17 +193,20 @@ bool ProfileSyncServiceHarness::SetupSync( |
// Now that auth is completed, request that sync actually start. |
service()->RequestStart(); |
- if (!AwaitEngineInitialization()) { |
+ if (!AwaitEngineInitialization(skip_passphrase_verification)) { |
return false; |
} |
- |
// Choose the datatypes to be synced. If all datatypes are to be synced, |
// set sync_everything to true; otherwise, set it to false. |
bool sync_everything = (synced_datatypes == syncer::UserSelectableTypes()); |
service()->OnUserChoseDatatypes(sync_everything, synced_datatypes); |
// Notify ProfileSyncService that we are done with configuration. |
- FinishSyncSetup(); |
+ if (skip_passphrase_verification) { |
+ sync_blocker_.reset(); |
+ } else { |
+ FinishSyncSetup(); |
+ } |
if ((signin_type_ == SigninType::UI_SIGNIN) && |
!login_ui_test_utils::DismissSyncConfirmationDialog( |
@@ -199,9 +216,57 @@ bool ProfileSyncServiceHarness::SetupSync( |
return false; |
} |
+ // OneClickSigninSyncStarter observer is created with a real user sign in. |
+ // It is deleted on certain conditions which are not satisfied by our tests, |
+ // and this causes the SigninTracker observer to stay hanging at shutdown. |
+ // Calling LoginUIService::SyncConfirmationUIClosed forces the observer to |
+ // be removed. http://crbug.com/484388 |
+ if (signin_type_ == SigninType::UI_SIGNIN) { |
+ 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
|
+ LoginUIService::SYNC_WITH_DEFAULT_SETTINGS); |
+ } |
+ |
+ 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
|
+ return true; |
+ } |
+ |
// Set an implicit passphrase for encryption if an explicit one hasn't already |
// been set. If an explicit passphrase has been set, immediately return false, |
// since a decryption passphrase is required. |
+ if (!skip_passphrase_verification && |
+ !service()->IsUsingSecondaryPassphrase()) { |
+ service()->SetEncryptionPassphrase(password_, ProfileSyncService::IMPLICIT); |
+ } else if (!skip_passphrase_verification) { |
+ LOG(ERROR) << "A passphrase is required for decryption. Sync cannot proceed" |
+ " until SetDecryptionPassphrase is called."; |
+ return false; |
+ } |
+ |
+ // Wait for initial sync cycle to be completed. |
+ if (!AwaitSyncSetupCompletion(skip_passphrase_verification)) { |
+ return false; |
+ } |
+ |
+ return true; |
+} |
+ |
+bool ProfileSyncServiceHarness::RestartSyncService() { |
+ DVLOG(1) << "Requesting stop for service."; |
+ service()->RequestStop(ProfileSyncService::CLEAR_DATA); |
+ |
+ std::unique_ptr<syncer::SyncSetupInProgressHandle> blocker = |
+ service()->GetSetupInProgressHandle(); |
+ DVLOG(1) << "Requesting start for service"; |
+ service()->RequestStart(); |
+ |
+ if (!AwaitEngineInitialization()) { |
+ LOG(ERROR) << "AwaitEngineInitialization failed."; |
+ return false; |
+ } |
+ DVLOG(1) << "Engine Initialized successfully."; |
+ |
+ // This passphrase should be implicit because ClearServerData should be called |
+ // prior. |
if (!service()->IsUsingSecondaryPassphrase()) { |
service()->SetEncryptionPassphrase(password_, ProfileSyncService::IMPLICIT); |
} else { |
@@ -209,10 +274,13 @@ bool ProfileSyncServiceHarness::SetupSync( |
" until SetDecryptionPassphrase is called."; |
return false; |
} |
+ DVLOG(1) << "Passphrase decryption success."; |
+ |
+ blocker.reset(); |
+ service()->SetFirstSetupComplete(); |
- // Wait for initial sync cycle to be completed. |
if (!AwaitSyncSetupCompletion()) { |
- LOG(ERROR) << "Initial sync cycle timed out."; |
+ LOG(FATAL) << "AwaitSyncSetupCompletion failed."; |
return false; |
} |
@@ -246,7 +314,8 @@ bool ProfileSyncServiceHarness::AwaitQuiescence( |
return QuiesceStatusChangeChecker(services).Wait(); |
} |
-bool ProfileSyncServiceHarness::AwaitEngineInitialization() { |
+bool ProfileSyncServiceHarness::AwaitEngineInitialization( |
+ bool skip_passphrase_verification) { |
if (!EngineInitializeChecker(service()).Wait()) { |
LOG(ERROR) << "EngineInitializeChecker timed out."; |
return false; |
@@ -258,7 +327,8 @@ bool ProfileSyncServiceHarness::AwaitEngineInitialization() { |
} |
// Make sure that initial sync wasn't blocked by a missing passphrase. |
- if (service()->passphrase_required_reason() == syncer::REASON_DECRYPTION) { |
+ if (!skip_passphrase_verification && |
+ service()->passphrase_required_reason() == syncer::REASON_DECRYPTION) { |
LOG(ERROR) << "A passphrase is required for decryption. Sync cannot proceed" |
" until SetDecryptionPassphrase is called."; |
return false; |
@@ -272,14 +342,16 @@ bool ProfileSyncServiceHarness::AwaitEngineInitialization() { |
return true; |
} |
-bool ProfileSyncServiceHarness::AwaitSyncSetupCompletion() { |
+bool ProfileSyncServiceHarness::AwaitSyncSetupCompletion( |
+ bool skip_passphrase_verification) { |
if (!SyncSetupChecker(service()).Wait()) { |
LOG(ERROR) << "SyncSetupChecker timed out."; |
return false; |
} |
// Make sure that initial sync wasn't blocked by a missing passphrase. |
- if (service()->passphrase_required_reason() == syncer::REASON_DECRYPTION) { |
+ if (!skip_passphrase_verification && |
+ service()->passphrase_required_reason() == syncer::REASON_DECRYPTION) { |
LOG(ERROR) << "A passphrase is required for decryption. Sync cannot proceed" |
" until SetDecryptionPassphrase is called."; |
return false; |