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 OAuth2MintTokenFlow. | 5 // A complete set of unit tests for OAuth2MintTokenFlow. |
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" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
13 #include "base/values.h" | 13 #include "base/values.h" |
14 #include "google_apis/gaia/google_service_auth_error.h" | 14 #include "google_apis/gaia/google_service_auth_error.h" |
15 #include "google_apis/gaia/oauth2_access_token_fetcher.h" | 15 #include "google_apis/gaia/oauth2_access_token_fetcher.h" |
16 #include "google_apis/gaia/oauth2_mint_token_flow.h" | 16 #include "google_apis/gaia/oauth2_mint_token_flow.h" |
| 17 #include "net/base/net_errors.h" |
17 #include "net/url_request/test_url_fetcher_factory.h" | 18 #include "net/url_request/test_url_fetcher_factory.h" |
18 #include "net/url_request/url_request_status.h" | 19 #include "net/url_request/url_request_status.h" |
19 #include "testing/gmock/include/gmock/gmock.h" | 20 #include "testing/gmock/include/gmock/gmock.h" |
20 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
21 | 22 |
22 using net::TestURLFetcher; | 23 using net::TestURLFetcher; |
23 using net::URLFetcher; | 24 using net::URLFetcher; |
24 using net::URLRequestStatus; | 25 using net::URLRequestStatus; |
25 using testing::_; | 26 using testing::_; |
26 using testing::StrictMock; | 27 using testing::StrictMock; |
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
345 CreateFlow(OAuth2MintTokenFlow::MODE_ISSUE_ADVICE); | 346 CreateFlow(OAuth2MintTokenFlow::MODE_ISSUE_ADVICE); |
346 IssueAdviceInfo ia(CreateIssueAdvice()); | 347 IssueAdviceInfo ia(CreateIssueAdvice()); |
347 EXPECT_CALL(delegate_, OnIssueAdviceSuccess(ia)); | 348 EXPECT_CALL(delegate_, OnIssueAdviceSuccess(ia)); |
348 flow_->ProcessApiCallSuccess(&url_fetcher); | 349 flow_->ProcessApiCallSuccess(&url_fetcher); |
349 } | 350 } |
350 } | 351 } |
351 | 352 |
352 TEST_F(OAuth2MintTokenFlowTest, ProcessApiCallFailure) { | 353 TEST_F(OAuth2MintTokenFlowTest, ProcessApiCallFailure) { |
353 { // Null delegate should work fine. | 354 { // Null delegate should work fine. |
354 TestURLFetcher url_fetcher(1, GURL("http://www.google.com"), NULL); | 355 TestURLFetcher url_fetcher(1, GURL("http://www.google.com"), NULL); |
355 url_fetcher.set_status(URLRequestStatus(URLRequestStatus::FAILED, 101)); | 356 url_fetcher.set_status(URLRequestStatus::FromError(net::ERR_FAILED)); |
356 CreateFlow(NULL, OAuth2MintTokenFlow::MODE_MINT_TOKEN_NO_FORCE, ""); | 357 CreateFlow(NULL, OAuth2MintTokenFlow::MODE_MINT_TOKEN_NO_FORCE, ""); |
357 flow_->ProcessApiCallFailure(&url_fetcher); | 358 flow_->ProcessApiCallFailure(&url_fetcher); |
358 } | 359 } |
359 | 360 |
360 { // Non-null delegate. | 361 { // Non-null delegate. |
361 TestURLFetcher url_fetcher(1, GURL("http://www.google.com"), NULL); | 362 TestURLFetcher url_fetcher(1, GURL("http://www.google.com"), NULL); |
362 url_fetcher.set_status(URLRequestStatus(URLRequestStatus::FAILED, 101)); | 363 url_fetcher.set_status(URLRequestStatus::FromError(net::ERR_FAILED)); |
363 CreateFlow(OAuth2MintTokenFlow::MODE_MINT_TOKEN_NO_FORCE); | 364 CreateFlow(OAuth2MintTokenFlow::MODE_MINT_TOKEN_NO_FORCE); |
364 EXPECT_CALL(delegate_, OnMintTokenFailure(_)); | 365 EXPECT_CALL(delegate_, OnMintTokenFailure(_)); |
365 flow_->ProcessApiCallFailure(&url_fetcher); | 366 flow_->ProcessApiCallFailure(&url_fetcher); |
366 } | 367 } |
367 } | 368 } |
OLD | NEW |