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

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

Issue 305443005: Remove ProtocolFactory use from resource_dispatcher_host_unittest.cc (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
(...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after
453 base::SplitString(url.path(), ',', &parts); 453 base::SplitString(url.path(), ',', &parts);
454 454
455 if (parts.size() != 2) 455 if (parts.size() != 2)
456 return false; 456 return false;
457 457
458 *text = parts[0]; 458 *text = parts[0];
459 return base::StringToInt(parts[1], count); 459 return base::StringToInt(parts[1], count);
460 } 460 }
461 }; 461 };
462 462
463 class TestURLRequestJobFactory : public net::URLRequestJobFactory {
464 public:
465 explicit TestURLRequestJobFactory(ResourceDispatcherHostTest* test_fixture) :
466 test_fixture_(test_fixture),
467 delay_start_(false),
468 delay_complete_(false),
469 network_start_notification_(false),
470 url_request_jobs_created_count_(0) {
471 }
472
473 void HandleScheme(const std::string& scheme) {
474 supported_schemes_.insert(scheme);
475 }
476
477 int url_request_jobs_created_count() const {
478 return url_request_jobs_created_count_;
479 }
480
481 void SetDelayedStartJobGeneration(bool delay_job_start) {
482 delay_start_ = delay_job_start;
483 }
484
485 void SetDelayedCompleteJobGeneration(bool delay_job_complete) {
486 delay_complete_ = delay_job_complete;
487 }
488
489 void SetNetworkStartNotificationJobGeneration(bool notification) {
490 network_start_notification_ = notification;
491 }
492
493 virtual net::URLRequestJob* MaybeCreateJobWithProtocolHandler(
494 const std::string& scheme,
495 net::URLRequest* request,
496 net::NetworkDelegate* network_delegate) const OVERRIDE;
497
498 virtual bool IsHandledProtocol(const std::string& scheme) const OVERRIDE {
499 return supported_schemes_.count(scheme) > 0;
500 }
501
502 virtual bool IsHandledURL(const GURL& url) const OVERRIDE {
503 return supported_schemes_.count(url.scheme()) > 0;
504 }
505
506 virtual bool IsSafeRedirectTarget(const GURL& location) const OVERRIDE {
507 return false;
508 }
509
510 private:
511 ResourceDispatcherHostTest* test_fixture_;
512 bool delay_start_;
513 bool delay_complete_;
514 bool network_start_notification_;
515 mutable int url_request_jobs_created_count_;
516 std::set<std::string> supported_schemes_;
517
518 DISALLOW_COPY_AND_ASSIGN(TestURLRequestJobFactory);
519 };
520
463 // Associated with an URLRequest to determine if the URLRequest gets deleted. 521 // Associated with an URLRequest to determine if the URLRequest gets deleted.
464 class TestUserData : public base::SupportsUserData::Data { 522 class TestUserData : public base::SupportsUserData::Data {
465 public: 523 public:
466 explicit TestUserData(bool* was_deleted) 524 explicit TestUserData(bool* was_deleted)
467 : was_deleted_(was_deleted) { 525 : was_deleted_(was_deleted) {
468 } 526 }
469 527
470 virtual ~TestUserData() { 528 virtual ~TestUserData() {
471 *was_deleted_ = true; 529 *was_deleted_ = true;
472 } 530 }
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
656 public IPC::Sender { 714 public IPC::Sender {
657 public: 715 public:
658 ResourceDispatcherHostTest() 716 ResourceDispatcherHostTest()
659 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), 717 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP),
660 old_factory_(NULL), 718 old_factory_(NULL),
661 send_data_received_acks_(false) { 719 send_data_received_acks_(false) {
662 browser_context_.reset(new TestBrowserContext()); 720 browser_context_.reset(new TestBrowserContext());
663 BrowserContext::EnsureResourceContextInitialized(browser_context_.get()); 721 BrowserContext::EnsureResourceContextInitialized(browser_context_.get());
664 base::RunLoop().RunUntilIdle(); 722 base::RunLoop().RunUntilIdle();
665 filter_ = MakeForwardingFilter(); 723 filter_ = MakeForwardingFilter();
666 ResourceContext* resource_context = browser_context_->GetResourceContext(); 724 // TODO(cbentzel): Better way to get URLRequestContext?
667 resource_context->GetRequestContext()->set_network_delegate( 725 net::URLRequestContext* request_context =
668 &network_delegate_); 726 browser_context_->GetResourceContext()->GetRequestContext();
727 job_factory_.reset(new TestURLRequestJobFactory(this));
728 request_context->set_job_factory(job_factory_.get());
729 request_context->set_network_delegate(&network_delegate_);
669 } 730 }
670 731
671 // IPC::Sender implementation 732 // IPC::Sender implementation
672 virtual bool Send(IPC::Message* msg) OVERRIDE { 733 virtual bool Send(IPC::Message* msg) OVERRIDE {
673 accum_.AddMessage(*msg); 734 accum_.AddMessage(*msg);
674 735
675 if (send_data_received_acks_ && 736 if (send_data_received_acks_ &&
676 msg->type() == ResourceMsg_DataReceived::ID) { 737 msg->type() == ResourceMsg_DataReceived::ID) {
677 GenerateDataReceivedACK(*msg); 738 GenerateDataReceivedACK(*msg);
678 } 739 }
679 740
680 if (wait_for_request_complete_loop_ && 741 if (wait_for_request_complete_loop_ &&
681 msg->type() == ResourceMsg_RequestComplete::ID) { 742 msg->type() == ResourceMsg_RequestComplete::ID) {
682 wait_for_request_complete_loop_->Quit(); 743 wait_for_request_complete_loop_->Quit();
683 } 744 }
684 745
685 // Do not release handles in it yet; the accumulator owns them now. 746 // Do not release handles in it yet; the accumulator owns them now.
686 delete msg; 747 delete msg;
687 return true; 748 return true;
688 } 749 }
689 750
690 protected: 751 protected:
752 friend class TestURLRequestJobFactory;
753
691 // testing::Test 754 // testing::Test
692 virtual void SetUp() OVERRIDE { 755 virtual void SetUp() OVERRIDE {
693 DCHECK(!test_fixture_);
694 test_fixture_ = this;
695 ChildProcessSecurityPolicyImpl::GetInstance()->Add(0); 756 ChildProcessSecurityPolicyImpl::GetInstance()->Add(0);
696 net::URLRequest::Deprecated::RegisterProtocolFactory( 757 HandleScheme("test");
697 "test",
698 &ResourceDispatcherHostTest::Factory);
699 EnsureTestSchemeIsAllowed();
700 delay_start_ = false;
701 delay_complete_ = false;
702 network_start_notification_ = false;
703 url_request_jobs_created_count_ = 0;
704 } 758 }
705 759
706 virtual void TearDown() { 760 virtual void TearDown() {
707 net::URLRequest::Deprecated::RegisterProtocolFactory("test", NULL);
708 if (!scheme_.empty())
709 net::URLRequest::Deprecated::RegisterProtocolFactory(
710 scheme_, old_factory_);
711
712 EXPECT_TRUE(URLRequestTestDelayedStartJob::DelayedStartQueueEmpty()); 761 EXPECT_TRUE(URLRequestTestDelayedStartJob::DelayedStartQueueEmpty());
713 URLRequestTestDelayedStartJob::ClearQueue(); 762 URLRequestTestDelayedStartJob::ClearQueue();
714 763
715 DCHECK(test_fixture_ == this);
716 test_fixture_ = NULL;
717
718 for (std::set<int>::iterator it = child_ids_.begin(); 764 for (std::set<int>::iterator it = child_ids_.begin();
719 it != child_ids_.end(); ++it) { 765 it != child_ids_.end(); ++it) {
720 host_.CancelRequestsForProcess(*it); 766 host_.CancelRequestsForProcess(*it);
721 } 767 }
722 768
723 host_.Shutdown(); 769 host_.Shutdown();
724 770
725 ChildProcessSecurityPolicyImpl::GetInstance()->Remove(0); 771 ChildProcessSecurityPolicyImpl::GetInstance()->Remove(0);
726 772
727 // Flush the message loop to make application verifiers happy. 773 // Flush the message loop to make application verifiers happy.
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
768 814
769 net::TestNetworkDelegate* network_delegate() { return &network_delegate_; } 815 net::TestNetworkDelegate* network_delegate() { return &network_delegate_; }
770 816
771 void EnsureSchemeIsAllowed(const std::string& scheme) { 817 void EnsureSchemeIsAllowed(const std::string& scheme) {
772 ChildProcessSecurityPolicyImpl* policy = 818 ChildProcessSecurityPolicyImpl* policy =
773 ChildProcessSecurityPolicyImpl::GetInstance(); 819 ChildProcessSecurityPolicyImpl::GetInstance();
774 if (!policy->IsWebSafeScheme(scheme)) 820 if (!policy->IsWebSafeScheme(scheme))
775 policy->RegisterWebSafeScheme(scheme); 821 policy->RegisterWebSafeScheme(scheme);
776 } 822 }
777 823
778 void EnsureTestSchemeIsAllowed() {
779 EnsureSchemeIsAllowed("test");
780 }
781
782 // Sets a particular response for any request from now on. To switch back to 824 // Sets a particular response for any request from now on. To switch back to
783 // the default bahavior, pass an empty |headers|. |headers| should be raw- 825 // the default bahavior, pass an empty |headers|. |headers| should be raw-
784 // formatted (NULLs instead of EOLs). 826 // formatted (NULLs instead of EOLs).
785 void SetResponse(const std::string& headers, const std::string& data) { 827 void SetResponse(const std::string& headers, const std::string& data) {
786 response_headers_ = net::HttpUtil::AssembleRawHeaders(headers.data(), 828 response_headers_ = net::HttpUtil::AssembleRawHeaders(headers.data(),
787 headers.size()); 829 headers.size());
788 response_data_ = data; 830 response_data_ = data;
789 } 831 }
790 void SetResponse(const std::string& headers) { 832 void SetResponse(const std::string& headers) {
791 SetResponse(headers, std::string()); 833 SetResponse(headers, std::string());
792 } 834 }
793 835
794 void SendDataReceivedACKs(bool send_acks) { 836 void SendDataReceivedACKs(bool send_acks) {
795 send_data_received_acks_ = send_acks; 837 send_data_received_acks_ = send_acks;
796 } 838 }
797 839
798 // Intercepts requests for the given protocol. 840 // Intercepts requests for the given protocol.
799 void HandleScheme(const std::string& scheme) { 841 void HandleScheme(const std::string& scheme) {
800 DCHECK(scheme_.empty()); 842 job_factory_->HandleScheme(scheme);
801 DCHECK(!old_factory_);
802 scheme_ = scheme;
803 old_factory_ = net::URLRequest::Deprecated::RegisterProtocolFactory(
804 scheme_, &ResourceDispatcherHostTest::Factory);
805 EnsureSchemeIsAllowed(scheme); 843 EnsureSchemeIsAllowed(scheme);
806 } 844 }
807 845
808 // Our own net::URLRequestJob factory.
809 static net::URLRequestJob* Factory(net::URLRequest* request,
810 net::NetworkDelegate* network_delegate,
811 const std::string& scheme) {
812 url_request_jobs_created_count_++;
813 if (test_fixture_->response_headers_.empty()) {
814 if (delay_start_) {
815 return new URLRequestTestDelayedStartJob(request, network_delegate);
816 } else if (delay_complete_) {
817 return new URLRequestTestDelayedCompletionJob(request,
818 network_delegate);
819 } else if (network_start_notification_) {
820 return new URLRequestTestDelayedNetworkJob(request, network_delegate);
821 } else if (scheme == "big-job") {
822 return new URLRequestBigJob(request, network_delegate);
823 } else {
824 return new net::URLRequestTestJob(request, network_delegate);
825 }
826 } else {
827 if (delay_start_) {
828 return new URLRequestTestDelayedStartJob(
829 request, network_delegate,
830 test_fixture_->response_headers_, test_fixture_->response_data_,
831 false);
832 } else if (delay_complete_) {
833 return new URLRequestTestDelayedCompletionJob(
834 request, network_delegate,
835 test_fixture_->response_headers_, test_fixture_->response_data_,
836 false);
837 } else {
838 return new net::URLRequestTestJob(
839 request, network_delegate,
840 test_fixture_->response_headers_, test_fixture_->response_data_,
841 false);
842 }
843 }
844 }
845
846 void SetDelayedStartJobGeneration(bool delay_job_start) {
847 delay_start_ = delay_job_start;
848 }
849
850 void SetDelayedCompleteJobGeneration(bool delay_job_complete) {
851 delay_complete_ = delay_job_complete;
852 }
853
854 void SetNetworkStartNotificationJobGeneration(bool notification) {
855 network_start_notification_ = notification;
856 }
857
858 void GenerateDataReceivedACK(const IPC::Message& msg) { 846 void GenerateDataReceivedACK(const IPC::Message& msg) {
859 EXPECT_EQ(ResourceMsg_DataReceived::ID, msg.type()); 847 EXPECT_EQ(ResourceMsg_DataReceived::ID, msg.type());
860 848
861 int request_id = -1; 849 int request_id = -1;
862 bool result = PickleIterator(msg).ReadInt(&request_id); 850 bool result = PickleIterator(msg).ReadInt(&request_id);
863 DCHECK(result); 851 DCHECK(result);
864 scoped_ptr<IPC::Message> ack( 852 scoped_ptr<IPC::Message> ack(
865 new ResourceHostMsg_DataReceived_ACK(request_id)); 853 new ResourceHostMsg_DataReceived_ACK(request_id));
866 854
867 base::MessageLoop::current()->PostTask( 855 base::MessageLoop::current()->PostTask(
(...skipping 11 matching lines...) Expand all
879 867
880 void WaitForRequestComplete() { 868 void WaitForRequestComplete() {
881 DCHECK(!wait_for_request_complete_loop_); 869 DCHECK(!wait_for_request_complete_loop_);
882 wait_for_request_complete_loop_.reset(new base::RunLoop); 870 wait_for_request_complete_loop_.reset(new base::RunLoop);
883 wait_for_request_complete_loop_->Run(); 871 wait_for_request_complete_loop_->Run();
884 wait_for_request_complete_loop_.reset(); 872 wait_for_request_complete_loop_.reset();
885 } 873 }
886 874
887 content::TestBrowserThreadBundle thread_bundle_; 875 content::TestBrowserThreadBundle thread_bundle_;
888 scoped_ptr<TestBrowserContext> browser_context_; 876 scoped_ptr<TestBrowserContext> browser_context_;
877 scoped_ptr<TestURLRequestJobFactory> job_factory_;
889 scoped_refptr<ForwardingFilter> filter_; 878 scoped_refptr<ForwardingFilter> filter_;
890 net::TestNetworkDelegate network_delegate_; 879 net::TestNetworkDelegate network_delegate_;
891 ResourceDispatcherHostImpl host_; 880 ResourceDispatcherHostImpl host_;
892 ResourceIPCAccumulator accum_; 881 ResourceIPCAccumulator accum_;
893 std::string response_headers_; 882 std::string response_headers_;
894 std::string response_data_; 883 std::string response_data_;
895 std::string scheme_; 884 std::string scheme_;
896 net::URLRequest::ProtocolFactory* old_factory_; 885 net::URLRequest::ProtocolFactory* old_factory_;
897 bool send_data_received_acks_; 886 bool send_data_received_acks_;
898 std::set<int> child_ids_; 887 std::set<int> child_ids_;
899 scoped_ptr<base::RunLoop> wait_for_request_complete_loop_; 888 scoped_ptr<base::RunLoop> wait_for_request_complete_loop_;
900 static ResourceDispatcherHostTest* test_fixture_;
901 static bool delay_start_;
902 static bool delay_complete_;
903 static bool network_start_notification_;
904 static int url_request_jobs_created_count_;
905 }; 889 };
906 // Static.
907 ResourceDispatcherHostTest* ResourceDispatcherHostTest::test_fixture_ = NULL;
908 bool ResourceDispatcherHostTest::delay_start_ = false;
909 bool ResourceDispatcherHostTest::delay_complete_ = false;
910 bool ResourceDispatcherHostTest::network_start_notification_ = false;
911 int ResourceDispatcherHostTest::url_request_jobs_created_count_ = 0;
912 890
913 void ResourceDispatcherHostTest::MakeTestRequest(int render_view_id, 891 void ResourceDispatcherHostTest::MakeTestRequest(int render_view_id,
914 int request_id, 892 int request_id,
915 const GURL& url) { 893 const GURL& url) {
916 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id, 894 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id,
917 url, ResourceType::SUB_RESOURCE); 895 url, ResourceType::SUB_RESOURCE);
918 } 896 }
919 897
920 void ResourceDispatcherHostTest::MakeTestRequestWithResourceType( 898 void ResourceDispatcherHostTest::MakeTestRequestWithResourceType(
921 ResourceMessageFilter* filter, 899 ResourceMessageFilter* filter,
(...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after
1362 base::MessageLoop::current()->RunUntilIdle(); 1340 base::MessageLoop::current()->RunUntilIdle();
1363 1341
1364 ResourceIPCAccumulator::ClassifiedMessages msgs; 1342 ResourceIPCAccumulator::ClassifiedMessages msgs;
1365 accum_.GetClassifiedMessages(&msgs); 1343 accum_.GetClassifiedMessages(&msgs);
1366 1344
1367 // Check that request got canceled. 1345 // Check that request got canceled.
1368 ASSERT_EQ(1U, msgs[0].size()); 1346 ASSERT_EQ(1U, msgs[0].size());
1369 CheckRequestCompleteErrorCode(msgs[0][0], net::ERR_ABORTED); 1347 CheckRequestCompleteErrorCode(msgs[0][0], net::ERR_ABORTED);
1370 1348
1371 // Make sure URLRequest is never started. 1349 // Make sure URLRequest is never started.
1372 EXPECT_EQ(0, url_request_jobs_created_count_); 1350 EXPECT_EQ(0, job_factory_->url_request_jobs_created_count());
1373 } 1351 }
1374 1352
1375 TEST_F(ResourceDispatcherHostTest, PausedStartError) { 1353 TEST_F(ResourceDispatcherHostTest, PausedStartError) {
1376 // Arrange to have requests deferred before processing response headers. 1354 // Arrange to have requests deferred before processing response headers.
1377 TestResourceDispatcherHostDelegate delegate; 1355 TestResourceDispatcherHostDelegate delegate;
1378 delegate.set_flags(DEFER_PROCESSING_RESPONSE); 1356 delegate.set_flags(DEFER_PROCESSING_RESPONSE);
1379 host_.SetDelegate(&delegate); 1357 host_.SetDelegate(&delegate);
1380 1358
1381 SetDelayedStartJobGeneration(true); 1359 job_factory_->SetDelayedStartJobGeneration(true);
1382 MakeTestRequest(0, 1, net::URLRequestTestJob::test_url_error()); 1360 MakeTestRequest(0, 1, net::URLRequestTestJob::test_url_error());
1383 CompleteStartRequest(1); 1361 CompleteStartRequest(1);
1384 1362
1385 // flush all the pending requests 1363 // flush all the pending requests
1386 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} 1364 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {}
1387 base::MessageLoop::current()->RunUntilIdle(); 1365 base::MessageLoop::current()->RunUntilIdle();
1388 1366
1389 EXPECT_EQ(0, host_.pending_requests()); 1367 EXPECT_EQ(0, host_.pending_requests());
1390 } 1368 }
1391 1369
1392 // Test the OnBeforeNetworkStart throttle. 1370 // Test the OnBeforeNetworkStart throttle.
1393 TEST_F(ResourceDispatcherHostTest, ThrottleNetworkStart) { 1371 TEST_F(ResourceDispatcherHostTest, ThrottleNetworkStart) {
1394 // Arrange to have requests deferred before processing response headers. 1372 // Arrange to have requests deferred before processing response headers.
1395 TestResourceDispatcherHostDelegate delegate; 1373 TestResourceDispatcherHostDelegate delegate;
1396 delegate.set_flags(DEFER_NETWORK_START); 1374 delegate.set_flags(DEFER_NETWORK_START);
1397 host_.SetDelegate(&delegate); 1375 host_.SetDelegate(&delegate);
1398 1376
1399 SetNetworkStartNotificationJobGeneration(true); 1377 job_factory_->SetNetworkStartNotificationJobGeneration(true);
1400 MakeTestRequest(0, 1, net::URLRequestTestJob::test_url_2()); 1378 MakeTestRequest(0, 1, net::URLRequestTestJob::test_url_2());
1401 1379
1402 // Should have deferred for network start. 1380 // Should have deferred for network start.
1403 GenericResourceThrottle* first_throttle = 1381 GenericResourceThrottle* first_throttle =
1404 GenericResourceThrottle::active_throttle(); 1382 GenericResourceThrottle::active_throttle();
1405 ASSERT_TRUE(first_throttle); 1383 ASSERT_TRUE(first_throttle);
1406 EXPECT_EQ(0, network_delegate()->completed_requests()); 1384 EXPECT_EQ(0, network_delegate()->completed_requests());
1407 EXPECT_EQ(1, host_.pending_requests()); 1385 EXPECT_EQ(1, host_.pending_requests());
1408 1386
1409 first_throttle->Resume(); 1387 first_throttle->Resume();
(...skipping 689 matching lines...) Expand 10 before | Expand all | Expand 10 after
2099 std::string response_data("01234567890123456789\x01foobar"); 2077 std::string response_data("01234567890123456789\x01foobar");
2100 2078
2101 // Get past sniffing metrics in the BufferedResourceHandler. Note that 2079 // Get past sniffing metrics in the BufferedResourceHandler. Note that
2102 // if we don't get past the sniffing metrics, the result will be that 2080 // if we don't get past the sniffing metrics, the result will be that
2103 // the BufferedResourceHandler won't have figured out that it's a download, 2081 // the BufferedResourceHandler won't have figured out that it's a download,
2104 // won't have constructed a DownloadResourceHandler, and and the request 2082 // won't have constructed a DownloadResourceHandler, and and the request
2105 // will be successfully canceled below, failing the test. 2083 // will be successfully canceled below, failing the test.
2106 response_data.resize(1025, ' '); 2084 response_data.resize(1025, ' ');
2107 2085
2108 SetResponse(raw_headers, response_data); 2086 SetResponse(raw_headers, response_data);
2109 SetDelayedCompleteJobGeneration(true); 2087 job_factory_->SetDelayedCompleteJobGeneration(true);
2110 HandleScheme("http"); 2088 HandleScheme("http");
2111 2089
2112 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id, 2090 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id,
2113 GURL("http://example.com/blah"), 2091 GURL("http://example.com/blah"),
2114 ResourceType::MAIN_FRAME); 2092 ResourceType::MAIN_FRAME);
2115 // Return some data so that the request is identified as a download 2093 // Return some data so that the request is identified as a download
2116 // and the proper resource handlers are created. 2094 // and the proper resource handlers are created.
2117 EXPECT_TRUE(net::URLRequestTestJob::ProcessOnePendingMessage()); 2095 EXPECT_TRUE(net::URLRequestTestJob::ProcessOnePendingMessage());
2118 2096
2119 // And now simulate a cancellation coming from the renderer. 2097 // And now simulate a cancellation coming from the renderer.
(...skipping 14 matching lines...) Expand all
2134 int render_view_id = 0; 2112 int render_view_id = 0;
2135 int request_id = 1; 2113 int request_id = 1;
2136 2114
2137 std::string raw_headers("HTTP\n" 2115 std::string raw_headers("HTTP\n"
2138 "Content-disposition: attachment; filename=foo\n\n"); 2116 "Content-disposition: attachment; filename=foo\n\n");
2139 std::string response_data("01234567890123456789\x01foobar"); 2117 std::string response_data("01234567890123456789\x01foobar");
2140 // Get past sniffing metrics. 2118 // Get past sniffing metrics.
2141 response_data.resize(1025, ' '); 2119 response_data.resize(1025, ' ');
2142 2120
2143 SetResponse(raw_headers, response_data); 2121 SetResponse(raw_headers, response_data);
2144 SetDelayedCompleteJobGeneration(true); 2122 job_factory_->SetDelayedCompleteJobGeneration(true);
2145 HandleScheme("http"); 2123 HandleScheme("http");
2146 2124
2147 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id, 2125 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id,
2148 GURL("http://example.com/blah"), 2126 GURL("http://example.com/blah"),
2149 ResourceType::MAIN_FRAME); 2127 ResourceType::MAIN_FRAME);
2150 // Return some data so that the request is identified as a download 2128 // Return some data so that the request is identified as a download
2151 // and the proper resource handlers are created. 2129 // and the proper resource handlers are created.
2152 EXPECT_TRUE(net::URLRequestTestJob::ProcessOnePendingMessage()); 2130 EXPECT_TRUE(net::URLRequestTestJob::ProcessOnePendingMessage());
2153 2131
2154 // And now simulate a cancellation coming from the renderer. 2132 // And now simulate a cancellation coming from the renderer.
(...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after
2612 std::string raw_headers("HTTP\n" 2590 std::string raw_headers("HTTP\n"
2613 "Content-type: image/jpeg\n\n"); 2591 "Content-type: image/jpeg\n\n");
2614 std::string response_data("01234567890123456789\x01foobar"); 2592 std::string response_data("01234567890123456789\x01foobar");
2615 2593
2616 // Create a response larger than kMaxAllocationSize (currently 32K). Note 2594 // Create a response larger than kMaxAllocationSize (currently 32K). Note
2617 // that if this increase beyond 512K we'll need to make the response longer. 2595 // that if this increase beyond 512K we'll need to make the response longer.
2618 const int kAllocSize = 1024*512; 2596 const int kAllocSize = 1024*512;
2619 response_data.resize(kAllocSize, ' '); 2597 response_data.resize(kAllocSize, ' ');
2620 2598
2621 SetResponse(raw_headers, response_data); 2599 SetResponse(raw_headers, response_data);
2622 SetDelayedCompleteJobGeneration(true); 2600 job_factory_->SetDelayedCompleteJobGeneration(true);
2623 HandleScheme("http"); 2601 HandleScheme("http");
2624 2602
2625 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id, 2603 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id,
2626 GURL("http://example.com/blah"), 2604 GURL("http://example.com/blah"),
2627 ResourceType::PREFETCH); 2605 ResourceType::PREFETCH);
2628 2606
2629 // Get a bit of data before cancelling. 2607 // Get a bit of data before cancelling.
2630 EXPECT_TRUE(net::URLRequestTestJob::ProcessOnePendingMessage()); 2608 EXPECT_TRUE(net::URLRequestTestJob::ProcessOnePendingMessage());
2631 2609
2632 // Simulate a cancellation coming from the renderer. 2610 // Simulate a cancellation coming from the renderer.
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
2901 // The release callback runs before the delete is scheduled, so pump the 2879 // The release callback runs before the delete is scheduled, so pump the
2902 // message loop for the delete itself. (This relies on the delete happening on 2880 // message loop for the delete itself. (This relies on the delete happening on
2903 // the FILE thread which is mapped to main thread in this test.) 2881 // the FILE thread which is mapped to main thread in this test.)
2904 base::RunLoop().RunUntilIdle(); 2882 base::RunLoop().RunUntilIdle();
2905 2883
2906 EXPECT_FALSE(base::PathExists(response_head.download_file_path)); 2884 EXPECT_FALSE(base::PathExists(response_head.download_file_path));
2907 EXPECT_FALSE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile( 2885 EXPECT_FALSE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile(
2908 filter_->child_id(), response_head.download_file_path)); 2886 filter_->child_id(), response_head.download_file_path));
2909 } 2887 }
2910 2888
2889 net::URLRequestJob* TestURLRequestJobFactory::MaybeCreateJobWithProtocolHandler(
2890 const std::string& scheme,
2891 net::URLRequest* request,
2892 net::NetworkDelegate* network_delegate) const {
2893 url_request_jobs_created_count_++;
2894 if (test_fixture_->response_headers_.empty()) {
2895 if (delay_start_) {
2896 return new URLRequestTestDelayedStartJob(request, network_delegate);
2897 } else if (delay_complete_) {
2898 return new URLRequestTestDelayedCompletionJob(request,
2899 network_delegate);
2900 } else if (network_start_notification_) {
2901 return new URLRequestTestDelayedNetworkJob(request, network_delegate);
2902 } else if (scheme == "big-job") {
2903 return new URLRequestBigJob(request, network_delegate);
2904 } else {
2905 return new net::URLRequestTestJob(request, network_delegate);
2906 }
2907 } else {
2908 if (delay_start_) {
2909 return new URLRequestTestDelayedStartJob(
2910 request, network_delegate,
2911 test_fixture_->response_headers_, test_fixture_->response_data_,
2912 false);
2913 } else if (delay_complete_) {
2914 return new URLRequestTestDelayedCompletionJob(
2915 request, network_delegate,
2916 test_fixture_->response_headers_, test_fixture_->response_data_,
2917 false);
2918 } else {
2919 return new net::URLRequestTestJob(
2920 request, network_delegate,
2921 test_fixture_->response_headers_, test_fixture_->response_data_,
2922 false);
2923 }
2924 }
2925 }
2926
2911 } // namespace content 2927 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698