Chromium Code Reviews| 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 #include <stddef.h> | 5 #include <stddef.h> |
| 6 #include <utility> | 6 #include <utility> |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/feature_list.h" | 10 #include "base/feature_list.h" |
| 11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
| 12 #include "base/files/file_util.h" | 12 #include "base/files/file_util.h" |
| 13 #include "base/location.h" | 13 #include "base/location.h" |
| 14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/memory/scoped_vector.h" | 15 #include "base/memory/scoped_vector.h" |
| 16 #include "base/memory/shared_memory.h" | 16 #include "base/memory/shared_memory.h" |
| 17 #include "base/pickle.h" | 17 #include "base/pickle.h" |
| 18 #include "base/run_loop.h" | 18 #include "base/run_loop.h" |
| 19 #include "base/single_thread_task_runner.h" | 19 #include "base/single_thread_task_runner.h" |
| 20 #include "base/strings/string_number_conversions.h" | 20 #include "base/strings/string_number_conversions.h" |
| 21 #include "base/strings/string_split.h" | 21 #include "base/strings/string_split.h" |
| 22 #include "base/thread_task_runner_handle.h" | 22 #include "base/thread_task_runner_handle.h" |
| 23 #include "content/browser/browser_thread_impl.h" | 23 #include "content/browser/browser_thread_impl.h" |
| 24 #include "content/browser/cert_store_impl.h" | 24 #include "content/browser/cert_store_impl.h" |
| 25 #include "content/browser/child_process_security_policy_impl.h" | 25 #include "content/browser/child_process_security_policy_impl.h" |
| 26 #include "content/browser/frame_host/navigation_request_info.h" | |
| 26 #include "content/browser/loader/cross_site_resource_handler.h" | 27 #include "content/browser/loader/cross_site_resource_handler.h" |
| 27 #include "content/browser/loader/detachable_resource_handler.h" | 28 #include "content/browser/loader/detachable_resource_handler.h" |
| 29 #include "content/browser/loader/navigation_url_loader.h" | |
| 28 #include "content/browser/loader/resource_dispatcher_host_impl.h" | 30 #include "content/browser/loader/resource_dispatcher_host_impl.h" |
| 29 #include "content/browser/loader/resource_loader.h" | 31 #include "content/browser/loader/resource_loader.h" |
| 30 #include "content/browser/loader/resource_message_filter.h" | 32 #include "content/browser/loader/resource_message_filter.h" |
| 31 #include "content/browser/loader/resource_request_info_impl.h" | 33 #include "content/browser/loader/resource_request_info_impl.h" |
| 32 #include "content/common/appcache_interfaces.h" | 34 #include "content/common/appcache_interfaces.h" |
| 33 #include "content/common/child_process_host_impl.h" | 35 #include "content/common/child_process_host_impl.h" |
| 36 #include "content/common/navigation_params.h" | |
| 34 #include "content/common/resource_messages.h" | 37 #include "content/common/resource_messages.h" |
| 35 #include "content/common/ssl_status_serialization.h" | 38 #include "content/common/ssl_status_serialization.h" |
| 36 #include "content/common/view_messages.h" | 39 #include "content/common/view_messages.h" |
| 37 #include "content/public/browser/global_request_id.h" | 40 #include "content/public/browser/global_request_id.h" |
| 38 #include "content/public/browser/render_process_host.h" | 41 #include "content/public/browser/render_process_host.h" |
| 39 #include "content/public/browser/resource_context.h" | 42 #include "content/public/browser/resource_context.h" |
| 40 #include "content/public/browser/resource_dispatcher_host_delegate.h" | 43 #include "content/public/browser/resource_dispatcher_host_delegate.h" |
| 41 #include "content/public/browser/resource_request_info.h" | 44 #include "content/public/browser/resource_request_info.h" |
| 42 #include "content/public/browser/resource_throttle.h" | 45 #include "content/public/browser/resource_throttle.h" |
| 43 #include "content/public/browser/web_contents.h" | 46 #include "content/public/browser/web_contents.h" |
| 44 #include "content/public/browser/web_contents_observer.h" | 47 #include "content/public/browser/web_contents_observer.h" |
| 45 #include "content/public/common/browser_side_navigation_policy.h" | 48 #include "content/public/common/browser_side_navigation_policy.h" |
| 46 #include "content/public/common/child_process_host.h" | 49 #include "content/public/common/child_process_host.h" |
| 47 #include "content/public/common/content_features.h" | 50 #include "content/public/common/content_features.h" |
| 48 #include "content/public/common/process_type.h" | 51 #include "content/public/common/process_type.h" |
| 49 #include "content/public/common/resource_response.h" | 52 #include "content/public/common/resource_response.h" |
| 50 #include "content/public/test/test_browser_context.h" | 53 #include "content/public/test/test_browser_context.h" |
| 51 #include "content/public/test/test_browser_thread_bundle.h" | 54 #include "content/public/test/test_browser_thread_bundle.h" |
| 52 #include "content/public/test/test_renderer_host.h" | 55 #include "content/public/test/test_renderer_host.h" |
| 53 #include "content/test/test_content_browser_client.h" | 56 #include "content/test/test_content_browser_client.h" |
| 57 #include "content/test/test_navigation_url_loader_delegate.h" | |
| 54 #include "net/base/elements_upload_data_stream.h" | 58 #include "net/base/elements_upload_data_stream.h" |
| 59 #include "net/base/load_flags.h" | |
| 55 #include "net/base/net_errors.h" | 60 #include "net/base/net_errors.h" |
| 56 #include "net/base/request_priority.h" | 61 #include "net/base/request_priority.h" |
| 57 #include "net/base/test_data_directory.h" | 62 #include "net/base/test_data_directory.h" |
| 58 #include "net/base/upload_bytes_element_reader.h" | 63 #include "net/base/upload_bytes_element_reader.h" |
| 59 #include "net/http/http_util.h" | 64 #include "net/http/http_util.h" |
| 60 #include "net/test/cert_test_util.h" | 65 #include "net/test/cert_test_util.h" |
| 61 #include "net/test/url_request/url_request_failed_job.h" | 66 #include "net/test/url_request/url_request_failed_job.h" |
| 62 #include "net/url_request/url_request.h" | 67 #include "net/url_request/url_request.h" |
| 63 #include "net/url_request/url_request_context.h" | 68 #include "net/url_request/url_request_context.h" |
| 64 #include "net/url_request/url_request_job.h" | 69 #include "net/url_request/url_request_job.h" |
| (...skipping 794 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 859 } | 864 } |
| 860 | 865 |
| 861 void set_default_cert_id(int default_cert_id) { | 866 void set_default_cert_id(int default_cert_id) { |
| 862 default_cert_id_ = default_cert_id; | 867 default_cert_id_ = default_cert_id; |
| 863 } | 868 } |
| 864 | 869 |
| 865 private: | 870 private: |
| 866 int default_cert_id_; | 871 int default_cert_id_; |
| 867 }; | 872 }; |
| 868 | 873 |
| 874 void CheckRequestCompleteErrorCode(const IPC::Message& message, | |
| 875 int expected_error_code) { | |
| 876 // Verify the expected error code was received. | |
| 877 int request_id; | |
| 878 int error_code; | |
| 879 | |
| 880 ASSERT_EQ(ResourceMsg_RequestComplete::ID, message.type()); | |
| 881 | |
| 882 base::PickleIterator iter(message); | |
| 883 ASSERT_TRUE(IPC::ReadParam(&message, &iter, &request_id)); | |
| 884 ASSERT_TRUE(IPC::ReadParam(&message, &iter, &error_code)); | |
| 885 ASSERT_EQ(expected_error_code, error_code); | |
| 886 } | |
| 887 | |
| 869 class ResourceDispatcherHostTest : public testing::TestWithParam<TestConfig>, | 888 class ResourceDispatcherHostTest : public testing::TestWithParam<TestConfig>, |
| 870 public IPC::Sender { | 889 public IPC::Sender { |
| 871 public: | 890 public: |
| 872 typedef ResourceDispatcherHostImpl::LoadInfo LoadInfo; | 891 typedef ResourceDispatcherHostImpl::LoadInfo LoadInfo; |
| 873 typedef ResourceDispatcherHostImpl::LoadInfoMap LoadInfoMap; | 892 typedef ResourceDispatcherHostImpl::LoadInfoMap LoadInfoMap; |
| 874 | 893 |
| 875 ResourceDispatcherHostTest() | 894 ResourceDispatcherHostTest() |
| 876 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), | 895 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), |
| 877 use_test_ssl_certificate_(false), | 896 use_test_ssl_certificate_(false), |
| 878 old_factory_(NULL), | 897 old_factory_(NULL), |
| 879 send_data_received_acks_(false) { | 898 send_data_received_acks_(false), |
| 899 auto_advance_(false) { | |
| 880 browser_context_.reset(new TestBrowserContext()); | 900 browser_context_.reset(new TestBrowserContext()); |
| 881 BrowserContext::EnsureResourceContextInitialized(browser_context_.get()); | 901 BrowserContext::EnsureResourceContextInitialized(browser_context_.get()); |
| 882 base::RunLoop().RunUntilIdle(); | 902 base::RunLoop().RunUntilIdle(); |
| 883 filter_ = MakeForwardingFilter(); | 903 filter_ = MakeForwardingFilter(); |
| 884 // TODO(cbentzel): Better way to get URLRequestContext? | 904 // TODO(cbentzel): Better way to get URLRequestContext? |
| 885 net::URLRequestContext* request_context = | 905 net::URLRequestContext* request_context = |
| 886 browser_context_->GetResourceContext()->GetRequestContext(); | 906 browser_context_->GetResourceContext()->GetRequestContext(); |
| 887 job_factory_.reset(new TestURLRequestJobFactory(this)); | 907 job_factory_.reset(new TestURLRequestJobFactory(this)); |
| 888 request_context->set_job_factory(job_factory_.get()); | 908 request_context->set_job_factory(job_factory_.get()); |
| 889 request_context->set_network_delegate(&network_delegate_); | 909 request_context->set_network_delegate(&network_delegate_); |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1099 DCHECK(!wait_for_request_complete_loop_); | 1119 DCHECK(!wait_for_request_complete_loop_); |
| 1100 wait_for_request_complete_loop_.reset(new base::RunLoop); | 1120 wait_for_request_complete_loop_.reset(new base::RunLoop); |
| 1101 wait_for_request_complete_loop_->Run(); | 1121 wait_for_request_complete_loop_->Run(); |
| 1102 wait_for_request_complete_loop_.reset(); | 1122 wait_for_request_complete_loop_.reset(); |
| 1103 } | 1123 } |
| 1104 | 1124 |
| 1105 void DeleteRenderFrame(const GlobalFrameRoutingId& global_routing_id) { | 1125 void DeleteRenderFrame(const GlobalFrameRoutingId& global_routing_id) { |
| 1106 host_.OnRenderFrameDeleted(global_routing_id); | 1126 host_.OnRenderFrameDeleted(global_routing_id); |
| 1107 } | 1127 } |
| 1108 | 1128 |
| 1129 // Creates and drive a main resource request until completion. Then asserts | |
|
mmenke
2016/04/08 15:19:12
nit: "Create and drive" or "creates and drives".
clamy
2016/04/08 16:03:17
Done.
| |
| 1130 // that the expected_error_code has been emitted for the request. | |
| 1131 void CompleteFailingMainResourceRequest(const GURL& url, | |
| 1132 int expected_error_code) { | |
| 1133 if (IsBrowserSideNavigationEnabled()) { | |
| 1134 auto_advance_ = true; | |
| 1135 | |
| 1136 // Make a navigation request. | |
| 1137 TestNavigationURLLoaderDelegate delegate; | |
| 1138 BeginNavigationParams begin_params(std::string(), net::LOAD_NORMAL, false, | |
| 1139 false, REQUEST_CONTEXT_TYPE_LOCATION); | |
|
mmenke
2016/04/08 15:19:12
I assume "REQUEST_CONTEXT_TYPE_LOCATION" is the ge
clamy
2016/04/08 16:03:17
I think so. It's the clicking on a link case.
| |
| 1140 CommonNavigationParams common_params; | |
| 1141 common_params.url = url; | |
| 1142 scoped_ptr<NavigationRequestInfo> request_info(new NavigationRequestInfo( | |
| 1143 common_params, begin_params, url, url::Origin(url), true, false, -1, | |
| 1144 scoped_refptr<ResourceRequestBody>())); | |
| 1145 scoped_ptr<NavigationURLLoader> test_loader = NavigationURLLoader::Create( | |
| 1146 browser_context_.get(), std::move(request_info), nullptr, &delegate); | |
| 1147 | |
| 1148 // The navigation should fail with the error code of ERR_INVALID_RESPONSE. | |
|
carlosk
2016/04/05 15:28:46
As the expected error code is an input parameter t
clamy
2016/04/08 16:03:17
Done. Indeed.
| |
| 1149 delegate.WaitForRequestFailed(); | |
| 1150 ASSERT_EQ(expected_error_code, delegate.net_error()); | |
| 1151 return; | |
| 1152 } | |
| 1153 | |
| 1154 MakeTestRequestWithResourceType(filter_.get(), 0, 1, url, | |
| 1155 RESOURCE_TYPE_MAIN_FRAME); | |
| 1156 | |
| 1157 // Flush all pending requests. | |
| 1158 while (net::URLRequestTestJob::ProcessOnePendingMessage()) { | |
| 1159 } | |
| 1160 base::MessageLoop::current()->RunUntilIdle(); | |
| 1161 | |
| 1162 // Sorts out all the messages we saw by request. | |
| 1163 ResourceIPCAccumulator::ClassifiedMessages msgs; | |
| 1164 accum_.GetClassifiedMessages(&msgs); | |
| 1165 | |
| 1166 // We should have gotten one RequestComplete message. | |
| 1167 ASSERT_EQ(1U, msgs.size()); | |
| 1168 ASSERT_EQ(1U, msgs[0].size()); | |
| 1169 EXPECT_EQ(ResourceMsg_RequestComplete::ID, msgs[0][0].type()); | |
| 1170 | |
| 1171 // The RequestComplete message should have had the expected error code. | |
| 1172 CheckRequestCompleteErrorCode(msgs[0][0], expected_error_code); | |
| 1173 } | |
| 1174 | |
| 1109 scoped_ptr<LoadInfoTestRequestInfo> loader_test_request_info_; | 1175 scoped_ptr<LoadInfoTestRequestInfo> loader_test_request_info_; |
| 1110 scoped_ptr<base::RunLoop> wait_for_request_create_loop_; | 1176 scoped_ptr<base::RunLoop> wait_for_request_create_loop_; |
| 1111 | 1177 |
| 1112 content::TestBrowserThreadBundle thread_bundle_; | 1178 content::TestBrowserThreadBundle thread_bundle_; |
| 1113 scoped_ptr<TestBrowserContext> browser_context_; | 1179 scoped_ptr<TestBrowserContext> browser_context_; |
| 1114 scoped_ptr<TestURLRequestJobFactory> job_factory_; | 1180 scoped_ptr<TestURLRequestJobFactory> job_factory_; |
| 1115 scoped_ptr<WebContents> web_contents_; | 1181 scoped_ptr<WebContents> web_contents_; |
| 1116 scoped_ptr<TestWebContentsObserver> web_contents_observer_; | 1182 scoped_ptr<TestWebContentsObserver> web_contents_observer_; |
| 1117 scoped_refptr<ForwardingFilter> filter_; | 1183 scoped_refptr<ForwardingFilter> filter_; |
| 1118 scoped_refptr<TestFilterSpecifyingChild> web_contents_filter_; | 1184 scoped_refptr<TestFilterSpecifyingChild> web_contents_filter_; |
| 1119 net::TestNetworkDelegate network_delegate_; | 1185 net::TestNetworkDelegate network_delegate_; |
| 1120 ResourceDispatcherHostImpl host_; | 1186 ResourceDispatcherHostImpl host_; |
| 1121 ResourceIPCAccumulator accum_; | 1187 ResourceIPCAccumulator accum_; |
| 1122 std::string response_headers_; | 1188 std::string response_headers_; |
| 1123 std::string response_data_; | 1189 std::string response_data_; |
| 1124 bool use_test_ssl_certificate_; | 1190 bool use_test_ssl_certificate_; |
| 1125 std::string scheme_; | 1191 std::string scheme_; |
| 1126 net::URLRequest::ProtocolFactory* old_factory_; | 1192 net::URLRequest::ProtocolFactory* old_factory_; |
| 1127 bool send_data_received_acks_; | 1193 bool send_data_received_acks_; |
| 1128 std::set<int> child_ids_; | 1194 std::set<int> child_ids_; |
| 1129 scoped_ptr<base::RunLoop> wait_for_request_complete_loop_; | 1195 scoped_ptr<base::RunLoop> wait_for_request_complete_loop_; |
| 1130 RenderViewHostTestEnabler render_view_host_test_enabler_; | 1196 RenderViewHostTestEnabler render_view_host_test_enabler_; |
| 1131 MockCertStore mock_cert_store_; | 1197 MockCertStore mock_cert_store_; |
| 1198 bool auto_advance_; | |
| 1132 }; | 1199 }; |
| 1133 | 1200 |
| 1134 void ResourceDispatcherHostTest::MakeTestRequest(int render_view_id, | 1201 void ResourceDispatcherHostTest::MakeTestRequest(int render_view_id, |
| 1135 int request_id, | 1202 int request_id, |
| 1136 const GURL& url) { | 1203 const GURL& url) { |
| 1137 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id, | 1204 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id, |
| 1138 url, RESOURCE_TYPE_SUB_RESOURCE); | 1205 url, RESOURCE_TYPE_SUB_RESOURCE); |
| 1139 } | 1206 } |
| 1140 | 1207 |
| 1141 void ResourceDispatcherHostTest::MakeTestRequestWithRenderFrame( | 1208 void ResourceDispatcherHostTest::MakeTestRequestWithRenderFrame( |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1231 void ResourceDispatcherHostTest::CompleteStartRequest( | 1298 void ResourceDispatcherHostTest::CompleteStartRequest( |
| 1232 ResourceMessageFilter* filter, | 1299 ResourceMessageFilter* filter, |
| 1233 int request_id) { | 1300 int request_id) { |
| 1234 GlobalRequestID gid(filter->child_id(), request_id); | 1301 GlobalRequestID gid(filter->child_id(), request_id); |
| 1235 net::URLRequest* req = host_.GetURLRequest(gid); | 1302 net::URLRequest* req = host_.GetURLRequest(gid); |
| 1236 EXPECT_TRUE(req); | 1303 EXPECT_TRUE(req); |
| 1237 if (req) | 1304 if (req) |
| 1238 URLRequestTestDelayedStartJob::CompleteStart(req); | 1305 URLRequestTestDelayedStartJob::CompleteStart(req); |
| 1239 } | 1306 } |
| 1240 | 1307 |
| 1241 void CheckRequestCompleteErrorCode(const IPC::Message& message, | |
| 1242 int expected_error_code) { | |
| 1243 // Verify the expected error code was received. | |
| 1244 int request_id; | |
| 1245 int error_code; | |
| 1246 | |
| 1247 ASSERT_EQ(ResourceMsg_RequestComplete::ID, message.type()); | |
| 1248 | |
| 1249 base::PickleIterator iter(message); | |
| 1250 ASSERT_TRUE(IPC::ReadParam(&message, &iter, &request_id)); | |
| 1251 ASSERT_TRUE(IPC::ReadParam(&message, &iter, &error_code)); | |
| 1252 ASSERT_EQ(expected_error_code, error_code); | |
| 1253 } | |
| 1254 | |
| 1255 testing::AssertionResult ExtractInlinedChunkData( | 1308 testing::AssertionResult ExtractInlinedChunkData( |
| 1256 const IPC::Message& message, | 1309 const IPC::Message& message, |
| 1257 std::string* leading_chunk_data) { | 1310 std::string* leading_chunk_data) { |
| 1258 base::PickleIterator iter(message); | 1311 base::PickleIterator iter(message); |
| 1259 int request_id; | 1312 int request_id; |
| 1260 if (!IPC::ReadParam(&message, &iter, &request_id)) | 1313 if (!IPC::ReadParam(&message, &iter, &request_id)) |
| 1261 return testing::AssertionFailure() << "Could not read request_id"; | 1314 return testing::AssertionFailure() << "Could not read request_id"; |
| 1262 | 1315 |
| 1263 std::vector<char> data; | 1316 std::vector<char> data; |
| 1264 if (!IPC::ReadParam(&message, &iter, &data)) | 1317 if (!IPC::ReadParam(&message, &iter, &data)) |
| (...skipping 1195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2460 // Tests for crbug.com/31266 (Non-2xx + application/octet-stream). | 2513 // Tests for crbug.com/31266 (Non-2xx + application/octet-stream). |
| 2461 TEST_P(ResourceDispatcherHostTest, ForbiddenDownload) { | 2514 TEST_P(ResourceDispatcherHostTest, ForbiddenDownload) { |
| 2462 std::string raw_headers("HTTP/1.1 403 Forbidden\n" | 2515 std::string raw_headers("HTTP/1.1 403 Forbidden\n" |
| 2463 "Content-disposition: attachment; filename=blah\n" | 2516 "Content-disposition: attachment; filename=blah\n" |
| 2464 "Content-type: application/octet-stream\n\n"); | 2517 "Content-type: application/octet-stream\n\n"); |
| 2465 std::string response_data("<html><title>Test One</title></html>"); | 2518 std::string response_data("<html><title>Test One</title></html>"); |
| 2466 SetResponse(raw_headers, response_data); | 2519 SetResponse(raw_headers, response_data); |
| 2467 | 2520 |
| 2468 HandleScheme("http"); | 2521 HandleScheme("http"); |
| 2469 | 2522 |
| 2470 // Only MAIN_FRAMEs can trigger a download. | 2523 const int expected_error_code = net::ERR_INVALID_RESPONSE; |
| 2471 MakeTestRequestWithResourceType(filter_.get(), 0, 1, GURL("http:bla"), | 2524 const GURL forbidden_download_url = GURL("http:bla"); |
|
mmenke
2016/04/08 15:19:12
consts are pretty rare, unless you use kConstNamin
clamy
2016/04/08 16:03:17
Done.
| |
| 2472 RESOURCE_TYPE_MAIN_FRAME); | |
| 2473 | 2525 |
| 2474 // Flush all pending requests. | 2526 CompleteFailingMainResourceRequest(forbidden_download_url, |
| 2475 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} | 2527 expected_error_code); |
| 2476 base::MessageLoop::current()->RunUntilIdle(); | |
| 2477 | |
| 2478 // Sorts out all the messages we saw by request. | |
| 2479 ResourceIPCAccumulator::ClassifiedMessages msgs; | |
| 2480 accum_.GetClassifiedMessages(&msgs); | |
| 2481 | |
| 2482 // We should have gotten one RequestComplete message. | |
| 2483 ASSERT_EQ(1U, msgs.size()); | |
| 2484 ASSERT_EQ(1U, msgs[0].size()); | |
| 2485 EXPECT_EQ(ResourceMsg_RequestComplete::ID, msgs[0][0].type()); | |
| 2486 | |
| 2487 // The RequestComplete message should have had the error code of | |
| 2488 // ERR_INVALID_RESPONSE. | |
| 2489 CheckRequestCompleteErrorCode(msgs[0][0], net::ERR_INVALID_RESPONSE); | |
| 2490 } | 2528 } |
| 2491 | 2529 |
| 2492 // Test for http://crbug.com/76202 . We don't want to destroy a | 2530 // Test for http://crbug.com/76202 . We don't want to destroy a |
| 2493 // download request prematurely when processing a cancellation from | 2531 // download request prematurely when processing a cancellation from |
| 2494 // the renderer. | 2532 // the renderer. |
| 2495 TEST_P(ResourceDispatcherHostTest, IgnoreCancelForDownloads) { | 2533 TEST_P(ResourceDispatcherHostTest, IgnoreCancelForDownloads) { |
| 2534 // PlzNavigate: A request that ends up being a download is a main resource | |
| 2535 // request. Hence, it has been initiated by the browser and is not associated | |
| 2536 // with a renderer. Therefore, it cannot be canceled by a renderer IPC. | |
| 2537 if (IsBrowserSideNavigationEnabled()) | |
|
carlosk
2016/04/05 15:28:46
nit: use the SUCCEED() << "Message" operator (whic
clamy
2016/04/08 16:03:17
Done.
| |
| 2538 return; | |
| 2539 | |
| 2496 EXPECT_EQ(0, host_.pending_requests()); | 2540 EXPECT_EQ(0, host_.pending_requests()); |
| 2497 | 2541 |
| 2498 int render_view_id = 0; | 2542 int render_view_id = 0; |
| 2499 int request_id = 1; | 2543 int request_id = 1; |
| 2500 | 2544 |
| 2501 std::string raw_headers("HTTP\n" | 2545 std::string raw_headers("HTTP\n" |
| 2502 "Content-disposition: attachment; filename=foo\n\n"); | 2546 "Content-disposition: attachment; filename=foo\n\n"); |
| 2503 std::string response_data("01234567890123456789\x01foobar"); | 2547 std::string response_data("01234567890123456789\x01foobar"); |
| 2504 | 2548 |
| 2505 // Get past sniffing metrics in the MimeTypeResourceHandler. Note that | 2549 // Get past sniffing metrics in the MimeTypeResourceHandler. Note that |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2541 std::string raw_headers("HTTP\n" | 2585 std::string raw_headers("HTTP\n" |
| 2542 "Content-disposition: attachment; filename=foo\n\n"); | 2586 "Content-disposition: attachment; filename=foo\n\n"); |
| 2543 std::string response_data("01234567890123456789\x01foobar"); | 2587 std::string response_data("01234567890123456789\x01foobar"); |
| 2544 // Get past sniffing metrics. | 2588 // Get past sniffing metrics. |
| 2545 response_data.resize(1025, ' '); | 2589 response_data.resize(1025, ' '); |
| 2546 | 2590 |
| 2547 SetResponse(raw_headers, response_data); | 2591 SetResponse(raw_headers, response_data); |
| 2548 job_factory_->SetDelayedCompleteJobGeneration(true); | 2592 job_factory_->SetDelayedCompleteJobGeneration(true); |
| 2549 HandleScheme("http"); | 2593 HandleScheme("http"); |
| 2550 | 2594 |
| 2551 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id, | 2595 const GURL download_url = GURL("http://example.com/blah"); |
| 2552 GURL("http://example.com/blah"), | |
| 2553 RESOURCE_TYPE_MAIN_FRAME); | |
| 2554 // Return some data so that the request is identified as a download | |
| 2555 // and the proper resource handlers are created. | |
| 2556 EXPECT_TRUE(net::URLRequestTestJob::ProcessOnePendingMessage()); | |
| 2557 | 2596 |
| 2558 // And now simulate a cancellation coming from the renderer. | 2597 if (IsBrowserSideNavigationEnabled()) { |
| 2559 ResourceHostMsg_CancelRequest msg(request_id); | 2598 // Create a NavigationRequest. |
| 2560 host_.OnMessageReceived(msg, filter_.get()); | 2599 TestNavigationURLLoaderDelegate delegate; |
| 2600 BeginNavigationParams begin_params(std::string(), net::LOAD_NORMAL, false, | |
| 2601 false, REQUEST_CONTEXT_TYPE_LOCATION); | |
| 2602 CommonNavigationParams common_params; | |
| 2603 common_params.url = download_url; | |
| 2604 scoped_ptr<NavigationRequestInfo> request_info(new NavigationRequestInfo( | |
| 2605 common_params, begin_params, download_url, url::Origin(download_url), | |
| 2606 true, false, -1, scoped_refptr<ResourceRequestBody>())); | |
| 2607 scoped_ptr<NavigationURLLoader> loader = NavigationURLLoader::Create( | |
| 2608 browser_context_.get(), std::move(request_info), nullptr, &delegate); | |
| 2561 | 2609 |
| 2562 // Since the request had already started processing as a download, | 2610 // Wait until a response has been received and proceed with the response. |
| 2563 // the cancellation above should have been ignored and the request | 2611 KickOffRequest(); |
| 2564 // should still be alive. | |
| 2565 EXPECT_EQ(1, host_.pending_requests()); | |
| 2566 | 2612 |
| 2567 // Cancelling by other methods shouldn't work either. | 2613 // Return some data so that the request is identified as a download |
| 2568 host_.CancelRequestsForProcess(render_view_id); | 2614 // and the proper resource handlers are created. |
| 2569 EXPECT_EQ(1, host_.pending_requests()); | 2615 EXPECT_TRUE(net::URLRequestTestJob::ProcessOnePendingMessage()); |
| 2616 base::MessageLoop::current()->RunUntilIdle(); | |
| 2570 | 2617 |
| 2571 // Cancelling by context should work. | 2618 EXPECT_EQ(delegate.net_error(), net::ERR_ABORTED); |
|
mmenke
2016/04/08 15:19:12
Think this requires a comment. I assume this is b
clamy
2016/04/08 16:03:17
Done.
| |
| 2572 host_.CancelRequestsForContext(filter_->resource_context()); | 2619 EXPECT_EQ(1, host_.pending_requests()); |
| 2573 EXPECT_EQ(0, host_.pending_requests()); | 2620 |
| 2621 // In PlzNavigate, the renderer cannot cancel the request directly. | |
| 2622 // However, cancelling by context should work. | |
| 2623 host_.CancelRequestsForContext(browser_context_->GetResourceContext()); | |
| 2624 EXPECT_EQ(0, host_.pending_requests()); | |
| 2625 | |
| 2626 base::MessageLoop::current()->RunUntilIdle(); | |
| 2627 } else { | |
| 2628 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id, | |
| 2629 download_url, RESOURCE_TYPE_MAIN_FRAME); | |
| 2630 | |
| 2631 // Return some data so that the request is identified as a download | |
| 2632 // and the proper resource handlers are created. | |
| 2633 EXPECT_TRUE(net::URLRequestTestJob::ProcessOnePendingMessage()); | |
| 2634 | |
| 2635 // And now simulate a cancellation coming from the renderer. | |
| 2636 ResourceHostMsg_CancelRequest msg(request_id); | |
| 2637 host_.OnMessageReceived(msg, filter_.get()); | |
| 2638 | |
| 2639 // Since the request had already started processing as a download, | |
| 2640 // the cancellation above should have been ignored and the request | |
| 2641 // should still be alive. | |
| 2642 EXPECT_EQ(1, host_.pending_requests()); | |
| 2643 | |
| 2644 // Cancelling by other methods shouldn't work either. | |
| 2645 host_.CancelRequestsForProcess(render_view_id); | |
| 2646 EXPECT_EQ(1, host_.pending_requests()); | |
| 2647 | |
| 2648 // Cancelling by context should work. | |
| 2649 host_.CancelRequestsForContext(filter_->resource_context()); | |
| 2650 EXPECT_EQ(0, host_.pending_requests()); | |
| 2651 } | |
| 2574 } | 2652 } |
| 2575 | 2653 |
| 2576 TEST_P(ResourceDispatcherHostTest, CancelRequestsForContextDetached) { | 2654 TEST_P(ResourceDispatcherHostTest, CancelRequestsForContextDetached) { |
| 2577 EXPECT_EQ(0, host_.pending_requests()); | 2655 EXPECT_EQ(0, host_.pending_requests()); |
| 2578 | 2656 |
| 2579 int render_view_id = 0; | 2657 int render_view_id = 0; |
| 2580 int request_id = 1; | 2658 int request_id = 1; |
| 2581 | 2659 |
| 2582 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id, | 2660 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id, |
| 2583 net::URLRequestTestJob::test_url_4(), | 2661 net::URLRequestTestJob::test_url_4(), |
| (...skipping 572 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3156 ASSERT_EQ(2U, msgs.size()); | 3234 ASSERT_EQ(2U, msgs.size()); |
| 3157 EXPECT_EQ(ResourceMsg_ReceivedRedirect::ID, msgs[0][0].type()); | 3235 EXPECT_EQ(ResourceMsg_ReceivedRedirect::ID, msgs[0][0].type()); |
| 3158 CheckSuccessfulRequest(msgs[1], kResponseBody); | 3236 CheckSuccessfulRequest(msgs[1], kResponseBody); |
| 3159 } | 3237 } |
| 3160 | 3238 |
| 3161 TEST_P(ResourceDispatcherHostTest, UnknownURLScheme) { | 3239 TEST_P(ResourceDispatcherHostTest, UnknownURLScheme) { |
| 3162 EXPECT_EQ(0, host_.pending_requests()); | 3240 EXPECT_EQ(0, host_.pending_requests()); |
| 3163 | 3241 |
| 3164 HandleScheme("http"); | 3242 HandleScheme("http"); |
| 3165 | 3243 |
| 3166 MakeTestRequestWithResourceType(filter_.get(), 0, 1, GURL("foo://bar"), | 3244 const GURL invalid_sheme_url = GURL("foo://bar"); |
| 3167 RESOURCE_TYPE_MAIN_FRAME); | 3245 const int expected_error_code = net::ERR_UNKNOWN_URL_SCHEME; |
| 3168 | 3246 |
| 3169 // Flush all pending requests. | 3247 CompleteFailingMainResourceRequest(invalid_sheme_url, expected_error_code); |
| 3170 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} | |
| 3171 | |
| 3172 // Sort all the messages we saw by request. | |
| 3173 ResourceIPCAccumulator::ClassifiedMessages msgs; | |
| 3174 accum_.GetClassifiedMessages(&msgs); | |
| 3175 | |
| 3176 // We should have gotten one RequestComplete message. | |
| 3177 ASSERT_EQ(1U, msgs[0].size()); | |
| 3178 EXPECT_EQ(ResourceMsg_RequestComplete::ID, msgs[0][0].type()); | |
| 3179 | |
| 3180 // The RequestComplete message should have the error code of | |
| 3181 // ERR_UNKNOWN_URL_SCHEME. | |
| 3182 CheckRequestCompleteErrorCode(msgs[0][0], net::ERR_UNKNOWN_URL_SCHEME); | |
| 3183 } | 3248 } |
| 3184 | 3249 |
| 3185 TEST_P(ResourceDispatcherHostTest, DataReceivedACKs) { | 3250 TEST_P(ResourceDispatcherHostTest, DataReceivedACKs) { |
| 3186 EXPECT_EQ(0, host_.pending_requests()); | 3251 EXPECT_EQ(0, host_.pending_requests()); |
| 3187 | 3252 |
| 3188 SendDataReceivedACKs(true); | 3253 SendDataReceivedACKs(true); |
| 3189 | 3254 |
| 3190 HandleScheme("big-job"); | 3255 HandleScheme("big-job"); |
| 3191 MakeTestRequest(0, 1, GURL("big-job:0123456789,1000000")); | 3256 MakeTestRequest(0, 1, GURL("big-job:0123456789,1000000")); |
| 3192 | 3257 |
| (...skipping 590 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3783 if (delay_start_) { | 3848 if (delay_start_) { |
| 3784 return new URLRequestTestDelayedStartJob(request, network_delegate); | 3849 return new URLRequestTestDelayedStartJob(request, network_delegate); |
| 3785 } else if (delay_complete_) { | 3850 } else if (delay_complete_) { |
| 3786 return new URLRequestTestDelayedCompletionJob(request, | 3851 return new URLRequestTestDelayedCompletionJob(request, |
| 3787 network_delegate); | 3852 network_delegate); |
| 3788 } else if (network_start_notification_) { | 3853 } else if (network_start_notification_) { |
| 3789 return new URLRequestTestDelayedNetworkJob(request, network_delegate); | 3854 return new URLRequestTestDelayedNetworkJob(request, network_delegate); |
| 3790 } else if (scheme == "big-job") { | 3855 } else if (scheme == "big-job") { |
| 3791 return new URLRequestBigJob(request, network_delegate); | 3856 return new URLRequestBigJob(request, network_delegate); |
| 3792 } else { | 3857 } else { |
| 3793 return new net::URLRequestTestJob(request, network_delegate); | 3858 return new net::URLRequestTestJob(request, network_delegate, |
| 3859 test_fixture_->auto_advance_); | |
| 3794 } | 3860 } |
| 3795 } else { | 3861 } else { |
| 3796 if (delay_start_) { | 3862 if (delay_start_) { |
| 3797 return new URLRequestTestDelayedStartJob( | 3863 return new URLRequestTestDelayedStartJob( |
| 3798 request, network_delegate, | 3864 request, network_delegate, |
| 3799 test_fixture_->response_headers_, test_fixture_->response_data_, | 3865 test_fixture_->response_headers_, test_fixture_->response_data_, |
| 3800 false); | 3866 false); |
| 3801 } else if (delay_complete_) { | 3867 } else if (delay_complete_) { |
| 3802 return new URLRequestTestDelayedCompletionJob( | 3868 return new URLRequestTestDelayedCompletionJob( |
| 3803 request, network_delegate, | 3869 request, network_delegate, |
| 3804 test_fixture_->response_headers_, test_fixture_->response_data_, | 3870 test_fixture_->response_headers_, test_fixture_->response_data_, |
| 3805 false); | 3871 false); |
| 3806 } else if (test_fixture_->use_test_ssl_certificate_) { | 3872 } else if (test_fixture_->use_test_ssl_certificate_) { |
| 3807 return new TestHTTPSURLRequestJob(request, network_delegate, | 3873 return new TestHTTPSURLRequestJob(request, network_delegate, |
| 3808 test_fixture_->response_headers_, | 3874 test_fixture_->response_headers_, |
| 3809 test_fixture_->response_data_, false); | 3875 test_fixture_->response_data_, false); |
| 3810 } else { | 3876 } else { |
| 3811 return new net::URLRequestTestJob( | 3877 return new net::URLRequestTestJob( |
| 3812 request, network_delegate, | 3878 request, network_delegate, test_fixture_->response_headers_, |
| 3813 test_fixture_->response_headers_, test_fixture_->response_data_, | 3879 test_fixture_->response_data_, test_fixture_->auto_advance_); |
| 3814 false); | |
| 3815 } | 3880 } |
| 3816 } | 3881 } |
| 3817 } | 3882 } |
| 3818 | 3883 |
| 3819 net::URLRequestJob* TestURLRequestJobFactory::MaybeInterceptRedirect( | 3884 net::URLRequestJob* TestURLRequestJobFactory::MaybeInterceptRedirect( |
| 3820 net::URLRequest* request, | 3885 net::URLRequest* request, |
| 3821 net::NetworkDelegate* network_delegate, | 3886 net::NetworkDelegate* network_delegate, |
| 3822 const GURL& location) const { | 3887 const GURL& location) const { |
| 3823 return nullptr; | 3888 return nullptr; |
| 3824 } | 3889 } |
| 3825 | 3890 |
| 3826 net::URLRequestJob* TestURLRequestJobFactory::MaybeInterceptResponse( | 3891 net::URLRequestJob* TestURLRequestJobFactory::MaybeInterceptResponse( |
| 3827 net::URLRequest* request, | 3892 net::URLRequest* request, |
| 3828 net::NetworkDelegate* network_delegate) const { | 3893 net::NetworkDelegate* network_delegate) const { |
| 3829 return nullptr; | 3894 return nullptr; |
| 3830 } | 3895 } |
| 3831 | 3896 |
| 3832 INSTANTIATE_TEST_CASE_P( | 3897 INSTANTIATE_TEST_CASE_P( |
| 3833 ResourceDispatcherHostTests, | 3898 ResourceDispatcherHostTests, |
| 3834 ResourceDispatcherHostTest, | 3899 ResourceDispatcherHostTest, |
| 3835 testing::Values(TestConfig::kDefault, | 3900 testing::Values(TestConfig::kDefault, |
| 3836 TestConfig::kOptimizeIPCForSmallResourceEnabled)); | 3901 TestConfig::kOptimizeIPCForSmallResourceEnabled)); |
| 3837 | 3902 |
| 3838 } // namespace content | 3903 } // namespace content |
| OLD | NEW |