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