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

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

Issue 1285863003: ResourceScheduler: remove dependency on ResourceRequestInfo and request_id (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@lkgr
Patch Set: Rename resource_throttle variables back to throttle. Created 5 years, 4 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 <vector> 5 #include <vector>
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
(...skipping 928 matching lines...) Expand 10 before | Expand all | Expand 10 after
939 939
940 // Generates a request using the given filter and resource type. 940 // Generates a request using the given filter and resource type.
941 void MakeTestRequestWithResourceType(ResourceMessageFilter* filter, 941 void MakeTestRequestWithResourceType(ResourceMessageFilter* filter,
942 int render_view_id, 942 int render_view_id,
943 int request_id, 943 int request_id,
944 const GURL& url, 944 const GURL& url,
945 ResourceType type); 945 ResourceType type);
946 946
947 void MakeWebContentsAssociatedTestRequest(int request_id, const GURL& url); 947 void MakeWebContentsAssociatedTestRequest(int request_id, const GURL& url);
948 948
949 // Generates a request with the given priority.
950 void MakeTestRequestWithPriority(int render_view_id,
951 int request_id,
952 net::RequestPriority priority);
953
949 void CancelRequest(int request_id); 954 void CancelRequest(int request_id);
950 void RendererCancelRequest(int request_id) { 955 void RendererCancelRequest(int request_id) {
951 ResourceMessageFilter* old_filter = SetFilter(filter_.get()); 956 ResourceMessageFilter* old_filter = SetFilter(filter_.get());
952 host_.OnCancelRequest(request_id); 957 host_.OnCancelRequest(request_id);
953 SetFilter(old_filter); 958 SetFilter(old_filter);
954 } 959 }
955 960
956 void CompleteStartRequest(int request_id); 961 void CompleteStartRequest(int request_id);
957 void CompleteStartRequest(ResourceMessageFilter* filter, int request_id); 962 void CompleteStartRequest(ResourceMessageFilter* filter, int request_id);
958 963
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
1065 ResourceHostMsg_Request request = 1070 ResourceHostMsg_Request request =
1066 CreateResourceRequest("GET", RESOURCE_TYPE_SUB_RESOURCE, url); 1071 CreateResourceRequest("GET", RESOURCE_TYPE_SUB_RESOURCE, url);
1067 request.origin_pid = web_contents_->GetRenderProcessHost()->GetID(); 1072 request.origin_pid = web_contents_->GetRenderProcessHost()->GetID();
1068 request.render_frame_id = web_contents_->GetMainFrame()->GetRoutingID(); 1073 request.render_frame_id = web_contents_->GetMainFrame()->GetRoutingID();
1069 ResourceHostMsg_RequestResource msg(web_contents_->GetRoutingID(), request_id, 1074 ResourceHostMsg_RequestResource msg(web_contents_->GetRoutingID(), request_id,
1070 request); 1075 request);
1071 host_.OnMessageReceived(msg, web_contents_filter_.get()); 1076 host_.OnMessageReceived(msg, web_contents_filter_.get());
1072 KickOffRequest(); 1077 KickOffRequest();
1073 } 1078 }
1074 1079
1080 void ResourceDispatcherHostTest::MakeTestRequestWithPriority(
1081 int render_view_id,
1082 int request_id,
1083 net::RequestPriority priority) {
1084 ResourceHostMsg_Request request = CreateResourceRequest(
1085 "GET", RESOURCE_TYPE_SUB_RESOURCE, GURL("http://example.com/priority"));
1086 request.priority = priority;
1087 ResourceHostMsg_RequestResource msg(render_view_id, request_id, request);
1088 host_.OnMessageReceived(msg, filter_.get());
1089 }
1090
1075 void ResourceDispatcherHostTest::CancelRequest(int request_id) { 1091 void ResourceDispatcherHostTest::CancelRequest(int request_id) {
1076 host_.CancelRequest(filter_->child_id(), request_id); 1092 host_.CancelRequest(filter_->child_id(), request_id);
1077 } 1093 }
1078 1094
1079 void ResourceDispatcherHostTest::CompleteStartRequest(int request_id) { 1095 void ResourceDispatcherHostTest::CompleteStartRequest(int request_id) {
1080 CompleteStartRequest(filter_.get(), request_id); 1096 CompleteStartRequest(filter_.get(), request_id);
1081 } 1097 }
1082 1098
1083 void ResourceDispatcherHostTest::CompleteStartRequest( 1099 void ResourceDispatcherHostTest::CompleteStartRequest(
1084 ResourceMessageFilter* filter, 1100 ResourceMessageFilter* filter,
(...skipping 2237 matching lines...) Expand 10 before | Expand all | Expand 10 after
3322 int initial_count = web_contents_observer_->resource_request_redirect_count(); 3338 int initial_count = web_contents_observer_->resource_request_redirect_count();
3323 3339
3324 MakeWebContentsAssociatedTestRequest( 3340 MakeWebContentsAssociatedTestRequest(
3325 1, net::URLRequestTestJob::test_url_redirect_to_url_2()); 3341 1, net::URLRequestTestJob::test_url_redirect_to_url_2());
3326 base::MessageLoop::current()->RunUntilIdle(); 3342 base::MessageLoop::current()->RunUntilIdle();
3327 3343
3328 EXPECT_EQ(initial_count + 1, 3344 EXPECT_EQ(initial_count + 1,
3329 web_contents_observer_->resource_request_redirect_count()); 3345 web_contents_observer_->resource_request_redirect_count());
3330 } 3346 }
3331 3347
3348 // Confirm that DidChangePriority messages are respected.
3349 TEST_F(ResourceDispatcherHostTest, DidChangePriority) {
3350 // ResourceScheduler only throttles http and https requests.
3351 HandleScheme("http");
3352
3353 // Needed to enable scheduling for this child.
3354 host_.OnRenderViewHostCreated(filter_->child_id(), // child_id
3355 0, // route_id
3356 true, // is_visible
3357 false); // is_audible
3358
3359 // Prevent any of these requests from completing.
3360 job_factory_->SetDelayedCompleteJobGeneration(true);
3361 SetResponse("HTTP/1.1 200 OK\n\n", "<title>Dummy body</title>");
3362
3363 // Only one idle priority request will run while a high-priority request
3364 // exists.
3365 MakeTestRequestWithPriority(0, 1, net::HIGHEST);
3366 MakeTestRequestWithPriority(0, 2, net::IDLE);
3367 MakeTestRequestWithPriority(0, 3, net::IDLE);
3368
3369 KickOffRequest();
3370
3371 EXPECT_EQ(2, job_factory_->url_request_jobs_created_count());
3372
3373 // Increase the priority of the second idle priority request. It was
3374 // scheduled later, so it is not currently running.
3375 ResourceHostMsg_DidChangePriority priority_msg(3, net::MAXIMUM_PRIORITY, 0);
3376 host_.OnMessageReceived(priority_msg, filter_.get());
3377 base::MessageLoop::current()->RunUntilIdle();
3378
3379 EXPECT_EQ(3, job_factory_->url_request_jobs_created_count());
3380
3381 // Cleanup.
3382 host_.OnRenderViewHostDeleted(filter_->child_id(), // child_id
3383 0); // route_id
3384 }
3385
3332 net::URLRequestJob* TestURLRequestJobFactory::MaybeCreateJobWithProtocolHandler( 3386 net::URLRequestJob* TestURLRequestJobFactory::MaybeCreateJobWithProtocolHandler(
3333 const std::string& scheme, 3387 const std::string& scheme,
3334 net::URLRequest* request, 3388 net::URLRequest* request,
3335 net::NetworkDelegate* network_delegate) const { 3389 net::NetworkDelegate* network_delegate) const {
3336 url_request_jobs_created_count_++; 3390 url_request_jobs_created_count_++;
3337 if (test_fixture_->wait_for_request_create_loop_) 3391 if (test_fixture_->wait_for_request_create_loop_)
3338 test_fixture_->wait_for_request_create_loop_->Quit(); 3392 test_fixture_->wait_for_request_create_loop_->Quit();
3339 if (test_fixture_->loader_test_request_info_) { 3393 if (test_fixture_->loader_test_request_info_) {
3340 DCHECK_EQ(test_fixture_->loader_test_request_info_->url, request->url()); 3394 DCHECK_EQ(test_fixture_->loader_test_request_info_->url, request->url());
3341 scoped_ptr<LoadInfoTestRequestInfo> info = 3395 scoped_ptr<LoadInfoTestRequestInfo> info =
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
3383 return nullptr; 3437 return nullptr;
3384 } 3438 }
3385 3439
3386 net::URLRequestJob* TestURLRequestJobFactory::MaybeInterceptResponse( 3440 net::URLRequestJob* TestURLRequestJobFactory::MaybeInterceptResponse(
3387 net::URLRequest* request, 3441 net::URLRequest* request,
3388 net::NetworkDelegate* network_delegate) const { 3442 net::NetworkDelegate* network_delegate) const {
3389 return nullptr; 3443 return nullptr;
3390 } 3444 }
3391 3445
3392 } // namespace content 3446 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698