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 <memory> | 5 #include <memory> |
6 #include <utility> | 6 #include <utility> |
7 | 7 |
8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
(...skipping 733 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
744 default_context_.set_job_factory(job_factory_.get()); | 744 default_context_.set_job_factory(job_factory_.get()); |
745 default_context_.Init(); | 745 default_context_.Init(); |
746 PlatformTest::SetUp(); | 746 PlatformTest::SetUp(); |
747 } | 747 } |
748 | 748 |
749 virtual void SetUpFactory() { | 749 virtual void SetUpFactory() { |
750 job_factory_impl_->SetProtocolHandler( | 750 job_factory_impl_->SetProtocolHandler( |
751 "data", base::WrapUnique(new DataProtocolHandler)); | 751 "data", base::WrapUnique(new DataProtocolHandler)); |
752 #if !defined(DISABLE_FILE_SUPPORT) | 752 #if !defined(DISABLE_FILE_SUPPORT) |
753 job_factory_impl_->SetProtocolHandler( | 753 job_factory_impl_->SetProtocolHandler( |
754 "file", base::WrapUnique(new FileProtocolHandler( | 754 "file", base::MakeUnique<FileProtocolHandler>( |
755 base::ThreadTaskRunnerHandle::Get()))); | 755 base::ThreadTaskRunnerHandle::Get())); |
756 #endif | 756 #endif |
757 } | 757 } |
758 | 758 |
759 TestNetworkDelegate* default_network_delegate() { | 759 TestNetworkDelegate* default_network_delegate() { |
760 return &default_network_delegate_; | 760 return &default_network_delegate_; |
761 } | 761 } |
762 | 762 |
763 const TestURLRequestContext& default_context() const { | 763 const TestURLRequestContext& default_context() const { |
764 return default_context_; | 764 return default_context_; |
765 } | 765 } |
(...skipping 4920 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5686 base::FilePath dir; | 5686 base::FilePath dir; |
5687 PathService::Get(base::DIR_EXE, &dir); | 5687 PathService::Get(base::DIR_EXE, &dir); |
5688 base::SetCurrentDirectory(dir); | 5688 base::SetCurrentDirectory(dir); |
5689 | 5689 |
5690 std::vector<std::unique_ptr<UploadElementReader>> element_readers; | 5690 std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
5691 | 5691 |
5692 base::FilePath path; | 5692 base::FilePath path; |
5693 PathService::Get(base::DIR_SOURCE_ROOT, &path); | 5693 PathService::Get(base::DIR_SOURCE_ROOT, &path); |
5694 path = path.Append(kTestFilePath); | 5694 path = path.Append(kTestFilePath); |
5695 path = path.Append(FILE_PATH_LITERAL("with-headers.html")); | 5695 path = path.Append(FILE_PATH_LITERAL("with-headers.html")); |
5696 element_readers.push_back(base::WrapUnique(new UploadFileElementReader( | 5696 element_readers.push_back(base::MakeUnique<UploadFileElementReader>( |
5697 base::ThreadTaskRunnerHandle::Get().get(), path, 0, | 5697 base::ThreadTaskRunnerHandle::Get().get(), path, 0, |
5698 std::numeric_limits<uint64_t>::max(), base::Time()))); | 5698 std::numeric_limits<uint64_t>::max(), base::Time())); |
5699 r->set_upload(base::WrapUnique<UploadDataStream>( | 5699 r->set_upload(base::WrapUnique<UploadDataStream>( |
5700 new ElementsUploadDataStream(std::move(element_readers), 0))); | 5700 new ElementsUploadDataStream(std::move(element_readers), 0))); |
5701 | 5701 |
5702 r->Start(); | 5702 r->Start(); |
5703 EXPECT_TRUE(r->is_pending()); | 5703 EXPECT_TRUE(r->is_pending()); |
5704 | 5704 |
5705 base::RunLoop().Run(); | 5705 base::RunLoop().Run(); |
5706 | 5706 |
5707 int64_t size64 = 0; | 5707 int64_t size64 = 0; |
5708 ASSERT_EQ(true, base::GetFileSize(path, &size64)); | 5708 ASSERT_EQ(true, base::GetFileSize(path, &size64)); |
(...skipping 18 matching lines...) Expand all Loading... |
5727 ASSERT_TRUE(http_test_server()->Start()); | 5727 ASSERT_TRUE(http_test_server()->Start()); |
5728 | 5728 |
5729 TestDelegate d; | 5729 TestDelegate d; |
5730 { | 5730 { |
5731 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( | 5731 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( |
5732 http_test_server()->GetURL("/echo"), DEFAULT_PRIORITY, &d)); | 5732 http_test_server()->GetURL("/echo"), DEFAULT_PRIORITY, &d)); |
5733 r->set_method("POST"); | 5733 r->set_method("POST"); |
5734 | 5734 |
5735 std::vector<std::unique_ptr<UploadElementReader>> element_readers; | 5735 std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
5736 | 5736 |
5737 element_readers.push_back(base::WrapUnique(new UploadFileElementReader( | 5737 element_readers.push_back(base::MakeUnique<UploadFileElementReader>( |
5738 base::ThreadTaskRunnerHandle::Get().get(), | 5738 base::ThreadTaskRunnerHandle::Get().get(), |
5739 base::FilePath(FILE_PATH_LITERAL( | 5739 base::FilePath(FILE_PATH_LITERAL( |
5740 "c:\\path\\to\\non\\existant\\file.randomness.12345")), | 5740 "c:\\path\\to\\non\\existant\\file.randomness.12345")), |
5741 0, std::numeric_limits<uint64_t>::max(), base::Time()))); | 5741 0, std::numeric_limits<uint64_t>::max(), base::Time())); |
5742 r->set_upload(base::WrapUnique<UploadDataStream>( | 5742 r->set_upload(base::WrapUnique<UploadDataStream>( |
5743 new ElementsUploadDataStream(std::move(element_readers), 0))); | 5743 new ElementsUploadDataStream(std::move(element_readers), 0))); |
5744 | 5744 |
5745 r->Start(); | 5745 r->Start(); |
5746 EXPECT_TRUE(r->is_pending()); | 5746 EXPECT_TRUE(r->is_pending()); |
5747 | 5747 |
5748 base::RunLoop().Run(); | 5748 base::RunLoop().Run(); |
5749 | 5749 |
5750 EXPECT_TRUE(d.request_failed()); | 5750 EXPECT_TRUE(d.request_failed()); |
5751 EXPECT_FALSE(d.received_data_before_response()); | 5751 EXPECT_FALSE(d.received_data_before_response()); |
(...skipping 4133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9885 base::FilePath(kTestFilePath)) { | 9885 base::FilePath(kTestFilePath)) { |
9886 // Can't use |default_context_|'s HostResolver to set up the | 9886 // Can't use |default_context_|'s HostResolver to set up the |
9887 // FTPTransactionFactory because it hasn't been created yet. | 9887 // FTPTransactionFactory because it hasn't been created yet. |
9888 default_context_.set_host_resolver(&host_resolver_); | 9888 default_context_.set_host_resolver(&host_resolver_); |
9889 } | 9889 } |
9890 | 9890 |
9891 // URLRequestTest interface: | 9891 // URLRequestTest interface: |
9892 void SetUpFactory() override { | 9892 void SetUpFactory() override { |
9893 // Add FTP support to the default URLRequestContext. | 9893 // Add FTP support to the default URLRequestContext. |
9894 job_factory_impl_->SetProtocolHandler( | 9894 job_factory_impl_->SetProtocolHandler( |
9895 "ftp", | 9895 "ftp", base::MakeUnique<FtpProtocolHandler>(&ftp_transaction_factory_)); |
9896 base::WrapUnique(new FtpProtocolHandler(&ftp_transaction_factory_))); | |
9897 } | 9896 } |
9898 | 9897 |
9899 std::string GetTestFileContents() { | 9898 std::string GetTestFileContents() { |
9900 base::FilePath path; | 9899 base::FilePath path; |
9901 EXPECT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &path)); | 9900 EXPECT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &path)); |
9902 path = path.Append(kTestFilePath); | 9901 path = path.Append(kTestFilePath); |
9903 path = path.AppendASCII(kFtpTestFile); | 9902 path = path.AppendASCII(kFtpTestFile); |
9904 std::string contents; | 9903 std::string contents; |
9905 EXPECT_TRUE(base::ReadFileToString(path, &contents)); | 9904 EXPECT_TRUE(base::ReadFileToString(path, &contents)); |
9906 return contents; | 9905 return contents; |
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10240 AddTestInterceptor()->set_main_intercept_job(std::move(job)); | 10239 AddTestInterceptor()->set_main_intercept_job(std::move(job)); |
10241 | 10240 |
10242 req->Start(); | 10241 req->Start(); |
10243 req->Cancel(); | 10242 req->Cancel(); |
10244 base::RunLoop().RunUntilIdle(); | 10243 base::RunLoop().RunUntilIdle(); |
10245 EXPECT_EQ(URLRequestStatus::CANCELED, req->status().status()); | 10244 EXPECT_EQ(URLRequestStatus::CANCELED, req->status().status()); |
10246 EXPECT_EQ(0, d.received_redirect_count()); | 10245 EXPECT_EQ(0, d.received_redirect_count()); |
10247 } | 10246 } |
10248 | 10247 |
10249 } // namespace net | 10248 } // namespace net |
OLD | NEW |