blob: fc4cf9485b9659b1e6c8b8bd09f2676e8a4bc6e6 [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 Shie01f2db2019-02-22 19:53:23649 "\"retransmittable_on_wire_timeout_milliseconds\":1000,"
Zhongyi Shibc85e3e2019-02-12 19:34:42650 "\"idle_session_migration_period_seconds\":15,"
Zhongyi Shi8b1e43f2017-12-13 20:46:30651 "\"max_time_on_non_default_network_seconds\":10,"
Zhongyi Shiee760762018-08-01 00:54:29652 "\"max_migrations_to_non_default_network_on_write_error\":3,"
Zhongyi Shi8b1e43f2017-12-13 20:46:30653 "\"max_migrations_to_non_default_network_on_path_degrading\":4}}",
Zhongyi Shi64795622017-11-20 02:21:49654 // MockCertVerifier to use for testing purposes.
655 std::unique_ptr<net::CertVerifier>(),
656 // Enable network quality estimator.
657 false,
658 // Enable Public Key Pinning bypass for local trust anchors.
Paul Jensen6a1ea3a2018-08-24 14:46:41659 true,
660 // Optional network thread priority.
661 base::Optional<double>());
Zhongyi Shi64795622017-11-20 02:21:49662
663 net::URLRequestContextBuilder builder;
664 net::NetLog net_log;
665 config.ConfigureURLRequestContextBuilder(&builder, &net_log);
666 // Set a ProxyConfigService to avoid DCHECK failure when building.
667 builder.set_proxy_config_service(
Lily Houghtonef028852017-12-06 20:52:30668 std::make_unique<net::ProxyConfigServiceFixed>(
Ramin Halavatica8d5252018-03-12 05:33:49669 net::ProxyConfigWithAnnotation::CreateDirect()));
Zhongyi Shi64795622017-11-20 02:21:49670 std::unique_ptr<net::URLRequestContext> context(builder.Build());
671 const net::HttpNetworkSession::Params* params =
672 context->GetNetworkSessionParams();
673
674 EXPECT_TRUE(params->quic_migrate_sessions_on_network_change_v2);
Zhongyi Shif4683a32017-12-01 00:03:28675 EXPECT_TRUE(params->quic_migrate_sessions_early_v2);
Zhongyi Shiff359581bc2018-09-26 18:11:48676 EXPECT_TRUE(params->quic_retry_on_alternate_network_before_handshake);
Zhongyi Shie01f2db2019-02-22 19:53:23677 EXPECT_EQ(1000, params->quic_retransmittable_on_wire_timeout_milliseconds);
Zhongyi Shibc85e3e2019-02-12 19:34:42678 EXPECT_EQ(base::TimeDelta::FromSeconds(15),
679 params->quic_idle_session_migration_period);
Zhongyi Shi73f23ca872017-12-13 18:37:13680 EXPECT_EQ(base::TimeDelta::FromSeconds(10),
681 params->quic_max_time_on_non_default_network);
Zhongyi Shiee760762018-08-01 00:54:29682 EXPECT_EQ(3,
683 params->quic_max_migrations_to_non_default_network_on_write_error);
Zhongyi Shi8b1e43f2017-12-13 20:46:30684 EXPECT_EQ(
685 4, params->quic_max_migrations_to_non_default_network_on_path_degrading);
Zhongyi Shi64795622017-11-20 02:21:49686}
687
Renjie94b90712018-10-18 21:03:19688TEST(URLRequestContextConfigTest, SetQuicStaleDNSracing) {
689 base::test::ScopedTaskEnvironment scoped_task_environment_(
690 base::test::ScopedTaskEnvironment::MainThreadType::IO);
691
692 URLRequestContextConfig config(
693 // Enable QUIC.
694 true,
695 // QUIC User Agent ID.
696 "Default QUIC User Agent ID",
697 // Enable SPDY.
698 true,
699 // Enable Brotli.
700 false,
701 // Type of http cache.
702 URLRequestContextConfig::HttpCacheType::DISK,
703 // Max size of http cache in bytes.
704 1024000,
705 // Disable caching for HTTP responses. Other information may be stored in
706 // the cache.
707 false,
708 // Storage path for http cache and cookie storage.
709 "/data/data/org.chromium.net/app_cronet_test/test_storage",
710 // Accept-Language request header field.
711 "foreign-language",
712 // User-Agent request header field.
713 "fake agent",
714 // JSON encoded experimental options.
715 "{\"QUIC\":{\"race_stale_dns_on_connection\":true}}",
716 // MockCertVerifier to use for testing purposes.
717 std::unique_ptr<net::CertVerifier>(),
718 // Enable network quality estimator.
719 false,
720 // Enable Public Key Pinning bypass for local trust anchors.
721 true,
722 // Optional network thread priority.
723 base::Optional<double>());
724
725 net::URLRequestContextBuilder builder;
726 net::NetLog net_log;
727 config.ConfigureURLRequestContextBuilder(&builder, &net_log);
728 // Set a ProxyConfigService to avoid DCHECK failure when building.
729 builder.set_proxy_config_service(
730 std::make_unique<net::ProxyConfigServiceFixed>(
731 net::ProxyConfigWithAnnotation::CreateDirect()));
732 std::unique_ptr<net::URLRequestContext> context(builder.Build());
733 const net::HttpNetworkSession::Params* params =
734 context->GetNetworkSessionParams();
735
736 EXPECT_TRUE(params->quic_race_stale_dns_on_connection);
737}
738
Yixin Wang10f477ed2017-11-21 04:20:20739TEST(URLRequestContextConfigTest, SetQuicHostWhitelist) {
740 base::test::ScopedTaskEnvironment scoped_task_environment_(
741 base::test::ScopedTaskEnvironment::MainThreadType::IO);
742
743 URLRequestContextConfig config(
744 // Enable QUIC.
745 true,
746 // QUIC User Agent ID.
747 "Default QUIC User Agent ID",
748 // Enable SPDY.
749 true,
750 // Enable Brotli.
751 false,
752 // Type of http cache.
753 URLRequestContextConfig::HttpCacheType::DISK,
754 // Max size of http cache in bytes.
755 1024000,
756 // Disable caching for HTTP responses. Other information may be stored in
757 // the cache.
758 false,
759 // Storage path for http cache and cookie storage.
760 "/data/data/org.chromium.net/app_cronet_test/test_storage",
Misha Efimovd4ab38302018-01-30 23:56:42761 // Accept-Language request header field.
762 "foreign-language",
Yixin Wang10f477ed2017-11-21 04:20:20763 // User-Agent request header field.
764 "fake agent",
765 // JSON encoded experimental options.
766 "{\"QUIC\":{\"host_whitelist\":\"www.example.com,www.example.org\"}}",
767 // MockCertVerifier to use for testing purposes.
768 std::unique_ptr<net::CertVerifier>(),
769 // Enable network quality estimator.
770 false,
771 // Enable Public Key Pinning bypass for local trust anchors.
Paul Jensen6a1ea3a2018-08-24 14:46:41772 true,
773 // Optional network thread priority.
774 base::Optional<double>());
Yixin Wang10f477ed2017-11-21 04:20:20775
776 net::URLRequestContextBuilder builder;
777 net::NetLog net_log;
778 config.ConfigureURLRequestContextBuilder(&builder, &net_log);
779 // Set a ProxyConfigService to avoid DCHECK failure when building.
780 builder.set_proxy_config_service(
Lily Houghtonef028852017-12-06 20:52:30781 std::make_unique<net::ProxyConfigServiceFixed>(
Ramin Halavatica8d5252018-03-12 05:33:49782 net::ProxyConfigWithAnnotation::CreateDirect()));
Yixin Wang10f477ed2017-11-21 04:20:20783 std::unique_ptr<net::URLRequestContext> context(builder.Build());
784 const net::HttpNetworkSession::Params* params =
785 context->GetNetworkSessionParams();
786
787 EXPECT_TRUE(
788 base::ContainsKey(params->quic_host_whitelist, "www.example.com"));
789 EXPECT_TRUE(
790 base::ContainsKey(params->quic_host_whitelist, "www.example.org"));
791}
792
Yixin Wang983875152017-11-21 20:30:13793TEST(URLRequestContextConfigTest, SetQuicMaxTimeBeforeCryptoHandshake) {
794 base::test::ScopedTaskEnvironment scoped_task_environment_(
795 base::test::ScopedTaskEnvironment::MainThreadType::IO);
796
797 URLRequestContextConfig config(
798 // Enable QUIC.
799 true,
800 // QUIC User Agent ID.
801 "Default QUIC User Agent ID",
802 // Enable SPDY.
803 true,
804 // Enable Brotli.
805 false,
806 // Type of http cache.
807 URLRequestContextConfig::HttpCacheType::DISK,
808 // Max size of http cache in bytes.
809 1024000,
810 // Disable caching for HTTP responses. Other information may be stored in
811 // the cache.
812 false,
813 // Storage path for http cache and cookie storage.
814 "/data/data/org.chromium.net/app_cronet_test/test_storage",
Misha Efimovd4ab38302018-01-30 23:56:42815 // Accept-Language request header field.
816 "foreign-language",
Yixin Wang983875152017-11-21 20:30:13817 // User-Agent request header field.
818 "fake agent",
819 // JSON encoded experimental options.
820 "{\"QUIC\":{\"max_time_before_crypto_handshake_seconds\":7,"
821 "\"max_idle_time_before_crypto_handshake_seconds\":11}}",
822 // MockCertVerifier to use for testing purposes.
823 std::unique_ptr<net::CertVerifier>(),
824 // Enable network quality estimator.
825 false,
826 // Enable Public Key Pinning bypass for local trust anchors.
Paul Jensen6a1ea3a2018-08-24 14:46:41827 true,
828 // Optional network thread priority.
829 base::Optional<double>());
Yixin Wang983875152017-11-21 20:30:13830
831 net::URLRequestContextBuilder builder;
832 net::NetLog net_log;
833 config.ConfigureURLRequestContextBuilder(&builder, &net_log);
834 // Set a ProxyConfigService to avoid DCHECK failure when building.
835 builder.set_proxy_config_service(
Lily Houghtonef028852017-12-06 20:52:30836 std::make_unique<net::ProxyConfigServiceFixed>(
Ramin Halavatica8d5252018-03-12 05:33:49837 net::ProxyConfigWithAnnotation::CreateDirect()));
Yixin Wang983875152017-11-21 20:30:13838 std::unique_ptr<net::URLRequestContext> context(builder.Build());
839 const net::HttpNetworkSession::Params* params =
840 context->GetNetworkSessionParams();
841
842 EXPECT_EQ(7, params->quic_max_time_before_crypto_handshake_seconds);
843 EXPECT_EQ(11, params->quic_max_idle_time_before_crypto_handshake_seconds);
844}
845
Yixin Wang1875fdb2017-12-06 02:26:49846TEST(URLURLRequestContextConfigTest, SetQuicConnectionOptions) {
847 base::test::ScopedTaskEnvironment scoped_task_environment_(
848 base::test::ScopedTaskEnvironment::MainThreadType::IO);
849
850 URLRequestContextConfig config(
851 // Enable QUIC.
852 true,
853 // QUIC User Agent ID.
854 "Default QUIC User Agent ID",
855 // Enable SPDY.
856 true,
857 // Enable Brotli.
858 false,
859 // Type of http cache.
860 URLRequestContextConfig::HttpCacheType::DISK,
861 // Max size of http cache in bytes.
862 1024000,
863 // Disable caching for HTTP responses. Other information may be stored in
864 // the cache.
865 false,
866 // Storage path for http cache and cookie storage.
867 "/data/data/org.chromium.net/app_cronet_test/test_storage",
Misha Efimovd4ab38302018-01-30 23:56:42868 // Accept-Language request header field.
869 "foreign-language",
Yixin Wang1875fdb2017-12-06 02:26:49870 // User-Agent request header field.
871 "fake agent",
872 // JSON encoded experimental options.
873 "{\"QUIC\":{\"connection_options\":\"TIME,TBBR,REJ\","
874 "\"client_connection_options\":\"TBBR,1RTT\"}}",
875 // MockCertVerifier to use for testing purposes.
876 std::unique_ptr<net::CertVerifier>(),
877 // Enable network quality estimator.
878 false,
879 // Enable Public Key Pinning bypass for local trust anchors.
Paul Jensen6a1ea3a2018-08-24 14:46:41880 true,
881 // Optional network thread priority.
882 base::Optional<double>());
Yixin Wang1875fdb2017-12-06 02:26:49883
884 net::URLRequestContextBuilder builder;
885 net::NetLog net_log;
886 config.ConfigureURLRequestContextBuilder(&builder, &net_log);
887 // Set a ProxyConfigService to avoid DCHECK failure when building.
888 builder.set_proxy_config_service(
Gyuyoung Kim6afb5082018-01-19 13:35:57889 std::make_unique<net::ProxyConfigServiceFixed>(
Ramin Halavatica8d5252018-03-12 05:33:49890 net::ProxyConfigWithAnnotation::CreateDirect()));
Yixin Wang1875fdb2017-12-06 02:26:49891 std::unique_ptr<net::URLRequestContext> context(builder.Build());
892 const net::HttpNetworkSession::Params* params =
893 context->GetNetworkSessionParams();
894
Ryan Hamilton8d9ee76e2018-05-29 23:52:52895 quic::QuicTagVector connection_options;
896 connection_options.push_back(quic::kTIME);
897 connection_options.push_back(quic::kTBBR);
898 connection_options.push_back(quic::kREJ);
Yixin Wang1875fdb2017-12-06 02:26:49899 EXPECT_EQ(connection_options, params->quic_connection_options);
900
Ryan Hamilton8d9ee76e2018-05-29 23:52:52901 quic::QuicTagVector client_connection_options;
902 client_connection_options.push_back(quic::kTBBR);
903 client_connection_options.push_back(quic::k1RTT);
Yixin Wang1875fdb2017-12-06 02:26:49904 EXPECT_EQ(client_connection_options, params->quic_client_connection_options);
905}
906
Misha Efimovd4ab38302018-01-30 23:56:42907TEST(URLURLRequestContextConfigTest, SetAcceptLanguageAndUserAgent) {
908 base::test::ScopedTaskEnvironment scoped_task_environment_(
909 base::test::ScopedTaskEnvironment::MainThreadType::IO);
910
911 URLRequestContextConfig config(
912 // Enable QUIC.
913 true,
914 // QUIC User Agent ID.
915 "Default QUIC User Agent ID",
916 // Enable SPDY.
917 true,
918 // Enable Brotli.
919 false,
920 // Type of http cache.
921 URLRequestContextConfig::HttpCacheType::DISK,
922 // Max size of http cache in bytes.
923 1024000,
924 // Disable caching for HTTP responses. Other information may be stored in
925 // the cache.
926 false,
927 // Storage path for http cache and cookie storage.
928 "/data/data/org.chromium.net/app_cronet_test/test_storage",
929 // Accept-Language request header field.
930 "foreign-language",
931 // User-Agent request header field.
932 "fake agent",
933 // JSON encoded experimental options.
934 "{}",
935 // MockCertVerifier to use for testing purposes.
936 std::unique_ptr<net::CertVerifier>(),
937 // Enable network quality estimator.
938 false,
939 // Enable Public Key Pinning bypass for local trust anchors.
Paul Jensen6a1ea3a2018-08-24 14:46:41940 true,
941 // Optional network thread priority.
942 base::Optional<double>());
Misha Efimovd4ab38302018-01-30 23:56:42943
944 net::URLRequestContextBuilder builder;
945 net::NetLog net_log;
946 config.ConfigureURLRequestContextBuilder(&builder, &net_log);
947 // Set a ProxyConfigService to avoid DCHECK failure when building.
948 builder.set_proxy_config_service(
949 std::make_unique<net::ProxyConfigServiceFixed>(
Ramin Halavatica8d5252018-03-12 05:33:49950 net::ProxyConfigWithAnnotation::CreateDirect()));
Misha Efimovd4ab38302018-01-30 23:56:42951 std::unique_ptr<net::URLRequestContext> context(builder.Build());
952 EXPECT_EQ("foreign-language",
953 context->http_user_agent_settings()->GetAcceptLanguage());
954 EXPECT_EQ("fake agent", context->http_user_agent_settings()->GetUserAgent());
955}
956
juliatuttle50d9c4b2016-08-23 22:49:19957// See stale_host_resolver_unittest.cc for test of StaleDNS options.
958
xunjielif24ee5f2015-11-23 18:05:26959} // namespace cronet