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 "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/memory/scoped_vector.h" | 11 #include "base/memory/scoped_vector.h" |
12 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
13 #include "base/process_util.h" | 13 #include "base/process_util.h" |
14 #include "content/browser/browser_thread_impl.h" | 14 #include "content/browser/browser_thread_impl.h" |
15 #include "content/browser/child_process_security_policy.h" | 15 #include "content/browser/child_process_security_policy_impl.h" |
16 #include "content/browser/mock_resource_context.h" | 16 #include "content/browser/mock_resource_context.h" |
17 #include "content/browser/renderer_host/dummy_resource_handler.h" | 17 #include "content/browser/renderer_host/dummy_resource_handler.h" |
18 #include "content/browser/renderer_host/layered_resource_handler.h" | 18 #include "content/browser/renderer_host/layered_resource_handler.h" |
19 #include "content/browser/renderer_host/resource_dispatcher_host.h" | 19 #include "content/browser/renderer_host/resource_dispatcher_host.h" |
20 #include "content/browser/renderer_host/resource_dispatcher_host_request_info.h" | 20 #include "content/browser/renderer_host/resource_dispatcher_host_request_info.h" |
21 #include "content/browser/renderer_host/resource_message_filter.h" | 21 #include "content/browser/renderer_host/resource_message_filter.h" |
22 #include "content/common/child_process_host_impl.h" | 22 #include "content/common/child_process_host_impl.h" |
23 #include "content/common/resource_messages.h" | 23 #include "content/common/resource_messages.h" |
24 #include "content/common/view_messages.h" | 24 #include "content/common/view_messages.h" |
25 #include "content/public/browser/global_request_id.h" | 25 #include "content/public/browser/global_request_id.h" |
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
339 accum_.AddMessage(*msg); | 339 accum_.AddMessage(*msg); |
340 delete msg; | 340 delete msg; |
341 return true; | 341 return true; |
342 } | 342 } |
343 | 343 |
344 protected: | 344 protected: |
345 // testing::Test | 345 // testing::Test |
346 virtual void SetUp() { | 346 virtual void SetUp() { |
347 DCHECK(!test_fixture_); | 347 DCHECK(!test_fixture_); |
348 test_fixture_ = this; | 348 test_fixture_ = this; |
349 ChildProcessSecurityPolicy::GetInstance()->Add(0); | 349 ChildProcessSecurityPolicyImpl::GetInstance()->Add(0); |
350 net::URLRequest::Deprecated::RegisterProtocolFactory( | 350 net::URLRequest::Deprecated::RegisterProtocolFactory( |
351 "test", | 351 "test", |
352 &ResourceDispatcherHostTest::Factory); | 352 &ResourceDispatcherHostTest::Factory); |
353 EnsureTestSchemeIsAllowed(); | 353 EnsureTestSchemeIsAllowed(); |
354 delay_start_ = false; | 354 delay_start_ = false; |
355 } | 355 } |
356 | 356 |
357 virtual void TearDown() { | 357 virtual void TearDown() { |
358 net::URLRequest::Deprecated::RegisterProtocolFactory("test", NULL); | 358 net::URLRequest::Deprecated::RegisterProtocolFactory("test", NULL); |
359 if (!scheme_.empty()) | 359 if (!scheme_.empty()) |
360 net::URLRequest::Deprecated::RegisterProtocolFactory( | 360 net::URLRequest::Deprecated::RegisterProtocolFactory( |
361 scheme_, old_factory_); | 361 scheme_, old_factory_); |
362 | 362 |
363 EXPECT_TRUE(URLRequestTestDelayedStartJob::DelayedStartQueueEmpty()); | 363 EXPECT_TRUE(URLRequestTestDelayedStartJob::DelayedStartQueueEmpty()); |
364 URLRequestTestDelayedStartJob::ClearQueue(); | 364 URLRequestTestDelayedStartJob::ClearQueue(); |
365 | 365 |
366 DCHECK(test_fixture_ == this); | 366 DCHECK(test_fixture_ == this); |
367 test_fixture_ = NULL; | 367 test_fixture_ = NULL; |
368 | 368 |
369 host_.Shutdown(); | 369 host_.Shutdown(); |
370 | 370 |
371 ChildProcessSecurityPolicy::GetInstance()->Remove(0); | 371 ChildProcessSecurityPolicyImpl::GetInstance()->Remove(0); |
372 | 372 |
373 // Flush the message loop to make application verifiers happy. | 373 // Flush the message loop to make application verifiers happy. |
374 message_loop_.RunAllPending(); | 374 message_loop_.RunAllPending(); |
375 } | 375 } |
376 | 376 |
377 // Creates a request using the current test object as the filter. | 377 // Creates a request using the current test object as the filter. |
378 void MakeTestRequest(int render_view_id, | 378 void MakeTestRequest(int render_view_id, |
379 int request_id, | 379 int request_id, |
380 const GURL& url); | 380 const GURL& url); |
381 | 381 |
382 // Generates a request using the given filter. This will probably be a | 382 // Generates a request using the given filter. This will probably be a |
383 // ForwardingFilter. | 383 // ForwardingFilter. |
384 void MakeTestRequest(ResourceMessageFilter* filter, | 384 void MakeTestRequest(ResourceMessageFilter* filter, |
385 int render_view_id, | 385 int render_view_id, |
386 int request_id, | 386 int request_id, |
387 const GURL& url); | 387 const GURL& url); |
388 | 388 |
389 void CancelRequest(int request_id); | 389 void CancelRequest(int request_id); |
390 | 390 |
391 void PauseRequest(int request_id); | 391 void PauseRequest(int request_id); |
392 | 392 |
393 void ResumeRequest(int request_id); | 393 void ResumeRequest(int request_id); |
394 | 394 |
395 void CompleteStartRequest(int request_id); | 395 void CompleteStartRequest(int request_id); |
396 | 396 |
397 void EnsureTestSchemeIsAllowed() { | 397 void EnsureTestSchemeIsAllowed() { |
398 ChildProcessSecurityPolicy* policy = | 398 ChildProcessSecurityPolicyImpl* policy = |
399 ChildProcessSecurityPolicy::GetInstance(); | 399 ChildProcessSecurityPolicyImpl::GetInstance(); |
400 if (!policy->IsWebSafeScheme("test")) | 400 if (!policy->IsWebSafeScheme("test")) |
401 policy->RegisterWebSafeScheme("test"); | 401 policy->RegisterWebSafeScheme("test"); |
402 } | 402 } |
403 | 403 |
404 // Sets a particular response for any request from now on. To switch back to | 404 // Sets a particular response for any request from now on. To switch back to |
405 // the default bahavior, pass an empty |headers|. |headers| should be raw- | 405 // the default bahavior, pass an empty |headers|. |headers| should be raw- |
406 // formatted (NULLs instead of EOLs). | 406 // formatted (NULLs instead of EOLs). |
407 void SetResponse(const std::string& headers, const std::string& data) { | 407 void SetResponse(const std::string& headers, const std::string& data) { |
408 response_headers_ = headers; | 408 response_headers_ = headers; |
409 response_data_ = data; | 409 response_data_ = data; |
(...skipping 961 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1371 net::URLRequestStatus status; | 1371 net::URLRequestStatus status; |
1372 | 1372 |
1373 void* iter = NULL; | 1373 void* iter = NULL; |
1374 EXPECT_TRUE(IPC::ReadParam(&msgs[0][0], &iter, &request_id)); | 1374 EXPECT_TRUE(IPC::ReadParam(&msgs[0][0], &iter, &request_id)); |
1375 EXPECT_TRUE(IPC::ReadParam(&msgs[0][0], &iter, &status)); | 1375 EXPECT_TRUE(IPC::ReadParam(&msgs[0][0], &iter, &status)); |
1376 | 1376 |
1377 EXPECT_EQ(1, request_id); | 1377 EXPECT_EQ(1, request_id); |
1378 EXPECT_EQ(net::URLRequestStatus::FAILED, status.status()); | 1378 EXPECT_EQ(net::URLRequestStatus::FAILED, status.status()); |
1379 EXPECT_EQ(net::ERR_UNKNOWN_URL_SCHEME, status.error()); | 1379 EXPECT_EQ(net::ERR_UNKNOWN_URL_SCHEME, status.error()); |
1380 } | 1380 } |
OLD | NEW |