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 "content/browser/renderer_host/resource_dispatcher_host.h" | 5 #include "content/browser/renderer_host/resource_dispatcher_host.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 // have a different ID than the original. For the test, we want all the incoming | 167 // have a different ID than the original. For the test, we want all the incoming |
168 // messages to go to the same place, which is why this forwards. | 168 // messages to go to the same place, which is why this forwards. |
169 class ForwardingFilter : public ResourceMessageFilter { | 169 class ForwardingFilter : public ResourceMessageFilter { |
170 public: | 170 public: |
171 explicit ForwardingFilter(IPC::Message::Sender* dest) | 171 explicit ForwardingFilter(IPC::Message::Sender* dest) |
172 : ResourceMessageFilter( | 172 : ResourceMessageFilter( |
173 ChildProcessHostImpl::GenerateChildProcessUniqueId(), | 173 ChildProcessHostImpl::GenerateChildProcessUniqueId(), |
174 content::PROCESS_TYPE_RENDERER, | 174 content::PROCESS_TYPE_RENDERER, |
175 content::MockResourceContext::GetInstance(), | 175 content::MockResourceContext::GetInstance(), |
176 new MockURLRequestContextSelector( | 176 new MockURLRequestContextSelector( |
177 content::MockResourceContext::GetInstance()->request_context())), | 177 content::MockResourceContext::GetInstance()->GetRequestContext())), |
178 dest_(dest) { | 178 dest_(dest) { |
179 OnChannelConnected(base::GetCurrentProcId()); | 179 OnChannelConnected(base::GetCurrentProcId()); |
180 } | 180 } |
181 | 181 |
182 // ResourceMessageFilter override | 182 // ResourceMessageFilter override |
183 virtual bool Send(IPC::Message* msg) { | 183 virtual bool Send(IPC::Message* msg) { |
184 if (!dest_) | 184 if (!dest_) |
185 return false; | 185 return false; |
186 return dest_->Send(msg); | 186 return dest_->Send(msg); |
187 } | 187 } |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
296 } | 296 } |
297 | 297 |
298 void set_defer_start(bool value) { | 298 void set_defer_start(bool value) { |
299 defer_start_ = value; | 299 defer_start_ = value; |
300 } | 300 } |
301 | 301 |
302 // ResourceDispatcherHostDelegate implementation: | 302 // ResourceDispatcherHostDelegate implementation: |
303 | 303 |
304 virtual void RequestBeginning( | 304 virtual void RequestBeginning( |
305 net::URLRequest* request, | 305 net::URLRequest* request, |
306 const content::ResourceContext& resource_context, | 306 content::ResourceContext* resource_context, |
307 ResourceType::Type resource_type, | 307 ResourceType::Type resource_type, |
308 int child_id, | 308 int child_id, |
309 int route_id, | 309 int route_id, |
310 bool is_continuation_of_transferred_request, | 310 bool is_continuation_of_transferred_request, |
311 ScopedVector<content::ResourceThrottle>* throttles) OVERRIDE { | 311 ScopedVector<content::ResourceThrottle>* throttles) OVERRIDE { |
312 const void* key = user_data_.get(); | 312 const void* key = user_data_.get(); |
313 request->SetUserData(key, user_data_.release()); | 313 request->SetUserData(key, user_data_.release()); |
314 } | 314 } |
315 | 315 |
316 virtual bool ShouldDeferStart( | 316 virtual bool ShouldDeferStart( |
317 net::URLRequest* request, | 317 net::URLRequest* request, |
318 const content::ResourceContext& resource_context) OVERRIDE { | 318 content::ResourceContext* resource_context) OVERRIDE { |
319 return defer_start_; | 319 return defer_start_; |
320 } | 320 } |
321 | 321 |
322 private: | 322 private: |
323 bool defer_start_; | 323 bool defer_start_; |
324 scoped_ptr<net::URLRequest::UserData> user_data_; | 324 scoped_ptr<net::URLRequest::UserData> user_data_; |
325 }; | 325 }; |
326 | 326 |
327 class ResourceDispatcherHostTest : public testing::Test, | 327 class ResourceDispatcherHostTest : public testing::Test, |
328 public IPC::Message::Sender { | 328 public IPC::Message::Sender { |
(...skipping 963 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1292 // Since the request had already started processing as a download, | 1292 // Since the request had already started processing as a download, |
1293 // the cancellation above should have been ignored and the request | 1293 // the cancellation above should have been ignored and the request |
1294 // should still be alive. | 1294 // should still be alive. |
1295 EXPECT_EQ(1, host_.pending_requests()); | 1295 EXPECT_EQ(1, host_.pending_requests()); |
1296 | 1296 |
1297 // Cancelling by other methods shouldn't work either. | 1297 // Cancelling by other methods shouldn't work either. |
1298 host_.CancelRequestsForProcess(render_view_id); | 1298 host_.CancelRequestsForProcess(render_view_id); |
1299 EXPECT_EQ(1, host_.pending_requests()); | 1299 EXPECT_EQ(1, host_.pending_requests()); |
1300 | 1300 |
1301 // Cancelling by context should work. | 1301 // Cancelling by context should work. |
1302 host_.CancelRequestsForContext(&filter_->resource_context()); | 1302 host_.CancelRequestsForContext(filter_->resource_context()); |
1303 EXPECT_EQ(0, host_.pending_requests()); | 1303 EXPECT_EQ(0, host_.pending_requests()); |
1304 } | 1304 } |
1305 | 1305 |
1306 // Test the cancelling of requests that are being transferred to a new renderer | 1306 // Test the cancelling of requests that are being transferred to a new renderer |
1307 // due to a redirection. | 1307 // due to a redirection. |
1308 TEST_F(ResourceDispatcherHostTest, CancelRequestsForContextTransferred) { | 1308 TEST_F(ResourceDispatcherHostTest, CancelRequestsForContextTransferred) { |
1309 EXPECT_EQ(0, host_.pending_requests()); | 1309 EXPECT_EQ(0, host_.pending_requests()); |
1310 | 1310 |
1311 int render_view_id = 0; | 1311 int render_view_id = 0; |
1312 int request_id = 1; | 1312 int request_id = 1; |
(...skipping 22 matching lines...) Expand all Loading... |
1335 // Since the request is marked as being transferred, | 1335 // Since the request is marked as being transferred, |
1336 // the cancellation above should have been ignored and the request | 1336 // the cancellation above should have been ignored and the request |
1337 // should still be alive. | 1337 // should still be alive. |
1338 EXPECT_EQ(1, host_.pending_requests()); | 1338 EXPECT_EQ(1, host_.pending_requests()); |
1339 | 1339 |
1340 // Cancelling by other methods shouldn't work either. | 1340 // Cancelling by other methods shouldn't work either. |
1341 host_.CancelRequestsForProcess(render_view_id); | 1341 host_.CancelRequestsForProcess(render_view_id); |
1342 EXPECT_EQ(1, host_.pending_requests()); | 1342 EXPECT_EQ(1, host_.pending_requests()); |
1343 | 1343 |
1344 // Cancelling by context should work. | 1344 // Cancelling by context should work. |
1345 host_.CancelRequestsForContext(&filter_->resource_context()); | 1345 host_.CancelRequestsForContext(filter_->resource_context()); |
1346 EXPECT_EQ(0, host_.pending_requests()); | 1346 EXPECT_EQ(0, host_.pending_requests()); |
1347 } | 1347 } |
1348 | 1348 |
1349 TEST_F(ResourceDispatcherHostTest, UnknownURLScheme) { | 1349 TEST_F(ResourceDispatcherHostTest, UnknownURLScheme) { |
1350 EXPECT_EQ(0, host_.pending_requests()); | 1350 EXPECT_EQ(0, host_.pending_requests()); |
1351 | 1351 |
1352 SetResourceType(ResourceType::MAIN_FRAME); | 1352 SetResourceType(ResourceType::MAIN_FRAME); |
1353 HandleScheme("http"); | 1353 HandleScheme("http"); |
1354 | 1354 |
1355 MakeTestRequest(0, 1, GURL("foo://bar")); | 1355 MakeTestRequest(0, 1, GURL("foo://bar")); |
(...skipping 15 matching lines...) Expand all Loading... |
1371 net::URLRequestStatus status; | 1371 net::URLRequestStatus status; |
1372 | 1372 |
1373 void* iter = NULL; | 1373 void* iter = NULL; |
1374 EXPECT_TRUE(IPC::ReadParam(&msgs[0][0], &iter, &request_id)); | 1374 EXPECT_TRUE(IPC::ReadParam(&msgs[0][0], &iter, &request_id)); |
1375 EXPECT_TRUE(IPC::ReadParam(&msgs[0][0], &iter, &status)); | 1375 EXPECT_TRUE(IPC::ReadParam(&msgs[0][0], &iter, &status)); |
1376 | 1376 |
1377 EXPECT_EQ(1, request_id); | 1377 EXPECT_EQ(1, request_id); |
1378 EXPECT_EQ(net::URLRequestStatus::FAILED, status.status()); | 1378 EXPECT_EQ(net::URLRequestStatus::FAILED, status.status()); |
1379 EXPECT_EQ(net::ERR_UNKNOWN_URL_SCHEME, status.error()); | 1379 EXPECT_EQ(net::ERR_UNKNOWN_URL_SCHEME, status.error()); |
1380 } | 1380 } |
OLD | NEW |