Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(43)

Side by Side Diff: content/browser/loader/resource_dispatcher_host_unittest.cc

Issue 1863573003: PlzNavigate: make all ResourceDispatcherHostTests pass (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed mmenke's comments Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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 drives a main resource request until completion. Then asserts
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);
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 expected error code.
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
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
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 int expected_error_code = net::ERR_INVALID_RESPONSE;
2471 MakeTestRequestWithResourceType(filter_.get(), 0, 1, GURL("http:bla"), 2524 GURL forbidden_download_url = GURL("http:bla");
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()) {
2538 SUCCEED() << "Not applicable with --enable-browser-side-navigation.";
2539 return;
2540 }
2541
2496 EXPECT_EQ(0, host_.pending_requests()); 2542 EXPECT_EQ(0, host_.pending_requests());
2497 2543
2498 int render_view_id = 0; 2544 int render_view_id = 0;
2499 int request_id = 1; 2545 int request_id = 1;
2500 2546
2501 std::string raw_headers("HTTP\n" 2547 std::string raw_headers("HTTP\n"
2502 "Content-disposition: attachment; filename=foo\n\n"); 2548 "Content-disposition: attachment; filename=foo\n\n");
2503 std::string response_data("01234567890123456789\x01foobar"); 2549 std::string response_data("01234567890123456789\x01foobar");
2504 2550
2505 // Get past sniffing metrics in the MimeTypeResourceHandler. Note that 2551 // Get past sniffing metrics in the MimeTypeResourceHandler. Note that
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
2541 std::string raw_headers("HTTP\n" 2587 std::string raw_headers("HTTP\n"
2542 "Content-disposition: attachment; filename=foo\n\n"); 2588 "Content-disposition: attachment; filename=foo\n\n");
2543 std::string response_data("01234567890123456789\x01foobar"); 2589 std::string response_data("01234567890123456789\x01foobar");
2544 // Get past sniffing metrics. 2590 // Get past sniffing metrics.
2545 response_data.resize(1025, ' '); 2591 response_data.resize(1025, ' ');
2546 2592
2547 SetResponse(raw_headers, response_data); 2593 SetResponse(raw_headers, response_data);
2548 job_factory_->SetDelayedCompleteJobGeneration(true); 2594 job_factory_->SetDelayedCompleteJobGeneration(true);
2549 HandleScheme("http"); 2595 HandleScheme("http");
2550 2596
2551 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id, 2597 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 2598
2558 // And now simulate a cancellation coming from the renderer. 2599 if (IsBrowserSideNavigationEnabled()) {
2559 ResourceHostMsg_CancelRequest msg(request_id); 2600 // Create a NavigationRequest.
2560 host_.OnMessageReceived(msg, filter_.get()); 2601 TestNavigationURLLoaderDelegate delegate;
2602 BeginNavigationParams begin_params(std::string(), net::LOAD_NORMAL, false,
2603 false, REQUEST_CONTEXT_TYPE_LOCATION);
2604 CommonNavigationParams common_params;
2605 common_params.url = download_url;
2606 scoped_ptr<NavigationRequestInfo> request_info(new NavigationRequestInfo(
2607 common_params, begin_params, download_url, url::Origin(download_url),
2608 true, false, -1, scoped_refptr<ResourceRequestBody>()));
2609 scoped_ptr<NavigationURLLoader> loader = NavigationURLLoader::Create(
2610 browser_context_.get(), std::move(request_info), nullptr, &delegate);
2561 2611
2562 // Since the request had already started processing as a download, 2612 // Wait until a response has been received and proceed with the response.
2563 // the cancellation above should have been ignored and the request 2613 KickOffRequest();
2564 // should still be alive.
2565 EXPECT_EQ(1, host_.pending_requests());
2566 2614
2567 // Cancelling by other methods shouldn't work either. 2615 // Return some data so that the request is identified as a download
2568 host_.CancelRequestsForProcess(render_view_id); 2616 // and the proper resource handlers are created.
2569 EXPECT_EQ(1, host_.pending_requests()); 2617 EXPECT_TRUE(net::URLRequestTestJob::ProcessOnePendingMessage());
2618 base::MessageLoop::current()->RunUntilIdle();
2570 2619
2571 // Cancelling by context should work. 2620 // The UI thread will be informed that the navigation failed with an error
2572 host_.CancelRequestsForContext(filter_->resource_context()); 2621 // code of ERR_ABORTED because the navigation turns out to be a download.
2573 EXPECT_EQ(0, host_.pending_requests()); 2622 // The navigation is aborted, but the request goes on as a download.
2623 EXPECT_EQ(delegate.net_error(), net::ERR_ABORTED);
2624 EXPECT_EQ(1, host_.pending_requests());
2625
2626 // In PlzNavigate, the renderer cannot cancel the request directly.
2627 // However, cancelling by context should work.
2628 host_.CancelRequestsForContext(browser_context_->GetResourceContext());
2629 EXPECT_EQ(0, host_.pending_requests());
2630
2631 base::MessageLoop::current()->RunUntilIdle();
2632 } else {
2633 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id,
2634 download_url, RESOURCE_TYPE_MAIN_FRAME);
2635
2636 // Return some data so that the request is identified as a download
2637 // and the proper resource handlers are created.
2638 EXPECT_TRUE(net::URLRequestTestJob::ProcessOnePendingMessage());
2639
2640 // And now simulate a cancellation coming from the renderer.
2641 ResourceHostMsg_CancelRequest msg(request_id);
2642 host_.OnMessageReceived(msg, filter_.get());
2643
2644 // Since the request had already started processing as a download,
2645 // the cancellation above should have been ignored and the request
2646 // should still be alive.
2647 EXPECT_EQ(1, host_.pending_requests());
2648
2649 // Cancelling by other methods shouldn't work either.
2650 host_.CancelRequestsForProcess(render_view_id);
2651 EXPECT_EQ(1, host_.pending_requests());
2652
2653 // Cancelling by context should work.
2654 host_.CancelRequestsForContext(filter_->resource_context());
2655 EXPECT_EQ(0, host_.pending_requests());
2656 }
2574 } 2657 }
2575 2658
2576 TEST_P(ResourceDispatcherHostTest, CancelRequestsForContextDetached) { 2659 TEST_P(ResourceDispatcherHostTest, CancelRequestsForContextDetached) {
2577 EXPECT_EQ(0, host_.pending_requests()); 2660 EXPECT_EQ(0, host_.pending_requests());
2578 2661
2579 int render_view_id = 0; 2662 int render_view_id = 0;
2580 int request_id = 1; 2663 int request_id = 1;
2581 2664
2582 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id, 2665 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id,
2583 net::URLRequestTestJob::test_url_4(), 2666 net::URLRequestTestJob::test_url_4(),
(...skipping 572 matching lines...) Expand 10 before | Expand all | Expand 10 after
3156 ASSERT_EQ(2U, msgs.size()); 3239 ASSERT_EQ(2U, msgs.size());
3157 EXPECT_EQ(ResourceMsg_ReceivedRedirect::ID, msgs[0][0].type()); 3240 EXPECT_EQ(ResourceMsg_ReceivedRedirect::ID, msgs[0][0].type());
3158 CheckSuccessfulRequest(msgs[1], kResponseBody); 3241 CheckSuccessfulRequest(msgs[1], kResponseBody);
3159 } 3242 }
3160 3243
3161 TEST_P(ResourceDispatcherHostTest, UnknownURLScheme) { 3244 TEST_P(ResourceDispatcherHostTest, UnknownURLScheme) {
3162 EXPECT_EQ(0, host_.pending_requests()); 3245 EXPECT_EQ(0, host_.pending_requests());
3163 3246
3164 HandleScheme("http"); 3247 HandleScheme("http");
3165 3248
3166 MakeTestRequestWithResourceType(filter_.get(), 0, 1, GURL("foo://bar"), 3249 const GURL invalid_sheme_url = GURL("foo://bar");
3167 RESOURCE_TYPE_MAIN_FRAME); 3250 const int expected_error_code = net::ERR_UNKNOWN_URL_SCHEME;
3168 3251
3169 // Flush all pending requests. 3252 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 } 3253 }
3184 3254
3185 TEST_P(ResourceDispatcherHostTest, DataReceivedACKs) { 3255 TEST_P(ResourceDispatcherHostTest, DataReceivedACKs) {
3186 EXPECT_EQ(0, host_.pending_requests()); 3256 EXPECT_EQ(0, host_.pending_requests());
3187 3257
3188 SendDataReceivedACKs(true); 3258 SendDataReceivedACKs(true);
3189 3259
3190 HandleScheme("big-job"); 3260 HandleScheme("big-job");
3191 MakeTestRequest(0, 1, GURL("big-job:0123456789,1000000")); 3261 MakeTestRequest(0, 1, GURL("big-job:0123456789,1000000"));
3192 3262
(...skipping 590 matching lines...) Expand 10 before | Expand all | Expand 10 after
3783 if (delay_start_) { 3853 if (delay_start_) {
3784 return new URLRequestTestDelayedStartJob(request, network_delegate); 3854 return new URLRequestTestDelayedStartJob(request, network_delegate);
3785 } else if (delay_complete_) { 3855 } else if (delay_complete_) {
3786 return new URLRequestTestDelayedCompletionJob(request, 3856 return new URLRequestTestDelayedCompletionJob(request,
3787 network_delegate); 3857 network_delegate);
3788 } else if (network_start_notification_) { 3858 } else if (network_start_notification_) {
3789 return new URLRequestTestDelayedNetworkJob(request, network_delegate); 3859 return new URLRequestTestDelayedNetworkJob(request, network_delegate);
3790 } else if (scheme == "big-job") { 3860 } else if (scheme == "big-job") {
3791 return new URLRequestBigJob(request, network_delegate); 3861 return new URLRequestBigJob(request, network_delegate);
3792 } else { 3862 } else {
3793 return new net::URLRequestTestJob(request, network_delegate); 3863 return new net::URLRequestTestJob(request, network_delegate,
3864 test_fixture_->auto_advance_);
3794 } 3865 }
3795 } else { 3866 } else {
3796 if (delay_start_) { 3867 if (delay_start_) {
3797 return new URLRequestTestDelayedStartJob( 3868 return new URLRequestTestDelayedStartJob(
3798 request, network_delegate, 3869 request, network_delegate,
3799 test_fixture_->response_headers_, test_fixture_->response_data_, 3870 test_fixture_->response_headers_, test_fixture_->response_data_,
3800 false); 3871 false);
3801 } else if (delay_complete_) { 3872 } else if (delay_complete_) {
3802 return new URLRequestTestDelayedCompletionJob( 3873 return new URLRequestTestDelayedCompletionJob(
3803 request, network_delegate, 3874 request, network_delegate,
3804 test_fixture_->response_headers_, test_fixture_->response_data_, 3875 test_fixture_->response_headers_, test_fixture_->response_data_,
3805 false); 3876 false);
3806 } else if (test_fixture_->use_test_ssl_certificate_) { 3877 } else if (test_fixture_->use_test_ssl_certificate_) {
3807 return new TestHTTPSURLRequestJob(request, network_delegate, 3878 return new TestHTTPSURLRequestJob(request, network_delegate,
3808 test_fixture_->response_headers_, 3879 test_fixture_->response_headers_,
3809 test_fixture_->response_data_, false); 3880 test_fixture_->response_data_, false);
3810 } else { 3881 } else {
3811 return new net::URLRequestTestJob( 3882 return new net::URLRequestTestJob(
3812 request, network_delegate, 3883 request, network_delegate, test_fixture_->response_headers_,
3813 test_fixture_->response_headers_, test_fixture_->response_data_, 3884 test_fixture_->response_data_, test_fixture_->auto_advance_);
3814 false);
3815 } 3885 }
3816 } 3886 }
3817 } 3887 }
3818 3888
3819 net::URLRequestJob* TestURLRequestJobFactory::MaybeInterceptRedirect( 3889 net::URLRequestJob* TestURLRequestJobFactory::MaybeInterceptRedirect(
3820 net::URLRequest* request, 3890 net::URLRequest* request,
3821 net::NetworkDelegate* network_delegate, 3891 net::NetworkDelegate* network_delegate,
3822 const GURL& location) const { 3892 const GURL& location) const {
3823 return nullptr; 3893 return nullptr;
3824 } 3894 }
3825 3895
3826 net::URLRequestJob* TestURLRequestJobFactory::MaybeInterceptResponse( 3896 net::URLRequestJob* TestURLRequestJobFactory::MaybeInterceptResponse(
3827 net::URLRequest* request, 3897 net::URLRequest* request,
3828 net::NetworkDelegate* network_delegate) const { 3898 net::NetworkDelegate* network_delegate) const {
3829 return nullptr; 3899 return nullptr;
3830 } 3900 }
3831 3901
3832 INSTANTIATE_TEST_CASE_P( 3902 INSTANTIATE_TEST_CASE_P(
3833 ResourceDispatcherHostTests, 3903 ResourceDispatcherHostTests,
3834 ResourceDispatcherHostTest, 3904 ResourceDispatcherHostTest,
3835 testing::Values(TestConfig::kDefault, 3905 testing::Values(TestConfig::kDefault,
3836 TestConfig::kOptimizeIPCForSmallResourceEnabled)); 3906 TestConfig::kOptimizeIPCForSmallResourceEnabled));
3837 3907
3838 } // namespace content 3908 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698