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

Side by Side Diff: chrome/browser/sync/test/integration/profile_sync_service_harness.cc

Issue 2716413003: Initial clear server data impl (Closed)
Patch Set: Responding to CL comments. Some Logic changes, but mostly spelling/comments. Created 3 years, 9 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 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
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 == false) {
skym 2017/03/07 21:32:24 Ahh, you were copying from here. Can you fix this
wylieb 2017/03/07 23:04:40 Done.
135 std::string status = GetServiceStatus(); 135 std::string status = GetServiceStatus();
136 LOG(ERROR) << profile_debug_name_ 136 LOG(ERROR) << profile_debug_name_
137 << ": SetupSync failed. Syncer status:\n" << status; 137 << ": SetupSync failed. Syncer status:\n" << status;
138 } else { 138 } else {
139 DVLOG(1) << profile_debug_name_ << ": SetupSync successful."; 139 DVLOG(1) << profile_debug_name_ << ": SetupSync successful.";
140 } 140 }
141 return result; 141 return result;
142 } 142 }
143 143
144 bool ProfileSyncServiceHarness::SetupSync( 144 bool ProfileSyncServiceHarness::SetupSyncForClear() {
145 syncer::ModelTypeSet synced_datatypes) { 145 bool result = SetupSync(syncer::UserSelectableTypes(), true);
146 if (result == false) {
skym 2017/03/07 21:32:24 The result == false is a bit verbose. What do you
wylieb 2017/03/07 23:04:39 Done.
147 std::string status = GetServiceStatus();
skym 2017/03/07 21:32:24 What do you think of in-lining this?
wylieb 2017/03/07 23:04:39 Done.
148 LOG(ERROR) << profile_debug_name_
149 << ": SetupSyncForClear failed. Syncer status:\n"
150 << status;
151 } else {
152 DVLOG(1) << profile_debug_name_ << ": SetupSyncForClear successful.";
153 }
154 return result;
155 }
156
157 bool ProfileSyncServiceHarness::SetupSync(syncer::ModelTypeSet synced_datatypes,
158 bool forClear) {
146 DCHECK(!profile_->IsLegacySupervised()) 159 DCHECK(!profile_->IsLegacySupervised())
147 << "SetupSync should not be used for legacy supervised users."; 160 << "SetupSync should not be used for legacy supervised users.";
148 161
149 // Initialize the sync client's profile sync service object. 162 // Initialize the sync client's profile sync service object.
150 if (service() == nullptr) { 163 if (service() == nullptr) {
151 LOG(ERROR) << "SetupSync(): service() is null."; 164 LOG(ERROR) << "SetupSync(): service() is null.";
152 return false; 165 return false;
153 } 166 }
154 167
155 // Tell the sync service that setup is in progress so we don't start syncing 168 // Tell the sync service that setup is in progress so we don't start syncing
(...skipping 16 matching lines...) Expand all
172 service()->GoogleSigninSucceeded(account_id, username_, password_); 185 service()->GoogleSigninSucceeded(account_id, username_, password_);
173 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_)-> 186 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_)->
174 UpdateCredentials(account_id, GenerateFakeOAuth2RefreshTokenString()); 187 UpdateCredentials(account_id, GenerateFakeOAuth2RefreshTokenString());
175 } else { 188 } else {
176 LOG(ERROR) << "Unsupported profile signin type."; 189 LOG(ERROR) << "Unsupported profile signin type.";
177 } 190 }
178 191
179 // Now that auth is completed, request that sync actually start. 192 // Now that auth is completed, request that sync actually start.
180 service()->RequestStart(); 193 service()->RequestStart();
181 194
182 if (!AwaitEngineInitialization()) { 195 if (forClear && !AwaitEngineInitializationForClear()) {
196 LOG(ERROR) << "AwaitEngineInitializationForClear failed.";
skym 2017/03/07 21:32:25 These logs are kind of redundant, the await call a
wylieb 2017/03/07 23:04:40 Done.
197 return false;
198 } else if (!forClear && !AwaitEngineInitialization()) {
199 LOG(ERROR) << "AwaitEngineInitialization failed.";
183 return false; 200 return false;
184 } 201 }
185 202
skym 2017/03/07 21:32:24 Why do you need to go any farther than waiting for
wylieb 2017/03/07 23:04:40 Good insight, thanks! Done.
186 // Choose the datatypes to be synced. If all datatypes are to be synced, 203 // Choose the datatypes to be synced. If all datatypes are to be synced,
187 // set sync_everything to true; otherwise, set it to false. 204 // set sync_everything to true; otherwise, set it to false.
188 bool sync_everything = (synced_datatypes == syncer::UserSelectableTypes()); 205 bool sync_everything = (synced_datatypes == syncer::UserSelectableTypes());
189 service()->OnUserChoseDatatypes(sync_everything, synced_datatypes); 206 service()->OnUserChoseDatatypes(sync_everything, synced_datatypes);
190 207
191 // Notify ProfileSyncService that we are done with configuration. 208 // Notify ProfileSyncService that we are done with configuration.
192 FinishSyncSetup(); 209 FinishSyncSetup();
193 210
194 if ((signin_type_ == SigninType::UI_SIGNIN) && 211 if ((signin_type_ == SigninType::UI_SIGNIN) &&
skym 2017/03/07 21:32:24 What kind of sign in are E2E tests by the way? FAK
wylieb 2017/03/07 23:04:39 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
202 // Set an implicit passphrase for encryption if an explicit one hasn't already 219 // 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, 220 // been set. If an explicit passphrase has been set, immediately return false,
204 // since a decryption passphrase is required. 221 // since a decryption passphrase is required.
205 if (!service()->IsUsingSecondaryPassphrase()) { 222 if (forClear) {
223 // If we're clearing server data, don't check for decryption passphrase.
224 LOG(WARNING) << "Not checking passphrase decryption";
skym 2017/03/07 21:32:25 Punctuation!
wylieb 2017/03/07 23:04:40 Done.
225 } else if (!service()->IsUsingSecondaryPassphrase()) {
206 service()->SetEncryptionPassphrase(password_, ProfileSyncService::IMPLICIT); 226 service()->SetEncryptionPassphrase(password_, ProfileSyncService::IMPLICIT);
207 } else { 227 } else {
208 LOG(ERROR) << "A passphrase is required for decryption. Sync cannot proceed" 228 LOG(ERROR) << "A passphrase is required for decryption. Sync cannot proceed"
209 " until SetDecryptionPassphrase is called."; 229 " until SetDecryptionPassphrase is called.";
210 return false; 230 return false;
211 } 231 }
212 232
213 // Wait for initial sync cycle to be completed. 233 // Wait for initial sync cycle to be completed.
214 if (!AwaitSyncSetupCompletion()) { 234 if (forClear && !AwaitSyncSetupCompletionForClear()) {
215 LOG(ERROR) << "Initial sync cycle timed out."; 235 LOG(ERROR) << "AwaitSyncSetupCompletionForClear failed.";
236 return false;
237 } else if (!forClear && !AwaitSyncSetupCompletion()) {
238 LOG(ERROR) << "AwaitSyncSetupCompletion failed.";
216 return false; 239 return false;
217 } 240 }
218 241
219 return true; 242 return true;
220 } 243 }
221 244
245 bool ProfileSyncServiceHarness::RestartSyncService() {
246 sync_blocker_ = service()->GetSetupInProgressHandle();
skym 2017/03/07 21:32:25 Sorry if it feels like I'm flip-flopping here, but
wylieb 2017/03/07 23:04:40 Yeah that's why I had it that way to begin with. C
247 DVLOG(1) << "Requesting stop for service.";
248 service()->RequestStop(ProfileSyncService::CLEAR_DATA);
249 DVLOG(1) << "Requesting start for service";
250
251 service()->RequestStart();
252 if (!AwaitEngineInitialization()) {
253 LOG(ERROR) << "AwaitEngineInitialization failed.";
254 return false;
255 }
256
257 // Check passphrase now, should be implicit
skym 2017/03/07 21:32:24 This comment should end with a period as well.
wylieb 2017/03/07 23:04:40 Done.
258 if (!service()->IsUsingSecondaryPassphrase()) {
259 service()->SetEncryptionPassphrase(password_, ProfileSyncService::IMPLICIT);
260 } else {
261 LOG(ERROR) << "A passphrase is required for decryption. Sync cannot proceed"
262 " until SetDecryptionPassphrase is called.";
263 return false;
264 }
265
266 FinishSyncSetup();
267
skym 2017/03/07 21:32:24 Do you need to call AwaitSyncSetupCompletion() ?
wylieb 2017/03/07 23:04:40 Good point. Done.
skym 2017/03/08 19:15:02 This never happened as far as I can tell.
wylieb 2017/03/09 18:42:26 Sorry. I tried to implement this, but it times out
skym 2017/03/10 17:36:31 Was it possible this was while the blocker was sti
268 return true;
269 }
270
222 bool ProfileSyncServiceHarness::AwaitMutualSyncCycleCompletion( 271 bool ProfileSyncServiceHarness::AwaitMutualSyncCycleCompletion(
223 ProfileSyncServiceHarness* partner) { 272 ProfileSyncServiceHarness* partner) {
224 std::vector<ProfileSyncServiceHarness*> harnesses; 273 std::vector<ProfileSyncServiceHarness*> harnesses;
225 harnesses.push_back(this); 274 harnesses.push_back(this);
226 harnesses.push_back(partner); 275 harnesses.push_back(partner);
227 return AwaitQuiescence(harnesses); 276 return AwaitQuiescence(harnesses);
228 } 277 }
229 278
230 bool ProfileSyncServiceHarness::AwaitGroupSyncCycleCompletion( 279 bool ProfileSyncServiceHarness::AwaitGroupSyncCycleCompletion(
231 const std::vector<ProfileSyncServiceHarness*>& partners) { 280 const std::vector<ProfileSyncServiceHarness*>& partners) {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 } 314 }
266 315
267 if (HasAuthError(service())) { 316 if (HasAuthError(service())) {
268 LOG(ERROR) << "Credentials were rejected. Sync cannot proceed."; 317 LOG(ERROR) << "Credentials were rejected. Sync cannot proceed.";
269 return false; 318 return false;
270 } 319 }
271 320
272 return true; 321 return true;
273 } 322 }
274 323
324 bool ProfileSyncServiceHarness::AwaitEngineInitializationForClear() {
325 LOG(WARNING) << "AwaitEngineInitializationForClear";
326 if (!EngineInitializeChecker(service()).Wait()) {
327 LOG(ERROR) << "EngineInitializeChecker timed out.";
328 return false;
329 }
330
331 if (!service()->IsEngineInitialized()) {
332 LOG(ERROR) << "Service engine not initialized.";
333 return false;
334 }
335
336 if (HasAuthError(service())) {
337 LOG(ERROR) << "Credentials were rejected. Sync cannot proceed.";
338 return false;
339 }
340
341 return true;
342 }
343
275 bool ProfileSyncServiceHarness::AwaitSyncSetupCompletion() { 344 bool ProfileSyncServiceHarness::AwaitSyncSetupCompletion() {
345 LOG(WARNING) << "AwaitSyncSetupCompletion";
276 if (!SyncSetupChecker(service()).Wait()) { 346 if (!SyncSetupChecker(service()).Wait()) {
277 LOG(ERROR) << "SyncSetupChecker timed out."; 347 LOG(ERROR) << "SyncSetupChecker timed out.";
278 return false; 348 return false;
279 } 349 }
280 350
281 // Make sure that initial sync wasn't blocked by a missing passphrase. 351 // Make sure that initial sync wasn't blocked by a missing passphrase.
282 if (service()->passphrase_required_reason() == syncer::REASON_DECRYPTION) { 352 if (service()->passphrase_required_reason() == syncer::REASON_DECRYPTION) {
283 LOG(ERROR) << "A passphrase is required for decryption. Sync cannot proceed" 353 LOG(ERROR) << "A passphrase is required for decryption. Sync cannot proceed"
284 " until SetDecryptionPassphrase is called."; 354 " until SetDecryptionPassphrase is called.";
285 return false; 355 return false;
286 } 356 }
287 357
288 if (HasAuthError(service())) { 358 if (HasAuthError(service())) {
289 LOG(ERROR) << "Credentials were rejected. Sync cannot proceed."; 359 LOG(ERROR) << "Credentials were rejected. Sync cannot proceed.";
290 return false; 360 return false;
291 } 361 }
292 362
293 return true; 363 return true;
294 } 364 }
295 365
366 bool ProfileSyncServiceHarness::AwaitSyncSetupCompletionForClear() {
367 LOG(WARNING) << "AwaitSyncSetupCompletionForClear";
368 if (!SyncSetupChecker(service()).Wait()) {
369 LOG(ERROR) << "SyncSetupChecker timed out.";
370 return false;
371 }
372
373 if (HasAuthError(service())) {
374 LOG(ERROR) << "Credentials were rejected. Sync cannot proceed.";
375 return false;
376 }
377
378 return true;
379 }
380
296 std::string ProfileSyncServiceHarness::GenerateFakeOAuth2RefreshTokenString() { 381 std::string ProfileSyncServiceHarness::GenerateFakeOAuth2RefreshTokenString() {
297 return base::StringPrintf("oauth2_refresh_token_%d", 382 return base::StringPrintf("oauth2_refresh_token_%d",
298 ++oauth2_refesh_token_number_); 383 ++oauth2_refesh_token_number_);
299 } 384 }
300 385
301 bool ProfileSyncServiceHarness::IsSyncDisabled() const { 386 bool ProfileSyncServiceHarness::IsSyncDisabled() const {
302 return !service()->IsSetupInProgress() && !service()->IsFirstSetupComplete(); 387 return !service()->IsSetupInProgress() && !service()->IsFirstSetupComplete();
303 } 388 }
304 389
305 void ProfileSyncServiceHarness::FinishSyncSetup() { 390 void ProfileSyncServiceHarness::FinishSyncSetup() {
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
476 561
477 std::string ProfileSyncServiceHarness::GetServiceStatus() { 562 std::string ProfileSyncServiceHarness::GetServiceStatus() {
478 std::unique_ptr<base::DictionaryValue> value( 563 std::unique_ptr<base::DictionaryValue> value(
479 syncer::sync_ui_util::ConstructAboutInformation( 564 syncer::sync_ui_util::ConstructAboutInformation(
480 service(), service()->signin(), chrome::GetChannel())); 565 service(), service()->signin(), chrome::GetChannel()));
481 std::string service_status; 566 std::string service_status;
482 base::JSONWriter::WriteWithOptions( 567 base::JSONWriter::WriteWithOptions(
483 *value, base::JSONWriter::OPTIONS_PRETTY_PRINT, &service_status); 568 *value, base::JSONWriter::OPTIONS_PRETTY_PRINT, &service_status);
484 return service_status; 569 return service_status;
485 } 570 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698