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

Side by Side Diff: net/url_request/url_request_unittest.cc

Issue 2428143002: Clean up FtpTransactionFacory ownership. (Closed)
Patch Set: --typos Created 4 years, 2 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
« no previous file with comments | « net/url_request/url_request_ftp_job_unittest.cc ('k') | 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 <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 9840 matching lines...) Expand 10 before | Expand all | Expand 10 after
9851 } 9851 }
9852 #endif // !defined(OS_IOS) 9852 #endif // !defined(OS_IOS)
9853 9853
9854 #if !defined(DISABLE_FTP_SUPPORT) && !defined(OS_ANDROID) 9854 #if !defined(DISABLE_FTP_SUPPORT) && !defined(OS_ANDROID)
9855 // These tests aren't passing on Android. Either the RemoteTestServer isn't 9855 // These tests aren't passing on Android. Either the RemoteTestServer isn't
9856 // starting up successfully, or it can't access the test files. 9856 // starting up successfully, or it can't access the test files.
9857 // TODO(mmenke): Fix this. See http://crbug.com/495220 9857 // TODO(mmenke): Fix this. See http://crbug.com/495220
9858 class URLRequestTestFTP : public URLRequestTest { 9858 class URLRequestTestFTP : public URLRequestTest {
9859 public: 9859 public:
9860 URLRequestTestFTP() 9860 URLRequestTestFTP()
9861 : ftp_transaction_factory_(&host_resolver_), 9861 : ftp_test_server_(SpawnedTestServer::TYPE_FTP,
9862 ftp_test_server_(SpawnedTestServer::TYPE_FTP,
9863 SpawnedTestServer::kLocalhost, 9862 SpawnedTestServer::kLocalhost,
9864 base::FilePath(kTestFilePath)) { 9863 base::FilePath(kTestFilePath)) {
9865 // Can't use |default_context_|'s HostResolver to set up the 9864 // Can't use |default_context_|'s HostResolver to set up the
9866 // FTPTransactionFactory because it hasn't been created yet. 9865 // FTPTransactionFactory because it hasn't been created yet.
9867 default_context_.set_host_resolver(&host_resolver_); 9866 default_context_.set_host_resolver(&host_resolver_);
9868 } 9867 }
9869 9868
9870 // URLRequestTest interface: 9869 // URLRequestTest interface:
9871 void SetUpFactory() override { 9870 void SetUpFactory() override {
9872 // Add FTP support to the default URLRequestContext. 9871 // Add FTP support to the default URLRequestContext.
9873 job_factory_impl_->SetProtocolHandler( 9872 job_factory_impl_->SetProtocolHandler(
9874 "ftp", base::MakeUnique<FtpProtocolHandler>(&ftp_transaction_factory_)); 9873 "ftp", FtpProtocolHandler::Create(&host_resolver_));
9875 } 9874 }
9876 9875
9877 std::string GetTestFileContents() { 9876 std::string GetTestFileContents() {
9878 base::FilePath path; 9877 base::FilePath path;
9879 EXPECT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &path)); 9878 EXPECT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &path));
9880 path = path.Append(kTestFilePath); 9879 path = path.Append(kTestFilePath);
9881 path = path.AppendASCII(kFtpTestFile); 9880 path = path.AppendASCII(kFtpTestFile);
9882 std::string contents; 9881 std::string contents;
9883 EXPECT_TRUE(base::ReadFileToString(path, &contents)); 9882 EXPECT_TRUE(base::ReadFileToString(path, &contents));
9884 return contents; 9883 return contents;
9885 } 9884 }
9886 9885
9887 protected: 9886 protected:
9887 // Note that this is destroyed before the FtpProtocolHandler that references
9888 // it, which is owned by the parent class. Since no requests are made during
9889 // teardown, this works, though it's not great.
9888 MockHostResolver host_resolver_; 9890 MockHostResolver host_resolver_;
9889 FtpNetworkLayer ftp_transaction_factory_;
9890 9891
9891 SpawnedTestServer ftp_test_server_; 9892 SpawnedTestServer ftp_test_server_;
9892 }; 9893 };
9893 9894
9894 // Make sure an FTP request using an unsafe ports fails. 9895 // Make sure an FTP request using an unsafe ports fails.
9895 TEST_F(URLRequestTestFTP, UnsafePort) { 9896 TEST_F(URLRequestTestFTP, UnsafePort) {
9896 GURL url("ftp://127.0.0.1:7"); 9897 GURL url("ftp://127.0.0.1:7");
9897 9898
9898 TestDelegate d; 9899 TestDelegate d;
9899 { 9900 {
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
10217 AddTestInterceptor()->set_main_intercept_job(std::move(job)); 10218 AddTestInterceptor()->set_main_intercept_job(std::move(job));
10218 10219
10219 req->Start(); 10220 req->Start();
10220 req->Cancel(); 10221 req->Cancel();
10221 base::RunLoop().RunUntilIdle(); 10222 base::RunLoop().RunUntilIdle();
10222 EXPECT_EQ(ERR_ABORTED, d.request_status()); 10223 EXPECT_EQ(ERR_ABORTED, d.request_status());
10223 EXPECT_EQ(0, d.received_redirect_count()); 10224 EXPECT_EQ(0, d.received_redirect_count());
10224 } 10225 }
10225 10226
10226 } // namespace net 10227 } // namespace net
OLDNEW
« no previous file with comments | « net/url_request/url_request_ftp_job_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698