| 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 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <utility> | 8 #include <utility> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 #include "content/public/browser/resource_throttle.h" | 50 #include "content/public/browser/resource_throttle.h" |
| 51 #include "content/public/browser/web_contents.h" | 51 #include "content/public/browser/web_contents.h" |
| 52 #include "content/public/browser/web_contents_observer.h" | 52 #include "content/public/browser/web_contents_observer.h" |
| 53 #include "content/public/common/browser_side_navigation_policy.h" | 53 #include "content/public/common/browser_side_navigation_policy.h" |
| 54 #include "content/public/common/child_process_host.h" | 54 #include "content/public/common/child_process_host.h" |
| 55 #include "content/public/common/process_type.h" | 55 #include "content/public/common/process_type.h" |
| 56 #include "content/public/common/resource_response.h" | 56 #include "content/public/common/resource_response.h" |
| 57 #include "content/public/test/test_browser_context.h" | 57 #include "content/public/test/test_browser_context.h" |
| 58 #include "content/public/test/test_browser_thread_bundle.h" | 58 #include "content/public/test/test_browser_thread_bundle.h" |
| 59 #include "content/public/test/test_renderer_host.h" | 59 #include "content/public/test/test_renderer_host.h" |
| 60 #include "content/public/test/test_utils.h" |
| 60 #include "content/test/test_content_browser_client.h" | 61 #include "content/test/test_content_browser_client.h" |
| 61 #include "content/test/test_navigation_url_loader_delegate.h" | 62 #include "content/test/test_navigation_url_loader_delegate.h" |
| 62 #include "net/base/chunked_upload_data_stream.h" | 63 #include "net/base/chunked_upload_data_stream.h" |
| 63 #include "net/base/elements_upload_data_stream.h" | 64 #include "net/base/elements_upload_data_stream.h" |
| 64 #include "net/base/load_flags.h" | 65 #include "net/base/load_flags.h" |
| 65 #include "net/base/net_errors.h" | 66 #include "net/base/net_errors.h" |
| 66 #include "net/base/request_priority.h" | 67 #include "net/base/request_priority.h" |
| 67 #include "net/base/upload_bytes_element_reader.h" | 68 #include "net/base/upload_bytes_element_reader.h" |
| 68 #include "net/http/http_util.h" | 69 #include "net/http/http_util.h" |
| 69 #include "net/test/cert_test_util.h" | 70 #include "net/test/cert_test_util.h" |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 request.should_reset_appcache = false; | 170 request.should_reset_appcache = false; |
| 170 request.is_main_frame = true; | 171 request.is_main_frame = true; |
| 171 request.parent_is_main_frame = false; | 172 request.parent_is_main_frame = false; |
| 172 request.transition_type = ui::PAGE_TRANSITION_LINK; | 173 request.transition_type = ui::PAGE_TRANSITION_LINK; |
| 173 request.allow_download = true; | 174 request.allow_download = true; |
| 174 return request; | 175 return request; |
| 175 } | 176 } |
| 176 | 177 |
| 177 // Spin up the message loop to kick off the request. | 178 // Spin up the message loop to kick off the request. |
| 178 static void KickOffRequest() { | 179 static void KickOffRequest() { |
| 179 base::RunLoop().RunUntilIdle(); | 180 content::RunAllBlockingPoolTasksUntilIdle(); |
| 180 } | 181 } |
| 181 | 182 |
| 182 // We may want to move this to a shared space if it is useful for something else | 183 // We may want to move this to a shared space if it is useful for something else |
| 183 class ResourceIPCAccumulator { | 184 class ResourceIPCAccumulator { |
| 184 public: | 185 public: |
| 185 ~ResourceIPCAccumulator() { | 186 ~ResourceIPCAccumulator() { |
| 186 for (size_t i = 0; i < messages_.size(); i++) { | 187 for (size_t i = 0; i < messages_.size(); i++) { |
| 187 ReleaseHandlesInMessage(messages_[i]); | 188 ReleaseHandlesInMessage(messages_[i]); |
| 188 } | 189 } |
| 189 } | 190 } |
| (...skipping 656 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 846 ResourceDispatcherHostTest() | 847 ResourceDispatcherHostTest() |
| 847 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), | 848 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), |
| 848 host_(base::Bind(&DownloadResourceHandler::Create), | 849 host_(base::Bind(&DownloadResourceHandler::Create), |
| 849 base::ThreadTaskRunnerHandle::Get()), | 850 base::ThreadTaskRunnerHandle::Get()), |
| 850 use_test_ssl_certificate_(false), | 851 use_test_ssl_certificate_(false), |
| 851 send_data_received_acks_(false), | 852 send_data_received_acks_(false), |
| 852 auto_advance_(false) { | 853 auto_advance_(false) { |
| 853 host_.SetLoaderDelegate(&loader_delegate_); | 854 host_.SetLoaderDelegate(&loader_delegate_); |
| 854 browser_context_.reset(new TestBrowserContext()); | 855 browser_context_.reset(new TestBrowserContext()); |
| 855 BrowserContext::EnsureResourceContextInitialized(browser_context_.get()); | 856 BrowserContext::EnsureResourceContextInitialized(browser_context_.get()); |
| 856 base::RunLoop().RunUntilIdle(); | 857 content::RunAllBlockingPoolTasksUntilIdle(); |
| 858 |
| 857 filter_ = MakeForwardingFilter(); | 859 filter_ = MakeForwardingFilter(); |
| 858 // TODO(cbentzel): Better way to get URLRequestContext? | 860 // TODO(cbentzel): Better way to get URLRequestContext? |
| 859 net::URLRequestContext* request_context = | 861 net::URLRequestContext* request_context = |
| 860 browser_context_->GetResourceContext()->GetRequestContext(); | 862 browser_context_->GetResourceContext()->GetRequestContext(); |
| 861 job_factory_.reset(new TestURLRequestJobFactory(this)); | 863 job_factory_.reset(new TestURLRequestJobFactory(this)); |
| 862 request_context->set_job_factory(job_factory_.get()); | 864 request_context->set_job_factory(job_factory_.get()); |
| 863 request_context->set_network_delegate(&network_delegate_); | 865 request_context->set_network_delegate(&network_delegate_); |
| 864 } | 866 } |
| 865 | 867 |
| 866 ~ResourceDispatcherHostTest() override { | 868 ~ResourceDispatcherHostTest() override { |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 923 host_.Shutdown(); | 925 host_.Shutdown(); |
| 924 | 926 |
| 925 ChildProcessSecurityPolicyImpl::GetInstance()->Remove(0); | 927 ChildProcessSecurityPolicyImpl::GetInstance()->Remove(0); |
| 926 | 928 |
| 927 // Flush the message loop to make application verifiers happy. | 929 // Flush the message loop to make application verifiers happy. |
| 928 if (ResourceDispatcherHostImpl::Get()) | 930 if (ResourceDispatcherHostImpl::Get()) |
| 929 ResourceDispatcherHostImpl::Get()->CancelRequestsForContext( | 931 ResourceDispatcherHostImpl::Get()->CancelRequestsForContext( |
| 930 browser_context_->GetResourceContext()); | 932 browser_context_->GetResourceContext()); |
| 931 | 933 |
| 932 browser_context_.reset(); | 934 browser_context_.reset(); |
| 933 base::RunLoop().RunUntilIdle(); | 935 content::RunAllBlockingPoolTasksUntilIdle(); |
| 934 } | 936 } |
| 935 | 937 |
| 936 // Creates a new ForwardingFilter and registers it with |child_ids_| so as not | 938 // Creates a new ForwardingFilter and registers it with |child_ids_| so as not |
| 937 // to leak per-child state on test shutdown. | 939 // to leak per-child state on test shutdown. |
| 938 ForwardingFilter* MakeForwardingFilter() { | 940 ForwardingFilter* MakeForwardingFilter() { |
| 939 ForwardingFilter* filter = | 941 ForwardingFilter* filter = |
| 940 new ForwardingFilter(this, browser_context_->GetResourceContext()); | 942 new ForwardingFilter(this, browser_context_->GetResourceContext()); |
| 941 child_ids_.insert(filter->child_id()); | 943 child_ids_.insert(filter->child_id()); |
| 942 return filter; | 944 return filter; |
| 943 } | 945 } |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1082 ASSERT_EQ(expected_error_code, delegate.net_error()); | 1084 ASSERT_EQ(expected_error_code, delegate.net_error()); |
| 1083 return; | 1085 return; |
| 1084 } | 1086 } |
| 1085 | 1087 |
| 1086 MakeTestRequestWithResourceType(filter_.get(), 0, 1, url, | 1088 MakeTestRequestWithResourceType(filter_.get(), 0, 1, url, |
| 1087 RESOURCE_TYPE_MAIN_FRAME); | 1089 RESOURCE_TYPE_MAIN_FRAME); |
| 1088 | 1090 |
| 1089 // Flush all pending requests. | 1091 // Flush all pending requests. |
| 1090 while (net::URLRequestTestJob::ProcessOnePendingMessage()) { | 1092 while (net::URLRequestTestJob::ProcessOnePendingMessage()) { |
| 1091 } | 1093 } |
| 1092 base::RunLoop().RunUntilIdle(); | 1094 content::RunAllBlockingPoolTasksUntilIdle(); |
| 1093 | 1095 |
| 1094 // Sorts out all the messages we saw by request. | 1096 // Sorts out all the messages we saw by request. |
| 1095 ResourceIPCAccumulator::ClassifiedMessages msgs; | 1097 ResourceIPCAccumulator::ClassifiedMessages msgs; |
| 1096 accum_.GetClassifiedMessages(&msgs); | 1098 accum_.GetClassifiedMessages(&msgs); |
| 1097 | 1099 |
| 1098 // We should have gotten one RequestComplete message. | 1100 // We should have gotten one RequestComplete message. |
| 1099 ASSERT_EQ(1U, msgs.size()); | 1101 ASSERT_EQ(1U, msgs.size()); |
| 1100 ASSERT_EQ(1U, msgs[0].size()); | 1102 ASSERT_EQ(1U, msgs[0].size()); |
| 1101 EXPECT_EQ(ResourceMsg_RequestComplete::ID, msgs[0][0].type()); | 1103 EXPECT_EQ(ResourceMsg_RequestComplete::ID, msgs[0][0].type()); |
| 1102 | 1104 |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1342 MakeTestRequest(0, 2, net::URLRequestTestJob::test_url_2()); | 1344 MakeTestRequest(0, 2, net::URLRequestTestJob::test_url_2()); |
| 1343 MakeTestRequest(0, 3, net::URLRequestTestJob::test_url_3()); | 1345 MakeTestRequest(0, 3, net::URLRequestTestJob::test_url_3()); |
| 1344 MakeTestRequestWithResourceType(filter_.get(), 0, 4, | 1346 MakeTestRequestWithResourceType(filter_.get(), 0, 4, |
| 1345 net::URLRequestTestJob::test_url_4(), | 1347 net::URLRequestTestJob::test_url_4(), |
| 1346 RESOURCE_TYPE_PREFETCH); // detachable type | 1348 RESOURCE_TYPE_PREFETCH); // detachable type |
| 1347 MakeTestRequest(0, 5, net::URLRequestTestJob::test_url_redirect_to_url_2()); | 1349 MakeTestRequest(0, 5, net::URLRequestTestJob::test_url_redirect_to_url_2()); |
| 1348 | 1350 |
| 1349 // Finish the redirection | 1351 // Finish the redirection |
| 1350 ResourceHostMsg_FollowRedirect redirect_msg(5); | 1352 ResourceHostMsg_FollowRedirect redirect_msg(5); |
| 1351 OnMessageReceived(redirect_msg, filter_.get()); | 1353 OnMessageReceived(redirect_msg, filter_.get()); |
| 1352 base::RunLoop().RunUntilIdle(); | 1354 content::RunAllBlockingPoolTasksUntilIdle(); |
| 1353 | 1355 |
| 1354 // flush all the pending requests | 1356 // flush all the pending requests |
| 1355 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} | 1357 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} |
| 1356 | 1358 |
| 1357 // sorts out all the messages we saw by request | 1359 // sorts out all the messages we saw by request |
| 1358 ResourceIPCAccumulator::ClassifiedMessages msgs; | 1360 ResourceIPCAccumulator::ClassifiedMessages msgs; |
| 1359 accum_.GetClassifiedMessages(&msgs); | 1361 accum_.GetClassifiedMessages(&msgs); |
| 1360 | 1362 |
| 1361 // there are five requests, so we should have gotten them classified as such | 1363 // there are five requests, so we should have gotten them classified as such |
| 1362 ASSERT_EQ(5U, msgs.size()); | 1364 ASSERT_EQ(5U, msgs.size()); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 1386 RendererCancelRequest(4); | 1388 RendererCancelRequest(4); |
| 1387 | 1389 |
| 1388 // The handler should have been detached now. | 1390 // The handler should have been detached now. |
| 1389 GlobalRequestID global_request_id(filter_->child_id(), 4); | 1391 GlobalRequestID global_request_id(filter_->child_id(), 4); |
| 1390 ResourceRequestInfoImpl* info = ResourceRequestInfoImpl::ForRequest( | 1392 ResourceRequestInfoImpl* info = ResourceRequestInfoImpl::ForRequest( |
| 1391 host_.GetURLRequest(global_request_id)); | 1393 host_.GetURLRequest(global_request_id)); |
| 1392 ASSERT_TRUE(info->detachable_handler()->is_detached()); | 1394 ASSERT_TRUE(info->detachable_handler()->is_detached()); |
| 1393 | 1395 |
| 1394 // flush all the pending requests | 1396 // flush all the pending requests |
| 1395 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} | 1397 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} |
| 1396 base::RunLoop().RunUntilIdle(); | 1398 content::RunAllBlockingPoolTasksUntilIdle(); |
| 1397 | 1399 |
| 1398 // Everything should be out now. | 1400 // Everything should be out now. |
| 1399 EXPECT_EQ(0, host_.pending_requests()); | 1401 EXPECT_EQ(0, host_.pending_requests()); |
| 1400 | 1402 |
| 1401 ResourceIPCAccumulator::ClassifiedMessages msgs; | 1403 ResourceIPCAccumulator::ClassifiedMessages msgs; |
| 1402 accum_.GetClassifiedMessages(&msgs); | 1404 accum_.GetClassifiedMessages(&msgs); |
| 1403 | 1405 |
| 1404 // there are four requests, so we should have gotten them classified as such | 1406 // there are four requests, so we should have gotten them classified as such |
| 1405 ASSERT_EQ(4U, msgs.size()); | 1407 ASSERT_EQ(4U, msgs.size()); |
| 1406 | 1408 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1438 | 1440 |
| 1439 // The handler for the cache-only request should have been detached now. | 1441 // The handler for the cache-only request should have been detached now. |
| 1440 GlobalRequestID global_request_id(filter_->child_id(), 2); | 1442 GlobalRequestID global_request_id(filter_->child_id(), 2); |
| 1441 ResourceRequestInfoImpl* info = ResourceRequestInfoImpl::ForRequest( | 1443 ResourceRequestInfoImpl* info = ResourceRequestInfoImpl::ForRequest( |
| 1442 host_.GetURLRequest(global_request_id)); | 1444 host_.GetURLRequest(global_request_id)); |
| 1443 ASSERT_TRUE(info->detachable_handler()->is_detached()); | 1445 ASSERT_TRUE(info->detachable_handler()->is_detached()); |
| 1444 | 1446 |
| 1445 // Flush all the pending requests. | 1447 // Flush all the pending requests. |
| 1446 while (net::URLRequestTestJob::ProcessOnePendingMessage()) { | 1448 while (net::URLRequestTestJob::ProcessOnePendingMessage()) { |
| 1447 } | 1449 } |
| 1448 base::RunLoop().RunUntilIdle(); | 1450 content::RunAllBlockingPoolTasksUntilIdle(); |
| 1449 | 1451 |
| 1450 // Everything should be out now. | 1452 // Everything should be out now. |
| 1451 EXPECT_EQ(0, host_.pending_requests()); | 1453 EXPECT_EQ(0, host_.pending_requests()); |
| 1452 | 1454 |
| 1453 ResourceIPCAccumulator::ClassifiedMessages msgs; | 1455 ResourceIPCAccumulator::ClassifiedMessages msgs; |
| 1454 accum_.GetClassifiedMessages(&msgs); | 1456 accum_.GetClassifiedMessages(&msgs); |
| 1455 | 1457 |
| 1456 // There are two requests, so we should have gotten them classified as such. | 1458 // There are two requests, so we should have gotten them classified as such. |
| 1457 ASSERT_EQ(2U, msgs.size()); | 1459 ASSERT_EQ(2U, msgs.size()); |
| 1458 | 1460 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1474 TEST_F(ResourceDispatcherHostTest, DetachedResourceTimesOut) { | 1476 TEST_F(ResourceDispatcherHostTest, DetachedResourceTimesOut) { |
| 1475 MakeTestRequestWithResourceType(filter_.get(), 0, 1, | 1477 MakeTestRequestWithResourceType(filter_.get(), 0, 1, |
| 1476 net::URLRequestTestJob::test_url_2(), | 1478 net::URLRequestTestJob::test_url_2(), |
| 1477 RESOURCE_TYPE_PREFETCH); // detachable type | 1479 RESOURCE_TYPE_PREFETCH); // detachable type |
| 1478 GlobalRequestID global_request_id(filter_->child_id(), 1); | 1480 GlobalRequestID global_request_id(filter_->child_id(), 1); |
| 1479 ResourceRequestInfoImpl* info = ResourceRequestInfoImpl::ForRequest( | 1481 ResourceRequestInfoImpl* info = ResourceRequestInfoImpl::ForRequest( |
| 1480 host_.GetURLRequest(global_request_id)); | 1482 host_.GetURLRequest(global_request_id)); |
| 1481 ASSERT_TRUE(info->detachable_handler()); | 1483 ASSERT_TRUE(info->detachable_handler()); |
| 1482 info->detachable_handler()->set_cancel_delay( | 1484 info->detachable_handler()->set_cancel_delay( |
| 1483 base::TimeDelta::FromMilliseconds(200)); | 1485 base::TimeDelta::FromMilliseconds(200)); |
| 1484 base::RunLoop().RunUntilIdle(); | 1486 content::RunAllBlockingPoolTasksUntilIdle(); |
| 1485 | 1487 |
| 1486 RendererCancelRequest(1); | 1488 RendererCancelRequest(1); |
| 1487 | 1489 |
| 1488 // From the renderer's perspective, the request was cancelled. | 1490 // From the renderer's perspective, the request was cancelled. |
| 1489 ResourceIPCAccumulator::ClassifiedMessages msgs; | 1491 ResourceIPCAccumulator::ClassifiedMessages msgs; |
| 1490 accum_.GetClassifiedMessages(&msgs); | 1492 accum_.GetClassifiedMessages(&msgs); |
| 1491 ASSERT_EQ(1U, msgs.size()); | 1493 ASSERT_EQ(1U, msgs.size()); |
| 1492 ASSERT_EQ(2U, msgs[0].size()); | 1494 ASSERT_EQ(2U, msgs[0].size()); |
| 1493 ASSERT_EQ(ResourceMsg_ReceivedResponse::ID, msgs[0][0].type()); | 1495 ASSERT_EQ(ResourceMsg_ReceivedResponse::ID, msgs[0][0].type()); |
| 1494 CheckRequestCompleteErrorCode(msgs[0][1], net::ERR_ABORTED); | 1496 CheckRequestCompleteErrorCode(msgs[0][1], net::ERR_ABORTED); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1513 | 1515 |
| 1514 TEST_F(ResourceDispatcherHostTest, SyncLoadSuccess) { | 1516 TEST_F(ResourceDispatcherHostTest, SyncLoadSuccess) { |
| 1515 ResourceRequest request = CreateResourceRequest( | 1517 ResourceRequest request = CreateResourceRequest( |
| 1516 "GET", RESOURCE_TYPE_XHR, net::URLRequestTestJob::test_url_1()); | 1518 "GET", RESOURCE_TYPE_XHR, net::URLRequestTestJob::test_url_1()); |
| 1517 request.priority = net::MAXIMUM_PRIORITY; | 1519 request.priority = net::MAXIMUM_PRIORITY; |
| 1518 | 1520 |
| 1519 // Successful sync load. | 1521 // Successful sync load. |
| 1520 std::tuple<SyncLoadResult> result; | 1522 std::tuple<SyncLoadResult> result; |
| 1521 ResourceHostMsg_SyncLoad sync_load_msg(0, 1, request, &std::get<0>(result)); | 1523 ResourceHostMsg_SyncLoad sync_load_msg(0, 1, request, &std::get<0>(result)); |
| 1522 OnMessageReceived(sync_load_msg, filter_.get()); | 1524 OnMessageReceived(sync_load_msg, filter_.get()); |
| 1523 base::RunLoop().RunUntilIdle(); | 1525 content::RunAllBlockingPoolTasksUntilIdle(); |
| 1524 | 1526 |
| 1525 const IPC::Message* reply = accum_.GetReply(sync_load_msg); | 1527 const IPC::Message* reply = accum_.GetReply(sync_load_msg); |
| 1526 ASSERT_TRUE(reply); | 1528 ASSERT_TRUE(reply); |
| 1527 | 1529 |
| 1528 ASSERT_TRUE(ResourceHostMsg_SyncLoad::ReadReplyParam(reply, &result)); | 1530 ASSERT_TRUE(ResourceHostMsg_SyncLoad::ReadReplyParam(reply, &result)); |
| 1529 EXPECT_EQ(net::OK, std::get<0>(result).error_code); | 1531 EXPECT_EQ(net::OK, std::get<0>(result).error_code); |
| 1530 } | 1532 } |
| 1531 | 1533 |
| 1532 TEST_F(ResourceDispatcherHostTest, SyncLoadError) { | 1534 TEST_F(ResourceDispatcherHostTest, SyncLoadError) { |
| 1533 ResourceRequest request = CreateResourceRequest( | 1535 ResourceRequest request = CreateResourceRequest( |
| 1534 "GET", RESOURCE_TYPE_XHR, net::URLRequestTestJob::test_url_error()); | 1536 "GET", RESOURCE_TYPE_XHR, net::URLRequestTestJob::test_url_error()); |
| 1535 request.priority = net::MAXIMUM_PRIORITY; | 1537 request.priority = net::MAXIMUM_PRIORITY; |
| 1536 | 1538 |
| 1537 // Failued sync load. | 1539 // Failued sync load. |
| 1538 std::tuple<SyncLoadResult> result; | 1540 std::tuple<SyncLoadResult> result; |
| 1539 ResourceHostMsg_SyncLoad sync_load_msg(0, 1, request, &std::get<0>(result)); | 1541 ResourceHostMsg_SyncLoad sync_load_msg(0, 1, request, &std::get<0>(result)); |
| 1540 OnMessageReceived(sync_load_msg, filter_.get()); | 1542 OnMessageReceived(sync_load_msg, filter_.get()); |
| 1541 base::RunLoop().RunUntilIdle(); | 1543 content::RunAllBlockingPoolTasksUntilIdle(); |
| 1542 | 1544 |
| 1543 const IPC::Message* reply = accum_.GetReply(sync_load_msg); | 1545 const IPC::Message* reply = accum_.GetReply(sync_load_msg); |
| 1544 ASSERT_TRUE(reply); | 1546 ASSERT_TRUE(reply); |
| 1545 | 1547 |
| 1546 ASSERT_TRUE(ResourceHostMsg_SyncLoad::ReadReplyParam(reply, &result)); | 1548 ASSERT_TRUE(ResourceHostMsg_SyncLoad::ReadReplyParam(reply, &result)); |
| 1547 EXPECT_EQ(net::ERR_INVALID_URL, std::get<0>(result).error_code); | 1549 EXPECT_EQ(net::ERR_INVALID_URL, std::get<0>(result).error_code); |
| 1548 } | 1550 } |
| 1549 | 1551 |
| 1550 TEST_F(ResourceDispatcherHostTest, SyncLoadCancel) { | 1552 TEST_F(ResourceDispatcherHostTest, SyncLoadCancel) { |
| 1551 ResourceRequest request = CreateResourceRequest( | 1553 ResourceRequest request = CreateResourceRequest( |
| 1552 "GET", RESOURCE_TYPE_XHR, net::URLRequestTestJob::test_url_1()); | 1554 "GET", RESOURCE_TYPE_XHR, net::URLRequestTestJob::test_url_1()); |
| 1553 request.priority = net::MAXIMUM_PRIORITY; | 1555 request.priority = net::MAXIMUM_PRIORITY; |
| 1554 | 1556 |
| 1555 // Cancelled sync load. | 1557 // Cancelled sync load. |
| 1556 SyncLoadResult result; | 1558 SyncLoadResult result; |
| 1557 ResourceHostMsg_SyncLoad sync_load_msg(0, 1, request, &result); | 1559 ResourceHostMsg_SyncLoad sync_load_msg(0, 1, request, &result); |
| 1558 | 1560 |
| 1559 OnMessageReceived(sync_load_msg, filter_.get()); | 1561 OnMessageReceived(sync_load_msg, filter_.get()); |
| 1560 host_.CancelRequestsForProcess(filter_->child_id()); | 1562 host_.CancelRequestsForProcess(filter_->child_id()); |
| 1561 base::RunLoop().RunUntilIdle(); | 1563 content::RunAllBlockingPoolTasksUntilIdle(); |
| 1562 | 1564 |
| 1563 const IPC::Message* reply = accum_.GetReply(sync_load_msg); | 1565 const IPC::Message* reply = accum_.GetReply(sync_load_msg); |
| 1564 ASSERT_TRUE(reply); | 1566 ASSERT_TRUE(reply); |
| 1565 ASSERT_TRUE(reply->is_reply_error()); | 1567 ASSERT_TRUE(reply->is_reply_error()); |
| 1566 } | 1568 } |
| 1567 | 1569 |
| 1568 // If the filter has disappeared then detachable resources should continue to | 1570 // If the filter has disappeared then detachable resources should continue to |
| 1569 // load. | 1571 // load. |
| 1570 TEST_F(ResourceDispatcherHostTest, DeletedFilterDetached) { | 1572 TEST_F(ResourceDispatcherHostTest, DeletedFilterDetached) { |
| 1571 // test_url_1's data is available synchronously, so use 2 and 3. | 1573 // test_url_1's data is available synchronously, so use 2 and 3. |
| (...skipping 28 matching lines...) Expand all Loading... |
| 1600 EXPECT_EQ(2, host_.pending_requests()); | 1602 EXPECT_EQ(2, host_.pending_requests()); |
| 1601 EXPECT_TRUE(info_prefetch->detachable_handler()->is_detached()); | 1603 EXPECT_TRUE(info_prefetch->detachable_handler()->is_detached()); |
| 1602 EXPECT_TRUE(info_ping->detachable_handler()->is_detached()); | 1604 EXPECT_TRUE(info_ping->detachable_handler()->is_detached()); |
| 1603 | 1605 |
| 1604 KickOffRequest(); | 1606 KickOffRequest(); |
| 1605 | 1607 |
| 1606 // Make sure the requests weren't canceled early. | 1608 // Make sure the requests weren't canceled early. |
| 1607 EXPECT_EQ(2, host_.pending_requests()); | 1609 EXPECT_EQ(2, host_.pending_requests()); |
| 1608 | 1610 |
| 1609 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} | 1611 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} |
| 1610 base::RunLoop().RunUntilIdle(); | 1612 content::RunAllBlockingPoolTasksUntilIdle(); |
| 1611 | 1613 |
| 1612 EXPECT_EQ(0, host_.pending_requests()); | 1614 EXPECT_EQ(0, host_.pending_requests()); |
| 1613 EXPECT_EQ(2, network_delegate()->completed_requests()); | 1615 EXPECT_EQ(2, network_delegate()->completed_requests()); |
| 1614 EXPECT_EQ(0, network_delegate()->canceled_requests()); | 1616 EXPECT_EQ(0, network_delegate()->canceled_requests()); |
| 1615 EXPECT_EQ(0, network_delegate()->error_count()); | 1617 EXPECT_EQ(0, network_delegate()->error_count()); |
| 1616 } | 1618 } |
| 1617 | 1619 |
| 1618 // If the filter has disappeared (original process dies) then detachable | 1620 // If the filter has disappeared (original process dies) then detachable |
| 1619 // resources should continue to load, even when redirected. | 1621 // resources should continue to load, even when redirected. |
| 1620 TEST_F(ResourceDispatcherHostTest, DeletedFilterDetachedRedirect) { | 1622 TEST_F(ResourceDispatcherHostTest, DeletedFilterDetachedRedirect) { |
| (...skipping 27 matching lines...) Expand all Loading... |
| 1648 KickOffRequest(); | 1650 KickOffRequest(); |
| 1649 | 1651 |
| 1650 // Verify that a redirect was followed. | 1652 // Verify that a redirect was followed. |
| 1651 EXPECT_EQ(2u, url_request->url_chain().size()); | 1653 EXPECT_EQ(2u, url_request->url_chain().size()); |
| 1652 | 1654 |
| 1653 // Make sure the request wasn't canceled early. | 1655 // Make sure the request wasn't canceled early. |
| 1654 EXPECT_EQ(1, host_.pending_requests()); | 1656 EXPECT_EQ(1, host_.pending_requests()); |
| 1655 | 1657 |
| 1656 // Finish up the request. | 1658 // Finish up the request. |
| 1657 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} | 1659 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} |
| 1658 base::RunLoop().RunUntilIdle(); | 1660 content::RunAllBlockingPoolTasksUntilIdle(); |
| 1659 | 1661 |
| 1660 EXPECT_EQ(0, host_.pending_requests()); | 1662 EXPECT_EQ(0, host_.pending_requests()); |
| 1661 EXPECT_EQ(1, network_delegate()->completed_requests()); | 1663 EXPECT_EQ(1, network_delegate()->completed_requests()); |
| 1662 EXPECT_EQ(0, network_delegate()->canceled_requests()); | 1664 EXPECT_EQ(0, network_delegate()->canceled_requests()); |
| 1663 EXPECT_EQ(0, network_delegate()->error_count()); | 1665 EXPECT_EQ(0, network_delegate()->error_count()); |
| 1664 } | 1666 } |
| 1665 | 1667 |
| 1666 TEST_F(ResourceDispatcherHostTest, CancelWhileStartIsDeferred) { | 1668 TEST_F(ResourceDispatcherHostTest, CancelWhileStartIsDeferred) { |
| 1667 bool was_deleted = false; | 1669 bool was_deleted = false; |
| 1668 | 1670 |
| 1669 // Arrange to have requests deferred before starting. | 1671 // Arrange to have requests deferred before starting. |
| 1670 TestResourceDispatcherHostDelegate delegate; | 1672 TestResourceDispatcherHostDelegate delegate; |
| 1671 delegate.set_flags(DEFER_STARTING_REQUEST); | 1673 delegate.set_flags(DEFER_STARTING_REQUEST); |
| 1672 delegate.set_url_request_user_data(new TestUserData(&was_deleted)); | 1674 delegate.set_url_request_user_data(new TestUserData(&was_deleted)); |
| 1673 host_.SetDelegate(&delegate); | 1675 host_.SetDelegate(&delegate); |
| 1674 | 1676 |
| 1675 MakeTestRequest(0, 1, net::URLRequestTestJob::test_url_1()); | 1677 MakeTestRequest(0, 1, net::URLRequestTestJob::test_url_1()); |
| 1676 // We cancel from the renderer because all non-renderer cancels delete | 1678 // We cancel from the renderer because all non-renderer cancels delete |
| 1677 // the request synchronously. | 1679 // the request synchronously. |
| 1678 RendererCancelRequest(1); | 1680 RendererCancelRequest(1); |
| 1679 | 1681 |
| 1680 // Our TestResourceThrottle should not have been deleted yet. This is to | 1682 // Our TestResourceThrottle should not have been deleted yet. This is to |
| 1681 // ensure that destruction of the URLRequest happens asynchronously to | 1683 // ensure that destruction of the URLRequest happens asynchronously to |
| 1682 // calling CancelRequest. | 1684 // calling CancelRequest. |
| 1683 EXPECT_FALSE(was_deleted); | 1685 EXPECT_FALSE(was_deleted); |
| 1684 | 1686 |
| 1685 base::RunLoop().RunUntilIdle(); | 1687 content::RunAllBlockingPoolTasksUntilIdle(); |
| 1686 | 1688 |
| 1687 EXPECT_TRUE(was_deleted); | 1689 EXPECT_TRUE(was_deleted); |
| 1688 } | 1690 } |
| 1689 | 1691 |
| 1690 TEST_F(ResourceDispatcherHostTest, DetachWhileStartIsDeferred) { | 1692 TEST_F(ResourceDispatcherHostTest, DetachWhileStartIsDeferred) { |
| 1691 bool was_deleted = false; | 1693 bool was_deleted = false; |
| 1692 | 1694 |
| 1693 // Arrange to have requests deferred before starting. | 1695 // Arrange to have requests deferred before starting. |
| 1694 TestResourceDispatcherHostDelegate delegate; | 1696 TestResourceDispatcherHostDelegate delegate; |
| 1695 delegate.set_flags(DEFER_STARTING_REQUEST); | 1697 delegate.set_flags(DEFER_STARTING_REQUEST); |
| 1696 delegate.set_url_request_user_data(new TestUserData(&was_deleted)); | 1698 delegate.set_url_request_user_data(new TestUserData(&was_deleted)); |
| 1697 host_.SetDelegate(&delegate); | 1699 host_.SetDelegate(&delegate); |
| 1698 | 1700 |
| 1699 MakeTestRequestWithResourceType(filter_.get(), 0, 1, | 1701 MakeTestRequestWithResourceType(filter_.get(), 0, 1, |
| 1700 net::URLRequestTestJob::test_url_1(), | 1702 net::URLRequestTestJob::test_url_1(), |
| 1701 RESOURCE_TYPE_PREFETCH); // detachable type | 1703 RESOURCE_TYPE_PREFETCH); // detachable type |
| 1702 // Cancel request must come from the renderer for a detachable resource to | 1704 // Cancel request must come from the renderer for a detachable resource to |
| 1703 // detach. | 1705 // detach. |
| 1704 RendererCancelRequest(1); | 1706 RendererCancelRequest(1); |
| 1705 | 1707 |
| 1706 // Even after driving the event loop, the request has not been deleted. | 1708 // Even after driving the event loop, the request has not been deleted. |
| 1707 EXPECT_FALSE(was_deleted); | 1709 EXPECT_FALSE(was_deleted); |
| 1708 | 1710 |
| 1709 // However, it is still throttled because the defer happened above the | 1711 // However, it is still throttled because the defer happened above the |
| 1710 // DetachableResourceHandler. | 1712 // DetachableResourceHandler. |
| 1711 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} | 1713 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} |
| 1712 base::RunLoop().RunUntilIdle(); | 1714 content::RunAllBlockingPoolTasksUntilIdle(); |
| 1713 EXPECT_FALSE(was_deleted); | 1715 EXPECT_FALSE(was_deleted); |
| 1714 | 1716 |
| 1715 // Resume the request. | 1717 // Resume the request. |
| 1716 GenericResourceThrottle* throttle = | 1718 GenericResourceThrottle* throttle = |
| 1717 GenericResourceThrottle::active_throttle(); | 1719 GenericResourceThrottle::active_throttle(); |
| 1718 ASSERT_TRUE(throttle); | 1720 ASSERT_TRUE(throttle); |
| 1719 throttle->AssertAndResume(); | 1721 throttle->AssertAndResume(); |
| 1720 | 1722 |
| 1721 // Now, the request completes. | 1723 // Now, the request completes. |
| 1722 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} | 1724 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} |
| 1723 base::RunLoop().RunUntilIdle(); | 1725 content::RunAllBlockingPoolTasksUntilIdle(); |
| 1724 EXPECT_TRUE(was_deleted); | 1726 EXPECT_TRUE(was_deleted); |
| 1725 EXPECT_EQ(1, network_delegate()->completed_requests()); | 1727 EXPECT_EQ(1, network_delegate()->completed_requests()); |
| 1726 EXPECT_EQ(0, network_delegate()->canceled_requests()); | 1728 EXPECT_EQ(0, network_delegate()->canceled_requests()); |
| 1727 EXPECT_EQ(0, network_delegate()->error_count()); | 1729 EXPECT_EQ(0, network_delegate()->error_count()); |
| 1728 } | 1730 } |
| 1729 | 1731 |
| 1730 // Tests if cancel is called in ResourceThrottle::WillStartRequest, then the | 1732 // Tests if cancel is called in ResourceThrottle::WillStartRequest, then the |
| 1731 // URLRequest will not be started. | 1733 // URLRequest will not be started. |
| 1732 TEST_F(ResourceDispatcherHostTest, CancelInResourceThrottleWillStartRequest) { | 1734 TEST_F(ResourceDispatcherHostTest, CancelInResourceThrottleWillStartRequest) { |
| 1733 TestResourceDispatcherHostDelegate delegate; | 1735 TestResourceDispatcherHostDelegate delegate; |
| 1734 delegate.set_flags(CANCEL_BEFORE_START); | 1736 delegate.set_flags(CANCEL_BEFORE_START); |
| 1735 host_.SetDelegate(&delegate); | 1737 host_.SetDelegate(&delegate); |
| 1736 | 1738 |
| 1737 MakeTestRequest(0, 1, net::URLRequestTestJob::test_url_1()); | 1739 MakeTestRequest(0, 1, net::URLRequestTestJob::test_url_1()); |
| 1738 | 1740 |
| 1739 // flush all the pending requests | 1741 // flush all the pending requests |
| 1740 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} | 1742 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} |
| 1741 base::RunLoop().RunUntilIdle(); | 1743 content::RunAllBlockingPoolTasksUntilIdle(); |
| 1742 | 1744 |
| 1743 ResourceIPCAccumulator::ClassifiedMessages msgs; | 1745 ResourceIPCAccumulator::ClassifiedMessages msgs; |
| 1744 accum_.GetClassifiedMessages(&msgs); | 1746 accum_.GetClassifiedMessages(&msgs); |
| 1745 | 1747 |
| 1746 // Check that request got canceled. | 1748 // Check that request got canceled. |
| 1747 ASSERT_EQ(1U, msgs[0].size()); | 1749 ASSERT_EQ(1U, msgs[0].size()); |
| 1748 CheckRequestCompleteErrorCode(msgs[0][0], net::ERR_ABORTED); | 1750 CheckRequestCompleteErrorCode(msgs[0][0], net::ERR_ABORTED); |
| 1749 | 1751 |
| 1750 // Make sure URLRequest is never started. | 1752 // Make sure URLRequest is never started. |
| 1751 EXPECT_EQ(0, job_factory_->url_request_jobs_created_count()); | 1753 EXPECT_EQ(0, job_factory_->url_request_jobs_created_count()); |
| 1752 } | 1754 } |
| 1753 | 1755 |
| 1754 TEST_F(ResourceDispatcherHostTest, PausedStartError) { | 1756 TEST_F(ResourceDispatcherHostTest, PausedStartError) { |
| 1755 // Arrange to have requests deferred before processing response headers. | 1757 // Arrange to have requests deferred before processing response headers. |
| 1756 TestResourceDispatcherHostDelegate delegate; | 1758 TestResourceDispatcherHostDelegate delegate; |
| 1757 delegate.set_flags(DEFER_PROCESSING_RESPONSE); | 1759 delegate.set_flags(DEFER_PROCESSING_RESPONSE); |
| 1758 host_.SetDelegate(&delegate); | 1760 host_.SetDelegate(&delegate); |
| 1759 | 1761 |
| 1760 job_factory_->SetDelayedStartJobGeneration(true); | 1762 job_factory_->SetDelayedStartJobGeneration(true); |
| 1761 MakeTestRequest(0, 1, net::URLRequestTestJob::test_url_error()); | 1763 MakeTestRequest(0, 1, net::URLRequestTestJob::test_url_error()); |
| 1762 CompleteStartRequest(1); | 1764 CompleteStartRequest(1); |
| 1763 | 1765 |
| 1764 // flush all the pending requests | 1766 // flush all the pending requests |
| 1765 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} | 1767 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} |
| 1766 base::RunLoop().RunUntilIdle(); | 1768 content::RunAllBlockingPoolTasksUntilIdle(); |
| 1767 | 1769 |
| 1768 EXPECT_EQ(0, host_.pending_requests()); | 1770 EXPECT_EQ(0, host_.pending_requests()); |
| 1769 } | 1771 } |
| 1770 | 1772 |
| 1771 TEST_F(ResourceDispatcherHostTest, ThrottleAndResumeTwice) { | 1773 TEST_F(ResourceDispatcherHostTest, ThrottleAndResumeTwice) { |
| 1772 // Arrange to have requests deferred before starting. | 1774 // Arrange to have requests deferred before starting. |
| 1773 TestResourceDispatcherHostDelegate delegate; | 1775 TestResourceDispatcherHostDelegate delegate; |
| 1774 delegate.set_flags(DEFER_STARTING_REQUEST); | 1776 delegate.set_flags(DEFER_STARTING_REQUEST); |
| 1775 delegate.set_create_two_throttles(true); | 1777 delegate.set_create_two_throttles(true); |
| 1776 host_.SetDelegate(&delegate); | 1778 host_.SetDelegate(&delegate); |
| 1777 | 1779 |
| 1778 // Make sure the first throttle blocked the request, and then resume. | 1780 // Make sure the first throttle blocked the request, and then resume. |
| 1779 MakeTestRequest(0, 1, net::URLRequestTestJob::test_url_1()); | 1781 MakeTestRequest(0, 1, net::URLRequestTestJob::test_url_1()); |
| 1780 GenericResourceThrottle* first_throttle = | 1782 GenericResourceThrottle* first_throttle = |
| 1781 GenericResourceThrottle::active_throttle(); | 1783 GenericResourceThrottle::active_throttle(); |
| 1782 ASSERT_TRUE(first_throttle); | 1784 ASSERT_TRUE(first_throttle); |
| 1783 first_throttle->AssertAndResume(); | 1785 first_throttle->AssertAndResume(); |
| 1784 | 1786 |
| 1785 // Make sure the second throttle blocked the request, and then resume. | 1787 // Make sure the second throttle blocked the request, and then resume. |
| 1786 ASSERT_TRUE(GenericResourceThrottle::active_throttle()); | 1788 ASSERT_TRUE(GenericResourceThrottle::active_throttle()); |
| 1787 ASSERT_NE(first_throttle, GenericResourceThrottle::active_throttle()); | 1789 ASSERT_NE(first_throttle, GenericResourceThrottle::active_throttle()); |
| 1788 GenericResourceThrottle::active_throttle()->AssertAndResume(); | 1790 GenericResourceThrottle::active_throttle()->AssertAndResume(); |
| 1789 | 1791 |
| 1790 ASSERT_FALSE(GenericResourceThrottle::active_throttle()); | 1792 ASSERT_FALSE(GenericResourceThrottle::active_throttle()); |
| 1791 | 1793 |
| 1792 // The request is started asynchronously. | 1794 // The request is started asynchronously. |
| 1793 base::RunLoop().RunUntilIdle(); | 1795 content::RunAllBlockingPoolTasksUntilIdle(); |
| 1794 | 1796 |
| 1795 // Flush all the pending requests. | 1797 // Flush all the pending requests. |
| 1796 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} | 1798 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} |
| 1797 | 1799 |
| 1798 EXPECT_EQ(0, host_.pending_requests()); | 1800 EXPECT_EQ(0, host_.pending_requests()); |
| 1799 | 1801 |
| 1800 // Make sure the request completed successfully. | 1802 // Make sure the request completed successfully. |
| 1801 ResourceIPCAccumulator::ClassifiedMessages msgs; | 1803 ResourceIPCAccumulator::ClassifiedMessages msgs; |
| 1802 accum_.GetClassifiedMessages(&msgs); | 1804 accum_.GetClassifiedMessages(&msgs); |
| 1803 ASSERT_EQ(1U, msgs.size()); | 1805 ASSERT_EQ(1U, msgs.size()); |
| 1804 CheckSuccessfulRequest(msgs[0], net::URLRequestTestJob::test_data_1()); | 1806 CheckSuccessfulRequest(msgs[0], net::URLRequestTestJob::test_data_1()); |
| 1805 } | 1807 } |
| 1806 | 1808 |
| 1807 | 1809 |
| 1808 // Tests that the delegate can cancel a request and provide a error code. | 1810 // Tests that the delegate can cancel a request and provide a error code. |
| 1809 TEST_F(ResourceDispatcherHostTest, CancelInDelegate) { | 1811 TEST_F(ResourceDispatcherHostTest, CancelInDelegate) { |
| 1810 TestResourceDispatcherHostDelegate delegate; | 1812 TestResourceDispatcherHostDelegate delegate; |
| 1811 delegate.set_flags(CANCEL_BEFORE_START); | 1813 delegate.set_flags(CANCEL_BEFORE_START); |
| 1812 delegate.set_error_code_for_cancellation(net::ERR_ACCESS_DENIED); | 1814 delegate.set_error_code_for_cancellation(net::ERR_ACCESS_DENIED); |
| 1813 host_.SetDelegate(&delegate); | 1815 host_.SetDelegate(&delegate); |
| 1814 | 1816 |
| 1815 MakeTestRequest(0, 1, net::URLRequestTestJob::test_url_1()); | 1817 MakeTestRequest(0, 1, net::URLRequestTestJob::test_url_1()); |
| 1816 // The request will get cancelled by the throttle. | 1818 // The request will get cancelled by the throttle. |
| 1817 | 1819 |
| 1818 // flush all the pending requests | 1820 // flush all the pending requests |
| 1819 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} | 1821 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} |
| 1820 base::RunLoop().RunUntilIdle(); | 1822 content::RunAllBlockingPoolTasksUntilIdle(); |
| 1821 | 1823 |
| 1822 ResourceIPCAccumulator::ClassifiedMessages msgs; | 1824 ResourceIPCAccumulator::ClassifiedMessages msgs; |
| 1823 accum_.GetClassifiedMessages(&msgs); | 1825 accum_.GetClassifiedMessages(&msgs); |
| 1824 | 1826 |
| 1825 // Check the cancellation | 1827 // Check the cancellation |
| 1826 ASSERT_EQ(1U, msgs.size()); | 1828 ASSERT_EQ(1U, msgs.size()); |
| 1827 ASSERT_EQ(1U, msgs[0].size()); | 1829 ASSERT_EQ(1U, msgs[0].size()); |
| 1828 | 1830 |
| 1829 CheckRequestCompleteErrorCode(msgs[0][0], net::ERR_ACCESS_DENIED); | 1831 CheckRequestCompleteErrorCode(msgs[0][0], net::ERR_ACCESS_DENIED); |
| 1830 } | 1832 } |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1849 RESOURCE_TYPE_SUB_RESOURCE); | 1851 RESOURCE_TYPE_SUB_RESOURCE); |
| 1850 | 1852 |
| 1851 // request 4 goes to us | 1853 // request 4 goes to us |
| 1852 MakeTestRequestWithResourceType(filter_.get(), 0, 4, | 1854 MakeTestRequestWithResourceType(filter_.get(), 0, 4, |
| 1853 net::URLRequestTestJob::test_url_4(), | 1855 net::URLRequestTestJob::test_url_4(), |
| 1854 RESOURCE_TYPE_PREFETCH); // detachable type | 1856 RESOURCE_TYPE_PREFETCH); // detachable type |
| 1855 | 1857 |
| 1856 | 1858 |
| 1857 // Make sure all requests have finished stage one. test_url_1 will have | 1859 // Make sure all requests have finished stage one. test_url_1 will have |
| 1858 // finished. | 1860 // finished. |
| 1859 base::RunLoop().RunUntilIdle(); | 1861 content::RunAllBlockingPoolTasksUntilIdle(); |
| 1860 | 1862 |
| 1861 // TODO(mbelshe): | 1863 // TODO(mbelshe): |
| 1862 // Now that the async IO path is in place, the IO always completes on the | 1864 // Now that the async IO path is in place, the IO always completes on the |
| 1863 // initial call; so the requests have already completed. This basically | 1865 // initial call; so the requests have already completed. This basically |
| 1864 // breaks the whole test. | 1866 // breaks the whole test. |
| 1865 // EXPECT_EQ(3, host_.pending_requests()); | 1867 // EXPECT_EQ(3, host_.pending_requests()); |
| 1866 | 1868 |
| 1867 // Process test_url_2 and test_url_3 for one level so one callback is called. | 1869 // Process test_url_2 and test_url_3 for one level so one callback is called. |
| 1868 // We'll cancel test_url_4 (detachable) before processing it to verify that it | 1870 // We'll cancel test_url_4 (detachable) before processing it to verify that it |
| 1869 // delays the cancel. | 1871 // delays the cancel. |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1941 KickOffRequest(); | 1943 KickOffRequest(); |
| 1942 EXPECT_EQ(3, network_delegate_.created_requests()); | 1944 EXPECT_EQ(3, network_delegate_.created_requests()); |
| 1943 EXPECT_EQ(0, network_delegate_.canceled_requests()); | 1945 EXPECT_EQ(0, network_delegate_.canceled_requests()); |
| 1944 | 1946 |
| 1945 // The first two RenderFrameHosts are destroyed. All 4 of their requests | 1947 // The first two RenderFrameHosts are destroyed. All 4 of their requests |
| 1946 // should be cancelled, and none of the two deferred requests should be | 1948 // should be cancelled, and none of the two deferred requests should be |
| 1947 // started. | 1949 // started. |
| 1948 DeleteRenderFrame(GlobalFrameRoutingId(filter_->child_id(), 10)); | 1950 DeleteRenderFrame(GlobalFrameRoutingId(filter_->child_id(), 10)); |
| 1949 DeleteRenderFrame(GlobalFrameRoutingId(filter_->child_id(), 11)); | 1951 DeleteRenderFrame(GlobalFrameRoutingId(filter_->child_id(), 11)); |
| 1950 host_.OnRenderViewHostDeleted(filter_->child_id(), 0); | 1952 host_.OnRenderViewHostDeleted(filter_->child_id(), 0); |
| 1951 base::RunLoop().RunUntilIdle(); | 1953 content::RunAllBlockingPoolTasksUntilIdle(); |
| 1952 EXPECT_EQ(3, network_delegate_.created_requests()); | 1954 EXPECT_EQ(3, network_delegate_.created_requests()); |
| 1953 EXPECT_EQ(4, network_delegate_.canceled_requests()); | 1955 EXPECT_EQ(4, network_delegate_.canceled_requests()); |
| 1954 | 1956 |
| 1955 // No messages should have been sent, since none of the jobs made any | 1957 // No messages should have been sent, since none of the jobs made any |
| 1956 // progress. | 1958 // progress. |
| 1957 ResourceIPCAccumulator::ClassifiedMessages msgs; | 1959 ResourceIPCAccumulator::ClassifiedMessages msgs; |
| 1958 accum_.GetClassifiedMessages(&msgs); | 1960 accum_.GetClassifiedMessages(&msgs); |
| 1959 EXPECT_EQ(0U, msgs.size()); | 1961 EXPECT_EQ(0U, msgs.size()); |
| 1960 } | 1962 } |
| 1961 | 1963 |
| 1962 TEST_F(ResourceDispatcherHostTest, TestProcessCancelDetachedTimesOut) { | 1964 TEST_F(ResourceDispatcherHostTest, TestProcessCancelDetachedTimesOut) { |
| 1963 MakeTestRequestWithResourceType(filter_.get(), 0, 1, | 1965 MakeTestRequestWithResourceType(filter_.get(), 0, 1, |
| 1964 net::URLRequestTestJob::test_url_4(), | 1966 net::URLRequestTestJob::test_url_4(), |
| 1965 RESOURCE_TYPE_PREFETCH); // detachable type | 1967 RESOURCE_TYPE_PREFETCH); // detachable type |
| 1966 GlobalRequestID global_request_id(filter_->child_id(), 1); | 1968 GlobalRequestID global_request_id(filter_->child_id(), 1); |
| 1967 ResourceRequestInfoImpl* info = ResourceRequestInfoImpl::ForRequest( | 1969 ResourceRequestInfoImpl* info = ResourceRequestInfoImpl::ForRequest( |
| 1968 host_.GetURLRequest(global_request_id)); | 1970 host_.GetURLRequest(global_request_id)); |
| 1969 ASSERT_TRUE(info->detachable_handler()); | 1971 ASSERT_TRUE(info->detachable_handler()); |
| 1970 info->detachable_handler()->set_cancel_delay( | 1972 info->detachable_handler()->set_cancel_delay( |
| 1971 base::TimeDelta::FromMilliseconds(200)); | 1973 base::TimeDelta::FromMilliseconds(200)); |
| 1972 base::RunLoop().RunUntilIdle(); | 1974 content::RunAllBlockingPoolTasksUntilIdle(); |
| 1973 | 1975 |
| 1974 // Cancel the requests to the test process. | 1976 // Cancel the requests to the test process. |
| 1975 host_.CancelRequestsForProcess(filter_->child_id()); | 1977 host_.CancelRequestsForProcess(filter_->child_id()); |
| 1976 EXPECT_EQ(1, host_.pending_requests()); | 1978 EXPECT_EQ(1, host_.pending_requests()); |
| 1977 | 1979 |
| 1978 // Wait until after the delay timer times out before we start processing any | 1980 // Wait until after the delay timer times out before we start processing any |
| 1979 // messages. | 1981 // messages. |
| 1980 base::OneShotTimer timer; | 1982 base::OneShotTimer timer; |
| 1981 timer.Start(FROM_HERE, base::TimeDelta::FromMilliseconds(210), | 1983 timer.Start(FROM_HERE, base::TimeDelta::FromMilliseconds(210), |
| 1982 base::MessageLoop::current(), &base::MessageLoop::QuitWhenIdle); | 1984 base::MessageLoop::current(), &base::MessageLoop::QuitWhenIdle); |
| 1983 base::RunLoop().Run(); | 1985 base::RunLoop().Run(); |
| 1984 | 1986 |
| 1985 // The prefetch should be cancelled by now. | 1987 // The prefetch should be cancelled by now. |
| 1986 EXPECT_EQ(0, host_.pending_requests()); | 1988 EXPECT_EQ(0, host_.pending_requests()); |
| 1987 | 1989 |
| 1988 // In case any messages are still to be processed. | 1990 // In case any messages are still to be processed. |
| 1989 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} | 1991 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} |
| 1990 base::RunLoop().RunUntilIdle(); | 1992 content::RunAllBlockingPoolTasksUntilIdle(); |
| 1991 | 1993 |
| 1992 ResourceIPCAccumulator::ClassifiedMessages msgs; | 1994 ResourceIPCAccumulator::ClassifiedMessages msgs; |
| 1993 accum_.GetClassifiedMessages(&msgs); | 1995 accum_.GetClassifiedMessages(&msgs); |
| 1994 | 1996 |
| 1995 ASSERT_EQ(1U, msgs.size()); | 1997 ASSERT_EQ(1U, msgs.size()); |
| 1996 | 1998 |
| 1997 // The request should have cancelled. | 1999 // The request should have cancelled. |
| 1998 ASSERT_EQ(2U, msgs[0].size()); | 2000 ASSERT_EQ(2U, msgs[0].size()); |
| 1999 ASSERT_EQ(ResourceMsg_ReceivedResponse::ID, msgs[0][0].type()); | 2001 ASSERT_EQ(ResourceMsg_ReceivedResponse::ID, msgs[0][0].type()); |
| 2000 CheckRequestCompleteErrorCode(msgs[0][1], net::ERR_ABORTED); | 2002 CheckRequestCompleteErrorCode(msgs[0][1], net::ERR_ABORTED); |
| (...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2272 // it is just process 0 that is saturated. | 2274 // it is just process 0 that is saturated. |
| 2273 MakeTestRequestWithResourceType(second_filter.get(), 0, kMaxRequests + 3, | 2275 MakeTestRequestWithResourceType(second_filter.get(), 0, kMaxRequests + 3, |
| 2274 net::URLRequestTestJob::test_url_2(), | 2276 net::URLRequestTestJob::test_url_2(), |
| 2275 RESOURCE_TYPE_SUB_RESOURCE); | 2277 RESOURCE_TYPE_SUB_RESOURCE); |
| 2276 MakeTestRequestWithResourceType(second_filter.get(), 0, kMaxRequests + 4, | 2278 MakeTestRequestWithResourceType(second_filter.get(), 0, kMaxRequests + 4, |
| 2277 net::URLRequestTestJob::test_url_2(), | 2279 net::URLRequestTestJob::test_url_2(), |
| 2278 RESOURCE_TYPE_SUB_RESOURCE); | 2280 RESOURCE_TYPE_SUB_RESOURCE); |
| 2279 | 2281 |
| 2280 // Flush all the pending requests. | 2282 // Flush all the pending requests. |
| 2281 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} | 2283 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} |
| 2282 base::RunLoop().RunUntilIdle(); | 2284 content::RunAllBlockingPoolTasksUntilIdle(); |
| 2283 | 2285 |
| 2284 // Sorts out all the messages we saw by request. | 2286 // Sorts out all the messages we saw by request. |
| 2285 ResourceIPCAccumulator::ClassifiedMessages msgs; | 2287 ResourceIPCAccumulator::ClassifiedMessages msgs; |
| 2286 accum_.GetClassifiedMessages(&msgs); | 2288 accum_.GetClassifiedMessages(&msgs); |
| 2287 | 2289 |
| 2288 // We issued (kMaxRequests + 4) total requests. | 2290 // We issued (kMaxRequests + 4) total requests. |
| 2289 ASSERT_EQ(kMaxRequests + 4, msgs.size()); | 2291 ASSERT_EQ(kMaxRequests + 4, msgs.size()); |
| 2290 | 2292 |
| 2291 // Check that the first kMaxRequests succeeded. | 2293 // Check that the first kMaxRequests succeeded. |
| 2292 for (size_t i = 0; i < kMaxRequests; ++i) | 2294 for (size_t i = 0; i < kMaxRequests; ++i) |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2343 net::URLRequestTestJob::test_url_2(), RESOURCE_TYPE_SUB_RESOURCE); | 2345 net::URLRequestTestJob::test_url_2(), RESOURCE_TYPE_SUB_RESOURCE); |
| 2344 | 2346 |
| 2345 // Issue a request for the third process -- this should fail, because the | 2347 // Issue a request for the third process -- this should fail, because the |
| 2346 // global limit has been reached. | 2348 // global limit has been reached. |
| 2347 MakeTestRequestWithResourceType( | 2349 MakeTestRequestWithResourceType( |
| 2348 third_filter.get(), 0, kMaxRequestsPerProcess + 3, | 2350 third_filter.get(), 0, kMaxRequestsPerProcess + 3, |
| 2349 net::URLRequestTestJob::test_url_2(), RESOURCE_TYPE_SUB_RESOURCE); | 2351 net::URLRequestTestJob::test_url_2(), RESOURCE_TYPE_SUB_RESOURCE); |
| 2350 | 2352 |
| 2351 // Flush all the pending requests. | 2353 // Flush all the pending requests. |
| 2352 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} | 2354 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} |
| 2353 base::RunLoop().RunUntilIdle(); | 2355 content::RunAllBlockingPoolTasksUntilIdle(); |
| 2354 | 2356 |
| 2355 // Sorts out all the messages we saw by request. | 2357 // Sorts out all the messages we saw by request. |
| 2356 ResourceIPCAccumulator::ClassifiedMessages msgs; | 2358 ResourceIPCAccumulator::ClassifiedMessages msgs; |
| 2357 accum_.GetClassifiedMessages(&msgs); | 2359 accum_.GetClassifiedMessages(&msgs); |
| 2358 | 2360 |
| 2359 // The processes issued the following requests: | 2361 // The processes issued the following requests: |
| 2360 // #1 issued kMaxRequestsPerProcess that passed + 1 that failed | 2362 // #1 issued kMaxRequestsPerProcess that passed + 1 that failed |
| 2361 // #2 issued 1 request that passed | 2363 // #2 issued 1 request that passed |
| 2362 // #3 issued 1 request that failed | 2364 // #3 issued 1 request that failed |
| 2363 ASSERT_EQ((kMaxRequestsPerProcess + 1) + 1 + 1, msgs.size()); | 2365 ASSERT_EQ((kMaxRequestsPerProcess + 1) + 1 + 1, msgs.size()); |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2532 SetResponse(raw_headers, response_data); | 2534 SetResponse(raw_headers, response_data); |
| 2533 job_factory_->SetDelayedCompleteJobGeneration(true); | 2535 job_factory_->SetDelayedCompleteJobGeneration(true); |
| 2534 HandleScheme("http"); | 2536 HandleScheme("http"); |
| 2535 | 2537 |
| 2536 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id, | 2538 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id, |
| 2537 GURL("http://example.com/blah"), | 2539 GURL("http://example.com/blah"), |
| 2538 RESOURCE_TYPE_MAIN_FRAME); | 2540 RESOURCE_TYPE_MAIN_FRAME); |
| 2539 // Return some data so that the request is identified as a download | 2541 // Return some data so that the request is identified as a download |
| 2540 // and the proper resource handlers are created. | 2542 // and the proper resource handlers are created. |
| 2541 EXPECT_TRUE(net::URLRequestTestJob::ProcessOnePendingMessage()); | 2543 EXPECT_TRUE(net::URLRequestTestJob::ProcessOnePendingMessage()); |
| 2542 base::RunLoop().RunUntilIdle(); | 2544 content::RunAllBlockingPoolTasksUntilIdle(); |
| 2543 | 2545 |
| 2544 // And now simulate a cancellation coming from the renderer. | 2546 // And now simulate a cancellation coming from the renderer. |
| 2545 ResourceHostMsg_CancelRequest msg(request_id); | 2547 ResourceHostMsg_CancelRequest msg(request_id); |
| 2546 OnMessageReceived(msg, filter_.get()); | 2548 OnMessageReceived(msg, filter_.get()); |
| 2547 | 2549 |
| 2548 // Since the request had already started processing as a download, | 2550 // Since the request had already started processing as a download, |
| 2549 // the cancellation above should have been ignored and the request | 2551 // the cancellation above should have been ignored and the request |
| 2550 // should still be alive. | 2552 // should still be alive. |
| 2551 EXPECT_EQ(1, host_.pending_requests()); | 2553 EXPECT_EQ(1, host_.pending_requests()); |
| 2552 | 2554 |
| 2553 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} | 2555 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} |
| 2554 base::RunLoop().RunUntilIdle(); | 2556 content::RunAllBlockingPoolTasksUntilIdle(); |
| 2555 } | 2557 } |
| 2556 | 2558 |
| 2557 TEST_F(ResourceDispatcherHostTest, CancelRequestsForContext) { | 2559 TEST_F(ResourceDispatcherHostTest, CancelRequestsForContext) { |
| 2558 EXPECT_EQ(0, host_.pending_requests()); | 2560 EXPECT_EQ(0, host_.pending_requests()); |
| 2559 NavigationResourceThrottle::set_ui_checks_always_succeed_for_testing(true); | 2561 NavigationResourceThrottle::set_ui_checks_always_succeed_for_testing(true); |
| 2560 | 2562 |
| 2561 int render_view_id = 0; | 2563 int render_view_id = 0; |
| 2562 int request_id = 1; | 2564 int request_id = 1; |
| 2563 | 2565 |
| 2564 std::string raw_headers("HTTP\n" | 2566 std::string raw_headers("HTTP\n" |
| (...skipping 27 matching lines...) Expand all Loading... |
| 2592 browser_context_->GetResourceContext(), | 2594 browser_context_->GetResourceContext(), |
| 2593 BrowserContext::GetDefaultStoragePartition(browser_context_.get()), | 2595 BrowserContext::GetDefaultStoragePartition(browser_context_.get()), |
| 2594 std::move(request_info), nullptr, nullptr, nullptr, &delegate); | 2596 std::move(request_info), nullptr, nullptr, nullptr, &delegate); |
| 2595 | 2597 |
| 2596 // Wait until a response has been received and proceed with the response. | 2598 // Wait until a response has been received and proceed with the response. |
| 2597 KickOffRequest(); | 2599 KickOffRequest(); |
| 2598 | 2600 |
| 2599 // Return some data so that the request is identified as a download | 2601 // Return some data so that the request is identified as a download |
| 2600 // and the proper resource handlers are created. | 2602 // and the proper resource handlers are created. |
| 2601 EXPECT_TRUE(net::URLRequestTestJob::ProcessOnePendingMessage()); | 2603 EXPECT_TRUE(net::URLRequestTestJob::ProcessOnePendingMessage()); |
| 2602 base::RunLoop().RunUntilIdle(); | 2604 content::RunAllBlockingPoolTasksUntilIdle(); |
| 2603 | 2605 |
| 2604 // The UI thread will be informed that the navigation failed with an error | 2606 // The UI thread will be informed that the navigation failed with an error |
| 2605 // code of ERR_ABORTED because the navigation turns out to be a download. | 2607 // code of ERR_ABORTED because the navigation turns out to be a download. |
| 2606 // The navigation is aborted, but the request goes on as a download. | 2608 // The navigation is aborted, but the request goes on as a download. |
| 2607 EXPECT_EQ(delegate.net_error(), net::ERR_ABORTED); | 2609 EXPECT_EQ(delegate.net_error(), net::ERR_ABORTED); |
| 2608 EXPECT_EQ(1, host_.pending_requests()); | 2610 EXPECT_EQ(1, host_.pending_requests()); |
| 2609 | 2611 |
| 2610 // In PlzNavigate, the renderer cannot cancel the request directly. | 2612 // In PlzNavigate, the renderer cannot cancel the request directly. |
| 2611 // However, cancelling by context should work. | 2613 // However, cancelling by context should work. |
| 2612 host_.CancelRequestsForContext(browser_context_->GetResourceContext()); | 2614 host_.CancelRequestsForContext(browser_context_->GetResourceContext()); |
| 2613 EXPECT_EQ(0, host_.pending_requests()); | 2615 EXPECT_EQ(0, host_.pending_requests()); |
| 2614 | 2616 |
| 2615 base::RunLoop().RunUntilIdle(); | 2617 content::RunAllBlockingPoolTasksUntilIdle(); |
| 2616 } else { | 2618 } else { |
| 2617 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id, | 2619 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id, |
| 2618 download_url, RESOURCE_TYPE_MAIN_FRAME); | 2620 download_url, RESOURCE_TYPE_MAIN_FRAME); |
| 2619 | 2621 |
| 2620 // Return some data so that the request is identified as a download | 2622 // Return some data so that the request is identified as a download |
| 2621 // and the proper resource handlers are created. | 2623 // and the proper resource handlers are created. |
| 2622 EXPECT_TRUE(net::URLRequestTestJob::ProcessOnePendingMessage()); | 2624 EXPECT_TRUE(net::URLRequestTestJob::ProcessOnePendingMessage()); |
| 2623 base::RunLoop().RunUntilIdle(); | 2625 content::RunAllBlockingPoolTasksUntilIdle(); |
| 2624 | 2626 |
| 2625 // And now simulate a cancellation coming from the renderer. | 2627 // And now simulate a cancellation coming from the renderer. |
| 2626 ResourceHostMsg_CancelRequest msg(request_id); | 2628 ResourceHostMsg_CancelRequest msg(request_id); |
| 2627 OnMessageReceived(msg, filter_.get()); | 2629 OnMessageReceived(msg, filter_.get()); |
| 2628 | 2630 |
| 2629 // Since the request had already started processing as a download, | 2631 // Since the request had already started processing as a download, |
| 2630 // the cancellation above should have been ignored and the request | 2632 // the cancellation above should have been ignored and the request |
| 2631 // should still be alive. | 2633 // should still be alive. |
| 2632 EXPECT_EQ(1, host_.pending_requests()); | 2634 EXPECT_EQ(1, host_.pending_requests()); |
| 2633 | 2635 |
| 2634 // Cancelling by other methods shouldn't work either. | 2636 // Cancelling by other methods shouldn't work either. |
| 2635 host_.CancelRequestsForProcess(render_view_id); | 2637 host_.CancelRequestsForProcess(render_view_id); |
| 2636 EXPECT_EQ(1, host_.pending_requests()); | 2638 EXPECT_EQ(1, host_.pending_requests()); |
| 2637 | 2639 |
| 2638 // Cancelling by context should work. | 2640 // Cancelling by context should work. |
| 2639 host_.CancelRequestsForContext(filter_->resource_context()); | 2641 host_.CancelRequestsForContext(filter_->resource_context()); |
| 2640 EXPECT_EQ(0, host_.pending_requests()); | 2642 EXPECT_EQ(0, host_.pending_requests()); |
| 2641 | 2643 |
| 2642 while (net::URLRequestTestJob::ProcessOnePendingMessage()) { | 2644 while (net::URLRequestTestJob::ProcessOnePendingMessage()) { |
| 2643 } | 2645 } |
| 2644 base::RunLoop().RunUntilIdle(); | 2646 content::RunAllBlockingPoolTasksUntilIdle(); |
| 2645 } | 2647 } |
| 2646 } | 2648 } |
| 2647 | 2649 |
| 2648 TEST_F(ResourceDispatcherHostTest, CancelRequestsForContextDetached) { | 2650 TEST_F(ResourceDispatcherHostTest, CancelRequestsForContextDetached) { |
| 2649 EXPECT_EQ(0, host_.pending_requests()); | 2651 EXPECT_EQ(0, host_.pending_requests()); |
| 2650 | 2652 |
| 2651 int render_view_id = 0; | 2653 int render_view_id = 0; |
| 2652 int request_id = 1; | 2654 int request_id = 1; |
| 2653 | 2655 |
| 2654 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id, | 2656 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id, |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2745 RESOURCE_TYPE_MAIN_FRAME); | 2747 RESOURCE_TYPE_MAIN_FRAME); |
| 2746 | 2748 |
| 2747 // Now that we're blocked on the redirect, update the response and unblock by | 2749 // Now that we're blocked on the redirect, update the response and unblock by |
| 2748 // telling the AsyncResourceHandler to follow the redirect. | 2750 // telling the AsyncResourceHandler to follow the redirect. |
| 2749 const std::string kResponseBody = "hello world"; | 2751 const std::string kResponseBody = "hello world"; |
| 2750 SetResponse("HTTP/1.1 200 OK\n" | 2752 SetResponse("HTTP/1.1 200 OK\n" |
| 2751 "Content-Type: text/html\n\n", | 2753 "Content-Type: text/html\n\n", |
| 2752 kResponseBody); | 2754 kResponseBody); |
| 2753 ResourceHostMsg_FollowRedirect redirect_msg(request_id); | 2755 ResourceHostMsg_FollowRedirect redirect_msg(request_id); |
| 2754 OnMessageReceived(redirect_msg, filter_.get()); | 2756 OnMessageReceived(redirect_msg, filter_.get()); |
| 2755 base::RunLoop().RunUntilIdle(); | 2757 content::RunAllBlockingPoolTasksUntilIdle(); |
| 2756 | 2758 |
| 2757 // Flush all the pending requests to get the response through the | 2759 // Flush all the pending requests to get the response through the |
| 2758 // MimeTypeResourceHandler. | 2760 // MimeTypeResourceHandler. |
| 2759 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} | 2761 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} |
| 2760 | 2762 |
| 2761 // This second filter is used to emulate a second process. | 2763 // This second filter is used to emulate a second process. |
| 2762 scoped_refptr<ForwardingFilter> second_filter = MakeForwardingFilter(); | 2764 scoped_refptr<ForwardingFilter> second_filter = MakeForwardingFilter(); |
| 2763 | 2765 |
| 2764 int new_render_view_id = 1; | 2766 int new_render_view_id = 1; |
| 2765 int new_request_id = 2; | 2767 int new_request_id = 2; |
| 2766 | 2768 |
| 2767 ResourceRequest request = CreateResourceRequest( | 2769 ResourceRequest request = CreateResourceRequest( |
| 2768 "GET", RESOURCE_TYPE_MAIN_FRAME, GURL("http://other.com/blech")); | 2770 "GET", RESOURCE_TYPE_MAIN_FRAME, GURL("http://other.com/blech")); |
| 2769 request.transferred_request_child_id = filter_->child_id(); | 2771 request.transferred_request_child_id = filter_->child_id(); |
| 2770 request.transferred_request_request_id = request_id; | 2772 request.transferred_request_request_id = request_id; |
| 2771 | 2773 |
| 2772 ResourceHostMsg_RequestResource transfer_request_msg( | 2774 ResourceHostMsg_RequestResource transfer_request_msg( |
| 2773 new_render_view_id, new_request_id, request); | 2775 new_render_view_id, new_request_id, request); |
| 2774 OnMessageReceived(transfer_request_msg, second_filter.get()); | 2776 OnMessageReceived(transfer_request_msg, second_filter.get()); |
| 2775 base::RunLoop().RunUntilIdle(); | 2777 content::RunAllBlockingPoolTasksUntilIdle(); |
| 2776 | 2778 |
| 2777 // Check generated messages. | 2779 // Check generated messages. |
| 2778 ResourceIPCAccumulator::ClassifiedMessages msgs; | 2780 ResourceIPCAccumulator::ClassifiedMessages msgs; |
| 2779 accum_.GetClassifiedMessages(&msgs); | 2781 accum_.GetClassifiedMessages(&msgs); |
| 2780 | 2782 |
| 2781 ASSERT_EQ(2U, msgs.size()); | 2783 ASSERT_EQ(2U, msgs.size()); |
| 2782 EXPECT_EQ(ResourceMsg_ReceivedRedirect::ID, msgs[0][0].type()); | 2784 EXPECT_EQ(ResourceMsg_ReceivedRedirect::ID, msgs[0][0].type()); |
| 2783 CheckSuccessfulRequest(msgs[1], kResponseBody); | 2785 CheckSuccessfulRequest(msgs[1], kResponseBody); |
| 2784 | 2786 |
| 2785 second_filter->OnChannelClosing(); | 2787 second_filter->OnChannelClosing(); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2834 int new_render_view_id = 1; | 2836 int new_render_view_id = 1; |
| 2835 int new_request_id = 5; | 2837 int new_request_id = 5; |
| 2836 ResourceRequest request = CreateResourceRequest( | 2838 ResourceRequest request = CreateResourceRequest( |
| 2837 "GET", RESOURCE_TYPE_MAIN_FRAME, GURL("http://example.com/blah")); | 2839 "GET", RESOURCE_TYPE_MAIN_FRAME, GURL("http://example.com/blah")); |
| 2838 request.transferred_request_child_id = filter_->child_id(); | 2840 request.transferred_request_child_id = filter_->child_id(); |
| 2839 request.transferred_request_request_id = request_id; | 2841 request.transferred_request_request_id = request_id; |
| 2840 | 2842 |
| 2841 ResourceHostMsg_RequestResource transfer_request_msg( | 2843 ResourceHostMsg_RequestResource transfer_request_msg( |
| 2842 new_render_view_id, new_request_id, request); | 2844 new_render_view_id, new_request_id, request); |
| 2843 OnMessageReceived(transfer_request_msg, second_filter.get()); | 2845 OnMessageReceived(transfer_request_msg, second_filter.get()); |
| 2844 base::RunLoop().RunUntilIdle(); | 2846 content::RunAllBlockingPoolTasksUntilIdle(); |
| 2845 | 2847 |
| 2846 // Transfer the second request. | 2848 // Transfer the second request. |
| 2847 int new_second_request_id = 6; | 2849 int new_second_request_id = 6; |
| 2848 ResourceRequest second_request = CreateResourceRequest( | 2850 ResourceRequest second_request = CreateResourceRequest( |
| 2849 "GET", RESOURCE_TYPE_MAIN_FRAME, GURL("http://example.com/foo")); | 2851 "GET", RESOURCE_TYPE_MAIN_FRAME, GURL("http://example.com/foo")); |
| 2850 request.transferred_request_child_id = filter_->child_id(); | 2852 request.transferred_request_child_id = filter_->child_id(); |
| 2851 request.transferred_request_request_id = second_request_id; | 2853 request.transferred_request_request_id = second_request_id; |
| 2852 | 2854 |
| 2853 ResourceHostMsg_RequestResource second_transfer_request_msg( | 2855 ResourceHostMsg_RequestResource second_transfer_request_msg( |
| 2854 new_render_view_id, new_second_request_id, second_request); | 2856 new_render_view_id, new_second_request_id, second_request); |
| 2855 OnMessageReceived(second_transfer_request_msg, second_filter.get()); | 2857 OnMessageReceived(second_transfer_request_msg, second_filter.get()); |
| 2856 base::RunLoop().RunUntilIdle(); | 2858 content::RunAllBlockingPoolTasksUntilIdle(); |
| 2857 | 2859 |
| 2858 // Check generated messages. | 2860 // Check generated messages. |
| 2859 ResourceIPCAccumulator::ClassifiedMessages msgs; | 2861 ResourceIPCAccumulator::ClassifiedMessages msgs; |
| 2860 accum_.GetClassifiedMessages(&msgs); | 2862 accum_.GetClassifiedMessages(&msgs); |
| 2861 | 2863 |
| 2862 ASSERT_EQ(2U, msgs.size()); | 2864 ASSERT_EQ(2U, msgs.size()); |
| 2863 CheckSuccessfulRequest(msgs[0], kResponseBody); | 2865 CheckSuccessfulRequest(msgs[0], kResponseBody); |
| 2864 | 2866 |
| 2865 second_filter->OnChannelClosing(); | 2867 second_filter->OnChannelClosing(); |
| 2866 } | 2868 } |
| (...skipping 28 matching lines...) Expand all Loading... |
| 2895 // Now that we're blocked on the redirect, update the response and unblock by | 2897 // Now that we're blocked on the redirect, update the response and unblock by |
| 2896 // telling the AsyncResourceHandler to follow the redirect. Use a text/plain | 2898 // telling the AsyncResourceHandler to follow the redirect. Use a text/plain |
| 2897 // MIME type, which causes MimeTypeResourceHandler to buffer it before the | 2899 // MIME type, which causes MimeTypeResourceHandler to buffer it before the |
| 2898 // transfer occurs. | 2900 // transfer occurs. |
| 2899 const std::string kResponseBody = "hello world"; | 2901 const std::string kResponseBody = "hello world"; |
| 2900 SetResponse("HTTP/1.1 200 OK\n" | 2902 SetResponse("HTTP/1.1 200 OK\n" |
| 2901 "Content-Type: text/plain\n\n", | 2903 "Content-Type: text/plain\n\n", |
| 2902 kResponseBody); | 2904 kResponseBody); |
| 2903 ResourceHostMsg_FollowRedirect redirect_msg(request_id); | 2905 ResourceHostMsg_FollowRedirect redirect_msg(request_id); |
| 2904 OnMessageReceived(redirect_msg, filter_.get()); | 2906 OnMessageReceived(redirect_msg, filter_.get()); |
| 2905 base::RunLoop().RunUntilIdle(); | 2907 content::RunAllBlockingPoolTasksUntilIdle(); |
| 2906 | 2908 |
| 2907 // Flush all the pending requests to get the response through the | 2909 // Flush all the pending requests to get the response through the |
| 2908 // MimeTypeResourceHandler. | 2910 // MimeTypeResourceHandler. |
| 2909 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} | 2911 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} |
| 2910 base::RunLoop().RunUntilIdle(); | 2912 content::RunAllBlockingPoolTasksUntilIdle(); |
| 2911 | 2913 |
| 2912 // This second filter is used to emulate a second process. | 2914 // This second filter is used to emulate a second process. |
| 2913 scoped_refptr<ForwardingFilter> second_filter = MakeForwardingFilter(); | 2915 scoped_refptr<ForwardingFilter> second_filter = MakeForwardingFilter(); |
| 2914 | 2916 |
| 2915 int new_render_view_id = 1; | 2917 int new_render_view_id = 1; |
| 2916 int new_request_id = 2; | 2918 int new_request_id = 2; |
| 2917 | 2919 |
| 2918 ResourceRequest request = CreateResourceRequest( | 2920 ResourceRequest request = CreateResourceRequest( |
| 2919 "GET", RESOURCE_TYPE_MAIN_FRAME, GURL("http://other.com/blech")); | 2921 "GET", RESOURCE_TYPE_MAIN_FRAME, GURL("http://other.com/blech")); |
| 2920 request.transferred_request_child_id = filter_->child_id(); | 2922 request.transferred_request_child_id = filter_->child_id(); |
| 2921 request.transferred_request_request_id = request_id; | 2923 request.transferred_request_request_id = request_id; |
| 2922 | 2924 |
| 2923 ResourceHostMsg_RequestResource transfer_request_msg( | 2925 ResourceHostMsg_RequestResource transfer_request_msg( |
| 2924 new_render_view_id, new_request_id, request); | 2926 new_render_view_id, new_request_id, request); |
| 2925 OnMessageReceived(transfer_request_msg, second_filter.get()); | 2927 OnMessageReceived(transfer_request_msg, second_filter.get()); |
| 2926 base::RunLoop().RunUntilIdle(); | 2928 content::RunAllBlockingPoolTasksUntilIdle(); |
| 2927 | 2929 |
| 2928 // Check generated messages. | 2930 // Check generated messages. |
| 2929 ResourceIPCAccumulator::ClassifiedMessages msgs; | 2931 ResourceIPCAccumulator::ClassifiedMessages msgs; |
| 2930 accum_.GetClassifiedMessages(&msgs); | 2932 accum_.GetClassifiedMessages(&msgs); |
| 2931 | 2933 |
| 2932 ASSERT_EQ(2U, msgs.size()); | 2934 ASSERT_EQ(2U, msgs.size()); |
| 2933 EXPECT_EQ(ResourceMsg_ReceivedRedirect::ID, msgs[0][0].type()); | 2935 EXPECT_EQ(ResourceMsg_ReceivedRedirect::ID, msgs[0][0].type()); |
| 2934 CheckSuccessfulRequest(msgs[1], kResponseBody); | 2936 CheckSuccessfulRequest(msgs[1], kResponseBody); |
| 2935 | 2937 |
| 2936 second_filter->OnChannelClosing(); | 2938 second_filter->OnChannelClosing(); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 2962 { | 2964 { |
| 2963 scoped_refptr<ForwardingFilter> first_filter = MakeForwardingFilter(); | 2965 scoped_refptr<ForwardingFilter> first_filter = MakeForwardingFilter(); |
| 2964 first_child_id = first_filter->child_id(); | 2966 first_child_id = first_filter->child_id(); |
| 2965 | 2967 |
| 2966 ResourceRequest first_request = CreateResourceRequest( | 2968 ResourceRequest first_request = CreateResourceRequest( |
| 2967 "GET", RESOURCE_TYPE_MAIN_FRAME, GURL("http://example.com/blah")); | 2969 "GET", RESOURCE_TYPE_MAIN_FRAME, GURL("http://example.com/blah")); |
| 2968 | 2970 |
| 2969 ResourceHostMsg_RequestResource first_request_msg( | 2971 ResourceHostMsg_RequestResource first_request_msg( |
| 2970 render_view_id, request_id, first_request); | 2972 render_view_id, request_id, first_request); |
| 2971 OnMessageReceived(first_request_msg, first_filter.get()); | 2973 OnMessageReceived(first_request_msg, first_filter.get()); |
| 2972 base::RunLoop().RunUntilIdle(); | 2974 content::RunAllBlockingPoolTasksUntilIdle(); |
| 2973 | 2975 |
| 2974 // Now that we're blocked on the redirect, update the response and unblock | 2976 // Now that we're blocked on the redirect, update the response and unblock |
| 2975 // by telling the AsyncResourceHandler to follow the redirect. | 2977 // by telling the AsyncResourceHandler to follow the redirect. |
| 2976 SetResponse("HTTP/1.1 200 OK\n" | 2978 SetResponse("HTTP/1.1 200 OK\n" |
| 2977 "Content-Type: text/html\n\n", | 2979 "Content-Type: text/html\n\n", |
| 2978 kResponseBody); | 2980 kResponseBody); |
| 2979 ResourceHostMsg_FollowRedirect redirect_msg(request_id); | 2981 ResourceHostMsg_FollowRedirect redirect_msg(request_id); |
| 2980 OnMessageReceived(redirect_msg, first_filter.get()); | 2982 OnMessageReceived(redirect_msg, first_filter.get()); |
| 2981 base::RunLoop().RunUntilIdle(); | 2983 content::RunAllBlockingPoolTasksUntilIdle(); |
| 2982 | 2984 |
| 2983 // Flush all the pending requests to get the response through the | 2985 // Flush all the pending requests to get the response through the |
| 2984 // MimeTypeResourceHandler. | 2986 // MimeTypeResourceHandler. |
| 2985 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} | 2987 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} |
| 2986 | 2988 |
| 2987 first_filter->OnChannelClosing(); | 2989 first_filter->OnChannelClosing(); |
| 2988 } | 2990 } |
| 2989 // The first filter is now deleted, as if the child process died. | 2991 // The first filter is now deleted, as if the child process died. |
| 2990 | 2992 |
| 2991 // Make sure we don't hold onto the ResourceMessageFilter after it is deleted. | 2993 // Make sure we don't hold onto the ResourceMessageFilter after it is deleted. |
| 2992 GlobalRequestID first_global_request_id(first_child_id, request_id); | 2994 GlobalRequestID first_global_request_id(first_child_id, request_id); |
| 2993 | 2995 |
| 2994 // This second filter is used to emulate a second process. | 2996 // This second filter is used to emulate a second process. |
| 2995 scoped_refptr<ForwardingFilter> second_filter = MakeForwardingFilter(); | 2997 scoped_refptr<ForwardingFilter> second_filter = MakeForwardingFilter(); |
| 2996 | 2998 |
| 2997 int new_render_view_id = 1; | 2999 int new_render_view_id = 1; |
| 2998 int new_request_id = 2; | 3000 int new_request_id = 2; |
| 2999 | 3001 |
| 3000 ResourceRequest request = CreateResourceRequest( | 3002 ResourceRequest request = CreateResourceRequest( |
| 3001 "GET", RESOURCE_TYPE_MAIN_FRAME, GURL("http://other.com/blech")); | 3003 "GET", RESOURCE_TYPE_MAIN_FRAME, GURL("http://other.com/blech")); |
| 3002 request.transferred_request_child_id = first_child_id; | 3004 request.transferred_request_child_id = first_child_id; |
| 3003 request.transferred_request_request_id = request_id; | 3005 request.transferred_request_request_id = request_id; |
| 3004 | 3006 |
| 3005 // For cleanup. | 3007 // For cleanup. |
| 3006 child_ids_.insert(second_filter->child_id()); | 3008 child_ids_.insert(second_filter->child_id()); |
| 3007 ResourceHostMsg_RequestResource transfer_request_msg( | 3009 ResourceHostMsg_RequestResource transfer_request_msg( |
| 3008 new_render_view_id, new_request_id, request); | 3010 new_render_view_id, new_request_id, request); |
| 3009 OnMessageReceived(transfer_request_msg, second_filter.get()); | 3011 OnMessageReceived(transfer_request_msg, second_filter.get()); |
| 3010 base::RunLoop().RunUntilIdle(); | 3012 content::RunAllBlockingPoolTasksUntilIdle(); |
| 3011 | 3013 |
| 3012 // Check generated messages. | 3014 // Check generated messages. |
| 3013 ResourceIPCAccumulator::ClassifiedMessages msgs; | 3015 ResourceIPCAccumulator::ClassifiedMessages msgs; |
| 3014 accum_.GetClassifiedMessages(&msgs); | 3016 accum_.GetClassifiedMessages(&msgs); |
| 3015 | 3017 |
| 3016 ASSERT_EQ(2U, msgs.size()); | 3018 ASSERT_EQ(2U, msgs.size()); |
| 3017 EXPECT_EQ(ResourceMsg_ReceivedRedirect::ID, msgs[0][0].type()); | 3019 EXPECT_EQ(ResourceMsg_ReceivedRedirect::ID, msgs[0][0].type()); |
| 3018 CheckSuccessfulRequest(msgs[1], kResponseBody); | 3020 CheckSuccessfulRequest(msgs[1], kResponseBody); |
| 3019 | 3021 |
| 3020 second_filter->OnChannelClosing(); | 3022 second_filter->OnChannelClosing(); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 3042 | 3044 |
| 3043 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id, | 3045 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id, |
| 3044 GURL("http://example.com/blah"), | 3046 GURL("http://example.com/blah"), |
| 3045 RESOURCE_TYPE_MAIN_FRAME); | 3047 RESOURCE_TYPE_MAIN_FRAME); |
| 3046 | 3048 |
| 3047 // Now that we're blocked on the redirect, simulate hitting another redirect. | 3049 // Now that we're blocked on the redirect, simulate hitting another redirect. |
| 3048 SetResponse("HTTP/1.1 302 Found\n" | 3050 SetResponse("HTTP/1.1 302 Found\n" |
| 3049 "Location: http://other.com/blerg\n\n"); | 3051 "Location: http://other.com/blerg\n\n"); |
| 3050 ResourceHostMsg_FollowRedirect redirect_msg(request_id); | 3052 ResourceHostMsg_FollowRedirect redirect_msg(request_id); |
| 3051 OnMessageReceived(redirect_msg, filter_.get()); | 3053 OnMessageReceived(redirect_msg, filter_.get()); |
| 3052 base::RunLoop().RunUntilIdle(); | 3054 content::RunAllBlockingPoolTasksUntilIdle(); |
| 3053 | 3055 |
| 3054 // Now that we're blocked on the second redirect, update the response and | 3056 // Now that we're blocked on the second redirect, update the response and |
| 3055 // unblock by telling the AsyncResourceHandler to follow the redirect. | 3057 // unblock by telling the AsyncResourceHandler to follow the redirect. |
| 3056 // Again, use text/plain to force MimeTypeResourceHandler to buffer before | 3058 // Again, use text/plain to force MimeTypeResourceHandler to buffer before |
| 3057 // the transfer. | 3059 // the transfer. |
| 3058 const std::string kResponseBody = "hello world"; | 3060 const std::string kResponseBody = "hello world"; |
| 3059 SetResponse("HTTP/1.1 200 OK\n" | 3061 SetResponse("HTTP/1.1 200 OK\n" |
| 3060 "Content-Type: text/plain\n\n", | 3062 "Content-Type: text/plain\n\n", |
| 3061 kResponseBody); | 3063 kResponseBody); |
| 3062 ResourceHostMsg_FollowRedirect redirect_msg2(request_id); | 3064 ResourceHostMsg_FollowRedirect redirect_msg2(request_id); |
| 3063 OnMessageReceived(redirect_msg2, filter_.get()); | 3065 OnMessageReceived(redirect_msg2, filter_.get()); |
| 3064 base::RunLoop().RunUntilIdle(); | 3066 content::RunAllBlockingPoolTasksUntilIdle(); |
| 3065 | 3067 |
| 3066 // Flush all the pending requests to get the response through the | 3068 // Flush all the pending requests to get the response through the |
| 3067 // MimeTypeResourceHandler. | 3069 // MimeTypeResourceHandler. |
| 3068 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} | 3070 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} |
| 3069 base::RunLoop().RunUntilIdle(); | 3071 content::RunAllBlockingPoolTasksUntilIdle(); |
| 3070 | 3072 |
| 3071 // This second filter is used to emulate a second process. | 3073 // This second filter is used to emulate a second process. |
| 3072 scoped_refptr<ForwardingFilter> second_filter = MakeForwardingFilter(); | 3074 scoped_refptr<ForwardingFilter> second_filter = MakeForwardingFilter(); |
| 3073 | 3075 |
| 3074 int new_render_view_id = 1; | 3076 int new_render_view_id = 1; |
| 3075 int new_request_id = 2; | 3077 int new_request_id = 2; |
| 3076 | 3078 |
| 3077 ResourceRequest request = CreateResourceRequest( | 3079 ResourceRequest request = CreateResourceRequest( |
| 3078 "GET", RESOURCE_TYPE_MAIN_FRAME, GURL("http://other.com/blech")); | 3080 "GET", RESOURCE_TYPE_MAIN_FRAME, GURL("http://other.com/blech")); |
| 3079 request.transferred_request_child_id = filter_->child_id(); | 3081 request.transferred_request_child_id = filter_->child_id(); |
| 3080 request.transferred_request_request_id = request_id; | 3082 request.transferred_request_request_id = request_id; |
| 3081 | 3083 |
| 3082 // For cleanup. | 3084 // For cleanup. |
| 3083 child_ids_.insert(second_filter->child_id()); | 3085 child_ids_.insert(second_filter->child_id()); |
| 3084 ResourceHostMsg_RequestResource transfer_request_msg( | 3086 ResourceHostMsg_RequestResource transfer_request_msg( |
| 3085 new_render_view_id, new_request_id, request); | 3087 new_render_view_id, new_request_id, request); |
| 3086 OnMessageReceived(transfer_request_msg, second_filter.get()); | 3088 OnMessageReceived(transfer_request_msg, second_filter.get()); |
| 3087 | 3089 |
| 3088 // Verify that we update the ResourceRequestInfo. | 3090 // Verify that we update the ResourceRequestInfo. |
| 3089 GlobalRequestID global_request_id(second_filter->child_id(), new_request_id); | 3091 GlobalRequestID global_request_id(second_filter->child_id(), new_request_id); |
| 3090 ResourceRequestInfoImpl* info = ResourceRequestInfoImpl::ForRequest( | 3092 ResourceRequestInfoImpl* info = ResourceRequestInfoImpl::ForRequest( |
| 3091 host_.GetURLRequest(global_request_id)); | 3093 host_.GetURLRequest(global_request_id)); |
| 3092 EXPECT_EQ(second_filter->child_id(), info->GetChildID()); | 3094 EXPECT_EQ(second_filter->child_id(), info->GetChildID()); |
| 3093 EXPECT_EQ(new_render_view_id, info->GetRouteID()); | 3095 EXPECT_EQ(new_render_view_id, info->GetRouteID()); |
| 3094 EXPECT_EQ(new_request_id, info->GetRequestID()); | 3096 EXPECT_EQ(new_request_id, info->GetRequestID()); |
| 3095 EXPECT_EQ(second_filter.get(), info->requester_info()->filter()); | 3097 EXPECT_EQ(second_filter.get(), info->requester_info()->filter()); |
| 3096 | 3098 |
| 3097 // Let request complete. | 3099 // Let request complete. |
| 3098 base::RunLoop().RunUntilIdle(); | 3100 content::RunAllBlockingPoolTasksUntilIdle(); |
| 3099 | 3101 |
| 3100 // Check generated messages. | 3102 // Check generated messages. |
| 3101 ResourceIPCAccumulator::ClassifiedMessages msgs; | 3103 ResourceIPCAccumulator::ClassifiedMessages msgs; |
| 3102 accum_.GetClassifiedMessages(&msgs); | 3104 accum_.GetClassifiedMessages(&msgs); |
| 3103 | 3105 |
| 3104 ASSERT_EQ(2U, msgs.size()); | 3106 ASSERT_EQ(2U, msgs.size()); |
| 3105 EXPECT_EQ(ResourceMsg_ReceivedRedirect::ID, msgs[0][0].type()); | 3107 EXPECT_EQ(ResourceMsg_ReceivedRedirect::ID, msgs[0][0].type()); |
| 3106 CheckSuccessfulRequest(msgs[1], kResponseBody); | 3108 CheckSuccessfulRequest(msgs[1], kResponseBody); |
| 3107 | 3109 |
| 3108 second_filter->OnChannelClosing(); | 3110 second_filter->OnChannelClosing(); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 3121 } | 3123 } |
| 3122 | 3124 |
| 3123 TEST_F(ResourceDispatcherHostTest, DataReceivedACKs) { | 3125 TEST_F(ResourceDispatcherHostTest, DataReceivedACKs) { |
| 3124 EXPECT_EQ(0, host_.pending_requests()); | 3126 EXPECT_EQ(0, host_.pending_requests()); |
| 3125 | 3127 |
| 3126 SendDataReceivedACKs(true); | 3128 SendDataReceivedACKs(true); |
| 3127 | 3129 |
| 3128 HandleScheme("big-job"); | 3130 HandleScheme("big-job"); |
| 3129 MakeTestRequest(0, 1, GURL("big-job:0123456789,1000000")); | 3131 MakeTestRequest(0, 1, GURL("big-job:0123456789,1000000")); |
| 3130 | 3132 |
| 3131 base::RunLoop().RunUntilIdle(); | 3133 content::RunAllBlockingPoolTasksUntilIdle(); |
| 3132 | 3134 |
| 3133 // Sort all the messages we saw by request. | 3135 // Sort all the messages we saw by request. |
| 3134 ResourceIPCAccumulator::ClassifiedMessages msgs; | 3136 ResourceIPCAccumulator::ClassifiedMessages msgs; |
| 3135 accum_.GetClassifiedMessages(&msgs); | 3137 accum_.GetClassifiedMessages(&msgs); |
| 3136 | 3138 |
| 3137 size_t size = msgs[0].size(); | 3139 size_t size = msgs[0].size(); |
| 3138 | 3140 |
| 3139 EXPECT_EQ(ResourceMsg_ReceivedResponse::ID, msgs[0][0].type()); | 3141 EXPECT_EQ(ResourceMsg_ReceivedResponse::ID, msgs[0][0].type()); |
| 3140 EXPECT_EQ(ResourceMsg_SetDataBuffer::ID, msgs[0][1].type()); | 3142 EXPECT_EQ(ResourceMsg_SetDataBuffer::ID, msgs[0][1].type()); |
| 3141 for (size_t i = 2; i < size - 1; ++i) | 3143 for (size_t i = 2; i < size - 1; ++i) |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3200 std::string(response_data.begin(), response_data.begin() + data_length), | 3202 std::string(response_data.begin(), response_data.begin() + data_length), |
| 3201 net::ERR_ABORTED); | 3203 net::ERR_ABORTED); |
| 3202 } | 3204 } |
| 3203 | 3205 |
| 3204 TEST_F(ResourceDispatcherHostTest, DelayedDataReceivedACKs) { | 3206 TEST_F(ResourceDispatcherHostTest, DelayedDataReceivedACKs) { |
| 3205 EXPECT_EQ(0, host_.pending_requests()); | 3207 EXPECT_EQ(0, host_.pending_requests()); |
| 3206 | 3208 |
| 3207 HandleScheme("big-job"); | 3209 HandleScheme("big-job"); |
| 3208 MakeTestRequest(0, 1, GURL("big-job:0123456789,1000000")); | 3210 MakeTestRequest(0, 1, GURL("big-job:0123456789,1000000")); |
| 3209 | 3211 |
| 3210 base::RunLoop().RunUntilIdle(); | 3212 content::RunAllBlockingPoolTasksUntilIdle(); |
| 3211 | 3213 |
| 3212 // Sort all the messages we saw by request. | 3214 // Sort all the messages we saw by request. |
| 3213 ResourceIPCAccumulator::ClassifiedMessages msgs; | 3215 ResourceIPCAccumulator::ClassifiedMessages msgs; |
| 3214 accum_.GetClassifiedMessages(&msgs); | 3216 accum_.GetClassifiedMessages(&msgs); |
| 3215 | 3217 |
| 3216 // We expect 1x ReceivedResponse, 1x SetDataBuffer, Nx ReceivedData messages. | 3218 // We expect 1x ReceivedResponse, 1x SetDataBuffer, Nx ReceivedData messages. |
| 3217 EXPECT_EQ(ResourceMsg_ReceivedResponse::ID, msgs[0][0].type()); | 3219 EXPECT_EQ(ResourceMsg_ReceivedResponse::ID, msgs[0][0].type()); |
| 3218 EXPECT_EQ(ResourceMsg_SetDataBuffer::ID, msgs[0][1].type()); | 3220 EXPECT_EQ(ResourceMsg_SetDataBuffer::ID, msgs[0][1].type()); |
| 3219 for (size_t i = 2; i < msgs[0].size(); ++i) | 3221 for (size_t i = 2; i < msgs[0].size(); ++i) |
| 3220 EXPECT_EQ(ResourceMsg_DataReceived::ID, msgs[0][i].type()); | 3222 EXPECT_EQ(ResourceMsg_DataReceived::ID, msgs[0][i].type()); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 3234 complete = true; | 3236 complete = true; |
| 3235 break; | 3237 break; |
| 3236 } | 3238 } |
| 3237 | 3239 |
| 3238 EXPECT_EQ(ResourceMsg_DataReceived::ID, msgs[0][i].type()); | 3240 EXPECT_EQ(ResourceMsg_DataReceived::ID, msgs[0][i].type()); |
| 3239 | 3241 |
| 3240 ResourceHostMsg_DataReceived_ACK msg(1); | 3242 ResourceHostMsg_DataReceived_ACK msg(1); |
| 3241 OnMessageReceived(msg, filter_.get()); | 3243 OnMessageReceived(msg, filter_.get()); |
| 3242 } | 3244 } |
| 3243 | 3245 |
| 3244 base::RunLoop().RunUntilIdle(); | 3246 content::RunAllBlockingPoolTasksUntilIdle(); |
| 3245 | 3247 |
| 3246 msgs.clear(); | 3248 msgs.clear(); |
| 3247 accum_.GetClassifiedMessages(&msgs); | 3249 accum_.GetClassifiedMessages(&msgs); |
| 3248 } | 3250 } |
| 3249 } | 3251 } |
| 3250 | 3252 |
| 3251 // Flakyness of this test might indicate memory corruption issues with | 3253 // Flakyness of this test might indicate memory corruption issues with |
| 3252 // for example the ResourceBuffer of AsyncResourceHandler. | 3254 // for example the ResourceBuffer of AsyncResourceHandler. |
| 3253 TEST_F(ResourceDispatcherHostTest, DataReceivedUnexpectedACKs) { | 3255 TEST_F(ResourceDispatcherHostTest, DataReceivedUnexpectedACKs) { |
| 3254 EXPECT_EQ(0, host_.pending_requests()); | 3256 EXPECT_EQ(0, host_.pending_requests()); |
| 3255 | 3257 |
| 3256 HandleScheme("big-job"); | 3258 HandleScheme("big-job"); |
| 3257 MakeTestRequest(0, 1, GURL("big-job:0123456789,1000000")); | 3259 MakeTestRequest(0, 1, GURL("big-job:0123456789,1000000")); |
| 3258 | 3260 |
| 3259 base::RunLoop().RunUntilIdle(); | 3261 content::RunAllBlockingPoolTasksUntilIdle(); |
| 3260 | 3262 |
| 3261 // Sort all the messages we saw by request. | 3263 // Sort all the messages we saw by request. |
| 3262 ResourceIPCAccumulator::ClassifiedMessages msgs; | 3264 ResourceIPCAccumulator::ClassifiedMessages msgs; |
| 3263 accum_.GetClassifiedMessages(&msgs); | 3265 accum_.GetClassifiedMessages(&msgs); |
| 3264 | 3266 |
| 3265 // We expect 1x ReceivedResponse, 1x SetDataBuffer, Nx ReceivedData messages. | 3267 // We expect 1x ReceivedResponse, 1x SetDataBuffer, Nx ReceivedData messages. |
| 3266 EXPECT_EQ(ResourceMsg_ReceivedResponse::ID, msgs[0][0].type()); | 3268 EXPECT_EQ(ResourceMsg_ReceivedResponse::ID, msgs[0][0].type()); |
| 3267 EXPECT_EQ(ResourceMsg_SetDataBuffer::ID, msgs[0][1].type()); | 3269 EXPECT_EQ(ResourceMsg_SetDataBuffer::ID, msgs[0][1].type()); |
| 3268 for (size_t i = 2; i < msgs[0].size(); ++i) | 3270 for (size_t i = 2; i < msgs[0].size(); ++i) |
| 3269 EXPECT_EQ(ResourceMsg_DataReceived::ID, msgs[0][i].type()); | 3271 EXPECT_EQ(ResourceMsg_DataReceived::ID, msgs[0][i].type()); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 3288 complete = true; | 3290 complete = true; |
| 3289 break; | 3291 break; |
| 3290 } | 3292 } |
| 3291 | 3293 |
| 3292 EXPECT_EQ(ResourceMsg_DataReceived::ID, msgs[0][i].type()); | 3294 EXPECT_EQ(ResourceMsg_DataReceived::ID, msgs[0][i].type()); |
| 3293 | 3295 |
| 3294 ResourceHostMsg_DataReceived_ACK msg(1); | 3296 ResourceHostMsg_DataReceived_ACK msg(1); |
| 3295 OnMessageReceived(msg, filter_.get()); | 3297 OnMessageReceived(msg, filter_.get()); |
| 3296 } | 3298 } |
| 3297 | 3299 |
| 3298 base::RunLoop().RunUntilIdle(); | 3300 content::RunAllBlockingPoolTasksUntilIdle(); |
| 3299 | 3301 |
| 3300 msgs.clear(); | 3302 msgs.clear(); |
| 3301 accum_.GetClassifiedMessages(&msgs); | 3303 accum_.GetClassifiedMessages(&msgs); |
| 3302 } | 3304 } |
| 3303 } | 3305 } |
| 3304 | 3306 |
| 3305 // Tests the dispatcher host's temporary file management. | 3307 // Tests the dispatcher host's temporary file management. |
| 3306 TEST_F(ResourceDispatcherHostTest, RegisterDownloadedTempFile) { | 3308 TEST_F(ResourceDispatcherHostTest, RegisterDownloadedTempFile) { |
| 3307 const int kRequestID = 1; | 3309 const int kRequestID = 1; |
| 3308 | 3310 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 3332 | 3334 |
| 3333 // Still readable because there is another reference to the file. (The child | 3335 // Still readable because there is another reference to the file. (The child |
| 3334 // may take additional blob references.) | 3336 // may take additional blob references.) |
| 3335 EXPECT_TRUE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile( | 3337 EXPECT_TRUE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile( |
| 3336 filter_->child_id(), file_path)); | 3338 filter_->child_id(), file_path)); |
| 3337 | 3339 |
| 3338 // Release extra references and wait for the file to be deleted. (This relies | 3340 // Release extra references and wait for the file to be deleted. (This relies |
| 3339 // on the delete happening on the FILE thread which is mapped to main thread | 3341 // on the delete happening on the FILE thread which is mapped to main thread |
| 3340 // in this test.) | 3342 // in this test.) |
| 3341 deletable_file = nullptr; | 3343 deletable_file = nullptr; |
| 3342 base::RunLoop().RunUntilIdle(); | 3344 content::RunAllBlockingPoolTasksUntilIdle(); |
| 3343 | 3345 |
| 3344 // The file is no longer readable to the child and has been deleted. | 3346 // The file is no longer readable to the child and has been deleted. |
| 3345 EXPECT_FALSE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile( | 3347 EXPECT_FALSE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile( |
| 3346 filter_->child_id(), file_path)); | 3348 filter_->child_id(), file_path)); |
| 3347 EXPECT_FALSE(base::PathExists(file_path)); | 3349 EXPECT_FALSE(base::PathExists(file_path)); |
| 3348 } | 3350 } |
| 3349 | 3351 |
| 3350 // Tests the dispatcher host's temporary file management in the mojo-enabled | 3352 // Tests the dispatcher host's temporary file management in the mojo-enabled |
| 3351 // loading. | 3353 // loading. |
| 3352 TEST_F(ResourceDispatcherHostTest, RegisterDownloadedTempFileWithMojo) { | 3354 TEST_F(ResourceDispatcherHostTest, RegisterDownloadedTempFileWithMojo) { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 3371 mojom::DownloadedTempFilePtr downloaded_file_ptr = | 3373 mojom::DownloadedTempFilePtr downloaded_file_ptr = |
| 3372 DownloadedTempFileImpl::Create(filter_->child_id(), kRequestID); | 3374 DownloadedTempFileImpl::Create(filter_->child_id(), kRequestID); |
| 3373 host_.RegisterDownloadedTempFile(filter_->child_id(), kRequestID, file_path); | 3375 host_.RegisterDownloadedTempFile(filter_->child_id(), kRequestID, file_path); |
| 3374 | 3376 |
| 3375 // Should be readable now. | 3377 // Should be readable now. |
| 3376 EXPECT_TRUE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile( | 3378 EXPECT_TRUE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile( |
| 3377 filter_->child_id(), file_path)); | 3379 filter_->child_id(), file_path)); |
| 3378 | 3380 |
| 3379 // The child releases from the request. | 3381 // The child releases from the request. |
| 3380 downloaded_file_ptr = nullptr; | 3382 downloaded_file_ptr = nullptr; |
| 3381 base::RunLoop().RunUntilIdle(); | 3383 content::RunAllBlockingPoolTasksUntilIdle(); |
| 3382 | 3384 |
| 3383 // Still readable because there is another reference to the file. (The child | 3385 // Still readable because there is another reference to the file. (The child |
| 3384 // may take additional blob references.) | 3386 // may take additional blob references.) |
| 3385 EXPECT_TRUE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile( | 3387 EXPECT_TRUE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile( |
| 3386 filter_->child_id(), file_path)); | 3388 filter_->child_id(), file_path)); |
| 3387 | 3389 |
| 3388 // Release extra references and wait for the file to be deleted. (This relies | 3390 // Release extra references and wait for the file to be deleted. (This relies |
| 3389 // on the delete happening on the FILE thread which is mapped to main thread | 3391 // on the delete happening on the FILE thread which is mapped to main thread |
| 3390 // in this test.) | 3392 // in this test.) |
| 3391 deletable_file = nullptr; | 3393 deletable_file = nullptr; |
| 3392 base::RunLoop().RunUntilIdle(); | 3394 content::RunAllBlockingPoolTasksUntilIdle(); |
| 3393 | 3395 |
| 3394 // The file is no longer readable to the child and has been deleted. | 3396 // The file is no longer readable to the child and has been deleted. |
| 3395 EXPECT_FALSE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile( | 3397 EXPECT_FALSE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile( |
| 3396 filter_->child_id(), file_path)); | 3398 filter_->child_id(), file_path)); |
| 3397 EXPECT_FALSE(base::PathExists(file_path)); | 3399 EXPECT_FALSE(base::PathExists(file_path)); |
| 3398 } | 3400 } |
| 3399 | 3401 |
| 3400 // Tests that temporary files held on behalf of child processes are released | 3402 // Tests that temporary files held on behalf of child processes are released |
| 3401 // when the child process dies. | 3403 // when the child process dies. |
| 3402 TEST_F(ResourceDispatcherHostTest, ReleaseTemporiesOnProcessExit) { | 3404 TEST_F(ResourceDispatcherHostTest, ReleaseTemporiesOnProcessExit) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 3413 // Register it for a resource request. | 3415 // Register it for a resource request. |
| 3414 host_.RegisterDownloadedTempFile(filter_->child_id(), kRequestID, file_path); | 3416 host_.RegisterDownloadedTempFile(filter_->child_id(), kRequestID, file_path); |
| 3415 deletable_file = NULL; | 3417 deletable_file = NULL; |
| 3416 | 3418 |
| 3417 // Should be readable now. | 3419 // Should be readable now. |
| 3418 EXPECT_TRUE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile( | 3420 EXPECT_TRUE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile( |
| 3419 filter_->child_id(), file_path)); | 3421 filter_->child_id(), file_path)); |
| 3420 | 3422 |
| 3421 // Let the process die. | 3423 // Let the process die. |
| 3422 filter_->OnChannelClosing(); | 3424 filter_->OnChannelClosing(); |
| 3423 base::RunLoop().RunUntilIdle(); | 3425 content::RunAllBlockingPoolTasksUntilIdle(); |
| 3424 | 3426 |
| 3425 // The file is no longer readable to the child and has been deleted. | 3427 // The file is no longer readable to the child and has been deleted. |
| 3426 EXPECT_FALSE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile( | 3428 EXPECT_FALSE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile( |
| 3427 filter_->child_id(), file_path)); | 3429 filter_->child_id(), file_path)); |
| 3428 EXPECT_FALSE(base::PathExists(file_path)); | 3430 EXPECT_FALSE(base::PathExists(file_path)); |
| 3429 } | 3431 } |
| 3430 | 3432 |
| 3431 TEST_F(ResourceDispatcherHostTest, DownloadToFile) { | 3433 TEST_F(ResourceDispatcherHostTest, DownloadToFile) { |
| 3432 // Make a request which downloads to file. | 3434 // Make a request which downloads to file. |
| 3433 ResourceRequest request = CreateResourceRequest( | 3435 ResourceRequest request = CreateResourceRequest( |
| 3434 "GET", RESOURCE_TYPE_SUB_RESOURCE, net::URLRequestTestJob::test_url_1()); | 3436 "GET", RESOURCE_TYPE_SUB_RESOURCE, net::URLRequestTestJob::test_url_1()); |
| 3435 request.download_to_file = true; | 3437 request.download_to_file = true; |
| 3436 ResourceHostMsg_RequestResource request_msg(0, 1, request); | 3438 ResourceHostMsg_RequestResource request_msg(0, 1, request); |
| 3437 OnMessageReceived(request_msg, filter_.get()); | 3439 OnMessageReceived(request_msg, filter_.get()); |
| 3438 | 3440 |
| 3439 // Running the message loop until idle does not work because | 3441 // Running the message loop until idle does not work because |
| 3440 // RedirectToFileResourceHandler posts things to base::WorkerPool. Instead, | 3442 // RedirectToFileResourceHandler posts things to base::WorkerPool. Instead, |
| 3441 // wait for the ResourceMsg_RequestComplete to go out. Then run the event loop | 3443 // wait for the ResourceMsg_RequestComplete to go out. Then run the event loop |
| 3442 // until idle so the loader is gone. | 3444 // until idle so the loader is gone. |
| 3443 WaitForRequestComplete(); | 3445 WaitForRequestComplete(); |
| 3444 base::RunLoop().RunUntilIdle(); | 3446 content::RunAllBlockingPoolTasksUntilIdle(); |
| 3445 EXPECT_EQ(0, host_.pending_requests()); | 3447 EXPECT_EQ(0, host_.pending_requests()); |
| 3446 | 3448 |
| 3447 ResourceIPCAccumulator::ClassifiedMessages msgs; | 3449 ResourceIPCAccumulator::ClassifiedMessages msgs; |
| 3448 accum_.GetClassifiedMessages(&msgs); | 3450 accum_.GetClassifiedMessages(&msgs); |
| 3449 | 3451 |
| 3450 ASSERT_EQ(1U, msgs.size()); | 3452 ASSERT_EQ(1U, msgs.size()); |
| 3451 const std::vector<IPC::Message>& messages = msgs[0]; | 3453 const std::vector<IPC::Message>& messages = msgs[0]; |
| 3452 | 3454 |
| 3453 // The request should contain the following messages: | 3455 // The request should contain the following messages: |
| 3454 // ReceivedResponse (indicates headers received and filename) | 3456 // ReceivedResponse (indicates headers received and filename) |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3487 | 3489 |
| 3488 // When the renderer releases the file, it should be deleted. Again, | 3490 // When the renderer releases the file, it should be deleted. Again, |
| 3489 // RunUntilIdle doesn't work because base::WorkerPool is involved. | 3491 // RunUntilIdle doesn't work because base::WorkerPool is involved. |
| 3490 ShareableFileReleaseWaiter waiter(response_head.download_file_path); | 3492 ShareableFileReleaseWaiter waiter(response_head.download_file_path); |
| 3491 ResourceHostMsg_ReleaseDownloadedFile release_msg(1); | 3493 ResourceHostMsg_ReleaseDownloadedFile release_msg(1); |
| 3492 OnMessageReceived(release_msg, filter_.get()); | 3494 OnMessageReceived(release_msg, filter_.get()); |
| 3493 waiter.Wait(); | 3495 waiter.Wait(); |
| 3494 // The release callback runs before the delete is scheduled, so pump the | 3496 // The release callback runs before the delete is scheduled, so pump the |
| 3495 // message loop for the delete itself. (This relies on the delete happening on | 3497 // message loop for the delete itself. (This relies on the delete happening on |
| 3496 // the FILE thread which is mapped to main thread in this test.) | 3498 // the FILE thread which is mapped to main thread in this test.) |
| 3497 base::RunLoop().RunUntilIdle(); | 3499 content::RunAllBlockingPoolTasksUntilIdle(); |
| 3498 | 3500 |
| 3499 EXPECT_FALSE(base::PathExists(response_head.download_file_path)); | 3501 EXPECT_FALSE(base::PathExists(response_head.download_file_path)); |
| 3500 EXPECT_FALSE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile( | 3502 EXPECT_FALSE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile( |
| 3501 filter_->child_id(), response_head.download_file_path)); | 3503 filter_->child_id(), response_head.download_file_path)); |
| 3502 } | 3504 } |
| 3503 | 3505 |
| 3504 WebContents* WebContentsBinder(WebContents* rv) { return rv; } | 3506 WebContents* WebContentsBinder(WebContents* rv) { return rv; } |
| 3505 | 3507 |
| 3506 // Tests GetLoadInfoForAllRoutes when there are 3 requests from the same | 3508 // Tests GetLoadInfoForAllRoutes when there are 3 requests from the same |
| 3507 // RenderView. The second one is farthest along. | 3509 // RenderView. The second one is farthest along. |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3663 EXPECT_EQ(0u, (*load_info_map)[wc2].upload_position); | 3665 EXPECT_EQ(0u, (*load_info_map)[wc2].upload_position); |
| 3664 EXPECT_EQ(0u, (*load_info_map)[wc2].upload_size); | 3666 EXPECT_EQ(0u, (*load_info_map)[wc2].upload_size); |
| 3665 } | 3667 } |
| 3666 | 3668 |
| 3667 // Confirm that resource response started notifications are correctly | 3669 // Confirm that resource response started notifications are correctly |
| 3668 // transmitted to the WebContents. | 3670 // transmitted to the WebContents. |
| 3669 TEST_F(ResourceDispatcherHostTest, TransferResponseStarted) { | 3671 TEST_F(ResourceDispatcherHostTest, TransferResponseStarted) { |
| 3670 int initial_count = web_contents_observer_->resource_response_start_count(); | 3672 int initial_count = web_contents_observer_->resource_response_start_count(); |
| 3671 | 3673 |
| 3672 MakeWebContentsAssociatedTestRequest(1, net::URLRequestTestJob::test_url_1()); | 3674 MakeWebContentsAssociatedTestRequest(1, net::URLRequestTestJob::test_url_1()); |
| 3673 base::RunLoop().RunUntilIdle(); | 3675 content::RunAllBlockingPoolTasksUntilIdle(); |
| 3674 | 3676 |
| 3675 EXPECT_EQ(initial_count + 1, | 3677 EXPECT_EQ(initial_count + 1, |
| 3676 web_contents_observer_->resource_response_start_count()); | 3678 web_contents_observer_->resource_response_start_count()); |
| 3677 } | 3679 } |
| 3678 | 3680 |
| 3679 // Confirm that request redirected notifications are correctly | 3681 // Confirm that request redirected notifications are correctly |
| 3680 // transmitted to the WebContents. | 3682 // transmitted to the WebContents. |
| 3681 TEST_F(ResourceDispatcherHostTest, TransferRequestRedirected) { | 3683 TEST_F(ResourceDispatcherHostTest, TransferRequestRedirected) { |
| 3682 int initial_count = web_contents_observer_->resource_request_redirect_count(); | 3684 int initial_count = web_contents_observer_->resource_request_redirect_count(); |
| 3683 | 3685 |
| 3684 MakeWebContentsAssociatedTestRequest( | 3686 MakeWebContentsAssociatedTestRequest( |
| 3685 1, net::URLRequestTestJob::test_url_redirect_to_url_2()); | 3687 1, net::URLRequestTestJob::test_url_redirect_to_url_2()); |
| 3686 base::RunLoop().RunUntilIdle(); | 3688 content::RunAllBlockingPoolTasksUntilIdle(); |
| 3687 | 3689 |
| 3688 EXPECT_EQ(initial_count + 1, | 3690 EXPECT_EQ(initial_count + 1, |
| 3689 web_contents_observer_->resource_request_redirect_count()); | 3691 web_contents_observer_->resource_request_redirect_count()); |
| 3690 } | 3692 } |
| 3691 | 3693 |
| 3692 // Confirm that DidChangePriority messages are respected. | 3694 // Confirm that DidChangePriority messages are respected. |
| 3693 TEST_F(ResourceDispatcherHostTest, DidChangePriority) { | 3695 TEST_F(ResourceDispatcherHostTest, DidChangePriority) { |
| 3694 // ResourceScheduler only throttles http and https requests. | 3696 // ResourceScheduler only throttles http and https requests. |
| 3695 HandleScheme("http"); | 3697 HandleScheme("http"); |
| 3696 | 3698 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 3709 MakeTestRequestWithPriority(0, 3, net::IDLE); | 3711 MakeTestRequestWithPriority(0, 3, net::IDLE); |
| 3710 | 3712 |
| 3711 KickOffRequest(); | 3713 KickOffRequest(); |
| 3712 | 3714 |
| 3713 EXPECT_EQ(2, job_factory_->url_request_jobs_created_count()); | 3715 EXPECT_EQ(2, job_factory_->url_request_jobs_created_count()); |
| 3714 | 3716 |
| 3715 // Increase the priority of the second idle priority request. It was | 3717 // Increase the priority of the second idle priority request. It was |
| 3716 // scheduled later, so it is not currently running. | 3718 // scheduled later, so it is not currently running. |
| 3717 ResourceHostMsg_DidChangePriority priority_msg(3, net::MAXIMUM_PRIORITY, 0); | 3719 ResourceHostMsg_DidChangePriority priority_msg(3, net::MAXIMUM_PRIORITY, 0); |
| 3718 OnMessageReceived(priority_msg, filter_.get()); | 3720 OnMessageReceived(priority_msg, filter_.get()); |
| 3719 base::RunLoop().RunUntilIdle(); | 3721 content::RunAllBlockingPoolTasksUntilIdle(); |
| 3720 | 3722 |
| 3721 EXPECT_EQ(3, job_factory_->url_request_jobs_created_count()); | 3723 EXPECT_EQ(3, job_factory_->url_request_jobs_created_count()); |
| 3722 | 3724 |
| 3723 // Cleanup. | 3725 // Cleanup. |
| 3724 host_.OnRenderViewHostDeleted(filter_->child_id(), // child_id | 3726 host_.OnRenderViewHostDeleted(filter_->child_id(), // child_id |
| 3725 0); // route_id | 3727 0); // route_id |
| 3726 } | 3728 } |
| 3727 | 3729 |
| 3728 // Confirm that resource response started notifications for downloads are not | 3730 // Confirm that resource response started notifications for downloads are not |
| 3729 // transmitted to the WebContents. | 3731 // transmitted to the WebContents. |
| 3730 TEST_F(ResourceDispatcherHostTest, TransferResponseStartedDownload) { | 3732 TEST_F(ResourceDispatcherHostTest, TransferResponseStartedDownload) { |
| 3731 int initial_count(web_contents_observer_->resource_response_start_count()); | 3733 int initial_count(web_contents_observer_->resource_response_start_count()); |
| 3732 | 3734 |
| 3733 MakeWebContentsAssociatedDownloadRequest( | 3735 MakeWebContentsAssociatedDownloadRequest( |
| 3734 1, net::URLRequestTestJob::test_url_1()); | 3736 1, net::URLRequestTestJob::test_url_1()); |
| 3735 base::RunLoop().RunUntilIdle(); | 3737 content::RunAllBlockingPoolTasksUntilIdle(); |
| 3736 EXPECT_EQ(initial_count, | 3738 EXPECT_EQ(initial_count, |
| 3737 web_contents_observer_->resource_response_start_count()); | 3739 web_contents_observer_->resource_response_start_count()); |
| 3738 } | 3740 } |
| 3739 | 3741 |
| 3740 // Confirm that request redirected notifications for downloads are not | 3742 // Confirm that request redirected notifications for downloads are not |
| 3741 // transmitted to the WebContents. | 3743 // transmitted to the WebContents. |
| 3742 TEST_F(ResourceDispatcherHostTest, TransferRequestRedirectedDownload) { | 3744 TEST_F(ResourceDispatcherHostTest, TransferRequestRedirectedDownload) { |
| 3743 int initial_count(web_contents_observer_->resource_request_redirect_count()); | 3745 int initial_count(web_contents_observer_->resource_request_redirect_count()); |
| 3744 | 3746 |
| 3745 MakeWebContentsAssociatedDownloadRequest( | 3747 MakeWebContentsAssociatedDownloadRequest( |
| 3746 1, net::URLRequestTestJob::test_url_redirect_to_url_2()); | 3748 1, net::URLRequestTestJob::test_url_redirect_to_url_2()); |
| 3747 base::RunLoop().RunUntilIdle(); | 3749 content::RunAllBlockingPoolTasksUntilIdle(); |
| 3748 EXPECT_EQ(initial_count, | 3750 EXPECT_EQ(initial_count, |
| 3749 web_contents_observer_->resource_request_redirect_count()); | 3751 web_contents_observer_->resource_request_redirect_count()); |
| 3750 } | 3752 } |
| 3751 | 3753 |
| 3752 // Tests that a ResourceThrottle that needs to process the response before any | 3754 // Tests that a ResourceThrottle that needs to process the response before any |
| 3753 // part of the body is read can do so. | 3755 // part of the body is read can do so. |
| 3754 TEST_F(ResourceDispatcherHostTest, ThrottleMustProcessResponseBeforeRead) { | 3756 TEST_F(ResourceDispatcherHostTest, ThrottleMustProcessResponseBeforeRead) { |
| 3755 // Ensure all jobs will check that no read operation is called. | 3757 // Ensure all jobs will check that no read operation is called. |
| 3756 job_factory_->SetMustNotReadJobGeneration(true); | 3758 job_factory_->SetMustNotReadJobGeneration(true); |
| 3757 HandleScheme("http"); | 3759 HandleScheme("http"); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 3771 "Content-Type: text/plain; charset=utf-8\n\n"); | 3773 "Content-Type: text/plain; charset=utf-8\n\n"); |
| 3772 std::string response_data("p { text-align: center; }"); | 3774 std::string response_data("p { text-align: center; }"); |
| 3773 SetResponse(raw_headers, response_data); | 3775 SetResponse(raw_headers, response_data); |
| 3774 | 3776 |
| 3775 MakeTestRequestWithResourceType(filter_.get(), filter_->child_id(), 1, | 3777 MakeTestRequestWithResourceType(filter_.get(), filter_->child_id(), 1, |
| 3776 GURL("http://example.com/blah"), | 3778 GURL("http://example.com/blah"), |
| 3777 RESOURCE_TYPE_STYLESHEET); | 3779 RESOURCE_TYPE_STYLESHEET); |
| 3778 | 3780 |
| 3779 while (net::URLRequestTestJob::ProcessOnePendingMessage()) { | 3781 while (net::URLRequestTestJob::ProcessOnePendingMessage()) { |
| 3780 } | 3782 } |
| 3781 base::RunLoop().RunUntilIdle(); | 3783 content::RunAllBlockingPoolTasksUntilIdle(); |
| 3782 } | 3784 } |
| 3783 | 3785 |
| 3784 namespace { | 3786 namespace { |
| 3785 | 3787 |
| 3786 void StoreSyncLoadResult(bool* called, | 3788 void StoreSyncLoadResult(bool* called, |
| 3787 bool* was_null, | 3789 bool* was_null, |
| 3788 SyncLoadResult* result_out, | 3790 SyncLoadResult* result_out, |
| 3789 const SyncLoadResult* result) { | 3791 const SyncLoadResult* result) { |
| 3790 *called = true; | 3792 *called = true; |
| 3791 *was_null = !result; | 3793 *was_null = !result; |
| 3792 | 3794 |
| 3793 if (result) | 3795 if (result) |
| 3794 *result_out = *result; | 3796 *result_out = *result; |
| 3795 } | 3797 } |
| 3796 | 3798 |
| 3797 } // namespace | 3799 } // namespace |
| 3798 | 3800 |
| 3799 TEST_F(ResourceDispatcherHostTest, SyncLoadWithMojoSuccess) { | 3801 TEST_F(ResourceDispatcherHostTest, SyncLoadWithMojoSuccess) { |
| 3800 ResourceRequest request = CreateResourceRequest( | 3802 ResourceRequest request = CreateResourceRequest( |
| 3801 "GET", RESOURCE_TYPE_XHR, net::URLRequestTestJob::test_url_1()); | 3803 "GET", RESOURCE_TYPE_XHR, net::URLRequestTestJob::test_url_1()); |
| 3802 request.priority = net::MAXIMUM_PRIORITY; | 3804 request.priority = net::MAXIMUM_PRIORITY; |
| 3803 | 3805 |
| 3804 bool called = false; | 3806 bool called = false; |
| 3805 bool was_null = false; | 3807 bool was_null = false; |
| 3806 SyncLoadResult result; | 3808 SyncLoadResult result; |
| 3807 host_.OnSyncLoadWithMojo( | 3809 host_.OnSyncLoadWithMojo( |
| 3808 GetResourceRequesterInfo(filter_.get()), 0, 1, request, | 3810 GetResourceRequesterInfo(filter_.get()), 0, 1, request, |
| 3809 base::Bind(&StoreSyncLoadResult, &called, &was_null, &result)); | 3811 base::Bind(&StoreSyncLoadResult, &called, &was_null, &result)); |
| 3810 base::RunLoop().RunUntilIdle(); | 3812 content::RunAllBlockingPoolTasksUntilIdle(); |
| 3811 EXPECT_TRUE(called); | 3813 EXPECT_TRUE(called); |
| 3812 EXPECT_FALSE(was_null); | 3814 EXPECT_FALSE(was_null); |
| 3813 EXPECT_EQ(net::OK, result.error_code); | 3815 EXPECT_EQ(net::OK, result.error_code); |
| 3814 } | 3816 } |
| 3815 | 3817 |
| 3816 TEST_F(ResourceDispatcherHostTest, SyncLoadWithMojoError) { | 3818 TEST_F(ResourceDispatcherHostTest, SyncLoadWithMojoError) { |
| 3817 ResourceRequest request = CreateResourceRequest( | 3819 ResourceRequest request = CreateResourceRequest( |
| 3818 "GET", RESOURCE_TYPE_XHR, net::URLRequestTestJob::test_url_error()); | 3820 "GET", RESOURCE_TYPE_XHR, net::URLRequestTestJob::test_url_error()); |
| 3819 request.priority = net::MAXIMUM_PRIORITY; | 3821 request.priority = net::MAXIMUM_PRIORITY; |
| 3820 | 3822 |
| 3821 bool called = false; | 3823 bool called = false; |
| 3822 bool was_null = false; | 3824 bool was_null = false; |
| 3823 SyncLoadResult result; | 3825 SyncLoadResult result; |
| 3824 host_.OnSyncLoadWithMojo( | 3826 host_.OnSyncLoadWithMojo( |
| 3825 GetResourceRequesterInfo(filter_.get()), 0, 1, request, | 3827 GetResourceRequesterInfo(filter_.get()), 0, 1, request, |
| 3826 base::Bind(&StoreSyncLoadResult, &called, &was_null, &result)); | 3828 base::Bind(&StoreSyncLoadResult, &called, &was_null, &result)); |
| 3827 base::RunLoop().RunUntilIdle(); | 3829 content::RunAllBlockingPoolTasksUntilIdle(); |
| 3828 EXPECT_TRUE(called); | 3830 EXPECT_TRUE(called); |
| 3829 EXPECT_FALSE(was_null); | 3831 EXPECT_FALSE(was_null); |
| 3830 EXPECT_EQ(net::ERR_INVALID_URL, result.error_code); | 3832 EXPECT_EQ(net::ERR_INVALID_URL, result.error_code); |
| 3831 } | 3833 } |
| 3832 | 3834 |
| 3833 TEST_F(ResourceDispatcherHostTest, SyncLoadWithMojoCancel) { | 3835 TEST_F(ResourceDispatcherHostTest, SyncLoadWithMojoCancel) { |
| 3834 ResourceRequest request = CreateResourceRequest( | 3836 ResourceRequest request = CreateResourceRequest( |
| 3835 "GET", RESOURCE_TYPE_XHR, net::URLRequestTestJob::test_url_error()); | 3837 "GET", RESOURCE_TYPE_XHR, net::URLRequestTestJob::test_url_error()); |
| 3836 request.priority = net::MAXIMUM_PRIORITY; | 3838 request.priority = net::MAXIMUM_PRIORITY; |
| 3837 | 3839 |
| 3838 bool called = false; | 3840 bool called = false; |
| 3839 bool was_null = false; | 3841 bool was_null = false; |
| 3840 SyncLoadResult result; | 3842 SyncLoadResult result; |
| 3841 host_.OnSyncLoadWithMojo( | 3843 host_.OnSyncLoadWithMojo( |
| 3842 GetResourceRequesterInfo(filter_.get()), 0, 1, request, | 3844 GetResourceRequesterInfo(filter_.get()), 0, 1, request, |
| 3843 base::Bind(&StoreSyncLoadResult, &called, &was_null, &result)); | 3845 base::Bind(&StoreSyncLoadResult, &called, &was_null, &result)); |
| 3844 host_.CancelRequestsForProcess(filter_->child_id()); | 3846 host_.CancelRequestsForProcess(filter_->child_id()); |
| 3845 base::RunLoop().RunUntilIdle(); | 3847 content::RunAllBlockingPoolTasksUntilIdle(); |
| 3846 EXPECT_TRUE(called); | 3848 EXPECT_TRUE(called); |
| 3847 EXPECT_TRUE(was_null); | 3849 EXPECT_TRUE(was_null); |
| 3848 } | 3850 } |
| 3849 | 3851 |
| 3850 // A URLRequestTestJob that sets a test certificate on the |ssl_info| | 3852 // A URLRequestTestJob that sets a test certificate on the |ssl_info| |
| 3851 // field of the response. | 3853 // field of the response. |
| 3852 class TestHTTPSURLRequestJob : public net::URLRequestTestJob { | 3854 class TestHTTPSURLRequestJob : public net::URLRequestTestJob { |
| 3853 public: | 3855 public: |
| 3854 TestHTTPSURLRequestJob(net::URLRequest* request, | 3856 TestHTTPSURLRequestJob(net::URLRequest* request, |
| 3855 net::NetworkDelegate* network_delegate, | 3857 net::NetworkDelegate* network_delegate, |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3924 return nullptr; | 3926 return nullptr; |
| 3925 } | 3927 } |
| 3926 | 3928 |
| 3927 net::URLRequestJob* TestURLRequestJobFactory::MaybeInterceptResponse( | 3929 net::URLRequestJob* TestURLRequestJobFactory::MaybeInterceptResponse( |
| 3928 net::URLRequest* request, | 3930 net::URLRequest* request, |
| 3929 net::NetworkDelegate* network_delegate) const { | 3931 net::NetworkDelegate* network_delegate) const { |
| 3930 return nullptr; | 3932 return nullptr; |
| 3931 } | 3933 } |
| 3932 | 3934 |
| 3933 } // namespace content | 3935 } // namespace content |
| OLD | NEW |