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

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

Issue 425653002: content: ResourceType cleanup. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: REBASE Created 6 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 | Annotate | Revision Log
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/file_util.h" 9 #include "base/file_util.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 case ResourceMsg_DataDownloaded::ID: 118 case ResourceMsg_DataDownloaded::ID:
119 case ResourceMsg_RequestComplete::ID: { 119 case ResourceMsg_RequestComplete::ID: {
120 bool result = PickleIterator(msg).ReadInt(&request_id); 120 bool result = PickleIterator(msg).ReadInt(&request_id);
121 DCHECK(result); 121 DCHECK(result);
122 break; 122 break;
123 } 123 }
124 } 124 }
125 return request_id; 125 return request_id;
126 } 126 }
127 127
128 static ResourceHostMsg_Request CreateResourceRequest( 128 static ResourceHostMsg_Request CreateResourceRequest(const char* method,
129 const char* method, 129 ResourceType type,
130 ResourceType::Type type, 130 const GURL& url) {
131 const GURL& url) {
132 ResourceHostMsg_Request request; 131 ResourceHostMsg_Request request;
133 request.method = std::string(method); 132 request.method = std::string(method);
134 request.url = url; 133 request.url = url;
135 request.first_party_for_cookies = url; // bypass third-party cookie blocking 134 request.first_party_for_cookies = url; // bypass third-party cookie blocking
136 request.referrer_policy = blink::WebReferrerPolicyDefault; 135 request.referrer_policy = blink::WebReferrerPolicyDefault;
137 request.load_flags = 0; 136 request.load_flags = 0;
138 request.origin_pid = 0; 137 request.origin_pid = 0;
139 request.resource_type = type; 138 request.resource_type = type;
140 request.request_context = 0; 139 request.request_context = 0;
141 request.appcache_host_id = kAppCacheNoHostId; 140 request.appcache_host_id = kAppCacheNoHostId;
(...skipping 513 matching lines...) Expand 10 before | Expand all | Expand 10 after
655 void set_create_two_throttles(bool create_two_throttles) { 654 void set_create_two_throttles(bool create_two_throttles) {
656 create_two_throttles_ = create_two_throttles; 655 create_two_throttles_ = create_two_throttles;
657 } 656 }
658 657
659 // ResourceDispatcherHostDelegate implementation: 658 // ResourceDispatcherHostDelegate implementation:
660 659
661 virtual void RequestBeginning( 660 virtual void RequestBeginning(
662 net::URLRequest* request, 661 net::URLRequest* request,
663 ResourceContext* resource_context, 662 ResourceContext* resource_context,
664 AppCacheService* appcache_service, 663 AppCacheService* appcache_service,
665 ResourceType::Type resource_type, 664 ResourceType resource_type,
666 int child_id, 665 int child_id,
667 int route_id, 666 int route_id,
668 ScopedVector<ResourceThrottle>* throttles) OVERRIDE { 667 ScopedVector<ResourceThrottle>* throttles) OVERRIDE {
669 if (user_data_) { 668 if (user_data_) {
670 const void* key = user_data_.get(); 669 const void* key = user_data_.get();
671 request->SetUserData(key, user_data_.release()); 670 request->SetUserData(key, user_data_.release());
672 } 671 }
673 672
674 if (flags_ != NONE) { 673 if (flags_ != NONE) {
675 throttles->push_back(new GenericResourceThrottle( 674 throttles->push_back(new GenericResourceThrottle(
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
791 } 790 }
792 791
793 // Creates a request using the current test object as the filter and 792 // Creates a request using the current test object as the filter and
794 // SubResource as the resource type. 793 // SubResource as the resource type.
795 void MakeTestRequest(int render_view_id, 794 void MakeTestRequest(int render_view_id,
796 int request_id, 795 int request_id,
797 const GURL& url); 796 const GURL& url);
798 797
799 // Generates a request using the given filter and resource type. 798 // Generates a request using the given filter and resource type.
800 void MakeTestRequestWithResourceType(ResourceMessageFilter* filter, 799 void MakeTestRequestWithResourceType(ResourceMessageFilter* filter,
801 int render_view_id, int request_id, 800 int render_view_id,
801 int request_id,
802 const GURL& url, 802 const GURL& url,
803 ResourceType::Type type); 803 ResourceType type);
804 804
805 void CancelRequest(int request_id); 805 void CancelRequest(int request_id);
806 void RendererCancelRequest(int request_id) { 806 void RendererCancelRequest(int request_id) {
807 ResourceMessageFilter* old_filter = SetFilter(filter_.get()); 807 ResourceMessageFilter* old_filter = SetFilter(filter_.get());
808 host_.OnCancelRequest(request_id); 808 host_.OnCancelRequest(request_id);
809 SetFilter(old_filter); 809 SetFilter(old_filter);
810 } 810 }
811 811
812 void CompleteStartRequest(int request_id); 812 void CompleteStartRequest(int request_id);
813 void CompleteStartRequest(ResourceMessageFilter* filter, int request_id); 813 void CompleteStartRequest(ResourceMessageFilter* filter, int request_id);
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
885 net::URLRequest::ProtocolFactory* old_factory_; 885 net::URLRequest::ProtocolFactory* old_factory_;
886 bool send_data_received_acks_; 886 bool send_data_received_acks_;
887 std::set<int> child_ids_; 887 std::set<int> child_ids_;
888 scoped_ptr<base::RunLoop> wait_for_request_complete_loop_; 888 scoped_ptr<base::RunLoop> wait_for_request_complete_loop_;
889 }; 889 };
890 890
891 void ResourceDispatcherHostTest::MakeTestRequest(int render_view_id, 891 void ResourceDispatcherHostTest::MakeTestRequest(int render_view_id,
892 int request_id, 892 int request_id,
893 const GURL& url) { 893 const GURL& url) {
894 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id, 894 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id,
895 url, ResourceType::SUB_RESOURCE); 895 url, RESOURCE_TYPE_SUB_RESOURCE);
896 } 896 }
897 897
898 void ResourceDispatcherHostTest::MakeTestRequestWithResourceType( 898 void ResourceDispatcherHostTest::MakeTestRequestWithResourceType(
899 ResourceMessageFilter* filter, 899 ResourceMessageFilter* filter,
900 int render_view_id, 900 int render_view_id,
901 int request_id, 901 int request_id,
902 const GURL& url, 902 const GURL& url,
903 ResourceType::Type type) { 903 ResourceType type) {
904 ResourceHostMsg_Request request = 904 ResourceHostMsg_Request request =
905 CreateResourceRequest("GET", type, url); 905 CreateResourceRequest("GET", type, url);
906 ResourceHostMsg_RequestResource msg(render_view_id, request_id, request); 906 ResourceHostMsg_RequestResource msg(render_view_id, request_id, request);
907 host_.OnMessageReceived(msg, filter); 907 host_.OnMessageReceived(msg, filter);
908 KickOffRequest(); 908 KickOffRequest();
909 } 909 }
910 910
911 void ResourceDispatcherHostTest::CancelRequest(int request_id) { 911 void ResourceDispatcherHostTest::CancelRequest(int request_id) {
912 host_.CancelRequest(filter_->child_id(), request_id); 912 host_.CancelRequest(filter_->child_id(), request_id);
913 } 913 }
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
1032 CheckRequestCompleteErrorCode(messages[failure_index], expected_error); 1032 CheckRequestCompleteErrorCode(messages[failure_index], expected_error);
1033 } 1033 }
1034 1034
1035 // Tests whether many messages get dispatched properly. 1035 // Tests whether many messages get dispatched properly.
1036 TEST_F(ResourceDispatcherHostTest, TestMany) { 1036 TEST_F(ResourceDispatcherHostTest, TestMany) {
1037 MakeTestRequest(0, 1, net::URLRequestTestJob::test_url_1()); 1037 MakeTestRequest(0, 1, net::URLRequestTestJob::test_url_1());
1038 MakeTestRequest(0, 2, net::URLRequestTestJob::test_url_2()); 1038 MakeTestRequest(0, 2, net::URLRequestTestJob::test_url_2());
1039 MakeTestRequest(0, 3, net::URLRequestTestJob::test_url_3()); 1039 MakeTestRequest(0, 3, net::URLRequestTestJob::test_url_3());
1040 MakeTestRequestWithResourceType(filter_.get(), 0, 4, 1040 MakeTestRequestWithResourceType(filter_.get(), 0, 4,
1041 net::URLRequestTestJob::test_url_4(), 1041 net::URLRequestTestJob::test_url_4(),
1042 ResourceType::PREFETCH); // detachable type 1042 RESOURCE_TYPE_PREFETCH); // detachable type
1043 MakeTestRequest(0, 5, net::URLRequestTestJob::test_url_redirect_to_url_2()); 1043 MakeTestRequest(0, 5, net::URLRequestTestJob::test_url_redirect_to_url_2());
1044 1044
1045 // Finish the redirection 1045 // Finish the redirection
1046 ResourceHostMsg_FollowRedirect redirect_msg(5); 1046 ResourceHostMsg_FollowRedirect redirect_msg(5);
1047 host_.OnMessageReceived(redirect_msg, filter_.get()); 1047 host_.OnMessageReceived(redirect_msg, filter_.get());
1048 base::MessageLoop::current()->RunUntilIdle(); 1048 base::MessageLoop::current()->RunUntilIdle();
1049 1049
1050 // flush all the pending requests 1050 // flush all the pending requests
1051 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} 1051 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {}
1052 1052
(...skipping 13 matching lines...) Expand all
1066 1066
1067 // Tests whether messages get canceled properly. We issue four requests, 1067 // Tests whether messages get canceled properly. We issue four requests,
1068 // cancel two of them, and make sure that each sent the proper notifications. 1068 // cancel two of them, and make sure that each sent the proper notifications.
1069 TEST_F(ResourceDispatcherHostTest, Cancel) { 1069 TEST_F(ResourceDispatcherHostTest, Cancel) {
1070 MakeTestRequest(0, 1, net::URLRequestTestJob::test_url_1()); 1070 MakeTestRequest(0, 1, net::URLRequestTestJob::test_url_1());
1071 MakeTestRequest(0, 2, net::URLRequestTestJob::test_url_2()); 1071 MakeTestRequest(0, 2, net::URLRequestTestJob::test_url_2());
1072 MakeTestRequest(0, 3, net::URLRequestTestJob::test_url_3()); 1072 MakeTestRequest(0, 3, net::URLRequestTestJob::test_url_3());
1073 1073
1074 MakeTestRequestWithResourceType(filter_.get(), 0, 4, 1074 MakeTestRequestWithResourceType(filter_.get(), 0, 4,
1075 net::URLRequestTestJob::test_url_4(), 1075 net::URLRequestTestJob::test_url_4(),
1076 ResourceType::PREFETCH); // detachable type 1076 RESOURCE_TYPE_PREFETCH); // detachable type
1077 1077
1078 CancelRequest(2); 1078 CancelRequest(2);
1079 1079
1080 // Cancel request must come from the renderer for a detachable resource to 1080 // Cancel request must come from the renderer for a detachable resource to
1081 // delay. 1081 // delay.
1082 RendererCancelRequest(4); 1082 RendererCancelRequest(4);
1083 1083
1084 // The handler should have been detached now. 1084 // The handler should have been detached now.
1085 GlobalRequestID global_request_id(filter_->child_id(), 4); 1085 GlobalRequestID global_request_id(filter_->child_id(), 4);
1086 ResourceRequestInfoImpl* info = ResourceRequestInfoImpl::ForRequest( 1086 ResourceRequestInfoImpl* info = ResourceRequestInfoImpl::ForRequest(
(...skipping 30 matching lines...) Expand all
1117 EXPECT_EQ(4, network_delegate()->completed_requests()); 1117 EXPECT_EQ(4, network_delegate()->completed_requests());
1118 EXPECT_EQ(1, network_delegate()->canceled_requests()); 1118 EXPECT_EQ(1, network_delegate()->canceled_requests());
1119 EXPECT_EQ(0, network_delegate()->error_count()); 1119 EXPECT_EQ(0, network_delegate()->error_count());
1120 } 1120 }
1121 1121
1122 // Shows that detachable requests will timeout if the request takes too long to 1122 // Shows that detachable requests will timeout if the request takes too long to
1123 // complete. 1123 // complete.
1124 TEST_F(ResourceDispatcherHostTest, DetachedResourceTimesOut) { 1124 TEST_F(ResourceDispatcherHostTest, DetachedResourceTimesOut) {
1125 MakeTestRequestWithResourceType(filter_.get(), 0, 1, 1125 MakeTestRequestWithResourceType(filter_.get(), 0, 1,
1126 net::URLRequestTestJob::test_url_2(), 1126 net::URLRequestTestJob::test_url_2(),
1127 ResourceType::PREFETCH); // detachable type 1127 RESOURCE_TYPE_PREFETCH); // detachable type
1128 GlobalRequestID global_request_id(filter_->child_id(), 1); 1128 GlobalRequestID global_request_id(filter_->child_id(), 1);
1129 ResourceRequestInfoImpl* info = ResourceRequestInfoImpl::ForRequest( 1129 ResourceRequestInfoImpl* info = ResourceRequestInfoImpl::ForRequest(
1130 host_.GetURLRequest(global_request_id)); 1130 host_.GetURLRequest(global_request_id));
1131 ASSERT_TRUE(info->detachable_handler()); 1131 ASSERT_TRUE(info->detachable_handler());
1132 info->detachable_handler()->set_cancel_delay( 1132 info->detachable_handler()->set_cancel_delay(
1133 base::TimeDelta::FromMilliseconds(200)); 1133 base::TimeDelta::FromMilliseconds(200));
1134 base::MessageLoop::current()->RunUntilIdle(); 1134 base::MessageLoop::current()->RunUntilIdle();
1135 1135
1136 RendererCancelRequest(1); 1136 RendererCancelRequest(1);
1137 1137
(...skipping 21 matching lines...) Expand all
1159 EXPECT_EQ(1, network_delegate()->completed_requests()); 1159 EXPECT_EQ(1, network_delegate()->completed_requests());
1160 EXPECT_EQ(1, network_delegate()->canceled_requests()); 1160 EXPECT_EQ(1, network_delegate()->canceled_requests());
1161 EXPECT_EQ(0, network_delegate()->error_count()); 1161 EXPECT_EQ(0, network_delegate()->error_count());
1162 } 1162 }
1163 1163
1164 // If the filter has disappeared then detachable resources should continue to 1164 // If the filter has disappeared then detachable resources should continue to
1165 // load. 1165 // load.
1166 TEST_F(ResourceDispatcherHostTest, DeletedFilterDetached) { 1166 TEST_F(ResourceDispatcherHostTest, DeletedFilterDetached) {
1167 // test_url_1's data is available synchronously, so use 2 and 3. 1167 // test_url_1's data is available synchronously, so use 2 and 3.
1168 ResourceHostMsg_Request request_prefetch = CreateResourceRequest( 1168 ResourceHostMsg_Request request_prefetch = CreateResourceRequest(
1169 "GET", ResourceType::PREFETCH, net::URLRequestTestJob::test_url_2()); 1169 "GET", RESOURCE_TYPE_PREFETCH, net::URLRequestTestJob::test_url_2());
1170 ResourceHostMsg_Request request_ping = CreateResourceRequest( 1170 ResourceHostMsg_Request request_ping = CreateResourceRequest(
1171 "GET", ResourceType::PING, net::URLRequestTestJob::test_url_3()); 1171 "GET", RESOURCE_TYPE_PING, net::URLRequestTestJob::test_url_3());
1172 1172
1173 ResourceHostMsg_RequestResource msg_prefetch(0, 1, request_prefetch); 1173 ResourceHostMsg_RequestResource msg_prefetch(0, 1, request_prefetch);
1174 host_.OnMessageReceived(msg_prefetch, filter_); 1174 host_.OnMessageReceived(msg_prefetch, filter_);
1175 ResourceHostMsg_RequestResource msg_ping(0, 2, request_ping); 1175 ResourceHostMsg_RequestResource msg_ping(0, 2, request_ping);
1176 host_.OnMessageReceived(msg_ping, filter_); 1176 host_.OnMessageReceived(msg_ping, filter_);
1177 1177
1178 // Remove the filter before processing the requests by simulating channel 1178 // Remove the filter before processing the requests by simulating channel
1179 // closure. 1179 // closure.
1180 ResourceRequestInfoImpl* info_prefetch = ResourceRequestInfoImpl::ForRequest( 1180 ResourceRequestInfoImpl* info_prefetch = ResourceRequestInfoImpl::ForRequest(
1181 host_.GetURLRequest(GlobalRequestID(filter_->child_id(), 1))); 1181 host_.GetURLRequest(GlobalRequestID(filter_->child_id(), 1)));
(...skipping 28 matching lines...) Expand all
1210 EXPECT_EQ(0, host_.pending_requests()); 1210 EXPECT_EQ(0, host_.pending_requests());
1211 EXPECT_EQ(2, network_delegate()->completed_requests()); 1211 EXPECT_EQ(2, network_delegate()->completed_requests());
1212 EXPECT_EQ(0, network_delegate()->canceled_requests()); 1212 EXPECT_EQ(0, network_delegate()->canceled_requests());
1213 EXPECT_EQ(0, network_delegate()->error_count()); 1213 EXPECT_EQ(0, network_delegate()->error_count());
1214 } 1214 }
1215 1215
1216 // If the filter has disappeared (original process dies) then detachable 1216 // If the filter has disappeared (original process dies) then detachable
1217 // resources should continue to load, even when redirected. 1217 // resources should continue to load, even when redirected.
1218 TEST_F(ResourceDispatcherHostTest, DeletedFilterDetachedRedirect) { 1218 TEST_F(ResourceDispatcherHostTest, DeletedFilterDetachedRedirect) {
1219 ResourceHostMsg_Request request = CreateResourceRequest( 1219 ResourceHostMsg_Request request = CreateResourceRequest(
1220 "GET", ResourceType::PREFETCH, 1220 "GET", RESOURCE_TYPE_PREFETCH,
1221 net::URLRequestTestJob::test_url_redirect_to_url_2()); 1221 net::URLRequestTestJob::test_url_redirect_to_url_2());
1222 1222
1223 ResourceHostMsg_RequestResource msg(0, 1, request); 1223 ResourceHostMsg_RequestResource msg(0, 1, request);
1224 host_.OnMessageReceived(msg, filter_); 1224 host_.OnMessageReceived(msg, filter_);
1225 1225
1226 // Remove the filter before processing the request by simulating channel 1226 // Remove the filter before processing the request by simulating channel
1227 // closure. 1227 // closure.
1228 GlobalRequestID global_request_id(filter_->child_id(), 1); 1228 GlobalRequestID global_request_id(filter_->child_id(), 1);
1229 ResourceRequestInfoImpl* info = ResourceRequestInfoImpl::ForRequest( 1229 ResourceRequestInfoImpl* info = ResourceRequestInfoImpl::ForRequest(
1230 host_.GetURLRequest(global_request_id)); 1230 host_.GetURLRequest(global_request_id));
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
1290 bool was_deleted = false; 1290 bool was_deleted = false;
1291 1291
1292 // Arrange to have requests deferred before starting. 1292 // Arrange to have requests deferred before starting.
1293 TestResourceDispatcherHostDelegate delegate; 1293 TestResourceDispatcherHostDelegate delegate;
1294 delegate.set_flags(DEFER_STARTING_REQUEST); 1294 delegate.set_flags(DEFER_STARTING_REQUEST);
1295 delegate.set_url_request_user_data(new TestUserData(&was_deleted)); 1295 delegate.set_url_request_user_data(new TestUserData(&was_deleted));
1296 host_.SetDelegate(&delegate); 1296 host_.SetDelegate(&delegate);
1297 1297
1298 MakeTestRequestWithResourceType(filter_.get(), 0, 1, 1298 MakeTestRequestWithResourceType(filter_.get(), 0, 1,
1299 net::URLRequestTestJob::test_url_1(), 1299 net::URLRequestTestJob::test_url_1(),
1300 ResourceType::PREFETCH); // detachable type 1300 RESOURCE_TYPE_PREFETCH); // detachable type
1301 // Cancel request must come from the renderer for a detachable resource to 1301 // Cancel request must come from the renderer for a detachable resource to
1302 // detach. 1302 // detach.
1303 RendererCancelRequest(1); 1303 RendererCancelRequest(1);
1304 1304
1305 // Even after driving the event loop, the request has not been deleted. 1305 // Even after driving the event loop, the request has not been deleted.
1306 EXPECT_FALSE(was_deleted); 1306 EXPECT_FALSE(was_deleted);
1307 1307
1308 // However, it is still throttled because the defer happened above the 1308 // However, it is still throttled because the defer happened above the
1309 // DetachableResourceHandler. 1309 // DetachableResourceHandler.
1310 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} 1310 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {}
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
1456 } 1456 }
1457 1457
1458 // Tests CancelRequestsForProcess 1458 // Tests CancelRequestsForProcess
1459 TEST_F(ResourceDispatcherHostTest, TestProcessCancel) { 1459 TEST_F(ResourceDispatcherHostTest, TestProcessCancel) {
1460 scoped_refptr<TestFilter> test_filter = new TestFilter( 1460 scoped_refptr<TestFilter> test_filter = new TestFilter(
1461 browser_context_->GetResourceContext()); 1461 browser_context_->GetResourceContext());
1462 child_ids_.insert(test_filter->child_id()); 1462 child_ids_.insert(test_filter->child_id());
1463 1463
1464 // request 1 goes to the test delegate 1464 // request 1 goes to the test delegate
1465 ResourceHostMsg_Request request = CreateResourceRequest( 1465 ResourceHostMsg_Request request = CreateResourceRequest(
1466 "GET", ResourceType::SUB_RESOURCE, net::URLRequestTestJob::test_url_1()); 1466 "GET", RESOURCE_TYPE_SUB_RESOURCE, net::URLRequestTestJob::test_url_1());
1467 1467
1468 MakeTestRequestWithResourceType(test_filter.get(), 0, 1, 1468 MakeTestRequestWithResourceType(test_filter.get(), 0, 1,
1469 net::URLRequestTestJob::test_url_1(), 1469 net::URLRequestTestJob::test_url_1(),
1470 ResourceType::SUB_RESOURCE); 1470 RESOURCE_TYPE_SUB_RESOURCE);
1471 1471
1472 // request 2 goes to us 1472 // request 2 goes to us
1473 MakeTestRequest(0, 2, net::URLRequestTestJob::test_url_2()); 1473 MakeTestRequest(0, 2, net::URLRequestTestJob::test_url_2());
1474 1474
1475 // request 3 goes to the test delegate 1475 // request 3 goes to the test delegate
1476 MakeTestRequestWithResourceType(test_filter.get(), 0, 3, 1476 MakeTestRequestWithResourceType(test_filter.get(), 0, 3,
1477 net::URLRequestTestJob::test_url_3(), 1477 net::URLRequestTestJob::test_url_3(),
1478 ResourceType::SUB_RESOURCE); 1478 RESOURCE_TYPE_SUB_RESOURCE);
1479 1479
1480 // request 4 goes to us 1480 // request 4 goes to us
1481 MakeTestRequestWithResourceType(filter_.get(), 0, 4, 1481 MakeTestRequestWithResourceType(filter_.get(), 0, 4,
1482 net::URLRequestTestJob::test_url_4(), 1482 net::URLRequestTestJob::test_url_4(),
1483 ResourceType::PREFETCH); // detachable type 1483 RESOURCE_TYPE_PREFETCH); // detachable type
1484 1484
1485 1485
1486 // Make sure all requests have finished stage one. test_url_1 will have 1486 // Make sure all requests have finished stage one. test_url_1 will have
1487 // finished. 1487 // finished.
1488 base::MessageLoop::current()->RunUntilIdle(); 1488 base::MessageLoop::current()->RunUntilIdle();
1489 1489
1490 // TODO(mbelshe): 1490 // TODO(mbelshe):
1491 // Now that the async IO path is in place, the IO always completes on the 1491 // Now that the async IO path is in place, the IO always completes on the
1492 // initial call; so the requests have already completed. This basically 1492 // initial call; so the requests have already completed. This basically
1493 // breaks the whole test. 1493 // breaks the whole test.
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1530 CheckRequestCompleteErrorCode(msgs[1][1], net::ERR_ABORTED); 1530 CheckRequestCompleteErrorCode(msgs[1][1], net::ERR_ABORTED);
1531 // But it completed anyway. For the network stack, no requests were canceled. 1531 // But it completed anyway. For the network stack, no requests were canceled.
1532 EXPECT_EQ(4, network_delegate()->completed_requests()); 1532 EXPECT_EQ(4, network_delegate()->completed_requests());
1533 EXPECT_EQ(0, network_delegate()->canceled_requests()); 1533 EXPECT_EQ(0, network_delegate()->canceled_requests());
1534 EXPECT_EQ(0, network_delegate()->error_count()); 1534 EXPECT_EQ(0, network_delegate()->error_count());
1535 } 1535 }
1536 1536
1537 TEST_F(ResourceDispatcherHostTest, TestProcessCancelDetachedTimesOut) { 1537 TEST_F(ResourceDispatcherHostTest, TestProcessCancelDetachedTimesOut) {
1538 MakeTestRequestWithResourceType(filter_.get(), 0, 1, 1538 MakeTestRequestWithResourceType(filter_.get(), 0, 1,
1539 net::URLRequestTestJob::test_url_4(), 1539 net::URLRequestTestJob::test_url_4(),
1540 ResourceType::PREFETCH); // detachable type 1540 RESOURCE_TYPE_PREFETCH); // detachable type
1541 GlobalRequestID global_request_id(filter_->child_id(), 1); 1541 GlobalRequestID global_request_id(filter_->child_id(), 1);
1542 ResourceRequestInfoImpl* info = ResourceRequestInfoImpl::ForRequest( 1542 ResourceRequestInfoImpl* info = ResourceRequestInfoImpl::ForRequest(
1543 host_.GetURLRequest(global_request_id)); 1543 host_.GetURLRequest(global_request_id));
1544 ASSERT_TRUE(info->detachable_handler()); 1544 ASSERT_TRUE(info->detachable_handler());
1545 info->detachable_handler()->set_cancel_delay( 1545 info->detachable_handler()->set_cancel_delay(
1546 base::TimeDelta::FromMilliseconds(200)); 1546 base::TimeDelta::FromMilliseconds(200));
1547 base::MessageLoop::current()->RunUntilIdle(); 1547 base::MessageLoop::current()->RunUntilIdle();
1548 1548
1549 // Cancel the requests to the test process. 1549 // Cancel the requests to the test process.
1550 host_.CancelRequestsForProcess(filter_->child_id()); 1550 host_.CancelRequestsForProcess(filter_->child_id());
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
1641 TEST_F(ResourceDispatcherHostTest, TestBlockingCancelingRequests) { 1641 TEST_F(ResourceDispatcherHostTest, TestBlockingCancelingRequests) {
1642 host_.BlockRequestsForRoute(filter_->child_id(), 1); 1642 host_.BlockRequestsForRoute(filter_->child_id(), 1);
1643 1643
1644 MakeTestRequest(0, 1, net::URLRequestTestJob::test_url_1()); 1644 MakeTestRequest(0, 1, net::URLRequestTestJob::test_url_1());
1645 MakeTestRequest(1, 2, net::URLRequestTestJob::test_url_2()); 1645 MakeTestRequest(1, 2, net::URLRequestTestJob::test_url_2());
1646 MakeTestRequest(0, 3, net::URLRequestTestJob::test_url_3()); 1646 MakeTestRequest(0, 3, net::URLRequestTestJob::test_url_3());
1647 MakeTestRequest(1, 4, net::URLRequestTestJob::test_url_1()); 1647 MakeTestRequest(1, 4, net::URLRequestTestJob::test_url_1());
1648 // Blocked detachable resources should not delay cancellation. 1648 // Blocked detachable resources should not delay cancellation.
1649 MakeTestRequestWithResourceType(filter_.get(), 1, 5, 1649 MakeTestRequestWithResourceType(filter_.get(), 1, 5,
1650 net::URLRequestTestJob::test_url_4(), 1650 net::URLRequestTestJob::test_url_4(),
1651 ResourceType::PREFETCH); // detachable type 1651 RESOURCE_TYPE_PREFETCH); // detachable type
1652 1652
1653 // Flush all the pending requests. 1653 // Flush all the pending requests.
1654 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} 1654 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {}
1655 1655
1656 // Sort out all the messages we saw by request. 1656 // Sort out all the messages we saw by request.
1657 ResourceIPCAccumulator::ClassifiedMessages msgs; 1657 ResourceIPCAccumulator::ClassifiedMessages msgs;
1658 accum_.GetClassifiedMessages(&msgs); 1658 accum_.GetClassifiedMessages(&msgs);
1659 1659
1660 // The 2 requests for the RVH 0 should have been processed. 1660 // The 2 requests for the RVH 0 should have been processed.
1661 ASSERT_EQ(2U, msgs.size()); 1661 ASSERT_EQ(2U, msgs.size());
(...skipping 13 matching lines...) Expand all
1675 1675
1676 // Tests that blocked requests are canceled if their associated process dies. 1676 // Tests that blocked requests are canceled if their associated process dies.
1677 TEST_F(ResourceDispatcherHostTest, TestBlockedRequestsProcessDies) { 1677 TEST_F(ResourceDispatcherHostTest, TestBlockedRequestsProcessDies) {
1678 // This second filter is used to emulate a second process. 1678 // This second filter is used to emulate a second process.
1679 scoped_refptr<ForwardingFilter> second_filter = MakeForwardingFilter(); 1679 scoped_refptr<ForwardingFilter> second_filter = MakeForwardingFilter();
1680 1680
1681 host_.BlockRequestsForRoute(second_filter->child_id(), 0); 1681 host_.BlockRequestsForRoute(second_filter->child_id(), 0);
1682 1682
1683 MakeTestRequestWithResourceType(filter_.get(), 0, 1, 1683 MakeTestRequestWithResourceType(filter_.get(), 0, 1,
1684 net::URLRequestTestJob::test_url_1(), 1684 net::URLRequestTestJob::test_url_1(),
1685 ResourceType::SUB_RESOURCE); 1685 RESOURCE_TYPE_SUB_RESOURCE);
1686 MakeTestRequestWithResourceType(second_filter.get(), 0, 2, 1686 MakeTestRequestWithResourceType(second_filter.get(), 0, 2,
1687 net::URLRequestTestJob::test_url_2(), 1687 net::URLRequestTestJob::test_url_2(),
1688 ResourceType::SUB_RESOURCE); 1688 RESOURCE_TYPE_SUB_RESOURCE);
1689 MakeTestRequestWithResourceType(filter_.get(), 0, 3, 1689 MakeTestRequestWithResourceType(filter_.get(), 0, 3,
1690 net::URLRequestTestJob::test_url_3(), 1690 net::URLRequestTestJob::test_url_3(),
1691 ResourceType::SUB_RESOURCE); 1691 RESOURCE_TYPE_SUB_RESOURCE);
1692 MakeTestRequestWithResourceType(second_filter.get(), 0, 4, 1692 MakeTestRequestWithResourceType(second_filter.get(), 0, 4,
1693 net::URLRequestTestJob::test_url_1(), 1693 net::URLRequestTestJob::test_url_1(),
1694 ResourceType::SUB_RESOURCE); 1694 RESOURCE_TYPE_SUB_RESOURCE);
1695 MakeTestRequestWithResourceType(second_filter.get(), 0, 5, 1695 MakeTestRequestWithResourceType(second_filter.get(), 0, 5,
1696 net::URLRequestTestJob::test_url_4(), 1696 net::URLRequestTestJob::test_url_4(),
1697 ResourceType::PREFETCH); // detachable type 1697 RESOURCE_TYPE_PREFETCH); // detachable type
1698 1698
1699 // Simulate process death. 1699 // Simulate process death.
1700 host_.CancelRequestsForProcess(second_filter->child_id()); 1700 host_.CancelRequestsForProcess(second_filter->child_id());
1701 1701
1702 // Flush all the pending requests. 1702 // Flush all the pending requests.
1703 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} 1703 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {}
1704 1704
1705 // Sort out all the messages we saw by request. 1705 // Sort out all the messages we saw by request.
1706 ResourceIPCAccumulator::ClassifiedMessages msgs; 1706 ResourceIPCAccumulator::ClassifiedMessages msgs;
1707 accum_.GetClassifiedMessages(&msgs); 1707 accum_.GetClassifiedMessages(&msgs);
(...skipping 15 matching lines...) Expand all
1723 TEST_F(ResourceDispatcherHostTest, TestBlockedRequestsDontLeak) { 1723 TEST_F(ResourceDispatcherHostTest, TestBlockedRequestsDontLeak) {
1724 // This second filter is used to emulate a second process. 1724 // This second filter is used to emulate a second process.
1725 scoped_refptr<ForwardingFilter> second_filter = MakeForwardingFilter(); 1725 scoped_refptr<ForwardingFilter> second_filter = MakeForwardingFilter();
1726 1726
1727 host_.BlockRequestsForRoute(filter_->child_id(), 1); 1727 host_.BlockRequestsForRoute(filter_->child_id(), 1);
1728 host_.BlockRequestsForRoute(filter_->child_id(), 2); 1728 host_.BlockRequestsForRoute(filter_->child_id(), 2);
1729 host_.BlockRequestsForRoute(second_filter->child_id(), 1); 1729 host_.BlockRequestsForRoute(second_filter->child_id(), 1);
1730 1730
1731 MakeTestRequestWithResourceType(filter_.get(), 0, 1, 1731 MakeTestRequestWithResourceType(filter_.get(), 0, 1,
1732 net::URLRequestTestJob::test_url_1(), 1732 net::URLRequestTestJob::test_url_1(),
1733 ResourceType::SUB_RESOURCE); 1733 RESOURCE_TYPE_SUB_RESOURCE);
1734 MakeTestRequestWithResourceType(filter_.get(), 1, 2, 1734 MakeTestRequestWithResourceType(filter_.get(), 1, 2,
1735 net::URLRequestTestJob::test_url_2(), 1735 net::URLRequestTestJob::test_url_2(),
1736 ResourceType::SUB_RESOURCE); 1736 RESOURCE_TYPE_SUB_RESOURCE);
1737 MakeTestRequestWithResourceType(filter_.get(), 0, 3, 1737 MakeTestRequestWithResourceType(filter_.get(), 0, 3,
1738 net::URLRequestTestJob::test_url_3(), 1738 net::URLRequestTestJob::test_url_3(),
1739 ResourceType::SUB_RESOURCE); 1739 RESOURCE_TYPE_SUB_RESOURCE);
1740 MakeTestRequestWithResourceType(second_filter.get(), 1, 4, 1740 MakeTestRequestWithResourceType(second_filter.get(), 1, 4,
1741 net::URLRequestTestJob::test_url_1(), 1741 net::URLRequestTestJob::test_url_1(),
1742 ResourceType::SUB_RESOURCE); 1742 RESOURCE_TYPE_SUB_RESOURCE);
1743 MakeTestRequestWithResourceType(filter_.get(), 2, 5, 1743 MakeTestRequestWithResourceType(filter_.get(), 2, 5,
1744 net::URLRequestTestJob::test_url_2(), 1744 net::URLRequestTestJob::test_url_2(),
1745 ResourceType::SUB_RESOURCE); 1745 RESOURCE_TYPE_SUB_RESOURCE);
1746 MakeTestRequestWithResourceType(filter_.get(), 2, 6, 1746 MakeTestRequestWithResourceType(filter_.get(), 2, 6,
1747 net::URLRequestTestJob::test_url_3(), 1747 net::URLRequestTestJob::test_url_3(),
1748 ResourceType::SUB_RESOURCE); 1748 RESOURCE_TYPE_SUB_RESOURCE);
1749 MakeTestRequestWithResourceType(filter_.get(), 0, 7, 1749 MakeTestRequestWithResourceType(filter_.get(), 0, 7,
1750 net::URLRequestTestJob::test_url_4(), 1750 net::URLRequestTestJob::test_url_4(),
1751 ResourceType::PREFETCH); // detachable type 1751 RESOURCE_TYPE_PREFETCH); // detachable type
1752 MakeTestRequestWithResourceType(second_filter.get(), 1, 8, 1752 MakeTestRequestWithResourceType(second_filter.get(), 1, 8,
1753 net::URLRequestTestJob::test_url_4(), 1753 net::URLRequestTestJob::test_url_4(),
1754 ResourceType::PREFETCH); // detachable type 1754 RESOURCE_TYPE_PREFETCH); // detachable type
1755 1755
1756 host_.CancelRequestsForProcess(filter_->child_id()); 1756 host_.CancelRequestsForProcess(filter_->child_id());
1757 host_.CancelRequestsForProcess(second_filter->child_id()); 1757 host_.CancelRequestsForProcess(second_filter->child_id());
1758 1758
1759 // Flush all the pending requests. 1759 // Flush all the pending requests.
1760 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} 1760 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {}
1761 } 1761 }
1762 1762
1763 // Test the private helper method "CalculateApproximateMemoryCost()". 1763 // Test the private helper method "CalculateApproximateMemoryCost()".
1764 TEST_F(ResourceDispatcherHostTest, CalculateApproximateMemoryCost) { 1764 TEST_F(ResourceDispatcherHostTest, CalculateApproximateMemoryCost) {
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1805 // throttling kicks in. 1805 // throttling kicks in.
1806 size_t kMaxRequests = kMaxCostPerProcess / kMemoryCostOfTest2Req; 1806 size_t kMaxRequests = kMaxCostPerProcess / kMemoryCostOfTest2Req;
1807 1807
1808 // This second filter is used to emulate a second process. 1808 // This second filter is used to emulate a second process.
1809 scoped_refptr<ForwardingFilter> second_filter = MakeForwardingFilter(); 1809 scoped_refptr<ForwardingFilter> second_filter = MakeForwardingFilter();
1810 1810
1811 // Saturate the number of outstanding requests for our process. 1811 // Saturate the number of outstanding requests for our process.
1812 for (size_t i = 0; i < kMaxRequests; ++i) { 1812 for (size_t i = 0; i < kMaxRequests; ++i) {
1813 MakeTestRequestWithResourceType(filter_.get(), 0, i + 1, 1813 MakeTestRequestWithResourceType(filter_.get(), 0, i + 1,
1814 net::URLRequestTestJob::test_url_2(), 1814 net::URLRequestTestJob::test_url_2(),
1815 ResourceType::SUB_RESOURCE); 1815 RESOURCE_TYPE_SUB_RESOURCE);
1816 } 1816 }
1817 1817
1818 // Issue two more requests for our process -- these should fail immediately. 1818 // Issue two more requests for our process -- these should fail immediately.
1819 MakeTestRequestWithResourceType(filter_.get(), 0, kMaxRequests + 1, 1819 MakeTestRequestWithResourceType(filter_.get(), 0, kMaxRequests + 1,
1820 net::URLRequestTestJob::test_url_2(), 1820 net::URLRequestTestJob::test_url_2(),
1821 ResourceType::SUB_RESOURCE); 1821 RESOURCE_TYPE_SUB_RESOURCE);
1822 MakeTestRequestWithResourceType(filter_.get(), 0, kMaxRequests + 2, 1822 MakeTestRequestWithResourceType(filter_.get(), 0, kMaxRequests + 2,
1823 net::URLRequestTestJob::test_url_2(), 1823 net::URLRequestTestJob::test_url_2(),
1824 ResourceType::SUB_RESOURCE); 1824 RESOURCE_TYPE_SUB_RESOURCE);
1825 1825
1826 // Issue two requests for the second process -- these should succeed since 1826 // Issue two requests for the second process -- these should succeed since
1827 // it is just process 0 that is saturated. 1827 // it is just process 0 that is saturated.
1828 MakeTestRequestWithResourceType(second_filter.get(), 0, kMaxRequests + 3, 1828 MakeTestRequestWithResourceType(second_filter.get(), 0, kMaxRequests + 3,
1829 net::URLRequestTestJob::test_url_2(), 1829 net::URLRequestTestJob::test_url_2(),
1830 ResourceType::SUB_RESOURCE); 1830 RESOURCE_TYPE_SUB_RESOURCE);
1831 MakeTestRequestWithResourceType(second_filter.get(), 0, kMaxRequests + 4, 1831 MakeTestRequestWithResourceType(second_filter.get(), 0, kMaxRequests + 4,
1832 net::URLRequestTestJob::test_url_2(), 1832 net::URLRequestTestJob::test_url_2(),
1833 ResourceType::SUB_RESOURCE); 1833 RESOURCE_TYPE_SUB_RESOURCE);
1834 1834
1835 // Flush all the pending requests. 1835 // Flush all the pending requests.
1836 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} 1836 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {}
1837 base::MessageLoop::current()->RunUntilIdle(); 1837 base::MessageLoop::current()->RunUntilIdle();
1838 1838
1839 // Sorts out all the messages we saw by request. 1839 // Sorts out all the messages we saw by request.
1840 ResourceIPCAccumulator::ClassifiedMessages msgs; 1840 ResourceIPCAccumulator::ClassifiedMessages msgs;
1841 accum_.GetClassifiedMessages(&msgs); 1841 accum_.GetClassifiedMessages(&msgs);
1842 1842
1843 // We issued (kMaxRequests + 4) total requests. 1843 // We issued (kMaxRequests + 4) total requests.
(...skipping 30 matching lines...) Expand all
1874 host_.set_max_num_in_flight_requests(kMaxRequests); 1874 host_.set_max_num_in_flight_requests(kMaxRequests);
1875 1875
1876 // Needed to emulate additional processes. 1876 // Needed to emulate additional processes.
1877 scoped_refptr<ForwardingFilter> second_filter = MakeForwardingFilter(); 1877 scoped_refptr<ForwardingFilter> second_filter = MakeForwardingFilter();
1878 scoped_refptr<ForwardingFilter> third_filter = MakeForwardingFilter(); 1878 scoped_refptr<ForwardingFilter> third_filter = MakeForwardingFilter();
1879 1879
1880 // Saturate the number of outstanding requests for our process. 1880 // Saturate the number of outstanding requests for our process.
1881 for (size_t i = 0; i < kMaxRequestsPerProcess; ++i) { 1881 for (size_t i = 0; i < kMaxRequestsPerProcess; ++i) {
1882 MakeTestRequestWithResourceType(filter_.get(), 0, i + 1, 1882 MakeTestRequestWithResourceType(filter_.get(), 0, i + 1,
1883 net::URLRequestTestJob::test_url_2(), 1883 net::URLRequestTestJob::test_url_2(),
1884 ResourceType::SUB_RESOURCE); 1884 RESOURCE_TYPE_SUB_RESOURCE);
1885 } 1885 }
1886 1886
1887 // Issue another request for our process -- this should fail immediately. 1887 // Issue another request for our process -- this should fail immediately.
1888 MakeTestRequestWithResourceType(filter_.get(), 0, kMaxRequestsPerProcess + 1, 1888 MakeTestRequestWithResourceType(filter_.get(), 0, kMaxRequestsPerProcess + 1,
1889 net::URLRequestTestJob::test_url_2(), 1889 net::URLRequestTestJob::test_url_2(),
1890 ResourceType::SUB_RESOURCE); 1890 RESOURCE_TYPE_SUB_RESOURCE);
1891 1891
1892 // Issue a request for the second process -- this should succeed, because it 1892 // Issue a request for the second process -- this should succeed, because it
1893 // is just process 0 that is saturated. 1893 // is just process 0 that is saturated.
1894 MakeTestRequestWithResourceType( 1894 MakeTestRequestWithResourceType(
1895 second_filter.get(), 0, kMaxRequestsPerProcess + 2, 1895 second_filter.get(), 0, kMaxRequestsPerProcess + 2,
1896 net::URLRequestTestJob::test_url_2(), ResourceType::SUB_RESOURCE); 1896 net::URLRequestTestJob::test_url_2(), RESOURCE_TYPE_SUB_RESOURCE);
1897 1897
1898 // Issue a request for the third process -- this should fail, because the 1898 // Issue a request for the third process -- this should fail, because the
1899 // global limit has been reached. 1899 // global limit has been reached.
1900 MakeTestRequestWithResourceType( 1900 MakeTestRequestWithResourceType(
1901 third_filter.get(), 0, kMaxRequestsPerProcess + 3, 1901 third_filter.get(), 0, kMaxRequestsPerProcess + 3,
1902 net::URLRequestTestJob::test_url_2(), ResourceType::SUB_RESOURCE); 1902 net::URLRequestTestJob::test_url_2(), RESOURCE_TYPE_SUB_RESOURCE);
1903 1903
1904 // Flush all the pending requests. 1904 // Flush all the pending requests.
1905 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} 1905 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {}
1906 base::MessageLoop::current()->RunUntilIdle(); 1906 base::MessageLoop::current()->RunUntilIdle();
1907 1907
1908 // Sorts out all the messages we saw by request. 1908 // Sorts out all the messages we saw by request.
1909 ResourceIPCAccumulator::ClassifiedMessages msgs; 1909 ResourceIPCAccumulator::ClassifiedMessages msgs;
1910 accum_.GetClassifiedMessages(&msgs); 1910 accum_.GetClassifiedMessages(&msgs);
1911 1911
1912 // The processes issued the following requests: 1912 // The processes issued the following requests:
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
2036 std::string raw_headers("HTTP/1.1 403 Forbidden\n" 2036 std::string raw_headers("HTTP/1.1 403 Forbidden\n"
2037 "Content-disposition: attachment; filename=blah\n" 2037 "Content-disposition: attachment; filename=blah\n"
2038 "Content-type: application/octet-stream\n\n"); 2038 "Content-type: application/octet-stream\n\n");
2039 std::string response_data("<html><title>Test One</title></html>"); 2039 std::string response_data("<html><title>Test One</title></html>");
2040 SetResponse(raw_headers, response_data); 2040 SetResponse(raw_headers, response_data);
2041 2041
2042 HandleScheme("http"); 2042 HandleScheme("http");
2043 2043
2044 // Only MAIN_FRAMEs can trigger a download. 2044 // Only MAIN_FRAMEs can trigger a download.
2045 MakeTestRequestWithResourceType(filter_.get(), 0, 1, GURL("http:bla"), 2045 MakeTestRequestWithResourceType(filter_.get(), 0, 1, GURL("http:bla"),
2046 ResourceType::MAIN_FRAME); 2046 RESOURCE_TYPE_MAIN_FRAME);
2047 2047
2048 // Flush all pending requests. 2048 // Flush all pending requests.
2049 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} 2049 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {}
2050 base::MessageLoop::current()->RunUntilIdle(); 2050 base::MessageLoop::current()->RunUntilIdle();
2051 2051
2052 // Sorts out all the messages we saw by request. 2052 // Sorts out all the messages we saw by request.
2053 ResourceIPCAccumulator::ClassifiedMessages msgs; 2053 ResourceIPCAccumulator::ClassifiedMessages msgs;
2054 accum_.GetClassifiedMessages(&msgs); 2054 accum_.GetClassifiedMessages(&msgs);
2055 2055
2056 // We should have gotten one RequestComplete message. 2056 // We should have gotten one RequestComplete message.
(...skipping 25 matching lines...) Expand all
2082 // won't have constructed a DownloadResourceHandler, and and the request 2082 // won't have constructed a DownloadResourceHandler, and and the request
2083 // will be successfully canceled below, failing the test. 2083 // will be successfully canceled below, failing the test.
2084 response_data.resize(1025, ' '); 2084 response_data.resize(1025, ' ');
2085 2085
2086 SetResponse(raw_headers, response_data); 2086 SetResponse(raw_headers, response_data);
2087 job_factory_->SetDelayedCompleteJobGeneration(true); 2087 job_factory_->SetDelayedCompleteJobGeneration(true);
2088 HandleScheme("http"); 2088 HandleScheme("http");
2089 2089
2090 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id, 2090 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id,
2091 GURL("http://example.com/blah"), 2091 GURL("http://example.com/blah"),
2092 ResourceType::MAIN_FRAME); 2092 RESOURCE_TYPE_MAIN_FRAME);
2093 // Return some data so that the request is identified as a download 2093 // Return some data so that the request is identified as a download
2094 // and the proper resource handlers are created. 2094 // and the proper resource handlers are created.
2095 EXPECT_TRUE(net::URLRequestTestJob::ProcessOnePendingMessage()); 2095 EXPECT_TRUE(net::URLRequestTestJob::ProcessOnePendingMessage());
2096 2096
2097 // And now simulate a cancellation coming from the renderer. 2097 // And now simulate a cancellation coming from the renderer.
2098 ResourceHostMsg_CancelRequest msg(request_id); 2098 ResourceHostMsg_CancelRequest msg(request_id);
2099 host_.OnMessageReceived(msg, filter_.get()); 2099 host_.OnMessageReceived(msg, filter_.get());
2100 2100
2101 // Since the request had already started processing as a download, 2101 // Since the request had already started processing as a download,
2102 // the cancellation above should have been ignored and the request 2102 // the cancellation above should have been ignored and the request
(...skipping 14 matching lines...) Expand all
2117 std::string response_data("01234567890123456789\x01foobar"); 2117 std::string response_data("01234567890123456789\x01foobar");
2118 // Get past sniffing metrics. 2118 // Get past sniffing metrics.
2119 response_data.resize(1025, ' '); 2119 response_data.resize(1025, ' ');
2120 2120
2121 SetResponse(raw_headers, response_data); 2121 SetResponse(raw_headers, response_data);
2122 job_factory_->SetDelayedCompleteJobGeneration(true); 2122 job_factory_->SetDelayedCompleteJobGeneration(true);
2123 HandleScheme("http"); 2123 HandleScheme("http");
2124 2124
2125 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id, 2125 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id,
2126 GURL("http://example.com/blah"), 2126 GURL("http://example.com/blah"),
2127 ResourceType::MAIN_FRAME); 2127 RESOURCE_TYPE_MAIN_FRAME);
2128 // Return some data so that the request is identified as a download 2128 // Return some data so that the request is identified as a download
2129 // and the proper resource handlers are created. 2129 // and the proper resource handlers are created.
2130 EXPECT_TRUE(net::URLRequestTestJob::ProcessOnePendingMessage()); 2130 EXPECT_TRUE(net::URLRequestTestJob::ProcessOnePendingMessage());
2131 2131
2132 // And now simulate a cancellation coming from the renderer. 2132 // And now simulate a cancellation coming from the renderer.
2133 ResourceHostMsg_CancelRequest msg(request_id); 2133 ResourceHostMsg_CancelRequest msg(request_id);
2134 host_.OnMessageReceived(msg, filter_.get()); 2134 host_.OnMessageReceived(msg, filter_.get());
2135 2135
2136 // Since the request had already started processing as a download, 2136 // Since the request had already started processing as a download,
2137 // the cancellation above should have been ignored and the request 2137 // the cancellation above should have been ignored and the request
(...skipping 10 matching lines...) Expand all
2148 } 2148 }
2149 2149
2150 TEST_F(ResourceDispatcherHostTest, CancelRequestsForContextDetached) { 2150 TEST_F(ResourceDispatcherHostTest, CancelRequestsForContextDetached) {
2151 EXPECT_EQ(0, host_.pending_requests()); 2151 EXPECT_EQ(0, host_.pending_requests());
2152 2152
2153 int render_view_id = 0; 2153 int render_view_id = 0;
2154 int request_id = 1; 2154 int request_id = 1;
2155 2155
2156 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id, 2156 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id,
2157 net::URLRequestTestJob::test_url_4(), 2157 net::URLRequestTestJob::test_url_4(),
2158 ResourceType::PREFETCH); // detachable type 2158 RESOURCE_TYPE_PREFETCH); // detachable type
2159 2159
2160 // Simulate a cancel coming from the renderer. 2160 // Simulate a cancel coming from the renderer.
2161 RendererCancelRequest(request_id); 2161 RendererCancelRequest(request_id);
2162 2162
2163 // Since the request had already started processing as detachable, 2163 // Since the request had already started processing as detachable,
2164 // the cancellation above should have been ignored and the request 2164 // the cancellation above should have been ignored and the request
2165 // should have been detached. 2165 // should have been detached.
2166 EXPECT_EQ(1, host_.pending_requests()); 2166 EXPECT_EQ(1, host_.pending_requests());
2167 2167
2168 // Cancelling by other methods should also leave it detached. 2168 // Cancelling by other methods should also leave it detached.
(...skipping 15 matching lines...) Expand all
2184 2184
2185 std::string raw_headers("HTTP/1.1 200 OK\n" 2185 std::string raw_headers("HTTP/1.1 200 OK\n"
2186 "Content-Type: text/html; charset=utf-8\n\n"); 2186 "Content-Type: text/html; charset=utf-8\n\n");
2187 std::string response_data("<html>foobar</html>"); 2187 std::string response_data("<html>foobar</html>");
2188 2188
2189 SetResponse(raw_headers, response_data); 2189 SetResponse(raw_headers, response_data);
2190 HandleScheme("http"); 2190 HandleScheme("http");
2191 2191
2192 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id, 2192 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id,
2193 GURL("http://example.com/blah"), 2193 GURL("http://example.com/blah"),
2194 ResourceType::MAIN_FRAME); 2194 RESOURCE_TYPE_MAIN_FRAME);
2195 2195
2196 2196
2197 GlobalRequestID global_request_id(filter_->child_id(), request_id); 2197 GlobalRequestID global_request_id(filter_->child_id(), request_id);
2198 host_.MarkAsTransferredNavigation(global_request_id); 2198 host_.MarkAsTransferredNavigation(global_request_id);
2199 2199
2200 // And now simulate a cancellation coming from the renderer. 2200 // And now simulate a cancellation coming from the renderer.
2201 ResourceHostMsg_CancelRequest msg(request_id); 2201 ResourceHostMsg_CancelRequest msg(request_id);
2202 host_.OnMessageReceived(msg, filter_.get()); 2202 host_.OnMessageReceived(msg, filter_.get());
2203 2203
2204 // Since the request is marked as being transferred, 2204 // Since the request is marked as being transferred,
(...skipping 28 matching lines...) Expand all
2233 2233
2234 HandleScheme("http"); 2234 HandleScheme("http");
2235 2235
2236 // Temporarily replace ContentBrowserClient with one that will trigger the 2236 // Temporarily replace ContentBrowserClient with one that will trigger the
2237 // transfer navigation code paths. 2237 // transfer navigation code paths.
2238 TransfersAllNavigationsContentBrowserClient new_client; 2238 TransfersAllNavigationsContentBrowserClient new_client;
2239 ContentBrowserClient* old_client = SetBrowserClientForTesting(&new_client); 2239 ContentBrowserClient* old_client = SetBrowserClientForTesting(&new_client);
2240 2240
2241 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id, 2241 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id,
2242 GURL("http://example.com/blah"), 2242 GURL("http://example.com/blah"),
2243 ResourceType::MAIN_FRAME); 2243 RESOURCE_TYPE_MAIN_FRAME);
2244 2244
2245 // Now that we're blocked on the redirect, update the response and unblock by 2245 // Now that we're blocked on the redirect, update the response and unblock by
2246 // telling the AsyncResourceHandler to follow the redirect. 2246 // telling the AsyncResourceHandler to follow the redirect.
2247 const std::string kResponseBody = "hello world"; 2247 const std::string kResponseBody = "hello world";
2248 SetResponse("HTTP/1.1 200 OK\n" 2248 SetResponse("HTTP/1.1 200 OK\n"
2249 "Content-Type: text/html\n\n", 2249 "Content-Type: text/html\n\n",
2250 kResponseBody); 2250 kResponseBody);
2251 ResourceHostMsg_FollowRedirect redirect_msg(request_id); 2251 ResourceHostMsg_FollowRedirect redirect_msg(request_id);
2252 host_.OnMessageReceived(redirect_msg, filter_.get()); 2252 host_.OnMessageReceived(redirect_msg, filter_.get());
2253 base::MessageLoop::current()->RunUntilIdle(); 2253 base::MessageLoop::current()->RunUntilIdle();
2254 2254
2255 // Flush all the pending requests to get the response through the 2255 // Flush all the pending requests to get the response through the
2256 // BufferedResourceHandler. 2256 // BufferedResourceHandler.
2257 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} 2257 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {}
2258 2258
2259 // Restore, now that we've set up a transfer. 2259 // Restore, now that we've set up a transfer.
2260 SetBrowserClientForTesting(old_client); 2260 SetBrowserClientForTesting(old_client);
2261 2261
2262 // This second filter is used to emulate a second process. 2262 // This second filter is used to emulate a second process.
2263 scoped_refptr<ForwardingFilter> second_filter = MakeForwardingFilter(); 2263 scoped_refptr<ForwardingFilter> second_filter = MakeForwardingFilter();
2264 2264
2265 int new_render_view_id = 1; 2265 int new_render_view_id = 1;
2266 int new_request_id = 2; 2266 int new_request_id = 2;
2267 2267
2268 ResourceHostMsg_Request request = 2268 ResourceHostMsg_Request request =
2269 CreateResourceRequest("GET", ResourceType::MAIN_FRAME, 2269 CreateResourceRequest("GET", RESOURCE_TYPE_MAIN_FRAME,
2270 GURL("http://other.com/blech")); 2270 GURL("http://other.com/blech"));
2271 request.transferred_request_child_id = filter_->child_id(); 2271 request.transferred_request_child_id = filter_->child_id();
2272 request.transferred_request_request_id = request_id; 2272 request.transferred_request_request_id = request_id;
2273 2273
2274 ResourceHostMsg_RequestResource transfer_request_msg( 2274 ResourceHostMsg_RequestResource transfer_request_msg(
2275 new_render_view_id, new_request_id, request); 2275 new_render_view_id, new_request_id, request);
2276 host_.OnMessageReceived(transfer_request_msg, second_filter.get()); 2276 host_.OnMessageReceived(transfer_request_msg, second_filter.get());
2277 base::MessageLoop::current()->RunUntilIdle(); 2277 base::MessageLoop::current()->RunUntilIdle();
2278 2278
2279 // Check generated messages. 2279 // Check generated messages.
(...skipping 24 matching lines...) Expand all
2304 2304
2305 HandleScheme("http"); 2305 HandleScheme("http");
2306 2306
2307 // Temporarily replace ContentBrowserClient with one that will trigger the 2307 // Temporarily replace ContentBrowserClient with one that will trigger the
2308 // transfer navigation code paths. 2308 // transfer navigation code paths.
2309 TransfersAllNavigationsContentBrowserClient new_client; 2309 TransfersAllNavigationsContentBrowserClient new_client;
2310 ContentBrowserClient* old_client = SetBrowserClientForTesting(&new_client); 2310 ContentBrowserClient* old_client = SetBrowserClientForTesting(&new_client);
2311 2311
2312 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id, 2312 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id,
2313 GURL("http://example.com/blah"), 2313 GURL("http://example.com/blah"),
2314 ResourceType::MAIN_FRAME); 2314 RESOURCE_TYPE_MAIN_FRAME);
2315 2315
2316 // Now that we're blocked on the redirect, update the response and unblock by 2316 // Now that we're blocked on the redirect, update the response and unblock by
2317 // telling the AsyncResourceHandler to follow the redirect. Use a text/plain 2317 // telling the AsyncResourceHandler to follow the redirect. Use a text/plain
2318 // MIME type, which causes BufferedResourceHandler to buffer it before the 2318 // MIME type, which causes BufferedResourceHandler to buffer it before the
2319 // transfer occurs. 2319 // transfer occurs.
2320 const std::string kResponseBody = "hello world"; 2320 const std::string kResponseBody = "hello world";
2321 SetResponse("HTTP/1.1 200 OK\n" 2321 SetResponse("HTTP/1.1 200 OK\n"
2322 "Content-Type: text/plain\n\n", 2322 "Content-Type: text/plain\n\n",
2323 kResponseBody); 2323 kResponseBody);
2324 ResourceHostMsg_FollowRedirect redirect_msg(request_id); 2324 ResourceHostMsg_FollowRedirect redirect_msg(request_id);
2325 host_.OnMessageReceived(redirect_msg, filter_.get()); 2325 host_.OnMessageReceived(redirect_msg, filter_.get());
2326 base::MessageLoop::current()->RunUntilIdle(); 2326 base::MessageLoop::current()->RunUntilIdle();
2327 2327
2328 // Flush all the pending requests to get the response through the 2328 // Flush all the pending requests to get the response through the
2329 // BufferedResourceHandler. 2329 // BufferedResourceHandler.
2330 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} 2330 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {}
2331 2331
2332 // Restore, now that we've set up a transfer. 2332 // Restore, now that we've set up a transfer.
2333 SetBrowserClientForTesting(old_client); 2333 SetBrowserClientForTesting(old_client);
2334 2334
2335 // This second filter is used to emulate a second process. 2335 // This second filter is used to emulate a second process.
2336 scoped_refptr<ForwardingFilter> second_filter = MakeForwardingFilter(); 2336 scoped_refptr<ForwardingFilter> second_filter = MakeForwardingFilter();
2337 2337
2338 int new_render_view_id = 1; 2338 int new_render_view_id = 1;
2339 int new_request_id = 2; 2339 int new_request_id = 2;
2340 2340
2341 ResourceHostMsg_Request request = 2341 ResourceHostMsg_Request request =
2342 CreateResourceRequest("GET", ResourceType::MAIN_FRAME, 2342 CreateResourceRequest("GET", RESOURCE_TYPE_MAIN_FRAME,
2343 GURL("http://other.com/blech")); 2343 GURL("http://other.com/blech"));
2344 request.transferred_request_child_id = filter_->child_id(); 2344 request.transferred_request_child_id = filter_->child_id();
2345 request.transferred_request_request_id = request_id; 2345 request.transferred_request_request_id = request_id;
2346 2346
2347 ResourceHostMsg_RequestResource transfer_request_msg( 2347 ResourceHostMsg_RequestResource transfer_request_msg(
2348 new_render_view_id, new_request_id, request); 2348 new_render_view_id, new_request_id, request);
2349 host_.OnMessageReceived(transfer_request_msg, second_filter.get()); 2349 host_.OnMessageReceived(transfer_request_msg, second_filter.get());
2350 base::MessageLoop::current()->RunUntilIdle(); 2350 base::MessageLoop::current()->RunUntilIdle();
2351 2351
2352 // Check generated messages. 2352 // Check generated messages.
(...skipping 27 matching lines...) Expand all
2380 // transfer navigation code paths. 2380 // transfer navigation code paths.
2381 TransfersAllNavigationsContentBrowserClient new_client; 2381 TransfersAllNavigationsContentBrowserClient new_client;
2382 ContentBrowserClient* old_client = SetBrowserClientForTesting(&new_client); 2382 ContentBrowserClient* old_client = SetBrowserClientForTesting(&new_client);
2383 2383
2384 // Create a first filter that can be deleted before the second one starts. 2384 // Create a first filter that can be deleted before the second one starts.
2385 { 2385 {
2386 scoped_refptr<ForwardingFilter> first_filter = MakeForwardingFilter(); 2386 scoped_refptr<ForwardingFilter> first_filter = MakeForwardingFilter();
2387 first_child_id = first_filter->child_id(); 2387 first_child_id = first_filter->child_id();
2388 2388
2389 ResourceHostMsg_Request first_request = 2389 ResourceHostMsg_Request first_request =
2390 CreateResourceRequest("GET", ResourceType::MAIN_FRAME, 2390 CreateResourceRequest("GET", RESOURCE_TYPE_MAIN_FRAME,
2391 GURL("http://example.com/blah")); 2391 GURL("http://example.com/blah"));
2392 2392
2393 ResourceHostMsg_RequestResource first_request_msg( 2393 ResourceHostMsg_RequestResource first_request_msg(
2394 render_view_id, request_id, first_request); 2394 render_view_id, request_id, first_request);
2395 host_.OnMessageReceived(first_request_msg, first_filter.get()); 2395 host_.OnMessageReceived(first_request_msg, first_filter.get());
2396 base::MessageLoop::current()->RunUntilIdle(); 2396 base::MessageLoop::current()->RunUntilIdle();
2397 2397
2398 // Now that we're blocked on the redirect, update the response and unblock 2398 // Now that we're blocked on the redirect, update the response and unblock
2399 // by telling the AsyncResourceHandler to follow the redirect. 2399 // by telling the AsyncResourceHandler to follow the redirect.
2400 SetResponse("HTTP/1.1 200 OK\n" 2400 SetResponse("HTTP/1.1 200 OK\n"
(...skipping 15 matching lines...) Expand all
2416 // Make sure we don't hold onto the ResourceMessageFilter after it is deleted. 2416 // Make sure we don't hold onto the ResourceMessageFilter after it is deleted.
2417 GlobalRequestID first_global_request_id(first_child_id, request_id); 2417 GlobalRequestID first_global_request_id(first_child_id, request_id);
2418 2418
2419 // This second filter is used to emulate a second process. 2419 // This second filter is used to emulate a second process.
2420 scoped_refptr<ForwardingFilter> second_filter = MakeForwardingFilter(); 2420 scoped_refptr<ForwardingFilter> second_filter = MakeForwardingFilter();
2421 2421
2422 int new_render_view_id = 1; 2422 int new_render_view_id = 1;
2423 int new_request_id = 2; 2423 int new_request_id = 2;
2424 2424
2425 ResourceHostMsg_Request request = 2425 ResourceHostMsg_Request request =
2426 CreateResourceRequest("GET", ResourceType::MAIN_FRAME, 2426 CreateResourceRequest("GET", RESOURCE_TYPE_MAIN_FRAME,
2427 GURL("http://other.com/blech")); 2427 GURL("http://other.com/blech"));
2428 request.transferred_request_child_id = first_child_id; 2428 request.transferred_request_child_id = first_child_id;
2429 request.transferred_request_request_id = request_id; 2429 request.transferred_request_request_id = request_id;
2430 2430
2431 // For cleanup. 2431 // For cleanup.
2432 child_ids_.insert(second_filter->child_id()); 2432 child_ids_.insert(second_filter->child_id());
2433 ResourceHostMsg_RequestResource transfer_request_msg( 2433 ResourceHostMsg_RequestResource transfer_request_msg(
2434 new_render_view_id, new_request_id, request); 2434 new_render_view_id, new_request_id, request);
2435 host_.OnMessageReceived(transfer_request_msg, second_filter.get()); 2435 host_.OnMessageReceived(transfer_request_msg, second_filter.get());
2436 base::MessageLoop::current()->RunUntilIdle(); 2436 base::MessageLoop::current()->RunUntilIdle();
(...skipping 23 matching lines...) Expand all
2460 2460
2461 HandleScheme("http"); 2461 HandleScheme("http");
2462 2462
2463 // Temporarily replace ContentBrowserClient with one that will trigger the 2463 // Temporarily replace ContentBrowserClient with one that will trigger the
2464 // transfer navigation code paths. 2464 // transfer navigation code paths.
2465 TransfersAllNavigationsContentBrowserClient new_client; 2465 TransfersAllNavigationsContentBrowserClient new_client;
2466 ContentBrowserClient* old_client = SetBrowserClientForTesting(&new_client); 2466 ContentBrowserClient* old_client = SetBrowserClientForTesting(&new_client);
2467 2467
2468 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id, 2468 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id,
2469 GURL("http://example.com/blah"), 2469 GURL("http://example.com/blah"),
2470 ResourceType::MAIN_FRAME); 2470 RESOURCE_TYPE_MAIN_FRAME);
2471 2471
2472 // Now that we're blocked on the redirect, simulate hitting another redirect. 2472 // Now that we're blocked on the redirect, simulate hitting another redirect.
2473 SetResponse("HTTP/1.1 302 Found\n" 2473 SetResponse("HTTP/1.1 302 Found\n"
2474 "Location: http://other.com/blerg\n\n"); 2474 "Location: http://other.com/blerg\n\n");
2475 ResourceHostMsg_FollowRedirect redirect_msg(request_id); 2475 ResourceHostMsg_FollowRedirect redirect_msg(request_id);
2476 host_.OnMessageReceived(redirect_msg, filter_.get()); 2476 host_.OnMessageReceived(redirect_msg, filter_.get());
2477 base::MessageLoop::current()->RunUntilIdle(); 2477 base::MessageLoop::current()->RunUntilIdle();
2478 2478
2479 // Now that we're blocked on the second redirect, update the response and 2479 // Now that we're blocked on the second redirect, update the response and
2480 // unblock by telling the AsyncResourceHandler to follow the redirect. 2480 // unblock by telling the AsyncResourceHandler to follow the redirect.
(...skipping 14 matching lines...) Expand all
2495 // Restore. 2495 // Restore.
2496 SetBrowserClientForTesting(old_client); 2496 SetBrowserClientForTesting(old_client);
2497 2497
2498 // This second filter is used to emulate a second process. 2498 // This second filter is used to emulate a second process.
2499 scoped_refptr<ForwardingFilter> second_filter = MakeForwardingFilter(); 2499 scoped_refptr<ForwardingFilter> second_filter = MakeForwardingFilter();
2500 2500
2501 int new_render_view_id = 1; 2501 int new_render_view_id = 1;
2502 int new_request_id = 2; 2502 int new_request_id = 2;
2503 2503
2504 ResourceHostMsg_Request request = 2504 ResourceHostMsg_Request request =
2505 CreateResourceRequest("GET", ResourceType::MAIN_FRAME, 2505 CreateResourceRequest("GET", RESOURCE_TYPE_MAIN_FRAME,
2506 GURL("http://other.com/blech")); 2506 GURL("http://other.com/blech"));
2507 request.transferred_request_child_id = filter_->child_id(); 2507 request.transferred_request_child_id = filter_->child_id();
2508 request.transferred_request_request_id = request_id; 2508 request.transferred_request_request_id = request_id;
2509 2509
2510 // For cleanup. 2510 // For cleanup.
2511 child_ids_.insert(second_filter->child_id()); 2511 child_ids_.insert(second_filter->child_id());
2512 ResourceHostMsg_RequestResource transfer_request_msg( 2512 ResourceHostMsg_RequestResource transfer_request_msg(
2513 new_render_view_id, new_request_id, request); 2513 new_render_view_id, new_request_id, request);
2514 host_.OnMessageReceived(transfer_request_msg, second_filter.get()); 2514 host_.OnMessageReceived(transfer_request_msg, second_filter.get());
2515 2515
(...skipping 17 matching lines...) Expand all
2533 EXPECT_EQ(ResourceMsg_ReceivedRedirect::ID, msgs[0][0].type()); 2533 EXPECT_EQ(ResourceMsg_ReceivedRedirect::ID, msgs[0][0].type());
2534 CheckSuccessfulRequest(msgs[1], kResponseBody); 2534 CheckSuccessfulRequest(msgs[1], kResponseBody);
2535 } 2535 }
2536 2536
2537 TEST_F(ResourceDispatcherHostTest, UnknownURLScheme) { 2537 TEST_F(ResourceDispatcherHostTest, UnknownURLScheme) {
2538 EXPECT_EQ(0, host_.pending_requests()); 2538 EXPECT_EQ(0, host_.pending_requests());
2539 2539
2540 HandleScheme("http"); 2540 HandleScheme("http");
2541 2541
2542 MakeTestRequestWithResourceType(filter_.get(), 0, 1, GURL("foo://bar"), 2542 MakeTestRequestWithResourceType(filter_.get(), 0, 1, GURL("foo://bar"),
2543 ResourceType::MAIN_FRAME); 2543 RESOURCE_TYPE_MAIN_FRAME);
2544 2544
2545 // Flush all pending requests. 2545 // Flush all pending requests.
2546 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} 2546 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {}
2547 2547
2548 // Sort all the messages we saw by request. 2548 // Sort all the messages we saw by request.
2549 ResourceIPCAccumulator::ClassifiedMessages msgs; 2549 ResourceIPCAccumulator::ClassifiedMessages msgs;
2550 accum_.GetClassifiedMessages(&msgs); 2550 accum_.GetClassifiedMessages(&msgs);
2551 2551
2552 // We should have gotten one RequestComplete message. 2552 // We should have gotten one RequestComplete message.
2553 ASSERT_EQ(1U, msgs[0].size()); 2553 ASSERT_EQ(1U, msgs[0].size());
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
2595 // that if this increase beyond 512K we'll need to make the response longer. 2595 // that if this increase beyond 512K we'll need to make the response longer.
2596 const int kAllocSize = 1024*512; 2596 const int kAllocSize = 1024*512;
2597 response_data.resize(kAllocSize, ' '); 2597 response_data.resize(kAllocSize, ' ');
2598 2598
2599 SetResponse(raw_headers, response_data); 2599 SetResponse(raw_headers, response_data);
2600 job_factory_->SetDelayedCompleteJobGeneration(true); 2600 job_factory_->SetDelayedCompleteJobGeneration(true);
2601 HandleScheme("http"); 2601 HandleScheme("http");
2602 2602
2603 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id, 2603 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id,
2604 GURL("http://example.com/blah"), 2604 GURL("http://example.com/blah"),
2605 ResourceType::PREFETCH); 2605 RESOURCE_TYPE_PREFETCH);
2606 2606
2607 // Get a bit of data before cancelling. 2607 // Get a bit of data before cancelling.
2608 EXPECT_TRUE(net::URLRequestTestJob::ProcessOnePendingMessage()); 2608 EXPECT_TRUE(net::URLRequestTestJob::ProcessOnePendingMessage());
2609 2609
2610 // Simulate a cancellation coming from the renderer. 2610 // Simulate a cancellation coming from the renderer.
2611 ResourceHostMsg_CancelRequest msg(request_id); 2611 ResourceHostMsg_CancelRequest msg(request_id);
2612 host_.OnMessageReceived(msg, filter_.get()); 2612 host_.OnMessageReceived(msg, filter_.get());
2613 2613
2614 EXPECT_EQ(1, host_.pending_requests()); 2614 EXPECT_EQ(1, host_.pending_requests());
2615 2615
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
2809 2809
2810 // The file is no longer readable to the child and has been deleted. 2810 // The file is no longer readable to the child and has been deleted.
2811 EXPECT_FALSE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile( 2811 EXPECT_FALSE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile(
2812 filter_->child_id(), file_path)); 2812 filter_->child_id(), file_path));
2813 EXPECT_FALSE(base::PathExists(file_path)); 2813 EXPECT_FALSE(base::PathExists(file_path));
2814 } 2814 }
2815 2815
2816 TEST_F(ResourceDispatcherHostTest, DownloadToFile) { 2816 TEST_F(ResourceDispatcherHostTest, DownloadToFile) {
2817 // Make a request which downloads to file. 2817 // Make a request which downloads to file.
2818 ResourceHostMsg_Request request = CreateResourceRequest( 2818 ResourceHostMsg_Request request = CreateResourceRequest(
2819 "GET", ResourceType::SUB_RESOURCE, net::URLRequestTestJob::test_url_1()); 2819 "GET", RESOURCE_TYPE_SUB_RESOURCE, net::URLRequestTestJob::test_url_1());
2820 request.download_to_file = true; 2820 request.download_to_file = true;
2821 ResourceHostMsg_RequestResource request_msg(0, 1, request); 2821 ResourceHostMsg_RequestResource request_msg(0, 1, request);
2822 host_.OnMessageReceived(request_msg, filter_); 2822 host_.OnMessageReceived(request_msg, filter_);
2823 2823
2824 // Running the message loop until idle does not work because 2824 // Running the message loop until idle does not work because
2825 // RedirectToFileResourceHandler posts things to base::WorkerPool. Instead, 2825 // RedirectToFileResourceHandler posts things to base::WorkerPool. Instead,
2826 // wait for the ResourceMsg_RequestComplete to go out. Then run the event loop 2826 // wait for the ResourceMsg_RequestComplete to go out. Then run the event loop
2827 // until idle so the loader is gone. 2827 // until idle so the loader is gone.
2828 WaitForRequestComplete(); 2828 WaitForRequestComplete();
2829 base::RunLoop().RunUntilIdle(); 2829 base::RunLoop().RunUntilIdle();
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
2918 } else { 2918 } else {
2919 return new net::URLRequestTestJob( 2919 return new net::URLRequestTestJob(
2920 request, network_delegate, 2920 request, network_delegate,
2921 test_fixture_->response_headers_, test_fixture_->response_data_, 2921 test_fixture_->response_headers_, test_fixture_->response_data_,
2922 false); 2922 false);
2923 } 2923 }
2924 } 2924 }
2925 } 2925 }
2926 2926
2927 } // namespace content 2927 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/loader/resource_dispatcher_host_impl.cc ('k') | content/browser/loader/resource_loader.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698