blob: cb62f84691848b78d1b2562a6d01de848ad7bcc9 [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
Julia Tuttle3cc27a4a2018-04-25 15:57:069#include "base/json/json_writer.h"
Douglas Creagera220947e2018-08-23 20:08:5310#include "base/strings/string_piece.h"
mmenke51629db12017-06-28 13:34:1211#include "base/test/scoped_task_environment.h"
Douglas Creagera220947e2018-08-23 20:08:5312#include "base/test/values_test_util.h"
tfhef3618f2016-01-11 23:07:0813#include "base/values.h"
Zhongyi Shiaa518c22018-06-15 04:37:3614#include "build/build_config.h"
pauljensen9041eb3c2015-12-09 12:29:0115#include "net/cert/cert_verifier.h"
xunjielif24ee5f2015-11-23 18:05:2616#include "net/http/http_network_session.h"
mikecironef22f9812016-10-04 03:40:1917#include "net/log/net_log.h"
18#include "net/log/net_log_with_source.h"
Lily Houghton582d4622018-01-22 22:43:4019#include "net/proxy_resolution/proxy_config.h"
20#include "net/proxy_resolution/proxy_config_service_fixed.h"
Misha Efimovd4ab38302018-01-30 23:56:4221#include "net/url_request/http_user_agent_settings.h"
xunjielif24ee5f2015-11-23 18:05:2622#include "net/url_request/url_request_context.h"
23#include "net/url_request/url_request_context_builder.h"
24#include "testing/gtest/include/gtest/gtest.h"
25
Douglas Creagera220947e2018-08-23 20:08:5326#if BUILDFLAG(ENABLE_REPORTING)
27#include "net/network_error_logging/network_error_logging_service.h"
28#include "net/reporting/reporting_service.h"
29#endif // BUILDFLAG(ENABLE_REPORTING)
30
xunjielif24ee5f2015-11-23 18:05:2631namespace cronet {
32
Douglas Creagera220947e2018-08-23 20:08:5333namespace {
34
Douglas Creagera220947e2018-08-23 20:08:5335std::string WrapJsonHeader(base::StringPiece value) {
36 std::string result;
37 result.reserve(value.size() + 2);
38 result.push_back('[');
39 value.AppendToString(&result);
40 result.push_back(']');
41 return result;
42}
43
44// Returns whether two JSON-encoded headers contain the same content, ignoring
45// irrelevant encoding issues like whitespace and map element ordering.
46bool JsonHeaderEquals(base::StringPiece expected, base::StringPiece actual) {
Lei Zhang9b9d5792019-02-20 07:24:4247 return base::test::ParseJson(WrapJsonHeader(expected)) ==
48 base::test::ParseJson(WrapJsonHeader(actual));
Douglas Creagera220947e2018-08-23 20:08:5349}
50
51} // namespace
52
mmenke51629db12017-06-28 13:34:1253TEST(URLRequestContextConfigTest, TestExperimentalOptionParsing) {
54 base::test::ScopedTaskEnvironment scoped_task_environment_(
55 base::test::ScopedTaskEnvironment::MainThreadType::IO);
56
Julia Tuttle3cc27a4a2018-04-25 15:57:0657 // Create JSON for experimental options.
58 base::DictionaryValue options;
59 options.SetPath({"QUIC", "max_server_configs_stored_in_properties"},
60 base::Value(2));
61 options.SetPath({"QUIC", "user_agent_id"}, base::Value("Custom QUIC UAID"));
62 options.SetPath({"QUIC", "idle_connection_timeout_seconds"},
63 base::Value(300));
64 options.SetPath({"QUIC", "close_sessions_on_ip_change"}, base::Value(true));
65 options.SetPath({"QUIC", "race_cert_verification"}, base::Value(true));
66 options.SetPath({"QUIC", "connection_options"}, base::Value("TIME,TBBR,REJ"));
67 options.SetPath({"AsyncDNS", "enable"}, base::Value(true));
68 options.SetPath({"NetworkErrorLogging", "enable"}, base::Value(true));
Douglas Creagera220947e2018-08-23 20:08:5369 options.SetPath({"NetworkErrorLogging", "preloaded_report_to_headers"},
Lei Zhang9b9d5792019-02-20 07:24:4270 base::test::ParseJson(R"json(
Douglas Creagera220947e2018-08-23 20:08:5371 [
72 {
73 "origin": "https://test-origin/",
74 "value": {
75 "group": "test-group",
76 "max_age": 86400,
77 "endpoints": [
78 {"url": "https://test-endpoint/"},
79 ],
80 },
81 },
82 {
83 "origin": "https://test-origin-2/",
84 "value": [
85 {
86 "group": "test-group-2",
87 "max_age": 86400,
88 "endpoints": [
89 {"url": "https://test-endpoint-2/"},
90 ],
91 },
92 {
93 "group": "test-group-3",
94 "max_age": 86400,
95 "endpoints": [
96 {"url": "https://test-endpoint-3/"},
97 ],
98 },
99 ],
100 },
101 {
102 "origin": "https://value-is-missing/",
103 },
104 {
105 "value": "origin is missing",
106 },
107 {
108 "origin": 123,
109 "value": "origin is not a string",
110 },
111 {
112 "origin": "this is not a URL",
113 "value": "origin not a URL",
114 },
115 ]
116 )json"));
117 options.SetPath({"NetworkErrorLogging", "preloaded_nel_headers"},
Lei Zhang9b9d5792019-02-20 07:24:42118 base::test::ParseJson(R"json(
Douglas Creagera220947e2018-08-23 20:08:53119 [
120 {
121 "origin": "https://test-origin/",
122 "value": {
123 "report_to": "test-group",
124 "max_age": 86400,
125 },
126 },
127 ]
128 )json"));
Julia Tuttle3cc27a4a2018-04-25 15:57:06129 options.SetPath({"UnknownOption", "foo"}, base::Value(true));
130 options.SetPath({"HostResolverRules", "host_resolver_rules"},
131 base::Value("MAP * 127.0.0.1"));
132 // See http://crbug.com/696569.
133 options.SetKey("disable_ipv6_on_wifi", base::Value(true));
134 std::string options_json;
135 EXPECT_TRUE(base::JSONWriter::Write(options, &options_json));
136
pauljensen9041eb3c2015-12-09 12:29:01137 URLRequestContextConfig config(
138 // Enable QUIC.
139 true,
mefc5da5712016-02-09 20:14:23140 // QUIC User Agent ID.
141 "Default QUIC User Agent ID",
pauljensen9041eb3c2015-12-09 12:29:01142 // Enable SPDY.
143 true,
xunjieli186d2bf2017-04-18 13:45:47144 // Enable Brotli.
145 false,
pauljensen9041eb3c2015-12-09 12:29:01146 // Type of http cache.
147 URLRequestContextConfig::HttpCacheType::DISK,
148 // Max size of http cache in bytes.
149 1024000,
150 // Disable caching for HTTP responses. Other information may be stored in
151 // the cache.
152 false,
153 // Storage path for http cache and cookie storage.
154 "/data/data/org.chromium.net/app_cronet_test/test_storage",
Misha Efimovd4ab38302018-01-30 23:56:42155 // Accept-Language request header field.
156 "foreign-language",
pauljensen9041eb3c2015-12-09 12:29:01157 // User-Agent request header field.
158 "fake agent",
159 // JSON encoded experimental options.
Julia Tuttle3cc27a4a2018-04-25 15:57:06160 options_json,
pauljensen9041eb3c2015-12-09 12:29:01161 // MockCertVerifier to use for testing purposes.
tbansal7018e2a2016-06-25 00:40:39162 std::unique_ptr<net::CertVerifier>(),
163 // Enable network quality estimator.
kapishnikov385aa422016-07-01 20:53:02164 false,
165 // Enable Public Key Pinning bypass for local trust anchors.
Paul Jensen6a1ea3a2018-08-24 14:46:41166 true,
167 // Optional network thread priority.
168 base::Optional<double>(42.0));
xunjielif24ee5f2015-11-23 18:05:26169
xunjielif24ee5f2015-11-23 18:05:26170 net::URLRequestContextBuilder builder;
pauljensene92c4092015-12-09 19:13:48171 net::NetLog net_log;
David Benjamindc2f4b02017-07-27 23:59:02172 config.ConfigureURLRequestContextBuilder(&builder, &net_log);
xunjielid67295e2017-03-16 21:05:41173 EXPECT_FALSE(config.effective_experimental_options->HasKey("UnknownOption"));
xunjielif24ee5f2015-11-23 18:05:26174 // Set a ProxyConfigService to avoid DCHECK failure when building.
ricea85ec57952016-08-31 09:34:10175 builder.set_proxy_config_service(
Lily Houghtonef028852017-12-06 20:52:30176 std::make_unique<net::ProxyConfigServiceFixed>(
Ramin Halavatica8d5252018-03-12 05:33:49177 net::ProxyConfigWithAnnotation::CreateDirect()));
dchengfe3745e6242016-04-21 23:49:58178 std::unique_ptr<net::URLRequestContext> context(builder.Build());
xunjielif24ee5f2015-11-23 18:05:26179 const net::HttpNetworkSession::Params* params =
180 context->GetNetworkSessionParams();
181 // Check Quic Connection options.
Ryan Hamilton8d9ee76e2018-05-29 23:52:52182 quic::QuicTagVector quic_connection_options;
183 quic_connection_options.push_back(quic::kTIME);
184 quic_connection_options.push_back(quic::kTBBR);
185 quic_connection_options.push_back(quic::kREJ);
xunjielif24ee5f2015-11-23 18:05:26186 EXPECT_EQ(quic_connection_options, params->quic_connection_options);
187
mefc5da5712016-02-09 20:14:23188 // Check Custom QUIC User Agent Id.
189 EXPECT_EQ("Custom QUIC UAID", params->quic_user_agent_id);
190
rtenneti6971c172016-01-15 20:12:10191 // Check max_server_configs_stored_in_properties.
192 EXPECT_EQ(2u, params->quic_max_server_configs_stored_in_properties);
xunjielif24ee5f2015-11-23 18:05:26193
rtenneti64e809d02015-12-11 00:26:20194 // Check idle_connection_timeout_seconds.
195 EXPECT_EQ(300, params->quic_idle_connection_timeout_seconds);
196
Jana Iyengar903dec22017-11-28 00:44:23197 EXPECT_TRUE(params->quic_close_sessions_on_ip_change);
Zhongyi Shi63574b72018-06-01 20:22:25198 EXPECT_FALSE(params->quic_goaway_sessions_on_ip_change);
Zhongyi Shi8ff38c12018-02-22 00:02:30199 EXPECT_FALSE(params->quic_allow_server_migration);
Zhongyi Shi64795622017-11-20 02:21:49200 EXPECT_FALSE(params->quic_migrate_sessions_on_network_change_v2);
Zhongyi Shif4683a32017-12-01 00:03:28201 EXPECT_FALSE(params->quic_migrate_sessions_early_v2);
Zhongyi Shiff359581bc2018-09-26 18:11:48202 EXPECT_FALSE(params->quic_retry_on_alternate_network_before_handshake);
Renjie94b90712018-10-18 21:03:19203 EXPECT_FALSE(params->quic_race_stale_dns_on_connection);
jrid26566952016-02-04 21:06:42204
rtennetid073dd22016-08-04 01:58:33205 // Check race_cert_verification.
206 EXPECT_TRUE(params->quic_race_cert_verification);
207
Misha Efimov63957912017-12-06 07:13:26208#if defined(ENABLE_BUILT_IN_DNS)
209 // Check AsyncDNS resolver is enabled (not supported on iOS).
tfhef3618f2016-01-11 23:07:08210 EXPECT_TRUE(context->host_resolver()->GetDnsConfigAsValue());
Misha Efimov63957912017-12-06 07:13:26211#endif // defined(ENABLE_BUILT_IN_DNS)
mgershaf2c12c2016-08-22 16:33:54212
Julia Tuttle9715d1642018-01-29 17:02:26213#if BUILDFLAG(ENABLE_REPORTING)
214 // Check Reporting and Network Error Logging are enabled (can be disabled at
215 // build time).
216 EXPECT_TRUE(context->reporting_service());
Julia Tuttlecba7d222018-02-23 19:37:27217 EXPECT_TRUE(context->network_error_logging_service());
Julia Tuttle9715d1642018-01-29 17:02:26218#endif // BUILDFLAG(ENABLE_REPORTING)
219
Douglas Creagera220947e2018-08-23 20:08:53220 ASSERT_EQ(2u, config.preloaded_report_to_headers.size());
221 EXPECT_EQ(url::Origin::CreateFromNormalizedTuple("https", "test-origin", 443),
222 config.preloaded_report_to_headers[0].origin);
223 EXPECT_TRUE(JsonHeaderEquals( //
224 R"json(
225 {
226 "group": "test-group",
227 "max_age": 86400,
228 "endpoints": [
229 {"url": "https://test-endpoint/"},
230 ],
231 }
232 )json",
233 config.preloaded_report_to_headers[0].value));
234 EXPECT_EQ(
235 url::Origin::CreateFromNormalizedTuple("https", "test-origin-2", 443),
236 config.preloaded_report_to_headers[1].origin);
237 EXPECT_TRUE(JsonHeaderEquals( //
238 R"json(
239 {
240 "group": "test-group-2",
241 "max_age": 86400,
242 "endpoints": [
243 {"url": "https://test-endpoint-2/"},
244 ],
245 },
246 {
247 "group": "test-group-3",
248 "max_age": 86400,
249 "endpoints": [
250 {"url": "https://test-endpoint-3/"},
251 ],
252 }
253 )json",
254 config.preloaded_report_to_headers[1].value));
255
256 ASSERT_EQ(1u, config.preloaded_nel_headers.size());
257 EXPECT_EQ(url::Origin::CreateFromNormalizedTuple("https", "test-origin", 443),
258 config.preloaded_nel_headers[0].origin);
259 EXPECT_TRUE(JsonHeaderEquals( //
260 R"json(
261 {
262 "report_to": "test-group",
263 "max_age": 86400,
264 }
265 )json",
266 config.preloaded_nel_headers[0].value));
267
mgershaf9a9232017-04-13 20:19:03268 // Check IPv6 is disabled when on wifi.
269 EXPECT_TRUE(context->host_resolver()->GetNoIPv6OnWifi());
mgershb3fe8082017-02-28 20:09:20270
mgershaf2c12c2016-08-22 16:33:54271 net::HostResolver::RequestInfo info(net::HostPortPair("abcde", 80));
272 net::AddressList addresses;
273 EXPECT_EQ(net::OK, context->host_resolver()->ResolveFromCache(
tfarina428341112016-09-22 13:38:20274 info, &addresses, net::NetLogWithSource()));
Paul Jensen6a1ea3a2018-08-24 14:46:41275
276 EXPECT_TRUE(config.network_thread_priority);
277 EXPECT_EQ(42.0, config.network_thread_priority.value());
xunjielif24ee5f2015-11-23 18:05:26278}
279
Zhongyi Shi57247962018-11-05 20:03:52280TEST(URLRequestContextConfigTest, SetSupportedQuicVersion) {
281 base::test::ScopedTaskEnvironment scoped_task_environment_(
282 base::test::ScopedTaskEnvironment::MainThreadType::IO);
283
284 URLRequestContextConfig config(
285 // Enable QUIC.
286 true,
287 // QUIC User Agent ID.
288 "Default QUIC User Agent ID",
289 // Enable SPDY.
290 true,
291 // Enable Brotli.
292 false,
293 // Type of http cache.
294 URLRequestContextConfig::HttpCacheType::DISK,
295 // Max size of http cache in bytes.
296 1024000,
297 // Disable caching for HTTP responses. Other information may be stored in
298 // the cache.
299 false,
300 // Storage path for http cache and cookie storage.
301 "/data/data/org.chromium.net/app_cronet_test/test_storage",
302 // Accept-Language request header field.
303 "foreign-language",
304 // User-Agent request header field.
305 "fake agent",
306 // JSON encoded experimental options.
307 "{\"QUIC\":{\"quic_version\":\"QUIC_VERSION_44\"}}",
308 // MockCertVerifier to use for testing purposes.
309 std::unique_ptr<net::CertVerifier>(),
310 // Enable network quality estimator.
311 false,
312 // Enable Public Key Pinning bypass for local trust anchors.
313 true,
314 // Optional network thread priority.
315 base::Optional<double>());
316
317 net::URLRequestContextBuilder builder;
318 net::NetLog net_log;
319 config.ConfigureURLRequestContextBuilder(&builder, &net_log);
320 // Set a ProxyConfigService to avoid DCHECK failure when building.
321 builder.set_proxy_config_service(
322 std::make_unique<net::ProxyConfigServiceFixed>(
323 net::ProxyConfigWithAnnotation::CreateDirect()));
324 std::unique_ptr<net::URLRequestContext> context(builder.Build());
325 const net::HttpNetworkSession::Params* params =
326 context->GetNetworkSessionParams();
327 EXPECT_EQ(params->quic_supported_versions.size(), 1u);
328 EXPECT_EQ(params->quic_supported_versions[0], quic::QUIC_VERSION_44);
329}
330
331TEST(URLRequestContextConfigTest, SetUnsupportedQuicVersion) {
332 base::test::ScopedTaskEnvironment scoped_task_environment_(
333 base::test::ScopedTaskEnvironment::MainThreadType::IO);
334
335 URLRequestContextConfig config(
336 // Enable QUIC.
337 true,
338 // QUIC User Agent ID.
339 "Default QUIC User Agent ID",
340 // Enable SPDY.
341 true,
342 // Enable Brotli.
343 false,
344 // Type of http cache.
345 URLRequestContextConfig::HttpCacheType::DISK,
346 // Max size of http cache in bytes.
347 1024000,
348 // Disable caching for HTTP responses. Other information may be stored in
349 // the cache.
350 false,
351 // Storage path for http cache and cookie storage.
352 "/data/data/org.chromium.net/app_cronet_test/test_storage",
353 // Accept-Language request header field.
354 "foreign-language",
355 // User-Agent request header field.
356 "fake agent",
357 // JSON encoded experimental options.
358 "{\"QUIC\":{\"quic_version\":\"QUIC_VERSION_33\"}}",
359 // MockCertVerifier to use for testing purposes.
360 std::unique_ptr<net::CertVerifier>(),
361 // Enable network quality estimator.
362 false,
363 // Enable Public Key Pinning bypass for local trust anchors.
364 true,
365 // Optional network thread priority.
366 base::Optional<double>());
367
368 net::URLRequestContextBuilder builder;
369 net::NetLog net_log;
370 config.ConfigureURLRequestContextBuilder(&builder, &net_log);
371 // Set a ProxyConfigService to avoid DCHECK failure when building.
372 builder.set_proxy_config_service(
373 std::make_unique<net::ProxyConfigServiceFixed>(
374 net::ProxyConfigWithAnnotation::CreateDirect()));
375 std::unique_ptr<net::URLRequestContext> context(builder.Build());
376 const net::HttpNetworkSession::Params* params =
377 context->GetNetworkSessionParams();
378 EXPECT_EQ(params->quic_supported_versions.size(), 1u);
379 EXPECT_EQ(params->quic_supported_versions[0], quic::QUIC_VERSION_43);
380}
381
Zhongyi Shi8ff38c12018-02-22 00:02:30382TEST(URLRequestContextConfigTest, SetQuicServerMigrationOptions) {
383 base::test::ScopedTaskEnvironment scoped_task_environment_(
384 base::test::ScopedTaskEnvironment::MainThreadType::IO);
385
386 URLRequestContextConfig config(
387 // Enable QUIC.
388 true,
389 // QUIC User Agent ID.
390 "Default QUIC User Agent ID",
391 // Enable SPDY.
392 true,
393 // Enable Brotli.
394 false,
395 // Type of http cache.
396 URLRequestContextConfig::HttpCacheType::DISK,
397 // Max size of http cache in bytes.
398 1024000,
399 // Disable caching for HTTP responses. Other information may be stored in
400 // the cache.
401 false,
402 // Storage path for http cache and cookie storage.
403 "/data/data/org.chromium.net/app_cronet_test/test_storage",
404 // Accept-Language request header field.
405 "foreign-language",
406 // User-Agent request header field.
407 "fake agent",
408 // JSON encoded experimental options.
409 "{\"QUIC\":{\"allow_server_migration\":true}}",
410 // MockCertVerifier to use for testing purposes.
411 std::unique_ptr<net::CertVerifier>(),
412 // Enable network quality estimator.
413 false,
414 // Enable Public Key Pinning bypass for local trust anchors.
Paul Jensen6a1ea3a2018-08-24 14:46:41415 true,
416 // Optional network thread priority.
417 base::Optional<double>());
Zhongyi Shi8ff38c12018-02-22 00:02:30418
419 net::URLRequestContextBuilder builder;
420 net::NetLog net_log;
421 config.ConfigureURLRequestContextBuilder(&builder, &net_log);
422 // Set a ProxyConfigService to avoid DCHECK failure when building.
423 builder.set_proxy_config_service(
424 std::make_unique<net::ProxyConfigServiceFixed>(
Ramin Halavatica8d5252018-03-12 05:33:49425 net::ProxyConfigWithAnnotation::CreateDirect()));
Zhongyi Shi8ff38c12018-02-22 00:02:30426 std::unique_ptr<net::URLRequestContext> context(builder.Build());
427 const net::HttpNetworkSession::Params* params =
428 context->GetNetworkSessionParams();
429
430 EXPECT_FALSE(params->quic_close_sessions_on_ip_change);
431 EXPECT_TRUE(params->quic_allow_server_migration);
432}
433
Zhongyi Shiaa518c22018-06-15 04:37:36434// Test that goaway_sessions_on_ip_change is set on by default for iOS.
435#if defined(OS_IOS)
436#define MAYBE_SetQuicGoAwaySessionsOnIPChangeByDefault \
437 SetQuicGoAwaySessionsOnIPChangeByDefault
438#else
439#define MAYBE_SetQuicGoAwaySessionsOnIPChangeByDefault \
440 DISABLED_SetQuicGoAwaySessionsOnIPChangeByDefault
441#endif
442TEST(URLRequestContextConfigTest,
443 MAYBE_SetQuicGoAwaySessionsOnIPChangeByDefault) {
444 base::test::ScopedTaskEnvironment scoped_task_environment_(
445 base::test::ScopedTaskEnvironment::MainThreadType::IO);
446
447 URLRequestContextConfig config(
448 // Enable QUIC.
449 true,
450 // QUIC User Agent ID.
451 "Default QUIC User Agent ID",
452 // Enable SPDY.
453 true,
454 // Enable Brotli.
455 false,
456 // Type of http cache.
457 URLRequestContextConfig::HttpCacheType::DISK,
458 // Max size of http cache in bytes.
459 1024000,
460 // Disable caching for HTTP responses. Other information may be stored in
461 // the cache.
462 false,
463 // Storage path for http cache and cookie storage.
464 "/data/data/org.chromium.net/app_cronet_test/test_storage",
465 // Accept-Language request header field.
466 "foreign-language",
467 // User-Agent request header field.
468 "fake agent",
469 // JSON encoded experimental options.
470 "{\"QUIC\":{}}",
471 // MockCertVerifier to use for testing purposes.
472 std::unique_ptr<net::CertVerifier>(),
473 // Enable network quality estimator.
474 false,
475 // Enable Public Key Pinning bypass for local trust anchors.
Paul Jensen6a1ea3a2018-08-24 14:46:41476 true,
477 // Optional network thread priority.
478 base::Optional<double>());
Zhongyi Shiaa518c22018-06-15 04:37:36479
480 net::URLRequestContextBuilder builder;
481 net::NetLog net_log;
482 config.ConfigureURLRequestContextBuilder(&builder, &net_log);
483 // Set a ProxyConfigService to avoid DCHECK failure when building.
484 builder.set_proxy_config_service(
485 std::make_unique<net::ProxyConfigServiceFixed>(
486 net::ProxyConfigWithAnnotation::CreateDirect()));
487 std::unique_ptr<net::URLRequestContext> context(builder.Build());
488 const net::HttpNetworkSession::Params* params =
489 context->GetNetworkSessionParams();
490
491 EXPECT_FALSE(params->quic_close_sessions_on_ip_change);
492 EXPECT_TRUE(params->quic_goaway_sessions_on_ip_change);
493}
494
495// Tests that goaway_sessions_on_ip_changes can be set on via
496// experimental options on non-iOS.
497#if !defined(OS_IOS)
498#define MAYBE_SetQuicGoAwaySessionsOnIPChangeViaExperimentOptions \
499 SetQuicGoAwaySessionsOnIPChangeViaExperimentOptions
500#else
501#define MAYBE_SetQuicGoAwaySessionsOnIPChangeViaExperimentOptions \
502 DISABLED_SetQuicGoAwaySessionsOnIPChangeViaExperimentOptions
503#endif
504TEST(URLRequestContextConfigTest,
505 MAYBE_SetQuicGoAwaySessionsOnIPChangeViaExperimentOptions) {
Zhongyi Shi63574b72018-06-01 20:22:25506 base::test::ScopedTaskEnvironment scoped_task_environment_(
507 base::test::ScopedTaskEnvironment::MainThreadType::IO);
508
509 URLRequestContextConfig config(
510 // Enable QUIC.
511 true,
512 // QUIC User Agent ID.
513 "Default QUIC User Agent ID",
514 // Enable SPDY.
515 true,
516 // Enable Brotli.
517 false,
518 // Type of http cache.
519 URLRequestContextConfig::HttpCacheType::DISK,
520 // Max size of http cache in bytes.
521 1024000,
522 // Disable caching for HTTP responses. Other information may be stored in
523 // the cache.
524 false,
525 // Storage path for http cache and cookie storage.
526 "/data/data/org.chromium.net/app_cronet_test/test_storage",
527 // Accept-Language request header field.
528 "foreign-language",
529 // User-Agent request header field.
530 "fake agent",
531 // JSON encoded experimental options.
532 "{\"QUIC\":{\"goaway_sessions_on_ip_change\":true}}",
533 // MockCertVerifier to use for testing purposes.
534 std::unique_ptr<net::CertVerifier>(),
535 // Enable network quality estimator.
536 false,
537 // Enable Public Key Pinning bypass for local trust anchors.
Paul Jensen6a1ea3a2018-08-24 14:46:41538 true,
539 // Optional network thread priority.
540 base::Optional<double>());
Zhongyi Shi63574b72018-06-01 20:22:25541
542 net::URLRequestContextBuilder builder;
543 net::NetLog net_log;
544 config.ConfigureURLRequestContextBuilder(&builder, &net_log);
545 // Set a ProxyConfigService to avoid DCHECK failure when building.
546 builder.set_proxy_config_service(
547 std::make_unique<net::ProxyConfigServiceFixed>(
548 net::ProxyConfigWithAnnotation::CreateDirect()));
549 std::unique_ptr<net::URLRequestContext> context(builder.Build());
550 const net::HttpNetworkSession::Params* params =
551 context->GetNetworkSessionParams();
552
553 EXPECT_FALSE(params->quic_close_sessions_on_ip_change);
554 EXPECT_TRUE(params->quic_goaway_sessions_on_ip_change);
555}
556
Zhongyi Shiaa518c22018-06-15 04:37:36557// Test that goaway_sessions_on_ip_change can be set to false via
558// exprimental options on iOS.
559#if defined(OS_IOS)
560#define MAYBE_DisableQuicGoAwaySessionsOnIPChangeViaExperimentOptions \
561 DisableQuicGoAwaySessionsOnIPChangeViaExperimentOptions
562#else
563#define MAYBE_DisableQuicGoAwaySessionsOnIPChangeViaExperimentOptions \
564 DISABLED_DisableQuicGoAwaySessionsOnIPChangeViaExperimentOptions
565#endif
566TEST(URLRequestContextConfigTest,
567 MAYBE_DisableQuicGoAwaySessionsOnIPChangeViaExperimentOptions) {
568 base::test::ScopedTaskEnvironment scoped_task_environment_(
569 base::test::ScopedTaskEnvironment::MainThreadType::IO);
570
571 URLRequestContextConfig config(
572 // Enable QUIC.
573 true,
574 // QUIC User Agent ID.
575 "Default QUIC User Agent ID",
576 // Enable SPDY.
577 true,
578 // Enable Brotli.
579 false,
580 // Type of http cache.
581 URLRequestContextConfig::HttpCacheType::DISK,
582 // Max size of http cache in bytes.
583 1024000,
584 // Disable caching for HTTP responses. Other information may be stored in
585 // the cache.
586 false,
587 // Storage path for http cache and cookie storage.
588 "/data/data/org.chromium.net/app_cronet_test/test_storage",
589 // Accept-Language request header field.
590 "foreign-language",
591 // User-Agent request header field.
592 "fake agent",
593 // JSON encoded experimental options.
594 "{\"QUIC\":{\"goaway_sessions_on_ip_change\":false}}",
595 // MockCertVerifier to use for testing purposes.
596 std::unique_ptr<net::CertVerifier>(),
597 // Enable network quality estimator.
598 false,
599 // Enable Public Key Pinning bypass for local trust anchors.
Paul Jensen6a1ea3a2018-08-24 14:46:41600 true,
601 // Optional network thread priority.
602 base::Optional<double>());
Zhongyi Shiaa518c22018-06-15 04:37:36603
604 net::URLRequestContextBuilder builder;
605 net::NetLog net_log;
606 config.ConfigureURLRequestContextBuilder(&builder, &net_log);
607 // Set a ProxyConfigService to avoid DCHECK failure when building.
608 builder.set_proxy_config_service(
609 std::make_unique<net::ProxyConfigServiceFixed>(
610 net::ProxyConfigWithAnnotation::CreateDirect()));
611 std::unique_ptr<net::URLRequestContext> context(builder.Build());
612 const net::HttpNetworkSession::Params* params =
613 context->GetNetworkSessionParams();
614
615 EXPECT_FALSE(params->quic_close_sessions_on_ip_change);
616 EXPECT_FALSE(params->quic_goaway_sessions_on_ip_change);
617}
618
Yixin Wang10f477ed2017-11-21 04:20:20619TEST(URLRequestContextConfigTest, SetQuicConnectionMigrationV2Options) {
Zhongyi Shi64795622017-11-20 02:21:49620 base::test::ScopedTaskEnvironment scoped_task_environment_(
621 base::test::ScopedTaskEnvironment::MainThreadType::IO);
622
623 URLRequestContextConfig config(
624 // Enable QUIC.
625 true,
626 // QUIC User Agent ID.
627 "Default QUIC User Agent ID",
628 // Enable SPDY.
629 true,
630 // Enable Brotli.
631 false,
632 // Type of http cache.
633 URLRequestContextConfig::HttpCacheType::DISK,
634 // Max size of http cache in bytes.
635 1024000,
636 // Disable caching for HTTP responses. Other information may be stored in
637 // the cache.
638 false,
639 // Storage path for http cache and cookie storage.
640 "/data/data/org.chromium.net/app_cronet_test/test_storage",
Misha Efimovd4ab38302018-01-30 23:56:42641 // Accept-Language request header field.
642 "foreign-language",
Zhongyi Shi64795622017-11-20 02:21:49643 // User-Agent request header field.
644 "fake agent",
645 // JSON encoded experimental options.
Zhongyi Shif4683a32017-12-01 00:03:28646 "{\"QUIC\":{\"migrate_sessions_on_network_change_v2\":true,"
Zhongyi Shi73f23ca872017-12-13 18:37:13647 "\"migrate_sessions_early_v2\":true,"
Zhongyi Shiff359581bc2018-09-26 18:11:48648 "\"retry_on_alternate_network_before_handshake\":true,"
Zhongyi Shibc85e3e2019-02-12 19:34:42649 "\"idle_session_migration_period_seconds\":15,"
Zhongyi Shi8b1e43f2017-12-13 20:46:30650 "\"max_time_on_non_default_network_seconds\":10,"
Zhongyi Shiee760762018-08-01 00:54:29651 "\"max_migrations_to_non_default_network_on_write_error\":3,"
Zhongyi Shi8b1e43f2017-12-13 20:46:30652 "\"max_migrations_to_non_default_network_on_path_degrading\":4}}",
Zhongyi Shi64795622017-11-20 02:21:49653 // MockCertVerifier to use for testing purposes.
654 std::unique_ptr<net::CertVerifier>(),
655 // Enable network quality estimator.
656 false,
657 // Enable Public Key Pinning bypass for local trust anchors.
Paul Jensen6a1ea3a2018-08-24 14:46:41658 true,
659 // Optional network thread priority.
660 base::Optional<double>());
Zhongyi Shi64795622017-11-20 02:21:49661
662 net::URLRequestContextBuilder builder;
663 net::NetLog net_log;
664 config.ConfigureURLRequestContextBuilder(&builder, &net_log);
665 // Set a ProxyConfigService to avoid DCHECK failure when building.
666 builder.set_proxy_config_service(
Lily Houghtonef028852017-12-06 20:52:30667 std::make_unique<net::ProxyConfigServiceFixed>(
Ramin Halavatica8d5252018-03-12 05:33:49668 net::ProxyConfigWithAnnotation::CreateDirect()));
Zhongyi Shi64795622017-11-20 02:21:49669 std::unique_ptr<net::URLRequestContext> context(builder.Build());
670 const net::HttpNetworkSession::Params* params =
671 context->GetNetworkSessionParams();
672
673 EXPECT_TRUE(params->quic_migrate_sessions_on_network_change_v2);
Zhongyi Shif4683a32017-12-01 00:03:28674 EXPECT_TRUE(params->quic_migrate_sessions_early_v2);
Zhongyi Shiff359581bc2018-09-26 18:11:48675 EXPECT_TRUE(params->quic_retry_on_alternate_network_before_handshake);
Zhongyi Shibc85e3e2019-02-12 19:34:42676 EXPECT_EQ(base::TimeDelta::FromSeconds(15),
677 params->quic_idle_session_migration_period);
Zhongyi Shi73f23ca872017-12-13 18:37:13678 EXPECT_EQ(base::TimeDelta::FromSeconds(10),
679 params->quic_max_time_on_non_default_network);
Zhongyi Shiee760762018-08-01 00:54:29680 EXPECT_EQ(3,
681 params->quic_max_migrations_to_non_default_network_on_write_error);
Zhongyi Shi8b1e43f2017-12-13 20:46:30682 EXPECT_EQ(
683 4, params->quic_max_migrations_to_non_default_network_on_path_degrading);
Zhongyi Shi64795622017-11-20 02:21:49684}
685
Renjie94b90712018-10-18 21:03:19686TEST(URLRequestContextConfigTest, SetQuicStaleDNSracing) {
687 base::test::ScopedTaskEnvironment scoped_task_environment_(
688 base::test::ScopedTaskEnvironment::MainThreadType::IO);
689
690 URLRequestContextConfig config(
691 // Enable QUIC.
692 true,
693 // QUIC User Agent ID.
694 "Default QUIC User Agent ID",
695 // Enable SPDY.
696 true,
697 // Enable Brotli.
698 false,
699 // Type of http cache.
700 URLRequestContextConfig::HttpCacheType::DISK,
701 // Max size of http cache in bytes.
702 1024000,
703 // Disable caching for HTTP responses. Other information may be stored in
704 // the cache.
705 false,
706 // Storage path for http cache and cookie storage.
707 "/data/data/org.chromium.net/app_cronet_test/test_storage",
708 // Accept-Language request header field.
709 "foreign-language",
710 // User-Agent request header field.
711 "fake agent",
712 // JSON encoded experimental options.
713 "{\"QUIC\":{\"race_stale_dns_on_connection\":true}}",
714 // MockCertVerifier to use for testing purposes.
715 std::unique_ptr<net::CertVerifier>(),
716 // Enable network quality estimator.
717 false,
718 // Enable Public Key Pinning bypass for local trust anchors.
719 true,
720 // Optional network thread priority.
721 base::Optional<double>());
722
723 net::URLRequestContextBuilder builder;
724 net::NetLog net_log;
725 config.ConfigureURLRequestContextBuilder(&builder, &net_log);
726 // Set a ProxyConfigService to avoid DCHECK failure when building.
727 builder.set_proxy_config_service(
728 std::make_unique<net::ProxyConfigServiceFixed>(
729 net::ProxyConfigWithAnnotation::CreateDirect()));
730 std::unique_ptr<net::URLRequestContext> context(builder.Build());
731 const net::HttpNetworkSession::Params* params =
732 context->GetNetworkSessionParams();
733
734 EXPECT_TRUE(params->quic_race_stale_dns_on_connection);
735}
736
Yixin Wang10f477ed2017-11-21 04:20:20737TEST(URLRequestContextConfigTest, SetQuicHostWhitelist) {
738 base::test::ScopedTaskEnvironment scoped_task_environment_(
739 base::test::ScopedTaskEnvironment::MainThreadType::IO);
740
741 URLRequestContextConfig config(
742 // Enable QUIC.
743 true,
744 // QUIC User Agent ID.
745 "Default QUIC User Agent ID",
746 // Enable SPDY.
747 true,
748 // Enable Brotli.
749 false,
750 // Type of http cache.
751 URLRequestContextConfig::HttpCacheType::DISK,
752 // Max size of http cache in bytes.
753 1024000,
754 // Disable caching for HTTP responses. Other information may be stored in
755 // the cache.
756 false,
757 // Storage path for http cache and cookie storage.
758 "/data/data/org.chromium.net/app_cronet_test/test_storage",
Misha Efimovd4ab38302018-01-30 23:56:42759 // Accept-Language request header field.
760 "foreign-language",
Yixin Wang10f477ed2017-11-21 04:20:20761 // User-Agent request header field.
762 "fake agent",
763 // JSON encoded experimental options.
764 "{\"QUIC\":{\"host_whitelist\":\"www.example.com,www.example.org\"}}",
765 // MockCertVerifier to use for testing purposes.
766 std::unique_ptr<net::CertVerifier>(),
767 // Enable network quality estimator.
768 false,
769 // Enable Public Key Pinning bypass for local trust anchors.
Paul Jensen6a1ea3a2018-08-24 14:46:41770 true,
771 // Optional network thread priority.
772 base::Optional<double>());
Yixin Wang10f477ed2017-11-21 04:20:20773
774 net::URLRequestContextBuilder builder;
775 net::NetLog net_log;
776 config.ConfigureURLRequestContextBuilder(&builder, &net_log);
777 // Set a ProxyConfigService to avoid DCHECK failure when building.
778 builder.set_proxy_config_service(
Lily Houghtonef028852017-12-06 20:52:30779 std::make_unique<net::ProxyConfigServiceFixed>(
Ramin Halavatica8d5252018-03-12 05:33:49780 net::ProxyConfigWithAnnotation::CreateDirect()));
Yixin Wang10f477ed2017-11-21 04:20:20781 std::unique_ptr<net::URLRequestContext> context(builder.Build());
782 const net::HttpNetworkSession::Params* params =
783 context->GetNetworkSessionParams();
784
785 EXPECT_TRUE(
786 base::ContainsKey(params->quic_host_whitelist, "www.example.com"));
787 EXPECT_TRUE(
788 base::ContainsKey(params->quic_host_whitelist, "www.example.org"));
789}
790
Yixin Wang983875152017-11-21 20:30:13791TEST(URLRequestContextConfigTest, SetQuicMaxTimeBeforeCryptoHandshake) {
792 base::test::ScopedTaskEnvironment scoped_task_environment_(
793 base::test::ScopedTaskEnvironment::MainThreadType::IO);
794
795 URLRequestContextConfig config(
796 // Enable QUIC.
797 true,
798 // QUIC User Agent ID.
799 "Default QUIC User Agent ID",
800 // Enable SPDY.
801 true,
802 // Enable Brotli.
803 false,
804 // Type of http cache.
805 URLRequestContextConfig::HttpCacheType::DISK,
806 // Max size of http cache in bytes.
807 1024000,
808 // Disable caching for HTTP responses. Other information may be stored in
809 // the cache.
810 false,
811 // Storage path for http cache and cookie storage.
812 "/data/data/org.chromium.net/app_cronet_test/test_storage",
Misha Efimovd4ab38302018-01-30 23:56:42813 // Accept-Language request header field.
814 "foreign-language",
Yixin Wang983875152017-11-21 20:30:13815 // User-Agent request header field.
816 "fake agent",
817 // JSON encoded experimental options.
818 "{\"QUIC\":{\"max_time_before_crypto_handshake_seconds\":7,"
819 "\"max_idle_time_before_crypto_handshake_seconds\":11}}",
820 // MockCertVerifier to use for testing purposes.
821 std::unique_ptr<net::CertVerifier>(),
822 // Enable network quality estimator.
823 false,
824 // Enable Public Key Pinning bypass for local trust anchors.
Paul Jensen6a1ea3a2018-08-24 14:46:41825 true,
826 // Optional network thread priority.
827 base::Optional<double>());
Yixin Wang983875152017-11-21 20:30:13828
829 net::URLRequestContextBuilder builder;
830 net::NetLog net_log;
831 config.ConfigureURLRequestContextBuilder(&builder, &net_log);
832 // Set a ProxyConfigService to avoid DCHECK failure when building.
833 builder.set_proxy_config_service(
Lily Houghtonef028852017-12-06 20:52:30834 std::make_unique<net::ProxyConfigServiceFixed>(
Ramin Halavatica8d5252018-03-12 05:33:49835 net::ProxyConfigWithAnnotation::CreateDirect()));
Yixin Wang983875152017-11-21 20:30:13836 std::unique_ptr<net::URLRequestContext> context(builder.Build());
837 const net::HttpNetworkSession::Params* params =
838 context->GetNetworkSessionParams();
839
840 EXPECT_EQ(7, params->quic_max_time_before_crypto_handshake_seconds);
841 EXPECT_EQ(11, params->quic_max_idle_time_before_crypto_handshake_seconds);
842}
843
Yixin Wang1875fdb2017-12-06 02:26:49844TEST(URLURLRequestContextConfigTest, SetQuicConnectionOptions) {
845 base::test::ScopedTaskEnvironment scoped_task_environment_(
846 base::test::ScopedTaskEnvironment::MainThreadType::IO);
847
848 URLRequestContextConfig config(
849 // Enable QUIC.
850 true,
851 // QUIC User Agent ID.
852 "Default QUIC User Agent ID",
853 // Enable SPDY.
854 true,
855 // Enable Brotli.
856 false,
857 // Type of http cache.
858 URLRequestContextConfig::HttpCacheType::DISK,
859 // Max size of http cache in bytes.
860 1024000,
861 // Disable caching for HTTP responses. Other information may be stored in
862 // the cache.
863 false,
864 // Storage path for http cache and cookie storage.
865 "/data/data/org.chromium.net/app_cronet_test/test_storage",
Misha Efimovd4ab38302018-01-30 23:56:42866 // Accept-Language request header field.
867 "foreign-language",
Yixin Wang1875fdb2017-12-06 02:26:49868 // User-Agent request header field.
869 "fake agent",
870 // JSON encoded experimental options.
871 "{\"QUIC\":{\"connection_options\":\"TIME,TBBR,REJ\","
872 "\"client_connection_options\":\"TBBR,1RTT\"}}",
873 // MockCertVerifier to use for testing purposes.
874 std::unique_ptr<net::CertVerifier>(),
875 // Enable network quality estimator.
876 false,
877 // Enable Public Key Pinning bypass for local trust anchors.
Paul Jensen6a1ea3a2018-08-24 14:46:41878 true,
879 // Optional network thread priority.
880 base::Optional<double>());
Yixin Wang1875fdb2017-12-06 02:26:49881
882 net::URLRequestContextBuilder builder;
883 net::NetLog net_log;
884 config.ConfigureURLRequestContextBuilder(&builder, &net_log);
885 // Set a ProxyConfigService to avoid DCHECK failure when building.
886 builder.set_proxy_config_service(
Gyuyoung Kim6afb5082018-01-19 13:35:57887 std::make_unique<net::ProxyConfigServiceFixed>(
Ramin Halavatica8d5252018-03-12 05:33:49888 net::ProxyConfigWithAnnotation::CreateDirect()));
Yixin Wang1875fdb2017-12-06 02:26:49889 std::unique_ptr<net::URLRequestContext> context(builder.Build());
890 const net::HttpNetworkSession::Params* params =
891 context->GetNetworkSessionParams();
892
Ryan Hamilton8d9ee76e2018-05-29 23:52:52893 quic::QuicTagVector connection_options;
894 connection_options.push_back(quic::kTIME);
895 connection_options.push_back(quic::kTBBR);
896 connection_options.push_back(quic::kREJ);
Yixin Wang1875fdb2017-12-06 02:26:49897 EXPECT_EQ(connection_options, params->quic_connection_options);
898
Ryan Hamilton8d9ee76e2018-05-29 23:52:52899 quic::QuicTagVector client_connection_options;
900 client_connection_options.push_back(quic::kTBBR);
901 client_connection_options.push_back(quic::k1RTT);
Yixin Wang1875fdb2017-12-06 02:26:49902 EXPECT_EQ(client_connection_options, params->quic_client_connection_options);
903}
904
Misha Efimovd4ab38302018-01-30 23:56:42905TEST(URLURLRequestContextConfigTest, SetAcceptLanguageAndUserAgent) {
906 base::test::ScopedTaskEnvironment scoped_task_environment_(
907 base::test::ScopedTaskEnvironment::MainThreadType::IO);
908
909 URLRequestContextConfig config(
910 // Enable QUIC.
911 true,
912 // QUIC User Agent ID.
913 "Default QUIC User Agent ID",
914 // Enable SPDY.
915 true,
916 // Enable Brotli.
917 false,
918 // Type of http cache.
919 URLRequestContextConfig::HttpCacheType::DISK,
920 // Max size of http cache in bytes.
921 1024000,
922 // Disable caching for HTTP responses. Other information may be stored in
923 // the cache.
924 false,
925 // Storage path for http cache and cookie storage.
926 "/data/data/org.chromium.net/app_cronet_test/test_storage",
927 // Accept-Language request header field.
928 "foreign-language",
929 // User-Agent request header field.
930 "fake agent",
931 // JSON encoded experimental options.
932 "{}",
933 // MockCertVerifier to use for testing purposes.
934 std::unique_ptr<net::CertVerifier>(),
935 // Enable network quality estimator.
936 false,
937 // Enable Public Key Pinning bypass for local trust anchors.
Paul Jensen6a1ea3a2018-08-24 14:46:41938 true,
939 // Optional network thread priority.
940 base::Optional<double>());
Misha Efimovd4ab38302018-01-30 23:56:42941
942 net::URLRequestContextBuilder builder;
943 net::NetLog net_log;
944 config.ConfigureURLRequestContextBuilder(&builder, &net_log);
945 // Set a ProxyConfigService to avoid DCHECK failure when building.
946 builder.set_proxy_config_service(
947 std::make_unique<net::ProxyConfigServiceFixed>(
Ramin Halavatica8d5252018-03-12 05:33:49948 net::ProxyConfigWithAnnotation::CreateDirect()));
Misha Efimovd4ab38302018-01-30 23:56:42949 std::unique_ptr<net::URLRequestContext> context(builder.Build());
950 EXPECT_EQ("foreign-language",
951 context->http_user_agent_settings()->GetAcceptLanguage());
952 EXPECT_EQ("fake agent", context->http_user_agent_settings()->GetUserAgent());
953}
954
juliatuttle50d9c4b2016-08-23 22:49:19955// See stale_host_resolver_unittest.cc for test of StaleDNS options.
956
xunjielif24ee5f2015-11-23 18:05:26957} // namespace cronet