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

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

Issue 324143002: Decouple IPC::MessageFilter from IPC::Channel (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixing compilation errors Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <vector> 5 #include <vector>
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
11 #include "base/memory/scoped_vector.h" 11 #include "base/memory/scoped_vector.h"
12 #include "base/memory/shared_memory.h" 12 #include "base/memory/shared_memory.h"
13 #include "base/message_loop/message_loop.h" 13 #include "base/message_loop/message_loop.h"
14 #include "base/pickle.h" 14 #include "base/pickle.h"
15 #include "base/run_loop.h" 15 #include "base/run_loop.h"
16 #include "base/strings/string_number_conversions.h" 16 #include "base/strings/string_number_conversions.h"
17 #include "base/strings/string_split.h" 17 #include "base/strings/string_split.h"
18 #include "content/browser/browser_message_filter_peer.h"
18 #include "content/browser/browser_thread_impl.h" 19 #include "content/browser/browser_thread_impl.h"
19 #include "content/browser/child_process_security_policy_impl.h" 20 #include "content/browser/child_process_security_policy_impl.h"
20 #include "content/browser/loader/cross_site_resource_handler.h" 21 #include "content/browser/loader/cross_site_resource_handler.h"
21 #include "content/browser/loader/detachable_resource_handler.h" 22 #include "content/browser/loader/detachable_resource_handler.h"
22 #include "content/browser/loader/resource_dispatcher_host_impl.h" 23 #include "content/browser/loader/resource_dispatcher_host_impl.h"
23 #include "content/browser/loader/resource_loader.h" 24 #include "content/browser/loader/resource_loader.h"
24 #include "content/browser/loader/resource_message_filter.h" 25 #include "content/browser/loader/resource_message_filter.h"
25 #include "content/browser/loader/resource_request_info_impl.h" 26 #include "content/browser/loader/resource_request_info_impl.h"
26 #include "content/browser/worker_host/worker_service_impl.h" 27 #include "content/browser/worker_host/worker_service_impl.h"
27 #include "content/common/child_process_host_impl.h" 28 #include "content/common/child_process_host_impl.h"
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 // have a different ID than the original. 210 // have a different ID than the original.
210 class TestFilter : public ResourceMessageFilter { 211 class TestFilter : public ResourceMessageFilter {
211 public: 212 public:
212 explicit TestFilter(ResourceContext* resource_context) 213 explicit TestFilter(ResourceContext* resource_context)
213 : ResourceMessageFilter( 214 : ResourceMessageFilter(
214 ChildProcessHostImpl::GenerateChildProcessUniqueId(), 215 ChildProcessHostImpl::GenerateChildProcessUniqueId(),
215 PROCESS_TYPE_RENDERER, NULL, NULL, NULL, NULL, 216 PROCESS_TYPE_RENDERER, NULL, NULL, NULL, NULL,
216 base::Bind(&TestFilter::GetContexts, base::Unretained(this))), 217 base::Bind(&TestFilter::GetContexts, base::Unretained(this))),
217 resource_context_(resource_context), 218 resource_context_(resource_context),
218 canceled_(false), 219 canceled_(false),
219 received_after_canceled_(0) { 220 received_after_canceled_(0),
221 peer_(new BrowserMessageFilterPeer(base::GetCurrentProcId())) {
220 ChildProcessSecurityPolicyImpl::GetInstance()->Add(child_id()); 222 ChildProcessSecurityPolicyImpl::GetInstance()->Add(child_id());
221 set_peer_pid_for_testing(base::GetCurrentProcId()); 223 OnFilterAddedToHost(peer_.get());
222 } 224 }
223 225
224 void set_canceled(bool canceled) { canceled_ = canceled; } 226 void set_canceled(bool canceled) { canceled_ = canceled; }
225 int received_after_canceled() const { return received_after_canceled_; } 227 int received_after_canceled() const { return received_after_canceled_; }
226 228
227 // ResourceMessageFilter override 229 // ResourceMessageFilter override
228 virtual bool Send(IPC::Message* msg) OVERRIDE { 230 virtual bool Send(IPC::Message* msg) OVERRIDE {
229 // No messages should be received when the process has been canceled. 231 // No messages should be received when the process has been canceled.
230 if (canceled_) 232 if (canceled_)
231 received_after_canceled_++; 233 received_after_canceled_++;
(...skipping 11 matching lines...) Expand all
243 void GetContexts(const ResourceHostMsg_Request& request, 245 void GetContexts(const ResourceHostMsg_Request& request,
244 ResourceContext** resource_context, 246 ResourceContext** resource_context,
245 net::URLRequestContext** request_context) { 247 net::URLRequestContext** request_context) {
246 *resource_context = resource_context_; 248 *resource_context = resource_context_;
247 *request_context = resource_context_->GetRequestContext(); 249 *request_context = resource_context_->GetRequestContext();
248 } 250 }
249 251
250 ResourceContext* resource_context_; 252 ResourceContext* resource_context_;
251 bool canceled_; 253 bool canceled_;
252 int received_after_canceled_; 254 int received_after_canceled_;
253 255 scoped_ptr<BrowserMessageFilterPeer> peer_;
254 DISALLOW_COPY_AND_ASSIGN(TestFilter); 256 DISALLOW_COPY_AND_ASSIGN(TestFilter);
255 }; 257 };
256 258
257 259
258 // This class forwards the incoming messages to the ResourceDispatcherHostTest. 260 // This class forwards the incoming messages to the ResourceDispatcherHostTest.
259 // For the test, we want all the incoming messages to go to the same place, 261 // For the test, we want all the incoming messages to go to the same place,
260 // which is why this forwards. 262 // which is why this forwards.
261 class ForwardingFilter : public TestFilter { 263 class ForwardingFilter : public TestFilter {
262 public: 264 public:
263 explicit ForwardingFilter(IPC::Sender* dest, 265 explicit ForwardingFilter(IPC::Sender* dest,
(...skipping 915 matching lines...) Expand 10 before | Expand all | Expand 10 after
1179 host_.OnMessageReceived(msg_ping, filter_); 1181 host_.OnMessageReceived(msg_ping, filter_);
1180 1182
1181 // Remove the filter before processing the requests by simulating channel 1183 // Remove the filter before processing the requests by simulating channel
1182 // closure. 1184 // closure.
1183 ResourceRequestInfoImpl* info_prefetch = ResourceRequestInfoImpl::ForRequest( 1185 ResourceRequestInfoImpl* info_prefetch = ResourceRequestInfoImpl::ForRequest(
1184 host_.GetURLRequest(GlobalRequestID(filter_->child_id(), 1))); 1186 host_.GetURLRequest(GlobalRequestID(filter_->child_id(), 1)));
1185 ResourceRequestInfoImpl* info_ping = ResourceRequestInfoImpl::ForRequest( 1187 ResourceRequestInfoImpl* info_ping = ResourceRequestInfoImpl::ForRequest(
1186 host_.GetURLRequest(GlobalRequestID(filter_->child_id(), 2))); 1188 host_.GetURLRequest(GlobalRequestID(filter_->child_id(), 2)));
1187 DCHECK_EQ(filter_.get(), info_prefetch->filter()); 1189 DCHECK_EQ(filter_.get(), info_prefetch->filter());
1188 DCHECK_EQ(filter_.get(), info_ping->filter()); 1190 DCHECK_EQ(filter_.get(), info_ping->filter());
1189 filter_->OnChannelClosing(); 1191 filter_->OnSenderClosing();
1190 info_prefetch->filter_.reset(); 1192 info_prefetch->filter_.reset();
1191 info_ping->filter_.reset(); 1193 info_ping->filter_.reset();
1192 1194
1193 // From the renderer's perspective, the requests were cancelled. 1195 // From the renderer's perspective, the requests were cancelled.
1194 ResourceIPCAccumulator::ClassifiedMessages msgs; 1196 ResourceIPCAccumulator::ClassifiedMessages msgs;
1195 accum_.GetClassifiedMessages(&msgs); 1197 accum_.GetClassifiedMessages(&msgs);
1196 ASSERT_EQ(2U, msgs.size()); 1198 ASSERT_EQ(2U, msgs.size());
1197 CheckRequestCompleteErrorCode(msgs[0][0], net::ERR_ABORTED); 1199 CheckRequestCompleteErrorCode(msgs[0][0], net::ERR_ABORTED);
1198 CheckRequestCompleteErrorCode(msgs[1][0], net::ERR_ABORTED); 1200 CheckRequestCompleteErrorCode(msgs[1][0], net::ERR_ABORTED);
1199 1201
(...skipping 24 matching lines...) Expand all
1224 net::URLRequestTestJob::test_url_redirect_to_url_2()); 1226 net::URLRequestTestJob::test_url_redirect_to_url_2());
1225 1227
1226 ResourceHostMsg_RequestResource msg(0, 1, request); 1228 ResourceHostMsg_RequestResource msg(0, 1, request);
1227 host_.OnMessageReceived(msg, filter_); 1229 host_.OnMessageReceived(msg, filter_);
1228 1230
1229 // Remove the filter before processing the request by simulating channel 1231 // Remove the filter before processing the request by simulating channel
1230 // closure. 1232 // closure.
1231 GlobalRequestID global_request_id(filter_->child_id(), 1); 1233 GlobalRequestID global_request_id(filter_->child_id(), 1);
1232 ResourceRequestInfoImpl* info = ResourceRequestInfoImpl::ForRequest( 1234 ResourceRequestInfoImpl* info = ResourceRequestInfoImpl::ForRequest(
1233 host_.GetURLRequest(global_request_id)); 1235 host_.GetURLRequest(global_request_id));
1234 info->filter_->OnChannelClosing(); 1236 info->filter_->OnSenderClosing();
1235 info->filter_.reset(); 1237 info->filter_.reset();
1236 1238
1237 // From the renderer's perspective, the request was cancelled. 1239 // From the renderer's perspective, the request was cancelled.
1238 ResourceIPCAccumulator::ClassifiedMessages msgs; 1240 ResourceIPCAccumulator::ClassifiedMessages msgs;
1239 accum_.GetClassifiedMessages(&msgs); 1241 accum_.GetClassifiedMessages(&msgs);
1240 ASSERT_EQ(1U, msgs.size()); 1242 ASSERT_EQ(1U, msgs.size());
1241 CheckRequestCompleteErrorCode(msgs[0][0], net::ERR_ABORTED); 1243 CheckRequestCompleteErrorCode(msgs[0][0], net::ERR_ABORTED);
1242 1244
1243 // But it continues detached. 1245 // But it continues detached.
1244 EXPECT_EQ(1, host_.pending_requests()); 1246 EXPECT_EQ(1, host_.pending_requests());
(...skipping 1555 matching lines...) Expand 10 before | Expand all | Expand 10 after
2800 2802
2801 // Register it for a resource request. 2803 // Register it for a resource request.
2802 host_.RegisterDownloadedTempFile(filter_->child_id(), kRequestID, file_path); 2804 host_.RegisterDownloadedTempFile(filter_->child_id(), kRequestID, file_path);
2803 deletable_file = NULL; 2805 deletable_file = NULL;
2804 2806
2805 // Should be readable now. 2807 // Should be readable now.
2806 EXPECT_TRUE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile( 2808 EXPECT_TRUE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile(
2807 filter_->child_id(), file_path)); 2809 filter_->child_id(), file_path));
2808 2810
2809 // Let the process die. 2811 // Let the process die.
2810 filter_->OnChannelClosing(); 2812 filter_->OnSenderClosing();
2811 base::RunLoop().RunUntilIdle(); 2813 base::RunLoop().RunUntilIdle();
2812 2814
2813 // The file is no longer readable to the child and has been deleted. 2815 // The file is no longer readable to the child and has been deleted.
2814 EXPECT_FALSE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile( 2816 EXPECT_FALSE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile(
2815 filter_->child_id(), file_path)); 2817 filter_->child_id(), file_path));
2816 EXPECT_FALSE(base::PathExists(file_path)); 2818 EXPECT_FALSE(base::PathExists(file_path));
2817 } 2819 }
2818 2820
2819 TEST_F(ResourceDispatcherHostTest, DownloadToFile) { 2821 TEST_F(ResourceDispatcherHostTest, DownloadToFile) {
2820 // Make a request which downloads to file. 2822 // Make a request which downloads to file.
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
2921 } else { 2923 } else {
2922 return new net::URLRequestTestJob( 2924 return new net::URLRequestTestJob(
2923 request, network_delegate, 2925 request, network_delegate,
2924 test_fixture_->response_headers_, test_fixture_->response_data_, 2926 test_fixture_->response_headers_, test_fixture_->response_data_,
2925 false); 2927 false);
2926 } 2928 }
2927 } 2929 }
2928 } 2930 }
2929 2931
2930 } // namespace content 2932 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698