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 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 123 | 123 |
| 124 ProfileSyncServiceHarness::~ProfileSyncServiceHarness() { } | 124 ProfileSyncServiceHarness::~ProfileSyncServiceHarness() { } |
| 125 | 125 |
| 126 void ProfileSyncServiceHarness::SetCredentials(const std::string& username, | 126 void ProfileSyncServiceHarness::SetCredentials(const std::string& username, |
| 127 const std::string& password) { | 127 const std::string& password) { |
| 128 username_ = username; | 128 username_ = username; |
| 129 password_ = password; | 129 password_ = password; |
| 130 } | 130 } |
| 131 | 131 |
| 132 bool ProfileSyncServiceHarness::SetupSync() { | 132 bool ProfileSyncServiceHarness::SetupSync() { |
| 133 bool result = SetupSync(syncer::UserSelectableTypes()); | 133 bool result = SetupSync(syncer::UserSelectableTypes(), false); |
| 134 if (result == false) { | 134 if (!result) { |
| 135 std::string status = GetServiceStatus(); | 135 LOG(ERROR) << profile_debug_name_ << ": SetupSync failed. Syncer status:\n" |
| 136 LOG(ERROR) << profile_debug_name_ | 136 << GetServiceStatus(); |
| 137 << ": SetupSync failed. Syncer status:\n" << status; | |
| 138 } else { | 137 } else { |
| 139 DVLOG(1) << profile_debug_name_ << ": SetupSync successful."; | 138 DVLOG(1) << profile_debug_name_ << ": SetupSync successful."; |
| 140 } | 139 } |
| 141 return result; | 140 return result; |
| 142 } | 141 } |
| 143 | 142 |
| 144 bool ProfileSyncServiceHarness::SetupSync( | 143 bool ProfileSyncServiceHarness::SetupSyncForClear() { |
|
pavely
2017/03/08 21:15:14
This function is only used in sync_test when setti
wylieb
2017/03/09 18:42:26
This is a helper to call into SetupSync with the c
| |
| 145 syncer::ModelTypeSet synced_datatypes) { | 144 bool result = SetupSync(syncer::UserSelectableTypes(), true); |
| 145 if (!result) { | |
| 146 LOG(ERROR) << profile_debug_name_ | |
| 147 << ": SetupSyncForClear failed. Syncer status:\n" | |
| 148 << GetServiceStatus(); | |
| 149 } else { | |
| 150 DVLOG(1) << profile_debug_name_ << ": SetupSyncForClear successful."; | |
| 151 } | |
| 152 return result; | |
| 153 } | |
| 154 | |
| 155 bool ProfileSyncServiceHarness::SetupSync(syncer::ModelTypeSet synced_datatypes, | |
| 156 bool for_clear) { | |
|
pavely
2017/03/08 21:15:13
"for_clear" name is not very clear. It denotes sce
wylieb
2017/03/09 18:42:26
It makes sense to rename this variable to skip_pas
| |
| 146 DCHECK(!profile_->IsLegacySupervised()) | 157 DCHECK(!profile_->IsLegacySupervised()) |
| 147 << "SetupSync should not be used for legacy supervised users."; | 158 << "SetupSync should not be used for legacy supervised users."; |
| 148 | 159 |
| 149 // Initialize the sync client's profile sync service object. | 160 // Initialize the sync client's profile sync service object. |
| 150 if (service() == nullptr) { | 161 if (service() == nullptr) { |
| 151 LOG(ERROR) << "SetupSync(): service() is null."; | 162 LOG(ERROR) << "SetupSync(): service() is null."; |
| 152 return false; | 163 return false; |
| 153 } | 164 } |
| 154 | 165 |
| 155 // Tell the sync service that setup is in progress so we don't start syncing | 166 // 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_); | 183 service()->GoogleSigninSucceeded(account_id, username_, password_); |
| 173 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_)-> | 184 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_)-> |
| 174 UpdateCredentials(account_id, GenerateFakeOAuth2RefreshTokenString()); | 185 UpdateCredentials(account_id, GenerateFakeOAuth2RefreshTokenString()); |
| 175 } else { | 186 } else { |
| 176 LOG(ERROR) << "Unsupported profile signin type."; | 187 LOG(ERROR) << "Unsupported profile signin type."; |
| 177 } | 188 } |
| 178 | 189 |
| 179 // Now that auth is completed, request that sync actually start. | 190 // Now that auth is completed, request that sync actually start. |
| 180 service()->RequestStart(); | 191 service()->RequestStart(); |
| 181 | 192 |
| 182 if (!AwaitEngineInitialization()) { | 193 if (for_clear && !AwaitEngineInitializationForClear()) { |
| 194 return false; | |
| 195 } else if (!for_clear && !AwaitEngineInitialization()) { | |
| 183 return false; | 196 return false; |
| 184 } | 197 } |
| 185 | 198 |
| 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 FinishSyncSetup(); |
| 193 | 206 |
| 194 if ((signin_type_ == SigninType::UI_SIGNIN) && | 207 if ((signin_type_ == SigninType::UI_SIGNIN) && |
| 195 !login_ui_test_utils::DismissSyncConfirmationDialog( | 208 !login_ui_test_utils::DismissSyncConfirmationDialog( |
| 196 chrome::FindBrowserWithProfile(profile_), | 209 chrome::FindBrowserWithProfile(profile_), |
| 197 base::TimeDelta::FromSeconds(30))) { | 210 base::TimeDelta::FromSeconds(30))) { |
| 198 LOG(ERROR) << "Failed to dismiss sync confirmation dialog."; | 211 LOG(ERROR) << "Failed to dismiss sync confirmation dialog."; |
| 199 return false; | 212 return false; |
| 200 } | 213 } |
| 201 | 214 |
| 215 // If we're setting up for clear, we don't need to wait. | |
| 216 if (for_clear) { | |
| 217 return true; | |
| 218 } | |
| 219 | |
| 202 // Set an implicit passphrase for encryption if an explicit one hasn't already | 220 // 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, | 221 // been set. If an explicit passphrase has been set, immediately return false, |
| 204 // since a decryption passphrase is required. | 222 // since a decryption passphrase is required. |
| 205 if (!service()->IsUsingSecondaryPassphrase()) { | 223 if (!service()->IsUsingSecondaryPassphrase()) { |
| 206 service()->SetEncryptionPassphrase(password_, ProfileSyncService::IMPLICIT); | 224 service()->SetEncryptionPassphrase(password_, ProfileSyncService::IMPLICIT); |
| 207 } else { | 225 } else { |
| 208 LOG(ERROR) << "A passphrase is required for decryption. Sync cannot proceed" | 226 LOG(ERROR) << "A passphrase is required for decryption. Sync cannot proceed" |
| 209 " until SetDecryptionPassphrase is called."; | 227 " until SetDecryptionPassphrase is called."; |
| 210 return false; | 228 return false; |
| 211 } | 229 } |
| 212 | 230 |
| 213 // Wait for initial sync cycle to be completed. | 231 // Wait for initial sync cycle to be completed. |
| 214 if (!AwaitSyncSetupCompletion()) { | 232 if (!AwaitSyncSetupCompletion()) { |
| 215 LOG(ERROR) << "Initial sync cycle timed out."; | |
| 216 return false; | 233 return false; |
| 217 } | 234 } |
| 218 | 235 |
| 219 return true; | 236 return true; |
| 220 } | 237 } |
| 221 | 238 |
| 239 bool ProfileSyncServiceHarness::RestartSyncService() { | |
| 240 std::unique_ptr<syncer::SyncSetupInProgressHandle> blocker = | |
| 241 service()->GetSetupInProgressHandle(); | |
| 242 DVLOG(1) << "Requesting stop for service."; | |
| 243 service()->RequestStop(ProfileSyncService::CLEAR_DATA); | |
| 244 DVLOG(1) << "Requesting start for service"; | |
| 245 | |
| 246 service()->RequestStart(); | |
| 247 if (!AwaitEngineInitialization()) { | |
| 248 LOG(ERROR) << "AwaitEngineInitialization failed."; | |
| 249 return false; | |
| 250 } | |
| 251 | |
| 252 // This passphrase should be implicit because ClearServerData should be called | |
| 253 // prior. | |
| 254 if (!service()->IsUsingSecondaryPassphrase()) { | |
| 255 service()->SetEncryptionPassphrase(password_, ProfileSyncService::IMPLICIT); | |
| 256 } else { | |
| 257 LOG(ERROR) << "A passphrase is required for decryption. Sync cannot proceed" | |
| 258 " until SetDecryptionPassphrase is called."; | |
| 259 return false; | |
| 260 } | |
| 261 | |
| 262 service()->SetFirstSetupComplete(); | |
| 263 | |
| 264 return true; | |
| 265 } | |
| 266 | |
| 222 bool ProfileSyncServiceHarness::AwaitMutualSyncCycleCompletion( | 267 bool ProfileSyncServiceHarness::AwaitMutualSyncCycleCompletion( |
| 223 ProfileSyncServiceHarness* partner) { | 268 ProfileSyncServiceHarness* partner) { |
| 224 std::vector<ProfileSyncServiceHarness*> harnesses; | 269 std::vector<ProfileSyncServiceHarness*> harnesses; |
| 225 harnesses.push_back(this); | 270 harnesses.push_back(this); |
| 226 harnesses.push_back(partner); | 271 harnesses.push_back(partner); |
| 227 return AwaitQuiescence(harnesses); | 272 return AwaitQuiescence(harnesses); |
| 228 } | 273 } |
| 229 | 274 |
| 230 bool ProfileSyncServiceHarness::AwaitGroupSyncCycleCompletion( | 275 bool ProfileSyncServiceHarness::AwaitGroupSyncCycleCompletion( |
| 231 const std::vector<ProfileSyncServiceHarness*>& partners) { | 276 const std::vector<ProfileSyncServiceHarness*>& partners) { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 265 } | 310 } |
| 266 | 311 |
| 267 if (HasAuthError(service())) { | 312 if (HasAuthError(service())) { |
| 268 LOG(ERROR) << "Credentials were rejected. Sync cannot proceed."; | 313 LOG(ERROR) << "Credentials were rejected. Sync cannot proceed."; |
| 269 return false; | 314 return false; |
| 270 } | 315 } |
| 271 | 316 |
| 272 return true; | 317 return true; |
| 273 } | 318 } |
| 274 | 319 |
| 320 bool ProfileSyncServiceHarness::AwaitEngineInitializationForClear() { | |
|
pavely
2017/03/08 21:15:13
Could you add "bool ensure_valid_passphrase" param
wylieb
2017/03/09 18:42:26
Done.
| |
| 321 if (!EngineInitializeChecker(service()).Wait()) { | |
| 322 LOG(ERROR) | |
| 323 << "Initializing up for clear: EngineInitializeChecker timed out."; | |
| 324 return false; | |
| 325 } | |
| 326 | |
| 327 if (!service()->IsEngineInitialized()) { | |
| 328 LOG(ERROR) << "Initializing up for clear: Service engine not initialized."; | |
| 329 return false; | |
| 330 } | |
| 331 | |
| 332 if (HasAuthError(service())) { | |
| 333 LOG(ERROR) << "Initializing up for clear: Credentials were rejected. Sync " | |
| 334 "cannot proceed."; | |
| 335 return false; | |
| 336 } | |
| 337 | |
| 338 return true; | |
| 339 } | |
| 340 | |
| 275 bool ProfileSyncServiceHarness::AwaitSyncSetupCompletion() { | 341 bool ProfileSyncServiceHarness::AwaitSyncSetupCompletion() { |
| 276 if (!SyncSetupChecker(service()).Wait()) { | 342 if (!SyncSetupChecker(service()).Wait()) { |
| 277 LOG(ERROR) << "SyncSetupChecker timed out."; | 343 LOG(ERROR) << "SyncSetupChecker timed out."; |
| 278 return false; | 344 return false; |
| 279 } | 345 } |
| 280 | 346 |
| 281 // Make sure that initial sync wasn't blocked by a missing passphrase. | 347 // Make sure that initial sync wasn't blocked by a missing passphrase. |
| 282 if (service()->passphrase_required_reason() == syncer::REASON_DECRYPTION) { | 348 if (service()->passphrase_required_reason() == syncer::REASON_DECRYPTION) { |
| 283 LOG(ERROR) << "A passphrase is required for decryption. Sync cannot proceed" | 349 LOG(ERROR) << "A passphrase is required for decryption. Sync cannot proceed" |
| 284 " until SetDecryptionPassphrase is called."; | 350 " until SetDecryptionPassphrase is called."; |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 476 | 542 |
| 477 std::string ProfileSyncServiceHarness::GetServiceStatus() { | 543 std::string ProfileSyncServiceHarness::GetServiceStatus() { |
| 478 std::unique_ptr<base::DictionaryValue> value( | 544 std::unique_ptr<base::DictionaryValue> value( |
| 479 syncer::sync_ui_util::ConstructAboutInformation( | 545 syncer::sync_ui_util::ConstructAboutInformation( |
| 480 service(), service()->signin(), chrome::GetChannel())); | 546 service(), service()->signin(), chrome::GetChannel())); |
| 481 std::string service_status; | 547 std::string service_status; |
| 482 base::JSONWriter::WriteWithOptions( | 548 base::JSONWriter::WriteWithOptions( |
| 483 *value, base::JSONWriter::OPTIONS_PRETTY_PRINT, &service_status); | 549 *value, base::JSONWriter::OPTIONS_PRETTY_PRINT, &service_status); |
| 484 return service_status; | 550 return service_status; |
| 485 } | 551 } |
| OLD | NEW |