blob: 6a6f507abc27dca70f9d96fbb71a8e74f121d3c8 [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"
pauljensen9041eb3c2015-12-09 12:29:0122#include "net/cert/cert_verifier.h"
Eric Orthe1cdd902019-02-26 02:52:4623#include "net/dns/host_resolver.h"
Eric Orth607b6d82019-05-08 16:43:3224#include "net/dns/host_resolver_manager.h"
xunjielif24ee5f2015-11-23 18:05:2625#include "net/http/http_network_session.h"
mikecironef22f9812016-10-04 03:40:1926#include "net/log/net_log_with_source.h"
Lily Houghton582d4622018-01-22 22:43:4027#include "net/proxy_resolution/proxy_config.h"
28#include "net/proxy_resolution/proxy_config_service_fixed.h"
xunjielif24ee5f2015-11-23 18:05:2629#include "net/url_request/url_request_context.h"
30#include "net/url_request/url_request_context_builder.h"
31#include "testing/gtest/include/gtest/gtest.h"
32
Douglas Creagera220947e2018-08-23 20:08:5333#if BUILDFLAG(ENABLE_REPORTING)
34#include "net/network_error_logging/network_error_logging_service.h"
35#include "net/reporting/reporting_service.h"
36#endif // BUILDFLAG(ENABLE_REPORTING)
37
xunjielif24ee5f2015-11-23 18:05:2638namespace cronet {
39
Douglas Creagera220947e2018-08-23 20:08:5340namespace {
41
Douglas Creagera220947e2018-08-23 20:08:5342std::string WrapJsonHeader(base::StringPiece value) {
Jan Wilken Dörriefb1d7b662020-02-04 11:10:2343 return base::StrCat({"[", value, "]"});
Douglas Creagera220947e2018-08-23 20:08:5344}
45
46// Returns whether two JSON-encoded headers contain the same content, ignoring
47// irrelevant encoding issues like whitespace and map element ordering.
48bool JsonHeaderEquals(base::StringPiece expected, base::StringPiece actual) {
Lei Zhang9b9d5792019-02-20 07:24:4249 return base::test::ParseJson(WrapJsonHeader(expected)) ==
50 base::test::ParseJson(WrapJsonHeader(actual));
Douglas Creagera220947e2018-08-23 20:08:5351}
52
53} // namespace
54
mmenke51629db12017-06-28 13:34:1255TEST(URLRequestContextConfigTest, TestExperimentalOptionParsing) {
Gabriel Charettedfa36042019-08-19 17:30:1156 base::test::TaskEnvironment task_environment_(
57 base::test::TaskEnvironment::MainThreadType::IO);
mmenke51629db12017-06-28 13:34:1258
Julia Tuttle3cc27a4a2018-04-25 15:57:0659 // Create JSON for experimental options.
60 base::DictionaryValue options;
61 options.SetPath({"QUIC", "max_server_configs_stored_in_properties"},
62 base::Value(2));
63 options.SetPath({"QUIC", "user_agent_id"}, base::Value("Custom QUIC UAID"));
64 options.SetPath({"QUIC", "idle_connection_timeout_seconds"},
65 base::Value(300));
66 options.SetPath({"QUIC", "close_sessions_on_ip_change"}, base::Value(true));
67 options.SetPath({"QUIC", "race_cert_verification"}, base::Value(true));
68 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 Schinazi3ad7e7d2020-03-06 13:12:0571 base::Value(
Zhongyi Shi2a549fe2020-04-02 17:53:0572 "FLAGS_quic_max_aggressive_retransmittable_on_wire_ping_count=5,"
Renjie Tang21939bfd2020-04-15 02:07:2573 "FLAGS_quic_reloadable_flag_quic_enable_version_t050_v2=true,"
David Schinazi3ad7e7d2020-03-06 13:12:0574 "FLAGS_quic_reloadable_flag_quic_enable_version_draft_27=true"));
Julia Tuttle3cc27a4a2018-04-25 15:57:0675 options.SetPath({"AsyncDNS", "enable"}, base::Value(true));
76 options.SetPath({"NetworkErrorLogging", "enable"}, base::Value(true));
Douglas Creagera220947e2018-08-23 20:08:5377 options.SetPath({"NetworkErrorLogging", "preloaded_report_to_headers"},
Lei Zhang9b9d5792019-02-20 07:24:4278 base::test::ParseJson(R"json(
Douglas Creagera220947e2018-08-23 20:08:5379 [
80 {
81 "origin": "https://test-origin/",
82 "value": {
83 "group": "test-group",
84 "max_age": 86400,
85 "endpoints": [
86 {"url": "https://test-endpoint/"},
87 ],
88 },
89 },
90 {
91 "origin": "https://test-origin-2/",
92 "value": [
93 {
94 "group": "test-group-2",
95 "max_age": 86400,
96 "endpoints": [
97 {"url": "https://test-endpoint-2/"},
98 ],
99 },
100 {
101 "group": "test-group-3",
102 "max_age": 86400,
103 "endpoints": [
104 {"url": "https://test-endpoint-3/"},
105 ],
106 },
107 ],
108 },
109 {
110 "origin": "https://value-is-missing/",
111 },
112 {
113 "value": "origin is missing",
114 },
115 {
116 "origin": 123,
117 "value": "origin is not a string",
118 },
119 {
120 "origin": "this is not a URL",
121 "value": "origin not a URL",
122 },
123 ]
124 )json"));
125 options.SetPath({"NetworkErrorLogging", "preloaded_nel_headers"},
Lei Zhang9b9d5792019-02-20 07:24:42126 base::test::ParseJson(R"json(
Douglas Creagera220947e2018-08-23 20:08:53127 [
128 {
129 "origin": "https://test-origin/",
130 "value": {
131 "report_to": "test-group",
132 "max_age": 86400,
133 },
134 },
135 ]
136 )json"));
Julia Tuttle3cc27a4a2018-04-25 15:57:06137 options.SetPath({"UnknownOption", "foo"}, base::Value(true));
138 options.SetPath({"HostResolverRules", "host_resolver_rules"},
139 base::Value("MAP * 127.0.0.1"));
140 // See http://crbug.com/696569.
141 options.SetKey("disable_ipv6_on_wifi", base::Value(true));
142 std::string options_json;
143 EXPECT_TRUE(base::JSONWriter::Write(options, &options_json));
144
Ryan Hamiltona31239f12019-09-25 21:01:00145 // Initialize QUIC flags set by the config.
Zhongyi Shi2a549fe2020-04-02 17:53:05146 FLAGS_quic_max_aggressive_retransmittable_on_wire_ping_count = 0;
Renjie Tang21939bfd2020-04-15 02:07:25147 FLAGS_quic_reloadable_flag_quic_enable_version_t050_v2 = false;
David Schinazi3ad7e7d2020-03-06 13:12:05148 FLAGS_quic_reloadable_flag_quic_enable_version_draft_27 = false;
Ryan Hamiltona31239f12019-09-25 21:01:00149
pauljensen9041eb3c2015-12-09 12:29:01150 URLRequestContextConfig config(
151 // Enable QUIC.
152 true,
mefc5da5712016-02-09 20:14:23153 // QUIC User Agent ID.
154 "Default QUIC User Agent ID",
pauljensen9041eb3c2015-12-09 12:29:01155 // Enable SPDY.
156 true,
xunjieli186d2bf2017-04-18 13:45:47157 // Enable Brotli.
158 false,
pauljensen9041eb3c2015-12-09 12:29:01159 // Type of http cache.
160 URLRequestContextConfig::HttpCacheType::DISK,
161 // Max size of http cache in bytes.
162 1024000,
163 // Disable caching for HTTP responses. Other information may be stored in
164 // the cache.
165 false,
166 // Storage path for http cache and cookie storage.
167 "/data/data/org.chromium.net/app_cronet_test/test_storage",
Misha Efimovd4ab38302018-01-30 23:56:42168 // Accept-Language request header field.
169 "foreign-language",
pauljensen9041eb3c2015-12-09 12:29:01170 // User-Agent request header field.
171 "fake agent",
172 // JSON encoded experimental options.
Julia Tuttle3cc27a4a2018-04-25 15:57:06173 options_json,
pauljensen9041eb3c2015-12-09 12:29:01174 // MockCertVerifier to use for testing purposes.
tbansal7018e2a2016-06-25 00:40:39175 std::unique_ptr<net::CertVerifier>(),
176 // Enable network quality estimator.
kapishnikov385aa422016-07-01 20:53:02177 false,
178 // Enable Public Key Pinning bypass for local trust anchors.
Paul Jensen6a1ea3a2018-08-24 14:46:41179 true,
180 // Optional network thread priority.
181 base::Optional<double>(42.0));
xunjielif24ee5f2015-11-23 18:05:26182
xunjielif24ee5f2015-11-23 18:05:26183 net::URLRequestContextBuilder builder;
Matt Muellerde5dadf2019-11-27 20:11:58184 config.ConfigureURLRequestContextBuilder(&builder);
xunjielid67295e2017-03-16 21:05:41185 EXPECT_FALSE(config.effective_experimental_options->HasKey("UnknownOption"));
xunjielif24ee5f2015-11-23 18:05:26186 // Set a ProxyConfigService to avoid DCHECK failure when building.
ricea85ec57952016-08-31 09:34:10187 builder.set_proxy_config_service(
Lily Houghtonef028852017-12-06 20:52:30188 std::make_unique<net::ProxyConfigServiceFixed>(
Ramin Halavatica8d5252018-03-12 05:33:49189 net::ProxyConfigWithAnnotation::CreateDirect()));
dchengfe3745e6242016-04-21 23:49:58190 std::unique_ptr<net::URLRequestContext> context(builder.Build());
Victor Vasilieva1e66d72019-12-05 17:55:38191 const net::QuicParams* quic_params = context->quic_context()->params();
xunjielif24ee5f2015-11-23 18:05:26192 // Check Quic Connection options.
Ryan Hamilton8d9ee76e2018-05-29 23:52:52193 quic::QuicTagVector quic_connection_options;
194 quic_connection_options.push_back(quic::kTIME);
195 quic_connection_options.push_back(quic::kTBBR);
196 quic_connection_options.push_back(quic::kREJ);
Victor Vasilieva1e66d72019-12-05 17:55:38197 EXPECT_EQ(quic_connection_options, quic_params->connection_options);
xunjielif24ee5f2015-11-23 18:05:26198
Zhongyi Shi2a549fe2020-04-02 17:53:05199 EXPECT_EQ(FLAGS_quic_max_aggressive_retransmittable_on_wire_ping_count, 5);
Renjie Tang21939bfd2020-04-15 02:07:25200 EXPECT_TRUE(FLAGS_quic_reloadable_flag_quic_enable_version_t050_v2);
David Schinazi3ad7e7d2020-03-06 13:12:05201 EXPECT_TRUE(FLAGS_quic_reloadable_flag_quic_enable_version_draft_27);
Ryan Hamiltona31239f12019-09-25 21:01:00202
mefc5da5712016-02-09 20:14:23203 // Check Custom QUIC User Agent Id.
Victor Vasilieva1e66d72019-12-05 17:55:38204 EXPECT_EQ("Custom QUIC UAID", quic_params->user_agent_id);
mefc5da5712016-02-09 20:14:23205
rtenneti6971c172016-01-15 20:12:10206 // Check max_server_configs_stored_in_properties.
Victor Vasilieva1e66d72019-12-05 17:55:38207 EXPECT_EQ(2u, quic_params->max_server_configs_stored_in_properties);
xunjielif24ee5f2015-11-23 18:05:26208
Ryan Sleevi2e8255b2019-07-17 21:02:21209 // Check idle_connection_timeout.
Victor Vasilieva1e66d72019-12-05 17:55:38210 EXPECT_EQ(300, quic_params->idle_connection_timeout.InSeconds());
rtenneti64e809d02015-12-11 00:26:20211
Victor Vasilieva1e66d72019-12-05 17:55:38212 EXPECT_TRUE(quic_params->close_sessions_on_ip_change);
213 EXPECT_FALSE(quic_params->goaway_sessions_on_ip_change);
214 EXPECT_FALSE(quic_params->allow_server_migration);
215 EXPECT_FALSE(quic_params->migrate_sessions_on_network_change_v2);
216 EXPECT_FALSE(quic_params->migrate_sessions_early_v2);
217 EXPECT_FALSE(quic_params->migrate_idle_sessions);
218 EXPECT_FALSE(quic_params->retry_on_alternate_network_before_handshake);
219 EXPECT_FALSE(quic_params->race_stale_dns_on_connection);
220 EXPECT_FALSE(quic_params->go_away_on_path_degrading);
jrid26566952016-02-04 21:06:42221
rtennetid073dd22016-08-04 01:58:33222 // Check race_cert_verification.
Victor Vasilieva1e66d72019-12-05 17:55:38223 EXPECT_TRUE(quic_params->race_cert_verification);
rtennetid073dd22016-08-04 01:58:33224
Misha Efimov63957912017-12-06 07:13:26225#if defined(ENABLE_BUILT_IN_DNS)
226 // Check AsyncDNS resolver is enabled (not supported on iOS).
tfhef3618f2016-01-11 23:07:08227 EXPECT_TRUE(context->host_resolver()->GetDnsConfigAsValue());
Misha Efimov63957912017-12-06 07:13:26228#endif // defined(ENABLE_BUILT_IN_DNS)
mgershaf2c12c2016-08-22 16:33:54229
Julia Tuttle9715d1642018-01-29 17:02:26230#if BUILDFLAG(ENABLE_REPORTING)
231 // Check Reporting and Network Error Logging are enabled (can be disabled at
232 // build time).
233 EXPECT_TRUE(context->reporting_service());
Julia Tuttlecba7d222018-02-23 19:37:27234 EXPECT_TRUE(context->network_error_logging_service());
Julia Tuttle9715d1642018-01-29 17:02:26235#endif // BUILDFLAG(ENABLE_REPORTING)
236
Douglas Creagera220947e2018-08-23 20:08:53237 ASSERT_EQ(2u, config.preloaded_report_to_headers.size());
238 EXPECT_EQ(url::Origin::CreateFromNormalizedTuple("https", "test-origin", 443),
239 config.preloaded_report_to_headers[0].origin);
240 EXPECT_TRUE(JsonHeaderEquals( //
241 R"json(
242 {
243 "group": "test-group",
244 "max_age": 86400,
245 "endpoints": [
246 {"url": "https://test-endpoint/"},
247 ],
248 }
249 )json",
250 config.preloaded_report_to_headers[0].value));
251 EXPECT_EQ(
252 url::Origin::CreateFromNormalizedTuple("https", "test-origin-2", 443),
253 config.preloaded_report_to_headers[1].origin);
254 EXPECT_TRUE(JsonHeaderEquals( //
255 R"json(
256 {
257 "group": "test-group-2",
258 "max_age": 86400,
259 "endpoints": [
260 {"url": "https://test-endpoint-2/"},
261 ],
262 },
263 {
264 "group": "test-group-3",
265 "max_age": 86400,
266 "endpoints": [
267 {"url": "https://test-endpoint-3/"},
268 ],
269 }
270 )json",
271 config.preloaded_report_to_headers[1].value));
272
273 ASSERT_EQ(1u, config.preloaded_nel_headers.size());
274 EXPECT_EQ(url::Origin::CreateFromNormalizedTuple("https", "test-origin", 443),
275 config.preloaded_nel_headers[0].origin);
276 EXPECT_TRUE(JsonHeaderEquals( //
277 R"json(
278 {
279 "report_to": "test-group",
280 "max_age": 86400,
281 }
282 )json",
283 config.preloaded_nel_headers[0].value));
284
mgershaf9a9232017-04-13 20:19:03285 // Check IPv6 is disabled when on wifi.
Eric Orth607b6d82019-05-08 16:43:32286 EXPECT_FALSE(context->host_resolver()
287 ->GetManagerForTesting()
288 ->check_ipv6_on_wifi_for_testing());
mgershb3fe8082017-02-28 20:09:20289
Eric Orthe1cdd902019-02-26 02:52:46290 // All host resolution expected to be mapped to an immediately-resolvable IP.
291 std::unique_ptr<net::HostResolver::ResolveHostRequest> resolve_request =
292 context->host_resolver()->CreateRequest(net::HostPortPair("abcde", 80),
293 net::NetLogWithSource(),
294 base::nullopt);
295 EXPECT_EQ(net::OK, resolve_request->Start(
296 base::BindOnce([](int error) { NOTREACHED(); })));
Paul Jensen6a1ea3a2018-08-24 14:46:41297
298 EXPECT_TRUE(config.network_thread_priority);
299 EXPECT_EQ(42.0, config.network_thread_priority.value());
xunjielif24ee5f2015-11-23 18:05:26300}
301
Zhongyi Shi57247962018-11-05 20:03:52302TEST(URLRequestContextConfigTest, SetSupportedQuicVersion) {
Gabriel Charettedfa36042019-08-19 17:30:11303 base::test::TaskEnvironment task_environment_(
304 base::test::TaskEnvironment::MainThreadType::IO);
Zhongyi Shi57247962018-11-05 20:03:52305
306 URLRequestContextConfig config(
307 // Enable QUIC.
308 true,
309 // QUIC User Agent ID.
310 "Default QUIC User Agent ID",
311 // Enable SPDY.
312 true,
313 // Enable Brotli.
314 false,
315 // Type of http cache.
316 URLRequestContextConfig::HttpCacheType::DISK,
317 // Max size of http cache in bytes.
318 1024000,
319 // Disable caching for HTTP responses. Other information may be stored in
320 // the cache.
321 false,
322 // Storage path for http cache and cookie storage.
323 "/data/data/org.chromium.net/app_cronet_test/test_storage",
324 // Accept-Language request header field.
325 "foreign-language",
326 // User-Agent request header field.
327 "fake agent",
328 // JSON encoded experimental options.
Ryan Hamilton8380c652019-06-04 02:25:06329 "{\"QUIC\":{\"quic_version\":\"QUIC_VERSION_46\"}}",
Zhongyi Shi57247962018-11-05 20:03:52330 // MockCertVerifier to use for testing purposes.
331 std::unique_ptr<net::CertVerifier>(),
332 // Enable network quality estimator.
333 false,
334 // Enable Public Key Pinning bypass for local trust anchors.
335 true,
336 // Optional network thread priority.
337 base::Optional<double>());
338
339 net::URLRequestContextBuilder builder;
Matt Muellerde5dadf2019-11-27 20:11:58340 config.ConfigureURLRequestContextBuilder(&builder);
Zhongyi Shi57247962018-11-05 20:03:52341 // Set a ProxyConfigService to avoid DCHECK failure when building.
342 builder.set_proxy_config_service(
343 std::make_unique<net::ProxyConfigServiceFixed>(
344 net::ProxyConfigWithAnnotation::CreateDirect()));
345 std::unique_ptr<net::URLRequestContext> context(builder.Build());
Victor Vasilieva1e66d72019-12-05 17:55:38346 const net::QuicParams* quic_params = context->quic_context()->params();
347 EXPECT_EQ(quic_params->supported_versions.size(), 1u);
348 EXPECT_EQ(quic_params->supported_versions[0],
Nick Harper23290b82019-05-02 00:02:56349 quic::ParsedQuicVersion(quic::PROTOCOL_QUIC_CRYPTO,
Ryan Hamilton8380c652019-06-04 02:25:06350 quic::QUIC_VERSION_46));
Zhongyi Shi57247962018-11-05 20:03:52351}
352
Ryan Hamilton209227b2020-01-17 01:29:05353TEST(URLRequestContextConfigTest, SetSupportedQuicVersionByAlpn) {
354 base::test::TaskEnvironment task_environment_(
355 base::test::TaskEnvironment::MainThreadType::IO);
356
357 URLRequestContextConfig config(
358 // Enable QUIC.
359 true,
360 // QUIC User Agent ID.
361 "Default QUIC User Agent ID",
362 // Enable SPDY.
363 true,
364 // Enable Brotli.
365 false,
366 // Type of http cache.
367 URLRequestContextConfig::HttpCacheType::DISK,
368 // Max size of http cache in bytes.
369 1024000,
370 // Disable caching for HTTP responses. Other information may be stored in
371 // the cache.
372 false,
373 // Storage path for http cache and cookie storage.
374 "/data/data/org.chromium.net/app_cronet_test/test_storage",
375 // Accept-Language request header field.
376 "foreign-language",
377 // User-Agent request header field.
378 "fake agent",
379 // JSON encoded experimental options.
380 "{\"QUIC\":{\"quic_version\":\"h3-T050\"}}",
381 // MockCertVerifier to use for testing purposes.
382 std::unique_ptr<net::CertVerifier>(),
383 // Enable network quality estimator.
384 false,
385 // Enable Public Key Pinning bypass for local trust anchors.
386 true,
387 // Optional network thread priority.
388 base::Optional<double>());
389
390 net::URLRequestContextBuilder builder;
391 config.ConfigureURLRequestContextBuilder(&builder);
392 // Set a ProxyConfigService to avoid DCHECK failure when building.
393 builder.set_proxy_config_service(
394 std::make_unique<net::ProxyConfigServiceFixed>(
395 net::ProxyConfigWithAnnotation::CreateDirect()));
396 std::unique_ptr<net::URLRequestContext> context(builder.Build());
397 const net::QuicParams* quic_params = context->quic_context()->params();
398 EXPECT_EQ(quic_params->supported_versions.size(), 1u);
399 EXPECT_EQ(
400 quic_params->supported_versions[0],
401 quic::ParsedQuicVersion(quic::PROTOCOL_TLS1_3, quic::QUIC_VERSION_50));
402}
403
Zhongyi Shi57247962018-11-05 20:03:52404TEST(URLRequestContextConfigTest, SetUnsupportedQuicVersion) {
Gabriel Charettedfa36042019-08-19 17:30:11405 base::test::TaskEnvironment task_environment_(
406 base::test::TaskEnvironment::MainThreadType::IO);
Zhongyi Shi57247962018-11-05 20:03:52407
408 URLRequestContextConfig config(
409 // Enable QUIC.
410 true,
411 // QUIC User Agent ID.
412 "Default QUIC User Agent ID",
413 // Enable SPDY.
414 true,
415 // Enable Brotli.
416 false,
417 // Type of http cache.
418 URLRequestContextConfig::HttpCacheType::DISK,
419 // Max size of http cache in bytes.
420 1024000,
421 // Disable caching for HTTP responses. Other information may be stored in
422 // the cache.
423 false,
424 // Storage path for http cache and cookie storage.
425 "/data/data/org.chromium.net/app_cronet_test/test_storage",
426 // Accept-Language request header field.
427 "foreign-language",
428 // User-Agent request header field.
429 "fake agent",
430 // JSON encoded experimental options.
431 "{\"QUIC\":{\"quic_version\":\"QUIC_VERSION_33\"}}",
432 // MockCertVerifier to use for testing purposes.
433 std::unique_ptr<net::CertVerifier>(),
434 // Enable network quality estimator.
435 false,
436 // Enable Public Key Pinning bypass for local trust anchors.
437 true,
438 // Optional network thread priority.
439 base::Optional<double>());
440
441 net::URLRequestContextBuilder builder;
Matt Muellerde5dadf2019-11-27 20:11:58442 config.ConfigureURLRequestContextBuilder(&builder);
Zhongyi Shi57247962018-11-05 20:03:52443 // Set a ProxyConfigService to avoid DCHECK failure when building.
444 builder.set_proxy_config_service(
445 std::make_unique<net::ProxyConfigServiceFixed>(
446 net::ProxyConfigWithAnnotation::CreateDirect()));
447 std::unique_ptr<net::URLRequestContext> context(builder.Build());
Victor Vasilieva1e66d72019-12-05 17:55:38448 const net::QuicParams* quic_params = context->quic_context()->params();
449 EXPECT_EQ(quic_params->supported_versions.size(), 1u);
450 EXPECT_EQ(quic_params->supported_versions[0],
Nick Harper23290b82019-05-02 00:02:56451 quic::ParsedQuicVersion(quic::PROTOCOL_QUIC_CRYPTO,
Ryan Hamilton3cbc5632019-05-20 17:16:29452 quic::QUIC_VERSION_46));
Zhongyi Shi57247962018-11-05 20:03:52453}
454
Zhongyi Shi8ff38c12018-02-22 00:02:30455TEST(URLRequestContextConfigTest, SetQuicServerMigrationOptions) {
Gabriel Charettedfa36042019-08-19 17:30:11456 base::test::TaskEnvironment task_environment_(
457 base::test::TaskEnvironment::MainThreadType::IO);
Zhongyi Shi8ff38c12018-02-22 00:02:30458
459 URLRequestContextConfig config(
460 // Enable QUIC.
461 true,
462 // QUIC User Agent ID.
463 "Default QUIC User Agent ID",
464 // Enable SPDY.
465 true,
466 // Enable Brotli.
467 false,
468 // Type of http cache.
469 URLRequestContextConfig::HttpCacheType::DISK,
470 // Max size of http cache in bytes.
471 1024000,
472 // Disable caching for HTTP responses. Other information may be stored in
473 // the cache.
474 false,
475 // Storage path for http cache and cookie storage.
476 "/data/data/org.chromium.net/app_cronet_test/test_storage",
477 // Accept-Language request header field.
478 "foreign-language",
479 // User-Agent request header field.
480 "fake agent",
481 // JSON encoded experimental options.
482 "{\"QUIC\":{\"allow_server_migration\":true}}",
483 // MockCertVerifier to use for testing purposes.
484 std::unique_ptr<net::CertVerifier>(),
485 // Enable network quality estimator.
486 false,
487 // Enable Public Key Pinning bypass for local trust anchors.
Paul Jensen6a1ea3a2018-08-24 14:46:41488 true,
489 // Optional network thread priority.
490 base::Optional<double>());
Zhongyi Shi8ff38c12018-02-22 00:02:30491
492 net::URLRequestContextBuilder builder;
Matt Muellerde5dadf2019-11-27 20:11:58493 config.ConfigureURLRequestContextBuilder(&builder);
Zhongyi Shi8ff38c12018-02-22 00:02:30494 // Set a ProxyConfigService to avoid DCHECK failure when building.
495 builder.set_proxy_config_service(
496 std::make_unique<net::ProxyConfigServiceFixed>(
Ramin Halavatica8d5252018-03-12 05:33:49497 net::ProxyConfigWithAnnotation::CreateDirect()));
Zhongyi Shi8ff38c12018-02-22 00:02:30498 std::unique_ptr<net::URLRequestContext> context(builder.Build());
Victor Vasilieva1e66d72019-12-05 17:55:38499 const net::QuicParams* quic_params = context->quic_context()->params();
Zhongyi Shi8ff38c12018-02-22 00:02:30500
Victor Vasilieva1e66d72019-12-05 17:55:38501 EXPECT_FALSE(quic_params->close_sessions_on_ip_change);
502 EXPECT_TRUE(quic_params->allow_server_migration);
Zhongyi Shi8ff38c12018-02-22 00:02:30503}
504
Zhongyi Shiaa518c22018-06-15 04:37:36505// Test that goaway_sessions_on_ip_change is set on by default for iOS.
506#if defined(OS_IOS)
507#define MAYBE_SetQuicGoAwaySessionsOnIPChangeByDefault \
508 SetQuicGoAwaySessionsOnIPChangeByDefault
509#else
510#define MAYBE_SetQuicGoAwaySessionsOnIPChangeByDefault \
511 DISABLED_SetQuicGoAwaySessionsOnIPChangeByDefault
512#endif
513TEST(URLRequestContextConfigTest,
514 MAYBE_SetQuicGoAwaySessionsOnIPChangeByDefault) {
Gabriel Charettedfa36042019-08-19 17:30:11515 base::test::TaskEnvironment task_environment_(
516 base::test::TaskEnvironment::MainThreadType::IO);
Zhongyi Shiaa518c22018-06-15 04:37:36517
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 "{\"QUIC\":{}}",
542 // MockCertVerifier to use for testing purposes.
543 std::unique_ptr<net::CertVerifier>(),
544 // Enable network quality estimator.
545 false,
546 // Enable Public Key Pinning bypass for local trust anchors.
Paul Jensen6a1ea3a2018-08-24 14:46:41547 true,
548 // Optional network thread priority.
549 base::Optional<double>());
Zhongyi Shiaa518c22018-06-15 04:37:36550
551 net::URLRequestContextBuilder builder;
Matt Muellerde5dadf2019-11-27 20:11:58552 config.ConfigureURLRequestContextBuilder(&builder);
Zhongyi Shiaa518c22018-06-15 04:37:36553 // Set a ProxyConfigService to avoid DCHECK failure when building.
554 builder.set_proxy_config_service(
555 std::make_unique<net::ProxyConfigServiceFixed>(
556 net::ProxyConfigWithAnnotation::CreateDirect()));
557 std::unique_ptr<net::URLRequestContext> context(builder.Build());
Victor Vasilieva1e66d72019-12-05 17:55:38558 const net::QuicParams* quic_params = context->quic_context()->params();
Zhongyi Shiaa518c22018-06-15 04:37:36559
Victor Vasilieva1e66d72019-12-05 17:55:38560 EXPECT_FALSE(quic_params->close_sessions_on_ip_change);
561 EXPECT_TRUE(quic_params->goaway_sessions_on_ip_change);
Zhongyi Shiaa518c22018-06-15 04:37:36562}
563
564// Tests that goaway_sessions_on_ip_changes can be set on via
565// experimental options on non-iOS.
566#if !defined(OS_IOS)
567#define MAYBE_SetQuicGoAwaySessionsOnIPChangeViaExperimentOptions \
568 SetQuicGoAwaySessionsOnIPChangeViaExperimentOptions
569#else
570#define MAYBE_SetQuicGoAwaySessionsOnIPChangeViaExperimentOptions \
571 DISABLED_SetQuicGoAwaySessionsOnIPChangeViaExperimentOptions
572#endif
573TEST(URLRequestContextConfigTest,
574 MAYBE_SetQuicGoAwaySessionsOnIPChangeViaExperimentOptions) {
Gabriel Charettedfa36042019-08-19 17:30:11575 base::test::TaskEnvironment task_environment_(
576 base::test::TaskEnvironment::MainThreadType::IO);
Zhongyi Shi63574b72018-06-01 20:22:25577
578 URLRequestContextConfig config(
579 // Enable QUIC.
580 true,
581 // QUIC User Agent ID.
582 "Default QUIC User Agent ID",
583 // Enable SPDY.
584 true,
585 // Enable Brotli.
586 false,
587 // Type of http cache.
588 URLRequestContextConfig::HttpCacheType::DISK,
589 // Max size of http cache in bytes.
590 1024000,
591 // Disable caching for HTTP responses. Other information may be stored in
592 // the cache.
593 false,
594 // Storage path for http cache and cookie storage.
595 "/data/data/org.chromium.net/app_cronet_test/test_storage",
596 // Accept-Language request header field.
597 "foreign-language",
598 // User-Agent request header field.
599 "fake agent",
600 // JSON encoded experimental options.
601 "{\"QUIC\":{\"goaway_sessions_on_ip_change\":true}}",
602 // MockCertVerifier to use for testing purposes.
603 std::unique_ptr<net::CertVerifier>(),
604 // Enable network quality estimator.
605 false,
606 // Enable Public Key Pinning bypass for local trust anchors.
Paul Jensen6a1ea3a2018-08-24 14:46:41607 true,
608 // Optional network thread priority.
609 base::Optional<double>());
Zhongyi Shi63574b72018-06-01 20:22:25610
611 net::URLRequestContextBuilder builder;
Matt Muellerde5dadf2019-11-27 20:11:58612 config.ConfigureURLRequestContextBuilder(&builder);
Zhongyi Shi63574b72018-06-01 20:22:25613 // Set a ProxyConfigService to avoid DCHECK failure when building.
614 builder.set_proxy_config_service(
615 std::make_unique<net::ProxyConfigServiceFixed>(
616 net::ProxyConfigWithAnnotation::CreateDirect()));
617 std::unique_ptr<net::URLRequestContext> context(builder.Build());
Victor Vasilieva1e66d72019-12-05 17:55:38618 const net::QuicParams* quic_params = context->quic_context()->params();
Zhongyi Shi63574b72018-06-01 20:22:25619
Victor Vasilieva1e66d72019-12-05 17:55:38620 EXPECT_FALSE(quic_params->close_sessions_on_ip_change);
621 EXPECT_TRUE(quic_params->goaway_sessions_on_ip_change);
Zhongyi Shi63574b72018-06-01 20:22:25622}
623
Zhongyi Shiaa518c22018-06-15 04:37:36624// Test that goaway_sessions_on_ip_change can be set to false via
625// exprimental options on iOS.
626#if defined(OS_IOS)
627#define MAYBE_DisableQuicGoAwaySessionsOnIPChangeViaExperimentOptions \
628 DisableQuicGoAwaySessionsOnIPChangeViaExperimentOptions
629#else
630#define MAYBE_DisableQuicGoAwaySessionsOnIPChangeViaExperimentOptions \
631 DISABLED_DisableQuicGoAwaySessionsOnIPChangeViaExperimentOptions
632#endif
633TEST(URLRequestContextConfigTest,
634 MAYBE_DisableQuicGoAwaySessionsOnIPChangeViaExperimentOptions) {
Gabriel Charettedfa36042019-08-19 17:30:11635 base::test::TaskEnvironment task_environment_(
636 base::test::TaskEnvironment::MainThreadType::IO);
Zhongyi Shiaa518c22018-06-15 04:37:36637
638 URLRequestContextConfig config(
639 // Enable QUIC.
640 true,
641 // QUIC User Agent ID.
642 "Default QUIC User Agent ID",
643 // Enable SPDY.
644 true,
645 // Enable Brotli.
646 false,
647 // Type of http cache.
648 URLRequestContextConfig::HttpCacheType::DISK,
649 // Max size of http cache in bytes.
650 1024000,
651 // Disable caching for HTTP responses. Other information may be stored in
652 // the cache.
653 false,
654 // Storage path for http cache and cookie storage.
655 "/data/data/org.chromium.net/app_cronet_test/test_storage",
656 // Accept-Language request header field.
657 "foreign-language",
658 // User-Agent request header field.
659 "fake agent",
660 // JSON encoded experimental options.
661 "{\"QUIC\":{\"goaway_sessions_on_ip_change\":false}}",
662 // MockCertVerifier to use for testing purposes.
663 std::unique_ptr<net::CertVerifier>(),
664 // Enable network quality estimator.
665 false,
666 // Enable Public Key Pinning bypass for local trust anchors.
Paul Jensen6a1ea3a2018-08-24 14:46:41667 true,
668 // Optional network thread priority.
669 base::Optional<double>());
Zhongyi Shiaa518c22018-06-15 04:37:36670
671 net::URLRequestContextBuilder builder;
Matt Muellerde5dadf2019-11-27 20:11:58672 config.ConfigureURLRequestContextBuilder(&builder);
Zhongyi Shiaa518c22018-06-15 04:37:36673 // Set a ProxyConfigService to avoid DCHECK failure when building.
674 builder.set_proxy_config_service(
675 std::make_unique<net::ProxyConfigServiceFixed>(
676 net::ProxyConfigWithAnnotation::CreateDirect()));
677 std::unique_ptr<net::URLRequestContext> context(builder.Build());
Victor Vasilieva1e66d72019-12-05 17:55:38678 const net::QuicParams* quic_params = context->quic_context()->params();
Zhongyi Shiaa518c22018-06-15 04:37:36679
Victor Vasilieva1e66d72019-12-05 17:55:38680 EXPECT_FALSE(quic_params->close_sessions_on_ip_change);
681 EXPECT_FALSE(quic_params->goaway_sessions_on_ip_change);
Zhongyi Shiaa518c22018-06-15 04:37:36682}
683
Yixin Wang10f477ed2017-11-21 04:20:20684TEST(URLRequestContextConfigTest, SetQuicConnectionMigrationV2Options) {
Gabriel Charettedfa36042019-08-19 17:30:11685 base::test::TaskEnvironment task_environment_(
686 base::test::TaskEnvironment::MainThreadType::IO);
Zhongyi Shi64795622017-11-20 02:21:49687
688 URLRequestContextConfig config(
689 // Enable QUIC.
690 true,
691 // QUIC User Agent ID.
692 "Default QUIC User Agent ID",
693 // Enable SPDY.
694 true,
695 // Enable Brotli.
696 false,
697 // Type of http cache.
698 URLRequestContextConfig::HttpCacheType::DISK,
699 // Max size of http cache in bytes.
700 1024000,
701 // Disable caching for HTTP responses. Other information may be stored in
702 // the cache.
703 false,
704 // Storage path for http cache and cookie storage.
705 "/data/data/org.chromium.net/app_cronet_test/test_storage",
Misha Efimovd4ab38302018-01-30 23:56:42706 // Accept-Language request header field.
707 "foreign-language",
Zhongyi Shi64795622017-11-20 02:21:49708 // User-Agent request header field.
709 "fake agent",
710 // JSON encoded experimental options.
Zhongyi Shid02a48c2019-08-27 21:03:58711 // Explicitly turn off "goaway_sessions_on_ip_change" which is default
712 // enabled on iOS but cannot be simultaneously set with migration option.
Zhongyi Shif4683a32017-12-01 00:03:28713 "{\"QUIC\":{\"migrate_sessions_on_network_change_v2\":true,"
Zhongyi Shid02a48c2019-08-27 21:03:58714 "\"goaway_sessions_on_ip_change\":false,"
Zhongyi Shi73f23ca872017-12-13 18:37:13715 "\"migrate_sessions_early_v2\":true,"
Zhongyi Shiff359581bc2018-09-26 18:11:48716 "\"retry_on_alternate_network_before_handshake\":true,"
Zhongyi Shi32fe14d42019-02-28 00:25:36717 "\"migrate_idle_sessions\":true,"
Zhongyi Shie01f2db2019-02-22 19:53:23718 "\"retransmittable_on_wire_timeout_milliseconds\":1000,"
Zhongyi Shibc85e3e2019-02-12 19:34:42719 "\"idle_session_migration_period_seconds\":15,"
Zhongyi Shi8b1e43f2017-12-13 20:46:30720 "\"max_time_on_non_default_network_seconds\":10,"
Zhongyi Shiee760762018-08-01 00:54:29721 "\"max_migrations_to_non_default_network_on_write_error\":3,"
Zhongyi Shi8b1e43f2017-12-13 20:46:30722 "\"max_migrations_to_non_default_network_on_path_degrading\":4}}",
Zhongyi Shi64795622017-11-20 02:21:49723 // MockCertVerifier to use for testing purposes.
724 std::unique_ptr<net::CertVerifier>(),
725 // Enable network quality estimator.
726 false,
727 // Enable Public Key Pinning bypass for local trust anchors.
Paul Jensen6a1ea3a2018-08-24 14:46:41728 true,
729 // Optional network thread priority.
730 base::Optional<double>());
Zhongyi Shi64795622017-11-20 02:21:49731
732 net::URLRequestContextBuilder builder;
Matt Muellerde5dadf2019-11-27 20:11:58733 config.ConfigureURLRequestContextBuilder(&builder);
Zhongyi Shi64795622017-11-20 02:21:49734 // Set a ProxyConfigService to avoid DCHECK failure when building.
735 builder.set_proxy_config_service(
Lily Houghtonef028852017-12-06 20:52:30736 std::make_unique<net::ProxyConfigServiceFixed>(
Ramin Halavatica8d5252018-03-12 05:33:49737 net::ProxyConfigWithAnnotation::CreateDirect()));
Zhongyi Shi64795622017-11-20 02:21:49738 std::unique_ptr<net::URLRequestContext> context(builder.Build());
Victor Vasilieva1e66d72019-12-05 17:55:38739 const net::QuicParams* quic_params = context->quic_context()->params();
Zhongyi Shi64795622017-11-20 02:21:49740
Victor Vasilieva1e66d72019-12-05 17:55:38741 EXPECT_TRUE(quic_params->migrate_sessions_on_network_change_v2);
742 EXPECT_TRUE(quic_params->migrate_sessions_early_v2);
743 EXPECT_TRUE(quic_params->retry_on_alternate_network_before_handshake);
744 EXPECT_EQ(1000,
745 quic_params->retransmittable_on_wire_timeout.InMilliseconds());
746 EXPECT_TRUE(quic_params->migrate_idle_sessions);
Zhongyi Shibc85e3e2019-02-12 19:34:42747 EXPECT_EQ(base::TimeDelta::FromSeconds(15),
Victor Vasilieva1e66d72019-12-05 17:55:38748 quic_params->idle_session_migration_period);
Zhongyi Shi73f23ca872017-12-13 18:37:13749 EXPECT_EQ(base::TimeDelta::FromSeconds(10),
Victor Vasilieva1e66d72019-12-05 17:55:38750 quic_params->max_time_on_non_default_network);
751 EXPECT_EQ(3,
752 quic_params->max_migrations_to_non_default_network_on_write_error);
Zhongyi Shi8b1e43f2017-12-13 20:46:30753 EXPECT_EQ(
Victor Vasilieva1e66d72019-12-05 17:55:38754 4, quic_params->max_migrations_to_non_default_network_on_path_degrading);
Zhongyi Shi64795622017-11-20 02:21:49755}
756
Renjie94b90712018-10-18 21:03:19757TEST(URLRequestContextConfigTest, SetQuicStaleDNSracing) {
Gabriel Charettedfa36042019-08-19 17:30:11758 base::test::TaskEnvironment task_environment_(
759 base::test::TaskEnvironment::MainThreadType::IO);
Renjie94b90712018-10-18 21:03:19760
761 URLRequestContextConfig config(
762 // Enable QUIC.
763 true,
764 // QUIC User Agent ID.
765 "Default QUIC User Agent ID",
766 // Enable SPDY.
767 true,
768 // Enable Brotli.
769 false,
770 // Type of http cache.
771 URLRequestContextConfig::HttpCacheType::DISK,
772 // Max size of http cache in bytes.
773 1024000,
774 // Disable caching for HTTP responses. Other information may be stored in
775 // the cache.
776 false,
777 // Storage path for http cache and cookie storage.
778 "/data/data/org.chromium.net/app_cronet_test/test_storage",
779 // Accept-Language request header field.
780 "foreign-language",
781 // User-Agent request header field.
782 "fake agent",
783 // JSON encoded experimental options.
784 "{\"QUIC\":{\"race_stale_dns_on_connection\":true}}",
785 // MockCertVerifier to use for testing purposes.
786 std::unique_ptr<net::CertVerifier>(),
787 // Enable network quality estimator.
788 false,
789 // Enable Public Key Pinning bypass for local trust anchors.
790 true,
791 // Optional network thread priority.
792 base::Optional<double>());
793
794 net::URLRequestContextBuilder builder;
Matt Muellerde5dadf2019-11-27 20:11:58795 config.ConfigureURLRequestContextBuilder(&builder);
Renjie94b90712018-10-18 21:03:19796 // Set a ProxyConfigService to avoid DCHECK failure when building.
797 builder.set_proxy_config_service(
798 std::make_unique<net::ProxyConfigServiceFixed>(
799 net::ProxyConfigWithAnnotation::CreateDirect()));
800 std::unique_ptr<net::URLRequestContext> context(builder.Build());
Victor Vasilieva1e66d72019-12-05 17:55:38801 const net::QuicParams* quic_params = context->quic_context()->params();
Renjie94b90712018-10-18 21:03:19802
Victor Vasilieva1e66d72019-12-05 17:55:38803 EXPECT_TRUE(quic_params->race_stale_dns_on_connection);
Renjie94b90712018-10-18 21:03:19804}
805
Renjie Tangcbbc84c2019-09-06 22:23:23806TEST(URLRequestContextConfigTest, SetQuicGoawayOnPathDegrading) {
807 base::test::TaskEnvironment task_environment_(
808 base::test::TaskEnvironment::MainThreadType::IO);
809
810 URLRequestContextConfig config(
811 // Enable QUIC.
812 true,
813 // QUIC User Agent ID.
814 "Default QUIC User Agent ID",
815 // Enable SPDY.
816 true,
817 // Enable Brotli.
818 false,
819 // Type of http cache.
820 URLRequestContextConfig::HttpCacheType::DISK,
821 // Max size of http cache in bytes.
822 1024000,
823 // Disable caching for HTTP responses. Other information may be stored in
824 // the cache.
825 false,
826 // Storage path for http cache and cookie storage.
827 "/data/data/org.chromium.net/app_cronet_test/test_storage",
828 // Accept-Language request header field.
829 "foreign-language",
830 // User-Agent request header field.
831 "fake agent",
832 // JSON encoded experimental options.
833 "{\"QUIC\":{\"go_away_on_path_degrading\":true}}",
834 // 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.
839 true,
840 // Optional network thread priority.
841 base::Optional<double>());
842
843 net::URLRequestContextBuilder builder;
Matt Muellerde5dadf2019-11-27 20:11:58844 config.ConfigureURLRequestContextBuilder(&builder);
Renjie Tangcbbc84c2019-09-06 22:23:23845 // Set a ProxyConfigService to avoid DCHECK failure when building.
846 builder.set_proxy_config_service(
847 std::make_unique<net::ProxyConfigServiceFixed>(
848 net::ProxyConfigWithAnnotation::CreateDirect()));
849 std::unique_ptr<net::URLRequestContext> context(builder.Build());
Victor Vasilieva1e66d72019-12-05 17:55:38850 const net::QuicParams* quic_params = context->quic_context()->params();
Renjie Tangcbbc84c2019-09-06 22:23:23851
Victor Vasilieva1e66d72019-12-05 17:55:38852 EXPECT_TRUE(quic_params->go_away_on_path_degrading);
Renjie Tangcbbc84c2019-09-06 22:23:23853}
854
Yixin Wang10f477ed2017-11-21 04:20:20855TEST(URLRequestContextConfigTest, SetQuicHostWhitelist) {
Gabriel Charettedfa36042019-08-19 17:30:11856 base::test::TaskEnvironment task_environment_(
857 base::test::TaskEnvironment::MainThreadType::IO);
Yixin Wang10f477ed2017-11-21 04:20:20858
859 URLRequestContextConfig config(
860 // Enable QUIC.
861 true,
862 // QUIC User Agent ID.
863 "Default QUIC User Agent ID",
864 // Enable SPDY.
865 true,
866 // Enable Brotli.
867 false,
868 // Type of http cache.
869 URLRequestContextConfig::HttpCacheType::DISK,
870 // Max size of http cache in bytes.
871 1024000,
872 // Disable caching for HTTP responses. Other information may be stored in
873 // the cache.
874 false,
875 // Storage path for http cache and cookie storage.
876 "/data/data/org.chromium.net/app_cronet_test/test_storage",
Misha Efimovd4ab38302018-01-30 23:56:42877 // Accept-Language request header field.
878 "foreign-language",
Yixin Wang10f477ed2017-11-21 04:20:20879 // User-Agent request header field.
880 "fake agent",
881 // JSON encoded experimental options.
882 "{\"QUIC\":{\"host_whitelist\":\"www.example.com,www.example.org\"}}",
883 // MockCertVerifier to use for testing purposes.
884 std::unique_ptr<net::CertVerifier>(),
885 // Enable network quality estimator.
886 false,
887 // Enable Public Key Pinning bypass for local trust anchors.
Paul Jensen6a1ea3a2018-08-24 14:46:41888 true,
889 // Optional network thread priority.
890 base::Optional<double>());
Yixin Wang10f477ed2017-11-21 04:20:20891
892 net::URLRequestContextBuilder builder;
Matt Muellerde5dadf2019-11-27 20:11:58893 config.ConfigureURLRequestContextBuilder(&builder);
Yixin Wang10f477ed2017-11-21 04:20:20894 // Set a ProxyConfigService to avoid DCHECK failure when building.
895 builder.set_proxy_config_service(
Lily Houghtonef028852017-12-06 20:52:30896 std::make_unique<net::ProxyConfigServiceFixed>(
Ramin Halavatica8d5252018-03-12 05:33:49897 net::ProxyConfigWithAnnotation::CreateDirect()));
Yixin Wang10f477ed2017-11-21 04:20:20898 std::unique_ptr<net::URLRequestContext> context(builder.Build());
899 const net::HttpNetworkSession::Params* params =
900 context->GetNetworkSessionParams();
901
Ryan Sleevia9d6aa62019-07-26 13:32:18902 EXPECT_TRUE(base::Contains(params->quic_host_allowlist, "www.example.com"));
903 EXPECT_TRUE(base::Contains(params->quic_host_allowlist, "www.example.org"));
Yixin Wang10f477ed2017-11-21 04:20:20904}
905
Yixin Wang983875152017-11-21 20:30:13906TEST(URLRequestContextConfigTest, SetQuicMaxTimeBeforeCryptoHandshake) {
Gabriel Charettedfa36042019-08-19 17:30:11907 base::test::TaskEnvironment task_environment_(
908 base::test::TaskEnvironment::MainThreadType::IO);
Yixin Wang983875152017-11-21 20:30:13909
910 URLRequestContextConfig config(
911 // Enable QUIC.
912 true,
913 // QUIC User Agent ID.
914 "Default QUIC User Agent ID",
915 // Enable SPDY.
916 true,
917 // Enable Brotli.
918 false,
919 // Type of http cache.
920 URLRequestContextConfig::HttpCacheType::DISK,
921 // Max size of http cache in bytes.
922 1024000,
923 // Disable caching for HTTP responses. Other information may be stored in
924 // the cache.
925 false,
926 // Storage path for http cache and cookie storage.
927 "/data/data/org.chromium.net/app_cronet_test/test_storage",
Misha Efimovd4ab38302018-01-30 23:56:42928 // Accept-Language request header field.
929 "foreign-language",
Yixin Wang983875152017-11-21 20:30:13930 // User-Agent request header field.
931 "fake agent",
932 // JSON encoded experimental options.
933 "{\"QUIC\":{\"max_time_before_crypto_handshake_seconds\":7,"
934 "\"max_idle_time_before_crypto_handshake_seconds\":11}}",
935 // MockCertVerifier to use for testing purposes.
936 std::unique_ptr<net::CertVerifier>(),
937 // Enable network quality estimator.
938 false,
939 // Enable Public Key Pinning bypass for local trust anchors.
Paul Jensen6a1ea3a2018-08-24 14:46:41940 true,
941 // Optional network thread priority.
942 base::Optional<double>());
Yixin Wang983875152017-11-21 20:30:13943
944 net::URLRequestContextBuilder builder;
Matt Muellerde5dadf2019-11-27 20:11:58945 config.ConfigureURLRequestContextBuilder(&builder);
Yixin Wang983875152017-11-21 20:30:13946 // Set a ProxyConfigService to avoid DCHECK failure when building.
947 builder.set_proxy_config_service(
Lily Houghtonef028852017-12-06 20:52:30948 std::make_unique<net::ProxyConfigServiceFixed>(
Ramin Halavatica8d5252018-03-12 05:33:49949 net::ProxyConfigWithAnnotation::CreateDirect()));
Yixin Wang983875152017-11-21 20:30:13950 std::unique_ptr<net::URLRequestContext> context(builder.Build());
Victor Vasilieva1e66d72019-12-05 17:55:38951 const net::QuicParams* quic_params = context->quic_context()->params();
Yixin Wang983875152017-11-21 20:30:13952
Victor Vasilieva1e66d72019-12-05 17:55:38953 EXPECT_EQ(7, quic_params->max_time_before_crypto_handshake.InSeconds());
954 EXPECT_EQ(11, quic_params->max_idle_time_before_crypto_handshake.InSeconds());
Yixin Wang983875152017-11-21 20:30:13955}
956
Yixin Wang1875fdb2017-12-06 02:26:49957TEST(URLURLRequestContextConfigTest, SetQuicConnectionOptions) {
Gabriel Charettedfa36042019-08-19 17:30:11958 base::test::TaskEnvironment task_environment_(
959 base::test::TaskEnvironment::MainThreadType::IO);
Yixin Wang1875fdb2017-12-06 02:26:49960
961 URLRequestContextConfig config(
962 // Enable QUIC.
963 true,
964 // QUIC User Agent ID.
965 "Default QUIC User Agent ID",
966 // Enable SPDY.
967 true,
968 // Enable Brotli.
969 false,
970 // Type of http cache.
971 URLRequestContextConfig::HttpCacheType::DISK,
972 // Max size of http cache in bytes.
973 1024000,
974 // Disable caching for HTTP responses. Other information may be stored in
975 // the cache.
976 false,
977 // Storage path for http cache and cookie storage.
978 "/data/data/org.chromium.net/app_cronet_test/test_storage",
Misha Efimovd4ab38302018-01-30 23:56:42979 // Accept-Language request header field.
980 "foreign-language",
Yixin Wang1875fdb2017-12-06 02:26:49981 // User-Agent request header field.
982 "fake agent",
983 // JSON encoded experimental options.
984 "{\"QUIC\":{\"connection_options\":\"TIME,TBBR,REJ\","
985 "\"client_connection_options\":\"TBBR,1RTT\"}}",
986 // MockCertVerifier to use for testing purposes.
987 std::unique_ptr<net::CertVerifier>(),
988 // Enable network quality estimator.
989 false,
990 // Enable Public Key Pinning bypass for local trust anchors.
Paul Jensen6a1ea3a2018-08-24 14:46:41991 true,
992 // Optional network thread priority.
993 base::Optional<double>());
Yixin Wang1875fdb2017-12-06 02:26:49994
995 net::URLRequestContextBuilder builder;
Matt Muellerde5dadf2019-11-27 20:11:58996 config.ConfigureURLRequestContextBuilder(&builder);
Yixin Wang1875fdb2017-12-06 02:26:49997 // Set a ProxyConfigService to avoid DCHECK failure when building.
998 builder.set_proxy_config_service(
Gyuyoung Kim6afb5082018-01-19 13:35:57999 std::make_unique<net::ProxyConfigServiceFixed>(
Ramin Halavatica8d5252018-03-12 05:33:491000 net::ProxyConfigWithAnnotation::CreateDirect()));
Yixin Wang1875fdb2017-12-06 02:26:491001 std::unique_ptr<net::URLRequestContext> context(builder.Build());
Victor Vasilieva1e66d72019-12-05 17:55:381002 const net::QuicParams* quic_params = context->quic_context()->params();
Yixin Wang1875fdb2017-12-06 02:26:491003
Ryan Hamilton8d9ee76e2018-05-29 23:52:521004 quic::QuicTagVector connection_options;
1005 connection_options.push_back(quic::kTIME);
1006 connection_options.push_back(quic::kTBBR);
1007 connection_options.push_back(quic::kREJ);
Victor Vasilieva1e66d72019-12-05 17:55:381008 EXPECT_EQ(connection_options, quic_params->connection_options);
Yixin Wang1875fdb2017-12-06 02:26:491009
Ryan Hamilton8d9ee76e2018-05-29 23:52:521010 quic::QuicTagVector client_connection_options;
1011 client_connection_options.push_back(quic::kTBBR);
1012 client_connection_options.push_back(quic::k1RTT);
Victor Vasilieva1e66d72019-12-05 17:55:381013 EXPECT_EQ(client_connection_options, quic_params->client_connection_options);
Yixin Wang1875fdb2017-12-06 02:26:491014}
1015
Misha Efimovd4ab38302018-01-30 23:56:421016TEST(URLURLRequestContextConfigTest, SetAcceptLanguageAndUserAgent) {
Gabriel Charettedfa36042019-08-19 17:30:111017 base::test::TaskEnvironment task_environment_(
1018 base::test::TaskEnvironment::MainThreadType::IO);
Misha Efimovd4ab38302018-01-30 23:56:421019
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",
1038 // Accept-Language request header field.
1039 "foreign-language",
1040 // User-Agent request header field.
1041 "fake agent",
1042 // JSON encoded experimental options.
1043 "{}",
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>());
Misha Efimovd4ab38302018-01-30 23:56:421052
1053 net::URLRequestContextBuilder builder;
Matt Muellerde5dadf2019-11-27 20:11:581054 config.ConfigureURLRequestContextBuilder(&builder);
Misha Efimovd4ab38302018-01-30 23:56:421055 // Set a ProxyConfigService to avoid DCHECK failure when building.
1056 builder.set_proxy_config_service(
1057 std::make_unique<net::ProxyConfigServiceFixed>(
Ramin Halavatica8d5252018-03-12 05:33:491058 net::ProxyConfigWithAnnotation::CreateDirect()));
Misha Efimovd4ab38302018-01-30 23:56:421059 std::unique_ptr<net::URLRequestContext> context(builder.Build());
1060 EXPECT_EQ("foreign-language",
1061 context->http_user_agent_settings()->GetAcceptLanguage());
1062 EXPECT_EQ("fake agent", context->http_user_agent_settings()->GetUserAgent());
1063}
1064
Renjie Tang8c3a1d02020-04-23 17:42:301065TEST(URLURLRequestContextConfigTest, TurningOffQuic) {
1066 base::test::TaskEnvironment task_environment_(
1067 base::test::TaskEnvironment::MainThreadType::IO);
1068
1069 URLRequestContextConfig config(
1070 // Enable QUIC.
1071 false,
1072 // QUIC User Agent ID.
1073 "Default QUIC User Agent ID",
1074 // Enable SPDY.
1075 true,
1076 // Enable Brotli.
1077 false,
1078 // Type of http cache.
1079 URLRequestContextConfig::HttpCacheType::DISK,
1080 // Max size of http cache in bytes.
1081 1024000,
1082 // Disable caching for HTTP responses. Other information may be stored in
1083 // the cache.
1084 false,
1085 // Storage path for http cache and cookie storage.
1086 "/data/data/org.chromium.net/app_cronet_test/test_storage",
1087 // Accept-Language request header field.
1088 "foreign-language",
1089 // User-Agent request header field.
1090 "fake agent",
1091 // JSON encoded experimental options.
1092 "{}",
1093 // MockCertVerifier to use for testing purposes.
1094 std::unique_ptr<net::CertVerifier>(),
1095 // Enable network quality estimator.
1096 false,
1097 // Enable Public Key Pinning bypass for local trust anchors.
1098 true,
1099 // Optional network thread priority.
1100 base::Optional<double>());
1101
1102 net::URLRequestContextBuilder builder;
1103 config.ConfigureURLRequestContextBuilder(&builder);
1104 // Set a ProxyConfigService to avoid DCHECK failure when building.
1105 builder.set_proxy_config_service(
1106 std::make_unique<net::ProxyConfigServiceFixed>(
1107 net::ProxyConfigWithAnnotation::CreateDirect()));
1108 std::unique_ptr<net::URLRequestContext> context(builder.Build());
1109 const net::HttpNetworkSession::Params* params =
1110 context->GetNetworkSessionParams();
1111 EXPECT_EQ(false, params->enable_quic);
1112}
1113
juliatuttle50d9c4b2016-08-23 22:49:191114// See stale_host_resolver_unittest.cc for test of StaleDNS options.
1115
xunjielif24ee5f2015-11-23 18:05:261116} // namespace cronet