| 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 "build/build_config.h" | 5 #include "build/build_config.h" |
| 6 | 6 |
| 7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
| 8 #include <windows.h> | 8 #include <windows.h> |
| 9 #include <shlobj.h> | 9 #include <shlobj.h> |
| 10 #endif | 10 #endif |
| (...skipping 648 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 659 } | 659 } |
| 660 | 660 |
| 661 void SetUp() override { | 661 void SetUp() override { |
| 662 SetUpFactory(); | 662 SetUpFactory(); |
| 663 default_context_.set_job_factory(job_factory_.get()); | 663 default_context_.set_job_factory(job_factory_.get()); |
| 664 default_context_.Init(); | 664 default_context_.Init(); |
| 665 PlatformTest::SetUp(); | 665 PlatformTest::SetUp(); |
| 666 } | 666 } |
| 667 | 667 |
| 668 virtual void SetUpFactory() { | 668 virtual void SetUpFactory() { |
| 669 job_factory_impl_->SetProtocolHandler("data", new DataProtocolHandler); | 669 job_factory_impl_->SetProtocolHandler( |
| 670 "data", make_scoped_ptr(new DataProtocolHandler)); |
| 670 #if !defined(DISABLE_FILE_SUPPORT) | 671 #if !defined(DISABLE_FILE_SUPPORT) |
| 671 job_factory_impl_->SetProtocolHandler( | 672 job_factory_impl_->SetProtocolHandler( |
| 672 "file", new FileProtocolHandler(base::ThreadTaskRunnerHandle::Get())); | 673 "file", make_scoped_ptr(new FileProtocolHandler( |
| 674 base::ThreadTaskRunnerHandle::Get()))); |
| 673 #endif | 675 #endif |
| 674 } | 676 } |
| 675 | 677 |
| 676 TestNetworkDelegate* default_network_delegate() { | 678 TestNetworkDelegate* default_network_delegate() { |
| 677 return &default_network_delegate_; | 679 return &default_network_delegate_; |
| 678 } | 680 } |
| 679 | 681 |
| 680 const TestURLRequestContext& default_context() const { | 682 const TestURLRequestContext& default_context() const { |
| 681 return default_context_; | 683 return default_context_; |
| 682 } | 684 } |
| 683 | 685 |
| 684 | 686 |
| 685 // Adds the TestJobInterceptor to the default context. | 687 // Adds the TestJobInterceptor to the default context. |
| 686 TestJobInterceptor* AddTestInterceptor() { | 688 TestJobInterceptor* AddTestInterceptor() { |
| 687 TestJobInterceptor* protocol_handler_ = new TestJobInterceptor(); | 689 TestJobInterceptor* protocol_handler_ = new TestJobInterceptor(); |
| 688 job_factory_impl_->SetProtocolHandler("http", NULL); | 690 job_factory_impl_->SetProtocolHandler("http", nullptr); |
| 689 job_factory_impl_->SetProtocolHandler("http", protocol_handler_); | 691 job_factory_impl_->SetProtocolHandler("http", |
| 692 make_scoped_ptr(protocol_handler_)); |
| 690 return protocol_handler_; | 693 return protocol_handler_; |
| 691 } | 694 } |
| 692 | 695 |
| 693 protected: | 696 protected: |
| 694 TestNetLog net_log_; | 697 TestNetLog net_log_; |
| 695 TestNetworkDelegate default_network_delegate_; // Must outlive URLRequest. | 698 TestNetworkDelegate default_network_delegate_; // Must outlive URLRequest. |
| 696 URLRequestJobFactoryImpl* job_factory_impl_; | 699 URLRequestJobFactoryImpl* job_factory_impl_; |
| 697 scoped_ptr<URLRequestJobFactory> job_factory_; | 700 scoped_ptr<URLRequestJobFactory> job_factory_; |
| 698 TestURLRequestContext default_context_; | 701 TestURLRequestContext default_context_; |
| 699 }; | 702 }; |
| (...skipping 8379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9079 base::FilePath(kTestFilePath)) { | 9082 base::FilePath(kTestFilePath)) { |
| 9080 // Can't use |default_context_|'s HostResolver to set up the | 9083 // Can't use |default_context_|'s HostResolver to set up the |
| 9081 // FTPTransactionFactory because it hasn't been created yet. | 9084 // FTPTransactionFactory because it hasn't been created yet. |
| 9082 default_context_.set_host_resolver(&host_resolver_); | 9085 default_context_.set_host_resolver(&host_resolver_); |
| 9083 } | 9086 } |
| 9084 | 9087 |
| 9085 // URLRequestTest interface: | 9088 // URLRequestTest interface: |
| 9086 void SetUpFactory() override { | 9089 void SetUpFactory() override { |
| 9087 // Add FTP support to the default URLRequestContext. | 9090 // Add FTP support to the default URLRequestContext. |
| 9088 job_factory_impl_->SetProtocolHandler( | 9091 job_factory_impl_->SetProtocolHandler( |
| 9089 "ftp", new FtpProtocolHandler(&ftp_transaction_factory_)); | 9092 "ftp", |
| 9093 make_scoped_ptr(new FtpProtocolHandler(&ftp_transaction_factory_))); |
| 9090 } | 9094 } |
| 9091 | 9095 |
| 9092 std::string GetTestFileContents() { | 9096 std::string GetTestFileContents() { |
| 9093 base::FilePath path; | 9097 base::FilePath path; |
| 9094 EXPECT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &path)); | 9098 EXPECT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &path)); |
| 9095 path = path.Append(kTestFilePath); | 9099 path = path.Append(kTestFilePath); |
| 9096 path = path.AppendASCII(kFtpTestFile); | 9100 path = path.AppendASCII(kFtpTestFile); |
| 9097 std::string contents; | 9101 std::string contents; |
| 9098 EXPECT_TRUE(base::ReadFileToString(path, &contents)); | 9102 EXPECT_TRUE(base::ReadFileToString(path, &contents)); |
| 9099 return contents; | 9103 return contents; |
| (...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9441 | 9445 |
| 9442 req->Start(); | 9446 req->Start(); |
| 9443 req->Cancel(); | 9447 req->Cancel(); |
| 9444 job->DetachRequest(); | 9448 job->DetachRequest(); |
| 9445 base::RunLoop().RunUntilIdle(); | 9449 base::RunLoop().RunUntilIdle(); |
| 9446 EXPECT_EQ(URLRequestStatus::CANCELED, req->status().status()); | 9450 EXPECT_EQ(URLRequestStatus::CANCELED, req->status().status()); |
| 9447 EXPECT_EQ(0, d.received_redirect_count()); | 9451 EXPECT_EQ(0, d.received_redirect_count()); |
| 9448 } | 9452 } |
| 9449 | 9453 |
| 9450 } // namespace net | 9454 } // namespace net |
| OLD | NEW |