| 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 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 <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
| 11 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
| 12 #include "base/stringprintf.h" | 12 #include "base/stringprintf.h" |
| 13 #include "base/values.h" | 13 #include "base/values.h" |
| 14 #include "chrome/common/net/gaia/gaia_auth_consumer.h" | 14 #include "chrome/common/net/gaia/gaia_auth_consumer.h" |
| 15 #include "chrome/common/net/gaia/gaia_auth_fetcher.h" | 15 #include "chrome/common/net/gaia/gaia_auth_fetcher.h" |
| 16 #include "chrome/common/net/gaia/gaia_urls.h" | 16 #include "chrome/common/net/gaia/gaia_urls.h" |
| 17 #include "chrome/common/net/gaia/google_service_auth_error.h" | 17 #include "chrome/common/net/gaia/google_service_auth_error.h" |
| 18 #include "chrome/common/net/gaia/mock_url_fetcher_factory.h" | 18 #include "chrome/common/net/gaia/mock_url_fetcher_factory.h" |
| 19 #include "chrome/test/base/testing_profile.h" | 19 #include "chrome/test/base/testing_profile.h" |
| 20 #include "content/public/common/url_fetcher_delegate.h" | |
| 21 #include "content/test/test_url_fetcher_factory.h" | 20 #include "content/test/test_url_fetcher_factory.h" |
| 22 #include "googleurl/src/gurl.h" | 21 #include "googleurl/src/gurl.h" |
| 23 #include "net/base/load_flags.h" | 22 #include "net/base/load_flags.h" |
| 24 #include "net/base/net_errors.h" | 23 #include "net/base/net_errors.h" |
| 25 #include "net/http/http_status_code.h" | 24 #include "net/http/http_status_code.h" |
| 25 #include "net/url_request/url_fetcher_delegate.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 using ::testing::Invoke; | 31 using ::testing::Invoke; |
| 32 | 32 |
| 33 namespace { | 33 namespace { |
| 34 static const char kGetAuthCodeValidCookie[] = | 34 static const char kGetAuthCodeValidCookie[] = |
| 35 "oauth_code=test-code; Path=/test; Secure; HttpOnly"; | 35 "oauth_code=test-code; Path=/test; Secure; HttpOnly"; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 EXPECT_EQ("alternate_text", error.second_factor().alternate_text); | 78 EXPECT_EQ("alternate_text", error.second_factor().alternate_text); |
| 79 EXPECT_EQ(10, error.second_factor().field_length); | 79 EXPECT_EQ(10, error.second_factor().field_length); |
| 80 } | 80 } |
| 81 | 81 |
| 82 } // namespace | 82 } // namespace |
| 83 | 83 |
| 84 MockFetcher::MockFetcher(bool success, | 84 MockFetcher::MockFetcher(bool success, |
| 85 const GURL& url, | 85 const GURL& url, |
| 86 const std::string& results, | 86 const std::string& results, |
| 87 content::URLFetcher::RequestType request_type, | 87 content::URLFetcher::RequestType request_type, |
| 88 content::URLFetcherDelegate* d) | 88 net::URLFetcherDelegate* d) |
| 89 : TestURLFetcher(0, url, d) { | 89 : TestURLFetcher(0, url, d) { |
| 90 set_url(url); | 90 set_url(url); |
| 91 net::URLRequestStatus::Status code; | 91 net::URLRequestStatus::Status code; |
| 92 | 92 |
| 93 if (success) { | 93 if (success) { |
| 94 set_response_code(net::HTTP_OK); | 94 set_response_code(net::HTTP_OK); |
| 95 code = net::URLRequestStatus::SUCCESS; | 95 code = net::URLRequestStatus::SUCCESS; |
| 96 } else { | 96 } else { |
| 97 set_response_code(net::HTTP_FORBIDDEN); | 97 set_response_code(net::HTTP_FORBIDDEN); |
| 98 code = net::URLRequestStatus::FAILED; | 98 code = net::URLRequestStatus::FAILED; |
| 99 } | 99 } |
| 100 | 100 |
| 101 set_status(net::URLRequestStatus(code, 0)); | 101 set_status(net::URLRequestStatus(code, 0)); |
| 102 SetResponseString(results); | 102 SetResponseString(results); |
| 103 } | 103 } |
| 104 | 104 |
| 105 MockFetcher::MockFetcher(const GURL& url, | 105 MockFetcher::MockFetcher(const GURL& url, |
| 106 const net::URLRequestStatus& status, | 106 const net::URLRequestStatus& status, |
| 107 int response_code, | 107 int response_code, |
| 108 const net::ResponseCookies& cookies, | 108 const net::ResponseCookies& cookies, |
| 109 const std::string& results, | 109 const std::string& results, |
| 110 content::URLFetcher::RequestType request_type, | 110 content::URLFetcher::RequestType request_type, |
| 111 content::URLFetcherDelegate* d) | 111 net::URLFetcherDelegate* d) |
| 112 : TestURLFetcher(0, url, d) { | 112 : TestURLFetcher(0, url, d) { |
| 113 set_url(url); | 113 set_url(url); |
| 114 set_status(status); | 114 set_status(status); |
| 115 set_response_code(response_code); | 115 set_response_code(response_code); |
| 116 set_cookies(cookies); | 116 set_cookies(cookies); |
| 117 SetResponseString(results); | 117 SetResponseString(results); |
| 118 } | 118 } |
| 119 | 119 |
| 120 MockFetcher::~MockFetcher() {} | 120 MockFetcher::~MockFetcher() {} |
| 121 | 121 |
| (...skipping 903 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1025 .Times(1); | 1025 .Times(1); |
| 1026 | 1026 |
| 1027 GaiaAuthFetcher auth(&consumer, std::string(), | 1027 GaiaAuthFetcher auth(&consumer, std::string(), |
| 1028 profile_.GetRequestContext()); | 1028 profile_.GetRequestContext()); |
| 1029 net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0); | 1029 net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0); |
| 1030 MockFetcher mock_fetcher( | 1030 MockFetcher mock_fetcher( |
| 1031 oauth_login_gurl_, status, net::HTTP_OK, cookies_, data, | 1031 oauth_login_gurl_, status, net::HTTP_OK, cookies_, data, |
| 1032 content::URLFetcher::GET, &auth); | 1032 content::URLFetcher::GET, &auth); |
| 1033 auth.OnURLFetchComplete(&mock_fetcher); | 1033 auth.OnURLFetchComplete(&mock_fetcher); |
| 1034 } | 1034 } |
| OLD | NEW |