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 <vector> | 5 #include <vector> |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/file_path.h" | 8 #include "base/file_path.h" |
9 #include "base/memory/scoped_vector.h" | 9 #include "base/memory/scoped_vector.h" |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 } | 159 } |
160 | 160 |
161 class MockURLRequestContextSelector | 161 class MockURLRequestContextSelector |
162 : public ResourceMessageFilter::URLRequestContextSelector { | 162 : public ResourceMessageFilter::URLRequestContextSelector { |
163 public: | 163 public: |
164 explicit MockURLRequestContextSelector( | 164 explicit MockURLRequestContextSelector( |
165 net::URLRequestContext* request_context) | 165 net::URLRequestContext* request_context) |
166 : request_context_(request_context) {} | 166 : request_context_(request_context) {} |
167 | 167 |
168 virtual net::URLRequestContext* GetRequestContext( | 168 virtual net::URLRequestContext* GetRequestContext( |
169 ResourceType::Type request_type) { | 169 ResourceType::Type request_type) OVERRIDE { |
170 return request_context_; | 170 return request_context_; |
171 } | 171 } |
172 | 172 |
173 private: | 173 private: |
174 net::URLRequestContext* const request_context_; | 174 net::URLRequestContext* const request_context_; |
175 }; | 175 }; |
176 | 176 |
177 // This class forwards the incoming messages to the ResourceDispatcherHostTest. | 177 // This class forwards the incoming messages to the ResourceDispatcherHostTest. |
178 // This is used to emulate different sub-processes, since this filter will | 178 // This is used to emulate different sub-processes, since this filter will |
179 // have a different ID than the original. For the test, we want all the incoming | 179 // have a different ID than the original. For the test, we want all the incoming |
180 // messages to go to the same place, which is why this forwards. | 180 // messages to go to the same place, which is why this forwards. |
181 class ForwardingFilter : public ResourceMessageFilter { | 181 class ForwardingFilter : public ResourceMessageFilter { |
182 public: | 182 public: |
183 explicit ForwardingFilter(IPC::Sender* dest, | 183 explicit ForwardingFilter(IPC::Sender* dest, |
184 ResourceContext* resource_context) | 184 ResourceContext* resource_context) |
185 : ResourceMessageFilter( | 185 : ResourceMessageFilter( |
186 ChildProcessHostImpl::GenerateChildProcessUniqueId(), | 186 ChildProcessHostImpl::GenerateChildProcessUniqueId(), |
187 PROCESS_TYPE_RENDERER, | 187 PROCESS_TYPE_RENDERER, |
188 resource_context, NULL, NULL, NULL, | 188 resource_context, NULL, NULL, NULL, |
189 new MockURLRequestContextSelector( | 189 new MockURLRequestContextSelector( |
190 resource_context->GetRequestContext())), | 190 resource_context->GetRequestContext())), |
191 dest_(dest) { | 191 dest_(dest) { |
192 OnChannelConnected(base::GetCurrentProcId()); | 192 OnChannelConnected(base::GetCurrentProcId()); |
193 } | 193 } |
194 | 194 |
195 // ResourceMessageFilter override | 195 // ResourceMessageFilter override |
196 virtual bool Send(IPC::Message* msg) { | 196 virtual bool Send(IPC::Message* msg) OVERRIDE { |
197 if (!dest_) | 197 if (!dest_) |
198 return false; | 198 return false; |
199 return dest_->Send(msg); | 199 return dest_->Send(msg); |
200 } | 200 } |
201 | 201 |
202 protected: | 202 protected: |
203 virtual ~ForwardingFilter() {} | 203 virtual ~ForwardingFilter() {} |
204 | 204 |
205 private: | 205 private: |
206 IPC::Sender* dest_; | 206 IPC::Sender* dest_; |
(...skipping 23 matching lines...) Expand all Loading... |
230 bool auto_advance) | 230 bool auto_advance) |
231 : net::URLRequestTestJob(request, | 231 : net::URLRequestTestJob(request, |
232 network_delegate, | 232 network_delegate, |
233 response_headers, | 233 response_headers, |
234 response_data, | 234 response_data, |
235 auto_advance) { | 235 auto_advance) { |
236 Init(); | 236 Init(); |
237 } | 237 } |
238 | 238 |
239 // Do nothing until you're told to. | 239 // Do nothing until you're told to. |
240 virtual void Start() {} | 240 virtual void Start() OVERRIDE {} |
241 | 241 |
242 // Finish starting a URL request whose job is an instance of | 242 // Finish starting a URL request whose job is an instance of |
243 // URLRequestTestDelayedStartJob. It is illegal to call this routine | 243 // URLRequestTestDelayedStartJob. It is illegal to call this routine |
244 // with a URLRequest that does not use URLRequestTestDelayedStartJob. | 244 // with a URLRequest that does not use URLRequestTestDelayedStartJob. |
245 static void CompleteStart(net::URLRequest* request) { | 245 static void CompleteStart(net::URLRequest* request) { |
246 for (URLRequestTestDelayedStartJob* job = list_head_; | 246 for (URLRequestTestDelayedStartJob* job = list_head_; |
247 job; | 247 job; |
248 job = job->next_) { | 248 job = job->next_) { |
249 if (job->request() == request) { | 249 if (job->request() == request) { |
250 job->net::URLRequestTestJob::Start(); | 250 job->net::URLRequestTestJob::Start(); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 const std::string& response_headers, | 308 const std::string& response_headers, |
309 const std::string& response_data, | 309 const std::string& response_data, |
310 bool auto_advance) | 310 bool auto_advance) |
311 : net::URLRequestTestJob(request, | 311 : net::URLRequestTestJob(request, |
312 network_delegate, | 312 network_delegate, |
313 response_headers, | 313 response_headers, |
314 response_data, | 314 response_data, |
315 auto_advance) {} | 315 auto_advance) {} |
316 | 316 |
317 protected: | 317 protected: |
318 ~URLRequestTestDelayedCompletionJob() {} | 318 virtual ~URLRequestTestDelayedCompletionJob() {} |
319 | 319 |
320 private: | 320 private: |
321 virtual bool NextReadAsync() OVERRIDE { return true; } | 321 virtual bool NextReadAsync() OVERRIDE { return true; } |
322 }; | 322 }; |
323 | 323 |
324 class URLRequestBigJob : public net::URLRequestSimpleJob { | 324 class URLRequestBigJob : public net::URLRequestSimpleJob { |
325 public: | 325 public: |
326 URLRequestBigJob(net::URLRequest* request, | 326 URLRequestBigJob(net::URLRequest* request, |
327 net::NetworkDelegate* network_delegate) | 327 net::NetworkDelegate* network_delegate) |
328 : net::URLRequestSimpleJob(request, network_delegate) { | 328 : net::URLRequestSimpleJob(request, network_delegate) { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
363 } | 363 } |
364 }; | 364 }; |
365 | 365 |
366 // Associated with an URLRequest to determine if the URLRequest gets deleted. | 366 // Associated with an URLRequest to determine if the URLRequest gets deleted. |
367 class TestUserData : public base::SupportsUserData::Data { | 367 class TestUserData : public base::SupportsUserData::Data { |
368 public: | 368 public: |
369 explicit TestUserData(bool* was_deleted) | 369 explicit TestUserData(bool* was_deleted) |
370 : was_deleted_(was_deleted) { | 370 : was_deleted_(was_deleted) { |
371 } | 371 } |
372 | 372 |
373 ~TestUserData() { | 373 virtual ~TestUserData() { |
374 *was_deleted_ = true; | 374 *was_deleted_ = true; |
375 } | 375 } |
376 | 376 |
377 private: | 377 private: |
378 bool* was_deleted_; | 378 bool* was_deleted_; |
379 }; | 379 }; |
380 | 380 |
381 class TransfersAllNavigationsContentBrowserClient | 381 class TransfersAllNavigationsContentBrowserClient |
382 : public TestContentBrowserClient { | 382 : public TestContentBrowserClient { |
383 public: | 383 public: |
384 virtual bool ShouldSwapProcessesForRedirect(ResourceContext* resource_context, | 384 virtual bool ShouldSwapProcessesForRedirect(ResourceContext* resource_context, |
385 const GURL& current_url, | 385 const GURL& current_url, |
386 const GURL& new_url) { | 386 const GURL& new_url) OVERRIDE { |
387 return true; | 387 return true; |
388 } | 388 } |
389 }; | 389 }; |
390 | 390 |
391 enum GenericResourceThrottleFlags { | 391 enum GenericResourceThrottleFlags { |
392 NONE = 0, | 392 NONE = 0, |
393 DEFER_STARTING_REQUEST = 1 << 0, | 393 DEFER_STARTING_REQUEST = 1 << 0, |
394 DEFER_PROCESSING_RESPONSE = 1 << 1, | 394 DEFER_PROCESSING_RESPONSE = 1 << 1, |
395 CANCEL_BEFORE_START = 1 << 2 | 395 CANCEL_BEFORE_START = 1 << 2 |
396 }; | 396 }; |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
528 old_factory_(NULL), | 528 old_factory_(NULL), |
529 resource_type_(ResourceType::SUB_RESOURCE), | 529 resource_type_(ResourceType::SUB_RESOURCE), |
530 send_data_received_acks_(false) { | 530 send_data_received_acks_(false) { |
531 browser_context_.reset(new TestBrowserContext()); | 531 browser_context_.reset(new TestBrowserContext()); |
532 BrowserContext::EnsureResourceContextInitialized(browser_context_.get()); | 532 BrowserContext::EnsureResourceContextInitialized(browser_context_.get()); |
533 message_loop_.RunUntilIdle(); | 533 message_loop_.RunUntilIdle(); |
534 filter_ = new ForwardingFilter( | 534 filter_ = new ForwardingFilter( |
535 this, browser_context_->GetResourceContext()); | 535 this, browser_context_->GetResourceContext()); |
536 } | 536 } |
537 // IPC::Sender implementation | 537 // IPC::Sender implementation |
538 virtual bool Send(IPC::Message* msg) { | 538 virtual bool Send(IPC::Message* msg) OVERRIDE { |
539 accum_.AddMessage(*msg); | 539 accum_.AddMessage(*msg); |
540 | 540 |
541 if (send_data_received_acks_ && | 541 if (send_data_received_acks_ && |
542 msg->type() == ResourceMsg_DataReceived::ID) { | 542 msg->type() == ResourceMsg_DataReceived::ID) { |
543 GenerateDataReceivedACK(*msg); | 543 GenerateDataReceivedACK(*msg); |
544 } | 544 } |
545 | 545 |
546 delete msg; | 546 delete msg; |
547 return true; | 547 return true; |
548 } | 548 } |
(...skipping 1405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1954 } | 1954 } |
1955 | 1955 |
1956 MessageLoop::current()->RunUntilIdle(); | 1956 MessageLoop::current()->RunUntilIdle(); |
1957 | 1957 |
1958 msgs.clear(); | 1958 msgs.clear(); |
1959 accum_.GetClassifiedMessages(&msgs); | 1959 accum_.GetClassifiedMessages(&msgs); |
1960 } | 1960 } |
1961 } | 1961 } |
1962 | 1962 |
1963 } // namespace content | 1963 } // namespace content |
OLD | NEW |