| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 GaiaAuthFetcher. | 5 // A complete set of unit tests for GaiaAuthFetcher. |
| 6 // Originally ported from GoogleAuthenticator tests. | 6 // Originally ported from GoogleAuthenticator tests. |
| 7 | 7 |
| 8 #include "chrome/common/net/gaia/gaia_auth_fetcher_unittest.h" | 8 #include "chrome/common/net/gaia/gaia_auth_fetcher_unittest.h" |
| 9 | 9 |
| 10 #include <string> | 10 #include <string> |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 #include "net/base/net_errors.h" | 25 #include "net/base/net_errors.h" |
| 26 #include "net/url_request/url_request_status.h" | 26 #include "net/url_request/url_request_status.h" |
| 27 #include "testing/gmock/include/gmock/gmock.h" | 27 #include "testing/gmock/include/gmock/gmock.h" |
| 28 #include "testing/gtest/include/gtest/gtest.h" | 28 #include "testing/gtest/include/gtest/gtest.h" |
| 29 | 29 |
| 30 using ::testing::_; | 30 using ::testing::_; |
| 31 | 31 |
| 32 MockFetcher::MockFetcher(bool success, | 32 MockFetcher::MockFetcher(bool success, |
| 33 const GURL& url, | 33 const GURL& url, |
| 34 const std::string& results, | 34 const std::string& results, |
| 35 URLFetcher::RequestType request_type, | 35 content::URLFetcher::RequestType request_type, |
| 36 content::URLFetcherDelegate* d) | 36 content::URLFetcherDelegate* d) |
| 37 : URLFetcher(url, request_type, d), | 37 : TestURLFetcher(0, url, request_type, d) { |
| 38 url_(url), | 38 set_url(url); |
| 39 results_(results) { | |
| 40 net::URLRequestStatus::Status code; | 39 net::URLRequestStatus::Status code; |
| 41 | 40 |
| 42 if (success) { | 41 if (success) { |
| 43 response_code_ = RC_REQUEST_OK; | 42 set_response_code(RC_REQUEST_OK); |
| 44 code = net::URLRequestStatus::SUCCESS; | 43 code = net::URLRequestStatus::SUCCESS; |
| 45 } else { | 44 } else { |
| 46 response_code_ = RC_FORBIDDEN; | 45 set_response_code(RC_FORBIDDEN); |
| 47 code = net::URLRequestStatus::FAILED; | 46 code = net::URLRequestStatus::FAILED; |
| 48 } | 47 } |
| 49 | 48 |
| 50 status_ = net::URLRequestStatus(code, 0); | 49 set_status(net::URLRequestStatus(code, 0)); |
| 50 SetResponseString(results); |
| 51 } | 51 } |
| 52 | 52 |
| 53 MockFetcher::MockFetcher(const GURL& url, | 53 MockFetcher::MockFetcher(const GURL& url, |
| 54 const net::URLRequestStatus& status, | 54 const net::URLRequestStatus& status, |
| 55 int response_code, | 55 int response_code, |
| 56 const net::ResponseCookies& cookies, | 56 const net::ResponseCookies& cookies, |
| 57 const std::string& results, | 57 const std::string& results, |
| 58 URLFetcher::RequestType request_type, | 58 content::URLFetcher::RequestType request_type, |
| 59 content::URLFetcherDelegate* d) | 59 content::URLFetcherDelegate* d) |
| 60 : URLFetcher(url, request_type, d), | 60 : TestURLFetcher(0, url, request_type, d) { |
| 61 url_(url), | 61 set_url(url); |
| 62 status_(status), | 62 set_status(status); |
| 63 response_code_(response_code), | 63 set_response_code(response_code); |
| 64 cookies_(cookies), | 64 set_cookies(cookies); |
| 65 results_(results) { | 65 SetResponseString(results); |
| 66 } | 66 } |
| 67 | 67 |
| 68 MockFetcher::~MockFetcher() {} | 68 MockFetcher::~MockFetcher() {} |
| 69 | 69 |
| 70 void MockFetcher::Start() { | 70 void MockFetcher::Start() { |
| 71 delegate()->OnURLFetchComplete(this); | 71 delegate()->OnURLFetchComplete(this); |
| 72 } | 72 } |
| 73 | 73 |
| 74 const GURL& MockFetcher::GetUrl() const { | |
| 75 return url_; | |
| 76 } | |
| 77 | |
| 78 const net::URLRequestStatus& MockFetcher::GetStatus() const { | |
| 79 return status_; | |
| 80 } | |
| 81 | |
| 82 int MockFetcher::GetResponseCode() const { | |
| 83 return response_code_; | |
| 84 } | |
| 85 | |
| 86 const net::ResponseCookies& MockFetcher::GetCookies() const { | |
| 87 return cookies_; | |
| 88 } | |
| 89 | |
| 90 bool MockFetcher::GetResponseAsString(std::string* out_response_string) const { | |
| 91 *out_response_string = results_; | |
| 92 return true; | |
| 93 } | |
| 94 | |
| 95 | |
| 96 class GaiaAuthFetcherTest : public testing::Test { | 74 class GaiaAuthFetcherTest : public testing::Test { |
| 97 public: | 75 public: |
| 98 GaiaAuthFetcherTest() | 76 GaiaAuthFetcherTest() |
| 99 : client_login_source_(GaiaUrls::GetInstance()->client_login_url()), | 77 : client_login_source_(GaiaUrls::GetInstance()->client_login_url()), |
| 100 issue_auth_token_source_( | 78 issue_auth_token_source_( |
| 101 GaiaUrls::GetInstance()->issue_auth_token_url()), | 79 GaiaUrls::GetInstance()->issue_auth_token_url()), |
| 102 token_auth_source_(GaiaUrls::GetInstance()->token_auth_url()), | 80 token_auth_source_(GaiaUrls::GetInstance()->token_auth_url()), |
| 103 merge_session_source_(GaiaUrls::GetInstance()->merge_session_url()) {} | 81 merge_session_source_(GaiaUrls::GetInstance()->merge_session_url()) {} |
| 104 | 82 |
| 105 void RunParsingTest(const std::string& data, | 83 void RunParsingTest(const std::string& data, |
| (...skipping 547 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 653 test_fetcher->set_url(final_url); | 631 test_fetcher->set_url(final_url); |
| 654 test_fetcher->set_status( | 632 test_fetcher->set_status( |
| 655 net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0)); | 633 net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0)); |
| 656 test_fetcher->set_response_code(RC_REQUEST_OK); | 634 test_fetcher->set_response_code(RC_REQUEST_OK); |
| 657 test_fetcher->set_cookies(cookies_); | 635 test_fetcher->set_cookies(cookies_); |
| 658 test_fetcher->SetResponseString("<html></html>"); | 636 test_fetcher->SetResponseString("<html></html>"); |
| 659 | 637 |
| 660 auth.OnURLFetchComplete(test_fetcher); | 638 auth.OnURLFetchComplete(test_fetcher); |
| 661 EXPECT_FALSE(auth.HasPendingFetch()); | 639 EXPECT_FALSE(auth.HasPendingFetch()); |
| 662 } | 640 } |
| OLD | NEW |