| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // A complete set of unit tests for GaiaOAuthClient. | 5 // A complete set of unit tests for GaiaOAuthClient. |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
| (...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 292 EXPECT_CALL(delegate, OnGetTokensResponse(kTestRefreshToken, kTestAccessToken, | 292 EXPECT_CALL(delegate, OnGetTokensResponse(kTestRefreshToken, kTestAccessToken, |
| 293 kTestExpiresIn)).Times(1); | 293 kTestExpiresIn)).Times(1); |
| 294 | 294 |
| 295 MockOAuthFetcherFactory factory; | 295 MockOAuthFetcherFactory factory; |
| 296 factory.set_results(kDummyGetTokensResult); | 296 factory.set_results(kDummyGetTokensResult); |
| 297 | 297 |
| 298 GaiaOAuthClient auth(GetRequestContext()); | 298 GaiaOAuthClient auth(GetRequestContext()); |
| 299 auth.GetTokensFromAuthCode(client_info_, "auth_code", -1, &delegate); | 299 auth.GetTokensFromAuthCode(client_info_, "auth_code", -1, &delegate); |
| 300 } | 300 } |
| 301 | 301 |
| 302 TEST_F(GaiaOAuthClientTest, GetTokensAfterNetworkFailure) { |
| 303 int response_code = net::HTTP_INTERNAL_SERVER_ERROR; |
| 304 |
| 305 MockGaiaOAuthClientDelegate failure_delegate; |
| 306 EXPECT_CALL(failure_delegate, OnNetworkError(response_code)).Times(1); |
| 307 |
| 308 MockGaiaOAuthClientDelegate success_delegate; |
| 309 EXPECT_CALL(success_delegate, OnGetTokensResponse(kTestRefreshToken, |
| 310 kTestAccessToken, kTestExpiresIn)).Times(1); |
| 311 |
| 312 MockOAuthFetcherFactory factory; |
| 313 factory.set_response_code(response_code); |
| 314 factory.set_max_failure_count(4); |
| 315 factory.set_results(kDummyGetTokensResult); |
| 316 |
| 317 GaiaOAuthClient auth(GetRequestContext()); |
| 318 auth.GetTokensFromAuthCode(client_info_, "auth_code", 2, &failure_delegate); |
| 319 auth.GetTokensFromAuthCode(client_info_, "auth_code", -1, &success_delegate); |
| 320 } |
| 321 |
| 302 TEST_F(GaiaOAuthClientTest, RefreshTokenSuccess) { | 322 TEST_F(GaiaOAuthClientTest, RefreshTokenSuccess) { |
| 303 MockGaiaOAuthClientDelegate delegate; | 323 MockGaiaOAuthClientDelegate delegate; |
| 304 EXPECT_CALL(delegate, OnRefreshTokenResponse(kTestAccessToken, | 324 EXPECT_CALL(delegate, OnRefreshTokenResponse(kTestAccessToken, |
| 305 kTestExpiresIn)).Times(1); | 325 kTestExpiresIn)).Times(1); |
| 306 | 326 |
| 307 MockOAuthFetcherFactory factory; | 327 MockOAuthFetcherFactory factory; |
| 308 factory.set_results(kDummyRefreshTokenResult); | 328 factory.set_results(kDummyRefreshTokenResult); |
| 309 factory.set_complete_immediately(false); | 329 factory.set_complete_immediately(false); |
| 310 | 330 |
| 311 GaiaOAuthClient auth(GetRequestContext()); | 331 GaiaOAuthClient auth(GetRequestContext()); |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 409 | 429 |
| 410 GaiaOAuthClient auth(GetRequestContext()); | 430 GaiaOAuthClient auth(GetRequestContext()); |
| 411 auth.GetTokenHandleInfo("some_handle", 1, &delegate); | 431 auth.GetTokenHandleInfo("some_handle", 1, &delegate); |
| 412 | 432 |
| 413 std::string audience; | 433 std::string audience; |
| 414 ASSERT_TRUE(captured_result->GetString("audience", &audience)); | 434 ASSERT_TRUE(captured_result->GetString("audience", &audience)); |
| 415 ASSERT_EQ("1234567890.apps.googleusercontent.com", audience); | 435 ASSERT_EQ("1234567890.apps.googleusercontent.com", audience); |
| 416 } | 436 } |
| 417 | 437 |
| 418 } // namespace gaia | 438 } // namespace gaia |
| OLD | NEW |