OLD | NEW |
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 593 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
604 | 604 |
605 bool SyncTest::SetupSync() { | 605 bool SyncTest::SetupSync() { |
606 // Create sync profiles and clients if they haven't already been created. | 606 // Create sync profiles and clients if they haven't already been created. |
607 if (profiles_.empty()) { | 607 if (profiles_.empty()) { |
608 if (!SetupClients()) { | 608 if (!SetupClients()) { |
609 LOG(FATAL) << "SetupClients() failed."; | 609 LOG(FATAL) << "SetupClients() failed."; |
610 return false; | 610 return false; |
611 } | 611 } |
612 } | 612 } |
613 | 613 |
| 614 int clientIndex = 0; |
| 615 // If we're using external servers, clear server data so the account starts |
| 616 // with a clean slate. |
| 617 if (UsingExternalServers()) { |
| 618 if (!SetupAndClearClient(clientIndex++)) { |
| 619 LOG(FATAL) << "Setting up and clearing data for client " |
| 620 << clientIndex - 1 << " failed"; |
| 621 return false; |
| 622 } |
| 623 } |
| 624 |
614 // Sync each of the profiles. | 625 // Sync each of the profiles. |
615 for (int i = 0; i < num_clients_; ++i) { | 626 for (; clientIndex < num_clients_; clientIndex++) { |
616 if (!GetClient(i)->SetupSync()) { | 627 DVLOG(1) << "Setting up " << clientIndex << " client"; |
| 628 if (!GetClient(clientIndex)->SetupSync()) { |
617 LOG(FATAL) << "SetupSync() failed."; | 629 LOG(FATAL) << "SetupSync() failed."; |
618 return false; | 630 return false; |
619 } | 631 } |
620 } | 632 } |
621 | 633 |
622 // Because clients may modify sync data as part of startup (for example local | 634 // 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 | 635 // session-releated data is rewritten), we need to ensure all startup-based |
624 // changes have propagated between the clients. | 636 // changes have propagated between the clients. |
625 // | 637 // |
626 // Tests that don't use self-notifications can't await quiescense. They'll | 638 // Tests that don't use self-notifications can't await quiescense. They'll |
(...skipping 26 matching lines...) Expand all Loading... |
653 // be removed. http://crbug.com/484388 | 665 // be removed. http://crbug.com/484388 |
654 for (int i = 0; i < num_clients_; ++i) { | 666 for (int i = 0; i < num_clients_; ++i) { |
655 LoginUIServiceFactory::GetForProfile(GetProfile(i))-> | 667 LoginUIServiceFactory::GetForProfile(GetProfile(i))-> |
656 SyncConfirmationUIClosed(LoginUIService::SYNC_WITH_DEFAULT_SETTINGS); | 668 SyncConfirmationUIClosed(LoginUIService::SYNC_WITH_DEFAULT_SETTINGS); |
657 } | 669 } |
658 } | 670 } |
659 | 671 |
660 return true; | 672 return true; |
661 } | 673 } |
662 | 674 |
| 675 bool SyncTest::SetupAndClearClient(size_t index) { |
| 676 // Setup the first client so the sync engine is initialized, which is |
| 677 // required to clear server data. |
| 678 DVLOG(1) << "Setting up first client for clear."; |
| 679 if (!GetClient(index)->SetupSyncForClear()) { |
| 680 LOG(FATAL) << "SetupSync() failed."; |
| 681 return false; |
| 682 } |
| 683 |
| 684 DVLOG(1) << "Done setting up first client for clear."; |
| 685 if (!ClearServerData(GetClient(index++))) { |
| 686 LOG(FATAL) << "ClearServerData failed."; |
| 687 return false; |
| 688 } |
| 689 return true; |
| 690 } |
| 691 |
663 void SyncTest::TearDownOnMainThread() { | 692 void SyncTest::TearDownOnMainThread() { |
664 for (size_t i = 0; i < clients_.size(); ++i) { | 693 for (size_t i = 0; i < clients_.size(); ++i) { |
665 clients_[i]->service()->RequestStop(ProfileSyncService::CLEAR_DATA); | 694 clients_[i]->service()->RequestStop(ProfileSyncService::CLEAR_DATA); |
666 } | 695 } |
667 | 696 |
668 // Closing all browsers created by this test. The calls here block until | 697 // Closing all browsers created by this test. The calls here block until |
669 // they are closed. Other browsers created outside SyncTest setup should be | 698 // they are closed. Other browsers created outside SyncTest setup should be |
670 // closed by the creator of that browser. | 699 // closed by the creator of that browser. |
671 size_t init_browser_count = chrome::GetTotalBrowserCount(); | 700 size_t init_browser_count = chrome::GetTotalBrowserCount(); |
672 for (size_t i = 0; i < browsers_.size(); ++i) { | 701 for (size_t i = 0; i < browsers_.size(); ++i) { |
(...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1132 | 1161 |
1133 void SyncTest::TriggerSyncForModelTypes(int index, | 1162 void SyncTest::TriggerSyncForModelTypes(int index, |
1134 syncer::ModelTypeSet model_types) { | 1163 syncer::ModelTypeSet model_types) { |
1135 GetSyncService(index)->TriggerRefresh(model_types); | 1164 GetSyncService(index)->TriggerRefresh(model_types); |
1136 } | 1165 } |
1137 | 1166 |
1138 void SyncTest::SetPreexistingPreferencesFileContents( | 1167 void SyncTest::SetPreexistingPreferencesFileContents( |
1139 const std::string& contents) { | 1168 const std::string& contents) { |
1140 preexisting_preferences_file_contents_ = contents; | 1169 preexisting_preferences_file_contents_ = contents; |
1141 } | 1170 } |
| 1171 |
| 1172 bool SyncTest::ClearServerData(ProfileSyncServiceHarness* harness) { |
| 1173 // At this point our birthday is good. |
| 1174 base::RunLoop run_loop; |
| 1175 harness->service()->ClearServerDataForTest(run_loop.QuitClosure()); |
| 1176 run_loop.Run(); |
| 1177 |
| 1178 // Our birthday is invalidated on the server here so restart sync to get |
| 1179 // the new birthday from the server. |
| 1180 return harness->RestartSyncService(); |
| 1181 } |
OLD | NEW |