blob: b5b94c8c03b23c051ab4f41553ce344154b00baa [file] [log] [blame]
xunjielif24ee5f2015-11-23 18:05:261// Copyright 2015 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "components/cronet/url_request_context_config.h"
6
Gyuyoung Kim6afb5082018-01-19 13:35:577#include <memory>
8
Eric Orthe1cdd902019-02-26 02:52:469#include "base/bind.h"
Hans Wennborgdf87046c2020-04-28 11:06:2410#include "base/check.h"
Julia Tuttle3cc27a4a2018-04-25 15:57:0611#include "base/json/json_writer.h"
Hans Wennborgdf87046c2020-04-28 11:06:2412#include "base/notreached.h"
Jan Wilken Dörriefb1d7b662020-02-04 11:10:2313#include "base/strings/strcat.h"
Douglas Creagera220947e2018-08-23 20:08:5314#include "base/strings/string_piece.h"
Gabriel Charettec7108742019-08-23 03:31:4015#include "base/test/task_environment.h"
Douglas Creagera220947e2018-08-23 20:08:5316#include "base/test/values_test_util.h"
tfhef3618f2016-01-11 23:07:0817#include "base/values.h"
Zhongyi Shiaa518c22018-06-15 04:37:3618#include "build/build_config.h"
Eric Orthe1cdd902019-02-26 02:52:4619#include "net/base/host_port_pair.h"
Matt Menked732ea42019-03-08 12:05:0020#include "net/base/http_user_agent_settings.h"
Eric Orthe1cdd902019-02-26 02:52:4621#include "net/base/net_errors.h"
Matt Menke32a243e2020-05-22 03:40:0922#include "net/base/network_isolation_key.h"
pauljensen9041eb3c2015-12-09 12:29:0123#include "net/cert/cert_verifier.h"
Eric Orthe1cdd902019-02-26 02:52:4624#include "net/dns/host_resolver.h"
Eric Orth607b6d82019-05-08 16:43:3225#include "net/dns/host_resolver_manager.h"
xunjielif24ee5f2015-11-23 18:05:2626#include "net/http/http_network_session.h"
mikecironef22f9812016-10-04 03:40:1927#include "net/log/net_log_with_source.h"
Lily Houghton582d4622018-01-22 22:43:4028#include "net/proxy_resolution/proxy_config.h"
29#include "net/proxy_resolution/proxy_config_service_fixed.h"
xunjielif24ee5f2015-11-23 18:05:2630#include "net/url_request/url_request_context.h"
31#include "net/url_request/url_request_context_builder.h"
32#include "testing/gtest/include/gtest/gtest.h"
33
Douglas Creagera220947e2018-08-23 20:08:5334#if BUILDFLAG(ENABLE_REPORTING)
35#include "net/network_error_logging/network_error_logging_service.h"
36#include "net/reporting/reporting_service.h"
37#endif // BUILDFLAG(ENABLE_REPORTING)
38
xunjielif24ee5f2015-11-23 18:05:2639namespace cronet {
40
Douglas Creagera220947e2018-08-23 20:08:5341namespace {
42
Douglas Creagera220947e2018-08-23 20:08:5343std::string WrapJsonHeader(base::StringPiece value) {
Jan Wilken Dörriefb1d7b662020-02-04 11:10:2344 return base::StrCat({"[", value, "]"});
Douglas Creagera220947e2018-08-23 20:08:5345}
46
47// Returns whether two JSON-encoded headers contain the same content, ignoring
48// irrelevant encoding issues like whitespace and map element ordering.
49bool JsonHeaderEquals(base::StringPiece expected, base::StringPiece actual) {
Lei Zhang9b9d5792019-02-20 07:24:4250 return base::test::ParseJson(WrapJsonHeader(expected)) ==
51 base::test::ParseJson(WrapJsonHeader(actual));
Douglas Creagera220947e2018-08-23 20:08:5352}
53
54} // namespace
55
mmenke51629db12017-06-28 13:34:1256TEST(URLRequestContextConfigTest, TestExperimentalOptionParsing) {
Gabriel Charettedfa36042019-08-19 17:30:1157 base::test::TaskEnvironment task_environment_(
58 base::test::TaskEnvironment::MainThreadType::IO);
mmenke51629db12017-06-28 13:34:1259
Julia Tuttle3cc27a4a2018-04-25 15:57:0660 // Create JSON for experimental options.
61 base::DictionaryValue options;
62 options.SetPath({"QUIC", "max_server_configs_stored_in_properties"},
63 base::Value(2));
64 options.SetPath({"QUIC", "user_agent_id"}, base::Value("Custom QUIC UAID"));
65 options.SetPath({"QUIC", "idle_connection_timeout_seconds"},
66 base::Value(300));
67 options.SetPath({"QUIC", "close_sessions_on_ip_change"}, base::Value(true));
Julia Tuttle3cc27a4a2018-04-25 15:57:0668 options.SetPath({"QUIC", "connection_options"}, base::Value("TIME,TBBR,REJ"));
Ryan Hamiltona31239f12019-09-25 21:01:0069 options.SetPath(
70 {"QUIC", "set_quic_flags"},
David Schinazifb4bb562020-06-19 18:18:3571 base::Value("FLAGS_quic_reloadable_flag_quic_testonly_default_false=true,"
72 "FLAGS_quic_restart_flag_quic_testonly_default_true=false"));
Julia Tuttle3cc27a4a2018-04-25 15:57:0673 options.SetPath({"AsyncDNS", "enable"}, base::Value(true));
74 options.SetPath({"NetworkErrorLogging", "enable"}, base::Value(true));
Douglas Creagera220947e2018-08-23 20:08:5375 options.SetPath({"NetworkErrorLogging", "preloaded_report_to_headers"},
Lei Zhang9b9d5792019-02-20 07:24:4276 base::test::ParseJson(R"json(
Douglas Creagera220947e2018-08-23 20:08:5377 [
78 {
79 "origin": "https://test-origin/",
80 "value": {
81 "group": "test-group",
82 "max_age": 86400,
83 "endpoints": [
84 {"url": "https://test-endpoint/"},
85 ],
86 },
87 },
88 {
89 "origin": "https://test-origin-2/",
90 "value": [
91 {
92 "group": "test-group-2",
93 "max_age": 86400,
94 "endpoints": [
95 {"url": "https://test-endpoint-2/"},
96 ],
97 },
98 {
99 "group": "test-group-3",
100 "max_age": 86400,
101 "endpoints": [
102 {"url": "https://test-endpoint-3/"},
103 ],
104 },
105 ],
106 },
107 {
108 "origin": "https://value-is-missing/",
109 },
110 {
111 "value": "origin is missing",
112 },
113 {
114 "origin": 123,
115 "value": "origin is not a string",
116 },
117 {
118 "origin": "this is not a URL",
119 "value": "origin not a URL",
120 },
121 ]
122 )json"));
123 options.SetPath({"NetworkErrorLogging", "preloaded_nel_headers"},
Lei Zhang9b9d5792019-02-20 07:24:42124 base::test::ParseJson(R"json(
Douglas Creagera220947e2018-08-23 20:08:53125 [
126 {
127 "origin": "https://test-origin/",
128 "value": {
129 "report_to": "test-group",
130 "max_age": 86400,
131 },
132 },
133 ]
134 )json"));
Julia Tuttle3cc27a4a2018-04-25 15:57:06135 options.SetPath({"UnknownOption", "foo"}, base::Value(true));
136 options.SetPath({"HostResolverRules", "host_resolver_rules"},
137 base::Value("MAP * 127.0.0.1"));
138 // See http://crbug.com/696569.
139 options.SetKey("disable_ipv6_on_wifi", base::Value(true));
Yu Suca37f3c2020-10-09 20:02:23140 options.SetPath({"QUIC", "ios_network_service_type"}, base::Value(2));
Julia Tuttle3cc27a4a2018-04-25 15:57:06141 std::string options_json;
142 EXPECT_TRUE(base::JSONWriter::Write(options, &options_json));
143
Ryan Hamiltona31239f12019-09-25 21:01:00144 // Initialize QUIC flags set by the config.
David Schinazifb4bb562020-06-19 18:18:35145 FLAGS_quic_reloadable_flag_quic_testonly_default_false = false;
146 FLAGS_quic_restart_flag_quic_testonly_default_true = true;
Ryan Hamiltona31239f12019-09-25 21:01:00147
pauljensen9041eb3c2015-12-09 12:29:01148 URLRequestContextConfig config(
149 // Enable QUIC.
150 true,
mefc5da5712016-02-09 20:14:23151 // QUIC User Agent ID.
152 "Default QUIC User Agent ID",
pauljensen9041eb3c2015-12-09 12:29:01153 // Enable SPDY.
154 true,
xunjieli186d2bf2017-04-18 13:45:47155 // Enable Brotli.
156 false,
pauljensen9041eb3c2015-12-09 12:29:01157 // Type of http cache.
158 URLRequestContextConfig::HttpCacheType::DISK,
159 // Max size of http cache in bytes.
160 1024000,
161 // Disable caching for HTTP responses. Other information may be stored in
162 // the cache.
163 false,
164 // Storage path for http cache and cookie storage.
165 "/data/data/org.chromium.net/app_cronet_test/test_storage",
Misha Efimovd4ab38302018-01-30 23:56:42166 // Accept-Language request header field.
167 "foreign-language",
pauljensen9041eb3c2015-12-09 12:29:01168 // User-Agent request header field.
169 "fake agent",
170 // JSON encoded experimental options.
Julia Tuttle3cc27a4a2018-04-25 15:57:06171 options_json,
pauljensen9041eb3c2015-12-09 12:29:01172 // MockCertVerifier to use for testing purposes.
tbansal7018e2a2016-06-25 00:40:39173 std::unique_ptr<net::CertVerifier>(),
174 // Enable network quality estimator.
kapishnikov385aa422016-07-01 20:53:02175 false,
176 // Enable Public Key Pinning bypass for local trust anchors.
Paul Jensen6a1ea3a2018-08-24 14:46:41177 true,
178 // Optional network thread priority.
179 base::Optional<double>(42.0));
xunjielif24ee5f2015-11-23 18:05:26180
xunjielif24ee5f2015-11-23 18:05:26181 net::URLRequestContextBuilder builder;
Matt Muellerde5dadf2019-11-27 20:11:58182 config.ConfigureURLRequestContextBuilder(&builder);
xunjielid67295e2017-03-16 21:05:41183 EXPECT_FALSE(config.effective_experimental_options->HasKey("UnknownOption"));
xunjielif24ee5f2015-11-23 18:05:26184 // Set a ProxyConfigService to avoid DCHECK failure when building.
ricea85ec57952016-08-31 09:34:10185 builder.set_proxy_config_service(
Lily Houghtonef028852017-12-06 20:52:30186 std::make_unique<net::ProxyConfigServiceFixed>(
Ramin Halavatica8d5252018-03-12 05:33:49187 net::ProxyConfigWithAnnotation::CreateDirect()));
dchengfe3745e6242016-04-21 23:49:58188 std::unique_ptr<net::URLRequestContext> context(builder.Build());
Victor Vasilieva1e66d72019-12-05 17:55:38189 const net::QuicParams* quic_params = context->quic_context()->params();
xunjielif24ee5f2015-11-23 18:05:26190 // Check Quic Connection options.
Ryan Hamilton8d9ee76e2018-05-29 23:52:52191 quic::QuicTagVector quic_connection_options;
192 quic_connection_options.push_back(quic::kTIME);
193 quic_connection_options.push_back(quic::kTBBR);
194 quic_connection_options.push_back(quic::kREJ);
Victor Vasilieva1e66d72019-12-05 17:55:38195 EXPECT_EQ(quic_connection_options, quic_params->connection_options);
xunjielif24ee5f2015-11-23 18:05:26196
David Schinazifb4bb562020-06-19 18:18:35197 // Check QUIC flags.
198 EXPECT_TRUE(FLAGS_quic_reloadable_flag_quic_testonly_default_false);
199 EXPECT_FALSE(FLAGS_quic_restart_flag_quic_testonly_default_true);
Ryan Hamiltona31239f12019-09-25 21:01:00200
mefc5da5712016-02-09 20:14:23201 // Check Custom QUIC User Agent Id.
Victor Vasilieva1e66d72019-12-05 17:55:38202 EXPECT_EQ("Custom QUIC UAID", quic_params->user_agent_id);
mefc5da5712016-02-09 20:14:23203
rtenneti6971c172016-01-15 20:12:10204 // Check max_server_configs_stored_in_properties.
Victor Vasilieva1e66d72019-12-05 17:55:38205 EXPECT_EQ(2u, quic_params->max_server_configs_stored_in_properties);
xunjielif24ee5f2015-11-23 18:05:26206
Ryan Sleevi2e8255b2019-07-17 21:02:21207 // Check idle_connection_timeout.
Victor Vasilieva1e66d72019-12-05 17:55:38208 EXPECT_EQ(300, quic_params->idle_connection_timeout.InSeconds());
rtenneti64e809d02015-12-11 00:26:20209
Victor Vasilieva1e66d72019-12-05 17:55:38210 EXPECT_TRUE(quic_params->close_sessions_on_ip_change);
211 EXPECT_FALSE(quic_params->goaway_sessions_on_ip_change);
212 EXPECT_FALSE(quic_params->allow_server_migration);
213 EXPECT_FALSE(quic_params->migrate_sessions_on_network_change_v2);
214 EXPECT_FALSE(quic_params->migrate_sessions_early_v2);
215 EXPECT_FALSE(quic_params->migrate_idle_sessions);
216 EXPECT_FALSE(quic_params->retry_on_alternate_network_before_handshake);
217 EXPECT_FALSE(quic_params->race_stale_dns_on_connection);
218 EXPECT_FALSE(quic_params->go_away_on_path_degrading);
Renjie Tang55ba9ae2021-04-30 22:01:05219 EXPECT_FALSE(quic_params->allow_port_migration);
jrid26566952016-02-04 21:06:42220
Yu Suca37f3c2020-10-09 20:02:23221 // Check network_service_type for iOS.
222 EXPECT_EQ(2, quic_params->ios_network_service_type);
223
Misha Efimov63957912017-12-06 07:13:26224#if defined(ENABLE_BUILT_IN_DNS)
225 // Check AsyncDNS resolver is enabled (not supported on iOS).
tfhef3618f2016-01-11 23:07:08226 EXPECT_TRUE(context->host_resolver()->GetDnsConfigAsValue());
Misha Efimov63957912017-12-06 07:13:26227#endif // defined(ENABLE_BUILT_IN_DNS)
mgershaf2c12c2016-08-22 16:33:54228
Julia Tuttle9715d1642018-01-29 17:02:26229#if BUILDFLAG(ENABLE_REPORTING)
230 // Check Reporting and Network Error Logging are enabled (can be disabled at
231 // build time).
232 EXPECT_TRUE(context->reporting_service());
Julia Tuttlecba7d222018-02-23 19:37:27233 EXPECT_TRUE(context->network_error_logging_service());
Julia Tuttle9715d1642018-01-29 17:02:26234#endif // BUILDFLAG(ENABLE_REPORTING)
235
Douglas Creagera220947e2018-08-23 20:08:53236 ASSERT_EQ(2u, config.preloaded_report_to_headers.size());
237 EXPECT_EQ(url::Origin::CreateFromNormalizedTuple("https", "test-origin", 443),
238 config.preloaded_report_to_headers[0].origin);
239 EXPECT_TRUE(JsonHeaderEquals( //
240 R"json(
241 {
242 "group": "test-group",
243 "max_age": 86400,
244 "endpoints": [
245 {"url": "https://test-endpoint/"},
246 ],
247 }
248 )json",
249 config.preloaded_report_to_headers[0].value));
250 EXPECT_EQ(
251 url::Origin::CreateFromNormalizedTuple("https", "test-origin-2", 443),
252 config.preloaded_report_to_headers[1].origin);
253 EXPECT_TRUE(JsonHeaderEquals( //
254 R"json(
255 {
256 "group": "test-group-2",
257 "max_age": 86400,
258 "endpoints": [
259 {"url": "https://test-endpoint-2/"},
260 ],
261 },
262 {
263 "group": "test-group-3",
264 "max_age": 86400,
265 "endpoints": [
266 {"url": "https://test-endpoint-3/"},
267 ],
268 }
269 )json",
270 config.preloaded_report_to_headers[1].value));
271
272 ASSERT_EQ(1u, config.preloaded_nel_headers.size());
273 EXPECT_EQ(url::Origin::CreateFromNormalizedTuple("https", "test-origin", 443),
274 config.preloaded_nel_headers[0].origin);
275 EXPECT_TRUE(JsonHeaderEquals( //
276 R"json(
277 {
278 "report_to": "test-group",
279 "max_age": 86400,
280 }
281 )json",
282 config.preloaded_nel_headers[0].value));
283
mgershaf9a9232017-04-13 20:19:03284 // Check IPv6 is disabled when on wifi.
Eric Orth607b6d82019-05-08 16:43:32285 EXPECT_FALSE(context->host_resolver()
286 ->GetManagerForTesting()
287 ->check_ipv6_on_wifi_for_testing());
mgershb3fe8082017-02-28 20:09:20288
Eric Orthe1cdd902019-02-26 02:52:46289 // All host resolution expected to be mapped to an immediately-resolvable IP.
290 std::unique_ptr<net::HostResolver::ResolveHostRequest> resolve_request =
Matt Menke32a243e2020-05-22 03:40:09291 context->host_resolver()->CreateRequest(
292 net::HostPortPair("abcde", 80), net::NetworkIsolationKey(),
293 net::NetLogWithSource(), base::nullopt);
Eric Orthe1cdd902019-02-26 02:52:46294 EXPECT_EQ(net::OK, resolve_request->Start(
295 base::BindOnce([](int error) { NOTREACHED(); })));
Paul Jensen6a1ea3a2018-08-24 14:46:41296
297 EXPECT_TRUE(config.network_thread_priority);
298 EXPECT_EQ(42.0, config.network_thread_priority.value());
xunjielif24ee5f2015-11-23 18:05:26299}
300
Zhongyi Shi57247962018-11-05 20:03:52301TEST(URLRequestContextConfigTest, SetSupportedQuicVersion) {
David Schinazi84c58bb2020-06-04 20:14:33302 // Note that this test covers the legacy mechanism which relies on
303 // QuicVersionToString. We should now be using ALPNs instead.
Gabriel Charettedfa36042019-08-19 17:30:11304 base::test::TaskEnvironment task_environment_(
305 base::test::TaskEnvironment::MainThreadType::IO);
Zhongyi Shi57247962018-11-05 20:03:52306
David Schinazi84c58bb2020-06-04 20:14:33307 quic::ParsedQuicVersion version =
308 quic::AllSupportedVersionsWithQuicCrypto().front();
309 std::string experimental_options =
310 "{\"QUIC\":{\"quic_version\":\"" +
311 quic::QuicVersionToString(version.transport_version) + "\"}}";
312
Zhongyi Shi57247962018-11-05 20:03:52313 URLRequestContextConfig config(
314 // Enable QUIC.
315 true,
316 // QUIC User Agent ID.
317 "Default QUIC User Agent ID",
318 // Enable SPDY.
319 true,
320 // Enable Brotli.
321 false,
322 // Type of http cache.
323 URLRequestContextConfig::HttpCacheType::DISK,
324 // Max size of http cache in bytes.
325 1024000,
326 // Disable caching for HTTP responses. Other information may be stored in
327 // the cache.
328 false,
329 // Storage path for http cache and cookie storage.
330 "/data/data/org.chromium.net/app_cronet_test/test_storage",
331 // Accept-Language request header field.
332 "foreign-language",
333 // User-Agent request header field.
334 "fake agent",
335 // JSON encoded experimental options.
David Schinazi84c58bb2020-06-04 20:14:33336 experimental_options,
Zhongyi Shi57247962018-11-05 20:03:52337 // MockCertVerifier to use for testing purposes.
338 std::unique_ptr<net::CertVerifier>(),
339 // Enable network quality estimator.
340 false,
341 // Enable Public Key Pinning bypass for local trust anchors.
342 true,
343 // Optional network thread priority.
344 base::Optional<double>());
345
346 net::URLRequestContextBuilder builder;
Matt Muellerde5dadf2019-11-27 20:11:58347 config.ConfigureURLRequestContextBuilder(&builder);
Zhongyi Shi57247962018-11-05 20:03:52348 // Set a ProxyConfigService to avoid DCHECK failure when building.
349 builder.set_proxy_config_service(
350 std::make_unique<net::ProxyConfigServiceFixed>(
351 net::ProxyConfigWithAnnotation::CreateDirect()));
352 std::unique_ptr<net::URLRequestContext> context(builder.Build());
Victor Vasilieva1e66d72019-12-05 17:55:38353 const net::QuicParams* quic_params = context->quic_context()->params();
354 EXPECT_EQ(quic_params->supported_versions.size(), 1u);
David Schinazi84c58bb2020-06-04 20:14:33355 EXPECT_EQ(quic_params->supported_versions[0], version);
Zhongyi Shi57247962018-11-05 20:03:52356}
357
Ryan Hamilton209227b2020-01-17 01:29:05358TEST(URLRequestContextConfigTest, SetSupportedQuicVersionByAlpn) {
359 base::test::TaskEnvironment task_environment_(
360 base::test::TaskEnvironment::MainThreadType::IO);
361
David Schinazi84c58bb2020-06-04 20:14:33362 quic::ParsedQuicVersion version = quic::AllSupportedVersions().front();
363 std::string experimental_options =
364 "{\"QUIC\":{\"quic_version\":\"" + quic::AlpnForVersion(version) + "\"}}";
365
Ryan Hamilton209227b2020-01-17 01:29:05366 URLRequestContextConfig config(
367 // Enable QUIC.
368 true,
369 // QUIC User Agent ID.
370 "Default QUIC User Agent ID",
371 // Enable SPDY.
372 true,
373 // Enable Brotli.
374 false,
375 // Type of http cache.
376 URLRequestContextConfig::HttpCacheType::DISK,
377 // Max size of http cache in bytes.
378 1024000,
379 // Disable caching for HTTP responses. Other information may be stored in
380 // the cache.
381 false,
382 // Storage path for http cache and cookie storage.
383 "/data/data/org.chromium.net/app_cronet_test/test_storage",
384 // Accept-Language request header field.
385 "foreign-language",
386 // User-Agent request header field.
387 "fake agent",
388 // JSON encoded experimental options.
David Schinazi84c58bb2020-06-04 20:14:33389 experimental_options,
Ryan Hamilton209227b2020-01-17 01:29:05390 // MockCertVerifier to use for testing purposes.
391 std::unique_ptr<net::CertVerifier>(),
392 // Enable network quality estimator.
393 false,
394 // Enable Public Key Pinning bypass for local trust anchors.
395 true,
396 // Optional network thread priority.
397 base::Optional<double>());
398
399 net::URLRequestContextBuilder builder;
400 config.ConfigureURLRequestContextBuilder(&builder);
401 // Set a ProxyConfigService to avoid DCHECK failure when building.
402 builder.set_proxy_config_service(
403 std::make_unique<net::ProxyConfigServiceFixed>(
404 net::ProxyConfigWithAnnotation::CreateDirect()));
405 std::unique_ptr<net::URLRequestContext> context(builder.Build());
406 const net::QuicParams* quic_params = context->quic_context()->params();
407 EXPECT_EQ(quic_params->supported_versions.size(), 1u);
David Schinazi84c58bb2020-06-04 20:14:33408 EXPECT_EQ(quic_params->supported_versions[0], version);
Ryan Hamilton209227b2020-01-17 01:29:05409}
410
Zhongyi Shi57247962018-11-05 20:03:52411TEST(URLRequestContextConfigTest, SetUnsupportedQuicVersion) {
Gabriel Charettedfa36042019-08-19 17:30:11412 base::test::TaskEnvironment task_environment_(
413 base::test::TaskEnvironment::MainThreadType::IO);
Zhongyi Shi57247962018-11-05 20:03:52414
415 URLRequestContextConfig config(
416 // Enable QUIC.
417 true,
418 // QUIC User Agent ID.
419 "Default QUIC User Agent ID",
420 // Enable SPDY.
421 true,
422 // Enable Brotli.
423 false,
424 // Type of http cache.
425 URLRequestContextConfig::HttpCacheType::DISK,
426 // Max size of http cache in bytes.
427 1024000,
428 // Disable caching for HTTP responses. Other information may be stored in
429 // the cache.
430 false,
431 // Storage path for http cache and cookie storage.
432 "/data/data/org.chromium.net/app_cronet_test/test_storage",
433 // Accept-Language request header field.
434 "foreign-language",
435 // User-Agent request header field.
436 "fake agent",
437 // JSON encoded experimental options.
David Schinazi84c58bb2020-06-04 20:14:33438 "{\"QUIC\":{\"quic_version\":\"h3-Q047\"}}",
Zhongyi Shi57247962018-11-05 20:03:52439 // MockCertVerifier to use for testing purposes.
440 std::unique_ptr<net::CertVerifier>(),
441 // Enable network quality estimator.
442 false,
443 // Enable Public Key Pinning bypass for local trust anchors.
444 true,
445 // Optional network thread priority.
446 base::Optional<double>());
447
448 net::URLRequestContextBuilder builder;
Matt Muellerde5dadf2019-11-27 20:11:58449 config.ConfigureURLRequestContextBuilder(&builder);
Zhongyi Shi57247962018-11-05 20:03:52450 // Set a ProxyConfigService to avoid DCHECK failure when building.
451 builder.set_proxy_config_service(
452 std::make_unique<net::ProxyConfigServiceFixed>(
453 net::ProxyConfigWithAnnotation::CreateDirect()));
454 std::unique_ptr<net::URLRequestContext> context(builder.Build());
Victor Vasilieva1e66d72019-12-05 17:55:38455 const net::QuicParams* quic_params = context->quic_context()->params();
David Schinazi1c76e032020-09-19 00:54:14456 EXPECT_EQ(quic_params->supported_versions,
457 net::DefaultSupportedQuicVersions());
Zhongyi Shi57247962018-11-05 20:03:52458}
459
David Schinaziabbf02502020-09-25 10:29:31460TEST(URLRequestContextConfigTest, SetObsoleteQuicVersion) {
461 // This test configures cronet with an obsolete QUIC version and validates
462 // that cronet ignores that version and uses the default versions.
463 base::test::TaskEnvironment task_environment_(
464 base::test::TaskEnvironment::MainThreadType::IO);
465
466 URLRequestContextConfig config(
467 // Enable QUIC.
468 true,
469 // QUIC User Agent ID.
470 "Default QUIC User Agent ID",
471 // Enable SPDY.
472 true,
473 // Enable Brotli.
474 false,
475 // Type of http cache.
476 URLRequestContextConfig::HttpCacheType::DISK,
477 // Max size of http cache in bytes.
478 1024000,
479 // Disable caching for HTTP responses. Other information may be stored in
480 // the cache.
481 false,
482 // Storage path for http cache and cookie storage.
483 "/data/data/org.chromium.net/app_cronet_test/test_storage",
484 // Accept-Language request header field.
485 "foreign-language",
486 // User-Agent request header field.
487 "fake agent",
488 // JSON encoded experimental options.
489 std::string("{\"QUIC\":{\"quic_version\":\"") +
490 quic::AlpnForVersion(net::ObsoleteQuicVersions().back()) + "\"}}",
491 // MockCertVerifier to use for testing purposes.
492 std::unique_ptr<net::CertVerifier>(),
493 // Enable network quality estimator.
494 false,
495 // Enable Public Key Pinning bypass for local trust anchors.
496 true,
497 // Optional network thread priority.
498 base::Optional<double>());
499
500 net::URLRequestContextBuilder builder;
501 config.ConfigureURLRequestContextBuilder(&builder);
502 // Set a ProxyConfigService to avoid DCHECK failure when building.
503 builder.set_proxy_config_service(
504 std::make_unique<net::ProxyConfigServiceFixed>(
505 net::ProxyConfigWithAnnotation::CreateDirect()));
506 std::unique_ptr<net::URLRequestContext> context(builder.Build());
507 const net::QuicParams* quic_params = context->quic_context()->params();
508 EXPECT_EQ(quic_params->supported_versions,
509 net::DefaultSupportedQuicVersions());
510}
511
512TEST(URLRequestContextConfigTest, SetObsoleteQuicVersionWhenAllowed) {
513 // This test configures cronet with an obsolete QUIC version and explicitly
514 // allows it, then validates that cronet uses that version.
515 base::test::TaskEnvironment task_environment_(
516 base::test::TaskEnvironment::MainThreadType::IO);
517
518 URLRequestContextConfig config(
519 // Enable QUIC.
520 true,
521 // QUIC User Agent ID.
522 "Default QUIC User Agent ID",
523 // Enable SPDY.
524 true,
525 // Enable Brotli.
526 false,
527 // Type of http cache.
528 URLRequestContextConfig::HttpCacheType::DISK,
529 // Max size of http cache in bytes.
530 1024000,
531 // Disable caching for HTTP responses. Other information may be stored in
532 // the cache.
533 false,
534 // Storage path for http cache and cookie storage.
535 "/data/data/org.chromium.net/app_cronet_test/test_storage",
536 // Accept-Language request header field.
537 "foreign-language",
538 // User-Agent request header field.
539 "fake agent",
540 // JSON encoded experimental options.
541 std::string("{\"QUIC\":{\"quic_version\":\"") +
542 quic::AlpnForVersion(net::ObsoleteQuicVersions().back()) +
543 "\",\"obsolete_versions_allowed\":true}}",
544 // MockCertVerifier to use for testing purposes.
545 std::unique_ptr<net::CertVerifier>(),
546 // Enable network quality estimator.
547 false,
548 // Enable Public Key Pinning bypass for local trust anchors.
549 true,
550 // Optional network thread priority.
551 base::Optional<double>());
552
553 net::URLRequestContextBuilder builder;
554 config.ConfigureURLRequestContextBuilder(&builder);
555 // Set a ProxyConfigService to avoid DCHECK failure when building.
556 builder.set_proxy_config_service(
557 std::make_unique<net::ProxyConfigServiceFixed>(
558 net::ProxyConfigWithAnnotation::CreateDirect()));
559 std::unique_ptr<net::URLRequestContext> context(builder.Build());
560 const net::QuicParams* quic_params = context->quic_context()->params();
561 quic::ParsedQuicVersionVector supported_versions = {
562 net::ObsoleteQuicVersions().back()};
563 EXPECT_EQ(quic_params->supported_versions, supported_versions);
564}
565
Zhongyi Shi8ff38c12018-02-22 00:02:30566TEST(URLRequestContextConfigTest, SetQuicServerMigrationOptions) {
Gabriel Charettedfa36042019-08-19 17:30:11567 base::test::TaskEnvironment task_environment_(
568 base::test::TaskEnvironment::MainThreadType::IO);
Zhongyi Shi8ff38c12018-02-22 00:02:30569
570 URLRequestContextConfig config(
571 // Enable QUIC.
572 true,
573 // QUIC User Agent ID.
574 "Default QUIC User Agent ID",
575 // Enable SPDY.
576 true,
577 // Enable Brotli.
578 false,
579 // Type of http cache.
580 URLRequestContextConfig::HttpCacheType::DISK,
581 // Max size of http cache in bytes.
582 1024000,
583 // Disable caching for HTTP responses. Other information may be stored in
584 // the cache.
585 false,
586 // Storage path for http cache and cookie storage.
587 "/data/data/org.chromium.net/app_cronet_test/test_storage",
588 // Accept-Language request header field.
589 "foreign-language",
590 // User-Agent request header field.
591 "fake agent",
592 // JSON encoded experimental options.
593 "{\"QUIC\":{\"allow_server_migration\":true}}",
594 // MockCertVerifier to use for testing purposes.
595 std::unique_ptr<net::CertVerifier>(),
596 // Enable network quality estimator.
597 false,
598 // Enable Public Key Pinning bypass for local trust anchors.
Paul Jensen6a1ea3a2018-08-24 14:46:41599 true,
600 // Optional network thread priority.
601 base::Optional<double>());
Zhongyi Shi8ff38c12018-02-22 00:02:30602
603 net::URLRequestContextBuilder builder;
Matt Muellerde5dadf2019-11-27 20:11:58604 config.ConfigureURLRequestContextBuilder(&builder);
Zhongyi Shi8ff38c12018-02-22 00:02:30605 // Set a ProxyConfigService to avoid DCHECK failure when building.
606 builder.set_proxy_config_service(
607 std::make_unique<net::ProxyConfigServiceFixed>(
Ramin Halavatica8d5252018-03-12 05:33:49608 net::ProxyConfigWithAnnotation::CreateDirect()));
Zhongyi Shi8ff38c12018-02-22 00:02:30609 std::unique_ptr<net::URLRequestContext> context(builder.Build());
Victor Vasilieva1e66d72019-12-05 17:55:38610 const net::QuicParams* quic_params = context->quic_context()->params();
Zhongyi Shi8ff38c12018-02-22 00:02:30611
Victor Vasilieva1e66d72019-12-05 17:55:38612 EXPECT_FALSE(quic_params->close_sessions_on_ip_change);
613 EXPECT_TRUE(quic_params->allow_server_migration);
Zhongyi Shi8ff38c12018-02-22 00:02:30614}
615
Zhongyi Shiaa518c22018-06-15 04:37:36616// Test that goaway_sessions_on_ip_change is set on by default for iOS.
617#if defined(OS_IOS)
618#define MAYBE_SetQuicGoAwaySessionsOnIPChangeByDefault \
619 SetQuicGoAwaySessionsOnIPChangeByDefault
620#else
621#define MAYBE_SetQuicGoAwaySessionsOnIPChangeByDefault \
622 DISABLED_SetQuicGoAwaySessionsOnIPChangeByDefault
623#endif
624TEST(URLRequestContextConfigTest,
625 MAYBE_SetQuicGoAwaySessionsOnIPChangeByDefault) {
Gabriel Charettedfa36042019-08-19 17:30:11626 base::test::TaskEnvironment task_environment_(
627 base::test::TaskEnvironment::MainThreadType::IO);
Zhongyi Shiaa518c22018-06-15 04:37:36628
629 URLRequestContextConfig config(
630 // Enable QUIC.
631 true,
632 // QUIC User Agent ID.
633 "Default QUIC User Agent ID",
634 // Enable SPDY.
635 true,
636 // Enable Brotli.
637 false,
638 // Type of http cache.
639 URLRequestContextConfig::HttpCacheType::DISK,
640 // Max size of http cache in bytes.
641 1024000,
642 // Disable caching for HTTP responses. Other information may be stored in
643 // the cache.
644 false,
645 // Storage path for http cache and cookie storage.
646 "/data/data/org.chromium.net/app_cronet_test/test_storage",
647 // Accept-Language request header field.
648 "foreign-language",
649 // User-Agent request header field.
650 "fake agent",
651 // JSON encoded experimental options.
652 "{\"QUIC\":{}}",
653 // MockCertVerifier to use for testing purposes.
654 std::unique_ptr<net::CertVerifier>(),
655 // Enable network quality estimator.
656 false,
657 // Enable Public Key Pinning bypass for local trust anchors.
Paul Jensen6a1ea3a2018-08-24 14:46:41658 true,
659 // Optional network thread priority.
660 base::Optional<double>());
Zhongyi Shiaa518c22018-06-15 04:37:36661
662 net::URLRequestContextBuilder builder;
Matt Muellerde5dadf2019-11-27 20:11:58663 config.ConfigureURLRequestContextBuilder(&builder);
Zhongyi Shiaa518c22018-06-15 04:37:36664 // Set a ProxyConfigService to avoid DCHECK failure when building.
665 builder.set_proxy_config_service(
666 std::make_unique<net::ProxyConfigServiceFixed>(
667 net::ProxyConfigWithAnnotation::CreateDirect()));
668 std::unique_ptr<net::URLRequestContext> context(builder.Build());
Victor Vasilieva1e66d72019-12-05 17:55:38669 const net::QuicParams* quic_params = context->quic_context()->params();
Zhongyi Shiaa518c22018-06-15 04:37:36670
Victor Vasilieva1e66d72019-12-05 17:55:38671 EXPECT_FALSE(quic_params->close_sessions_on_ip_change);
672 EXPECT_TRUE(quic_params->goaway_sessions_on_ip_change);
Zhongyi Shiaa518c22018-06-15 04:37:36673}
674
675// Tests that goaway_sessions_on_ip_changes can be set on via
676// experimental options on non-iOS.
677#if !defined(OS_IOS)
678#define MAYBE_SetQuicGoAwaySessionsOnIPChangeViaExperimentOptions \
679 SetQuicGoAwaySessionsOnIPChangeViaExperimentOptions
680#else
681#define MAYBE_SetQuicGoAwaySessionsOnIPChangeViaExperimentOptions \
682 DISABLED_SetQuicGoAwaySessionsOnIPChangeViaExperimentOptions
683#endif
684TEST(URLRequestContextConfigTest,
685 MAYBE_SetQuicGoAwaySessionsOnIPChangeViaExperimentOptions) {
Gabriel Charettedfa36042019-08-19 17:30:11686 base::test::TaskEnvironment task_environment_(
687 base::test::TaskEnvironment::MainThreadType::IO);
Zhongyi Shi63574b72018-06-01 20:22:25688
689 URLRequestContextConfig config(
690 // Enable QUIC.
691 true,
692 // QUIC User Agent ID.
693 "Default QUIC User Agent ID",
694 // Enable SPDY.
695 true,
696 // Enable Brotli.
697 false,
698 // Type of http cache.
699 URLRequestContextConfig::HttpCacheType::DISK,
700 // Max size of http cache in bytes.
701 1024000,
702 // Disable caching for HTTP responses. Other information may be stored in
703 // the cache.
704 false,
705 // Storage path for http cache and cookie storage.
706 "/data/data/org.chromium.net/app_cronet_test/test_storage",
707 // Accept-Language request header field.
708 "foreign-language",
709 // User-Agent request header field.
710 "fake agent",
711 // JSON encoded experimental options.
712 "{\"QUIC\":{\"goaway_sessions_on_ip_change\":true}}",
713 // MockCertVerifier to use for testing purposes.
714 std::unique_ptr<net::CertVerifier>(),
715 // Enable network quality estimator.
716 false,
717 // Enable Public Key Pinning bypass for local trust anchors.
Paul Jensen6a1ea3a2018-08-24 14:46:41718 true,
719 // Optional network thread priority.
720 base::Optional<double>());
Zhongyi Shi63574b72018-06-01 20:22:25721
722 net::URLRequestContextBuilder builder;
Matt Muellerde5dadf2019-11-27 20:11:58723 config.ConfigureURLRequestContextBuilder(&builder);
Zhongyi Shi63574b72018-06-01 20:22:25724 // Set a ProxyConfigService to avoid DCHECK failure when building.
725 builder.set_proxy_config_service(
726 std::make_unique<net::ProxyConfigServiceFixed>(
727 net::ProxyConfigWithAnnotation::CreateDirect()));
728 std::unique_ptr<net::URLRequestContext> context(builder.Build());
Victor Vasilieva1e66d72019-12-05 17:55:38729 const net::QuicParams* quic_params = context->quic_context()->params();
Zhongyi Shi63574b72018-06-01 20:22:25730
Victor Vasilieva1e66d72019-12-05 17:55:38731 EXPECT_FALSE(quic_params->close_sessions_on_ip_change);
732 EXPECT_TRUE(quic_params->goaway_sessions_on_ip_change);
Zhongyi Shi63574b72018-06-01 20:22:25733}
734
Zhongyi Shiaa518c22018-06-15 04:37:36735// Test that goaway_sessions_on_ip_change can be set to false via
736// exprimental options on iOS.
737#if defined(OS_IOS)
738#define MAYBE_DisableQuicGoAwaySessionsOnIPChangeViaExperimentOptions \
739 DisableQuicGoAwaySessionsOnIPChangeViaExperimentOptions
740#else
741#define MAYBE_DisableQuicGoAwaySessionsOnIPChangeViaExperimentOptions \
742 DISABLED_DisableQuicGoAwaySessionsOnIPChangeViaExperimentOptions
743#endif
744TEST(URLRequestContextConfigTest,
745 MAYBE_DisableQuicGoAwaySessionsOnIPChangeViaExperimentOptions) {
Gabriel Charettedfa36042019-08-19 17:30:11746 base::test::TaskEnvironment task_environment_(
747 base::test::TaskEnvironment::MainThreadType::IO);
Zhongyi Shiaa518c22018-06-15 04:37:36748
749 URLRequestContextConfig config(
750 // Enable QUIC.
751 true,
752 // QUIC User Agent ID.
753 "Default QUIC User Agent ID",
754 // Enable SPDY.
755 true,
756 // Enable Brotli.
757 false,
758 // Type of http cache.
759 URLRequestContextConfig::HttpCacheType::DISK,
760 // Max size of http cache in bytes.
761 1024000,
762 // Disable caching for HTTP responses. Other information may be stored in
763 // the cache.
764 false,
765 // Storage path for http cache and cookie storage.
766 "/data/data/org.chromium.net/app_cronet_test/test_storage",
767 // Accept-Language request header field.
768 "foreign-language",
769 // User-Agent request header field.
770 "fake agent",
771 // JSON encoded experimental options.
772 "{\"QUIC\":{\"goaway_sessions_on_ip_change\":false}}",
773 // MockCertVerifier to use for testing purposes.
774 std::unique_ptr<net::CertVerifier>(),
775 // Enable network quality estimator.
776 false,
777 // Enable Public Key Pinning bypass for local trust anchors.
Paul Jensen6a1ea3a2018-08-24 14:46:41778 true,
779 // Optional network thread priority.
780 base::Optional<double>());
Zhongyi Shiaa518c22018-06-15 04:37:36781
782 net::URLRequestContextBuilder builder;
Matt Muellerde5dadf2019-11-27 20:11:58783 config.ConfigureURLRequestContextBuilder(&builder);
Zhongyi Shiaa518c22018-06-15 04:37:36784 // Set a ProxyConfigService to avoid DCHECK failure when building.
785 builder.set_proxy_config_service(
786 std::make_unique<net::ProxyConfigServiceFixed>(
787 net::ProxyConfigWithAnnotation::CreateDirect()));
788 std::unique_ptr<net::URLRequestContext> context(builder.Build());
Victor Vasilieva1e66d72019-12-05 17:55:38789 const net::QuicParams* quic_params = context->quic_context()->params();
Zhongyi Shiaa518c22018-06-15 04:37:36790
Victor Vasilieva1e66d72019-12-05 17:55:38791 EXPECT_FALSE(quic_params->close_sessions_on_ip_change);
792 EXPECT_FALSE(quic_params->goaway_sessions_on_ip_change);
Zhongyi Shiaa518c22018-06-15 04:37:36793}
794
Yixin Wang10f477ed2017-11-21 04:20:20795TEST(URLRequestContextConfigTest, SetQuicConnectionMigrationV2Options) {
Gabriel Charettedfa36042019-08-19 17:30:11796 base::test::TaskEnvironment task_environment_(
797 base::test::TaskEnvironment::MainThreadType::IO);
Zhongyi Shi64795622017-11-20 02:21:49798
799 URLRequestContextConfig config(
800 // Enable QUIC.
801 true,
802 // QUIC User Agent ID.
803 "Default QUIC User Agent ID",
804 // Enable SPDY.
805 true,
806 // Enable Brotli.
807 false,
808 // Type of http cache.
809 URLRequestContextConfig::HttpCacheType::DISK,
810 // Max size of http cache in bytes.
811 1024000,
812 // Disable caching for HTTP responses. Other information may be stored in
813 // the cache.
814 false,
815 // Storage path for http cache and cookie storage.
816 "/data/data/org.chromium.net/app_cronet_test/test_storage",
Misha Efimovd4ab38302018-01-30 23:56:42817 // Accept-Language request header field.
818 "foreign-language",
Zhongyi Shi64795622017-11-20 02:21:49819 // User-Agent request header field.
820 "fake agent",
821 // JSON encoded experimental options.
Zhongyi Shid02a48c2019-08-27 21:03:58822 // Explicitly turn off "goaway_sessions_on_ip_change" which is default
823 // enabled on iOS but cannot be simultaneously set with migration option.
Zhongyi Shif4683a32017-12-01 00:03:28824 "{\"QUIC\":{\"migrate_sessions_on_network_change_v2\":true,"
Zhongyi Shid02a48c2019-08-27 21:03:58825 "\"goaway_sessions_on_ip_change\":false,"
Zhongyi Shi73f23ca872017-12-13 18:37:13826 "\"migrate_sessions_early_v2\":true,"
Zhongyi Shiff359581bc2018-09-26 18:11:48827 "\"retry_on_alternate_network_before_handshake\":true,"
Zhongyi Shi32fe14d42019-02-28 00:25:36828 "\"migrate_idle_sessions\":true,"
Zhongyi Shie01f2db2019-02-22 19:53:23829 "\"retransmittable_on_wire_timeout_milliseconds\":1000,"
Zhongyi Shibc85e3e2019-02-12 19:34:42830 "\"idle_session_migration_period_seconds\":15,"
Zhongyi Shi8b1e43f2017-12-13 20:46:30831 "\"max_time_on_non_default_network_seconds\":10,"
Zhongyi Shiee760762018-08-01 00:54:29832 "\"max_migrations_to_non_default_network_on_write_error\":3,"
Zhongyi Shi8b1e43f2017-12-13 20:46:30833 "\"max_migrations_to_non_default_network_on_path_degrading\":4}}",
Zhongyi Shi64795622017-11-20 02:21:49834 // MockCertVerifier to use for testing purposes.
835 std::unique_ptr<net::CertVerifier>(),
836 // Enable network quality estimator.
837 false,
838 // Enable Public Key Pinning bypass for local trust anchors.
Paul Jensen6a1ea3a2018-08-24 14:46:41839 true,
840 // Optional network thread priority.
841 base::Optional<double>());
Zhongyi Shi64795622017-11-20 02:21:49842
843 net::URLRequestContextBuilder builder;
Matt Muellerde5dadf2019-11-27 20:11:58844 config.ConfigureURLRequestContextBuilder(&builder);
Zhongyi Shi64795622017-11-20 02:21:49845 // Set a ProxyConfigService to avoid DCHECK failure when building.
846 builder.set_proxy_config_service(
Lily Houghtonef028852017-12-06 20:52:30847 std::make_unique<net::ProxyConfigServiceFixed>(
Ramin Halavatica8d5252018-03-12 05:33:49848 net::ProxyConfigWithAnnotation::CreateDirect()));
Zhongyi Shi64795622017-11-20 02:21:49849 std::unique_ptr<net::URLRequestContext> context(builder.Build());
Victor Vasilieva1e66d72019-12-05 17:55:38850 const net::QuicParams* quic_params = context->quic_context()->params();
Zhongyi Shi64795622017-11-20 02:21:49851
Victor Vasilieva1e66d72019-12-05 17:55:38852 EXPECT_TRUE(quic_params->migrate_sessions_on_network_change_v2);
853 EXPECT_TRUE(quic_params->migrate_sessions_early_v2);
854 EXPECT_TRUE(quic_params->retry_on_alternate_network_before_handshake);
855 EXPECT_EQ(1000,
856 quic_params->retransmittable_on_wire_timeout.InMilliseconds());
857 EXPECT_TRUE(quic_params->migrate_idle_sessions);
Zhongyi Shibc85e3e2019-02-12 19:34:42858 EXPECT_EQ(base::TimeDelta::FromSeconds(15),
Victor Vasilieva1e66d72019-12-05 17:55:38859 quic_params->idle_session_migration_period);
Zhongyi Shi73f23ca872017-12-13 18:37:13860 EXPECT_EQ(base::TimeDelta::FromSeconds(10),
Victor Vasilieva1e66d72019-12-05 17:55:38861 quic_params->max_time_on_non_default_network);
862 EXPECT_EQ(3,
863 quic_params->max_migrations_to_non_default_network_on_write_error);
Zhongyi Shi8b1e43f2017-12-13 20:46:30864 EXPECT_EQ(
Victor Vasilieva1e66d72019-12-05 17:55:38865 4, quic_params->max_migrations_to_non_default_network_on_path_degrading);
David Schinazi07c4661b2021-02-18 02:32:10866 EXPECT_EQ(quic::ParsedQuicVersionVector{quic::ParsedQuicVersion::Q050()},
867 quic_params->supported_versions);
Zhongyi Shi64795622017-11-20 02:21:49868}
869
Renjie94b90712018-10-18 21:03:19870TEST(URLRequestContextConfigTest, SetQuicStaleDNSracing) {
Gabriel Charettedfa36042019-08-19 17:30:11871 base::test::TaskEnvironment task_environment_(
872 base::test::TaskEnvironment::MainThreadType::IO);
Renjie94b90712018-10-18 21:03:19873
874 URLRequestContextConfig config(
875 // Enable QUIC.
876 true,
877 // QUIC User Agent ID.
878 "Default QUIC User Agent ID",
879 // Enable SPDY.
880 true,
881 // Enable Brotli.
882 false,
883 // Type of http cache.
884 URLRequestContextConfig::HttpCacheType::DISK,
885 // Max size of http cache in bytes.
886 1024000,
887 // Disable caching for HTTP responses. Other information may be stored in
888 // the cache.
889 false,
890 // Storage path for http cache and cookie storage.
891 "/data/data/org.chromium.net/app_cronet_test/test_storage",
892 // Accept-Language request header field.
893 "foreign-language",
894 // User-Agent request header field.
895 "fake agent",
896 // JSON encoded experimental options.
897 "{\"QUIC\":{\"race_stale_dns_on_connection\":true}}",
898 // MockCertVerifier to use for testing purposes.
899 std::unique_ptr<net::CertVerifier>(),
900 // Enable network quality estimator.
901 false,
902 // Enable Public Key Pinning bypass for local trust anchors.
903 true,
904 // Optional network thread priority.
905 base::Optional<double>());
906
907 net::URLRequestContextBuilder builder;
Matt Muellerde5dadf2019-11-27 20:11:58908 config.ConfigureURLRequestContextBuilder(&builder);
Renjie94b90712018-10-18 21:03:19909 // Set a ProxyConfigService to avoid DCHECK failure when building.
910 builder.set_proxy_config_service(
911 std::make_unique<net::ProxyConfigServiceFixed>(
912 net::ProxyConfigWithAnnotation::CreateDirect()));
913 std::unique_ptr<net::URLRequestContext> context(builder.Build());
Victor Vasilieva1e66d72019-12-05 17:55:38914 const net::QuicParams* quic_params = context->quic_context()->params();
Renjie94b90712018-10-18 21:03:19915
Victor Vasilieva1e66d72019-12-05 17:55:38916 EXPECT_TRUE(quic_params->race_stale_dns_on_connection);
Renjie94b90712018-10-18 21:03:19917}
918
Renjie Tang55ba9ae2021-04-30 22:01:05919TEST(URLRequestContextConfigTest, SetQuicAllowPortMigration) {
920 base::test::TaskEnvironment task_environment_(
921 base::test::TaskEnvironment::MainThreadType::IO);
922 URLRequestContextConfig config(
923 // Enable QUIC.
924 true,
925 // QUIC User Agent ID.
926 "Default QUIC User Agent ID",
927 // Enable SPDY.
928 true,
929 // Enable Brotli.
930 false,
931 // Type of http cache.
932 URLRequestContextConfig::HttpCacheType::DISK,
933 // Max size of http cache in bytes.
934 1024000,
935 // Disable caching for HTTP responses. Other information may be stored in
936 // the cache.
937 false,
938 // Storage path for http cache and cookie storage.
939 "/data/data/org.chromium.net/app_cronet_test/test_storage",
940 // Accept-Language request header field.
941 "foreign-language",
942 // User-Agent request header field.
943 "fake agent",
944 // JSON encoded experimental options.
945 "{\"QUIC\":{\"allow_port_migration\":true}}",
946 // MockCertVerifier to use for testing purposes.
947 std::unique_ptr<net::CertVerifier>(),
948 // Enable network quality estimator.
949 false,
950 // Enable Public Key Pinning bypass for local trust anchors.
951 true,
952 // Optional network thread priority.
953 base::Optional<double>());
954
955 net::URLRequestContextBuilder builder;
956 config.ConfigureURLRequestContextBuilder(&builder);
957 // Set a ProxyConfigService to avoid DCHECK failure when building.
958 builder.set_proxy_config_service(
959 std::make_unique<net::ProxyConfigServiceFixed>(
960 net::ProxyConfigWithAnnotation::CreateDirect()));
961 std::unique_ptr<net::URLRequestContext> context(builder.Build());
962 const net::QuicParams* quic_params = context->quic_context()->params();
963
964 EXPECT_TRUE(quic_params->allow_port_migration);
965}
966
Renjie Tangcbbc84c2019-09-06 22:23:23967TEST(URLRequestContextConfigTest, SetQuicGoawayOnPathDegrading) {
968 base::test::TaskEnvironment task_environment_(
969 base::test::TaskEnvironment::MainThreadType::IO);
970
971 URLRequestContextConfig config(
972 // Enable QUIC.
973 true,
974 // QUIC User Agent ID.
975 "Default QUIC User Agent ID",
976 // Enable SPDY.
977 true,
978 // Enable Brotli.
979 false,
980 // Type of http cache.
981 URLRequestContextConfig::HttpCacheType::DISK,
982 // Max size of http cache in bytes.
983 1024000,
984 // Disable caching for HTTP responses. Other information may be stored in
985 // the cache.
986 false,
987 // Storage path for http cache and cookie storage.
988 "/data/data/org.chromium.net/app_cronet_test/test_storage",
989 // Accept-Language request header field.
990 "foreign-language",
991 // User-Agent request header field.
992 "fake agent",
993 // JSON encoded experimental options.
994 "{\"QUIC\":{\"go_away_on_path_degrading\":true}}",
995 // MockCertVerifier to use for testing purposes.
996 std::unique_ptr<net::CertVerifier>(),
997 // Enable network quality estimator.
998 false,
999 // Enable Public Key Pinning bypass for local trust anchors.
1000 true,
1001 // Optional network thread priority.
1002 base::Optional<double>());
1003
1004 net::URLRequestContextBuilder builder;
Matt Muellerde5dadf2019-11-27 20:11:581005 config.ConfigureURLRequestContextBuilder(&builder);
Renjie Tangcbbc84c2019-09-06 22:23:231006 // Set a ProxyConfigService to avoid DCHECK failure when building.
1007 builder.set_proxy_config_service(
1008 std::make_unique<net::ProxyConfigServiceFixed>(
1009 net::ProxyConfigWithAnnotation::CreateDirect()));
1010 std::unique_ptr<net::URLRequestContext> context(builder.Build());
Victor Vasilieva1e66d72019-12-05 17:55:381011 const net::QuicParams* quic_params = context->quic_context()->params();
Renjie Tangcbbc84c2019-09-06 22:23:231012
Victor Vasilieva1e66d72019-12-05 17:55:381013 EXPECT_TRUE(quic_params->go_away_on_path_degrading);
Renjie Tangcbbc84c2019-09-06 22:23:231014}
1015
Yixin Wang10f477ed2017-11-21 04:20:201016TEST(URLRequestContextConfigTest, SetQuicHostWhitelist) {
Gabriel Charettedfa36042019-08-19 17:30:111017 base::test::TaskEnvironment task_environment_(
1018 base::test::TaskEnvironment::MainThreadType::IO);
Yixin Wang10f477ed2017-11-21 04:20:201019
1020 URLRequestContextConfig config(
1021 // Enable QUIC.
1022 true,
1023 // QUIC User Agent ID.
1024 "Default QUIC User Agent ID",
1025 // Enable SPDY.
1026 true,
1027 // Enable Brotli.
1028 false,
1029 // Type of http cache.
1030 URLRequestContextConfig::HttpCacheType::DISK,
1031 // Max size of http cache in bytes.
1032 1024000,
1033 // Disable caching for HTTP responses. Other information may be stored in
1034 // the cache.
1035 false,
1036 // Storage path for http cache and cookie storage.
1037 "/data/data/org.chromium.net/app_cronet_test/test_storage",
Misha Efimovd4ab38302018-01-30 23:56:421038 // Accept-Language request header field.
1039 "foreign-language",
Yixin Wang10f477ed2017-11-21 04:20:201040 // User-Agent request header field.
1041 "fake agent",
1042 // JSON encoded experimental options.
1043 "{\"QUIC\":{\"host_whitelist\":\"www.example.com,www.example.org\"}}",
1044 // MockCertVerifier to use for testing purposes.
1045 std::unique_ptr<net::CertVerifier>(),
1046 // Enable network quality estimator.
1047 false,
1048 // Enable Public Key Pinning bypass for local trust anchors.
Paul Jensen6a1ea3a2018-08-24 14:46:411049 true,
1050 // Optional network thread priority.
1051 base::Optional<double>());
Yixin Wang10f477ed2017-11-21 04:20:201052
1053 net::URLRequestContextBuilder builder;
Matt Muellerde5dadf2019-11-27 20:11:581054 config.ConfigureURLRequestContextBuilder(&builder);
Yixin Wang10f477ed2017-11-21 04:20:201055 // Set a ProxyConfigService to avoid DCHECK failure when building.
1056 builder.set_proxy_config_service(
Lily Houghtonef028852017-12-06 20:52:301057 std::make_unique<net::ProxyConfigServiceFixed>(
Ramin Halavatica8d5252018-03-12 05:33:491058 net::ProxyConfigWithAnnotation::CreateDirect()));
Yixin Wang10f477ed2017-11-21 04:20:201059 std::unique_ptr<net::URLRequestContext> context(builder.Build());
1060 const net::HttpNetworkSession::Params* params =
1061 context->GetNetworkSessionParams();
1062
Ryan Sleevia9d6aa62019-07-26 13:32:181063 EXPECT_TRUE(base::Contains(params->quic_host_allowlist, "www.example.com"));
1064 EXPECT_TRUE(base::Contains(params->quic_host_allowlist, "www.example.org"));
Yixin Wang10f477ed2017-11-21 04:20:201065}
1066
Yixin Wang983875152017-11-21 20:30:131067TEST(URLRequestContextConfigTest, SetQuicMaxTimeBeforeCryptoHandshake) {
Gabriel Charettedfa36042019-08-19 17:30:111068 base::test::TaskEnvironment task_environment_(
1069 base::test::TaskEnvironment::MainThreadType::IO);
Yixin Wang983875152017-11-21 20:30:131070
1071 URLRequestContextConfig config(
1072 // Enable QUIC.
1073 true,
1074 // QUIC User Agent ID.
1075 "Default QUIC User Agent ID",
1076 // Enable SPDY.
1077 true,
1078 // Enable Brotli.
1079 false,
1080 // Type of http cache.
1081 URLRequestContextConfig::HttpCacheType::DISK,
1082 // Max size of http cache in bytes.
1083 1024000,
1084 // Disable caching for HTTP responses. Other information may be stored in
1085 // the cache.
1086 false,
1087 // Storage path for http cache and cookie storage.
1088 "/data/data/org.chromium.net/app_cronet_test/test_storage",
Misha Efimovd4ab38302018-01-30 23:56:421089 // Accept-Language request header field.
1090 "foreign-language",
Yixin Wang983875152017-11-21 20:30:131091 // User-Agent request header field.
1092 "fake agent",
1093 // JSON encoded experimental options.
1094 "{\"QUIC\":{\"max_time_before_crypto_handshake_seconds\":7,"
1095 "\"max_idle_time_before_crypto_handshake_seconds\":11}}",
1096 // MockCertVerifier to use for testing purposes.
1097 std::unique_ptr<net::CertVerifier>(),
1098 // Enable network quality estimator.
1099 false,
1100 // Enable Public Key Pinning bypass for local trust anchors.
Paul Jensen6a1ea3a2018-08-24 14:46:411101 true,
1102 // Optional network thread priority.
1103 base::Optional<double>());
Yixin Wang983875152017-11-21 20:30:131104
1105 net::URLRequestContextBuilder builder;
Matt Muellerde5dadf2019-11-27 20:11:581106 config.ConfigureURLRequestContextBuilder(&builder);
Yixin Wang983875152017-11-21 20:30:131107 // Set a ProxyConfigService to avoid DCHECK failure when building.
1108 builder.set_proxy_config_service(
Lily Houghtonef028852017-12-06 20:52:301109 std::make_unique<net::ProxyConfigServiceFixed>(
Ramin Halavatica8d5252018-03-12 05:33:491110 net::ProxyConfigWithAnnotation::CreateDirect()));
Yixin Wang983875152017-11-21 20:30:131111 std::unique_ptr<net::URLRequestContext> context(builder.Build());
Victor Vasilieva1e66d72019-12-05 17:55:381112 const net::QuicParams* quic_params = context->quic_context()->params();
Yixin Wang983875152017-11-21 20:30:131113
Victor Vasilieva1e66d72019-12-05 17:55:381114 EXPECT_EQ(7, quic_params->max_time_before_crypto_handshake.InSeconds());
1115 EXPECT_EQ(11, quic_params->max_idle_time_before_crypto_handshake.InSeconds());
Yixin Wang983875152017-11-21 20:30:131116}
1117
Yixin Wang1875fdb2017-12-06 02:26:491118TEST(URLURLRequestContextConfigTest, SetQuicConnectionOptions) {
Gabriel Charettedfa36042019-08-19 17:30:111119 base::test::TaskEnvironment task_environment_(
1120 base::test::TaskEnvironment::MainThreadType::IO);
Yixin Wang1875fdb2017-12-06 02:26:491121
1122 URLRequestContextConfig config(
1123 // Enable QUIC.
1124 true,
1125 // QUIC User Agent ID.
1126 "Default QUIC User Agent ID",
1127 // Enable SPDY.
1128 true,
1129 // Enable Brotli.
1130 false,
1131 // Type of http cache.
1132 URLRequestContextConfig::HttpCacheType::DISK,
1133 // Max size of http cache in bytes.
1134 1024000,
1135 // Disable caching for HTTP responses. Other information may be stored in
1136 // the cache.
1137 false,
1138 // Storage path for http cache and cookie storage.
1139 "/data/data/org.chromium.net/app_cronet_test/test_storage",
Misha Efimovd4ab38302018-01-30 23:56:421140 // Accept-Language request header field.
1141 "foreign-language",
Yixin Wang1875fdb2017-12-06 02:26:491142 // User-Agent request header field.
1143 "fake agent",
1144 // JSON encoded experimental options.
1145 "{\"QUIC\":{\"connection_options\":\"TIME,TBBR,REJ\","
1146 "\"client_connection_options\":\"TBBR,1RTT\"}}",
1147 // MockCertVerifier to use for testing purposes.
1148 std::unique_ptr<net::CertVerifier>(),
1149 // Enable network quality estimator.
1150 false,
1151 // Enable Public Key Pinning bypass for local trust anchors.
Paul Jensen6a1ea3a2018-08-24 14:46:411152 true,
1153 // Optional network thread priority.
1154 base::Optional<double>());
Yixin Wang1875fdb2017-12-06 02:26:491155
1156 net::URLRequestContextBuilder builder;
Matt Muellerde5dadf2019-11-27 20:11:581157 config.ConfigureURLRequestContextBuilder(&builder);
Yixin Wang1875fdb2017-12-06 02:26:491158 // Set a ProxyConfigService to avoid DCHECK failure when building.
1159 builder.set_proxy_config_service(
Gyuyoung Kim6afb5082018-01-19 13:35:571160 std::make_unique<net::ProxyConfigServiceFixed>(
Ramin Halavatica8d5252018-03-12 05:33:491161 net::ProxyConfigWithAnnotation::CreateDirect()));
Yixin Wang1875fdb2017-12-06 02:26:491162 std::unique_ptr<net::URLRequestContext> context(builder.Build());
Victor Vasilieva1e66d72019-12-05 17:55:381163 const net::QuicParams* quic_params = context->quic_context()->params();
Yixin Wang1875fdb2017-12-06 02:26:491164
Ryan Hamilton8d9ee76e2018-05-29 23:52:521165 quic::QuicTagVector connection_options;
1166 connection_options.push_back(quic::kTIME);
1167 connection_options.push_back(quic::kTBBR);
1168 connection_options.push_back(quic::kREJ);
Victor Vasilieva1e66d72019-12-05 17:55:381169 EXPECT_EQ(connection_options, quic_params->connection_options);
Yixin Wang1875fdb2017-12-06 02:26:491170
Ryan Hamilton8d9ee76e2018-05-29 23:52:521171 quic::QuicTagVector client_connection_options;
1172 client_connection_options.push_back(quic::kTBBR);
1173 client_connection_options.push_back(quic::k1RTT);
Victor Vasilieva1e66d72019-12-05 17:55:381174 EXPECT_EQ(client_connection_options, quic_params->client_connection_options);
Yixin Wang1875fdb2017-12-06 02:26:491175}
1176
Misha Efimovd4ab38302018-01-30 23:56:421177TEST(URLURLRequestContextConfigTest, SetAcceptLanguageAndUserAgent) {
Gabriel Charettedfa36042019-08-19 17:30:111178 base::test::TaskEnvironment task_environment_(
1179 base::test::TaskEnvironment::MainThreadType::IO);
Misha Efimovd4ab38302018-01-30 23:56:421180
1181 URLRequestContextConfig config(
1182 // Enable QUIC.
1183 true,
1184 // QUIC User Agent ID.
1185 "Default QUIC User Agent ID",
1186 // Enable SPDY.
1187 true,
1188 // Enable Brotli.
1189 false,
1190 // Type of http cache.
1191 URLRequestContextConfig::HttpCacheType::DISK,
1192 // Max size of http cache in bytes.
1193 1024000,
1194 // Disable caching for HTTP responses. Other information may be stored in
1195 // the cache.
1196 false,
1197 // Storage path for http cache and cookie storage.
1198 "/data/data/org.chromium.net/app_cronet_test/test_storage",
1199 // Accept-Language request header field.
1200 "foreign-language",
1201 // User-Agent request header field.
1202 "fake agent",
1203 // JSON encoded experimental options.
1204 "{}",
1205 // MockCertVerifier to use for testing purposes.
1206 std::unique_ptr<net::CertVerifier>(),
1207 // Enable network quality estimator.
1208 false,
1209 // Enable Public Key Pinning bypass for local trust anchors.
Paul Jensen6a1ea3a2018-08-24 14:46:411210 true,
1211 // Optional network thread priority.
1212 base::Optional<double>());
Misha Efimovd4ab38302018-01-30 23:56:421213
1214 net::URLRequestContextBuilder builder;
Matt Muellerde5dadf2019-11-27 20:11:581215 config.ConfigureURLRequestContextBuilder(&builder);
Misha Efimovd4ab38302018-01-30 23:56:421216 // Set a ProxyConfigService to avoid DCHECK failure when building.
1217 builder.set_proxy_config_service(
1218 std::make_unique<net::ProxyConfigServiceFixed>(
Ramin Halavatica8d5252018-03-12 05:33:491219 net::ProxyConfigWithAnnotation::CreateDirect()));
Misha Efimovd4ab38302018-01-30 23:56:421220 std::unique_ptr<net::URLRequestContext> context(builder.Build());
1221 EXPECT_EQ("foreign-language",
1222 context->http_user_agent_settings()->GetAcceptLanguage());
1223 EXPECT_EQ("fake agent", context->http_user_agent_settings()->GetUserAgent());
1224}
1225
Renjie Tang8c3a1d02020-04-23 17:42:301226TEST(URLURLRequestContextConfigTest, TurningOffQuic) {
1227 base::test::TaskEnvironment task_environment_(
1228 base::test::TaskEnvironment::MainThreadType::IO);
1229
1230 URLRequestContextConfig config(
1231 // Enable QUIC.
1232 false,
1233 // QUIC User Agent ID.
1234 "Default QUIC User Agent ID",
1235 // Enable SPDY.
1236 true,
1237 // Enable Brotli.
1238 false,
1239 // Type of http cache.
1240 URLRequestContextConfig::HttpCacheType::DISK,
1241 // Max size of http cache in bytes.
1242 1024000,
1243 // Disable caching for HTTP responses. Other information may be stored in
1244 // the cache.
1245 false,
1246 // Storage path for http cache and cookie storage.
1247 "/data/data/org.chromium.net/app_cronet_test/test_storage",
1248 // Accept-Language request header field.
1249 "foreign-language",
1250 // User-Agent request header field.
1251 "fake agent",
1252 // JSON encoded experimental options.
1253 "{}",
1254 // MockCertVerifier to use for testing purposes.
1255 std::unique_ptr<net::CertVerifier>(),
1256 // Enable network quality estimator.
1257 false,
1258 // Enable Public Key Pinning bypass for local trust anchors.
1259 true,
1260 // Optional network thread priority.
1261 base::Optional<double>());
1262
1263 net::URLRequestContextBuilder builder;
1264 config.ConfigureURLRequestContextBuilder(&builder);
1265 // Set a ProxyConfigService to avoid DCHECK failure when building.
1266 builder.set_proxy_config_service(
1267 std::make_unique<net::ProxyConfigServiceFixed>(
1268 net::ProxyConfigWithAnnotation::CreateDirect()));
1269 std::unique_ptr<net::URLRequestContext> context(builder.Build());
1270 const net::HttpNetworkSession::Params* params =
1271 context->GetNetworkSessionParams();
1272 EXPECT_EQ(false, params->enable_quic);
1273}
1274
Renjie Tang1c718942020-06-11 23:05:381275TEST(URLURLRequestContextConfigTest, DefaultEnableQuic) {
1276 base::test::TaskEnvironment task_environment_(
1277 base::test::TaskEnvironment::MainThreadType::IO);
1278
1279 URLRequestContextConfigBuilder config_builder;
1280 std::unique_ptr<URLRequestContextConfig> config = config_builder.Build();
1281 net::URLRequestContextBuilder builder;
1282 config->ConfigureURLRequestContextBuilder(&builder);
1283 // Set a ProxyConfigService to avoid DCHECK failure when building.
1284 builder.set_proxy_config_service(
1285 std::make_unique<net::ProxyConfigServiceFixed>(
1286 net::ProxyConfigWithAnnotation::CreateDirect()));
1287 std::unique_ptr<net::URLRequestContext> context(builder.Build());
1288 const net::HttpNetworkSession::Params* params =
1289 context->GetNetworkSessionParams();
1290 EXPECT_EQ(true, params->enable_quic);
1291}
1292
juliatuttle50d9c4b2016-08-23 22:49:191293// See stale_host_resolver_unittest.cc for test of StaleDNS options.
1294
xunjielif24ee5f2015-11-23 18:05:261295} // namespace cronet