Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "remoting/test/access_token_fetcher.h" | |
| 6 | |
| 7 #include "base/bind.h" | |
| 8 #include "testing/gmock/include/gmock/gmock.h" | |
| 9 #include "testing/gtest/include/gtest/gtest.h" | |
| 10 | |
| 11 namespace { | |
| 12 const char kAuthCodeValue[] = "test_auth_code_value"; | |
|
Wez
2015/02/13 03:01:52
nit: Indentation
joedow
2015/02/14 02:31:26
Done.
| |
| 13 const char kAccessTokenValue[] = "test_access_token_value"; | |
| 14 const char kRefreshTokenValue[] = "test_refresh_token_value"; | |
| 15 const int kTokenExpirationValue = 3600; | |
| 16 const int kNetworkErrorCode = 404; | |
| 17 } | |
| 18 | |
| 19 namespace remoting { | |
| 20 namespace test { | |
| 21 | |
| 22 using testing::_; | |
| 23 | |
| 24 // This class implements the adapter interface which is used by the | |
| 25 // AccessTokenFetcher to make its gaia network calls. | |
| 26 class MockGaiaOAuthClient : public GaiaOAuthClientAdapter { | |
| 27 public: | |
| 28 MockGaiaOAuthClient() : GaiaOAuthClientAdapter(nullptr) {} | |
| 29 ~MockGaiaOAuthClient() override {} | |
| 30 | |
| 31 void OnAccessTokenRetrieved( | |
|
Wez
2015/02/13 03:01:52
Style-guide prefers that non-accessor methods not
joedow
2015/02/14 02:31:27
Done.
| |
| 32 const std::string& access_token, | |
| 33 const std::string& refresh_token) { | |
| 34 access_token_retrieved = access_token; | |
| 35 refresh_token_retrieved = refresh_token; | |
| 36 } | |
| 37 | |
| 38 // Since we only want the delegate parameter for this mock, we will override | |
| 39 // the virtual members and have them call simplified versions. | |
|
Wez
2015/02/13 03:01:52
Since you'll ignore the other three parameters, do
joedow
2015/02/14 02:31:27
Done.
| |
| 40 void GetTokensFromAuthCode( | |
| 41 const gaia::OAuthClientInfo& oauth_client_info, | |
| 42 const std::string& auth_code, | |
| 43 int max_retries, | |
| 44 gaia::GaiaOAuthClient::Delegate* delegate) override { | |
| 45 GetTokensFromAuthCodeImpl(delegate); | |
| 46 } | |
| 47 void RefreshToken( | |
| 48 const gaia::OAuthClientInfo& oauth_client_info, | |
| 49 const std::string& refresh_token, | |
| 50 const std::vector<std::string>& scopes, | |
| 51 int max_retries, | |
| 52 gaia::GaiaOAuthClient::Delegate* delegate) override { | |
| 53 RefreshTokenImpl(delegate); | |
| 54 } | |
| 55 void GetTokenInfo( | |
| 56 const std::string& oauth_access_token, | |
| 57 int max_retries, | |
| 58 gaia::GaiaOAuthClient::Delegate* delegate) override { | |
| 59 GetTokenInfoImpl(delegate); | |
| 60 } | |
| 61 | |
| 62 MOCK_METHOD1(GetTokensFromAuthCodeImpl, | |
| 63 void(gaia::GaiaOAuthClient::Delegate* delegate)); | |
| 64 | |
| 65 MOCK_METHOD1(RefreshTokenImpl, | |
| 66 void(gaia::GaiaOAuthClient::Delegate* delegate)); | |
| 67 | |
| 68 MOCK_METHOD1(GetTokenInfoImpl, | |
| 69 void(gaia::GaiaOAuthClient::Delegate* delegate)); | |
| 70 | |
| 71 void DelegateToCompleteCallbacks() { | |
|
Wez
2015/02/13 03:01:51
This function name isn't very descriptive - looks
joedow
2015/02/14 02:31:26
Done.
| |
| 72 ON_CALL(*this, GetTokensFromAuthCodeImpl(_)) | |
| 73 .WillByDefault(testing::Invoke(this, | |
| 74 &MockGaiaOAuthClient::CompleteAuthCodeCallback)); | |
| 75 ON_CALL(*this, RefreshTokenImpl(_)) | |
| 76 .WillByDefault(testing::Invoke(this, | |
| 77 &MockGaiaOAuthClient::CompleteRefreshCallback)); | |
| 78 ON_CALL(*this, GetTokenInfoImpl(_)) | |
| 79 .WillByDefault(testing::Invoke(this, | |
| 80 &MockGaiaOAuthClient::CompleteTokenInfoCallback)); | |
| 81 } | |
| 82 | |
| 83 void DelegateToOAuthErrorCallback() { | |
| 84 ON_CALL(*this, GetTokensFromAuthCodeImpl(_)) | |
| 85 .WillByDefault(testing::Invoke(this, | |
| 86 &MockGaiaOAuthClient::OAuthErrorCallback)); | |
| 87 ON_CALL(*this, RefreshTokenImpl(_)) | |
| 88 .WillByDefault(testing::Invoke(this, | |
| 89 &MockGaiaOAuthClient::OAuthErrorCallback)); | |
| 90 ON_CALL(*this, GetTokenInfoImpl(_)) | |
| 91 .WillByDefault(testing::Invoke(this, | |
| 92 &MockGaiaOAuthClient::OAuthErrorCallback)); | |
| 93 } | |
| 94 | |
| 95 void DelegateToNetworkErrorCallback() { | |
| 96 ON_CALL(*this, GetTokensFromAuthCodeImpl(_)) | |
| 97 .WillByDefault(testing::Invoke(this, | |
| 98 &MockGaiaOAuthClient::NetworkErrorCallback)); | |
| 99 ON_CALL(*this, RefreshTokenImpl(_)) | |
| 100 .WillByDefault(testing::Invoke(this, | |
| 101 &MockGaiaOAuthClient::NetworkErrorCallback)); | |
| 102 ON_CALL(*this, GetTokenInfoImpl(_)) | |
| 103 .WillByDefault(testing::Invoke(this, | |
| 104 &MockGaiaOAuthClient::NetworkErrorCallback)); | |
| 105 } | |
| 106 | |
| 107 void DelegateToInvalidTokenCallback() { | |
| 108 ON_CALL(*this, GetTokensFromAuthCodeImpl(_)) | |
| 109 .WillByDefault(testing::Invoke(this, | |
| 110 &MockGaiaOAuthClient::CompleteAuthCodeCallback)); | |
| 111 ON_CALL(*this, RefreshTokenImpl(_)) | |
| 112 .WillByDefault(testing::Invoke(this, | |
| 113 &MockGaiaOAuthClient::CompleteRefreshCallback)); | |
| 114 ON_CALL(*this, GetTokenInfoImpl(_)) | |
| 115 .WillByDefault(testing::Invoke(this, | |
| 116 &MockGaiaOAuthClient::InvalidTokenInfoCallback)); | |
| 117 } | |
| 118 | |
| 119 void CompleteAuthCodeCallback(gaia::GaiaOAuthClient::Delegate* delegate) { | |
| 120 DCHECK(delegate); | |
| 121 | |
| 122 delegate->OnGetTokensResponse( | |
| 123 kRefreshTokenValue, | |
| 124 kAccessTokenValue, | |
| 125 kTokenExpirationValue); | |
| 126 } | |
| 127 | |
| 128 void CompleteRefreshCallback(gaia::GaiaOAuthClient::Delegate* delegate) { | |
| 129 DCHECK(delegate); | |
| 130 | |
| 131 delegate->OnRefreshTokenResponse(kAccessTokenValue, kTokenExpirationValue); | |
| 132 } | |
| 133 | |
| 134 void CompleteTokenInfoCallback(gaia::GaiaOAuthClient::Delegate* delegate) { | |
| 135 DCHECK(delegate); | |
| 136 | |
| 137 // This call needs a dictionary object, but does not it to be populated. | |
| 138 scoped_ptr<base::DictionaryValue> token_info(new base::DictionaryValue()); | |
| 139 delegate->OnGetTokenInfoResponse(token_info.Pass()); | |
|
Wez
2015/02/13 03:01:52
nit: Just use make_scoped_ptr(new base::Dictionary
joedow
2015/02/14 02:31:27
Acknowledged.
| |
| 140 } | |
| 141 | |
| 142 void InvalidTokenInfoCallback(gaia::GaiaOAuthClient::Delegate* delegate) { | |
| 143 DCHECK(delegate); | |
| 144 | |
| 145 scoped_ptr<base::DictionaryValue> token_info(new base::DictionaryValue()); | |
|
Wez
2015/02/13 03:01:52
And here?
joedow
2015/02/14 02:31:27
Acknowledged.
| |
| 146 token_info->SetString("error", "invalid"); | |
| 147 token_info->SetString("error_description", "Whoa! Invalid Token!"); | |
| 148 delegate->OnGetTokenInfoResponse(token_info.Pass()); | |
| 149 } | |
| 150 | |
| 151 void OAuthErrorCallback(gaia::GaiaOAuthClient::Delegate* delegate) { | |
| 152 DCHECK(delegate); | |
| 153 | |
| 154 delegate->OnOAuthError(); | |
| 155 } | |
| 156 | |
| 157 void NetworkErrorCallback(gaia::GaiaOAuthClient::Delegate* delegate) { | |
| 158 DCHECK(delegate); | |
| 159 | |
| 160 delegate->OnNetworkError(kNetworkErrorCode); | |
| 161 } | |
| 162 | |
| 163 // Verification members used to observe the value of the data retrieved. | |
|
Wez
2015/02/13 03:01:52
nit: Indentation
joedow
2015/02/14 02:31:27
Acknowledged.
| |
| 164 std::string access_token_retrieved; | |
| 165 std::string refresh_token_retrieved; | |
| 166 }; | |
|
Wez
2015/02/13 03:01:51
DISALLOW_COPY_AND_ASSIGN()?
joedow
2015/02/14 02:31:26
Acknowledged.
| |
| 167 | |
| 168 // This class uses all of the same logic as the normal AccessTokenFetcher but it | |
| 169 // overrides the function which refreshes the GaiaOAuthClient so it can use a | |
| 170 // mock instance. | |
| 171 class TestAccessTokenFetcher : public AccessTokenFetcher { | |
|
Wez
2015/02/13 03:01:51
nit: AccessTokenFetcherForTest or FakeAccessTokenF
joedow
2015/02/14 02:31:26
Done.
| |
| 172 public: | |
| 173 explicit TestAccessTokenFetcher(GaiaOAuthClientAdapter* mock_client) { | |
|
Wez
2015/02/13 03:01:51
Make this a scoped_ptr and use make_scoped_ptr() i
joedow
2015/02/14 02:31:26
Done.
| |
| 174 DCHECK(mock_client); | |
| 175 auth_client_.reset(mock_client); | |
| 176 } | |
| 177 ~TestAccessTokenFetcher() override {} | |
| 178 | |
| 179 void RefreshGaiaOAuthClientInstance() override { | |
|
Wez
2015/02/13 03:01:52
If you follow the suggestion re CreateGaiaOAuthCli
joedow
2015/02/14 02:31:26
I don't think I need too make this complex (e.g. a
| |
| 180 // No need to refresh the object here since we use the same mock instance. | |
| 181 } | |
| 182 }; | |
|
Wez
2015/02/13 03:01:52
DISALLOW_COPY_AND_ASSIGN
joedow
2015/02/14 02:31:26
Done.
| |
| 183 | |
| 184 TEST(AccessTokenFetcherTest, ExchangeAuthCodeForAccessToken) { | |
| 185 MockGaiaOAuthClient* mock_gaia_client = new MockGaiaOAuthClient(); | |
| 186 | |
| 187 mock_gaia_client->DelegateToCompleteCallbacks(); | |
|
Wez
2015/02/13 03:01:51
Based on this usage, it looks like this should be
joedow
2015/02/14 02:31:26
Acknowledged.
| |
| 188 | |
| 189 { | |
| 190 testing::Sequence call_sequence; | |
| 191 | |
| 192 EXPECT_CALL(*mock_gaia_client, | |
| 193 GetTokensFromAuthCodeImpl(_)). | |
| 194 Times(1); | |
| 195 | |
| 196 EXPECT_CALL(*mock_gaia_client, | |
| 197 GetTokenInfoImpl(_)). | |
| 198 Times(1); | |
| 199 } | |
| 200 | |
| 201 EXPECT_CALL(*mock_gaia_client, | |
| 202 RefreshTokenImpl(_)). | |
| 203 Times(0); | |
| 204 | |
| 205 // Passing the pointer transfers ownership to the token fetcher class. We | |
| 206 // will continue to use the object as it will be alive until the token fetcher | |
| 207 // is destructed, but we do not want to free it at the end of the function. | |
|
Wez
2015/02/13 03:01:52
nit: destroyed :)
joedow
2015/02/14 02:31:26
Done.
| |
| 208 TestAccessTokenFetcher access_token_fetcher(mock_gaia_client); | |
| 209 | |
| 210 AccessTokenCallback access_token_callback = base::Bind( | |
| 211 &MockGaiaOAuthClient::OnAccessTokenRetrieved, | |
| 212 base::Unretained(mock_gaia_client)); | |
| 213 | |
| 214 access_token_fetcher.GetAccessTokenFromAuthCode( | |
| 215 kAuthCodeValue, | |
| 216 access_token_callback); | |
| 217 | |
| 218 EXPECT_STREQ(kAccessTokenValue, | |
| 219 mock_gaia_client->access_token_retrieved.c_str()); | |
| 220 EXPECT_STREQ(kRefreshTokenValue, | |
| 221 mock_gaia_client->refresh_token_retrieved.c_str()); | |
| 222 } | |
| 223 | |
| 224 TEST(AccessTokenFetcherTest, ExchangeRefreshTokenForAccessToken) { | |
| 225 MockGaiaOAuthClient* mock_gaia_client = new MockGaiaOAuthClient(); | |
| 226 | |
| 227 mock_gaia_client->DelegateToCompleteCallbacks(); | |
| 228 | |
| 229 // Passing the pointer transfers ownership to the token fetcher class. We | |
| 230 // will continue to use the object as it will be alive until the token fetcher | |
| 231 // is destructed, but we do not want to free it at the end of the function. | |
| 232 TestAccessTokenFetcher access_token_fetcher(mock_gaia_client); | |
| 233 | |
| 234 AccessTokenCallback access_token_callback = base::Bind( | |
| 235 &MockGaiaOAuthClient::OnAccessTokenRetrieved, | |
| 236 base::Unretained(mock_gaia_client)); | |
| 237 | |
| 238 { | |
| 239 testing::Sequence call_sequence; | |
| 240 | |
| 241 EXPECT_CALL(*mock_gaia_client, | |
| 242 RefreshTokenImpl(_)). | |
| 243 Times(1); | |
| 244 | |
| 245 EXPECT_CALL(*mock_gaia_client, | |
| 246 GetTokenInfoImpl(_)). | |
| 247 Times(1); | |
| 248 } | |
| 249 | |
| 250 EXPECT_CALL(*mock_gaia_client, | |
| 251 GetTokensFromAuthCodeImpl(_)). | |
| 252 Times(0); | |
| 253 | |
| 254 access_token_fetcher.GetAccessTokenFromRefreshToken( | |
| 255 kRefreshTokenValue, | |
| 256 access_token_callback); | |
| 257 | |
| 258 EXPECT_STREQ(kAccessTokenValue, | |
| 259 mock_gaia_client->access_token_retrieved.c_str()); | |
| 260 EXPECT_STREQ(kRefreshTokenValue, | |
| 261 mock_gaia_client->refresh_token_retrieved.c_str()); | |
| 262 } | |
| 263 | |
| 264 TEST(AccessTokenFetcherTest, MultipleAccessTokenCalls) { | |
| 265 MockGaiaOAuthClient* mock_gaia_client = new MockGaiaOAuthClient(); | |
| 266 | |
| 267 mock_gaia_client->DelegateToCompleteCallbacks(); | |
| 268 | |
| 269 // Passing the pointer transfers ownership to the token fetcher class. We | |
| 270 // will continue to use the object as it will be alive until the token fetcher | |
| 271 // is destructed, but we do not want to free it at the end of the function. | |
| 272 TestAccessTokenFetcher access_token_fetcher(mock_gaia_client); | |
| 273 | |
| 274 AccessTokenCallback access_token_callback = base::Bind( | |
| 275 &MockGaiaOAuthClient::OnAccessTokenRetrieved, | |
| 276 base::Unretained(mock_gaia_client)); | |
| 277 | |
| 278 EXPECT_CALL(*mock_gaia_client, | |
| 279 GetTokensFromAuthCodeImpl(_)). | |
| 280 Times(1); | |
| 281 | |
| 282 EXPECT_CALL(*mock_gaia_client, | |
| 283 RefreshTokenImpl(_)). | |
| 284 Times(2); | |
| 285 | |
| 286 EXPECT_CALL(*mock_gaia_client, | |
| 287 GetTokenInfoImpl(_)). | |
| 288 Times(3); | |
| 289 | |
| 290 access_token_fetcher.GetAccessTokenFromAuthCode( | |
| 291 kAuthCodeValue, | |
| 292 access_token_callback); | |
| 293 | |
| 294 EXPECT_STREQ(kAccessTokenValue, | |
| 295 mock_gaia_client->access_token_retrieved.c_str()); | |
| 296 EXPECT_STREQ(kRefreshTokenValue, | |
| 297 mock_gaia_client->refresh_token_retrieved.c_str()); | |
| 298 | |
| 299 // Reset our token data for the next iteration. | |
| 300 mock_gaia_client->access_token_retrieved.clear(); | |
| 301 mock_gaia_client->refresh_token_retrieved.clear(); | |
| 302 | |
| 303 access_token_fetcher.GetAccessTokenFromRefreshToken( | |
| 304 kRefreshTokenValue, | |
| 305 access_token_callback); | |
| 306 | |
| 307 EXPECT_STREQ(kAccessTokenValue, | |
| 308 mock_gaia_client->access_token_retrieved.c_str()); | |
| 309 EXPECT_STREQ(kRefreshTokenValue, | |
| 310 mock_gaia_client->refresh_token_retrieved.c_str()); | |
| 311 | |
| 312 // Reset our token data for the next iteration. | |
| 313 mock_gaia_client->access_token_retrieved.clear(); | |
| 314 mock_gaia_client->refresh_token_retrieved.clear(); | |
| 315 | |
| 316 access_token_fetcher.GetAccessTokenFromRefreshToken( | |
| 317 kRefreshTokenValue, | |
| 318 access_token_callback); | |
| 319 | |
| 320 EXPECT_STREQ(kAccessTokenValue, | |
| 321 mock_gaia_client->access_token_retrieved.c_str()); | |
| 322 EXPECT_STREQ(kRefreshTokenValue, | |
| 323 mock_gaia_client->refresh_token_retrieved.c_str()); | |
| 324 } | |
| 325 | |
| 326 TEST(AccessTokenFetcherTest, ExchangeAuthCode_OAuthError) { | |
| 327 MockGaiaOAuthClient* mock_gaia_client = new MockGaiaOAuthClient(); | |
| 328 | |
| 329 mock_gaia_client->DelegateToOAuthErrorCallback(); | |
| 330 | |
| 331 // Passing the pointer transfers ownership to the token fetcher class. We | |
| 332 // will continue to use the object as it will be alive until the token fetcher | |
| 333 // is destructed, but we do not want to free it at the end of the function. | |
| 334 TestAccessTokenFetcher access_token_fetcher(mock_gaia_client); | |
| 335 | |
| 336 AccessTokenCallback access_token_callback = base::Bind( | |
| 337 &MockGaiaOAuthClient::OnAccessTokenRetrieved, | |
| 338 base::Unretained(mock_gaia_client)); | |
| 339 | |
| 340 EXPECT_CALL(*mock_gaia_client, | |
| 341 GetTokensFromAuthCodeImpl(_)). | |
| 342 Times(1); | |
| 343 | |
| 344 EXPECT_CALL(*mock_gaia_client, | |
| 345 RefreshTokenImpl(_)). | |
| 346 Times(0); | |
| 347 | |
| 348 EXPECT_CALL(*mock_gaia_client, | |
| 349 GetTokenInfoImpl(_)). | |
| 350 Times(0); | |
| 351 | |
| 352 access_token_fetcher.GetAccessTokenFromAuthCode( | |
| 353 kAuthCodeValue, | |
| 354 access_token_callback); | |
| 355 | |
| 356 // Our callback should have been called with empty strings. | |
| 357 EXPECT_STREQ(mock_gaia_client->access_token_retrieved.c_str(), ""); | |
| 358 EXPECT_STREQ(mock_gaia_client->refresh_token_retrieved.c_str(), ""); | |
| 359 } | |
| 360 | |
| 361 TEST(AccessTokenFetcherTest, ExchangeRefreshToken_OAuthError) { | |
| 362 MockGaiaOAuthClient* mock_gaia_client = new MockGaiaOAuthClient(); | |
| 363 | |
| 364 mock_gaia_client->DelegateToOAuthErrorCallback(); | |
| 365 | |
| 366 // Passing the pointer transfers ownership to the token fetcher class. We | |
| 367 // will continue to use the object as it will be alive until the token fetcher | |
| 368 // is destructed, but we do not want to free it at the end of the function. | |
| 369 TestAccessTokenFetcher access_token_fetcher(mock_gaia_client); | |
| 370 | |
| 371 AccessTokenCallback access_token_callback = base::Bind( | |
| 372 &MockGaiaOAuthClient::OnAccessTokenRetrieved, | |
| 373 base::Unretained(mock_gaia_client)); | |
| 374 | |
| 375 EXPECT_CALL(*mock_gaia_client, | |
| 376 RefreshTokenImpl(_)). | |
| 377 Times(1); | |
| 378 | |
| 379 EXPECT_CALL(*mock_gaia_client, | |
| 380 GetTokenInfoImpl(_)). | |
| 381 Times(0); | |
| 382 | |
| 383 EXPECT_CALL(*mock_gaia_client, | |
| 384 GetTokensFromAuthCodeImpl(_)). | |
| 385 Times(0); | |
| 386 | |
| 387 access_token_fetcher.GetAccessTokenFromRefreshToken( | |
| 388 kRefreshTokenValue, | |
| 389 access_token_callback); | |
| 390 | |
| 391 // Our callback should have been called with empty strings. | |
| 392 EXPECT_STREQ(mock_gaia_client->access_token_retrieved.c_str(), ""); | |
| 393 EXPECT_STREQ(mock_gaia_client->refresh_token_retrieved.c_str(), ""); | |
| 394 } | |
| 395 | |
| 396 TEST(AccessTokenFetcherTest, ExchangeAuthCode_NetworkError) { | |
| 397 MockGaiaOAuthClient* mock_gaia_client = new MockGaiaOAuthClient(); | |
| 398 | |
| 399 mock_gaia_client->DelegateToNetworkErrorCallback(); | |
| 400 | |
| 401 // Passing the pointer transfers ownership to the token fetcher class. We | |
| 402 // will continue to use the object as it will be alive until the token fetcher | |
| 403 // is destructed, but we do not want to free it at the end of the function. | |
| 404 TestAccessTokenFetcher access_token_fetcher(mock_gaia_client); | |
| 405 | |
| 406 AccessTokenCallback access_token_callback = base::Bind( | |
| 407 &MockGaiaOAuthClient::OnAccessTokenRetrieved, | |
| 408 base::Unretained(mock_gaia_client)); | |
| 409 | |
| 410 EXPECT_CALL(*mock_gaia_client, | |
| 411 GetTokensFromAuthCodeImpl(_)). | |
| 412 Times(1); | |
| 413 | |
| 414 EXPECT_CALL(*mock_gaia_client, | |
| 415 RefreshTokenImpl(_)). | |
| 416 Times(0); | |
| 417 | |
| 418 EXPECT_CALL(*mock_gaia_client, | |
| 419 GetTokenInfoImpl(_)). | |
| 420 Times(0); | |
| 421 | |
| 422 access_token_fetcher.GetAccessTokenFromAuthCode( | |
| 423 kAuthCodeValue, | |
| 424 access_token_callback); | |
| 425 | |
| 426 // Our callback should have been called with empty strings. | |
| 427 EXPECT_STREQ(mock_gaia_client->access_token_retrieved.c_str(), ""); | |
| 428 EXPECT_STREQ(mock_gaia_client->refresh_token_retrieved.c_str(), ""); | |
| 429 } | |
| 430 | |
| 431 TEST(AccessTokenFetcherTest, ExchangeRefreshToken_NetworkError) { | |
| 432 MockGaiaOAuthClient* mock_gaia_client = new MockGaiaOAuthClient(); | |
| 433 | |
| 434 mock_gaia_client->DelegateToNetworkErrorCallback(); | |
| 435 | |
| 436 // Passing the pointer transfers ownership to the token fetcher class. We | |
| 437 // will continue to use the object as it will be alive until the token fetcher | |
| 438 // is destructed, but we do not want to free it at the end of the function. | |
| 439 TestAccessTokenFetcher access_token_fetcher(mock_gaia_client); | |
| 440 | |
| 441 AccessTokenCallback access_token_callback = base::Bind( | |
| 442 &MockGaiaOAuthClient::OnAccessTokenRetrieved, | |
| 443 base::Unretained(mock_gaia_client)); | |
| 444 | |
| 445 EXPECT_CALL(*mock_gaia_client, | |
| 446 RefreshTokenImpl(_)). | |
| 447 Times(1); | |
| 448 | |
| 449 EXPECT_CALL(*mock_gaia_client, | |
| 450 GetTokenInfoImpl(_)). | |
| 451 Times(0); | |
| 452 | |
| 453 EXPECT_CALL(*mock_gaia_client, | |
| 454 GetTokensFromAuthCodeImpl(_)). | |
| 455 Times(0); | |
| 456 | |
| 457 access_token_fetcher.GetAccessTokenFromRefreshToken( | |
| 458 kRefreshTokenValue, | |
| 459 access_token_callback); | |
| 460 | |
| 461 // Our callback should have been called with empty strings. | |
| 462 EXPECT_STREQ(mock_gaia_client->access_token_retrieved.c_str(), ""); | |
| 463 EXPECT_STREQ(mock_gaia_client->refresh_token_retrieved.c_str(), ""); | |
| 464 } | |
| 465 | |
| 466 TEST(AccessTokenFetcherTest, AuthCode_GetTokenInfoResponse_InvalidToken) { | |
| 467 MockGaiaOAuthClient* mock_gaia_client = new MockGaiaOAuthClient(); | |
| 468 | |
| 469 mock_gaia_client->DelegateToInvalidTokenCallback(); | |
| 470 | |
| 471 // Passing the pointer transfers ownership to the token fetcher class. We | |
| 472 // will continue to use the object as it will be alive until the token fetcher | |
| 473 // is destructed, but we do not want to free it at the end of the function. | |
| 474 TestAccessTokenFetcher access_token_fetcher(mock_gaia_client); | |
| 475 | |
| 476 AccessTokenCallback access_token_callback = base::Bind( | |
| 477 &MockGaiaOAuthClient::OnAccessTokenRetrieved, | |
| 478 base::Unretained(mock_gaia_client)); | |
| 479 | |
| 480 EXPECT_CALL(*mock_gaia_client, | |
| 481 GetTokensFromAuthCodeImpl(_)). | |
| 482 Times(1); | |
| 483 | |
| 484 EXPECT_CALL(*mock_gaia_client, | |
| 485 GetTokenInfoImpl(_)). | |
| 486 Times(1); | |
| 487 | |
| 488 EXPECT_CALL(*mock_gaia_client, | |
| 489 RefreshTokenImpl(_)). | |
| 490 Times(0); | |
| 491 | |
| 492 access_token_fetcher.GetAccessTokenFromAuthCode( | |
| 493 kAuthCodeValue, | |
| 494 access_token_callback); | |
| 495 | |
| 496 // Our callback should have been called with empty strings. | |
| 497 EXPECT_STREQ(mock_gaia_client->access_token_retrieved.c_str(), ""); | |
| 498 EXPECT_STREQ(mock_gaia_client->refresh_token_retrieved.c_str(), ""); | |
| 499 } | |
| 500 | |
| 501 TEST(AccessTokenFetcherTest, RefreshToken_GetTokenInfoResponse_InvalidToken) { | |
| 502 MockGaiaOAuthClient* mock_gaia_client = new MockGaiaOAuthClient(); | |
| 503 | |
| 504 mock_gaia_client->DelegateToInvalidTokenCallback(); | |
| 505 | |
| 506 // Passing the pointer transfers ownership to the token fetcher class. We | |
| 507 // will continue to use the object as it will be alive until the token fetcher | |
| 508 // is destructed, but we do not want to free it at the end of the function. | |
|
Wez
2015/02/13 03:01:52
Suggest moving this comment in this and the preced
joedow
2015/02/14 02:31:26
Done.
| |
| 509 TestAccessTokenFetcher access_token_fetcher(mock_gaia_client); | |
| 510 | |
| 511 AccessTokenCallback access_token_callback = base::Bind( | |
| 512 &MockGaiaOAuthClient::OnAccessTokenRetrieved, | |
| 513 base::Unretained(mock_gaia_client)); | |
| 514 | |
| 515 EXPECT_CALL(*mock_gaia_client, | |
| 516 RefreshTokenImpl(_)). | |
| 517 Times(1); | |
| 518 | |
| 519 EXPECT_CALL(*mock_gaia_client, | |
| 520 GetTokenInfoImpl(_)). | |
| 521 Times(1); | |
| 522 | |
| 523 EXPECT_CALL(*mock_gaia_client, | |
| 524 GetTokensFromAuthCodeImpl(_)). | |
| 525 Times(0); | |
|
Wez
2015/02/13 03:01:51
Here and in earlier tests; can't you set these exp
joedow
2015/02/14 02:31:26
Done.
| |
| 526 | |
| 527 access_token_fetcher.GetAccessTokenFromRefreshToken( | |
| 528 kRefreshTokenValue, | |
| 529 access_token_callback); | |
| 530 | |
| 531 // Our callback should have been called with empty strings. | |
| 532 EXPECT_STREQ(mock_gaia_client->access_token_retrieved.c_str(), ""); | |
| 533 EXPECT_STREQ(mock_gaia_client->refresh_token_retrieved.c_str(), ""); | |
| 534 } | |
| 535 | |
| 536 } // namespace test | |
| 537 } // namespace remoting | |
| OLD | NEW |