Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2943)

Unified Diff: blimp/client/core/session/identity_source_unittest.cc

Issue 2261273002: Integrate UI with authentication flow. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Misc fixes/ Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « blimp/client/core/session/identity_source.cc ('k') | blimp/client/core/settings/BUILD.gn » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: blimp/client/core/session/identity_source_unittest.cc
diff --git a/blimp/client/core/session/identity_source_unittest.cc b/blimp/client/core/session/identity_source_unittest.cc
index 64118c80c4e177a25cfb626c74a82dab2ad06206..06db6e9ec1106d60efb50af91a0f753a105be247 100644
--- a/blimp/client/core/session/identity_source_unittest.cc
+++ b/blimp/client/core/session/identity_source_unittest.cc
@@ -167,7 +167,7 @@ TEST_F(IdentitySourceTest, TestConnect) {
auth.ResetTestRecords();
// Direct connect with refresh token, and no listener should be
- // added.
+ // added. The request is a retry request.
auth.Connect();
auth.Connect();
token_service->IssueAllTokensForAccount(account, mock_access_token, time);
@@ -179,6 +179,48 @@ TEST_F(IdentitySourceTest, TestConnect) {
DCHECK_EQ(auth.CallbackToken(), mock_access_token);
}
+// Test retry on token fetching when refresh token is updated during token
+// request.
+TEST_F(IdentitySourceTest, TestConnectRetry) {
+ TestBlimpClientContextDelegate mock_blimp_delegate;
+ MockIdentitySource auth(
+ &mock_blimp_delegate,
+ base::Bind(&MockIdentitySource::MockTokenCall, base::Unretained(&auth)));
+ FakeOAuth2TokenService* token_service = mock_blimp_delegate.GetTokenService();
+ FakeIdentityProvider* id_provider =
+ static_cast<FakeIdentityProvider*>(auth.GetIdentityProvider());
+
+ std::string account = "mock_account";
+ std::string mock_access_token = "mock_token";
+ id_provider->LogIn(account);
+
+ // Prepare refresh token.
+ FakeOAuth2TokenServiceDelegate* mock_token_service_delegate =
+ token_service->GetFakeOAuth2TokenServiceDelegate();
+ mock_token_service_delegate->UpdateCredentials(account, "mock_refresh_token");
+
+ // Connect and update the refresh token.
+ auth.Connect();
+ GoogleServiceAuthError error(GoogleServiceAuthError::State::REQUEST_CANCELED);
+ token_service->IssueErrorForAllPendingRequestsForAccount(account, error);
+
+ // At this point, the first request should be canceled, but there should be
+ // another retry request.
+ DCHECK_EQ(auth.Succeeded(), 0);
+ DCHECK_EQ(auth.Failed(), 1);
+ DCHECK_EQ(auth.Token(), std::string());
+ DCHECK_EQ(auth.TokenCallbackCount(), 0);
+ auth.ResetTestRecords();
+
+ // Trigger the second request without calling connect.
+ base::Time time;
+ token_service->IssueAllTokensForAccount(account, mock_access_token, time);
+ DCHECK_EQ(auth.Succeeded(), 1);
+ DCHECK_EQ(auth.Token(), mock_access_token);
+ DCHECK_EQ(auth.TokenCallbackCount(), 1);
+ DCHECK_EQ(auth.CallbackToken(), mock_access_token);
+}
+
} // namespace
} // namespace client
} // namespace blimp
« no previous file with comments | « blimp/client/core/session/identity_source.cc ('k') | blimp/client/core/settings/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698