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

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: Rebase + addressed nit 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
« no previous file with comments | « content/browser/loader/navigation_url_loader_unittest.cc ('k') | content/content_tests.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 793 matching lines...) Expand 10 before | Expand all | Expand 10 after
858 } 863 }
859 864
860 void set_default_cert_id(int default_cert_id) { 865 void set_default_cert_id(int default_cert_id) {
861 default_cert_id_ = default_cert_id; 866 default_cert_id_ = default_cert_id;
862 } 867 }
863 868
864 private: 869 private:
865 int default_cert_id_; 870 int default_cert_id_;
866 }; 871 };
867 872
873 void CheckRequestCompleteErrorCode(const IPC::Message& message,
874 int expected_error_code) {
875 // Verify the expected error code was received.
876 int request_id;
877 int error_code;
878
879 ASSERT_EQ(ResourceMsg_RequestComplete::ID, message.type());
880
881 base::PickleIterator iter(message);
882 ASSERT_TRUE(IPC::ReadParam(&message, &iter, &request_id));
883 ASSERT_TRUE(IPC::ReadParam(&message, &iter, &error_code));
884 ASSERT_EQ(expected_error_code, error_code);
885 }
886
868 class ResourceDispatcherHostTest : public testing::TestWithParam<TestConfig>, 887 class ResourceDispatcherHostTest : public testing::TestWithParam<TestConfig>,
869 public IPC::Sender { 888 public IPC::Sender {
870 public: 889 public:
871 typedef ResourceDispatcherHostImpl::LoadInfo LoadInfo; 890 typedef ResourceDispatcherHostImpl::LoadInfo LoadInfo;
872 typedef ResourceDispatcherHostImpl::LoadInfoMap LoadInfoMap; 891 typedef ResourceDispatcherHostImpl::LoadInfoMap LoadInfoMap;
873 892
874 ResourceDispatcherHostTest() 893 ResourceDispatcherHostTest()
875 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), 894 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP),
876 use_test_ssl_certificate_(false), 895 use_test_ssl_certificate_(false),
877 old_factory_(NULL), 896 old_factory_(NULL),
878 send_data_received_acks_(false) { 897 send_data_received_acks_(false),
898 auto_advance_(false) {
879 browser_context_.reset(new TestBrowserContext()); 899 browser_context_.reset(new TestBrowserContext());
880 BrowserContext::EnsureResourceContextInitialized(browser_context_.get()); 900 BrowserContext::EnsureResourceContextInitialized(browser_context_.get());
881 base::RunLoop().RunUntilIdle(); 901 base::RunLoop().RunUntilIdle();
882 filter_ = MakeForwardingFilter(); 902 filter_ = MakeForwardingFilter();
883 // TODO(cbentzel): Better way to get URLRequestContext? 903 // TODO(cbentzel): Better way to get URLRequestContext?
884 net::URLRequestContext* request_context = 904 net::URLRequestContext* request_context =
885 browser_context_->GetResourceContext()->GetRequestContext(); 905 browser_context_->GetResourceContext()->GetRequestContext();
886 job_factory_.reset(new TestURLRequestJobFactory(this)); 906 job_factory_.reset(new TestURLRequestJobFactory(this));
887 request_context->set_job_factory(job_factory_.get()); 907 request_context->set_job_factory(job_factory_.get());
888 request_context->set_network_delegate(&network_delegate_); 908 request_context->set_network_delegate(&network_delegate_);
(...skipping 210 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 std::unique_ptr<LoadInfoTestRequestInfo> loader_test_request_info_; 1175 std::unique_ptr<LoadInfoTestRequestInfo> loader_test_request_info_;
1110 std::unique_ptr<base::RunLoop> wait_for_request_create_loop_; 1176 std::unique_ptr<base::RunLoop> wait_for_request_create_loop_;
1111 1177
1112 content::TestBrowserThreadBundle thread_bundle_; 1178 content::TestBrowserThreadBundle thread_bundle_;
1113 std::unique_ptr<TestBrowserContext> browser_context_; 1179 std::unique_ptr<TestBrowserContext> browser_context_;
1114 std::unique_ptr<TestURLRequestJobFactory> job_factory_; 1180 std::unique_ptr<TestURLRequestJobFactory> job_factory_;
1115 std::unique_ptr<WebContents> web_contents_; 1181 std::unique_ptr<WebContents> web_contents_;
1116 std::unique_ptr<TestWebContentsObserver> web_contents_observer_; 1182 std::unique_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 std::unique_ptr<base::RunLoop> wait_for_request_complete_loop_; 1195 std::unique_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 1196 matching lines...) Expand 10 before | Expand all | Expand 10 after
2461 // Tests for crbug.com/31266 (Non-2xx + application/octet-stream). 2514 // Tests for crbug.com/31266 (Non-2xx + application/octet-stream).
2462 TEST_P(ResourceDispatcherHostTest, ForbiddenDownload) { 2515 TEST_P(ResourceDispatcherHostTest, ForbiddenDownload) {
2463 std::string raw_headers("HTTP/1.1 403 Forbidden\n" 2516 std::string raw_headers("HTTP/1.1 403 Forbidden\n"
2464 "Content-disposition: attachment; filename=blah\n" 2517 "Content-disposition: attachment; filename=blah\n"
2465 "Content-type: application/octet-stream\n\n"); 2518 "Content-type: application/octet-stream\n\n");
2466 std::string response_data("<html><title>Test One</title></html>"); 2519 std::string response_data("<html><title>Test One</title></html>");
2467 SetResponse(raw_headers, response_data); 2520 SetResponse(raw_headers, response_data);
2468 2521
2469 HandleScheme("http"); 2522 HandleScheme("http");
2470 2523
2471 // Only MAIN_FRAMEs can trigger a download. 2524 int expected_error_code = net::ERR_INVALID_RESPONSE;
2472 MakeTestRequestWithResourceType(filter_.get(), 0, 1, GURL("http:bla"), 2525 GURL forbidden_download_url = GURL("http:bla");
2473 RESOURCE_TYPE_MAIN_FRAME);
2474 2526
2475 // Flush all pending requests. 2527 CompleteFailingMainResourceRequest(forbidden_download_url,
2476 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} 2528 expected_error_code);
2477 base::MessageLoop::current()->RunUntilIdle();
2478
2479 // Sorts out all the messages we saw by request.
2480 ResourceIPCAccumulator::ClassifiedMessages msgs;
2481 accum_.GetClassifiedMessages(&msgs);
2482
2483 // We should have gotten one RequestComplete message.
2484 ASSERT_EQ(1U, msgs.size());
2485 ASSERT_EQ(1U, msgs[0].size());
2486 EXPECT_EQ(ResourceMsg_RequestComplete::ID, msgs[0][0].type());
2487
2488 // The RequestComplete message should have had the error code of
2489 // ERR_INVALID_RESPONSE.
2490 CheckRequestCompleteErrorCode(msgs[0][0], net::ERR_INVALID_RESPONSE);
2491 } 2529 }
2492 2530
2493 // Test for http://crbug.com/76202 . We don't want to destroy a 2531 // Test for http://crbug.com/76202 . We don't want to destroy a
2494 // download request prematurely when processing a cancellation from 2532 // download request prematurely when processing a cancellation from
2495 // the renderer. 2533 // the renderer.
2496 TEST_P(ResourceDispatcherHostTest, IgnoreCancelForDownloads) { 2534 TEST_P(ResourceDispatcherHostTest, IgnoreCancelForDownloads) {
2535 // PlzNavigate: A request that ends up being a download is a main resource
2536 // request. Hence, it has been initiated by the browser and is not associated
2537 // with a renderer. Therefore, it cannot be canceled by a renderer IPC.
2538 if (IsBrowserSideNavigationEnabled()) {
2539 SUCCEED() << "Not applicable with --enable-browser-side-navigation.";
2540 return;
2541 }
2542
2497 EXPECT_EQ(0, host_.pending_requests()); 2543 EXPECT_EQ(0, host_.pending_requests());
2498 2544
2499 int render_view_id = 0; 2545 int render_view_id = 0;
2500 int request_id = 1; 2546 int request_id = 1;
2501 2547
2502 std::string raw_headers("HTTP\n" 2548 std::string raw_headers("HTTP\n"
2503 "Content-disposition: attachment; filename=foo\n\n"); 2549 "Content-disposition: attachment; filename=foo\n\n");
2504 std::string response_data("01234567890123456789\x01foobar"); 2550 std::string response_data("01234567890123456789\x01foobar");
2505 2551
2506 // Get past sniffing metrics in the MimeTypeResourceHandler. Note that 2552 // Get past sniffing metrics in the MimeTypeResourceHandler. Note that
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
2542 std::string raw_headers("HTTP\n" 2588 std::string raw_headers("HTTP\n"
2543 "Content-disposition: attachment; filename=foo\n\n"); 2589 "Content-disposition: attachment; filename=foo\n\n");
2544 std::string response_data("01234567890123456789\x01foobar"); 2590 std::string response_data("01234567890123456789\x01foobar");
2545 // Get past sniffing metrics. 2591 // Get past sniffing metrics.
2546 response_data.resize(1025, ' '); 2592 response_data.resize(1025, ' ');
2547 2593
2548 SetResponse(raw_headers, response_data); 2594 SetResponse(raw_headers, response_data);
2549 job_factory_->SetDelayedCompleteJobGeneration(true); 2595 job_factory_->SetDelayedCompleteJobGeneration(true);
2550 HandleScheme("http"); 2596 HandleScheme("http");
2551 2597
2552 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id, 2598 const GURL download_url = GURL("http://example.com/blah");
2553 GURL("http://example.com/blah"),
2554 RESOURCE_TYPE_MAIN_FRAME);
2555 // Return some data so that the request is identified as a download
2556 // and the proper resource handlers are created.
2557 EXPECT_TRUE(net::URLRequestTestJob::ProcessOnePendingMessage());
2558 2599
2559 // And now simulate a cancellation coming from the renderer. 2600 if (IsBrowserSideNavigationEnabled()) {
2560 ResourceHostMsg_CancelRequest msg(request_id); 2601 // Create a NavigationRequest.
2561 host_.OnMessageReceived(msg, filter_.get()); 2602 TestNavigationURLLoaderDelegate delegate;
2603 BeginNavigationParams begin_params(std::string(), net::LOAD_NORMAL, false,
2604 false, REQUEST_CONTEXT_TYPE_LOCATION);
2605 CommonNavigationParams common_params;
2606 common_params.url = download_url;
2607 scoped_ptr<NavigationRequestInfo> request_info(new NavigationRequestInfo(
2608 common_params, begin_params, download_url, url::Origin(download_url),
2609 true, false, -1, scoped_refptr<ResourceRequestBody>()));
2610 scoped_ptr<NavigationURLLoader> loader = NavigationURLLoader::Create(
2611 browser_context_.get(), std::move(request_info), nullptr, &delegate);
2562 2612
2563 // Since the request had already started processing as a download, 2613 // Wait until a response has been received and proceed with the response.
2564 // the cancellation above should have been ignored and the request 2614 KickOffRequest();
2565 // should still be alive.
2566 EXPECT_EQ(1, host_.pending_requests());
2567 2615
2568 // Cancelling by other methods shouldn't work either. 2616 // Return some data so that the request is identified as a download
2569 host_.CancelRequestsForProcess(render_view_id); 2617 // and the proper resource handlers are created.
2570 EXPECT_EQ(1, host_.pending_requests()); 2618 EXPECT_TRUE(net::URLRequestTestJob::ProcessOnePendingMessage());
2619 base::MessageLoop::current()->RunUntilIdle();
2571 2620
2572 // Cancelling by context should work. 2621 // The UI thread will be informed that the navigation failed with an error
2573 host_.CancelRequestsForContext(filter_->resource_context()); 2622 // code of ERR_ABORTED because the navigation turns out to be a download.
2574 EXPECT_EQ(0, host_.pending_requests()); 2623 // The navigation is aborted, but the request goes on as a download.
2624 EXPECT_EQ(delegate.net_error(), net::ERR_ABORTED);
2625 EXPECT_EQ(1, host_.pending_requests());
2626
2627 // In PlzNavigate, the renderer cannot cancel the request directly.
2628 // However, cancelling by context should work.
2629 host_.CancelRequestsForContext(browser_context_->GetResourceContext());
2630 EXPECT_EQ(0, host_.pending_requests());
2631
2632 base::MessageLoop::current()->RunUntilIdle();
2633 } else {
2634 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id,
2635 download_url, RESOURCE_TYPE_MAIN_FRAME);
2636
2637 // Return some data so that the request is identified as a download
2638 // and the proper resource handlers are created.
2639 EXPECT_TRUE(net::URLRequestTestJob::ProcessOnePendingMessage());
2640
2641 // And now simulate a cancellation coming from the renderer.
2642 ResourceHostMsg_CancelRequest msg(request_id);
2643 host_.OnMessageReceived(msg, filter_.get());
2644
2645 // Since the request had already started processing as a download,
2646 // the cancellation above should have been ignored and the request
2647 // should still be alive.
2648 EXPECT_EQ(1, host_.pending_requests());
2649
2650 // Cancelling by other methods shouldn't work either.
2651 host_.CancelRequestsForProcess(render_view_id);
2652 EXPECT_EQ(1, host_.pending_requests());
2653
2654 // Cancelling by context should work.
2655 host_.CancelRequestsForContext(filter_->resource_context());
2656 EXPECT_EQ(0, host_.pending_requests());
2657 }
2575 } 2658 }
2576 2659
2577 TEST_P(ResourceDispatcherHostTest, CancelRequestsForContextDetached) { 2660 TEST_P(ResourceDispatcherHostTest, CancelRequestsForContextDetached) {
2578 EXPECT_EQ(0, host_.pending_requests()); 2661 EXPECT_EQ(0, host_.pending_requests());
2579 2662
2580 int render_view_id = 0; 2663 int render_view_id = 0;
2581 int request_id = 1; 2664 int request_id = 1;
2582 2665
2583 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id, 2666 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id,
2584 net::URLRequestTestJob::test_url_4(), 2667 net::URLRequestTestJob::test_url_4(),
(...skipping 572 matching lines...) Expand 10 before | Expand all | Expand 10 after
3157 ASSERT_EQ(2U, msgs.size()); 3240 ASSERT_EQ(2U, msgs.size());
3158 EXPECT_EQ(ResourceMsg_ReceivedRedirect::ID, msgs[0][0].type()); 3241 EXPECT_EQ(ResourceMsg_ReceivedRedirect::ID, msgs[0][0].type());
3159 CheckSuccessfulRequest(msgs[1], kResponseBody); 3242 CheckSuccessfulRequest(msgs[1], kResponseBody);
3160 } 3243 }
3161 3244
3162 TEST_P(ResourceDispatcherHostTest, UnknownURLScheme) { 3245 TEST_P(ResourceDispatcherHostTest, UnknownURLScheme) {
3163 EXPECT_EQ(0, host_.pending_requests()); 3246 EXPECT_EQ(0, host_.pending_requests());
3164 3247
3165 HandleScheme("http"); 3248 HandleScheme("http");
3166 3249
3167 MakeTestRequestWithResourceType(filter_.get(), 0, 1, GURL("foo://bar"), 3250 const GURL invalid_sheme_url = GURL("foo://bar");
3168 RESOURCE_TYPE_MAIN_FRAME); 3251 const int expected_error_code = net::ERR_UNKNOWN_URL_SCHEME;
3169 3252
3170 // Flush all pending requests. 3253 CompleteFailingMainResourceRequest(invalid_sheme_url, expected_error_code);
3171 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {}
3172
3173 // Sort all the messages we saw by request.
3174 ResourceIPCAccumulator::ClassifiedMessages msgs;
3175 accum_.GetClassifiedMessages(&msgs);
3176
3177 // We should have gotten one RequestComplete message.
3178 ASSERT_EQ(1U, msgs[0].size());
3179 EXPECT_EQ(ResourceMsg_RequestComplete::ID, msgs[0][0].type());
3180
3181 // The RequestComplete message should have the error code of
3182 // ERR_UNKNOWN_URL_SCHEME.
3183 CheckRequestCompleteErrorCode(msgs[0][0], net::ERR_UNKNOWN_URL_SCHEME);
3184 } 3254 }
3185 3255
3186 TEST_P(ResourceDispatcherHostTest, DataReceivedACKs) { 3256 TEST_P(ResourceDispatcherHostTest, DataReceivedACKs) {
3187 EXPECT_EQ(0, host_.pending_requests()); 3257 EXPECT_EQ(0, host_.pending_requests());
3188 3258
3189 SendDataReceivedACKs(true); 3259 SendDataReceivedACKs(true);
3190 3260
3191 HandleScheme("big-job"); 3261 HandleScheme("big-job");
3192 MakeTestRequest(0, 1, GURL("big-job:0123456789,1000000")); 3262 MakeTestRequest(0, 1, GURL("big-job:0123456789,1000000"));
3193 3263
(...skipping 590 matching lines...) Expand 10 before | Expand all | Expand 10 after
3784 if (delay_start_) { 3854 if (delay_start_) {
3785 return new URLRequestTestDelayedStartJob(request, network_delegate); 3855 return new URLRequestTestDelayedStartJob(request, network_delegate);
3786 } else if (delay_complete_) { 3856 } else if (delay_complete_) {
3787 return new URLRequestTestDelayedCompletionJob(request, 3857 return new URLRequestTestDelayedCompletionJob(request,
3788 network_delegate); 3858 network_delegate);
3789 } else if (network_start_notification_) { 3859 } else if (network_start_notification_) {
3790 return new URLRequestTestDelayedNetworkJob(request, network_delegate); 3860 return new URLRequestTestDelayedNetworkJob(request, network_delegate);
3791 } else if (scheme == "big-job") { 3861 } else if (scheme == "big-job") {
3792 return new URLRequestBigJob(request, network_delegate); 3862 return new URLRequestBigJob(request, network_delegate);
3793 } else { 3863 } else {
3794 return new net::URLRequestTestJob(request, network_delegate); 3864 return new net::URLRequestTestJob(request, network_delegate,
3865 test_fixture_->auto_advance_);
3795 } 3866 }
3796 } else { 3867 } else {
3797 if (delay_start_) { 3868 if (delay_start_) {
3798 return new URLRequestTestDelayedStartJob( 3869 return new URLRequestTestDelayedStartJob(
3799 request, network_delegate, 3870 request, network_delegate,
3800 test_fixture_->response_headers_, test_fixture_->response_data_, 3871 test_fixture_->response_headers_, test_fixture_->response_data_,
3801 false); 3872 false);
3802 } else if (delay_complete_) { 3873 } else if (delay_complete_) {
3803 return new URLRequestTestDelayedCompletionJob( 3874 return new URLRequestTestDelayedCompletionJob(
3804 request, network_delegate, 3875 request, network_delegate,
3805 test_fixture_->response_headers_, test_fixture_->response_data_, 3876 test_fixture_->response_headers_, test_fixture_->response_data_,
3806 false); 3877 false);
3807 } else if (test_fixture_->use_test_ssl_certificate_) { 3878 } else if (test_fixture_->use_test_ssl_certificate_) {
3808 return new TestHTTPSURLRequestJob(request, network_delegate, 3879 return new TestHTTPSURLRequestJob(request, network_delegate,
3809 test_fixture_->response_headers_, 3880 test_fixture_->response_headers_,
3810 test_fixture_->response_data_, false); 3881 test_fixture_->response_data_, false);
3811 } else { 3882 } else {
3812 return new net::URLRequestTestJob( 3883 return new net::URLRequestTestJob(
3813 request, network_delegate, 3884 request, network_delegate, test_fixture_->response_headers_,
3814 test_fixture_->response_headers_, test_fixture_->response_data_, 3885 test_fixture_->response_data_, test_fixture_->auto_advance_);
3815 false);
3816 } 3886 }
3817 } 3887 }
3818 } 3888 }
3819 3889
3820 net::URLRequestJob* TestURLRequestJobFactory::MaybeInterceptRedirect( 3890 net::URLRequestJob* TestURLRequestJobFactory::MaybeInterceptRedirect(
3821 net::URLRequest* request, 3891 net::URLRequest* request,
3822 net::NetworkDelegate* network_delegate, 3892 net::NetworkDelegate* network_delegate,
3823 const GURL& location) const { 3893 const GURL& location) const {
3824 return nullptr; 3894 return nullptr;
3825 } 3895 }
3826 3896
3827 net::URLRequestJob* TestURLRequestJobFactory::MaybeInterceptResponse( 3897 net::URLRequestJob* TestURLRequestJobFactory::MaybeInterceptResponse(
3828 net::URLRequest* request, 3898 net::URLRequest* request,
3829 net::NetworkDelegate* network_delegate) const { 3899 net::NetworkDelegate* network_delegate) const {
3830 return nullptr; 3900 return nullptr;
3831 } 3901 }
3832 3902
3833 INSTANTIATE_TEST_CASE_P( 3903 INSTANTIATE_TEST_CASE_P(
3834 ResourceDispatcherHostTests, 3904 ResourceDispatcherHostTests,
3835 ResourceDispatcherHostTest, 3905 ResourceDispatcherHostTest,
3836 testing::Values(TestConfig::kDefault, 3906 testing::Values(TestConfig::kDefault,
3837 TestConfig::kOptimizeIPCForSmallResourceEnabled)); 3907 TestConfig::kOptimizeIPCForSmallResourceEnabled));
3838 3908
3839 } // namespace content 3909 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/loader/navigation_url_loader_unittest.cc ('k') | content/content_tests.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698