Commit 19f72352 authored by Julie Jeongeun Kim's avatar Julie Jeongeun Kim Committed by Commit Bot

Introduce OnAccessTokenInvalidated in 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 introduces OnAccessTokenInvalidated in O2ATMtest to
test that InvalidateAccessToken triggers
OnAccessTokenInvalidated from |delegate_|.

Bug: 967598
Change-Id: I8c1433646b1e765b072baf20f69ab5f2374e3b9f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1724152Reviewed-by: default avatarColin Blundell <blundell@chromium.org>
Commit-Queue: Julie Jeongeun Kim <jkim@igalia.com>
Cr-Commit-Position: refs/heads/master@{#682243}
parent 107a4e3e
......@@ -66,6 +66,21 @@ class FakeOAuth2AccessTokenManagerDelegate
return false;
}
void OnAccessTokenInvalidated(
const CoreAccountId& account_id,
const std::string& client_id,
const OAuth2AccessTokenManager::ScopeSet& scopes,
const std::string& access_token) override {
if (!on_access_token_invalidated_callback_)
return;
EXPECT_EQ(access_token_invalidated_account_id_, account_id);
EXPECT_EQ(access_token_invalidated_client_id_, client_id);
EXPECT_EQ(access_token_invalidated_scopes_, scopes);
EXPECT_EQ(access_token_invalidated_access_token_, access_token);
std::move(on_access_token_invalidated_callback_).Run();
}
void AddAccount(CoreAccountId id, std::string refresh_token) {
account_ids_to_refresh_tokens_[id] = refresh_token;
}
......@@ -74,10 +89,28 @@ class FakeOAuth2AccessTokenManagerDelegate
access_token_fetch_closure_ = std::move(closure);
}
void SetOnAccessTokenInvalidated(
const CoreAccountId& account_id,
const std::string& client_id,
const OAuth2AccessTokenManager::ScopeSet& scopes,
const std::string& access_token,
base::OnceClosure callback) {
access_token_invalidated_account_id_ = account_id;
access_token_invalidated_client_id_ = client_id;
access_token_invalidated_scopes_ = scopes;
access_token_invalidated_access_token_ = access_token;
on_access_token_invalidated_callback_ = std::move(callback);
}
private:
scoped_refptr<network::SharedURLLoaderFactory> shared_factory_;
std::map<CoreAccountId, std::string> account_ids_to_refresh_tokens_;
base::OnceClosure access_token_fetch_closure_;
CoreAccountId access_token_invalidated_account_id_;
std::string access_token_invalidated_client_id_;
OAuth2AccessTokenManager::ScopeSet access_token_invalidated_scopes_;
std::string access_token_invalidated_access_token_;
base::OnceClosure on_access_token_invalidated_callback_;
};
class FakeOAuth2AccessTokenManagerConsumer
......@@ -322,3 +355,16 @@ TEST_F(OAuth2AccessTokenManagerTest, HandleAccessTokenFetch) {
GaiaUrls::GetInstance()->oauth2_chrome_client_id(),
account_id_, OAuth2AccessTokenManager::ScopeSet()));
}
// Test that InvalidateAccessToken triggers OnAccessTokenInvalidated.
TEST_F(OAuth2AccessTokenManagerTest, OnAccessTokenInvalidated) {
base::RunLoop run_loop;
OAuth2AccessTokenManager::ScopeSet scope_set;
scope_set.insert("scope");
std::string access_token("access_token");
delegate_.SetOnAccessTokenInvalidated(
account_id_, GaiaUrls::GetInstance()->oauth2_chrome_client_id(),
scope_set, access_token, run_loop.QuitClosure());
token_manager_.InvalidateAccessToken(account_id_, scope_set, access_token);
run_loop.Run();
}
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