blob: 8278ce60b54b15337b5e09e27266bb4181872e2b [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"
Julia Tuttle3cc27a4a2018-04-25 15:57:0610#include "base/json/json_writer.h"
Eric Orthe1cdd902019-02-26 02:52:4611#include "base/logging.h"
Douglas Creagera220947e2018-08-23 20:08:5312#include "base/strings/string_piece.h"
Gabriel Charettec7108742019-08-23 03:31:4013#include "base/test/task_environment.h"
Douglas Creagera220947e2018-08-23 20:08:5314#include "base/test/values_test_util.h"
tfhef3618f2016-01-11 23:07:0815#include "base/values.h"
Zhongyi Shiaa518c22018-06-15 04:37:3616#include "build/build_config.h"
Eric Orthe1cdd902019-02-26 02:52:4617#include "net/base/host_port_pair.h"
Matt Menked732ea42019-03-08 12:05:0018#include "net/base/http_user_agent_settings.h"
Eric Orthe1cdd902019-02-26 02:52:4619#include "net/base/net_errors.h"
pauljensen9041eb3c2015-12-09 12:29:0120#include "net/cert/cert_verifier.h"
Eric Orthe1cdd902019-02-26 02:52:4621#include "net/dns/host_resolver.h"
Eric Orth607b6d82019-05-08 16:43:3222#include "net/dns/host_resolver_manager.h"
xunjielif24ee5f2015-11-23 18:05:2623#include "net/http/http_network_session.h"
mikecironef22f9812016-10-04 03:40:1924#include "net/log/net_log_with_source.h"
Lily Houghton582d4622018-01-22 22:43:4025#include "net/proxy_resolution/proxy_config.h"
26#include "net/proxy_resolution/proxy_config_service_fixed.h"
xunjielif24ee5f2015-11-23 18:05:2627#include "net/url_request/url_request_context.h"
28#include "net/url_request/url_request_context_builder.h"
29#include "testing/gtest/include/gtest/gtest.h"
30
Douglas Creagera220947e2018-08-23 20:08:5331#if BUILDFLAG(ENABLE_REPORTING)
32#include "net/network_error_logging/network_error_logging_service.h"
33#include "net/reporting/reporting_service.h"
34#endif // BUILDFLAG(ENABLE_REPORTING)
35
xunjielif24ee5f2015-11-23 18:05:2636namespace cronet {
37
Douglas Creagera220947e2018-08-23 20:08:5338namespace {
39
Douglas Creagera220947e2018-08-23 20:08:5340std::string WrapJsonHeader(base::StringPiece value) {
41 std::string result;
42 result.reserve(value.size() + 2);
43 result.push_back('[');
44 value.AppendToString(&result);
45 result.push_back(']');
46 return result;
47}
48
49// Returns whether two JSON-encoded headers contain the same content, ignoring
50// irrelevant encoding issues like whitespace and map element ordering.
51bool JsonHeaderEquals(base::StringPiece expected, base::StringPiece actual) {
Lei Zhang9b9d5792019-02-20 07:24:4252 return base::test::ParseJson(WrapJsonHeader(expected)) ==
53 base::test::ParseJson(WrapJsonHeader(actual));
Douglas Creagera220947e2018-08-23 20:08:5354}
55
56} // namespace
57
mmenke51629db12017-06-28 13:34:1258TEST(URLRequestContextConfigTest, TestExperimentalOptionParsing) {
Gabriel Charettedfa36042019-08-19 17:30:1159 base::test::TaskEnvironment task_environment_(
60 base::test::TaskEnvironment::MainThreadType::IO);
mmenke51629db12017-06-28 13:34:1261
Julia Tuttle3cc27a4a2018-04-25 15:57:0662 // Create JSON for experimental options.
63 base::DictionaryValue options;
64 options.SetPath({"QUIC", "max_server_configs_stored_in_properties"},
65 base::Value(2));
66 options.SetPath({"QUIC", "user_agent_id"}, base::Value("Custom QUIC UAID"));
67 options.SetPath({"QUIC", "idle_connection_timeout_seconds"},
68 base::Value(300));
69 options.SetPath({"QUIC", "close_sessions_on_ip_change"}, base::Value(true));
70 options.SetPath({"QUIC", "race_cert_verification"}, base::Value(true));
71 options.SetPath({"QUIC", "connection_options"}, base::Value("TIME,TBBR,REJ"));
Ryan Hamiltona31239f12019-09-25 21:01:0072 options.SetPath(
73 {"QUIC", "set_quic_flags"},
74 base::Value("FLAGS_quic_reloadable_flag_quic_supports_tls_handshake=true,"
75 "FLAGS_quic_reloadable_flag_quic_enable_version_99=true"));
Julia Tuttle3cc27a4a2018-04-25 15:57:0676 options.SetPath({"AsyncDNS", "enable"}, base::Value(true));
77 options.SetPath({"NetworkErrorLogging", "enable"}, base::Value(true));
Douglas Creagera220947e2018-08-23 20:08:5378 options.SetPath({"NetworkErrorLogging", "preloaded_report_to_headers"},
Lei Zhang9b9d5792019-02-20 07:24:4279 base::test::ParseJson(R"json(
Douglas Creagera220947e2018-08-23 20:08:5380 [
81 {
82 "origin": "https://test-origin/",
83 "value": {
84 "group": "test-group",
85 "max_age": 86400,
86 "endpoints": [
87 {"url": "https://test-endpoint/"},
88 ],
89 },
90 },
91 {
92 "origin": "https://test-origin-2/",
93 "value": [
94 {
95 "group": "test-group-2",
96 "max_age": 86400,
97 "endpoints": [
98 {"url": "https://test-endpoint-2/"},
99 ],
100 },
101 {
102 "group": "test-group-3",
103 "max_age": 86400,
104 "endpoints": [
105 {"url": "https://test-endpoint-3/"},
106 ],
107 },
108 ],
109 },
110 {
111 "origin": "https://value-is-missing/",
112 },
113 {
114 "value": "origin is missing",
115 },
116 {
117 "origin": 123,
118 "value": "origin is not a string",
119 },
120 {
121 "origin": "this is not a URL",
122 "value": "origin not a URL",
123 },
124 ]
125 )json"));
126 options.SetPath({"NetworkErrorLogging", "preloaded_nel_headers"},
Lei Zhang9b9d5792019-02-20 07:24:42127 base::test::ParseJson(R"json(
Douglas Creagera220947e2018-08-23 20:08:53128 [
129 {
130 "origin": "https://test-origin/",
131 "value": {
132 "report_to": "test-group",
133 "max_age": 86400,
134 },
135 },
136 ]
137 )json"));
Julia Tuttle3cc27a4a2018-04-25 15:57:06138 options.SetPath({"UnknownOption", "foo"}, base::Value(true));
139 options.SetPath({"HostResolverRules", "host_resolver_rules"},
140 base::Value("MAP * 127.0.0.1"));
141 // See http://crbug.com/696569.
142 options.SetKey("disable_ipv6_on_wifi", base::Value(true));
143 std::string options_json;
144 EXPECT_TRUE(base::JSONWriter::Write(options, &options_json));
145
Ryan Hamiltona31239f12019-09-25 21:01:00146 // Initialize QUIC flags set by the config.
147 FLAGS_quic_reloadable_flag_quic_supports_tls_handshake = false;
148 FLAGS_quic_reloadable_flag_quic_enable_version_99 = false;
149
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());
xunjielif24ee5f2015-11-23 18:05:26191 const net::HttpNetworkSession::Params* params =
192 context->GetNetworkSessionParams();
193 // Check Quic Connection options.
Ryan Hamilton8d9ee76e2018-05-29 23:52:52194 quic::QuicTagVector quic_connection_options;
195 quic_connection_options.push_back(quic::kTIME);
196 quic_connection_options.push_back(quic::kTBBR);
197 quic_connection_options.push_back(quic::kREJ);
Nick Harper72ade192019-07-17 03:30:42198 EXPECT_EQ(quic_connection_options, params->quic_params.connection_options);
xunjielif24ee5f2015-11-23 18:05:26199
Ryan Hamiltona31239f12019-09-25 21:01:00200 EXPECT_TRUE(FLAGS_quic_reloadable_flag_quic_supports_tls_handshake);
201 EXPECT_TRUE(FLAGS_quic_reloadable_flag_quic_enable_version_99);
202
mefc5da5712016-02-09 20:14:23203 // Check Custom QUIC User Agent Id.
Nick Harper72ade192019-07-17 03:30:42204 EXPECT_EQ("Custom QUIC UAID", params->quic_params.user_agent_id);
mefc5da5712016-02-09 20:14:23205
rtenneti6971c172016-01-15 20:12:10206 // Check max_server_configs_stored_in_properties.
Nick Harper72ade192019-07-17 03:30:42207 EXPECT_EQ(2u, params->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.
210 EXPECT_EQ(300, params->quic_params.idle_connection_timeout.InSeconds());
rtenneti64e809d02015-12-11 00:26:20211
Nick Harper72ade192019-07-17 03:30:42212 EXPECT_TRUE(params->quic_params.close_sessions_on_ip_change);
213 EXPECT_FALSE(params->quic_params.goaway_sessions_on_ip_change);
214 EXPECT_FALSE(params->quic_params.allow_server_migration);
215 EXPECT_FALSE(params->quic_params.migrate_sessions_on_network_change_v2);
216 EXPECT_FALSE(params->quic_params.migrate_sessions_early_v2);
217 EXPECT_FALSE(params->quic_params.migrate_idle_sessions);
218 EXPECT_FALSE(params->quic_params.retry_on_alternate_network_before_handshake);
219 EXPECT_FALSE(params->quic_params.race_stale_dns_on_connection);
Renjie Tangcbbc84c2019-09-06 22:23:23220 EXPECT_FALSE(params->quic_params.go_away_on_path_degrading);
jrid26566952016-02-04 21:06:42221
rtennetid073dd22016-08-04 01:58:33222 // Check race_cert_verification.
Nick Harper72ade192019-07-17 03:30:42223 EXPECT_TRUE(params->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());
346 const net::HttpNetworkSession::Params* params =
347 context->GetNetworkSessionParams();
Nick Harper72ade192019-07-17 03:30:42348 EXPECT_EQ(params->quic_params.supported_versions.size(), 1u);
349 EXPECT_EQ(params->quic_params.supported_versions[0],
Nick Harper23290b82019-05-02 00:02:56350 quic::ParsedQuicVersion(quic::PROTOCOL_QUIC_CRYPTO,
Ryan Hamilton8380c652019-06-04 02:25:06351 quic::QUIC_VERSION_46));
Zhongyi Shi57247962018-11-05 20:03:52352}
353
354TEST(URLRequestContextConfigTest, SetUnsupportedQuicVersion) {
Gabriel Charettedfa36042019-08-19 17:30:11355 base::test::TaskEnvironment task_environment_(
356 base::test::TaskEnvironment::MainThreadType::IO);
Zhongyi Shi57247962018-11-05 20:03:52357
358 URLRequestContextConfig config(
359 // Enable QUIC.
360 true,
361 // QUIC User Agent ID.
362 "Default QUIC User Agent ID",
363 // Enable SPDY.
364 true,
365 // Enable Brotli.
366 false,
367 // Type of http cache.
368 URLRequestContextConfig::HttpCacheType::DISK,
369 // Max size of http cache in bytes.
370 1024000,
371 // Disable caching for HTTP responses. Other information may be stored in
372 // the cache.
373 false,
374 // Storage path for http cache and cookie storage.
375 "/data/data/org.chromium.net/app_cronet_test/test_storage",
376 // Accept-Language request header field.
377 "foreign-language",
378 // User-Agent request header field.
379 "fake agent",
380 // JSON encoded experimental options.
381 "{\"QUIC\":{\"quic_version\":\"QUIC_VERSION_33\"}}",
382 // MockCertVerifier to use for testing purposes.
383 std::unique_ptr<net::CertVerifier>(),
384 // Enable network quality estimator.
385 false,
386 // Enable Public Key Pinning bypass for local trust anchors.
387 true,
388 // Optional network thread priority.
389 base::Optional<double>());
390
391 net::URLRequestContextBuilder builder;
Matt Muellerde5dadf2019-11-27 20:11:58392 config.ConfigureURLRequestContextBuilder(&builder);
Zhongyi Shi57247962018-11-05 20:03:52393 // Set a ProxyConfigService to avoid DCHECK failure when building.
394 builder.set_proxy_config_service(
395 std::make_unique<net::ProxyConfigServiceFixed>(
396 net::ProxyConfigWithAnnotation::CreateDirect()));
397 std::unique_ptr<net::URLRequestContext> context(builder.Build());
398 const net::HttpNetworkSession::Params* params =
399 context->GetNetworkSessionParams();
Nick Harper72ade192019-07-17 03:30:42400 EXPECT_EQ(params->quic_params.supported_versions.size(), 1u);
401 EXPECT_EQ(params->quic_params.supported_versions[0],
Nick Harper23290b82019-05-02 00:02:56402 quic::ParsedQuicVersion(quic::PROTOCOL_QUIC_CRYPTO,
Ryan Hamilton3cbc5632019-05-20 17:16:29403 quic::QUIC_VERSION_46));
Zhongyi Shi57247962018-11-05 20:03:52404}
405
Zhongyi Shi8ff38c12018-02-22 00:02:30406TEST(URLRequestContextConfigTest, SetQuicServerMigrationOptions) {
Gabriel Charettedfa36042019-08-19 17:30:11407 base::test::TaskEnvironment task_environment_(
408 base::test::TaskEnvironment::MainThreadType::IO);
Zhongyi Shi8ff38c12018-02-22 00:02:30409
410 URLRequestContextConfig config(
411 // Enable QUIC.
412 true,
413 // QUIC User Agent ID.
414 "Default QUIC User Agent ID",
415 // Enable SPDY.
416 true,
417 // Enable Brotli.
418 false,
419 // Type of http cache.
420 URLRequestContextConfig::HttpCacheType::DISK,
421 // Max size of http cache in bytes.
422 1024000,
423 // Disable caching for HTTP responses. Other information may be stored in
424 // the cache.
425 false,
426 // Storage path for http cache and cookie storage.
427 "/data/data/org.chromium.net/app_cronet_test/test_storage",
428 // Accept-Language request header field.
429 "foreign-language",
430 // User-Agent request header field.
431 "fake agent",
432 // JSON encoded experimental options.
433 "{\"QUIC\":{\"allow_server_migration\":true}}",
434 // MockCertVerifier to use for testing purposes.
435 std::unique_ptr<net::CertVerifier>(),
436 // Enable network quality estimator.
437 false,
438 // Enable Public Key Pinning bypass for local trust anchors.
Paul Jensen6a1ea3a2018-08-24 14:46:41439 true,
440 // Optional network thread priority.
441 base::Optional<double>());
Zhongyi Shi8ff38c12018-02-22 00:02:30442
443 net::URLRequestContextBuilder builder;
Matt Muellerde5dadf2019-11-27 20:11:58444 config.ConfigureURLRequestContextBuilder(&builder);
Zhongyi Shi8ff38c12018-02-22 00:02:30445 // Set a ProxyConfigService to avoid DCHECK failure when building.
446 builder.set_proxy_config_service(
447 std::make_unique<net::ProxyConfigServiceFixed>(
Ramin Halavatica8d5252018-03-12 05:33:49448 net::ProxyConfigWithAnnotation::CreateDirect()));
Zhongyi Shi8ff38c12018-02-22 00:02:30449 std::unique_ptr<net::URLRequestContext> context(builder.Build());
450 const net::HttpNetworkSession::Params* params =
451 context->GetNetworkSessionParams();
452
Nick Harper72ade192019-07-17 03:30:42453 EXPECT_FALSE(params->quic_params.close_sessions_on_ip_change);
454 EXPECT_TRUE(params->quic_params.allow_server_migration);
Zhongyi Shi8ff38c12018-02-22 00:02:30455}
456
Zhongyi Shiaa518c22018-06-15 04:37:36457// Test that goaway_sessions_on_ip_change is set on by default for iOS.
458#if defined(OS_IOS)
459#define MAYBE_SetQuicGoAwaySessionsOnIPChangeByDefault \
460 SetQuicGoAwaySessionsOnIPChangeByDefault
461#else
462#define MAYBE_SetQuicGoAwaySessionsOnIPChangeByDefault \
463 DISABLED_SetQuicGoAwaySessionsOnIPChangeByDefault
464#endif
465TEST(URLRequestContextConfigTest,
466 MAYBE_SetQuicGoAwaySessionsOnIPChangeByDefault) {
Gabriel Charettedfa36042019-08-19 17:30:11467 base::test::TaskEnvironment task_environment_(
468 base::test::TaskEnvironment::MainThreadType::IO);
Zhongyi Shiaa518c22018-06-15 04:37:36469
470 URLRequestContextConfig config(
471 // Enable QUIC.
472 true,
473 // QUIC User Agent ID.
474 "Default QUIC User Agent ID",
475 // Enable SPDY.
476 true,
477 // Enable Brotli.
478 false,
479 // Type of http cache.
480 URLRequestContextConfig::HttpCacheType::DISK,
481 // Max size of http cache in bytes.
482 1024000,
483 // Disable caching for HTTP responses. Other information may be stored in
484 // the cache.
485 false,
486 // Storage path for http cache and cookie storage.
487 "/data/data/org.chromium.net/app_cronet_test/test_storage",
488 // Accept-Language request header field.
489 "foreign-language",
490 // User-Agent request header field.
491 "fake agent",
492 // JSON encoded experimental options.
493 "{\"QUIC\":{}}",
494 // MockCertVerifier to use for testing purposes.
495 std::unique_ptr<net::CertVerifier>(),
496 // Enable network quality estimator.
497 false,
498 // Enable Public Key Pinning bypass for local trust anchors.
Paul Jensen6a1ea3a2018-08-24 14:46:41499 true,
500 // Optional network thread priority.
501 base::Optional<double>());
Zhongyi Shiaa518c22018-06-15 04:37:36502
503 net::URLRequestContextBuilder builder;
Matt Muellerde5dadf2019-11-27 20:11:58504 config.ConfigureURLRequestContextBuilder(&builder);
Zhongyi Shiaa518c22018-06-15 04:37:36505 // Set a ProxyConfigService to avoid DCHECK failure when building.
506 builder.set_proxy_config_service(
507 std::make_unique<net::ProxyConfigServiceFixed>(
508 net::ProxyConfigWithAnnotation::CreateDirect()));
509 std::unique_ptr<net::URLRequestContext> context(builder.Build());
510 const net::HttpNetworkSession::Params* params =
511 context->GetNetworkSessionParams();
512
Nick Harper72ade192019-07-17 03:30:42513 EXPECT_FALSE(params->quic_params.close_sessions_on_ip_change);
514 EXPECT_TRUE(params->quic_params.goaway_sessions_on_ip_change);
Zhongyi Shiaa518c22018-06-15 04:37:36515}
516
517// Tests that goaway_sessions_on_ip_changes can be set on via
518// experimental options on non-iOS.
519#if !defined(OS_IOS)
520#define MAYBE_SetQuicGoAwaySessionsOnIPChangeViaExperimentOptions \
521 SetQuicGoAwaySessionsOnIPChangeViaExperimentOptions
522#else
523#define MAYBE_SetQuicGoAwaySessionsOnIPChangeViaExperimentOptions \
524 DISABLED_SetQuicGoAwaySessionsOnIPChangeViaExperimentOptions
525#endif
526TEST(URLRequestContextConfigTest,
527 MAYBE_SetQuicGoAwaySessionsOnIPChangeViaExperimentOptions) {
Gabriel Charettedfa36042019-08-19 17:30:11528 base::test::TaskEnvironment task_environment_(
529 base::test::TaskEnvironment::MainThreadType::IO);
Zhongyi Shi63574b72018-06-01 20:22:25530
531 URLRequestContextConfig config(
532 // Enable QUIC.
533 true,
534 // QUIC User Agent ID.
535 "Default QUIC User Agent ID",
536 // Enable SPDY.
537 true,
538 // Enable Brotli.
539 false,
540 // Type of http cache.
541 URLRequestContextConfig::HttpCacheType::DISK,
542 // Max size of http cache in bytes.
543 1024000,
544 // Disable caching for HTTP responses. Other information may be stored in
545 // the cache.
546 false,
547 // Storage path for http cache and cookie storage.
548 "/data/data/org.chromium.net/app_cronet_test/test_storage",
549 // Accept-Language request header field.
550 "foreign-language",
551 // User-Agent request header field.
552 "fake agent",
553 // JSON encoded experimental options.
554 "{\"QUIC\":{\"goaway_sessions_on_ip_change\":true}}",
555 // MockCertVerifier to use for testing purposes.
556 std::unique_ptr<net::CertVerifier>(),
557 // Enable network quality estimator.
558 false,
559 // Enable Public Key Pinning bypass for local trust anchors.
Paul Jensen6a1ea3a2018-08-24 14:46:41560 true,
561 // Optional network thread priority.
562 base::Optional<double>());
Zhongyi Shi63574b72018-06-01 20:22:25563
564 net::URLRequestContextBuilder builder;
Matt Muellerde5dadf2019-11-27 20:11:58565 config.ConfigureURLRequestContextBuilder(&builder);
Zhongyi Shi63574b72018-06-01 20:22:25566 // Set a ProxyConfigService to avoid DCHECK failure when building.
567 builder.set_proxy_config_service(
568 std::make_unique<net::ProxyConfigServiceFixed>(
569 net::ProxyConfigWithAnnotation::CreateDirect()));
570 std::unique_ptr<net::URLRequestContext> context(builder.Build());
571 const net::HttpNetworkSession::Params* params =
572 context->GetNetworkSessionParams();
573
Nick Harper72ade192019-07-17 03:30:42574 EXPECT_FALSE(params->quic_params.close_sessions_on_ip_change);
575 EXPECT_TRUE(params->quic_params.goaway_sessions_on_ip_change);
Zhongyi Shi63574b72018-06-01 20:22:25576}
577
Zhongyi Shiaa518c22018-06-15 04:37:36578// Test that goaway_sessions_on_ip_change can be set to false via
579// exprimental options on iOS.
580#if defined(OS_IOS)
581#define MAYBE_DisableQuicGoAwaySessionsOnIPChangeViaExperimentOptions \
582 DisableQuicGoAwaySessionsOnIPChangeViaExperimentOptions
583#else
584#define MAYBE_DisableQuicGoAwaySessionsOnIPChangeViaExperimentOptions \
585 DISABLED_DisableQuicGoAwaySessionsOnIPChangeViaExperimentOptions
586#endif
587TEST(URLRequestContextConfigTest,
588 MAYBE_DisableQuicGoAwaySessionsOnIPChangeViaExperimentOptions) {
Gabriel Charettedfa36042019-08-19 17:30:11589 base::test::TaskEnvironment task_environment_(
590 base::test::TaskEnvironment::MainThreadType::IO);
Zhongyi Shiaa518c22018-06-15 04:37:36591
592 URLRequestContextConfig config(
593 // Enable QUIC.
594 true,
595 // QUIC User Agent ID.
596 "Default QUIC User Agent ID",
597 // Enable SPDY.
598 true,
599 // Enable Brotli.
600 false,
601 // Type of http cache.
602 URLRequestContextConfig::HttpCacheType::DISK,
603 // Max size of http cache in bytes.
604 1024000,
605 // Disable caching for HTTP responses. Other information may be stored in
606 // the cache.
607 false,
608 // Storage path for http cache and cookie storage.
609 "/data/data/org.chromium.net/app_cronet_test/test_storage",
610 // Accept-Language request header field.
611 "foreign-language",
612 // User-Agent request header field.
613 "fake agent",
614 // JSON encoded experimental options.
615 "{\"QUIC\":{\"goaway_sessions_on_ip_change\":false}}",
616 // MockCertVerifier to use for testing purposes.
617 std::unique_ptr<net::CertVerifier>(),
618 // Enable network quality estimator.
619 false,
620 // Enable Public Key Pinning bypass for local trust anchors.
Paul Jensen6a1ea3a2018-08-24 14:46:41621 true,
622 // Optional network thread priority.
623 base::Optional<double>());
Zhongyi Shiaa518c22018-06-15 04:37:36624
625 net::URLRequestContextBuilder builder;
Matt Muellerde5dadf2019-11-27 20:11:58626 config.ConfigureURLRequestContextBuilder(&builder);
Zhongyi Shiaa518c22018-06-15 04:37:36627 // Set a ProxyConfigService to avoid DCHECK failure when building.
628 builder.set_proxy_config_service(
629 std::make_unique<net::ProxyConfigServiceFixed>(
630 net::ProxyConfigWithAnnotation::CreateDirect()));
631 std::unique_ptr<net::URLRequestContext> context(builder.Build());
632 const net::HttpNetworkSession::Params* params =
633 context->GetNetworkSessionParams();
634
Nick Harper72ade192019-07-17 03:30:42635 EXPECT_FALSE(params->quic_params.close_sessions_on_ip_change);
636 EXPECT_FALSE(params->quic_params.goaway_sessions_on_ip_change);
Zhongyi Shiaa518c22018-06-15 04:37:36637}
638
Yixin Wang10f477ed2017-11-21 04:20:20639TEST(URLRequestContextConfigTest, SetQuicConnectionMigrationV2Options) {
Gabriel Charettedfa36042019-08-19 17:30:11640 base::test::TaskEnvironment task_environment_(
641 base::test::TaskEnvironment::MainThreadType::IO);
Zhongyi Shi64795622017-11-20 02:21:49642
643 URLRequestContextConfig config(
644 // Enable QUIC.
645 true,
646 // QUIC User Agent ID.
647 "Default QUIC User Agent ID",
648 // Enable SPDY.
649 true,
650 // Enable Brotli.
651 false,
652 // Type of http cache.
653 URLRequestContextConfig::HttpCacheType::DISK,
654 // Max size of http cache in bytes.
655 1024000,
656 // Disable caching for HTTP responses. Other information may be stored in
657 // the cache.
658 false,
659 // Storage path for http cache and cookie storage.
660 "/data/data/org.chromium.net/app_cronet_test/test_storage",
Misha Efimovd4ab38302018-01-30 23:56:42661 // Accept-Language request header field.
662 "foreign-language",
Zhongyi Shi64795622017-11-20 02:21:49663 // User-Agent request header field.
664 "fake agent",
665 // JSON encoded experimental options.
Zhongyi Shid02a48c2019-08-27 21:03:58666 // Explicitly turn off "goaway_sessions_on_ip_change" which is default
667 // enabled on iOS but cannot be simultaneously set with migration option.
Zhongyi Shif4683a32017-12-01 00:03:28668 "{\"QUIC\":{\"migrate_sessions_on_network_change_v2\":true,"
Zhongyi Shid02a48c2019-08-27 21:03:58669 "\"goaway_sessions_on_ip_change\":false,"
Zhongyi Shi73f23ca872017-12-13 18:37:13670 "\"migrate_sessions_early_v2\":true,"
Zhongyi Shiff359581bc2018-09-26 18:11:48671 "\"retry_on_alternate_network_before_handshake\":true,"
Zhongyi Shi32fe14d42019-02-28 00:25:36672 "\"migrate_idle_sessions\":true,"
Zhongyi Shie01f2db2019-02-22 19:53:23673 "\"retransmittable_on_wire_timeout_milliseconds\":1000,"
Zhongyi Shibc85e3e2019-02-12 19:34:42674 "\"idle_session_migration_period_seconds\":15,"
Zhongyi Shi8b1e43f2017-12-13 20:46:30675 "\"max_time_on_non_default_network_seconds\":10,"
Zhongyi Shiee760762018-08-01 00:54:29676 "\"max_migrations_to_non_default_network_on_write_error\":3,"
Zhongyi Shi8b1e43f2017-12-13 20:46:30677 "\"max_migrations_to_non_default_network_on_path_degrading\":4}}",
Zhongyi Shi64795622017-11-20 02:21:49678 // MockCertVerifier to use for testing purposes.
679 std::unique_ptr<net::CertVerifier>(),
680 // Enable network quality estimator.
681 false,
682 // Enable Public Key Pinning bypass for local trust anchors.
Paul Jensen6a1ea3a2018-08-24 14:46:41683 true,
684 // Optional network thread priority.
685 base::Optional<double>());
Zhongyi Shi64795622017-11-20 02:21:49686
687 net::URLRequestContextBuilder builder;
Matt Muellerde5dadf2019-11-27 20:11:58688 config.ConfigureURLRequestContextBuilder(&builder);
Zhongyi Shi64795622017-11-20 02:21:49689 // Set a ProxyConfigService to avoid DCHECK failure when building.
690 builder.set_proxy_config_service(
Lily Houghtonef028852017-12-06 20:52:30691 std::make_unique<net::ProxyConfigServiceFixed>(
Ramin Halavatica8d5252018-03-12 05:33:49692 net::ProxyConfigWithAnnotation::CreateDirect()));
Zhongyi Shi64795622017-11-20 02:21:49693 std::unique_ptr<net::URLRequestContext> context(builder.Build());
694 const net::HttpNetworkSession::Params* params =
695 context->GetNetworkSessionParams();
696
Nick Harper72ade192019-07-17 03:30:42697 EXPECT_TRUE(params->quic_params.migrate_sessions_on_network_change_v2);
698 EXPECT_TRUE(params->quic_params.migrate_sessions_early_v2);
699 EXPECT_TRUE(params->quic_params.retry_on_alternate_network_before_handshake);
Ryan Sleevi2e8255b2019-07-17 21:02:21700 EXPECT_EQ(
701 1000,
702 params->quic_params.retransmittable_on_wire_timeout.InMilliseconds());
Nick Harper72ade192019-07-17 03:30:42703 EXPECT_TRUE(params->quic_params.migrate_idle_sessions);
Zhongyi Shibc85e3e2019-02-12 19:34:42704 EXPECT_EQ(base::TimeDelta::FromSeconds(15),
Nick Harper72ade192019-07-17 03:30:42705 params->quic_params.idle_session_migration_period);
Zhongyi Shi73f23ca872017-12-13 18:37:13706 EXPECT_EQ(base::TimeDelta::FromSeconds(10),
Nick Harper72ade192019-07-17 03:30:42707 params->quic_params.max_time_on_non_default_network);
Zhongyi Shi8b1e43f2017-12-13 20:46:30708 EXPECT_EQ(
Nick Harper72ade192019-07-17 03:30:42709 3,
710 params->quic_params.max_migrations_to_non_default_network_on_write_error);
711 EXPECT_EQ(4, params->quic_params
712 .max_migrations_to_non_default_network_on_path_degrading);
Zhongyi Shi64795622017-11-20 02:21:49713}
714
Renjie94b90712018-10-18 21:03:19715TEST(URLRequestContextConfigTest, SetQuicStaleDNSracing) {
Gabriel Charettedfa36042019-08-19 17:30:11716 base::test::TaskEnvironment task_environment_(
717 base::test::TaskEnvironment::MainThreadType::IO);
Renjie94b90712018-10-18 21:03:19718
719 URLRequestContextConfig config(
720 // Enable QUIC.
721 true,
722 // QUIC User Agent ID.
723 "Default QUIC User Agent ID",
724 // Enable SPDY.
725 true,
726 // Enable Brotli.
727 false,
728 // Type of http cache.
729 URLRequestContextConfig::HttpCacheType::DISK,
730 // Max size of http cache in bytes.
731 1024000,
732 // Disable caching for HTTP responses. Other information may be stored in
733 // the cache.
734 false,
735 // Storage path for http cache and cookie storage.
736 "/data/data/org.chromium.net/app_cronet_test/test_storage",
737 // Accept-Language request header field.
738 "foreign-language",
739 // User-Agent request header field.
740 "fake agent",
741 // JSON encoded experimental options.
742 "{\"QUIC\":{\"race_stale_dns_on_connection\":true}}",
743 // MockCertVerifier to use for testing purposes.
744 std::unique_ptr<net::CertVerifier>(),
745 // Enable network quality estimator.
746 false,
747 // Enable Public Key Pinning bypass for local trust anchors.
748 true,
749 // Optional network thread priority.
750 base::Optional<double>());
751
752 net::URLRequestContextBuilder builder;
Matt Muellerde5dadf2019-11-27 20:11:58753 config.ConfigureURLRequestContextBuilder(&builder);
Renjie94b90712018-10-18 21:03:19754 // Set a ProxyConfigService to avoid DCHECK failure when building.
755 builder.set_proxy_config_service(
756 std::make_unique<net::ProxyConfigServiceFixed>(
757 net::ProxyConfigWithAnnotation::CreateDirect()));
758 std::unique_ptr<net::URLRequestContext> context(builder.Build());
759 const net::HttpNetworkSession::Params* params =
760 context->GetNetworkSessionParams();
761
Nick Harper72ade192019-07-17 03:30:42762 EXPECT_TRUE(params->quic_params.race_stale_dns_on_connection);
Renjie94b90712018-10-18 21:03:19763}
764
Renjie Tangcbbc84c2019-09-06 22:23:23765TEST(URLRequestContextConfigTest, SetQuicGoawayOnPathDegrading) {
766 base::test::TaskEnvironment task_environment_(
767 base::test::TaskEnvironment::MainThreadType::IO);
768
769 URLRequestContextConfig config(
770 // Enable QUIC.
771 true,
772 // QUIC User Agent ID.
773 "Default QUIC User Agent ID",
774 // Enable SPDY.
775 true,
776 // Enable Brotli.
777 false,
778 // Type of http cache.
779 URLRequestContextConfig::HttpCacheType::DISK,
780 // Max size of http cache in bytes.
781 1024000,
782 // Disable caching for HTTP responses. Other information may be stored in
783 // the cache.
784 false,
785 // Storage path for http cache and cookie storage.
786 "/data/data/org.chromium.net/app_cronet_test/test_storage",
787 // Accept-Language request header field.
788 "foreign-language",
789 // User-Agent request header field.
790 "fake agent",
791 // JSON encoded experimental options.
792 "{\"QUIC\":{\"go_away_on_path_degrading\":true}}",
793 // MockCertVerifier to use for testing purposes.
794 std::unique_ptr<net::CertVerifier>(),
795 // Enable network quality estimator.
796 false,
797 // Enable Public Key Pinning bypass for local trust anchors.
798 true,
799 // Optional network thread priority.
800 base::Optional<double>());
801
802 net::URLRequestContextBuilder builder;
Matt Muellerde5dadf2019-11-27 20:11:58803 config.ConfigureURLRequestContextBuilder(&builder);
Renjie Tangcbbc84c2019-09-06 22:23:23804 // Set a ProxyConfigService to avoid DCHECK failure when building.
805 builder.set_proxy_config_service(
806 std::make_unique<net::ProxyConfigServiceFixed>(
807 net::ProxyConfigWithAnnotation::CreateDirect()));
808 std::unique_ptr<net::URLRequestContext> context(builder.Build());
809 const net::HttpNetworkSession::Params* params =
810 context->GetNetworkSessionParams();
811
812 EXPECT_TRUE(params->quic_params.go_away_on_path_degrading);
813}
814
Yixin Wang10f477ed2017-11-21 04:20:20815TEST(URLRequestContextConfigTest, SetQuicHostWhitelist) {
Gabriel Charettedfa36042019-08-19 17:30:11816 base::test::TaskEnvironment task_environment_(
817 base::test::TaskEnvironment::MainThreadType::IO);
Yixin Wang10f477ed2017-11-21 04:20:20818
819 URLRequestContextConfig config(
820 // Enable QUIC.
821 true,
822 // QUIC User Agent ID.
823 "Default QUIC User Agent ID",
824 // Enable SPDY.
825 true,
826 // Enable Brotli.
827 false,
828 // Type of http cache.
829 URLRequestContextConfig::HttpCacheType::DISK,
830 // Max size of http cache in bytes.
831 1024000,
832 // Disable caching for HTTP responses. Other information may be stored in
833 // the cache.
834 false,
835 // Storage path for http cache and cookie storage.
836 "/data/data/org.chromium.net/app_cronet_test/test_storage",
Misha Efimovd4ab38302018-01-30 23:56:42837 // Accept-Language request header field.
838 "foreign-language",
Yixin Wang10f477ed2017-11-21 04:20:20839 // User-Agent request header field.
840 "fake agent",
841 // JSON encoded experimental options.
842 "{\"QUIC\":{\"host_whitelist\":\"www.example.com,www.example.org\"}}",
843 // MockCertVerifier to use for testing purposes.
844 std::unique_ptr<net::CertVerifier>(),
845 // Enable network quality estimator.
846 false,
847 // Enable Public Key Pinning bypass for local trust anchors.
Paul Jensen6a1ea3a2018-08-24 14:46:41848 true,
849 // Optional network thread priority.
850 base::Optional<double>());
Yixin Wang10f477ed2017-11-21 04:20:20851
852 net::URLRequestContextBuilder builder;
Matt Muellerde5dadf2019-11-27 20:11:58853 config.ConfigureURLRequestContextBuilder(&builder);
Yixin Wang10f477ed2017-11-21 04:20:20854 // Set a ProxyConfigService to avoid DCHECK failure when building.
855 builder.set_proxy_config_service(
Lily Houghtonef028852017-12-06 20:52:30856 std::make_unique<net::ProxyConfigServiceFixed>(
Ramin Halavatica8d5252018-03-12 05:33:49857 net::ProxyConfigWithAnnotation::CreateDirect()));
Yixin Wang10f477ed2017-11-21 04:20:20858 std::unique_ptr<net::URLRequestContext> context(builder.Build());
859 const net::HttpNetworkSession::Params* params =
860 context->GetNetworkSessionParams();
861
Ryan Sleevia9d6aa62019-07-26 13:32:18862 EXPECT_TRUE(base::Contains(params->quic_host_allowlist, "www.example.com"));
863 EXPECT_TRUE(base::Contains(params->quic_host_allowlist, "www.example.org"));
Yixin Wang10f477ed2017-11-21 04:20:20864}
865
Yixin Wang983875152017-11-21 20:30:13866TEST(URLRequestContextConfigTest, SetQuicMaxTimeBeforeCryptoHandshake) {
Gabriel Charettedfa36042019-08-19 17:30:11867 base::test::TaskEnvironment task_environment_(
868 base::test::TaskEnvironment::MainThreadType::IO);
Yixin Wang983875152017-11-21 20:30:13869
870 URLRequestContextConfig config(
871 // Enable QUIC.
872 true,
873 // QUIC User Agent ID.
874 "Default QUIC User Agent ID",
875 // Enable SPDY.
876 true,
877 // Enable Brotli.
878 false,
879 // Type of http cache.
880 URLRequestContextConfig::HttpCacheType::DISK,
881 // Max size of http cache in bytes.
882 1024000,
883 // Disable caching for HTTP responses. Other information may be stored in
884 // the cache.
885 false,
886 // Storage path for http cache and cookie storage.
887 "/data/data/org.chromium.net/app_cronet_test/test_storage",
Misha Efimovd4ab38302018-01-30 23:56:42888 // Accept-Language request header field.
889 "foreign-language",
Yixin Wang983875152017-11-21 20:30:13890 // User-Agent request header field.
891 "fake agent",
892 // JSON encoded experimental options.
893 "{\"QUIC\":{\"max_time_before_crypto_handshake_seconds\":7,"
894 "\"max_idle_time_before_crypto_handshake_seconds\":11}}",
895 // MockCertVerifier to use for testing purposes.
896 std::unique_ptr<net::CertVerifier>(),
897 // Enable network quality estimator.
898 false,
899 // Enable Public Key Pinning bypass for local trust anchors.
Paul Jensen6a1ea3a2018-08-24 14:46:41900 true,
901 // Optional network thread priority.
902 base::Optional<double>());
Yixin Wang983875152017-11-21 20:30:13903
904 net::URLRequestContextBuilder builder;
Matt Muellerde5dadf2019-11-27 20:11:58905 config.ConfigureURLRequestContextBuilder(&builder);
Yixin Wang983875152017-11-21 20:30:13906 // Set a ProxyConfigService to avoid DCHECK failure when building.
907 builder.set_proxy_config_service(
Lily Houghtonef028852017-12-06 20:52:30908 std::make_unique<net::ProxyConfigServiceFixed>(
Ramin Halavatica8d5252018-03-12 05:33:49909 net::ProxyConfigWithAnnotation::CreateDirect()));
Yixin Wang983875152017-11-21 20:30:13910 std::unique_ptr<net::URLRequestContext> context(builder.Build());
911 const net::HttpNetworkSession::Params* params =
912 context->GetNetworkSessionParams();
913
Ryan Sleevi2e8255b2019-07-17 21:02:21914 EXPECT_EQ(7,
915 params->quic_params.max_time_before_crypto_handshake.InSeconds());
916 EXPECT_EQ(
917 11,
918 params->quic_params.max_idle_time_before_crypto_handshake.InSeconds());
Yixin Wang983875152017-11-21 20:30:13919}
920
Yixin Wang1875fdb2017-12-06 02:26:49921TEST(URLURLRequestContextConfigTest, SetQuicConnectionOptions) {
Gabriel Charettedfa36042019-08-19 17:30:11922 base::test::TaskEnvironment task_environment_(
923 base::test::TaskEnvironment::MainThreadType::IO);
Yixin Wang1875fdb2017-12-06 02:26:49924
925 URLRequestContextConfig config(
926 // Enable QUIC.
927 true,
928 // QUIC User Agent ID.
929 "Default QUIC User Agent ID",
930 // Enable SPDY.
931 true,
932 // Enable Brotli.
933 false,
934 // Type of http cache.
935 URLRequestContextConfig::HttpCacheType::DISK,
936 // Max size of http cache in bytes.
937 1024000,
938 // Disable caching for HTTP responses. Other information may be stored in
939 // the cache.
940 false,
941 // Storage path for http cache and cookie storage.
942 "/data/data/org.chromium.net/app_cronet_test/test_storage",
Misha Efimovd4ab38302018-01-30 23:56:42943 // Accept-Language request header field.
944 "foreign-language",
Yixin Wang1875fdb2017-12-06 02:26:49945 // User-Agent request header field.
946 "fake agent",
947 // JSON encoded experimental options.
948 "{\"QUIC\":{\"connection_options\":\"TIME,TBBR,REJ\","
949 "\"client_connection_options\":\"TBBR,1RTT\"}}",
950 // MockCertVerifier to use for testing purposes.
951 std::unique_ptr<net::CertVerifier>(),
952 // Enable network quality estimator.
953 false,
954 // Enable Public Key Pinning bypass for local trust anchors.
Paul Jensen6a1ea3a2018-08-24 14:46:41955 true,
956 // Optional network thread priority.
957 base::Optional<double>());
Yixin Wang1875fdb2017-12-06 02:26:49958
959 net::URLRequestContextBuilder builder;
Matt Muellerde5dadf2019-11-27 20:11:58960 config.ConfigureURLRequestContextBuilder(&builder);
Yixin Wang1875fdb2017-12-06 02:26:49961 // Set a ProxyConfigService to avoid DCHECK failure when building.
962 builder.set_proxy_config_service(
Gyuyoung Kim6afb5082018-01-19 13:35:57963 std::make_unique<net::ProxyConfigServiceFixed>(
Ramin Halavatica8d5252018-03-12 05:33:49964 net::ProxyConfigWithAnnotation::CreateDirect()));
Yixin Wang1875fdb2017-12-06 02:26:49965 std::unique_ptr<net::URLRequestContext> context(builder.Build());
966 const net::HttpNetworkSession::Params* params =
967 context->GetNetworkSessionParams();
968
Ryan Hamilton8d9ee76e2018-05-29 23:52:52969 quic::QuicTagVector connection_options;
970 connection_options.push_back(quic::kTIME);
971 connection_options.push_back(quic::kTBBR);
972 connection_options.push_back(quic::kREJ);
Nick Harper72ade192019-07-17 03:30:42973 EXPECT_EQ(connection_options, params->quic_params.connection_options);
Yixin Wang1875fdb2017-12-06 02:26:49974
Ryan Hamilton8d9ee76e2018-05-29 23:52:52975 quic::QuicTagVector client_connection_options;
976 client_connection_options.push_back(quic::kTBBR);
977 client_connection_options.push_back(quic::k1RTT);
Nick Harper72ade192019-07-17 03:30:42978 EXPECT_EQ(client_connection_options,
979 params->quic_params.client_connection_options);
Yixin Wang1875fdb2017-12-06 02:26:49980}
981
Misha Efimovd4ab38302018-01-30 23:56:42982TEST(URLURLRequestContextConfigTest, SetAcceptLanguageAndUserAgent) {
Gabriel Charettedfa36042019-08-19 17:30:11983 base::test::TaskEnvironment task_environment_(
984 base::test::TaskEnvironment::MainThreadType::IO);
Misha Efimovd4ab38302018-01-30 23:56:42985
986 URLRequestContextConfig config(
987 // Enable QUIC.
988 true,
989 // QUIC User Agent ID.
990 "Default QUIC User Agent ID",
991 // Enable SPDY.
992 true,
993 // Enable Brotli.
994 false,
995 // Type of http cache.
996 URLRequestContextConfig::HttpCacheType::DISK,
997 // Max size of http cache in bytes.
998 1024000,
999 // Disable caching for HTTP responses. Other information may be stored in
1000 // the cache.
1001 false,
1002 // Storage path for http cache and cookie storage.
1003 "/data/data/org.chromium.net/app_cronet_test/test_storage",
1004 // Accept-Language request header field.
1005 "foreign-language",
1006 // User-Agent request header field.
1007 "fake agent",
1008 // JSON encoded experimental options.
1009 "{}",
1010 // MockCertVerifier to use for testing purposes.
1011 std::unique_ptr<net::CertVerifier>(),
1012 // Enable network quality estimator.
1013 false,
1014 // Enable Public Key Pinning bypass for local trust anchors.
Paul Jensen6a1ea3a2018-08-24 14:46:411015 true,
1016 // Optional network thread priority.
1017 base::Optional<double>());
Misha Efimovd4ab38302018-01-30 23:56:421018
1019 net::URLRequestContextBuilder builder;
Matt Muellerde5dadf2019-11-27 20:11:581020 config.ConfigureURLRequestContextBuilder(&builder);
Misha Efimovd4ab38302018-01-30 23:56:421021 // Set a ProxyConfigService to avoid DCHECK failure when building.
1022 builder.set_proxy_config_service(
1023 std::make_unique<net::ProxyConfigServiceFixed>(
Ramin Halavatica8d5252018-03-12 05:33:491024 net::ProxyConfigWithAnnotation::CreateDirect()));
Misha Efimovd4ab38302018-01-30 23:56:421025 std::unique_ptr<net::URLRequestContext> context(builder.Build());
1026 EXPECT_EQ("foreign-language",
1027 context->http_user_agent_settings()->GetAcceptLanguage());
1028 EXPECT_EQ("fake agent", context->http_user_agent_settings()->GetUserAgent());
1029}
1030
juliatuttle50d9c4b2016-08-23 22:49:191031// See stale_host_resolver_unittest.cc for test of StaleDNS options.
1032
xunjielif24ee5f2015-11-23 18:05:261033} // namespace cronet