OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "blimp/client/core/session/identity_source.h" | 5 #include "blimp/client/core/session/identity_source.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 DCHECK_EQ(auth.Token(), std::string()); | 160 DCHECK_EQ(auth.Token(), std::string()); |
161 DCHECK_EQ(auth.TokenCallbackCount(), 0); | 161 DCHECK_EQ(auth.TokenCallbackCount(), 0); |
162 auth.ResetTestRecords(); | 162 auth.ResetTestRecords(); |
163 | 163 |
164 // Refresh token listener should have been removed. | 164 // Refresh token listener should have been removed. |
165 mock_token_service_delegate->UpdateCredentials(account, "mock_refresh_token"); | 165 mock_token_service_delegate->UpdateCredentials(account, "mock_refresh_token"); |
166 DCHECK_EQ(auth.Refreshed(), 0); | 166 DCHECK_EQ(auth.Refreshed(), 0); |
167 auth.ResetTestRecords(); | 167 auth.ResetTestRecords(); |
168 | 168 |
169 // Direct connect with refresh token, and no listener should be | 169 // Direct connect with refresh token, and no listener should be |
170 // added. | 170 // added. The request is a retry request. |
171 auth.Connect(); | 171 auth.Connect(); |
172 auth.Connect(); | 172 auth.Connect(); |
173 token_service->IssueAllTokensForAccount(account, mock_access_token, time); | 173 token_service->IssueAllTokensForAccount(account, mock_access_token, time); |
174 DCHECK_EQ(auth.Succeeded(), 1); | 174 DCHECK_EQ(auth.Succeeded(), 1); |
175 DCHECK_EQ(auth.Token(), mock_access_token); | 175 DCHECK_EQ(auth.Token(), mock_access_token); |
176 mock_token_service_delegate->UpdateCredentials(account, "mock_refresh_token"); | 176 mock_token_service_delegate->UpdateCredentials(account, "mock_refresh_token"); |
177 DCHECK_EQ(auth.Refreshed(), 0); | 177 DCHECK_EQ(auth.Refreshed(), 0); |
178 DCHECK_EQ(auth.TokenCallbackCount(), 1); | 178 DCHECK_EQ(auth.TokenCallbackCount(), 1); |
179 DCHECK_EQ(auth.CallbackToken(), mock_access_token); | 179 DCHECK_EQ(auth.CallbackToken(), mock_access_token); |
180 } | 180 } |
181 | 181 |
| 182 // Test retry on token fetching when refresh token is updated during token |
| 183 // request. |
| 184 TEST_F(IdentitySourceTest, TestConnectRetry) { |
| 185 TestBlimpClientContextDelegate mock_blimp_delegate; |
| 186 MockIdentitySource auth( |
| 187 &mock_blimp_delegate, |
| 188 base::Bind(&MockIdentitySource::MockTokenCall, base::Unretained(&auth))); |
| 189 FakeOAuth2TokenService* token_service = mock_blimp_delegate.GetTokenService(); |
| 190 FakeIdentityProvider* id_provider = |
| 191 static_cast<FakeIdentityProvider*>(auth.GetIdentityProvider()); |
| 192 |
| 193 std::string account = "mock_account"; |
| 194 std::string mock_access_token = "mock_token"; |
| 195 id_provider->LogIn(account); |
| 196 |
| 197 // Prepare refresh token. |
| 198 FakeOAuth2TokenServiceDelegate* mock_token_service_delegate = |
| 199 token_service->GetFakeOAuth2TokenServiceDelegate(); |
| 200 mock_token_service_delegate->UpdateCredentials(account, "mock_refresh_token"); |
| 201 |
| 202 // Connect and update the refresh token. |
| 203 auth.Connect(); |
| 204 GoogleServiceAuthError error(GoogleServiceAuthError::State::REQUEST_CANCELED); |
| 205 token_service->IssueErrorForAllPendingRequestsForAccount(account, error); |
| 206 |
| 207 // At this point, the first request should be canceled, but there should be |
| 208 // another retry request. |
| 209 DCHECK_EQ(auth.Succeeded(), 0); |
| 210 DCHECK_EQ(auth.Failed(), 1); |
| 211 DCHECK_EQ(auth.Token(), std::string()); |
| 212 DCHECK_EQ(auth.TokenCallbackCount(), 0); |
| 213 auth.ResetTestRecords(); |
| 214 |
| 215 // Trigger the second request without calling connect. |
| 216 base::Time time; |
| 217 token_service->IssueAllTokensForAccount(account, mock_access_token, time); |
| 218 DCHECK_EQ(auth.Succeeded(), 1); |
| 219 DCHECK_EQ(auth.Token(), mock_access_token); |
| 220 DCHECK_EQ(auth.TokenCallbackCount(), 1); |
| 221 DCHECK_EQ(auth.CallbackToken(), mock_access_token); |
| 222 } |
| 223 |
182 } // namespace | 224 } // namespace |
183 } // namespace client | 225 } // namespace client |
184 } // namespace blimp | 226 } // namespace blimp |
OLD | NEW |