| 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 450 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 461 profiles_.push_back(profile); | 461 profiles_.push_back(profile); |
| 462 | 462 |
| 463 return browsers_[browsers_.size() - 1]; | 463 return browsers_[browsers_.size() - 1]; |
| 464 } | 464 } |
| 465 | 465 |
| 466 ProfileSyncServiceHarness* SyncTest::GetClient(int index) { | 466 ProfileSyncServiceHarness* SyncTest::GetClient(int index) { |
| 467 if (clients_.empty()) | 467 if (clients_.empty()) |
| 468 LOG(FATAL) << "SetupClients() has not yet been called."; | 468 LOG(FATAL) << "SetupClients() has not yet been called."; |
| 469 if (index < 0 || index >= static_cast<int>(clients_.size())) | 469 if (index < 0 || index >= static_cast<int>(clients_.size())) |
| 470 LOG(FATAL) << "GetClient(): Index is out of bounds."; | 470 LOG(FATAL) << "GetClient(): Index is out of bounds."; |
| 471 return clients_[index]; | 471 return clients_[index].get(); |
| 472 } |
| 473 |
| 474 std::vector<ProfileSyncServiceHarness*> SyncTest::GetSyncClients() { |
| 475 std::vector<ProfileSyncServiceHarness*> clients(clients_.size()); |
| 476 for (size_t i = 0; i < clients_.size(); ++i) |
| 477 clients[i] = clients_[i].get(); |
| 478 return clients; |
| 472 } | 479 } |
| 473 | 480 |
| 474 ProfileSyncService* SyncTest::GetSyncService(int index) { | 481 ProfileSyncService* SyncTest::GetSyncService(int index) { |
| 475 return ProfileSyncServiceFactory::GetForProfile(GetProfile(index)); | 482 return ProfileSyncServiceFactory::GetForProfile(GetProfile(index)); |
| 476 } | 483 } |
| 477 | 484 |
| 478 std::vector<ProfileSyncService*> SyncTest::GetSyncServices() { | 485 std::vector<ProfileSyncService*> SyncTest::GetSyncServices() { |
| 479 std::vector<ProfileSyncService*> services; | 486 std::vector<ProfileSyncService*> services; |
| 480 for (int i = 0; i < num_clients(); ++i) { | 487 for (int i = 0; i < num_clients(); ++i) { |
| 481 services.push_back(GetSyncService(i)); | 488 services.push_back(GetSyncService(i)); |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 578 profile_sync_service->OverrideNetworkResourcesForTest( | 585 profile_sync_service->OverrideNetworkResourcesForTest( |
| 579 base::WrapUnique<syncer::NetworkResources>( | 586 base::WrapUnique<syncer::NetworkResources>( |
| 580 new fake_server::FakeServerNetworkResources( | 587 new fake_server::FakeServerNetworkResources( |
| 581 fake_server_->AsWeakPtr()))); | 588 fake_server_->AsWeakPtr()))); |
| 582 } | 589 } |
| 583 | 590 |
| 584 ProfileSyncServiceHarness::SigninType singin_type = UsingExternalServers() | 591 ProfileSyncServiceHarness::SigninType singin_type = UsingExternalServers() |
| 585 ? ProfileSyncServiceHarness::SigninType::UI_SIGNIN | 592 ? ProfileSyncServiceHarness::SigninType::UI_SIGNIN |
| 586 : ProfileSyncServiceHarness::SigninType::FAKE_SIGNIN; | 593 : ProfileSyncServiceHarness::SigninType::FAKE_SIGNIN; |
| 587 | 594 |
| 595 DCHECK(!clients_[index]); |
| 588 clients_[index] = | 596 clients_[index] = |
| 589 ProfileSyncServiceHarness::Create(GetProfile(index), | 597 ProfileSyncServiceHarness::Create(GetProfile(index), |
| 590 username_, | 598 username_, |
| 591 password_, | 599 password_, |
| 592 singin_type); | 600 singin_type); |
| 593 EXPECT_NE(nullptr, GetClient(index)) << "Could not create Client " << index; | 601 EXPECT_NE(nullptr, GetClient(index)) << "Could not create Client " << index; |
| 594 InitializeInvalidations(index); | 602 InitializeInvalidations(index); |
| 595 } | 603 } |
| 596 | 604 |
| 597 void SyncTest::InitializeInvalidations(int index) { | 605 void SyncTest::InitializeInvalidations(int index) { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 622 static_cast<invalidation::ProfileInvalidationProvider*>( | 630 static_cast<invalidation::ProfileInvalidationProvider*>( |
| 623 invalidation::ProfileInvalidationProviderFactory:: | 631 invalidation::ProfileInvalidationProviderFactory:: |
| 624 GetInstance()->SetTestingFactoryAndUse( | 632 GetInstance()->SetTestingFactoryAndUse( |
| 625 GetProfile(index), | 633 GetProfile(index), |
| 626 TestUsesSelfNotifications() ? | 634 TestUsesSelfNotifications() ? |
| 627 BuildSelfNotifyingP2PProfileInvalidationProvider : | 635 BuildSelfNotifyingP2PProfileInvalidationProvider : |
| 628 BuildRealisticP2PProfileInvalidationProvider))-> | 636 BuildRealisticP2PProfileInvalidationProvider))-> |
| 629 GetInvalidationService()); | 637 GetInvalidationService()); |
| 630 p2p_invalidation_service->UpdateCredentials(username_, password_); | 638 p2p_invalidation_service->UpdateCredentials(username_, password_); |
| 631 // Start listening for and emitting notifications of commits. | 639 // Start listening for and emitting notifications of commits. |
| 640 DCHECK(!invalidation_forwarders_[index]); |
| 632 invalidation_forwarders_[index] = | 641 invalidation_forwarders_[index] = |
| 633 new P2PInvalidationForwarder(clients_[index]->service(), | 642 base::MakeUnique<P2PInvalidationForwarder>(clients_[index]->service(), |
| 634 p2p_invalidation_service); | 643 p2p_invalidation_service); |
| 635 } | 644 } |
| 636 } | 645 } |
| 637 | 646 |
| 638 bool SyncTest::SetupSync() { | 647 bool SyncTest::SetupSync() { |
| 639 // Create sync profiles and clients if they haven't already been created. | 648 // Create sync profiles and clients if they haven't already been created. |
| 640 if (profiles_.empty()) { | 649 if (profiles_.empty()) { |
| 641 if (!SetupClients()) { | 650 if (!SetupClients()) { |
| 642 LOG(FATAL) << "SetupClients() failed."; | 651 LOG(FATAL) << "SetupClients() failed."; |
| 643 return false; | 652 return false; |
| 644 } | 653 } |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 680 | 689 |
| 681 // SyncRefresher is used instead of invalidations to notify other profiles to | 690 // SyncRefresher is used instead of invalidations to notify other profiles to |
| 682 // do a sync refresh on committed data sets. This is only needed when running | 691 // do a sync refresh on committed data sets. This is only needed when running |
| 683 // tests against external live server, otherwise invalidation service is used. | 692 // tests against external live server, otherwise invalidation service is used. |
| 684 // With external live servers, the profiles commit data on first sync cycle | 693 // With external live servers, the profiles commit data on first sync cycle |
| 685 // automatically after signing in. To avoid misleading sync commit | 694 // automatically after signing in. To avoid misleading sync commit |
| 686 // notifications at start up, we start the SyncRefresher observers post | 695 // notifications at start up, we start the SyncRefresher observers post |
| 687 // client set up. | 696 // client set up. |
| 688 if (UsingExternalServers()) { | 697 if (UsingExternalServers()) { |
| 689 for (int i = 0; i < num_clients_; ++i) { | 698 for (int i = 0; i < num_clients_; ++i) { |
| 690 sync_refreshers_[i] = | 699 DCHECK(!sync_refreshers_[i]); |
| 691 new P2PSyncRefresher(GetProfile(i), clients_[i]->service()); | 700 sync_refreshers_[i] = base::MakeUnique<P2PSyncRefresher>( |
| 701 GetProfile(i), clients_[i]->service()); |
| 692 } | 702 } |
| 693 | 703 |
| 694 // OneClickSigninSyncStarter observer is created with a real user sign in. | 704 // OneClickSigninSyncStarter observer is created with a real user sign in. |
| 695 // It is deleted on certain conditions which are not satisfied by our tests, | 705 // It is deleted on certain conditions which are not satisfied by our tests, |
| 696 // and this causes the SigninTracker observer to stay hanging at shutdown. | 706 // and this causes the SigninTracker observer to stay hanging at shutdown. |
| 697 // Calling LoginUIService::SyncConfirmationUIClosed forces the observer to | 707 // Calling LoginUIService::SyncConfirmationUIClosed forces the observer to |
| 698 // be removed. http://crbug.com/484388 | 708 // be removed. http://crbug.com/484388 |
| 699 for (int i = 0; i < num_clients_; ++i) { | 709 for (int i = 0; i < num_clients_; ++i) { |
| 700 LoginUIServiceFactory::GetForProfile(GetProfile(i))-> | 710 LoginUIServiceFactory::GetForProfile(GetProfile(i))-> |
| 701 SyncConfirmationUIClosed(LoginUIService::SYNC_WITH_DEFAULT_SETTINGS); | 711 SyncConfirmationUIClosed(LoginUIService::SYNC_WITH_DEFAULT_SETTINGS); |
| (...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1077 bool SyncTest::IsEncryptionComplete(int index) { | 1087 bool SyncTest::IsEncryptionComplete(int index) { |
| 1078 return ::IsEncryptionComplete(GetClient(index)->service()); | 1088 return ::IsEncryptionComplete(GetClient(index)->service()); |
| 1079 } | 1089 } |
| 1080 | 1090 |
| 1081 bool SyncTest::AwaitEncryptionComplete(int index) { | 1091 bool SyncTest::AwaitEncryptionComplete(int index) { |
| 1082 ProfileSyncService* service = GetClient(index)->service(); | 1092 ProfileSyncService* service = GetClient(index)->service(); |
| 1083 return EncryptionChecker(service).Wait(); | 1093 return EncryptionChecker(service).Wait(); |
| 1084 } | 1094 } |
| 1085 | 1095 |
| 1086 bool SyncTest::AwaitQuiescence() { | 1096 bool SyncTest::AwaitQuiescence() { |
| 1087 return ProfileSyncServiceHarness::AwaitQuiescence(clients()); | 1097 return ProfileSyncServiceHarness::AwaitQuiescence(GetSyncClients()); |
| 1088 } | 1098 } |
| 1089 | 1099 |
| 1090 bool SyncTest::UsingExternalServers() { | 1100 bool SyncTest::UsingExternalServers() { |
| 1091 return server_type_ == EXTERNAL_LIVE_SERVER; | 1101 return server_type_ == EXTERNAL_LIVE_SERVER; |
| 1092 } | 1102 } |
| 1093 | 1103 |
| 1094 bool SyncTest::ServerSupportsNotificationControl() const { | 1104 bool SyncTest::ServerSupportsNotificationControl() const { |
| 1095 EXPECT_NE(SERVER_TYPE_UNDECIDED, server_type_); | 1105 EXPECT_NE(SERVER_TYPE_UNDECIDED, server_type_); |
| 1096 | 1106 |
| 1097 // Supported only if we're using the python testserver. | 1107 // Supported only if we're using the python testserver. |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1213 bool SyncTest::ClearServerData(ProfileSyncServiceHarness* harness) { | 1223 bool SyncTest::ClearServerData(ProfileSyncServiceHarness* harness) { |
| 1214 // At this point our birthday is good. | 1224 // At this point our birthday is good. |
| 1215 base::RunLoop run_loop; | 1225 base::RunLoop run_loop; |
| 1216 harness->service()->ClearServerDataForTest(run_loop.QuitClosure()); | 1226 harness->service()->ClearServerDataForTest(run_loop.QuitClosure()); |
| 1217 run_loop.Run(); | 1227 run_loop.Run(); |
| 1218 | 1228 |
| 1219 // Our birthday is invalidated on the server here so restart sync to get | 1229 // Our birthday is invalidated on the server here so restart sync to get |
| 1220 // the new birthday from the server. | 1230 // the new birthday from the server. |
| 1221 return harness->RestartSyncService(); | 1231 return harness->RestartSyncService(); |
| 1222 } | 1232 } |
| OLD | NEW |