blob: 71511f279c25730a881f66a187fbb2694e67aa4a [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.h"
25#include "net/log/net_log_with_source.h"
Lily Houghton582d4622018-01-22 22:43:4026#include "net/proxy_resolution/proxy_config.h"
27#include "net/proxy_resolution/proxy_config_service_fixed.h"
xunjielif24ee5f2015-11-23 18:05:2628#include "net/url_request/url_request_context.h"
29#include "net/url_request/url_request_context_builder.h"
30#include "testing/gtest/include/gtest/gtest.h"
31
Douglas Creagera220947e2018-08-23 20:08:5332#if BUILDFLAG(ENABLE_REPORTING)
33#include "net/network_error_logging/network_error_logging_service.h"
34#include "net/reporting/reporting_service.h"
35#endif // BUILDFLAG(ENABLE_REPORTING)
36
xunjielif24ee5f2015-11-23 18:05:2637namespace cronet {
38
Douglas Creagera220947e2018-08-23 20:08:5339namespace {
40
Douglas Creagera220947e2018-08-23 20:08:5341std::string WrapJsonHeader(base::StringPiece value) {
42 std::string result;
43 result.reserve(value.size() + 2);
44 result.push_back('[');
45 value.AppendToString(&result);
46 result.push_back(']');
47 return result;
48}
49
50// Returns whether two JSON-encoded headers contain the same content, ignoring
51// irrelevant encoding issues like whitespace and map element ordering.
52bool JsonHeaderEquals(base::StringPiece expected, base::StringPiece actual) {
Lei Zhang9b9d5792019-02-20 07:24:4253 return base::test::ParseJson(WrapJsonHeader(expected)) ==
54 base::test::ParseJson(WrapJsonHeader(actual));
Douglas Creagera220947e2018-08-23 20:08:5355}
56
57} // namespace
58
mmenke51629db12017-06-28 13:34:1259TEST(URLRequestContextConfigTest, TestExperimentalOptionParsing) {
Gabriel Charettedfa36042019-08-19 17:30:1160 base::test::TaskEnvironment task_environment_(
61 base::test::TaskEnvironment::MainThreadType::IO);
mmenke51629db12017-06-28 13:34:1262
Julia Tuttle3cc27a4a2018-04-25 15:57:0663 // Create JSON for experimental options.
64 base::DictionaryValue options;
65 options.SetPath({"QUIC", "max_server_configs_stored_in_properties"},
66 base::Value(2));
67 options.SetPath({"QUIC", "user_agent_id"}, base::Value("Custom QUIC UAID"));
68 options.SetPath({"QUIC", "idle_connection_timeout_seconds"},
69 base::Value(300));
70 options.SetPath({"QUIC", "close_sessions_on_ip_change"}, base::Value(true));
71 options.SetPath({"QUIC", "race_cert_verification"}, base::Value(true));
72 options.SetPath({"QUIC", "connection_options"}, base::Value("TIME,TBBR,REJ"));
Ryan Hamiltona31239f12019-09-25 21:01:0073 options.SetPath(
74 {"QUIC", "set_quic_flags"},
75 base::Value("FLAGS_quic_reloadable_flag_quic_supports_tls_handshake=true,"
76 "FLAGS_quic_reloadable_flag_quic_enable_version_99=true"));
Julia Tuttle3cc27a4a2018-04-25 15:57:0677 options.SetPath({"AsyncDNS", "enable"}, base::Value(true));
78 options.SetPath({"NetworkErrorLogging", "enable"}, base::Value(true));
Douglas Creagera220947e2018-08-23 20:08:5379 options.SetPath({"NetworkErrorLogging", "preloaded_report_to_headers"},
Lei Zhang9b9d5792019-02-20 07:24:4280 base::test::ParseJson(R"json(
Douglas Creagera220947e2018-08-23 20:08:5381 [
82 {
83 "origin": "https://test-origin/",
84 "value": {
85 "group": "test-group",
86 "max_age": 86400,
87 "endpoints": [
88 {"url": "https://test-endpoint/"},
89 ],
90 },
91 },
92 {
93 "origin": "https://test-origin-2/",
94 "value": [
95 {
96 "group": "test-group-2",
97 "max_age": 86400,
98 "endpoints": [
99 {"url": "https://test-endpoint-2/"},
100 ],
101 },
102 {
103 "group": "test-group-3",
104 "max_age": 86400,
105 "endpoints": [
106 {"url": "https://test-endpoint-3/"},
107 ],
108 },
109 ],
110 },
111 {
112 "origin": "https://value-is-missing/",
113 },
114 {
115 "value": "origin is missing",
116 },
117 {
118 "origin": 123,
119 "value": "origin is not a string",
120 },
121 {
122 "origin": "this is not a URL",
123 "value": "origin not a URL",
124 },
125 ]
126 )json"));
127 options.SetPath({"NetworkErrorLogging", "preloaded_nel_headers"},
Lei Zhang9b9d5792019-02-20 07:24:42128 base::test::ParseJson(R"json(
Douglas Creagera220947e2018-08-23 20:08:53129 [
130 {
131 "origin": "https://test-origin/",
132 "value": {
133 "report_to": "test-group",
134 "max_age": 86400,
135 },
136 },
137 ]
138 )json"));
Julia Tuttle3cc27a4a2018-04-25 15:57:06139 options.SetPath({"UnknownOption", "foo"}, base::Value(true));
140 options.SetPath({"HostResolverRules", "host_resolver_rules"},
141 base::Value("MAP * 127.0.0.1"));
142 // See http://crbug.com/696569.
143 options.SetKey("disable_ipv6_on_wifi", base::Value(true));
144 std::string options_json;
145 EXPECT_TRUE(base::JSONWriter::Write(options, &options_json));
146
Ryan Hamiltona31239f12019-09-25 21:01:00147 // Initialize QUIC flags set by the config.
148 FLAGS_quic_reloadable_flag_quic_supports_tls_handshake = false;
149 FLAGS_quic_reloadable_flag_quic_enable_version_99 = false;
150
pauljensen9041eb3c2015-12-09 12:29:01151 URLRequestContextConfig config(
152 // Enable QUIC.
153 true,
mefc5da5712016-02-09 20:14:23154 // QUIC User Agent ID.
155 "Default QUIC User Agent ID",
pauljensen9041eb3c2015-12-09 12:29:01156 // Enable SPDY.
157 true,
xunjieli186d2bf2017-04-18 13:45:47158 // Enable Brotli.
159 false,
pauljensen9041eb3c2015-12-09 12:29:01160 // Type of http cache.
161 URLRequestContextConfig::HttpCacheType::DISK,
162 // Max size of http cache in bytes.
163 1024000,
164 // Disable caching for HTTP responses. Other information may be stored in
165 // the cache.
166 false,
167 // Storage path for http cache and cookie storage.
168 "/data/data/org.chromium.net/app_cronet_test/test_storage",
Misha Efimovd4ab38302018-01-30 23:56:42169 // Accept-Language request header field.
170 "foreign-language",
pauljensen9041eb3c2015-12-09 12:29:01171 // User-Agent request header field.
172 "fake agent",
173 // JSON encoded experimental options.
Julia Tuttle3cc27a4a2018-04-25 15:57:06174 options_json,
pauljensen9041eb3c2015-12-09 12:29:01175 // MockCertVerifier to use for testing purposes.
tbansal7018e2a2016-06-25 00:40:39176 std::unique_ptr<net::CertVerifier>(),
177 // Enable network quality estimator.
kapishnikov385aa422016-07-01 20:53:02178 false,
179 // Enable Public Key Pinning bypass for local trust anchors.
Paul Jensen6a1ea3a2018-08-24 14:46:41180 true,
181 // Optional network thread priority.
182 base::Optional<double>(42.0));
xunjielif24ee5f2015-11-23 18:05:26183
xunjielif24ee5f2015-11-23 18:05:26184 net::URLRequestContextBuilder builder;
pauljensene92c4092015-12-09 19:13:48185 net::NetLog net_log;
David Benjamindc2f4b02017-07-27 23:59:02186 config.ConfigureURLRequestContextBuilder(&builder, &net_log);
xunjielid67295e2017-03-16 21:05:41187 EXPECT_FALSE(config.effective_experimental_options->HasKey("UnknownOption"));
xunjielif24ee5f2015-11-23 18:05:26188 // Set a ProxyConfigService to avoid DCHECK failure when building.
ricea85ec57952016-08-31 09:34:10189 builder.set_proxy_config_service(
Lily Houghtonef028852017-12-06 20:52:30190 std::make_unique<net::ProxyConfigServiceFixed>(
Ramin Halavatica8d5252018-03-12 05:33:49191 net::ProxyConfigWithAnnotation::CreateDirect()));
dchengfe3745e6242016-04-21 23:49:58192 std::unique_ptr<net::URLRequestContext> context(builder.Build());
xunjielif24ee5f2015-11-23 18:05:26193 const net::HttpNetworkSession::Params* params =
194 context->GetNetworkSessionParams();
195 // Check Quic Connection options.
Ryan Hamilton8d9ee76e2018-05-29 23:52:52196 quic::QuicTagVector quic_connection_options;
197 quic_connection_options.push_back(quic::kTIME);
198 quic_connection_options.push_back(quic::kTBBR);
199 quic_connection_options.push_back(quic::kREJ);
Nick Harper72ade192019-07-17 03:30:42200 EXPECT_EQ(quic_connection_options, params->quic_params.connection_options);
xunjielif24ee5f2015-11-23 18:05:26201
Ryan Hamiltona31239f12019-09-25 21:01:00202 EXPECT_TRUE(FLAGS_quic_reloadable_flag_quic_supports_tls_handshake);
203 EXPECT_TRUE(FLAGS_quic_reloadable_flag_quic_enable_version_99);
204
mefc5da5712016-02-09 20:14:23205 // Check Custom QUIC User Agent Id.
Nick Harper72ade192019-07-17 03:30:42206 EXPECT_EQ("Custom QUIC UAID", params->quic_params.user_agent_id);
mefc5da5712016-02-09 20:14:23207
rtenneti6971c172016-01-15 20:12:10208 // Check max_server_configs_stored_in_properties.
Nick Harper72ade192019-07-17 03:30:42209 EXPECT_EQ(2u, params->quic_params.max_server_configs_stored_in_properties);
xunjielif24ee5f2015-11-23 18:05:26210
Ryan Sleevi2e8255b2019-07-17 21:02:21211 // Check idle_connection_timeout.
212 EXPECT_EQ(300, params->quic_params.idle_connection_timeout.InSeconds());
rtenneti64e809d02015-12-11 00:26:20213
Nick Harper72ade192019-07-17 03:30:42214 EXPECT_TRUE(params->quic_params.close_sessions_on_ip_change);
215 EXPECT_FALSE(params->quic_params.goaway_sessions_on_ip_change);
216 EXPECT_FALSE(params->quic_params.allow_server_migration);
217 EXPECT_FALSE(params->quic_params.migrate_sessions_on_network_change_v2);
218 EXPECT_FALSE(params->quic_params.migrate_sessions_early_v2);
219 EXPECT_FALSE(params->quic_params.migrate_idle_sessions);
220 EXPECT_FALSE(params->quic_params.retry_on_alternate_network_before_handshake);
221 EXPECT_FALSE(params->quic_params.race_stale_dns_on_connection);
Renjie Tangcbbc84c2019-09-06 22:23:23222 EXPECT_FALSE(params->quic_params.go_away_on_path_degrading);
jrid26566952016-02-04 21:06:42223
rtennetid073dd22016-08-04 01:58:33224 // Check race_cert_verification.
Nick Harper72ade192019-07-17 03:30:42225 EXPECT_TRUE(params->quic_params.race_cert_verification);
rtennetid073dd22016-08-04 01:58:33226
Misha Efimov63957912017-12-06 07:13:26227#if defined(ENABLE_BUILT_IN_DNS)
228 // Check AsyncDNS resolver is enabled (not supported on iOS).
tfhef3618f2016-01-11 23:07:08229 EXPECT_TRUE(context->host_resolver()->GetDnsConfigAsValue());
Misha Efimov63957912017-12-06 07:13:26230#endif // defined(ENABLE_BUILT_IN_DNS)
mgershaf2c12c2016-08-22 16:33:54231
Julia Tuttle9715d1642018-01-29 17:02:26232#if BUILDFLAG(ENABLE_REPORTING)
233 // Check Reporting and Network Error Logging are enabled (can be disabled at
234 // build time).
235 EXPECT_TRUE(context->reporting_service());
Julia Tuttlecba7d222018-02-23 19:37:27236 EXPECT_TRUE(context->network_error_logging_service());
Julia Tuttle9715d1642018-01-29 17:02:26237#endif // BUILDFLAG(ENABLE_REPORTING)
238
Douglas Creagera220947e2018-08-23 20:08:53239 ASSERT_EQ(2u, config.preloaded_report_to_headers.size());
240 EXPECT_EQ(url::Origin::CreateFromNormalizedTuple("https", "test-origin", 443),
241 config.preloaded_report_to_headers[0].origin);
242 EXPECT_TRUE(JsonHeaderEquals( //
243 R"json(
244 {
245 "group": "test-group",
246 "max_age": 86400,
247 "endpoints": [
248 {"url": "https://test-endpoint/"},
249 ],
250 }
251 )json",
252 config.preloaded_report_to_headers[0].value));
253 EXPECT_EQ(
254 url::Origin::CreateFromNormalizedTuple("https", "test-origin-2", 443),
255 config.preloaded_report_to_headers[1].origin);
256 EXPECT_TRUE(JsonHeaderEquals( //
257 R"json(
258 {
259 "group": "test-group-2",
260 "max_age": 86400,
261 "endpoints": [
262 {"url": "https://test-endpoint-2/"},
263 ],
264 },
265 {
266 "group": "test-group-3",
267 "max_age": 86400,
268 "endpoints": [
269 {"url": "https://test-endpoint-3/"},
270 ],
271 }
272 )json",
273 config.preloaded_report_to_headers[1].value));
274
275 ASSERT_EQ(1u, config.preloaded_nel_headers.size());
276 EXPECT_EQ(url::Origin::CreateFromNormalizedTuple("https", "test-origin", 443),
277 config.preloaded_nel_headers[0].origin);
278 EXPECT_TRUE(JsonHeaderEquals( //
279 R"json(
280 {
281 "report_to": "test-group",
282 "max_age": 86400,
283 }
284 )json",
285 config.preloaded_nel_headers[0].value));
286
mgershaf9a9232017-04-13 20:19:03287 // Check IPv6 is disabled when on wifi.
Eric Orth607b6d82019-05-08 16:43:32288 EXPECT_FALSE(context->host_resolver()
289 ->GetManagerForTesting()
290 ->check_ipv6_on_wifi_for_testing());
mgershb3fe8082017-02-28 20:09:20291
Eric Orthe1cdd902019-02-26 02:52:46292 // All host resolution expected to be mapped to an immediately-resolvable IP.
293 std::unique_ptr<net::HostResolver::ResolveHostRequest> resolve_request =
294 context->host_resolver()->CreateRequest(net::HostPortPair("abcde", 80),
295 net::NetLogWithSource(),
296 base::nullopt);
297 EXPECT_EQ(net::OK, resolve_request->Start(
298 base::BindOnce([](int error) { NOTREACHED(); })));
Paul Jensen6a1ea3a2018-08-24 14:46:41299
300 EXPECT_TRUE(config.network_thread_priority);
301 EXPECT_EQ(42.0, config.network_thread_priority.value());
xunjielif24ee5f2015-11-23 18:05:26302}
303
Zhongyi Shi57247962018-11-05 20:03:52304TEST(URLRequestContextConfigTest, SetSupportedQuicVersion) {
Gabriel Charettedfa36042019-08-19 17:30:11305 base::test::TaskEnvironment task_environment_(
306 base::test::TaskEnvironment::MainThreadType::IO);
Zhongyi Shi57247962018-11-05 20:03:52307
308 URLRequestContextConfig config(
309 // Enable QUIC.
310 true,
311 // QUIC User Agent ID.
312 "Default QUIC User Agent ID",
313 // Enable SPDY.
314 true,
315 // Enable Brotli.
316 false,
317 // Type of http cache.
318 URLRequestContextConfig::HttpCacheType::DISK,
319 // Max size of http cache in bytes.
320 1024000,
321 // Disable caching for HTTP responses. Other information may be stored in
322 // the cache.
323 false,
324 // Storage path for http cache and cookie storage.
325 "/data/data/org.chromium.net/app_cronet_test/test_storage",
326 // Accept-Language request header field.
327 "foreign-language",
328 // User-Agent request header field.
329 "fake agent",
330 // JSON encoded experimental options.
Ryan Hamilton8380c652019-06-04 02:25:06331 "{\"QUIC\":{\"quic_version\":\"QUIC_VERSION_46\"}}",
Zhongyi Shi57247962018-11-05 20:03:52332 // MockCertVerifier to use for testing purposes.
333 std::unique_ptr<net::CertVerifier>(),
334 // Enable network quality estimator.
335 false,
336 // Enable Public Key Pinning bypass for local trust anchors.
337 true,
338 // Optional network thread priority.
339 base::Optional<double>());
340
341 net::URLRequestContextBuilder builder;
342 net::NetLog net_log;
343 config.ConfigureURLRequestContextBuilder(&builder, &net_log);
344 // Set a ProxyConfigService to avoid DCHECK failure when building.
345 builder.set_proxy_config_service(
346 std::make_unique<net::ProxyConfigServiceFixed>(
347 net::ProxyConfigWithAnnotation::CreateDirect()));
348 std::unique_ptr<net::URLRequestContext> context(builder.Build());
349 const net::HttpNetworkSession::Params* params =
350 context->GetNetworkSessionParams();
Nick Harper72ade192019-07-17 03:30:42351 EXPECT_EQ(params->quic_params.supported_versions.size(), 1u);
352 EXPECT_EQ(params->quic_params.supported_versions[0],
Nick Harper23290b82019-05-02 00:02:56353 quic::ParsedQuicVersion(quic::PROTOCOL_QUIC_CRYPTO,
Ryan Hamilton8380c652019-06-04 02:25:06354 quic::QUIC_VERSION_46));
Zhongyi Shi57247962018-11-05 20:03:52355}
356
357TEST(URLRequestContextConfigTest, SetUnsupportedQuicVersion) {
Gabriel Charettedfa36042019-08-19 17:30:11358 base::test::TaskEnvironment task_environment_(
359 base::test::TaskEnvironment::MainThreadType::IO);
Zhongyi Shi57247962018-11-05 20:03:52360
361 URLRequestContextConfig config(
362 // Enable QUIC.
363 true,
364 // QUIC User Agent ID.
365 "Default QUIC User Agent ID",
366 // Enable SPDY.
367 true,
368 // Enable Brotli.
369 false,
370 // Type of http cache.
371 URLRequestContextConfig::HttpCacheType::DISK,
372 // Max size of http cache in bytes.
373 1024000,
374 // Disable caching for HTTP responses. Other information may be stored in
375 // the cache.
376 false,
377 // Storage path for http cache and cookie storage.
378 "/data/data/org.chromium.net/app_cronet_test/test_storage",
379 // Accept-Language request header field.
380 "foreign-language",
381 // User-Agent request header field.
382 "fake agent",
383 // JSON encoded experimental options.
384 "{\"QUIC\":{\"quic_version\":\"QUIC_VERSION_33\"}}",
385 // MockCertVerifier to use for testing purposes.
386 std::unique_ptr<net::CertVerifier>(),
387 // Enable network quality estimator.
388 false,
389 // Enable Public Key Pinning bypass for local trust anchors.
390 true,
391 // Optional network thread priority.
392 base::Optional<double>());
393
394 net::URLRequestContextBuilder builder;
395 net::NetLog net_log;
396 config.ConfigureURLRequestContextBuilder(&builder, &net_log);
397 // Set a ProxyConfigService to avoid DCHECK failure when building.
398 builder.set_proxy_config_service(
399 std::make_unique<net::ProxyConfigServiceFixed>(
400 net::ProxyConfigWithAnnotation::CreateDirect()));
401 std::unique_ptr<net::URLRequestContext> context(builder.Build());
402 const net::HttpNetworkSession::Params* params =
403 context->GetNetworkSessionParams();
Nick Harper72ade192019-07-17 03:30:42404 EXPECT_EQ(params->quic_params.supported_versions.size(), 1u);
405 EXPECT_EQ(params->quic_params.supported_versions[0],
Nick Harper23290b82019-05-02 00:02:56406 quic::ParsedQuicVersion(quic::PROTOCOL_QUIC_CRYPTO,
Ryan Hamilton3cbc5632019-05-20 17:16:29407 quic::QUIC_VERSION_46));
Zhongyi Shi57247962018-11-05 20:03:52408}
409
Zhongyi Shi8ff38c12018-02-22 00:02:30410TEST(URLRequestContextConfigTest, SetQuicServerMigrationOptions) {
Gabriel Charettedfa36042019-08-19 17:30:11411 base::test::TaskEnvironment task_environment_(
412 base::test::TaskEnvironment::MainThreadType::IO);
Zhongyi Shi8ff38c12018-02-22 00:02:30413
414 URLRequestContextConfig config(
415 // Enable QUIC.
416 true,
417 // QUIC User Agent ID.
418 "Default QUIC User Agent ID",
419 // Enable SPDY.
420 true,
421 // Enable Brotli.
422 false,
423 // Type of http cache.
424 URLRequestContextConfig::HttpCacheType::DISK,
425 // Max size of http cache in bytes.
426 1024000,
427 // Disable caching for HTTP responses. Other information may be stored in
428 // the cache.
429 false,
430 // Storage path for http cache and cookie storage.
431 "/data/data/org.chromium.net/app_cronet_test/test_storage",
432 // Accept-Language request header field.
433 "foreign-language",
434 // User-Agent request header field.
435 "fake agent",
436 // JSON encoded experimental options.
437 "{\"QUIC\":{\"allow_server_migration\":true}}",
438 // MockCertVerifier to use for testing purposes.
439 std::unique_ptr<net::CertVerifier>(),
440 // Enable network quality estimator.
441 false,
442 // Enable Public Key Pinning bypass for local trust anchors.
Paul Jensen6a1ea3a2018-08-24 14:46:41443 true,
444 // Optional network thread priority.
445 base::Optional<double>());
Zhongyi Shi8ff38c12018-02-22 00:02:30446
447 net::URLRequestContextBuilder builder;
448 net::NetLog net_log;
449 config.ConfigureURLRequestContextBuilder(&builder, &net_log);
450 // Set a ProxyConfigService to avoid DCHECK failure when building.
451 builder.set_proxy_config_service(
452 std::make_unique<net::ProxyConfigServiceFixed>(
Ramin Halavatica8d5252018-03-12 05:33:49453 net::ProxyConfigWithAnnotation::CreateDirect()));
Zhongyi Shi8ff38c12018-02-22 00:02:30454 std::unique_ptr<net::URLRequestContext> context(builder.Build());
455 const net::HttpNetworkSession::Params* params =
456 context->GetNetworkSessionParams();
457
Nick Harper72ade192019-07-17 03:30:42458 EXPECT_FALSE(params->quic_params.close_sessions_on_ip_change);
459 EXPECT_TRUE(params->quic_params.allow_server_migration);
Zhongyi Shi8ff38c12018-02-22 00:02:30460}
461
Zhongyi Shiaa518c22018-06-15 04:37:36462// Test that goaway_sessions_on_ip_change is set on by default for iOS.
463#if defined(OS_IOS)
464#define MAYBE_SetQuicGoAwaySessionsOnIPChangeByDefault \
465 SetQuicGoAwaySessionsOnIPChangeByDefault
466#else
467#define MAYBE_SetQuicGoAwaySessionsOnIPChangeByDefault \
468 DISABLED_SetQuicGoAwaySessionsOnIPChangeByDefault
469#endif
470TEST(URLRequestContextConfigTest,
471 MAYBE_SetQuicGoAwaySessionsOnIPChangeByDefault) {
Gabriel Charettedfa36042019-08-19 17:30:11472 base::test::TaskEnvironment task_environment_(
473 base::test::TaskEnvironment::MainThreadType::IO);
Zhongyi Shiaa518c22018-06-15 04:37:36474
475 URLRequestContextConfig config(
476 // Enable QUIC.
477 true,
478 // QUIC User Agent ID.
479 "Default QUIC User Agent ID",
480 // Enable SPDY.
481 true,
482 // Enable Brotli.
483 false,
484 // Type of http cache.
485 URLRequestContextConfig::HttpCacheType::DISK,
486 // Max size of http cache in bytes.
487 1024000,
488 // Disable caching for HTTP responses. Other information may be stored in
489 // the cache.
490 false,
491 // Storage path for http cache and cookie storage.
492 "/data/data/org.chromium.net/app_cronet_test/test_storage",
493 // Accept-Language request header field.
494 "foreign-language",
495 // User-Agent request header field.
496 "fake agent",
497 // JSON encoded experimental options.
498 "{\"QUIC\":{}}",
499 // MockCertVerifier to use for testing purposes.
500 std::unique_ptr<net::CertVerifier>(),
501 // Enable network quality estimator.
502 false,
503 // Enable Public Key Pinning bypass for local trust anchors.
Paul Jensen6a1ea3a2018-08-24 14:46:41504 true,
505 // Optional network thread priority.
506 base::Optional<double>());
Zhongyi Shiaa518c22018-06-15 04:37:36507
508 net::URLRequestContextBuilder builder;
509 net::NetLog net_log;
510 config.ConfigureURLRequestContextBuilder(&builder, &net_log);
511 // Set a ProxyConfigService to avoid DCHECK failure when building.
512 builder.set_proxy_config_service(
513 std::make_unique<net::ProxyConfigServiceFixed>(
514 net::ProxyConfigWithAnnotation::CreateDirect()));
515 std::unique_ptr<net::URLRequestContext> context(builder.Build());
516 const net::HttpNetworkSession::Params* params =
517 context->GetNetworkSessionParams();
518
Nick Harper72ade192019-07-17 03:30:42519 EXPECT_FALSE(params->quic_params.close_sessions_on_ip_change);
520 EXPECT_TRUE(params->quic_params.goaway_sessions_on_ip_change);
Zhongyi Shiaa518c22018-06-15 04:37:36521}
522
523// Tests that goaway_sessions_on_ip_changes can be set on via
524// experimental options on non-iOS.
525#if !defined(OS_IOS)
526#define MAYBE_SetQuicGoAwaySessionsOnIPChangeViaExperimentOptions \
527 SetQuicGoAwaySessionsOnIPChangeViaExperimentOptions
528#else
529#define MAYBE_SetQuicGoAwaySessionsOnIPChangeViaExperimentOptions \
530 DISABLED_SetQuicGoAwaySessionsOnIPChangeViaExperimentOptions
531#endif
532TEST(URLRequestContextConfigTest,
533 MAYBE_SetQuicGoAwaySessionsOnIPChangeViaExperimentOptions) {
Gabriel Charettedfa36042019-08-19 17:30:11534 base::test::TaskEnvironment task_environment_(
535 base::test::TaskEnvironment::MainThreadType::IO);
Zhongyi Shi63574b72018-06-01 20:22:25536
537 URLRequestContextConfig config(
538 // Enable QUIC.
539 true,
540 // QUIC User Agent ID.
541 "Default QUIC User Agent ID",
542 // Enable SPDY.
543 true,
544 // Enable Brotli.
545 false,
546 // Type of http cache.
547 URLRequestContextConfig::HttpCacheType::DISK,
548 // Max size of http cache in bytes.
549 1024000,
550 // Disable caching for HTTP responses. Other information may be stored in
551 // the cache.
552 false,
553 // Storage path for http cache and cookie storage.
554 "/data/data/org.chromium.net/app_cronet_test/test_storage",
555 // Accept-Language request header field.
556 "foreign-language",
557 // User-Agent request header field.
558 "fake agent",
559 // JSON encoded experimental options.
560 "{\"QUIC\":{\"goaway_sessions_on_ip_change\":true}}",
561 // MockCertVerifier to use for testing purposes.
562 std::unique_ptr<net::CertVerifier>(),
563 // Enable network quality estimator.
564 false,
565 // Enable Public Key Pinning bypass for local trust anchors.
Paul Jensen6a1ea3a2018-08-24 14:46:41566 true,
567 // Optional network thread priority.
568 base::Optional<double>());
Zhongyi Shi63574b72018-06-01 20:22:25569
570 net::URLRequestContextBuilder builder;
571 net::NetLog net_log;
572 config.ConfigureURLRequestContextBuilder(&builder, &net_log);
573 // Set a ProxyConfigService to avoid DCHECK failure when building.
574 builder.set_proxy_config_service(
575 std::make_unique<net::ProxyConfigServiceFixed>(
576 net::ProxyConfigWithAnnotation::CreateDirect()));
577 std::unique_ptr<net::URLRequestContext> context(builder.Build());
578 const net::HttpNetworkSession::Params* params =
579 context->GetNetworkSessionParams();
580
Nick Harper72ade192019-07-17 03:30:42581 EXPECT_FALSE(params->quic_params.close_sessions_on_ip_change);
582 EXPECT_TRUE(params->quic_params.goaway_sessions_on_ip_change);
Zhongyi Shi63574b72018-06-01 20:22:25583}
584
Zhongyi Shiaa518c22018-06-15 04:37:36585// Test that goaway_sessions_on_ip_change can be set to false via
586// exprimental options on iOS.
587#if defined(OS_IOS)
588#define MAYBE_DisableQuicGoAwaySessionsOnIPChangeViaExperimentOptions \
589 DisableQuicGoAwaySessionsOnIPChangeViaExperimentOptions
590#else
591#define MAYBE_DisableQuicGoAwaySessionsOnIPChangeViaExperimentOptions \
592 DISABLED_DisableQuicGoAwaySessionsOnIPChangeViaExperimentOptions
593#endif
594TEST(URLRequestContextConfigTest,
595 MAYBE_DisableQuicGoAwaySessionsOnIPChangeViaExperimentOptions) {
Gabriel Charettedfa36042019-08-19 17:30:11596 base::test::TaskEnvironment task_environment_(
597 base::test::TaskEnvironment::MainThreadType::IO);
Zhongyi Shiaa518c22018-06-15 04:37:36598
599 URLRequestContextConfig config(
600 // Enable QUIC.
601 true,
602 // QUIC User Agent ID.
603 "Default QUIC User Agent ID",
604 // Enable SPDY.
605 true,
606 // Enable Brotli.
607 false,
608 // Type of http cache.
609 URLRequestContextConfig::HttpCacheType::DISK,
610 // Max size of http cache in bytes.
611 1024000,
612 // Disable caching for HTTP responses. Other information may be stored in
613 // the cache.
614 false,
615 // Storage path for http cache and cookie storage.
616 "/data/data/org.chromium.net/app_cronet_test/test_storage",
617 // Accept-Language request header field.
618 "foreign-language",
619 // User-Agent request header field.
620 "fake agent",
621 // JSON encoded experimental options.
622 "{\"QUIC\":{\"goaway_sessions_on_ip_change\":false}}",
623 // MockCertVerifier to use for testing purposes.
624 std::unique_ptr<net::CertVerifier>(),
625 // Enable network quality estimator.
626 false,
627 // Enable Public Key Pinning bypass for local trust anchors.
Paul Jensen6a1ea3a2018-08-24 14:46:41628 true,
629 // Optional network thread priority.
630 base::Optional<double>());
Zhongyi Shiaa518c22018-06-15 04:37:36631
632 net::URLRequestContextBuilder builder;
633 net::NetLog net_log;
634 config.ConfigureURLRequestContextBuilder(&builder, &net_log);
635 // Set a ProxyConfigService to avoid DCHECK failure when building.
636 builder.set_proxy_config_service(
637 std::make_unique<net::ProxyConfigServiceFixed>(
638 net::ProxyConfigWithAnnotation::CreateDirect()));
639 std::unique_ptr<net::URLRequestContext> context(builder.Build());
640 const net::HttpNetworkSession::Params* params =
641 context->GetNetworkSessionParams();
642
Nick Harper72ade192019-07-17 03:30:42643 EXPECT_FALSE(params->quic_params.close_sessions_on_ip_change);
644 EXPECT_FALSE(params->quic_params.goaway_sessions_on_ip_change);
Zhongyi Shiaa518c22018-06-15 04:37:36645}
646
Yixin Wang10f477ed2017-11-21 04:20:20647TEST(URLRequestContextConfigTest, SetQuicConnectionMigrationV2Options) {
Gabriel Charettedfa36042019-08-19 17:30:11648 base::test::TaskEnvironment task_environment_(
649 base::test::TaskEnvironment::MainThreadType::IO);
Zhongyi Shi64795622017-11-20 02:21:49650
651 URLRequestContextConfig config(
652 // Enable QUIC.
653 true,
654 // QUIC User Agent ID.
655 "Default QUIC User Agent ID",
656 // Enable SPDY.
657 true,
658 // Enable Brotli.
659 false,
660 // Type of http cache.
661 URLRequestContextConfig::HttpCacheType::DISK,
662 // Max size of http cache in bytes.
663 1024000,
664 // Disable caching for HTTP responses. Other information may be stored in
665 // the cache.
666 false,
667 // Storage path for http cache and cookie storage.
668 "/data/data/org.chromium.net/app_cronet_test/test_storage",
Misha Efimovd4ab38302018-01-30 23:56:42669 // Accept-Language request header field.
670 "foreign-language",
Zhongyi Shi64795622017-11-20 02:21:49671 // User-Agent request header field.
672 "fake agent",
673 // JSON encoded experimental options.
Zhongyi Shid02a48c2019-08-27 21:03:58674 // Explicitly turn off "goaway_sessions_on_ip_change" which is default
675 // enabled on iOS but cannot be simultaneously set with migration option.
Zhongyi Shif4683a32017-12-01 00:03:28676 "{\"QUIC\":{\"migrate_sessions_on_network_change_v2\":true,"
Zhongyi Shid02a48c2019-08-27 21:03:58677 "\"goaway_sessions_on_ip_change\":false,"
Zhongyi Shi73f23ca872017-12-13 18:37:13678 "\"migrate_sessions_early_v2\":true,"
Zhongyi Shiff359581bc2018-09-26 18:11:48679 "\"retry_on_alternate_network_before_handshake\":true,"
Zhongyi Shi32fe14d42019-02-28 00:25:36680 "\"migrate_idle_sessions\":true,"
Zhongyi Shie01f2db2019-02-22 19:53:23681 "\"retransmittable_on_wire_timeout_milliseconds\":1000,"
Zhongyi Shibc85e3e2019-02-12 19:34:42682 "\"idle_session_migration_period_seconds\":15,"
Zhongyi Shi8b1e43f2017-12-13 20:46:30683 "\"max_time_on_non_default_network_seconds\":10,"
Zhongyi Shiee760762018-08-01 00:54:29684 "\"max_migrations_to_non_default_network_on_write_error\":3,"
Zhongyi Shi8b1e43f2017-12-13 20:46:30685 "\"max_migrations_to_non_default_network_on_path_degrading\":4}}",
Zhongyi Shi64795622017-11-20 02:21:49686 // MockCertVerifier to use for testing purposes.
687 std::unique_ptr<net::CertVerifier>(),
688 // Enable network quality estimator.
689 false,
690 // Enable Public Key Pinning bypass for local trust anchors.
Paul Jensen6a1ea3a2018-08-24 14:46:41691 true,
692 // Optional network thread priority.
693 base::Optional<double>());
Zhongyi Shi64795622017-11-20 02:21:49694
695 net::URLRequestContextBuilder builder;
696 net::NetLog net_log;
697 config.ConfigureURLRequestContextBuilder(&builder, &net_log);
698 // Set a ProxyConfigService to avoid DCHECK failure when building.
699 builder.set_proxy_config_service(
Lily Houghtonef028852017-12-06 20:52:30700 std::make_unique<net::ProxyConfigServiceFixed>(
Ramin Halavatica8d5252018-03-12 05:33:49701 net::ProxyConfigWithAnnotation::CreateDirect()));
Zhongyi Shi64795622017-11-20 02:21:49702 std::unique_ptr<net::URLRequestContext> context(builder.Build());
703 const net::HttpNetworkSession::Params* params =
704 context->GetNetworkSessionParams();
705
Nick Harper72ade192019-07-17 03:30:42706 EXPECT_TRUE(params->quic_params.migrate_sessions_on_network_change_v2);
707 EXPECT_TRUE(params->quic_params.migrate_sessions_early_v2);
708 EXPECT_TRUE(params->quic_params.retry_on_alternate_network_before_handshake);
Ryan Sleevi2e8255b2019-07-17 21:02:21709 EXPECT_EQ(
710 1000,
711 params->quic_params.retransmittable_on_wire_timeout.InMilliseconds());
Nick Harper72ade192019-07-17 03:30:42712 EXPECT_TRUE(params->quic_params.migrate_idle_sessions);
Zhongyi Shibc85e3e2019-02-12 19:34:42713 EXPECT_EQ(base::TimeDelta::FromSeconds(15),
Nick Harper72ade192019-07-17 03:30:42714 params->quic_params.idle_session_migration_period);
Zhongyi Shi73f23ca872017-12-13 18:37:13715 EXPECT_EQ(base::TimeDelta::FromSeconds(10),
Nick Harper72ade192019-07-17 03:30:42716 params->quic_params.max_time_on_non_default_network);
Zhongyi Shi8b1e43f2017-12-13 20:46:30717 EXPECT_EQ(
Nick Harper72ade192019-07-17 03:30:42718 3,
719 params->quic_params.max_migrations_to_non_default_network_on_write_error);
720 EXPECT_EQ(4, params->quic_params
721 .max_migrations_to_non_default_network_on_path_degrading);
Zhongyi Shi64795622017-11-20 02:21:49722}
723
Renjie94b90712018-10-18 21:03:19724TEST(URLRequestContextConfigTest, SetQuicStaleDNSracing) {
Gabriel Charettedfa36042019-08-19 17:30:11725 base::test::TaskEnvironment task_environment_(
726 base::test::TaskEnvironment::MainThreadType::IO);
Renjie94b90712018-10-18 21:03:19727
728 URLRequestContextConfig config(
729 // Enable QUIC.
730 true,
731 // QUIC User Agent ID.
732 "Default QUIC User Agent ID",
733 // Enable SPDY.
734 true,
735 // Enable Brotli.
736 false,
737 // Type of http cache.
738 URLRequestContextConfig::HttpCacheType::DISK,
739 // Max size of http cache in bytes.
740 1024000,
741 // Disable caching for HTTP responses. Other information may be stored in
742 // the cache.
743 false,
744 // Storage path for http cache and cookie storage.
745 "/data/data/org.chromium.net/app_cronet_test/test_storage",
746 // Accept-Language request header field.
747 "foreign-language",
748 // User-Agent request header field.
749 "fake agent",
750 // JSON encoded experimental options.
751 "{\"QUIC\":{\"race_stale_dns_on_connection\":true}}",
752 // MockCertVerifier to use for testing purposes.
753 std::unique_ptr<net::CertVerifier>(),
754 // Enable network quality estimator.
755 false,
756 // Enable Public Key Pinning bypass for local trust anchors.
757 true,
758 // Optional network thread priority.
759 base::Optional<double>());
760
761 net::URLRequestContextBuilder builder;
762 net::NetLog net_log;
763 config.ConfigureURLRequestContextBuilder(&builder, &net_log);
764 // Set a ProxyConfigService to avoid DCHECK failure when building.
765 builder.set_proxy_config_service(
766 std::make_unique<net::ProxyConfigServiceFixed>(
767 net::ProxyConfigWithAnnotation::CreateDirect()));
768 std::unique_ptr<net::URLRequestContext> context(builder.Build());
769 const net::HttpNetworkSession::Params* params =
770 context->GetNetworkSessionParams();
771
Nick Harper72ade192019-07-17 03:30:42772 EXPECT_TRUE(params->quic_params.race_stale_dns_on_connection);
Renjie94b90712018-10-18 21:03:19773}
774
Renjie Tangcbbc84c2019-09-06 22:23:23775TEST(URLRequestContextConfigTest, SetQuicGoawayOnPathDegrading) {
776 base::test::TaskEnvironment task_environment_(
777 base::test::TaskEnvironment::MainThreadType::IO);
778
779 URLRequestContextConfig config(
780 // Enable QUIC.
781 true,
782 // QUIC User Agent ID.
783 "Default QUIC User Agent ID",
784 // Enable SPDY.
785 true,
786 // Enable Brotli.
787 false,
788 // Type of http cache.
789 URLRequestContextConfig::HttpCacheType::DISK,
790 // Max size of http cache in bytes.
791 1024000,
792 // Disable caching for HTTP responses. Other information may be stored in
793 // the cache.
794 false,
795 // Storage path for http cache and cookie storage.
796 "/data/data/org.chromium.net/app_cronet_test/test_storage",
797 // Accept-Language request header field.
798 "foreign-language",
799 // User-Agent request header field.
800 "fake agent",
801 // JSON encoded experimental options.
802 "{\"QUIC\":{\"go_away_on_path_degrading\":true}}",
803 // MockCertVerifier to use for testing purposes.
804 std::unique_ptr<net::CertVerifier>(),
805 // Enable network quality estimator.
806 false,
807 // Enable Public Key Pinning bypass for local trust anchors.
808 true,
809 // Optional network thread priority.
810 base::Optional<double>());
811
812 net::URLRequestContextBuilder builder;
813 net::NetLog net_log;
814 config.ConfigureURLRequestContextBuilder(&builder, &net_log);
815 // Set a ProxyConfigService to avoid DCHECK failure when building.
816 builder.set_proxy_config_service(
817 std::make_unique<net::ProxyConfigServiceFixed>(
818 net::ProxyConfigWithAnnotation::CreateDirect()));
819 std::unique_ptr<net::URLRequestContext> context(builder.Build());
820 const net::HttpNetworkSession::Params* params =
821 context->GetNetworkSessionParams();
822
823 EXPECT_TRUE(params->quic_params.go_away_on_path_degrading);
824}
825
Yixin Wang10f477ed2017-11-21 04:20:20826TEST(URLRequestContextConfigTest, SetQuicHostWhitelist) {
Gabriel Charettedfa36042019-08-19 17:30:11827 base::test::TaskEnvironment task_environment_(
828 base::test::TaskEnvironment::MainThreadType::IO);
Yixin Wang10f477ed2017-11-21 04:20:20829
830 URLRequestContextConfig config(
831 // Enable QUIC.
832 true,
833 // QUIC User Agent ID.
834 "Default QUIC User Agent ID",
835 // Enable SPDY.
836 true,
837 // Enable Brotli.
838 false,
839 // Type of http cache.
840 URLRequestContextConfig::HttpCacheType::DISK,
841 // Max size of http cache in bytes.
842 1024000,
843 // Disable caching for HTTP responses. Other information may be stored in
844 // the cache.
845 false,
846 // Storage path for http cache and cookie storage.
847 "/data/data/org.chromium.net/app_cronet_test/test_storage",
Misha Efimovd4ab38302018-01-30 23:56:42848 // Accept-Language request header field.
849 "foreign-language",
Yixin Wang10f477ed2017-11-21 04:20:20850 // User-Agent request header field.
851 "fake agent",
852 // JSON encoded experimental options.
853 "{\"QUIC\":{\"host_whitelist\":\"www.example.com,www.example.org\"}}",
854 // MockCertVerifier to use for testing purposes.
855 std::unique_ptr<net::CertVerifier>(),
856 // Enable network quality estimator.
857 false,
858 // Enable Public Key Pinning bypass for local trust anchors.
Paul Jensen6a1ea3a2018-08-24 14:46:41859 true,
860 // Optional network thread priority.
861 base::Optional<double>());
Yixin Wang10f477ed2017-11-21 04:20:20862
863 net::URLRequestContextBuilder builder;
864 net::NetLog net_log;
865 config.ConfigureURLRequestContextBuilder(&builder, &net_log);
866 // Set a ProxyConfigService to avoid DCHECK failure when building.
867 builder.set_proxy_config_service(
Lily Houghtonef028852017-12-06 20:52:30868 std::make_unique<net::ProxyConfigServiceFixed>(
Ramin Halavatica8d5252018-03-12 05:33:49869 net::ProxyConfigWithAnnotation::CreateDirect()));
Yixin Wang10f477ed2017-11-21 04:20:20870 std::unique_ptr<net::URLRequestContext> context(builder.Build());
871 const net::HttpNetworkSession::Params* params =
872 context->GetNetworkSessionParams();
873
Ryan Sleevia9d6aa62019-07-26 13:32:18874 EXPECT_TRUE(base::Contains(params->quic_host_allowlist, "www.example.com"));
875 EXPECT_TRUE(base::Contains(params->quic_host_allowlist, "www.example.org"));
Yixin Wang10f477ed2017-11-21 04:20:20876}
877
Yixin Wang983875152017-11-21 20:30:13878TEST(URLRequestContextConfigTest, SetQuicMaxTimeBeforeCryptoHandshake) {
Gabriel Charettedfa36042019-08-19 17:30:11879 base::test::TaskEnvironment task_environment_(
880 base::test::TaskEnvironment::MainThreadType::IO);
Yixin Wang983875152017-11-21 20:30:13881
882 URLRequestContextConfig config(
883 // Enable QUIC.
884 true,
885 // QUIC User Agent ID.
886 "Default QUIC User Agent ID",
887 // Enable SPDY.
888 true,
889 // Enable Brotli.
890 false,
891 // Type of http cache.
892 URLRequestContextConfig::HttpCacheType::DISK,
893 // Max size of http cache in bytes.
894 1024000,
895 // Disable caching for HTTP responses. Other information may be stored in
896 // the cache.
897 false,
898 // Storage path for http cache and cookie storage.
899 "/data/data/org.chromium.net/app_cronet_test/test_storage",
Misha Efimovd4ab38302018-01-30 23:56:42900 // Accept-Language request header field.
901 "foreign-language",
Yixin Wang983875152017-11-21 20:30:13902 // User-Agent request header field.
903 "fake agent",
904 // JSON encoded experimental options.
905 "{\"QUIC\":{\"max_time_before_crypto_handshake_seconds\":7,"
906 "\"max_idle_time_before_crypto_handshake_seconds\":11}}",
907 // MockCertVerifier to use for testing purposes.
908 std::unique_ptr<net::CertVerifier>(),
909 // Enable network quality estimator.
910 false,
911 // Enable Public Key Pinning bypass for local trust anchors.
Paul Jensen6a1ea3a2018-08-24 14:46:41912 true,
913 // Optional network thread priority.
914 base::Optional<double>());
Yixin Wang983875152017-11-21 20:30:13915
916 net::URLRequestContextBuilder builder;
917 net::NetLog net_log;
918 config.ConfigureURLRequestContextBuilder(&builder, &net_log);
919 // Set a ProxyConfigService to avoid DCHECK failure when building.
920 builder.set_proxy_config_service(
Lily Houghtonef028852017-12-06 20:52:30921 std::make_unique<net::ProxyConfigServiceFixed>(
Ramin Halavatica8d5252018-03-12 05:33:49922 net::ProxyConfigWithAnnotation::CreateDirect()));
Yixin Wang983875152017-11-21 20:30:13923 std::unique_ptr<net::URLRequestContext> context(builder.Build());
924 const net::HttpNetworkSession::Params* params =
925 context->GetNetworkSessionParams();
926
Ryan Sleevi2e8255b2019-07-17 21:02:21927 EXPECT_EQ(7,
928 params->quic_params.max_time_before_crypto_handshake.InSeconds());
929 EXPECT_EQ(
930 11,
931 params->quic_params.max_idle_time_before_crypto_handshake.InSeconds());
Yixin Wang983875152017-11-21 20:30:13932}
933
Yixin Wang1875fdb2017-12-06 02:26:49934TEST(URLURLRequestContextConfigTest, SetQuicConnectionOptions) {
Gabriel Charettedfa36042019-08-19 17:30:11935 base::test::TaskEnvironment task_environment_(
936 base::test::TaskEnvironment::MainThreadType::IO);
Yixin Wang1875fdb2017-12-06 02:26:49937
938 URLRequestContextConfig config(
939 // Enable QUIC.
940 true,
941 // QUIC User Agent ID.
942 "Default QUIC User Agent ID",
943 // Enable SPDY.
944 true,
945 // Enable Brotli.
946 false,
947 // Type of http cache.
948 URLRequestContextConfig::HttpCacheType::DISK,
949 // Max size of http cache in bytes.
950 1024000,
951 // Disable caching for HTTP responses. Other information may be stored in
952 // the cache.
953 false,
954 // Storage path for http cache and cookie storage.
955 "/data/data/org.chromium.net/app_cronet_test/test_storage",
Misha Efimovd4ab38302018-01-30 23:56:42956 // Accept-Language request header field.
957 "foreign-language",
Yixin Wang1875fdb2017-12-06 02:26:49958 // User-Agent request header field.
959 "fake agent",
960 // JSON encoded experimental options.
961 "{\"QUIC\":{\"connection_options\":\"TIME,TBBR,REJ\","
962 "\"client_connection_options\":\"TBBR,1RTT\"}}",
963 // MockCertVerifier to use for testing purposes.
964 std::unique_ptr<net::CertVerifier>(),
965 // Enable network quality estimator.
966 false,
967 // Enable Public Key Pinning bypass for local trust anchors.
Paul Jensen6a1ea3a2018-08-24 14:46:41968 true,
969 // Optional network thread priority.
970 base::Optional<double>());
Yixin Wang1875fdb2017-12-06 02:26:49971
972 net::URLRequestContextBuilder builder;
973 net::NetLog net_log;
974 config.ConfigureURLRequestContextBuilder(&builder, &net_log);
975 // Set a ProxyConfigService to avoid DCHECK failure when building.
976 builder.set_proxy_config_service(
Gyuyoung Kim6afb5082018-01-19 13:35:57977 std::make_unique<net::ProxyConfigServiceFixed>(
Ramin Halavatica8d5252018-03-12 05:33:49978 net::ProxyConfigWithAnnotation::CreateDirect()));
Yixin Wang1875fdb2017-12-06 02:26:49979 std::unique_ptr<net::URLRequestContext> context(builder.Build());
980 const net::HttpNetworkSession::Params* params =
981 context->GetNetworkSessionParams();
982
Ryan Hamilton8d9ee76e2018-05-29 23:52:52983 quic::QuicTagVector connection_options;
984 connection_options.push_back(quic::kTIME);
985 connection_options.push_back(quic::kTBBR);
986 connection_options.push_back(quic::kREJ);
Nick Harper72ade192019-07-17 03:30:42987 EXPECT_EQ(connection_options, params->quic_params.connection_options);
Yixin Wang1875fdb2017-12-06 02:26:49988
Ryan Hamilton8d9ee76e2018-05-29 23:52:52989 quic::QuicTagVector client_connection_options;
990 client_connection_options.push_back(quic::kTBBR);
991 client_connection_options.push_back(quic::k1RTT);
Nick Harper72ade192019-07-17 03:30:42992 EXPECT_EQ(client_connection_options,
993 params->quic_params.client_connection_options);
Yixin Wang1875fdb2017-12-06 02:26:49994}
995
Misha Efimovd4ab38302018-01-30 23:56:42996TEST(URLURLRequestContextConfigTest, SetAcceptLanguageAndUserAgent) {
Gabriel Charettedfa36042019-08-19 17:30:11997 base::test::TaskEnvironment task_environment_(
998 base::test::TaskEnvironment::MainThreadType::IO);
Misha Efimovd4ab38302018-01-30 23:56:42999
1000 URLRequestContextConfig config(
1001 // Enable QUIC.
1002 true,
1003 // QUIC User Agent ID.
1004 "Default QUIC User Agent ID",
1005 // Enable SPDY.
1006 true,
1007 // Enable Brotli.
1008 false,
1009 // Type of http cache.
1010 URLRequestContextConfig::HttpCacheType::DISK,
1011 // Max size of http cache in bytes.
1012 1024000,
1013 // Disable caching for HTTP responses. Other information may be stored in
1014 // the cache.
1015 false,
1016 // Storage path for http cache and cookie storage.
1017 "/data/data/org.chromium.net/app_cronet_test/test_storage",
1018 // Accept-Language request header field.
1019 "foreign-language",
1020 // User-Agent request header field.
1021 "fake agent",
1022 // JSON encoded experimental options.
1023 "{}",
1024 // MockCertVerifier to use for testing purposes.
1025 std::unique_ptr<net::CertVerifier>(),
1026 // Enable network quality estimator.
1027 false,
1028 // Enable Public Key Pinning bypass for local trust anchors.
Paul Jensen6a1ea3a2018-08-24 14:46:411029 true,
1030 // Optional network thread priority.
1031 base::Optional<double>());
Misha Efimovd4ab38302018-01-30 23:56:421032
1033 net::URLRequestContextBuilder builder;
1034 net::NetLog net_log;
1035 config.ConfigureURLRequestContextBuilder(&builder, &net_log);
1036 // Set a ProxyConfigService to avoid DCHECK failure when building.
1037 builder.set_proxy_config_service(
1038 std::make_unique<net::ProxyConfigServiceFixed>(
Ramin Halavatica8d5252018-03-12 05:33:491039 net::ProxyConfigWithAnnotation::CreateDirect()));
Misha Efimovd4ab38302018-01-30 23:56:421040 std::unique_ptr<net::URLRequestContext> context(builder.Build());
1041 EXPECT_EQ("foreign-language",
1042 context->http_user_agent_settings()->GetAcceptLanguage());
1043 EXPECT_EQ("fake agent", context->http_user_agent_settings()->GetUserAgent());
1044}
1045
juliatuttle50d9c4b2016-08-23 22:49:191046// See stale_host_resolver_unittest.cc for test of StaleDNS options.
1047
xunjielif24ee5f2015-11-23 18:05:261048} // namespace cronet