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

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

Issue 6825038: Create a content::ResourceContext. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Own database_tracker. Created 9 years, 8 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) 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 <vector> 5 #include <vector>
6 6
7 #include "base/file_path.h" 7 #include "base/file_path.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "base/process_util.h" 9 #include "base/process_util.h"
10 #include "chrome/common/render_messages.h" 10 #include "chrome/common/render_messages.h"
11 #include "content/browser/browser_thread.h" 11 #include "content/browser/browser_thread.h"
12 #include "content/browser/child_process_security_policy.h" 12 #include "content/browser/child_process_security_policy.h"
13 #include "content/browser/mock_resource_context.h"
13 #include "content/browser/renderer_host/resource_dispatcher_host.h" 14 #include "content/browser/renderer_host/resource_dispatcher_host.h"
14 #include "content/browser/renderer_host/resource_dispatcher_host_request_info.h" 15 #include "content/browser/renderer_host/resource_dispatcher_host_request_info.h"
15 #include "content/browser/renderer_host/resource_handler.h" 16 #include "content/browser/renderer_host/resource_handler.h"
16 #include "content/browser/renderer_host/resource_message_filter.h" 17 #include "content/browser/renderer_host/resource_message_filter.h"
17 #include "content/common/resource_messages.h" 18 #include "content/common/resource_messages.h"
18 #include "content/common/resource_response.h" 19 #include "content/common/resource_response.h"
19 #include "net/base/net_errors.h" 20 #include "net/base/net_errors.h"
20 #include "net/base/upload_data.h" 21 #include "net/base/upload_data.h"
21 #include "net/http/http_util.h" 22 #include "net/http/http_util.h"
22 #include "net/url_request/url_request.h" 23 #include "net/url_request/url_request.h"
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 124
124 // This class forwards the incoming messages to the ResourceDispatcherHostTest. 125 // This class forwards the incoming messages to the ResourceDispatcherHostTest.
125 // This is used to emulate different sub-processes, since this filter will 126 // This is used to emulate different sub-processes, since this filter will
126 // have a different ID than the original. For the test, we want all the incoming 127 // have a different ID than the original. For the test, we want all the incoming
127 // messages to go to the same place, which is why this forwards. 128 // messages to go to the same place, which is why this forwards.
128 class ForwardingFilter : public ResourceMessageFilter { 129 class ForwardingFilter : public ResourceMessageFilter {
129 public: 130 public:
130 explicit ForwardingFilter(IPC::Message::Sender* dest) 131 explicit ForwardingFilter(IPC::Message::Sender* dest)
131 : ResourceMessageFilter(ChildProcessInfo::GenerateChildProcessUniqueId(), 132 : ResourceMessageFilter(ChildProcessInfo::GenerateChildProcessUniqueId(),
132 ChildProcessInfo::RENDER_PROCESS, 133 ChildProcessInfo::RENDER_PROCESS,
134 content::MockResourceContext::GetInstance(),
133 NULL), 135 NULL),
134 dest_(dest) { 136 dest_(dest) {
135 OnChannelConnected(base::GetCurrentProcId()); 137 OnChannelConnected(base::GetCurrentProcId());
136 } 138 }
137 139
138 // ResourceMessageFilter override 140 // ResourceMessageFilter override
139 virtual bool Send(IPC::Message* msg) { 141 virtual bool Send(IPC::Message* msg) {
140 if (!dest_) 142 if (!dest_)
141 return false; 143 return false;
142 return dest_->Send(msg); 144 return dest_->Send(msg);
143 } 145 }
144 146
145 private: 147 private:
146 IPC::Message::Sender* dest_; 148 IPC::Message::Sender* dest_;
147 149
148 DISALLOW_COPY_AND_ASSIGN(ForwardingFilter); 150 DISALLOW_COPY_AND_ASSIGN(ForwardingFilter);
149 }; 151 };
150 152
151 class ResourceDispatcherHostTest : public testing::Test, 153 class ResourceDispatcherHostTest : public testing::Test,
152 public IPC::Message::Sender { 154 public IPC::Message::Sender {
153 public: 155 public:
154 ResourceDispatcherHostTest() 156 ResourceDispatcherHostTest()
155 : ALLOW_THIS_IN_INITIALIZER_LIST(filter_(new ForwardingFilter(this))), 157 : ui_thread_(BrowserThread::UI, &message_loop_),
156 ui_thread_(BrowserThread::UI, &message_loop_),
157 io_thread_(BrowserThread::IO, &message_loop_), 158 io_thread_(BrowserThread::IO, &message_loop_),
159 ALLOW_THIS_IN_INITIALIZER_LIST(filter_(new ForwardingFilter(this))),
158 host_(ResourceQueue::DelegateSet()), 160 host_(ResourceQueue::DelegateSet()),
159 old_factory_(NULL), 161 old_factory_(NULL),
160 resource_type_(ResourceType::SUB_RESOURCE) { 162 resource_type_(ResourceType::SUB_RESOURCE) {
161 } 163 }
162 // IPC::Message::Sender implementation 164 // IPC::Message::Sender implementation
163 virtual bool Send(IPC::Message* msg) { 165 virtual bool Send(IPC::Message* msg) {
164 accum_.AddMessage(*msg); 166 accum_.AddMessage(*msg);
165 delete msg; 167 delete msg;
166 return true; 168 return true;
167 } 169 }
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 if (test_fixture_->response_headers_.empty()) { 247 if (test_fixture_->response_headers_.empty()) {
246 return new net::URLRequestTestJob(request); 248 return new net::URLRequestTestJob(request);
247 } else { 249 } else {
248 return new net::URLRequestTestJob(request, 250 return new net::URLRequestTestJob(request,
249 test_fixture_->response_headers_, 251 test_fixture_->response_headers_,
250 test_fixture_->response_data_, 252 test_fixture_->response_data_,
251 false); 253 false);
252 } 254 }
253 } 255 }
254 256
255 scoped_refptr<ForwardingFilter> filter_;
256 MessageLoopForIO message_loop_; 257 MessageLoopForIO message_loop_;
257 BrowserThread ui_thread_; 258 BrowserThread ui_thread_;
258 BrowserThread io_thread_; 259 BrowserThread io_thread_;
260 scoped_refptr<ForwardingFilter> filter_;
259 ResourceDispatcherHost host_; 261 ResourceDispatcherHost host_;
260 ResourceIPCAccumulator accum_; 262 ResourceIPCAccumulator accum_;
261 std::string response_headers_; 263 std::string response_headers_;
262 std::string response_data_; 264 std::string response_data_;
263 std::string scheme_; 265 std::string scheme_;
264 net::URLRequest::ProtocolFactory* old_factory_; 266 net::URLRequest::ProtocolFactory* old_factory_;
265 ResourceType::Type resource_type_; 267 ResourceType::Type resource_type_;
266 static ResourceDispatcherHostTest* test_fixture_; 268 static ResourceDispatcherHostTest* test_fixture_;
267 }; 269 };
268 // Static. 270 // Static.
(...skipping 735 matching lines...) Expand 10 before | Expand all | Expand 10 after
1004 const net::URLRequestStatus& status, 1006 const net::URLRequestStatus& status,
1005 const std::string& info) { 1007 const std::string& info) {
1006 return true; 1008 return true;
1007 } 1009 }
1008 1010
1009 void OnRequestClosed() {} 1011 void OnRequestClosed() {}
1010 1012
1011 private: 1013 private:
1012 DISALLOW_COPY_AND_ASSIGN(DummyResourceHandler); 1014 DISALLOW_COPY_AND_ASSIGN(DummyResourceHandler);
1013 }; 1015 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698