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

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

Issue 2481093003: Introduce ResourceRequesterInfo to abstract the requester of resource request (Closed)
Patch Set: incorporated kinuko's comment Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <stddef.h> 5 #include <stddef.h>
6 6
7 #include <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 95
96 // The first messages should be received response. 96 // The first messages should be received response.
97 ASSERT_EQ(ResourceMsg_ReceivedResponse::ID, messages[0].type()); 97 ASSERT_EQ(ResourceMsg_ReceivedResponse::ID, messages[0].type());
98 98
99 base::PickleIterator iter(messages[0]); 99 base::PickleIterator iter(messages[0]);
100 int request_id; 100 int request_id;
101 ASSERT_TRUE(IPC::ReadParam(&messages[0], &iter, &request_id)); 101 ASSERT_TRUE(IPC::ReadParam(&messages[0], &iter, &request_id));
102 ASSERT_TRUE(IPC::ReadParam(&messages[0], &iter, response_head)); 102 ASSERT_TRUE(IPC::ReadParam(&messages[0], &iter, response_head));
103 } 103 }
104 104
105 void GenerateIPCMessage(scoped_refptr<ResourceMessageFilter> filter, 105 void GenerateIPCMessage(
106 std::unique_ptr<IPC::Message> message) { 106 scoped_refptr<const ResourceRequesterInfo> requester_info,
107 ResourceDispatcherHostImpl::Get()->OnMessageReceived( 107 std::unique_ptr<IPC::Message> message) {
108 *message, filter.get()); 108 ResourceDispatcherHostImpl::Get()->OnMessageReceived(*message,
109 requester_info.get());
109 } 110 }
110 111
111 // On Windows, ResourceMsg_SetDataBuffer supplies a HANDLE which is not 112 // On Windows, ResourceMsg_SetDataBuffer supplies a HANDLE which is not
112 // automatically released. 113 // automatically released.
113 // 114 //
114 // See ResourceDispatcher::ReleaseResourcesInDataMessage. 115 // See ResourceDispatcher::ReleaseResourcesInDataMessage.
115 // 116 //
116 // TODO(davidben): It would be nice if the behavior for base::SharedMemoryHandle 117 // TODO(davidben): It would be nice if the behavior for base::SharedMemoryHandle
117 // were more like it is in POSIX where the received fds are tracked in a 118 // were more like it is in POSIX where the received fds are tracked in a
118 // ref-counted core that closes them if not extracted. 119 // ref-counted core that closes them if not extracted.
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 return nullptr; 247 return nullptr;
247 } 248 }
248 249
249 // This is used to create a filter matching a specified child id. 250 // This is used to create a filter matching a specified child id.
250 class TestFilterSpecifyingChild : public ResourceMessageFilter { 251 class TestFilterSpecifyingChild : public ResourceMessageFilter {
251 public: 252 public:
252 explicit TestFilterSpecifyingChild(ResourceContext* resource_context, 253 explicit TestFilterSpecifyingChild(ResourceContext* resource_context,
253 int process_id) 254 int process_id)
254 : ResourceMessageFilter( 255 : ResourceMessageFilter(
255 process_id, 256 process_id,
256 PROCESS_TYPE_RENDERER,
257 NULL, 257 NULL,
258 NULL, 258 NULL,
259 NULL, 259 NULL,
260 NULL, 260 NULL,
261 base::Bind(&TestFilterSpecifyingChild::GetContexts, 261 base::Bind(&TestFilterSpecifyingChild::GetContexts,
262 base::Unretained(this))), 262 base::Unretained(this))),
263 resource_context_(resource_context), 263 resource_context_(resource_context),
264 canceled_(false), 264 canceled_(false),
265 received_after_canceled_(0) { 265 received_after_canceled_(0) {
266 InitializeOnIOThread();
266 set_peer_process_for_testing(base::Process::Current()); 267 set_peer_process_for_testing(base::Process::Current());
267 } 268 }
268 269
269 void set_canceled(bool canceled) { canceled_ = canceled; } 270 void set_canceled(bool canceled) { canceled_ = canceled; }
270 int received_after_canceled() const { return received_after_canceled_; } 271 int received_after_canceled() const { return received_after_canceled_; }
271 272
272 // ResourceMessageFilter override 273 // ResourceMessageFilter override
273 bool Send(IPC::Message* msg) override { 274 bool Send(IPC::Message* msg) override {
274 // No messages should be received when the process has been canceled. 275 // No messages should be received when the process has been canceled.
275 if (canceled_) 276 if (canceled_)
(...skipping 720 matching lines...) Expand 10 before | Expand all | Expand 10 after
996 void MakeTestRequestWithPriorityAndRenderFrame(int render_view_id, 997 void MakeTestRequestWithPriorityAndRenderFrame(int render_view_id,
997 int render_frame_id, 998 int render_frame_id,
998 int request_id, 999 int request_id,
999 net::RequestPriority priority); 1000 net::RequestPriority priority);
1000 1001
1001 void MakeWebContentsAssociatedDownloadRequest(int request_id, 1002 void MakeWebContentsAssociatedDownloadRequest(int request_id,
1002 const GURL& url); 1003 const GURL& url);
1003 1004
1004 void CancelRequest(int request_id); 1005 void CancelRequest(int request_id);
1005 void RendererCancelRequest(int request_id) { 1006 void RendererCancelRequest(int request_id) {
1006 ResourceMessageFilter* old_filter = SetFilter(filter_.get()); 1007 filter_->OnMessageReceived(ResourceHostMsg_CancelRequest(request_id));
1007 host_.OnCancelRequest(request_id);
1008 SetFilter(old_filter);
1009 } 1008 }
1010 1009
1011 void CompleteStartRequest(int request_id); 1010 void CompleteStartRequest(int request_id);
1012 void CompleteStartRequest(ResourceMessageFilter* filter, int request_id); 1011 void CompleteStartRequest(ResourceMessageFilter* filter, int request_id);
1013 1012
1014 net::TestNetworkDelegate* network_delegate() { return &network_delegate_; } 1013 net::TestNetworkDelegate* network_delegate() { return &network_delegate_; }
1015 1014
1016 void EnsureSchemeIsAllowed(const std::string& scheme) { 1015 void EnsureSchemeIsAllowed(const std::string& scheme) {
1017 ChildProcessSecurityPolicyImpl* policy = 1016 ChildProcessSecurityPolicyImpl* policy =
1018 ChildProcessSecurityPolicyImpl::GetInstance(); 1017 ChildProcessSecurityPolicyImpl::GetInstance();
(...skipping 30 matching lines...) Expand all
1049 void GenerateDataReceivedACK(const IPC::Message& msg) { 1048 void GenerateDataReceivedACK(const IPC::Message& msg) {
1050 EXPECT_EQ(ResourceMsg_DataReceived::ID, msg.type()); 1049 EXPECT_EQ(ResourceMsg_DataReceived::ID, msg.type());
1051 1050
1052 int request_id = -1; 1051 int request_id = -1;
1053 bool result = base::PickleIterator(msg).ReadInt(&request_id); 1052 bool result = base::PickleIterator(msg).ReadInt(&request_id);
1054 DCHECK(result); 1053 DCHECK(result);
1055 std::unique_ptr<IPC::Message> ack( 1054 std::unique_ptr<IPC::Message> ack(
1056 new ResourceHostMsg_DataReceived_ACK(request_id)); 1055 new ResourceHostMsg_DataReceived_ACK(request_id));
1057 1056
1058 base::ThreadTaskRunnerHandle::Get()->PostTask( 1057 base::ThreadTaskRunnerHandle::Get()->PostTask(
1059 FROM_HERE, 1058 FROM_HERE, base::Bind(&GenerateIPCMessage, filter_->requester_info(),
1060 base::Bind(&GenerateIPCMessage, filter_, base::Passed(&ack))); 1059 base::Passed(&ack)));
1061 }
1062
1063 // Setting filters for testing renderer messages.
1064 // Returns the previous filter.
1065 ResourceMessageFilter* SetFilter(ResourceMessageFilter* new_filter) {
1066 ResourceMessageFilter* old_filter = host_.filter_;
1067 host_.filter_ = new_filter;
1068 return old_filter;
1069 } 1060 }
1070 1061
1071 void WaitForRequestComplete() { 1062 void WaitForRequestComplete() {
1072 DCHECK(!wait_for_request_complete_loop_); 1063 DCHECK(!wait_for_request_complete_loop_);
1073 wait_for_request_complete_loop_.reset(new base::RunLoop); 1064 wait_for_request_complete_loop_.reset(new base::RunLoop);
1074 wait_for_request_complete_loop_->Run(); 1065 wait_for_request_complete_loop_->Run();
1075 wait_for_request_complete_loop_.reset(); 1066 wait_for_request_complete_loop_.reset();
1076 } 1067 }
1077 1068
1078 void DeleteRenderFrame(const GlobalFrameRoutingId& global_routing_id) { 1069 void DeleteRenderFrame(const GlobalFrameRoutingId& global_routing_id) {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1121 1112
1122 // We should have gotten one RequestComplete message. 1113 // We should have gotten one RequestComplete message.
1123 ASSERT_EQ(1U, msgs.size()); 1114 ASSERT_EQ(1U, msgs.size());
1124 ASSERT_EQ(1U, msgs[0].size()); 1115 ASSERT_EQ(1U, msgs[0].size());
1125 EXPECT_EQ(ResourceMsg_RequestComplete::ID, msgs[0][0].type()); 1116 EXPECT_EQ(ResourceMsg_RequestComplete::ID, msgs[0][0].type());
1126 1117
1127 // The RequestComplete message should have had the expected error code. 1118 // The RequestComplete message should have had the expected error code.
1128 CheckRequestCompleteErrorCode(msgs[0][0], expected_error_code); 1119 CheckRequestCompleteErrorCode(msgs[0][0], expected_error_code);
1129 } 1120 }
1130 1121
1122 void OnMessageReceived(const IPC::Message& message,
1123 ResourceMessageFilter* filter) {
1124 host_.OnMessageReceived(message, filter->requester_info());
1125 }
1126
1127 const ResourceRequesterInfo* GetResourceRequesterInfo(
1128 ResourceMessageFilter* filter) {
1129 return filter->requester_info();
1130 }
1131
1131 content::TestBrowserThreadBundle thread_bundle_; 1132 content::TestBrowserThreadBundle thread_bundle_;
1132 std::unique_ptr<TestBrowserContext> browser_context_; 1133 std::unique_ptr<TestBrowserContext> browser_context_;
1133 std::unique_ptr<TestURLRequestJobFactory> job_factory_; 1134 std::unique_ptr<TestURLRequestJobFactory> job_factory_;
1134 std::unique_ptr<WebContents> web_contents_; 1135 std::unique_ptr<WebContents> web_contents_;
1135 std::unique_ptr<TestWebContentsObserver> web_contents_observer_; 1136 std::unique_ptr<TestWebContentsObserver> web_contents_observer_;
1136 scoped_refptr<ForwardingFilter> filter_; 1137 scoped_refptr<ForwardingFilter> filter_;
1137 scoped_refptr<TestFilterSpecifyingChild> web_contents_filter_; 1138 scoped_refptr<TestFilterSpecifyingChild> web_contents_filter_;
1138 net::TestNetworkDelegate network_delegate_; 1139 net::TestNetworkDelegate network_delegate_;
1139 LoaderDelegateImpl loader_delegate_; 1140 LoaderDelegateImpl loader_delegate_;
1140 ResourceDispatcherHostImpl host_; 1141 ResourceDispatcherHostImpl host_;
(...skipping 19 matching lines...) Expand all
1160 1161
1161 void ResourceDispatcherHostTest::MakeTestRequestWithRenderFrame( 1162 void ResourceDispatcherHostTest::MakeTestRequestWithRenderFrame(
1162 int render_view_id, 1163 int render_view_id,
1163 int render_frame_id, 1164 int render_frame_id,
1164 int request_id, 1165 int request_id,
1165 const GURL& url, 1166 const GURL& url,
1166 ResourceType type) { 1167 ResourceType type) {
1167 ResourceRequest request = CreateResourceRequest("GET", type, url); 1168 ResourceRequest request = CreateResourceRequest("GET", type, url);
1168 request.render_frame_id = render_frame_id; 1169 request.render_frame_id = render_frame_id;
1169 ResourceHostMsg_RequestResource msg(render_view_id, request_id, request); 1170 ResourceHostMsg_RequestResource msg(render_view_id, request_id, request);
1170 host_.OnMessageReceived(msg, filter_.get()); 1171 OnMessageReceived(msg, filter_.get());
1171 KickOffRequest(); 1172 KickOffRequest();
1172 } 1173 }
1173 1174
1174 void ResourceDispatcherHostTest::MakeTestRequestWithResourceType( 1175 void ResourceDispatcherHostTest::MakeTestRequestWithResourceType(
1175 ResourceMessageFilter* filter, 1176 ResourceMessageFilter* filter,
1176 int render_view_id, 1177 int render_view_id,
1177 int request_id, 1178 int request_id,
1178 const GURL& url, 1179 const GURL& url,
1179 ResourceType type) { 1180 ResourceType type) {
1180 ResourceRequest request = CreateResourceRequest("GET", type, url); 1181 ResourceRequest request = CreateResourceRequest("GET", type, url);
1181 ResourceHostMsg_RequestResource msg(render_view_id, request_id, request); 1182 ResourceHostMsg_RequestResource msg(render_view_id, request_id, request);
1182 host_.OnMessageReceived(msg, filter); 1183 OnMessageReceived(msg, filter);
1183 KickOffRequest(); 1184 KickOffRequest();
1184 } 1185 }
1185 1186
1186 void ResourceDispatcherHostTest::MakeWebContentsAssociatedTestRequest( 1187 void ResourceDispatcherHostTest::MakeWebContentsAssociatedTestRequest(
1187 int request_id, 1188 int request_id,
1188 const GURL& url) { 1189 const GURL& url) {
1189 MakeWebContentsAssociatedTestRequestWithResourceType( 1190 MakeWebContentsAssociatedTestRequestWithResourceType(
1190 request_id, url, RESOURCE_TYPE_SUB_RESOURCE); 1191 request_id, url, RESOURCE_TYPE_SUB_RESOURCE);
1191 } 1192 }
1192 1193
1193 void ResourceDispatcherHostTest:: 1194 void ResourceDispatcherHostTest::
1194 MakeWebContentsAssociatedTestRequestWithResourceType(int request_id, 1195 MakeWebContentsAssociatedTestRequestWithResourceType(int request_id,
1195 const GURL& url, 1196 const GURL& url,
1196 ResourceType type) { 1197 ResourceType type) {
1197 ResourceRequest request = CreateResourceRequest("GET", type, url); 1198 ResourceRequest request = CreateResourceRequest("GET", type, url);
1198 request.origin_pid = web_contents_->GetRenderProcessHost()->GetID(); 1199 request.origin_pid = web_contents_->GetRenderProcessHost()->GetID();
1199 request.render_frame_id = web_contents_->GetMainFrame()->GetRoutingID(); 1200 request.render_frame_id = web_contents_->GetMainFrame()->GetRoutingID();
1200 ResourceHostMsg_RequestResource msg(web_contents_->GetRoutingID(), request_id, 1201 ResourceHostMsg_RequestResource msg(web_contents_->GetRoutingID(), request_id,
1201 request); 1202 request);
1202 host_.OnMessageReceived(msg, web_contents_filter_.get()); 1203 OnMessageReceived(msg, web_contents_filter_.get());
1203 KickOffRequest(); 1204 KickOffRequest();
1204 } 1205 }
1205 1206
1206 void ResourceDispatcherHostTest::MakeTestRequestWithPriority( 1207 void ResourceDispatcherHostTest::MakeTestRequestWithPriority(
1207 int render_view_id, 1208 int render_view_id,
1208 int request_id, 1209 int request_id,
1209 net::RequestPriority priority) { 1210 net::RequestPriority priority) {
1210 MakeTestRequestWithPriorityAndRenderFrame(render_view_id, -1, request_id, 1211 MakeTestRequestWithPriorityAndRenderFrame(render_view_id, -1, request_id,
1211 priority); 1212 priority);
1212 } 1213 }
1213 1214
1214 void ResourceDispatcherHostTest::MakeTestRequestWithPriorityAndRenderFrame( 1215 void ResourceDispatcherHostTest::MakeTestRequestWithPriorityAndRenderFrame(
1215 int render_view_id, 1216 int render_view_id,
1216 int render_frame_id, 1217 int render_frame_id,
1217 int request_id, 1218 int request_id,
1218 net::RequestPriority priority) { 1219 net::RequestPriority priority) {
1219 ResourceRequest request = CreateResourceRequest( 1220 ResourceRequest request = CreateResourceRequest(
1220 "GET", RESOURCE_TYPE_SUB_RESOURCE, GURL("http://example.com/priority")); 1221 "GET", RESOURCE_TYPE_SUB_RESOURCE, GURL("http://example.com/priority"));
1221 request.render_frame_id = render_frame_id; 1222 request.render_frame_id = render_frame_id;
1222 request.priority = priority; 1223 request.priority = priority;
1223 ResourceHostMsg_RequestResource msg(render_view_id, request_id, request); 1224 ResourceHostMsg_RequestResource msg(render_view_id, request_id, request);
1224 host_.OnMessageReceived(msg, filter_.get()); 1225 OnMessageReceived(msg, filter_.get());
1225 } 1226 }
1226 1227
1227 void ResourceDispatcherHostTest::MakeWebContentsAssociatedDownloadRequest( 1228 void ResourceDispatcherHostTest::MakeWebContentsAssociatedDownloadRequest(
1228 int request_id, 1229 int request_id,
1229 const GURL& url) { 1230 const GURL& url) {
1230 net::URLRequestContext* request_context = 1231 net::URLRequestContext* request_context =
1231 browser_context_->GetResourceContext()->GetRequestContext(); 1232 browser_context_->GetResourceContext()->GetRequestContext();
1232 std::unique_ptr<net::URLRequest> request( 1233 std::unique_ptr<net::URLRequest> request(
1233 request_context->CreateRequest(url, net::DEFAULT_PRIORITY, NULL)); 1234 request_context->CreateRequest(url, net::DEFAULT_PRIORITY, NULL));
1234 DownloadManagerImpl::BeginDownloadRequest( 1235 DownloadManagerImpl::BeginDownloadRequest(
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
1400 MakeTestRequest(0, 1, net::URLRequestTestJob::test_url_1()); 1401 MakeTestRequest(0, 1, net::URLRequestTestJob::test_url_1());
1401 MakeTestRequest(0, 2, net::URLRequestTestJob::test_url_2()); 1402 MakeTestRequest(0, 2, net::URLRequestTestJob::test_url_2());
1402 MakeTestRequest(0, 3, net::URLRequestTestJob::test_url_3()); 1403 MakeTestRequest(0, 3, net::URLRequestTestJob::test_url_3());
1403 MakeTestRequestWithResourceType(filter_.get(), 0, 4, 1404 MakeTestRequestWithResourceType(filter_.get(), 0, 4,
1404 net::URLRequestTestJob::test_url_4(), 1405 net::URLRequestTestJob::test_url_4(),
1405 RESOURCE_TYPE_PREFETCH); // detachable type 1406 RESOURCE_TYPE_PREFETCH); // detachable type
1406 MakeTestRequest(0, 5, net::URLRequestTestJob::test_url_redirect_to_url_2()); 1407 MakeTestRequest(0, 5, net::URLRequestTestJob::test_url_redirect_to_url_2());
1407 1408
1408 // Finish the redirection 1409 // Finish the redirection
1409 ResourceHostMsg_FollowRedirect redirect_msg(5); 1410 ResourceHostMsg_FollowRedirect redirect_msg(5);
1410 host_.OnMessageReceived(redirect_msg, filter_.get()); 1411 OnMessageReceived(redirect_msg, filter_.get());
1411 base::RunLoop().RunUntilIdle(); 1412 base::RunLoop().RunUntilIdle();
1412 1413
1413 // flush all the pending requests 1414 // flush all the pending requests
1414 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} 1415 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {}
1415 1416
1416 // sorts out all the messages we saw by request 1417 // sorts out all the messages we saw by request
1417 ResourceIPCAccumulator::ClassifiedMessages msgs; 1418 ResourceIPCAccumulator::ClassifiedMessages msgs;
1418 accum_.GetClassifiedMessages(&msgs); 1419 accum_.GetClassifiedMessages(&msgs);
1419 1420
1420 // there are five requests, so we should have gotten them classified as such 1421 // there are five requests, so we should have gotten them classified as such
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
1484 1485
1485 TEST_P(ResourceDispatcherHostTest, DownloadToNetworkCache) { 1486 TEST_P(ResourceDispatcherHostTest, DownloadToNetworkCache) {
1486 // Normal request. 1487 // Normal request.
1487 MakeTestRequest(0, 1, net::URLRequestTestJob::test_url_2()); 1488 MakeTestRequest(0, 1, net::URLRequestTestJob::test_url_2());
1488 1489
1489 // Cache-only request. 1490 // Cache-only request.
1490 ResourceRequest request_to_cache = CreateResourceRequest( 1491 ResourceRequest request_to_cache = CreateResourceRequest(
1491 "GET", RESOURCE_TYPE_IMAGE, net::URLRequestTestJob::test_url_3()); 1492 "GET", RESOURCE_TYPE_IMAGE, net::URLRequestTestJob::test_url_3());
1492 request_to_cache.download_to_network_cache_only = true; 1493 request_to_cache.download_to_network_cache_only = true;
1493 ResourceHostMsg_RequestResource msg_to_cache(0, 2, request_to_cache); 1494 ResourceHostMsg_RequestResource msg_to_cache(0, 2, request_to_cache);
1494 host_.OnMessageReceived(msg_to_cache, filter_.get()); 1495 OnMessageReceived(msg_to_cache, filter_.get());
1495 1496
1496 KickOffRequest(); 1497 KickOffRequest();
1497 1498
1498 // The handler for the cache-only request should have been detached now. 1499 // The handler for the cache-only request should have been detached now.
1499 GlobalRequestID global_request_id(filter_->child_id(), 2); 1500 GlobalRequestID global_request_id(filter_->child_id(), 2);
1500 ResourceRequestInfoImpl* info = ResourceRequestInfoImpl::ForRequest( 1501 ResourceRequestInfoImpl* info = ResourceRequestInfoImpl::ForRequest(
1501 host_.GetURLRequest(global_request_id)); 1502 host_.GetURLRequest(global_request_id));
1502 ASSERT_TRUE(info->detachable_handler()->is_detached()); 1503 ASSERT_TRUE(info->detachable_handler()->is_detached());
1503 1504
1504 // Flush all the pending requests. 1505 // Flush all the pending requests.
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
1571 } 1572 }
1572 1573
1573 TEST_P(ResourceDispatcherHostTest, SyncLoadSuccess) { 1574 TEST_P(ResourceDispatcherHostTest, SyncLoadSuccess) {
1574 ResourceRequest request = CreateResourceRequest( 1575 ResourceRequest request = CreateResourceRequest(
1575 "GET", RESOURCE_TYPE_XHR, net::URLRequestTestJob::test_url_1()); 1576 "GET", RESOURCE_TYPE_XHR, net::URLRequestTestJob::test_url_1());
1576 request.priority = net::MAXIMUM_PRIORITY; 1577 request.priority = net::MAXIMUM_PRIORITY;
1577 1578
1578 // Successful sync load. 1579 // Successful sync load.
1579 std::tuple<SyncLoadResult> result; 1580 std::tuple<SyncLoadResult> result;
1580 ResourceHostMsg_SyncLoad sync_load_msg(0, 1, request, &std::get<0>(result)); 1581 ResourceHostMsg_SyncLoad sync_load_msg(0, 1, request, &std::get<0>(result));
1581 host_.OnMessageReceived(sync_load_msg, filter_.get()); 1582 OnMessageReceived(sync_load_msg, filter_.get());
1582 base::RunLoop().RunUntilIdle(); 1583 base::RunLoop().RunUntilIdle();
1583 1584
1584 const IPC::Message* reply = accum_.GetReply(sync_load_msg); 1585 const IPC::Message* reply = accum_.GetReply(sync_load_msg);
1585 ASSERT_TRUE(reply); 1586 ASSERT_TRUE(reply);
1586 1587
1587 ASSERT_TRUE(ResourceHostMsg_SyncLoad::ReadReplyParam(reply, &result)); 1588 ASSERT_TRUE(ResourceHostMsg_SyncLoad::ReadReplyParam(reply, &result));
1588 EXPECT_EQ(net::OK, std::get<0>(result).error_code); 1589 EXPECT_EQ(net::OK, std::get<0>(result).error_code);
1589 } 1590 }
1590 1591
1591 TEST_P(ResourceDispatcherHostTest, SyncLoadError) { 1592 TEST_P(ResourceDispatcherHostTest, SyncLoadError) {
1592 ResourceRequest request = CreateResourceRequest( 1593 ResourceRequest request = CreateResourceRequest(
1593 "GET", RESOURCE_TYPE_XHR, net::URLRequestTestJob::test_url_error()); 1594 "GET", RESOURCE_TYPE_XHR, net::URLRequestTestJob::test_url_error());
1594 request.priority = net::MAXIMUM_PRIORITY; 1595 request.priority = net::MAXIMUM_PRIORITY;
1595 1596
1596 // Failued sync load. 1597 // Failued sync load.
1597 std::tuple<SyncLoadResult> result; 1598 std::tuple<SyncLoadResult> result;
1598 ResourceHostMsg_SyncLoad sync_load_msg(0, 1, request, &std::get<0>(result)); 1599 ResourceHostMsg_SyncLoad sync_load_msg(0, 1, request, &std::get<0>(result));
1599 host_.OnMessageReceived(sync_load_msg, filter_.get()); 1600 OnMessageReceived(sync_load_msg, filter_.get());
1600 base::RunLoop().RunUntilIdle(); 1601 base::RunLoop().RunUntilIdle();
1601 1602
1602 const IPC::Message* reply = accum_.GetReply(sync_load_msg); 1603 const IPC::Message* reply = accum_.GetReply(sync_load_msg);
1603 ASSERT_TRUE(reply); 1604 ASSERT_TRUE(reply);
1604 1605
1605 ASSERT_TRUE(ResourceHostMsg_SyncLoad::ReadReplyParam(reply, &result)); 1606 ASSERT_TRUE(ResourceHostMsg_SyncLoad::ReadReplyParam(reply, &result));
1606 EXPECT_EQ(net::ERR_INVALID_URL, std::get<0>(result).error_code); 1607 EXPECT_EQ(net::ERR_INVALID_URL, std::get<0>(result).error_code);
1607 } 1608 }
1608 1609
1609 TEST_P(ResourceDispatcherHostTest, SyncLoadCancel) { 1610 TEST_P(ResourceDispatcherHostTest, SyncLoadCancel) {
1610 ResourceRequest request = CreateResourceRequest( 1611 ResourceRequest request = CreateResourceRequest(
1611 "GET", RESOURCE_TYPE_XHR, net::URLRequestTestJob::test_url_1()); 1612 "GET", RESOURCE_TYPE_XHR, net::URLRequestTestJob::test_url_1());
1612 request.priority = net::MAXIMUM_PRIORITY; 1613 request.priority = net::MAXIMUM_PRIORITY;
1613 1614
1614 // Cancelled sync load. 1615 // Cancelled sync load.
1615 SyncLoadResult result; 1616 SyncLoadResult result;
1616 ResourceHostMsg_SyncLoad sync_load_msg(0, 1, request, &result); 1617 ResourceHostMsg_SyncLoad sync_load_msg(0, 1, request, &result);
1617 1618
1618 host_.OnMessageReceived(sync_load_msg, filter_.get()); 1619 OnMessageReceived(sync_load_msg, filter_.get());
1619 host_.CancelRequestsForProcess(filter_->child_id()); 1620 host_.CancelRequestsForProcess(filter_->child_id());
1620 base::RunLoop().RunUntilIdle(); 1621 base::RunLoop().RunUntilIdle();
1621 1622
1622 const IPC::Message* reply = accum_.GetReply(sync_load_msg); 1623 const IPC::Message* reply = accum_.GetReply(sync_load_msg);
1623 ASSERT_TRUE(reply); 1624 ASSERT_TRUE(reply);
1624 ASSERT_TRUE(reply->is_reply_error()); 1625 ASSERT_TRUE(reply->is_reply_error());
1625 } 1626 }
1626 1627
1627 // If the filter has disappeared then detachable resources should continue to 1628 // If the filter has disappeared then detachable resources should continue to
1628 // load. 1629 // load.
1629 TEST_P(ResourceDispatcherHostTest, DeletedFilterDetached) { 1630 TEST_P(ResourceDispatcherHostTest, DeletedFilterDetached) {
1630 // test_url_1's data is available synchronously, so use 2 and 3. 1631 // test_url_1's data is available synchronously, so use 2 and 3.
1631 ResourceRequest request_prefetch = CreateResourceRequest( 1632 ResourceRequest request_prefetch = CreateResourceRequest(
1632 "GET", RESOURCE_TYPE_PREFETCH, net::URLRequestTestJob::test_url_2()); 1633 "GET", RESOURCE_TYPE_PREFETCH, net::URLRequestTestJob::test_url_2());
1633 ResourceRequest request_ping = CreateResourceRequest( 1634 ResourceRequest request_ping = CreateResourceRequest(
1634 "GET", RESOURCE_TYPE_PING, net::URLRequestTestJob::test_url_3()); 1635 "GET", RESOURCE_TYPE_PING, net::URLRequestTestJob::test_url_3());
1635 1636
1636 ResourceHostMsg_RequestResource msg_prefetch(0, 1, request_prefetch); 1637 ResourceHostMsg_RequestResource msg_prefetch(0, 1, request_prefetch);
1637 host_.OnMessageReceived(msg_prefetch, filter_.get()); 1638 OnMessageReceived(msg_prefetch, filter_.get());
1638 ResourceHostMsg_RequestResource msg_ping(0, 2, request_ping); 1639 ResourceHostMsg_RequestResource msg_ping(0, 2, request_ping);
1639 host_.OnMessageReceived(msg_ping, filter_.get()); 1640 OnMessageReceived(msg_ping, filter_.get());
1640 1641
1641 // Remove the filter before processing the requests by simulating channel 1642 // Remove the filter before processing the requests by simulating channel
1642 // closure. 1643 // closure.
1643 ResourceRequestInfoImpl* info_prefetch = ResourceRequestInfoImpl::ForRequest( 1644 ResourceRequestInfoImpl* info_prefetch = ResourceRequestInfoImpl::ForRequest(
1644 host_.GetURLRequest(GlobalRequestID(filter_->child_id(), 1))); 1645 host_.GetURLRequest(GlobalRequestID(filter_->child_id(), 1)));
1645 ResourceRequestInfoImpl* info_ping = ResourceRequestInfoImpl::ForRequest( 1646 ResourceRequestInfoImpl* info_ping = ResourceRequestInfoImpl::ForRequest(
1646 host_.GetURLRequest(GlobalRequestID(filter_->child_id(), 2))); 1647 host_.GetURLRequest(GlobalRequestID(filter_->child_id(), 2)));
1647 DCHECK_EQ(filter_.get(), info_prefetch->filter()); 1648 DCHECK_EQ(filter_.get(), info_prefetch->requester_info().filter());
1648 DCHECK_EQ(filter_.get(), info_ping->filter()); 1649 DCHECK_EQ(filter_.get(), info_ping->requester_info().filter());
1649 filter_->OnChannelClosing(); 1650 filter_->OnChannelClosing();
1650 info_prefetch->filter_.reset();
1651 info_ping->filter_.reset();
1652 1651
1653 // From the renderer's perspective, the requests were cancelled. 1652 // From the renderer's perspective, the requests were cancelled.
1654 ResourceIPCAccumulator::ClassifiedMessages msgs; 1653 ResourceIPCAccumulator::ClassifiedMessages msgs;
1655 accum_.GetClassifiedMessages(&msgs); 1654 accum_.GetClassifiedMessages(&msgs);
1656 ASSERT_EQ(2U, msgs.size()); 1655 ASSERT_EQ(2U, msgs.size());
1657 CheckRequestCompleteErrorCode(msgs[0][0], net::ERR_ABORTED); 1656 CheckRequestCompleteErrorCode(msgs[0][0], net::ERR_ABORTED);
1658 CheckRequestCompleteErrorCode(msgs[1][0], net::ERR_ABORTED); 1657 CheckRequestCompleteErrorCode(msgs[1][0], net::ERR_ABORTED);
1659 1658
1660 // But it continues detached. 1659 // But it continues detached.
1661 EXPECT_EQ(2, host_.pending_requests()); 1660 EXPECT_EQ(2, host_.pending_requests());
(...skipping 15 matching lines...) Expand all
1677 } 1676 }
1678 1677
1679 // If the filter has disappeared (original process dies) then detachable 1678 // If the filter has disappeared (original process dies) then detachable
1680 // resources should continue to load, even when redirected. 1679 // resources should continue to load, even when redirected.
1681 TEST_P(ResourceDispatcherHostTest, DeletedFilterDetachedRedirect) { 1680 TEST_P(ResourceDispatcherHostTest, DeletedFilterDetachedRedirect) {
1682 ResourceRequest request = CreateResourceRequest( 1681 ResourceRequest request = CreateResourceRequest(
1683 "GET", RESOURCE_TYPE_PREFETCH, 1682 "GET", RESOURCE_TYPE_PREFETCH,
1684 net::URLRequestTestJob::test_url_redirect_to_url_2()); 1683 net::URLRequestTestJob::test_url_redirect_to_url_2());
1685 1684
1686 ResourceHostMsg_RequestResource msg(0, 1, request); 1685 ResourceHostMsg_RequestResource msg(0, 1, request);
1687 host_.OnMessageReceived(msg, filter_.get()); 1686 OnMessageReceived(msg, filter_.get());
1688 1687
1689 // Remove the filter before processing the request by simulating channel 1688 // Remove the filter before processing the request by simulating channel
1690 // closure. 1689 // closure.
1691 GlobalRequestID global_request_id(filter_->child_id(), 1); 1690 GlobalRequestID global_request_id(filter_->child_id(), 1);
1692 ResourceRequestInfoImpl* info = ResourceRequestInfoImpl::ForRequest( 1691 ResourceRequestInfoImpl* info = ResourceRequestInfoImpl::ForRequest(
1693 host_.GetURLRequest(global_request_id)); 1692 host_.GetURLRequest(global_request_id));
1694 info->filter_->OnChannelClosing(); 1693 info->requester_info().filter()->OnChannelClosing();
1695 info->filter_.reset();
1696 1694
1697 // From the renderer's perspective, the request was cancelled. 1695 // From the renderer's perspective, the request was cancelled.
1698 ResourceIPCAccumulator::ClassifiedMessages msgs; 1696 ResourceIPCAccumulator::ClassifiedMessages msgs;
1699 accum_.GetClassifiedMessages(&msgs); 1697 accum_.GetClassifiedMessages(&msgs);
1700 ASSERT_EQ(1U, msgs.size()); 1698 ASSERT_EQ(1U, msgs.size());
1701 CheckRequestCompleteErrorCode(msgs[0][0], net::ERR_ABORTED); 1699 CheckRequestCompleteErrorCode(msgs[0][0], net::ERR_ABORTED);
1702 1700
1703 // But it continues detached. 1701 // But it continues detached.
1704 EXPECT_EQ(1, host_.pending_requests()); 1702 EXPECT_EQ(1, host_.pending_requests());
1705 EXPECT_TRUE(info->detachable_handler()->is_detached()); 1703 EXPECT_TRUE(info->detachable_handler()->is_detached());
(...skipping 892 matching lines...) Expand 10 before | Expand all | Expand 10 after
2598 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id, 2596 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id,
2599 GURL("http://example.com/blah"), 2597 GURL("http://example.com/blah"),
2600 RESOURCE_TYPE_MAIN_FRAME); 2598 RESOURCE_TYPE_MAIN_FRAME);
2601 // Return some data so that the request is identified as a download 2599 // Return some data so that the request is identified as a download
2602 // and the proper resource handlers are created. 2600 // and the proper resource handlers are created.
2603 EXPECT_TRUE(net::URLRequestTestJob::ProcessOnePendingMessage()); 2601 EXPECT_TRUE(net::URLRequestTestJob::ProcessOnePendingMessage());
2604 base::RunLoop().RunUntilIdle(); 2602 base::RunLoop().RunUntilIdle();
2605 2603
2606 // And now simulate a cancellation coming from the renderer. 2604 // And now simulate a cancellation coming from the renderer.
2607 ResourceHostMsg_CancelRequest msg(request_id); 2605 ResourceHostMsg_CancelRequest msg(request_id);
2608 host_.OnMessageReceived(msg, filter_.get()); 2606 OnMessageReceived(msg, filter_.get());
2609 2607
2610 // Since the request had already started processing as a download, 2608 // Since the request had already started processing as a download,
2611 // the cancellation above should have been ignored and the request 2609 // the cancellation above should have been ignored and the request
2612 // should still be alive. 2610 // should still be alive.
2613 EXPECT_EQ(1, host_.pending_requests()); 2611 EXPECT_EQ(1, host_.pending_requests());
2614 2612
2615 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} 2613 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {}
2616 base::RunLoop().RunUntilIdle(); 2614 base::RunLoop().RunUntilIdle();
2617 } 2615 }
2618 2616
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
2674 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id, 2672 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id,
2675 download_url, RESOURCE_TYPE_MAIN_FRAME); 2673 download_url, RESOURCE_TYPE_MAIN_FRAME);
2676 2674
2677 // Return some data so that the request is identified as a download 2675 // Return some data so that the request is identified as a download
2678 // and the proper resource handlers are created. 2676 // and the proper resource handlers are created.
2679 EXPECT_TRUE(net::URLRequestTestJob::ProcessOnePendingMessage()); 2677 EXPECT_TRUE(net::URLRequestTestJob::ProcessOnePendingMessage());
2680 base::RunLoop().RunUntilIdle(); 2678 base::RunLoop().RunUntilIdle();
2681 2679
2682 // And now simulate a cancellation coming from the renderer. 2680 // And now simulate a cancellation coming from the renderer.
2683 ResourceHostMsg_CancelRequest msg(request_id); 2681 ResourceHostMsg_CancelRequest msg(request_id);
2684 host_.OnMessageReceived(msg, filter_.get()); 2682 OnMessageReceived(msg, filter_.get());
2685 2683
2686 // Since the request had already started processing as a download, 2684 // Since the request had already started processing as a download,
2687 // the cancellation above should have been ignored and the request 2685 // the cancellation above should have been ignored and the request
2688 // should still be alive. 2686 // should still be alive.
2689 EXPECT_EQ(1, host_.pending_requests()); 2687 EXPECT_EQ(1, host_.pending_requests());
2690 2688
2691 // Cancelling by other methods shouldn't work either. 2689 // Cancelling by other methods shouldn't work either.
2692 host_.CancelRequestsForProcess(render_view_id); 2690 host_.CancelRequestsForProcess(render_view_id);
2693 EXPECT_EQ(1, host_.pending_requests()); 2691 EXPECT_EQ(1, host_.pending_requests());
2694 2692
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
2751 2749
2752 MakeWebContentsAssociatedTestRequestWithResourceType( 2750 MakeWebContentsAssociatedTestRequestWithResourceType(
2753 request_id, GURL("http://example.com/blah"), RESOURCE_TYPE_MAIN_FRAME); 2751 request_id, GURL("http://example.com/blah"), RESOURCE_TYPE_MAIN_FRAME);
2754 2752
2755 GlobalRequestID global_request_id(web_contents_filter_->child_id(), 2753 GlobalRequestID global_request_id(web_contents_filter_->child_id(),
2756 request_id); 2754 request_id);
2757 host_.MarkAsTransferredNavigation(global_request_id, base::Closure()); 2755 host_.MarkAsTransferredNavigation(global_request_id, base::Closure());
2758 2756
2759 // And now simulate a cancellation coming from the renderer. 2757 // And now simulate a cancellation coming from the renderer.
2760 ResourceHostMsg_CancelRequest msg(request_id); 2758 ResourceHostMsg_CancelRequest msg(request_id);
2761 host_.OnMessageReceived(msg, web_contents_filter_.get()); 2759 OnMessageReceived(msg, web_contents_filter_.get());
2762 2760
2763 // Since the request is marked as being transferred, 2761 // Since the request is marked as being transferred,
2764 // the cancellation above should have been ignored and the request 2762 // the cancellation above should have been ignored and the request
2765 // should still be alive. 2763 // should still be alive.
2766 EXPECT_EQ(1, host_.pending_requests()); 2764 EXPECT_EQ(1, host_.pending_requests());
2767 2765
2768 // Cancelling by other methods shouldn't work either. 2766 // Cancelling by other methods shouldn't work either.
2769 host_.CancelRequestsForProcess(web_contents_->GetRoutingID()); 2767 host_.CancelRequestsForProcess(web_contents_->GetRoutingID());
2770 EXPECT_EQ(1, host_.pending_requests()); 2768 EXPECT_EQ(1, host_.pending_requests());
2771 2769
(...skipping 28 matching lines...) Expand all
2800 GURL("http://example.com/blah"), 2798 GURL("http://example.com/blah"),
2801 RESOURCE_TYPE_MAIN_FRAME); 2799 RESOURCE_TYPE_MAIN_FRAME);
2802 2800
2803 // Now that we're blocked on the redirect, update the response and unblock by 2801 // Now that we're blocked on the redirect, update the response and unblock by
2804 // telling the AsyncResourceHandler to follow the redirect. 2802 // telling the AsyncResourceHandler to follow the redirect.
2805 const std::string kResponseBody = "hello world"; 2803 const std::string kResponseBody = "hello world";
2806 SetResponse("HTTP/1.1 200 OK\n" 2804 SetResponse("HTTP/1.1 200 OK\n"
2807 "Content-Type: text/html\n\n", 2805 "Content-Type: text/html\n\n",
2808 kResponseBody); 2806 kResponseBody);
2809 ResourceHostMsg_FollowRedirect redirect_msg(request_id); 2807 ResourceHostMsg_FollowRedirect redirect_msg(request_id);
2810 host_.OnMessageReceived(redirect_msg, filter_.get()); 2808 OnMessageReceived(redirect_msg, filter_.get());
2811 base::RunLoop().RunUntilIdle(); 2809 base::RunLoop().RunUntilIdle();
2812 2810
2813 // Flush all the pending requests to get the response through the 2811 // Flush all the pending requests to get the response through the
2814 // MimeTypeResourceHandler. 2812 // MimeTypeResourceHandler.
2815 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} 2813 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {}
2816 2814
2817 // This second filter is used to emulate a second process. 2815 // This second filter is used to emulate a second process.
2818 scoped_refptr<ForwardingFilter> second_filter = MakeForwardingFilter(); 2816 scoped_refptr<ForwardingFilter> second_filter = MakeForwardingFilter();
2819 2817
2820 int new_render_view_id = 1; 2818 int new_render_view_id = 1;
2821 int new_request_id = 2; 2819 int new_request_id = 2;
2822 2820
2823 ResourceRequest request = CreateResourceRequest( 2821 ResourceRequest request = CreateResourceRequest(
2824 "GET", RESOURCE_TYPE_MAIN_FRAME, GURL("http://other.com/blech")); 2822 "GET", RESOURCE_TYPE_MAIN_FRAME, GURL("http://other.com/blech"));
2825 request.transferred_request_child_id = filter_->child_id(); 2823 request.transferred_request_child_id = filter_->child_id();
2826 request.transferred_request_request_id = request_id; 2824 request.transferred_request_request_id = request_id;
2827 2825
2828 ResourceHostMsg_RequestResource transfer_request_msg( 2826 ResourceHostMsg_RequestResource transfer_request_msg(
2829 new_render_view_id, new_request_id, request); 2827 new_render_view_id, new_request_id, request);
2830 host_.OnMessageReceived(transfer_request_msg, second_filter.get()); 2828 OnMessageReceived(transfer_request_msg, second_filter.get());
2831 base::RunLoop().RunUntilIdle(); 2829 base::RunLoop().RunUntilIdle();
2832 2830
2833 // Check generated messages. 2831 // Check generated messages.
2834 ResourceIPCAccumulator::ClassifiedMessages msgs; 2832 ResourceIPCAccumulator::ClassifiedMessages msgs;
2835 accum_.GetClassifiedMessages(&msgs); 2833 accum_.GetClassifiedMessages(&msgs);
2836 2834
2837 ASSERT_EQ(2U, msgs.size()); 2835 ASSERT_EQ(2U, msgs.size());
2838 EXPECT_EQ(ResourceMsg_ReceivedRedirect::ID, msgs[0][0].type()); 2836 EXPECT_EQ(ResourceMsg_ReceivedRedirect::ID, msgs[0][0].type());
2839 CheckSuccessfulRequest(msgs[1], kResponseBody); 2837 CheckSuccessfulRequest(msgs[1], kResponseBody);
2840 2838
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
2889 // Transfer the first request. 2887 // Transfer the first request.
2890 int new_render_view_id = 1; 2888 int new_render_view_id = 1;
2891 int new_request_id = 5; 2889 int new_request_id = 5;
2892 ResourceRequest request = CreateResourceRequest( 2890 ResourceRequest request = CreateResourceRequest(
2893 "GET", RESOURCE_TYPE_MAIN_FRAME, GURL("http://example.com/blah")); 2891 "GET", RESOURCE_TYPE_MAIN_FRAME, GURL("http://example.com/blah"));
2894 request.transferred_request_child_id = filter_->child_id(); 2892 request.transferred_request_child_id = filter_->child_id();
2895 request.transferred_request_request_id = request_id; 2893 request.transferred_request_request_id = request_id;
2896 2894
2897 ResourceHostMsg_RequestResource transfer_request_msg( 2895 ResourceHostMsg_RequestResource transfer_request_msg(
2898 new_render_view_id, new_request_id, request); 2896 new_render_view_id, new_request_id, request);
2899 host_.OnMessageReceived(transfer_request_msg, second_filter.get()); 2897 OnMessageReceived(transfer_request_msg, second_filter.get());
2900 base::RunLoop().RunUntilIdle(); 2898 base::RunLoop().RunUntilIdle();
2901 2899
2902 // Transfer the second request. 2900 // Transfer the second request.
2903 int new_second_request_id = 6; 2901 int new_second_request_id = 6;
2904 ResourceRequest second_request = CreateResourceRequest( 2902 ResourceRequest second_request = CreateResourceRequest(
2905 "GET", RESOURCE_TYPE_MAIN_FRAME, GURL("http://example.com/foo")); 2903 "GET", RESOURCE_TYPE_MAIN_FRAME, GURL("http://example.com/foo"));
2906 request.transferred_request_child_id = filter_->child_id(); 2904 request.transferred_request_child_id = filter_->child_id();
2907 request.transferred_request_request_id = second_request_id; 2905 request.transferred_request_request_id = second_request_id;
2908 2906
2909 ResourceHostMsg_RequestResource second_transfer_request_msg( 2907 ResourceHostMsg_RequestResource second_transfer_request_msg(
2910 new_render_view_id, new_second_request_id, second_request); 2908 new_render_view_id, new_second_request_id, second_request);
2911 host_.OnMessageReceived(second_transfer_request_msg, second_filter.get()); 2909 OnMessageReceived(second_transfer_request_msg, second_filter.get());
2912 base::RunLoop().RunUntilIdle(); 2910 base::RunLoop().RunUntilIdle();
2913 2911
2914 // Check generated messages. 2912 // Check generated messages.
2915 ResourceIPCAccumulator::ClassifiedMessages msgs; 2913 ResourceIPCAccumulator::ClassifiedMessages msgs;
2916 accum_.GetClassifiedMessages(&msgs); 2914 accum_.GetClassifiedMessages(&msgs);
2917 2915
2918 ASSERT_EQ(2U, msgs.size()); 2916 ASSERT_EQ(2U, msgs.size());
2919 CheckSuccessfulRequest(msgs[0], kResponseBody); 2917 CheckSuccessfulRequest(msgs[0], kResponseBody);
2920 2918
2921 second_filter->OnChannelClosing(); 2919 second_filter->OnChannelClosing();
(...skipping 28 matching lines...) Expand all
2950 2948
2951 // Now that we're blocked on the redirect, update the response and unblock by 2949 // Now that we're blocked on the redirect, update the response and unblock by
2952 // telling the AsyncResourceHandler to follow the redirect. Use a text/plain 2950 // telling the AsyncResourceHandler to follow the redirect. Use a text/plain
2953 // MIME type, which causes MimeTypeResourceHandler to buffer it before the 2951 // MIME type, which causes MimeTypeResourceHandler to buffer it before the
2954 // transfer occurs. 2952 // transfer occurs.
2955 const std::string kResponseBody = "hello world"; 2953 const std::string kResponseBody = "hello world";
2956 SetResponse("HTTP/1.1 200 OK\n" 2954 SetResponse("HTTP/1.1 200 OK\n"
2957 "Content-Type: text/plain\n\n", 2955 "Content-Type: text/plain\n\n",
2958 kResponseBody); 2956 kResponseBody);
2959 ResourceHostMsg_FollowRedirect redirect_msg(request_id); 2957 ResourceHostMsg_FollowRedirect redirect_msg(request_id);
2960 host_.OnMessageReceived(redirect_msg, filter_.get()); 2958 OnMessageReceived(redirect_msg, filter_.get());
2961 base::RunLoop().RunUntilIdle(); 2959 base::RunLoop().RunUntilIdle();
2962 2960
2963 // Flush all the pending requests to get the response through the 2961 // Flush all the pending requests to get the response through the
2964 // MimeTypeResourceHandler. 2962 // MimeTypeResourceHandler.
2965 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} 2963 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {}
2966 base::RunLoop().RunUntilIdle(); 2964 base::RunLoop().RunUntilIdle();
2967 2965
2968 // This second filter is used to emulate a second process. 2966 // This second filter is used to emulate a second process.
2969 scoped_refptr<ForwardingFilter> second_filter = MakeForwardingFilter(); 2967 scoped_refptr<ForwardingFilter> second_filter = MakeForwardingFilter();
2970 2968
2971 int new_render_view_id = 1; 2969 int new_render_view_id = 1;
2972 int new_request_id = 2; 2970 int new_request_id = 2;
2973 2971
2974 ResourceRequest request = CreateResourceRequest( 2972 ResourceRequest request = CreateResourceRequest(
2975 "GET", RESOURCE_TYPE_MAIN_FRAME, GURL("http://other.com/blech")); 2973 "GET", RESOURCE_TYPE_MAIN_FRAME, GURL("http://other.com/blech"));
2976 request.transferred_request_child_id = filter_->child_id(); 2974 request.transferred_request_child_id = filter_->child_id();
2977 request.transferred_request_request_id = request_id; 2975 request.transferred_request_request_id = request_id;
2978 2976
2979 ResourceHostMsg_RequestResource transfer_request_msg( 2977 ResourceHostMsg_RequestResource transfer_request_msg(
2980 new_render_view_id, new_request_id, request); 2978 new_render_view_id, new_request_id, request);
2981 host_.OnMessageReceived(transfer_request_msg, second_filter.get()); 2979 OnMessageReceived(transfer_request_msg, second_filter.get());
2982 base::RunLoop().RunUntilIdle(); 2980 base::RunLoop().RunUntilIdle();
2983 2981
2984 // Check generated messages. 2982 // Check generated messages.
2985 ResourceIPCAccumulator::ClassifiedMessages msgs; 2983 ResourceIPCAccumulator::ClassifiedMessages msgs;
2986 accum_.GetClassifiedMessages(&msgs); 2984 accum_.GetClassifiedMessages(&msgs);
2987 2985
2988 ASSERT_EQ(2U, msgs.size()); 2986 ASSERT_EQ(2U, msgs.size());
2989 EXPECT_EQ(ResourceMsg_ReceivedRedirect::ID, msgs[0][0].type()); 2987 EXPECT_EQ(ResourceMsg_ReceivedRedirect::ID, msgs[0][0].type());
2990 CheckSuccessfulRequest(msgs[1], kResponseBody); 2988 CheckSuccessfulRequest(msgs[1], kResponseBody);
2991 2989
(...skipping 25 matching lines...) Expand all
3017 // Create a first filter that can be deleted before the second one starts. 3015 // Create a first filter that can be deleted before the second one starts.
3018 { 3016 {
3019 scoped_refptr<ForwardingFilter> first_filter = MakeForwardingFilter(); 3017 scoped_refptr<ForwardingFilter> first_filter = MakeForwardingFilter();
3020 first_child_id = first_filter->child_id(); 3018 first_child_id = first_filter->child_id();
3021 3019
3022 ResourceRequest first_request = CreateResourceRequest( 3020 ResourceRequest first_request = CreateResourceRequest(
3023 "GET", RESOURCE_TYPE_MAIN_FRAME, GURL("http://example.com/blah")); 3021 "GET", RESOURCE_TYPE_MAIN_FRAME, GURL("http://example.com/blah"));
3024 3022
3025 ResourceHostMsg_RequestResource first_request_msg( 3023 ResourceHostMsg_RequestResource first_request_msg(
3026 render_view_id, request_id, first_request); 3024 render_view_id, request_id, first_request);
3027 host_.OnMessageReceived(first_request_msg, first_filter.get()); 3025 OnMessageReceived(first_request_msg, first_filter.get());
3028 base::RunLoop().RunUntilIdle(); 3026 base::RunLoop().RunUntilIdle();
3029 3027
3030 // Now that we're blocked on the redirect, update the response and unblock 3028 // Now that we're blocked on the redirect, update the response and unblock
3031 // by telling the AsyncResourceHandler to follow the redirect. 3029 // by telling the AsyncResourceHandler to follow the redirect.
3032 SetResponse("HTTP/1.1 200 OK\n" 3030 SetResponse("HTTP/1.1 200 OK\n"
3033 "Content-Type: text/html\n\n", 3031 "Content-Type: text/html\n\n",
3034 kResponseBody); 3032 kResponseBody);
3035 ResourceHostMsg_FollowRedirect redirect_msg(request_id); 3033 ResourceHostMsg_FollowRedirect redirect_msg(request_id);
3036 host_.OnMessageReceived(redirect_msg, first_filter.get()); 3034 OnMessageReceived(redirect_msg, first_filter.get());
3037 base::RunLoop().RunUntilIdle(); 3035 base::RunLoop().RunUntilIdle();
3038 3036
3039 // Flush all the pending requests to get the response through the 3037 // Flush all the pending requests to get the response through the
3040 // MimeTypeResourceHandler. 3038 // MimeTypeResourceHandler.
3041 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} 3039 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {}
3042 3040
3043 first_filter->OnChannelClosing(); 3041 first_filter->OnChannelClosing();
3044 } 3042 }
3045 // The first filter is now deleted, as if the child process died. 3043 // The first filter is now deleted, as if the child process died.
3046 3044
3047 // Make sure we don't hold onto the ResourceMessageFilter after it is deleted. 3045 // Make sure we don't hold onto the ResourceMessageFilter after it is deleted.
3048 GlobalRequestID first_global_request_id(first_child_id, request_id); 3046 GlobalRequestID first_global_request_id(first_child_id, request_id);
3049 3047
3050 // This second filter is used to emulate a second process. 3048 // This second filter is used to emulate a second process.
3051 scoped_refptr<ForwardingFilter> second_filter = MakeForwardingFilter(); 3049 scoped_refptr<ForwardingFilter> second_filter = MakeForwardingFilter();
3052 3050
3053 int new_render_view_id = 1; 3051 int new_render_view_id = 1;
3054 int new_request_id = 2; 3052 int new_request_id = 2;
3055 3053
3056 ResourceRequest request = CreateResourceRequest( 3054 ResourceRequest request = CreateResourceRequest(
3057 "GET", RESOURCE_TYPE_MAIN_FRAME, GURL("http://other.com/blech")); 3055 "GET", RESOURCE_TYPE_MAIN_FRAME, GURL("http://other.com/blech"));
3058 request.transferred_request_child_id = first_child_id; 3056 request.transferred_request_child_id = first_child_id;
3059 request.transferred_request_request_id = request_id; 3057 request.transferred_request_request_id = request_id;
3060 3058
3061 // For cleanup. 3059 // For cleanup.
3062 child_ids_.insert(second_filter->child_id()); 3060 child_ids_.insert(second_filter->child_id());
3063 ResourceHostMsg_RequestResource transfer_request_msg( 3061 ResourceHostMsg_RequestResource transfer_request_msg(
3064 new_render_view_id, new_request_id, request); 3062 new_render_view_id, new_request_id, request);
3065 host_.OnMessageReceived(transfer_request_msg, second_filter.get()); 3063 OnMessageReceived(transfer_request_msg, second_filter.get());
3066 base::RunLoop().RunUntilIdle(); 3064 base::RunLoop().RunUntilIdle();
3067 3065
3068 // Check generated messages. 3066 // Check generated messages.
3069 ResourceIPCAccumulator::ClassifiedMessages msgs; 3067 ResourceIPCAccumulator::ClassifiedMessages msgs;
3070 accum_.GetClassifiedMessages(&msgs); 3068 accum_.GetClassifiedMessages(&msgs);
3071 3069
3072 ASSERT_EQ(2U, msgs.size()); 3070 ASSERT_EQ(2U, msgs.size());
3073 EXPECT_EQ(ResourceMsg_ReceivedRedirect::ID, msgs[0][0].type()); 3071 EXPECT_EQ(ResourceMsg_ReceivedRedirect::ID, msgs[0][0].type());
3074 CheckSuccessfulRequest(msgs[1], kResponseBody); 3072 CheckSuccessfulRequest(msgs[1], kResponseBody);
3075 3073
(...skipping 21 matching lines...) Expand all
3097 HandleScheme("http"); 3095 HandleScheme("http");
3098 3096
3099 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id, 3097 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id,
3100 GURL("http://example.com/blah"), 3098 GURL("http://example.com/blah"),
3101 RESOURCE_TYPE_MAIN_FRAME); 3099 RESOURCE_TYPE_MAIN_FRAME);
3102 3100
3103 // Now that we're blocked on the redirect, simulate hitting another redirect. 3101 // Now that we're blocked on the redirect, simulate hitting another redirect.
3104 SetResponse("HTTP/1.1 302 Found\n" 3102 SetResponse("HTTP/1.1 302 Found\n"
3105 "Location: http://other.com/blerg\n\n"); 3103 "Location: http://other.com/blerg\n\n");
3106 ResourceHostMsg_FollowRedirect redirect_msg(request_id); 3104 ResourceHostMsg_FollowRedirect redirect_msg(request_id);
3107 host_.OnMessageReceived(redirect_msg, filter_.get()); 3105 OnMessageReceived(redirect_msg, filter_.get());
3108 base::RunLoop().RunUntilIdle(); 3106 base::RunLoop().RunUntilIdle();
3109 3107
3110 // Now that we're blocked on the second redirect, update the response and 3108 // Now that we're blocked on the second redirect, update the response and
3111 // unblock by telling the AsyncResourceHandler to follow the redirect. 3109 // unblock by telling the AsyncResourceHandler to follow the redirect.
3112 // Again, use text/plain to force MimeTypeResourceHandler to buffer before 3110 // Again, use text/plain to force MimeTypeResourceHandler to buffer before
3113 // the transfer. 3111 // the transfer.
3114 const std::string kResponseBody = "hello world"; 3112 const std::string kResponseBody = "hello world";
3115 SetResponse("HTTP/1.1 200 OK\n" 3113 SetResponse("HTTP/1.1 200 OK\n"
3116 "Content-Type: text/plain\n\n", 3114 "Content-Type: text/plain\n\n",
3117 kResponseBody); 3115 kResponseBody);
3118 ResourceHostMsg_FollowRedirect redirect_msg2(request_id); 3116 ResourceHostMsg_FollowRedirect redirect_msg2(request_id);
3119 host_.OnMessageReceived(redirect_msg2, filter_.get()); 3117 OnMessageReceived(redirect_msg2, filter_.get());
3120 base::RunLoop().RunUntilIdle(); 3118 base::RunLoop().RunUntilIdle();
3121 3119
3122 // Flush all the pending requests to get the response through the 3120 // Flush all the pending requests to get the response through the
3123 // MimeTypeResourceHandler. 3121 // MimeTypeResourceHandler.
3124 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} 3122 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {}
3125 base::RunLoop().RunUntilIdle(); 3123 base::RunLoop().RunUntilIdle();
3126 3124
3127 // This second filter is used to emulate a second process. 3125 // This second filter is used to emulate a second process.
3128 scoped_refptr<ForwardingFilter> second_filter = MakeForwardingFilter(); 3126 scoped_refptr<ForwardingFilter> second_filter = MakeForwardingFilter();
3129 3127
3130 int new_render_view_id = 1; 3128 int new_render_view_id = 1;
3131 int new_request_id = 2; 3129 int new_request_id = 2;
3132 3130
3133 ResourceRequest request = CreateResourceRequest( 3131 ResourceRequest request = CreateResourceRequest(
3134 "GET", RESOURCE_TYPE_MAIN_FRAME, GURL("http://other.com/blech")); 3132 "GET", RESOURCE_TYPE_MAIN_FRAME, GURL("http://other.com/blech"));
3135 request.transferred_request_child_id = filter_->child_id(); 3133 request.transferred_request_child_id = filter_->child_id();
3136 request.transferred_request_request_id = request_id; 3134 request.transferred_request_request_id = request_id;
3137 3135
3138 // For cleanup. 3136 // For cleanup.
3139 child_ids_.insert(second_filter->child_id()); 3137 child_ids_.insert(second_filter->child_id());
3140 ResourceHostMsg_RequestResource transfer_request_msg( 3138 ResourceHostMsg_RequestResource transfer_request_msg(
3141 new_render_view_id, new_request_id, request); 3139 new_render_view_id, new_request_id, request);
3142 host_.OnMessageReceived(transfer_request_msg, second_filter.get()); 3140 OnMessageReceived(transfer_request_msg, second_filter.get());
3143 3141
3144 // Verify that we update the ResourceRequestInfo. 3142 // Verify that we update the ResourceRequestInfo.
3145 GlobalRequestID global_request_id(second_filter->child_id(), new_request_id); 3143 GlobalRequestID global_request_id(second_filter->child_id(), new_request_id);
3146 const ResourceRequestInfoImpl* info = ResourceRequestInfoImpl::ForRequest( 3144 const ResourceRequestInfoImpl* info = ResourceRequestInfoImpl::ForRequest(
3147 host_.GetURLRequest(global_request_id)); 3145 host_.GetURLRequest(global_request_id));
3148 EXPECT_EQ(second_filter->child_id(), info->GetChildID()); 3146 EXPECT_EQ(second_filter->child_id(), info->GetChildID());
3149 EXPECT_EQ(new_render_view_id, info->GetRouteID()); 3147 EXPECT_EQ(new_render_view_id, info->GetRouteID());
3150 EXPECT_EQ(new_request_id, info->GetRequestID()); 3148 EXPECT_EQ(new_request_id, info->GetRequestID());
3151 EXPECT_EQ(second_filter.get(), info->filter()); 3149 EXPECT_EQ(second_filter.get(), info->requester_info().filter());
3152 3150
3153 // Let request complete. 3151 // Let request complete.
3154 base::RunLoop().RunUntilIdle(); 3152 base::RunLoop().RunUntilIdle();
3155 3153
3156 // Check generated messages. 3154 // Check generated messages.
3157 ResourceIPCAccumulator::ClassifiedMessages msgs; 3155 ResourceIPCAccumulator::ClassifiedMessages msgs;
3158 accum_.GetClassifiedMessages(&msgs); 3156 accum_.GetClassifiedMessages(&msgs);
3159 3157
3160 ASSERT_EQ(2U, msgs.size()); 3158 ASSERT_EQ(2U, msgs.size());
3161 EXPECT_EQ(ResourceMsg_ReceivedRedirect::ID, msgs[0][0].type()); 3159 EXPECT_EQ(ResourceMsg_ReceivedRedirect::ID, msgs[0][0].type());
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
3222 3220
3223 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id, 3221 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id,
3224 GURL("http://example.com/blah"), 3222 GURL("http://example.com/blah"),
3225 RESOURCE_TYPE_PREFETCH); 3223 RESOURCE_TYPE_PREFETCH);
3226 3224
3227 // Get a bit of data before cancelling. 3225 // Get a bit of data before cancelling.
3228 EXPECT_TRUE(net::URLRequestTestJob::ProcessOnePendingMessage()); 3226 EXPECT_TRUE(net::URLRequestTestJob::ProcessOnePendingMessage());
3229 3227
3230 // Simulate a cancellation coming from the renderer. 3228 // Simulate a cancellation coming from the renderer.
3231 ResourceHostMsg_CancelRequest msg(request_id); 3229 ResourceHostMsg_CancelRequest msg(request_id);
3232 host_.OnMessageReceived(msg, filter_.get()); 3230 OnMessageReceived(msg, filter_.get());
3233 3231
3234 EXPECT_EQ(1, host_.pending_requests()); 3232 EXPECT_EQ(1, host_.pending_requests());
3235 3233
3236 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} 3234 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {}
3237 3235
3238 // Sort all the messages we saw by request. 3236 // Sort all the messages we saw by request.
3239 ResourceIPCAccumulator::ClassifiedMessages msgs; 3237 ResourceIPCAccumulator::ClassifiedMessages msgs;
3240 accum_.GetClassifiedMessages(&msgs); 3238 accum_.GetClassifiedMessages(&msgs);
3241 3239
3242 EXPECT_EQ(4U, msgs[0].size()); 3240 EXPECT_EQ(4U, msgs[0].size());
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
3287 while (!complete) { 3285 while (!complete) {
3288 for (size_t i = 0; i < msgs[0].size(); ++i) { 3286 for (size_t i = 0; i < msgs[0].size(); ++i) {
3289 if (msgs[0][i].type() == ResourceMsg_RequestComplete::ID) { 3287 if (msgs[0][i].type() == ResourceMsg_RequestComplete::ID) {
3290 complete = true; 3288 complete = true;
3291 break; 3289 break;
3292 } 3290 }
3293 3291
3294 EXPECT_EQ(ResourceMsg_DataReceived::ID, msgs[0][i].type()); 3292 EXPECT_EQ(ResourceMsg_DataReceived::ID, msgs[0][i].type());
3295 3293
3296 ResourceHostMsg_DataReceived_ACK msg(1); 3294 ResourceHostMsg_DataReceived_ACK msg(1);
3297 host_.OnMessageReceived(msg, filter_.get()); 3295 OnMessageReceived(msg, filter_.get());
3298 } 3296 }
3299 3297
3300 base::RunLoop().RunUntilIdle(); 3298 base::RunLoop().RunUntilIdle();
3301 3299
3302 msgs.clear(); 3300 msgs.clear();
3303 accum_.GetClassifiedMessages(&msgs); 3301 accum_.GetClassifiedMessages(&msgs);
3304 } 3302 }
3305 } 3303 }
3306 3304
3307 // Flakyness of this test might indicate memory corruption issues with 3305 // Flakyness of this test might indicate memory corruption issues with
(...skipping 15 matching lines...) Expand all
3323 EXPECT_EQ(ResourceMsg_SetDataBuffer::ID, msgs[0][1].type()); 3321 EXPECT_EQ(ResourceMsg_SetDataBuffer::ID, msgs[0][1].type());
3324 for (size_t i = 2; i < msgs[0].size(); ++i) 3322 for (size_t i = 2; i < msgs[0].size(); ++i)
3325 EXPECT_EQ(ResourceMsg_DataReceived::ID, msgs[0][i].type()); 3323 EXPECT_EQ(ResourceMsg_DataReceived::ID, msgs[0][i].type());
3326 3324
3327 // NOTE: If we fail the above checks then it means that we probably didn't 3325 // NOTE: If we fail the above checks then it means that we probably didn't
3328 // load a big enough response to trigger the delay mechanism. 3326 // load a big enough response to trigger the delay mechanism.
3329 3327
3330 // Send some unexpected ACKs. 3328 // Send some unexpected ACKs.
3331 for (size_t i = 0; i < 128; ++i) { 3329 for (size_t i = 0; i < 128; ++i) {
3332 ResourceHostMsg_DataReceived_ACK msg(1); 3330 ResourceHostMsg_DataReceived_ACK msg(1);
3333 host_.OnMessageReceived(msg, filter_.get()); 3331 OnMessageReceived(msg, filter_.get());
3334 } 3332 }
3335 3333
3336 msgs[0].erase(msgs[0].begin()); 3334 msgs[0].erase(msgs[0].begin());
3337 msgs[0].erase(msgs[0].begin()); 3335 msgs[0].erase(msgs[0].begin());
3338 3336
3339 // ACK all DataReceived messages until we find a RequestComplete message. 3337 // ACK all DataReceived messages until we find a RequestComplete message.
3340 bool complete = false; 3338 bool complete = false;
3341 while (!complete) { 3339 while (!complete) {
3342 for (size_t i = 0; i < msgs[0].size(); ++i) { 3340 for (size_t i = 0; i < msgs[0].size(); ++i) {
3343 if (msgs[0][i].type() == ResourceMsg_RequestComplete::ID) { 3341 if (msgs[0][i].type() == ResourceMsg_RequestComplete::ID) {
3344 complete = true; 3342 complete = true;
3345 break; 3343 break;
3346 } 3344 }
3347 3345
3348 EXPECT_EQ(ResourceMsg_DataReceived::ID, msgs[0][i].type()); 3346 EXPECT_EQ(ResourceMsg_DataReceived::ID, msgs[0][i].type());
3349 3347
3350 ResourceHostMsg_DataReceived_ACK msg(1); 3348 ResourceHostMsg_DataReceived_ACK msg(1);
3351 host_.OnMessageReceived(msg, filter_.get()); 3349 OnMessageReceived(msg, filter_.get());
3352 } 3350 }
3353 3351
3354 base::RunLoop().RunUntilIdle(); 3352 base::RunLoop().RunUntilIdle();
3355 3353
3356 msgs.clear(); 3354 msgs.clear();
3357 accum_.GetClassifiedMessages(&msgs); 3355 accum_.GetClassifiedMessages(&msgs);
3358 } 3356 }
3359 } 3357 }
3360 3358
3361 // Tests the dispatcher host's temporary file management. 3359 // Tests the dispatcher host's temporary file management.
(...skipping 14 matching lines...) Expand all
3376 3374
3377 // Register it for a resource request. 3375 // Register it for a resource request.
3378 host_.RegisterDownloadedTempFile(filter_->child_id(), kRequestID, file_path); 3376 host_.RegisterDownloadedTempFile(filter_->child_id(), kRequestID, file_path);
3379 3377
3380 // Should be readable now. 3378 // Should be readable now.
3381 EXPECT_TRUE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile( 3379 EXPECT_TRUE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile(
3382 filter_->child_id(), file_path)); 3380 filter_->child_id(), file_path));
3383 3381
3384 // The child releases from the request. 3382 // The child releases from the request.
3385 ResourceHostMsg_ReleaseDownloadedFile release_msg(kRequestID); 3383 ResourceHostMsg_ReleaseDownloadedFile release_msg(kRequestID);
3386 host_.OnMessageReceived(release_msg, filter_.get()); 3384 OnMessageReceived(release_msg, filter_.get());
3387 3385
3388 // Still readable because there is another reference to the file. (The child 3386 // Still readable because there is another reference to the file. (The child
3389 // may take additional blob references.) 3387 // may take additional blob references.)
3390 EXPECT_TRUE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile( 3388 EXPECT_TRUE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile(
3391 filter_->child_id(), file_path)); 3389 filter_->child_id(), file_path));
3392 3390
3393 // Release extra references and wait for the file to be deleted. (This relies 3391 // Release extra references and wait for the file to be deleted. (This relies
3394 // on the delete happening on the FILE thread which is mapped to main thread 3392 // on the delete happening on the FILE thread which is mapped to main thread
3395 // in this test.) 3393 // in this test.)
3396 deletable_file = NULL; 3394 deletable_file = NULL;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
3432 filter_->child_id(), file_path)); 3430 filter_->child_id(), file_path));
3433 EXPECT_FALSE(base::PathExists(file_path)); 3431 EXPECT_FALSE(base::PathExists(file_path));
3434 } 3432 }
3435 3433
3436 TEST_P(ResourceDispatcherHostTest, DownloadToFile) { 3434 TEST_P(ResourceDispatcherHostTest, DownloadToFile) {
3437 // Make a request which downloads to file. 3435 // Make a request which downloads to file.
3438 ResourceRequest request = CreateResourceRequest( 3436 ResourceRequest request = CreateResourceRequest(
3439 "GET", RESOURCE_TYPE_SUB_RESOURCE, net::URLRequestTestJob::test_url_1()); 3437 "GET", RESOURCE_TYPE_SUB_RESOURCE, net::URLRequestTestJob::test_url_1());
3440 request.download_to_file = true; 3438 request.download_to_file = true;
3441 ResourceHostMsg_RequestResource request_msg(0, 1, request); 3439 ResourceHostMsg_RequestResource request_msg(0, 1, request);
3442 host_.OnMessageReceived(request_msg, filter_.get()); 3440 OnMessageReceived(request_msg, filter_.get());
3443 3441
3444 // Running the message loop until idle does not work because 3442 // Running the message loop until idle does not work because
3445 // RedirectToFileResourceHandler posts things to base::WorkerPool. Instead, 3443 // RedirectToFileResourceHandler posts things to base::WorkerPool. Instead,
3446 // wait for the ResourceMsg_RequestComplete to go out. Then run the event loop 3444 // wait for the ResourceMsg_RequestComplete to go out. Then run the event loop
3447 // until idle so the loader is gone. 3445 // until idle so the loader is gone.
3448 WaitForRequestComplete(); 3446 WaitForRequestComplete();
3449 base::RunLoop().RunUntilIdle(); 3447 base::RunLoop().RunUntilIdle();
3450 EXPECT_EQ(0, host_.pending_requests()); 3448 EXPECT_EQ(0, host_.pending_requests());
3451 3449
3452 ResourceIPCAccumulator::ClassifiedMessages msgs; 3450 ResourceIPCAccumulator::ClassifiedMessages msgs;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
3487 EXPECT_EQ(net::URLRequestTestJob::test_data_1(), contents); 3485 EXPECT_EQ(net::URLRequestTestJob::test_data_1(), contents);
3488 3486
3489 // The file should be readable by the child. 3487 // The file should be readable by the child.
3490 EXPECT_TRUE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile( 3488 EXPECT_TRUE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile(
3491 filter_->child_id(), response_head.download_file_path)); 3489 filter_->child_id(), response_head.download_file_path));
3492 3490
3493 // When the renderer releases the file, it should be deleted. Again, 3491 // When the renderer releases the file, it should be deleted. Again,
3494 // RunUntilIdle doesn't work because base::WorkerPool is involved. 3492 // RunUntilIdle doesn't work because base::WorkerPool is involved.
3495 ShareableFileReleaseWaiter waiter(response_head.download_file_path); 3493 ShareableFileReleaseWaiter waiter(response_head.download_file_path);
3496 ResourceHostMsg_ReleaseDownloadedFile release_msg(1); 3494 ResourceHostMsg_ReleaseDownloadedFile release_msg(1);
3497 host_.OnMessageReceived(release_msg, filter_.get()); 3495 OnMessageReceived(release_msg, filter_.get());
3498 waiter.Wait(); 3496 waiter.Wait();
3499 // The release callback runs before the delete is scheduled, so pump the 3497 // The release callback runs before the delete is scheduled, so pump the
3500 // message loop for the delete itself. (This relies on the delete happening on 3498 // message loop for the delete itself. (This relies on the delete happening on
3501 // the FILE thread which is mapped to main thread in this test.) 3499 // the FILE thread which is mapped to main thread in this test.)
3502 base::RunLoop().RunUntilIdle(); 3500 base::RunLoop().RunUntilIdle();
3503 3501
3504 EXPECT_FALSE(base::PathExists(response_head.download_file_path)); 3502 EXPECT_FALSE(base::PathExists(response_head.download_file_path));
3505 EXPECT_FALSE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile( 3503 EXPECT_FALSE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile(
3506 filter_->child_id(), response_head.download_file_path)); 3504 filter_->child_id(), response_head.download_file_path));
3507 } 3505 }
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
3713 MakeTestRequestWithPriority(0, 2, net::IDLE); 3711 MakeTestRequestWithPriority(0, 2, net::IDLE);
3714 MakeTestRequestWithPriority(0, 3, net::IDLE); 3712 MakeTestRequestWithPriority(0, 3, net::IDLE);
3715 3713
3716 KickOffRequest(); 3714 KickOffRequest();
3717 3715
3718 EXPECT_EQ(2, job_factory_->url_request_jobs_created_count()); 3716 EXPECT_EQ(2, job_factory_->url_request_jobs_created_count());
3719 3717
3720 // Increase the priority of the second idle priority request. It was 3718 // Increase the priority of the second idle priority request. It was
3721 // scheduled later, so it is not currently running. 3719 // scheduled later, so it is not currently running.
3722 ResourceHostMsg_DidChangePriority priority_msg(3, net::MAXIMUM_PRIORITY, 0); 3720 ResourceHostMsg_DidChangePriority priority_msg(3, net::MAXIMUM_PRIORITY, 0);
3723 host_.OnMessageReceived(priority_msg, filter_.get()); 3721 OnMessageReceived(priority_msg, filter_.get());
3724 base::RunLoop().RunUntilIdle(); 3722 base::RunLoop().RunUntilIdle();
3725 3723
3726 EXPECT_EQ(3, job_factory_->url_request_jobs_created_count()); 3724 EXPECT_EQ(3, job_factory_->url_request_jobs_created_count());
3727 3725
3728 // Cleanup. 3726 // Cleanup.
3729 host_.OnRenderViewHostDeleted(filter_->child_id(), // child_id 3727 host_.OnRenderViewHostDeleted(filter_->child_id(), // child_id
3730 0); // route_id 3728 0); // route_id
3731 } 3729 }
3732 3730
3733 // Confirm that resource response started notifications for downloads are not 3731 // Confirm that resource response started notifications for downloads are not
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
3802 } // namespace 3800 } // namespace
3803 3801
3804 TEST_P(ResourceDispatcherHostTest, SyncLoadWithMojoSuccess) { 3802 TEST_P(ResourceDispatcherHostTest, SyncLoadWithMojoSuccess) {
3805 ResourceRequest request = CreateResourceRequest( 3803 ResourceRequest request = CreateResourceRequest(
3806 "GET", RESOURCE_TYPE_XHR, net::URLRequestTestJob::test_url_1()); 3804 "GET", RESOURCE_TYPE_XHR, net::URLRequestTestJob::test_url_1());
3807 request.priority = net::MAXIMUM_PRIORITY; 3805 request.priority = net::MAXIMUM_PRIORITY;
3808 3806
3809 bool called = false; 3807 bool called = false;
3810 bool was_null = false; 3808 bool was_null = false;
3811 SyncLoadResult result; 3809 SyncLoadResult result;
3812 host_.OnSyncLoadWithMojo(0, 1, request, filter_.get(), 3810 host_.OnSyncLoadWithMojo(
3813 base::Bind(&StoreSyncLoadResult, 3811 GetResourceRequesterInfo(filter_.get()), 0, 1, request,
3814 &called, &was_null, &result)); 3812 base::Bind(&StoreSyncLoadResult, &called, &was_null, &result));
3815 base::RunLoop().RunUntilIdle(); 3813 base::RunLoop().RunUntilIdle();
3816 EXPECT_TRUE(called); 3814 EXPECT_TRUE(called);
3817 EXPECT_FALSE(was_null); 3815 EXPECT_FALSE(was_null);
3818 EXPECT_EQ(net::OK, result.error_code); 3816 EXPECT_EQ(net::OK, result.error_code);
3819 } 3817 }
3820 3818
3821 TEST_P(ResourceDispatcherHostTest, SyncLoadWithMojoError) { 3819 TEST_P(ResourceDispatcherHostTest, SyncLoadWithMojoError) {
3822 ResourceRequest request = CreateResourceRequest( 3820 ResourceRequest request = CreateResourceRequest(
3823 "GET", RESOURCE_TYPE_XHR, net::URLRequestTestJob::test_url_error()); 3821 "GET", RESOURCE_TYPE_XHR, net::URLRequestTestJob::test_url_error());
3824 request.priority = net::MAXIMUM_PRIORITY; 3822 request.priority = net::MAXIMUM_PRIORITY;
3825 3823
3826 bool called = false; 3824 bool called = false;
3827 bool was_null = false; 3825 bool was_null = false;
3828 SyncLoadResult result; 3826 SyncLoadResult result;
3829 host_.OnSyncLoadWithMojo(0, 1, request, filter_.get(), 3827 host_.OnSyncLoadWithMojo(
3830 base::Bind(&StoreSyncLoadResult, 3828 GetResourceRequesterInfo(filter_.get()), 0, 1, request,
3831 &called, &was_null, &result)); 3829 base::Bind(&StoreSyncLoadResult, &called, &was_null, &result));
3832 base::RunLoop().RunUntilIdle(); 3830 base::RunLoop().RunUntilIdle();
3833 EXPECT_TRUE(called); 3831 EXPECT_TRUE(called);
3834 EXPECT_FALSE(was_null); 3832 EXPECT_FALSE(was_null);
3835 EXPECT_EQ(net::ERR_INVALID_URL, result.error_code); 3833 EXPECT_EQ(net::ERR_INVALID_URL, result.error_code);
3836 } 3834 }
3837 3835
3838 TEST_P(ResourceDispatcherHostTest, SyncLoadWithMojoCancel) { 3836 TEST_P(ResourceDispatcherHostTest, SyncLoadWithMojoCancel) {
3839 ResourceRequest request = CreateResourceRequest( 3837 ResourceRequest request = CreateResourceRequest(
3840 "GET", RESOURCE_TYPE_XHR, net::URLRequestTestJob::test_url_error()); 3838 "GET", RESOURCE_TYPE_XHR, net::URLRequestTestJob::test_url_error());
3841 request.priority = net::MAXIMUM_PRIORITY; 3839 request.priority = net::MAXIMUM_PRIORITY;
3842 3840
3843 bool called = false; 3841 bool called = false;
3844 bool was_null = false; 3842 bool was_null = false;
3845 SyncLoadResult result; 3843 SyncLoadResult result;
3846 host_.OnSyncLoadWithMojo(0, 1, request, filter_.get(), 3844 host_.OnSyncLoadWithMojo(
3847 base::Bind(&StoreSyncLoadResult, 3845 GetResourceRequesterInfo(filter_.get()), 0, 1, request,
3848 &called, &was_null, &result)); 3846 base::Bind(&StoreSyncLoadResult, &called, &was_null, &result));
3849 host_.CancelRequestsForProcess(filter_->child_id()); 3847 host_.CancelRequestsForProcess(filter_->child_id());
3850 base::RunLoop().RunUntilIdle(); 3848 base::RunLoop().RunUntilIdle();
3851 EXPECT_TRUE(called); 3849 EXPECT_TRUE(called);
3852 EXPECT_TRUE(was_null); 3850 EXPECT_TRUE(was_null);
3853 } 3851 }
3854 3852
3855 // A URLRequestTestJob that sets a test certificate on the |ssl_info| 3853 // A URLRequestTestJob that sets a test certificate on the |ssl_info|
3856 // field of the response. 3854 // field of the response.
3857 class TestHTTPSURLRequestJob : public net::URLRequestTestJob { 3855 class TestHTTPSURLRequestJob : public net::URLRequestTestJob {
3858 public: 3856 public:
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
3935 return nullptr; 3933 return nullptr;
3936 } 3934 }
3937 3935
3938 INSTANTIATE_TEST_CASE_P( 3936 INSTANTIATE_TEST_CASE_P(
3939 ResourceDispatcherHostTests, 3937 ResourceDispatcherHostTests,
3940 ResourceDispatcherHostTest, 3938 ResourceDispatcherHostTest,
3941 testing::Values(TestConfig::kDefault, 3939 testing::Values(TestConfig::kDefault,
3942 TestConfig::kOptimizeIPCForSmallResourceEnabled)); 3940 TestConfig::kOptimizeIPCForSmallResourceEnabled));
3943 3941
3944 } // namespace content 3942 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698