OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #include "net/url_request/url_request_unittest.h" | 5 #include "net/url_request/url_request_unittest.h" |
6 | 6 |
7 #include "build/build_config.h" | 7 #include "build/build_config.h" |
8 | 8 |
9 #if defined(OS_WIN) | 9 #if defined(OS_WIN) |
10 #include <windows.h> | 10 #include <windows.h> |
11 #include <shlobj.h> | 11 #include <shlobj.h> |
12 #elif defined(USE_NSS) | 12 #elif defined(USE_NSS) |
13 #include "base/nss_util.h" | 13 #include "base/nss_util.h" |
14 #endif | 14 #endif |
15 | 15 |
16 #include <algorithm> | 16 #include <algorithm> |
17 #include <string> | 17 #include <string> |
18 | 18 |
19 #include "base/file_util.h" | 19 #include "base/file_util.h" |
20 #include "base/format_macros.h" | 20 #include "base/format_macros.h" |
21 #include "base/message_loop.h" | 21 #include "base/message_loop.h" |
22 #include "base/path_service.h" | 22 #include "base/path_service.h" |
23 #include "base/process_util.h" | 23 #include "base/process_util.h" |
24 #include "base/string_piece.h" | 24 #include "base/string_piece.h" |
25 #include "base/string_util.h" | 25 #include "base/string_number_conversions.h" |
26 #include "net/base/cookie_monster.h" | 26 #include "net/base/cookie_monster.h" |
27 #include "net/base/cookie_policy.h" | 27 #include "net/base/cookie_policy.h" |
28 #include "net/base/load_flags.h" | 28 #include "net/base/load_flags.h" |
29 #include "net/base/net_log.h" | 29 #include "net/base/net_log.h" |
30 #include "net/base/net_log_unittest.h" | 30 #include "net/base/net_log_unittest.h" |
31 #include "net/base/net_errors.h" | 31 #include "net/base/net_errors.h" |
32 #include "net/base/net_module.h" | 32 #include "net/base/net_module.h" |
33 #include "net/base/net_util.h" | 33 #include "net/base/net_util.h" |
34 #include "net/base/upload_data.h" | 34 #include "net/base/upload_data.h" |
35 #include "net/disk_cache/disk_cache.h" | 35 #include "net/disk_cache/disk_cache.h" |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 TEST_F(URLRequestTestHTTP, ProxyTunnelRedirectTest) { | 165 TEST_F(URLRequestTestHTTP, ProxyTunnelRedirectTest) { |
166 // In this unit test, we're using the HTTPTestServer as a proxy server and | 166 // In this unit test, we're using the HTTPTestServer as a proxy server and |
167 // issuing a CONNECT request with the magic host name "www.redirect.com". | 167 // issuing a CONNECT request with the magic host name "www.redirect.com". |
168 // The HTTPTestServer will return a 302 response, which we should not | 168 // The HTTPTestServer will return a 302 response, which we should not |
169 // follow. | 169 // follow. |
170 ASSERT_TRUE(NULL != server_.get()); | 170 ASSERT_TRUE(NULL != server_.get()); |
171 TestDelegate d; | 171 TestDelegate d; |
172 { | 172 { |
173 URLRequest r(GURL("https://www.redirect.com/"), &d); | 173 URLRequest r(GURL("https://www.redirect.com/"), &d); |
174 std::string proxy("localhost:"); | 174 std::string proxy("localhost:"); |
175 proxy.append(IntToString(kHTTPDefaultPort)); | 175 proxy.append(base::IntToString(kHTTPDefaultPort)); |
176 r.set_context(new TestURLRequestContext(proxy)); | 176 r.set_context(new TestURLRequestContext(proxy)); |
177 | 177 |
178 r.Start(); | 178 r.Start(); |
179 EXPECT_TRUE(r.is_pending()); | 179 EXPECT_TRUE(r.is_pending()); |
180 | 180 |
181 MessageLoop::current()->Run(); | 181 MessageLoop::current()->Run(); |
182 | 182 |
183 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status()); | 183 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status()); |
184 EXPECT_EQ(net::ERR_TUNNEL_CONNECTION_FAILED, r.status().os_error()); | 184 EXPECT_EQ(net::ERR_TUNNEL_CONNECTION_FAILED, r.status().os_error()); |
185 EXPECT_EQ(1, d.response_started_count()); | 185 EXPECT_EQ(1, d.response_started_count()); |
186 // We should not have followed the redirect. | 186 // We should not have followed the redirect. |
187 EXPECT_EQ(0, d.received_redirect_count()); | 187 EXPECT_EQ(0, d.received_redirect_count()); |
188 } | 188 } |
189 } | 189 } |
190 | 190 |
191 TEST_F(URLRequestTestHTTP, UnexpectedServerAuthTest) { | 191 TEST_F(URLRequestTestHTTP, UnexpectedServerAuthTest) { |
192 // In this unit test, we're using the HTTPTestServer as a proxy server and | 192 // In this unit test, we're using the HTTPTestServer as a proxy server and |
193 // issuing a CONNECT request with the magic host name "www.server-auth.com". | 193 // issuing a CONNECT request with the magic host name "www.server-auth.com". |
194 // The HTTPTestServer will return a 401 response, which we should balk at. | 194 // The HTTPTestServer will return a 401 response, which we should balk at. |
195 ASSERT_TRUE(NULL != server_.get()); | 195 ASSERT_TRUE(NULL != server_.get()); |
196 TestDelegate d; | 196 TestDelegate d; |
197 { | 197 { |
198 URLRequest r(GURL("https://www.server-auth.com/"), &d); | 198 URLRequest r(GURL("https://www.server-auth.com/"), &d); |
199 std::string proxy("localhost:"); | 199 std::string proxy("localhost:"); |
200 proxy.append(IntToString(kHTTPDefaultPort)); | 200 proxy.append(base::IntToString(kHTTPDefaultPort)); |
201 r.set_context(new TestURLRequestContext(proxy)); | 201 r.set_context(new TestURLRequestContext(proxy)); |
202 | 202 |
203 r.Start(); | 203 r.Start(); |
204 EXPECT_TRUE(r.is_pending()); | 204 EXPECT_TRUE(r.is_pending()); |
205 | 205 |
206 MessageLoop::current()->Run(); | 206 MessageLoop::current()->Run(); |
207 | 207 |
208 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status()); | 208 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status()); |
209 EXPECT_EQ(net::ERR_TUNNEL_CONNECTION_FAILED, r.status().os_error()); | 209 EXPECT_EQ(net::ERR_TUNNEL_CONNECTION_FAILED, r.status().os_error()); |
210 } | 210 } |
(...skipping 1543 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1754 TEST_F(URLRequestTestHTTP, Post307RedirectPost) { | 1754 TEST_F(URLRequestTestHTTP, Post307RedirectPost) { |
1755 const char kData[] = "hello world"; | 1755 const char kData[] = "hello world"; |
1756 ASSERT_TRUE(NULL != server_.get()); | 1756 ASSERT_TRUE(NULL != server_.get()); |
1757 TestDelegate d; | 1757 TestDelegate d; |
1758 TestURLRequest req(server_->TestServerPage("files/redirect307-to-echo"), | 1758 TestURLRequest req(server_->TestServerPage("files/redirect307-to-echo"), |
1759 &d); | 1759 &d); |
1760 req.set_method("POST"); | 1760 req.set_method("POST"); |
1761 req.set_upload(CreateSimpleUploadData(kData).get()); | 1761 req.set_upload(CreateSimpleUploadData(kData).get()); |
1762 net::HttpRequestHeaders headers; | 1762 net::HttpRequestHeaders headers; |
1763 headers.SetHeader(net::HttpRequestHeaders::kContentLength, | 1763 headers.SetHeader(net::HttpRequestHeaders::kContentLength, |
1764 UintToString(arraysize(kData) - 1)); | 1764 base::UintToString(arraysize(kData) - 1)); |
1765 req.SetExtraRequestHeaders(headers); | 1765 req.SetExtraRequestHeaders(headers); |
1766 req.Start(); | 1766 req.Start(); |
1767 MessageLoop::current()->Run(); | 1767 MessageLoop::current()->Run(); |
1768 EXPECT_EQ("POST", req.method()); | 1768 EXPECT_EQ("POST", req.method()); |
1769 EXPECT_EQ(kData, d.data_received()); | 1769 EXPECT_EQ(kData, d.data_received()); |
1770 } | 1770 } |
1771 | 1771 |
1772 // Custom URLRequestJobs for use with interceptor tests | 1772 // Custom URLRequestJobs for use with interceptor tests |
1773 class RestartTestJob : public URLRequestTestJob { | 1773 class RestartTestJob : public URLRequestTestJob { |
1774 public: | 1774 public: |
(...skipping 785 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2560 TestURLRequest | 2560 TestURLRequest |
2561 req(server_->TestServerPage("echoheaderoverride?Accept-Charset"), &d); | 2561 req(server_->TestServerPage("echoheaderoverride?Accept-Charset"), &d); |
2562 req.set_context(new TestURLRequestContext()); | 2562 req.set_context(new TestURLRequestContext()); |
2563 net::HttpRequestHeaders headers; | 2563 net::HttpRequestHeaders headers; |
2564 headers.SetHeader(net::HttpRequestHeaders::kAcceptCharset, "koi-8r"); | 2564 headers.SetHeader(net::HttpRequestHeaders::kAcceptCharset, "koi-8r"); |
2565 req.SetExtraRequestHeaders(headers); | 2565 req.SetExtraRequestHeaders(headers); |
2566 req.Start(); | 2566 req.Start(); |
2567 MessageLoop::current()->Run(); | 2567 MessageLoop::current()->Run(); |
2568 EXPECT_EQ(std::string("koi-8r"), d.data_received()); | 2568 EXPECT_EQ(std::string("koi-8r"), d.data_received()); |
2569 } | 2569 } |
OLD | NEW |