blob: bbff7005a7929341bfffd5e619fe49bd7d18bd36 [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
dchengfe3745e6242016-04-21 23:49:587#include "base/memory/ptr_util.h"
rdsmithbf8c3c12016-11-18 18:16:248#include "base/message_loop/message_loop.h"
tfhef3618f2016-01-11 23:07:089#include "base/values.h"
pauljensen9041eb3c2015-12-09 12:29:0110#include "net/cert/cert_verifier.h"
xunjielif24ee5f2015-11-23 18:05:2611#include "net/http/http_network_session.h"
mikecironef22f9812016-10-04 03:40:1912#include "net/log/net_log.h"
13#include "net/log/net_log_with_source.h"
xunjielif24ee5f2015-11-23 18:05:2614#include "net/proxy/proxy_config.h"
15#include "net/proxy/proxy_config_service_fixed.h"
16#include "net/url_request/url_request_context.h"
17#include "net/url_request/url_request_context_builder.h"
18#include "testing/gtest/include/gtest/gtest.h"
19
20namespace cronet {
21
xunjielid67295e2017-03-16 21:05:4122TEST(URLRequestContextConfigTest, TestExperimentalOptionParsing) {
pauljensen9041eb3c2015-12-09 12:29:0123 URLRequestContextConfig config(
24 // Enable QUIC.
25 true,
mefc5da5712016-02-09 20:14:2326 // QUIC User Agent ID.
27 "Default QUIC User Agent ID",
pauljensen9041eb3c2015-12-09 12:29:0128 // Enable SPDY.
29 true,
30 // Enable SDCH.
31 false,
32 // Type of http cache.
33 URLRequestContextConfig::HttpCacheType::DISK,
34 // Max size of http cache in bytes.
35 1024000,
36 // Disable caching for HTTP responses. Other information may be stored in
37 // the cache.
38 false,
39 // Storage path for http cache and cookie storage.
40 "/data/data/org.chromium.net/app_cronet_test/test_storage",
41 // User-Agent request header field.
42 "fake agent",
43 // JSON encoded experimental options.
rtenneti6971c172016-01-15 20:12:1044 "{\"QUIC\":{\"max_server_configs_stored_in_properties\":2,"
rtennetib8e80fb2016-05-16 00:12:0945 "\"delay_tcp_race\":true,"
mefc5da5712016-02-09 20:14:2346 "\"prefer_aes\":true,"
47 "\"user_agent_id\":\"Custom QUIC UAID\","
rtenneti64e809d02015-12-11 00:26:2048 "\"idle_connection_timeout_seconds\":300,"
jrid26566952016-02-04 21:06:4249 "\"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.
57 "\"disable_ipv6\":true}",
pauljensen9041eb3c2015-12-09 12:29:0158 // Data reduction proxy key.
59 "",
60 // Data reduction proxy.
61 "",
62 // Fallback data reduction proxy.
63 "",
64 // Data reduction proxy secure proxy check URL.
65 "",
66 // MockCertVerifier to use for testing purposes.
tbansal7018e2a2016-06-25 00:40:3967 std::unique_ptr<net::CertVerifier>(),
68 // Enable network quality estimator.
kapishnikov385aa422016-07-01 20:53:0269 false,
70 // Enable Public Key Pinning bypass for local trust anchors.
rtenneti121f9fa2016-07-07 23:49:2871 true,
72 // Certificate verifier cache data.
73 "");
xunjielif24ee5f2015-11-23 18:05:2674
rdsmithbf8c3c12016-11-18 18:16:2475 base::MessageLoop message_loop;
xunjielif24ee5f2015-11-23 18:05:2676 net::URLRequestContextBuilder builder;
pauljensene92c4092015-12-09 19:13:4877 net::NetLog net_log;
xunjielida7f77022016-03-28 16:36:3678 config.ConfigureURLRequestContextBuilder(&builder, &net_log, nullptr);
xunjielid67295e2017-03-16 21:05:4179 EXPECT_FALSE(config.effective_experimental_options->HasKey("UnknownOption"));
xunjielif24ee5f2015-11-23 18:05:2680 // Set a ProxyConfigService to avoid DCHECK failure when building.
ricea85ec57952016-08-31 09:34:1081 builder.set_proxy_config_service(
82 base::MakeUnique<net::ProxyConfigServiceFixed>(
83 net::ProxyConfig::CreateDirect()));
dchengfe3745e6242016-04-21 23:49:5884 std::unique_ptr<net::URLRequestContext> context(builder.Build());
xunjielif24ee5f2015-11-23 18:05:2685 const net::HttpNetworkSession::Params* params =
86 context->GetNetworkSessionParams();
87 // Check Quic Connection options.
88 net::QuicTagVector quic_connection_options;
89 quic_connection_options.push_back(net::kTIME);
90 quic_connection_options.push_back(net::kTBBR);
91 quic_connection_options.push_back(net::kREJ);
92 EXPECT_EQ(quic_connection_options, params->quic_connection_options);
93
mefc5da5712016-02-09 20:14:2394 // Check Custom QUIC User Agent Id.
95 EXPECT_EQ("Custom QUIC UAID", params->quic_user_agent_id);
96
rtenneti6971c172016-01-15 20:12:1097 // Check max_server_configs_stored_in_properties.
98 EXPECT_EQ(2u, params->quic_max_server_configs_stored_in_properties);
xunjielif24ee5f2015-11-23 18:05:2699
rtennetib8e80fb2016-05-16 00:12:09100 // Check delay_tcp_race.
101 EXPECT_TRUE(params->quic_delay_tcp_race);
102
mefc5da5712016-02-09 20:14:23103 // Check prefer_aes.
104 EXPECT_TRUE(params->quic_prefer_aes);
105
rtenneti64e809d02015-12-11 00:26:20106 // Check idle_connection_timeout_seconds.
107 EXPECT_EQ(300, params->quic_idle_connection_timeout_seconds);
108
jrid26566952016-02-04 21:06:42109 EXPECT_TRUE(params->quic_close_sessions_on_ip_change);
jric69a88422016-02-12 19:48:36110 EXPECT_FALSE(params->quic_migrate_sessions_on_network_change);
jrid26566952016-02-04 21:06:42111
rtennetid073dd22016-08-04 01:58:33112 // Check race_cert_verification.
113 EXPECT_TRUE(params->quic_race_cert_verification);
114
pauljensene92c4092015-12-09 19:13:48115 // Check AsyncDNS resolver is enabled.
tfhef3618f2016-01-11 23:07:08116 EXPECT_TRUE(context->host_resolver()->GetDnsConfigAsValue());
mgershaf2c12c2016-08-22 16:33:54117
mgershb3fe8082017-02-28 20:09:20118 // Check IPv6 is disabled.
119 EXPECT_EQ(net::ADDRESS_FAMILY_IPV4,
120 context->host_resolver()->GetDefaultAddressFamily());
121
mgershaf2c12c2016-08-22 16:33:54122 net::HostResolver::RequestInfo info(net::HostPortPair("abcde", 80));
123 net::AddressList addresses;
124 EXPECT_EQ(net::OK, context->host_resolver()->ResolveFromCache(
tfarina428341112016-09-22 13:38:20125 info, &addresses, net::NetLogWithSource()));
xunjielif24ee5f2015-11-23 18:05:26126}
127
jric69a88422016-02-12 19:48:36128TEST(URLRequestContextConfigTest, SetQuicConnectionMigrationOptions) {
129 URLRequestContextConfig config(
130 // Enable QUIC.
131 true,
132 // QUIC User Agent ID.
133 "Default QUIC User Agent ID",
134 // Enable SPDY.
135 true,
136 // Enable SDCH.
137 false,
138 // Type of http cache.
139 URLRequestContextConfig::HttpCacheType::DISK,
140 // Max size of http cache in bytes.
141 1024000,
142 // Disable caching for HTTP responses. Other information may be stored in
143 // the cache.
144 false,
145 // Storage path for http cache and cookie storage.
146 "/data/data/org.chromium.net/app_cronet_test/test_storage",
147 // User-Agent request header field.
148 "fake agent",
149 // JSON encoded experimental options.
jrie68df0e2016-02-12 22:01:42150 "{\"QUIC\":{\"migrate_sessions_on_network_change\":true,"
151 "\"migrate_sessions_early\":true}}",
jric69a88422016-02-12 19:48:36152 // Data reduction proxy key.
153 "",
154 // Data reduction proxy.
155 "",
156 // Fallback data reduction proxy.
157 "",
158 // Data reduction proxy secure proxy check URL.
159 "",
160 // MockCertVerifier to use for testing purposes.
tbansal7018e2a2016-06-25 00:40:39161 std::unique_ptr<net::CertVerifier>(),
162 // Enable network quality estimator.
kapishnikov385aa422016-07-01 20:53:02163 false,
164 // Enable Public Key Pinning bypass for local trust anchors.
rtenneti121f9fa2016-07-07 23:49:28165 true,
166 // Certificate verifier cache data.
167 "");
jric69a88422016-02-12 19:48:36168
rdsmithbf8c3c12016-11-18 18:16:24169 base::MessageLoop message_loop;
jric69a88422016-02-12 19:48:36170 net::URLRequestContextBuilder builder;
171 net::NetLog net_log;
xunjielida7f77022016-03-28 16:36:36172 config.ConfigureURLRequestContextBuilder(&builder, &net_log, nullptr);
jric69a88422016-02-12 19:48:36173 // Set a ProxyConfigService to avoid DCHECK failure when building.
ricea85ec57952016-08-31 09:34:10174 builder.set_proxy_config_service(
175 base::MakeUnique<net::ProxyConfigServiceFixed>(
176 net::ProxyConfig::CreateDirect()));
dchengfe3745e6242016-04-21 23:49:58177 std::unique_ptr<net::URLRequestContext> context(builder.Build());
jric69a88422016-02-12 19:48:36178 const net::HttpNetworkSession::Params* params =
179 context->GetNetworkSessionParams();
180
181 EXPECT_FALSE(params->quic_close_sessions_on_ip_change);
182 EXPECT_TRUE(params->quic_migrate_sessions_on_network_change);
jrie68df0e2016-02-12 22:01:42183 EXPECT_TRUE(params->quic_migrate_sessions_early);
jric69a88422016-02-12 19:48:36184}
185
juliatuttle50d9c4b2016-08-23 22:49:19186// See stale_host_resolver_unittest.cc for test of StaleDNS options.
187
xunjielif24ee5f2015-11-23 18:05:26188} // namespace cronet