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/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
12 #include "base/time/time.h" | 12 #include "base/time/time.h" |
13 #include "google_apis/gaia/gaia_urls.h" | 13 #include "google_apis/gaia/gaia_urls.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_consumer.h" | 15 #include "google_apis/gaia/oauth2_access_token_consumer.h" |
16 #include "google_apis/gaia/oauth2_access_token_fetcher_impl.h" | 16 #include "google_apis/gaia/oauth2_access_token_fetcher_impl.h" |
17 #include "google_apis/gaia/oauth2_api_call_flow.h" | 17 #include "google_apis/gaia/oauth2_api_call_flow.h" |
| 18 #include "net/base/net_errors.h" |
18 #include "net/http/http_request_headers.h" | 19 #include "net/http/http_request_headers.h" |
19 #include "net/http/http_status_code.h" | 20 #include "net/http/http_status_code.h" |
20 #include "net/url_request/test_url_fetcher_factory.h" | 21 #include "net/url_request/test_url_fetcher_factory.h" |
21 #include "net/url_request/url_fetcher.h" | 22 #include "net/url_request/url_fetcher.h" |
22 #include "net/url_request/url_fetcher_delegate.h" | 23 #include "net/url_request/url_fetcher_delegate.h" |
23 #include "net/url_request/url_fetcher_factory.h" | 24 #include "net/url_request/url_fetcher_factory.h" |
24 #include "net/url_request/url_request.h" | 25 #include "net/url_request/url_request.h" |
25 #include "net/url_request/url_request_status.h" | 26 #include "net/url_request/url_request_status.h" |
26 #include "net/url_request/url_request_test_util.h" | 27 #include "net/url_request/url_request_test_util.h" |
27 #include "testing/gmock/include/gmock/gmock.h" | 28 #include "testing/gmock/include/gmock/gmock.h" |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 class OAuth2ApiCallFlowTest : public testing::Test { | 99 class OAuth2ApiCallFlowTest : public testing::Test { |
99 protected: | 100 protected: |
100 OAuth2ApiCallFlowTest() | 101 OAuth2ApiCallFlowTest() |
101 : request_context_getter_(new net::TestURLRequestContextGetter( | 102 : request_context_getter_(new net::TestURLRequestContextGetter( |
102 message_loop_.task_runner())) {} | 103 message_loop_.task_runner())) {} |
103 | 104 |
104 TestURLFetcher* CreateURLFetcher( | 105 TestURLFetcher* CreateURLFetcher( |
105 const GURL& url, bool fetch_succeeds, | 106 const GURL& url, bool fetch_succeeds, |
106 int response_code, const std::string& body) { | 107 int response_code, const std::string& body) { |
107 TestURLFetcher* url_fetcher = new TestURLFetcher(0, url, &flow_); | 108 TestURLFetcher* url_fetcher = new TestURLFetcher(0, url, &flow_); |
108 URLRequestStatus::Status status = | 109 net::Error error = fetch_succeeds ? net::OK : net::ERR_FAILED; |
109 fetch_succeeds ? URLRequestStatus::SUCCESS : URLRequestStatus::FAILED; | 110 url_fetcher->set_status(URLRequestStatus::FromError(error)); |
110 url_fetcher->set_status(URLRequestStatus(status, 0)); | |
111 | 111 |
112 if (response_code != 0) | 112 if (response_code != 0) |
113 url_fetcher->set_response_code(response_code); | 113 url_fetcher->set_response_code(response_code); |
114 | 114 |
115 if (!body.empty()) | 115 if (!body.empty()) |
116 url_fetcher->SetResponseString(body); | 116 url_fetcher->SetResponseString(body); |
117 | 117 |
118 return url_fetcher; | 118 return url_fetcher; |
119 } | 119 } |
120 | 120 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 TestURLFetcher* url_fetcher = SetupApiCall(true, net::HTTP_OK); | 164 TestURLFetcher* url_fetcher = SetupApiCall(true, net::HTTP_OK); |
165 flow_.Start(request_context_getter_.get(), kAccessToken); | 165 flow_.Start(request_context_getter_.get(), kAccessToken); |
166 HttpRequestHeaders headers; | 166 HttpRequestHeaders headers; |
167 url_fetcher->GetExtraRequestHeaders(&headers); | 167 url_fetcher->GetExtraRequestHeaders(&headers); |
168 std::string auth_header; | 168 std::string auth_header; |
169 EXPECT_TRUE(headers.GetHeader("Authorization", &auth_header)); | 169 EXPECT_TRUE(headers.GetHeader("Authorization", &auth_header)); |
170 EXPECT_EQ("Bearer access_token", auth_header); | 170 EXPECT_EQ("Bearer access_token", auth_header); |
171 EXPECT_EQ(url, url_fetcher->GetOriginalURL()); | 171 EXPECT_EQ(url, url_fetcher->GetOriginalURL()); |
172 EXPECT_EQ(body, url_fetcher->upload_data()); | 172 EXPECT_EQ(body, url_fetcher->upload_data()); |
173 } | 173 } |
OLD | NEW |