Commit 1339be2a authored by Antonio Gomes's avatar Antonio Gomes Committed by Commit Bot

[s13n] Convert AdvancedProtectionStatusManagerTest away from FakeProfileOAuth2TokenService

This CL is a continuation of [1], where AdvancedProtectionStatusManager (production code)
was migrated from SigninManager and OAuth2TokenService to IdentityManager. At this time
the respective unittests are migrated.

The CL adds the adds/changes the following testing APIs:

- IdentityTestEnvironment::WaitForAccessTokenRequestIfNecessaryAndRespondWithToken
receives an extra (optional) parameter |id_token|, and forward it to
FakeProfileOAuth2TokenService::IssueAllTokensForAccount.
This allows the body of AdvancedProtectionStatusManagerTest::MakeOAuthTokenFetchSucceed
to be migrated flawlessly.

- IdentityTestEnvironment::UpdateAccountInfoForAccount. This method updates the account
information for a given known account, by calling AccountTrackerService::SeedAccountInfo.

[1] https://crrev.com/c/1250968

BUG=887266

Change-Id: Ica84fd299794552f2ae6957dfc6c7dde6bba7afa
Reviewed-on: https://chromium-review.googlesource.com/c/1308993
Commit-Queue: Antonio Gomes <tonikitoo@igalia.com>
Reviewed-by: default avatarColin Blundell <blundell@chromium.org>
Reviewed-by: default avatarNathan Parker <nparker@chromium.org>
Reviewed-by: default avatarJialiu Lin <jialiul@chromium.org>
Cr-Commit-Position: refs/heads/master@{#606440}
parent f4a5aa2a
......@@ -294,9 +294,12 @@ void IdentityTestEnvironment::
WaitForAccessTokenRequestIfNecessaryAndRespondWithToken(
const std::string& account_id,
const std::string& token,
const base::Time& expiration) {
const base::Time& expiration,
const std::string& id_token) {
WaitForAccessTokenRequestIfNecessary(account_id);
token_service_->IssueAllTokensForAccount(account_id, token, expiration);
token_service_->IssueAllTokensForAccount(
account_id,
OAuth2AccessTokenConsumer::TokenResponse(token, expiration, id_token));
}
void IdentityTestEnvironment::
......@@ -399,4 +402,9 @@ void IdentityTestEnvironment::WaitForAccessTokenRequestIfNecessary(
run_loop.Run();
}
void IdentityTestEnvironment::UpdateAccountInfoForAccount(
AccountInfo account_info) {
identity::UpdateAccountInfoForAccount(account_tracker_service_, account_info);
}
} // namespace identity
......@@ -170,7 +170,8 @@ class IdentityTestEnvironment : public IdentityManager::DiagnosticsObserver {
void WaitForAccessTokenRequestIfNecessaryAndRespondWithToken(
const std::string& account_id,
const std::string& token,
const base::Time& expiration);
const base::Time& expiration,
const std::string& id_token = std::string());
// Issues |error| in response to any access token request that either has (a)
// already occurred and has not been matched by a previous call to this or
......@@ -204,6 +205,10 @@ class IdentityTestEnvironment : public IdentityManager::DiagnosticsObserver {
// passing in a null callback, before the Wait* methods can be used again.
void SetCallbackForNextAccessTokenRequest(base::OnceClosure callback);
// Updates the info for |account_info.account_id|, which must be a known
// account.
void UpdateAccountInfoForAccount(AccountInfo account_info);
private:
friend class ::IdentityTestEnvironmentChromeBrowserStateAdaptor;
friend class ::IdentityTestEnvironmentProfileAdaptor;
......
......@@ -326,4 +326,13 @@ void SetCookieAccounts(FakeGaiaCookieManagerService* cookie_manager,
run_loop.Run();
}
void UpdateAccountInfoForAccount(AccountTrackerService* account_tracker_service,
AccountInfo account_info) {
// Make sure the account being updated is a known account.
DCHECK(!account_tracker_service->GetAccountInfo(account_info.account_id)
.account_id.empty());
account_tracker_service->SeedAccountInfo(account_info);
}
} // namespace identity
......@@ -143,6 +143,11 @@ void SetCookieAccounts(FakeGaiaCookieManagerService* cookie_manager,
IdentityManager* identity_manager,
const std::vector<CookieParams>& cookie_accounts);
// Updates the info for |account_info.account_id|, which must be a known
// account.
void UpdateAccountInfoForAccount(AccountTrackerService* account_tracker_service,
AccountInfo account_info);
} // namespace identity
#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