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 #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 <shlobj.h> | 10 #include <shlobj.h> |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 { | 190 { |
191 net::URLRequest r(GURL("https://www.redirect.com/"), &d); | 191 net::URLRequest r(GURL("https://www.redirect.com/"), &d); |
192 r.set_context( | 192 r.set_context( |
193 new TestURLRequestContext(test_server_.host_port_pair().ToString())); | 193 new TestURLRequestContext(test_server_.host_port_pair().ToString())); |
194 | 194 |
195 r.Start(); | 195 r.Start(); |
196 EXPECT_TRUE(r.is_pending()); | 196 EXPECT_TRUE(r.is_pending()); |
197 | 197 |
198 MessageLoop::current()->Run(); | 198 MessageLoop::current()->Run(); |
199 | 199 |
200 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status()); | 200 EXPECT_EQ(net::URLRequestStatus::FAILED, r.status().status()); |
201 EXPECT_EQ(net::ERR_TUNNEL_CONNECTION_FAILED, r.status().os_error()); | 201 EXPECT_EQ(net::ERR_TUNNEL_CONNECTION_FAILED, r.status().os_error()); |
202 EXPECT_EQ(1, d.response_started_count()); | 202 EXPECT_EQ(1, d.response_started_count()); |
203 // We should not have followed the redirect. | 203 // We should not have followed the redirect. |
204 EXPECT_EQ(0, d.received_redirect_count()); | 204 EXPECT_EQ(0, d.received_redirect_count()); |
205 } | 205 } |
206 } | 206 } |
207 | 207 |
208 // In this unit test, we're using the HTTPTestServer as a proxy server and | 208 // In this unit test, we're using the HTTPTestServer as a proxy server and |
209 // issuing a CONNECT request with the magic host name "www.server-auth.com". | 209 // issuing a CONNECT request with the magic host name "www.server-auth.com". |
210 // The HTTPTestServer will return a 401 response, which we should balk at. | 210 // The HTTPTestServer will return a 401 response, which we should balk at. |
211 TEST_F(URLRequestTestHTTP, UnexpectedServerAuthTest) { | 211 TEST_F(URLRequestTestHTTP, UnexpectedServerAuthTest) { |
212 ASSERT_TRUE(test_server_.Start()); | 212 ASSERT_TRUE(test_server_.Start()); |
213 | 213 |
214 TestDelegate d; | 214 TestDelegate d; |
215 { | 215 { |
216 net::URLRequest r(GURL("https://www.server-auth.com/"), &d); | 216 net::URLRequest r(GURL("https://www.server-auth.com/"), &d); |
217 r.set_context( | 217 r.set_context( |
218 new TestURLRequestContext(test_server_.host_port_pair().ToString())); | 218 new TestURLRequestContext(test_server_.host_port_pair().ToString())); |
219 | 219 |
220 r.Start(); | 220 r.Start(); |
221 EXPECT_TRUE(r.is_pending()); | 221 EXPECT_TRUE(r.is_pending()); |
222 | 222 |
223 MessageLoop::current()->Run(); | 223 MessageLoop::current()->Run(); |
224 | 224 |
225 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status()); | 225 EXPECT_EQ(net::URLRequestStatus::FAILED, r.status().status()); |
226 EXPECT_EQ(net::ERR_TUNNEL_CONNECTION_FAILED, r.status().os_error()); | 226 EXPECT_EQ(net::ERR_TUNNEL_CONNECTION_FAILED, r.status().os_error()); |
227 } | 227 } |
228 } | 228 } |
229 | 229 |
230 TEST_F(URLRequestTestHTTP, GetTest_NoCache) { | 230 TEST_F(URLRequestTestHTTP, GetTest_NoCache) { |
231 ASSERT_TRUE(test_server_.Start()); | 231 ASSERT_TRUE(test_server_.Start()); |
232 | 232 |
233 TestDelegate d; | 233 TestDelegate d; |
234 { | 234 { |
235 TestURLRequest r(test_server_.GetURL(""), &d); | 235 TestURLRequest r(test_server_.GetURL(""), &d); |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
468 d.set_cancel_in_response_started(true); | 468 d.set_cancel_in_response_started(true); |
469 | 469 |
470 r.Start(); | 470 r.Start(); |
471 EXPECT_TRUE(r.is_pending()); | 471 EXPECT_TRUE(r.is_pending()); |
472 | 472 |
473 MessageLoop::current()->Run(); | 473 MessageLoop::current()->Run(); |
474 | 474 |
475 EXPECT_EQ(1, d.response_started_count()); | 475 EXPECT_EQ(1, d.response_started_count()); |
476 EXPECT_EQ(0, d.bytes_received()); | 476 EXPECT_EQ(0, d.bytes_received()); |
477 EXPECT_FALSE(d.received_data_before_response()); | 477 EXPECT_FALSE(d.received_data_before_response()); |
478 EXPECT_EQ(URLRequestStatus::CANCELED, r.status().status()); | 478 EXPECT_EQ(net::URLRequestStatus::CANCELED, r.status().status()); |
479 } | 479 } |
480 } | 480 } |
481 | 481 |
482 TEST_F(URLRequestTestHTTP, CancelTest3) { | 482 TEST_F(URLRequestTestHTTP, CancelTest3) { |
483 ASSERT_TRUE(test_server_.Start()); | 483 ASSERT_TRUE(test_server_.Start()); |
484 | 484 |
485 TestDelegate d; | 485 TestDelegate d; |
486 { | 486 { |
487 TestURLRequest r(test_server_.GetURL(""), &d); | 487 TestURLRequest r(test_server_.GetURL(""), &d); |
488 | 488 |
489 d.set_cancel_in_received_data(true); | 489 d.set_cancel_in_received_data(true); |
490 | 490 |
491 r.Start(); | 491 r.Start(); |
492 EXPECT_TRUE(r.is_pending()); | 492 EXPECT_TRUE(r.is_pending()); |
493 | 493 |
494 MessageLoop::current()->Run(); | 494 MessageLoop::current()->Run(); |
495 | 495 |
496 EXPECT_EQ(1, d.response_started_count()); | 496 EXPECT_EQ(1, d.response_started_count()); |
497 // There is no guarantee about how much data was received | 497 // There is no guarantee about how much data was received |
498 // before the cancel was issued. It could have been 0 bytes, | 498 // before the cancel was issued. It could have been 0 bytes, |
499 // or it could have been all the bytes. | 499 // or it could have been all the bytes. |
500 // EXPECT_EQ(0, d.bytes_received()); | 500 // EXPECT_EQ(0, d.bytes_received()); |
501 EXPECT_FALSE(d.received_data_before_response()); | 501 EXPECT_FALSE(d.received_data_before_response()); |
502 EXPECT_EQ(URLRequestStatus::CANCELED, r.status().status()); | 502 EXPECT_EQ(net::URLRequestStatus::CANCELED, r.status().status()); |
503 } | 503 } |
504 } | 504 } |
505 | 505 |
506 TEST_F(URLRequestTestHTTP, CancelTest4) { | 506 TEST_F(URLRequestTestHTTP, CancelTest4) { |
507 ASSERT_TRUE(test_server_.Start()); | 507 ASSERT_TRUE(test_server_.Start()); |
508 | 508 |
509 TestDelegate d; | 509 TestDelegate d; |
510 { | 510 { |
511 TestURLRequest r(test_server_.GetURL(""), &d); | 511 TestURLRequest r(test_server_.GetURL(""), &d); |
512 | 512 |
(...skipping 20 matching lines...) Expand all Loading... |
533 | 533 |
534 scoped_refptr<URLRequestContext> context(new TestURLRequestContext()); | 534 scoped_refptr<URLRequestContext> context(new TestURLRequestContext()); |
535 | 535 |
536 // populate cache | 536 // populate cache |
537 { | 537 { |
538 TestDelegate d; | 538 TestDelegate d; |
539 net::URLRequest r(test_server_.GetURL("cachetime"), &d); | 539 net::URLRequest r(test_server_.GetURL("cachetime"), &d); |
540 r.set_context(context); | 540 r.set_context(context); |
541 r.Start(); | 541 r.Start(); |
542 MessageLoop::current()->Run(); | 542 MessageLoop::current()->Run(); |
543 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); | 543 EXPECT_EQ(net::URLRequestStatus::SUCCESS, r.status().status()); |
544 } | 544 } |
545 | 545 |
546 // cancel read from cache (see bug 990242) | 546 // cancel read from cache (see bug 990242) |
547 { | 547 { |
548 TestDelegate d; | 548 TestDelegate d; |
549 net::URLRequest r(test_server_.GetURL("cachetime"), &d); | 549 net::URLRequest r(test_server_.GetURL("cachetime"), &d); |
550 r.set_context(context); | 550 r.set_context(context); |
551 r.Start(); | 551 r.Start(); |
552 r.Cancel(); | 552 r.Cancel(); |
553 MessageLoop::current()->Run(); | 553 MessageLoop::current()->Run(); |
554 | 554 |
555 EXPECT_EQ(URLRequestStatus::CANCELED, r.status().status()); | 555 EXPECT_EQ(net::URLRequestStatus::CANCELED, r.status().status()); |
556 EXPECT_EQ(1, d.response_started_count()); | 556 EXPECT_EQ(1, d.response_started_count()); |
557 EXPECT_EQ(0, d.bytes_received()); | 557 EXPECT_EQ(0, d.bytes_received()); |
558 EXPECT_FALSE(d.received_data_before_response()); | 558 EXPECT_FALSE(d.received_data_before_response()); |
559 } | 559 } |
560 } | 560 } |
561 | 561 |
562 TEST_F(URLRequestTestHTTP, PostTest) { | 562 TEST_F(URLRequestTestHTTP, PostTest) { |
563 ASSERT_TRUE(test_server_.Start()); | 563 ASSERT_TRUE(test_server_.Start()); |
564 HTTPUploadDataOperationTest("POST"); | 564 HTTPUploadDataOperationTest("POST"); |
565 } | 565 } |
(...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1024 | 1024 |
1025 TEST_F(URLRequestTestHTTP, RestrictRedirects) { | 1025 TEST_F(URLRequestTestHTTP, RestrictRedirects) { |
1026 ASSERT_TRUE(test_server_.Start()); | 1026 ASSERT_TRUE(test_server_.Start()); |
1027 | 1027 |
1028 TestDelegate d; | 1028 TestDelegate d; |
1029 TestURLRequest req(test_server_.GetURL( | 1029 TestURLRequest req(test_server_.GetURL( |
1030 "files/redirect-to-file.html"), &d); | 1030 "files/redirect-to-file.html"), &d); |
1031 req.Start(); | 1031 req.Start(); |
1032 MessageLoop::current()->Run(); | 1032 MessageLoop::current()->Run(); |
1033 | 1033 |
1034 EXPECT_EQ(URLRequestStatus::FAILED, req.status().status()); | 1034 EXPECT_EQ(net::URLRequestStatus::FAILED, req.status().status()); |
1035 EXPECT_EQ(net::ERR_UNSAFE_REDIRECT, req.status().os_error()); | 1035 EXPECT_EQ(net::ERR_UNSAFE_REDIRECT, req.status().os_error()); |
1036 } | 1036 } |
1037 | 1037 |
1038 TEST_F(URLRequestTestHTTP, RedirectToInvalidURL) { | 1038 TEST_F(URLRequestTestHTTP, RedirectToInvalidURL) { |
1039 ASSERT_TRUE(test_server_.Start()); | 1039 ASSERT_TRUE(test_server_.Start()); |
1040 | 1040 |
1041 TestDelegate d; | 1041 TestDelegate d; |
1042 TestURLRequest req(test_server_.GetURL( | 1042 TestURLRequest req(test_server_.GetURL( |
1043 "files/redirect-to-invalid-url.html"), &d); | 1043 "files/redirect-to-invalid-url.html"), &d); |
1044 req.Start(); | 1044 req.Start(); |
1045 MessageLoop::current()->Run(); | 1045 MessageLoop::current()->Run(); |
1046 | 1046 |
1047 EXPECT_EQ(URLRequestStatus::FAILED, req.status().status()); | 1047 EXPECT_EQ(net::URLRequestStatus::FAILED, req.status().status()); |
1048 EXPECT_EQ(net::ERR_INVALID_URL, req.status().os_error()); | 1048 EXPECT_EQ(net::ERR_INVALID_URL, req.status().os_error()); |
1049 } | 1049 } |
1050 | 1050 |
1051 TEST_F(URLRequestTestHTTP, NoUserPassInReferrer) { | 1051 TEST_F(URLRequestTestHTTP, NoUserPassInReferrer) { |
1052 ASSERT_TRUE(test_server_.Start()); | 1052 ASSERT_TRUE(test_server_.Start()); |
1053 | 1053 |
1054 TestDelegate d; | 1054 TestDelegate d; |
1055 TestURLRequest req(test_server_.GetURL( | 1055 TestURLRequest req(test_server_.GetURL( |
1056 "echoheader?Referer"), &d); | 1056 "echoheader?Referer"), &d); |
1057 req.set_referrer("http://user:pass@foo.com/"); | 1057 req.set_referrer("http://user:pass@foo.com/"); |
(...skipping 10 matching lines...) Expand all Loading... |
1068 { | 1068 { |
1069 d.set_cancel_in_received_redirect(true); | 1069 d.set_cancel_in_received_redirect(true); |
1070 TestURLRequest req(test_server_.GetURL( | 1070 TestURLRequest req(test_server_.GetURL( |
1071 "files/redirect-test.html"), &d); | 1071 "files/redirect-test.html"), &d); |
1072 req.Start(); | 1072 req.Start(); |
1073 MessageLoop::current()->Run(); | 1073 MessageLoop::current()->Run(); |
1074 | 1074 |
1075 EXPECT_EQ(1, d.response_started_count()); | 1075 EXPECT_EQ(1, d.response_started_count()); |
1076 EXPECT_EQ(0, d.bytes_received()); | 1076 EXPECT_EQ(0, d.bytes_received()); |
1077 EXPECT_FALSE(d.received_data_before_response()); | 1077 EXPECT_FALSE(d.received_data_before_response()); |
1078 EXPECT_EQ(URLRequestStatus::CANCELED, req.status().status()); | 1078 EXPECT_EQ(net::URLRequestStatus::CANCELED, req.status().status()); |
1079 } | 1079 } |
1080 } | 1080 } |
1081 | 1081 |
1082 TEST_F(URLRequestTestHTTP, DeferredRedirect) { | 1082 TEST_F(URLRequestTestHTTP, DeferredRedirect) { |
1083 ASSERT_TRUE(test_server_.Start()); | 1083 ASSERT_TRUE(test_server_.Start()); |
1084 | 1084 |
1085 TestDelegate d; | 1085 TestDelegate d; |
1086 { | 1086 { |
1087 d.set_quit_on_redirect(true); | 1087 d.set_quit_on_redirect(true); |
1088 TestURLRequest req(test_server_.GetURL( | 1088 TestURLRequest req(test_server_.GetURL( |
1089 "files/redirect-test.html"), &d); | 1089 "files/redirect-test.html"), &d); |
1090 req.Start(); | 1090 req.Start(); |
1091 MessageLoop::current()->Run(); | 1091 MessageLoop::current()->Run(); |
1092 | 1092 |
1093 EXPECT_EQ(1, d.received_redirect_count()); | 1093 EXPECT_EQ(1, d.received_redirect_count()); |
1094 | 1094 |
1095 req.FollowDeferredRedirect(); | 1095 req.FollowDeferredRedirect(); |
1096 MessageLoop::current()->Run(); | 1096 MessageLoop::current()->Run(); |
1097 | 1097 |
1098 EXPECT_EQ(1, d.response_started_count()); | 1098 EXPECT_EQ(1, d.response_started_count()); |
1099 EXPECT_FALSE(d.received_data_before_response()); | 1099 EXPECT_FALSE(d.received_data_before_response()); |
1100 EXPECT_EQ(URLRequestStatus::SUCCESS, req.status().status()); | 1100 EXPECT_EQ(net::URLRequestStatus::SUCCESS, req.status().status()); |
1101 | 1101 |
1102 FilePath path; | 1102 FilePath path; |
1103 PathService::Get(base::DIR_SOURCE_ROOT, &path); | 1103 PathService::Get(base::DIR_SOURCE_ROOT, &path); |
1104 path = path.Append(FILE_PATH_LITERAL("net")); | 1104 path = path.Append(FILE_PATH_LITERAL("net")); |
1105 path = path.Append(FILE_PATH_LITERAL("data")); | 1105 path = path.Append(FILE_PATH_LITERAL("data")); |
1106 path = path.Append(FILE_PATH_LITERAL("url_request_unittest")); | 1106 path = path.Append(FILE_PATH_LITERAL("url_request_unittest")); |
1107 path = path.Append(FILE_PATH_LITERAL("with-headers.html")); | 1107 path = path.Append(FILE_PATH_LITERAL("with-headers.html")); |
1108 | 1108 |
1109 std::string contents; | 1109 std::string contents; |
1110 EXPECT_TRUE(file_util::ReadFileToString(path, &contents)); | 1110 EXPECT_TRUE(file_util::ReadFileToString(path, &contents)); |
(...skipping 13 matching lines...) Expand all Loading... |
1124 MessageLoop::current()->Run(); | 1124 MessageLoop::current()->Run(); |
1125 | 1125 |
1126 EXPECT_EQ(1, d.received_redirect_count()); | 1126 EXPECT_EQ(1, d.received_redirect_count()); |
1127 | 1127 |
1128 req.Cancel(); | 1128 req.Cancel(); |
1129 MessageLoop::current()->Run(); | 1129 MessageLoop::current()->Run(); |
1130 | 1130 |
1131 EXPECT_EQ(1, d.response_started_count()); | 1131 EXPECT_EQ(1, d.response_started_count()); |
1132 EXPECT_EQ(0, d.bytes_received()); | 1132 EXPECT_EQ(0, d.bytes_received()); |
1133 EXPECT_FALSE(d.received_data_before_response()); | 1133 EXPECT_FALSE(d.received_data_before_response()); |
1134 EXPECT_EQ(URLRequestStatus::CANCELED, req.status().status()); | 1134 EXPECT_EQ(net::URLRequestStatus::CANCELED, req.status().status()); |
1135 } | 1135 } |
1136 } | 1136 } |
1137 | 1137 |
1138 TEST_F(URLRequestTestHTTP, VaryHeader) { | 1138 TEST_F(URLRequestTestHTTP, VaryHeader) { |
1139 ASSERT_TRUE(test_server_.Start()); | 1139 ASSERT_TRUE(test_server_.Start()); |
1140 | 1140 |
1141 scoped_refptr<URLRequestContext> context(new TestURLRequestContext()); | 1141 scoped_refptr<URLRequestContext> context(new TestURLRequestContext()); |
1142 | 1142 |
1143 // populate the cache | 1143 // populate the cache |
1144 { | 1144 { |
(...skipping 526 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1671 { | 1671 { |
1672 TestDelegate d; | 1672 TestDelegate d; |
1673 d.set_cancel_in_get_cookies_blocked(true); | 1673 d.set_cancel_in_get_cookies_blocked(true); |
1674 net::URLRequest req(test_server.GetURL("set-cookie?A=1&B=2&C=3"), | 1674 net::URLRequest req(test_server.GetURL("set-cookie?A=1&B=2&C=3"), |
1675 &d); | 1675 &d); |
1676 req.set_context(context); | 1676 req.set_context(context); |
1677 req.Start(); // Triggers an asynchronous cookie policy check. | 1677 req.Start(); // Triggers an asynchronous cookie policy check. |
1678 | 1678 |
1679 MessageLoop::current()->Run(); | 1679 MessageLoop::current()->Run(); |
1680 | 1680 |
1681 EXPECT_EQ(URLRequestStatus::CANCELED, req.status().status()); | 1681 EXPECT_EQ(net::URLRequestStatus::CANCELED, req.status().status()); |
1682 | 1682 |
1683 EXPECT_EQ(1, d.blocked_get_cookies_count()); | 1683 EXPECT_EQ(1, d.blocked_get_cookies_count()); |
1684 EXPECT_EQ(0, d.blocked_set_cookie_count()); | 1684 EXPECT_EQ(0, d.blocked_set_cookie_count()); |
1685 } | 1685 } |
1686 | 1686 |
1687 context->set_cookie_policy(NULL); | 1687 context->set_cookie_policy(NULL); |
1688 } | 1688 } |
1689 | 1689 |
1690 TEST_F(URLRequestTest, CancelTest_During_OnSetCookie) { | 1690 TEST_F(URLRequestTest, CancelTest_During_OnSetCookie) { |
1691 net::TestServer test_server(net::TestServer::TYPE_HTTP, FilePath()); | 1691 net::TestServer test_server(net::TestServer::TYPE_HTTP, FilePath()); |
1692 ASSERT_TRUE(test_server.Start()); | 1692 ASSERT_TRUE(test_server.Start()); |
1693 | 1693 |
1694 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext()); | 1694 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext()); |
1695 | 1695 |
1696 TestCookiePolicy cookie_policy(TestCookiePolicy::NO_SET_COOKIE); | 1696 TestCookiePolicy cookie_policy(TestCookiePolicy::NO_SET_COOKIE); |
1697 context->set_cookie_policy(&cookie_policy); | 1697 context->set_cookie_policy(&cookie_policy); |
1698 | 1698 |
1699 // Set up a cookie. | 1699 // Set up a cookie. |
1700 { | 1700 { |
1701 TestDelegate d; | 1701 TestDelegate d; |
1702 d.set_cancel_in_set_cookie_blocked(true); | 1702 d.set_cancel_in_set_cookie_blocked(true); |
1703 net::URLRequest req(test_server.GetURL("set-cookie?A=1&B=2&C=3"), | 1703 net::URLRequest req(test_server.GetURL("set-cookie?A=1&B=2&C=3"), |
1704 &d); | 1704 &d); |
1705 req.set_context(context); | 1705 req.set_context(context); |
1706 req.Start(); // Triggers an asynchronous cookie policy check. | 1706 req.Start(); // Triggers an asynchronous cookie policy check. |
1707 | 1707 |
1708 MessageLoop::current()->Run(); | 1708 MessageLoop::current()->Run(); |
1709 | 1709 |
1710 EXPECT_EQ(URLRequestStatus::CANCELED, req.status().status()); | 1710 EXPECT_EQ(net::URLRequestStatus::CANCELED, req.status().status()); |
1711 | 1711 |
1712 // Even though the response will contain 3 set-cookie headers, we expect | 1712 // Even though the response will contain 3 set-cookie headers, we expect |
1713 // only one to be blocked as that first one will cause OnSetCookie to be | 1713 // only one to be blocked as that first one will cause OnSetCookie to be |
1714 // called, which will cancel the request. Once canceled, it should not | 1714 // called, which will cancel the request. Once canceled, it should not |
1715 // attempt to set further cookies. | 1715 // attempt to set further cookies. |
1716 | 1716 |
1717 EXPECT_EQ(0, d.blocked_get_cookies_count()); | 1717 EXPECT_EQ(0, d.blocked_get_cookies_count()); |
1718 EXPECT_EQ(1, d.blocked_set_cookie_count()); | 1718 EXPECT_EQ(1, d.blocked_set_cookie_count()); |
1719 } | 1719 } |
1720 | 1720 |
(...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2185 req.set_method("GET"); | 2185 req.set_method("GET"); |
2186 req.Start(); | 2186 req.Start(); |
2187 MessageLoop::current()->Run(); | 2187 MessageLoop::current()->Run(); |
2188 | 2188 |
2189 // Check the interceptor got called as expected | 2189 // Check the interceptor got called as expected |
2190 EXPECT_TRUE(interceptor.did_cancel_main_); | 2190 EXPECT_TRUE(interceptor.did_cancel_main_); |
2191 EXPECT_FALSE(interceptor.did_intercept_final_); | 2191 EXPECT_FALSE(interceptor.did_intercept_final_); |
2192 | 2192 |
2193 // Check we see a canceled request | 2193 // Check we see a canceled request |
2194 EXPECT_FALSE(req.status().is_success()); | 2194 EXPECT_FALSE(req.status().is_success()); |
2195 EXPECT_EQ(URLRequestStatus::CANCELED, req.status().status()); | 2195 EXPECT_EQ(net::URLRequestStatus::CANCELED, req.status().status()); |
2196 } | 2196 } |
2197 | 2197 |
2198 TEST_F(URLRequestTest, InterceptRespectsCancelRedirect) { | 2198 TEST_F(URLRequestTest, InterceptRespectsCancelRedirect) { |
2199 TestInterceptor interceptor; | 2199 TestInterceptor interceptor; |
2200 | 2200 |
2201 // intercept the main request and respond with a redirect | 2201 // intercept the main request and respond with a redirect |
2202 interceptor.intercept_main_request_ = true; | 2202 interceptor.intercept_main_request_ = true; |
2203 interceptor.main_headers_ = TestInterceptor::redirect_headers(); | 2203 interceptor.main_headers_ = TestInterceptor::redirect_headers(); |
2204 interceptor.main_data_ = TestInterceptor::redirect_data(); | 2204 interceptor.main_data_ = TestInterceptor::redirect_data(); |
2205 | 2205 |
(...skipping 11 matching lines...) Expand all Loading... |
2217 req.Start(); | 2217 req.Start(); |
2218 MessageLoop::current()->Run(); | 2218 MessageLoop::current()->Run(); |
2219 | 2219 |
2220 // Check the interceptor got called as expected | 2220 // Check the interceptor got called as expected |
2221 EXPECT_TRUE(interceptor.did_intercept_main_); | 2221 EXPECT_TRUE(interceptor.did_intercept_main_); |
2222 EXPECT_TRUE(interceptor.did_cancel_redirect_); | 2222 EXPECT_TRUE(interceptor.did_cancel_redirect_); |
2223 EXPECT_FALSE(interceptor.did_intercept_final_); | 2223 EXPECT_FALSE(interceptor.did_intercept_final_); |
2224 | 2224 |
2225 // Check we see a canceled request | 2225 // Check we see a canceled request |
2226 EXPECT_FALSE(req.status().is_success()); | 2226 EXPECT_FALSE(req.status().is_success()); |
2227 EXPECT_EQ(URLRequestStatus::CANCELED, req.status().status()); | 2227 EXPECT_EQ(net::URLRequestStatus::CANCELED, req.status().status()); |
2228 } | 2228 } |
2229 | 2229 |
2230 TEST_F(URLRequestTest, InterceptRespectsCancelFinal) { | 2230 TEST_F(URLRequestTest, InterceptRespectsCancelFinal) { |
2231 TestInterceptor interceptor; | 2231 TestInterceptor interceptor; |
2232 | 2232 |
2233 // intercept the main request to simulate a network error | 2233 // intercept the main request to simulate a network error |
2234 interceptor.simulate_main_network_error_ = true; | 2234 interceptor.simulate_main_network_error_ = true; |
2235 | 2235 |
2236 // setup to intercept final response and cancel from within that job | 2236 // setup to intercept final response and cancel from within that job |
2237 interceptor.cancel_final_request_ = true; | 2237 interceptor.cancel_final_request_ = true; |
2238 | 2238 |
2239 TestDelegate d; | 2239 TestDelegate d; |
2240 TestURLRequest req(GURL("http://test_intercept/foo"), &d); | 2240 TestURLRequest req(GURL("http://test_intercept/foo"), &d); |
2241 req.set_method("GET"); | 2241 req.set_method("GET"); |
2242 req.Start(); | 2242 req.Start(); |
2243 MessageLoop::current()->Run(); | 2243 MessageLoop::current()->Run(); |
2244 | 2244 |
2245 // Check the interceptor got called as expected | 2245 // Check the interceptor got called as expected |
2246 EXPECT_TRUE(interceptor.did_simulate_error_main_); | 2246 EXPECT_TRUE(interceptor.did_simulate_error_main_); |
2247 EXPECT_TRUE(interceptor.did_cancel_final_); | 2247 EXPECT_TRUE(interceptor.did_cancel_final_); |
2248 | 2248 |
2249 // Check we see a canceled request | 2249 // Check we see a canceled request |
2250 EXPECT_FALSE(req.status().is_success()); | 2250 EXPECT_FALSE(req.status().is_success()); |
2251 EXPECT_EQ(URLRequestStatus::CANCELED, req.status().status()); | 2251 EXPECT_EQ(net::URLRequestStatus::CANCELED, req.status().status()); |
2252 } | 2252 } |
2253 | 2253 |
2254 TEST_F(URLRequestTest, InterceptRespectsCancelInRestart) { | 2254 TEST_F(URLRequestTest, InterceptRespectsCancelInRestart) { |
2255 TestInterceptor interceptor; | 2255 TestInterceptor interceptor; |
2256 | 2256 |
2257 // intercept the main request and cancel then restart from within that job | 2257 // intercept the main request and cancel then restart from within that job |
2258 interceptor.cancel_then_restart_main_request_ = true; | 2258 interceptor.cancel_then_restart_main_request_ = true; |
2259 | 2259 |
2260 // setup to intercept final response and override it with an OK response | 2260 // setup to intercept final response and override it with an OK response |
2261 interceptor.intercept_final_response_ = true; | 2261 interceptor.intercept_final_response_ = true; |
2262 interceptor.final_headers_ = TestInterceptor::ok_headers(); | 2262 interceptor.final_headers_ = TestInterceptor::ok_headers(); |
2263 interceptor.final_data_ = TestInterceptor::ok_data(); | 2263 interceptor.final_data_ = TestInterceptor::ok_data(); |
2264 | 2264 |
2265 TestDelegate d; | 2265 TestDelegate d; |
2266 TestURLRequest req(GURL("http://test_intercept/foo"), &d); | 2266 TestURLRequest req(GURL("http://test_intercept/foo"), &d); |
2267 req.set_method("GET"); | 2267 req.set_method("GET"); |
2268 req.Start(); | 2268 req.Start(); |
2269 MessageLoop::current()->Run(); | 2269 MessageLoop::current()->Run(); |
2270 | 2270 |
2271 // Check the interceptor got called as expected | 2271 // Check the interceptor got called as expected |
2272 EXPECT_TRUE(interceptor.did_cancel_then_restart_main_); | 2272 EXPECT_TRUE(interceptor.did_cancel_then_restart_main_); |
2273 EXPECT_FALSE(interceptor.did_intercept_final_); | 2273 EXPECT_FALSE(interceptor.did_intercept_final_); |
2274 | 2274 |
2275 // Check we see a canceled request | 2275 // Check we see a canceled request |
2276 EXPECT_FALSE(req.status().is_success()); | 2276 EXPECT_FALSE(req.status().is_success()); |
2277 EXPECT_EQ(URLRequestStatus::CANCELED, req.status().status()); | 2277 EXPECT_EQ(net::URLRequestStatus::CANCELED, req.status().status()); |
2278 } | 2278 } |
2279 | 2279 |
2280 class URLRequestTestFTP : public URLRequestTest { | 2280 class URLRequestTestFTP : public URLRequestTest { |
2281 public: | 2281 public: |
2282 URLRequestTestFTP() : test_server_(net::TestServer::TYPE_FTP, FilePath()) { | 2282 URLRequestTestFTP() : test_server_(net::TestServer::TYPE_FTP, FilePath()) { |
2283 } | 2283 } |
2284 | 2284 |
2285 protected: | 2285 protected: |
2286 net::TestServer test_server_; | 2286 net::TestServer test_server_; |
2287 }; | 2287 }; |
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2635 TestURLRequest | 2635 TestURLRequest |
2636 req(test_server_.GetURL("echoheaderoverride?Accept-Charset"), &d); | 2636 req(test_server_.GetURL("echoheaderoverride?Accept-Charset"), &d); |
2637 req.set_context(new TestURLRequestContext()); | 2637 req.set_context(new TestURLRequestContext()); |
2638 net::HttpRequestHeaders headers; | 2638 net::HttpRequestHeaders headers; |
2639 headers.SetHeader(net::HttpRequestHeaders::kAcceptCharset, "koi-8r"); | 2639 headers.SetHeader(net::HttpRequestHeaders::kAcceptCharset, "koi-8r"); |
2640 req.SetExtraRequestHeaders(headers); | 2640 req.SetExtraRequestHeaders(headers); |
2641 req.Start(); | 2641 req.Start(); |
2642 MessageLoop::current()->Run(); | 2642 MessageLoop::current()->Run(); |
2643 EXPECT_EQ(std::string("koi-8r"), d.data_received()); | 2643 EXPECT_EQ(std::string("koi-8r"), d.data_received()); |
2644 } | 2644 } |
OLD | NEW |