Commit 75c63f8a authored by Julie Jeongeun Kim's avatar Julie Jeongeun Kim Committed by Commit Bot

Move UpdateClearsCache from PO2TStest to O2ATMtest

This CL is a part of moving access token management to
OAuth2AccessTokenManager.

It is specifically a step toward folding O2TS into PO2TS
now that O2TS is only one subclass of PO2TS.

It removes ClearCache from PO2TS since it's only used
by PO2TS and it could call ClearCache through
|token_manager_| instead of having a helper method and
it moves UpdateClearsCache from
ProfileOAuth2TokenServiceTest to
OAuth2AccessTokenManagerTest.

It removes GetTokenCacheCountForTesting from PO2TS
because UpdateClearsCache which needs a cache size
is moved to OAuth2AccessTokenManagerTest and it gets
the size from |token_manager_| directly.

The test name, 'UpdateClearsCache', is also renamed
to 'ClearCache' in OAuth2AccessTokenManagerTest.

Bug: 967598
Change-Id: Icf700cd3709a3749df13e556bd6ca9107d615900
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1719112
Commit-Queue: Julie Jeongeun Kim <jkim@igalia.com>
Reviewed-by: default avatarColin Blundell <blundell@chromium.org>
Cr-Commit-Position: refs/heads/master@{#682131}
parent 16bb4c0e
......@@ -288,7 +288,7 @@ void ProfileOAuth2TokenService::RevokeAllCredentials(
base::AutoReset<SourceForRefreshTokenOperation> auto_reset(
&update_refresh_token_source_, source);
token_manager_->CancelAllRequests();
ClearCache();
token_manager_->ClearCache();
GetDelegate()->RevokeAllCredentials();
}
......@@ -341,10 +341,6 @@ void ProfileOAuth2TokenService::UpdateAuthErrorForTesting(
GetDelegate()->UpdateAuthError(account_id, error);
}
int ProfileOAuth2TokenService::GetTokenCacheCountForTesting() {
return token_manager_->token_cache().size();
}
void ProfileOAuth2TokenService::
set_max_authorization_token_fetch_retries_for_testing(int max_retries) {
token_manager_->set_max_authorization_token_fetch_retries_for_testing(
......@@ -416,10 +412,6 @@ void ProfileOAuth2TokenService::OnRefreshTokensLoaded() {
RecreateDeviceIdIfNeeded();
}
void ProfileOAuth2TokenService::ClearCache() {
token_manager_->ClearCache();
}
void ProfileOAuth2TokenService::ClearCacheForAccount(
const CoreAccountId& account_id) {
token_manager_->ClearCacheForAccount(account_id);
......
......@@ -250,8 +250,6 @@ class ProfileOAuth2TokenService : public OAuth2AccessTokenManager::Delegate,
void UpdateAuthErrorForTesting(const CoreAccountId& account_id,
const GoogleServiceAuthError& error);
int GetTokenCacheCountForTesting();
void set_max_authorization_token_fetch_retries_for_testing(int max_retries);
// Override |token_manager_| for testing.
......@@ -269,9 +267,6 @@ class ProfileOAuth2TokenService : public OAuth2AccessTokenManager::Delegate,
void OnRefreshTokenRevoked(const CoreAccountId& account_id) override;
void OnRefreshTokensLoaded() override;
// Clears the internal token cache.
void ClearCache();
// Clears all of the tokens belonging to |account_id| from the internal token
// cache. It does not matter what other parameters, like |client_id| were
// used to request the tokens.
......@@ -297,7 +292,6 @@ class ProfileOAuth2TokenService : public OAuth2AccessTokenManager::Delegate,
signin_metrics::SourceForRefreshTokenOperation update_refresh_token_source_ =
signin_metrics::SourceForRefreshTokenOperation::kUnknown;
FRIEND_TEST_ALL_PREFIXES(ProfileOAuth2TokenServiceTest, UpdateClearsCache);
FRIEND_TEST_ALL_PREFIXES(ProfileOAuth2TokenServiceTest,
SameScopesRequestedForDifferentClients);
......
......@@ -710,34 +710,6 @@ TEST_F(ProfileOAuth2TokenServiceTest, RequestParametersOrderTest) {
}
}
TEST_F(ProfileOAuth2TokenServiceTest, UpdateClearsCache) {
const CoreAccountId account_id("test@gmail.com");
std::set<std::string> scope_list;
scope_list.insert("scope");
oauth2_service_->GetDelegate()->UpdateCredentials(account_id, "refreshToken");
std::unique_ptr<OAuth2AccessTokenManager::Request> request(
oauth2_service_->StartRequest(account_id, scope_list, &consumer_));
SimulateOAuthTokenResponse(GetValidTokenResponse("token", 3600));
base::RunLoop().RunUntilIdle();
EXPECT_EQ(1, consumer_.number_of_successful_tokens_);
EXPECT_EQ(0, consumer_.number_of_errors_);
EXPECT_EQ("token", consumer_.last_token_);
EXPECT_EQ(1, oauth2_service_->GetTokenCacheCountForTesting());
oauth2_service_->ClearCache();
EXPECT_EQ(0, oauth2_service_->GetTokenCacheCountForTesting());
oauth2_service_->GetDelegate()->UpdateCredentials(account_id, "refreshToken");
SimulateOAuthTokenResponse(GetValidTokenResponse("another token", 3600));
request = oauth2_service_->StartRequest(account_id, scope_list, &consumer_);
base::RunLoop().RunUntilIdle();
EXPECT_EQ(2, consumer_.number_of_successful_tokens_);
EXPECT_EQ(0, consumer_.number_of_errors_);
EXPECT_EQ("another token", consumer_.last_token_);
EXPECT_EQ(1, oauth2_service_->GetTokenCacheCountForTesting());
}
TEST_F(ProfileOAuth2TokenServiceTest, FixRequestErrorIfPossible) {
oauth2_service_->GetDelegate()->UpdateCredentials(account_id_,
"refreshToken");
......
......@@ -287,10 +287,6 @@ class OAuth2AccessTokenManager {
GetDiagnosticsObserversForTesting();
private:
// TODO(https://crbug.com/967598): Determine whether ProfileOAuth2TokenService
// needs to have API to access to token_cache().
friend class ProfileOAuth2TokenService;
class Fetcher;
friend class Fetcher;
......@@ -344,6 +340,8 @@ class OAuth2AccessTokenManager {
SEQUENCE_CHECKER(sequence_checker_);
FRIEND_TEST_ALL_PREFIXES(OAuth2AccessTokenManagerTest, ClearCache);
DISALLOW_COPY_AND_ASSIGN(OAuth2AccessTokenManager);
};
......
......@@ -195,3 +195,35 @@ TEST_F(OAuth2AccessTokenManagerTest, CancelRequestsForAccount) {
EXPECT_EQ(0, consumer_.number_of_successful_tokens_);
EXPECT_EQ(3, consumer_.number_of_errors_);
}
// Test that StartRequest fetches a network request after ClearCache.
TEST_F(OAuth2AccessTokenManagerTest, ClearCache) {
base::RunLoop run_loop1;
consumer_.SetResponseCompletedClosure(run_loop1.QuitClosure());
std::set<std::string> scope_list;
scope_list.insert("scope");
std::unique_ptr<OAuth2AccessTokenManager::Request> request(
token_manager_.StartRequest(account_id_, scope_list, &consumer_));
SimulateOAuthTokenResponse(GetValidTokenResponse("token", 3600));
run_loop1.Run();
EXPECT_EQ(1, consumer_.number_of_successful_tokens_);
EXPECT_EQ(0, consumer_.number_of_errors_);
EXPECT_EQ("token", consumer_.last_token_);
EXPECT_EQ(1U, token_manager_.token_cache().size());
token_manager_.ClearCache();
EXPECT_EQ(0U, token_manager_.token_cache().size());
base::RunLoop run_loop2;
consumer_.SetResponseCompletedClosure(run_loop2.QuitClosure());
SimulateOAuthTokenResponse(GetValidTokenResponse("another token", 3600));
request = token_manager_.StartRequest(account_id_, scope_list, &consumer_);
run_loop2.Run();
EXPECT_EQ(2, consumer_.number_of_successful_tokens_);
EXPECT_EQ(0, consumer_.number_of_errors_);
EXPECT_EQ("another token", consumer_.last_token_);
EXPECT_EQ(1U, token_manager_.token_cache().size());
}
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