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

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

Issue 2767923002: Always use an async TaskScheduler in TestBrowserThreadBundle. (Closed)
Patch Set: fix-test-errors 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();
181 ;
mmenke 2017/04/04 22:47:16 I think you have a few extra semi-colons in this f
fdoray 2017/04/05 12:34:21 Done.
180 } 182 }
181 183
182 // We may want to move this to a shared space if it is useful for something else 184 // We may want to move this to a shared space if it is useful for something else
183 class ResourceIPCAccumulator { 185 class ResourceIPCAccumulator {
184 public: 186 public:
185 ~ResourceIPCAccumulator() { 187 ~ResourceIPCAccumulator() {
186 for (size_t i = 0; i < messages_.size(); i++) { 188 for (size_t i = 0; i < messages_.size(); i++) {
187 ReleaseHandlesInMessage(messages_[i]); 189 ReleaseHandlesInMessage(messages_[i]);
188 } 190 }
189 } 191 }
(...skipping 658 matching lines...) Expand 10 before | Expand all | Expand 10 after
848 850
849 ResourceDispatcherHostTest() 851 ResourceDispatcherHostTest()
850 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), 852 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP),
851 host_(base::Bind(&DownloadResourceHandler::Create)), 853 host_(base::Bind(&DownloadResourceHandler::Create)),
852 use_test_ssl_certificate_(false), 854 use_test_ssl_certificate_(false),
853 send_data_received_acks_(false), 855 send_data_received_acks_(false),
854 auto_advance_(false) { 856 auto_advance_(false) {
855 host_.SetLoaderDelegate(&loader_delegate_); 857 host_.SetLoaderDelegate(&loader_delegate_);
856 browser_context_.reset(new TestBrowserContext()); 858 browser_context_.reset(new TestBrowserContext());
857 BrowserContext::EnsureResourceContextInitialized(browser_context_.get()); 859 BrowserContext::EnsureResourceContextInitialized(browser_context_.get());
858 base::RunLoop().RunUntilIdle(); 860 content::RunAllBlockingPoolTasksUntilIdle();
861 ;
859 filter_ = MakeForwardingFilter(); 862 filter_ = MakeForwardingFilter();
860 // TODO(cbentzel): Better way to get URLRequestContext? 863 // TODO(cbentzel): Better way to get URLRequestContext?
861 net::URLRequestContext* request_context = 864 net::URLRequestContext* request_context =
862 browser_context_->GetResourceContext()->GetRequestContext(); 865 browser_context_->GetResourceContext()->GetRequestContext();
863 job_factory_.reset(new TestURLRequestJobFactory(this)); 866 job_factory_.reset(new TestURLRequestJobFactory(this));
864 request_context->set_job_factory(job_factory_.get()); 867 request_context->set_job_factory(job_factory_.get());
865 request_context->set_network_delegate(&network_delegate_); 868 request_context->set_network_delegate(&network_delegate_);
866 } 869 }
867 870
868 ~ResourceDispatcherHostTest() override { 871 ~ResourceDispatcherHostTest() override {
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
923 host_.Shutdown(); 926 host_.Shutdown();
924 927
925 ChildProcessSecurityPolicyImpl::GetInstance()->Remove(0); 928 ChildProcessSecurityPolicyImpl::GetInstance()->Remove(0);
926 929
927 // Flush the message loop to make application verifiers happy. 930 // Flush the message loop to make application verifiers happy.
928 if (ResourceDispatcherHostImpl::Get()) 931 if (ResourceDispatcherHostImpl::Get())
929 ResourceDispatcherHostImpl::Get()->CancelRequestsForContext( 932 ResourceDispatcherHostImpl::Get()->CancelRequestsForContext(
930 browser_context_->GetResourceContext()); 933 browser_context_->GetResourceContext());
931 934
932 browser_context_.reset(); 935 browser_context_.reset();
933 base::RunLoop().RunUntilIdle(); 936 content::RunAllBlockingPoolTasksUntilIdle();
937 ;
934 } 938 }
935 939
936 // Creates a new ForwardingFilter and registers it with |child_ids_| so as not 940 // Creates a new ForwardingFilter and registers it with |child_ids_| so as not
937 // to leak per-child state on test shutdown. 941 // to leak per-child state on test shutdown.
938 ForwardingFilter* MakeForwardingFilter() { 942 ForwardingFilter* MakeForwardingFilter() {
939 ForwardingFilter* filter = 943 ForwardingFilter* filter =
940 new ForwardingFilter(this, browser_context_->GetResourceContext()); 944 new ForwardingFilter(this, browser_context_->GetResourceContext());
941 child_ids_.insert(filter->child_id()); 945 child_ids_.insert(filter->child_id());
942 return filter; 946 return filter;
943 } 947 }
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
1082 ASSERT_EQ(expected_error_code, delegate.net_error()); 1086 ASSERT_EQ(expected_error_code, delegate.net_error());
1083 return; 1087 return;
1084 } 1088 }
1085 1089
1086 MakeTestRequestWithResourceType(filter_.get(), 0, 1, url, 1090 MakeTestRequestWithResourceType(filter_.get(), 0, 1, url,
1087 RESOURCE_TYPE_MAIN_FRAME); 1091 RESOURCE_TYPE_MAIN_FRAME);
1088 1092
1089 // Flush all pending requests. 1093 // Flush all pending requests.
1090 while (net::URLRequestTestJob::ProcessOnePendingMessage()) { 1094 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {
1091 } 1095 }
1092 base::RunLoop().RunUntilIdle(); 1096 content::RunAllBlockingPoolTasksUntilIdle();
1097 ;
1093 1098
1094 // Sorts out all the messages we saw by request. 1099 // Sorts out all the messages we saw by request.
1095 ResourceIPCAccumulator::ClassifiedMessages msgs; 1100 ResourceIPCAccumulator::ClassifiedMessages msgs;
1096 accum_.GetClassifiedMessages(&msgs); 1101 accum_.GetClassifiedMessages(&msgs);
1097 1102
1098 // We should have gotten one RequestComplete message. 1103 // We should have gotten one RequestComplete message.
1099 ASSERT_EQ(1U, msgs.size()); 1104 ASSERT_EQ(1U, msgs.size());
1100 ASSERT_EQ(1U, msgs[0].size()); 1105 ASSERT_EQ(1U, msgs[0].size());
1101 EXPECT_EQ(ResourceMsg_RequestComplete::ID, msgs[0][0].type()); 1106 EXPECT_EQ(ResourceMsg_RequestComplete::ID, msgs[0][0].type());
1102 1107
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
1342 MakeTestRequest(0, 2, net::URLRequestTestJob::test_url_2()); 1347 MakeTestRequest(0, 2, net::URLRequestTestJob::test_url_2());
1343 MakeTestRequest(0, 3, net::URLRequestTestJob::test_url_3()); 1348 MakeTestRequest(0, 3, net::URLRequestTestJob::test_url_3());
1344 MakeTestRequestWithResourceType(filter_.get(), 0, 4, 1349 MakeTestRequestWithResourceType(filter_.get(), 0, 4,
1345 net::URLRequestTestJob::test_url_4(), 1350 net::URLRequestTestJob::test_url_4(),
1346 RESOURCE_TYPE_PREFETCH); // detachable type 1351 RESOURCE_TYPE_PREFETCH); // detachable type
1347 MakeTestRequest(0, 5, net::URLRequestTestJob::test_url_redirect_to_url_2()); 1352 MakeTestRequest(0, 5, net::URLRequestTestJob::test_url_redirect_to_url_2());
1348 1353
1349 // Finish the redirection 1354 // Finish the redirection
1350 ResourceHostMsg_FollowRedirect redirect_msg(5); 1355 ResourceHostMsg_FollowRedirect redirect_msg(5);
1351 OnMessageReceived(redirect_msg, filter_.get()); 1356 OnMessageReceived(redirect_msg, filter_.get());
1352 base::RunLoop().RunUntilIdle(); 1357 content::RunAllBlockingPoolTasksUntilIdle();
1358 ;
1353 1359
1354 // flush all the pending requests 1360 // flush all the pending requests
1355 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} 1361 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {}
1356 1362
1357 // sorts out all the messages we saw by request 1363 // sorts out all the messages we saw by request
1358 ResourceIPCAccumulator::ClassifiedMessages msgs; 1364 ResourceIPCAccumulator::ClassifiedMessages msgs;
1359 accum_.GetClassifiedMessages(&msgs); 1365 accum_.GetClassifiedMessages(&msgs);
1360 1366
1361 // there are five requests, so we should have gotten them classified as such 1367 // there are five requests, so we should have gotten them classified as such
1362 ASSERT_EQ(5U, msgs.size()); 1368 ASSERT_EQ(5U, msgs.size());
(...skipping 23 matching lines...) Expand all
1386 RendererCancelRequest(4); 1392 RendererCancelRequest(4);
1387 1393
1388 // The handler should have been detached now. 1394 // The handler should have been detached now.
1389 GlobalRequestID global_request_id(filter_->child_id(), 4); 1395 GlobalRequestID global_request_id(filter_->child_id(), 4);
1390 ResourceRequestInfoImpl* info = ResourceRequestInfoImpl::ForRequest( 1396 ResourceRequestInfoImpl* info = ResourceRequestInfoImpl::ForRequest(
1391 host_.GetURLRequest(global_request_id)); 1397 host_.GetURLRequest(global_request_id));
1392 ASSERT_TRUE(info->detachable_handler()->is_detached()); 1398 ASSERT_TRUE(info->detachable_handler()->is_detached());
1393 1399
1394 // flush all the pending requests 1400 // flush all the pending requests
1395 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} 1401 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {}
1396 base::RunLoop().RunUntilIdle(); 1402 content::RunAllBlockingPoolTasksUntilIdle();
1403 ;
1397 1404
1398 // Everything should be out now. 1405 // Everything should be out now.
1399 EXPECT_EQ(0, host_.pending_requests()); 1406 EXPECT_EQ(0, host_.pending_requests());
1400 1407
1401 ResourceIPCAccumulator::ClassifiedMessages msgs; 1408 ResourceIPCAccumulator::ClassifiedMessages msgs;
1402 accum_.GetClassifiedMessages(&msgs); 1409 accum_.GetClassifiedMessages(&msgs);
1403 1410
1404 // there are four requests, so we should have gotten them classified as such 1411 // there are four requests, so we should have gotten them classified as such
1405 ASSERT_EQ(4U, msgs.size()); 1412 ASSERT_EQ(4U, msgs.size());
1406 1413
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1438 1445
1439 // The handler for the cache-only request should have been detached now. 1446 // The handler for the cache-only request should have been detached now.
1440 GlobalRequestID global_request_id(filter_->child_id(), 2); 1447 GlobalRequestID global_request_id(filter_->child_id(), 2);
1441 ResourceRequestInfoImpl* info = ResourceRequestInfoImpl::ForRequest( 1448 ResourceRequestInfoImpl* info = ResourceRequestInfoImpl::ForRequest(
1442 host_.GetURLRequest(global_request_id)); 1449 host_.GetURLRequest(global_request_id));
1443 ASSERT_TRUE(info->detachable_handler()->is_detached()); 1450 ASSERT_TRUE(info->detachable_handler()->is_detached());
1444 1451
1445 // Flush all the pending requests. 1452 // Flush all the pending requests.
1446 while (net::URLRequestTestJob::ProcessOnePendingMessage()) { 1453 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {
1447 } 1454 }
1448 base::RunLoop().RunUntilIdle(); 1455 content::RunAllBlockingPoolTasksUntilIdle();
1456 ;
1449 1457
1450 // Everything should be out now. 1458 // Everything should be out now.
1451 EXPECT_EQ(0, host_.pending_requests()); 1459 EXPECT_EQ(0, host_.pending_requests());
1452 1460
1453 ResourceIPCAccumulator::ClassifiedMessages msgs; 1461 ResourceIPCAccumulator::ClassifiedMessages msgs;
1454 accum_.GetClassifiedMessages(&msgs); 1462 accum_.GetClassifiedMessages(&msgs);
1455 1463
1456 // There are two requests, so we should have gotten them classified as such. 1464 // There are two requests, so we should have gotten them classified as such.
1457 ASSERT_EQ(2U, msgs.size()); 1465 ASSERT_EQ(2U, msgs.size());
1458 1466
(...skipping 15 matching lines...) Expand all
1474 TEST_F(ResourceDispatcherHostTest, DetachedResourceTimesOut) { 1482 TEST_F(ResourceDispatcherHostTest, DetachedResourceTimesOut) {
1475 MakeTestRequestWithResourceType(filter_.get(), 0, 1, 1483 MakeTestRequestWithResourceType(filter_.get(), 0, 1,
1476 net::URLRequestTestJob::test_url_2(), 1484 net::URLRequestTestJob::test_url_2(),
1477 RESOURCE_TYPE_PREFETCH); // detachable type 1485 RESOURCE_TYPE_PREFETCH); // detachable type
1478 GlobalRequestID global_request_id(filter_->child_id(), 1); 1486 GlobalRequestID global_request_id(filter_->child_id(), 1);
1479 ResourceRequestInfoImpl* info = ResourceRequestInfoImpl::ForRequest( 1487 ResourceRequestInfoImpl* info = ResourceRequestInfoImpl::ForRequest(
1480 host_.GetURLRequest(global_request_id)); 1488 host_.GetURLRequest(global_request_id));
1481 ASSERT_TRUE(info->detachable_handler()); 1489 ASSERT_TRUE(info->detachable_handler());
1482 info->detachable_handler()->set_cancel_delay( 1490 info->detachable_handler()->set_cancel_delay(
1483 base::TimeDelta::FromMilliseconds(200)); 1491 base::TimeDelta::FromMilliseconds(200));
1484 base::RunLoop().RunUntilIdle(); 1492 content::RunAllBlockingPoolTasksUntilIdle();
1493 ;
1485 1494
1486 RendererCancelRequest(1); 1495 RendererCancelRequest(1);
1487 1496
1488 // From the renderer's perspective, the request was cancelled. 1497 // From the renderer's perspective, the request was cancelled.
1489 ResourceIPCAccumulator::ClassifiedMessages msgs; 1498 ResourceIPCAccumulator::ClassifiedMessages msgs;
1490 accum_.GetClassifiedMessages(&msgs); 1499 accum_.GetClassifiedMessages(&msgs);
1491 ASSERT_EQ(1U, msgs.size()); 1500 ASSERT_EQ(1U, msgs.size());
1492 ASSERT_EQ(2U, msgs[0].size()); 1501 ASSERT_EQ(2U, msgs[0].size());
1493 ASSERT_EQ(ResourceMsg_ReceivedResponse::ID, msgs[0][0].type()); 1502 ASSERT_EQ(ResourceMsg_ReceivedResponse::ID, msgs[0][0].type());
1494 CheckRequestCompleteErrorCode(msgs[0][1], net::ERR_ABORTED); 1503 CheckRequestCompleteErrorCode(msgs[0][1], net::ERR_ABORTED);
(...skipping 18 matching lines...) Expand all
1513 1522
1514 TEST_F(ResourceDispatcherHostTest, SyncLoadSuccess) { 1523 TEST_F(ResourceDispatcherHostTest, SyncLoadSuccess) {
1515 ResourceRequest request = CreateResourceRequest( 1524 ResourceRequest request = CreateResourceRequest(
1516 "GET", RESOURCE_TYPE_XHR, net::URLRequestTestJob::test_url_1()); 1525 "GET", RESOURCE_TYPE_XHR, net::URLRequestTestJob::test_url_1());
1517 request.priority = net::MAXIMUM_PRIORITY; 1526 request.priority = net::MAXIMUM_PRIORITY;
1518 1527
1519 // Successful sync load. 1528 // Successful sync load.
1520 std::tuple<SyncLoadResult> result; 1529 std::tuple<SyncLoadResult> result;
1521 ResourceHostMsg_SyncLoad sync_load_msg(0, 1, request, &std::get<0>(result)); 1530 ResourceHostMsg_SyncLoad sync_load_msg(0, 1, request, &std::get<0>(result));
1522 OnMessageReceived(sync_load_msg, filter_.get()); 1531 OnMessageReceived(sync_load_msg, filter_.get());
1523 base::RunLoop().RunUntilIdle(); 1532 content::RunAllBlockingPoolTasksUntilIdle();
1533 ;
1524 1534
1525 const IPC::Message* reply = accum_.GetReply(sync_load_msg); 1535 const IPC::Message* reply = accum_.GetReply(sync_load_msg);
1526 ASSERT_TRUE(reply); 1536 ASSERT_TRUE(reply);
1527 1537
1528 ASSERT_TRUE(ResourceHostMsg_SyncLoad::ReadReplyParam(reply, &result)); 1538 ASSERT_TRUE(ResourceHostMsg_SyncLoad::ReadReplyParam(reply, &result));
1529 EXPECT_EQ(net::OK, std::get<0>(result).error_code); 1539 EXPECT_EQ(net::OK, std::get<0>(result).error_code);
1530 } 1540 }
1531 1541
1532 TEST_F(ResourceDispatcherHostTest, SyncLoadError) { 1542 TEST_F(ResourceDispatcherHostTest, SyncLoadError) {
1533 ResourceRequest request = CreateResourceRequest( 1543 ResourceRequest request = CreateResourceRequest(
1534 "GET", RESOURCE_TYPE_XHR, net::URLRequestTestJob::test_url_error()); 1544 "GET", RESOURCE_TYPE_XHR, net::URLRequestTestJob::test_url_error());
1535 request.priority = net::MAXIMUM_PRIORITY; 1545 request.priority = net::MAXIMUM_PRIORITY;
1536 1546
1537 // Failued sync load. 1547 // Failued sync load.
1538 std::tuple<SyncLoadResult> result; 1548 std::tuple<SyncLoadResult> result;
1539 ResourceHostMsg_SyncLoad sync_load_msg(0, 1, request, &std::get<0>(result)); 1549 ResourceHostMsg_SyncLoad sync_load_msg(0, 1, request, &std::get<0>(result));
1540 OnMessageReceived(sync_load_msg, filter_.get()); 1550 OnMessageReceived(sync_load_msg, filter_.get());
1541 base::RunLoop().RunUntilIdle(); 1551 content::RunAllBlockingPoolTasksUntilIdle();
1552 ;
1542 1553
1543 const IPC::Message* reply = accum_.GetReply(sync_load_msg); 1554 const IPC::Message* reply = accum_.GetReply(sync_load_msg);
1544 ASSERT_TRUE(reply); 1555 ASSERT_TRUE(reply);
1545 1556
1546 ASSERT_TRUE(ResourceHostMsg_SyncLoad::ReadReplyParam(reply, &result)); 1557 ASSERT_TRUE(ResourceHostMsg_SyncLoad::ReadReplyParam(reply, &result));
1547 EXPECT_EQ(net::ERR_INVALID_URL, std::get<0>(result).error_code); 1558 EXPECT_EQ(net::ERR_INVALID_URL, std::get<0>(result).error_code);
1548 } 1559 }
1549 1560
1550 TEST_F(ResourceDispatcherHostTest, SyncLoadCancel) { 1561 TEST_F(ResourceDispatcherHostTest, SyncLoadCancel) {
1551 ResourceRequest request = CreateResourceRequest( 1562 ResourceRequest request = CreateResourceRequest(
1552 "GET", RESOURCE_TYPE_XHR, net::URLRequestTestJob::test_url_1()); 1563 "GET", RESOURCE_TYPE_XHR, net::URLRequestTestJob::test_url_1());
1553 request.priority = net::MAXIMUM_PRIORITY; 1564 request.priority = net::MAXIMUM_PRIORITY;
1554 1565
1555 // Cancelled sync load. 1566 // Cancelled sync load.
1556 SyncLoadResult result; 1567 SyncLoadResult result;
1557 ResourceHostMsg_SyncLoad sync_load_msg(0, 1, request, &result); 1568 ResourceHostMsg_SyncLoad sync_load_msg(0, 1, request, &result);
1558 1569
1559 OnMessageReceived(sync_load_msg, filter_.get()); 1570 OnMessageReceived(sync_load_msg, filter_.get());
1560 host_.CancelRequestsForProcess(filter_->child_id()); 1571 host_.CancelRequestsForProcess(filter_->child_id());
1561 base::RunLoop().RunUntilIdle(); 1572 content::RunAllBlockingPoolTasksUntilIdle();
1573 ;
1562 1574
1563 const IPC::Message* reply = accum_.GetReply(sync_load_msg); 1575 const IPC::Message* reply = accum_.GetReply(sync_load_msg);
1564 ASSERT_TRUE(reply); 1576 ASSERT_TRUE(reply);
1565 ASSERT_TRUE(reply->is_reply_error()); 1577 ASSERT_TRUE(reply->is_reply_error());
1566 } 1578 }
1567 1579
1568 // If the filter has disappeared then detachable resources should continue to 1580 // If the filter has disappeared then detachable resources should continue to
1569 // load. 1581 // load.
1570 TEST_F(ResourceDispatcherHostTest, DeletedFilterDetached) { 1582 TEST_F(ResourceDispatcherHostTest, DeletedFilterDetached) {
1571 // test_url_1's data is available synchronously, so use 2 and 3. 1583 // 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()); 1612 EXPECT_EQ(2, host_.pending_requests());
1601 EXPECT_TRUE(info_prefetch->detachable_handler()->is_detached()); 1613 EXPECT_TRUE(info_prefetch->detachable_handler()->is_detached());
1602 EXPECT_TRUE(info_ping->detachable_handler()->is_detached()); 1614 EXPECT_TRUE(info_ping->detachable_handler()->is_detached());
1603 1615
1604 KickOffRequest(); 1616 KickOffRequest();
1605 1617
1606 // Make sure the requests weren't canceled early. 1618 // Make sure the requests weren't canceled early.
1607 EXPECT_EQ(2, host_.pending_requests()); 1619 EXPECT_EQ(2, host_.pending_requests());
1608 1620
1609 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} 1621 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {}
1610 base::RunLoop().RunUntilIdle(); 1622 content::RunAllBlockingPoolTasksUntilIdle();
1623 ;
1611 1624
1612 EXPECT_EQ(0, host_.pending_requests()); 1625 EXPECT_EQ(0, host_.pending_requests());
1613 EXPECT_EQ(2, network_delegate()->completed_requests()); 1626 EXPECT_EQ(2, network_delegate()->completed_requests());
1614 EXPECT_EQ(0, network_delegate()->canceled_requests()); 1627 EXPECT_EQ(0, network_delegate()->canceled_requests());
1615 EXPECT_EQ(0, network_delegate()->error_count()); 1628 EXPECT_EQ(0, network_delegate()->error_count());
1616 } 1629 }
1617 1630
1618 // If the filter has disappeared (original process dies) then detachable 1631 // If the filter has disappeared (original process dies) then detachable
1619 // resources should continue to load, even when redirected. 1632 // resources should continue to load, even when redirected.
1620 TEST_F(ResourceDispatcherHostTest, DeletedFilterDetachedRedirect) { 1633 TEST_F(ResourceDispatcherHostTest, DeletedFilterDetachedRedirect) {
(...skipping 27 matching lines...) Expand all
1648 KickOffRequest(); 1661 KickOffRequest();
1649 1662
1650 // Verify that a redirect was followed. 1663 // Verify that a redirect was followed.
1651 EXPECT_EQ(2u, url_request->url_chain().size()); 1664 EXPECT_EQ(2u, url_request->url_chain().size());
1652 1665
1653 // Make sure the request wasn't canceled early. 1666 // Make sure the request wasn't canceled early.
1654 EXPECT_EQ(1, host_.pending_requests()); 1667 EXPECT_EQ(1, host_.pending_requests());
1655 1668
1656 // Finish up the request. 1669 // Finish up the request.
1657 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} 1670 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {}
1658 base::RunLoop().RunUntilIdle(); 1671 content::RunAllBlockingPoolTasksUntilIdle();
1672 ;
1659 1673
1660 EXPECT_EQ(0, host_.pending_requests()); 1674 EXPECT_EQ(0, host_.pending_requests());
1661 EXPECT_EQ(1, network_delegate()->completed_requests()); 1675 EXPECT_EQ(1, network_delegate()->completed_requests());
1662 EXPECT_EQ(0, network_delegate()->canceled_requests()); 1676 EXPECT_EQ(0, network_delegate()->canceled_requests());
1663 EXPECT_EQ(0, network_delegate()->error_count()); 1677 EXPECT_EQ(0, network_delegate()->error_count());
1664 } 1678 }
1665 1679
1666 TEST_F(ResourceDispatcherHostTest, CancelWhileStartIsDeferred) { 1680 TEST_F(ResourceDispatcherHostTest, CancelWhileStartIsDeferred) {
1667 bool was_deleted = false; 1681 bool was_deleted = false;
1668 1682
1669 // Arrange to have requests deferred before starting. 1683 // Arrange to have requests deferred before starting.
1670 TestResourceDispatcherHostDelegate delegate; 1684 TestResourceDispatcherHostDelegate delegate;
1671 delegate.set_flags(DEFER_STARTING_REQUEST); 1685 delegate.set_flags(DEFER_STARTING_REQUEST);
1672 delegate.set_url_request_user_data(new TestUserData(&was_deleted)); 1686 delegate.set_url_request_user_data(new TestUserData(&was_deleted));
1673 host_.SetDelegate(&delegate); 1687 host_.SetDelegate(&delegate);
1674 1688
1675 MakeTestRequest(0, 1, net::URLRequestTestJob::test_url_1()); 1689 MakeTestRequest(0, 1, net::URLRequestTestJob::test_url_1());
1676 // We cancel from the renderer because all non-renderer cancels delete 1690 // We cancel from the renderer because all non-renderer cancels delete
1677 // the request synchronously. 1691 // the request synchronously.
1678 RendererCancelRequest(1); 1692 RendererCancelRequest(1);
1679 1693
1680 // Our TestResourceThrottle should not have been deleted yet. This is to 1694 // Our TestResourceThrottle should not have been deleted yet. This is to
1681 // ensure that destruction of the URLRequest happens asynchronously to 1695 // ensure that destruction of the URLRequest happens asynchronously to
1682 // calling CancelRequest. 1696 // calling CancelRequest.
1683 EXPECT_FALSE(was_deleted); 1697 EXPECT_FALSE(was_deleted);
1684 1698
1685 base::RunLoop().RunUntilIdle(); 1699 content::RunAllBlockingPoolTasksUntilIdle();
1700 ;
1686 1701
1687 EXPECT_TRUE(was_deleted); 1702 EXPECT_TRUE(was_deleted);
1688 } 1703 }
1689 1704
1690 TEST_F(ResourceDispatcherHostTest, DetachWhileStartIsDeferred) { 1705 TEST_F(ResourceDispatcherHostTest, DetachWhileStartIsDeferred) {
1691 bool was_deleted = false; 1706 bool was_deleted = false;
1692 1707
1693 // Arrange to have requests deferred before starting. 1708 // Arrange to have requests deferred before starting.
1694 TestResourceDispatcherHostDelegate delegate; 1709 TestResourceDispatcherHostDelegate delegate;
1695 delegate.set_flags(DEFER_STARTING_REQUEST); 1710 delegate.set_flags(DEFER_STARTING_REQUEST);
1696 delegate.set_url_request_user_data(new TestUserData(&was_deleted)); 1711 delegate.set_url_request_user_data(new TestUserData(&was_deleted));
1697 host_.SetDelegate(&delegate); 1712 host_.SetDelegate(&delegate);
1698 1713
1699 MakeTestRequestWithResourceType(filter_.get(), 0, 1, 1714 MakeTestRequestWithResourceType(filter_.get(), 0, 1,
1700 net::URLRequestTestJob::test_url_1(), 1715 net::URLRequestTestJob::test_url_1(),
1701 RESOURCE_TYPE_PREFETCH); // detachable type 1716 RESOURCE_TYPE_PREFETCH); // detachable type
1702 // Cancel request must come from the renderer for a detachable resource to 1717 // Cancel request must come from the renderer for a detachable resource to
1703 // detach. 1718 // detach.
1704 RendererCancelRequest(1); 1719 RendererCancelRequest(1);
1705 1720
1706 // Even after driving the event loop, the request has not been deleted. 1721 // Even after driving the event loop, the request has not been deleted.
1707 EXPECT_FALSE(was_deleted); 1722 EXPECT_FALSE(was_deleted);
1708 1723
1709 // However, it is still throttled because the defer happened above the 1724 // However, it is still throttled because the defer happened above the
1710 // DetachableResourceHandler. 1725 // DetachableResourceHandler.
1711 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} 1726 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {}
1712 base::RunLoop().RunUntilIdle(); 1727 content::RunAllBlockingPoolTasksUntilIdle();
1728 ;
1713 EXPECT_FALSE(was_deleted); 1729 EXPECT_FALSE(was_deleted);
1714 1730
1715 // Resume the request. 1731 // Resume the request.
1716 GenericResourceThrottle* throttle = 1732 GenericResourceThrottle* throttle =
1717 GenericResourceThrottle::active_throttle(); 1733 GenericResourceThrottle::active_throttle();
1718 ASSERT_TRUE(throttle); 1734 ASSERT_TRUE(throttle);
1719 throttle->AssertAndResume(); 1735 throttle->AssertAndResume();
1720 1736
1721 // Now, the request completes. 1737 // Now, the request completes.
1722 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} 1738 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {}
1723 base::RunLoop().RunUntilIdle(); 1739 content::RunAllBlockingPoolTasksUntilIdle();
1740 ;
1724 EXPECT_TRUE(was_deleted); 1741 EXPECT_TRUE(was_deleted);
1725 EXPECT_EQ(1, network_delegate()->completed_requests()); 1742 EXPECT_EQ(1, network_delegate()->completed_requests());
1726 EXPECT_EQ(0, network_delegate()->canceled_requests()); 1743 EXPECT_EQ(0, network_delegate()->canceled_requests());
1727 EXPECT_EQ(0, network_delegate()->error_count()); 1744 EXPECT_EQ(0, network_delegate()->error_count());
1728 } 1745 }
1729 1746
1730 // Tests if cancel is called in ResourceThrottle::WillStartRequest, then the 1747 // Tests if cancel is called in ResourceThrottle::WillStartRequest, then the
1731 // URLRequest will not be started. 1748 // URLRequest will not be started.
1732 TEST_F(ResourceDispatcherHostTest, CancelInResourceThrottleWillStartRequest) { 1749 TEST_F(ResourceDispatcherHostTest, CancelInResourceThrottleWillStartRequest) {
1733 TestResourceDispatcherHostDelegate delegate; 1750 TestResourceDispatcherHostDelegate delegate;
1734 delegate.set_flags(CANCEL_BEFORE_START); 1751 delegate.set_flags(CANCEL_BEFORE_START);
1735 host_.SetDelegate(&delegate); 1752 host_.SetDelegate(&delegate);
1736 1753
1737 MakeTestRequest(0, 1, net::URLRequestTestJob::test_url_1()); 1754 MakeTestRequest(0, 1, net::URLRequestTestJob::test_url_1());
1738 1755
1739 // flush all the pending requests 1756 // flush all the pending requests
1740 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} 1757 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {}
1741 base::RunLoop().RunUntilIdle(); 1758 content::RunAllBlockingPoolTasksUntilIdle();
1759 ;
1742 1760
1743 ResourceIPCAccumulator::ClassifiedMessages msgs; 1761 ResourceIPCAccumulator::ClassifiedMessages msgs;
1744 accum_.GetClassifiedMessages(&msgs); 1762 accum_.GetClassifiedMessages(&msgs);
1745 1763
1746 // Check that request got canceled. 1764 // Check that request got canceled.
1747 ASSERT_EQ(1U, msgs[0].size()); 1765 ASSERT_EQ(1U, msgs[0].size());
1748 CheckRequestCompleteErrorCode(msgs[0][0], net::ERR_ABORTED); 1766 CheckRequestCompleteErrorCode(msgs[0][0], net::ERR_ABORTED);
1749 1767
1750 // Make sure URLRequest is never started. 1768 // Make sure URLRequest is never started.
1751 EXPECT_EQ(0, job_factory_->url_request_jobs_created_count()); 1769 EXPECT_EQ(0, job_factory_->url_request_jobs_created_count());
1752 } 1770 }
1753 1771
1754 TEST_F(ResourceDispatcherHostTest, PausedStartError) { 1772 TEST_F(ResourceDispatcherHostTest, PausedStartError) {
1755 // Arrange to have requests deferred before processing response headers. 1773 // Arrange to have requests deferred before processing response headers.
1756 TestResourceDispatcherHostDelegate delegate; 1774 TestResourceDispatcherHostDelegate delegate;
1757 delegate.set_flags(DEFER_PROCESSING_RESPONSE); 1775 delegate.set_flags(DEFER_PROCESSING_RESPONSE);
1758 host_.SetDelegate(&delegate); 1776 host_.SetDelegate(&delegate);
1759 1777
1760 job_factory_->SetDelayedStartJobGeneration(true); 1778 job_factory_->SetDelayedStartJobGeneration(true);
1761 MakeTestRequest(0, 1, net::URLRequestTestJob::test_url_error()); 1779 MakeTestRequest(0, 1, net::URLRequestTestJob::test_url_error());
1762 CompleteStartRequest(1); 1780 CompleteStartRequest(1);
1763 1781
1764 // flush all the pending requests 1782 // flush all the pending requests
1765 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} 1783 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {}
1766 base::RunLoop().RunUntilIdle(); 1784 content::RunAllBlockingPoolTasksUntilIdle();
1785 ;
1767 1786
1768 EXPECT_EQ(0, host_.pending_requests()); 1787 EXPECT_EQ(0, host_.pending_requests());
1769 } 1788 }
1770 1789
1771 TEST_F(ResourceDispatcherHostTest, ThrottleAndResumeTwice) { 1790 TEST_F(ResourceDispatcherHostTest, ThrottleAndResumeTwice) {
1772 // Arrange to have requests deferred before starting. 1791 // Arrange to have requests deferred before starting.
1773 TestResourceDispatcherHostDelegate delegate; 1792 TestResourceDispatcherHostDelegate delegate;
1774 delegate.set_flags(DEFER_STARTING_REQUEST); 1793 delegate.set_flags(DEFER_STARTING_REQUEST);
1775 delegate.set_create_two_throttles(true); 1794 delegate.set_create_two_throttles(true);
1776 host_.SetDelegate(&delegate); 1795 host_.SetDelegate(&delegate);
1777 1796
1778 // Make sure the first throttle blocked the request, and then resume. 1797 // Make sure the first throttle blocked the request, and then resume.
1779 MakeTestRequest(0, 1, net::URLRequestTestJob::test_url_1()); 1798 MakeTestRequest(0, 1, net::URLRequestTestJob::test_url_1());
1780 GenericResourceThrottle* first_throttle = 1799 GenericResourceThrottle* first_throttle =
1781 GenericResourceThrottle::active_throttle(); 1800 GenericResourceThrottle::active_throttle();
1782 ASSERT_TRUE(first_throttle); 1801 ASSERT_TRUE(first_throttle);
1783 first_throttle->AssertAndResume(); 1802 first_throttle->AssertAndResume();
1784 1803
1785 // Make sure the second throttle blocked the request, and then resume. 1804 // Make sure the second throttle blocked the request, and then resume.
1786 ASSERT_TRUE(GenericResourceThrottle::active_throttle()); 1805 ASSERT_TRUE(GenericResourceThrottle::active_throttle());
1787 ASSERT_NE(first_throttle, GenericResourceThrottle::active_throttle()); 1806 ASSERT_NE(first_throttle, GenericResourceThrottle::active_throttle());
1788 GenericResourceThrottle::active_throttle()->AssertAndResume(); 1807 GenericResourceThrottle::active_throttle()->AssertAndResume();
1789 1808
1790 ASSERT_FALSE(GenericResourceThrottle::active_throttle()); 1809 ASSERT_FALSE(GenericResourceThrottle::active_throttle());
1791 1810
1792 // The request is started asynchronously. 1811 // The request is started asynchronously.
1793 base::RunLoop().RunUntilIdle(); 1812 content::RunAllBlockingPoolTasksUntilIdle();
1813 ;
1794 1814
1795 // Flush all the pending requests. 1815 // Flush all the pending requests.
1796 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} 1816 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {}
1797 1817
1798 EXPECT_EQ(0, host_.pending_requests()); 1818 EXPECT_EQ(0, host_.pending_requests());
1799 1819
1800 // Make sure the request completed successfully. 1820 // Make sure the request completed successfully.
1801 ResourceIPCAccumulator::ClassifiedMessages msgs; 1821 ResourceIPCAccumulator::ClassifiedMessages msgs;
1802 accum_.GetClassifiedMessages(&msgs); 1822 accum_.GetClassifiedMessages(&msgs);
1803 ASSERT_EQ(1U, msgs.size()); 1823 ASSERT_EQ(1U, msgs.size());
1804 CheckSuccessfulRequest(msgs[0], net::URLRequestTestJob::test_data_1()); 1824 CheckSuccessfulRequest(msgs[0], net::URLRequestTestJob::test_data_1());
1805 } 1825 }
1806 1826
1807 1827
1808 // Tests that the delegate can cancel a request and provide a error code. 1828 // Tests that the delegate can cancel a request and provide a error code.
1809 TEST_F(ResourceDispatcherHostTest, CancelInDelegate) { 1829 TEST_F(ResourceDispatcherHostTest, CancelInDelegate) {
1810 TestResourceDispatcherHostDelegate delegate; 1830 TestResourceDispatcherHostDelegate delegate;
1811 delegate.set_flags(CANCEL_BEFORE_START); 1831 delegate.set_flags(CANCEL_BEFORE_START);
1812 delegate.set_error_code_for_cancellation(net::ERR_ACCESS_DENIED); 1832 delegate.set_error_code_for_cancellation(net::ERR_ACCESS_DENIED);
1813 host_.SetDelegate(&delegate); 1833 host_.SetDelegate(&delegate);
1814 1834
1815 MakeTestRequest(0, 1, net::URLRequestTestJob::test_url_1()); 1835 MakeTestRequest(0, 1, net::URLRequestTestJob::test_url_1());
1816 // The request will get cancelled by the throttle. 1836 // The request will get cancelled by the throttle.
1817 1837
1818 // flush all the pending requests 1838 // flush all the pending requests
1819 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} 1839 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {}
1820 base::RunLoop().RunUntilIdle(); 1840 content::RunAllBlockingPoolTasksUntilIdle();
1841 ;
1821 1842
1822 ResourceIPCAccumulator::ClassifiedMessages msgs; 1843 ResourceIPCAccumulator::ClassifiedMessages msgs;
1823 accum_.GetClassifiedMessages(&msgs); 1844 accum_.GetClassifiedMessages(&msgs);
1824 1845
1825 // Check the cancellation 1846 // Check the cancellation
1826 ASSERT_EQ(1U, msgs.size()); 1847 ASSERT_EQ(1U, msgs.size());
1827 ASSERT_EQ(1U, msgs[0].size()); 1848 ASSERT_EQ(1U, msgs[0].size());
1828 1849
1829 CheckRequestCompleteErrorCode(msgs[0][0], net::ERR_ACCESS_DENIED); 1850 CheckRequestCompleteErrorCode(msgs[0][0], net::ERR_ACCESS_DENIED);
1830 } 1851 }
(...skipping 18 matching lines...) Expand all
1849 RESOURCE_TYPE_SUB_RESOURCE); 1870 RESOURCE_TYPE_SUB_RESOURCE);
1850 1871
1851 // request 4 goes to us 1872 // request 4 goes to us
1852 MakeTestRequestWithResourceType(filter_.get(), 0, 4, 1873 MakeTestRequestWithResourceType(filter_.get(), 0, 4,
1853 net::URLRequestTestJob::test_url_4(), 1874 net::URLRequestTestJob::test_url_4(),
1854 RESOURCE_TYPE_PREFETCH); // detachable type 1875 RESOURCE_TYPE_PREFETCH); // detachable type
1855 1876
1856 1877
1857 // Make sure all requests have finished stage one. test_url_1 will have 1878 // Make sure all requests have finished stage one. test_url_1 will have
1858 // finished. 1879 // finished.
1859 base::RunLoop().RunUntilIdle(); 1880 content::RunAllBlockingPoolTasksUntilIdle();
1881 ;
1860 1882
1861 // TODO(mbelshe): 1883 // TODO(mbelshe):
1862 // Now that the async IO path is in place, the IO always completes on the 1884 // 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 1885 // initial call; so the requests have already completed. This basically
1864 // breaks the whole test. 1886 // breaks the whole test.
1865 // EXPECT_EQ(3, host_.pending_requests()); 1887 // EXPECT_EQ(3, host_.pending_requests());
1866 1888
1867 // Process test_url_2 and test_url_3 for one level so one callback is called. 1889 // 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 1890 // We'll cancel test_url_4 (detachable) before processing it to verify that it
1869 // delays the cancel. 1891 // delays the cancel.
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
1941 KickOffRequest(); 1963 KickOffRequest();
1942 EXPECT_EQ(3, network_delegate_.created_requests()); 1964 EXPECT_EQ(3, network_delegate_.created_requests());
1943 EXPECT_EQ(0, network_delegate_.canceled_requests()); 1965 EXPECT_EQ(0, network_delegate_.canceled_requests());
1944 1966
1945 // The first two RenderFrameHosts are destroyed. All 4 of their requests 1967 // The first two RenderFrameHosts are destroyed. All 4 of their requests
1946 // should be cancelled, and none of the two deferred requests should be 1968 // should be cancelled, and none of the two deferred requests should be
1947 // started. 1969 // started.
1948 DeleteRenderFrame(GlobalFrameRoutingId(filter_->child_id(), 10)); 1970 DeleteRenderFrame(GlobalFrameRoutingId(filter_->child_id(), 10));
1949 DeleteRenderFrame(GlobalFrameRoutingId(filter_->child_id(), 11)); 1971 DeleteRenderFrame(GlobalFrameRoutingId(filter_->child_id(), 11));
1950 host_.OnRenderViewHostDeleted(filter_->child_id(), 0); 1972 host_.OnRenderViewHostDeleted(filter_->child_id(), 0);
1951 base::RunLoop().RunUntilIdle(); 1973 content::RunAllBlockingPoolTasksUntilIdle();
1974 ;
1952 EXPECT_EQ(3, network_delegate_.created_requests()); 1975 EXPECT_EQ(3, network_delegate_.created_requests());
1953 EXPECT_EQ(4, network_delegate_.canceled_requests()); 1976 EXPECT_EQ(4, network_delegate_.canceled_requests());
1954 1977
1955 // No messages should have been sent, since none of the jobs made any 1978 // No messages should have been sent, since none of the jobs made any
1956 // progress. 1979 // progress.
1957 ResourceIPCAccumulator::ClassifiedMessages msgs; 1980 ResourceIPCAccumulator::ClassifiedMessages msgs;
1958 accum_.GetClassifiedMessages(&msgs); 1981 accum_.GetClassifiedMessages(&msgs);
1959 EXPECT_EQ(0U, msgs.size()); 1982 EXPECT_EQ(0U, msgs.size());
1960 } 1983 }
1961 1984
1962 TEST_F(ResourceDispatcherHostTest, TestProcessCancelDetachedTimesOut) { 1985 TEST_F(ResourceDispatcherHostTest, TestProcessCancelDetachedTimesOut) {
1963 MakeTestRequestWithResourceType(filter_.get(), 0, 1, 1986 MakeTestRequestWithResourceType(filter_.get(), 0, 1,
1964 net::URLRequestTestJob::test_url_4(), 1987 net::URLRequestTestJob::test_url_4(),
1965 RESOURCE_TYPE_PREFETCH); // detachable type 1988 RESOURCE_TYPE_PREFETCH); // detachable type
1966 GlobalRequestID global_request_id(filter_->child_id(), 1); 1989 GlobalRequestID global_request_id(filter_->child_id(), 1);
1967 ResourceRequestInfoImpl* info = ResourceRequestInfoImpl::ForRequest( 1990 ResourceRequestInfoImpl* info = ResourceRequestInfoImpl::ForRequest(
1968 host_.GetURLRequest(global_request_id)); 1991 host_.GetURLRequest(global_request_id));
1969 ASSERT_TRUE(info->detachable_handler()); 1992 ASSERT_TRUE(info->detachable_handler());
1970 info->detachable_handler()->set_cancel_delay( 1993 info->detachable_handler()->set_cancel_delay(
1971 base::TimeDelta::FromMilliseconds(200)); 1994 base::TimeDelta::FromMilliseconds(200));
1972 base::RunLoop().RunUntilIdle(); 1995 content::RunAllBlockingPoolTasksUntilIdle();
1996 ;
1973 1997
1974 // Cancel the requests to the test process. 1998 // Cancel the requests to the test process.
1975 host_.CancelRequestsForProcess(filter_->child_id()); 1999 host_.CancelRequestsForProcess(filter_->child_id());
1976 EXPECT_EQ(1, host_.pending_requests()); 2000 EXPECT_EQ(1, host_.pending_requests());
1977 2001
1978 // Wait until after the delay timer times out before we start processing any 2002 // Wait until after the delay timer times out before we start processing any
1979 // messages. 2003 // messages.
1980 base::OneShotTimer timer; 2004 base::OneShotTimer timer;
1981 timer.Start(FROM_HERE, base::TimeDelta::FromMilliseconds(210), 2005 timer.Start(FROM_HERE, base::TimeDelta::FromMilliseconds(210),
1982 base::MessageLoop::current(), &base::MessageLoop::QuitWhenIdle); 2006 base::MessageLoop::current(), &base::MessageLoop::QuitWhenIdle);
1983 base::RunLoop().Run(); 2007 base::RunLoop().Run();
1984 2008
1985 // The prefetch should be cancelled by now. 2009 // The prefetch should be cancelled by now.
1986 EXPECT_EQ(0, host_.pending_requests()); 2010 EXPECT_EQ(0, host_.pending_requests());
1987 2011
1988 // In case any messages are still to be processed. 2012 // In case any messages are still to be processed.
1989 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} 2013 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {}
1990 base::RunLoop().RunUntilIdle(); 2014 content::RunAllBlockingPoolTasksUntilIdle();
2015 ;
1991 2016
1992 ResourceIPCAccumulator::ClassifiedMessages msgs; 2017 ResourceIPCAccumulator::ClassifiedMessages msgs;
1993 accum_.GetClassifiedMessages(&msgs); 2018 accum_.GetClassifiedMessages(&msgs);
1994 2019
1995 ASSERT_EQ(1U, msgs.size()); 2020 ASSERT_EQ(1U, msgs.size());
1996 2021
1997 // The request should have cancelled. 2022 // The request should have cancelled.
1998 ASSERT_EQ(2U, msgs[0].size()); 2023 ASSERT_EQ(2U, msgs[0].size());
1999 ASSERT_EQ(ResourceMsg_ReceivedResponse::ID, msgs[0][0].type()); 2024 ASSERT_EQ(ResourceMsg_ReceivedResponse::ID, msgs[0][0].type());
2000 CheckRequestCompleteErrorCode(msgs[0][1], net::ERR_ABORTED); 2025 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. 2297 // it is just process 0 that is saturated.
2273 MakeTestRequestWithResourceType(second_filter.get(), 0, kMaxRequests + 3, 2298 MakeTestRequestWithResourceType(second_filter.get(), 0, kMaxRequests + 3,
2274 net::URLRequestTestJob::test_url_2(), 2299 net::URLRequestTestJob::test_url_2(),
2275 RESOURCE_TYPE_SUB_RESOURCE); 2300 RESOURCE_TYPE_SUB_RESOURCE);
2276 MakeTestRequestWithResourceType(second_filter.get(), 0, kMaxRequests + 4, 2301 MakeTestRequestWithResourceType(second_filter.get(), 0, kMaxRequests + 4,
2277 net::URLRequestTestJob::test_url_2(), 2302 net::URLRequestTestJob::test_url_2(),
2278 RESOURCE_TYPE_SUB_RESOURCE); 2303 RESOURCE_TYPE_SUB_RESOURCE);
2279 2304
2280 // Flush all the pending requests. 2305 // Flush all the pending requests.
2281 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} 2306 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {}
2282 base::RunLoop().RunUntilIdle(); 2307 content::RunAllBlockingPoolTasksUntilIdle();
2308 ;
2283 2309
2284 // Sorts out all the messages we saw by request. 2310 // Sorts out all the messages we saw by request.
2285 ResourceIPCAccumulator::ClassifiedMessages msgs; 2311 ResourceIPCAccumulator::ClassifiedMessages msgs;
2286 accum_.GetClassifiedMessages(&msgs); 2312 accum_.GetClassifiedMessages(&msgs);
2287 2313
2288 // We issued (kMaxRequests + 4) total requests. 2314 // We issued (kMaxRequests + 4) total requests.
2289 ASSERT_EQ(kMaxRequests + 4, msgs.size()); 2315 ASSERT_EQ(kMaxRequests + 4, msgs.size());
2290 2316
2291 // Check that the first kMaxRequests succeeded. 2317 // Check that the first kMaxRequests succeeded.
2292 for (size_t i = 0; i < kMaxRequests; ++i) 2318 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); 2369 net::URLRequestTestJob::test_url_2(), RESOURCE_TYPE_SUB_RESOURCE);
2344 2370
2345 // Issue a request for the third process -- this should fail, because the 2371 // Issue a request for the third process -- this should fail, because the
2346 // global limit has been reached. 2372 // global limit has been reached.
2347 MakeTestRequestWithResourceType( 2373 MakeTestRequestWithResourceType(
2348 third_filter.get(), 0, kMaxRequestsPerProcess + 3, 2374 third_filter.get(), 0, kMaxRequestsPerProcess + 3,
2349 net::URLRequestTestJob::test_url_2(), RESOURCE_TYPE_SUB_RESOURCE); 2375 net::URLRequestTestJob::test_url_2(), RESOURCE_TYPE_SUB_RESOURCE);
2350 2376
2351 // Flush all the pending requests. 2377 // Flush all the pending requests.
2352 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} 2378 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {}
2353 base::RunLoop().RunUntilIdle(); 2379 content::RunAllBlockingPoolTasksUntilIdle();
2380 ;
2354 2381
2355 // Sorts out all the messages we saw by request. 2382 // Sorts out all the messages we saw by request.
2356 ResourceIPCAccumulator::ClassifiedMessages msgs; 2383 ResourceIPCAccumulator::ClassifiedMessages msgs;
2357 accum_.GetClassifiedMessages(&msgs); 2384 accum_.GetClassifiedMessages(&msgs);
2358 2385
2359 // The processes issued the following requests: 2386 // The processes issued the following requests:
2360 // #1 issued kMaxRequestsPerProcess that passed + 1 that failed 2387 // #1 issued kMaxRequestsPerProcess that passed + 1 that failed
2361 // #2 issued 1 request that passed 2388 // #2 issued 1 request that passed
2362 // #3 issued 1 request that failed 2389 // #3 issued 1 request that failed
2363 ASSERT_EQ((kMaxRequestsPerProcess + 1) + 1 + 1, msgs.size()); 2390 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); 2559 SetResponse(raw_headers, response_data);
2533 job_factory_->SetDelayedCompleteJobGeneration(true); 2560 job_factory_->SetDelayedCompleteJobGeneration(true);
2534 HandleScheme("http"); 2561 HandleScheme("http");
2535 2562
2536 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id, 2563 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id,
2537 GURL("http://example.com/blah"), 2564 GURL("http://example.com/blah"),
2538 RESOURCE_TYPE_MAIN_FRAME); 2565 RESOURCE_TYPE_MAIN_FRAME);
2539 // Return some data so that the request is identified as a download 2566 // Return some data so that the request is identified as a download
2540 // and the proper resource handlers are created. 2567 // and the proper resource handlers are created.
2541 EXPECT_TRUE(net::URLRequestTestJob::ProcessOnePendingMessage()); 2568 EXPECT_TRUE(net::URLRequestTestJob::ProcessOnePendingMessage());
2542 base::RunLoop().RunUntilIdle(); 2569 content::RunAllBlockingPoolTasksUntilIdle();
2570 ;
2543 2571
2544 // And now simulate a cancellation coming from the renderer. 2572 // And now simulate a cancellation coming from the renderer.
2545 ResourceHostMsg_CancelRequest msg(request_id); 2573 ResourceHostMsg_CancelRequest msg(request_id);
2546 OnMessageReceived(msg, filter_.get()); 2574 OnMessageReceived(msg, filter_.get());
2547 2575
2548 // Since the request had already started processing as a download, 2576 // Since the request had already started processing as a download,
2549 // the cancellation above should have been ignored and the request 2577 // the cancellation above should have been ignored and the request
2550 // should still be alive. 2578 // should still be alive.
2551 EXPECT_EQ(1, host_.pending_requests()); 2579 EXPECT_EQ(1, host_.pending_requests());
2552 2580
2553 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} 2581 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {}
2554 base::RunLoop().RunUntilIdle(); 2582 content::RunAllBlockingPoolTasksUntilIdle();
2583 ;
2555 } 2584 }
2556 2585
2557 TEST_F(ResourceDispatcherHostTest, CancelRequestsForContext) { 2586 TEST_F(ResourceDispatcherHostTest, CancelRequestsForContext) {
2558 EXPECT_EQ(0, host_.pending_requests()); 2587 EXPECT_EQ(0, host_.pending_requests());
2559 NavigationResourceThrottle::set_ui_checks_always_succeed_for_testing(true); 2588 NavigationResourceThrottle::set_ui_checks_always_succeed_for_testing(true);
2560 2589
2561 int render_view_id = 0; 2590 int render_view_id = 0;
2562 int request_id = 1; 2591 int request_id = 1;
2563 2592
2564 std::string raw_headers("HTTP\n" 2593 std::string raw_headers("HTTP\n"
(...skipping 27 matching lines...) Expand all
2592 browser_context_->GetResourceContext(), 2621 browser_context_->GetResourceContext(),
2593 BrowserContext::GetDefaultStoragePartition(browser_context_.get()), 2622 BrowserContext::GetDefaultStoragePartition(browser_context_.get()),
2594 std::move(request_info), nullptr, nullptr, nullptr, &delegate); 2623 std::move(request_info), nullptr, nullptr, nullptr, &delegate);
2595 2624
2596 // Wait until a response has been received and proceed with the response. 2625 // Wait until a response has been received and proceed with the response.
2597 KickOffRequest(); 2626 KickOffRequest();
2598 2627
2599 // Return some data so that the request is identified as a download 2628 // Return some data so that the request is identified as a download
2600 // and the proper resource handlers are created. 2629 // and the proper resource handlers are created.
2601 EXPECT_TRUE(net::URLRequestTestJob::ProcessOnePendingMessage()); 2630 EXPECT_TRUE(net::URLRequestTestJob::ProcessOnePendingMessage());
2602 base::RunLoop().RunUntilIdle(); 2631 content::RunAllBlockingPoolTasksUntilIdle();
2632 ;
2603 2633
2604 // The UI thread will be informed that the navigation failed with an error 2634 // 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. 2635 // 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. 2636 // The navigation is aborted, but the request goes on as a download.
2607 EXPECT_EQ(delegate.net_error(), net::ERR_ABORTED); 2637 EXPECT_EQ(delegate.net_error(), net::ERR_ABORTED);
2608 EXPECT_EQ(1, host_.pending_requests()); 2638 EXPECT_EQ(1, host_.pending_requests());
2609 2639
2610 // In PlzNavigate, the renderer cannot cancel the request directly. 2640 // In PlzNavigate, the renderer cannot cancel the request directly.
2611 // However, cancelling by context should work. 2641 // However, cancelling by context should work.
2612 host_.CancelRequestsForContext(browser_context_->GetResourceContext()); 2642 host_.CancelRequestsForContext(browser_context_->GetResourceContext());
2613 EXPECT_EQ(0, host_.pending_requests()); 2643 EXPECT_EQ(0, host_.pending_requests());
2614 2644
2615 base::RunLoop().RunUntilIdle(); 2645 content::RunAllBlockingPoolTasksUntilIdle();
2646 ;
2616 } else { 2647 } else {
2617 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id, 2648 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id,
2618 download_url, RESOURCE_TYPE_MAIN_FRAME); 2649 download_url, RESOURCE_TYPE_MAIN_FRAME);
2619 2650
2620 // Return some data so that the request is identified as a download 2651 // Return some data so that the request is identified as a download
2621 // and the proper resource handlers are created. 2652 // and the proper resource handlers are created.
2622 EXPECT_TRUE(net::URLRequestTestJob::ProcessOnePendingMessage()); 2653 EXPECT_TRUE(net::URLRequestTestJob::ProcessOnePendingMessage());
2623 base::RunLoop().RunUntilIdle(); 2654 content::RunAllBlockingPoolTasksUntilIdle();
2655 ;
2624 2656
2625 // And now simulate a cancellation coming from the renderer. 2657 // And now simulate a cancellation coming from the renderer.
2626 ResourceHostMsg_CancelRequest msg(request_id); 2658 ResourceHostMsg_CancelRequest msg(request_id);
2627 OnMessageReceived(msg, filter_.get()); 2659 OnMessageReceived(msg, filter_.get());
2628 2660
2629 // Since the request had already started processing as a download, 2661 // Since the request had already started processing as a download,
2630 // the cancellation above should have been ignored and the request 2662 // the cancellation above should have been ignored and the request
2631 // should still be alive. 2663 // should still be alive.
2632 EXPECT_EQ(1, host_.pending_requests()); 2664 EXPECT_EQ(1, host_.pending_requests());
2633 2665
2634 // Cancelling by other methods shouldn't work either. 2666 // Cancelling by other methods shouldn't work either.
2635 host_.CancelRequestsForProcess(render_view_id); 2667 host_.CancelRequestsForProcess(render_view_id);
2636 EXPECT_EQ(1, host_.pending_requests()); 2668 EXPECT_EQ(1, host_.pending_requests());
2637 2669
2638 // Cancelling by context should work. 2670 // Cancelling by context should work.
2639 host_.CancelRequestsForContext(filter_->resource_context()); 2671 host_.CancelRequestsForContext(filter_->resource_context());
2640 EXPECT_EQ(0, host_.pending_requests()); 2672 EXPECT_EQ(0, host_.pending_requests());
2641 2673
2642 while (net::URLRequestTestJob::ProcessOnePendingMessage()) { 2674 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {
2643 } 2675 }
2644 base::RunLoop().RunUntilIdle(); 2676 content::RunAllBlockingPoolTasksUntilIdle();
2677 ;
2645 } 2678 }
2646 } 2679 }
2647 2680
2648 TEST_F(ResourceDispatcherHostTest, CancelRequestsForContextDetached) { 2681 TEST_F(ResourceDispatcherHostTest, CancelRequestsForContextDetached) {
2649 EXPECT_EQ(0, host_.pending_requests()); 2682 EXPECT_EQ(0, host_.pending_requests());
2650 2683
2651 int render_view_id = 0; 2684 int render_view_id = 0;
2652 int request_id = 1; 2685 int request_id = 1;
2653 2686
2654 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id, 2687 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); 2778 RESOURCE_TYPE_MAIN_FRAME);
2746 2779
2747 // Now that we're blocked on the redirect, update the response and unblock by 2780 // Now that we're blocked on the redirect, update the response and unblock by
2748 // telling the AsyncResourceHandler to follow the redirect. 2781 // telling the AsyncResourceHandler to follow the redirect.
2749 const std::string kResponseBody = "hello world"; 2782 const std::string kResponseBody = "hello world";
2750 SetResponse("HTTP/1.1 200 OK\n" 2783 SetResponse("HTTP/1.1 200 OK\n"
2751 "Content-Type: text/html\n\n", 2784 "Content-Type: text/html\n\n",
2752 kResponseBody); 2785 kResponseBody);
2753 ResourceHostMsg_FollowRedirect redirect_msg(request_id); 2786 ResourceHostMsg_FollowRedirect redirect_msg(request_id);
2754 OnMessageReceived(redirect_msg, filter_.get()); 2787 OnMessageReceived(redirect_msg, filter_.get());
2755 base::RunLoop().RunUntilIdle(); 2788 content::RunAllBlockingPoolTasksUntilIdle();
2789 ;
2756 2790
2757 // Flush all the pending requests to get the response through the 2791 // Flush all the pending requests to get the response through the
2758 // MimeTypeResourceHandler. 2792 // MimeTypeResourceHandler.
2759 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} 2793 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {}
2760 2794
2761 // This second filter is used to emulate a second process. 2795 // This second filter is used to emulate a second process.
2762 scoped_refptr<ForwardingFilter> second_filter = MakeForwardingFilter(); 2796 scoped_refptr<ForwardingFilter> second_filter = MakeForwardingFilter();
2763 2797
2764 int new_render_view_id = 1; 2798 int new_render_view_id = 1;
2765 int new_request_id = 2; 2799 int new_request_id = 2;
2766 2800
2767 ResourceRequest request = CreateResourceRequest( 2801 ResourceRequest request = CreateResourceRequest(
2768 "GET", RESOURCE_TYPE_MAIN_FRAME, GURL("http://other.com/blech")); 2802 "GET", RESOURCE_TYPE_MAIN_FRAME, GURL("http://other.com/blech"));
2769 request.transferred_request_child_id = filter_->child_id(); 2803 request.transferred_request_child_id = filter_->child_id();
2770 request.transferred_request_request_id = request_id; 2804 request.transferred_request_request_id = request_id;
2771 2805
2772 ResourceHostMsg_RequestResource transfer_request_msg( 2806 ResourceHostMsg_RequestResource transfer_request_msg(
2773 new_render_view_id, new_request_id, request); 2807 new_render_view_id, new_request_id, request);
2774 OnMessageReceived(transfer_request_msg, second_filter.get()); 2808 OnMessageReceived(transfer_request_msg, second_filter.get());
2775 base::RunLoop().RunUntilIdle(); 2809 content::RunAllBlockingPoolTasksUntilIdle();
2810 ;
2776 2811
2777 // Check generated messages. 2812 // Check generated messages.
2778 ResourceIPCAccumulator::ClassifiedMessages msgs; 2813 ResourceIPCAccumulator::ClassifiedMessages msgs;
2779 accum_.GetClassifiedMessages(&msgs); 2814 accum_.GetClassifiedMessages(&msgs);
2780 2815
2781 ASSERT_EQ(2U, msgs.size()); 2816 ASSERT_EQ(2U, msgs.size());
2782 EXPECT_EQ(ResourceMsg_ReceivedRedirect::ID, msgs[0][0].type()); 2817 EXPECT_EQ(ResourceMsg_ReceivedRedirect::ID, msgs[0][0].type());
2783 CheckSuccessfulRequest(msgs[1], kResponseBody); 2818 CheckSuccessfulRequest(msgs[1], kResponseBody);
2784 2819
2785 second_filter->OnChannelClosing(); 2820 second_filter->OnChannelClosing();
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
2834 int new_render_view_id = 1; 2869 int new_render_view_id = 1;
2835 int new_request_id = 5; 2870 int new_request_id = 5;
2836 ResourceRequest request = CreateResourceRequest( 2871 ResourceRequest request = CreateResourceRequest(
2837 "GET", RESOURCE_TYPE_MAIN_FRAME, GURL("http://example.com/blah")); 2872 "GET", RESOURCE_TYPE_MAIN_FRAME, GURL("http://example.com/blah"));
2838 request.transferred_request_child_id = filter_->child_id(); 2873 request.transferred_request_child_id = filter_->child_id();
2839 request.transferred_request_request_id = request_id; 2874 request.transferred_request_request_id = request_id;
2840 2875
2841 ResourceHostMsg_RequestResource transfer_request_msg( 2876 ResourceHostMsg_RequestResource transfer_request_msg(
2842 new_render_view_id, new_request_id, request); 2877 new_render_view_id, new_request_id, request);
2843 OnMessageReceived(transfer_request_msg, second_filter.get()); 2878 OnMessageReceived(transfer_request_msg, second_filter.get());
2844 base::RunLoop().RunUntilIdle(); 2879 content::RunAllBlockingPoolTasksUntilIdle();
2880 ;
2845 2881
2846 // Transfer the second request. 2882 // Transfer the second request.
2847 int new_second_request_id = 6; 2883 int new_second_request_id = 6;
2848 ResourceRequest second_request = CreateResourceRequest( 2884 ResourceRequest second_request = CreateResourceRequest(
2849 "GET", RESOURCE_TYPE_MAIN_FRAME, GURL("http://example.com/foo")); 2885 "GET", RESOURCE_TYPE_MAIN_FRAME, GURL("http://example.com/foo"));
2850 request.transferred_request_child_id = filter_->child_id(); 2886 request.transferred_request_child_id = filter_->child_id();
2851 request.transferred_request_request_id = second_request_id; 2887 request.transferred_request_request_id = second_request_id;
2852 2888
2853 ResourceHostMsg_RequestResource second_transfer_request_msg( 2889 ResourceHostMsg_RequestResource second_transfer_request_msg(
2854 new_render_view_id, new_second_request_id, second_request); 2890 new_render_view_id, new_second_request_id, second_request);
2855 OnMessageReceived(second_transfer_request_msg, second_filter.get()); 2891 OnMessageReceived(second_transfer_request_msg, second_filter.get());
2856 base::RunLoop().RunUntilIdle(); 2892 content::RunAllBlockingPoolTasksUntilIdle();
2893 ;
2857 2894
2858 // Check generated messages. 2895 // Check generated messages.
2859 ResourceIPCAccumulator::ClassifiedMessages msgs; 2896 ResourceIPCAccumulator::ClassifiedMessages msgs;
2860 accum_.GetClassifiedMessages(&msgs); 2897 accum_.GetClassifiedMessages(&msgs);
2861 2898
2862 ASSERT_EQ(2U, msgs.size()); 2899 ASSERT_EQ(2U, msgs.size());
2863 CheckSuccessfulRequest(msgs[0], kResponseBody); 2900 CheckSuccessfulRequest(msgs[0], kResponseBody);
2864 2901
2865 second_filter->OnChannelClosing(); 2902 second_filter->OnChannelClosing();
2866 } 2903 }
(...skipping 28 matching lines...) Expand all
2895 // Now that we're blocked on the redirect, update the response and unblock by 2932 // 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 2933 // telling the AsyncResourceHandler to follow the redirect. Use a text/plain
2897 // MIME type, which causes MimeTypeResourceHandler to buffer it before the 2934 // MIME type, which causes MimeTypeResourceHandler to buffer it before the
2898 // transfer occurs. 2935 // transfer occurs.
2899 const std::string kResponseBody = "hello world"; 2936 const std::string kResponseBody = "hello world";
2900 SetResponse("HTTP/1.1 200 OK\n" 2937 SetResponse("HTTP/1.1 200 OK\n"
2901 "Content-Type: text/plain\n\n", 2938 "Content-Type: text/plain\n\n",
2902 kResponseBody); 2939 kResponseBody);
2903 ResourceHostMsg_FollowRedirect redirect_msg(request_id); 2940 ResourceHostMsg_FollowRedirect redirect_msg(request_id);
2904 OnMessageReceived(redirect_msg, filter_.get()); 2941 OnMessageReceived(redirect_msg, filter_.get());
2905 base::RunLoop().RunUntilIdle(); 2942 content::RunAllBlockingPoolTasksUntilIdle();
2943 ;
2906 2944
2907 // Flush all the pending requests to get the response through the 2945 // Flush all the pending requests to get the response through the
2908 // MimeTypeResourceHandler. 2946 // MimeTypeResourceHandler.
2909 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} 2947 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {}
2910 base::RunLoop().RunUntilIdle(); 2948 content::RunAllBlockingPoolTasksUntilIdle();
2949 ;
2911 2950
2912 // This second filter is used to emulate a second process. 2951 // This second filter is used to emulate a second process.
2913 scoped_refptr<ForwardingFilter> second_filter = MakeForwardingFilter(); 2952 scoped_refptr<ForwardingFilter> second_filter = MakeForwardingFilter();
2914 2953
2915 int new_render_view_id = 1; 2954 int new_render_view_id = 1;
2916 int new_request_id = 2; 2955 int new_request_id = 2;
2917 2956
2918 ResourceRequest request = CreateResourceRequest( 2957 ResourceRequest request = CreateResourceRequest(
2919 "GET", RESOURCE_TYPE_MAIN_FRAME, GURL("http://other.com/blech")); 2958 "GET", RESOURCE_TYPE_MAIN_FRAME, GURL("http://other.com/blech"));
2920 request.transferred_request_child_id = filter_->child_id(); 2959 request.transferred_request_child_id = filter_->child_id();
2921 request.transferred_request_request_id = request_id; 2960 request.transferred_request_request_id = request_id;
2922 2961
2923 ResourceHostMsg_RequestResource transfer_request_msg( 2962 ResourceHostMsg_RequestResource transfer_request_msg(
2924 new_render_view_id, new_request_id, request); 2963 new_render_view_id, new_request_id, request);
2925 OnMessageReceived(transfer_request_msg, second_filter.get()); 2964 OnMessageReceived(transfer_request_msg, second_filter.get());
2926 base::RunLoop().RunUntilIdle(); 2965 content::RunAllBlockingPoolTasksUntilIdle();
2966 ;
2927 2967
2928 // Check generated messages. 2968 // Check generated messages.
2929 ResourceIPCAccumulator::ClassifiedMessages msgs; 2969 ResourceIPCAccumulator::ClassifiedMessages msgs;
2930 accum_.GetClassifiedMessages(&msgs); 2970 accum_.GetClassifiedMessages(&msgs);
2931 2971
2932 ASSERT_EQ(2U, msgs.size()); 2972 ASSERT_EQ(2U, msgs.size());
2933 EXPECT_EQ(ResourceMsg_ReceivedRedirect::ID, msgs[0][0].type()); 2973 EXPECT_EQ(ResourceMsg_ReceivedRedirect::ID, msgs[0][0].type());
2934 CheckSuccessfulRequest(msgs[1], kResponseBody); 2974 CheckSuccessfulRequest(msgs[1], kResponseBody);
2935 2975
2936 second_filter->OnChannelClosing(); 2976 second_filter->OnChannelClosing();
(...skipping 25 matching lines...) Expand all
2962 { 3002 {
2963 scoped_refptr<ForwardingFilter> first_filter = MakeForwardingFilter(); 3003 scoped_refptr<ForwardingFilter> first_filter = MakeForwardingFilter();
2964 first_child_id = first_filter->child_id(); 3004 first_child_id = first_filter->child_id();
2965 3005
2966 ResourceRequest first_request = CreateResourceRequest( 3006 ResourceRequest first_request = CreateResourceRequest(
2967 "GET", RESOURCE_TYPE_MAIN_FRAME, GURL("http://example.com/blah")); 3007 "GET", RESOURCE_TYPE_MAIN_FRAME, GURL("http://example.com/blah"));
2968 3008
2969 ResourceHostMsg_RequestResource first_request_msg( 3009 ResourceHostMsg_RequestResource first_request_msg(
2970 render_view_id, request_id, first_request); 3010 render_view_id, request_id, first_request);
2971 OnMessageReceived(first_request_msg, first_filter.get()); 3011 OnMessageReceived(first_request_msg, first_filter.get());
2972 base::RunLoop().RunUntilIdle(); 3012 content::RunAllBlockingPoolTasksUntilIdle();
3013 ;
2973 3014
2974 // Now that we're blocked on the redirect, update the response and unblock 3015 // Now that we're blocked on the redirect, update the response and unblock
2975 // by telling the AsyncResourceHandler to follow the redirect. 3016 // by telling the AsyncResourceHandler to follow the redirect.
2976 SetResponse("HTTP/1.1 200 OK\n" 3017 SetResponse("HTTP/1.1 200 OK\n"
2977 "Content-Type: text/html\n\n", 3018 "Content-Type: text/html\n\n",
2978 kResponseBody); 3019 kResponseBody);
2979 ResourceHostMsg_FollowRedirect redirect_msg(request_id); 3020 ResourceHostMsg_FollowRedirect redirect_msg(request_id);
2980 OnMessageReceived(redirect_msg, first_filter.get()); 3021 OnMessageReceived(redirect_msg, first_filter.get());
2981 base::RunLoop().RunUntilIdle(); 3022 content::RunAllBlockingPoolTasksUntilIdle();
3023 ;
2982 3024
2983 // Flush all the pending requests to get the response through the 3025 // Flush all the pending requests to get the response through the
2984 // MimeTypeResourceHandler. 3026 // MimeTypeResourceHandler.
2985 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} 3027 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {}
2986 3028
2987 first_filter->OnChannelClosing(); 3029 first_filter->OnChannelClosing();
2988 } 3030 }
2989 // The first filter is now deleted, as if the child process died. 3031 // The first filter is now deleted, as if the child process died.
2990 3032
2991 // Make sure we don't hold onto the ResourceMessageFilter after it is deleted. 3033 // Make sure we don't hold onto the ResourceMessageFilter after it is deleted.
2992 GlobalRequestID first_global_request_id(first_child_id, request_id); 3034 GlobalRequestID first_global_request_id(first_child_id, request_id);
2993 3035
2994 // This second filter is used to emulate a second process. 3036 // This second filter is used to emulate a second process.
2995 scoped_refptr<ForwardingFilter> second_filter = MakeForwardingFilter(); 3037 scoped_refptr<ForwardingFilter> second_filter = MakeForwardingFilter();
2996 3038
2997 int new_render_view_id = 1; 3039 int new_render_view_id = 1;
2998 int new_request_id = 2; 3040 int new_request_id = 2;
2999 3041
3000 ResourceRequest request = CreateResourceRequest( 3042 ResourceRequest request = CreateResourceRequest(
3001 "GET", RESOURCE_TYPE_MAIN_FRAME, GURL("http://other.com/blech")); 3043 "GET", RESOURCE_TYPE_MAIN_FRAME, GURL("http://other.com/blech"));
3002 request.transferred_request_child_id = first_child_id; 3044 request.transferred_request_child_id = first_child_id;
3003 request.transferred_request_request_id = request_id; 3045 request.transferred_request_request_id = request_id;
3004 3046
3005 // For cleanup. 3047 // For cleanup.
3006 child_ids_.insert(second_filter->child_id()); 3048 child_ids_.insert(second_filter->child_id());
3007 ResourceHostMsg_RequestResource transfer_request_msg( 3049 ResourceHostMsg_RequestResource transfer_request_msg(
3008 new_render_view_id, new_request_id, request); 3050 new_render_view_id, new_request_id, request);
3009 OnMessageReceived(transfer_request_msg, second_filter.get()); 3051 OnMessageReceived(transfer_request_msg, second_filter.get());
3010 base::RunLoop().RunUntilIdle(); 3052 content::RunAllBlockingPoolTasksUntilIdle();
3053 ;
3011 3054
3012 // Check generated messages. 3055 // Check generated messages.
3013 ResourceIPCAccumulator::ClassifiedMessages msgs; 3056 ResourceIPCAccumulator::ClassifiedMessages msgs;
3014 accum_.GetClassifiedMessages(&msgs); 3057 accum_.GetClassifiedMessages(&msgs);
3015 3058
3016 ASSERT_EQ(2U, msgs.size()); 3059 ASSERT_EQ(2U, msgs.size());
3017 EXPECT_EQ(ResourceMsg_ReceivedRedirect::ID, msgs[0][0].type()); 3060 EXPECT_EQ(ResourceMsg_ReceivedRedirect::ID, msgs[0][0].type());
3018 CheckSuccessfulRequest(msgs[1], kResponseBody); 3061 CheckSuccessfulRequest(msgs[1], kResponseBody);
3019 3062
3020 second_filter->OnChannelClosing(); 3063 second_filter->OnChannelClosing();
(...skipping 21 matching lines...) Expand all
3042 3085
3043 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id, 3086 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id,
3044 GURL("http://example.com/blah"), 3087 GURL("http://example.com/blah"),
3045 RESOURCE_TYPE_MAIN_FRAME); 3088 RESOURCE_TYPE_MAIN_FRAME);
3046 3089
3047 // Now that we're blocked on the redirect, simulate hitting another redirect. 3090 // Now that we're blocked on the redirect, simulate hitting another redirect.
3048 SetResponse("HTTP/1.1 302 Found\n" 3091 SetResponse("HTTP/1.1 302 Found\n"
3049 "Location: http://other.com/blerg\n\n"); 3092 "Location: http://other.com/blerg\n\n");
3050 ResourceHostMsg_FollowRedirect redirect_msg(request_id); 3093 ResourceHostMsg_FollowRedirect redirect_msg(request_id);
3051 OnMessageReceived(redirect_msg, filter_.get()); 3094 OnMessageReceived(redirect_msg, filter_.get());
3052 base::RunLoop().RunUntilIdle(); 3095 content::RunAllBlockingPoolTasksUntilIdle();
3096 ;
3053 3097
3054 // Now that we're blocked on the second redirect, update the response and 3098 // Now that we're blocked on the second redirect, update the response and
3055 // unblock by telling the AsyncResourceHandler to follow the redirect. 3099 // unblock by telling the AsyncResourceHandler to follow the redirect.
3056 // Again, use text/plain to force MimeTypeResourceHandler to buffer before 3100 // Again, use text/plain to force MimeTypeResourceHandler to buffer before
3057 // the transfer. 3101 // the transfer.
3058 const std::string kResponseBody = "hello world"; 3102 const std::string kResponseBody = "hello world";
3059 SetResponse("HTTP/1.1 200 OK\n" 3103 SetResponse("HTTP/1.1 200 OK\n"
3060 "Content-Type: text/plain\n\n", 3104 "Content-Type: text/plain\n\n",
3061 kResponseBody); 3105 kResponseBody);
3062 ResourceHostMsg_FollowRedirect redirect_msg2(request_id); 3106 ResourceHostMsg_FollowRedirect redirect_msg2(request_id);
3063 OnMessageReceived(redirect_msg2, filter_.get()); 3107 OnMessageReceived(redirect_msg2, filter_.get());
3064 base::RunLoop().RunUntilIdle(); 3108 content::RunAllBlockingPoolTasksUntilIdle();
3109 ;
3065 3110
3066 // Flush all the pending requests to get the response through the 3111 // Flush all the pending requests to get the response through the
3067 // MimeTypeResourceHandler. 3112 // MimeTypeResourceHandler.
3068 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} 3113 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {}
3069 base::RunLoop().RunUntilIdle(); 3114 content::RunAllBlockingPoolTasksUntilIdle();
3115 ;
3070 3116
3071 // This second filter is used to emulate a second process. 3117 // This second filter is used to emulate a second process.
3072 scoped_refptr<ForwardingFilter> second_filter = MakeForwardingFilter(); 3118 scoped_refptr<ForwardingFilter> second_filter = MakeForwardingFilter();
3073 3119
3074 int new_render_view_id = 1; 3120 int new_render_view_id = 1;
3075 int new_request_id = 2; 3121 int new_request_id = 2;
3076 3122
3077 ResourceRequest request = CreateResourceRequest( 3123 ResourceRequest request = CreateResourceRequest(
3078 "GET", RESOURCE_TYPE_MAIN_FRAME, GURL("http://other.com/blech")); 3124 "GET", RESOURCE_TYPE_MAIN_FRAME, GURL("http://other.com/blech"));
3079 request.transferred_request_child_id = filter_->child_id(); 3125 request.transferred_request_child_id = filter_->child_id();
3080 request.transferred_request_request_id = request_id; 3126 request.transferred_request_request_id = request_id;
3081 3127
3082 // For cleanup. 3128 // For cleanup.
3083 child_ids_.insert(second_filter->child_id()); 3129 child_ids_.insert(second_filter->child_id());
3084 ResourceHostMsg_RequestResource transfer_request_msg( 3130 ResourceHostMsg_RequestResource transfer_request_msg(
3085 new_render_view_id, new_request_id, request); 3131 new_render_view_id, new_request_id, request);
3086 OnMessageReceived(transfer_request_msg, second_filter.get()); 3132 OnMessageReceived(transfer_request_msg, second_filter.get());
3087 3133
3088 // Verify that we update the ResourceRequestInfo. 3134 // Verify that we update the ResourceRequestInfo.
3089 GlobalRequestID global_request_id(second_filter->child_id(), new_request_id); 3135 GlobalRequestID global_request_id(second_filter->child_id(), new_request_id);
3090 ResourceRequestInfoImpl* info = ResourceRequestInfoImpl::ForRequest( 3136 ResourceRequestInfoImpl* info = ResourceRequestInfoImpl::ForRequest(
3091 host_.GetURLRequest(global_request_id)); 3137 host_.GetURLRequest(global_request_id));
3092 EXPECT_EQ(second_filter->child_id(), info->GetChildID()); 3138 EXPECT_EQ(second_filter->child_id(), info->GetChildID());
3093 EXPECT_EQ(new_render_view_id, info->GetRouteID()); 3139 EXPECT_EQ(new_render_view_id, info->GetRouteID());
3094 EXPECT_EQ(new_request_id, info->GetRequestID()); 3140 EXPECT_EQ(new_request_id, info->GetRequestID());
3095 EXPECT_EQ(second_filter.get(), info->requester_info()->filter()); 3141 EXPECT_EQ(second_filter.get(), info->requester_info()->filter());
3096 3142
3097 // Let request complete. 3143 // Let request complete.
3098 base::RunLoop().RunUntilIdle(); 3144 content::RunAllBlockingPoolTasksUntilIdle();
3145 ;
3099 3146
3100 // Check generated messages. 3147 // Check generated messages.
3101 ResourceIPCAccumulator::ClassifiedMessages msgs; 3148 ResourceIPCAccumulator::ClassifiedMessages msgs;
3102 accum_.GetClassifiedMessages(&msgs); 3149 accum_.GetClassifiedMessages(&msgs);
3103 3150
3104 ASSERT_EQ(2U, msgs.size()); 3151 ASSERT_EQ(2U, msgs.size());
3105 EXPECT_EQ(ResourceMsg_ReceivedRedirect::ID, msgs[0][0].type()); 3152 EXPECT_EQ(ResourceMsg_ReceivedRedirect::ID, msgs[0][0].type());
3106 CheckSuccessfulRequest(msgs[1], kResponseBody); 3153 CheckSuccessfulRequest(msgs[1], kResponseBody);
3107 3154
3108 second_filter->OnChannelClosing(); 3155 second_filter->OnChannelClosing();
(...skipping 12 matching lines...) Expand all
3121 } 3168 }
3122 3169
3123 TEST_F(ResourceDispatcherHostTest, DataReceivedACKs) { 3170 TEST_F(ResourceDispatcherHostTest, DataReceivedACKs) {
3124 EXPECT_EQ(0, host_.pending_requests()); 3171 EXPECT_EQ(0, host_.pending_requests());
3125 3172
3126 SendDataReceivedACKs(true); 3173 SendDataReceivedACKs(true);
3127 3174
3128 HandleScheme("big-job"); 3175 HandleScheme("big-job");
3129 MakeTestRequest(0, 1, GURL("big-job:0123456789,1000000")); 3176 MakeTestRequest(0, 1, GURL("big-job:0123456789,1000000"));
3130 3177
3131 base::RunLoop().RunUntilIdle(); 3178 content::RunAllBlockingPoolTasksUntilIdle();
3132 3179
3133 // Sort all the messages we saw by request. 3180 // Sort all the messages we saw by request.
3134 ResourceIPCAccumulator::ClassifiedMessages msgs; 3181 ResourceIPCAccumulator::ClassifiedMessages msgs;
3135 accum_.GetClassifiedMessages(&msgs); 3182 accum_.GetClassifiedMessages(&msgs);
3136 3183
3137 size_t size = msgs[0].size(); 3184 size_t size = msgs[0].size();
3138 3185
3139 EXPECT_EQ(ResourceMsg_ReceivedResponse::ID, msgs[0][0].type()); 3186 EXPECT_EQ(ResourceMsg_ReceivedResponse::ID, msgs[0][0].type());
3140 EXPECT_EQ(ResourceMsg_SetDataBuffer::ID, msgs[0][1].type()); 3187 EXPECT_EQ(ResourceMsg_SetDataBuffer::ID, msgs[0][1].type());
3141 for (size_t i = 2; i < size - 1; ++i) 3188 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), 3247 std::string(response_data.begin(), response_data.begin() + data_length),
3201 net::ERR_ABORTED); 3248 net::ERR_ABORTED);
3202 } 3249 }
3203 3250
3204 TEST_F(ResourceDispatcherHostTest, DelayedDataReceivedACKs) { 3251 TEST_F(ResourceDispatcherHostTest, DelayedDataReceivedACKs) {
3205 EXPECT_EQ(0, host_.pending_requests()); 3252 EXPECT_EQ(0, host_.pending_requests());
3206 3253
3207 HandleScheme("big-job"); 3254 HandleScheme("big-job");
3208 MakeTestRequest(0, 1, GURL("big-job:0123456789,1000000")); 3255 MakeTestRequest(0, 1, GURL("big-job:0123456789,1000000"));
3209 3256
3210 base::RunLoop().RunUntilIdle(); 3257 content::RunAllBlockingPoolTasksUntilIdle();
3211 3258
3212 // Sort all the messages we saw by request. 3259 // Sort all the messages we saw by request.
3213 ResourceIPCAccumulator::ClassifiedMessages msgs; 3260 ResourceIPCAccumulator::ClassifiedMessages msgs;
3214 accum_.GetClassifiedMessages(&msgs); 3261 accum_.GetClassifiedMessages(&msgs);
3215 3262
3216 // We expect 1x ReceivedResponse, 1x SetDataBuffer, Nx ReceivedData messages. 3263 // We expect 1x ReceivedResponse, 1x SetDataBuffer, Nx ReceivedData messages.
3217 EXPECT_EQ(ResourceMsg_ReceivedResponse::ID, msgs[0][0].type()); 3264 EXPECT_EQ(ResourceMsg_ReceivedResponse::ID, msgs[0][0].type());
3218 EXPECT_EQ(ResourceMsg_SetDataBuffer::ID, msgs[0][1].type()); 3265 EXPECT_EQ(ResourceMsg_SetDataBuffer::ID, msgs[0][1].type());
3219 for (size_t i = 2; i < msgs[0].size(); ++i) 3266 for (size_t i = 2; i < msgs[0].size(); ++i)
3220 EXPECT_EQ(ResourceMsg_DataReceived::ID, msgs[0][i].type()); 3267 EXPECT_EQ(ResourceMsg_DataReceived::ID, msgs[0][i].type());
(...skipping 13 matching lines...) Expand all
3234 complete = true; 3281 complete = true;
3235 break; 3282 break;
3236 } 3283 }
3237 3284
3238 EXPECT_EQ(ResourceMsg_DataReceived::ID, msgs[0][i].type()); 3285 EXPECT_EQ(ResourceMsg_DataReceived::ID, msgs[0][i].type());
3239 3286
3240 ResourceHostMsg_DataReceived_ACK msg(1); 3287 ResourceHostMsg_DataReceived_ACK msg(1);
3241 OnMessageReceived(msg, filter_.get()); 3288 OnMessageReceived(msg, filter_.get());
3242 } 3289 }
3243 3290
3244 base::RunLoop().RunUntilIdle(); 3291 content::RunAllBlockingPoolTasksUntilIdle();
3245 3292
3246 msgs.clear(); 3293 msgs.clear();
3247 accum_.GetClassifiedMessages(&msgs); 3294 accum_.GetClassifiedMessages(&msgs);
3248 } 3295 }
3249 } 3296 }
3250 3297
3251 // Flakyness of this test might indicate memory corruption issues with 3298 // Flakyness of this test might indicate memory corruption issues with
3252 // for example the ResourceBuffer of AsyncResourceHandler. 3299 // for example the ResourceBuffer of AsyncResourceHandler.
3253 TEST_F(ResourceDispatcherHostTest, DataReceivedUnexpectedACKs) { 3300 TEST_F(ResourceDispatcherHostTest, DataReceivedUnexpectedACKs) {
3254 EXPECT_EQ(0, host_.pending_requests()); 3301 EXPECT_EQ(0, host_.pending_requests());
3255 3302
3256 HandleScheme("big-job"); 3303 HandleScheme("big-job");
3257 MakeTestRequest(0, 1, GURL("big-job:0123456789,1000000")); 3304 MakeTestRequest(0, 1, GURL("big-job:0123456789,1000000"));
3258 3305
3259 base::RunLoop().RunUntilIdle(); 3306 content::RunAllBlockingPoolTasksUntilIdle();
3260 3307
3261 // Sort all the messages we saw by request. 3308 // Sort all the messages we saw by request.
3262 ResourceIPCAccumulator::ClassifiedMessages msgs; 3309 ResourceIPCAccumulator::ClassifiedMessages msgs;
3263 accum_.GetClassifiedMessages(&msgs); 3310 accum_.GetClassifiedMessages(&msgs);
3264 3311
3265 // We expect 1x ReceivedResponse, 1x SetDataBuffer, Nx ReceivedData messages. 3312 // We expect 1x ReceivedResponse, 1x SetDataBuffer, Nx ReceivedData messages.
3266 EXPECT_EQ(ResourceMsg_ReceivedResponse::ID, msgs[0][0].type()); 3313 EXPECT_EQ(ResourceMsg_ReceivedResponse::ID, msgs[0][0].type());
3267 EXPECT_EQ(ResourceMsg_SetDataBuffer::ID, msgs[0][1].type()); 3314 EXPECT_EQ(ResourceMsg_SetDataBuffer::ID, msgs[0][1].type());
3268 for (size_t i = 2; i < msgs[0].size(); ++i) 3315 for (size_t i = 2; i < msgs[0].size(); ++i)
3269 EXPECT_EQ(ResourceMsg_DataReceived::ID, msgs[0][i].type()); 3316 EXPECT_EQ(ResourceMsg_DataReceived::ID, msgs[0][i].type());
(...skipping 18 matching lines...) Expand all
3288 complete = true; 3335 complete = true;
3289 break; 3336 break;
3290 } 3337 }
3291 3338
3292 EXPECT_EQ(ResourceMsg_DataReceived::ID, msgs[0][i].type()); 3339 EXPECT_EQ(ResourceMsg_DataReceived::ID, msgs[0][i].type());
3293 3340
3294 ResourceHostMsg_DataReceived_ACK msg(1); 3341 ResourceHostMsg_DataReceived_ACK msg(1);
3295 OnMessageReceived(msg, filter_.get()); 3342 OnMessageReceived(msg, filter_.get());
3296 } 3343 }
3297 3344
3298 base::RunLoop().RunUntilIdle(); 3345 content::RunAllBlockingPoolTasksUntilIdle();
3299 3346
3300 msgs.clear(); 3347 msgs.clear();
3301 accum_.GetClassifiedMessages(&msgs); 3348 accum_.GetClassifiedMessages(&msgs);
3302 } 3349 }
3303 } 3350 }
3304 3351
3305 // Tests the dispatcher host's temporary file management. 3352 // Tests the dispatcher host's temporary file management.
3306 TEST_F(ResourceDispatcherHostTest, RegisterDownloadedTempFile) { 3353 TEST_F(ResourceDispatcherHostTest, RegisterDownloadedTempFile) {
3307 const int kRequestID = 1; 3354 const int kRequestID = 1;
3308 3355
(...skipping 23 matching lines...) Expand all
3332 3379
3333 // Still readable because there is another reference to the file. (The child 3380 // Still readable because there is another reference to the file. (The child
3334 // may take additional blob references.) 3381 // may take additional blob references.)
3335 EXPECT_TRUE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile( 3382 EXPECT_TRUE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile(
3336 filter_->child_id(), file_path)); 3383 filter_->child_id(), file_path));
3337 3384
3338 // Release extra references and wait for the file to be deleted. (This relies 3385 // 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 3386 // on the delete happening on the FILE thread which is mapped to main thread
3340 // in this test.) 3387 // in this test.)
3341 deletable_file = nullptr; 3388 deletable_file = nullptr;
3342 base::RunLoop().RunUntilIdle(); 3389 content::RunAllBlockingPoolTasksUntilIdle();
3390 ;
3343 3391
3344 // The file is no longer readable to the child and has been deleted. 3392 // The file is no longer readable to the child and has been deleted.
3345 EXPECT_FALSE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile( 3393 EXPECT_FALSE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile(
3346 filter_->child_id(), file_path)); 3394 filter_->child_id(), file_path));
3347 EXPECT_FALSE(base::PathExists(file_path)); 3395 EXPECT_FALSE(base::PathExists(file_path));
3348 } 3396 }
3349 3397
3350 // Tests the dispatcher host's temporary file management in the mojo-enabled 3398 // Tests the dispatcher host's temporary file management in the mojo-enabled
3351 // loading. 3399 // loading.
3352 TEST_F(ResourceDispatcherHostTest, RegisterDownloadedTempFileWithMojo) { 3400 TEST_F(ResourceDispatcherHostTest, RegisterDownloadedTempFileWithMojo) {
(...skipping 18 matching lines...) Expand all
3371 mojom::DownloadedTempFilePtr downloaded_file_ptr = 3419 mojom::DownloadedTempFilePtr downloaded_file_ptr =
3372 DownloadedTempFileImpl::Create(filter_->child_id(), kRequestID); 3420 DownloadedTempFileImpl::Create(filter_->child_id(), kRequestID);
3373 host_.RegisterDownloadedTempFile(filter_->child_id(), kRequestID, file_path); 3421 host_.RegisterDownloadedTempFile(filter_->child_id(), kRequestID, file_path);
3374 3422
3375 // Should be readable now. 3423 // Should be readable now.
3376 EXPECT_TRUE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile( 3424 EXPECT_TRUE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile(
3377 filter_->child_id(), file_path)); 3425 filter_->child_id(), file_path));
3378 3426
3379 // The child releases from the request. 3427 // The child releases from the request.
3380 downloaded_file_ptr = nullptr; 3428 downloaded_file_ptr = nullptr;
3381 base::RunLoop().RunUntilIdle(); 3429 content::RunAllBlockingPoolTasksUntilIdle();
3430 ;
3382 3431
3383 // Still readable because there is another reference to the file. (The child 3432 // Still readable because there is another reference to the file. (The child
3384 // may take additional blob references.) 3433 // may take additional blob references.)
3385 EXPECT_TRUE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile( 3434 EXPECT_TRUE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile(
3386 filter_->child_id(), file_path)); 3435 filter_->child_id(), file_path));
3387 3436
3388 // Release extra references and wait for the file to be deleted. (This relies 3437 // 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 3438 // on the delete happening on the FILE thread which is mapped to main thread
3390 // in this test.) 3439 // in this test.)
3391 deletable_file = nullptr; 3440 deletable_file = nullptr;
3392 base::RunLoop().RunUntilIdle(); 3441 content::RunAllBlockingPoolTasksUntilIdle();
3442 ;
3393 3443
3394 // The file is no longer readable to the child and has been deleted. 3444 // The file is no longer readable to the child and has been deleted.
3395 EXPECT_FALSE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile( 3445 EXPECT_FALSE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile(
3396 filter_->child_id(), file_path)); 3446 filter_->child_id(), file_path));
3397 EXPECT_FALSE(base::PathExists(file_path)); 3447 EXPECT_FALSE(base::PathExists(file_path));
3398 } 3448 }
3399 3449
3400 // Tests that temporary files held on behalf of child processes are released 3450 // Tests that temporary files held on behalf of child processes are released
3401 // when the child process dies. 3451 // when the child process dies.
3402 TEST_F(ResourceDispatcherHostTest, ReleaseTemporiesOnProcessExit) { 3452 TEST_F(ResourceDispatcherHostTest, ReleaseTemporiesOnProcessExit) {
(...skipping 10 matching lines...) Expand all
3413 // Register it for a resource request. 3463 // Register it for a resource request.
3414 host_.RegisterDownloadedTempFile(filter_->child_id(), kRequestID, file_path); 3464 host_.RegisterDownloadedTempFile(filter_->child_id(), kRequestID, file_path);
3415 deletable_file = NULL; 3465 deletable_file = NULL;
3416 3466
3417 // Should be readable now. 3467 // Should be readable now.
3418 EXPECT_TRUE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile( 3468 EXPECT_TRUE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile(
3419 filter_->child_id(), file_path)); 3469 filter_->child_id(), file_path));
3420 3470
3421 // Let the process die. 3471 // Let the process die.
3422 filter_->OnChannelClosing(); 3472 filter_->OnChannelClosing();
3423 base::RunLoop().RunUntilIdle(); 3473 content::RunAllBlockingPoolTasksUntilIdle();
3474 ;
3424 3475
3425 // The file is no longer readable to the child and has been deleted. 3476 // The file is no longer readable to the child and has been deleted.
3426 EXPECT_FALSE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile( 3477 EXPECT_FALSE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile(
3427 filter_->child_id(), file_path)); 3478 filter_->child_id(), file_path));
3428 EXPECT_FALSE(base::PathExists(file_path)); 3479 EXPECT_FALSE(base::PathExists(file_path));
3429 } 3480 }
3430 3481
3431 TEST_F(ResourceDispatcherHostTest, DownloadToFile) { 3482 TEST_F(ResourceDispatcherHostTest, DownloadToFile) {
3432 // Make a request which downloads to file. 3483 // Make a request which downloads to file.
3433 ResourceRequest request = CreateResourceRequest( 3484 ResourceRequest request = CreateResourceRequest(
3434 "GET", RESOURCE_TYPE_SUB_RESOURCE, net::URLRequestTestJob::test_url_1()); 3485 "GET", RESOURCE_TYPE_SUB_RESOURCE, net::URLRequestTestJob::test_url_1());
3435 request.download_to_file = true; 3486 request.download_to_file = true;
3436 ResourceHostMsg_RequestResource request_msg(0, 1, request); 3487 ResourceHostMsg_RequestResource request_msg(0, 1, request);
3437 OnMessageReceived(request_msg, filter_.get()); 3488 OnMessageReceived(request_msg, filter_.get());
3438 3489
3439 // Running the message loop until idle does not work because 3490 // Running the message loop until idle does not work because
3440 // RedirectToFileResourceHandler posts things to base::WorkerPool. Instead, 3491 // RedirectToFileResourceHandler posts things to base::WorkerPool. Instead,
3441 // wait for the ResourceMsg_RequestComplete to go out. Then run the event loop 3492 // wait for the ResourceMsg_RequestComplete to go out. Then run the event loop
3442 // until idle so the loader is gone. 3493 // until idle so the loader is gone.
3443 WaitForRequestComplete(); 3494 WaitForRequestComplete();
3444 base::RunLoop().RunUntilIdle(); 3495 content::RunAllBlockingPoolTasksUntilIdle();
3496 ;
3445 EXPECT_EQ(0, host_.pending_requests()); 3497 EXPECT_EQ(0, host_.pending_requests());
3446 3498
3447 ResourceIPCAccumulator::ClassifiedMessages msgs; 3499 ResourceIPCAccumulator::ClassifiedMessages msgs;
3448 accum_.GetClassifiedMessages(&msgs); 3500 accum_.GetClassifiedMessages(&msgs);
3449 3501
3450 ASSERT_EQ(1U, msgs.size()); 3502 ASSERT_EQ(1U, msgs.size());
3451 const std::vector<IPC::Message>& messages = msgs[0]; 3503 const std::vector<IPC::Message>& messages = msgs[0];
3452 3504
3453 // The request should contain the following messages: 3505 // The request should contain the following messages:
3454 // ReceivedResponse (indicates headers received and filename) 3506 // ReceivedResponse (indicates headers received and filename)
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
3487 3539
3488 // When the renderer releases the file, it should be deleted. Again, 3540 // When the renderer releases the file, it should be deleted. Again,
3489 // RunUntilIdle doesn't work because base::WorkerPool is involved. 3541 // RunUntilIdle doesn't work because base::WorkerPool is involved.
3490 ShareableFileReleaseWaiter waiter(response_head.download_file_path); 3542 ShareableFileReleaseWaiter waiter(response_head.download_file_path);
3491 ResourceHostMsg_ReleaseDownloadedFile release_msg(1); 3543 ResourceHostMsg_ReleaseDownloadedFile release_msg(1);
3492 OnMessageReceived(release_msg, filter_.get()); 3544 OnMessageReceived(release_msg, filter_.get());
3493 waiter.Wait(); 3545 waiter.Wait();
3494 // The release callback runs before the delete is scheduled, so pump the 3546 // 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 3547 // 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.) 3548 // the FILE thread which is mapped to main thread in this test.)
3497 base::RunLoop().RunUntilIdle(); 3549 content::RunAllBlockingPoolTasksUntilIdle();
3550 ;
3498 3551
3499 EXPECT_FALSE(base::PathExists(response_head.download_file_path)); 3552 EXPECT_FALSE(base::PathExists(response_head.download_file_path));
3500 EXPECT_FALSE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile( 3553 EXPECT_FALSE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile(
3501 filter_->child_id(), response_head.download_file_path)); 3554 filter_->child_id(), response_head.download_file_path));
3502 } 3555 }
3503 3556
3504 WebContents* WebContentsBinder(WebContents* rv) { return rv; } 3557 WebContents* WebContentsBinder(WebContents* rv) { return rv; }
3505 3558
3506 // Tests GetLoadInfoForAllRoutes when there are 3 requests from the same 3559 // Tests GetLoadInfoForAllRoutes when there are 3 requests from the same
3507 // RenderView. The second one is farthest along. 3560 // 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); 3716 EXPECT_EQ(0u, (*load_info_map)[wc2].upload_position);
3664 EXPECT_EQ(0u, (*load_info_map)[wc2].upload_size); 3717 EXPECT_EQ(0u, (*load_info_map)[wc2].upload_size);
3665 } 3718 }
3666 3719
3667 // Confirm that resource response started notifications are correctly 3720 // Confirm that resource response started notifications are correctly
3668 // transmitted to the WebContents. 3721 // transmitted to the WebContents.
3669 TEST_F(ResourceDispatcherHostTest, TransferResponseStarted) { 3722 TEST_F(ResourceDispatcherHostTest, TransferResponseStarted) {
3670 int initial_count = web_contents_observer_->resource_response_start_count(); 3723 int initial_count = web_contents_observer_->resource_response_start_count();
3671 3724
3672 MakeWebContentsAssociatedTestRequest(1, net::URLRequestTestJob::test_url_1()); 3725 MakeWebContentsAssociatedTestRequest(1, net::URLRequestTestJob::test_url_1());
3673 base::RunLoop().RunUntilIdle(); 3726 content::RunAllBlockingPoolTasksUntilIdle();
3727 ;
3674 3728
3675 EXPECT_EQ(initial_count + 1, 3729 EXPECT_EQ(initial_count + 1,
3676 web_contents_observer_->resource_response_start_count()); 3730 web_contents_observer_->resource_response_start_count());
3677 } 3731 }
3678 3732
3679 // Confirm that request redirected notifications are correctly 3733 // Confirm that request redirected notifications are correctly
3680 // transmitted to the WebContents. 3734 // transmitted to the WebContents.
3681 TEST_F(ResourceDispatcherHostTest, TransferRequestRedirected) { 3735 TEST_F(ResourceDispatcherHostTest, TransferRequestRedirected) {
3682 int initial_count = web_contents_observer_->resource_request_redirect_count(); 3736 int initial_count = web_contents_observer_->resource_request_redirect_count();
3683 3737
3684 MakeWebContentsAssociatedTestRequest( 3738 MakeWebContentsAssociatedTestRequest(
3685 1, net::URLRequestTestJob::test_url_redirect_to_url_2()); 3739 1, net::URLRequestTestJob::test_url_redirect_to_url_2());
3686 base::RunLoop().RunUntilIdle(); 3740 content::RunAllBlockingPoolTasksUntilIdle();
3741 ;
3687 3742
3688 EXPECT_EQ(initial_count + 1, 3743 EXPECT_EQ(initial_count + 1,
3689 web_contents_observer_->resource_request_redirect_count()); 3744 web_contents_observer_->resource_request_redirect_count());
3690 } 3745 }
3691 3746
3692 // Confirm that DidChangePriority messages are respected. 3747 // Confirm that DidChangePriority messages are respected.
3693 TEST_F(ResourceDispatcherHostTest, DidChangePriority) { 3748 TEST_F(ResourceDispatcherHostTest, DidChangePriority) {
3694 // ResourceScheduler only throttles http and https requests. 3749 // ResourceScheduler only throttles http and https requests.
3695 HandleScheme("http"); 3750 HandleScheme("http");
3696 3751
(...skipping 12 matching lines...) Expand all
3709 MakeTestRequestWithPriority(0, 3, net::IDLE); 3764 MakeTestRequestWithPriority(0, 3, net::IDLE);
3710 3765
3711 KickOffRequest(); 3766 KickOffRequest();
3712 3767
3713 EXPECT_EQ(2, job_factory_->url_request_jobs_created_count()); 3768 EXPECT_EQ(2, job_factory_->url_request_jobs_created_count());
3714 3769
3715 // Increase the priority of the second idle priority request. It was 3770 // Increase the priority of the second idle priority request. It was
3716 // scheduled later, so it is not currently running. 3771 // scheduled later, so it is not currently running.
3717 ResourceHostMsg_DidChangePriority priority_msg(3, net::MAXIMUM_PRIORITY, 0); 3772 ResourceHostMsg_DidChangePriority priority_msg(3, net::MAXIMUM_PRIORITY, 0);
3718 OnMessageReceived(priority_msg, filter_.get()); 3773 OnMessageReceived(priority_msg, filter_.get());
3719 base::RunLoop().RunUntilIdle(); 3774 content::RunAllBlockingPoolTasksUntilIdle();
3775 ;
3720 3776
3721 EXPECT_EQ(3, job_factory_->url_request_jobs_created_count()); 3777 EXPECT_EQ(3, job_factory_->url_request_jobs_created_count());
3722 3778
3723 // Cleanup. 3779 // Cleanup.
3724 host_.OnRenderViewHostDeleted(filter_->child_id(), // child_id 3780 host_.OnRenderViewHostDeleted(filter_->child_id(), // child_id
3725 0); // route_id 3781 0); // route_id
3726 } 3782 }
3727 3783
3728 // Confirm that resource response started notifications for downloads are not 3784 // Confirm that resource response started notifications for downloads are not
3729 // transmitted to the WebContents. 3785 // transmitted to the WebContents.
3730 TEST_F(ResourceDispatcherHostTest, TransferResponseStartedDownload) { 3786 TEST_F(ResourceDispatcherHostTest, TransferResponseStartedDownload) {
3731 int initial_count(web_contents_observer_->resource_response_start_count()); 3787 int initial_count(web_contents_observer_->resource_response_start_count());
3732 3788
3733 MakeWebContentsAssociatedDownloadRequest( 3789 MakeWebContentsAssociatedDownloadRequest(
3734 1, net::URLRequestTestJob::test_url_1()); 3790 1, net::URLRequestTestJob::test_url_1());
3735 base::RunLoop().RunUntilIdle(); 3791 content::RunAllBlockingPoolTasksUntilIdle();
3792 ;
3736 EXPECT_EQ(initial_count, 3793 EXPECT_EQ(initial_count,
3737 web_contents_observer_->resource_response_start_count()); 3794 web_contents_observer_->resource_response_start_count());
3738 } 3795 }
3739 3796
3740 // Confirm that request redirected notifications for downloads are not 3797 // Confirm that request redirected notifications for downloads are not
3741 // transmitted to the WebContents. 3798 // transmitted to the WebContents.
3742 TEST_F(ResourceDispatcherHostTest, TransferRequestRedirectedDownload) { 3799 TEST_F(ResourceDispatcherHostTest, TransferRequestRedirectedDownload) {
3743 int initial_count(web_contents_observer_->resource_request_redirect_count()); 3800 int initial_count(web_contents_observer_->resource_request_redirect_count());
3744 3801
3745 MakeWebContentsAssociatedDownloadRequest( 3802 MakeWebContentsAssociatedDownloadRequest(
3746 1, net::URLRequestTestJob::test_url_redirect_to_url_2()); 3803 1, net::URLRequestTestJob::test_url_redirect_to_url_2());
3747 base::RunLoop().RunUntilIdle(); 3804 content::RunAllBlockingPoolTasksUntilIdle();
3805 ;
3748 EXPECT_EQ(initial_count, 3806 EXPECT_EQ(initial_count,
3749 web_contents_observer_->resource_request_redirect_count()); 3807 web_contents_observer_->resource_request_redirect_count());
3750 } 3808 }
3751 3809
3752 // Tests that a ResourceThrottle that needs to process the response before any 3810 // Tests that a ResourceThrottle that needs to process the response before any
3753 // part of the body is read can do so. 3811 // part of the body is read can do so.
3754 TEST_F(ResourceDispatcherHostTest, ThrottleMustProcessResponseBeforeRead) { 3812 TEST_F(ResourceDispatcherHostTest, ThrottleMustProcessResponseBeforeRead) {
3755 // Ensure all jobs will check that no read operation is called. 3813 // Ensure all jobs will check that no read operation is called.
3756 job_factory_->SetMustNotReadJobGeneration(true); 3814 job_factory_->SetMustNotReadJobGeneration(true);
3757 HandleScheme("http"); 3815 HandleScheme("http");
(...skipping 13 matching lines...) Expand all
3771 "Content-Type: text/plain; charset=utf-8\n\n"); 3829 "Content-Type: text/plain; charset=utf-8\n\n");
3772 std::string response_data("p { text-align: center; }"); 3830 std::string response_data("p { text-align: center; }");
3773 SetResponse(raw_headers, response_data); 3831 SetResponse(raw_headers, response_data);
3774 3832
3775 MakeTestRequestWithResourceType(filter_.get(), filter_->child_id(), 1, 3833 MakeTestRequestWithResourceType(filter_.get(), filter_->child_id(), 1,
3776 GURL("http://example.com/blah"), 3834 GURL("http://example.com/blah"),
3777 RESOURCE_TYPE_STYLESHEET); 3835 RESOURCE_TYPE_STYLESHEET);
3778 3836
3779 while (net::URLRequestTestJob::ProcessOnePendingMessage()) { 3837 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {
3780 } 3838 }
3781 base::RunLoop().RunUntilIdle(); 3839 content::RunAllBlockingPoolTasksUntilIdle();
3840 ;
3782 } 3841 }
3783 3842
3784 namespace { 3843 namespace {
3785 3844
3786 void StoreSyncLoadResult(bool* called, 3845 void StoreSyncLoadResult(bool* called,
3787 bool* was_null, 3846 bool* was_null,
3788 SyncLoadResult* result_out, 3847 SyncLoadResult* result_out,
3789 const SyncLoadResult* result) { 3848 const SyncLoadResult* result) {
3790 *called = true; 3849 *called = true;
3791 *was_null = !result; 3850 *was_null = !result;
3792 3851
3793 if (result) 3852 if (result)
3794 *result_out = *result; 3853 *result_out = *result;
3795 } 3854 }
3796 3855
3797 } // namespace 3856 } // namespace
3798 3857
3799 TEST_F(ResourceDispatcherHostTest, SyncLoadWithMojoSuccess) { 3858 TEST_F(ResourceDispatcherHostTest, SyncLoadWithMojoSuccess) {
3800 ResourceRequest request = CreateResourceRequest( 3859 ResourceRequest request = CreateResourceRequest(
3801 "GET", RESOURCE_TYPE_XHR, net::URLRequestTestJob::test_url_1()); 3860 "GET", RESOURCE_TYPE_XHR, net::URLRequestTestJob::test_url_1());
3802 request.priority = net::MAXIMUM_PRIORITY; 3861 request.priority = net::MAXIMUM_PRIORITY;
3803 3862
3804 bool called = false; 3863 bool called = false;
3805 bool was_null = false; 3864 bool was_null = false;
3806 SyncLoadResult result; 3865 SyncLoadResult result;
3807 host_.OnSyncLoadWithMojo( 3866 host_.OnSyncLoadWithMojo(
3808 GetResourceRequesterInfo(filter_.get()), 0, 1, request, 3867 GetResourceRequesterInfo(filter_.get()), 0, 1, request,
3809 base::Bind(&StoreSyncLoadResult, &called, &was_null, &result)); 3868 base::Bind(&StoreSyncLoadResult, &called, &was_null, &result));
3810 base::RunLoop().RunUntilIdle(); 3869 content::RunAllBlockingPoolTasksUntilIdle();
3870 ;
3811 EXPECT_TRUE(called); 3871 EXPECT_TRUE(called);
3812 EXPECT_FALSE(was_null); 3872 EXPECT_FALSE(was_null);
3813 EXPECT_EQ(net::OK, result.error_code); 3873 EXPECT_EQ(net::OK, result.error_code);
3814 } 3874 }
3815 3875
3816 TEST_F(ResourceDispatcherHostTest, SyncLoadWithMojoError) { 3876 TEST_F(ResourceDispatcherHostTest, SyncLoadWithMojoError) {
3817 ResourceRequest request = CreateResourceRequest( 3877 ResourceRequest request = CreateResourceRequest(
3818 "GET", RESOURCE_TYPE_XHR, net::URLRequestTestJob::test_url_error()); 3878 "GET", RESOURCE_TYPE_XHR, net::URLRequestTestJob::test_url_error());
3819 request.priority = net::MAXIMUM_PRIORITY; 3879 request.priority = net::MAXIMUM_PRIORITY;
3820 3880
3821 bool called = false; 3881 bool called = false;
3822 bool was_null = false; 3882 bool was_null = false;
3823 SyncLoadResult result; 3883 SyncLoadResult result;
3824 host_.OnSyncLoadWithMojo( 3884 host_.OnSyncLoadWithMojo(
3825 GetResourceRequesterInfo(filter_.get()), 0, 1, request, 3885 GetResourceRequesterInfo(filter_.get()), 0, 1, request,
3826 base::Bind(&StoreSyncLoadResult, &called, &was_null, &result)); 3886 base::Bind(&StoreSyncLoadResult, &called, &was_null, &result));
3827 base::RunLoop().RunUntilIdle(); 3887 content::RunAllBlockingPoolTasksUntilIdle();
3888 ;
3828 EXPECT_TRUE(called); 3889 EXPECT_TRUE(called);
3829 EXPECT_FALSE(was_null); 3890 EXPECT_FALSE(was_null);
3830 EXPECT_EQ(net::ERR_INVALID_URL, result.error_code); 3891 EXPECT_EQ(net::ERR_INVALID_URL, result.error_code);
3831 } 3892 }
3832 3893
3833 TEST_F(ResourceDispatcherHostTest, SyncLoadWithMojoCancel) { 3894 TEST_F(ResourceDispatcherHostTest, SyncLoadWithMojoCancel) {
3834 ResourceRequest request = CreateResourceRequest( 3895 ResourceRequest request = CreateResourceRequest(
3835 "GET", RESOURCE_TYPE_XHR, net::URLRequestTestJob::test_url_error()); 3896 "GET", RESOURCE_TYPE_XHR, net::URLRequestTestJob::test_url_error());
3836 request.priority = net::MAXIMUM_PRIORITY; 3897 request.priority = net::MAXIMUM_PRIORITY;
3837 3898
3838 bool called = false; 3899 bool called = false;
3839 bool was_null = false; 3900 bool was_null = false;
3840 SyncLoadResult result; 3901 SyncLoadResult result;
3841 host_.OnSyncLoadWithMojo( 3902 host_.OnSyncLoadWithMojo(
3842 GetResourceRequesterInfo(filter_.get()), 0, 1, request, 3903 GetResourceRequesterInfo(filter_.get()), 0, 1, request,
3843 base::Bind(&StoreSyncLoadResult, &called, &was_null, &result)); 3904 base::Bind(&StoreSyncLoadResult, &called, &was_null, &result));
3844 host_.CancelRequestsForProcess(filter_->child_id()); 3905 host_.CancelRequestsForProcess(filter_->child_id());
3845 base::RunLoop().RunUntilIdle(); 3906 content::RunAllBlockingPoolTasksUntilIdle();
3907 ;
3846 EXPECT_TRUE(called); 3908 EXPECT_TRUE(called);
3847 EXPECT_TRUE(was_null); 3909 EXPECT_TRUE(was_null);
3848 } 3910 }
3849 3911
3850 // A URLRequestTestJob that sets a test certificate on the |ssl_info| 3912 // A URLRequestTestJob that sets a test certificate on the |ssl_info|
3851 // field of the response. 3913 // field of the response.
3852 class TestHTTPSURLRequestJob : public net::URLRequestTestJob { 3914 class TestHTTPSURLRequestJob : public net::URLRequestTestJob {
3853 public: 3915 public:
3854 TestHTTPSURLRequestJob(net::URLRequest* request, 3916 TestHTTPSURLRequestJob(net::URLRequest* request,
3855 net::NetworkDelegate* network_delegate, 3917 net::NetworkDelegate* network_delegate,
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
3924 return nullptr; 3986 return nullptr;
3925 } 3987 }
3926 3988
3927 net::URLRequestJob* TestURLRequestJobFactory::MaybeInterceptResponse( 3989 net::URLRequestJob* TestURLRequestJobFactory::MaybeInterceptResponse(
3928 net::URLRequest* request, 3990 net::URLRequest* request,
3929 net::NetworkDelegate* network_delegate) const { 3991 net::NetworkDelegate* network_delegate) const {
3930 return nullptr; 3992 return nullptr;
3931 } 3993 }
3932 3994
3933 } // namespace content 3995 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698