blob: 3a0dfd508892fc0075f3ce9a5beab7687374b844 [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
mmenke51629db12017-06-28 13:34:129#include "base/test/scoped_task_environment.h"
tfhef3618f2016-01-11 23:07:0810#include "base/values.h"
pauljensen9041eb3c2015-12-09 12:29:0111#include "net/cert/cert_verifier.h"
xunjielif24ee5f2015-11-23 18:05:2612#include "net/http/http_network_session.h"
mikecironef22f9812016-10-04 03:40:1913#include "net/log/net_log.h"
14#include "net/log/net_log_with_source.h"
Lily Houghton582d4622018-01-22 22:43:4015#include "net/proxy_resolution/proxy_config.h"
16#include "net/proxy_resolution/proxy_config_service_fixed.h"
Misha Efimovd4ab38302018-01-30 23:56:4217#include "net/url_request/http_user_agent_settings.h"
xunjielif24ee5f2015-11-23 18:05:2618#include "net/url_request/url_request_context.h"
19#include "net/url_request/url_request_context_builder.h"
20#include "testing/gtest/include/gtest/gtest.h"
21
22namespace cronet {
23
mmenke51629db12017-06-28 13:34:1224TEST(URLRequestContextConfigTest, TestExperimentalOptionParsing) {
25 base::test::ScopedTaskEnvironment scoped_task_environment_(
26 base::test::ScopedTaskEnvironment::MainThreadType::IO);
27
pauljensen9041eb3c2015-12-09 12:29:0128 URLRequestContextConfig config(
29 // Enable QUIC.
30 true,
mefc5da5712016-02-09 20:14:2331 // QUIC User Agent ID.
32 "Default QUIC User Agent ID",
pauljensen9041eb3c2015-12-09 12:29:0133 // Enable SPDY.
34 true,
xunjieli186d2bf2017-04-18 13:45:4735 // Enable Brotli.
36 false,
pauljensen9041eb3c2015-12-09 12:29:0137 // Type of http cache.
38 URLRequestContextConfig::HttpCacheType::DISK,
39 // Max size of http cache in bytes.
40 1024000,
41 // Disable caching for HTTP responses. Other information may be stored in
42 // the cache.
43 false,
44 // Storage path for http cache and cookie storage.
45 "/data/data/org.chromium.net/app_cronet_test/test_storage",
Misha Efimovd4ab38302018-01-30 23:56:4246 // Accept-Language request header field.
47 "foreign-language",
pauljensen9041eb3c2015-12-09 12:29:0148 // User-Agent request header field.
49 "fake agent",
50 // JSON encoded experimental options.
rtenneti6971c172016-01-15 20:12:1051 "{\"QUIC\":{\"max_server_configs_stored_in_properties\":2,"
mefc5da5712016-02-09 20:14:2352 "\"user_agent_id\":\"Custom QUIC UAID\","
rtenneti64e809d02015-12-11 00:26:2053 "\"idle_connection_timeout_seconds\":300,"
Jana Iyengar903dec22017-11-28 00:44:2354 "\"close_sessions_on_ip_change\":true,"
rtennetid073dd22016-08-04 01:58:3355 "\"race_cert_verification\":true,"
pauljensene92c4092015-12-09 19:13:4856 "\"connection_options\":\"TIME,TBBR,REJ\"},"
mgershaf2c12c2016-08-22 16:33:5457 "\"AsyncDNS\":{\"enable\":true},"
Julia Tuttle9715d1642018-01-29 17:02:2658 "\"NetworkErrorLogging\":{\"enable\":true},"
xunjielid67295e2017-03-16 21:05:4159 "\"UnknownOption\":{\"foo\":true},"
mgershaf2c12c2016-08-22 16:33:5460 "\"HostResolverRules\":{\"host_resolver_rules\":"
mgershb3fe8082017-02-28 20:09:2061 "\"MAP * 127.0.0.1\"},"
62 // See http://crbug.com/696569.
mgershaf9a9232017-04-13 20:19:0363 "\"disable_ipv6_on_wifi\":true}",
pauljensen9041eb3c2015-12-09 12:29:0164 // MockCertVerifier to use for testing purposes.
tbansal7018e2a2016-06-25 00:40:3965 std::unique_ptr<net::CertVerifier>(),
66 // Enable network quality estimator.
kapishnikov385aa422016-07-01 20:53:0267 false,
68 // Enable Public Key Pinning bypass for local trust anchors.
rtenneti121f9fa2016-07-07 23:49:2869 true,
70 // Certificate verifier cache data.
71 "");
xunjielif24ee5f2015-11-23 18:05:2672
xunjielif24ee5f2015-11-23 18:05:2673 net::URLRequestContextBuilder builder;
pauljensene92c4092015-12-09 19:13:4874 net::NetLog net_log;
David Benjamindc2f4b02017-07-27 23:59:0275 config.ConfigureURLRequestContextBuilder(&builder, &net_log);
xunjielid67295e2017-03-16 21:05:4176 EXPECT_FALSE(config.effective_experimental_options->HasKey("UnknownOption"));
xunjielif24ee5f2015-11-23 18:05:2677 // Set a ProxyConfigService to avoid DCHECK failure when building.
ricea85ec57952016-08-31 09:34:1078 builder.set_proxy_config_service(
Lily Houghtonef028852017-12-06 20:52:3079 std::make_unique<net::ProxyConfigServiceFixed>(
ricea85ec57952016-08-31 09:34:1080 net::ProxyConfig::CreateDirect()));
dchengfe3745e6242016-04-21 23:49:5881 std::unique_ptr<net::URLRequestContext> context(builder.Build());
xunjielif24ee5f2015-11-23 18:05:2682 const net::HttpNetworkSession::Params* params =
83 context->GetNetworkSessionParams();
84 // Check Quic Connection options.
85 net::QuicTagVector quic_connection_options;
86 quic_connection_options.push_back(net::kTIME);
87 quic_connection_options.push_back(net::kTBBR);
88 quic_connection_options.push_back(net::kREJ);
89 EXPECT_EQ(quic_connection_options, params->quic_connection_options);
90
mefc5da5712016-02-09 20:14:2391 // Check Custom QUIC User Agent Id.
92 EXPECT_EQ("Custom QUIC UAID", params->quic_user_agent_id);
93
rtenneti6971c172016-01-15 20:12:1094 // Check max_server_configs_stored_in_properties.
95 EXPECT_EQ(2u, params->quic_max_server_configs_stored_in_properties);
xunjielif24ee5f2015-11-23 18:05:2696
rtenneti64e809d02015-12-11 00:26:2097 // Check idle_connection_timeout_seconds.
98 EXPECT_EQ(300, params->quic_idle_connection_timeout_seconds);
99
Jana Iyengar903dec22017-11-28 00:44:23100 EXPECT_TRUE(params->quic_close_sessions_on_ip_change);
Zhongyi Shi8ff38c12018-02-22 00:02:30101 EXPECT_FALSE(params->quic_allow_server_migration);
jric69a88422016-02-12 19:48:36102 EXPECT_FALSE(params->quic_migrate_sessions_on_network_change);
Zhongyi Shi64795622017-11-20 02:21:49103 EXPECT_FALSE(params->quic_migrate_sessions_on_network_change_v2);
Zhongyi Shif4683a32017-12-01 00:03:28104 EXPECT_FALSE(params->quic_migrate_sessions_early_v2);
jrid26566952016-02-04 21:06:42105
rtennetid073dd22016-08-04 01:58:33106 // Check race_cert_verification.
107 EXPECT_TRUE(params->quic_race_cert_verification);
108
Misha Efimov63957912017-12-06 07:13:26109#if defined(ENABLE_BUILT_IN_DNS)
110 // Check AsyncDNS resolver is enabled (not supported on iOS).
tfhef3618f2016-01-11 23:07:08111 EXPECT_TRUE(context->host_resolver()->GetDnsConfigAsValue());
Misha Efimov63957912017-12-06 07:13:26112#endif // defined(ENABLE_BUILT_IN_DNS)
mgershaf2c12c2016-08-22 16:33:54113
Julia Tuttle9715d1642018-01-29 17:02:26114#if BUILDFLAG(ENABLE_REPORTING)
115 // Check Reporting and Network Error Logging are enabled (can be disabled at
116 // build time).
117 EXPECT_TRUE(context->reporting_service());
Julia Tuttlecba7d222018-02-23 19:37:27118 EXPECT_TRUE(context->network_error_logging_service());
Julia Tuttle9715d1642018-01-29 17:02:26119#endif // BUILDFLAG(ENABLE_REPORTING)
120
mgershaf9a9232017-04-13 20:19:03121 // Check IPv6 is disabled when on wifi.
122 EXPECT_TRUE(context->host_resolver()->GetNoIPv6OnWifi());
mgershb3fe8082017-02-28 20:09:20123
mgershaf2c12c2016-08-22 16:33:54124 net::HostResolver::RequestInfo info(net::HostPortPair("abcde", 80));
125 net::AddressList addresses;
126 EXPECT_EQ(net::OK, context->host_resolver()->ResolveFromCache(
tfarina428341112016-09-22 13:38:20127 info, &addresses, net::NetLogWithSource()));
xunjielif24ee5f2015-11-23 18:05:26128}
129
Zhongyi Shi8ff38c12018-02-22 00:02:30130TEST(URLRequestContextConfigTest, SetQuicServerMigrationOptions) {
131 base::test::ScopedTaskEnvironment scoped_task_environment_(
132 base::test::ScopedTaskEnvironment::MainThreadType::IO);
133
134 URLRequestContextConfig config(
135 // Enable QUIC.
136 true,
137 // QUIC User Agent ID.
138 "Default QUIC User Agent ID",
139 // Enable SPDY.
140 true,
141 // Enable Brotli.
142 false,
143 // Type of http cache.
144 URLRequestContextConfig::HttpCacheType::DISK,
145 // Max size of http cache in bytes.
146 1024000,
147 // Disable caching for HTTP responses. Other information may be stored in
148 // the cache.
149 false,
150 // Storage path for http cache and cookie storage.
151 "/data/data/org.chromium.net/app_cronet_test/test_storage",
152 // Accept-Language request header field.
153 "foreign-language",
154 // User-Agent request header field.
155 "fake agent",
156 // JSON encoded experimental options.
157 "{\"QUIC\":{\"allow_server_migration\":true}}",
158 // MockCertVerifier to use for testing purposes.
159 std::unique_ptr<net::CertVerifier>(),
160 // Enable network quality estimator.
161 false,
162 // Enable Public Key Pinning bypass for local trust anchors.
163 true,
164 // Certificate verifier cache data.
165 "");
166
167 net::URLRequestContextBuilder builder;
168 net::NetLog net_log;
169 config.ConfigureURLRequestContextBuilder(&builder, &net_log);
170 // Set a ProxyConfigService to avoid DCHECK failure when building.
171 builder.set_proxy_config_service(
172 std::make_unique<net::ProxyConfigServiceFixed>(
173 net::ProxyConfig::CreateDirect()));
174 std::unique_ptr<net::URLRequestContext> context(builder.Build());
175 const net::HttpNetworkSession::Params* params =
176 context->GetNetworkSessionParams();
177
178 EXPECT_FALSE(params->quic_close_sessions_on_ip_change);
179 EXPECT_TRUE(params->quic_allow_server_migration);
180}
181
mmenke51629db12017-06-28 13:34:12182TEST(URLRequestContextConfigTest, SetQuicConnectionMigrationOptions) {
183 base::test::ScopedTaskEnvironment scoped_task_environment_(
184 base::test::ScopedTaskEnvironment::MainThreadType::IO);
185
jric69a88422016-02-12 19:48:36186 URLRequestContextConfig config(
187 // Enable QUIC.
188 true,
189 // QUIC User Agent ID.
190 "Default QUIC User Agent ID",
191 // Enable SPDY.
192 true,
xunjieli186d2bf2017-04-18 13:45:47193 // Enable Brotli.
194 false,
jric69a88422016-02-12 19:48:36195 // Type of http cache.
196 URLRequestContextConfig::HttpCacheType::DISK,
197 // Max size of http cache in bytes.
198 1024000,
199 // Disable caching for HTTP responses. Other information may be stored in
200 // the cache.
201 false,
202 // Storage path for http cache and cookie storage.
203 "/data/data/org.chromium.net/app_cronet_test/test_storage",
Misha Efimovd4ab38302018-01-30 23:56:42204 // Accept-Language request header field.
205 "foreign-language",
jric69a88422016-02-12 19:48:36206 // User-Agent request header field.
207 "fake agent",
208 // JSON encoded experimental options.
jrie68df0e2016-02-12 22:01:42209 "{\"QUIC\":{\"migrate_sessions_on_network_change\":true,"
210 "\"migrate_sessions_early\":true}}",
jric69a88422016-02-12 19:48:36211 // MockCertVerifier to use for testing purposes.
tbansal7018e2a2016-06-25 00:40:39212 std::unique_ptr<net::CertVerifier>(),
213 // Enable network quality estimator.
kapishnikov385aa422016-07-01 20:53:02214 false,
215 // Enable Public Key Pinning bypass for local trust anchors.
rtenneti121f9fa2016-07-07 23:49:28216 true,
217 // Certificate verifier cache data.
218 "");
jric69a88422016-02-12 19:48:36219
220 net::URLRequestContextBuilder builder;
221 net::NetLog net_log;
David Benjamindc2f4b02017-07-27 23:59:02222 config.ConfigureURLRequestContextBuilder(&builder, &net_log);
jric69a88422016-02-12 19:48:36223 // Set a ProxyConfigService to avoid DCHECK failure when building.
ricea85ec57952016-08-31 09:34:10224 builder.set_proxy_config_service(
Lily Houghtonef028852017-12-06 20:52:30225 std::make_unique<net::ProxyConfigServiceFixed>(
ricea85ec57952016-08-31 09:34:10226 net::ProxyConfig::CreateDirect()));
dchengfe3745e6242016-04-21 23:49:58227 std::unique_ptr<net::URLRequestContext> context(builder.Build());
jric69a88422016-02-12 19:48:36228 const net::HttpNetworkSession::Params* params =
229 context->GetNetworkSessionParams();
230
Jana Iyengar903dec22017-11-28 00:44:23231 EXPECT_FALSE(params->quic_close_sessions_on_ip_change);
jric69a88422016-02-12 19:48:36232 EXPECT_TRUE(params->quic_migrate_sessions_on_network_change);
jrie68df0e2016-02-12 22:01:42233 EXPECT_TRUE(params->quic_migrate_sessions_early);
jric69a88422016-02-12 19:48:36234}
235
Yixin Wang10f477ed2017-11-21 04:20:20236TEST(URLRequestContextConfigTest, SetQuicConnectionMigrationV2Options) {
Zhongyi Shi64795622017-11-20 02:21:49237 base::test::ScopedTaskEnvironment scoped_task_environment_(
238 base::test::ScopedTaskEnvironment::MainThreadType::IO);
239
240 URLRequestContextConfig config(
241 // Enable QUIC.
242 true,
243 // QUIC User Agent ID.
244 "Default QUIC User Agent ID",
245 // Enable SPDY.
246 true,
247 // Enable Brotli.
248 false,
249 // Type of http cache.
250 URLRequestContextConfig::HttpCacheType::DISK,
251 // Max size of http cache in bytes.
252 1024000,
253 // Disable caching for HTTP responses. Other information may be stored in
254 // the cache.
255 false,
256 // Storage path for http cache and cookie storage.
257 "/data/data/org.chromium.net/app_cronet_test/test_storage",
Misha Efimovd4ab38302018-01-30 23:56:42258 // Accept-Language request header field.
259 "foreign-language",
Zhongyi Shi64795622017-11-20 02:21:49260 // User-Agent request header field.
261 "fake agent",
262 // JSON encoded experimental options.
Zhongyi Shif4683a32017-12-01 00:03:28263 "{\"QUIC\":{\"migrate_sessions_on_network_change_v2\":true,"
Zhongyi Shi73f23ca872017-12-13 18:37:13264 "\"migrate_sessions_early_v2\":true,"
Zhongyi Shi8b1e43f2017-12-13 20:46:30265 "\"max_time_on_non_default_network_seconds\":10,"
266 "\"max_migrations_to_non_default_network_on_path_degrading\":4}}",
Zhongyi Shi64795622017-11-20 02:21:49267 // MockCertVerifier to use for testing purposes.
268 std::unique_ptr<net::CertVerifier>(),
269 // Enable network quality estimator.
270 false,
271 // Enable Public Key Pinning bypass for local trust anchors.
272 true,
273 // Certificate verifier cache data.
274 "");
275
276 net::URLRequestContextBuilder builder;
277 net::NetLog net_log;
278 config.ConfigureURLRequestContextBuilder(&builder, &net_log);
279 // Set a ProxyConfigService to avoid DCHECK failure when building.
280 builder.set_proxy_config_service(
Lily Houghtonef028852017-12-06 20:52:30281 std::make_unique<net::ProxyConfigServiceFixed>(
Zhongyi Shi64795622017-11-20 02:21:49282 net::ProxyConfig::CreateDirect()));
283 std::unique_ptr<net::URLRequestContext> context(builder.Build());
284 const net::HttpNetworkSession::Params* params =
285 context->GetNetworkSessionParams();
286
287 EXPECT_TRUE(params->quic_migrate_sessions_on_network_change_v2);
Zhongyi Shif4683a32017-12-01 00:03:28288 EXPECT_TRUE(params->quic_migrate_sessions_early_v2);
Zhongyi Shi73f23ca872017-12-13 18:37:13289 EXPECT_EQ(base::TimeDelta::FromSeconds(10),
290 params->quic_max_time_on_non_default_network);
Zhongyi Shi8b1e43f2017-12-13 20:46:30291 EXPECT_EQ(
292 4, params->quic_max_migrations_to_non_default_network_on_path_degrading);
Zhongyi Shi64795622017-11-20 02:21:49293}
294
Yixin Wang10f477ed2017-11-21 04:20:20295TEST(URLRequestContextConfigTest, SetQuicHostWhitelist) {
296 base::test::ScopedTaskEnvironment scoped_task_environment_(
297 base::test::ScopedTaskEnvironment::MainThreadType::IO);
298
299 URLRequestContextConfig config(
300 // Enable QUIC.
301 true,
302 // QUIC User Agent ID.
303 "Default QUIC User Agent ID",
304 // Enable SPDY.
305 true,
306 // Enable Brotli.
307 false,
308 // Type of http cache.
309 URLRequestContextConfig::HttpCacheType::DISK,
310 // Max size of http cache in bytes.
311 1024000,
312 // Disable caching for HTTP responses. Other information may be stored in
313 // the cache.
314 false,
315 // Storage path for http cache and cookie storage.
316 "/data/data/org.chromium.net/app_cronet_test/test_storage",
Misha Efimovd4ab38302018-01-30 23:56:42317 // Accept-Language request header field.
318 "foreign-language",
Yixin Wang10f477ed2017-11-21 04:20:20319 // User-Agent request header field.
320 "fake agent",
321 // JSON encoded experimental options.
322 "{\"QUIC\":{\"host_whitelist\":\"www.example.com,www.example.org\"}}",
323 // MockCertVerifier to use for testing purposes.
324 std::unique_ptr<net::CertVerifier>(),
325 // Enable network quality estimator.
326 false,
327 // Enable Public Key Pinning bypass for local trust anchors.
328 true,
329 // Certificate verifier cache data.
330 "");
331
332 net::URLRequestContextBuilder builder;
333 net::NetLog net_log;
334 config.ConfigureURLRequestContextBuilder(&builder, &net_log);
335 // Set a ProxyConfigService to avoid DCHECK failure when building.
336 builder.set_proxy_config_service(
Lily Houghtonef028852017-12-06 20:52:30337 std::make_unique<net::ProxyConfigServiceFixed>(
Yixin Wang10f477ed2017-11-21 04:20:20338 net::ProxyConfig::CreateDirect()));
339 std::unique_ptr<net::URLRequestContext> context(builder.Build());
340 const net::HttpNetworkSession::Params* params =
341 context->GetNetworkSessionParams();
342
343 EXPECT_TRUE(
344 base::ContainsKey(params->quic_host_whitelist, "www.example.com"));
345 EXPECT_TRUE(
346 base::ContainsKey(params->quic_host_whitelist, "www.example.org"));
347}
348
Yixin Wang983875152017-11-21 20:30:13349TEST(URLRequestContextConfigTest, SetQuicMaxTimeBeforeCryptoHandshake) {
350 base::test::ScopedTaskEnvironment scoped_task_environment_(
351 base::test::ScopedTaskEnvironment::MainThreadType::IO);
352
353 URLRequestContextConfig config(
354 // Enable QUIC.
355 true,
356 // QUIC User Agent ID.
357 "Default QUIC User Agent ID",
358 // Enable SPDY.
359 true,
360 // Enable Brotli.
361 false,
362 // Type of http cache.
363 URLRequestContextConfig::HttpCacheType::DISK,
364 // Max size of http cache in bytes.
365 1024000,
366 // Disable caching for HTTP responses. Other information may be stored in
367 // the cache.
368 false,
369 // Storage path for http cache and cookie storage.
370 "/data/data/org.chromium.net/app_cronet_test/test_storage",
Misha Efimovd4ab38302018-01-30 23:56:42371 // Accept-Language request header field.
372 "foreign-language",
Yixin Wang983875152017-11-21 20:30:13373 // User-Agent request header field.
374 "fake agent",
375 // JSON encoded experimental options.
376 "{\"QUIC\":{\"max_time_before_crypto_handshake_seconds\":7,"
377 "\"max_idle_time_before_crypto_handshake_seconds\":11}}",
378 // MockCertVerifier to use for testing purposes.
379 std::unique_ptr<net::CertVerifier>(),
380 // Enable network quality estimator.
381 false,
382 // Enable Public Key Pinning bypass for local trust anchors.
383 true,
384 // Certificate verifier cache data.
385 "");
386
387 net::URLRequestContextBuilder builder;
388 net::NetLog net_log;
389 config.ConfigureURLRequestContextBuilder(&builder, &net_log);
390 // Set a ProxyConfigService to avoid DCHECK failure when building.
391 builder.set_proxy_config_service(
Lily Houghtonef028852017-12-06 20:52:30392 std::make_unique<net::ProxyConfigServiceFixed>(
Yixin Wang983875152017-11-21 20:30:13393 net::ProxyConfig::CreateDirect()));
394 std::unique_ptr<net::URLRequestContext> context(builder.Build());
395 const net::HttpNetworkSession::Params* params =
396 context->GetNetworkSessionParams();
397
398 EXPECT_EQ(7, params->quic_max_time_before_crypto_handshake_seconds);
399 EXPECT_EQ(11, params->quic_max_idle_time_before_crypto_handshake_seconds);
400}
401
Yixin Wang1875fdb2017-12-06 02:26:49402TEST(URLURLRequestContextConfigTest, SetQuicConnectionOptions) {
403 base::test::ScopedTaskEnvironment scoped_task_environment_(
404 base::test::ScopedTaskEnvironment::MainThreadType::IO);
405
406 URLRequestContextConfig config(
407 // Enable QUIC.
408 true,
409 // QUIC User Agent ID.
410 "Default QUIC User Agent ID",
411 // Enable SPDY.
412 true,
413 // Enable Brotli.
414 false,
415 // Type of http cache.
416 URLRequestContextConfig::HttpCacheType::DISK,
417 // Max size of http cache in bytes.
418 1024000,
419 // Disable caching for HTTP responses. Other information may be stored in
420 // the cache.
421 false,
422 // Storage path for http cache and cookie storage.
423 "/data/data/org.chromium.net/app_cronet_test/test_storage",
Misha Efimovd4ab38302018-01-30 23:56:42424 // Accept-Language request header field.
425 "foreign-language",
Yixin Wang1875fdb2017-12-06 02:26:49426 // User-Agent request header field.
427 "fake agent",
428 // JSON encoded experimental options.
429 "{\"QUIC\":{\"connection_options\":\"TIME,TBBR,REJ\","
430 "\"client_connection_options\":\"TBBR,1RTT\"}}",
431 // MockCertVerifier to use for testing purposes.
432 std::unique_ptr<net::CertVerifier>(),
433 // Enable network quality estimator.
434 false,
435 // Enable Public Key Pinning bypass for local trust anchors.
436 true,
437 // Certificate verifier cache data.
438 "");
439
440 net::URLRequestContextBuilder builder;
441 net::NetLog net_log;
442 config.ConfigureURLRequestContextBuilder(&builder, &net_log);
443 // Set a ProxyConfigService to avoid DCHECK failure when building.
444 builder.set_proxy_config_service(
Gyuyoung Kim6afb5082018-01-19 13:35:57445 std::make_unique<net::ProxyConfigServiceFixed>(
Yixin Wang1875fdb2017-12-06 02:26:49446 net::ProxyConfig::CreateDirect()));
447 std::unique_ptr<net::URLRequestContext> context(builder.Build());
448 const net::HttpNetworkSession::Params* params =
449 context->GetNetworkSessionParams();
450
451 net::QuicTagVector connection_options;
452 connection_options.push_back(net::kTIME);
453 connection_options.push_back(net::kTBBR);
454 connection_options.push_back(net::kREJ);
455 EXPECT_EQ(connection_options, params->quic_connection_options);
456
457 net::QuicTagVector client_connection_options;
458 client_connection_options.push_back(net::kTBBR);
459 client_connection_options.push_back(net::k1RTT);
460 EXPECT_EQ(client_connection_options, params->quic_client_connection_options);
461}
462
Misha Efimovd4ab38302018-01-30 23:56:42463TEST(URLURLRequestContextConfigTest, SetAcceptLanguageAndUserAgent) {
464 base::test::ScopedTaskEnvironment scoped_task_environment_(
465 base::test::ScopedTaskEnvironment::MainThreadType::IO);
466
467 URLRequestContextConfig config(
468 // Enable QUIC.
469 true,
470 // QUIC User Agent ID.
471 "Default QUIC User Agent ID",
472 // Enable SPDY.
473 true,
474 // Enable Brotli.
475 false,
476 // Type of http cache.
477 URLRequestContextConfig::HttpCacheType::DISK,
478 // Max size of http cache in bytes.
479 1024000,
480 // Disable caching for HTTP responses. Other information may be stored in
481 // the cache.
482 false,
483 // Storage path for http cache and cookie storage.
484 "/data/data/org.chromium.net/app_cronet_test/test_storage",
485 // Accept-Language request header field.
486 "foreign-language",
487 // User-Agent request header field.
488 "fake agent",
489 // JSON encoded experimental options.
490 "{}",
491 // MockCertVerifier to use for testing purposes.
492 std::unique_ptr<net::CertVerifier>(),
493 // Enable network quality estimator.
494 false,
495 // Enable Public Key Pinning bypass for local trust anchors.
496 true,
497 // Certificate verifier cache data.
498 "");
499
500 net::URLRequestContextBuilder builder;
501 net::NetLog net_log;
502 config.ConfigureURLRequestContextBuilder(&builder, &net_log);
503 // Set a ProxyConfigService to avoid DCHECK failure when building.
504 builder.set_proxy_config_service(
505 std::make_unique<net::ProxyConfigServiceFixed>(
506 net::ProxyConfig::CreateDirect()));
507 std::unique_ptr<net::URLRequestContext> context(builder.Build());
508 EXPECT_EQ("foreign-language",
509 context->http_user_agent_settings()->GetAcceptLanguage());
510 EXPECT_EQ("fake agent", context->http_user_agent_settings()->GetUserAgent());
511}
512
juliatuttle50d9c4b2016-08-23 22:49:19513// See stale_host_resolver_unittest.cc for test of StaleDNS options.
514
xunjielif24ee5f2015-11-23 18:05:26515} // namespace cronet