Commit 07306a99 authored by Colin Blundell's avatar Colin Blundell Committed by Commit Bot

IdentityTestEnvironment: More APIs to interact with secondary accounts

This CL adds IdentityTestEnvironment APIs to interact with the refresh
token state of secondary accounts; these APIs will be needed in an
upcoming CL. In this CL we also change all such test APIs that return
the account ID of a newly-set account to instead return the AccountInfo;
for the upcoming use case, this will be convenient.

Bug: 798699
Change-Id: I9deceae9fb016147fce6206c263acf638d21ef6e
Reviewed-on: https://chromium-review.googlesource.com/1107984
Commit-Queue: Colin Blundell <blundell@chromium.org>
Reviewed-by: default avatarMarc Treib <treib@chromium.org>
Cr-Commit-Position: refs/heads/master@{#569201}
parent 766eaa49
...@@ -89,7 +89,7 @@ TEST_F(SyncAuthManagerTest, IgnoresEventsIfNotRegistered) { ...@@ -89,7 +89,7 @@ TEST_F(SyncAuthManagerTest, IgnoresEventsIfNotRegistered) {
// Fire some auth events. We haven't called RegisterForAuthNotifications, so // Fire some auth events. We haven't called RegisterForAuthNotifications, so
// none of this should result in any callback calls. // none of this should result in any callback calls.
std::string account_id = std::string account_id =
identity_env()->MakePrimaryAccountAvailable("test@email.com"); identity_env()->MakePrimaryAccountAvailable("test@email.com").account_id;
ASSERT_EQ(auth_manager->GetAuthenticatedAccountInfo().account_id, account_id); ASSERT_EQ(auth_manager->GetAuthenticatedAccountInfo().account_id, account_id);
identity_env()->SetRefreshTokenForPrimaryAccount(); identity_env()->SetRefreshTokenForPrimaryAccount();
identity_env()->ClearPrimaryAccount(); identity_env()->ClearPrimaryAccount();
...@@ -99,7 +99,7 @@ TEST_F(SyncAuthManagerTest, IgnoresEventsIfNotRegistered) { ...@@ -99,7 +99,7 @@ TEST_F(SyncAuthManagerTest, IgnoresEventsIfNotRegistered) {
TEST_F(SyncAuthManagerTest, ForwardsPrimaryAccountEvents) { TEST_F(SyncAuthManagerTest, ForwardsPrimaryAccountEvents) {
// Start out already signed in before the SyncAuthManager is created. // Start out already signed in before the SyncAuthManager is created.
std::string account_id = std::string account_id =
identity_env()->MakePrimaryAccountAvailable("test@email.com"); identity_env()->MakePrimaryAccountAvailable("test@email.com").account_id;
base::MockCallback<AccountStateChangedCallback> account_state_changed; base::MockCallback<AccountStateChangedCallback> account_state_changed;
base::MockCallback<CredentialsChangedCallback> credentials_changed; base::MockCallback<CredentialsChangedCallback> credentials_changed;
...@@ -124,7 +124,7 @@ TEST_F(SyncAuthManagerTest, ForwardsPrimaryAccountEvents) { ...@@ -124,7 +124,7 @@ TEST_F(SyncAuthManagerTest, ForwardsPrimaryAccountEvents) {
// Sign in to a different account. // Sign in to a different account.
EXPECT_CALL(account_state_changed, Run()); EXPECT_CALL(account_state_changed, Run());
std::string second_account_id = std::string second_account_id =
identity_env()->MakePrimaryAccountAvailable("test@email.com"); identity_env()->MakePrimaryAccountAvailable("test@email.com").account_id;
EXPECT_EQ(auth_manager->GetAuthenticatedAccountInfo().account_id, EXPECT_EQ(auth_manager->GetAuthenticatedAccountInfo().account_id,
second_account_id); second_account_id);
} }
...@@ -133,7 +133,7 @@ TEST_F(SyncAuthManagerTest, ForwardsPrimaryAccountEvents) { ...@@ -133,7 +133,7 @@ TEST_F(SyncAuthManagerTest, ForwardsPrimaryAccountEvents) {
TEST_F(SyncAuthManagerTest, ForwardsCredentialsEvents) { TEST_F(SyncAuthManagerTest, ForwardsCredentialsEvents) {
// Start out already signed in before the SyncAuthManager is created. // Start out already signed in before the SyncAuthManager is created.
std::string account_id = std::string account_id =
identity_env()->MakePrimaryAccountAvailable("test@email.com"); identity_env()->MakePrimaryAccountAvailable("test@email.com").account_id;
base::MockCallback<AccountStateChangedCallback> account_state_changed; base::MockCallback<AccountStateChangedCallback> account_state_changed;
base::MockCallback<CredentialsChangedCallback> credentials_changed; base::MockCallback<CredentialsChangedCallback> credentials_changed;
...@@ -179,7 +179,7 @@ TEST_F(SyncAuthManagerTest, ForwardsCredentialsEvents) { ...@@ -179,7 +179,7 @@ TEST_F(SyncAuthManagerTest, ForwardsCredentialsEvents) {
TEST_F(SyncAuthManagerTest, RequestsAccessTokenOnSyncStartup) { TEST_F(SyncAuthManagerTest, RequestsAccessTokenOnSyncStartup) {
std::string account_id = std::string account_id =
identity_env()->MakePrimaryAccountAvailable("test@email.com"); identity_env()->MakePrimaryAccountAvailable("test@email.com").account_id;
auto auth_manager = CreateAuthManager(); auto auth_manager = CreateAuthManager();
ASSERT_EQ(auth_manager->GetAuthenticatedAccountInfo().account_id, account_id); ASSERT_EQ(auth_manager->GetAuthenticatedAccountInfo().account_id, account_id);
auth_manager->RegisterForAuthNotifications(); auth_manager->RegisterForAuthNotifications();
...@@ -199,7 +199,7 @@ TEST_F(SyncAuthManagerTest, RequestsAccessTokenOnSyncStartup) { ...@@ -199,7 +199,7 @@ TEST_F(SyncAuthManagerTest, RequestsAccessTokenOnSyncStartup) {
TEST_F(SyncAuthManagerTest, TEST_F(SyncAuthManagerTest,
RetriesAccessTokenFetchWithBackoffOnTransientFailure) { RetriesAccessTokenFetchWithBackoffOnTransientFailure) {
std::string account_id = std::string account_id =
identity_env()->MakePrimaryAccountAvailable("test@email.com"); identity_env()->MakePrimaryAccountAvailable("test@email.com").account_id;
auto auth_manager = CreateAuthManager(); auto auth_manager = CreateAuthManager();
ASSERT_EQ(auth_manager->GetAuthenticatedAccountInfo().account_id, account_id); ASSERT_EQ(auth_manager->GetAuthenticatedAccountInfo().account_id, account_id);
auth_manager->RegisterForAuthNotifications(); auth_manager->RegisterForAuthNotifications();
...@@ -222,7 +222,7 @@ TEST_F(SyncAuthManagerTest, ...@@ -222,7 +222,7 @@ TEST_F(SyncAuthManagerTest,
TEST_F(SyncAuthManagerTest, AbortsAccessTokenFetchOnPersistentFailure) { TEST_F(SyncAuthManagerTest, AbortsAccessTokenFetchOnPersistentFailure) {
std::string account_id = std::string account_id =
identity_env()->MakePrimaryAccountAvailable("test@email.com"); identity_env()->MakePrimaryAccountAvailable("test@email.com").account_id;
auto auth_manager = CreateAuthManager(); auto auth_manager = CreateAuthManager();
ASSERT_EQ(auth_manager->GetAuthenticatedAccountInfo().account_id, account_id); ASSERT_EQ(auth_manager->GetAuthenticatedAccountInfo().account_id, account_id);
auth_manager->RegisterForAuthNotifications(); auth_manager->RegisterForAuthNotifications();
...@@ -247,7 +247,7 @@ TEST_F(SyncAuthManagerTest, AbortsAccessTokenFetchOnPersistentFailure) { ...@@ -247,7 +247,7 @@ TEST_F(SyncAuthManagerTest, AbortsAccessTokenFetchOnPersistentFailure) {
TEST_F(SyncAuthManagerTest, FetchesNewAccessTokenWithBackoffOnServerError) { TEST_F(SyncAuthManagerTest, FetchesNewAccessTokenWithBackoffOnServerError) {
std::string account_id = std::string account_id =
identity_env()->MakePrimaryAccountAvailable("test@email.com"); identity_env()->MakePrimaryAccountAvailable("test@email.com").account_id;
auto auth_manager = CreateAuthManager(); auto auth_manager = CreateAuthManager();
ASSERT_EQ(auth_manager->GetAuthenticatedAccountInfo().account_id, account_id); ASSERT_EQ(auth_manager->GetAuthenticatedAccountInfo().account_id, account_id);
auth_manager->RegisterForAuthNotifications(); auth_manager->RegisterForAuthNotifications();
...@@ -274,7 +274,7 @@ TEST_F(SyncAuthManagerTest, FetchesNewAccessTokenWithBackoffOnServerError) { ...@@ -274,7 +274,7 @@ TEST_F(SyncAuthManagerTest, FetchesNewAccessTokenWithBackoffOnServerError) {
TEST_F(SyncAuthManagerTest, ExposesServerError) { TEST_F(SyncAuthManagerTest, ExposesServerError) {
std::string account_id = std::string account_id =
identity_env()->MakePrimaryAccountAvailable("test@email.com"); identity_env()->MakePrimaryAccountAvailable("test@email.com").account_id;
auto auth_manager = CreateAuthManager(); auto auth_manager = CreateAuthManager();
ASSERT_EQ(auth_manager->GetAuthenticatedAccountInfo().account_id, account_id); ASSERT_EQ(auth_manager->GetAuthenticatedAccountInfo().account_id, account_id);
auth_manager->RegisterForAuthNotifications(); auth_manager->RegisterForAuthNotifications();
...@@ -301,7 +301,7 @@ TEST_F(SyncAuthManagerTest, ExposesServerError) { ...@@ -301,7 +301,7 @@ TEST_F(SyncAuthManagerTest, ExposesServerError) {
TEST_F(SyncAuthManagerTest, RequestsNewAccessTokenOnExpiry) { TEST_F(SyncAuthManagerTest, RequestsNewAccessTokenOnExpiry) {
std::string account_id = std::string account_id =
identity_env()->MakePrimaryAccountAvailable("test@email.com"); identity_env()->MakePrimaryAccountAvailable("test@email.com").account_id;
auto auth_manager = CreateAuthManager(); auto auth_manager = CreateAuthManager();
ASSERT_EQ(auth_manager->GetAuthenticatedAccountInfo().account_id, account_id); ASSERT_EQ(auth_manager->GetAuthenticatedAccountInfo().account_id, account_id);
auth_manager->RegisterForAuthNotifications(); auth_manager->RegisterForAuthNotifications();
...@@ -334,7 +334,7 @@ TEST_F(SyncAuthManagerTest, RequestsNewAccessTokenOnExpiry) { ...@@ -334,7 +334,7 @@ TEST_F(SyncAuthManagerTest, RequestsNewAccessTokenOnExpiry) {
TEST_F(SyncAuthManagerTest, RequestsNewAccessTokenOnRefreshTokenUpdate) { TEST_F(SyncAuthManagerTest, RequestsNewAccessTokenOnRefreshTokenUpdate) {
std::string account_id = std::string account_id =
identity_env()->MakePrimaryAccountAvailable("test@email.com"); identity_env()->MakePrimaryAccountAvailable("test@email.com").account_id;
auto auth_manager = CreateAuthManager(); auto auth_manager = CreateAuthManager();
ASSERT_EQ(auth_manager->GetAuthenticatedAccountInfo().account_id, account_id); ASSERT_EQ(auth_manager->GetAuthenticatedAccountInfo().account_id, account_id);
auth_manager->RegisterForAuthNotifications(); auth_manager->RegisterForAuthNotifications();
...@@ -367,7 +367,7 @@ TEST_F(SyncAuthManagerTest, RequestsNewAccessTokenOnRefreshTokenUpdate) { ...@@ -367,7 +367,7 @@ TEST_F(SyncAuthManagerTest, RequestsNewAccessTokenOnRefreshTokenUpdate) {
TEST_F(SyncAuthManagerTest, DoesNotRequestAccessTokenAutonomously) { TEST_F(SyncAuthManagerTest, DoesNotRequestAccessTokenAutonomously) {
std::string account_id = std::string account_id =
identity_env()->MakePrimaryAccountAvailable("test@email.com"); identity_env()->MakePrimaryAccountAvailable("test@email.com").account_id;
auto auth_manager = CreateAuthManager(); auto auth_manager = CreateAuthManager();
ASSERT_EQ(auth_manager->GetAuthenticatedAccountInfo().account_id, account_id); ASSERT_EQ(auth_manager->GetAuthenticatedAccountInfo().account_id, account_id);
auth_manager->RegisterForAuthNotifications(); auth_manager->RegisterForAuthNotifications();
...@@ -393,7 +393,7 @@ TEST_F(SyncAuthManagerTest, DoesNotRequestAccessTokenAutonomously) { ...@@ -393,7 +393,7 @@ TEST_F(SyncAuthManagerTest, DoesNotRequestAccessTokenAutonomously) {
TEST_F(SyncAuthManagerTest, ClearsCredentialsOnRefreshTokenRemoval) { TEST_F(SyncAuthManagerTest, ClearsCredentialsOnRefreshTokenRemoval) {
std::string account_id = std::string account_id =
identity_env()->MakePrimaryAccountAvailable("test@email.com"); identity_env()->MakePrimaryAccountAvailable("test@email.com").account_id;
auto auth_manager = CreateAuthManager(); auto auth_manager = CreateAuthManager();
ASSERT_EQ(auth_manager->GetAuthenticatedAccountInfo().account_id, account_id); ASSERT_EQ(auth_manager->GetAuthenticatedAccountInfo().account_id, account_id);
auth_manager->RegisterForAuthNotifications(); auth_manager->RegisterForAuthNotifications();
...@@ -433,7 +433,7 @@ TEST_F(SyncAuthManagerTest, ClearsCredentialsOnRefreshTokenRemoval) { ...@@ -433,7 +433,7 @@ TEST_F(SyncAuthManagerTest, ClearsCredentialsOnRefreshTokenRemoval) {
TEST_F(SyncAuthManagerTest, ClearsCredentialsOnInvalidRefreshToken) { TEST_F(SyncAuthManagerTest, ClearsCredentialsOnInvalidRefreshToken) {
std::string account_id = std::string account_id =
identity_env()->MakePrimaryAccountAvailable("test@email.com"); identity_env()->MakePrimaryAccountAvailable("test@email.com").account_id;
auto auth_manager = CreateAuthManager(); auto auth_manager = CreateAuthManager();
ASSERT_EQ(auth_manager->GetAuthenticatedAccountInfo().account_id, account_id); ASSERT_EQ(auth_manager->GetAuthenticatedAccountInfo().account_id, account_id);
auth_manager->RegisterForAuthNotifications(); auth_manager->RegisterForAuthNotifications();
......
...@@ -143,7 +143,7 @@ class IdentityManager : public SigninManagerBase::Observer, ...@@ -143,7 +143,7 @@ class IdentityManager : public SigninManagerBase::Observer,
private: private:
// These clients need to call SetPrimaryAccountSynchronouslyForTests(). // These clients need to call SetPrimaryAccountSynchronouslyForTests().
friend std::string SetPrimaryAccount(SigninManagerBase* signin_manager, friend AccountInfo SetPrimaryAccount(SigninManagerBase* signin_manager,
IdentityManager* identity_manager, IdentityManager* identity_manager,
const std::string& email); const std::string& email);
friend MultiProfileDownloadNotificationTest; friend MultiProfileDownloadNotificationTest;
......
...@@ -102,7 +102,7 @@ IdentityManager* IdentityTestEnvironment::identity_manager() { ...@@ -102,7 +102,7 @@ IdentityManager* IdentityTestEnvironment::identity_manager() {
return internals_->identity_manager(); return internals_->identity_manager();
} }
std::string IdentityTestEnvironment::SetPrimaryAccount( AccountInfo IdentityTestEnvironment::SetPrimaryAccount(
const std::string& email) { const std::string& email) {
return identity::SetPrimaryAccount(internals_->signin_manager(), return identity::SetPrimaryAccount(internals_->signin_manager(),
internals_->identity_manager(), email); internals_->identity_manager(), email);
...@@ -123,7 +123,7 @@ void IdentityTestEnvironment::RemoveRefreshTokenForPrimaryAccount() { ...@@ -123,7 +123,7 @@ void IdentityTestEnvironment::RemoveRefreshTokenForPrimaryAccount() {
internals_->identity_manager()); internals_->identity_manager());
} }
std::string IdentityTestEnvironment::MakePrimaryAccountAvailable( AccountInfo IdentityTestEnvironment::MakePrimaryAccountAvailable(
const std::string& email) { const std::string& email) {
return identity::MakePrimaryAccountAvailable( return identity::MakePrimaryAccountAvailable(
internals_->signin_manager(), internals_->token_service(), internals_->signin_manager(), internals_->token_service(),
...@@ -135,13 +135,31 @@ void IdentityTestEnvironment::ClearPrimaryAccount() { ...@@ -135,13 +135,31 @@ void IdentityTestEnvironment::ClearPrimaryAccount() {
internals_->identity_manager()); internals_->identity_manager());
} }
std::string IdentityTestEnvironment::MakeAccountAvailable( AccountInfo IdentityTestEnvironment::MakeAccountAvailable(
const std::string& email) { const std::string& email) {
return identity::MakeAccountAvailable(internals_->account_tracker_service(), return identity::MakeAccountAvailable(internals_->account_tracker_service(),
internals_->token_service(), internals_->token_service(),
internals_->identity_manager(), email); internals_->identity_manager(), email);
} }
void IdentityTestEnvironment::SetRefreshTokenForAccount(
const std::string& account_id) {
return identity::SetRefreshTokenForAccount(
internals_->token_service(), internals_->identity_manager(), account_id);
}
void IdentityTestEnvironment::SetInvalidRefreshTokenForAccount(
const std::string& account_id) {
return identity::SetInvalidRefreshTokenForAccount(
internals_->token_service(), internals_->identity_manager(), account_id);
}
void IdentityTestEnvironment::RemoveRefreshTokenForAccount(
const std::string& account_id) {
return identity::RemoveRefreshTokenForAccount(
internals_->token_service(), internals_->identity_manager(), account_id);
}
void IdentityTestEnvironment::SetAutomaticIssueOfAccessTokens(bool grant) { void IdentityTestEnvironment::SetAutomaticIssueOfAccessTokens(bool grant) {
internals_->token_service()->set_auto_post_fetch_response_on_message_loop( internals_->token_service()->set_auto_post_fetch_response_on_message_loop(
grant); grant);
......
...@@ -26,9 +26,9 @@ class IdentityTestEnvironment : public IdentityManager::DiagnosticsObserver { ...@@ -26,9 +26,9 @@ class IdentityTestEnvironment : public IdentityManager::DiagnosticsObserver {
// Sets the primary account for the given email address, generating a GAIA ID // Sets the primary account for the given email address, generating a GAIA ID
// that corresponds uniquely to that email address. On non-ChromeOS, results // that corresponds uniquely to that email address. On non-ChromeOS, results
// in the firing of the IdentityManager and SigninManager callbacks for signin // in the firing of the IdentityManager and SigninManager callbacks for signin
// success. Blocks until the primary account is set. Returns the account ID // success. Blocks until the primary account is set. Returns the AccountInfo
// of the newly-set account. // of the newly-set account.
std::string SetPrimaryAccount(const std::string& email); AccountInfo SetPrimaryAccount(const std::string& email);
// Sets a refresh token for the primary account (which must already be set). // Sets a refresh token for the primary account (which must already be set).
// Blocks until the refresh token is set. // Blocks until the refresh token is set.
...@@ -47,7 +47,8 @@ class IdentityTestEnvironment : public IdentityManager::DiagnosticsObserver { ...@@ -47,7 +47,8 @@ class IdentityTestEnvironment : public IdentityManager::DiagnosticsObserver {
// On non-ChromeOS platforms, this will also result in the firing of the // On non-ChromeOS platforms, this will also result in the firing of the
// IdentityManager and SigninManager callbacks for signin success. On all // IdentityManager and SigninManager callbacks for signin success. On all
// platforms, this method blocks until the primary account is available. // platforms, this method blocks until the primary account is available.
std::string MakePrimaryAccountAvailable(const std::string& email); // Returns the AccountInfo of the newly-available account.
AccountInfo MakePrimaryAccountAvailable(const std::string& email);
// Clears the primary account. On non-ChromeOS, results in the firing of the // Clears the primary account. On non-ChromeOS, results in the firing of the
// IdentityManager and SigninManager callbacks for signout. Blocks until the // IdentityManager and SigninManager callbacks for signout. Blocks until the
...@@ -56,9 +57,24 @@ class IdentityTestEnvironment : public IdentityManager::DiagnosticsObserver { ...@@ -56,9 +57,24 @@ class IdentityTestEnvironment : public IdentityManager::DiagnosticsObserver {
// Makes an account available for the given email address, generating a GAIA // Makes an account available for the given email address, generating a GAIA
// ID and refresh token that correspond uniquely to that email address. Blocks // ID and refresh token that correspond uniquely to that email address. Blocks
// until the account is available. Returns the account ID of the // until the account is available. Returns the AccountInfo of the
// newly-available account. // newly-available account.
std::string MakeAccountAvailable(const std::string& email); AccountInfo MakeAccountAvailable(const std::string& email);
// Sets a refresh token for the given account (which must already be
// available). Blocks until the refresh token is set. NOTE: See disclaimer at
// top of file re: direct usage.
void SetRefreshTokenForAccount(const std::string& account_id);
// Sets a special invalid refresh token for the given account (which must
// already be available). Blocks until the refresh token is set. NOTE: See
// disclaimer at top of file re: direct usage.
void SetInvalidRefreshTokenForAccount(const std::string& account_id);
// Removes any refresh token for the given account (which must already be
// available). Blocks until the refresh token is removed. NOTE: See disclaimer
// at top of file re: direct usage.
void RemoveRefreshTokenForAccount(const std::string& account_id);
// When this is set, access token requests will be automatically granted with // When this is set, access token requests will be automatically granted with
// an access token value of "access_token". // an access token value of "access_token".
......
...@@ -115,7 +115,7 @@ void UpdateRefreshTokenForAccount(ProfileOAuth2TokenService* token_service, ...@@ -115,7 +115,7 @@ void UpdateRefreshTokenForAccount(ProfileOAuth2TokenService* token_service,
} // namespace } // namespace
std::string SetPrimaryAccount(SigninManagerBase* signin_manager, AccountInfo SetPrimaryAccount(SigninManagerBase* signin_manager,
IdentityManager* identity_manager, IdentityManager* identity_manager,
const std::string& email) { const std::string& email) {
DCHECK(!signin_manager->IsAuthenticated()); DCHECK(!signin_manager->IsAuthenticated());
...@@ -153,7 +153,7 @@ std::string SetPrimaryAccount(SigninManagerBase* signin_manager, ...@@ -153,7 +153,7 @@ std::string SetPrimaryAccount(SigninManagerBase* signin_manager,
DCHECK(signin_manager->IsAuthenticated()); DCHECK(signin_manager->IsAuthenticated());
DCHECK(identity_manager->HasPrimaryAccount()); DCHECK(identity_manager->HasPrimaryAccount());
return identity_manager->GetPrimaryAccountInfo().account_id; return identity_manager->GetPrimaryAccountInfo();
} }
void SetRefreshTokenForPrimaryAccount(ProfileOAuth2TokenService* token_service, void SetRefreshTokenForPrimaryAccount(ProfileOAuth2TokenService* token_service,
...@@ -162,8 +162,7 @@ void SetRefreshTokenForPrimaryAccount(ProfileOAuth2TokenService* token_service, ...@@ -162,8 +162,7 @@ void SetRefreshTokenForPrimaryAccount(ProfileOAuth2TokenService* token_service,
std::string account_id = identity_manager->GetPrimaryAccountInfo().account_id; std::string account_id = identity_manager->GetPrimaryAccountInfo().account_id;
std::string refresh_token = "refresh_token_for_" + account_id; std::string refresh_token = "refresh_token_for_" + account_id;
UpdateRefreshTokenForAccount(token_service, identity_manager, account_id, SetRefreshTokenForAccount(token_service, identity_manager, account_id);
refresh_token);
} }
void SetInvalidRefreshTokenForPrimaryAccount( void SetInvalidRefreshTokenForPrimaryAccount(
...@@ -172,9 +171,7 @@ void SetInvalidRefreshTokenForPrimaryAccount( ...@@ -172,9 +171,7 @@ void SetInvalidRefreshTokenForPrimaryAccount(
DCHECK(identity_manager->HasPrimaryAccount()); DCHECK(identity_manager->HasPrimaryAccount());
std::string account_id = identity_manager->GetPrimaryAccountInfo().account_id; std::string account_id = identity_manager->GetPrimaryAccountInfo().account_id;
UpdateRefreshTokenForAccount( SetInvalidRefreshTokenForAccount(token_service, identity_manager, account_id);
token_service, identity_manager, account_id,
OAuth2TokenServiceDelegate::kInvalidRefreshToken);
} }
void RemoveRefreshTokenForPrimaryAccount( void RemoveRefreshTokenForPrimaryAccount(
...@@ -183,25 +180,18 @@ void RemoveRefreshTokenForPrimaryAccount( ...@@ -183,25 +180,18 @@ void RemoveRefreshTokenForPrimaryAccount(
DCHECK(identity_manager->HasPrimaryAccount()); DCHECK(identity_manager->HasPrimaryAccount());
std::string account_id = identity_manager->GetPrimaryAccountInfo().account_id; std::string account_id = identity_manager->GetPrimaryAccountInfo().account_id;
base::RunLoop run_loop; RemoveRefreshTokenForAccount(token_service, identity_manager, account_id);
OneShotIdentityManagerObserver token_updated_observer(
identity_manager, run_loop.QuitClosure(),
IdentityManagerEvent::REFRESH_TOKEN_REMOVED);
token_service->RevokeCredentials(account_id);
run_loop.Run();
} }
std::string MakePrimaryAccountAvailable( AccountInfo MakePrimaryAccountAvailable(
SigninManagerBase* signin_manager, SigninManagerBase* signin_manager,
ProfileOAuth2TokenService* token_service, ProfileOAuth2TokenService* token_service,
IdentityManager* identity_manager, IdentityManager* identity_manager,
const std::string& email) { const std::string& email) {
std::string account_id = AccountInfo account_info =
SetPrimaryAccount(signin_manager, identity_manager, email); SetPrimaryAccount(signin_manager, identity_manager, email);
SetRefreshTokenForPrimaryAccount(token_service, identity_manager); SetRefreshTokenForPrimaryAccount(token_service, identity_manager);
return account_id; return account_info;
} }
void ClearPrimaryAccount(SigninManagerForTest* signin_manager, void ClearPrimaryAccount(SigninManagerForTest* signin_manager,
...@@ -223,7 +213,7 @@ void ClearPrimaryAccount(SigninManagerForTest* signin_manager, ...@@ -223,7 +213,7 @@ void ClearPrimaryAccount(SigninManagerForTest* signin_manager,
#endif #endif
} }
std::string MakeAccountAvailable(AccountTrackerService* account_tracker_service, AccountInfo MakeAccountAvailable(AccountTrackerService* account_tracker_service,
ProfileOAuth2TokenService* token_service, ProfileOAuth2TokenService* token_service,
IdentityManager* identity_manager, IdentityManager* identity_manager,
const std::string& email) { const std::string& email) {
...@@ -232,15 +222,43 @@ std::string MakeAccountAvailable(AccountTrackerService* account_tracker_service, ...@@ -232,15 +222,43 @@ std::string MakeAccountAvailable(AccountTrackerService* account_tracker_service,
std::string gaia_id = "gaia_id_for_" + email; std::string gaia_id = "gaia_id_for_" + email;
account_tracker_service->SeedAccountInfo(gaia_id, email); account_tracker_service->SeedAccountInfo(gaia_id, email);
std::string account_id = AccountInfo account_info =
account_tracker_service->FindAccountInfoByEmail(email).account_id; account_tracker_service->FindAccountInfoByEmail(email);
DCHECK(!account_id.empty()); DCHECK(!account_info.account_id.empty());
SetRefreshTokenForAccount(token_service, identity_manager,
account_info.account_id);
return account_info;
}
void SetRefreshTokenForAccount(ProfileOAuth2TokenService* token_service,
IdentityManager* identity_manager,
const std::string& account_id) {
std::string refresh_token = "refresh_token_for_" + account_id; std::string refresh_token = "refresh_token_for_" + account_id;
UpdateRefreshTokenForAccount(token_service, identity_manager, account_id, UpdateRefreshTokenForAccount(token_service, identity_manager, account_id,
refresh_token); refresh_token);
}
void SetInvalidRefreshTokenForAccount(ProfileOAuth2TokenService* token_service,
IdentityManager* identity_manager,
const std::string& account_id) {
UpdateRefreshTokenForAccount(
token_service, identity_manager, account_id,
OAuth2TokenServiceDelegate::kInvalidRefreshToken);
}
void RemoveRefreshTokenForAccount(ProfileOAuth2TokenService* token_service,
IdentityManager* identity_manager,
const std::string& account_id) {
base::RunLoop run_loop;
OneShotIdentityManagerObserver token_updated_observer(
identity_manager, run_loop.QuitClosure(),
IdentityManagerEvent::REFRESH_TOKEN_REMOVED);
token_service->RevokeCredentials(account_id);
return account_id; run_loop.Run();
} }
} // namespace identity } // namespace identity
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include <string> #include <string>
#include "build/build_config.h" #include "build/build_config.h"
#include "components/signin/core/browser/account_info.h"
class AccountTrackerService; class AccountTrackerService;
class FakeSigninManagerBase; class FakeSigninManagerBase;
...@@ -36,10 +37,10 @@ class IdentityManager; ...@@ -36,10 +37,10 @@ class IdentityManager;
// Sets the primary account for the given email address, generating a GAIA ID // Sets the primary account for the given email address, generating a GAIA ID
// that corresponds uniquely to that email address. On non-ChromeOS, results in // that corresponds uniquely to that email address. On non-ChromeOS, results in
// the firing of the IdentityManager and SigninManager callbacks for signin // the firing of the IdentityManager and SigninManager callbacks for signin
// success. Blocks until the primary account is set. Returns the account ID // success. Blocks until the primary account is set. Returns the AccountInfo
// of the newly-set account. // of the newly-set account.
// NOTE: See disclaimer at top of file re: direct usage. // NOTE: See disclaimer at top of file re: direct usage.
std::string SetPrimaryAccount(SigninManagerBase* signin_manager, AccountInfo SetPrimaryAccount(SigninManagerBase* signin_manager,
IdentityManager* identity_manager, IdentityManager* identity_manager,
const std::string& email); const std::string& email);
...@@ -67,9 +68,9 @@ void RemoveRefreshTokenForPrimaryAccount( ...@@ -67,9 +68,9 @@ void RemoveRefreshTokenForPrimaryAccount(
// GAIA ID and refresh token that correspond uniquely to that email address. On // GAIA ID and refresh token that correspond uniquely to that email address. On
// non-ChromeOS, results in the firing of the IdentityManager and SigninManager // non-ChromeOS, results in the firing of the IdentityManager and SigninManager
// callbacks for signin success. Blocks until the primary account is available. // callbacks for signin success. Blocks until the primary account is available.
// Returns the account ID of the newly-available account. // Returns the AccountInfo of the newly-available account.
// NOTE: See disclaimer at top of file re: direct usage. // NOTE: See disclaimer at top of file re: direct usage.
std::string MakePrimaryAccountAvailable( AccountInfo MakePrimaryAccountAvailable(
SigninManagerBase* signin_manager, SigninManagerBase* signin_manager,
ProfileOAuth2TokenService* token_service, ProfileOAuth2TokenService* token_service,
IdentityManager* identity_manager, IdentityManager* identity_manager,
...@@ -87,14 +88,35 @@ void ClearPrimaryAccount(SigninManagerForTest* signin_manager, ...@@ -87,14 +88,35 @@ void ClearPrimaryAccount(SigninManagerForTest* signin_manager,
// Makes an account available for the given email address, generating a GAIA ID // Makes an account available for the given email address, generating a GAIA ID
// and refresh token that correspond uniquely to that email address. Blocks // and refresh token that correspond uniquely to that email address. Blocks
// until the account is available. Returns the account ID of the // until the account is available. Returns the AccountInfo of the
// newly-available account. // newly-available account.
// NOTE: See disclaimer at top of file re: direct usage. // NOTE: See disclaimer at top of file re: direct usage.
std::string MakeAccountAvailable(AccountTrackerService* account_tracker_service, AccountInfo MakeAccountAvailable(AccountTrackerService* account_tracker_service,
ProfileOAuth2TokenService* token_service, ProfileOAuth2TokenService* token_service,
IdentityManager* identity_manager, IdentityManager* identity_manager,
const std::string& email); const std::string& email);
// Sets a refresh token for the given account (which must already be available).
// Blocks until the refresh token is set.
// NOTE: See disclaimer at top of file re: direct usage.
void SetRefreshTokenForAccount(ProfileOAuth2TokenService* token_service,
IdentityManager* identity_manager,
const std::string& account_id);
// Sets a special invalid refresh token for the given account (which must
// already be available). Blocks until the refresh token is set.
// NOTE: See disclaimer at top of file re: direct usage.
void SetInvalidRefreshTokenForAccount(ProfileOAuth2TokenService* token_service,
IdentityManager* identity_manager,
const std::string& account_id);
// Removes any refresh token for the given account (which must already be
// available). Blocks until the refresh token is removed. NOTE: See disclaimer
// at top of file re: direct usage.
void RemoveRefreshTokenForAccount(ProfileOAuth2TokenService* token_service,
IdentityManager* identity_manager,
const std::string& account_id);
} // namespace identity } // namespace identity
#endif // SERVICES_IDENTITY_PUBLIC_CPP_IDENTITY_TEST_UTILS_H_ #endif // SERVICES_IDENTITY_PUBLIC_CPP_IDENTITY_TEST_UTILS_H_
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