Commit 14feef5e authored by Marc Treib's avatar Marc Treib Committed by Commit Bot

ProfileSyncServiceStartupTest: Prepare for IdentityManager

This merges IssueTestTokens into SimulateTestUserSignin. IdentityManager
doesn't know of this distinction (signed in but no tokens), and only one
of the (non-disabled) tests depends on it.

Bug: 825190
Change-Id: Id6695ba2febc973c6a0b670624bb1ecf9ed3e0ae
Reviewed-on: https://chromium-review.googlesource.com/1007274Reviewed-by: default avatarColin Blundell <blundell@chromium.org>
Commit-Queue: Marc Treib <treib@chromium.org>
Cr-Commit-Position: refs/heads/master@{#550128}
parent 5b74b87c
......@@ -97,11 +97,6 @@ class ProfileSyncServiceStartupTest : public testing::Test {
sync_service_->AddObserver(&observer_);
}
void IssueTestTokens(const std::string& account_id) {
profile_sync_service_bundle_.auth_service()->UpdateCredentials(
account_id, "oauth2_login_token");
}
void SetError(DataTypeManager::ConfigureResult* result) {
syncer::DataTypeStatusTable::TypeErrorMap errors;
errors[syncer::BOOKMARKS] =
......@@ -111,7 +106,7 @@ class ProfileSyncServiceStartupTest : public testing::Test {
}
protected:
std::string SimulateTestUserSignin(ProfileSyncService* sync_service) {
void SimulateTestUserSignin() {
std::string account_id =
profile_sync_service_bundle_.account_tracker()->SeedAccountInfo(kGaiaId,
kEmail);
......@@ -121,12 +116,10 @@ class ProfileSyncServiceStartupTest : public testing::Test {
profile_sync_service_bundle_.signin_manager()->SignIn(kGaiaId, kEmail,
kDummyPassword);
#else
profile_sync_service_bundle_.signin_manager()->SetAuthenticatedAccountInfo(
kGaiaId, kEmail);
if (sync_service)
sync_service->GoogleSigninSucceeded(account_id, kEmail);
profile_sync_service_bundle_.signin_manager()->SignIn(account_id);
#endif
return account_id;
profile_sync_service_bundle_.auth_service()->UpdateCredentials(
account_id, "oauth2_login_token");
}
DataTypeManagerMock* SetUpDataTypeManager() {
......@@ -159,7 +152,17 @@ class ProfileSyncServiceStartupCrosTest : public ProfileSyncServiceStartupTest {
public:
ProfileSyncServiceStartupCrosTest() {
CreateSyncService(ProfileSyncService::AUTO_START);
SimulateTestUserSignin(nullptr);
// Set the primary account *without* providing an OAuth token.
std::string account_id =
profile_sync_service_bundle_.account_tracker()->SeedAccountInfo(kGaiaId,
kEmail);
#if !defined(OS_CHROMEOS)
const char kDummyPassword[] = "foobar";
profile_sync_service_bundle_.signin_manager()->SignIn(kGaiaId, kEmail,
kDummyPassword);
#else
profile_sync_service_bundle_.signin_manager()->SignIn(account_id);
#endif
EXPECT_TRUE(
profile_sync_service_bundle_.signin_manager()->IsAuthenticated());
}
......@@ -198,10 +201,7 @@ TEST_F(ProfileSyncServiceStartupTest, StartFirstTime) {
EXPECT_FALSE(sync_service_->IsSyncConfirmationNeeded());
// Simulate successful signin as test_user.
std::string account_id = SimulateTestUserSignin(sync_service_.get());
ON_CALL(*data_type_manager, IsNigoriEnabled()).WillByDefault(Return(true));
// Create some tokens in the token service.
IssueTestTokens(account_id);
SimulateTestUserSignin();
// Simulate the UI telling sync it has finished setting up.
sync_blocker.reset();
......@@ -231,9 +231,7 @@ TEST_F(ProfileSyncServiceStartupTest, DISABLED_StartNoCredentials) {
auto sync_blocker = sync_service_->GetSetupInProgressHandle();
// Simulate successful signin as test_user.
std::string account_id = SimulateTestUserSignin(sync_service_.get());
profile_sync_service_bundle_.auth_service()->LoadCredentials(account_id);
SimulateTestUserSignin();
sync_blocker.reset();
// ProfileSyncService should try to start by requesting access token.
......@@ -246,7 +244,7 @@ TEST_F(ProfileSyncServiceStartupTest, DISABLED_StartNoCredentials) {
// TODO(pavely): Reenable test once android is switched to oauth2.
TEST_F(ProfileSyncServiceStartupTest, DISABLED_StartInvalidCredentials) {
CreateSyncService(ProfileSyncService::MANUAL_START);
std::string account_id = SimulateTestUserSignin(sync_service_.get());
SimulateTestUserSignin();
FakeSyncEngine* mock_sbh = SetUpSyncEngine();
// Tell the backend to stall while downloading control types (simulating an
......@@ -270,7 +268,7 @@ TEST_F(ProfileSyncServiceStartupTest, DISABLED_StartInvalidCredentials) {
auto sync_blocker = sync_service_->GetSetupInProgressHandle();
// Simulate successful signin.
SimulateTestUserSignin(sync_service_.get());
SimulateTestUserSignin();
sync_blocker.reset();
......@@ -304,17 +302,14 @@ TEST_F(ProfileSyncServiceStartupCrosTest, StartFirstTime) {
EXPECT_CALL(*data_type_manager, Stop());
EXPECT_CALL(observer_, OnStateChanged(_)).Times(AnyNumber());
IssueTestTokens(
profile_sync_service_bundle_.account_tracker()->PickAccountIdForAccount(
"12345", kEmail));
SimulateTestUserSignin();
sync_service_->Initialize();
EXPECT_TRUE(sync_service_->IsSyncActive());
}
TEST_F(ProfileSyncServiceStartupTest, StartNormal) {
// Pre load the tokens
CreateSyncService(ProfileSyncService::MANUAL_START);
std::string account_id = SimulateTestUserSignin(sync_service_.get());
SimulateTestUserSignin();
sync_service_->SetFirstSetupComplete();
SetUpSyncEngine();
DataTypeManagerMock* data_type_manager = SetUpDataTypeManager();
......@@ -325,8 +320,6 @@ TEST_F(ProfileSyncServiceStartupTest, StartNormal) {
EXPECT_CALL(observer_, OnStateChanged(_)).Times(AnyNumber());
ON_CALL(*data_type_manager, IsNigoriEnabled()).WillByDefault(Return(true));
IssueTestTokens(account_id);
sync_service_->Initialize();
}
......@@ -343,9 +336,8 @@ TEST_F(ProfileSyncServiceStartupTest, StartRecoverDatatypePrefs) {
syncer::SyncPrefs::GetPrefNameForDataType(iter.Get()));
}
// Pre load the tokens
CreateSyncService(ProfileSyncService::MANUAL_START);
std::string account_id = SimulateTestUserSignin(sync_service_.get());
SimulateTestUserSignin();
sync_service_->SetFirstSetupComplete();
SetUpSyncEngine();
DataTypeManagerMock* data_type_manager = SetUpDataTypeManager();
......@@ -356,7 +348,6 @@ TEST_F(ProfileSyncServiceStartupTest, StartRecoverDatatypePrefs) {
EXPECT_CALL(observer_, OnStateChanged(_)).Times(AnyNumber());
ON_CALL(*data_type_manager, IsNigoriEnabled()).WillByDefault(Return(true));
IssueTestTokens(account_id);
sync_service_->Initialize();
EXPECT_TRUE(
......@@ -370,9 +361,8 @@ TEST_F(ProfileSyncServiceStartupTest, StartDontRecoverDatatypePrefs) {
// enabled.
pref_service()->SetBoolean(syncer::prefs::kSyncKeepEverythingSynced, false);
// Pre load the tokens
CreateSyncService(ProfileSyncService::MANUAL_START);
std::string account_id = SimulateTestUserSignin(sync_service_.get());
SimulateTestUserSignin();
sync_service_->SetFirstSetupComplete();
SetUpSyncEngine();
DataTypeManagerMock* data_type_manager = SetUpDataTypeManager();
......@@ -382,7 +372,6 @@ TEST_F(ProfileSyncServiceStartupTest, StartDontRecoverDatatypePrefs) {
EXPECT_CALL(*data_type_manager, Stop()).Times(1);
EXPECT_CALL(observer_, OnStateChanged(_)).Times(AnyNumber());
ON_CALL(*data_type_manager, IsNigoriEnabled()).WillByDefault(Return(true));
IssueTestTokens(account_id);
sync_service_->Initialize();
EXPECT_FALSE(
......@@ -405,7 +394,7 @@ TEST_F(ProfileSyncServiceStartupTest, ManagedStartup) {
TEST_F(ProfileSyncServiceStartupTest, SwitchManaged) {
CreateSyncService(ProfileSyncService::MANUAL_START);
std::string account_id = SimulateTestUserSignin(sync_service_.get());
SimulateTestUserSignin();
sync_service_->SetFirstSetupComplete();
SetUpSyncEngine();
DataTypeManagerMock* data_type_manager = SetUpDataTypeManager();
......@@ -414,7 +403,6 @@ TEST_F(ProfileSyncServiceStartupTest, SwitchManaged) {
.WillRepeatedly(Return(DataTypeManager::CONFIGURED));
EXPECT_CALL(observer_, OnStateChanged(_)).Times(AnyNumber());
ON_CALL(*data_type_manager, IsNigoriEnabled()).WillByDefault(Return(true));
IssueTestTokens(account_id);
sync_service_->Initialize();
EXPECT_TRUE(sync_service_->IsEngineInitialized());
EXPECT_TRUE(sync_service_->IsSyncActive());
......@@ -441,7 +429,7 @@ TEST_F(ProfileSyncServiceStartupTest, SwitchManaged) {
TEST_F(ProfileSyncServiceStartupTest, StartFailure) {
CreateSyncService(ProfileSyncService::MANUAL_START);
std::string account_id = SimulateTestUserSignin(sync_service_.get());
SimulateTestUserSignin();
sync_service_->SetFirstSetupComplete();
SetUpSyncEngine();
DataTypeManagerMock* data_type_manager = SetUpDataTypeManager();
......@@ -459,15 +447,13 @@ TEST_F(ProfileSyncServiceStartupTest, StartFailure) {
.WillOnce(Return(DataTypeManager::STOPPED));
EXPECT_CALL(observer_, OnStateChanged(_)).Times(AnyNumber());
ON_CALL(*data_type_manager, IsNigoriEnabled()).WillByDefault(Return(true));
IssueTestTokens(account_id);
sync_service_->Initialize();
EXPECT_TRUE(sync_service_->HasUnrecoverableError());
}
TEST_F(ProfileSyncServiceStartupTest, StartDownloadFailed) {
// Pre load the tokens
CreateSyncService(ProfileSyncService::MANUAL_START);
std::string account_id = SimulateTestUserSignin(sync_service_.get());
SimulateTestUserSignin();
FakeSyncEngine* mock_sbh = SetUpSyncEngine();
mock_sbh->set_fail_initial_download(true);
......@@ -477,7 +463,6 @@ TEST_F(ProfileSyncServiceStartupTest, StartDownloadFailed) {
sync_service_->Initialize();
auto sync_blocker = sync_service_->GetSetupInProgressHandle();
IssueTestTokens(account_id);
sync_blocker.reset();
EXPECT_FALSE(sync_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