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

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

Issue 2767923002: Always use an async TaskScheduler in TestBrowserThreadBundle. (Closed)
Patch Set: CR-mmenke-remove-extra-semi-colons Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <stddef.h> 5 #include <stddef.h>
6 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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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();
2618
mmenke 2017/04/05 15:14:16 nit: Remove blank line.
fdoray 2017/04/05 15:45:57 Done.
2616 } else { 2619 } else {
2617 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id, 2620 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id,
2618 download_url, RESOURCE_TYPE_MAIN_FRAME); 2621 download_url, RESOURCE_TYPE_MAIN_FRAME);
2619 2622
2620 // Return some data so that the request is identified as a download 2623 // Return some data so that the request is identified as a download
2621 // and the proper resource handlers are created. 2624 // and the proper resource handlers are created.
2622 EXPECT_TRUE(net::URLRequestTestJob::ProcessOnePendingMessage()); 2625 EXPECT_TRUE(net::URLRequestTestJob::ProcessOnePendingMessage());
2623 base::RunLoop().RunUntilIdle(); 2626 content::RunAllBlockingPoolTasksUntilIdle();
2624 2627
2625 // And now simulate a cancellation coming from the renderer. 2628 // And now simulate a cancellation coming from the renderer.
2626 ResourceHostMsg_CancelRequest msg(request_id); 2629 ResourceHostMsg_CancelRequest msg(request_id);
2627 OnMessageReceived(msg, filter_.get()); 2630 OnMessageReceived(msg, filter_.get());
2628 2631
2629 // Since the request had already started processing as a download, 2632 // Since the request had already started processing as a download,
2630 // the cancellation above should have been ignored and the request 2633 // the cancellation above should have been ignored and the request
2631 // should still be alive. 2634 // should still be alive.
2632 EXPECT_EQ(1, host_.pending_requests()); 2635 EXPECT_EQ(1, host_.pending_requests());
2633 2636
2634 // Cancelling by other methods shouldn't work either. 2637 // Cancelling by other methods shouldn't work either.
2635 host_.CancelRequestsForProcess(render_view_id); 2638 host_.CancelRequestsForProcess(render_view_id);
2636 EXPECT_EQ(1, host_.pending_requests()); 2639 EXPECT_EQ(1, host_.pending_requests());
2637 2640
2638 // Cancelling by context should work. 2641 // Cancelling by context should work.
2639 host_.CancelRequestsForContext(filter_->resource_context()); 2642 host_.CancelRequestsForContext(filter_->resource_context());
2640 EXPECT_EQ(0, host_.pending_requests()); 2643 EXPECT_EQ(0, host_.pending_requests());
2641 2644
2642 while (net::URLRequestTestJob::ProcessOnePendingMessage()) { 2645 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {
2643 } 2646 }
2644 base::RunLoop().RunUntilIdle(); 2647 content::RunAllBlockingPoolTasksUntilIdle();
2645 } 2648 }
2646 } 2649 }
2647 2650
2648 TEST_F(ResourceDispatcherHostTest, CancelRequestsForContextDetached) { 2651 TEST_F(ResourceDispatcherHostTest, CancelRequestsForContextDetached) {
2649 EXPECT_EQ(0, host_.pending_requests()); 2652 EXPECT_EQ(0, host_.pending_requests());
2650 2653
2651 int render_view_id = 0; 2654 int render_view_id = 0;
2652 int request_id = 1; 2655 int request_id = 1;
2653 2656
2654 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id, 2657 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id,
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
2745 RESOURCE_TYPE_MAIN_FRAME); 2748 RESOURCE_TYPE_MAIN_FRAME);
2746 2749
2747 // Now that we're blocked on the redirect, update the response and unblock by 2750 // Now that we're blocked on the redirect, update the response and unblock by
2748 // telling the AsyncResourceHandler to follow the redirect. 2751 // telling the AsyncResourceHandler to follow the redirect.
2749 const std::string kResponseBody = "hello world"; 2752 const std::string kResponseBody = "hello world";
2750 SetResponse("HTTP/1.1 200 OK\n" 2753 SetResponse("HTTP/1.1 200 OK\n"
2751 "Content-Type: text/html\n\n", 2754 "Content-Type: text/html\n\n",
2752 kResponseBody); 2755 kResponseBody);
2753 ResourceHostMsg_FollowRedirect redirect_msg(request_id); 2756 ResourceHostMsg_FollowRedirect redirect_msg(request_id);
2754 OnMessageReceived(redirect_msg, filter_.get()); 2757 OnMessageReceived(redirect_msg, filter_.get());
2755 base::RunLoop().RunUntilIdle(); 2758 content::RunAllBlockingPoolTasksUntilIdle();
2756 2759
2757 // Flush all the pending requests to get the response through the 2760 // Flush all the pending requests to get the response through the
2758 // MimeTypeResourceHandler. 2761 // MimeTypeResourceHandler.
2759 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} 2762 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {}
2760 2763
2761 // This second filter is used to emulate a second process. 2764 // This second filter is used to emulate a second process.
2762 scoped_refptr<ForwardingFilter> second_filter = MakeForwardingFilter(); 2765 scoped_refptr<ForwardingFilter> second_filter = MakeForwardingFilter();
2763 2766
2764 int new_render_view_id = 1; 2767 int new_render_view_id = 1;
2765 int new_request_id = 2; 2768 int new_request_id = 2;
2766 2769
2767 ResourceRequest request = CreateResourceRequest( 2770 ResourceRequest request = CreateResourceRequest(
2768 "GET", RESOURCE_TYPE_MAIN_FRAME, GURL("http://other.com/blech")); 2771 "GET", RESOURCE_TYPE_MAIN_FRAME, GURL("http://other.com/blech"));
2769 request.transferred_request_child_id = filter_->child_id(); 2772 request.transferred_request_child_id = filter_->child_id();
2770 request.transferred_request_request_id = request_id; 2773 request.transferred_request_request_id = request_id;
2771 2774
2772 ResourceHostMsg_RequestResource transfer_request_msg( 2775 ResourceHostMsg_RequestResource transfer_request_msg(
2773 new_render_view_id, new_request_id, request); 2776 new_render_view_id, new_request_id, request);
2774 OnMessageReceived(transfer_request_msg, second_filter.get()); 2777 OnMessageReceived(transfer_request_msg, second_filter.get());
2775 base::RunLoop().RunUntilIdle(); 2778 content::RunAllBlockingPoolTasksUntilIdle();
2776 2779
2777 // Check generated messages. 2780 // Check generated messages.
2778 ResourceIPCAccumulator::ClassifiedMessages msgs; 2781 ResourceIPCAccumulator::ClassifiedMessages msgs;
2779 accum_.GetClassifiedMessages(&msgs); 2782 accum_.GetClassifiedMessages(&msgs);
2780 2783
2781 ASSERT_EQ(2U, msgs.size()); 2784 ASSERT_EQ(2U, msgs.size());
2782 EXPECT_EQ(ResourceMsg_ReceivedRedirect::ID, msgs[0][0].type()); 2785 EXPECT_EQ(ResourceMsg_ReceivedRedirect::ID, msgs[0][0].type());
2783 CheckSuccessfulRequest(msgs[1], kResponseBody); 2786 CheckSuccessfulRequest(msgs[1], kResponseBody);
2784 2787
2785 second_filter->OnChannelClosing(); 2788 second_filter->OnChannelClosing();
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
2834 int new_render_view_id = 1; 2837 int new_render_view_id = 1;
2835 int new_request_id = 5; 2838 int new_request_id = 5;
2836 ResourceRequest request = CreateResourceRequest( 2839 ResourceRequest request = CreateResourceRequest(
2837 "GET", RESOURCE_TYPE_MAIN_FRAME, GURL("http://example.com/blah")); 2840 "GET", RESOURCE_TYPE_MAIN_FRAME, GURL("http://example.com/blah"));
2838 request.transferred_request_child_id = filter_->child_id(); 2841 request.transferred_request_child_id = filter_->child_id();
2839 request.transferred_request_request_id = request_id; 2842 request.transferred_request_request_id = request_id;
2840 2843
2841 ResourceHostMsg_RequestResource transfer_request_msg( 2844 ResourceHostMsg_RequestResource transfer_request_msg(
2842 new_render_view_id, new_request_id, request); 2845 new_render_view_id, new_request_id, request);
2843 OnMessageReceived(transfer_request_msg, second_filter.get()); 2846 OnMessageReceived(transfer_request_msg, second_filter.get());
2844 base::RunLoop().RunUntilIdle(); 2847 content::RunAllBlockingPoolTasksUntilIdle();
2845 2848
2846 // Transfer the second request. 2849 // Transfer the second request.
2847 int new_second_request_id = 6; 2850 int new_second_request_id = 6;
2848 ResourceRequest second_request = CreateResourceRequest( 2851 ResourceRequest second_request = CreateResourceRequest(
2849 "GET", RESOURCE_TYPE_MAIN_FRAME, GURL("http://example.com/foo")); 2852 "GET", RESOURCE_TYPE_MAIN_FRAME, GURL("http://example.com/foo"));
2850 request.transferred_request_child_id = filter_->child_id(); 2853 request.transferred_request_child_id = filter_->child_id();
2851 request.transferred_request_request_id = second_request_id; 2854 request.transferred_request_request_id = second_request_id;
2852 2855
2853 ResourceHostMsg_RequestResource second_transfer_request_msg( 2856 ResourceHostMsg_RequestResource second_transfer_request_msg(
2854 new_render_view_id, new_second_request_id, second_request); 2857 new_render_view_id, new_second_request_id, second_request);
2855 OnMessageReceived(second_transfer_request_msg, second_filter.get()); 2858 OnMessageReceived(second_transfer_request_msg, second_filter.get());
2856 base::RunLoop().RunUntilIdle(); 2859 content::RunAllBlockingPoolTasksUntilIdle();
2857 2860
2858 // Check generated messages. 2861 // Check generated messages.
2859 ResourceIPCAccumulator::ClassifiedMessages msgs; 2862 ResourceIPCAccumulator::ClassifiedMessages msgs;
2860 accum_.GetClassifiedMessages(&msgs); 2863 accum_.GetClassifiedMessages(&msgs);
2861 2864
2862 ASSERT_EQ(2U, msgs.size()); 2865 ASSERT_EQ(2U, msgs.size());
2863 CheckSuccessfulRequest(msgs[0], kResponseBody); 2866 CheckSuccessfulRequest(msgs[0], kResponseBody);
2864 2867
2865 second_filter->OnChannelClosing(); 2868 second_filter->OnChannelClosing();
2866 } 2869 }
(...skipping 28 matching lines...) Expand all
2895 // Now that we're blocked on the redirect, update the response and unblock by 2898 // 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 2899 // telling the AsyncResourceHandler to follow the redirect. Use a text/plain
2897 // MIME type, which causes MimeTypeResourceHandler to buffer it before the 2900 // MIME type, which causes MimeTypeResourceHandler to buffer it before the
2898 // transfer occurs. 2901 // transfer occurs.
2899 const std::string kResponseBody = "hello world"; 2902 const std::string kResponseBody = "hello world";
2900 SetResponse("HTTP/1.1 200 OK\n" 2903 SetResponse("HTTP/1.1 200 OK\n"
2901 "Content-Type: text/plain\n\n", 2904 "Content-Type: text/plain\n\n",
2902 kResponseBody); 2905 kResponseBody);
2903 ResourceHostMsg_FollowRedirect redirect_msg(request_id); 2906 ResourceHostMsg_FollowRedirect redirect_msg(request_id);
2904 OnMessageReceived(redirect_msg, filter_.get()); 2907 OnMessageReceived(redirect_msg, filter_.get());
2905 base::RunLoop().RunUntilIdle(); 2908 content::RunAllBlockingPoolTasksUntilIdle();
2906 2909
2907 // Flush all the pending requests to get the response through the 2910 // Flush all the pending requests to get the response through the
2908 // MimeTypeResourceHandler. 2911 // MimeTypeResourceHandler.
2909 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} 2912 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {}
2910 base::RunLoop().RunUntilIdle(); 2913 content::RunAllBlockingPoolTasksUntilIdle();
2911 2914
2912 // This second filter is used to emulate a second process. 2915 // This second filter is used to emulate a second process.
2913 scoped_refptr<ForwardingFilter> second_filter = MakeForwardingFilter(); 2916 scoped_refptr<ForwardingFilter> second_filter = MakeForwardingFilter();
2914 2917
2915 int new_render_view_id = 1; 2918 int new_render_view_id = 1;
2916 int new_request_id = 2; 2919 int new_request_id = 2;
2917 2920
2918 ResourceRequest request = CreateResourceRequest( 2921 ResourceRequest request = CreateResourceRequest(
2919 "GET", RESOURCE_TYPE_MAIN_FRAME, GURL("http://other.com/blech")); 2922 "GET", RESOURCE_TYPE_MAIN_FRAME, GURL("http://other.com/blech"));
2920 request.transferred_request_child_id = filter_->child_id(); 2923 request.transferred_request_child_id = filter_->child_id();
2921 request.transferred_request_request_id = request_id; 2924 request.transferred_request_request_id = request_id;
2922 2925
2923 ResourceHostMsg_RequestResource transfer_request_msg( 2926 ResourceHostMsg_RequestResource transfer_request_msg(
2924 new_render_view_id, new_request_id, request); 2927 new_render_view_id, new_request_id, request);
2925 OnMessageReceived(transfer_request_msg, second_filter.get()); 2928 OnMessageReceived(transfer_request_msg, second_filter.get());
2926 base::RunLoop().RunUntilIdle(); 2929 content::RunAllBlockingPoolTasksUntilIdle();
2927 2930
2928 // Check generated messages. 2931 // Check generated messages.
2929 ResourceIPCAccumulator::ClassifiedMessages msgs; 2932 ResourceIPCAccumulator::ClassifiedMessages msgs;
2930 accum_.GetClassifiedMessages(&msgs); 2933 accum_.GetClassifiedMessages(&msgs);
2931 2934
2932 ASSERT_EQ(2U, msgs.size()); 2935 ASSERT_EQ(2U, msgs.size());
2933 EXPECT_EQ(ResourceMsg_ReceivedRedirect::ID, msgs[0][0].type()); 2936 EXPECT_EQ(ResourceMsg_ReceivedRedirect::ID, msgs[0][0].type());
2934 CheckSuccessfulRequest(msgs[1], kResponseBody); 2937 CheckSuccessfulRequest(msgs[1], kResponseBody);
2935 2938
2936 second_filter->OnChannelClosing(); 2939 second_filter->OnChannelClosing();
(...skipping 25 matching lines...) Expand all
2962 { 2965 {
2963 scoped_refptr<ForwardingFilter> first_filter = MakeForwardingFilter(); 2966 scoped_refptr<ForwardingFilter> first_filter = MakeForwardingFilter();
2964 first_child_id = first_filter->child_id(); 2967 first_child_id = first_filter->child_id();
2965 2968
2966 ResourceRequest first_request = CreateResourceRequest( 2969 ResourceRequest first_request = CreateResourceRequest(
2967 "GET", RESOURCE_TYPE_MAIN_FRAME, GURL("http://example.com/blah")); 2970 "GET", RESOURCE_TYPE_MAIN_FRAME, GURL("http://example.com/blah"));
2968 2971
2969 ResourceHostMsg_RequestResource first_request_msg( 2972 ResourceHostMsg_RequestResource first_request_msg(
2970 render_view_id, request_id, first_request); 2973 render_view_id, request_id, first_request);
2971 OnMessageReceived(first_request_msg, first_filter.get()); 2974 OnMessageReceived(first_request_msg, first_filter.get());
2972 base::RunLoop().RunUntilIdle(); 2975 content::RunAllBlockingPoolTasksUntilIdle();
2973 2976
2974 // Now that we're blocked on the redirect, update the response and unblock 2977 // Now that we're blocked on the redirect, update the response and unblock
2975 // by telling the AsyncResourceHandler to follow the redirect. 2978 // by telling the AsyncResourceHandler to follow the redirect.
2976 SetResponse("HTTP/1.1 200 OK\n" 2979 SetResponse("HTTP/1.1 200 OK\n"
2977 "Content-Type: text/html\n\n", 2980 "Content-Type: text/html\n\n",
2978 kResponseBody); 2981 kResponseBody);
2979 ResourceHostMsg_FollowRedirect redirect_msg(request_id); 2982 ResourceHostMsg_FollowRedirect redirect_msg(request_id);
2980 OnMessageReceived(redirect_msg, first_filter.get()); 2983 OnMessageReceived(redirect_msg, first_filter.get());
2981 base::RunLoop().RunUntilIdle(); 2984 content::RunAllBlockingPoolTasksUntilIdle();
2982 2985
2983 // Flush all the pending requests to get the response through the 2986 // Flush all the pending requests to get the response through the
2984 // MimeTypeResourceHandler. 2987 // MimeTypeResourceHandler.
2985 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} 2988 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {}
2986 2989
2987 first_filter->OnChannelClosing(); 2990 first_filter->OnChannelClosing();
2988 } 2991 }
2989 // The first filter is now deleted, as if the child process died. 2992 // The first filter is now deleted, as if the child process died.
2990 2993
2991 // Make sure we don't hold onto the ResourceMessageFilter after it is deleted. 2994 // Make sure we don't hold onto the ResourceMessageFilter after it is deleted.
2992 GlobalRequestID first_global_request_id(first_child_id, request_id); 2995 GlobalRequestID first_global_request_id(first_child_id, request_id);
2993 2996
2994 // This second filter is used to emulate a second process. 2997 // This second filter is used to emulate a second process.
2995 scoped_refptr<ForwardingFilter> second_filter = MakeForwardingFilter(); 2998 scoped_refptr<ForwardingFilter> second_filter = MakeForwardingFilter();
2996 2999
2997 int new_render_view_id = 1; 3000 int new_render_view_id = 1;
2998 int new_request_id = 2; 3001 int new_request_id = 2;
2999 3002
3000 ResourceRequest request = CreateResourceRequest( 3003 ResourceRequest request = CreateResourceRequest(
3001 "GET", RESOURCE_TYPE_MAIN_FRAME, GURL("http://other.com/blech")); 3004 "GET", RESOURCE_TYPE_MAIN_FRAME, GURL("http://other.com/blech"));
3002 request.transferred_request_child_id = first_child_id; 3005 request.transferred_request_child_id = first_child_id;
3003 request.transferred_request_request_id = request_id; 3006 request.transferred_request_request_id = request_id;
3004 3007
3005 // For cleanup. 3008 // For cleanup.
3006 child_ids_.insert(second_filter->child_id()); 3009 child_ids_.insert(second_filter->child_id());
3007 ResourceHostMsg_RequestResource transfer_request_msg( 3010 ResourceHostMsg_RequestResource transfer_request_msg(
3008 new_render_view_id, new_request_id, request); 3011 new_render_view_id, new_request_id, request);
3009 OnMessageReceived(transfer_request_msg, second_filter.get()); 3012 OnMessageReceived(transfer_request_msg, second_filter.get());
3010 base::RunLoop().RunUntilIdle(); 3013 content::RunAllBlockingPoolTasksUntilIdle();
3011 3014
3012 // Check generated messages. 3015 // Check generated messages.
3013 ResourceIPCAccumulator::ClassifiedMessages msgs; 3016 ResourceIPCAccumulator::ClassifiedMessages msgs;
3014 accum_.GetClassifiedMessages(&msgs); 3017 accum_.GetClassifiedMessages(&msgs);
3015 3018
3016 ASSERT_EQ(2U, msgs.size()); 3019 ASSERT_EQ(2U, msgs.size());
3017 EXPECT_EQ(ResourceMsg_ReceivedRedirect::ID, msgs[0][0].type()); 3020 EXPECT_EQ(ResourceMsg_ReceivedRedirect::ID, msgs[0][0].type());
3018 CheckSuccessfulRequest(msgs[1], kResponseBody); 3021 CheckSuccessfulRequest(msgs[1], kResponseBody);
3019 3022
3020 second_filter->OnChannelClosing(); 3023 second_filter->OnChannelClosing();
(...skipping 21 matching lines...) Expand all
3042 3045
3043 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id, 3046 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id,
3044 GURL("http://example.com/blah"), 3047 GURL("http://example.com/blah"),
3045 RESOURCE_TYPE_MAIN_FRAME); 3048 RESOURCE_TYPE_MAIN_FRAME);
3046 3049
3047 // Now that we're blocked on the redirect, simulate hitting another redirect. 3050 // Now that we're blocked on the redirect, simulate hitting another redirect.
3048 SetResponse("HTTP/1.1 302 Found\n" 3051 SetResponse("HTTP/1.1 302 Found\n"
3049 "Location: http://other.com/blerg\n\n"); 3052 "Location: http://other.com/blerg\n\n");
3050 ResourceHostMsg_FollowRedirect redirect_msg(request_id); 3053 ResourceHostMsg_FollowRedirect redirect_msg(request_id);
3051 OnMessageReceived(redirect_msg, filter_.get()); 3054 OnMessageReceived(redirect_msg, filter_.get());
3052 base::RunLoop().RunUntilIdle(); 3055 content::RunAllBlockingPoolTasksUntilIdle();
3053 3056
3054 // Now that we're blocked on the second redirect, update the response and 3057 // Now that we're blocked on the second redirect, update the response and
3055 // unblock by telling the AsyncResourceHandler to follow the redirect. 3058 // unblock by telling the AsyncResourceHandler to follow the redirect.
3056 // Again, use text/plain to force MimeTypeResourceHandler to buffer before 3059 // Again, use text/plain to force MimeTypeResourceHandler to buffer before
3057 // the transfer. 3060 // the transfer.
3058 const std::string kResponseBody = "hello world"; 3061 const std::string kResponseBody = "hello world";
3059 SetResponse("HTTP/1.1 200 OK\n" 3062 SetResponse("HTTP/1.1 200 OK\n"
3060 "Content-Type: text/plain\n\n", 3063 "Content-Type: text/plain\n\n",
3061 kResponseBody); 3064 kResponseBody);
3062 ResourceHostMsg_FollowRedirect redirect_msg2(request_id); 3065 ResourceHostMsg_FollowRedirect redirect_msg2(request_id);
3063 OnMessageReceived(redirect_msg2, filter_.get()); 3066 OnMessageReceived(redirect_msg2, filter_.get());
3064 base::RunLoop().RunUntilIdle(); 3067 content::RunAllBlockingPoolTasksUntilIdle();
3065 3068
3066 // Flush all the pending requests to get the response through the 3069 // Flush all the pending requests to get the response through the
3067 // MimeTypeResourceHandler. 3070 // MimeTypeResourceHandler.
3068 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} 3071 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {}
3069 base::RunLoop().RunUntilIdle(); 3072 content::RunAllBlockingPoolTasksUntilIdle();
3070 3073
3071 // This second filter is used to emulate a second process. 3074 // This second filter is used to emulate a second process.
3072 scoped_refptr<ForwardingFilter> second_filter = MakeForwardingFilter(); 3075 scoped_refptr<ForwardingFilter> second_filter = MakeForwardingFilter();
3073 3076
3074 int new_render_view_id = 1; 3077 int new_render_view_id = 1;
3075 int new_request_id = 2; 3078 int new_request_id = 2;
3076 3079
3077 ResourceRequest request = CreateResourceRequest( 3080 ResourceRequest request = CreateResourceRequest(
3078 "GET", RESOURCE_TYPE_MAIN_FRAME, GURL("http://other.com/blech")); 3081 "GET", RESOURCE_TYPE_MAIN_FRAME, GURL("http://other.com/blech"));
3079 request.transferred_request_child_id = filter_->child_id(); 3082 request.transferred_request_child_id = filter_->child_id();
3080 request.transferred_request_request_id = request_id; 3083 request.transferred_request_request_id = request_id;
3081 3084
3082 // For cleanup. 3085 // For cleanup.
3083 child_ids_.insert(second_filter->child_id()); 3086 child_ids_.insert(second_filter->child_id());
3084 ResourceHostMsg_RequestResource transfer_request_msg( 3087 ResourceHostMsg_RequestResource transfer_request_msg(
3085 new_render_view_id, new_request_id, request); 3088 new_render_view_id, new_request_id, request);
3086 OnMessageReceived(transfer_request_msg, second_filter.get()); 3089 OnMessageReceived(transfer_request_msg, second_filter.get());
3087 3090
3088 // Verify that we update the ResourceRequestInfo. 3091 // Verify that we update the ResourceRequestInfo.
3089 GlobalRequestID global_request_id(second_filter->child_id(), new_request_id); 3092 GlobalRequestID global_request_id(second_filter->child_id(), new_request_id);
3090 ResourceRequestInfoImpl* info = ResourceRequestInfoImpl::ForRequest( 3093 ResourceRequestInfoImpl* info = ResourceRequestInfoImpl::ForRequest(
3091 host_.GetURLRequest(global_request_id)); 3094 host_.GetURLRequest(global_request_id));
3092 EXPECT_EQ(second_filter->child_id(), info->GetChildID()); 3095 EXPECT_EQ(second_filter->child_id(), info->GetChildID());
3093 EXPECT_EQ(new_render_view_id, info->GetRouteID()); 3096 EXPECT_EQ(new_render_view_id, info->GetRouteID());
3094 EXPECT_EQ(new_request_id, info->GetRequestID()); 3097 EXPECT_EQ(new_request_id, info->GetRequestID());
3095 EXPECT_EQ(second_filter.get(), info->requester_info()->filter()); 3098 EXPECT_EQ(second_filter.get(), info->requester_info()->filter());
3096 3099
3097 // Let request complete. 3100 // Let request complete.
3098 base::RunLoop().RunUntilIdle(); 3101 content::RunAllBlockingPoolTasksUntilIdle();
3099 3102
3100 // Check generated messages. 3103 // Check generated messages.
3101 ResourceIPCAccumulator::ClassifiedMessages msgs; 3104 ResourceIPCAccumulator::ClassifiedMessages msgs;
3102 accum_.GetClassifiedMessages(&msgs); 3105 accum_.GetClassifiedMessages(&msgs);
3103 3106
3104 ASSERT_EQ(2U, msgs.size()); 3107 ASSERT_EQ(2U, msgs.size());
3105 EXPECT_EQ(ResourceMsg_ReceivedRedirect::ID, msgs[0][0].type()); 3108 EXPECT_EQ(ResourceMsg_ReceivedRedirect::ID, msgs[0][0].type());
3106 CheckSuccessfulRequest(msgs[1], kResponseBody); 3109 CheckSuccessfulRequest(msgs[1], kResponseBody);
3107 3110
3108 second_filter->OnChannelClosing(); 3111 second_filter->OnChannelClosing();
(...skipping 12 matching lines...) Expand all
3121 } 3124 }
3122 3125
3123 TEST_F(ResourceDispatcherHostTest, DataReceivedACKs) { 3126 TEST_F(ResourceDispatcherHostTest, DataReceivedACKs) {
3124 EXPECT_EQ(0, host_.pending_requests()); 3127 EXPECT_EQ(0, host_.pending_requests());
3125 3128
3126 SendDataReceivedACKs(true); 3129 SendDataReceivedACKs(true);
3127 3130
3128 HandleScheme("big-job"); 3131 HandleScheme("big-job");
3129 MakeTestRequest(0, 1, GURL("big-job:0123456789,1000000")); 3132 MakeTestRequest(0, 1, GURL("big-job:0123456789,1000000"));
3130 3133
3131 base::RunLoop().RunUntilIdle(); 3134 content::RunAllBlockingPoolTasksUntilIdle();
3132 3135
3133 // Sort all the messages we saw by request. 3136 // Sort all the messages we saw by request.
3134 ResourceIPCAccumulator::ClassifiedMessages msgs; 3137 ResourceIPCAccumulator::ClassifiedMessages msgs;
3135 accum_.GetClassifiedMessages(&msgs); 3138 accum_.GetClassifiedMessages(&msgs);
3136 3139
3137 size_t size = msgs[0].size(); 3140 size_t size = msgs[0].size();
3138 3141
3139 EXPECT_EQ(ResourceMsg_ReceivedResponse::ID, msgs[0][0].type()); 3142 EXPECT_EQ(ResourceMsg_ReceivedResponse::ID, msgs[0][0].type());
3140 EXPECT_EQ(ResourceMsg_SetDataBuffer::ID, msgs[0][1].type()); 3143 EXPECT_EQ(ResourceMsg_SetDataBuffer::ID, msgs[0][1].type());
3141 for (size_t i = 2; i < size - 1; ++i) 3144 for (size_t i = 2; i < size - 1; ++i)
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
3200 std::string(response_data.begin(), response_data.begin() + data_length), 3203 std::string(response_data.begin(), response_data.begin() + data_length),
3201 net::ERR_ABORTED); 3204 net::ERR_ABORTED);
3202 } 3205 }
3203 3206
3204 TEST_F(ResourceDispatcherHostTest, DelayedDataReceivedACKs) { 3207 TEST_F(ResourceDispatcherHostTest, DelayedDataReceivedACKs) {
3205 EXPECT_EQ(0, host_.pending_requests()); 3208 EXPECT_EQ(0, host_.pending_requests());
3206 3209
3207 HandleScheme("big-job"); 3210 HandleScheme("big-job");
3208 MakeTestRequest(0, 1, GURL("big-job:0123456789,1000000")); 3211 MakeTestRequest(0, 1, GURL("big-job:0123456789,1000000"));
3209 3212
3210 base::RunLoop().RunUntilIdle(); 3213 content::RunAllBlockingPoolTasksUntilIdle();
3211 3214
3212 // Sort all the messages we saw by request. 3215 // Sort all the messages we saw by request.
3213 ResourceIPCAccumulator::ClassifiedMessages msgs; 3216 ResourceIPCAccumulator::ClassifiedMessages msgs;
3214 accum_.GetClassifiedMessages(&msgs); 3217 accum_.GetClassifiedMessages(&msgs);
3215 3218
3216 // We expect 1x ReceivedResponse, 1x SetDataBuffer, Nx ReceivedData messages. 3219 // We expect 1x ReceivedResponse, 1x SetDataBuffer, Nx ReceivedData messages.
3217 EXPECT_EQ(ResourceMsg_ReceivedResponse::ID, msgs[0][0].type()); 3220 EXPECT_EQ(ResourceMsg_ReceivedResponse::ID, msgs[0][0].type());
3218 EXPECT_EQ(ResourceMsg_SetDataBuffer::ID, msgs[0][1].type()); 3221 EXPECT_EQ(ResourceMsg_SetDataBuffer::ID, msgs[0][1].type());
3219 for (size_t i = 2; i < msgs[0].size(); ++i) 3222 for (size_t i = 2; i < msgs[0].size(); ++i)
3220 EXPECT_EQ(ResourceMsg_DataReceived::ID, msgs[0][i].type()); 3223 EXPECT_EQ(ResourceMsg_DataReceived::ID, msgs[0][i].type());
(...skipping 13 matching lines...) Expand all
3234 complete = true; 3237 complete = true;
3235 break; 3238 break;
3236 } 3239 }
3237 3240
3238 EXPECT_EQ(ResourceMsg_DataReceived::ID, msgs[0][i].type()); 3241 EXPECT_EQ(ResourceMsg_DataReceived::ID, msgs[0][i].type());
3239 3242
3240 ResourceHostMsg_DataReceived_ACK msg(1); 3243 ResourceHostMsg_DataReceived_ACK msg(1);
3241 OnMessageReceived(msg, filter_.get()); 3244 OnMessageReceived(msg, filter_.get());
3242 } 3245 }
3243 3246
3244 base::RunLoop().RunUntilIdle(); 3247 content::RunAllBlockingPoolTasksUntilIdle();
3245 3248
3246 msgs.clear(); 3249 msgs.clear();
3247 accum_.GetClassifiedMessages(&msgs); 3250 accum_.GetClassifiedMessages(&msgs);
3248 } 3251 }
3249 } 3252 }
3250 3253
3251 // Flakyness of this test might indicate memory corruption issues with 3254 // Flakyness of this test might indicate memory corruption issues with
3252 // for example the ResourceBuffer of AsyncResourceHandler. 3255 // for example the ResourceBuffer of AsyncResourceHandler.
3253 TEST_F(ResourceDispatcherHostTest, DataReceivedUnexpectedACKs) { 3256 TEST_F(ResourceDispatcherHostTest, DataReceivedUnexpectedACKs) {
3254 EXPECT_EQ(0, host_.pending_requests()); 3257 EXPECT_EQ(0, host_.pending_requests());
3255 3258
3256 HandleScheme("big-job"); 3259 HandleScheme("big-job");
3257 MakeTestRequest(0, 1, GURL("big-job:0123456789,1000000")); 3260 MakeTestRequest(0, 1, GURL("big-job:0123456789,1000000"));
3258 3261
3259 base::RunLoop().RunUntilIdle(); 3262 content::RunAllBlockingPoolTasksUntilIdle();
3260 3263
3261 // Sort all the messages we saw by request. 3264 // Sort all the messages we saw by request.
3262 ResourceIPCAccumulator::ClassifiedMessages msgs; 3265 ResourceIPCAccumulator::ClassifiedMessages msgs;
3263 accum_.GetClassifiedMessages(&msgs); 3266 accum_.GetClassifiedMessages(&msgs);
3264 3267
3265 // We expect 1x ReceivedResponse, 1x SetDataBuffer, Nx ReceivedData messages. 3268 // We expect 1x ReceivedResponse, 1x SetDataBuffer, Nx ReceivedData messages.
3266 EXPECT_EQ(ResourceMsg_ReceivedResponse::ID, msgs[0][0].type()); 3269 EXPECT_EQ(ResourceMsg_ReceivedResponse::ID, msgs[0][0].type());
3267 EXPECT_EQ(ResourceMsg_SetDataBuffer::ID, msgs[0][1].type()); 3270 EXPECT_EQ(ResourceMsg_SetDataBuffer::ID, msgs[0][1].type());
3268 for (size_t i = 2; i < msgs[0].size(); ++i) 3271 for (size_t i = 2; i < msgs[0].size(); ++i)
3269 EXPECT_EQ(ResourceMsg_DataReceived::ID, msgs[0][i].type()); 3272 EXPECT_EQ(ResourceMsg_DataReceived::ID, msgs[0][i].type());
(...skipping 18 matching lines...) Expand all
3288 complete = true; 3291 complete = true;
3289 break; 3292 break;
3290 } 3293 }
3291 3294
3292 EXPECT_EQ(ResourceMsg_DataReceived::ID, msgs[0][i].type()); 3295 EXPECT_EQ(ResourceMsg_DataReceived::ID, msgs[0][i].type());
3293 3296
3294 ResourceHostMsg_DataReceived_ACK msg(1); 3297 ResourceHostMsg_DataReceived_ACK msg(1);
3295 OnMessageReceived(msg, filter_.get()); 3298 OnMessageReceived(msg, filter_.get());
3296 } 3299 }
3297 3300
3298 base::RunLoop().RunUntilIdle(); 3301 content::RunAllBlockingPoolTasksUntilIdle();
3299 3302
3300 msgs.clear(); 3303 msgs.clear();
3301 accum_.GetClassifiedMessages(&msgs); 3304 accum_.GetClassifiedMessages(&msgs);
3302 } 3305 }
3303 } 3306 }
3304 3307
3305 // Tests the dispatcher host's temporary file management. 3308 // Tests the dispatcher host's temporary file management.
3306 TEST_F(ResourceDispatcherHostTest, RegisterDownloadedTempFile) { 3309 TEST_F(ResourceDispatcherHostTest, RegisterDownloadedTempFile) {
3307 const int kRequestID = 1; 3310 const int kRequestID = 1;
3308 3311
(...skipping 23 matching lines...) Expand all
3332 3335
3333 // Still readable because there is another reference to the file. (The child 3336 // Still readable because there is another reference to the file. (The child
3334 // may take additional blob references.) 3337 // may take additional blob references.)
3335 EXPECT_TRUE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile( 3338 EXPECT_TRUE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile(
3336 filter_->child_id(), file_path)); 3339 filter_->child_id(), file_path));
3337 3340
3338 // Release extra references and wait for the file to be deleted. (This relies 3341 // 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 3342 // on the delete happening on the FILE thread which is mapped to main thread
3340 // in this test.) 3343 // in this test.)
3341 deletable_file = nullptr; 3344 deletable_file = nullptr;
3342 base::RunLoop().RunUntilIdle(); 3345 content::RunAllBlockingPoolTasksUntilIdle();
3343 3346
3344 // The file is no longer readable to the child and has been deleted. 3347 // The file is no longer readable to the child and has been deleted.
3345 EXPECT_FALSE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile( 3348 EXPECT_FALSE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile(
3346 filter_->child_id(), file_path)); 3349 filter_->child_id(), file_path));
3347 EXPECT_FALSE(base::PathExists(file_path)); 3350 EXPECT_FALSE(base::PathExists(file_path));
3348 } 3351 }
3349 3352
3350 // Tests the dispatcher host's temporary file management in the mojo-enabled 3353 // Tests the dispatcher host's temporary file management in the mojo-enabled
3351 // loading. 3354 // loading.
3352 TEST_F(ResourceDispatcherHostTest, RegisterDownloadedTempFileWithMojo) { 3355 TEST_F(ResourceDispatcherHostTest, RegisterDownloadedTempFileWithMojo) {
(...skipping 18 matching lines...) Expand all
3371 mojom::DownloadedTempFilePtr downloaded_file_ptr = 3374 mojom::DownloadedTempFilePtr downloaded_file_ptr =
3372 DownloadedTempFileImpl::Create(filter_->child_id(), kRequestID); 3375 DownloadedTempFileImpl::Create(filter_->child_id(), kRequestID);
3373 host_.RegisterDownloadedTempFile(filter_->child_id(), kRequestID, file_path); 3376 host_.RegisterDownloadedTempFile(filter_->child_id(), kRequestID, file_path);
3374 3377
3375 // Should be readable now. 3378 // Should be readable now.
3376 EXPECT_TRUE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile( 3379 EXPECT_TRUE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile(
3377 filter_->child_id(), file_path)); 3380 filter_->child_id(), file_path));
3378 3381
3379 // The child releases from the request. 3382 // The child releases from the request.
3380 downloaded_file_ptr = nullptr; 3383 downloaded_file_ptr = nullptr;
3381 base::RunLoop().RunUntilIdle(); 3384 content::RunAllBlockingPoolTasksUntilIdle();
3382 3385
3383 // Still readable because there is another reference to the file. (The child 3386 // Still readable because there is another reference to the file. (The child
3384 // may take additional blob references.) 3387 // may take additional blob references.)
3385 EXPECT_TRUE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile( 3388 EXPECT_TRUE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile(
3386 filter_->child_id(), file_path)); 3389 filter_->child_id(), file_path));
3387 3390
3388 // Release extra references and wait for the file to be deleted. (This relies 3391 // 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 3392 // on the delete happening on the FILE thread which is mapped to main thread
3390 // in this test.) 3393 // in this test.)
3391 deletable_file = nullptr; 3394 deletable_file = nullptr;
3392 base::RunLoop().RunUntilIdle(); 3395 content::RunAllBlockingPoolTasksUntilIdle();
3393 3396
3394 // The file is no longer readable to the child and has been deleted. 3397 // The file is no longer readable to the child and has been deleted.
3395 EXPECT_FALSE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile( 3398 EXPECT_FALSE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile(
3396 filter_->child_id(), file_path)); 3399 filter_->child_id(), file_path));
3397 EXPECT_FALSE(base::PathExists(file_path)); 3400 EXPECT_FALSE(base::PathExists(file_path));
3398 } 3401 }
3399 3402
3400 // Tests that temporary files held on behalf of child processes are released 3403 // Tests that temporary files held on behalf of child processes are released
3401 // when the child process dies. 3404 // when the child process dies.
3402 TEST_F(ResourceDispatcherHostTest, ReleaseTemporiesOnProcessExit) { 3405 TEST_F(ResourceDispatcherHostTest, ReleaseTemporiesOnProcessExit) {
(...skipping 10 matching lines...) Expand all
3413 // Register it for a resource request. 3416 // Register it for a resource request.
3414 host_.RegisterDownloadedTempFile(filter_->child_id(), kRequestID, file_path); 3417 host_.RegisterDownloadedTempFile(filter_->child_id(), kRequestID, file_path);
3415 deletable_file = NULL; 3418 deletable_file = NULL;
3416 3419
3417 // Should be readable now. 3420 // Should be readable now.
3418 EXPECT_TRUE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile( 3421 EXPECT_TRUE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile(
3419 filter_->child_id(), file_path)); 3422 filter_->child_id(), file_path));
3420 3423
3421 // Let the process die. 3424 // Let the process die.
3422 filter_->OnChannelClosing(); 3425 filter_->OnChannelClosing();
3423 base::RunLoop().RunUntilIdle(); 3426 content::RunAllBlockingPoolTasksUntilIdle();
3424 3427
3425 // The file is no longer readable to the child and has been deleted. 3428 // The file is no longer readable to the child and has been deleted.
3426 EXPECT_FALSE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile( 3429 EXPECT_FALSE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile(
3427 filter_->child_id(), file_path)); 3430 filter_->child_id(), file_path));
3428 EXPECT_FALSE(base::PathExists(file_path)); 3431 EXPECT_FALSE(base::PathExists(file_path));
3429 } 3432 }
3430 3433
3431 TEST_F(ResourceDispatcherHostTest, DownloadToFile) { 3434 TEST_F(ResourceDispatcherHostTest, DownloadToFile) {
3432 // Make a request which downloads to file. 3435 // Make a request which downloads to file.
3433 ResourceRequest request = CreateResourceRequest( 3436 ResourceRequest request = CreateResourceRequest(
3434 "GET", RESOURCE_TYPE_SUB_RESOURCE, net::URLRequestTestJob::test_url_1()); 3437 "GET", RESOURCE_TYPE_SUB_RESOURCE, net::URLRequestTestJob::test_url_1());
3435 request.download_to_file = true; 3438 request.download_to_file = true;
3436 ResourceHostMsg_RequestResource request_msg(0, 1, request); 3439 ResourceHostMsg_RequestResource request_msg(0, 1, request);
3437 OnMessageReceived(request_msg, filter_.get()); 3440 OnMessageReceived(request_msg, filter_.get());
3438 3441
3439 // Running the message loop until idle does not work because 3442 // Running the message loop until idle does not work because
3440 // RedirectToFileResourceHandler posts things to base::WorkerPool. Instead, 3443 // RedirectToFileResourceHandler posts things to base::WorkerPool. Instead,
3441 // wait for the ResourceMsg_RequestComplete to go out. Then run the event loop 3444 // wait for the ResourceMsg_RequestComplete to go out. Then run the event loop
3442 // until idle so the loader is gone. 3445 // until idle so the loader is gone.
3443 WaitForRequestComplete(); 3446 WaitForRequestComplete();
3444 base::RunLoop().RunUntilIdle(); 3447 content::RunAllBlockingPoolTasksUntilIdle();
3445 EXPECT_EQ(0, host_.pending_requests()); 3448 EXPECT_EQ(0, host_.pending_requests());
3446 3449
3447 ResourceIPCAccumulator::ClassifiedMessages msgs; 3450 ResourceIPCAccumulator::ClassifiedMessages msgs;
3448 accum_.GetClassifiedMessages(&msgs); 3451 accum_.GetClassifiedMessages(&msgs);
3449 3452
3450 ASSERT_EQ(1U, msgs.size()); 3453 ASSERT_EQ(1U, msgs.size());
3451 const std::vector<IPC::Message>& messages = msgs[0]; 3454 const std::vector<IPC::Message>& messages = msgs[0];
3452 3455
3453 // The request should contain the following messages: 3456 // The request should contain the following messages:
3454 // ReceivedResponse (indicates headers received and filename) 3457 // ReceivedResponse (indicates headers received and filename)
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
3487 3490
3488 // When the renderer releases the file, it should be deleted. Again, 3491 // When the renderer releases the file, it should be deleted. Again,
3489 // RunUntilIdle doesn't work because base::WorkerPool is involved. 3492 // RunUntilIdle doesn't work because base::WorkerPool is involved.
3490 ShareableFileReleaseWaiter waiter(response_head.download_file_path); 3493 ShareableFileReleaseWaiter waiter(response_head.download_file_path);
3491 ResourceHostMsg_ReleaseDownloadedFile release_msg(1); 3494 ResourceHostMsg_ReleaseDownloadedFile release_msg(1);
3492 OnMessageReceived(release_msg, filter_.get()); 3495 OnMessageReceived(release_msg, filter_.get());
3493 waiter.Wait(); 3496 waiter.Wait();
3494 // The release callback runs before the delete is scheduled, so pump the 3497 // 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 3498 // 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.) 3499 // the FILE thread which is mapped to main thread in this test.)
3497 base::RunLoop().RunUntilIdle(); 3500 content::RunAllBlockingPoolTasksUntilIdle();
3498 3501
3499 EXPECT_FALSE(base::PathExists(response_head.download_file_path)); 3502 EXPECT_FALSE(base::PathExists(response_head.download_file_path));
3500 EXPECT_FALSE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile( 3503 EXPECT_FALSE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile(
3501 filter_->child_id(), response_head.download_file_path)); 3504 filter_->child_id(), response_head.download_file_path));
3502 } 3505 }
3503 3506
3504 WebContents* WebContentsBinder(WebContents* rv) { return rv; } 3507 WebContents* WebContentsBinder(WebContents* rv) { return rv; }
3505 3508
3506 // Tests GetLoadInfoForAllRoutes when there are 3 requests from the same 3509 // Tests GetLoadInfoForAllRoutes when there are 3 requests from the same
3507 // RenderView. The second one is farthest along. 3510 // RenderView. The second one is farthest along.
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
3663 EXPECT_EQ(0u, (*load_info_map)[wc2].upload_position); 3666 EXPECT_EQ(0u, (*load_info_map)[wc2].upload_position);
3664 EXPECT_EQ(0u, (*load_info_map)[wc2].upload_size); 3667 EXPECT_EQ(0u, (*load_info_map)[wc2].upload_size);
3665 } 3668 }
3666 3669
3667 // Confirm that resource response started notifications are correctly 3670 // Confirm that resource response started notifications are correctly
3668 // transmitted to the WebContents. 3671 // transmitted to the WebContents.
3669 TEST_F(ResourceDispatcherHostTest, TransferResponseStarted) { 3672 TEST_F(ResourceDispatcherHostTest, TransferResponseStarted) {
3670 int initial_count = web_contents_observer_->resource_response_start_count(); 3673 int initial_count = web_contents_observer_->resource_response_start_count();
3671 3674
3672 MakeWebContentsAssociatedTestRequest(1, net::URLRequestTestJob::test_url_1()); 3675 MakeWebContentsAssociatedTestRequest(1, net::URLRequestTestJob::test_url_1());
3673 base::RunLoop().RunUntilIdle(); 3676 content::RunAllBlockingPoolTasksUntilIdle();
3674 3677
3675 EXPECT_EQ(initial_count + 1, 3678 EXPECT_EQ(initial_count + 1,
3676 web_contents_observer_->resource_response_start_count()); 3679 web_contents_observer_->resource_response_start_count());
3677 } 3680 }
3678 3681
3679 // Confirm that request redirected notifications are correctly 3682 // Confirm that request redirected notifications are correctly
3680 // transmitted to the WebContents. 3683 // transmitted to the WebContents.
3681 TEST_F(ResourceDispatcherHostTest, TransferRequestRedirected) { 3684 TEST_F(ResourceDispatcherHostTest, TransferRequestRedirected) {
3682 int initial_count = web_contents_observer_->resource_request_redirect_count(); 3685 int initial_count = web_contents_observer_->resource_request_redirect_count();
3683 3686
3684 MakeWebContentsAssociatedTestRequest( 3687 MakeWebContentsAssociatedTestRequest(
3685 1, net::URLRequestTestJob::test_url_redirect_to_url_2()); 3688 1, net::URLRequestTestJob::test_url_redirect_to_url_2());
3686 base::RunLoop().RunUntilIdle(); 3689 content::RunAllBlockingPoolTasksUntilIdle();
3687 3690
3688 EXPECT_EQ(initial_count + 1, 3691 EXPECT_EQ(initial_count + 1,
3689 web_contents_observer_->resource_request_redirect_count()); 3692 web_contents_observer_->resource_request_redirect_count());
3690 } 3693 }
3691 3694
3692 // Confirm that DidChangePriority messages are respected. 3695 // Confirm that DidChangePriority messages are respected.
3693 TEST_F(ResourceDispatcherHostTest, DidChangePriority) { 3696 TEST_F(ResourceDispatcherHostTest, DidChangePriority) {
3694 // ResourceScheduler only throttles http and https requests. 3697 // ResourceScheduler only throttles http and https requests.
3695 HandleScheme("http"); 3698 HandleScheme("http");
3696 3699
(...skipping 12 matching lines...) Expand all
3709 MakeTestRequestWithPriority(0, 3, net::IDLE); 3712 MakeTestRequestWithPriority(0, 3, net::IDLE);
3710 3713
3711 KickOffRequest(); 3714 KickOffRequest();
3712 3715
3713 EXPECT_EQ(2, job_factory_->url_request_jobs_created_count()); 3716 EXPECT_EQ(2, job_factory_->url_request_jobs_created_count());
3714 3717
3715 // Increase the priority of the second idle priority request. It was 3718 // Increase the priority of the second idle priority request. It was
3716 // scheduled later, so it is not currently running. 3719 // scheduled later, so it is not currently running.
3717 ResourceHostMsg_DidChangePriority priority_msg(3, net::MAXIMUM_PRIORITY, 0); 3720 ResourceHostMsg_DidChangePriority priority_msg(3, net::MAXIMUM_PRIORITY, 0);
3718 OnMessageReceived(priority_msg, filter_.get()); 3721 OnMessageReceived(priority_msg, filter_.get());
3719 base::RunLoop().RunUntilIdle(); 3722 content::RunAllBlockingPoolTasksUntilIdle();
3720 3723
3721 EXPECT_EQ(3, job_factory_->url_request_jobs_created_count()); 3724 EXPECT_EQ(3, job_factory_->url_request_jobs_created_count());
3722 3725
3723 // Cleanup. 3726 // Cleanup.
3724 host_.OnRenderViewHostDeleted(filter_->child_id(), // child_id 3727 host_.OnRenderViewHostDeleted(filter_->child_id(), // child_id
3725 0); // route_id 3728 0); // route_id
3726 } 3729 }
3727 3730
3728 // Confirm that resource response started notifications for downloads are not 3731 // Confirm that resource response started notifications for downloads are not
3729 // transmitted to the WebContents. 3732 // transmitted to the WebContents.
3730 TEST_F(ResourceDispatcherHostTest, TransferResponseStartedDownload) { 3733 TEST_F(ResourceDispatcherHostTest, TransferResponseStartedDownload) {
3731 int initial_count(web_contents_observer_->resource_response_start_count()); 3734 int initial_count(web_contents_observer_->resource_response_start_count());
3732 3735
3733 MakeWebContentsAssociatedDownloadRequest( 3736 MakeWebContentsAssociatedDownloadRequest(
3734 1, net::URLRequestTestJob::test_url_1()); 3737 1, net::URLRequestTestJob::test_url_1());
3735 base::RunLoop().RunUntilIdle(); 3738 content::RunAllBlockingPoolTasksUntilIdle();
3736 EXPECT_EQ(initial_count, 3739 EXPECT_EQ(initial_count,
3737 web_contents_observer_->resource_response_start_count()); 3740 web_contents_observer_->resource_response_start_count());
3738 } 3741 }
3739 3742
3740 // Confirm that request redirected notifications for downloads are not 3743 // Confirm that request redirected notifications for downloads are not
3741 // transmitted to the WebContents. 3744 // transmitted to the WebContents.
3742 TEST_F(ResourceDispatcherHostTest, TransferRequestRedirectedDownload) { 3745 TEST_F(ResourceDispatcherHostTest, TransferRequestRedirectedDownload) {
3743 int initial_count(web_contents_observer_->resource_request_redirect_count()); 3746 int initial_count(web_contents_observer_->resource_request_redirect_count());
3744 3747
3745 MakeWebContentsAssociatedDownloadRequest( 3748 MakeWebContentsAssociatedDownloadRequest(
3746 1, net::URLRequestTestJob::test_url_redirect_to_url_2()); 3749 1, net::URLRequestTestJob::test_url_redirect_to_url_2());
3747 base::RunLoop().RunUntilIdle(); 3750 content::RunAllBlockingPoolTasksUntilIdle();
3748 EXPECT_EQ(initial_count, 3751 EXPECT_EQ(initial_count,
3749 web_contents_observer_->resource_request_redirect_count()); 3752 web_contents_observer_->resource_request_redirect_count());
3750 } 3753 }
3751 3754
3752 // Tests that a ResourceThrottle that needs to process the response before any 3755 // Tests that a ResourceThrottle that needs to process the response before any
3753 // part of the body is read can do so. 3756 // part of the body is read can do so.
3754 TEST_F(ResourceDispatcherHostTest, ThrottleMustProcessResponseBeforeRead) { 3757 TEST_F(ResourceDispatcherHostTest, ThrottleMustProcessResponseBeforeRead) {
3755 // Ensure all jobs will check that no read operation is called. 3758 // Ensure all jobs will check that no read operation is called.
3756 job_factory_->SetMustNotReadJobGeneration(true); 3759 job_factory_->SetMustNotReadJobGeneration(true);
3757 HandleScheme("http"); 3760 HandleScheme("http");
(...skipping 13 matching lines...) Expand all
3771 "Content-Type: text/plain; charset=utf-8\n\n"); 3774 "Content-Type: text/plain; charset=utf-8\n\n");
3772 std::string response_data("p { text-align: center; }"); 3775 std::string response_data("p { text-align: center; }");
3773 SetResponse(raw_headers, response_data); 3776 SetResponse(raw_headers, response_data);
3774 3777
3775 MakeTestRequestWithResourceType(filter_.get(), filter_->child_id(), 1, 3778 MakeTestRequestWithResourceType(filter_.get(), filter_->child_id(), 1,
3776 GURL("http://example.com/blah"), 3779 GURL("http://example.com/blah"),
3777 RESOURCE_TYPE_STYLESHEET); 3780 RESOURCE_TYPE_STYLESHEET);
3778 3781
3779 while (net::URLRequestTestJob::ProcessOnePendingMessage()) { 3782 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {
3780 } 3783 }
3781 base::RunLoop().RunUntilIdle(); 3784 content::RunAllBlockingPoolTasksUntilIdle();
3782 } 3785 }
3783 3786
3784 namespace { 3787 namespace {
3785 3788
3786 void StoreSyncLoadResult(bool* called, 3789 void StoreSyncLoadResult(bool* called,
3787 bool* was_null, 3790 bool* was_null,
3788 SyncLoadResult* result_out, 3791 SyncLoadResult* result_out,
3789 const SyncLoadResult* result) { 3792 const SyncLoadResult* result) {
3790 *called = true; 3793 *called = true;
3791 *was_null = !result; 3794 *was_null = !result;
3792 3795
3793 if (result) 3796 if (result)
3794 *result_out = *result; 3797 *result_out = *result;
3795 } 3798 }
3796 3799
3797 } // namespace 3800 } // namespace
3798 3801
3799 TEST_F(ResourceDispatcherHostTest, SyncLoadWithMojoSuccess) { 3802 TEST_F(ResourceDispatcherHostTest, SyncLoadWithMojoSuccess) {
3800 ResourceRequest request = CreateResourceRequest( 3803 ResourceRequest request = CreateResourceRequest(
3801 "GET", RESOURCE_TYPE_XHR, net::URLRequestTestJob::test_url_1()); 3804 "GET", RESOURCE_TYPE_XHR, net::URLRequestTestJob::test_url_1());
3802 request.priority = net::MAXIMUM_PRIORITY; 3805 request.priority = net::MAXIMUM_PRIORITY;
3803 3806
3804 bool called = false; 3807 bool called = false;
3805 bool was_null = false; 3808 bool was_null = false;
3806 SyncLoadResult result; 3809 SyncLoadResult result;
3807 host_.OnSyncLoadWithMojo( 3810 host_.OnSyncLoadWithMojo(
3808 GetResourceRequesterInfo(filter_.get()), 0, 1, request, 3811 GetResourceRequesterInfo(filter_.get()), 0, 1, request,
3809 base::Bind(&StoreSyncLoadResult, &called, &was_null, &result)); 3812 base::Bind(&StoreSyncLoadResult, &called, &was_null, &result));
3810 base::RunLoop().RunUntilIdle(); 3813 content::RunAllBlockingPoolTasksUntilIdle();
3811 EXPECT_TRUE(called); 3814 EXPECT_TRUE(called);
3812 EXPECT_FALSE(was_null); 3815 EXPECT_FALSE(was_null);
3813 EXPECT_EQ(net::OK, result.error_code); 3816 EXPECT_EQ(net::OK, result.error_code);
3814 } 3817 }
3815 3818
3816 TEST_F(ResourceDispatcherHostTest, SyncLoadWithMojoError) { 3819 TEST_F(ResourceDispatcherHostTest, SyncLoadWithMojoError) {
3817 ResourceRequest request = CreateResourceRequest( 3820 ResourceRequest request = CreateResourceRequest(
3818 "GET", RESOURCE_TYPE_XHR, net::URLRequestTestJob::test_url_error()); 3821 "GET", RESOURCE_TYPE_XHR, net::URLRequestTestJob::test_url_error());
3819 request.priority = net::MAXIMUM_PRIORITY; 3822 request.priority = net::MAXIMUM_PRIORITY;
3820 3823
3821 bool called = false; 3824 bool called = false;
3822 bool was_null = false; 3825 bool was_null = false;
3823 SyncLoadResult result; 3826 SyncLoadResult result;
3824 host_.OnSyncLoadWithMojo( 3827 host_.OnSyncLoadWithMojo(
3825 GetResourceRequesterInfo(filter_.get()), 0, 1, request, 3828 GetResourceRequesterInfo(filter_.get()), 0, 1, request,
3826 base::Bind(&StoreSyncLoadResult, &called, &was_null, &result)); 3829 base::Bind(&StoreSyncLoadResult, &called, &was_null, &result));
3827 base::RunLoop().RunUntilIdle(); 3830 content::RunAllBlockingPoolTasksUntilIdle();
3828 EXPECT_TRUE(called); 3831 EXPECT_TRUE(called);
3829 EXPECT_FALSE(was_null); 3832 EXPECT_FALSE(was_null);
3830 EXPECT_EQ(net::ERR_INVALID_URL, result.error_code); 3833 EXPECT_EQ(net::ERR_INVALID_URL, result.error_code);
3831 } 3834 }
3832 3835
3833 TEST_F(ResourceDispatcherHostTest, SyncLoadWithMojoCancel) { 3836 TEST_F(ResourceDispatcherHostTest, SyncLoadWithMojoCancel) {
3834 ResourceRequest request = CreateResourceRequest( 3837 ResourceRequest request = CreateResourceRequest(
3835 "GET", RESOURCE_TYPE_XHR, net::URLRequestTestJob::test_url_error()); 3838 "GET", RESOURCE_TYPE_XHR, net::URLRequestTestJob::test_url_error());
3836 request.priority = net::MAXIMUM_PRIORITY; 3839 request.priority = net::MAXIMUM_PRIORITY;
3837 3840
3838 bool called = false; 3841 bool called = false;
3839 bool was_null = false; 3842 bool was_null = false;
3840 SyncLoadResult result; 3843 SyncLoadResult result;
3841 host_.OnSyncLoadWithMojo( 3844 host_.OnSyncLoadWithMojo(
3842 GetResourceRequesterInfo(filter_.get()), 0, 1, request, 3845 GetResourceRequesterInfo(filter_.get()), 0, 1, request,
3843 base::Bind(&StoreSyncLoadResult, &called, &was_null, &result)); 3846 base::Bind(&StoreSyncLoadResult, &called, &was_null, &result));
3844 host_.CancelRequestsForProcess(filter_->child_id()); 3847 host_.CancelRequestsForProcess(filter_->child_id());
3845 base::RunLoop().RunUntilIdle(); 3848 content::RunAllBlockingPoolTasksUntilIdle();
3846 EXPECT_TRUE(called); 3849 EXPECT_TRUE(called);
3847 EXPECT_TRUE(was_null); 3850 EXPECT_TRUE(was_null);
3848 } 3851 }
3849 3852
3850 // A URLRequestTestJob that sets a test certificate on the |ssl_info| 3853 // A URLRequestTestJob that sets a test certificate on the |ssl_info|
3851 // field of the response. 3854 // field of the response.
3852 class TestHTTPSURLRequestJob : public net::URLRequestTestJob { 3855 class TestHTTPSURLRequestJob : public net::URLRequestTestJob {
3853 public: 3856 public:
3854 TestHTTPSURLRequestJob(net::URLRequest* request, 3857 TestHTTPSURLRequestJob(net::URLRequest* request,
3855 net::NetworkDelegate* network_delegate, 3858 net::NetworkDelegate* network_delegate,
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
3924 return nullptr; 3927 return nullptr;
3925 } 3928 }
3926 3929
3927 net::URLRequestJob* TestURLRequestJobFactory::MaybeInterceptResponse( 3930 net::URLRequestJob* TestURLRequestJobFactory::MaybeInterceptResponse(
3928 net::URLRequest* request, 3931 net::URLRequest* request,
3929 net::NetworkDelegate* network_delegate) const { 3932 net::NetworkDelegate* network_delegate) const {
3930 return nullptr; 3933 return nullptr;
3931 } 3934 }
3932 3935
3933 } // namespace content 3936 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698