blob: fb97389a4bac4b4f70136e060be00d9dc2794d28 [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"
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"
11#include "net/proxy/proxy_config.h"
12#include "net/proxy/proxy_config_service_fixed.h"
13#include "net/url_request/url_request_context.h"
14#include "net/url_request/url_request_context_builder.h"
15#include "testing/gtest/include/gtest/gtest.h"
16
17namespace cronet {
18
mgershaf2c12c2016-08-22 16:33:5419TEST(URLRequestContextConfigTest, TestExperimentalOptionPassing) {
pauljensen9041eb3c2015-12-09 12:29:0120 URLRequestContextConfig config(
21 // Enable QUIC.
22 true,
mefc5da5712016-02-09 20:14:2323 // QUIC User Agent ID.
24 "Default QUIC User Agent ID",
pauljensen9041eb3c2015-12-09 12:29:0125 // Enable SPDY.
26 true,
27 // Enable SDCH.
28 false,
29 // Type of http cache.
30 URLRequestContextConfig::HttpCacheType::DISK,
31 // Max size of http cache in bytes.
32 1024000,
33 // Disable caching for HTTP responses. Other information may be stored in
34 // the cache.
35 false,
36 // Storage path for http cache and cookie storage.
37 "/data/data/org.chromium.net/app_cronet_test/test_storage",
38 // User-Agent request header field.
39 "fake agent",
40 // JSON encoded experimental options.
rtenneti6971c172016-01-15 20:12:1041 "{\"QUIC\":{\"max_server_configs_stored_in_properties\":2,"
rtennetib8e80fb2016-05-16 00:12:0942 "\"delay_tcp_race\":true,"
mefc5da5712016-02-09 20:14:2343 "\"prefer_aes\":true,"
44 "\"user_agent_id\":\"Custom QUIC UAID\","
rtenneti64e809d02015-12-11 00:26:2045 "\"idle_connection_timeout_seconds\":300,"
jrid26566952016-02-04 21:06:4246 "\"close_sessions_on_ip_change\":true,"
rtennetid073dd22016-08-04 01:58:3347 "\"race_cert_verification\":true,"
pauljensene92c4092015-12-09 19:13:4848 "\"connection_options\":\"TIME,TBBR,REJ\"},"
mgershaf2c12c2016-08-22 16:33:5449 "\"AsyncDNS\":{\"enable\":true},"
50 "\"HostResolverRules\":{\"host_resolver_rules\":"
51 "\"MAP * 127.0.0.1\"}}",
pauljensen9041eb3c2015-12-09 12:29:0152 // Data reduction proxy key.
53 "",
54 // Data reduction proxy.
55 "",
56 // Fallback data reduction proxy.
57 "",
58 // Data reduction proxy secure proxy check URL.
59 "",
60 // MockCertVerifier to use for testing purposes.
tbansal7018e2a2016-06-25 00:40:3961 std::unique_ptr<net::CertVerifier>(),
62 // Enable network quality estimator.
kapishnikov385aa422016-07-01 20:53:0263 false,
64 // Enable Public Key Pinning bypass for local trust anchors.
rtenneti121f9fa2016-07-07 23:49:2865 true,
66 // Certificate verifier cache data.
67 "");
xunjielif24ee5f2015-11-23 18:05:2668
xunjielif24ee5f2015-11-23 18:05:2669 net::URLRequestContextBuilder builder;
pauljensene92c4092015-12-09 19:13:4870 net::NetLog net_log;
xunjielida7f77022016-03-28 16:36:3671 config.ConfigureURLRequestContextBuilder(&builder, &net_log, nullptr);
xunjielif24ee5f2015-11-23 18:05:2672 // Set a ProxyConfigService to avoid DCHECK failure when building.
ricea85ec57952016-08-31 09:34:1073 builder.set_proxy_config_service(
74 base::MakeUnique<net::ProxyConfigServiceFixed>(
75 net::ProxyConfig::CreateDirect()));
dchengfe3745e6242016-04-21 23:49:5876 std::unique_ptr<net::URLRequestContext> context(builder.Build());
xunjielif24ee5f2015-11-23 18:05:2677 const net::HttpNetworkSession::Params* params =
78 context->GetNetworkSessionParams();
79 // Check Quic Connection options.
80 net::QuicTagVector quic_connection_options;
81 quic_connection_options.push_back(net::kTIME);
82 quic_connection_options.push_back(net::kTBBR);
83 quic_connection_options.push_back(net::kREJ);
84 EXPECT_EQ(quic_connection_options, params->quic_connection_options);
85
mefc5da5712016-02-09 20:14:2386 // Check Custom QUIC User Agent Id.
87 EXPECT_EQ("Custom QUIC UAID", params->quic_user_agent_id);
88
rtenneti6971c172016-01-15 20:12:1089 // Check max_server_configs_stored_in_properties.
90 EXPECT_EQ(2u, params->quic_max_server_configs_stored_in_properties);
xunjielif24ee5f2015-11-23 18:05:2691
rtennetib8e80fb2016-05-16 00:12:0992 // Check delay_tcp_race.
93 EXPECT_TRUE(params->quic_delay_tcp_race);
94
mefc5da5712016-02-09 20:14:2395 // Check prefer_aes.
96 EXPECT_TRUE(params->quic_prefer_aes);
97
rtenneti64e809d02015-12-11 00:26:2098 // Check idle_connection_timeout_seconds.
99 EXPECT_EQ(300, params->quic_idle_connection_timeout_seconds);
100
jrid26566952016-02-04 21:06:42101 EXPECT_TRUE(params->quic_close_sessions_on_ip_change);
jric69a88422016-02-12 19:48:36102 EXPECT_FALSE(params->quic_migrate_sessions_on_network_change);
jrid26566952016-02-04 21:06:42103
rtennetid073dd22016-08-04 01:58:33104 // Check race_cert_verification.
105 EXPECT_TRUE(params->quic_race_cert_verification);
106
pauljensene92c4092015-12-09 19:13:48107 // Check AsyncDNS resolver is enabled.
tfhef3618f2016-01-11 23:07:08108 EXPECT_TRUE(context->host_resolver()->GetDnsConfigAsValue());
mgershaf2c12c2016-08-22 16:33:54109
110 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
jric69a88422016-02-12 19:48:36116TEST(URLRequestContextConfigTest, SetQuicConnectionMigrationOptions) {
117 URLRequestContextConfig config(
118 // Enable QUIC.
119 true,
120 // QUIC User Agent ID.
121 "Default QUIC User Agent ID",
122 // Enable SPDY.
123 true,
124 // Enable SDCH.
125 false,
126 // Type of http cache.
127 URLRequestContextConfig::HttpCacheType::DISK,
128 // Max size of http cache in bytes.
129 1024000,
130 // Disable caching for HTTP responses. Other information may be stored in
131 // the cache.
132 false,
133 // Storage path for http cache and cookie storage.
134 "/data/data/org.chromium.net/app_cronet_test/test_storage",
135 // User-Agent request header field.
136 "fake agent",
137 // JSON encoded experimental options.
jrie68df0e2016-02-12 22:01:42138 "{\"QUIC\":{\"migrate_sessions_on_network_change\":true,"
139 "\"migrate_sessions_early\":true}}",
jric69a88422016-02-12 19:48:36140 // Data reduction proxy key.
141 "",
142 // Data reduction proxy.
143 "",
144 // Fallback data reduction proxy.
145 "",
146 // Data reduction proxy secure proxy check URL.
147 "",
148 // MockCertVerifier to use for testing purposes.
tbansal7018e2a2016-06-25 00:40:39149 std::unique_ptr<net::CertVerifier>(),
150 // Enable network quality estimator.
kapishnikov385aa422016-07-01 20:53:02151 false,
152 // Enable Public Key Pinning bypass for local trust anchors.
rtenneti121f9fa2016-07-07 23:49:28153 true,
154 // Certificate verifier cache data.
155 "");
jric69a88422016-02-12 19:48:36156
157 net::URLRequestContextBuilder builder;
158 net::NetLog net_log;
xunjielida7f77022016-03-28 16:36:36159 config.ConfigureURLRequestContextBuilder(&builder, &net_log, nullptr);
jric69a88422016-02-12 19:48:36160 // Set a ProxyConfigService to avoid DCHECK failure when building.
ricea85ec57952016-08-31 09:34:10161 builder.set_proxy_config_service(
162 base::MakeUnique<net::ProxyConfigServiceFixed>(
163 net::ProxyConfig::CreateDirect()));
dchengfe3745e6242016-04-21 23:49:58164 std::unique_ptr<net::URLRequestContext> context(builder.Build());
jric69a88422016-02-12 19:48:36165 const net::HttpNetworkSession::Params* params =
166 context->GetNetworkSessionParams();
167
168 EXPECT_FALSE(params->quic_close_sessions_on_ip_change);
169 EXPECT_TRUE(params->quic_migrate_sessions_on_network_change);
jrie68df0e2016-02-12 22:01:42170 EXPECT_TRUE(params->quic_migrate_sessions_early);
jric69a88422016-02-12 19:48:36171}
172
juliatuttle50d9c4b2016-08-23 22:49:19173// See stale_host_resolver_unittest.cc for test of StaleDNS options.
174
xunjielif24ee5f2015-11-23 18:05:26175} // namespace cronet