blob: 8f87838fa62723ec7db3baf3ca8bb891d5f5b7e7 [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
mmenke51629db12017-06-28 13:34:127#include "base/test/scoped_task_environment.h"
tfhef3618f2016-01-11 23:07:088#include "base/values.h"
pauljensen9041eb3c2015-12-09 12:29:019#include "net/cert/cert_verifier.h"
xunjielif24ee5f2015-11-23 18:05:2610#include "net/http/http_network_session.h"
mikecironef22f9812016-10-04 03:40:1911#include "net/log/net_log.h"
12#include "net/log/net_log_with_source.h"
xunjielif24ee5f2015-11-23 18:05:2613#include "net/proxy/proxy_config.h"
14#include "net/proxy/proxy_config_service_fixed.h"
15#include "net/url_request/url_request_context.h"
16#include "net/url_request/url_request_context_builder.h"
17#include "testing/gtest/include/gtest/gtest.h"
18
19namespace cronet {
20
mmenke51629db12017-06-28 13:34:1221TEST(URLRequestContextConfigTest, TestExperimentalOptionParsing) {
22 base::test::ScopedTaskEnvironment scoped_task_environment_(
23 base::test::ScopedTaskEnvironment::MainThreadType::IO);
24
pauljensen9041eb3c2015-12-09 12:29:0125 URLRequestContextConfig config(
26 // Enable QUIC.
27 true,
mefc5da5712016-02-09 20:14:2328 // QUIC User Agent ID.
29 "Default QUIC User Agent ID",
pauljensen9041eb3c2015-12-09 12:29:0130 // Enable SPDY.
31 true,
xunjieli186d2bf2017-04-18 13:45:4732 // Enable Brotli.
33 false,
pauljensen9041eb3c2015-12-09 12:29:0134 // Type of http cache.
35 URLRequestContextConfig::HttpCacheType::DISK,
36 // Max size of http cache in bytes.
37 1024000,
38 // Disable caching for HTTP responses. Other information may be stored in
39 // the cache.
40 false,
41 // Storage path for http cache and cookie storage.
42 "/data/data/org.chromium.net/app_cronet_test/test_storage",
43 // User-Agent request header field.
44 "fake agent",
45 // JSON encoded experimental options.
rtenneti6971c172016-01-15 20:12:1046 "{\"QUIC\":{\"max_server_configs_stored_in_properties\":2,"
mefc5da5712016-02-09 20:14:2347 "\"user_agent_id\":\"Custom QUIC UAID\","
rtenneti64e809d02015-12-11 00:26:2048 "\"idle_connection_timeout_seconds\":300,"
Jana Iyengar903dec22017-11-28 00:44:2349 "\"close_sessions_on_ip_change\":true,"
rtennetid073dd22016-08-04 01:58:3350 "\"race_cert_verification\":true,"
pauljensene92c4092015-12-09 19:13:4851 "\"connection_options\":\"TIME,TBBR,REJ\"},"
mgershaf2c12c2016-08-22 16:33:5452 "\"AsyncDNS\":{\"enable\":true},"
xunjielid67295e2017-03-16 21:05:4153 "\"UnknownOption\":{\"foo\":true},"
mgershaf2c12c2016-08-22 16:33:5454 "\"HostResolverRules\":{\"host_resolver_rules\":"
mgershb3fe8082017-02-28 20:09:2055 "\"MAP * 127.0.0.1\"},"
56 // See http://crbug.com/696569.
mgershaf9a9232017-04-13 20:19:0357 "\"disable_ipv6_on_wifi\":true}",
pauljensen9041eb3c2015-12-09 12:29:0158 // MockCertVerifier to use for testing purposes.
tbansal7018e2a2016-06-25 00:40:3959 std::unique_ptr<net::CertVerifier>(),
60 // Enable network quality estimator.
kapishnikov385aa422016-07-01 20:53:0261 false,
62 // Enable Public Key Pinning bypass for local trust anchors.
rtenneti121f9fa2016-07-07 23:49:2863 true,
64 // Certificate verifier cache data.
65 "");
xunjielif24ee5f2015-11-23 18:05:2666
xunjielif24ee5f2015-11-23 18:05:2667 net::URLRequestContextBuilder builder;
pauljensene92c4092015-12-09 19:13:4868 net::NetLog net_log;
David Benjamindc2f4b02017-07-27 23:59:0269 config.ConfigureURLRequestContextBuilder(&builder, &net_log);
xunjielid67295e2017-03-16 21:05:4170 EXPECT_FALSE(config.effective_experimental_options->HasKey("UnknownOption"));
xunjielif24ee5f2015-11-23 18:05:2671 // Set a ProxyConfigService to avoid DCHECK failure when building.
ricea85ec57952016-08-31 09:34:1072 builder.set_proxy_config_service(
Lily Houghtonef028852017-12-06 20:52:3073 std::make_unique<net::ProxyConfigServiceFixed>(
ricea85ec57952016-08-31 09:34:1074 net::ProxyConfig::CreateDirect()));
dchengfe3745e6242016-04-21 23:49:5875 std::unique_ptr<net::URLRequestContext> context(builder.Build());
xunjielif24ee5f2015-11-23 18:05:2676 const net::HttpNetworkSession::Params* params =
77 context->GetNetworkSessionParams();
78 // Check Quic Connection options.
79 net::QuicTagVector quic_connection_options;
80 quic_connection_options.push_back(net::kTIME);
81 quic_connection_options.push_back(net::kTBBR);
82 quic_connection_options.push_back(net::kREJ);
83 EXPECT_EQ(quic_connection_options, params->quic_connection_options);
84
mefc5da5712016-02-09 20:14:2385 // Check Custom QUIC User Agent Id.
86 EXPECT_EQ("Custom QUIC UAID", params->quic_user_agent_id);
87
rtenneti6971c172016-01-15 20:12:1088 // Check max_server_configs_stored_in_properties.
89 EXPECT_EQ(2u, params->quic_max_server_configs_stored_in_properties);
xunjielif24ee5f2015-11-23 18:05:2690
rtenneti64e809d02015-12-11 00:26:2091 // Check idle_connection_timeout_seconds.
92 EXPECT_EQ(300, params->quic_idle_connection_timeout_seconds);
93
Jana Iyengar903dec22017-11-28 00:44:2394 EXPECT_TRUE(params->quic_close_sessions_on_ip_change);
jric69a88422016-02-12 19:48:3695 EXPECT_FALSE(params->quic_migrate_sessions_on_network_change);
Zhongyi Shi64795622017-11-20 02:21:4996 EXPECT_FALSE(params->quic_migrate_sessions_on_network_change_v2);
Zhongyi Shif4683a32017-12-01 00:03:2897 EXPECT_FALSE(params->quic_migrate_sessions_early_v2);
jrid26566952016-02-04 21:06:4298
rtennetid073dd22016-08-04 01:58:3399 // Check race_cert_verification.
100 EXPECT_TRUE(params->quic_race_cert_verification);
101
Misha Efimov63957912017-12-06 07:13:26102#if defined(ENABLE_BUILT_IN_DNS)
103 // Check AsyncDNS resolver is enabled (not supported on iOS).
tfhef3618f2016-01-11 23:07:08104 EXPECT_TRUE(context->host_resolver()->GetDnsConfigAsValue());
Misha Efimov63957912017-12-06 07:13:26105#endif // defined(ENABLE_BUILT_IN_DNS)
mgershaf2c12c2016-08-22 16:33:54106
mgershaf9a9232017-04-13 20:19:03107 // Check IPv6 is disabled when on wifi.
108 EXPECT_TRUE(context->host_resolver()->GetNoIPv6OnWifi());
mgershb3fe8082017-02-28 20:09:20109
mgershaf2c12c2016-08-22 16:33:54110 net::HostResolver::RequestInfo info(net::HostPortPair("abcde", 80));
111 net::AddressList addresses;
112 EXPECT_EQ(net::OK, context->host_resolver()->ResolveFromCache(
tfarina428341112016-09-22 13:38:20113 info, &addresses, net::NetLogWithSource()));
xunjielif24ee5f2015-11-23 18:05:26114}
115
mmenke51629db12017-06-28 13:34:12116TEST(URLRequestContextConfigTest, SetQuicConnectionMigrationOptions) {
117 base::test::ScopedTaskEnvironment scoped_task_environment_(
118 base::test::ScopedTaskEnvironment::MainThreadType::IO);
119
jric69a88422016-02-12 19:48:36120 URLRequestContextConfig config(
121 // Enable QUIC.
122 true,
123 // QUIC User Agent ID.
124 "Default QUIC User Agent ID",
125 // Enable SPDY.
126 true,
xunjieli186d2bf2017-04-18 13:45:47127 // Enable Brotli.
128 false,
jric69a88422016-02-12 19:48:36129 // Type of http cache.
130 URLRequestContextConfig::HttpCacheType::DISK,
131 // Max size of http cache in bytes.
132 1024000,
133 // Disable caching for HTTP responses. Other information may be stored in
134 // the cache.
135 false,
136 // Storage path for http cache and cookie storage.
137 "/data/data/org.chromium.net/app_cronet_test/test_storage",
138 // User-Agent request header field.
139 "fake agent",
140 // JSON encoded experimental options.
jrie68df0e2016-02-12 22:01:42141 "{\"QUIC\":{\"migrate_sessions_on_network_change\":true,"
142 "\"migrate_sessions_early\":true}}",
jric69a88422016-02-12 19:48:36143 // MockCertVerifier to use for testing purposes.
tbansal7018e2a2016-06-25 00:40:39144 std::unique_ptr<net::CertVerifier>(),
145 // Enable network quality estimator.
kapishnikov385aa422016-07-01 20:53:02146 false,
147 // Enable Public Key Pinning bypass for local trust anchors.
rtenneti121f9fa2016-07-07 23:49:28148 true,
149 // Certificate verifier cache data.
150 "");
jric69a88422016-02-12 19:48:36151
152 net::URLRequestContextBuilder builder;
153 net::NetLog net_log;
David Benjamindc2f4b02017-07-27 23:59:02154 config.ConfigureURLRequestContextBuilder(&builder, &net_log);
jric69a88422016-02-12 19:48:36155 // Set a ProxyConfigService to avoid DCHECK failure when building.
ricea85ec57952016-08-31 09:34:10156 builder.set_proxy_config_service(
Lily Houghtonef028852017-12-06 20:52:30157 std::make_unique<net::ProxyConfigServiceFixed>(
ricea85ec57952016-08-31 09:34:10158 net::ProxyConfig::CreateDirect()));
dchengfe3745e6242016-04-21 23:49:58159 std::unique_ptr<net::URLRequestContext> context(builder.Build());
jric69a88422016-02-12 19:48:36160 const net::HttpNetworkSession::Params* params =
161 context->GetNetworkSessionParams();
162
Jana Iyengar903dec22017-11-28 00:44:23163 EXPECT_FALSE(params->quic_close_sessions_on_ip_change);
jric69a88422016-02-12 19:48:36164 EXPECT_TRUE(params->quic_migrate_sessions_on_network_change);
jrie68df0e2016-02-12 22:01:42165 EXPECT_TRUE(params->quic_migrate_sessions_early);
jric69a88422016-02-12 19:48:36166}
167
Yixin Wang10f477ed2017-11-21 04:20:20168TEST(URLRequestContextConfigTest, SetQuicConnectionMigrationV2Options) {
Zhongyi Shi64795622017-11-20 02:21:49169 base::test::ScopedTaskEnvironment scoped_task_environment_(
170 base::test::ScopedTaskEnvironment::MainThreadType::IO);
171
172 URLRequestContextConfig config(
173 // Enable QUIC.
174 true,
175 // QUIC User Agent ID.
176 "Default QUIC User Agent ID",
177 // Enable SPDY.
178 true,
179 // Enable Brotli.
180 false,
181 // Type of http cache.
182 URLRequestContextConfig::HttpCacheType::DISK,
183 // Max size of http cache in bytes.
184 1024000,
185 // Disable caching for HTTP responses. Other information may be stored in
186 // the cache.
187 false,
188 // Storage path for http cache and cookie storage.
189 "/data/data/org.chromium.net/app_cronet_test/test_storage",
190 // User-Agent request header field.
191 "fake agent",
192 // JSON encoded experimental options.
Zhongyi Shif4683a32017-12-01 00:03:28193 "{\"QUIC\":{\"migrate_sessions_on_network_change_v2\":true,"
Zhongyi Shi73f23ca872017-12-13 18:37:13194 "\"migrate_sessions_early_v2\":true,"
Zhongyi Shi8b1e43f2017-12-13 20:46:30195 "\"max_time_on_non_default_network_seconds\":10,"
196 "\"max_migrations_to_non_default_network_on_path_degrading\":4}}",
Zhongyi Shi64795622017-11-20 02:21:49197 // MockCertVerifier to use for testing purposes.
198 std::unique_ptr<net::CertVerifier>(),
199 // Enable network quality estimator.
200 false,
201 // Enable Public Key Pinning bypass for local trust anchors.
202 true,
203 // Certificate verifier cache data.
204 "");
205
206 net::URLRequestContextBuilder builder;
207 net::NetLog net_log;
208 config.ConfigureURLRequestContextBuilder(&builder, &net_log);
209 // Set a ProxyConfigService to avoid DCHECK failure when building.
210 builder.set_proxy_config_service(
Lily Houghtonef028852017-12-06 20:52:30211 std::make_unique<net::ProxyConfigServiceFixed>(
Zhongyi Shi64795622017-11-20 02:21:49212 net::ProxyConfig::CreateDirect()));
213 std::unique_ptr<net::URLRequestContext> context(builder.Build());
214 const net::HttpNetworkSession::Params* params =
215 context->GetNetworkSessionParams();
216
217 EXPECT_TRUE(params->quic_migrate_sessions_on_network_change_v2);
Zhongyi Shif4683a32017-12-01 00:03:28218 EXPECT_TRUE(params->quic_migrate_sessions_early_v2);
Zhongyi Shi73f23ca872017-12-13 18:37:13219 EXPECT_EQ(base::TimeDelta::FromSeconds(10),
220 params->quic_max_time_on_non_default_network);
Zhongyi Shi8b1e43f2017-12-13 20:46:30221 EXPECT_EQ(
222 4, params->quic_max_migrations_to_non_default_network_on_path_degrading);
Zhongyi Shi64795622017-11-20 02:21:49223}
224
Yixin Wang10f477ed2017-11-21 04:20:20225TEST(URLRequestContextConfigTest, SetQuicHostWhitelist) {
226 base::test::ScopedTaskEnvironment scoped_task_environment_(
227 base::test::ScopedTaskEnvironment::MainThreadType::IO);
228
229 URLRequestContextConfig config(
230 // Enable QUIC.
231 true,
232 // QUIC User Agent ID.
233 "Default QUIC User Agent ID",
234 // Enable SPDY.
235 true,
236 // Enable Brotli.
237 false,
238 // Type of http cache.
239 URLRequestContextConfig::HttpCacheType::DISK,
240 // Max size of http cache in bytes.
241 1024000,
242 // Disable caching for HTTP responses. Other information may be stored in
243 // the cache.
244 false,
245 // Storage path for http cache and cookie storage.
246 "/data/data/org.chromium.net/app_cronet_test/test_storage",
247 // User-Agent request header field.
248 "fake agent",
249 // JSON encoded experimental options.
250 "{\"QUIC\":{\"host_whitelist\":\"www.example.com,www.example.org\"}}",
251 // MockCertVerifier to use for testing purposes.
252 std::unique_ptr<net::CertVerifier>(),
253 // Enable network quality estimator.
254 false,
255 // Enable Public Key Pinning bypass for local trust anchors.
256 true,
257 // Certificate verifier cache data.
258 "");
259
260 net::URLRequestContextBuilder builder;
261 net::NetLog net_log;
262 config.ConfigureURLRequestContextBuilder(&builder, &net_log);
263 // Set a ProxyConfigService to avoid DCHECK failure when building.
264 builder.set_proxy_config_service(
Lily Houghtonef028852017-12-06 20:52:30265 std::make_unique<net::ProxyConfigServiceFixed>(
Yixin Wang10f477ed2017-11-21 04:20:20266 net::ProxyConfig::CreateDirect()));
267 std::unique_ptr<net::URLRequestContext> context(builder.Build());
268 const net::HttpNetworkSession::Params* params =
269 context->GetNetworkSessionParams();
270
271 EXPECT_TRUE(
272 base::ContainsKey(params->quic_host_whitelist, "www.example.com"));
273 EXPECT_TRUE(
274 base::ContainsKey(params->quic_host_whitelist, "www.example.org"));
275}
276
Yixin Wang983875152017-11-21 20:30:13277TEST(URLRequestContextConfigTest, SetQuicMaxTimeBeforeCryptoHandshake) {
278 base::test::ScopedTaskEnvironment scoped_task_environment_(
279 base::test::ScopedTaskEnvironment::MainThreadType::IO);
280
281 URLRequestContextConfig config(
282 // Enable QUIC.
283 true,
284 // QUIC User Agent ID.
285 "Default QUIC User Agent ID",
286 // Enable SPDY.
287 true,
288 // Enable Brotli.
289 false,
290 // Type of http cache.
291 URLRequestContextConfig::HttpCacheType::DISK,
292 // Max size of http cache in bytes.
293 1024000,
294 // Disable caching for HTTP responses. Other information may be stored in
295 // the cache.
296 false,
297 // Storage path for http cache and cookie storage.
298 "/data/data/org.chromium.net/app_cronet_test/test_storage",
299 // User-Agent request header field.
300 "fake agent",
301 // JSON encoded experimental options.
302 "{\"QUIC\":{\"max_time_before_crypto_handshake_seconds\":7,"
303 "\"max_idle_time_before_crypto_handshake_seconds\":11}}",
304 // MockCertVerifier to use for testing purposes.
305 std::unique_ptr<net::CertVerifier>(),
306 // Enable network quality estimator.
307 false,
308 // Enable Public Key Pinning bypass for local trust anchors.
309 true,
310 // Certificate verifier cache data.
311 "");
312
313 net::URLRequestContextBuilder builder;
314 net::NetLog net_log;
315 config.ConfigureURLRequestContextBuilder(&builder, &net_log);
316 // Set a ProxyConfigService to avoid DCHECK failure when building.
317 builder.set_proxy_config_service(
Lily Houghtonef028852017-12-06 20:52:30318 std::make_unique<net::ProxyConfigServiceFixed>(
Yixin Wang983875152017-11-21 20:30:13319 net::ProxyConfig::CreateDirect()));
320 std::unique_ptr<net::URLRequestContext> context(builder.Build());
321 const net::HttpNetworkSession::Params* params =
322 context->GetNetworkSessionParams();
323
324 EXPECT_EQ(7, params->quic_max_time_before_crypto_handshake_seconds);
325 EXPECT_EQ(11, params->quic_max_idle_time_before_crypto_handshake_seconds);
326}
327
Yixin Wang1875fdb2017-12-06 02:26:49328TEST(URLURLRequestContextConfigTest, SetQuicConnectionOptions) {
329 base::test::ScopedTaskEnvironment scoped_task_environment_(
330 base::test::ScopedTaskEnvironment::MainThreadType::IO);
331
332 URLRequestContextConfig config(
333 // Enable QUIC.
334 true,
335 // QUIC User Agent ID.
336 "Default QUIC User Agent ID",
337 // Enable SPDY.
338 true,
339 // Enable Brotli.
340 false,
341 // Type of http cache.
342 URLRequestContextConfig::HttpCacheType::DISK,
343 // Max size of http cache in bytes.
344 1024000,
345 // Disable caching for HTTP responses. Other information may be stored in
346 // the cache.
347 false,
348 // Storage path for http cache and cookie storage.
349 "/data/data/org.chromium.net/app_cronet_test/test_storage",
350 // User-Agent request header field.
351 "fake agent",
352 // JSON encoded experimental options.
353 "{\"QUIC\":{\"connection_options\":\"TIME,TBBR,REJ\","
354 "\"client_connection_options\":\"TBBR,1RTT\"}}",
355 // MockCertVerifier to use for testing purposes.
356 std::unique_ptr<net::CertVerifier>(),
357 // Enable network quality estimator.
358 false,
359 // Enable Public Key Pinning bypass for local trust anchors.
360 true,
361 // Certificate verifier cache data.
362 "");
363
364 net::URLRequestContextBuilder builder;
365 net::NetLog net_log;
366 config.ConfigureURLRequestContextBuilder(&builder, &net_log);
367 // Set a ProxyConfigService to avoid DCHECK failure when building.
368 builder.set_proxy_config_service(
369 base::MakeUnique<net::ProxyConfigServiceFixed>(
370 net::ProxyConfig::CreateDirect()));
371 std::unique_ptr<net::URLRequestContext> context(builder.Build());
372 const net::HttpNetworkSession::Params* params =
373 context->GetNetworkSessionParams();
374
375 net::QuicTagVector connection_options;
376 connection_options.push_back(net::kTIME);
377 connection_options.push_back(net::kTBBR);
378 connection_options.push_back(net::kREJ);
379 EXPECT_EQ(connection_options, params->quic_connection_options);
380
381 net::QuicTagVector client_connection_options;
382 client_connection_options.push_back(net::kTBBR);
383 client_connection_options.push_back(net::k1RTT);
384 EXPECT_EQ(client_connection_options, params->quic_client_connection_options);
385}
386
juliatuttle50d9c4b2016-08-23 22:49:19387// See stale_host_resolver_unittest.cc for test of StaleDNS options.
388
xunjielif24ee5f2015-11-23 18:05:26389} // namespace cronet