Commit 25f0157d authored by Marc Treib's avatar Marc Treib Committed by Commit Bot

ProfileSyncServiceHarness: don't sign in if already signed in

Changing the refresh token causes Sync (ServerConnectionManager in
particular) to mark the current access token as invalid. Since tests
typically always hand out the same access token string, any new access
token acquired later would also be considered invalid.

This was exposed by https://crrev.com/c/1148392, but the problem existed
all along.

Bug: 856179
Change-Id: I47e695e2415252281404b4e6e6170667ecf8180d
Reviewed-on: https://chromium-review.googlesource.com/1156595Reviewed-by: default avatarMikel Astiz <mastiz@chromium.org>
Commit-Queue: Marc Treib <treib@chromium.org>
Cr-Commit-Position: refs/heads/master@{#579410}
parent 26e4e80d
...@@ -174,14 +174,24 @@ bool ProfileSyncServiceHarness::SetupSync(syncer::ModelTypeSet synced_datatypes, ...@@ -174,14 +174,24 @@ bool ProfileSyncServiceHarness::SetupSync(syncer::ModelTypeSet synced_datatypes,
return false; return false;
} }
} else if (signin_type_ == SigninType::FAKE_SIGNIN) { } else if (signin_type_ == SigninType::FAKE_SIGNIN) {
// Authenticate sync client using GAIA credentials.
// TODO(https://crbug.com/814307): This ideally should go through
// identity_test_utils.h (and in the long run IdentityTestEnvironment), but
// making that change is complex for reasons described in the bug.
identity::IdentityManager* identity_manager = identity::IdentityManager* identity_manager =
IdentityManagerFactory::GetForProfile(profile_); IdentityManagerFactory::GetForProfile(profile_);
identity_manager->SetPrimaryAccountSynchronouslyForTests( if (identity_manager->HasPrimaryAccountWithRefreshToken()) {
gaia_id_, username_, GenerateFakeOAuth2RefreshTokenString()); // Don't sign in again if we're already signed in. The reason is that
// changing the refresh token causes Sync (ServerConnectionManager in
// particular) to mark the current access token as invalid. Since tests
// typically always hand out the same access token string, any new access
// token acquired later would also be considered invalid.
DCHECK_EQ(identity_manager->GetPrimaryAccountInfo().gaia, gaia_id_);
DCHECK_EQ(identity_manager->GetPrimaryAccountInfo().email, username_);
} else {
// Authenticate sync client using GAIA credentials.
// TODO(https://crbug.com/814307): This ideally should go through
// identity_test_utils.h (and in the long run IdentityTestEnvironment),
// but making that change is complex for reasons described in the bug.
identity_manager->SetPrimaryAccountSynchronouslyForTests(
gaia_id_, username_, GenerateFakeOAuth2RefreshTokenString());
}
} else { } else {
LOG(ERROR) << "Unsupported profile signin type."; LOG(ERROR) << "Unsupported profile signin type.";
} }
......
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