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

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

Issue 2716413003: Initial clear server data impl (Closed)
Patch Set: Fixed various CL 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/sync_test.h" 5 #include "chrome/browser/sync/test/integration/sync_test.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <limits> 10 #include <limits>
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 case TWO_CLIENT: 224 case TWO_CLIENT:
225 case TWO_CLIENT_LEGACY: { 225 case TWO_CLIENT_LEGACY: {
226 num_clients_ = 2; 226 num_clients_ = 2;
227 break; 227 break;
228 } 228 }
229 default: 229 default:
230 NOTREACHED() << "Invalid test type specified."; 230 NOTREACHED() << "Invalid test type specified.";
231 } 231 }
232 } 232 }
233 233
234 SyncTest::~SyncTest() {} 234 SyncTest::~SyncTest() {
235 sync_datatype_helper::DissociateWithTest(this);
236 }
235 237
236 void SyncTest::SetUp() { 238 void SyncTest::SetUp() {
237 // Sets |server_type_| if it wasn't specified by the test. 239 // Sets |server_type_| if it wasn't specified by the test.
238 DecideServerType(); 240 DecideServerType();
239 241
240 base::CommandLine* cl = base::CommandLine::ForCurrentProcess(); 242 base::CommandLine* cl = base::CommandLine::ForCurrentProcess();
241 if (cl->HasSwitch(switches::kPasswordFileForTest)) { 243 if (cl->HasSwitch(switches::kPasswordFileForTest)) {
242 ReadPasswordFile(); 244 ReadPasswordFile();
243 } else { 245 } else {
244 // Decide on username to use or create one. 246 // Decide on username to use or create one.
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after
604 606
605 bool SyncTest::SetupSync() { 607 bool SyncTest::SetupSync() {
606 // Create sync profiles and clients if they haven't already been created. 608 // Create sync profiles and clients if they haven't already been created.
607 if (profiles_.empty()) { 609 if (profiles_.empty()) {
608 if (!SetupClients()) { 610 if (!SetupClients()) {
609 LOG(FATAL) << "SetupClients() failed."; 611 LOG(FATAL) << "SetupClients() failed.";
610 return false; 612 return false;
611 } 613 }
612 } 614 }
613 615
616 int clientIndex = 0;
617 // If we're using external servers, clear server data so the account starts
618 // with a clean slate.
619 if (UsingExternalServers()) {
620 // Setup the first client so the sync engine is initialized, which is
621 // required to clear server data.
622 DVLOG(1) << "Setting up first client for clear.";
623 if (!GetClient(clientIndex)->SetupSyncForClear()) {
624 LOG(FATAL) << "SetupSync() failed.";
625 return false;
626 }
627
628 DVLOG(1) << "Done setting up first client for clear.";
629 if (!ClearServerData(GetClient(clientIndex++))) {
630 LOG(FATAL) << "ClearServerData failed.";
631 return false;
632 }
633 }
634
614 // Sync each of the profiles. 635 // Sync each of the profiles.
615 for (int i = 0; i < num_clients_; ++i) { 636 for (; clientIndex < num_clients_; clientIndex++) {
616 if (!GetClient(i)->SetupSync()) { 637 DVLOG(1) << "Setting up " << clientIndex << " client";
638 if (!GetClient(clientIndex)->SetupSync()) {
617 LOG(FATAL) << "SetupSync() failed."; 639 LOG(FATAL) << "SetupSync() failed.";
618 return false; 640 return false;
619 } 641 }
620 } 642 }
621 643
622 // Because clients may modify sync data as part of startup (for example local 644 // Because clients may modify sync data as part of startup (for example local
623 // session-releated data is rewritten), we need to ensure all startup-based 645 // session-releated data is rewritten), we need to ensure all startup-based
624 // changes have propagated between the clients. 646 // changes have propagated between the clients.
625 // 647 //
626 // Tests that don't use self-notifications can't await quiescense. They'll 648 // Tests that don't use self-notifications can't await quiescense. They'll
(...skipping 505 matching lines...) Expand 10 before | Expand all | Expand 10 after
1132 1154
1133 void SyncTest::TriggerSyncForModelTypes(int index, 1155 void SyncTest::TriggerSyncForModelTypes(int index,
1134 syncer::ModelTypeSet model_types) { 1156 syncer::ModelTypeSet model_types) {
1135 GetSyncService(index)->TriggerRefresh(model_types); 1157 GetSyncService(index)->TriggerRefresh(model_types);
1136 } 1158 }
1137 1159
1138 void SyncTest::SetPreexistingPreferencesFileContents( 1160 void SyncTest::SetPreexistingPreferencesFileContents(
1139 const std::string& contents) { 1161 const std::string& contents) {
1140 preexisting_preferences_file_contents_ = contents; 1162 preexisting_preferences_file_contents_ = contents;
1141 } 1163 }
1164
1165 bool SyncTest::ClearServerData(ProfileSyncServiceHarness* harness) {
1166 // At this point our birthday is good.
1167 base::RunLoop run_loop;
1168 harness->service()->ClearServerDataForTest(run_loop.QuitClosure());
1169 run_loop.Run();
1170
1171 // Our birthday is bad here so restart sync to get the new birthday from the
1172 // server.
1173 return harness->RestartSyncService();
1174 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698