Commit ba9df781 authored by Marc Treib's avatar Marc Treib Committed by Commit Bot

Small cleanups in ProfileSyncServiceTest

Bug: none
Change-Id: I25d60383abd1d62124d099bb1e364c32981729af
Reviewed-on: https://chromium-review.googlesource.com/1107699
Commit-Queue: Marc Treib <treib@chromium.org>
Reviewed-by: default avatarJan Krcal <jkrcal@chromium.org>
Cr-Commit-Position: refs/heads/master@{#568812}
parent aba0cdeb
...@@ -9,9 +9,9 @@ ...@@ -9,9 +9,9 @@
#include "base/callback.h" #include "base/callback.h"
#include "base/command_line.h" #include "base/command_line.h"
#include "base/run_loop.h" #include "base/run_loop.h"
#include "base/test/bind_test_util.h"
#include "base/test/scoped_feature_list.h" #include "base/test/scoped_feature_list.h"
#include "base/test/scoped_task_environment.h" #include "base/test/scoped_task_environment.h"
#include "base/threading/thread_task_runner_handle.h"
#include "base/values.h" #include "base/values.h"
#include "components/browser_sync/browser_sync_switches.h" #include "components/browser_sync/browser_sync_switches.h"
#include "components/browser_sync/profile_sync_test_util.h" #include "components/browser_sync/profile_sync_test_util.h"
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
#include "testing/gmock/include/gmock/gmock.h" #include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
using testing::_;
using testing::ByMove; using testing::ByMove;
using testing::Return; using testing::Return;
...@@ -43,7 +44,8 @@ namespace { ...@@ -43,7 +44,8 @@ namespace {
class FakeDataTypeManager : public syncer::DataTypeManager { class FakeDataTypeManager : public syncer::DataTypeManager {
public: public:
using ConfigureCalled = base::Callback<void(syncer::ConfigureReason)>; using ConfigureCalled =
base::RepeatingCallback<void(syncer::ConfigureReason)>;
explicit FakeDataTypeManager(const ConfigureCalled& configure_called) explicit FakeDataTypeManager(const ConfigureCalled& configure_called)
: configure_called_(configure_called) {} : configure_called_(configure_called) {}
...@@ -71,14 +73,10 @@ class FakeDataTypeManager : public syncer::DataTypeManager { ...@@ -71,14 +73,10 @@ class FakeDataTypeManager : public syncer::DataTypeManager {
ConfigureCalled configure_called_; ConfigureCalled configure_called_;
}; };
ACTION_P(ReturnNewDataTypeManager, configure_called) { ACTION_P(ReturnNewFakeDataTypeManager, configure_called) {
return std::make_unique<FakeDataTypeManager>(configure_called); return std::make_unique<FakeDataTypeManager>(configure_called);
} }
using testing::Return;
using testing::StrictMock;
using testing::_;
class TestSyncServiceObserver : public syncer::SyncServiceObserver { class TestSyncServiceObserver : public syncer::SyncServiceObserver {
public: public:
TestSyncServiceObserver() TestSyncServiceObserver()
...@@ -100,7 +98,7 @@ class TestSyncServiceObserver : public syncer::SyncServiceObserver { ...@@ -100,7 +98,7 @@ class TestSyncServiceObserver : public syncer::SyncServiceObserver {
// A variant of the FakeSyncEngine that won't automatically call back when asked // A variant of the FakeSyncEngine that won't automatically call back when asked
// to initialized. Allows us to test things that could happen while backend init // to initialized. Allows us to test things that could happen while backend init
// is in progress. // is in progress.
class SyncEngineNoReturn : public syncer::FakeSyncEngine { class FakeSyncEngineNoReturn : public syncer::FakeSyncEngine {
void Initialize(InitParams params) override {} void Initialize(InitParams params) override {}
}; };
...@@ -133,10 +131,11 @@ class FakeSyncEngineCollectCredentials : public syncer::FakeSyncEngine { ...@@ -133,10 +131,11 @@ class FakeSyncEngineCollectCredentials : public syncer::FakeSyncEngine {
// FakeSyncEngine that calls an external callback when ClearServerData is // FakeSyncEngine that calls an external callback when ClearServerData is
// called. // called.
class SyncEngineCaptureClearServerData : public syncer::FakeSyncEngine { class FakeSyncEngineCaptureClearServerData : public syncer::FakeSyncEngine {
public: public:
using ClearServerDataCalled = base::Callback<void(const base::Closure&)>; using ClearServerDataCalled =
explicit SyncEngineCaptureClearServerData( base::RepeatingCallback<void(const base::Closure&)>;
explicit FakeSyncEngineCaptureClearServerData(
const ClearServerDataCalled& clear_server_data_called) const ClearServerDataCalled& clear_server_data_called)
: clear_server_data_called_(clear_server_data_called) {} : clear_server_data_called_(clear_server_data_called) {}
...@@ -164,7 +163,7 @@ void OnClearServerDataCalled(base::Closure* captured_callback, ...@@ -164,7 +163,7 @@ void OnClearServerDataCalled(base::Closure* captured_callback,
// testing the SyncEngine. // testing the SyncEngine.
class ProfileSyncServiceTest : public ::testing::Test { class ProfileSyncServiceTest : public ::testing::Test {
protected: protected:
ProfileSyncServiceTest() : component_factory_(nullptr) {} ProfileSyncServiceTest() {}
~ProfileSyncServiceTest() override {} ~ProfileSyncServiceTest() override {}
void SetUp() override { void SetUp() override {
...@@ -174,20 +173,18 @@ class ProfileSyncServiceTest : public ::testing::Test { ...@@ -174,20 +173,18 @@ class ProfileSyncServiceTest : public ::testing::Test {
void TearDown() override { void TearDown() override {
// Kill the service before the profile. // Kill the service before the profile.
if (service_) ShutdownAndDeleteService();
service_->Shutdown();
service_.reset();
} }
void IssueTestTokens() { void SignIn() {
identity::MakePrimaryAccountAvailable(signin_manager(), auth_service(), identity::MakePrimaryAccountAvailable(signin_manager(), auth_service(),
identity_manager(), identity_manager(),
"test_user@gmail.com"); "test_user@gmail.com");
} }
void CreateService(ProfileSyncService::StartBehavior behavior) { void CreateService(ProfileSyncService::StartBehavior behavior) {
component_factory_ = profile_sync_service_bundle_.component_factory(); DCHECK(!service_);
ProfileSyncServiceBundle::SyncClientBuilder builder( ProfileSyncServiceBundle::SyncClientBuilder builder(
&profile_sync_service_bundle_); &profile_sync_service_bundle_);
ProfileSyncService::InitParams init_params = ProfileSyncService::InitParams init_params =
...@@ -198,7 +195,7 @@ class ProfileSyncServiceTest : public ::testing::Test { ...@@ -198,7 +195,7 @@ class ProfileSyncServiceTest : public ::testing::Test {
service_ = std::make_unique<ProfileSyncService>(std::move(init_params)); service_ = std::make_unique<ProfileSyncService>(std::move(init_params));
ON_CALL(*component_factory_, CreateCommonDataTypeControllers(_, _)) ON_CALL(*component_factory(), CreateCommonDataTypeControllers(_, _))
.WillByDefault(testing::InvokeWithoutArgs([=]() { .WillByDefault(testing::InvokeWithoutArgs([=]() {
syncer::DataTypeController::TypeVector controllers; syncer::DataTypeController::TypeVector controllers;
controllers.push_back( controllers.push_back(
...@@ -206,15 +203,16 @@ class ProfileSyncServiceTest : public ::testing::Test { ...@@ -206,15 +203,16 @@ class ProfileSyncServiceTest : public ::testing::Test {
syncer::BOOKMARKS)); syncer::BOOKMARKS));
return controllers; return controllers;
})); }));
ON_CALL(*component_factory_, CreateSyncEngine(_, _, _, _)) ON_CALL(*component_factory(), CreateSyncEngine(_, _, _, _))
.WillByDefault(ReturnNewFakeSyncEngine()); .WillByDefault(ReturnNewFakeSyncEngine());
ON_CALL(*component_factory_, CreateDataTypeManager(_, _, _, _, _, _)) ON_CALL(*component_factory(), CreateDataTypeManager(_, _, _, _, _, _))
.WillByDefault( .WillByDefault(
ReturnNewDataTypeManager(GetDefaultConfigureCalledCallback())); ReturnNewFakeDataTypeManager(GetDefaultConfigureCalledCallback()));
} }
void CreateServiceWithLocalSyncBackend() { void CreateServiceWithLocalSyncBackend() {
component_factory_ = profile_sync_service_bundle_.component_factory(); DCHECK(!service_);
ProfileSyncServiceBundle::SyncClientBuilder builder( ProfileSyncServiceBundle::SyncClientBuilder builder(
&profile_sync_service_bundle_); &profile_sync_service_bundle_);
ProfileSyncService::InitParams init_params = ProfileSyncService::InitParams init_params =
...@@ -227,7 +225,7 @@ class ProfileSyncServiceTest : public ::testing::Test { ...@@ -227,7 +225,7 @@ class ProfileSyncServiceTest : public ::testing::Test {
service_ = std::make_unique<ProfileSyncService>(std::move(init_params)); service_ = std::make_unique<ProfileSyncService>(std::move(init_params));
ON_CALL(*component_factory_, CreateCommonDataTypeControllers(_, _)) ON_CALL(*component_factory(), CreateCommonDataTypeControllers(_, _))
.WillByDefault(testing::InvokeWithoutArgs([=]() { .WillByDefault(testing::InvokeWithoutArgs([=]() {
syncer::DataTypeController::TypeVector controllers; syncer::DataTypeController::TypeVector controllers;
controllers.push_back( controllers.push_back(
...@@ -235,11 +233,11 @@ class ProfileSyncServiceTest : public ::testing::Test { ...@@ -235,11 +233,11 @@ class ProfileSyncServiceTest : public ::testing::Test {
syncer::BOOKMARKS)); syncer::BOOKMARKS));
return controllers; return controllers;
})); }));
ON_CALL(*component_factory_, CreateSyncEngine(_, _, _, _)) ON_CALL(*component_factory(), CreateSyncEngine(_, _, _, _))
.WillByDefault(ReturnNewFakeSyncEngine()); .WillByDefault(ReturnNewFakeSyncEngine());
ON_CALL(*component_factory_, CreateDataTypeManager(_, _, _, _, _, _)) ON_CALL(*component_factory(), CreateDataTypeManager(_, _, _, _, _, _))
.WillByDefault( .WillByDefault(
ReturnNewDataTypeManager(GetDefaultConfigureCalledCallback())); ReturnNewFakeDataTypeManager(GetDefaultConfigureCalledCallback()));
} }
void ShutdownAndDeleteService() { void ShutdownAndDeleteService() {
...@@ -281,16 +279,12 @@ class ProfileSyncServiceTest : public ::testing::Test { ...@@ -281,16 +279,12 @@ class ProfileSyncServiceTest : public ::testing::Test {
base::Unretained(this)); base::Unretained(this));
} }
void OnConfigureCalledRecordReason(syncer::ConfigureReason* reason_dest,
syncer::ConfigureReason reason) {
DCHECK(reason_dest);
*reason_dest = reason;
}
FakeDataTypeManager::ConfigureCalled GetRecordingConfigureCalledCallback( FakeDataTypeManager::ConfigureCalled GetRecordingConfigureCalledCallback(
syncer::ConfigureReason* reason) { syncer::ConfigureReason* reason_dest) {
return base::Bind(&ProfileSyncServiceTest::OnConfigureCalledRecordReason, return base::BindLambdaForTesting(
base::Unretained(this), reason); [reason_dest](syncer::ConfigureReason reason) {
*reason_dest = reason;
});
} }
AccountTrackerService* account_tracker() { AccountTrackerService* account_tracker() {
...@@ -322,17 +316,13 @@ class ProfileSyncServiceTest : public ::testing::Test { ...@@ -322,17 +316,13 @@ class ProfileSyncServiceTest : public ::testing::Test {
} }
syncer::SyncApiComponentFactoryMock* component_factory() { syncer::SyncApiComponentFactoryMock* component_factory() {
return component_factory_; return profile_sync_service_bundle_.component_factory();
} }
private: private:
base::test::ScopedTaskEnvironment scoped_task_environment_; base::test::ScopedTaskEnvironment scoped_task_environment_;
ProfileSyncServiceBundle profile_sync_service_bundle_; ProfileSyncServiceBundle profile_sync_service_bundle_;
std::unique_ptr<ProfileSyncService> service_; std::unique_ptr<ProfileSyncService> service_;
// The current component factory used by sync. May be null if the server
// hasn't been created yet.
syncer::SyncApiComponentFactoryMock* component_factory_;
}; };
// Verify that the server URLs are sane. // Verify that the server URLs are sane.
...@@ -348,12 +338,13 @@ TEST_F(ProfileSyncServiceTest, InitialState) { ...@@ -348,12 +338,13 @@ TEST_F(ProfileSyncServiceTest, InitialState) {
TEST_F(ProfileSyncServiceTest, SuccessfulInitialization) { TEST_F(ProfileSyncServiceTest, SuccessfulInitialization) {
prefs()->SetManagedPref(syncer::prefs::kSyncManaged, prefs()->SetManagedPref(syncer::prefs::kSyncManaged,
std::make_unique<base::Value>(false)); std::make_unique<base::Value>(false));
IssueTestTokens(); SignIn();
CreateService(ProfileSyncService::AUTO_START); CreateService(ProfileSyncService::AUTO_START);
EXPECT_CALL(*component_factory(), CreateSyncEngine(_, _, _, _)) EXPECT_CALL(*component_factory(), CreateSyncEngine(_, _, _, _))
.WillOnce(ReturnNewFakeSyncEngine()); .WillOnce(ReturnNewFakeSyncEngine());
EXPECT_CALL(*component_factory(), CreateDataTypeManager(_, _, _, _, _, _)) EXPECT_CALL(*component_factory(), CreateDataTypeManager(_, _, _, _, _, _))
.WillOnce(ReturnNewDataTypeManager(GetDefaultConfigureCalledCallback())); .WillOnce(
ReturnNewFakeDataTypeManager(GetDefaultConfigureCalledCallback()));
InitializeForNthSync(); InitializeForNthSync();
EXPECT_FALSE(service()->IsManaged()); EXPECT_FALSE(service()->IsManaged());
EXPECT_TRUE(service()->IsSyncActive()); EXPECT_TRUE(service()->IsSyncActive());
...@@ -367,7 +358,8 @@ TEST_F(ProfileSyncServiceTest, SuccessfulLocalBackendInitialization) { ...@@ -367,7 +358,8 @@ TEST_F(ProfileSyncServiceTest, SuccessfulLocalBackendInitialization) {
EXPECT_CALL(*component_factory(), CreateSyncEngine(_, _, _, _)) EXPECT_CALL(*component_factory(), CreateSyncEngine(_, _, _, _))
.WillOnce(ReturnNewFakeSyncEngine()); .WillOnce(ReturnNewFakeSyncEngine());
EXPECT_CALL(*component_factory(), CreateDataTypeManager(_, _, _, _, _, _)) EXPECT_CALL(*component_factory(), CreateDataTypeManager(_, _, _, _, _, _))
.WillOnce(ReturnNewDataTypeManager(GetDefaultConfigureCalledCallback())); .WillOnce(
ReturnNewFakeDataTypeManager(GetDefaultConfigureCalledCallback()));
InitializeForNthSync(); InitializeForNthSync();
EXPECT_FALSE(service()->IsManaged()); EXPECT_FALSE(service()->IsManaged());
EXPECT_TRUE(service()->IsSyncActive()); EXPECT_TRUE(service()->IsSyncActive());
...@@ -379,7 +371,7 @@ TEST_F(ProfileSyncServiceTest, SuccessfulLocalBackendInitialization) { ...@@ -379,7 +371,7 @@ TEST_F(ProfileSyncServiceTest, SuccessfulLocalBackendInitialization) {
TEST_F(ProfileSyncServiceTest, NeedsConfirmation) { TEST_F(ProfileSyncServiceTest, NeedsConfirmation) {
prefs()->SetManagedPref(syncer::prefs::kSyncManaged, prefs()->SetManagedPref(syncer::prefs::kSyncManaged,
std::make_unique<base::Value>(false)); std::make_unique<base::Value>(false));
IssueTestTokens(); SignIn();
CreateService(ProfileSyncService::MANUAL_START); CreateService(ProfileSyncService::MANUAL_START);
syncer::SyncPrefs sync_prefs(prefs()); syncer::SyncPrefs sync_prefs(prefs());
...@@ -417,7 +409,7 @@ TEST_F(ProfileSyncServiceTest, SetupInProgress) { ...@@ -417,7 +409,7 @@ TEST_F(ProfileSyncServiceTest, SetupInProgress) {
TEST_F(ProfileSyncServiceTest, DisabledByPolicyBeforeInit) { TEST_F(ProfileSyncServiceTest, DisabledByPolicyBeforeInit) {
prefs()->SetManagedPref(syncer::prefs::kSyncManaged, prefs()->SetManagedPref(syncer::prefs::kSyncManaged,
std::make_unique<base::Value>(true)); std::make_unique<base::Value>(true));
IssueTestTokens(); SignIn();
CreateService(ProfileSyncService::AUTO_START); CreateService(ProfileSyncService::AUTO_START);
InitializeForNthSync(); InitializeForNthSync();
EXPECT_TRUE(service()->IsManaged()); EXPECT_TRUE(service()->IsManaged());
...@@ -427,7 +419,7 @@ TEST_F(ProfileSyncServiceTest, DisabledByPolicyBeforeInit) { ...@@ -427,7 +419,7 @@ TEST_F(ProfileSyncServiceTest, DisabledByPolicyBeforeInit) {
// Verify that disable by enterprise policy works even after the backend has // Verify that disable by enterprise policy works even after the backend has
// been initialized. // been initialized.
TEST_F(ProfileSyncServiceTest, DisabledByPolicyAfterInit) { TEST_F(ProfileSyncServiceTest, DisabledByPolicyAfterInit) {
IssueTestTokens(); SignIn();
CreateService(ProfileSyncService::AUTO_START); CreateService(ProfileSyncService::AUTO_START);
InitializeForNthSync(); InitializeForNthSync();
...@@ -441,14 +433,15 @@ TEST_F(ProfileSyncServiceTest, DisabledByPolicyAfterInit) { ...@@ -441,14 +433,15 @@ TEST_F(ProfileSyncServiceTest, DisabledByPolicyAfterInit) {
EXPECT_FALSE(service()->IsSyncActive()); EXPECT_FALSE(service()->IsSyncActive());
} }
// Exercies the ProfileSyncService's code paths related to getting shut down // Exercises the ProfileSyncService's code paths related to getting shut down
// before the backend initialize call returns. // before the backend initialize call returns.
TEST_F(ProfileSyncServiceTest, AbortedByShutdown) { TEST_F(ProfileSyncServiceTest, AbortedByShutdown) {
CreateService(ProfileSyncService::AUTO_START); CreateService(ProfileSyncService::AUTO_START);
ON_CALL(*component_factory(), CreateSyncEngine(_, _, _, _)) ON_CALL(*component_factory(), CreateSyncEngine(_, _, _, _))
.WillByDefault(Return(ByMove(std::make_unique<SyncEngineNoReturn>()))); .WillByDefault(
Return(ByMove(std::make_unique<FakeSyncEngineNoReturn>())));
IssueTestTokens(); SignIn();
InitializeForNthSync(); InitializeForNthSync();
ASSERT_FALSE(service()->IsSyncActive()); ASSERT_FALSE(service()->IsSyncActive());
...@@ -458,7 +451,7 @@ TEST_F(ProfileSyncServiceTest, AbortedByShutdown) { ...@@ -458,7 +451,7 @@ TEST_F(ProfileSyncServiceTest, AbortedByShutdown) {
// Test RequestStop() before we've initialized the backend. // Test RequestStop() before we've initialized the backend.
TEST_F(ProfileSyncServiceTest, EarlyRequestStop) { TEST_F(ProfileSyncServiceTest, EarlyRequestStop) {
CreateService(ProfileSyncService::AUTO_START); CreateService(ProfileSyncService::AUTO_START);
IssueTestTokens(); SignIn();
service()->RequestStop(ProfileSyncService::KEEP_DATA); service()->RequestStop(ProfileSyncService::KEEP_DATA);
EXPECT_FALSE(service()->IsSyncRequested()); EXPECT_FALSE(service()->IsSyncRequested());
...@@ -477,7 +470,7 @@ TEST_F(ProfileSyncServiceTest, EarlyRequestStop) { ...@@ -477,7 +470,7 @@ TEST_F(ProfileSyncServiceTest, EarlyRequestStop) {
// Test RequestStop() after we've initialized the backend. // Test RequestStop() after we've initialized the backend.
TEST_F(ProfileSyncServiceTest, DisableAndEnableSyncTemporarily) { TEST_F(ProfileSyncServiceTest, DisableAndEnableSyncTemporarily) {
CreateService(ProfileSyncService::AUTO_START); CreateService(ProfileSyncService::AUTO_START);
IssueTestTokens(); SignIn();
InitializeForNthSync(); InitializeForNthSync();
ASSERT_TRUE(service()->IsSyncActive()); ASSERT_TRUE(service()->IsSyncActive());
...@@ -499,7 +492,7 @@ TEST_F(ProfileSyncServiceTest, DisableAndEnableSyncTemporarily) { ...@@ -499,7 +492,7 @@ TEST_F(ProfileSyncServiceTest, DisableAndEnableSyncTemporarily) {
#if !defined(OS_CHROMEOS) #if !defined(OS_CHROMEOS)
TEST_F(ProfileSyncServiceTest, EnableSyncAndSignOut) { TEST_F(ProfileSyncServiceTest, EnableSyncAndSignOut) {
CreateService(ProfileSyncService::AUTO_START); CreateService(ProfileSyncService::AUTO_START);
IssueTestTokens(); SignIn();
InitializeForNthSync(); InitializeForNthSync();
EXPECT_TRUE(service()->IsSyncActive()); EXPECT_TRUE(service()->IsSyncActive());
...@@ -516,7 +509,7 @@ TEST_F(ProfileSyncServiceTest, EnableSyncAndSignOut) { ...@@ -516,7 +509,7 @@ TEST_F(ProfileSyncServiceTest, EnableSyncAndSignOut) {
TEST_F(ProfileSyncServiceTest, GetSyncTokenStatus) { TEST_F(ProfileSyncServiceTest, GetSyncTokenStatus) {
CreateService(ProfileSyncService::AUTO_START); CreateService(ProfileSyncService::AUTO_START);
IssueTestTokens(); SignIn();
InitializeForNthSync(); InitializeForNthSync();
// Initial status. // Initial status.
...@@ -551,7 +544,7 @@ TEST_F(ProfileSyncServiceTest, RevokeAccessTokenFromTokenService) { ...@@ -551,7 +544,7 @@ TEST_F(ProfileSyncServiceTest, RevokeAccessTokenFromTokenService) {
syncer::SyncCredentials init_credentials; syncer::SyncCredentials init_credentials;
CreateService(ProfileSyncService::AUTO_START); CreateService(ProfileSyncService::AUTO_START);
IssueTestTokens(); SignIn();
EXPECT_CALL(*component_factory(), CreateSyncEngine(_, _, _, _)) EXPECT_CALL(*component_factory(), CreateSyncEngine(_, _, _, _))
.WillOnce( .WillOnce(
Return(ByMove(std::make_unique<FakeSyncEngineCollectCredentials>( Return(ByMove(std::make_unique<FakeSyncEngineCollectCredentials>(
...@@ -599,7 +592,7 @@ TEST_F(ProfileSyncServiceTest, CredentialsRejectedByClient) { ...@@ -599,7 +592,7 @@ TEST_F(ProfileSyncServiceTest, CredentialsRejectedByClient) {
base::Unretained(&invalidate_credentials_called)); base::Unretained(&invalidate_credentials_called));
CreateService(ProfileSyncService::AUTO_START); CreateService(ProfileSyncService::AUTO_START);
IssueTestTokens(); SignIn();
EXPECT_CALL(*component_factory(), CreateSyncEngine(_, _, _, _)) EXPECT_CALL(*component_factory(), CreateSyncEngine(_, _, _, _))
.WillOnce( .WillOnce(
Return(ByMove(std::make_unique<FakeSyncEngineCollectCredentials>( Return(ByMove(std::make_unique<FakeSyncEngineCollectCredentials>(
...@@ -654,7 +647,7 @@ TEST_F(ProfileSyncServiceTest, SignOutRevokeAccessToken) { ...@@ -654,7 +647,7 @@ TEST_F(ProfileSyncServiceTest, SignOutRevokeAccessToken) {
syncer::SyncCredentials init_credentials; syncer::SyncCredentials init_credentials;
CreateService(ProfileSyncService::AUTO_START); CreateService(ProfileSyncService::AUTO_START);
IssueTestTokens(); SignIn();
EXPECT_CALL(*component_factory(), CreateSyncEngine(_, _, _, _)) EXPECT_CALL(*component_factory(), CreateSyncEngine(_, _, _, _))
.WillOnce( .WillOnce(
Return(ByMove(std::make_unique<FakeSyncEngineCollectCredentials>( Return(ByMove(std::make_unique<FakeSyncEngineCollectCredentials>(
...@@ -687,7 +680,7 @@ TEST_F(ProfileSyncServiceTest, SignOutRevokeAccessToken) { ...@@ -687,7 +680,7 @@ TEST_F(ProfileSyncServiceTest, SignOutRevokeAccessToken) {
// Verify that LastSyncedTime and local DeviceInfo is cleared on sign out. // Verify that LastSyncedTime and local DeviceInfo is cleared on sign out.
TEST_F(ProfileSyncServiceTest, ClearDataOnSignOut) { TEST_F(ProfileSyncServiceTest, ClearDataOnSignOut) {
IssueTestTokens(); SignIn();
CreateService(ProfileSyncService::AUTO_START); CreateService(ProfileSyncService::AUTO_START);
InitializeForNthSync(); InitializeForNthSync();
ASSERT_TRUE(service()->IsSyncActive()); ASSERT_TRUE(service()->IsSyncActive());
...@@ -712,7 +705,7 @@ TEST_F(ProfileSyncServiceTest, CredentialErrorReturned) { ...@@ -712,7 +705,7 @@ TEST_F(ProfileSyncServiceTest, CredentialErrorReturned) {
syncer::SyncCredentials init_credentials; syncer::SyncCredentials init_credentials;
CreateService(ProfileSyncService::AUTO_START); CreateService(ProfileSyncService::AUTO_START);
IssueTestTokens(); SignIn();
EXPECT_CALL(*component_factory(), CreateSyncEngine(_, _, _, _)) EXPECT_CALL(*component_factory(), CreateSyncEngine(_, _, _, _))
.WillOnce( .WillOnce(
Return(ByMove(std::make_unique<FakeSyncEngineCollectCredentials>( Return(ByMove(std::make_unique<FakeSyncEngineCollectCredentials>(
...@@ -771,7 +764,7 @@ TEST_F(ProfileSyncServiceTest, CredentialErrorClearsOnNewToken) { ...@@ -771,7 +764,7 @@ TEST_F(ProfileSyncServiceTest, CredentialErrorClearsOnNewToken) {
syncer::SyncCredentials init_credentials; syncer::SyncCredentials init_credentials;
CreateService(ProfileSyncService::AUTO_START); CreateService(ProfileSyncService::AUTO_START);
IssueTestTokens(); SignIn();
EXPECT_CALL(*component_factory(), CreateSyncEngine(_, _, _, _)) EXPECT_CALL(*component_factory(), CreateSyncEngine(_, _, _, _))
.WillOnce( .WillOnce(
Return(ByMove(std::make_unique<FakeSyncEngineCollectCredentials>( Return(ByMove(std::make_unique<FakeSyncEngineCollectCredentials>(
...@@ -844,7 +837,7 @@ TEST_F(ProfileSyncServiceTest, NoDisableSyncFlag) { ...@@ -844,7 +837,7 @@ TEST_F(ProfileSyncServiceTest, NoDisableSyncFlag) {
// Test Sync will stop after receive memory pressure // Test Sync will stop after receive memory pressure
TEST_F(ProfileSyncServiceTest, MemoryPressureRecording) { TEST_F(ProfileSyncServiceTest, MemoryPressureRecording) {
CreateService(ProfileSyncService::AUTO_START); CreateService(ProfileSyncService::AUTO_START);
IssueTestTokens(); SignIn();
InitializeForNthSync(); InitializeForNthSync();
ASSERT_TRUE(service()->IsSyncActive()); ASSERT_TRUE(service()->IsSyncActive());
...@@ -886,7 +879,7 @@ TEST_F(ProfileSyncServiceTest, OnLocalSetPassphraseEncryption) { ...@@ -886,7 +879,7 @@ TEST_F(ProfileSyncServiceTest, OnLocalSetPassphraseEncryption) {
base::test::ScopedFeatureList scoped_feature_list; base::test::ScopedFeatureList scoped_feature_list;
scoped_feature_list.InitAndEnableFeature( scoped_feature_list.InitAndEnableFeature(
switches::kSyncClearDataOnPassphraseEncryption); switches::kSyncClearDataOnPassphraseEncryption);
IssueTestTokens(); SignIn();
CreateService(ProfileSyncService::AUTO_START); CreateService(ProfileSyncService::AUTO_START);
base::Closure captured_callback; base::Closure captured_callback;
...@@ -897,11 +890,11 @@ TEST_F(ProfileSyncServiceTest, OnLocalSetPassphraseEncryption) { ...@@ -897,11 +890,11 @@ TEST_F(ProfileSyncServiceTest, OnLocalSetPassphraseEncryption) {
// CONFIGURE_REASON_NEWLY_ENABLED_DATA_TYPE. // CONFIGURE_REASON_NEWLY_ENABLED_DATA_TYPE.
EXPECT_CALL(*component_factory(), CreateSyncEngine(_, _, _, _)) EXPECT_CALL(*component_factory(), CreateSyncEngine(_, _, _, _))
.WillOnce( .WillOnce(
Return(ByMove(std::make_unique<SyncEngineCaptureClearServerData>( Return(ByMove(std::make_unique<FakeSyncEngineCaptureClearServerData>(
base::BindRepeating(&OnClearServerDataCalled, base::BindRepeating(&OnClearServerDataCalled,
base::Unretained(&captured_callback)))))); base::Unretained(&captured_callback))))));
EXPECT_CALL(*component_factory(), CreateDataTypeManager(_, _, _, _, _, _)) EXPECT_CALL(*component_factory(), CreateDataTypeManager(_, _, _, _, _, _))
.WillOnce(ReturnNewDataTypeManager( .WillOnce(ReturnNewFakeDataTypeManager(
GetRecordingConfigureCalledCallback(&configure_reason))); GetRecordingConfigureCalledCallback(&configure_reason)));
InitializeForNthSync(); InitializeForNthSync();
ASSERT_TRUE(service()->IsSyncActive()); ASSERT_TRUE(service()->IsSyncActive());
...@@ -930,7 +923,7 @@ TEST_F(ProfileSyncServiceTest, OnLocalSetPassphraseEncryption) { ...@@ -930,7 +923,7 @@ TEST_F(ProfileSyncServiceTest, OnLocalSetPassphraseEncryption) {
// restarted. // restarted.
configure_reason = syncer::CONFIGURE_REASON_UNKNOWN; configure_reason = syncer::CONFIGURE_REASON_UNKNOWN;
EXPECT_CALL(*component_factory(), CreateDataTypeManager(_, _, _, _, _, _)) EXPECT_CALL(*component_factory(), CreateDataTypeManager(_, _, _, _, _, _))
.WillOnce(ReturnNewDataTypeManager( .WillOnce(ReturnNewFakeDataTypeManager(
GetRecordingConfigureCalledCallback(&configure_reason))); GetRecordingConfigureCalledCallback(&configure_reason)));
captured_callback.Run(); captured_callback.Run();
testing::Mock::VerifyAndClearExpectations(component_factory()); testing::Mock::VerifyAndClearExpectations(component_factory());
...@@ -946,10 +939,10 @@ TEST_F(ProfileSyncServiceTest, ...@@ -946,10 +939,10 @@ TEST_F(ProfileSyncServiceTest,
base::test::ScopedFeatureList scoped_feature_list; base::test::ScopedFeatureList scoped_feature_list;
scoped_feature_list.InitAndEnableFeature( scoped_feature_list.InitAndEnableFeature(
switches::kSyncClearDataOnPassphraseEncryption); switches::kSyncClearDataOnPassphraseEncryption);
IssueTestTokens(); SignIn();
CreateService(ProfileSyncService::AUTO_START); CreateService(ProfileSyncService::AUTO_START);
EXPECT_CALL(*component_factory(), CreateDataTypeManager(_, _, _, _, _, _)) EXPECT_CALL(*component_factory(), CreateDataTypeManager(_, _, _, _, _, _))
.WillOnce(ReturnNewDataTypeManager( .WillOnce(ReturnNewFakeDataTypeManager(
GetRecordingConfigureCalledCallback(&configure_reason))); GetRecordingConfigureCalledCallback(&configure_reason)));
InitializeForNthSync(); InitializeForNthSync();
testing::Mock::VerifyAndClearExpectations(component_factory()); testing::Mock::VerifyAndClearExpectations(component_factory());
...@@ -971,11 +964,11 @@ TEST_F(ProfileSyncServiceTest, ...@@ -971,11 +964,11 @@ TEST_F(ProfileSyncServiceTest,
base::Closure captured_callback; base::Closure captured_callback;
EXPECT_CALL(*component_factory(), CreateSyncEngine(_, _, _, _)) EXPECT_CALL(*component_factory(), CreateSyncEngine(_, _, _, _))
.WillOnce( .WillOnce(
Return(ByMove(std::make_unique<SyncEngineCaptureClearServerData>( Return(ByMove(std::make_unique<FakeSyncEngineCaptureClearServerData>(
base::BindRepeating(&OnClearServerDataCalled, base::BindRepeating(&OnClearServerDataCalled,
base::Unretained(&captured_callback)))))); base::Unretained(&captured_callback))))));
EXPECT_CALL(*component_factory(), CreateDataTypeManager(_, _, _, _, _, _)) EXPECT_CALL(*component_factory(), CreateDataTypeManager(_, _, _, _, _, _))
.WillOnce(ReturnNewDataTypeManager( .WillOnce(ReturnNewFakeDataTypeManager(
GetRecordingConfigureCalledCallback(&configure_reason))); GetRecordingConfigureCalledCallback(&configure_reason)));
InitializeForNthSync(); InitializeForNthSync();
testing::Mock::VerifyAndClearExpectations(component_factory()); testing::Mock::VerifyAndClearExpectations(component_factory());
...@@ -995,7 +988,7 @@ TEST_F(ProfileSyncServiceTest, ...@@ -995,7 +988,7 @@ TEST_F(ProfileSyncServiceTest,
EXPECT_FALSE(captured_callback.is_null()); EXPECT_FALSE(captured_callback.is_null());
EXPECT_CALL(*component_factory(), CreateDataTypeManager(_, _, _, _, _, _)) EXPECT_CALL(*component_factory(), CreateDataTypeManager(_, _, _, _, _, _))
.WillOnce(ReturnNewDataTypeManager( .WillOnce(ReturnNewFakeDataTypeManager(
GetRecordingConfigureCalledCallback(&configure_reason))); GetRecordingConfigureCalledCallback(&configure_reason)));
captured_callback.Run(); captured_callback.Run();
testing::Mock::VerifyAndClearExpectations(component_factory()); testing::Mock::VerifyAndClearExpectations(component_factory());
...@@ -1011,11 +1004,11 @@ TEST_F(ProfileSyncServiceTest, ...@@ -1011,11 +1004,11 @@ TEST_F(ProfileSyncServiceTest,
base::test::ScopedFeatureList scoped_feature_list; base::test::ScopedFeatureList scoped_feature_list;
scoped_feature_list.InitAndEnableFeature( scoped_feature_list.InitAndEnableFeature(
switches::kSyncClearDataOnPassphraseEncryption); switches::kSyncClearDataOnPassphraseEncryption);
IssueTestTokens(); SignIn();
CreateService(ProfileSyncService::AUTO_START); CreateService(ProfileSyncService::AUTO_START);
EXPECT_CALL(*component_factory(), CreateSyncEngine(_, _, _, _)) EXPECT_CALL(*component_factory(), CreateSyncEngine(_, _, _, _))
.WillOnce( .WillOnce(
Return(ByMove(std::make_unique<SyncEngineCaptureClearServerData>( Return(ByMove(std::make_unique<FakeSyncEngineCaptureClearServerData>(
base::BindRepeating(&OnClearServerDataCalled, base::BindRepeating(&OnClearServerDataCalled,
base::Unretained(&captured_callback)))))); base::Unretained(&captured_callback))))));
InitializeForNthSync(); InitializeForNthSync();
...@@ -1033,11 +1026,11 @@ TEST_F(ProfileSyncServiceTest, ...@@ -1033,11 +1026,11 @@ TEST_F(ProfileSyncServiceTest,
CreateService(ProfileSyncService::AUTO_START); CreateService(ProfileSyncService::AUTO_START);
EXPECT_CALL(*component_factory(), CreateSyncEngine(_, _, _, _)) EXPECT_CALL(*component_factory(), CreateSyncEngine(_, _, _, _))
.WillOnce( .WillOnce(
Return(ByMove(std::make_unique<SyncEngineCaptureClearServerData>( Return(ByMove(std::make_unique<FakeSyncEngineCaptureClearServerData>(
base::BindRepeating(&OnClearServerDataCalled, base::BindRepeating(&OnClearServerDataCalled,
base::Unretained(&captured_callback)))))); base::Unretained(&captured_callback))))));
EXPECT_CALL(*component_factory(), CreateDataTypeManager(_, _, _, _, _, _)) EXPECT_CALL(*component_factory(), CreateDataTypeManager(_, _, _, _, _, _))
.WillOnce(ReturnNewDataTypeManager( .WillOnce(ReturnNewFakeDataTypeManager(
GetRecordingConfigureCalledCallback(&configure_reason))); GetRecordingConfigureCalledCallback(&configure_reason)));
InitializeForNthSync(); InitializeForNthSync();
testing::Mock::VerifyAndClearExpectations(component_factory()); testing::Mock::VerifyAndClearExpectations(component_factory());
...@@ -1059,7 +1052,7 @@ TEST_F(ProfileSyncServiceTest, ...@@ -1059,7 +1052,7 @@ TEST_F(ProfileSyncServiceTest,
EXPECT_FALSE(captured_callback.is_null()); EXPECT_FALSE(captured_callback.is_null());
EXPECT_CALL(*component_factory(), CreateDataTypeManager(_, _, _, _, _, _)) EXPECT_CALL(*component_factory(), CreateDataTypeManager(_, _, _, _, _, _))
.WillOnce(ReturnNewDataTypeManager( .WillOnce(ReturnNewFakeDataTypeManager(
GetRecordingConfigureCalledCallback(&configure_reason))); GetRecordingConfigureCalledCallback(&configure_reason)));
captured_callback.Run(); captured_callback.Run();
testing::Mock::VerifyAndClearExpectations(component_factory()); testing::Mock::VerifyAndClearExpectations(component_factory());
...@@ -1069,7 +1062,7 @@ TEST_F(ProfileSyncServiceTest, ...@@ -1069,7 +1062,7 @@ TEST_F(ProfileSyncServiceTest,
// Test that the passphrase prompt due to version change logic gets triggered // Test that the passphrase prompt due to version change logic gets triggered
// on a datatype type requesting startup, but only happens once. // on a datatype type requesting startup, but only happens once.
TEST_F(ProfileSyncServiceTest, PassphrasePromptDueToVersion) { TEST_F(ProfileSyncServiceTest, PassphrasePromptDueToVersion) {
IssueTestTokens(); SignIn();
CreateService(ProfileSyncService::AUTO_START); CreateService(ProfileSyncService::AUTO_START);
InitializeForNthSync(); InitializeForNthSync();
...@@ -1098,13 +1091,15 @@ TEST_F(ProfileSyncServiceTest, PassphrasePromptDueToVersion) { ...@@ -1098,13 +1091,15 @@ TEST_F(ProfileSyncServiceTest, PassphrasePromptDueToVersion) {
// Test that when ProfileSyncService receives actionable error // Test that when ProfileSyncService receives actionable error
// RESET_LOCAL_SYNC_DATA it restarts sync. // RESET_LOCAL_SYNC_DATA it restarts sync.
TEST_F(ProfileSyncServiceTest, ResetSyncData) { TEST_F(ProfileSyncServiceTest, ResetSyncData) {
IssueTestTokens(); SignIn();
CreateService(ProfileSyncService::AUTO_START); CreateService(ProfileSyncService::AUTO_START);
// Backend should get initialized two times: once during initialization and // Backend should get initialized two times: once during initialization and
// once when handling actionable error. // once when handling actionable error.
EXPECT_CALL(*component_factory(), CreateDataTypeManager(_, _, _, _, _, _)) EXPECT_CALL(*component_factory(), CreateDataTypeManager(_, _, _, _, _, _))
.WillOnce(ReturnNewDataTypeManager(GetDefaultConfigureCalledCallback())) .WillOnce(
.WillOnce(ReturnNewDataTypeManager(GetDefaultConfigureCalledCallback())); ReturnNewFakeDataTypeManager(GetDefaultConfigureCalledCallback()))
.WillOnce(
ReturnNewFakeDataTypeManager(GetDefaultConfigureCalledCallback()));
EXPECT_CALL(*component_factory(), CreateSyncEngine(_, _, _, _)) EXPECT_CALL(*component_factory(), CreateSyncEngine(_, _, _, _))
.WillOnce(ReturnNewFakeSyncEngine()) .WillOnce(ReturnNewFakeSyncEngine())
.WillOnce(ReturnNewFakeSyncEngine()); .WillOnce(ReturnNewFakeSyncEngine());
...@@ -1119,7 +1114,7 @@ TEST_F(ProfileSyncServiceTest, ResetSyncData) { ...@@ -1119,7 +1114,7 @@ TEST_F(ProfileSyncServiceTest, ResetSyncData) {
// Test that when ProfileSyncService receives actionable error // Test that when ProfileSyncService receives actionable error
// DISABLE_SYNC_ON_CLIENT it disables sync and signs out. // DISABLE_SYNC_ON_CLIENT it disables sync and signs out.
TEST_F(ProfileSyncServiceTest, DisableSyncOnClient) { TEST_F(ProfileSyncServiceTest, DisableSyncOnClient) {
IssueTestTokens(); SignIn();
CreateService(ProfileSyncService::AUTO_START); CreateService(ProfileSyncService::AUTO_START);
InitializeForNthSync(); InitializeForNthSync();
...@@ -1173,12 +1168,12 @@ TEST_F(ProfileSyncServiceTest, ConfigureDataTypeManagerReason) { ...@@ -1173,12 +1168,12 @@ TEST_F(ProfileSyncServiceTest, ConfigureDataTypeManagerReason) {
syncer::DataTypeManager::OK, syncer::ModelTypeSet()); syncer::DataTypeManager::OK, syncer::ModelTypeSet());
syncer::ConfigureReason configure_reason = syncer::CONFIGURE_REASON_UNKNOWN; syncer::ConfigureReason configure_reason = syncer::CONFIGURE_REASON_UNKNOWN;
IssueTestTokens(); SignIn();
// First sync. // First sync.
CreateService(ProfileSyncService::AUTO_START); CreateService(ProfileSyncService::AUTO_START);
EXPECT_CALL(*component_factory(), CreateDataTypeManager(_, _, _, _, _, _)) EXPECT_CALL(*component_factory(), CreateDataTypeManager(_, _, _, _, _, _))
.WillOnce(ReturnNewDataTypeManager( .WillOnce(ReturnNewFakeDataTypeManager(
GetRecordingConfigureCalledCallback(&configure_reason))); GetRecordingConfigureCalledCallback(&configure_reason)));
InitializeForFirstSync(); InitializeForFirstSync();
ASSERT_TRUE(service()->IsSyncActive()); ASSERT_TRUE(service()->IsSyncActive());
...@@ -1195,7 +1190,7 @@ TEST_F(ProfileSyncServiceTest, ConfigureDataTypeManagerReason) { ...@@ -1195,7 +1190,7 @@ TEST_F(ProfileSyncServiceTest, ConfigureDataTypeManagerReason) {
// Nth sync. // Nth sync.
CreateService(ProfileSyncService::AUTO_START); CreateService(ProfileSyncService::AUTO_START);
EXPECT_CALL(*component_factory(), CreateDataTypeManager(_, _, _, _, _, _)) EXPECT_CALL(*component_factory(), CreateDataTypeManager(_, _, _, _, _, _))
.WillOnce(ReturnNewDataTypeManager( .WillOnce(ReturnNewFakeDataTypeManager(
GetRecordingConfigureCalledCallback(&configure_reason))); GetRecordingConfigureCalledCallback(&configure_reason)));
InitializeForNthSync(); InitializeForNthSync();
ASSERT_TRUE(service()->IsSyncActive()); ASSERT_TRUE(service()->IsSyncActive());
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment