| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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" |
| 11 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
| 12 #include "base/process_util.h" | 12 #include "base/process_util.h" |
| 13 #include "content/browser/browser_thread_impl.h" | 13 #include "content/browser/browser_thread_impl.h" |
| 14 #include "content/browser/child_process_security_policy.h" | 14 #include "content/browser/child_process_security_policy.h" |
| 15 #include "content/browser/download/download_id.h" | 15 #include "content/browser/download/download_id.h" |
| 16 #include "content/browser/download/download_id_factory.h" | 16 #include "content/browser/download/download_id_factory.h" |
| 17 #include "content/browser/mock_resource_context.h" | 17 #include "content/browser/mock_resource_context.h" |
| 18 #include "content/browser/renderer_host/dummy_resource_handler.h" | 18 #include "content/browser/renderer_host/dummy_resource_handler.h" |
| 19 #include "content/browser/renderer_host/global_request_id.h" | 19 #include "content/browser/renderer_host/global_request_id.h" |
| 20 #include "content/browser/renderer_host/resource_dispatcher_host.h" | 20 #include "content/browser/renderer_host/resource_dispatcher_host.h" |
| 21 #include "content/browser/renderer_host/resource_dispatcher_host_request_info.h" | 21 #include "content/browser/renderer_host/resource_dispatcher_host_request_info.h" |
| 22 #include "content/browser/renderer_host/resource_handler.h" | 22 #include "content/browser/renderer_host/resource_handler.h" |
| 23 #include "content/browser/renderer_host/resource_message_filter.h" | 23 #include "content/browser/renderer_host/resource_message_filter.h" |
| 24 #include "content/common/child_process_host.h" | 24 #include "content/common/child_process_host_impl.h" |
| 25 #include "content/common/resource_messages.h" | 25 #include "content/common/resource_messages.h" |
| 26 #include "content/common/view_messages.h" | 26 #include "content/common/view_messages.h" |
| 27 #include "content/public/common/resource_response.h" | 27 #include "content/public/common/resource_response.h" |
| 28 #include "net/base/net_errors.h" | 28 #include "net/base/net_errors.h" |
| 29 #include "net/base/upload_data.h" | 29 #include "net/base/upload_data.h" |
| 30 #include "net/http/http_util.h" | 30 #include "net/http/http_util.h" |
| 31 #include "net/url_request/url_request.h" | 31 #include "net/url_request/url_request.h" |
| 32 #include "net/url_request/url_request_job.h" | 32 #include "net/url_request/url_request_job.h" |
| 33 #include "net/url_request/url_request_test_job.h" | 33 #include "net/url_request/url_request_test_job.h" |
| 34 #include "testing/gtest/include/gtest/gtest.h" | 34 #include "testing/gtest/include/gtest/gtest.h" |
| 35 #include "webkit/appcache/appcache_interfaces.h" | 35 #include "webkit/appcache/appcache_interfaces.h" |
| 36 | 36 |
| 37 using content::BrowserThread; | 37 using content::BrowserThread; |
| 38 using content::BrowserThreadImpl; | 38 using content::BrowserThreadImpl; |
| 39 using content::ChildProcessHostImpl; |
| 39 | 40 |
| 40 // TODO(eroman): Write unit tests for SafeBrowsing that exercise | 41 // TODO(eroman): Write unit tests for SafeBrowsing that exercise |
| 41 // SafeBrowsingResourceHandler. | 42 // SafeBrowsingResourceHandler. |
| 42 | 43 |
| 43 namespace { | 44 namespace { |
| 44 | 45 |
| 45 // Returns the resource response header structure for this request. | 46 // Returns the resource response header structure for this request. |
| 46 void GetResponseHead(const std::vector<IPC::Message>& messages, | 47 void GetResponseHead(const std::vector<IPC::Message>& messages, |
| 47 content::ResourceResponseHead* response_head) { | 48 content::ResourceResponseHead* response_head) { |
| 48 ASSERT_GE(messages.size(), 2U); | 49 ASSERT_GE(messages.size(), 2U); |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 }; | 156 }; |
| 156 | 157 |
| 157 // This class forwards the incoming messages to the ResourceDispatcherHostTest. | 158 // This class forwards the incoming messages to the ResourceDispatcherHostTest. |
| 158 // This is used to emulate different sub-processes, since this filter will | 159 // This is used to emulate different sub-processes, since this filter will |
| 159 // have a different ID than the original. For the test, we want all the incoming | 160 // have a different ID than the original. For the test, we want all the incoming |
| 160 // messages to go to the same place, which is why this forwards. | 161 // messages to go to the same place, which is why this forwards. |
| 161 class ForwardingFilter : public ResourceMessageFilter { | 162 class ForwardingFilter : public ResourceMessageFilter { |
| 162 public: | 163 public: |
| 163 explicit ForwardingFilter(IPC::Message::Sender* dest) | 164 explicit ForwardingFilter(IPC::Message::Sender* dest) |
| 164 : ResourceMessageFilter( | 165 : ResourceMessageFilter( |
| 165 ChildProcessHost::GenerateChildProcessUniqueId(), | 166 ChildProcessHostImpl::GenerateChildProcessUniqueId(), |
| 166 content::PROCESS_TYPE_RENDERER, | 167 content::PROCESS_TYPE_RENDERER, |
| 167 content::MockResourceContext::GetInstance(), | 168 content::MockResourceContext::GetInstance(), |
| 168 new MockURLRequestContextSelector( | 169 new MockURLRequestContextSelector( |
| 169 content::MockResourceContext::GetInstance()->request_context()), | 170 content::MockResourceContext::GetInstance()->request_context()), |
| 170 NULL), | 171 NULL), |
| 171 dest_(dest) { | 172 dest_(dest) { |
| 172 OnChannelConnected(base::GetCurrentProcId()); | 173 OnChannelConnected(base::GetCurrentProcId()); |
| 173 } | 174 } |
| 174 | 175 |
| 175 // ResourceMessageFilter override | 176 // ResourceMessageFilter override |
| (...skipping 1050 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1226 EXPECT_EQ(1, host_.pending_requests()); | 1227 EXPECT_EQ(1, host_.pending_requests()); |
| 1227 | 1228 |
| 1228 // Cancelling by other methods shouldn't work either. | 1229 // Cancelling by other methods shouldn't work either. |
| 1229 host_.CancelRequestsForProcess(render_view_id); | 1230 host_.CancelRequestsForProcess(render_view_id); |
| 1230 EXPECT_EQ(1, host_.pending_requests()); | 1231 EXPECT_EQ(1, host_.pending_requests()); |
| 1231 | 1232 |
| 1232 // Cancelling by context should work. | 1233 // Cancelling by context should work. |
| 1233 host_.CancelRequestsForContext(&filter_->resource_context()); | 1234 host_.CancelRequestsForContext(&filter_->resource_context()); |
| 1234 EXPECT_EQ(0, host_.pending_requests()); | 1235 EXPECT_EQ(0, host_.pending_requests()); |
| 1235 } | 1236 } |
| OLD | NEW |