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

Unified Diff: content/browser/loader/resource_dispatcher_host_unittest.cc

Issue 1542743002: [RDHI] Refactored blocked_loaders_map_ to key by render frame route id (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: cleanup Created 4 years, 12 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/loader/resource_dispatcher_host_unittest.cc
diff --git a/content/browser/loader/resource_dispatcher_host_unittest.cc b/content/browser/loader/resource_dispatcher_host_unittest.cc
index f5a97aa7ab531defd2964c1d8b2b07d598399692..5562c55a2ef44e954aa0c116a3fbbb22d93a2706 100644
--- a/content/browser/loader/resource_dispatcher_host_unittest.cc
+++ b/content/browser/loader/resource_dispatcher_host_unittest.cc
@@ -942,6 +942,12 @@ class ResourceDispatcherHostTest : public testing::Test,
int request_id,
const GURL& url);
+ void MakeTestRequestWithRenderFrame(int render_view_id,
+ int render_frame_id,
+ int request_id,
+ const GURL& url,
+ ResourceType type);
+
// Generates a request using the given filter and resource type.
void MakeTestRequestWithResourceType(ResourceMessageFilter* filter,
int render_view_id,
@@ -959,6 +965,11 @@ class ResourceDispatcherHostTest : public testing::Test,
int request_id,
net::RequestPriority priority);
+ void MakeTestRequestWithPriorityAndRenderFrame(int render_view_id,
+ int render_frame_id,
+ int request_id,
+ net::RequestPriority priority);
+
void MakeWebContentsAssociatedDownloadRequest(int request_id,
const GURL& url);
@@ -1061,6 +1072,19 @@ void ResourceDispatcherHostTest::MakeTestRequest(int render_view_id,
url, RESOURCE_TYPE_SUB_RESOURCE);
}
+void ResourceDispatcherHostTest::MakeTestRequestWithRenderFrame(
+ int render_view_id,
+ int render_frame_id,
+ int request_id,
+ const GURL& url,
+ ResourceType type) {
+ ResourceHostMsg_Request request = CreateResourceRequest("GET", type, url);
+ request.render_frame_id = render_frame_id;
+ ResourceHostMsg_RequestResource msg(render_view_id, request_id, request);
+ host_.OnMessageReceived(msg, filter_.get());
+ KickOffRequest();
+}
+
void ResourceDispatcherHostTest::MakeTestRequestWithResourceType(
ResourceMessageFilter* filter,
int render_view_id,
@@ -1098,8 +1122,18 @@ void ResourceDispatcherHostTest::MakeTestRequestWithPriority(
int render_view_id,
int request_id,
net::RequestPriority priority) {
+ MakeTestRequestWithPriorityAndRenderFrame(render_view_id, -1, request_id,
+ priority);
+}
+
+void ResourceDispatcherHostTest::MakeTestRequestWithPriorityAndRenderFrame(
+ int render_view_id,
+ int render_frame_id,
+ int request_id,
+ net::RequestPriority priority) {
ResourceHostMsg_Request request = CreateResourceRequest(
"GET", RESOURCE_TYPE_SUB_RESOURCE, GURL("http://example.com/priority"));
+ request.render_frame_id = render_frame_id;
request.priority = priority;
ResourceHostMsg_RequestResource msg(render_view_id, request_id, request);
host_.OnMessageReceived(msg, filter_.get());
@@ -1749,7 +1783,7 @@ TEST_F(ResourceDispatcherHostTest, TestProcessCancel) {
// Tests whether the correct requests get canceled when a RenderViewHost is
// deleted.
-TEST_F(ResourceDispatcherHostTest, CancelRequestsOnRenderViewHostDeleted) {
+TEST_F(ResourceDispatcherHostTest, CancelRequestsOnRenderFrameHostDeleted) {
// Requests all hang once started. This prevents requests from being
// destroyed due to completion.
job_factory_->SetHangAfterStartJobGeneration(true);
@@ -1761,29 +1795,32 @@ TEST_F(ResourceDispatcherHostTest, CancelRequestsOnRenderViewHostDeleted) {
// One RenderView issues a high priority request and a low priority one. Both
// should be started.
- MakeTestRequestWithPriority(0, 1, net::HIGHEST);
- MakeTestRequestWithPriority(0, 2, net::LOWEST);
+ MakeTestRequestWithPriorityAndRenderFrame(0, 10, 1, net::HIGHEST);
+ MakeTestRequestWithPriorityAndRenderFrame(0, 11, 2, net::LOWEST);
KickOffRequest();
EXPECT_EQ(2, network_delegate_.created_requests());
EXPECT_EQ(0, network_delegate_.canceled_requests());
// The same RenderView issues two more low priority requests. The
// ResourceScheduler shouldn't let them start immediately.
- MakeTestRequestWithPriority(0, 3, net::LOWEST);
- MakeTestRequestWithPriority(0, 4, net::LOWEST);
+ MakeTestRequestWithPriorityAndRenderFrame(0, 10, 3, net::LOWEST);
+ MakeTestRequestWithPriorityAndRenderFrame(0, 11, 4, net::LOWEST);
KickOffRequest();
EXPECT_EQ(2, network_delegate_.created_requests());
EXPECT_EQ(0, network_delegate_.canceled_requests());
// Another RenderView in the same process as the old one issues a request,
// which is then started.
- MakeTestRequestWithPriority(1, 5, net::LOWEST);
+ MakeTestRequestWithPriorityAndRenderFrame(1, 12, 5, net::LOWEST);
KickOffRequest();
EXPECT_EQ(3, network_delegate_.created_requests());
EXPECT_EQ(0, network_delegate_.canceled_requests());
- // The first RenderView is destroyed. All 4 of its requests should be
- // cancelled, and none of the two deferred requests should be started.
+ // The first two RenderFrameHosts are destroyed. All 4 of their requests
+ // should be cancelled, and none of the two deferred requests should be
+ // started.
+ host_.OnRenderFrameHostDeleted(GlobalFrameRoutingId(filter_->child_id(), 10));
+ host_.OnRenderFrameHostDeleted(GlobalFrameRoutingId(filter_->child_id(), 11));
host_.OnRenderViewHostDeleted(filter_->child_id(), 0);
base::RunLoop().RunUntilIdle();
EXPECT_EQ(3, network_delegate_.created_requests());
@@ -1843,16 +1880,22 @@ TEST_F(ResourceDispatcherHostTest, TestProcessCancelDetachedTimesOut) {
// Tests blocking and resuming requests.
TEST_F(ResourceDispatcherHostTest, TestBlockingResumingRequests) {
- host_.BlockRequestsForRoute(filter_->child_id(), 1);
- host_.BlockRequestsForRoute(filter_->child_id(), 2);
- host_.BlockRequestsForRoute(filter_->child_id(), 3);
-
- MakeTestRequest(0, 1, net::URLRequestTestJob::test_url_1());
- MakeTestRequest(1, 2, net::URLRequestTestJob::test_url_2());
- MakeTestRequest(0, 3, net::URLRequestTestJob::test_url_3());
- MakeTestRequest(1, 4, net::URLRequestTestJob::test_url_1());
- MakeTestRequest(2, 5, net::URLRequestTestJob::test_url_2());
- MakeTestRequest(3, 6, net::URLRequestTestJob::test_url_3());
+ host_.BlockRequestsForFrame(GlobalFrameRoutingId(filter_->child_id(), 11));
+ host_.BlockRequestsForFrame(GlobalFrameRoutingId(filter_->child_id(), 12));
+ host_.BlockRequestsForFrame(GlobalFrameRoutingId(filter_->child_id(), 13));
+
+ MakeTestRequestWithRenderFrame(0, 10, 1, net::URLRequestTestJob::test_url_1(),
+ RESOURCE_TYPE_SUB_RESOURCE);
+ MakeTestRequestWithRenderFrame(1, 11, 2, net::URLRequestTestJob::test_url_2(),
+ RESOURCE_TYPE_SUB_RESOURCE);
+ MakeTestRequestWithRenderFrame(0, 10, 3, net::URLRequestTestJob::test_url_3(),
+ RESOURCE_TYPE_SUB_RESOURCE);
+ MakeTestRequestWithRenderFrame(1, 11, 4, net::URLRequestTestJob::test_url_1(),
+ RESOURCE_TYPE_SUB_RESOURCE);
+ MakeTestRequestWithRenderFrame(2, 12, 5, net::URLRequestTestJob::test_url_2(),
+ RESOURCE_TYPE_SUB_RESOURCE);
+ MakeTestRequestWithRenderFrame(3, 13, 6, net::URLRequestTestJob::test_url_3(),
+ RESOURCE_TYPE_SUB_RESOURCE);
// Flush all the pending requests
while (net::URLRequestTestJob::ProcessOnePendingMessage()) {}
@@ -1861,14 +1904,15 @@ TEST_F(ResourceDispatcherHostTest, TestBlockingResumingRequests) {
ResourceIPCAccumulator::ClassifiedMessages msgs;
accum_.GetClassifiedMessages(&msgs);
- // All requests but the 2 for the RVH 0 should have been blocked.
+ // All requests but the 2 for the RFH 0 should have been blocked.
ASSERT_EQ(2U, msgs.size());
CheckSuccessfulRequest(msgs[0], net::URLRequestTestJob::test_data_1());
CheckSuccessfulRequest(msgs[1], net::URLRequestTestJob::test_data_3());
- // Resume requests for RVH 1 and flush pending requests.
- host_.ResumeBlockedRequestsForRoute(filter_->child_id(), 1);
+ // Resume requests for RFH 11 and flush pending requests.
+ host_.ResumeBlockedRequestsForFrame(
+ GlobalFrameRoutingId(filter_->child_id(), 11));
KickOffRequest();
while (net::URLRequestTestJob::ProcessOnePendingMessage()) {}
@@ -1878,17 +1922,20 @@ TEST_F(ResourceDispatcherHostTest, TestBlockingResumingRequests) {
CheckSuccessfulRequest(msgs[0], net::URLRequestTestJob::test_data_2());
CheckSuccessfulRequest(msgs[1], net::URLRequestTestJob::test_data_1());
- // Test that new requests are not blocked for RVH 1.
- MakeTestRequest(1, 7, net::URLRequestTestJob::test_url_1());
+ // Test that new requests are not blocked for RFH 11.
+ MakeTestRequestWithRenderFrame(1, 11, 7, net::URLRequestTestJob::test_url_1(),
+ RESOURCE_TYPE_SUB_RESOURCE);
while (net::URLRequestTestJob::ProcessOnePendingMessage()) {}
msgs.clear();
accum_.GetClassifiedMessages(&msgs);
ASSERT_EQ(1U, msgs.size());
CheckSuccessfulRequest(msgs[0], net::URLRequestTestJob::test_data_1());
- // Now resumes requests for all RVH (2 and 3).
- host_.ResumeBlockedRequestsForRoute(filter_->child_id(), 2);
- host_.ResumeBlockedRequestsForRoute(filter_->child_id(), 3);
+ // Now resumes requests for all RFH (12 and 13).
+ host_.ResumeBlockedRequestsForFrame(
+ GlobalFrameRoutingId(filter_->child_id(), 12));
+ host_.ResumeBlockedRequestsForFrame(
+ GlobalFrameRoutingId(filter_->child_id(), 13));
KickOffRequest();
while (net::URLRequestTestJob::ProcessOnePendingMessage()) {}
@@ -1901,16 +1948,20 @@ TEST_F(ResourceDispatcherHostTest, TestBlockingResumingRequests) {
// Tests blocking and canceling requests.
TEST_F(ResourceDispatcherHostTest, TestBlockingCancelingRequests) {
- host_.BlockRequestsForRoute(filter_->child_id(), 1);
-
- MakeTestRequest(0, 1, net::URLRequestTestJob::test_url_1());
- MakeTestRequest(1, 2, net::URLRequestTestJob::test_url_2());
- MakeTestRequest(0, 3, net::URLRequestTestJob::test_url_3());
- MakeTestRequest(1, 4, net::URLRequestTestJob::test_url_1());
+ host_.BlockRequestsForFrame(GlobalFrameRoutingId(filter_->child_id(), 11));
+
+ MakeTestRequestWithRenderFrame(0, 10, 1, net::URLRequestTestJob::test_url_1(),
+ RESOURCE_TYPE_SUB_RESOURCE);
+ MakeTestRequestWithRenderFrame(1, 11, 2, net::URLRequestTestJob::test_url_2(),
+ RESOURCE_TYPE_SUB_RESOURCE);
+ MakeTestRequestWithRenderFrame(0, 10, 3, net::URLRequestTestJob::test_url_3(),
+ RESOURCE_TYPE_SUB_RESOURCE);
+ MakeTestRequestWithRenderFrame(1, 11, 4, net::URLRequestTestJob::test_url_1(),
+ RESOURCE_TYPE_SUB_RESOURCE);
// Blocked detachable resources should not delay cancellation.
- MakeTestRequestWithResourceType(filter_.get(), 1, 5,
- net::URLRequestTestJob::test_url_4(),
- RESOURCE_TYPE_PREFETCH); // detachable type
+ //
+ MakeTestRequestWithRenderFrame(1, 11, 5, net::URLRequestTestJob::test_url_4(),
+ RESOURCE_TYPE_PREFETCH); // detachable type
// Flush all the pending requests.
while (net::URLRequestTestJob::ProcessOnePendingMessage()) {}
@@ -1919,14 +1970,15 @@ TEST_F(ResourceDispatcherHostTest, TestBlockingCancelingRequests) {
ResourceIPCAccumulator::ClassifiedMessages msgs;
accum_.GetClassifiedMessages(&msgs);
- // The 2 requests for the RVH 0 should have been processed.
+ // The 2 requests for the RFH 10 should have been processed.
ASSERT_EQ(2U, msgs.size());
CheckSuccessfulRequest(msgs[0], net::URLRequestTestJob::test_data_1());
CheckSuccessfulRequest(msgs[1], net::URLRequestTestJob::test_data_3());
- // Cancel requests for RVH 1.
- host_.CancelBlockedRequestsForRoute(filter_->child_id(), 1);
+ // Cancel requests for RFH 11.
+ host_.CancelBlockedRequestsForFrame(
+ GlobalFrameRoutingId(filter_->child_id(), 11));
KickOffRequest();
while (net::URLRequestTestJob::ProcessOnePendingMessage()) {}
@@ -1940,7 +1992,8 @@ TEST_F(ResourceDispatcherHostTest, TestBlockedRequestsProcessDies) {
// This second filter is used to emulate a second process.
scoped_refptr<ForwardingFilter> second_filter = MakeForwardingFilter();
- host_.BlockRequestsForRoute(second_filter->child_id(), 0);
+ host_.BlockRequestsForFrame(
+ GlobalFrameRoutingId(second_filter->child_id(), 0));
MakeTestRequestWithResourceType(filter_.get(), 0, 1,
net::URLRequestTestJob::test_url_1(),
@@ -1986,9 +2039,10 @@ TEST_F(ResourceDispatcherHostTest, TestBlockedRequestsDontLeak) {
// This second filter is used to emulate a second process.
scoped_refptr<ForwardingFilter> second_filter = MakeForwardingFilter();
- host_.BlockRequestsForRoute(filter_->child_id(), 1);
- host_.BlockRequestsForRoute(filter_->child_id(), 2);
- host_.BlockRequestsForRoute(second_filter->child_id(), 1);
+ host_.BlockRequestsForFrame(GlobalFrameRoutingId(filter_->child_id(), 1));
+ host_.BlockRequestsForFrame(GlobalFrameRoutingId(filter_->child_id(), 2));
+ host_.BlockRequestsForFrame(
+ GlobalFrameRoutingId(second_filter->child_id(), 1));
MakeTestRequestWithResourceType(filter_.get(), 0, 1,
net::URLRequestTestJob::test_url_1(),

Powered by Google App Engine
This is Rietveld 408576698