summaryrefslogtreecommitdiff
path: root/chromium/net/url_request
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2022-02-02 12:21:57 +0100
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2022-02-12 08:13:00 +0000
commit606d85f2a5386472314d39923da28c70c60dc8e7 (patch)
treea8f4d7bf997f349f45605e6058259fba0630e4d7 /chromium/net/url_request
parent5786336dda477d04fb98483dca1a5426eebde2d7 (diff)
downloadqtwebengine-chromium-606d85f2a5386472314d39923da28c70c60dc8e7.tar.gz
BASELINE: Update Chromium to 96.0.4664.181
Change-Id: I762cd1da89d73aa6313b4a753fe126c34833f046 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'chromium/net/url_request')
-rw-r--r--chromium/net/url_request/ftp_protocol_handler.cc58
-rw-r--r--chromium/net/url_request/ftp_protocol_handler.h56
-rw-r--r--chromium/net/url_request/redirect_util.cc38
-rw-r--r--chromium/net/url_request/redirect_util.h16
-rw-r--r--chromium/net/url_request/report_sender.h5
-rw-r--r--chromium/net/url_request/report_sender_unittest.cc26
-rw-r--r--chromium/net/url_request/static_http_user_agent_settings.h7
-rw-r--r--chromium/net/url_request/test_url_fetcher_factory.h21
-rw-r--r--chromium/net/url_request/url_fetcher_core.cc8
-rw-r--r--chromium/net/url_request/url_fetcher_core.h12
-rw-r--r--chromium/net/url_request/url_fetcher_impl.h5
-rw-r--r--chromium/net/url_request/url_fetcher_impl_unittest.cc67
-rw-r--r--chromium/net/url_request/url_fetcher_response_writer.h12
-rw-r--r--chromium/net/url_request/url_request.cc24
-rw-r--r--chromium/net/url_request/url_request.h16
-rw-r--r--chromium/net/url_request/url_request_context.cc50
-rw-r--r--chromium/net/url_request/url_request_context.h69
-rw-r--r--chromium/net/url_request/url_request_context_builder.cc25
-rw-r--r--chromium/net/url_request/url_request_context_builder.h21
-rw-r--r--chromium/net/url_request/url_request_context_builder_unittest.cc5
-rw-r--r--chromium/net/url_request/url_request_context_getter.h5
-rw-r--r--chromium/net/url_request/url_request_context_getter_observer.h8
-rw-r--r--chromium/net/url_request/url_request_context_storage.cc14
-rw-r--r--chromium/net/url_request/url_request_context_storage.h13
-rw-r--r--chromium/net/url_request/url_request_context_unittest.cc71
-rw-r--r--chromium/net/url_request/url_request_filter.h5
-rw-r--r--chromium/net/url_request/url_request_filter_unittest.cc7
-rw-r--r--chromium/net/url_request/url_request_ftp_fuzzer.cc92
-rw-r--r--chromium/net/url_request/url_request_ftp_job.cc327
-rw-r--r--chromium/net/url_request/url_request_ftp_job.h102
-rw-r--r--chromium/net/url_request/url_request_ftp_job_unittest.cc245
-rw-r--r--chromium/net/url_request/url_request_http_job.cc99
-rw-r--r--chromium/net/url_request/url_request_http_job.h13
-rw-r--r--chromium/net/url_request/url_request_http_job_unittest.cc119
-rw-r--r--chromium/net/url_request/url_request_interceptor.h7
-rw-r--r--chromium/net/url_request/url_request_job.cc8
-rw-r--r--chromium/net/url_request/url_request_job.h6
-rw-r--r--chromium/net/url_request/url_request_job_factory.cc32
-rw-r--r--chromium/net/url_request/url_request_job_factory.h6
-rw-r--r--chromium/net/url_request/url_request_quic_unittest.cc18
-rw-r--r--chromium/net/url_request/url_request_redirect_job.cc38
-rw-r--r--chromium/net/url_request/url_request_redirect_job.h14
-rw-r--r--chromium/net/url_request/url_request_test_util.cc3
-rw-r--r--chromium/net/url_request/url_request_test_util.h1
-rw-r--r--chromium/net/url_request/url_request_throttler_entry.cc6
-rw-r--r--chromium/net/url_request/url_request_throttler_entry.h5
-rw-r--r--chromium/net/url_request/url_request_throttler_entry_interface.h6
-rw-r--r--chromium/net/url_request/url_request_throttler_manager.h7
-rw-r--r--chromium/net/url_request/url_request_throttler_simulation_unittest.cc120
-rw-r--r--chromium/net/url_request/url_request_throttler_test_support.h5
-rw-r--r--chromium/net/url_request/url_request_throttler_unittest.cc38
-rw-r--r--chromium/net/url_request/url_request_unittest.cc954
52 files changed, 966 insertions, 1969 deletions
diff --git a/chromium/net/url_request/ftp_protocol_handler.cc b/chromium/net/url_request/ftp_protocol_handler.cc
deleted file mode 100644
index 03783e50cfc..00000000000
--- a/chromium/net/url_request/ftp_protocol_handler.cc
+++ /dev/null
@@ -1,58 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "net/url_request/ftp_protocol_handler.h"
-
-#include "base/check_op.h"
-#include "base/memory/ptr_util.h"
-#include "net/base/net_errors.h"
-#include "net/base/port_util.h"
-#include "net/ftp/ftp_auth_cache.h"
-#include "net/ftp/ftp_network_layer.h"
-#include "net/url_request/url_request.h"
-#include "net/url_request/url_request_error_job.h"
-#include "net/url_request/url_request_ftp_job.h"
-#include "url/gurl.h"
-
-namespace net {
-
-std::unique_ptr<FtpProtocolHandler> FtpProtocolHandler::Create(
- HostResolver* host_resolver,
- FtpAuthCache* auth_cache) {
- DCHECK(auth_cache);
- return base::WrapUnique(new FtpProtocolHandler(
- base::WrapUnique(new FtpNetworkLayer(host_resolver)), auth_cache));
-}
-
-std::unique_ptr<FtpProtocolHandler> FtpProtocolHandler::CreateForTesting(
- std::unique_ptr<FtpTransactionFactory> ftp_transaction_factory,
- FtpAuthCache* auth_cache) {
- return base::WrapUnique(
- new FtpProtocolHandler(std::move(ftp_transaction_factory), auth_cache));
-}
-
-FtpProtocolHandler::~FtpProtocolHandler() = default;
-
-std::unique_ptr<URLRequestJob> FtpProtocolHandler::CreateJob(
- URLRequest* request) const {
- DCHECK_EQ("ftp", request->url().scheme());
-
- if (!IsPortAllowedForScheme(request->url().EffectiveIntPort(),
- request->url().scheme_piece())) {
- return std::make_unique<URLRequestErrorJob>(request, ERR_UNSAFE_PORT);
- }
-
- return std::make_unique<URLRequestFtpJob>(
- request, ftp_transaction_factory_.get(), ftp_auth_cache_);
-}
-
-FtpProtocolHandler::FtpProtocolHandler(
- std::unique_ptr<FtpTransactionFactory> ftp_transaction_factory,
- FtpAuthCache* auth_cache)
- : ftp_transaction_factory_(std::move(ftp_transaction_factory)),
- ftp_auth_cache_(auth_cache) {
- DCHECK(ftp_transaction_factory_);
-}
-
-} // namespace net
diff --git a/chromium/net/url_request/ftp_protocol_handler.h b/chromium/net/url_request/ftp_protocol_handler.h
deleted file mode 100644
index 114a051ee2a..00000000000
--- a/chromium/net/url_request/ftp_protocol_handler.h
+++ /dev/null
@@ -1,56 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef NET_URL_REQUEST_FTP_PROTOCOL_HANDLER_H_
-#define NET_URL_REQUEST_FTP_PROTOCOL_HANDLER_H_
-
-#include <memory>
-
-#include "base/compiler_specific.h"
-#include "base/macros.h"
-#include "net/base/net_export.h"
-#include "net/url_request/url_request_job_factory.h"
-
-namespace net {
-
-class FtpAuthCache;
-class FtpTransactionFactory;
-class HostResolver;
-class URLRequestJob;
-
-// Implements a ProtocolHandler for FTP.
-class NET_EXPORT FtpProtocolHandler :
- public URLRequestJobFactory::ProtocolHandler {
- public:
- ~FtpProtocolHandler() override;
-
- // Creates an FtpProtocolHandler using the specified HostResolver and
- // FtpAuthCache. |auth_cache| cannot be null.
- static std::unique_ptr<FtpProtocolHandler> Create(HostResolver* host_resolver,
- FtpAuthCache* auth_cache);
-
- // Creates an FtpProtocolHandler using the specified FtpTransactionFactory, to
- // allow a mock to be used for testing.
- static std::unique_ptr<FtpProtocolHandler> CreateForTesting(
- std::unique_ptr<FtpTransactionFactory> ftp_transaction_factory,
- FtpAuthCache* auth_cache);
-
- std::unique_ptr<URLRequestJob> CreateJob(URLRequest* request) const override;
-
- private:
- friend class FtpTestURLRequestContext;
-
- explicit FtpProtocolHandler(
- std::unique_ptr<FtpTransactionFactory> ftp_transaction_factory,
- FtpAuthCache* auth_cache);
-
- std::unique_ptr<FtpTransactionFactory> ftp_transaction_factory_;
- FtpAuthCache* ftp_auth_cache_;
-
- DISALLOW_COPY_AND_ASSIGN(FtpProtocolHandler);
-};
-
-} // namespace net
-
-#endif // NET_URL_REQUEST_FTP_PROTOCOL_HANDLER_H_
diff --git a/chromium/net/url_request/redirect_util.cc b/chromium/net/url_request/redirect_util.cc
index ff95dd67df9..a2e14e7b975 100644
--- a/chromium/net/url_request/redirect_util.cc
+++ b/chromium/net/url_request/redirect_util.cc
@@ -4,8 +4,12 @@
#include "net/url_request/redirect_util.h"
+#include "base/check.h"
+#include "base/memory/scoped_refptr.h"
+#include "base/strings/stringprintf.h"
#include "net/http/http_request_headers.h"
#include "net/http/http_response_headers.h"
+#include "net/http/http_util.h"
#include "net/url_request/redirect_info.h"
#include "url/gurl.h"
#include "url/origin.h"
@@ -96,4 +100,38 @@ absl::optional<std::string> RedirectUtil::GetReferrerPolicyHeader(
return referrer_policy_header;
}
+// static
+scoped_refptr<HttpResponseHeaders> RedirectUtil::SynthesizeRedirectHeaders(
+ const GURL& redirect_destination,
+ ResponseCode response_code,
+ const std::string& redirect_reason,
+ const HttpRequestHeaders& request_headers) {
+ std::string header_string = base::StringPrintf(
+ "HTTP/1.1 %i Internal Redirect\n"
+ "Location: %s\n"
+ "Non-Authoritative-Reason: %s",
+ response_code, redirect_destination.spec().c_str(),
+ redirect_reason.c_str());
+
+ std::string http_origin;
+ if (request_headers.GetHeader("Origin", &http_origin)) {
+ // If this redirect is used in a cross-origin request, add CORS headers to
+ // make sure that the redirect gets through. Note that the destination URL
+ // is still subject to the usual CORS policy, i.e. the resource will only
+ // be available to web pages if the server serves the response with the
+ // required CORS response headers.
+ header_string += base::StringPrintf(
+ "\n"
+ "Access-Control-Allow-Origin: %s\n"
+ "Access-Control-Allow-Credentials: true",
+ http_origin.c_str());
+ }
+
+ auto fake_headers = base::MakeRefCounted<HttpResponseHeaders>(
+ HttpUtil::AssembleRawHeaders(header_string));
+ DCHECK(fake_headers->IsRedirect(nullptr));
+
+ return fake_headers;
+}
+
} // namespace net
diff --git a/chromium/net/url_request/redirect_util.h b/chromium/net/url_request/redirect_util.h
index ba317b24f0a..bd83a8f64cf 100644
--- a/chromium/net/url_request/redirect_util.h
+++ b/chromium/net/url_request/redirect_util.h
@@ -8,6 +8,7 @@
#include <string>
#include <vector>
+#include "base/memory/scoped_refptr.h"
#include "net/base/net_export.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
@@ -21,6 +22,15 @@ class HttpResponseHeaders;
class RedirectUtil {
public:
+ // Valid status codes for the redirect job. Other 30x codes are theoretically
+ // valid, but unused so far. Both 302 and 307 are temporary redirects, with
+ // the difference being that 302 converts POSTs to GETs and removes upload
+ // data.
+ enum class ResponseCode {
+ REDIRECT_302_FOUND = 302,
+ REDIRECT_307_TEMPORARY_REDIRECT = 307,
+ };
+
// Updates HTTP headers in |request_headers| for a redirect.
// |removed_headers| and |modified_headers| are specified by
// clients to add or override existing headers for the redirect.
@@ -39,6 +49,12 @@ class RedirectUtil {
// Otherwise returns absl::nullopt.
NET_EXPORT static absl::optional<std::string> GetReferrerPolicyHeader(
const HttpResponseHeaders* response_headers);
+
+ NET_EXPORT static scoped_refptr<HttpResponseHeaders>
+ SynthesizeRedirectHeaders(const GURL& redirect_destination,
+ ResponseCode response_code,
+ const std::string& redirect_reason,
+ const HttpRequestHeaders& request_headers);
};
} // namespace net
diff --git a/chromium/net/url_request/report_sender.h b/chromium/net/url_request/report_sender.h
index 2400db52a6f..484012bb791 100644
--- a/chromium/net/url_request/report_sender.h
+++ b/chromium/net/url_request/report_sender.h
@@ -46,6 +46,9 @@ class NET_EXPORT ReportSender
explicit ReportSender(URLRequestContext* request_context,
net::NetworkTrafficAnnotationTag traffic_annotation);
+ ReportSender(const ReportSender&) = delete;
+ ReportSender& operator=(const ReportSender&) = delete;
+
~ReportSender() override;
// TransportSecurityState::ReportSenderInterface implementation.
@@ -64,8 +67,6 @@ class NET_EXPORT ReportSender
net::URLRequestContext* const request_context_;
std::map<URLRequest*, std::unique_ptr<URLRequest>> inflight_requests_;
const net::NetworkTrafficAnnotationTag traffic_annotation_;
-
- DISALLOW_COPY_AND_ASSIGN(ReportSender);
};
} // namespace net
diff --git a/chromium/net/url_request/report_sender_unittest.cc b/chromium/net/url_request/report_sender_unittest.cc
index 4dee747342d..79302732c49 100644
--- a/chromium/net/url_request/report_sender_unittest.cc
+++ b/chromium/net/url_request/report_sender_unittest.cc
@@ -82,6 +82,10 @@ void SuccessCallback(bool* called) {
class MockServerErrorJob : public URLRequestJob {
public:
explicit MockServerErrorJob(URLRequest* request) : URLRequestJob(request) {}
+
+ MockServerErrorJob(const MockServerErrorJob&) = delete;
+ MockServerErrorJob& operator=(const MockServerErrorJob&) = delete;
+
~MockServerErrorJob() override = default;
protected:
@@ -92,23 +96,22 @@ class MockServerErrorJob : public URLRequestJob {
"Content-Length: 0\n");
}
void Start() override { NotifyHeadersComplete(); }
-
- private:
- DISALLOW_COPY_AND_ASSIGN(MockServerErrorJob);
};
class MockServerErrorJobInterceptor : public URLRequestInterceptor {
public:
MockServerErrorJobInterceptor() = default;
+
+ MockServerErrorJobInterceptor(const MockServerErrorJobInterceptor&) = delete;
+ MockServerErrorJobInterceptor& operator=(
+ const MockServerErrorJobInterceptor&) = delete;
+
~MockServerErrorJobInterceptor() override = default;
std::unique_ptr<URLRequestJob> MaybeInterceptRequest(
URLRequest* request) const override {
return std::make_unique<MockServerErrorJob>(request);
}
-
- private:
- DISALLOW_COPY_AND_ASSIGN(MockServerErrorJobInterceptor);
};
// A network delegate that lets tests check that a report
@@ -118,10 +121,15 @@ class MockServerErrorJobInterceptor : public URLRequestInterceptor {
class TestReportSenderNetworkDelegate : public NetworkDelegateImpl {
public:
TestReportSenderNetworkDelegate()
- : url_request_destroyed_callback_(base::DoNothing::Repeatedly()),
- all_url_requests_destroyed_callback_(base::DoNothing::Repeatedly()),
+ : url_request_destroyed_callback_(base::DoNothing()),
+ all_url_requests_destroyed_callback_(base::DoNothing()),
num_requests_(0) {}
+ TestReportSenderNetworkDelegate(const TestReportSenderNetworkDelegate&) =
+ delete;
+ TestReportSenderNetworkDelegate& operator=(
+ const TestReportSenderNetworkDelegate&) = delete;
+
void ExpectReport(const std::string& report) {
expect_reports_.insert(report);
}
@@ -191,8 +199,6 @@ class TestReportSenderNetworkDelegate : public NetworkDelegateImpl {
std::set<std::string> expect_reports_;
std::string expected_content_type_;
NetworkIsolationKey expected_network_isolation_key_;
-
- DISALLOW_COPY_AND_ASSIGN(TestReportSenderNetworkDelegate);
};
class ReportSenderTest : public TestWithTaskEnvironment {
diff --git a/chromium/net/url_request/static_http_user_agent_settings.h b/chromium/net/url_request/static_http_user_agent_settings.h
index 0ccfe130f00..ab97cbf061c 100644
--- a/chromium/net/url_request/static_http_user_agent_settings.h
+++ b/chromium/net/url_request/static_http_user_agent_settings.h
@@ -20,6 +20,11 @@ class NET_EXPORT StaticHttpUserAgentSettings : public HttpUserAgentSettings {
public:
StaticHttpUserAgentSettings(const std::string& accept_language,
const std::string& user_agent);
+
+ StaticHttpUserAgentSettings(const StaticHttpUserAgentSettings&) = delete;
+ StaticHttpUserAgentSettings& operator=(const StaticHttpUserAgentSettings&) =
+ delete;
+
~StaticHttpUserAgentSettings() override;
void set_accept_language(const std::string& new_accept_language) {
@@ -33,8 +38,6 @@ class NET_EXPORT StaticHttpUserAgentSettings : public HttpUserAgentSettings {
private:
std::string accept_language_;
const std::string user_agent_;
-
- DISALLOW_COPY_AND_ASSIGN(StaticHttpUserAgentSettings);
};
} // namespace net
diff --git a/chromium/net/url_request/test_url_fetcher_factory.h b/chromium/net/url_request/test_url_fetcher_factory.h
index 44a48108265..2c213962567 100644
--- a/chromium/net/url_request/test_url_fetcher_factory.h
+++ b/chromium/net/url_request/test_url_fetcher_factory.h
@@ -37,12 +37,14 @@ namespace net {
class ScopedURLFetcherFactory {
public:
explicit ScopedURLFetcherFactory(URLFetcherFactory* factory);
+
+ ScopedURLFetcherFactory(const ScopedURLFetcherFactory&) = delete;
+ ScopedURLFetcherFactory& operator=(const ScopedURLFetcherFactory&) = delete;
+
virtual ~ScopedURLFetcherFactory();
private:
THREAD_CHECKER(thread_checker_);
-
- DISALLOW_COPY_AND_ASSIGN(ScopedURLFetcherFactory);
};
// TestURLFetcher and TestURLFetcherFactory are used for testing consumers of
@@ -92,6 +94,10 @@ class TestURLFetcher : public URLFetcher {
TestURLFetcher(int id,
const GURL& url,
URLFetcherDelegate* d);
+
+ TestURLFetcher(const TestURLFetcher&) = delete;
+ TestURLFetcher& operator=(const TestURLFetcher&) = delete;
+
~TestURLFetcher() override;
// URLFetcher implementation
@@ -236,8 +242,6 @@ class TestURLFetcher : public URLFetcher {
int fake_max_retries_;
base::TimeDelta fake_backoff_delay_;
std::unique_ptr<URLFetcherResponseWriter> response_writer_;
-
- DISALLOW_COPY_AND_ASSIGN(TestURLFetcher);
};
// The FakeURLFetcher and FakeURLFetcherFactory classes are similar to the
@@ -276,6 +280,9 @@ class FakeURLFetcher : public TestURLFetcher {
const GURL& GetURL() const override;
+ FakeURLFetcher(const FakeURLFetcher&) = delete;
+ FakeURLFetcher& operator=(const FakeURLFetcher&) = delete;
+
~FakeURLFetcher() override;
private:
@@ -285,8 +292,6 @@ class FakeURLFetcher : public TestURLFetcher {
int64_t response_bytes_;
base::WeakPtrFactory<FakeURLFetcher> weak_factory_{this};
-
- DISALLOW_COPY_AND_ASSIGN(FakeURLFetcher);
};
// FakeURLFetcherFactory is a factory for FakeURLFetcher objects. When
@@ -370,6 +375,9 @@ class FakeURLFetcherFactory : public URLFetcherFactory,
FakeURLFetcherFactory(URLFetcherFactory* default_factory,
const FakeURLFetcherCreator& creator);
+ FakeURLFetcherFactory(const FakeURLFetcherFactory&) = delete;
+ FakeURLFetcherFactory& operator=(const FakeURLFetcherFactory&) = delete;
+
~FakeURLFetcherFactory() override;
// If no fake response is set for the given URL this method will delegate the
@@ -417,7 +425,6 @@ class FakeURLFetcherFactory : public URLFetcherFactory,
const std::string& response_data,
HttpStatusCode response_code,
Error error);
- DISALLOW_COPY_AND_ASSIGN(FakeURLFetcherFactory);
};
} // namespace net
diff --git a/chromium/net/url_request/url_fetcher_core.cc b/chromium/net/url_request/url_fetcher_core.cc
index 912211d7402..ff48be19576 100644
--- a/chromium/net/url_request/url_fetcher_core.cc
+++ b/chromium/net/url_request/url_fetcher_core.cc
@@ -25,7 +25,9 @@
#include "net/base/upload_bytes_element_reader.h"
#include "net/base/upload_data_stream.h"
#include "net/base/upload_file_element_reader.h"
+#include "net/cert/x509_certificate.h"
#include "net/http/http_response_headers.h"
+#include "net/ssl/ssl_private_key.h"
#include "net/url_request/redirect_info.h"
#include "net/url_request/url_fetcher_delegate.h"
#include "net/url_request/url_fetcher_response_writer.h"
@@ -619,9 +621,7 @@ void URLFetcherCore::StartURLRequest() {
// layer and avoid using timer here.
upload_progress_checker_timer_ = std::make_unique<base::RepeatingTimer>();
upload_progress_checker_timer_->Start(
- FROM_HERE,
- base::TimeDelta::FromMilliseconds(kUploadProgressTimerInterval),
- this,
+ FROM_HERE, base::Milliseconds(kUploadProgressTimerInterval), this,
&URLFetcherCore::InformDelegateUploadProgress);
break;
}
@@ -680,7 +680,7 @@ void URLFetcherCore::StartURLRequestWhenAppropriate() {
if (delay != 0) {
network_task_runner_->PostDelayedTask(
FROM_HERE, base::BindOnce(&URLFetcherCore::StartURLRequest, this),
- base::TimeDelta::FromMilliseconds(delay));
+ base::Milliseconds(delay));
return;
}
}
diff --git a/chromium/net/url_request/url_fetcher_core.h b/chromium/net/url_request/url_fetcher_core.h
index 213e4abd1e5..3be328fbb14 100644
--- a/chromium/net/url_request/url_fetcher_core.h
+++ b/chromium/net/url_request/url_fetcher_core.h
@@ -16,6 +16,7 @@
#include "base/lazy_instance.h"
#include "base/macros.h"
#include "base/memory/ref_counted.h"
+#include "base/memory/scoped_refptr.h"
#include "base/timer/timer.h"
#include "net/base/chunked_upload_data_stream.h"
#include "net/base/ip_endpoint.h"
@@ -53,6 +54,9 @@ class URLFetcherCore : public base::RefCountedThreadSafe<URLFetcherCore>,
URLFetcherDelegate* d,
net::NetworkTrafficAnnotationTag traffic_annotation);
+ URLFetcherCore(const URLFetcherCore&) = delete;
+ URLFetcherCore& operator=(const URLFetcherCore&) = delete;
+
// Starts the load. It's important that this not happen in the constructor
// because it causes the IO thread to begin AddRef()ing and Release()ing
// us. If our caller hasn't had time to fully construct us and take a
@@ -163,6 +167,10 @@ class URLFetcherCore : public base::RefCountedThreadSafe<URLFetcherCore>,
class Registry {
public:
Registry();
+
+ Registry(const Registry&) = delete;
+ Registry& operator=(const Registry&) = delete;
+
~Registry();
void AddURLFetcherCore(URLFetcherCore* core);
@@ -176,8 +184,6 @@ class URLFetcherCore : public base::RefCountedThreadSafe<URLFetcherCore>,
private:
std::set<URLFetcherCore*> fetchers_;
-
- DISALLOW_COPY_AND_ASSIGN(Registry);
};
~URLFetcherCore() override;
@@ -357,8 +363,6 @@ class URLFetcherCore : public base::RefCountedThreadSafe<URLFetcherCore>,
const net::NetworkTrafficAnnotationTag traffic_annotation_;
static base::LazyInstance<Registry>::DestructorAtExit g_registry;
-
- DISALLOW_COPY_AND_ASSIGN(URLFetcherCore);
};
} // namespace net
diff --git a/chromium/net/url_request/url_fetcher_impl.h b/chromium/net/url_request/url_fetcher_impl.h
index 15bf0170875..c19950916b7 100644
--- a/chromium/net/url_request/url_fetcher_impl.h
+++ b/chromium/net/url_request/url_fetcher_impl.h
@@ -33,6 +33,9 @@ class URLFetcherFactory;
class NET_EXPORT_PRIVATE URLFetcherImpl : public URLFetcher {
public:
+ URLFetcherImpl(const URLFetcherImpl&) = delete;
+ URLFetcherImpl& operator=(const URLFetcherImpl&) = delete;
+
~URLFetcherImpl() override;
// URLFetcher implementation:
@@ -131,8 +134,6 @@ class NET_EXPORT_PRIVATE URLFetcherImpl : public URLFetcher {
static int GetNumFetcherCores();
const scoped_refptr<URLFetcherCore> core_;
-
- DISALLOW_COPY_AND_ASSIGN(URLFetcherImpl);
};
} // namespace net
diff --git a/chromium/net/url_request/url_fetcher_impl_unittest.cc b/chromium/net/url_request/url_fetcher_impl_unittest.cc
index 976a9ed3420..97d8231f1e2 100644
--- a/chromium/net/url_request/url_fetcher_impl_unittest.cc
+++ b/chromium/net/url_request/url_fetcher_impl_unittest.cc
@@ -36,6 +36,7 @@
#include "build/build_config.h"
#include "net/base/elements_upload_data_stream.h"
#include "net/base/network_change_notifier.h"
+#include "net/base/proxy_string_util.h"
#include "net/base/upload_bytes_element_reader.h"
#include "net/base/upload_element_reader.h"
#include "net/base/upload_file_element_reader.h"
@@ -56,7 +57,6 @@
namespace net {
using base::Time;
-using base::TimeDelta;
using net::test::IsError;
using net::test::IsOk;
@@ -66,6 +66,10 @@ class WaitingURLFetcherDelegate : public URLFetcherDelegate {
public:
WaitingURLFetcherDelegate() : did_complete_(false) {}
+ WaitingURLFetcherDelegate(const WaitingURLFetcherDelegate&) = delete;
+ WaitingURLFetcherDelegate& operator=(const WaitingURLFetcherDelegate&) =
+ delete;
+
void CreateFetcher(
const GURL& url,
URLFetcher::RequestType request_type,
@@ -155,8 +159,6 @@ class WaitingURLFetcherDelegate : public URLFetcherDelegate {
base::SequencedTaskRunnerHandle::Get();
std::unique_ptr<base::RunLoop> run_loop_;
base::OnceClosure on_complete_or_cancel_;
-
- DISALLOW_COPY_AND_ASSIGN(WaitingURLFetcherDelegate);
};
namespace {
@@ -203,12 +205,14 @@ class FetcherTestURLRequestContext : public TestURLRequestContext {
Init();
}
+ FetcherTestURLRequestContext(const FetcherTestURLRequestContext&) = delete;
+ FetcherTestURLRequestContext& operator=(const FetcherTestURLRequestContext&) =
+ delete;
+
MockHostResolver* mock_resolver() { return mock_resolver_; }
private:
MockHostResolver* mock_resolver_;
-
- DISALLOW_COPY_AND_ASSIGN(FetcherTestURLRequestContext);
};
class FetcherTestURLRequestContextGetter : public URLRequestContextGetter {
@@ -220,6 +224,11 @@ class FetcherTestURLRequestContextGetter : public URLRequestContextGetter {
hanging_domain_(hanging_domain),
shutting_down_(false) {}
+ FetcherTestURLRequestContextGetter(
+ const FetcherTestURLRequestContextGetter&) = delete;
+ FetcherTestURLRequestContextGetter& operator=(
+ const FetcherTestURLRequestContextGetter&) = delete;
+
// Sets callback to be invoked when the getter is destroyed.
void set_on_destruction_callback(base::OnceClosure on_destruction_callback) {
on_destruction_callback_ = std::move(on_destruction_callback);
@@ -334,8 +343,6 @@ class FetcherTestURLRequestContextGetter : public URLRequestContextGetter {
bool shutting_down_;
base::OnceClosure on_destruction_callback_;
-
- DISALLOW_COPY_AND_ASSIGN(FetcherTestURLRequestContextGetter);
};
} // namespace
@@ -509,7 +516,8 @@ TEST_F(URLFetcherTest, FetchedUsingProxy) {
std::unique_ptr<ProxyResolutionService> proxy_resolution_service =
ConfiguredProxyResolutionService::CreateFixedFromPacResult(
- proxy_server.ToPacString(), TRAFFIC_ANNOTATION_FOR_TESTS);
+ ProxyServerToPacResultElement(proxy_server),
+ TRAFFIC_ANNOTATION_FOR_TESTS);
context_getter->set_proxy_resolution_service(
std::move(proxy_resolution_service));
@@ -947,6 +955,11 @@ class CheckUploadProgressDelegate : public WaitingURLFetcherDelegate {
public:
CheckUploadProgressDelegate()
: chunk_(1 << 16, 'a'), num_chunks_appended_(0), last_seen_progress_(0) {}
+
+ CheckUploadProgressDelegate(const CheckUploadProgressDelegate&) = delete;
+ CheckUploadProgressDelegate& operator=(const CheckUploadProgressDelegate&) =
+ delete;
+
~CheckUploadProgressDelegate() override = default;
void OnURLFetchUploadProgress(const URLFetcher* source,
@@ -981,8 +994,6 @@ class CheckUploadProgressDelegate : public WaitingURLFetcherDelegate {
int64_t num_chunks_appended_;
int64_t last_seen_progress_;
-
- DISALLOW_COPY_AND_ASSIGN(CheckUploadProgressDelegate);
};
TEST_F(URLFetcherTest, UploadProgress) {
@@ -1014,6 +1025,11 @@ class CheckDownloadProgressDelegate : public WaitingURLFetcherDelegate {
public:
CheckDownloadProgressDelegate(int64_t file_size)
: file_size_(file_size), last_seen_progress_(0) {}
+
+ CheckDownloadProgressDelegate(const CheckDownloadProgressDelegate&) = delete;
+ CheckDownloadProgressDelegate& operator=(
+ const CheckDownloadProgressDelegate&) = delete;
+
~CheckDownloadProgressDelegate() override = default;
void OnURLFetchDownloadProgress(const URLFetcher* source,
@@ -1032,8 +1048,6 @@ class CheckDownloadProgressDelegate : public WaitingURLFetcherDelegate {
private:
int64_t file_size_;
int64_t last_seen_progress_;
-
- DISALLOW_COPY_AND_ASSIGN(CheckDownloadProgressDelegate);
};
TEST_F(URLFetcherTest, DownloadProgress) {
@@ -1065,6 +1079,12 @@ TEST_F(URLFetcherTest, DownloadProgress) {
class CancelOnUploadProgressDelegate : public WaitingURLFetcherDelegate {
public:
CancelOnUploadProgressDelegate() = default;
+
+ CancelOnUploadProgressDelegate(const CancelOnUploadProgressDelegate&) =
+ delete;
+ CancelOnUploadProgressDelegate& operator=(
+ const CancelOnUploadProgressDelegate&) = delete;
+
~CancelOnUploadProgressDelegate() override = default;
void OnURLFetchUploadProgress(const URLFetcher* source,
@@ -1072,9 +1092,6 @@ class CancelOnUploadProgressDelegate : public WaitingURLFetcherDelegate {
int64_t total) override {
CancelFetch();
}
-
- private:
- DISALLOW_COPY_AND_ASSIGN(CancelOnUploadProgressDelegate);
};
// Check that a fetch can be safely cancelled/deleted during an upload progress
@@ -1102,6 +1119,12 @@ TEST_F(URLFetcherTest, CancelInUploadProgressCallback) {
class CancelOnDownloadProgressDelegate : public WaitingURLFetcherDelegate {
public:
CancelOnDownloadProgressDelegate() = default;
+
+ CancelOnDownloadProgressDelegate(const CancelOnDownloadProgressDelegate&) =
+ delete;
+ CancelOnDownloadProgressDelegate& operator=(
+ const CancelOnDownloadProgressDelegate&) = delete;
+
~CancelOnDownloadProgressDelegate() override = default;
void OnURLFetchDownloadProgress(const URLFetcher* source,
@@ -1110,9 +1133,6 @@ class CancelOnDownloadProgressDelegate : public WaitingURLFetcherDelegate {
int64_t current_network_bytes) override {
CancelFetch();
}
-
- private:
- DISALLOW_COPY_AND_ASSIGN(CancelOnDownloadProgressDelegate);
};
// Check that a fetch can be safely cancelled/deleted during a download progress
@@ -1208,7 +1228,7 @@ TEST_F(URLFetcherTest, ThrottleOnRepeatedFetches) {
// 20 requests were sent. Due to throttling, they should have collectively
// taken over 1 second.
- EXPECT_GE(Time::Now() - start_time, base::TimeDelta::FromSeconds(1));
+ EXPECT_GE(Time::Now() - start_time, base::Seconds(1));
}
// If throttling kicks in for a chunked upload, there should be no crash.
@@ -1276,7 +1296,7 @@ TEST_F(URLFetcherTest, ThrottleOn5xxRetries) {
// The request should have been retried 11 times (12 times including the first
// attempt). Due to throttling, they should have collectively taken over 1
// second.
- EXPECT_GE(Time::Now() - start_time, base::TimeDelta::FromSeconds(1));
+ EXPECT_GE(Time::Now() - start_time, base::Seconds(1));
}
// Tests overload protection, when responses passed through.
@@ -1315,7 +1335,7 @@ TEST_F(URLFetcherTest, ProtectTestPassedThrough) {
// The request should not have been retried at all. If it had attempted all
// 11 retries, that should have taken 2.5 minutes.
- EXPECT_TRUE(Time::Now() - start_time < TimeDelta::FromMinutes(1));
+ EXPECT_TRUE(Time::Now() - start_time < base::Minutes(1));
}
// Used to check if a callback has been invoked.
@@ -1419,6 +1439,9 @@ class ReuseFetcherDelegate : public WaitingURLFetcherDelegate {
: first_request_complete_(false),
second_request_context_getter_(second_request_context_getter) {}
+ ReuseFetcherDelegate(const ReuseFetcherDelegate&) = delete;
+ ReuseFetcherDelegate& operator=(const ReuseFetcherDelegate&) = delete;
+
~ReuseFetcherDelegate() override = default;
void OnURLFetchComplete(const URLFetcher* source) override {
@@ -1443,8 +1466,6 @@ class ReuseFetcherDelegate : public WaitingURLFetcherDelegate {
private:
bool first_request_complete_;
scoped_refptr<URLRequestContextGetter> second_request_context_getter_;
-
- DISALLOW_COPY_AND_ASSIGN(ReuseFetcherDelegate);
};
TEST_F(URLFetcherTest, ReuseFetcherForSameURL) {
diff --git a/chromium/net/url_request/url_fetcher_response_writer.h b/chromium/net/url_request/url_fetcher_response_writer.h
index 202cf637ed8..c82ca68ef36 100644
--- a/chromium/net/url_request/url_fetcher_response_writer.h
+++ b/chromium/net/url_request/url_fetcher_response_writer.h
@@ -69,6 +69,10 @@ class NET_EXPORT URLFetcherResponseWriter {
class NET_EXPORT URLFetcherStringWriter : public URLFetcherResponseWriter {
public:
URLFetcherStringWriter();
+
+ URLFetcherStringWriter(const URLFetcherStringWriter&) = delete;
+ URLFetcherStringWriter& operator=(const URLFetcherStringWriter&) = delete;
+
~URLFetcherStringWriter() override;
const std::string& data() const { return data_; }
@@ -83,8 +87,6 @@ class NET_EXPORT URLFetcherStringWriter : public URLFetcherResponseWriter {
private:
std::string data_;
-
- DISALLOW_COPY_AND_ASSIGN(URLFetcherStringWriter);
};
// URLFetcherResponseWriter implementation for files.
@@ -97,6 +99,10 @@ class NET_EXPORT URLFetcherFileWriter : public URLFetcherResponseWriter {
URLFetcherFileWriter(
scoped_refptr<base::SequencedTaskRunner> file_task_runner,
const base::FilePath& file_path);
+
+ URLFetcherFileWriter(const URLFetcherFileWriter&) = delete;
+ URLFetcherFileWriter& operator=(const URLFetcherFileWriter&) = delete;
+
~URLFetcherFileWriter() override;
const base::FilePath& file_path() const { return file_path_; }
@@ -142,8 +148,6 @@ class NET_EXPORT URLFetcherFileWriter : public URLFetcherResponseWriter {
CompletionOnceCallback callback_;
base::WeakPtrFactory<URLFetcherFileWriter> weak_factory_{this};
-
- DISALLOW_COPY_AND_ASSIGN(URLFetcherFileWriter);
};
} // namespace net
diff --git a/chromium/net/url_request/url_request.cc b/chromium/net/url_request/url_request.cc
index f6beb8346ae..942504cdbbe 100644
--- a/chromium/net/url_request/url_request.cc
+++ b/chromium/net/url_request/url_request.cc
@@ -23,6 +23,7 @@
#include "net/base/network_change_notifier.h"
#include "net/base/network_delegate.h"
#include "net/base/upload_data_stream.h"
+#include "net/cert/x509_certificate.h"
#include "net/cookies/cookie_store.h"
#include "net/cookies/cookie_util.h"
#include "net/cookies/same_party_context.h"
@@ -34,6 +35,7 @@
#include "net/log/net_log_source_type.h"
#include "net/socket/next_proto.h"
#include "net/ssl/ssl_cert_request_info.h"
+#include "net/ssl/ssl_private_key.h"
#include "net/url_request/redirect_info.h"
#include "net/url_request/redirect_util.h"
#include "net/url_request/url_request_context.h"
@@ -129,6 +131,17 @@ void ConvertRealLoadTimesToBlockingTimes(LoadTimingInfo* load_timing_info) {
}
}
+NetLogWithSource CreateNetLogWithSource(
+ NetLog* net_log,
+ absl::optional<uint32_t> net_log_source_id) {
+ if (net_log_source_id) {
+ return NetLogWithSource::Make(
+ net_log,
+ NetLogSource(NetLogSourceType::URL_REQUEST, net_log_source_id.value()));
+ }
+ return NetLogWithSource::Make(net_log, NetLogSourceType::URL_REQUEST);
+}
+
} // namespace
///////////////////////////////////////////////////////////////////////////////
@@ -544,10 +557,11 @@ URLRequest::URLRequest(const GURL& url,
RequestPriority priority,
Delegate* delegate,
const URLRequestContext* context,
- NetworkTrafficAnnotationTag traffic_annotation)
+ NetworkTrafficAnnotationTag traffic_annotation,
+ bool is_for_websockets,
+ absl::optional<uint32_t> net_log_source_id)
: context_(context),
- net_log_(NetLogWithSource::Make(context->net_log(),
- NetLogSourceType::URL_REQUEST)),
+ net_log_(CreateNetLogWithSource(context->net_log(), net_log_source_id)),
url_chain_(1, url),
force_ignore_site_for_cookies_(false),
force_ignore_top_frame_party_for_cookies_(false),
@@ -564,6 +578,7 @@ URLRequest::URLRequest(const GURL& url,
reporting_upload_depth_(0),
#endif
delegate_(delegate),
+ is_for_websockets_(is_for_websockets),
status_(OK),
is_pending_(false),
is_redirecting_(false),
@@ -607,7 +622,8 @@ void URLRequest::BeforeRequestComplete(int error) {
StartJob(std::make_unique<URLRequestRedirectJob>(
this, new_url,
// Use status code 307 to preserve the method, so POST requests work.
- URLRequestRedirectJob::REDIRECT_307_TEMPORARY_REDIRECT, "Delegate"));
+ RedirectUtil::ResponseCode::REDIRECT_307_TEMPORARY_REDIRECT,
+ "Delegate"));
} else {
StartJob(context_->job_factory()->CreateJob(this));
}
diff --git a/chromium/net/url_request/url_request.h b/chromium/net/url_request/url_request.h
index 5cba78924aa..308ec99f537 100644
--- a/chromium/net/url_request/url_request.h
+++ b/chromium/net/url_request/url_request.h
@@ -210,6 +210,9 @@ class NET_EXPORT URLRequest : public base::SupportsUserData {
virtual ~Delegate() {}
};
+ URLRequest(const URLRequest&) = delete;
+ URLRequest& operator=(const URLRequest&) = delete;
+
// If destroyed after Start() has been called but while IO is pending,
// then the request will be effectively canceled and the delegate
// will not have any more of its methods called.
@@ -683,8 +686,7 @@ class NET_EXPORT URLRequest : public base::SupportsUserData {
}
// The number of bytes in the raw response body (before any decompression,
- // etc.). This is only available after the final Read completes. Not available
- // for FTP responses.
+ // etc.). This is only available after the final Read completes.
int64_t received_response_content_length() const {
return received_response_content_length_;
}
@@ -774,6 +776,8 @@ class NET_EXPORT URLRequest : public base::SupportsUserData {
send_client_certs_ = send_client_certs;
}
+ bool is_for_websockets() const { return is_for_websockets_; }
+
void SetIdempotency(Idempotency idempotency) { idempotency_ = idempotency; }
Idempotency GetIdempotency() const { return idempotency_; }
@@ -818,7 +822,9 @@ class NET_EXPORT URLRequest : public base::SupportsUserData {
RequestPriority priority,
Delegate* delegate,
const URLRequestContext* context,
- NetworkTrafficAnnotationTag traffic_annotation);
+ NetworkTrafficAnnotationTag traffic_annotation,
+ bool is_for_websockets,
+ absl::optional<uint32_t> net_log_source_id);
// Resumes or blocks a request paused by the NetworkDelegate::OnBeforeRequest
// handler. If |blocked| is true, the request is blocked and an error page is
@@ -937,6 +943,8 @@ class NET_EXPORT URLRequest : public base::SupportsUserData {
// Notify... methods for this.
Delegate* delegate_;
+ const bool is_for_websockets_;
+
// Current error status of the job, as a net::Error code. When the job is
// busy, it is ERR_IO_PENDING. When the job is idle (either completed, or
// awaiting a call from the URLRequestDelegate before continuing the request),
@@ -1030,8 +1038,6 @@ class NET_EXPORT URLRequest : public base::SupportsUserData {
THREAD_CHECKER(thread_checker_);
base::WeakPtrFactory<URLRequest> weak_factory_{this};
-
- DISALLOW_COPY_AND_ASSIGN(URLRequest);
};
} // namespace net
diff --git a/chromium/net/url_request/url_request_context.cc b/chromium/net/url_request/url_request_context.cc
index c7efe012e7d..382b195b139 100644
--- a/chromium/net/url_request/url_request_context.cc
+++ b/chromium/net/url_request/url_request_context.cc
@@ -5,6 +5,7 @@
#include "net/url_request/url_request_context.h"
#include <inttypes.h>
+#include <stdint.h>
#include "base/compiler_specific.h"
#include "base/debug/alias.h"
@@ -14,10 +15,6 @@
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/threading/thread_task_runner_handle.h"
-#include "base/trace_event/memory_allocator_dump.h"
-#include "base/trace_event/memory_dump_manager.h"
-#include "base/trace_event/memory_dump_request_args.h"
-#include "base/trace_event/process_memory_dump.h"
#include "build/chromeos_buildflags.h"
#include "net/base/http_user_agent_settings.h"
#include "net/cookies/cookie_store.h"
@@ -57,17 +54,12 @@ URLRequestContext::URLRequestContext()
url_requests_(std::make_unique<std::set<const URLRequest*>>()),
enable_brotli_(false),
check_cleartext_permitted_(false),
- require_network_isolation_key_(false),
- name_("unknown") {
- base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider(
- this, "URLRequestContext", base::ThreadTaskRunnerHandle::Get());
+ require_network_isolation_key_(false) {
}
URLRequestContext::~URLRequestContext() {
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
AssertNoURLRequests();
- base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider(
- this);
}
const HttpNetworkSessionParams* URLRequestContext::GetNetworkSessionParams()
@@ -99,7 +91,8 @@ std::unique_ptr<URLRequest> URLRequestContext::CreateRequest(
const GURL& url,
RequestPriority priority,
URLRequest::Delegate* delegate) const {
- return CreateRequest(url, priority, delegate, MISSING_TRAFFIC_ANNOTATION);
+ return CreateRequest(url, priority, delegate, MISSING_TRAFFIC_ANNOTATION,
+ /*is_for_websockets=*/false);
}
#endif
@@ -107,9 +100,12 @@ std::unique_ptr<URLRequest> URLRequestContext::CreateRequest(
const GURL& url,
RequestPriority priority,
URLRequest::Delegate* delegate,
- NetworkTrafficAnnotationTag traffic_annotation) const {
- return base::WrapUnique(
- new URLRequest(url, priority, delegate, this, traffic_annotation));
+ NetworkTrafficAnnotationTag traffic_annotation,
+ bool is_for_websockets,
+ const absl::optional<uint32_t> net_log_source_id) const {
+ return base::WrapUnique(new URLRequest(url, priority, delegate, this,
+ traffic_annotation, is_for_websockets,
+ net_log_source_id));
}
void URLRequestContext::set_cookie_store(CookieStore* cookie_store) {
@@ -131,30 +127,4 @@ void URLRequestContext::AssertNoURLRequests() const {
}
}
-bool URLRequestContext::OnMemoryDump(
- const base::trace_event::MemoryDumpArgs& args,
- base::trace_event::ProcessMemoryDump* pmd) {
- std::string dump_name =
- base::StringPrintf("net/url_request_context/%s/0x%" PRIxPTR,
- name_.c_str(), reinterpret_cast<uintptr_t>(this));
- base::trace_event::MemoryAllocatorDump* dump =
- pmd->CreateAllocatorDump(dump_name);
- dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameObjectCount,
- base::trace_event::MemoryAllocatorDump::kUnitsObjects,
- url_requests_->size());
- HttpTransactionFactory* transaction_factory = http_transaction_factory();
- if (transaction_factory) {
- HttpNetworkSession* network_session = transaction_factory->GetSession();
- if (network_session)
- network_session->DumpMemoryStats(pmd, dump->absolute_name());
- HttpCache* http_cache = transaction_factory->GetCache();
- if (http_cache)
- http_cache->DumpMemoryStats(pmd, dump->absolute_name());
- }
- if (cookie_store_) {
- cookie_store_->DumpMemoryStats(pmd, dump->absolute_name());
- }
- return true;
-}
-
} // namespace net
diff --git a/chromium/net/url_request/url_request_context.h b/chromium/net/url_request/url_request_context.h
index 9e14a66be77..472ab4dece7 100644
--- a/chromium/net/url_request/url_request_context.h
+++ b/chromium/net/url_request/url_request_context.h
@@ -8,6 +8,7 @@
#ifndef NET_URL_REQUEST_URL_REQUEST_CONTEXT_H_
#define NET_URL_REQUEST_URL_REQUEST_CONTEXT_H_
+#include <stdint.h>
#include <memory>
#include <set>
#include <string>
@@ -16,22 +17,14 @@
#include "base/memory/ref_counted.h"
#include "base/memory/weak_ptr.h"
#include "base/threading/thread_checker.h"
-#include "base/trace_event/memory_dump_provider.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "net/base/net_export.h"
#include "net/base/request_priority.h"
-#include "net/http/http_server_properties.h"
-#include "net/http/transport_security_state.h"
#include "net/net_buildflags.h"
#include "net/traffic_annotation/network_traffic_annotation.h"
#include "net/url_request/url_request.h"
-
-namespace base {
-namespace trace_event {
-class ProcessMemoryDump;
-}
-}
+#include "third_party/abseil-cpp/absl/types/optional.h"
namespace net {
class CertVerifier;
@@ -41,6 +34,7 @@ class HostResolver;
class HttpAuthHandlerFactory;
struct HttpNetworkSessionContext;
struct HttpNetworkSessionParams;
+class HttpServerProperties;
class HttpTransactionFactory;
class HttpUserAgentSettings;
class NetLog;
@@ -51,14 +45,11 @@ class ProxyResolutionService;
class QuicContext;
class SCTAuditingDelegate;
class SSLConfigService;
+class TransportSecurityState;
class URLRequest;
class URLRequestJobFactory;
class URLRequestThrottlerManager;
-#if !BUILDFLAG(DISABLE_FTP_SUPPORT)
-class FtpAuthCache;
-#endif // !BUILDFLAG(DISABLE_FTP_SUPPORT)
-
#if BUILDFLAG(ENABLE_REPORTING)
class NetworkErrorLoggingService;
class ReportingService;
@@ -70,11 +61,14 @@ class ReportingService;
// automatic lifetime management. Most callers should use an existing
// URLRequestContext rather than creating a new one, as guaranteeing that the
// URLRequestContext is destroyed before its members can be difficult.
-class NET_EXPORT URLRequestContext
- : public base::trace_event::MemoryDumpProvider {
+class NET_EXPORT URLRequestContext {
public:
URLRequestContext();
- ~URLRequestContext() override;
+
+ URLRequestContext(const URLRequestContext&) = delete;
+ URLRequestContext& operator=(const URLRequestContext&) = delete;
+
+ virtual ~URLRequestContext();
// May return nullptr if this context doesn't have an associated network
// session.
@@ -99,7 +93,7 @@ class NET_EXPORT URLRequestContext
URLRequest::Delegate* delegate) const;
#endif
- // |traffic_annotation| is metadata about the network traffic send via this
+ // `traffic_annotation` is metadata about the network traffic send via this
// URLRequest, see net::DefineNetworkTrafficAnnotation. Note that:
// - net provides the API for tagging requests with an opaque identifier.
// - chrome/browser/privacy/traffic_annotation.proto contains the Chrome
@@ -107,11 +101,21 @@ class NET_EXPORT URLRequestContext
// callsites are expected to follow.
// - tools/traffic_annotation/ contains sample and template for annotation and
// tools will be added for verification following crbug.com/690323.
+ //
+ // `is_for_websockets` should be true iff this was created for use by a
+ // websocket. HTTP/HTTPS requests fail if it's true, and WS/WSS requests fail
+ // if it's false. This is to protect against broken consumers.
+ //
+ // `net_log_source_id` is used to construct NetLogWithSource using the
+ // specified Source ID. This method is expected to be used when URLRequest
+ // wants to take over existing NetLogSource.
std::unique_ptr<URLRequest> CreateRequest(
const GURL& url,
RequestPriority priority,
URLRequest::Delegate* delegate,
- NetworkTrafficAnnotationTag traffic_annotation) const;
+ NetworkTrafficAnnotationTag traffic_annotation,
+ bool is_for_websockets = false,
+ const absl::optional<uint32_t> net_log_source_id = absl::nullopt) const;
NetLog* net_log() const { return net_log_; }
@@ -295,25 +299,6 @@ class NET_EXPORT URLRequestContext
return require_network_isolation_key_;
}
-#if !BUILDFLAG(DISABLE_FTP_SUPPORT)
- void set_ftp_auth_cache(FtpAuthCache* auth_cache) {
- ftp_auth_cache_ = auth_cache;
- }
- FtpAuthCache* ftp_auth_cache() { return ftp_auth_cache_; }
-#endif // !BUILDFLAG(DISABLE_FTP_SUPPORT)
-
- // Sets a name for this URLRequestContext. Currently the name is used in
- // MemoryDumpProvier to annotate memory usage. The name does not need to be
- // unique.
- void set_name(const std::string& name) { name_ = name; }
- const std::string& name() const { return name_; }
-
- // MemoryDumpProvider implementation:
- // This is reported as
- // "memory:chrome:all_processes:reported_by_chrome:net:effective_size_avg."
- bool OnMemoryDump(const base::trace_event::MemoryDumpArgs& args,
- base::trace_event::ProcessMemoryDump* pmd) override;
-
void AssertCalledOnValidThread() {
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
}
@@ -344,9 +329,6 @@ class NET_EXPORT URLRequestContext
ReportingService* reporting_service_;
NetworkErrorLoggingService* network_error_logging_service_;
#endif // BUILDFLAG(ENABLE_REPORTING)
-#if !BUILDFLAG(DISABLE_FTP_SUPPORT)
- FtpAuthCache* ftp_auth_cache_;
-#endif // !BUILDFLAG(DISABLE_FTP_SUPPORT)
std::unique_ptr<std::set<const URLRequest*>> url_requests_;
@@ -360,14 +342,7 @@ class NET_EXPORT URLRequestContext
// a request when true.
bool require_network_isolation_key_;
- // An optional name which can be set to describe this URLRequestContext.
- // Used in MemoryDumpProvier to annotate memory usage. The name does not need
- // to be unique.
- std::string name_;
-
THREAD_CHECKER(thread_checker_);
-
- DISALLOW_COPY_AND_ASSIGN(URLRequestContext);
};
} // namespace net
diff --git a/chromium/net/url_request/url_request_context_builder.cc b/chromium/net/url_request/url_request_context_builder.cc
index 07886a778a1..05a754609c9 100644
--- a/chromium/net/url_request/url_request_context_builder.cc
+++ b/chromium/net/url_request/url_request_context_builder.cc
@@ -52,12 +52,6 @@
#include "net/url_request/url_request_throttler_manager.h"
#include "url/url_constants.h"
-#if !BUILDFLAG(DISABLE_FTP_SUPPORT)
-#include "net/ftp/ftp_auth_cache.h" // nogncheck
-#include "net/ftp/ftp_network_layer.h" // nogncheck
-#include "net/url_request/ftp_protocol_handler.h" // nogncheck
-#endif
-
#if BUILDFLAG(ENABLE_REPORTING)
#include "net/network_error_logging/network_error_logging_service.h"
#include "net/network_error_logging/persistent_reporting_and_nel_store.h"
@@ -78,6 +72,10 @@ class ContainerURLRequestContext final : public URLRequestContext {
public:
explicit ContainerURLRequestContext() : storage_(this) {}
+ ContainerURLRequestContext(const ContainerURLRequestContext&) = delete;
+ ContainerURLRequestContext& operator=(const ContainerURLRequestContext&) =
+ delete;
+
~ContainerURLRequestContext() override {
#if BUILDFLAG(ENABLE_REPORTING)
// Shut down the NetworkErrorLoggingService so that destroying the
@@ -116,8 +114,6 @@ class ContainerURLRequestContext final : public URLRequestContext {
private:
URLRequestContextStorage storage_;
std::unique_ptr<TransportSecurityPersister> transport_security_persister_;
-
- DISALLOW_COPY_AND_ASSIGN(ContainerURLRequestContext);
};
} // namespace
@@ -300,8 +296,6 @@ std::unique_ptr<URLRequestContext> URLRequestContextBuilder::Build() {
new ContainerURLRequestContext());
URLRequestContextStorage* storage = context->storage();
- if (!name_.empty())
- context->set_name(name_);
context->set_enable_brotli(enable_brotli_);
context->set_network_quality_estimator(network_quality_estimator_);
@@ -546,23 +540,12 @@ std::unique_ptr<URLRequestContext> URLRequestContextBuilder::Build() {
std::unique_ptr<URLRequestJobFactory> job_factory =
std::make_unique<URLRequestJobFactory>();
- // Adds caller-provided protocol handlers first so that these handlers are
- // used over the ftp handler below.
for (auto& scheme_handler : protocol_handlers_) {
job_factory->SetProtocolHandler(scheme_handler.first,
std::move(scheme_handler.second));
}
protocol_handlers_.clear();
-#if !BUILDFLAG(DISABLE_FTP_SUPPORT)
- if (ftp_enabled_) {
- storage->set_ftp_auth_cache(std::make_unique<FtpAuthCache>());
- job_factory->SetProtocolHandler(
- url::kFtpScheme, FtpProtocolHandler::Create(context->host_resolver(),
- context->ftp_auth_cache()));
- }
-#endif // !BUILDFLAG(DISABLE_FTP_SUPPORT)
-
storage->set_job_factory(std::move(job_factory));
return std::move(context);
diff --git a/chromium/net/url_request/url_request_context_builder.h b/chromium/net/url_request/url_request_context_builder.h
index d0508ddaeff..560577e0744 100644
--- a/chromium/net/url_request/url_request_context_builder.h
+++ b/chromium/net/url_request/url_request_context_builder.h
@@ -127,12 +127,11 @@ class NET_EXPORT URLRequestContextBuilder {
};
URLRequestContextBuilder();
- virtual ~URLRequestContextBuilder();
- // Sets a name for this URLRequestContext. Currently the name is used in
- // MemoryDumpProvier to annotate memory usage. The name does not need to be
- // unique.
- void set_name(const std::string& name) { name_ = name; }
+ URLRequestContextBuilder(const URLRequestContextBuilder&) = delete;
+ URLRequestContextBuilder& operator=(const URLRequestContextBuilder&) = delete;
+
+ virtual ~URLRequestContextBuilder();
// Sets whether Brotli compression is enabled. Disabled by default;
void set_enable_brotli(bool enable_brotli) { enable_brotli_ = enable_brotli; }
@@ -192,11 +191,6 @@ class NET_EXPORT URLRequestContextBuilder {
void set_http_user_agent_settings(
std::unique_ptr<HttpUserAgentSettings> http_user_agent_settings);
-#if !BUILDFLAG(DISABLE_FTP_SUPPORT)
- // Control support for ftp:// requests. By default it's disabled.
- void set_ftp_enabled(bool enable) { ftp_enabled_ = enable; }
-#endif
-
// Sets a valid ProtocolHandler for a scheme.
// A ProtocolHandler already exists for |scheme| will be overwritten.
void SetProtocolHandler(
@@ -338,7 +332,6 @@ class NET_EXPORT URLRequestContextBuilder {
bool pac_quick_check_enabled);
private:
- std::string name_;
bool enable_brotli_ = false;
NetworkQualityEstimator* network_quality_estimator_ = nullptr;
@@ -346,10 +339,6 @@ class NET_EXPORT URLRequestContextBuilder {
std::string user_agent_;
std::unique_ptr<HttpUserAgentSettings> http_user_agent_settings_;
-#if !BUILDFLAG(DISABLE_FTP_SUPPORT)
- // Include support for ftp:// requests.
- bool ftp_enabled_ = false;
-#endif
bool http_cache_enabled_ = true;
bool throttling_enabled_ = false;
bool cookie_store_set_by_client_ = false;
@@ -387,8 +376,6 @@ class NET_EXPORT URLRequestContextBuilder {
protocol_handlers_;
ClientSocketFactory* client_socket_factory_for_testing_ = nullptr;
-
- DISALLOW_COPY_AND_ASSIGN(URLRequestContextBuilder);
};
} // namespace net
diff --git a/chromium/net/url_request/url_request_context_builder_unittest.cc b/chromium/net/url_request/url_request_context_builder_unittest.cc
index a4a694bc113..90fbdaaec88 100644
--- a/chromium/net/url_request/url_request_context_builder_unittest.cc
+++ b/chromium/net/url_request/url_request_context_builder_unittest.cc
@@ -206,8 +206,9 @@ TEST_F(URLRequestContextBuilderTest, ShutDownNELAndReportingWithPendingUpload) {
// Queue a pending upload.
GURL url("https://www.foo.test");
context->reporting_service()->GetContextForTesting()->uploader()->StartUpload(
- url::Origin::Create(url), url, NetworkIsolationKey(), "report body", 0,
- base::DoNothing());
+ url::Origin::Create(url), url, IsolationInfo::CreateTransient(),
+ "report body", 0,
+ /*eligible_for_credentials=*/false, base::DoNothing());
base::RunLoop().RunUntilIdle();
ASSERT_EQ(1, context->reporting_service()
->GetContextForTesting()
diff --git a/chromium/net/url_request/url_request_context_getter.h b/chromium/net/url_request/url_request_context_getter.h
index 3c59f5ef00c..9e58ed1cc6c 100644
--- a/chromium/net/url_request/url_request_context_getter.h
+++ b/chromium/net/url_request/url_request_context_getter.h
@@ -33,6 +33,9 @@ class NET_EXPORT URLRequestContextGetter
: public base::RefCountedThreadSafe<URLRequestContextGetter,
URLRequestContextGetterTraits> {
public:
+ URLRequestContextGetter(const URLRequestContextGetter&) = delete;
+ URLRequestContextGetter& operator=(const URLRequestContextGetter&) = delete;
+
// Returns the URLRequestContextGetter's URLRequestContext. Must only be
// called on the network task runner. Once NotifyContextShuttingDown() is
// invoked, must always return nullptr. Does not transfer ownership of
@@ -84,8 +87,6 @@ class NET_EXPORT URLRequestContextGetter
void OnDestruct() const;
base::ObserverList<URLRequestContextGetterObserver>::Unchecked observer_list_;
-
- DISALLOW_COPY_AND_ASSIGN(URLRequestContextGetter);
};
struct URLRequestContextGetterTraits {
diff --git a/chromium/net/url_request/url_request_context_getter_observer.h b/chromium/net/url_request/url_request_context_getter_observer.h
index 53cd6dc2c64..1243b96e610 100644
--- a/chromium/net/url_request/url_request_context_getter_observer.h
+++ b/chromium/net/url_request/url_request_context_getter_observer.h
@@ -17,6 +17,11 @@ class NET_EXPORT URLRequestContextGetterObserver {
public:
URLRequestContextGetterObserver() {}
+ URLRequestContextGetterObserver(const URLRequestContextGetterObserver&) =
+ delete;
+ URLRequestContextGetterObserver& operator=(
+ const URLRequestContextGetterObserver&) = delete;
+
// Called before the URLRequestContext shuts down. When called, the Getter's
// GetURLRequestContext method must return NULL to protected against
// re-entrancy, but the Context must still be valid and GetNetworkTaskRunner()
@@ -25,9 +30,6 @@ class NET_EXPORT URLRequestContextGetterObserver {
protected:
virtual ~URLRequestContextGetterObserver() {}
-
- private:
- DISALLOW_COPY_AND_ASSIGN(URLRequestContextGetterObserver);
};
} // namespace net
diff --git a/chromium/net/url_request/url_request_context_storage.cc b/chromium/net/url_request/url_request_context_storage.cc
index 193d247fb9f..a369f824316 100644
--- a/chromium/net/url_request/url_request_context_storage.cc
+++ b/chromium/net/url_request/url_request_context_storage.cc
@@ -9,6 +9,7 @@
#include "base/check.h"
#include "net/base/http_user_agent_settings.h"
#include "net/base/network_delegate.h"
+#include "net/base/port_util.h"
#include "net/base/proxy_delegate.h"
#include "net/cert/cert_verifier.h"
#include "net/cert/ct_policy_enforcer.h"
@@ -19,6 +20,7 @@
#include "net/http/http_network_session.h"
#include "net/http/http_server_properties.h"
#include "net/http/http_transaction_factory.h"
+#include "net/http/transport_security_state.h"
#include "net/proxy_resolution/proxy_resolution_service.h"
#include "net/quic/quic_context.h"
#include "net/ssl/ssl_config_service.h"
@@ -26,10 +28,6 @@
#include "net/url_request/url_request_job_factory.h"
#include "net/url_request/url_request_throttler_manager.h"
-#if !BUILDFLAG(DISABLE_FTP_SUPPORT)
-#include "net/ftp/ftp_auth_cache.h"
-#endif // !BUILDFLAG(DISABLE_FTP_SUPPORT)
-
#if BUILDFLAG(ENABLE_REPORTING)
#include "net/network_error_logging/network_error_logging_service.h"
#include "net/network_error_logging/persistent_reporting_and_nel_store.h"
@@ -152,14 +150,6 @@ void URLRequestContextStorage::set_http_user_agent_settings(
http_user_agent_settings_ = std::move(http_user_agent_settings);
}
-#if !BUILDFLAG(DISABLE_FTP_SUPPORT)
-void URLRequestContextStorage::set_ftp_auth_cache(
- std::unique_ptr<FtpAuthCache> ftp_auth_cache) {
- context_->set_ftp_auth_cache(ftp_auth_cache.get());
- ftp_auth_cache_ = std::move(ftp_auth_cache);
-}
-#endif // !BUILDFLAG(DISABLE_FTP_SUPPORT)
-
#if BUILDFLAG(ENABLE_REPORTING)
void URLRequestContextStorage::set_persistent_reporting_and_nel_store(
std::unique_ptr<PersistentReportingAndNelStore>
diff --git a/chromium/net/url_request/url_request_context_storage.h b/chromium/net/url_request/url_request_context_storage.h
index d78511a6c18..d58d9f84e50 100644
--- a/chromium/net/url_request/url_request_context_storage.h
+++ b/chromium/net/url_request/url_request_context_storage.h
@@ -18,7 +18,6 @@ namespace net {
class CertVerifier;
class CookieStore;
class CTPolicyEnforcer;
-class FtpAuthCache;
class HostResolver;
class HttpAuthHandlerFactory;
class HttpNetworkSession;
@@ -50,6 +49,10 @@ class NET_EXPORT URLRequestContextStorage {
// URLRequestContext, since it is often designed to be embedded in a
// URLRequestContext subclass.
explicit URLRequestContextStorage(URLRequestContext* context);
+
+ URLRequestContextStorage(const URLRequestContextStorage&) = delete;
+ URLRequestContextStorage& operator=(const URLRequestContextStorage&) = delete;
+
~URLRequestContextStorage();
// These setters will set both the member variables and call the setter on the
@@ -84,9 +87,6 @@ class NET_EXPORT URLRequestContextStorage {
void set_quic_context(std::unique_ptr<QuicContext> quic_context);
void set_http_user_agent_settings(
std::unique_ptr<HttpUserAgentSettings> http_user_agent_settings);
-#if !BUILDFLAG(DISABLE_FTP_SUPPORT)
- void set_ftp_auth_cache(std::unique_ptr<FtpAuthCache> ftp_auth_cache);
-#endif // !BUILDFLAG(DISABLE_FTP_SUPPORT)
#if BUILDFLAG(ENABLE_REPORTING)
void set_persistent_reporting_and_nel_store(
@@ -124,9 +124,6 @@ class NET_EXPORT URLRequestContextStorage {
std::unique_ptr<CTPolicyEnforcer> ct_policy_enforcer_;
std::unique_ptr<SCTAuditingDelegate> sct_auditing_delegate_;
std::unique_ptr<QuicContext> quic_context_;
-#if !BUILDFLAG(DISABLE_FTP_SUPPORT)
- std::unique_ptr<FtpAuthCache> ftp_auth_cache_;
-#endif // !BUILDFLAG(DISABLE_FTP_SUPPORT)
// Not actually pointed at by the URLRequestContext, but may be used (but not
// owned) by the HttpTransactionFactory.
@@ -144,8 +141,6 @@ class NET_EXPORT URLRequestContextStorage {
std::unique_ptr<ReportingService> reporting_service_;
std::unique_ptr<NetworkErrorLoggingService> network_error_logging_service_;
#endif // BUILDFLAG(ENABLE_REPORTING)
-
- DISALLOW_COPY_AND_ASSIGN(URLRequestContextStorage);
};
} // namespace net
diff --git a/chromium/net/url_request/url_request_context_unittest.cc b/chromium/net/url_request/url_request_context_unittest.cc
deleted file mode 100644
index 3cf06b035bb..00000000000
--- a/chromium/net/url_request/url_request_context_unittest.cc
+++ /dev/null
@@ -1,71 +0,0 @@
-// Copyright 2016 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "net/url_request/url_request_context.h"
-
-#include "base/strings/pattern.h"
-#include "base/trace_event/memory_dump_request_args.h"
-#include "base/trace_event/process_memory_dump.h"
-#include "net/proxy_resolution/proxy_config_service_fixed.h"
-#include "net/test/test_with_task_environment.h"
-#include "net/traffic_annotation/network_traffic_annotation_test_helper.h"
-#include "net/url_request/url_request_context_builder.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-namespace net {
-
-class URLRequestContextMemoryDumpTest
- : public testing::TestWithParam<base::trace_event::MemoryDumpLevelOfDetail>,
- public WithTaskEnvironment {};
-
-INSTANTIATE_TEST_SUITE_P(
- All,
- URLRequestContextMemoryDumpTest,
- ::testing::Values(base::trace_event::MemoryDumpLevelOfDetail::DETAILED,
- base::trace_event::MemoryDumpLevelOfDetail::BACKGROUND));
-
-// Checks if the dump provider runs without crashing and dumps root objects.
-TEST_P(URLRequestContextMemoryDumpTest, MemoryDumpProvider) {
- base::trace_event::MemoryDumpArgs dump_args = {GetParam()};
- std::unique_ptr<base::trace_event::ProcessMemoryDump> process_memory_dump(
- new base::trace_event::ProcessMemoryDump(dump_args));
- URLRequestContextBuilder builder;
-#if defined(OS_LINUX) || defined(OS_CHROMEOS) || defined(OS_ANDROID)
- builder.set_proxy_config_service(std::make_unique<ProxyConfigServiceFixed>(
- ProxyConfigWithAnnotation::CreateDirect()));
-#endif // defined(OS_LINUX) || defined(OS_CHROMEOS) || defined(OS_ANDROID)
- std::unique_ptr<URLRequestContext> context(builder.Build());
- context->OnMemoryDump(dump_args, process_memory_dump.get());
- const base::trace_event::ProcessMemoryDump::AllocatorDumpsMap&
- allocator_dumps = process_memory_dump->allocator_dumps();
-
- bool did_dump_http_network_session = false;
- bool did_dump_ssl_client_session_cache = false;
- bool did_dump_url_request_context = false;
- bool did_dump_url_request_context_http_network_session = false;
- for (const auto& it : allocator_dumps) {
- const std::string& dump_name = it.first;
- if (dump_name.find("net/http_network_session") != std::string::npos)
- did_dump_http_network_session = true;
- // Match against a relaxed form of the memory dump permitted pattern.
- if (base::MatchPattern(
- dump_name, "net/http_network_session_0x*/ssl_client_session_cache"))
- did_dump_ssl_client_session_cache = true;
- if (dump_name.find("net/url_request_context") != std::string::npos) {
- // A sub allocator dump to take into account of the sharing relationship.
- if (dump_name.find("http_network_session") != std::string::npos) {
- did_dump_url_request_context_http_network_session = true;
- } else {
- did_dump_url_request_context = true;
- }
- }
- }
- ASSERT_TRUE(did_dump_http_network_session);
- ASSERT_TRUE(did_dump_ssl_client_session_cache);
- ASSERT_TRUE(did_dump_url_request_context);
- ASSERT_TRUE(did_dump_url_request_context_http_network_session);
-}
-
-// TODO(xunjieli): Add more granular tests on the MemoryDumpProvider.
-} // namespace net
diff --git a/chromium/net/url_request/url_request_filter.h b/chromium/net/url_request/url_request_filter.h
index 003620a2f78..0051f0cefee 100644
--- a/chromium/net/url_request/url_request_filter.h
+++ b/chromium/net/url_request/url_request_filter.h
@@ -43,6 +43,9 @@ class NET_EXPORT URLRequestFilter : public URLRequestInterceptor {
// Singleton instance for use.
static URLRequestFilter* GetInstance();
+ URLRequestFilter(const URLRequestFilter&) = delete;
+ URLRequestFilter& operator=(const URLRequestFilter&) = delete;
+
void AddHostnameInterceptor(
const std::string& scheme,
const std::string& hostname,
@@ -90,8 +93,6 @@ class NET_EXPORT URLRequestFilter : public URLRequestInterceptor {
// Singleton instance.
static URLRequestFilter* shared_instance_;
-
- DISALLOW_COPY_AND_ASSIGN(URLRequestFilter);
};
} // namespace net
diff --git a/chromium/net/url_request/url_request_filter_unittest.cc b/chromium/net/url_request/url_request_filter_unittest.cc
index d0e3502b4dd..cc8e26f2fc4 100644
--- a/chromium/net/url_request/url_request_filter_unittest.cc
+++ b/chromium/net/url_request/url_request_filter_unittest.cc
@@ -26,6 +26,11 @@ namespace {
class TestURLRequestInterceptor : public URLRequestInterceptor {
public:
TestURLRequestInterceptor() : job_(nullptr) {}
+
+ TestURLRequestInterceptor(const TestURLRequestInterceptor&) = delete;
+ TestURLRequestInterceptor& operator=(const TestURLRequestInterceptor&) =
+ delete;
+
~TestURLRequestInterceptor() override = default;
// URLRequestInterceptor implementation:
@@ -42,8 +47,6 @@ class TestURLRequestInterceptor : public URLRequestInterceptor {
private:
mutable URLRequestTestJob* job_;
-
- DISALLOW_COPY_AND_ASSIGN(TestURLRequestInterceptor);
};
TEST(URLRequestFilter, BasicMatching) {
diff --git a/chromium/net/url_request/url_request_ftp_fuzzer.cc b/chromium/net/url_request/url_request_ftp_fuzzer.cc
deleted file mode 100644
index e589091fb92..00000000000
--- a/chromium/net/url_request/url_request_ftp_fuzzer.cc
+++ /dev/null
@@ -1,92 +0,0 @@
-// Copyright 2016 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include <stddef.h>
-#include <stdint.h>
-
-#include <fuzzer/FuzzedDataProvider.h>
-
-#include "base/macros.h"
-#include "base/run_loop.h"
-#include "net/base/request_priority.h"
-#include "net/dns/context_host_resolver.h"
-#include "net/dns/fuzzed_host_resolver_util.h"
-#include "net/ftp/ftp_auth_cache.h"
-#include "net/ftp/ftp_network_transaction.h"
-#include "net/ftp/ftp_transaction_factory.h"
-#include "net/socket/client_socket_factory.h"
-#include "net/socket/fuzzed_socket_factory.h"
-#include "net/traffic_annotation/network_traffic_annotation_test_helper.h"
-#include "net/url_request/ftp_protocol_handler.h"
-#include "net/url_request/url_request.h"
-#include "net/url_request/url_request_context.h"
-#include "net/url_request/url_request_job_factory.h"
-#include "net/url_request/url_request_test_util.h"
-#include "url/gurl.h"
-
-namespace {
-
-// Returns FtpNetworkTransactions using the specified HostResolver
-// and ClientSocketFactory.
-class FuzzedFtpTransactionFactory : public net::FtpTransactionFactory {
- public:
- FuzzedFtpTransactionFactory(net::HostResolver* host_resolver,
- net::ClientSocketFactory* client_socket_factory)
- : host_resolver_(host_resolver),
- client_socket_factory_(client_socket_factory) {}
-
- // FtpTransactionFactory:
- std::unique_ptr<net::FtpTransaction> CreateTransaction() override {
- return std::make_unique<net::FtpNetworkTransaction>(host_resolver_,
- client_socket_factory_);
- }
-
- void Suspend(bool suspend) override { NOTREACHED(); }
-
- private:
- net::HostResolver* host_resolver_;
- net::ClientSocketFactory* client_socket_factory_;
-
- DISALLOW_COPY_AND_ASSIGN(FuzzedFtpTransactionFactory);
-};
-
-} // namespace
-
-// Integration fuzzer for URLRequestFtpJob.
-extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
- FuzzedDataProvider data_provider(data, size);
- net::TestURLRequestContext url_request_context(true);
- net::FuzzedSocketFactory fuzzed_socket_factory(&data_provider);
- url_request_context.set_client_socket_factory(&fuzzed_socket_factory);
-
- // Need to fuzz the HostResolver to select between IPv4 and IPv6.
- std::unique_ptr<net::ContextHostResolver> host_resolver =
- net::CreateFuzzedContextHostResolver(net::HostResolver::ManagerOptions(),
- nullptr, &data_provider,
- true /* enable_caching */);
- url_request_context.set_host_resolver(host_resolver.get());
-
- net::URLRequestJobFactory job_factory;
- net::FtpAuthCache auth_cache;
- job_factory.SetProtocolHandler(
- "ftp", net::FtpProtocolHandler::CreateForTesting(
- std::make_unique<FuzzedFtpTransactionFactory>(
- host_resolver.get(), &fuzzed_socket_factory),
- &auth_cache));
- url_request_context.set_job_factory(&job_factory);
-
- url_request_context.Init();
-
- net::TestDelegate delegate;
-
- std::unique_ptr<net::URLRequest> url_request(
- url_request_context.CreateRequest(
- GURL("ftp://foo/" + data_provider.ConsumeRandomLengthString(1000)),
- net::DEFAULT_PRIORITY, &delegate, TRAFFIC_ANNOTATION_FOR_TESTS));
- url_request->Start();
- // TestDelegate quits the message loop on completion.
- base::RunLoop().Run();
-
- return 0;
-}
diff --git a/chromium/net/url_request/url_request_ftp_job.cc b/chromium/net/url_request/url_request_ftp_job.cc
deleted file mode 100644
index 8ce8e65a7f0..00000000000
--- a/chromium/net/url_request/url_request_ftp_job.cc
+++ /dev/null
@@ -1,327 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "net/url_request/url_request_ftp_job.h"
-
-#include "base/bind.h"
-#include "base/compiler_specific.h"
-#include "base/location.h"
-#include "base/metrics/histogram_macros.h"
-#include "base/single_thread_task_runner.h"
-#include "base/strings/utf_string_conversions.h"
-#include "base/threading/thread_task_runner_handle.h"
-#include "net/base/auth.h"
-#include "net/base/host_port_pair.h"
-#include "net/base/load_flags.h"
-#include "net/base/net_errors.h"
-#include "net/ftp/ftp_auth_cache.h"
-#include "net/ftp/ftp_network_transaction.h"
-#include "net/ftp/ftp_response_info.h"
-#include "net/ftp/ftp_transaction_factory.h"
-#include "net/http/http_response_headers.h"
-#include "net/http/http_transaction_factory.h"
-#include "net/proxy_resolution/proxy_resolution_request.h"
-#include "net/url_request/url_request.h"
-#include "net/url_request/url_request_context.h"
-#include "net/url_request/url_request_error_job.h"
-
-namespace net {
-
-class URLRequestFtpJob::AuthData {
- public:
- AuthState state; // Whether we need, have, or gave up on authentication.
- AuthCredentials credentials; // The credentials to use for auth.
-
- AuthData();
- ~AuthData();
-};
-
-URLRequestFtpJob::AuthData::AuthData() : state(AUTH_STATE_NEED_AUTH) {}
-
-URLRequestFtpJob::AuthData::~AuthData() = default;
-
-URLRequestFtpJob::URLRequestFtpJob(
- URLRequest* request,
- FtpTransactionFactory* ftp_transaction_factory,
- FtpAuthCache* ftp_auth_cache)
- : URLRequestJob(request),
- proxy_resolution_service_(
- request_->context()->proxy_resolution_service()),
- read_in_progress_(false),
- ftp_transaction_factory_(ftp_transaction_factory),
- ftp_auth_cache_(ftp_auth_cache) {
- DCHECK(proxy_resolution_service_);
- DCHECK(ftp_transaction_factory);
- DCHECK(ftp_auth_cache);
-}
-
-URLRequestFtpJob::~URLRequestFtpJob() {
- Kill();
-}
-
-bool URLRequestFtpJob::IsSafeRedirect(const GURL& location) {
- // Disallow all redirects.
- return false;
-}
-
-bool URLRequestFtpJob::GetMimeType(std::string* mime_type) const {
- // When auth has been cancelled, return a blank text/plain page instead of
- // triggering a download.
- if (auth_data_ && auth_data_->state == AUTH_STATE_CANCELED) {
- *mime_type = "text/plain";
- return true;
- }
-
- if (ftp_transaction_->GetResponseInfo()->is_directory_listing) {
- *mime_type = "text/vnd.chromium.ftp-dir";
- return true;
- }
-
- // FTP resources other than directory listings ought to be handled as raw
- // binary data, not sniffed into HTML or etc.
- *mime_type = "application/octet-stream";
- return true;
-}
-
-IPEndPoint URLRequestFtpJob::GetResponseRemoteEndpoint() const {
- if (!ftp_transaction_)
- return IPEndPoint();
- return ftp_transaction_->GetResponseInfo()->remote_endpoint;
-}
-
-void URLRequestFtpJob::Start() {
- DCHECK(!proxy_resolve_request_);
- DCHECK(!ftp_transaction_);
-
- int rv = OK;
- if (request_->load_flags() & LOAD_BYPASS_PROXY) {
- proxy_info_.UseDirect();
- } else {
- DCHECK_EQ(request_->context()->proxy_resolution_service(),
- proxy_resolution_service_);
- // "Fine" to use an empty NetworkIsolationKey() because FTP is slated for
- // removal.
- rv = proxy_resolution_service_->ResolveProxy(
- request_->url(), "GET", NetworkIsolationKey(), &proxy_info_,
- base::BindOnce(&URLRequestFtpJob::OnResolveProxyComplete,
- base::Unretained(this)),
- &proxy_resolve_request_, request_->net_log());
-
- if (rv == ERR_IO_PENDING)
- return;
- }
- OnResolveProxyComplete(rv);
-}
-
-void URLRequestFtpJob::Kill() {
- if (proxy_resolve_request_) {
- proxy_resolve_request_.reset();
- }
- if (ftp_transaction_)
- ftp_transaction_.reset();
- URLRequestJob::Kill();
- weak_factory_.InvalidateWeakPtrs();
-}
-
-void URLRequestFtpJob::GetResponseInfo(HttpResponseInfo* info) {
- // Don't expose the challenge if it has already been successfully
- // authenticated.
- if (!auth_data_ || auth_data_->state == AUTH_STATE_HAVE_AUTH)
- return;
-
- std::unique_ptr<AuthChallengeInfo> challenge = GetAuthChallengeInfo();
- if (challenge)
- info->auth_challenge = *challenge;
-}
-
-void URLRequestFtpJob::OnResolveProxyComplete(int result) {
- proxy_resolve_request_ = nullptr;
-
- if (result != OK) {
- OnStartCompletedAsync(result);
- return;
- }
-
- // Remove unsupported proxies from the list.
- proxy_info_.RemoveProxiesWithoutScheme(ProxyServer::SCHEME_DIRECT);
-
- if (proxy_info_.is_direct()) {
- StartFtpTransaction();
- } else {
- OnStartCompletedAsync(ERR_NO_SUPPORTED_PROXIES);
- }
-}
-
-void URLRequestFtpJob::StartFtpTransaction() {
- // Create a transaction.
- DCHECK(!ftp_transaction_);
-
- ftp_request_info_.url = request_->url();
- ftp_transaction_ = ftp_transaction_factory_->CreateTransaction();
-
- int rv;
- if (ftp_transaction_) {
- rv = ftp_transaction_->Start(
- &ftp_request_info_,
- base::BindOnce(&URLRequestFtpJob::OnStartCompleted,
- base::Unretained(this)),
- request_->net_log(), request_->traffic_annotation());
- if (rv == ERR_IO_PENDING)
- return;
- } else {
- rv = ERR_FAILED;
- }
- // The transaction started synchronously, but we need to notify the
- // URLRequest delegate via the message loop.
- OnStartCompletedAsync(rv);
-}
-
-void URLRequestFtpJob::OnStartCompleted(int result) {
- if (result == OK) {
- DCHECK(ftp_transaction_);
-
- // FTP obviously doesn't have HTTP Content-Length header. We have to pass
- // the content size information manually.
- set_expected_content_size(
- ftp_transaction_->GetResponseInfo()->expected_content_size);
-
- if (auth_data_ && auth_data_->state == AUTH_STATE_HAVE_AUTH) {
- LogFtpStartResult(FTPStartResult::kSuccessAuth);
- } else {
- LogFtpStartResult(FTPStartResult::kSuccessNoAuth);
- }
-
- NotifyHeadersComplete();
- } else if (ftp_transaction_ /* May be null if creation fails. */ &&
- ftp_transaction_->GetResponseInfo()->needs_auth) {
- HandleAuthNeededResponse();
- } else {
- LogFtpStartResult(FTPStartResult::kFailed);
- NotifyStartError(result);
- }
-}
-
-void URLRequestFtpJob::OnStartCompletedAsync(int result) {
- base::ThreadTaskRunnerHandle::Get()->PostTask(
- FROM_HERE, base::BindOnce(&URLRequestFtpJob::OnStartCompleted,
- weak_factory_.GetWeakPtr(), result));
-}
-
-void URLRequestFtpJob::OnReadCompleted(int result) {
- read_in_progress_ = false;
- ReadRawDataComplete(result);
-}
-
-void URLRequestFtpJob::RestartTransactionWithAuth() {
- DCHECK(auth_data_.get() && auth_data_->state == AUTH_STATE_HAVE_AUTH);
-
- int rv = ftp_transaction_->RestartWithAuth(
- auth_data_->credentials,
- base::BindOnce(&URLRequestFtpJob::OnStartCompleted,
- base::Unretained(this)));
- if (rv == ERR_IO_PENDING)
- return;
-
- OnStartCompletedAsync(rv);
-}
-
-LoadState URLRequestFtpJob::GetLoadState() const {
- if (proxy_resolve_request_)
- return proxy_resolve_request_->GetLoadState();
- return ftp_transaction_ ? ftp_transaction_->GetLoadState() : LOAD_STATE_IDLE;
-}
-
-bool URLRequestFtpJob::NeedsAuth() {
- return auth_data_.get() && auth_data_->state == AUTH_STATE_NEED_AUTH;
-}
-
-std::unique_ptr<AuthChallengeInfo> URLRequestFtpJob::GetAuthChallengeInfo() {
- std::unique_ptr<AuthChallengeInfo> result =
- std::make_unique<AuthChallengeInfo>();
- result->is_proxy = false;
- result->challenger = url::Origin::Create(request_->url());
- // scheme, realm, path, and challenge are kept empty.
- DCHECK(result->scheme.empty());
- DCHECK(result->realm.empty());
- DCHECK(result->challenge.empty());
- DCHECK(result->path.empty());
- return result;
-}
-
-void URLRequestFtpJob::SetAuth(const AuthCredentials& credentials) {
- DCHECK(ftp_transaction_);
- DCHECK(NeedsAuth());
-
- auth_data_->state = AUTH_STATE_HAVE_AUTH;
- auth_data_->credentials = credentials;
-
- ftp_auth_cache_->Add(request_->url().GetOrigin(), auth_data_->credentials);
-
- RestartTransactionWithAuth();
-}
-
-void URLRequestFtpJob::CancelAuth() {
- DCHECK(ftp_transaction_);
- DCHECK(NeedsAuth());
-
- auth_data_->state = AUTH_STATE_CANCELED;
-
- ftp_transaction_.reset();
- NotifyHeadersComplete();
-}
-
-int URLRequestFtpJob::ReadRawData(IOBuffer* buf, int buf_size) {
- DCHECK_NE(buf_size, 0);
- DCHECK(!read_in_progress_);
-
- if (!ftp_transaction_)
- return 0;
-
- int rv =
- ftp_transaction_->Read(buf, buf_size,
- base::BindOnce(&URLRequestFtpJob::OnReadCompleted,
- base::Unretained(this)));
-
- if (rv == ERR_IO_PENDING)
- read_in_progress_ = true;
- return rv;
-}
-
-void URLRequestFtpJob::HandleAuthNeededResponse() {
- GURL origin = request_->url().GetOrigin();
-
- if (auth_data_.get()) {
- if (auth_data_->state == AUTH_STATE_CANCELED) {
- NotifyHeadersComplete();
- return;
- }
-
- if (ftp_transaction_ && auth_data_->state == AUTH_STATE_HAVE_AUTH) {
- ftp_auth_cache_->Remove(origin, auth_data_->credentials);
-
- // The user entered invalid auth
- LogFtpStartResult(FTPStartResult::kFailed);
- }
- } else {
- auth_data_ = std::make_unique<AuthData>();
- }
- auth_data_->state = AUTH_STATE_NEED_AUTH;
-
- FtpAuthCache::Entry* cached_auth = nullptr;
- if (ftp_transaction_ && ftp_transaction_->GetResponseInfo()->needs_auth)
- cached_auth = ftp_auth_cache_->Lookup(origin);
- if (cached_auth) {
- // Retry using cached auth data.
- SetAuth(cached_auth->credentials);
- } else {
- // Prompt for a username/password.
- NotifyHeadersComplete();
- }
-}
-
-void URLRequestFtpJob::LogFtpStartResult(FTPStartResult result) {
- UMA_HISTOGRAM_ENUMERATION("Net.FTP.StartResult", result);
-}
-
-} // namespace net
diff --git a/chromium/net/url_request/url_request_ftp_job.h b/chromium/net/url_request/url_request_ftp_job.h
deleted file mode 100644
index 6a0b17d582b..00000000000
--- a/chromium/net/url_request/url_request_ftp_job.h
+++ /dev/null
@@ -1,102 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef NET_URL_REQUEST_URL_REQUEST_FTP_JOB_H_
-#define NET_URL_REQUEST_URL_REQUEST_FTP_JOB_H_
-
-#include <memory>
-#include <string>
-
-#include "base/macros.h"
-#include "base/memory/weak_ptr.h"
-#include "net/base/auth.h"
-#include "net/base/ip_endpoint.h"
-#include "net/base/net_export.h"
-#include "net/ftp/ftp_request_info.h"
-#include "net/ftp/ftp_transaction.h"
-#include "net/proxy_resolution/proxy_info.h"
-#include "net/proxy_resolution/proxy_resolution_service.h"
-#include "net/url_request/url_request_job.h"
-
-namespace net {
-
-// These values are persisted to logs. Entries should not be renumbered and
-// numeric values should never be reused.
-enum class FTPStartResult : int {
- kSuccessNoAuth = 0,
- kSuccessAuth = 1,
- kFailed = 2,
- kMaxValue = kFailed
-};
-
-class FtpAuthCache;
-class FtpTransactionFactory;
-class ProxyResolutionRequest;
-
-// A URLRequestJob subclass that is built on top of FtpTransaction. It
-// provides an implementation for FTP.
-class NET_EXPORT_PRIVATE URLRequestFtpJob : public URLRequestJob {
- public:
- URLRequestFtpJob(URLRequest* request,
- FtpTransactionFactory* ftp_transaction_factory,
- FtpAuthCache* ftp_auth_cache);
- ~URLRequestFtpJob() override;
- void Start() override;
-
- protected:
- // Overridden from URLRequestJob:
- bool IsSafeRedirect(const GURL& location) override;
- bool GetMimeType(std::string* mime_type) const override;
- IPEndPoint GetResponseRemoteEndpoint() const override;
- void Kill() override;
- void GetResponseInfo(HttpResponseInfo* info) override;
-
- private:
- class AuthData;
-
- void OnResolveProxyComplete(int result);
-
- void StartFtpTransaction();
-
- void OnStartCompleted(int result);
- void OnStartCompletedAsync(int result);
- void OnReadCompleted(int result);
-
- void RestartTransactionWithAuth();
-
- // Overridden from URLRequestJob:
- LoadState GetLoadState() const override;
- bool NeedsAuth() override;
- std::unique_ptr<AuthChallengeInfo> GetAuthChallengeInfo() override;
- void SetAuth(const AuthCredentials& credentials) override;
- void CancelAuth() override;
-
- int ReadRawData(IOBuffer* buf, int buf_size) override;
-
- void HandleAuthNeededResponse();
-
- void LogFtpStartResult(FTPStartResult result);
-
- ProxyResolutionService* proxy_resolution_service_;
- ProxyInfo proxy_info_;
- std::unique_ptr<ProxyResolutionRequest> proxy_resolve_request_;
-
- FtpRequestInfo ftp_request_info_;
- std::unique_ptr<FtpTransaction> ftp_transaction_;
-
- bool read_in_progress_;
-
- std::unique_ptr<AuthData> auth_data_;
-
- FtpTransactionFactory* ftp_transaction_factory_;
- FtpAuthCache* ftp_auth_cache_;
-
- base::WeakPtrFactory<URLRequestFtpJob> weak_factory_{this};
-
- DISALLOW_COPY_AND_ASSIGN(URLRequestFtpJob);
-};
-
-} // namespace net
-
-#endif // NET_URL_REQUEST_URL_REQUEST_FTP_JOB_H_
diff --git a/chromium/net/url_request/url_request_ftp_job_unittest.cc b/chromium/net/url_request/url_request_ftp_job_unittest.cc
deleted file mode 100644
index 62e4719adc7..00000000000
--- a/chromium/net/url_request/url_request_ftp_job_unittest.cc
+++ /dev/null
@@ -1,245 +0,0 @@
-// Copyright (c) 2019 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "net/url_request/url_request_ftp_job.h"
-
-#include <memory>
-
-#include "base/test/metrics/histogram_tester.h"
-#include "net/base/auth.h"
-#include "net/base/load_states.h"
-#include "net/base/net_errors.h"
-#include "net/base/request_priority.h"
-#include "net/ftp/ftp_auth_cache.h"
-#include "net/ftp/ftp_response_info.h"
-#include "net/ftp/ftp_transaction.h"
-#include "net/ftp/ftp_transaction_factory.h"
-#include "net/test/test_with_task_environment.h"
-#include "net/traffic_annotation/network_traffic_annotation_test_helper.h"
-#include "net/url_request/url_request_job_factory.h"
-#include "net/url_request/url_request_test_util.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-namespace net {
-namespace {
-
-class MockFtpTransaction : public FtpTransaction {
- public:
- MockFtpTransaction(int start_return_value,
- int read_return_value,
- bool needs_auth,
- std::vector<int> restart_return_values)
- : start_return_value_(start_return_value),
- read_return_value_(read_return_value),
- restart_return_values_(restart_return_values),
- restart_index_(0) {
- response_.needs_auth = needs_auth;
- }
- ~MockFtpTransaction() override {}
-
- int Start(const FtpRequestInfo* request_info,
- CompletionOnceCallback callback,
- const NetLogWithSource& net_log,
- const NetworkTrafficAnnotationTag& traffic_annotation) override {
- return start_return_value_;
- }
-
- int RestartWithAuth(const AuthCredentials& credentials,
- CompletionOnceCallback callback) override {
- CHECK(restart_index_ < restart_return_values_.size());
- return restart_return_values_[restart_index_++];
- }
-
- int Read(IOBuffer* buf,
- int buf_len,
- CompletionOnceCallback callback) override {
- return read_return_value_;
- }
-
- const FtpResponseInfo* GetResponseInfo() const override { return &response_; }
-
- LoadState GetLoadState() const override { return LOAD_STATE_IDLE; }
-
- uint64_t GetUploadProgress() const override { return 0; }
-
- private:
- FtpResponseInfo response_;
- int start_return_value_;
- int read_return_value_;
- std::vector<int> restart_return_values_;
- unsigned int restart_index_;
-
- DISALLOW_COPY_AND_ASSIGN(MockFtpTransaction);
-};
-
-class MockFtpTransactionFactory : public FtpTransactionFactory {
- public:
- MockFtpTransactionFactory(int start_return_value,
- int read_return_value,
- bool needs_auth,
- std::vector<int> restart_return_values)
- : start_return_value_(start_return_value),
- read_return_value_(read_return_value),
- needs_auth_(needs_auth),
- restart_return_values_(restart_return_values) {}
-
- ~MockFtpTransactionFactory() override {}
-
- std::unique_ptr<FtpTransaction> CreateTransaction() override {
- return std::make_unique<MockFtpTransaction>(start_return_value_,
- read_return_value_, needs_auth_,
- restart_return_values_);
- }
-
- void Suspend(bool suspend) override {}
-
- private:
- int start_return_value_;
- int read_return_value_;
- bool needs_auth_;
- std::vector<int> restart_return_values_;
-
- DISALLOW_COPY_AND_ASSIGN(MockFtpTransactionFactory);
-};
-
-class MockURLRequestFtpJobFactory : public URLRequestJobFactory {
- public:
- MockURLRequestFtpJobFactory(int start_return_value,
- int read_return_value,
- bool needs_auth,
- std::vector<int> restart_return_values)
- : auth_cache(new FtpAuthCache()),
- factory(new MockFtpTransactionFactory(start_return_value,
- read_return_value,
- needs_auth,
- restart_return_values)) {}
-
- ~MockURLRequestFtpJobFactory() override {
- delete auth_cache;
- delete factory;
- }
-
- std::unique_ptr<URLRequestJob> CreateJob(URLRequest* request) const override {
- return std::make_unique<URLRequestFtpJob>(request, factory, auth_cache);
- }
-
- bool IsSafeRedirectTarget(const GURL& location) const override {
- return true;
- }
-
- private:
- FtpAuthCache* auth_cache;
- MockFtpTransactionFactory* factory;
-
- DISALLOW_COPY_AND_ASSIGN(MockURLRequestFtpJobFactory);
-};
-
-using UrlRequestFtpJobTest = TestWithTaskEnvironment;
-
-TEST_F(UrlRequestFtpJobTest, HistogramLogSuccessNoAuth) {
- base::HistogramTester histograms;
- MockURLRequestFtpJobFactory url_request_ftp_job_factory(OK, OK, false, {OK});
- TestNetworkDelegate network_delegate;
- TestURLRequestContext context(true);
- context.set_network_delegate(&network_delegate);
- context.set_job_factory(&url_request_ftp_job_factory);
- context.Init();
-
- TestDelegate test_delegate;
- std::unique_ptr<URLRequest> r(context.CreateRequest(
- GURL("ftp://example.test/"), RequestPriority::DEFAULT_PRIORITY,
- &test_delegate, TRAFFIC_ANNOTATION_FOR_TESTS));
-
- r->Start();
- test_delegate.RunUntilComplete();
-
- histograms.ExpectBucketCount("Net.FTP.StartResult",
- FTPStartResult::kSuccessNoAuth, 1);
- histograms.ExpectBucketCount("Net.FTP.StartResult",
- FTPStartResult::kSuccessAuth, 0);
- histograms.ExpectBucketCount("Net.FTP.StartResult", FTPStartResult::kFailed,
- 0);
-}
-
-TEST_F(UrlRequestFtpJobTest, HistogramLogSuccessAuth) {
- base::HistogramTester histograms;
- MockURLRequestFtpJobFactory url_request_ftp_job_factory(
- ERR_FAILED, ERR_FAILED, true, {OK});
- TestNetworkDelegate network_delegate;
- TestURLRequestContext context(true);
- context.set_network_delegate(&network_delegate);
- context.set_job_factory(&url_request_ftp_job_factory);
- context.Init();
-
- TestDelegate test_delegate;
- test_delegate.set_credentials(AuthCredentials(u"user", u"pass"));
- std::unique_ptr<URLRequest> r(context.CreateRequest(
- GURL("ftp://example.test/"), RequestPriority::DEFAULT_PRIORITY,
- &test_delegate, TRAFFIC_ANNOTATION_FOR_TESTS));
-
- r->Start();
- test_delegate.RunUntilComplete();
-
- histograms.ExpectBucketCount("Net.FTP.StartResult",
- FTPStartResult::kSuccessNoAuth, 0);
- histograms.ExpectBucketCount("Net.FTP.StartResult",
- FTPStartResult::kSuccessAuth, 1);
- histograms.ExpectBucketCount("Net.FTP.StartResult", FTPStartResult::kFailed,
- 0);
-}
-
-TEST_F(UrlRequestFtpJobTest, HistogramLogFailed) {
- base::HistogramTester histograms;
- MockURLRequestFtpJobFactory url_request_ftp_job_factory(
- ERR_FAILED, ERR_FAILED, false, {ERR_FAILED});
- TestNetworkDelegate network_delegate;
- TestURLRequestContext context(true);
- context.set_network_delegate(&network_delegate);
- context.set_job_factory(&url_request_ftp_job_factory);
- context.Init();
-
- TestDelegate test_delegate;
- std::unique_ptr<URLRequest> r(context.CreateRequest(
- GURL("ftp://example.test/"), RequestPriority::DEFAULT_PRIORITY,
- &test_delegate, TRAFFIC_ANNOTATION_FOR_TESTS));
-
- r->Start();
- test_delegate.RunUntilComplete();
-
- histograms.ExpectBucketCount("Net.FTP.StartResult",
- FTPStartResult::kSuccessNoAuth, 0);
- histograms.ExpectBucketCount("Net.FTP.StartResult",
- FTPStartResult::kSuccessAuth, 0);
- histograms.ExpectBucketCount("Net.FTP.StartResult", FTPStartResult::kFailed,
- 1);
-}
-
-TEST_F(UrlRequestFtpJobTest, HistogramLogFailedInvalidAuthThenSucceed) {
- base::HistogramTester histograms;
- MockURLRequestFtpJobFactory url_request_ftp_job_factory(
- ERR_FAILED, ERR_FAILED, true, {ERR_ACCESS_DENIED, OK});
- TestNetworkDelegate network_delegate;
- TestURLRequestContext context(true);
- context.set_network_delegate(&network_delegate);
- context.set_job_factory(&url_request_ftp_job_factory);
- context.Init();
-
- TestDelegate test_delegate;
- test_delegate.set_credentials(AuthCredentials(u"user", u"pass"));
- std::unique_ptr<URLRequest> r(context.CreateRequest(
- GURL("ftp://example.test/"), RequestPriority::DEFAULT_PRIORITY,
- &test_delegate, TRAFFIC_ANNOTATION_FOR_TESTS));
-
- r->Start();
- test_delegate.RunUntilComplete();
-
- histograms.ExpectBucketCount("Net.FTP.StartResult",
- FTPStartResult::kSuccessNoAuth, 0);
- histograms.ExpectBucketCount("Net.FTP.StartResult",
- FTPStartResult::kSuccessAuth, 1);
- histograms.ExpectBucketCount("Net.FTP.StartResult", FTPStartResult::kFailed,
- 1);
-}
-} // namespace
-} // namespace net
diff --git a/chromium/net/url_request/url_request_http_job.cc b/chromium/net/url_request/url_request_http_job.cc
index a6cd1ef45ab..ef4933bc2cc 100644
--- a/chromium/net/url_request/url_request_http_job.cc
+++ b/chromium/net/url_request/url_request_http_job.cc
@@ -6,12 +6,14 @@
#include <algorithm>
#include <iterator>
+#include <memory>
#include <utility>
#include <vector>
#include "base/base_switches.h"
#include "base/bind.h"
#include "base/callback_helpers.h"
+#include "base/check_op.h"
#include "base/command_line.h"
#include "base/compiler_specific.h"
#include "base/file_version_info.h"
@@ -55,6 +57,7 @@
#include "net/filter/gzip_source_stream.h"
#include "net/filter/source_stream.h"
#include "net/http/http_content_disposition.h"
+#include "net/http/http_log_util.h"
#include "net/http/http_network_session.h"
#include "net/http/http_request_headers.h"
#include "net/http/http_response_headers.h"
@@ -63,6 +66,7 @@
#include "net/http/http_transaction.h"
#include "net/http/http_transaction_factory.h"
#include "net/http/http_util.h"
+#include "net/http/transport_security_state.h"
#include "net/log/net_log.h"
#include "net/log/net_log_event_type.h"
#include "net/log/net_log_values.h"
@@ -74,6 +78,7 @@
#include "net/ssl/ssl_cert_request_info.h"
#include "net/ssl/ssl_config_service.h"
#include "net/ssl/ssl_connection_status_flags.h"
+#include "net/url_request/redirect_util.h"
#include "net/url_request/url_request.h"
#include "net/url_request/url_request_context.h"
#include "net/url_request/url_request_error_job.h"
@@ -82,7 +87,9 @@
#include "net/url_request/url_request_throttler_manager.h"
#include "net/url_request/websocket_handshake_userdata_key.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
+#include "url/gurl.h"
#include "url/origin.h"
+#include "url/url_constants.h"
#if defined(OS_ANDROID)
#include "net/android/network_library.h"
@@ -186,6 +193,22 @@ bool IsTLS13OverTCP(const net::HttpResponseInfo& response_info) {
net::SSL_CONNECTION_VERSION_TLS1_3;
}
+GURL UpgradeSchemeToCryptographic(const GURL& insecure_url) {
+ DCHECK(!insecure_url.SchemeIsCryptographic());
+ DCHECK(insecure_url.SchemeIs(url::kHttpScheme) ||
+ insecure_url.SchemeIs(url::kWsScheme));
+
+ GURL::Replacements replacements;
+ replacements.SetSchemeStr(insecure_url.SchemeIs(url::kHttpScheme)
+ ? url::kHttpsScheme
+ : url::kWssScheme);
+
+ GURL secure_url = insecure_url.ReplaceComponents(replacements);
+ DCHECK(secure_url.SchemeIsCryptographic());
+
+ return secure_url;
+}
+
} // namespace
namespace net {
@@ -204,13 +227,10 @@ std::unique_ptr<URLRequestJob> URLRequestHttpJob::Create(URLRequest* request) {
TransportSecurityState* hsts =
request->context()->transport_security_state();
if (hsts && hsts->ShouldUpgradeToSSL(url.host())) {
- GURL::Replacements replacements;
- replacements.SetSchemeStr(
- url.SchemeIs(url::kHttpScheme) ? url::kHttpsScheme : url::kWssScheme);
return std::make_unique<URLRequestRedirectJob>(
- request, url.ReplaceComponents(replacements),
+ request, UpgradeSchemeToCryptographic(url),
// Use status code 307 to preserve the method, so POST requests work.
- URLRequestRedirectJob::REDIRECT_307_TEMPORARY_REDIRECT, "HSTS");
+ RedirectUtil::ResponseCode::REDIRECT_307_TEMPORARY_REDIRECT, "HSTS");
}
#if defined(OS_ANDROID)
@@ -346,7 +366,12 @@ void URLRequestHttpJob::NotifyHeadersComplete() {
DCHECK_EQ(0, num_cookie_lines_left_);
DCHECK(request_->maybe_stored_cookies().empty());
- response_info_ = transaction_->GetResponseInfo();
+ if (override_response_info_) {
+ DCHECK(!transaction_);
+ response_info_ = override_response_info_.get();
+ } else {
+ response_info_ = transaction_->GetResponseInfo();
+ }
if (!response_info_->was_cached && throttling_entry_.get())
throttling_entry_->UpdateWithResponse(GetResponseCode());
@@ -362,7 +387,7 @@ void URLRequestHttpJob::NotifyHeadersComplete() {
// The HTTP transaction may be restarted several times for the purposes
// of sending authorization information. Each time it restarts, we get
// notified of the headers completion so that we can update the cookie store.
- if (transaction_->IsReadyToRestartForAuth()) {
+ if (transaction_ && transaction_->IsReadyToRestartForAuth()) {
// TODO(battre): This breaks the webrequest API for
// URLRequestTestHTTP.BasicAuthWithCookies
// where OnBeforeStartTransaction -> OnStartTransaction ->
@@ -390,6 +415,8 @@ void URLRequestHttpJob::DestroyTransaction() {
}
void URLRequestHttpJob::StartTransaction() {
+ DCHECK(!override_response_info_);
+
NetworkDelegate* network_delegate = request()->network_delegate();
if (network_delegate) {
OnCallToDelegate(
@@ -594,8 +621,13 @@ void URLRequestHttpJob::AddCookieHeaderAndStart() {
request_site, request_->isolation_info(), delegate,
request_->force_ignore_top_frame_party_for_cookies()));
+ absl::optional<CookiePartitionKey> cookie_partition_key =
+ CookiePartitionKey::FromNetworkIsolationKey(
+ request_->isolation_info().network_isolation_key());
+
cookie_store->GetCookieListWithOptionsAsync(
request_->url(), options,
+ CookiePartitionKeychain::FromOptional(cookie_partition_key),
base::BindOnce(&URLRequestHttpJob::SetCookieHeaderAndStart,
weak_factory_.GetWeakPtr(), options));
} else {
@@ -965,6 +997,30 @@ void URLRequestHttpJob::OnStartCompleted(int result) {
} else if (result == ERR_SSL_CLIENT_AUTH_CERT_NEEDED) {
NotifyCertificateRequested(
transaction_->GetResponseInfo()->cert_request_info.get());
+ } else if (result == ERR_DNS_NAME_HTTPS_ONLY) {
+ // If DNS indicated the name is HTTPS-only, synthesize a redirect to either
+ // HTTPS or WSS.
+ DCHECK(features::kUseDnsHttpsSvcbHttpUpgrade.Get());
+ DCHECK(!request_->url().SchemeIsCryptographic());
+
+ base::Time request_time =
+ transaction_ && transaction_->GetResponseInfo()
+ ? transaction_->GetResponseInfo()->request_time
+ : base::Time::Now();
+ DestroyTransaction();
+ override_response_info_ = std::make_unique<HttpResponseInfo>();
+ override_response_info_->request_time = request_time;
+
+ override_response_info_->headers = RedirectUtil::SynthesizeRedirectHeaders(
+ UpgradeSchemeToCryptographic(request_->url()),
+ RedirectUtil::ResponseCode::REDIRECT_307_TEMPORARY_REDIRECT, "DNS",
+ request_->extra_request_headers());
+ NetLogResponseHeaders(
+ request_->net_log(),
+ NetLogEventType::URL_REQUEST_FAKE_RESPONSE_HEADERS_CREATED,
+ override_response_info_->headers.get());
+
+ NotifyHeadersComplete();
} else {
// Even on an error, there may be useful information in the response
// info (e.g. whether there's a cached copy).
@@ -1001,6 +1057,8 @@ void URLRequestHttpJob::OnReadCompleted(int result) {
void URLRequestHttpJob::RestartTransactionWithAuth(
const AuthCredentials& credentials) {
+ DCHECK(!override_response_info_);
+
auth_credentials_ = credentials;
// These will be reset in OnStartCompleted.
@@ -1025,13 +1083,15 @@ void URLRequestHttpJob::RestartTransactionWithAuth(
}
void URLRequestHttpJob::SetUpload(UploadDataStream* upload) {
- DCHECK(!transaction_.get()) << "cannot change once started";
+ DCHECK(!transaction_.get() && !override_response_info_)
+ << "cannot change once started";
request_info_.upload_data_stream = upload;
}
void URLRequestHttpJob::SetExtraRequestHeaders(
const HttpRequestHeaders& headers) {
- DCHECK(!transaction_.get()) << "cannot change once started";
+ DCHECK(!transaction_.get() && !override_response_info_)
+ << "cannot change once started";
request_info_.extra_headers.CopyFrom(headers);
}
@@ -1041,7 +1101,7 @@ LoadState URLRequestHttpJob::GetLoadState() const {
}
bool URLRequestHttpJob::GetMimeType(std::string* mime_type) const {
- DCHECK(transaction_.get());
+ DCHECK(transaction_.get() || override_response_info_);
if (!response_info_)
return false;
@@ -1053,7 +1113,7 @@ bool URLRequestHttpJob::GetMimeType(std::string* mime_type) const {
}
bool URLRequestHttpJob::GetCharset(std::string* charset) {
- DCHECK(transaction_.get());
+ DCHECK(transaction_.get() || override_response_info_);
if (!response_info_)
return false;
@@ -1062,6 +1122,12 @@ bool URLRequestHttpJob::GetCharset(std::string* charset) {
}
void URLRequestHttpJob::GetResponseInfo(HttpResponseInfo* info) {
+ if (override_response_info_) {
+ DCHECK(!transaction_.get());
+ *info = *override_response_info_;
+ return;
+ }
+
if (response_info_) {
DCHECK(transaction_.get());
@@ -1112,10 +1178,10 @@ std::unique_ptr<SourceStream> URLRequestHttpJob::SetUpSourceStream() {
std::unique_ptr<SourceStream> upstream = URLRequestJob::SetUpSourceStream();
HttpResponseHeaders* headers = GetResponseHeaders();
- std::string type;
std::vector<SourceStream::SourceType> types;
size_t iter = 0;
- while (headers->EnumerateHeader(&iter, "Content-Encoding", &type)) {
+ for (std::string type;
+ headers->EnumerateHeader(&iter, "Content-Encoding", &type);) {
SourceStream::SourceType source_type =
FilterSourceStream::ParseEncodingType(type);
switch (source_type) {
@@ -1376,6 +1442,7 @@ void URLRequestHttpJob::DoneReading() {
void URLRequestHttpJob::DoneReadingRedirectResponse() {
if (transaction_) {
+ DCHECK(!override_response_info_);
if (transaction_->GetResponseInfo()->headers->IsRedirect(nullptr)) {
// If the original headers indicate a redirect, go ahead and cache the
// response, even if the |override_response_headers_| are a redirect to
@@ -1554,8 +1621,14 @@ void URLRequestHttpJob::DoneWithRequest(CompletionCause reason) {
}
HttpResponseHeaders* URLRequestHttpJob::GetResponseHeaders() const {
+ if (override_response_info_) {
+ DCHECK(!transaction_.get());
+ return override_response_info_->headers.get();
+ }
+
DCHECK(transaction_.get());
DCHECK(transaction_->GetResponseInfo());
+
return override_response_headers_.get() ?
override_response_headers_.get() :
transaction_->GetResponseInfo()->headers.get();
diff --git a/chromium/net/url_request/url_request_http_job.h b/chromium/net/url_request/url_request_http_job.h
index 54afa5c1dbc..0873f0fdd62 100644
--- a/chromium/net/url_request/url_request_http_job.h
+++ b/chromium/net/url_request/url_request_http_job.h
@@ -49,6 +49,9 @@ class NET_EXPORT_PRIVATE URLRequestHttpJob : public URLRequestJob {
// them. Never returns nullptr.
static std::unique_ptr<URLRequestJob> Create(URLRequest* request);
+ URLRequestHttpJob(const URLRequestHttpJob&) = delete;
+ URLRequestHttpJob& operator=(const URLRequestHttpJob&) = delete;
+
void SetRequestHeadersCallback(RequestHeadersCallback callback) override;
void SetEarlyResponseHeadersCallback(
ResponseHeadersCallback callback) override;
@@ -199,7 +202,8 @@ class NET_EXPORT_PRIVATE URLRequestHttpJob : public URLRequestJob {
bool ShouldFixMismatchedContentLength(int rv) const;
// Returns the effective response headers, considering that they may be
- // overridden by |override_response_headers_|.
+ // overridden by `override_response_headers_` or
+ // `override_response_info_::headers`.
HttpResponseHeaders* GetResponseHeaders() const;
RequestPriority priority_;
@@ -207,6 +211,11 @@ class NET_EXPORT_PRIVATE URLRequestHttpJob : public URLRequestJob {
HttpRequestInfo request_info_;
const HttpResponseInfo* response_info_;
+ // Used for any logic, e.g. DNS-based scheme upgrade, that needs to synthesize
+ // response info to override the real response info. Transaction should be
+ // cleared before setting.
+ std::unique_ptr<HttpResponseInfo> override_response_info_;
+
// Auth states for proxy and origin server.
AuthState proxy_auth_state_;
AuthState server_auth_state_;
@@ -267,8 +276,6 @@ class NET_EXPORT_PRIVATE URLRequestHttpJob : public URLRequestJob {
ResponseHeadersCallback response_headers_callback_;
base::WeakPtrFactory<URLRequestHttpJob> weak_factory_{this};
-
- DISALLOW_COPY_AND_ASSIGN(URLRequestHttpJob);
};
} // namespace net
diff --git a/chromium/net/url_request/url_request_http_job_unittest.cc b/chromium/net/url_request/url_request_http_job_unittest.cc
index cea14f3dd07..0113bd20495 100644
--- a/chromium/net/url_request/url_request_http_job_unittest.cc
+++ b/chromium/net/url_request/url_request_http_job_unittest.cc
@@ -27,6 +27,8 @@
#include "net/base/features.h"
#include "net/base/isolation_info.h"
#include "net/base/network_isolation_key.h"
+#include "net/base/proxy_server.h"
+#include "net/base/proxy_string_util.h"
#include "net/base/request_priority.h"
#include "net/cert/ct_policy_status.h"
#include "net/cookies/canonical_cookie_test_helpers.h"
@@ -35,6 +37,7 @@
#include "net/cookies/cookie_store_test_helpers.h"
#include "net/http/http_transaction_factory.h"
#include "net/http/http_transaction_test_util.h"
+#include "net/http/transport_security_state.h"
#include "net/log/net_log_event_type.h"
#include "net/log/test_net_log.h"
#include "net/log/test_net_log_util.h"
@@ -104,6 +107,9 @@ class TestURLRequestHttpJob : public URLRequestHttpJob {
request->context()->http_user_agent_settings()),
use_null_source_stream_(false) {}
+ TestURLRequestHttpJob(const TestURLRequestHttpJob&) = delete;
+ TestURLRequestHttpJob& operator=(const TestURLRequestHttpJob&) = delete;
+
~TestURLRequestHttpJob() override = default;
// URLRequestJob implementation:
@@ -124,8 +130,6 @@ class TestURLRequestHttpJob : public URLRequestHttpJob {
private:
bool use_null_source_stream_;
-
- DISALLOW_COPY_AND_ASSIGN(TestURLRequestHttpJob);
};
class URLRequestHttpJobSetUpSourceTest : public TestWithTaskEnvironment {
@@ -205,13 +209,14 @@ class URLRequestHttpJobWithProxy {
context_->Init();
}
+ URLRequestHttpJobWithProxy(const URLRequestHttpJobWithProxy&) = delete;
+ URLRequestHttpJobWithProxy& operator=(const URLRequestHttpJobWithProxy&) =
+ delete;
+
MockClientSocketFactory socket_factory_;
TestNetworkDelegate network_delegate_;
std::unique_ptr<ProxyResolutionService> proxy_resolution_service_;
std::unique_ptr<TestURLRequestContext> context_;
-
- private:
- DISALLOW_COPY_AND_ASSIGN(URLRequestHttpJobWithProxy);
};
// Tests that when proxy is not used, the proxy server is set correctly on the
@@ -254,11 +259,12 @@ TEST_F(URLRequestHttpJobWithProxyTest, TestSuccessfulWithOneProxy) {
"Accept-Language: en-us,fr\r\n\r\n";
const ProxyServer proxy_server =
- ProxyServer::FromURI("http://origin.net:80", ProxyServer::SCHEME_HTTP);
+ ProxyUriToProxyServer("http://origin.net:80", ProxyServer::SCHEME_HTTP);
std::unique_ptr<ProxyResolutionService> proxy_resolution_service =
ConfiguredProxyResolutionService::CreateFixedFromPacResult(
- proxy_server.ToPacString(), TRAFFIC_ANNOTATION_FOR_TESTS);
+ ProxyServerToPacResultElement(proxy_server),
+ TRAFFIC_ANNOTATION_FOR_TESTS);
MockWrite writes[] = {MockWrite(kSimpleProxyGetMockWrite)};
MockRead reads[] = {MockRead(SYNCHRONOUS, ERR_CONNECTION_RESET)};
@@ -293,14 +299,13 @@ TEST_F(URLRequestHttpJobWithProxyTest, TestSuccessfulWithOneProxy) {
TEST_F(URLRequestHttpJobWithProxyTest,
TestContentLengthSuccessfulRequestWithTwoProxies) {
const ProxyServer proxy_server =
- ProxyServer::FromURI("http://origin.net:80", ProxyServer::SCHEME_HTTP);
+ ProxyUriToProxyServer("http://origin.net:80", ProxyServer::SCHEME_HTTP);
// Connection to |proxy_server| would fail. Request should be fetched over
// DIRECT.
std::unique_ptr<ProxyResolutionService> proxy_resolution_service =
ConfiguredProxyResolutionService::CreateFixedFromPacResult(
- proxy_server.ToPacString() + "; " +
- ProxyServer::Direct().ToPacString(),
+ ProxyServerToPacResultElement(proxy_server) + "; DIRECT",
TRAFFIC_ANNOTATION_FOR_TESTS);
MockWrite writes[] = {MockWrite(kSimpleGetMockWrite)};
@@ -1238,8 +1243,7 @@ TEST_F(URLRequestHttpJobTest, SetTransactionPriority) {
TEST_F(URLRequestHttpJobTest, HSTSInternalRedirectTest) {
// Setup HSTS state.
context_.transport_security_state()->AddHSTS(
- "upgrade.test", base::Time::Now() + base::TimeDelta::FromSeconds(10),
- true);
+ "upgrade.test", base::Time::Now() + base::Seconds(10), true);
ASSERT_TRUE(
context_.transport_security_state()->ShouldUpgradeToSSL("upgrade.test"));
ASSERT_FALSE(context_.transport_security_state()->ShouldUpgradeToSSL(
@@ -1264,10 +1268,17 @@ TEST_F(URLRequestHttpJobTest, HSTSInternalRedirectTest) {
for (const auto& test : cases) {
SCOPED_TRACE(test.url);
+
+ GURL url = GURL(test.url);
+ // This is needed to bypass logic that rejects using URLRequests directly
+ // for WebSocket requests.
+ bool is_for_websockets = url.SchemeIsWSOrWSS();
+
TestDelegate d;
TestNetworkDelegate network_delegate;
std::unique_ptr<URLRequest> r(context_.CreateRequest(
- GURL(test.url), DEFAULT_PRIORITY, &d, TRAFFIC_ANNOTATION_FOR_TESTS));
+ url, DEFAULT_PRIORITY, &d, TRAFFIC_ANNOTATION_FOR_TESTS,
+ is_for_websockets));
net_log_.Clear();
r->Start();
@@ -1298,7 +1309,7 @@ TEST_F(URLRequestHttpJobTest, HSTSInternalRedirectCallback) {
TestURLRequestContext context;
context.transport_security_state()->AddHSTS(
- "127.0.0.1", base::Time::Now() + base::TimeDelta::FromSeconds(10), true);
+ "127.0.0.1", base::Time::Now() + base::Seconds(10), true);
ASSERT_TRUE(
context.transport_security_state()->ShouldUpgradeToSSL("127.0.0.1"));
@@ -1587,7 +1598,8 @@ class URLRequestHttpJobWebSocketTest : public TestWithTaskEnvironment {
context_.Init();
req_ =
context_.CreateRequest(GURL("ws://www.example.org"), DEFAULT_PRIORITY,
- &delegate_, TRAFFIC_ANNOTATION_FOR_TESTS);
+ &delegate_, TRAFFIC_ANNOTATION_FOR_TESTS,
+ /*is_for_websockets=*/true);
}
// A Network Delegate is required for the WebSocketHandshakeStreamBase
@@ -1935,50 +1947,59 @@ INSTANTIATE_TEST_SUITE_P(/* no label */,
TEST_P(PartitionedCookiesURLRequestHttpJobTest, SetPartitionedCookie) {
EmbeddedTestServer https_test(EmbeddedTestServer::TYPE_HTTPS);
- const url::Origin kTopFrameOrigin =
- url::Origin::Create(GURL("https://www.toplevelsite.com"));
- const IsolationInfo kTestIsolationInfo =
- IsolationInfo::CreateForInternalRequest(kTopFrameOrigin);
-
https_test.AddDefaultHandlers(base::FilePath());
ASSERT_TRUE(https_test.Start());
- TestURLRequestContext context;
+ TestURLRequestContext context;
CookieMonster cookie_monster(nullptr, nullptr);
context.set_cookie_store(&cookie_monster);
- GURL test_url = https_test.GetURL(
- "/set-cookie?__Host-foo=bar;SameSite=None;Secure;Path=/;Partitioned;");
-
TestDelegate delegate;
- std::unique_ptr<URLRequest> request = context.CreateRequest(
- test_url, DEFAULT_PRIORITY, &delegate, TRAFFIC_ANNOTATION_FOR_TESTS);
+ std::unique_ptr<URLRequest> req(context.CreateRequest(
+ https_test.GetURL("/set-cookie?__Host-foo=bar;SameSite=None;Secure;Path=/"
+ ";Partitioned;"),
+ DEFAULT_PRIORITY, &delegate, TRAFFIC_ANNOTATION_FOR_TESTS));
- request->set_isolation_info(kTestIsolationInfo);
- request->Start();
- ASSERT_TRUE(request->is_pending());
+ const url::Origin kTopFrameOrigin =
+ url::Origin::Create(GURL("https://www.toplevelsite.com"));
+ const IsolationInfo kTestIsolationInfo =
+ IsolationInfo::CreateForInternalRequest(kTopFrameOrigin);
+
+ req->set_isolation_info(kTestIsolationInfo);
+ req->Start();
+ ASSERT_TRUE(req->is_pending());
delegate.RunUntilComplete();
- base::RunLoop run_loop;
- bool partitioned_cookies_enabled = PartitionedCookiesEnabled();
- cookie_monster.GetAllCookiesAsync(base::BindLambdaForTesting(
- [&partitioned_cookies_enabled, &run_loop](const CookieList& cookies) {
- EXPECT_EQ(1u, cookies.size());
- EXPECT_EQ(partitioned_cookies_enabled, cookies[0].IsPartitioned());
- if (partitioned_cookies_enabled) {
- EXPECT_EQ(CookiePartitionKey::FromURLForTesting(
- GURL("https://toplevelsite.com")),
- cookies[0].PartitionKey().value());
- } else {
- EXPECT_FALSE(cookies[0].PartitionKey());
- }
- run_loop.Quit();
- }));
- run_loop.Run();
-
- // TODO(crbug.com/1225444) Test that the cookie is available in a cross-site
- // context on a different top-level site only when partitioned cookies are
- // disabled.
+ { // Test request from the same top-level site.
+ TestDelegate delegate;
+ std::unique_ptr<URLRequest> req(context.CreateRequest(
+ https_test.GetURL("/echoheader?Cookie"), DEFAULT_PRIORITY, &delegate,
+ TRAFFIC_ANNOTATION_FOR_TESTS));
+ req->set_isolation_info(kTestIsolationInfo);
+ req->Start();
+ delegate.RunUntilComplete();
+ EXPECT_EQ("__Host-foo=bar", delegate.data_received());
+ }
+
+ { // Test request from a different top-level site.
+ const url::Origin kOtherTopFrameOrigin =
+ url::Origin::Create(GURL("https://www.anothertoplevelsite.com"));
+ const IsolationInfo kOtherTestIsolationInfo =
+ IsolationInfo::CreateForInternalRequest(kOtherTopFrameOrigin);
+
+ TestDelegate delegate;
+ std::unique_ptr<URLRequest> req(context.CreateRequest(
+ https_test.GetURL("/echoheader?Cookie"), DEFAULT_PRIORITY, &delegate,
+ TRAFFIC_ANNOTATION_FOR_TESTS));
+ req->set_isolation_info(kOtherTestIsolationInfo);
+ req->Start();
+ delegate.RunUntilComplete();
+ if (PartitionedCookiesEnabled()) {
+ EXPECT_EQ("None", delegate.data_received());
+ } else {
+ EXPECT_EQ("__Host-foo=bar", delegate.data_received());
+ }
+ }
}
} // namespace net
diff --git a/chromium/net/url_request/url_request_interceptor.h b/chromium/net/url_request/url_request_interceptor.h
index 0ce071f3747..99daa05c88b 100644
--- a/chromium/net/url_request/url_request_interceptor.h
+++ b/chromium/net/url_request/url_request_interceptor.h
@@ -24,6 +24,10 @@ class URLRequestJob;
class NET_EXPORT URLRequestInterceptor {
public:
URLRequestInterceptor();
+
+ URLRequestInterceptor(const URLRequestInterceptor&) = delete;
+ URLRequestInterceptor& operator=(const URLRequestInterceptor&) = delete;
+
virtual ~URLRequestInterceptor();
// Returns a URLRequestJob to handle |request|, if the interceptor wants to
@@ -31,9 +35,6 @@ class NET_EXPORT URLRequestInterceptor {
// Otherwise, returns nullptr.
virtual std::unique_ptr<URLRequestJob> MaybeInterceptRequest(
URLRequest* request) const = 0;
-
- private:
- DISALLOW_COPY_AND_ASSIGN(URLRequestInterceptor);
};
} // namespace net
diff --git a/chromium/net/url_request/url_request_job.cc b/chromium/net/url_request/url_request_job.cc
index b2458b80375..9ac20ba8cae 100644
--- a/chromium/net/url_request/url_request_job.cc
+++ b/chromium/net/url_request/url_request_job.cc
@@ -23,11 +23,13 @@
#include "net/base/net_errors.h"
#include "net/base/network_delegate.h"
#include "net/base/proxy_server.h"
+#include "net/cert/x509_certificate.h"
#include "net/log/net_log.h"
#include "net/log/net_log_capture_mode.h"
#include "net/log/net_log_event_type.h"
#include "net/log/net_log_with_source.h"
#include "net/nqe/network_quality_estimator.h"
+#include "net/ssl/ssl_private_key.h"
#include "net/url_request/redirect_util.h"
#include "net/url_request/url_request_context.h"
@@ -55,6 +57,10 @@ class URLRequestJob::URLRequestJobSourceStream : public SourceStream {
DCHECK(job_);
}
+ URLRequestJobSourceStream(const URLRequestJobSourceStream&) = delete;
+ URLRequestJobSourceStream& operator=(const URLRequestJobSourceStream&) =
+ delete;
+
~URLRequestJobSourceStream() override = default;
// SourceStream implementation:
@@ -75,8 +81,6 @@ class URLRequestJob::URLRequestJobSourceStream : public SourceStream {
// indirectly owns |this|. Therefore, |job_| will not be destroyed when |this|
// is alive.
URLRequestJob* const job_;
-
- DISALLOW_COPY_AND_ASSIGN(URLRequestJobSourceStream);
};
URLRequestJob::URLRequestJob(URLRequest* request)
diff --git a/chromium/net/url_request/url_request_job.h b/chromium/net/url_request/url_request_job.h
index 7cd566ddaf1..d0721381cbd 100644
--- a/chromium/net/url_request/url_request_job.h
+++ b/chromium/net/url_request/url_request_job.h
@@ -52,6 +52,10 @@ class X509Certificate;
class NET_EXPORT URLRequestJob {
public:
explicit URLRequestJob(URLRequest* request);
+
+ URLRequestJob(const URLRequestJob&) = delete;
+ URLRequestJob& operator=(const URLRequestJob&) = delete;
+
virtual ~URLRequestJob();
// Returns the request that owns this job.
@@ -447,8 +451,6 @@ class NET_EXPORT URLRequestJob {
CompletionOnceCallback read_raw_callback_;
base::WeakPtrFactory<URLRequestJob> weak_factory_{this};
-
- DISALLOW_COPY_AND_ASSIGN(URLRequestJob);
};
} // namespace net
diff --git a/chromium/net/url_request/url_request_job_factory.cc b/chromium/net/url_request/url_request_job_factory.cc
index 8ff76c530df..079187d608d 100644
--- a/chromium/net/url_request/url_request_job_factory.cc
+++ b/chromium/net/url_request/url_request_job_factory.cc
@@ -20,19 +20,30 @@ namespace {
URLRequestInterceptor* g_interceptor_for_testing = nullptr;
-// TODO(mmenke): Once FTP support is removed, look into removing this class, and
-// URLRequestJobFactory::ProtocolHandlers completely. The only other subclass is
-// iOS-only.
+// TODO(mmenke): Look into removing this class and
+// URLRequestJobFactory::ProtocolHandlers completely. The only other subclass
+// is iOS-only.
class HttpProtocolHandler : public URLRequestJobFactory::ProtocolHandler {
public:
- HttpProtocolHandler() = default;
+ // URLRequest::is_for_websockets() must match `is_for_websockets`, or requests
+ // will be failed. This is so that attempts to fetch WebSockets requests
+ // fails, and attempts to use HTTP URLs for WebSockets also fail.
+ explicit HttpProtocolHandler(bool is_for_websockets)
+ : is_for_websockets_(is_for_websockets) {}
+
HttpProtocolHandler(const HttpProtocolHandler&) = delete;
HttpProtocolHandler& operator=(const HttpProtocolHandler&) = delete;
~HttpProtocolHandler() override = default;
std::unique_ptr<URLRequestJob> CreateJob(URLRequest* request) const override {
+ if (request->is_for_websockets() != is_for_websockets_) {
+ return std::make_unique<URLRequestErrorJob>(request,
+ ERR_UNKNOWN_URL_SCHEME);
+ }
return URLRequestHttpJob::Create(request);
}
+
+ const bool is_for_websockets_;
};
} // namespace
@@ -45,12 +56,15 @@ bool URLRequestJobFactory::ProtocolHandler::IsSafeRedirectTarget(
}
URLRequestJobFactory::URLRequestJobFactory() {
- SetProtocolHandler(url::kHttpScheme, std::make_unique<HttpProtocolHandler>());
- SetProtocolHandler(url::kHttpsScheme,
- std::make_unique<HttpProtocolHandler>());
+ SetProtocolHandler(url::kHttpScheme, std::make_unique<HttpProtocolHandler>(
+ /*is_for_websockets=*/false));
+ SetProtocolHandler(url::kHttpsScheme, std::make_unique<HttpProtocolHandler>(
+ /*is_for_websockets=*/false));
#if BUILDFLAG(ENABLE_WEBSOCKETS)
- SetProtocolHandler(url::kWsScheme, std::make_unique<HttpProtocolHandler>());
- SetProtocolHandler(url::kWssScheme, std::make_unique<HttpProtocolHandler>());
+ SetProtocolHandler(url::kWsScheme, std::make_unique<HttpProtocolHandler>(
+ /*is_for_websockets=*/true));
+ SetProtocolHandler(url::kWssScheme, std::make_unique<HttpProtocolHandler>(
+ /*is_for_websockets=*/true));
#endif // BUILDFLAG(ENABLE_WEBSOCKETS)
}
diff --git a/chromium/net/url_request/url_request_job_factory.h b/chromium/net/url_request/url_request_job_factory.h
index 9d31c6cbd50..7809cdf118a 100644
--- a/chromium/net/url_request/url_request_job_factory.h
+++ b/chromium/net/url_request/url_request_job_factory.h
@@ -41,6 +41,10 @@ class NET_EXPORT URLRequestJobFactory {
};
URLRequestJobFactory();
+
+ URLRequestJobFactory(const URLRequestJobFactory&) = delete;
+ URLRequestJobFactory& operator=(const URLRequestJobFactory&) = delete;
+
virtual ~URLRequestJobFactory();
// Sets the ProtocolHandler for a scheme. Returns true on success, false on
@@ -77,8 +81,6 @@ class NET_EXPORT URLRequestJobFactory {
static void SetInterceptorForTesting(URLRequestInterceptor* interceptor);
ProtocolHandlerMap protocol_handler_map_;
-
- DISALLOW_COPY_AND_ASSIGN(URLRequestJobFactory);
};
} // namespace net
diff --git a/chromium/net/url_request/url_request_quic_unittest.cc b/chromium/net/url_request/url_request_quic_unittest.cc
index 136c94fa1b8..46f75a485d6 100644
--- a/chromium/net/url_request/url_request_quic_unittest.cc
+++ b/chromium/net/url_request/url_request_quic_unittest.cc
@@ -24,6 +24,7 @@
#include "net/cert/mock_cert_verifier.h"
#include "net/dns/mapped_host_resolver.h"
#include "net/dns/mock_host_resolver.h"
+#include "net/http/transport_security_state.h"
#include "net/log/net_log_event_type.h"
#include "net/log/test_net_log.h"
#include "net/log/test_net_log_util.h"
@@ -184,7 +185,6 @@ class URLRequestQuicTest
static const NetLogSource FindPushUrlSource(
const std::vector<NetLogEntry>& entries,
const std::string& push_url) {
- std::string entry_push_url;
for (const auto& entry : entries) {
if (entry.phase == NetLogEventPhase::BEGIN &&
entry.source.type ==
@@ -300,6 +300,10 @@ class CheckLoadTimingDelegate : public TestDelegate {
public:
CheckLoadTimingDelegate(bool session_reused)
: session_reused_(session_reused) {}
+
+ CheckLoadTimingDelegate(const CheckLoadTimingDelegate&) = delete;
+ CheckLoadTimingDelegate& operator=(const CheckLoadTimingDelegate&) = delete;
+
void OnResponseStarted(URLRequest* request, int error) override {
TestDelegate::OnResponseStarted(request, error);
LoadTimingInfo load_timing_info;
@@ -333,8 +337,6 @@ class CheckLoadTimingDelegate : public TestDelegate {
}
bool session_reused_;
-
- DISALLOW_COPY_AND_ASSIGN(CheckLoadTimingDelegate);
};
// A TestNetworkDelegate that invokes |all_requests_completed_callback| when
@@ -348,6 +350,11 @@ class WaitForCompletionNetworkDelegate : public net::TestNetworkDelegate {
std::move(all_requests_completed_callback)),
num_expected_requests_(num_expected_requests) {}
+ WaitForCompletionNetworkDelegate(const WaitForCompletionNetworkDelegate&) =
+ delete;
+ WaitForCompletionNetworkDelegate& operator=(
+ const WaitForCompletionNetworkDelegate&) = delete;
+
void OnCompleted(URLRequest* request, bool started, int net_error) override {
net::TestNetworkDelegate::OnCompleted(request, started, net_error);
num_expected_requests_--;
@@ -358,7 +365,6 @@ class WaitForCompletionNetworkDelegate : public net::TestNetworkDelegate {
private:
base::OnceClosure all_requests_completed_callback_;
size_t num_expected_requests_;
- DISALLOW_COPY_AND_ASSIGN(WaitForCompletionNetworkDelegate);
};
} // namespace
@@ -482,8 +488,8 @@ TEST_P(URLRequestQuicTest, ExpectCT) {
GURL report_uri("https://report.test/");
IsolationInfo isolation_info = IsolationInfo::CreateTransient();
transport_security_state()->AddExpectCT(
- kTestServerHost, base::Time::Now() + base::TimeDelta::FromDays(1),
- true /* enforce */, report_uri, isolation_info.network_isolation_key());
+ kTestServerHost, base::Time::Now() + base::Days(1), true /* enforce */,
+ report_uri, isolation_info.network_isolation_key());
base::RunLoop run_loop;
TestDelegate delegate;
diff --git a/chromium/net/url_request/url_request_redirect_job.cc b/chromium/net/url_request/url_request_redirect_job.cc
index d43060b4ce4..fb3929926ff 100644
--- a/chromium/net/url_request/url_request_redirect_job.cc
+++ b/chromium/net/url_request/url_request_redirect_job.cc
@@ -19,19 +19,20 @@
#include "net/http/http_log_util.h"
#include "net/http/http_raw_request_headers.h"
#include "net/http/http_response_headers.h"
-#include "net/http/http_util.h"
#include "net/log/net_log.h"
#include "net/log/net_log_event_type.h"
#include "net/log/net_log_with_source.h"
+#include "net/url_request/redirect_util.h"
#include "net/url_request/url_request.h"
#include "net/url_request/url_request_job.h"
namespace net {
-URLRequestRedirectJob::URLRequestRedirectJob(URLRequest* request,
- const GURL& redirect_destination,
- ResponseCode response_code,
- const std::string& redirect_reason)
+URLRequestRedirectJob::URLRequestRedirectJob(
+ URLRequest* request,
+ const GURL& redirect_destination,
+ RedirectUtil::ResponseCode response_code,
+ const std::string& redirect_reason)
: URLRequestJob(request),
redirect_destination_(redirect_destination),
response_code_(response_code),
@@ -87,32 +88,9 @@ void URLRequestRedirectJob::StartAsync() {
receive_headers_end_ = base::TimeTicks::Now();
response_time_ = base::Time::Now();
- std::string header_string =
- base::StringPrintf("HTTP/1.1 %i Internal Redirect\n"
- "Location: %s\n"
- "Non-Authoritative-Reason: %s",
- response_code_,
- redirect_destination_.spec().c_str(),
- redirect_reason_.c_str());
-
- std::string http_origin;
const HttpRequestHeaders& request_headers = request_->extra_request_headers();
- if (request_headers.GetHeader("Origin", &http_origin)) {
- // If this redirect is used in a cross-origin request, add CORS headers to
- // make sure that the redirect gets through. Note that the destination URL
- // is still subject to the usual CORS policy, i.e. the resource will only
- // be available to web pages if the server serves the response with the
- // required CORS response headers.
- header_string += base::StringPrintf(
- "\n"
- "Access-Control-Allow-Origin: %s\n"
- "Access-Control-Allow-Credentials: true",
- http_origin.c_str());
- }
-
- fake_headers_ = base::MakeRefCounted<HttpResponseHeaders>(
- HttpUtil::AssembleRawHeaders(header_string));
- DCHECK(fake_headers_->IsRedirect(nullptr));
+ fake_headers_ = RedirectUtil::SynthesizeRedirectHeaders(
+ redirect_destination_, response_code_, redirect_reason_, request_headers);
NetLogResponseHeaders(
request()->net_log(),
diff --git a/chromium/net/url_request/url_request_redirect_job.h b/chromium/net/url_request/url_request_redirect_job.h
index c4aa2df870d..6e185dff74f 100644
--- a/chromium/net/url_request/url_request_redirect_job.h
+++ b/chromium/net/url_request/url_request_redirect_job.h
@@ -12,6 +12,7 @@
#include "net/base/net_export.h"
#include "net/http/http_raw_request_headers.h"
#include "net/http/http_response_info.h"
+#include "net/url_request/redirect_util.h"
#include "net/url_request/url_request_job.h"
class GURL;
@@ -25,20 +26,11 @@ namespace net {
// headers.
class NET_EXPORT URLRequestRedirectJob : public URLRequestJob {
public:
- // Valid status codes for the redirect job. Other 30x codes are theoretically
- // valid, but unused so far. Both 302 and 307 are temporary redirects, with
- // the difference being that 302 converts POSTs to GETs and removes upload
- // data.
- enum ResponseCode {
- REDIRECT_302_FOUND = 302,
- REDIRECT_307_TEMPORARY_REDIRECT = 307,
- };
-
// Constructs a job that redirects to the specified URL. |redirect_reason| is
// logged for debugging purposes, and must not be an empty string.
URLRequestRedirectJob(URLRequest* request,
const GURL& redirect_destination,
- ResponseCode response_code,
+ RedirectUtil::ResponseCode response_code,
const std::string& redirect_reason);
~URLRequestRedirectJob() override;
@@ -55,7 +47,7 @@ class NET_EXPORT URLRequestRedirectJob : public URLRequestJob {
void StartAsync();
const GURL redirect_destination_;
- const ResponseCode response_code_;
+ const RedirectUtil::ResponseCode response_code_;
base::TimeTicks receive_headers_end_;
base::Time response_time_;
std::string redirect_reason_;
diff --git a/chromium/net/url_request/url_request_test_util.cc b/chromium/net/url_request/url_request_test_util.cc
index 0f6c55db0a1..fb5d73df26c 100644
--- a/chromium/net/url_request/url_request_test_util.cc
+++ b/chromium/net/url_request/url_request_test_util.cc
@@ -461,7 +461,8 @@ int TestNetworkDelegate::OnBeforeStartTransaction(
event_order_[req_id] += "OnBeforeStartTransaction\n";
EXPECT_TRUE(next_states_[req_id] & kStageBeforeStartTransaction)
<< event_order_[req_id];
- next_states_[req_id] = kStageHeadersReceived | kStageCompletedError;
+ next_states_[req_id] =
+ kStageHeadersReceived | kStageCompletedError | kStageBeforeRedirect;
before_start_transaction_count_++;
return OK;
}
diff --git a/chromium/net/url_request/url_request_test_util.h b/chromium/net/url_request/url_request_test_util.h
index d96034a2a6a..06185d6fd86 100644
--- a/chromium/net/url_request/url_request_test_util.h
+++ b/chromium/net/url_request/url_request_test_util.h
@@ -31,7 +31,6 @@
#include "net/cookies/cookie_monster.h"
#include "net/cookies/same_party_context.h"
#include "net/disk_cache/disk_cache.h"
-#include "net/ftp/ftp_network_layer.h"
#include "net/http/http_auth_handler_factory.h"
#include "net/http/http_cache.h"
#include "net/http/http_network_layer.h"
diff --git a/chromium/net/url_request/url_request_throttler_entry.cc b/chromium/net/url_request/url_request_throttler_entry.cc
index c50ed002547..ea553701e36 100644
--- a/chromium/net/url_request/url_request_throttler_entry.cc
+++ b/chromium/net/url_request/url_request_throttler_entry.cc
@@ -65,8 +65,7 @@ base::Value NetLogRejectedRequestParams(const std::string* url_id,
URLRequestThrottlerEntry::URLRequestThrottlerEntry(
URLRequestThrottlerManager* manager,
const std::string& url_id)
- : sliding_window_period_(
- base::TimeDelta::FromMilliseconds(kDefaultSlidingWindowPeriodMs)),
+ : sliding_window_period_(base::Milliseconds(kDefaultSlidingWindowPeriodMs)),
max_send_threshold_(kDefaultMaxSendThreshold),
is_backoff_disabled_(false),
backoff_entry_(&backoff_policy_),
@@ -88,8 +87,7 @@ URLRequestThrottlerEntry::URLRequestThrottlerEntry(
double multiply_factor,
double jitter_factor,
int maximum_backoff_ms)
- : sliding_window_period_(
- base::TimeDelta::FromMilliseconds(sliding_window_period_ms)),
+ : sliding_window_period_(base::Milliseconds(sliding_window_period_ms)),
max_send_threshold_(max_send_threshold),
is_backoff_disabled_(false),
backoff_entry_(&backoff_policy_),
diff --git a/chromium/net/url_request/url_request_throttler_entry.h b/chromium/net/url_request/url_request_throttler_entry.h
index 317537f90c9..5bf09679116 100644
--- a/chromium/net/url_request/url_request_throttler_entry.h
+++ b/chromium/net/url_request/url_request_throttler_entry.h
@@ -76,6 +76,9 @@ class NET_EXPORT URLRequestThrottlerEntry
double jitter_factor,
int maximum_backoff_ms);
+ URLRequestThrottlerEntry(const URLRequestThrottlerEntry&) = delete;
+ URLRequestThrottlerEntry& operator=(const URLRequestThrottlerEntry&) = delete;
+
// Used by the manager, returns true if the entry needs to be garbage
// collected.
bool IsEntryOutdated() const;
@@ -150,8 +153,6 @@ class NET_EXPORT URLRequestThrottlerEntry
std::string url_id_;
NetLogWithSource net_log_;
-
- DISALLOW_COPY_AND_ASSIGN(URLRequestThrottlerEntry);
};
} // namespace net
diff --git a/chromium/net/url_request/url_request_throttler_entry_interface.h b/chromium/net/url_request/url_request_throttler_entry_interface.h
index 03160b7db80..ec2bcd2f6ae 100644
--- a/chromium/net/url_request/url_request_throttler_entry_interface.h
+++ b/chromium/net/url_request/url_request_throttler_entry_interface.h
@@ -22,6 +22,11 @@ class NET_EXPORT URLRequestThrottlerEntryInterface
public:
URLRequestThrottlerEntryInterface() {}
+ URLRequestThrottlerEntryInterface(const URLRequestThrottlerEntryInterface&) =
+ delete;
+ URLRequestThrottlerEntryInterface& operator=(
+ const URLRequestThrottlerEntryInterface&) = delete;
+
// Returns true when we have encountered server errors and are doing
// exponential back-off, unless the request has load flags that mean
// it is likely to be user-initiated.
@@ -61,7 +66,6 @@ class NET_EXPORT URLRequestThrottlerEntryInterface
private:
friend class base::RefCounted<URLRequestThrottlerEntryInterface>;
- DISALLOW_COPY_AND_ASSIGN(URLRequestThrottlerEntryInterface);
};
} // namespace net
diff --git a/chromium/net/url_request/url_request_throttler_manager.h b/chromium/net/url_request/url_request_throttler_manager.h
index 308a472614a..4f523827b1e 100644
--- a/chromium/net/url_request/url_request_throttler_manager.h
+++ b/chromium/net/url_request/url_request_throttler_manager.h
@@ -37,6 +37,11 @@ class NET_EXPORT_PRIVATE URLRequestThrottlerManager
public NetworkChangeNotifier::ConnectionTypeObserver {
public:
URLRequestThrottlerManager();
+
+ URLRequestThrottlerManager(const URLRequestThrottlerManager&) = delete;
+ URLRequestThrottlerManager& operator=(const URLRequestThrottlerManager&) =
+ delete;
+
~URLRequestThrottlerManager() override;
// Must be called for every request, returns the URL request throttler entry
@@ -140,8 +145,6 @@ class NET_EXPORT_PRIVATE URLRequestThrottlerManager
base::PlatformThreadId registered_from_thread_;
THREAD_CHECKER(thread_checker_);
-
- DISALLOW_COPY_AND_ASSIGN(URLRequestThrottlerManager);
};
} // namespace net
diff --git a/chromium/net/url_request/url_request_throttler_simulation_unittest.cc b/chromium/net/url_request/url_request_throttler_simulation_unittest.cc
index 97b392e44ce..b493971fd14 100644
--- a/chromium/net/url_request/url_request_throttler_simulation_unittest.cc
+++ b/chromium/net/url_request/url_request_throttler_simulation_unittest.cc
@@ -31,7 +31,6 @@
#include "net/url_request/url_request_throttler_test_support.h"
#include "testing/gtest/include/gtest/gtest.h"
-using base::TimeDelta;
using base::TimeTicks;
namespace net {
@@ -78,6 +77,9 @@ class DiscreteTimeSimulation {
DiscreteTimeSimulation() = default;
+ DiscreteTimeSimulation(const DiscreteTimeSimulation&) = delete;
+ DiscreteTimeSimulation& operator=(const DiscreteTimeSimulation&) = delete;
+
// Adds an |actor| to the simulation. The client of the simulation maintains
// ownership of |actor| and must ensure its lifetime exceeds that of the
// simulation. Actors should be added in the order you wish for them to
@@ -90,8 +92,8 @@ class DiscreteTimeSimulation {
// tick to the next. The start time will be the current real time. The
// simulation will stop when the simulated duration is equal to or greater
// than |maximum_simulated_duration|.
- void RunSimulation(const TimeDelta& maximum_simulated_duration,
- const TimeDelta& time_between_ticks) {
+ void RunSimulation(const base::TimeDelta& maximum_simulated_duration,
+ const base::TimeDelta& time_between_ticks) {
TimeTicks start_time = TimeTicks();
TimeTicks now = start_time;
while ((now - start_time) <= maximum_simulated_duration) {
@@ -109,8 +111,6 @@ class DiscreteTimeSimulation {
private:
std::vector<Actor*> actors_;
-
- DISALLOW_COPY_AND_ASSIGN(DiscreteTimeSimulation);
};
// Represents a web server in a simulation of a server under attack by
@@ -130,7 +130,11 @@ class Server : public DiscreteTimeSimulation::Actor {
nullptr,
TRAFFIC_ANNOTATION_FOR_TESTS)) {}
- void SetDowntime(const TimeTicks& start_time, const TimeDelta& duration) {
+ Server(const Server&) = delete;
+ Server& operator=(const Server&) = delete;
+
+ void SetDowntime(const TimeTicks& start_time,
+ const base::TimeDelta& duration) {
start_downtime_ = start_time;
end_downtime_ = start_time + duration;
}
@@ -295,8 +299,6 @@ class Server : public DiscreteTimeSimulation::Actor {
TestURLRequestContext context_;
std::unique_ptr<URLRequest> mock_request_;
-
- DISALLOW_COPY_AND_ASSIGN(Server);
};
// Mock throttler entry used by Requester class.
@@ -394,7 +396,7 @@ class RequesterResults {
class Requester : public DiscreteTimeSimulation::Actor {
public:
Requester(MockURLRequestThrottlerEntry* throttler_entry,
- const TimeDelta& time_between_requests,
+ const base::TimeDelta& time_between_requests,
Server* server,
RequesterResults* results)
: throttler_entry_(throttler_entry),
@@ -405,6 +407,9 @@ class Requester : public DiscreteTimeSimulation::Actor {
DCHECK(server_);
}
+ Requester(const Requester&) = delete;
+ Requester& operator=(const Requester&) = delete;
+
void AdvanceTime(const TimeTicks& absolute_time) override {
if (time_of_last_success_.is_null())
time_of_last_success_ = absolute_time;
@@ -413,8 +418,8 @@ class Requester : public DiscreteTimeSimulation::Actor {
}
void PerformAction() override {
- const TimeDelta current_jitter = request_jitter_ * base::RandDouble();
- const TimeDelta effective_delay =
+ const base::TimeDelta current_jitter = request_jitter_ * base::RandDouble();
+ const base::TimeDelta effective_delay =
time_between_requests_ +
(base::RandInt(0, 1) ? -current_jitter : current_jitter);
@@ -450,30 +455,30 @@ class Requester : public DiscreteTimeSimulation::Actor {
// Adds a delay until the first request, equal to a uniformly distributed
// value between now and now + max_delay.
- void SetStartupJitter(const TimeDelta& max_delay) {
+ void SetStartupJitter(const base::TimeDelta& max_delay) {
int delay_ms = base::RandInt(0, max_delay.InMilliseconds());
- time_of_last_attempt_ = TimeTicks() +
- TimeDelta::FromMilliseconds(delay_ms) - time_between_requests_;
+ time_of_last_attempt_ =
+ TimeTicks() + base::Milliseconds(delay_ms) - time_between_requests_;
}
- void SetRequestJitter(const TimeDelta& request_jitter) {
+ void SetRequestJitter(const base::TimeDelta& request_jitter) {
request_jitter_ = request_jitter;
}
- TimeDelta last_downtime_duration() const { return last_downtime_duration_; }
+ base::TimeDelta last_downtime_duration() const {
+ return last_downtime_duration_;
+ }
private:
scoped_refptr<MockURLRequestThrottlerEntry> throttler_entry_;
- const TimeDelta time_between_requests_;
- TimeDelta request_jitter_;
+ const base::TimeDelta time_between_requests_;
+ base::TimeDelta request_jitter_;
TimeTicks time_of_last_attempt_;
TimeTicks time_of_last_success_;
bool last_attempt_was_failure_;
- TimeDelta last_downtime_duration_;
+ base::TimeDelta last_downtime_duration_;
Server* const server_;
RequesterResults* const results_; // May be NULL.
-
- DISALLOW_COPY_AND_ASSIGN(Requester);
};
void SimulateAttack(Server* server,
@@ -494,9 +499,9 @@ void SimulateAttack(Server* server,
throttler_entry->DisableBackoffThrottling();
std::unique_ptr<Requester> attacker(
- new Requester(throttler_entry.get(), TimeDelta::FromMilliseconds(1),
- server, attacker_results));
- attacker->SetStartupJitter(TimeDelta::FromSeconds(120));
+ new Requester(throttler_entry.get(), base::Milliseconds(1), server,
+ attacker_results));
+ attacker->SetStartupJitter(base::Seconds(120));
simulation.AddActor(attacker.get());
requesters.push_back(std::move(attacker));
}
@@ -507,18 +512,16 @@ void SimulateAttack(Server* server,
if (!enable_throttling)
throttler_entry->DisableBackoffThrottling();
- std::unique_ptr<Requester> client(new Requester(throttler_entry.get(),
- TimeDelta::FromMinutes(2),
- server, client_results));
- client->SetStartupJitter(TimeDelta::FromSeconds(120));
- client->SetRequestJitter(TimeDelta::FromMinutes(1));
+ std::unique_ptr<Requester> client(new Requester(
+ throttler_entry.get(), base::Minutes(2), server, client_results));
+ client->SetStartupJitter(base::Seconds(120));
+ client->SetRequestJitter(base::Minutes(1));
simulation.AddActor(client.get());
requesters.push_back(std::move(client));
}
simulation.AddActor(server);
- simulation.RunSimulation(TimeDelta::FromMinutes(6),
- TimeDelta::FromSeconds(1));
+ simulation.RunSimulation(base::Minutes(6), base::Seconds(1));
}
TEST(URLRequestThrottlerSimulation, HelpsInAttack) {
@@ -576,10 +579,10 @@ TEST(URLRequestThrottlerSimulation, HelpsInAttack) {
// Returns the downtime perceived by the client, as a ratio of the
// actual downtime.
-double SimulateDowntime(const TimeDelta& duration,
- const TimeDelta& average_client_interval,
+double SimulateDowntime(const base::TimeDelta& duration,
+ const base::TimeDelta& average_client_interval,
bool enable_throttling) {
- TimeDelta time_between_ticks = duration / 200;
+ base::TimeDelta time_between_ticks = duration / 200;
TimeTicks start_downtime = TimeTicks() + (duration / 2);
// A server that never rejects requests, but will go down for maintenance.
@@ -655,15 +658,14 @@ TEST(URLRequestThrottlerSimulation, PerceivedDowntimeRatio) {
Stats global_stats = { 1.08, 1.15 };
struct Trial {
- TimeDelta duration;
- TimeDelta average_client_interval;
+ base::TimeDelta duration;
+ base::TimeDelta average_client_interval;
Stats stats;
void PrintTrialDescription() {
- const double duration_minutes =
- duration / base::TimeDelta::FromMinutes(1);
+ const double duration_minutes = duration / base::Minutes(1);
const double interval_minutes =
- average_client_interval / base::TimeDelta::FromMinutes(1);
+ average_client_interval / base::Minutes(1);
VerboseOut("Trial with %.2f min downtime, avg. interval %.2f min.\n",
duration_minutes, interval_minutes);
}
@@ -677,26 +679,26 @@ TEST(URLRequestThrottlerSimulation, PerceivedDowntimeRatio) {
// in behavior between a client making requests every few minutes vs.
// one that makes a request every 15 seconds).
Trial trials[] = {
- { TimeDelta::FromSeconds(10), TimeDelta::FromSeconds(3) },
- { TimeDelta::FromSeconds(30), TimeDelta::FromSeconds(7) },
- { TimeDelta::FromMinutes(5), TimeDelta::FromSeconds(30) },
- { TimeDelta::FromMinutes(10), TimeDelta::FromSeconds(20) },
- { TimeDelta::FromMinutes(20), TimeDelta::FromSeconds(15) },
- { TimeDelta::FromMinutes(20), TimeDelta::FromSeconds(50) },
- { TimeDelta::FromMinutes(30), TimeDelta::FromMinutes(2) },
- { TimeDelta::FromMinutes(30), TimeDelta::FromMinutes(5) },
- { TimeDelta::FromMinutes(40), TimeDelta::FromMinutes(7) },
- { TimeDelta::FromMinutes(40), TimeDelta::FromMinutes(2) },
- { TimeDelta::FromMinutes(40), TimeDelta::FromSeconds(15) },
- { TimeDelta::FromMinutes(60), TimeDelta::FromMinutes(7) },
- { TimeDelta::FromMinutes(60), TimeDelta::FromMinutes(2) },
- { TimeDelta::FromMinutes(60), TimeDelta::FromSeconds(15) },
- { TimeDelta::FromMinutes(80), TimeDelta::FromMinutes(20) },
- { TimeDelta::FromMinutes(80), TimeDelta::FromMinutes(3) },
- { TimeDelta::FromMinutes(80), TimeDelta::FromSeconds(15) },
-
- // Most brutal?
- { TimeDelta::FromMinutes(45), TimeDelta::FromMilliseconds(500) },
+ {base::Seconds(10), base::Seconds(3)},
+ {base::Seconds(30), base::Seconds(7)},
+ {base::Minutes(5), base::Seconds(30)},
+ {base::Minutes(10), base::Seconds(20)},
+ {base::Minutes(20), base::Seconds(15)},
+ {base::Minutes(20), base::Seconds(50)},
+ {base::Minutes(30), base::Minutes(2)},
+ {base::Minutes(30), base::Minutes(5)},
+ {base::Minutes(40), base::Minutes(7)},
+ {base::Minutes(40), base::Minutes(2)},
+ {base::Minutes(40), base::Seconds(15)},
+ {base::Minutes(60), base::Minutes(7)},
+ {base::Minutes(60), base::Minutes(2)},
+ {base::Minutes(60), base::Seconds(15)},
+ {base::Minutes(80), base::Minutes(20)},
+ {base::Minutes(80), base::Minutes(3)},
+ {base::Minutes(80), base::Seconds(15)},
+
+ // Most brutal?
+ {base::Minutes(45), base::Milliseconds(500)},
};
// If things don't converge by the time we've done 100K trials, then
diff --git a/chromium/net/url_request/url_request_throttler_test_support.h b/chromium/net/url_request/url_request_throttler_test_support.h
index ede659f9065..b3e2c8cdf7a 100644
--- a/chromium/net/url_request/url_request_throttler_test_support.h
+++ b/chromium/net/url_request/url_request_throttler_test_support.h
@@ -16,6 +16,10 @@ class TestTickClock : public base::TickClock {
public:
TestTickClock();
explicit TestTickClock(base::TimeTicks now);
+
+ TestTickClock(const TestTickClock&) = delete;
+ TestTickClock& operator=(const TestTickClock&) = delete;
+
~TestTickClock() override;
base::TimeTicks NowTicks() const override;
@@ -23,7 +27,6 @@ class TestTickClock : public base::TickClock {
private:
base::TimeTicks now_ticks_;
- DISALLOW_COPY_AND_ASSIGN(TestTickClock);
};
} // namespace net
diff --git a/chromium/net/url_request/url_request_throttler_unittest.cc b/chromium/net/url_request/url_request_throttler_unittest.cc
index 2b260b115ae..f7133d33261 100644
--- a/chromium/net/url_request/url_request_throttler_unittest.cc
+++ b/chromium/net/url_request/url_request_throttler_unittest.cc
@@ -22,7 +22,6 @@
#include "net/url_request/url_request_throttler_test_support.h"
#include "testing/gtest/include/gtest/gtest.h"
-using base::TimeDelta;
using base::TimeTicks;
namespace net {
@@ -117,7 +116,7 @@ class MockURLRequestThrottlerManager : public URLRequestThrottlerManager {
void CreateEntry(bool is_outdated) {
TimeTicks time = TimeTicks::Now();
if (is_outdated) {
- time -= TimeDelta::FromMilliseconds(
+ time -= base::Milliseconds(
MockURLRequestThrottlerEntry::kDefaultEntryLifetimeMs + 1000);
}
std::string fake_url_string("http://www.fakeurl.com/");
@@ -191,8 +190,8 @@ std::ostream& operator<<(std::ostream& out, const base::TimeTicks& time) {
TEST_F(URLRequestThrottlerEntryTest, InterfaceDuringExponentialBackoff) {
base::HistogramTester histogram_tester;
- entry_->set_exponential_backoff_release_time(
- entry_->ImplGetTimeNow() + TimeDelta::FromMilliseconds(1));
+ entry_->set_exponential_backoff_release_time(entry_->ImplGetTimeNow() +
+ base::Milliseconds(1));
EXPECT_TRUE(entry_->ShouldRejectRequest(*request_));
histogram_tester.ExpectBucketCount(kRequestThrottledHistogramName, 0, 0);
@@ -203,8 +202,8 @@ TEST_F(URLRequestThrottlerEntryTest, InterfaceNotDuringExponentialBackoff) {
base::HistogramTester histogram_tester;
entry_->set_exponential_backoff_release_time(entry_->ImplGetTimeNow());
EXPECT_FALSE(entry_->ShouldRejectRequest(*request_));
- entry_->set_exponential_backoff_release_time(
- entry_->ImplGetTimeNow() - TimeDelta::FromMilliseconds(1));
+ entry_->set_exponential_backoff_release_time(entry_->ImplGetTimeNow() -
+ base::Milliseconds(1));
EXPECT_FALSE(entry_->ShouldRejectRequest(*request_));
histogram_tester.ExpectBucketCount(kRequestThrottledHistogramName, 0, 2);
@@ -235,9 +234,9 @@ TEST_F(URLRequestThrottlerEntryTest, InterfaceUpdateSuccessThenFailure) {
}
TEST_F(URLRequestThrottlerEntryTest, IsEntryReallyOutdated) {
- TimeDelta lifetime = TimeDelta::FromMilliseconds(
- MockURLRequestThrottlerEntry::kDefaultEntryLifetimeMs);
- const TimeDelta kFiveMs = TimeDelta::FromMilliseconds(5);
+ base::TimeDelta lifetime =
+ base::Milliseconds(MockURLRequestThrottlerEntry::kDefaultEntryLifetimeMs);
+ const base::TimeDelta kFiveMs = base::Milliseconds(5);
TimeAndBool test_values[] = {
TimeAndBool(now_, false, __LINE__),
@@ -259,7 +258,7 @@ TEST_F(URLRequestThrottlerEntryTest, MaxAllowedBackoff) {
entry_->UpdateWithResponse(503);
}
- TimeDelta delay = entry_->GetExponentialBackoffReleaseTime() - now_;
+ base::TimeDelta delay = entry_->GetExponentialBackoffReleaseTime() - now_;
EXPECT_EQ(delay.InMilliseconds(),
MockURLRequestThrottlerEntry::kDefaultMaximumBackoffMs);
}
@@ -285,14 +284,15 @@ TEST_F(URLRequestThrottlerEntryTest, SlidingWindow) {
int sliding_window =
URLRequestThrottlerEntry::kDefaultSlidingWindowPeriodMs;
- TimeTicks time_1 = entry_->ImplGetTimeNow() +
- TimeDelta::FromMilliseconds(sliding_window / 3);
- TimeTicks time_2 = entry_->ImplGetTimeNow() +
- TimeDelta::FromMilliseconds(2 * sliding_window / 3);
- TimeTicks time_3 = entry_->ImplGetTimeNow() +
- TimeDelta::FromMilliseconds(sliding_window);
- TimeTicks time_4 = entry_->ImplGetTimeNow() +
- TimeDelta::FromMilliseconds(sliding_window + 2 * sliding_window / 3);
+ TimeTicks time_1 =
+ entry_->ImplGetTimeNow() + base::Milliseconds(sliding_window / 3);
+ TimeTicks time_2 =
+ entry_->ImplGetTimeNow() + base::Milliseconds(2 * sliding_window / 3);
+ TimeTicks time_3 =
+ entry_->ImplGetTimeNow() + base::Milliseconds(sliding_window);
+ TimeTicks time_4 =
+ entry_->ImplGetTimeNow() +
+ base::Milliseconds(sliding_window + 2 * sliding_window / 3);
entry_->set_exponential_backoff_release_time(time_1);
@@ -404,7 +404,7 @@ TEST_F(URLRequestThrottlerManagerTest, LocalHostOptedOut) {
// so add a 100 ms buffer to avoid flakiness (that should always
// give enough time to get from the TimeTicks::Now() call here
// to the TimeTicks::Now() call in the entry class).
- EXPECT_GT(TimeTicks::Now() + TimeDelta::FromMilliseconds(100),
+ EXPECT_GT(TimeTicks::Now() + base::Milliseconds(100),
localhost_entry->GetExponentialBackoffReleaseTime());
}
diff --git a/chromium/net/url_request/url_request_unittest.cc b/chromium/net/url_request/url_request_unittest.cc
index 786fb062a38..39b4ebde37f 100644
--- a/chromium/net/url_request/url_request_unittest.cc
+++ b/chromium/net/url_request/url_request_unittest.cc
@@ -2,8 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include <stdint.h>
+
#include <algorithm>
#include <iterator>
+#include <limits>
#include <memory>
#include <utility>
@@ -12,6 +15,7 @@
#include "base/memory/ptr_util.h"
#include "build/build_config.h"
#include "net/dns/public/secure_dns_policy.h"
+#include "url/url_constants.h"
#if defined(OS_WIN)
#include <objbase.h>
@@ -20,12 +24,6 @@
#include <wrl/client.h>
#endif
-#include <stdint.h>
-
-#include <algorithm>
-#include <limits>
-#include <memory>
-
#include "base/base64url.h"
#include "base/bind.h"
#include "base/compiler_specific.h"
@@ -68,6 +66,7 @@
#include "net/base/net_errors.h"
#include "net/base/net_module.h"
#include "net/base/proxy_server.h"
+#include "net/base/proxy_string_util.h"
#include "net/base/request_priority.h"
#include "net/base/test_completion_callback.h"
#include "net/base/transport_info.h"
@@ -105,6 +104,8 @@
#include "net/http/http_server_properties.h"
#include "net/http/http_transaction_test_util.h"
#include "net/http/http_util.h"
+#include "net/http/transport_security_state.h"
+#include "net/http/transport_security_state_source.h"
#include "net/log/file_net_log_observer.h"
#include "net/log/net_log_event_type.h"
#include "net/log/net_log_source.h"
@@ -132,6 +133,7 @@
#include "net/test/url_request/url_request_failed_job.h"
#include "net/test/url_request/url_request_mock_http_job.h"
#include "net/traffic_annotation/network_traffic_annotation_test_helper.h"
+#include "net/url_request/redirect_util.h"
#include "net/url_request/referrer_policy.h"
#include "net/url_request/static_http_user_agent_settings.h"
#include "net/url_request/url_request.h"
@@ -142,6 +144,7 @@
#include "net/url_request/url_request_redirect_job.h"
#include "net/url_request/url_request_test_job.h"
#include "net/url_request/url_request_test_util.h"
+#include "net/url_request/websocket_handshake_userdata_key.h"
#include "testing/gmock/include/gmock/gmock-matchers.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -149,12 +152,6 @@
#include "third_party/abseil-cpp/absl/types/optional.h"
#include "url/url_util.h"
-#if !BUILDFLAG(DISABLE_FTP_SUPPORT) && !defined(OS_ANDROID)
-#include "net/ftp/ftp_auth_cache.h"
-#include "net/ftp/ftp_network_layer.h"
-#include "net/url_request/ftp_protocol_handler.h"
-#endif
-
#if defined(OS_WIN)
#include "base/win/scoped_com_initializer.h"
#endif
@@ -168,6 +165,10 @@
#include "net/network_error_logging/network_error_logging_test_util.h"
#endif // BUILDFLAG(ENABLE_REPORTING)
+#if BUILDFLAG(ENABLE_WEBSOCKETS)
+#include "net/websockets/websocket_test_util.h"
+#endif // BUILDFLAG(ENABLE_WEBSOCKETS)
+
using net::test::IsError;
using net::test::IsOk;
using net::test_server::RegisterDefaultHandlers;
@@ -197,12 +198,6 @@ const std::u16string kUser(u"user");
const base::FilePath::CharType kTestFilePath[] =
FILE_PATH_LITERAL("net/data/url_request_unittest");
-#if !BUILDFLAG(DISABLE_FTP_SUPPORT) && !defined(OS_ANDROID) && \
- !defined(OS_FUCHSIA)
-// Test file used in most FTP tests.
-const char kFtpTestFile[] = "BullRunSpeech.txt";
-#endif
-
// Tests load timing information in the case a fresh connection was used, with
// no proxy.
void TestLoadTimingNotReused(const LoadTimingInfo& load_timing_info,
@@ -304,29 +299,6 @@ void TestLoadTimingCacheHitNoNetwork(const LoadTimingInfo& load_timing_info) {
EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null());
}
-#if !BUILDFLAG(DISABLE_FTP_SUPPORT) && !defined(OS_ANDROID) && \
- !defined(OS_FUCHSIA)
-// Tests load timing in the case that there is no HTTP response. This can be
-// used to test in the case of errors or non-HTTP requests.
-void TestLoadTimingNoHttpResponse(const LoadTimingInfo& load_timing_info) {
- EXPECT_FALSE(load_timing_info.socket_reused);
- EXPECT_EQ(NetLogSource::kInvalidId, load_timing_info.socket_log_id);
-
- // Only the request times should be non-null.
- EXPECT_FALSE(load_timing_info.request_start_time.is_null());
- EXPECT_FALSE(load_timing_info.request_start.is_null());
-
- ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing);
-
- EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null());
- EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null());
- EXPECT_TRUE(load_timing_info.send_start.is_null());
- EXPECT_TRUE(load_timing_info.send_end.is_null());
- EXPECT_TRUE(load_timing_info.receive_headers_start.is_null());
- EXPECT_TRUE(load_timing_info.receive_headers_end.is_null());
-}
-#endif
-
// Job that allows monitoring of its priority.
class PriorityMonitoringURLRequestJob : public URLRequestTestJob {
public:
@@ -402,6 +374,9 @@ class BlockingNetworkDelegate : public TestNetworkDelegate {
// Creates a delegate which does not block at all.
explicit BlockingNetworkDelegate(BlockMode block_mode);
+ BlockingNetworkDelegate(const BlockingNetworkDelegate&) = delete;
+ BlockingNetworkDelegate& operator=(const BlockingNetworkDelegate&) = delete;
+
// Runs the message loop until the delegate blocks.
void RunUntilBlocked();
@@ -479,8 +454,6 @@ class BlockingNetworkDelegate : public TestNetworkDelegate {
base::OnceClosure on_blocked_;
base::WeakPtrFactory<BlockingNetworkDelegate> weak_factory_{this};
-
- DISALLOW_COPY_AND_ASSIGN(BlockingNetworkDelegate);
};
BlockingNetworkDelegate::BlockingNetworkDelegate(BlockMode block_mode)
@@ -785,6 +758,46 @@ TEST_F(URLRequestTest, InvalidUrlTest) {
}
}
+// Test that URLRequest rejects WS URLs by default.
+TEST_F(URLRequestTest, WsUrlTest) {
+ const url::Origin kOrigin = url::Origin::Create(GURL("http://foo.test/"));
+
+ TestDelegate d;
+ std::unique_ptr<URLRequest> r(
+ default_context().CreateRequest(GURL("ws://foo.test/"), DEFAULT_PRIORITY,
+ &d, TRAFFIC_ANNOTATION_FOR_TESTS));
+ // This is not strictly necessary for this test, but used to trigger a DCHECK.
+ // See https://crbug.com/1245115.
+ r->set_isolation_info(
+ IsolationInfo::Create(IsolationInfo::RequestType::kMainFrame, kOrigin,
+ kOrigin, SiteForCookies::FromOrigin(kOrigin)));
+
+ r->Start();
+ d.RunUntilComplete();
+ EXPECT_TRUE(d.request_failed());
+ EXPECT_THAT(d.request_status(), IsError(ERR_UNKNOWN_URL_SCHEME));
+}
+
+// Test that URLRequest rejects WSS URLs by default.
+TEST_F(URLRequestTest, WssUrlTest) {
+ const url::Origin kOrigin = url::Origin::Create(GURL("https://foo.test/"));
+
+ TestDelegate d;
+ std::unique_ptr<URLRequest> r(
+ default_context().CreateRequest(GURL("wss://foo.test/"), DEFAULT_PRIORITY,
+ &d, TRAFFIC_ANNOTATION_FOR_TESTS));
+ // This is not strictly necessary for this test, but used to trigger a DCHECK.
+ // See https://crbug.com/1245115.
+ r->set_isolation_info(
+ IsolationInfo::Create(IsolationInfo::RequestType::kMainFrame, kOrigin,
+ kOrigin, SiteForCookies::FromOrigin(kOrigin)));
+
+ r->Start();
+ d.RunUntilComplete();
+ EXPECT_TRUE(d.request_failed());
+ EXPECT_THAT(d.request_status(), IsError(ERR_UNKNOWN_URL_SCHEME));
+}
+
TEST_F(URLRequestTest, InvalidReferrerTest) {
TestURLRequestContext context;
TestNetworkDelegate network_delegate;
@@ -1037,26 +1050,26 @@ LoadTimingInfo NormalLoadTimingInfo(base::TimeTicks now,
load_timing.socket_log_id = 1;
if (used_proxy) {
- load_timing.proxy_resolve_start = now + base::TimeDelta::FromDays(1);
- load_timing.proxy_resolve_end = now + base::TimeDelta::FromDays(2);
+ load_timing.proxy_resolve_start = now + base::Days(1);
+ load_timing.proxy_resolve_end = now + base::Days(2);
}
LoadTimingInfo::ConnectTiming& connect_timing = load_timing.connect_timing;
if (connect_time_flags & CONNECT_TIMING_HAS_DNS_TIMES) {
- connect_timing.dns_start = now + base::TimeDelta::FromDays(3);
- connect_timing.dns_end = now + base::TimeDelta::FromDays(4);
+ connect_timing.dns_start = now + base::Days(3);
+ connect_timing.dns_end = now + base::Days(4);
}
- connect_timing.connect_start = now + base::TimeDelta::FromDays(5);
+ connect_timing.connect_start = now + base::Days(5);
if (connect_time_flags & CONNECT_TIMING_HAS_SSL_TIMES) {
- connect_timing.ssl_start = now + base::TimeDelta::FromDays(6);
- connect_timing.ssl_end = now + base::TimeDelta::FromDays(7);
+ connect_timing.ssl_start = now + base::Days(6);
+ connect_timing.ssl_end = now + base::Days(7);
}
- connect_timing.connect_end = now + base::TimeDelta::FromDays(8);
+ connect_timing.connect_end = now + base::Days(8);
- load_timing.send_start = now + base::TimeDelta::FromDays(9);
- load_timing.send_end = now + base::TimeDelta::FromDays(10);
- load_timing.receive_headers_start = now + base::TimeDelta::FromDays(11);
- load_timing.receive_headers_end = now + base::TimeDelta::FromDays(12);
+ load_timing.send_start = now + base::Days(9);
+ load_timing.send_end = now + base::Days(10);
+ load_timing.receive_headers_start = now + base::Days(11);
+ load_timing.receive_headers_end = now + base::Days(12);
return load_timing;
}
@@ -1068,14 +1081,14 @@ LoadTimingInfo NormalLoadTimingInfoReused(base::TimeTicks now,
load_timing.socket_reused = true;
if (used_proxy) {
- load_timing.proxy_resolve_start = now + base::TimeDelta::FromDays(1);
- load_timing.proxy_resolve_end = now + base::TimeDelta::FromDays(2);
+ load_timing.proxy_resolve_start = now + base::Days(1);
+ load_timing.proxy_resolve_end = now + base::Days(2);
}
- load_timing.send_start = now + base::TimeDelta::FromDays(9);
- load_timing.send_end = now + base::TimeDelta::FromDays(10);
- load_timing.receive_headers_start = now + base::TimeDelta::FromDays(11);
- load_timing.receive_headers_end = now + base::TimeDelta::FromDays(12);
+ load_timing.send_start = now + base::Days(9);
+ load_timing.send_end = now + base::Days(10);
+ load_timing.receive_headers_start = now + base::Days(11);
+ load_timing.receive_headers_end = now + base::Days(12);
return load_timing;
}
@@ -1182,14 +1195,12 @@ TEST_F(URLRequestLoadTimingTest, InterceptLoadTimingEarlyProxyResolution) {
base::TimeTicks now = base::TimeTicks::Now();
LoadTimingInfo job_load_timing =
NormalLoadTimingInfo(now, CONNECT_TIMING_HAS_DNS_TIMES, true);
- job_load_timing.proxy_resolve_start = now - base::TimeDelta::FromDays(6);
- job_load_timing.proxy_resolve_end = now - base::TimeDelta::FromDays(5);
- job_load_timing.connect_timing.dns_start = now - base::TimeDelta::FromDays(4);
- job_load_timing.connect_timing.dns_end = now - base::TimeDelta::FromDays(3);
- job_load_timing.connect_timing.connect_start =
- now - base::TimeDelta::FromDays(2);
- job_load_timing.connect_timing.connect_end =
- now - base::TimeDelta::FromDays(1);
+ job_load_timing.proxy_resolve_start = now - base::Days(6);
+ job_load_timing.proxy_resolve_end = now - base::Days(5);
+ job_load_timing.connect_timing.dns_start = now - base::Days(4);
+ job_load_timing.connect_timing.dns_end = now - base::Days(3);
+ job_load_timing.connect_timing.connect_start = now - base::Days(2);
+ job_load_timing.connect_timing.connect_end = now - base::Days(1);
LoadTimingInfo load_timing_result = RunURLRequestInterceptorLoadTimingTest(
job_load_timing, default_context(), interceptor());
@@ -1219,8 +1230,8 @@ TEST_F(URLRequestLoadTimingTest,
InterceptLoadTimingEarlyProxyResolutionReused) {
base::TimeTicks now = base::TimeTicks::Now();
LoadTimingInfo job_load_timing = NormalLoadTimingInfoReused(now, true);
- job_load_timing.proxy_resolve_start = now - base::TimeDelta::FromDays(4);
- job_load_timing.proxy_resolve_end = now - base::TimeDelta::FromDays(3);
+ job_load_timing.proxy_resolve_start = now - base::Days(4);
+ job_load_timing.proxy_resolve_end = now - base::Days(3);
LoadTimingInfo load_timing_result = RunURLRequestInterceptorLoadTimingTest(
job_load_timing, default_context(), interceptor());
@@ -1244,12 +1255,10 @@ TEST_F(URLRequestLoadTimingTest, InterceptLoadTimingEarlyConnect) {
base::TimeTicks now = base::TimeTicks::Now();
LoadTimingInfo job_load_timing =
NormalLoadTimingInfo(now, CONNECT_TIMING_HAS_SSL_TIMES, false);
- job_load_timing.connect_timing.connect_start =
- now - base::TimeDelta::FromDays(1);
- job_load_timing.connect_timing.ssl_start = now - base::TimeDelta::FromDays(2);
- job_load_timing.connect_timing.ssl_end = now - base::TimeDelta::FromDays(3);
- job_load_timing.connect_timing.connect_end =
- now - base::TimeDelta::FromDays(4);
+ job_load_timing.connect_timing.connect_start = now - base::Days(1);
+ job_load_timing.connect_timing.ssl_start = now - base::Days(2);
+ job_load_timing.connect_timing.ssl_end = now - base::Days(3);
+ job_load_timing.connect_timing.connect_end = now - base::Days(4);
LoadTimingInfo load_timing_result = RunURLRequestInterceptorLoadTimingTest(
job_load_timing, default_context(), interceptor());
@@ -1278,10 +1287,8 @@ TEST_F(URLRequestLoadTimingTest, InterceptLoadTimingEarlyConnectWithProxy) {
base::TimeTicks now = base::TimeTicks::Now();
LoadTimingInfo job_load_timing =
NormalLoadTimingInfo(now, CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY, true);
- job_load_timing.connect_timing.connect_start =
- now - base::TimeDelta::FromDays(1);
- job_load_timing.connect_timing.connect_end =
- now - base::TimeDelta::FromDays(2);
+ job_load_timing.connect_timing.connect_start = now - base::Days(1);
+ job_load_timing.connect_timing.connect_end = now - base::Days(2);
LoadTimingInfo load_timing_result = RunURLRequestInterceptorLoadTimingTest(
job_load_timing, default_context(), interceptor());
@@ -1318,7 +1325,7 @@ TEST_F(URLRequestTest, NetworkDelegateProxyError) {
// Check we see a failed request.
// The proxy server should be set before failure.
- EXPECT_EQ(ProxyServer::FromPacString("PROXY myproxy:70"),
+ EXPECT_EQ(PacResultElementToProxyServer("PROXY myproxy:70"),
req->proxy_server());
EXPECT_EQ(ERR_PROXY_CONNECTION_FAILED, d.request_status());
EXPECT_THAT(req->response_info().resolve_error_info.error,
@@ -1330,6 +1337,220 @@ TEST_F(URLRequestTest, NetworkDelegateProxyError) {
EXPECT_EQ(1, network_delegate.completed_requests());
}
+// Test that requests with "http" scheme are upgraded to "https" when DNS
+// indicates that the name is HTTPS-only.
+TEST_F(URLRequestTest, DnsHttpsRecordPresentCausesSchemeUpgrade) {
+ base::test::ScopedFeatureList features;
+ features.InitAndEnableFeatureWithParameters(
+ features::kUseDnsHttpsSvcb, {{"UseDnsHttpsSvcbHttpUpgrade", "true"}});
+
+ EmbeddedTestServer https_server(EmbeddedTestServer::TYPE_HTTPS);
+ https_server.SetSSLConfig(EmbeddedTestServer::CERT_TEST_NAMES);
+ RegisterDefaultHandlers(&https_server);
+ ASSERT_TRUE(https_server.Start());
+
+ // Build an http URL that should be auto-upgraded to https.
+ const std::string kHost = "foo.a.test"; // Covered by CERT_TEST_NAMES.
+ const GURL https_url = https_server.GetURL(kHost, "/defaultresponse");
+ GURL::Replacements replacements;
+ replacements.SetSchemeStr(url::kHttpScheme);
+ const GURL http_url = https_url.ReplaceComponents(replacements);
+
+ // Build a mocked resolver that returns ERR_DNS_NAME_HTTPS_ONLY for the
+ // first lookup, regardless of the request scheme. Real resolvers should
+ // only return this error when the scheme is "http" or "ws".
+ MockHostResolver host_resolver;
+ host_resolver.rules()->AddSimulatedHTTPSServiceFormRecord("*");
+
+ TestNetworkDelegate network_delegate; // Must outlive URLRequest.
+ TestURLRequestContext context(true);
+ context.set_network_delegate(&network_delegate);
+ context.set_host_resolver(&host_resolver);
+ context.Init();
+
+ TestDelegate d;
+ std::unique_ptr<URLRequest> req(context.CreateRequest(
+ http_url, DEFAULT_PRIORITY, &d, TRAFFIC_ANNOTATION_FOR_TESTS));
+ EXPECT_FALSE(req->url().SchemeIsCryptographic());
+
+ // Note that there is no http server running, so the request should fail or
+ // hang if its scheme is not upgraded to https.
+ req->Start();
+ d.RunUntilComplete();
+
+ EXPECT_EQ(d.received_redirect_count(), 1);
+
+ EXPECT_EQ(0, network_delegate.error_count());
+ EXPECT_EQ(200, req->GetResponseCode());
+ ASSERT_TRUE(req->response_headers());
+ EXPECT_EQ(200, req->response_headers()->response_code());
+
+ // Observe that the scheme has been upgraded to https.
+ EXPECT_TRUE(req->url().SchemeIsCryptographic());
+ EXPECT_TRUE(req->url().SchemeIs(url::kHttpsScheme));
+}
+
+// Test that DNS-based scheme upgrade supports deferred redirect.
+TEST_F(URLRequestTest, DnsHttpsRecordPresentCausesSchemeUpgradeDeferred) {
+ base::test::ScopedFeatureList features;
+ features.InitAndEnableFeatureWithParameters(
+ features::kUseDnsHttpsSvcb, {{"UseDnsHttpsSvcbHttpUpgrade", "true"}});
+
+ EmbeddedTestServer https_server(EmbeddedTestServer::TYPE_HTTPS);
+ https_server.SetSSLConfig(EmbeddedTestServer::CERT_TEST_NAMES);
+ RegisterDefaultHandlers(&https_server);
+ ASSERT_TRUE(https_server.Start());
+
+ // Build an http URL that should be auto-upgraded to https.
+ const std::string kHost = "foo.a.test"; // Covered by CERT_TEST_NAMES.
+ const GURL https_url = https_server.GetURL(kHost, "/defaultresponse");
+ GURL::Replacements replacements;
+ replacements.SetSchemeStr(url::kHttpScheme);
+ const GURL http_url = https_url.ReplaceComponents(replacements);
+
+ // Build a mocked resolver that returns ERR_DNS_NAME_HTTPS_ONLY for the
+ // first lookup, regardless of the request scheme. Real resolvers should
+ // only return this error when the scheme is "http" or "ws".
+ MockHostResolver host_resolver;
+ host_resolver.rules()->AddSimulatedHTTPSServiceFormRecord("*");
+
+ TestNetworkDelegate network_delegate; // Must outlive URLRequest.
+ TestURLRequestContext context(true);
+ context.set_network_delegate(&network_delegate);
+ context.set_host_resolver(&host_resolver);
+ context.Init();
+
+ TestDelegate d;
+ std::unique_ptr<URLRequest> req(context.CreateRequest(
+ http_url, DEFAULT_PRIORITY, &d, TRAFFIC_ANNOTATION_FOR_TESTS));
+ EXPECT_FALSE(req->url().SchemeIsCryptographic());
+
+ // Note that there is no http server running, so the request should fail or
+ // hang if its scheme is not upgraded to https.
+ req->Start();
+ d.RunUntilRedirect();
+
+ EXPECT_EQ(d.received_redirect_count(), 1);
+
+ req->FollowDeferredRedirect(/*removed_headers=*/absl::nullopt,
+ /*modified_headers=*/absl::nullopt);
+ d.RunUntilComplete();
+
+ EXPECT_EQ(0, network_delegate.error_count());
+ EXPECT_EQ(200, req->GetResponseCode());
+ ASSERT_TRUE(req->response_headers());
+ EXPECT_EQ(200, req->response_headers()->response_code());
+
+ // Observe that the scheme has been upgraded to https.
+ EXPECT_TRUE(req->url().SchemeIsCryptographic());
+ EXPECT_TRUE(req->url().SchemeIs(url::kHttpsScheme));
+}
+
+#if BUILDFLAG(ENABLE_WEBSOCKETS)
+// Test that requests with "ws" scheme are upgraded to "wss" when DNS
+// indicates that the name is HTTPS-only.
+TEST_F(URLRequestTest, DnsHttpsRecordPresentCausesWsSchemeUpgrade) {
+ base::test::ScopedFeatureList features;
+ features.InitAndEnableFeatureWithParameters(
+ features::kUseDnsHttpsSvcb, {{"UseDnsHttpsSvcbHttpUpgrade", "true"}});
+
+ EmbeddedTestServer https_server(EmbeddedTestServer::TYPE_HTTPS);
+ https_server.SetSSLConfig(EmbeddedTestServer::CERT_TEST_NAMES);
+ RegisterDefaultHandlers(&https_server);
+ ASSERT_TRUE(https_server.Start());
+
+ // Build an http URL that should be auto-upgraded to https.
+ const std::string kHost = "foo.a.test"; // Covered by CERT_TEST_NAMES.
+ const GURL https_url = https_server.GetURL(kHost, "/defaultresponse");
+ GURL::Replacements replacements;
+ replacements.SetSchemeStr(url::kWsScheme);
+ const GURL ws_url = https_url.ReplaceComponents(replacements);
+
+ // Build a mocked resolver that returns ERR_DNS_NAME_HTTPS_ONLY for the
+ // first lookup, regardless of the request scheme. Real resolvers should
+ // only return this error when the scheme is "http" or "ws".
+ MockHostResolver host_resolver;
+ host_resolver.rules()->AddSimulatedHTTPSServiceFormRecord("*");
+
+ TestNetworkDelegate network_delegate; // Must outlive URLRequest.
+ TestURLRequestContext context(true);
+ context.set_network_delegate(&network_delegate);
+ context.set_host_resolver(&host_resolver);
+ context.Init();
+
+ TestDelegate d;
+ std::unique_ptr<URLRequest> req(context.CreateRequest(
+ ws_url, DEFAULT_PRIORITY, &d, TRAFFIC_ANNOTATION_FOR_TESTS,
+ /*is_for_websockets=*/true));
+ EXPECT_FALSE(req->url().SchemeIsCryptographic());
+
+ HttpRequestHeaders headers = WebSocketCommonTestHeaders();
+ req->SetExtraRequestHeaders(headers);
+
+ auto websocket_stream_create_helper =
+ std::make_unique<TestWebSocketHandshakeStreamCreateHelper>();
+ req->SetUserData(kWebSocketHandshakeUserDataKey,
+ std::move(websocket_stream_create_helper));
+
+ // Note that there is no ws server running, so the request should fail or hang
+ // if its scheme is not upgraded to wss.
+ req->Start();
+ d.RunUntilComplete();
+
+ EXPECT_EQ(d.received_redirect_count(), 1);
+
+ // Expect failure because test server is not set up to provide websocket
+ // responses.
+ EXPECT_EQ(network_delegate.error_count(), 1);
+ EXPECT_EQ(network_delegate.last_error(), ERR_INVALID_RESPONSE);
+
+ // Observe that the scheme has been upgraded to wss.
+ EXPECT_TRUE(req->url().SchemeIsCryptographic());
+ EXPECT_TRUE(req->url().SchemeIs(url::kWssScheme));
+}
+#endif // BUILDFLAG(ENABLE_WEBSOCKETS)
+
+TEST_F(URLRequestTest, DnsHttpsRecordAbsentNoSchemeUpgrade) {
+ base::test::ScopedFeatureList features;
+ features.InitAndEnableFeatureWithParameters(
+ features::kUseDnsHttpsSvcb, {{"UseDnsHttpsSvcbHttpUpgrade", "true"}});
+
+ EmbeddedTestServer http_server(EmbeddedTestServer::TYPE_HTTP);
+ RegisterDefaultHandlers(&http_server);
+ ASSERT_TRUE(http_server.Start());
+
+ // Build an http URL that should be auto-upgraded to https.
+ const std::string kHost = "foo.a.test"; // Covered by CERT_TEST_NAMES.
+ const GURL http_url = http_server.GetURL(kHost, "/defaultresponse");
+
+ MockHostResolver host_resolver;
+ TestNetworkDelegate network_delegate; // Must outlive URLRequest.
+ TestURLRequestContext context(true);
+ context.set_network_delegate(&network_delegate);
+ context.set_host_resolver(&host_resolver);
+ context.Init();
+
+ TestDelegate d;
+ std::unique_ptr<URLRequest> req(context.CreateRequest(
+ http_url, DEFAULT_PRIORITY, &d, TRAFFIC_ANNOTATION_FOR_TESTS));
+ EXPECT_FALSE(req->url().SchemeIsCryptographic());
+
+ req->Start();
+ d.RunUntilComplete();
+
+ EXPECT_EQ(d.received_redirect_count(), 0);
+
+ EXPECT_EQ(0, network_delegate.error_count());
+ EXPECT_EQ(200, req->GetResponseCode());
+ ASSERT_TRUE(req->response_headers());
+ EXPECT_EQ(200, req->response_headers()->response_code());
+
+ // Observe that the scheme has not been upgraded.
+ EXPECT_EQ(http_url, req->url());
+ EXPECT_FALSE(req->url().SchemeIsCryptographic());
+ EXPECT_TRUE(req->url().SchemeIs(url::kHttpScheme));
+}
+
TEST_F(URLRequestTest, SkipSecureDnsDisabledByDefault) {
MockHostResolver host_resolver;
TestNetworkDelegate network_delegate; // Must outlive URLRequest.
@@ -1908,7 +2129,7 @@ TEST_F(URLRequestTest, DoNotSendCookies_ViaPolicy) {
#else
#define MAYBE_DoNotSaveCookies_ViaPolicy DoNotSaveCookies_ViaPolicy
#endif
-TEST_F(URLRequestTest, DoNotSaveCookies_ViaPolicy) {
+TEST_F(URLRequestTest, MAYBE_DoNotSaveCookies_ViaPolicy) {
HttpTestServer test_server;
ASSERT_TRUE(test_server.Start());
@@ -3361,6 +3582,10 @@ class FixedDateNetworkDelegate : public TestNetworkDelegate {
public:
explicit FixedDateNetworkDelegate(const std::string& fixed_date)
: fixed_date_(fixed_date) {}
+
+ FixedDateNetworkDelegate(const FixedDateNetworkDelegate&) = delete;
+ FixedDateNetworkDelegate& operator=(const FixedDateNetworkDelegate&) = delete;
+
~FixedDateNetworkDelegate() override = default;
// NetworkDelegate implementation
@@ -3374,8 +3599,6 @@ class FixedDateNetworkDelegate : public TestNetworkDelegate {
private:
std::string fixed_date_;
-
- DISALLOW_COPY_AND_ASSIGN(FixedDateNetworkDelegate);
};
int FixedDateNetworkDelegate::OnHeadersReceived(
@@ -3525,6 +3748,12 @@ class URLRequestTestHTTP : public URLRequestTest {
: public URLRequestJobFactory::ProtocolHandler {
public:
UnsafeRedirectProtocolHandler() = default;
+
+ UnsafeRedirectProtocolHandler(const UnsafeRedirectProtocolHandler&) =
+ delete;
+ UnsafeRedirectProtocolHandler& operator=(
+ const UnsafeRedirectProtocolHandler&) = delete;
+
~UnsafeRedirectProtocolHandler() override = default;
// URLRequestJobFactory::ProtocolHandler implementation:
@@ -3538,14 +3767,11 @@ class URLRequestTestHTTP : public URLRequestTest {
bool IsSafeRedirectTarget(const GURL& location) const override {
return false;
}
-
- private:
- DISALLOW_COPY_AND_ASSIGN(UnsafeRedirectProtocolHandler);
};
// URLRequestTest interface:
void SetUpFactory() override {
- // Add FTP support to the default URLRequestContext.
+ // Add support for an unsafe scheme to the default URLRequestContext.
job_factory_->SetProtocolHandler(
"unsafe", std::make_unique<UnsafeRedirectProtocolHandler>());
}
@@ -4673,6 +4899,9 @@ class AsyncDelegateLogger : public base::RefCounted<AsyncDelegateLogger> {
public:
using Callback = base::OnceCallback<void()>;
+ AsyncDelegateLogger(const AsyncDelegateLogger&) = delete;
+ AsyncDelegateLogger& operator=(const AsyncDelegateLogger&) = delete;
+
// Each time delegate information is added to the URLRequest, the resulting
// load state is checked. The expected load state after each request is
// passed in as an argument.
@@ -4778,8 +5007,6 @@ class AsyncDelegateLogger : public base::RefCounted<AsyncDelegateLogger> {
const int expected_second_load_state_;
const int expected_third_load_state_;
Callback callback_;
-
- DISALLOW_COPY_AND_ASSIGN(AsyncDelegateLogger);
};
// NetworkDelegate that logs delegate information before a request is started,
@@ -4788,6 +5015,11 @@ class AsyncDelegateLogger : public base::RefCounted<AsyncDelegateLogger> {
class AsyncLoggingNetworkDelegate : public TestNetworkDelegate {
public:
AsyncLoggingNetworkDelegate() = default;
+
+ AsyncLoggingNetworkDelegate(const AsyncLoggingNetworkDelegate&) = delete;
+ AsyncLoggingNetworkDelegate& operator=(const AsyncLoggingNetworkDelegate&) =
+ delete;
+
~AsyncLoggingNetworkDelegate() override = default;
// NetworkDelegate implementation.
@@ -4840,8 +5072,6 @@ class AsyncLoggingNetworkDelegate : public TestNetworkDelegate {
base::BindOnce(std::move(callback), OK));
return ERR_IO_PENDING;
}
-
- DISALLOW_COPY_AND_ASSIGN(AsyncLoggingNetworkDelegate);
};
// URLRequest::Delegate that logs delegate information when the headers
@@ -4868,6 +5098,12 @@ class AsyncLoggingUrlRequestDelegate : public TestDelegate {
else if (cancel_stage == CANCEL_ON_READ_COMPLETED)
set_cancel_in_received_data(true);
}
+
+ AsyncLoggingUrlRequestDelegate(const AsyncLoggingUrlRequestDelegate&) =
+ delete;
+ AsyncLoggingUrlRequestDelegate& operator=(
+ const AsyncLoggingUrlRequestDelegate&) = delete;
+
~AsyncLoggingUrlRequestDelegate() override = default;
// URLRequest::Delegate implementation:
@@ -4925,8 +5161,6 @@ class AsyncLoggingUrlRequestDelegate : public TestDelegate {
}
const CancelStage cancel_stage_;
-
- DISALLOW_COPY_AND_ASSIGN(AsyncLoggingUrlRequestDelegate);
};
// Tests handling of delegate info before a request starts.
@@ -6813,7 +7047,7 @@ TEST_F(URLRequestTestHTTP, RedirectJobWithReferenceFragment) {
std::unique_ptr<URLRequestRedirectJob> job =
std::make_unique<URLRequestRedirectJob>(
- r.get(), redirect_url, URLRequestRedirectJob::REDIRECT_302_FOUND,
+ r.get(), redirect_url, RedirectUtil::ResponseCode::REDIRECT_302_FOUND,
"Very Good Reason");
TestScopedURLInterceptor interceptor(r->url(), std::move(job));
@@ -8441,7 +8675,7 @@ TEST_F(URLRequestTestHTTP, InterceptPost302RedirectGet) {
std::unique_ptr<URLRequestRedirectJob> job =
std::make_unique<URLRequestRedirectJob>(
req.get(), http_test_server()->GetURL("/echo"),
- URLRequestRedirectJob::REDIRECT_302_FOUND, "Very Good Reason");
+ RedirectUtil::ResponseCode::REDIRECT_302_FOUND, "Very Good Reason");
TestScopedURLInterceptor interceptor(req->url(), std::move(job));
req->Start();
@@ -8468,7 +8702,7 @@ TEST_F(URLRequestTestHTTP, InterceptPost307RedirectPost) {
std::unique_ptr<URLRequestRedirectJob> job =
std::make_unique<URLRequestRedirectJob>(
req.get(), http_test_server()->GetURL("/echo"),
- URLRequestRedirectJob::REDIRECT_307_TEMPORARY_REDIRECT,
+ RedirectUtil::ResponseCode::REDIRECT_307_TEMPORARY_REDIRECT,
"Very Good Reason");
TestScopedURLInterceptor interceptor(req->url(), std::move(job));
@@ -8695,8 +8929,8 @@ TEST_F(URLRequestTestHTTP, SetSubsequentJobPriority) {
std::unique_ptr<URLRequestRedirectJob> redirect_job =
std::make_unique<URLRequestRedirectJob>(
- req.get(), redirect_url, URLRequestRedirectJob::REDIRECT_302_FOUND,
- "Very Good Reason");
+ req.get(), redirect_url,
+ RedirectUtil::ResponseCode::REDIRECT_302_FOUND, "Very Good Reason");
auto interceptor = std::make_unique<TestScopedURLInterceptor>(
initial_url, std::move(redirect_job));
@@ -8756,6 +8990,10 @@ class FailingHttpTransactionFactory : public HttpTransactionFactory {
explicit FailingHttpTransactionFactory(HttpNetworkSession* network_session)
: network_session_(network_session) {}
+ FailingHttpTransactionFactory(const FailingHttpTransactionFactory&) = delete;
+ FailingHttpTransactionFactory& operator=(
+ const FailingHttpTransactionFactory&) = delete;
+
~FailingHttpTransactionFactory() override = default;
// HttpTransactionFactory methods:
@@ -8770,8 +9008,6 @@ class FailingHttpTransactionFactory : public HttpTransactionFactory {
private:
HttpNetworkSession* network_session_;
-
- DISALLOW_COPY_AND_ASSIGN(FailingHttpTransactionFactory);
};
} // namespace
@@ -9519,7 +9755,7 @@ TEST_F(HTTPSRequestTest, HSTSPreservesPosts) {
// Force https for www.somewhere.com.
TransportSecurityState transport_security_state;
- base::Time expiry = base::Time::Now() + base::TimeDelta::FromDays(1000);
+ base::Time expiry = base::Time::Now() + base::Days(1000);
bool include_subdomains = false;
transport_security_state.AddHSTS("www.somewhere.com", expiry,
include_subdomains);
@@ -9572,7 +9808,7 @@ TEST_F(HTTPSRequestTest, HSTSCrossOriginAddHeaders) {
MockHostResolver host_resolver;
TransportSecurityState transport_security_state;
- base::Time expiry = base::Time::Now() + base::TimeDelta::FromDays(1);
+ base::Time expiry = base::Time::Now() + base::Days(1);
bool include_subdomains = false;
transport_security_state.AddHSTS("example.net", expiry, include_subdomains);
@@ -9969,14 +10205,12 @@ TEST_F(HTTPSRequestTest, ClientAuthFailSigningRetry) {
}
TEST_F(HTTPSRequestTest, ResumeTest) {
- // Test that we attempt a session resume when making two connections to the
+ // Test that we attempt resume sessions when making two connections to the
// same host.
- SpawnedTestServer::SSLOptions ssl_options;
- ssl_options.record_resume = true;
- SpawnedTestServer test_server(
- SpawnedTestServer::TYPE_HTTPS, ssl_options,
- base::FilePath(FILE_PATH_LITERAL("net/data/ssl")));
+ EmbeddedTestServer test_server(EmbeddedTestServer::TYPE_HTTPS);
+ RegisterDefaultHandlers(&test_server);
ASSERT_TRUE(test_server.Start());
+ const auto url = test_server.GetURL("/");
default_context_.http_transaction_factory()
->GetSession()
@@ -9985,8 +10219,7 @@ TEST_F(HTTPSRequestTest, ResumeTest) {
{
TestDelegate d;
std::unique_ptr<URLRequest> r(default_context_.CreateRequest(
- test_server.GetURL("ssl-session-cache"), DEFAULT_PRIORITY, &d,
- TRAFFIC_ANNOTATION_FOR_TESTS));
+ url, DEFAULT_PRIORITY, &d, TRAFFIC_ANNOTATION_FOR_TESTS));
r->Start();
EXPECT_TRUE(r->is_pending());
@@ -9994,6 +10227,7 @@ TEST_F(HTTPSRequestTest, ResumeTest) {
d.RunUntilComplete();
EXPECT_EQ(1, d.response_started_count());
+ EXPECT_EQ(SSLInfo::HANDSHAKE_FULL, r->ssl_info().handshake_type);
}
reinterpret_cast<HttpCache*>(default_context_.http_transaction_factory())
@@ -10002,55 +10236,25 @@ TEST_F(HTTPSRequestTest, ResumeTest) {
{
TestDelegate d;
std::unique_ptr<URLRequest> r(default_context_.CreateRequest(
- test_server.GetURL("ssl-session-cache"), DEFAULT_PRIORITY, &d,
- TRAFFIC_ANNOTATION_FOR_TESTS));
+ url, DEFAULT_PRIORITY, &d, TRAFFIC_ANNOTATION_FOR_TESTS));
r->Start();
EXPECT_TRUE(r->is_pending());
d.RunUntilComplete();
- // The response will look like;
- // lookup uvw (TLS 1.3's compatibility session ID)
- // insert abc
- // lookup abc
- // insert xyz
- //
- // With a newline at the end which makes the split think that there are
- // four lines.
-
EXPECT_EQ(1, d.response_started_count());
- std::vector<std::string> lines = base::SplitString(
- d.data_received(), "\n", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
- ASSERT_EQ(5u, lines.size()) << d.data_received();
-
- std::string session_id;
-
- for (size_t i = 0; i < 3; i++) {
- std::vector<std::string> parts = base::SplitString(
- lines[i], "\t", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
- ASSERT_EQ(2u, parts.size());
- if (i % 2 == 1) {
- EXPECT_EQ("insert", parts[0]);
- session_id = parts[1];
- } else {
- EXPECT_EQ("lookup", parts[0]);
- if (i != 0)
- EXPECT_EQ(session_id, parts[1]);
- }
- }
+ EXPECT_EQ(SSLInfo::HANDSHAKE_RESUME, r->ssl_info().handshake_type);
}
}
+// Test that sessions aren't resumed across HttpNetworkSessions.
TEST_F(HTTPSRequestTest, SSLSessionCacheShardTest) {
- // Test that sessions aren't resumed when the value of ssl_session_cache_shard
- // differs.
- SpawnedTestServer::SSLOptions ssl_options;
- ssl_options.record_resume = true;
- SpawnedTestServer test_server(
- SpawnedTestServer::TYPE_HTTPS, ssl_options,
- base::FilePath(FILE_PATH_LITERAL("net/data/ssl")));
+ // Start a server.
+ EmbeddedTestServer test_server(EmbeddedTestServer::TYPE_HTTPS);
+ RegisterDefaultHandlers(&test_server);
ASSERT_TRUE(test_server.Start());
+ const auto url = test_server.GetURL("/");
default_context_.http_transaction_factory()
->GetSession()
@@ -10059,8 +10263,7 @@ TEST_F(HTTPSRequestTest, SSLSessionCacheShardTest) {
{
TestDelegate d;
std::unique_ptr<URLRequest> r(default_context_.CreateRequest(
- test_server.GetURL("/"), DEFAULT_PRIORITY, &d,
- TRAFFIC_ANNOTATION_FOR_TESTS));
+ url, DEFAULT_PRIORITY, &d, TRAFFIC_ANNOTATION_FOR_TESTS));
r->Start();
EXPECT_TRUE(r->is_pending());
@@ -10070,7 +10273,7 @@ TEST_F(HTTPSRequestTest, SSLSessionCacheShardTest) {
EXPECT_EQ(1, d.response_started_count());
}
- // Now create a new HttpCache with a different ssl_session_cache_shard value.
+ // Now create a new HttpNetworkSession.
HttpNetworkSessionContext session_context;
session_context.host_resolver = default_context_.host_resolver();
session_context.cert_verifier = default_context_.cert_verifier();
@@ -10097,8 +10300,7 @@ TEST_F(HTTPSRequestTest, SSLSessionCacheShardTest) {
{
TestDelegate d;
std::unique_ptr<URLRequest> r(default_context_.CreateRequest(
- test_server.GetURL("ssl-session-cache"), DEFAULT_PRIORITY, &d,
- TRAFFIC_ANNOTATION_FOR_TESTS));
+ url, DEFAULT_PRIORITY, &d, TRAFFIC_ANNOTATION_FOR_TESTS));
r->Start();
EXPECT_TRUE(r->is_pending());
@@ -10262,12 +10464,10 @@ class HTTPSSessionTest : public TestWithTaskEnvironment {
// Tests that session resumption is not attempted if an invalid certificate
// is presented.
TEST_F(HTTPSSessionTest, DontResumeSessionsForInvalidCertificates) {
- SpawnedTestServer::SSLOptions ssl_options;
- ssl_options.record_resume = true;
- SpawnedTestServer test_server(
- SpawnedTestServer::TYPE_HTTPS, ssl_options,
- base::FilePath(FILE_PATH_LITERAL("net/data/ssl")));
+ EmbeddedTestServer test_server(EmbeddedTestServer::TYPE_HTTPS);
+ RegisterDefaultHandlers(&test_server);
ASSERT_TRUE(test_server.Start());
+ const auto url = test_server.GetURL("/");
default_context_.http_transaction_factory()
->GetSession()
@@ -10278,8 +10478,7 @@ TEST_F(HTTPSSessionTest, DontResumeSessionsForInvalidCertificates) {
{
TestDelegate d;
std::unique_ptr<URLRequest> r(default_context_.CreateRequest(
- test_server.GetURL("/"), DEFAULT_PRIORITY, &d,
- TRAFFIC_ANNOTATION_FOR_TESTS));
+ url, DEFAULT_PRIORITY, &d, TRAFFIC_ANNOTATION_FOR_TESTS));
r->Start();
EXPECT_TRUE(r->is_pending());
@@ -10298,8 +10497,7 @@ TEST_F(HTTPSSessionTest, DontResumeSessionsForInvalidCertificates) {
{
TestDelegate d;
std::unique_ptr<URLRequest> r(default_context_.CreateRequest(
- test_server.GetURL("ssl-session-cache"), DEFAULT_PRIORITY, &d,
- TRAFFIC_ANNOTATION_FOR_TESTS));
+ url, DEFAULT_PRIORITY, &d, TRAFFIC_ANNOTATION_FOR_TESTS));
r->Start();
EXPECT_TRUE(r->is_pending());
@@ -11672,404 +11870,6 @@ TEST_F(HTTPSLocalCRLSetTest, InterceptionBlockedAllowOverrideOnHSTS) {
}
#endif // !defined(OS_IOS)
-#if !BUILDFLAG(DISABLE_FTP_SUPPORT) && !defined(OS_ANDROID) && \
- !defined(OS_FUCHSIA)
-// FTP uses a second TCP connection with the port number allocated dynamically
-// on the server side, so it would be hard to make RemoteTestServer proxy FTP
-// connections reliably. FTP tests are disabled on platforms that use
-// RemoteTestServer. See http://crbug.com/495220
-class URLRequestTestFTP : public URLRequestTest {
- public:
- URLRequestTestFTP()
- : ftp_test_server_(SpawnedTestServer::TYPE_FTP,
- base::FilePath(kTestFilePath)) {
- // Can't use |default_context_|'s HostResolver to set up the
- // FTPTransactionFactory because it hasn't been created yet.
- default_context().set_host_resolver(&host_resolver_);
- }
-
- // URLRequestTest interface:
- void SetUpFactory() override {
- // Add FTP support to the default URLRequestContext.
- job_factory_->SetProtocolHandler(
- "ftp", FtpProtocolHandler::Create(&host_resolver_, &ftp_auth_cache_));
- }
-
- std::string GetTestFileContents() {
- base::FilePath path;
- EXPECT_TRUE(base::PathService::Get(base::DIR_SOURCE_ROOT, &path));
- path = path.Append(kTestFilePath);
- path = path.AppendASCII(kFtpTestFile);
- std::string contents;
- EXPECT_TRUE(base::ReadFileToString(path, &contents));
- return contents;
- }
-
- protected:
- MockHostResolver host_resolver_;
- FtpAuthCache ftp_auth_cache_;
-
- SpawnedTestServer ftp_test_server_;
-};
-
-// Make sure an FTP request using an unsafe ports fails.
-TEST_F(URLRequestTestFTP, UnsafePort) {
- GURL url("ftp://127.0.0.1:7");
-
- TestDelegate d;
- {
- std::unique_ptr<URLRequest> r(default_context().CreateRequest(
- url, DEFAULT_PRIORITY, &d, TRAFFIC_ANNOTATION_FOR_TESTS));
- r->Start();
- EXPECT_TRUE(r->is_pending());
-
- d.RunUntilComplete();
-
- EXPECT_FALSE(r->is_pending());
- EXPECT_EQ(ERR_UNSAFE_PORT, d.request_status());
- }
-}
-
-TEST_F(URLRequestTestFTP, FTPDirectoryListing) {
- ASSERT_TRUE(ftp_test_server_.Start());
-
- TestDelegate d;
- {
- std::unique_ptr<URLRequest> r(default_context().CreateRequest(
- ftp_test_server_.GetURL("/"), DEFAULT_PRIORITY, &d,
- TRAFFIC_ANNOTATION_FOR_TESTS));
- r->Start();
- EXPECT_TRUE(r->is_pending());
-
- d.RunUntilComplete();
-
- EXPECT_FALSE(r->is_pending());
- EXPECT_EQ(1, d.response_started_count());
- EXPECT_FALSE(d.received_data_before_response());
- EXPECT_LT(0, d.bytes_received());
- EXPECT_EQ(ftp_test_server_.host_port_pair().host(),
- r->GetResponseRemoteEndpoint().ToStringWithoutPort());
- EXPECT_EQ(ftp_test_server_.host_port_pair().port(),
- r->GetResponseRemoteEndpoint().port());
- }
-}
-
-TEST_F(URLRequestTestFTP, FTPGetTestAnonymous) {
- ASSERT_TRUE(ftp_test_server_.Start());
-
- TestDelegate d;
- {
- std::unique_ptr<URLRequest> r(default_context().CreateRequest(
- ftp_test_server_.GetURL(kFtpTestFile), DEFAULT_PRIORITY, &d,
- TRAFFIC_ANNOTATION_FOR_TESTS));
- r->Start();
- EXPECT_TRUE(r->is_pending());
-
- d.RunUntilComplete();
-
- EXPECT_FALSE(r->is_pending());
- EXPECT_EQ(1, d.response_started_count());
- EXPECT_FALSE(d.received_data_before_response());
- EXPECT_EQ(GetTestFileContents(), d.data_received());
- EXPECT_EQ(ftp_test_server_.host_port_pair().host(),
- r->GetResponseRemoteEndpoint().ToStringWithoutPort());
- EXPECT_EQ(ftp_test_server_.host_port_pair().port(),
- r->GetResponseRemoteEndpoint().port());
- }
-}
-
-TEST_F(URLRequestTestFTP, FTPMimeType) {
- ASSERT_TRUE(ftp_test_server_.Start());
-
- struct {
- const char* path;
- const char* mime;
- } test_cases[] = {
- {"/", "text/vnd.chromium.ftp-dir"},
- {kFtpTestFile, "application/octet-stream"},
- };
-
- for (const auto test : test_cases) {
- TestDelegate d;
-
- std::unique_ptr<URLRequest> r(default_context().CreateRequest(
- ftp_test_server_.GetURL(test.path), DEFAULT_PRIORITY, &d,
- TRAFFIC_ANNOTATION_FOR_TESTS));
- r->Start();
- EXPECT_TRUE(r->is_pending());
-
- d.RunUntilComplete();
-
- std::string mime;
- r->GetMimeType(&mime);
- EXPECT_EQ(test.mime, mime);
- }
-}
-
-TEST_F(URLRequestTestFTP, FTPGetTest) {
- ASSERT_TRUE(ftp_test_server_.Start());
-
- TestDelegate d;
- {
- std::unique_ptr<URLRequest> r(default_context().CreateRequest(
- ftp_test_server_.GetURLWithUserAndPassword(kFtpTestFile, "chrome",
- "chrome"),
- DEFAULT_PRIORITY, &d, TRAFFIC_ANNOTATION_FOR_TESTS));
- r->Start();
- EXPECT_TRUE(r->is_pending());
-
- d.RunUntilComplete();
-
- EXPECT_FALSE(r->is_pending());
- EXPECT_EQ(1, d.response_started_count());
- EXPECT_FALSE(d.received_data_before_response());
- EXPECT_EQ(GetTestFileContents(), d.data_received());
- EXPECT_EQ(ftp_test_server_.host_port_pair().host(),
- r->GetResponseRemoteEndpoint().ToStringWithoutPort());
- EXPECT_EQ(ftp_test_server_.host_port_pair().port(),
- r->GetResponseRemoteEndpoint().port());
-
- LoadTimingInfo load_timing_info;
- r->GetLoadTimingInfo(&load_timing_info);
- TestLoadTimingNoHttpResponse(load_timing_info);
- }
-}
-
-TEST_F(URLRequestTestFTP, FTPCheckWrongPassword) {
- ASSERT_TRUE(ftp_test_server_.Start());
-
- TestDelegate d;
- {
- std::unique_ptr<URLRequest> r(default_context().CreateRequest(
- ftp_test_server_.GetURLWithUserAndPassword(kFtpTestFile, "chrome",
- "wrong_password"),
- DEFAULT_PRIORITY, &d, TRAFFIC_ANNOTATION_FOR_TESTS));
- r->Start();
- EXPECT_TRUE(r->is_pending());
-
- d.RunUntilComplete();
-
- EXPECT_FALSE(r->is_pending());
- EXPECT_EQ(1, d.response_started_count());
- EXPECT_FALSE(d.received_data_before_response());
- EXPECT_EQ(d.bytes_received(), 0);
- }
-}
-
-TEST_F(URLRequestTestFTP, FTPCheckWrongPasswordRestart) {
- ASSERT_TRUE(ftp_test_server_.Start());
-
- TestDelegate d;
- // Set correct login credentials. The delegate will be asked for them when
- // the initial login with wrong credentials will fail.
- d.set_credentials(AuthCredentials(kChrome, kChrome));
- {
- std::unique_ptr<URLRequest> r(default_context().CreateRequest(
- ftp_test_server_.GetURLWithUserAndPassword(kFtpTestFile, "chrome",
- "wrong_password"),
- DEFAULT_PRIORITY, &d, TRAFFIC_ANNOTATION_FOR_TESTS));
- r->Start();
- EXPECT_TRUE(r->is_pending());
-
- d.RunUntilComplete();
-
- EXPECT_FALSE(r->is_pending());
- EXPECT_EQ(1, d.response_started_count());
- EXPECT_FALSE(d.received_data_before_response());
- EXPECT_EQ(GetTestFileContents(), d.data_received());
- }
-}
-
-TEST_F(URLRequestTestFTP, FTPCheckWrongUser) {
- ASSERT_TRUE(ftp_test_server_.Start());
-
- TestDelegate d;
- {
- std::unique_ptr<URLRequest> r(default_context().CreateRequest(
- ftp_test_server_.GetURLWithUserAndPassword(kFtpTestFile, "wrong_user",
- "chrome"),
- DEFAULT_PRIORITY, &d, TRAFFIC_ANNOTATION_FOR_TESTS));
- r->Start();
- EXPECT_TRUE(r->is_pending());
-
- d.RunUntilComplete();
-
- EXPECT_FALSE(r->is_pending());
- EXPECT_EQ(1, d.response_started_count());
- EXPECT_FALSE(d.received_data_before_response());
- EXPECT_EQ(0, d.bytes_received());
- }
-}
-
-TEST_F(URLRequestTestFTP, FTPCheckWrongUserRestart) {
- ASSERT_TRUE(ftp_test_server_.Start());
-
- TestDelegate d;
- // Set correct login credentials. The delegate will be asked for them when
- // the initial login with wrong credentials will fail.
- d.set_credentials(AuthCredentials(kChrome, kChrome));
- {
- std::unique_ptr<URLRequest> r(default_context().CreateRequest(
- ftp_test_server_.GetURLWithUserAndPassword(kFtpTestFile, "wrong_user",
- "chrome"),
- DEFAULT_PRIORITY, &d, TRAFFIC_ANNOTATION_FOR_TESTS));
- r->Start();
- EXPECT_TRUE(r->is_pending());
-
- d.RunUntilComplete();
-
- EXPECT_FALSE(r->is_pending());
- EXPECT_EQ(1, d.response_started_count());
- EXPECT_FALSE(d.received_data_before_response());
- EXPECT_EQ(GetTestFileContents(), d.data_received());
- }
-}
-
-TEST_F(URLRequestTestFTP, FTPCacheURLCredentials) {
- ASSERT_TRUE(ftp_test_server_.Start());
-
- std::unique_ptr<TestDelegate> d(new TestDelegate);
- {
- // Pass correct login identity in the URL.
- std::unique_ptr<URLRequest> r(default_context().CreateRequest(
- ftp_test_server_.GetURLWithUserAndPassword(kFtpTestFile, "chrome",
- "chrome"),
- DEFAULT_PRIORITY, d.get(), TRAFFIC_ANNOTATION_FOR_TESTS));
- r->Start();
- EXPECT_TRUE(r->is_pending());
-
- d->RunUntilComplete();
-
- EXPECT_FALSE(r->is_pending());
- EXPECT_EQ(1, d->response_started_count());
- EXPECT_FALSE(d->received_data_before_response());
- EXPECT_EQ(GetTestFileContents(), d->data_received());
- }
-
- d = std::make_unique<TestDelegate>();
- {
- // This request should use cached identity from previous request.
- std::unique_ptr<URLRequest> r(default_context().CreateRequest(
- ftp_test_server_.GetURL(kFtpTestFile), DEFAULT_PRIORITY, d.get(),
- TRAFFIC_ANNOTATION_FOR_TESTS));
- r->Start();
- EXPECT_TRUE(r->is_pending());
-
- d->RunUntilComplete();
-
- EXPECT_FALSE(r->is_pending());
- EXPECT_EQ(1, d->response_started_count());
- EXPECT_FALSE(d->received_data_before_response());
- EXPECT_EQ(GetTestFileContents(), d->data_received());
- }
-}
-
-TEST_F(URLRequestTestFTP, FTPCacheLoginBoxCredentials) {
- ASSERT_TRUE(ftp_test_server_.Start());
-
- std::unique_ptr<TestDelegate> d(new TestDelegate);
- // Set correct login credentials. The delegate will be asked for them when
- // the initial login with wrong credentials will fail.
- d->set_credentials(AuthCredentials(kChrome, kChrome));
- {
- std::unique_ptr<URLRequest> r(default_context().CreateRequest(
- ftp_test_server_.GetURLWithUserAndPassword(kFtpTestFile, "chrome",
- "wrong_password"),
- DEFAULT_PRIORITY, d.get(), TRAFFIC_ANNOTATION_FOR_TESTS));
- r->Start();
- EXPECT_TRUE(r->is_pending());
-
- d->RunUntilComplete();
-
- EXPECT_FALSE(r->is_pending());
- EXPECT_EQ(1, d->response_started_count());
- EXPECT_FALSE(d->received_data_before_response());
- EXPECT_EQ(GetTestFileContents(), d->data_received());
- }
-
- // Use a new delegate without explicit credentials. The cached ones should be
- // used.
- d = std::make_unique<TestDelegate>();
- {
- // Don't pass wrong credentials in the URL, they would override valid cached
- // ones.
- std::unique_ptr<URLRequest> r(default_context().CreateRequest(
- ftp_test_server_.GetURL(kFtpTestFile), DEFAULT_PRIORITY, d.get(),
- TRAFFIC_ANNOTATION_FOR_TESTS));
- r->Start();
- EXPECT_TRUE(r->is_pending());
-
- d->RunUntilComplete();
-
- EXPECT_FALSE(r->is_pending());
- EXPECT_EQ(1, d->response_started_count());
- EXPECT_FALSE(d->received_data_before_response());
- EXPECT_EQ(GetTestFileContents(), d->data_received());
- }
-}
-
-TEST_F(URLRequestTestFTP, RawBodyBytes) {
- ASSERT_TRUE(ftp_test_server_.Start());
-
- TestDelegate d;
- std::unique_ptr<URLRequest> req(default_context().CreateRequest(
- ftp_test_server_.GetURL("simple.html"), DEFAULT_PRIORITY, &d,
- TRAFFIC_ANNOTATION_FOR_TESTS));
- req->Start();
- d.RunUntilComplete();
-
- EXPECT_EQ(6, req->GetRawBodyBytes());
-}
-
-TEST_F(URLRequestTestFTP, FtpAuthCancellation) {
- ftp_test_server_.set_no_anonymous_ftp_user(true);
- ASSERT_TRUE(ftp_test_server_.Start());
- TestDelegate d;
- std::unique_ptr<URLRequest> req(default_context().CreateRequest(
- ftp_test_server_.GetURL("simple.html"), DEFAULT_PRIORITY, &d,
- TRAFFIC_ANNOTATION_FOR_TESTS));
- req->Start();
- d.RunUntilComplete();
-
- ASSERT_TRUE(d.auth_required_called());
- EXPECT_EQ(OK, d.request_status());
- EXPECT_TRUE(req->auth_challenge_info());
- std::string mime_type;
- req->GetMimeType(&mime_type);
- EXPECT_EQ("text/plain", mime_type);
- EXPECT_EQ("", d.data_received());
- EXPECT_EQ(-1, req->GetExpectedContentSize());
-}
-
-class URLRequestTestFTPOverHttpProxy : public URLRequestTestFTP {
- public:
- // Test interface:
- void SetUp() override {
- proxy_resolution_service_ = ConfiguredProxyResolutionService::CreateFixed(
- "localhost", TRAFFIC_ANNOTATION_FOR_TESTS);
- default_context_->set_proxy_resolution_service(
- proxy_resolution_service_.get());
- URLRequestTestFTP::SetUp();
- }
-
- private:
- std::unique_ptr<ProxyResolutionService> proxy_resolution_service_;
-};
-
-// Check that FTP is not supported over an HTTP proxy.
-TEST_F(URLRequestTestFTPOverHttpProxy, Fails) {
- TestDelegate delegate;
- std::unique_ptr<URLRequest> request(
- default_context_->CreateRequest(GURL("ftp://foo.test/"), DEFAULT_PRIORITY,
- &delegate, TRAFFIC_ANNOTATION_FOR_TESTS));
- request->Start();
- delegate.RunUntilComplete();
-
- EXPECT_THAT(delegate.request_status(), IsError(ERR_NO_SUPPORTED_PROXIES));
-}
-
-#endif // !BUILDFLAG(DISABLE_FTP_SUPPORT)
-
TEST_F(URLRequestTest, NetworkAccessedSetOnHostResolutionFailure) {
MockHostResolver host_resolver;
TestNetworkDelegate network_delegate; // Must outlive URLRequest.
@@ -12104,7 +11904,7 @@ TEST_F(URLRequestTest, URLRequestRedirectJobCancelRequest) {
std::unique_ptr<URLRequestRedirectJob> job =
std::make_unique<URLRequestRedirectJob>(
req.get(), GURL("http://this-should-never-be-navigated-to/"),
- URLRequestRedirectJob::REDIRECT_307_TEMPORARY_REDIRECT,
+ RedirectUtil::ResponseCode::REDIRECT_307_TEMPORARY_REDIRECT,
"Jumbo shrimp");
TestScopedURLInterceptor interceptor(req->url(), std::move(job));
@@ -12481,10 +12281,14 @@ class ZeroRTTResponse : public test_server::BasicHttpResponse {
public:
ZeroRTTResponse(bool zero_rtt, bool send_too_early)
: zero_rtt_(zero_rtt), send_too_early_(send_too_early) {}
+
+ ZeroRTTResponse(const ZeroRTTResponse&) = delete;
+ ZeroRTTResponse& operator=(const ZeroRTTResponse&) = delete;
+
~ZeroRTTResponse() override {}
- void SendResponse(const test_server::SendBytesCallback& send,
- test_server::SendCompleteCallback done) override {
+ void SendResponse(
+ base::WeakPtr<test_server::HttpResponseDelegate> delegate) override {
AddCustomHeader("Vary", "Early-Data");
set_content_type("text/plain");
AddCustomHeader("Cache-Control", "no-cache");
@@ -12499,23 +12303,24 @@ class ZeroRTTResponse : public test_server::BasicHttpResponse {
// Since the EmbeddedTestServer doesn't keep the socket open by default,
// it is explicitly kept alive to allow the remaining leg of the 0RTT
// handshake to be received after the early data.
- send.Run(ToResponseString(), base::DoNothing());
+ delegate->SendResponseHeaders(code(), GetHttpReasonPhrase(code()),
+ BuildHeaders());
+ delegate->SendContents(content(), base::DoNothing());
}
private:
bool zero_rtt_;
bool send_too_early_;
-
- DISALLOW_COPY_AND_ASSIGN(ZeroRTTResponse);
};
std::unique_ptr<test_server::HttpResponse> HandleZeroRTTRequest(
const test_server::HttpRequest& request) {
+ DCHECK(request.ssl_info);
+
if (request.GetURL().path() != "/zerortt")
return nullptr;
- auto iter = request.headers.find("Early-Data");
- bool zero_rtt = iter != request.headers.end() && iter->second == "1";
- return std::make_unique<ZeroRTTResponse>(zero_rtt, false);
+ return std::make_unique<ZeroRTTResponse>(
+ request.ssl_info->early_data_received, false);
}
} // namespace
@@ -12814,13 +12619,14 @@ TEST_F(HTTPSEarlyDataTest, TLSEarlyDataNonIdempotentRequestTest) {
std::unique_ptr<test_server::HttpResponse> HandleTooEarly(
bool* sent_425,
const test_server::HttpRequest& request) {
+ DCHECK(request.ssl_info);
+
if (request.GetURL().path() != "/tooearly")
return nullptr;
- auto iter = request.headers.find("Early-Data");
- bool zero_rtt = iter != request.headers.end() && iter->second == "1";
- if (zero_rtt)
+ if (request.ssl_info->early_data_received)
*sent_425 = true;
- return std::make_unique<ZeroRTTResponse>(zero_rtt, true);
+ return std::make_unique<ZeroRTTResponse>(
+ request.ssl_info->early_data_received, true);
}
// Test that we handle 425 (Too Early) correctly.