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

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

Issue 23851010: Modify ResourceMessageFilter so that it can support attaching to PluginProcessHost. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: sync Created 7 years, 3 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/bind.h" 7 #include "base/bind.h"
8 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "base/memory/scoped_vector.h" 9 #include "base/memory/scoped_vector.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 messages_.erase(messages_.begin() + i); 152 messages_.erase(messages_.begin() + i);
153 i--; 153 i--;
154 } 154 }
155 } 155 }
156 msgs->push_back(cur_requests); 156 msgs->push_back(cur_requests);
157 } 157 }
158 messages_.erase(messages_.begin()); 158 messages_.erase(messages_.begin());
159 } 159 }
160 } 160 }
161 161
162 class MockURLRequestContextSelector
163 : public ResourceMessageFilter::URLRequestContextSelector {
164 public:
165 explicit MockURLRequestContextSelector(
166 net::URLRequestContext* request_context)
167 : request_context_(request_context) {}
168
169 virtual net::URLRequestContext* GetRequestContext(
170 ResourceType::Type request_type) OVERRIDE {
171 return request_context_;
172 }
173
174 private:
175 net::URLRequestContext* const request_context_;
176 };
177
178 // This class forwards the incoming messages to the ResourceDispatcherHostTest. 162 // This class forwards the incoming messages to the ResourceDispatcherHostTest.
179 // This is used to emulate different sub-processes, since this filter will 163 // This is used to emulate different sub-processes, since this filter will
180 // have a different ID than the original. For the test, we want all the incoming 164 // have a different ID than the original. For the test, we want all the incoming
181 // messages to go to the same place, which is why this forwards. 165 // messages to go to the same place, which is why this forwards.
182 class ForwardingFilter : public ResourceMessageFilter { 166 class ForwardingFilter : public ResourceMessageFilter {
183 public: 167 public:
184 explicit ForwardingFilter(IPC::Sender* dest, 168 explicit ForwardingFilter(IPC::Sender* dest,
185 ResourceContext* resource_context) 169 ResourceContext* resource_context)
186 : ResourceMessageFilter( 170 : ResourceMessageFilter(
187 ChildProcessHostImpl::GenerateChildProcessUniqueId(), 171 ChildProcessHostImpl::GenerateChildProcessUniqueId(),
188 PROCESS_TYPE_RENDERER, 172 PROCESS_TYPE_RENDERER, NULL, NULL, NULL,
189 resource_context, NULL, NULL, NULL, 173 base::Bind(&ForwardingFilter::GetContexts,
190 new MockURLRequestContextSelector( 174 base::Unretained(this))),
191 resource_context->GetRequestContext())), 175 dest_(dest),
192 dest_(dest) { 176 resource_context_(resource_context) {
193 OnChannelConnected(base::GetCurrentProcId()); 177 OnChannelConnected(base::GetCurrentProcId());
194 } 178 }
195 179
196 // ResourceMessageFilter override 180 // ResourceMessageFilter override
197 virtual bool Send(IPC::Message* msg) OVERRIDE { 181 virtual bool Send(IPC::Message* msg) OVERRIDE {
198 if (!dest_) 182 if (!dest_)
199 return false; 183 return false;
200 return dest_->Send(msg); 184 return dest_->Send(msg);
201 } 185 }
202 186
187 ResourceContext* resource_context() { return resource_context_; }
188
203 protected: 189 protected:
204 virtual ~ForwardingFilter() {} 190 virtual ~ForwardingFilter() {}
205 191
206 private: 192 private:
193 void GetContexts(const ResourceHostMsg_Request& request,
194 ResourceContext** resource_context,
195 net::URLRequestContext** request_context) {
196 *resource_context = resource_context_;
197 *request_context = resource_context_->GetRequestContext();
198 }
199
207 IPC::Sender* dest_; 200 IPC::Sender* dest_;
201 ResourceContext* resource_context_;
208 202
209 DISALLOW_COPY_AND_ASSIGN(ForwardingFilter); 203 DISALLOW_COPY_AND_ASSIGN(ForwardingFilter);
210 }; 204 };
211 205
212 // This class is a variation on URLRequestTestJob in that it does 206 // This class is a variation on URLRequestTestJob in that it does
213 // not complete start upon entry, only when specifically told to. 207 // not complete start upon entry, only when specifically told to.
214 class URLRequestTestDelayedStartJob : public net::URLRequestTestJob { 208 class URLRequestTestDelayedStartJob : public net::URLRequestTestJob {
215 public: 209 public:
216 URLRequestTestDelayedStartJob(net::URLRequest* request, 210 URLRequestTestDelayedStartJob(net::URLRequest* request,
217 net::NetworkDelegate* network_delegate) 211 net::NetworkDelegate* network_delegate)
(...skipping 1780 matching lines...) Expand 10 before | Expand all | Expand 10 after
1998 } 1992 }
1999 1993
2000 base::MessageLoop::current()->RunUntilIdle(); 1994 base::MessageLoop::current()->RunUntilIdle();
2001 1995
2002 msgs.clear(); 1996 msgs.clear();
2003 accum_.GetClassifiedMessages(&msgs); 1997 accum_.GetClassifiedMessages(&msgs);
2004 } 1998 }
2005 } 1999 }
2006 2000
2007 } // namespace content 2001 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/loader/resource_dispatcher_host_impl.cc ('k') | content/browser/loader/resource_message_filter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698