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" | |
15 #include "chrome/common/net/gaia/gaia_auth_fetcher.h" | |
16 #include "chrome/common/net/gaia/gaia_urls.h" | |
17 #include "chrome/common/net/gaia/google_service_auth_error.h" | |
18 #include "chrome/common/net/gaia/mock_url_fetcher_factory.h" | |
19 #include "chrome/test/base/testing_profile.h" | 14 #include "chrome/test/base/testing_profile.h" |
| 15 #include "google_apis/gaia/gaia_auth_consumer.h" |
| 16 #include "google_apis/gaia/gaia_auth_fetcher.h" |
| 17 #include "google_apis/gaia/gaia_urls.h" |
| 18 #include "google_apis/gaia/google_service_auth_error.h" |
| 19 #include "google_apis/gaia/mock_url_fetcher_factory.h" |
20 #include "googleurl/src/gurl.h" | 20 #include "googleurl/src/gurl.h" |
21 #include "net/base/load_flags.h" | 21 #include "net/base/load_flags.h" |
22 #include "net/base/net_errors.h" | 22 #include "net/base/net_errors.h" |
23 #include "net/http/http_status_code.h" | 23 #include "net/http/http_status_code.h" |
24 #include "net/url_request/test_url_fetcher_factory.h" | 24 #include "net/url_request/test_url_fetcher_factory.h" |
25 #include "net/url_request/url_fetcher_delegate.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 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 net::URLFetcher::RequestType request_type, | 87 net::URLFetcher::RequestType request_type, |
88 net::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); |
(...skipping 909 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1012 .Times(1); | 1012 .Times(1); |
1013 | 1013 |
1014 GaiaAuthFetcher auth(&consumer, std::string(), | 1014 GaiaAuthFetcher auth(&consumer, std::string(), |
1015 profile_.GetRequestContext()); | 1015 profile_.GetRequestContext()); |
1016 net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0); | 1016 net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0); |
1017 MockFetcher mock_fetcher( | 1017 MockFetcher mock_fetcher( |
1018 oauth_login_gurl_, status, net::HTTP_OK, cookies_, data, | 1018 oauth_login_gurl_, status, net::HTTP_OK, cookies_, data, |
1019 net::URLFetcher::GET, &auth); | 1019 net::URLFetcher::GET, &auth); |
1020 auth.OnURLFetchComplete(&mock_fetcher); | 1020 auth.OnURLFetchComplete(&mock_fetcher); |
1021 } | 1021 } |
OLD | NEW |