blob: b072527ba5605e88ccec9650b3c5e5546c53a351 [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
mgershaf2c12c2016-08-22 16:33:5422TEST(URLRequestContextConfigTest, TestExperimentalOptionPassing) {
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},"
53 "\"HostResolverRules\":{\"host_resolver_rules\":"
54 "\"MAP * 127.0.0.1\"}}",
pauljensen9041eb3c2015-12-09 12:29:0155 // Data reduction proxy key.
56 "",
57 // Data reduction proxy.
58 "",
59 // Fallback data reduction proxy.
60 "",
61 // Data reduction proxy secure proxy check URL.
62 "",
63 // MockCertVerifier to use for testing purposes.
tbansal7018e2a2016-06-25 00:40:3964 std::unique_ptr<net::CertVerifier>(),
65 // Enable network quality estimator.
kapishnikov385aa422016-07-01 20:53:0266 false,
67 // Enable Public Key Pinning bypass for local trust anchors.
rtenneti121f9fa2016-07-07 23:49:2868 true,
69 // Certificate verifier cache data.
70 "");
xunjielif24ee5f2015-11-23 18:05:2671
rdsmithbf8c3c12016-11-18 18:16:2472 base::MessageLoop message_loop;
xunjielif24ee5f2015-11-23 18:05:2673 net::URLRequestContextBuilder builder;
pauljensene92c4092015-12-09 19:13:4874 net::NetLog net_log;
xunjielida7f77022016-03-28 16:36:3675 config.ConfigureURLRequestContextBuilder(&builder, &net_log, nullptr);
xunjielif24ee5f2015-11-23 18:05:2676 // Set a ProxyConfigService to avoid DCHECK failure when building.
ricea85ec57952016-08-31 09:34:1077 builder.set_proxy_config_service(
78 base::MakeUnique<net::ProxyConfigServiceFixed>(
79 net::ProxyConfig::CreateDirect()));
dchengfe3745e6242016-04-21 23:49:5880 std::unique_ptr<net::URLRequestContext> context(builder.Build());
xunjielif24ee5f2015-11-23 18:05:2681 const net::HttpNetworkSession::Params* params =
82 context->GetNetworkSessionParams();
83 // Check Quic Connection options.
84 net::QuicTagVector quic_connection_options;
85 quic_connection_options.push_back(net::kTIME);
86 quic_connection_options.push_back(net::kTBBR);
87 quic_connection_options.push_back(net::kREJ);
88 EXPECT_EQ(quic_connection_options, params->quic_connection_options);
89
mefc5da5712016-02-09 20:14:2390 // Check Custom QUIC User Agent Id.
91 EXPECT_EQ("Custom QUIC UAID", params->quic_user_agent_id);
92
rtenneti6971c172016-01-15 20:12:1093 // Check max_server_configs_stored_in_properties.
94 EXPECT_EQ(2u, params->quic_max_server_configs_stored_in_properties);
xunjielif24ee5f2015-11-23 18:05:2695
rtennetib8e80fb2016-05-16 00:12:0996 // Check delay_tcp_race.
97 EXPECT_TRUE(params->quic_delay_tcp_race);
98
mefc5da5712016-02-09 20:14:2399 // Check prefer_aes.
100 EXPECT_TRUE(params->quic_prefer_aes);
101
rtenneti64e809d02015-12-11 00:26:20102 // Check idle_connection_timeout_seconds.
103 EXPECT_EQ(300, params->quic_idle_connection_timeout_seconds);
104
jrid26566952016-02-04 21:06:42105 EXPECT_TRUE(params->quic_close_sessions_on_ip_change);
jric69a88422016-02-12 19:48:36106 EXPECT_FALSE(params->quic_migrate_sessions_on_network_change);
jrid26566952016-02-04 21:06:42107
rtennetid073dd22016-08-04 01:58:33108 // Check race_cert_verification.
109 EXPECT_TRUE(params->quic_race_cert_verification);
110
pauljensene92c4092015-12-09 19:13:48111 // Check AsyncDNS resolver is enabled.
tfhef3618f2016-01-11 23:07:08112 EXPECT_TRUE(context->host_resolver()->GetDnsConfigAsValue());
mgershaf2c12c2016-08-22 16:33:54113
114 net::HostResolver::RequestInfo info(net::HostPortPair("abcde", 80));
115 net::AddressList addresses;
116 EXPECT_EQ(net::OK, context->host_resolver()->ResolveFromCache(
tfarina428341112016-09-22 13:38:20117 info, &addresses, net::NetLogWithSource()));
xunjielif24ee5f2015-11-23 18:05:26118}
119
jric69a88422016-02-12 19:48:36120TEST(URLRequestContextConfigTest, SetQuicConnectionMigrationOptions) {
121 URLRequestContextConfig config(
122 // Enable QUIC.
123 true,
124 // QUIC User Agent ID.
125 "Default QUIC User Agent ID",
126 // Enable SPDY.
127 true,
128 // Enable SDCH.
129 false,
130 // Type of http cache.
131 URLRequestContextConfig::HttpCacheType::DISK,
132 // Max size of http cache in bytes.
133 1024000,
134 // Disable caching for HTTP responses. Other information may be stored in
135 // the cache.
136 false,
137 // Storage path for http cache and cookie storage.
138 "/data/data/org.chromium.net/app_cronet_test/test_storage",
139 // User-Agent request header field.
140 "fake agent",
141 // JSON encoded experimental options.
jrie68df0e2016-02-12 22:01:42142 "{\"QUIC\":{\"migrate_sessions_on_network_change\":true,"
143 "\"migrate_sessions_early\":true}}",
jric69a88422016-02-12 19:48:36144 // Data reduction proxy key.
145 "",
146 // Data reduction proxy.
147 "",
148 // Fallback data reduction proxy.
149 "",
150 // Data reduction proxy secure proxy check URL.
151 "",
152 // MockCertVerifier to use for testing purposes.
tbansal7018e2a2016-06-25 00:40:39153 std::unique_ptr<net::CertVerifier>(),
154 // Enable network quality estimator.
kapishnikov385aa422016-07-01 20:53:02155 false,
156 // Enable Public Key Pinning bypass for local trust anchors.
rtenneti121f9fa2016-07-07 23:49:28157 true,
158 // Certificate verifier cache data.
159 "");
jric69a88422016-02-12 19:48:36160
rdsmithbf8c3c12016-11-18 18:16:24161 base::MessageLoop message_loop;
jric69a88422016-02-12 19:48:36162 net::URLRequestContextBuilder builder;
163 net::NetLog net_log;
xunjielida7f77022016-03-28 16:36:36164 config.ConfigureURLRequestContextBuilder(&builder, &net_log, nullptr);
jric69a88422016-02-12 19:48:36165 // Set a ProxyConfigService to avoid DCHECK failure when building.
ricea85ec57952016-08-31 09:34:10166 builder.set_proxy_config_service(
167 base::MakeUnique<net::ProxyConfigServiceFixed>(
168 net::ProxyConfig::CreateDirect()));
dchengfe3745e6242016-04-21 23:49:58169 std::unique_ptr<net::URLRequestContext> context(builder.Build());
jric69a88422016-02-12 19:48:36170 const net::HttpNetworkSession::Params* params =
171 context->GetNetworkSessionParams();
172
173 EXPECT_FALSE(params->quic_close_sessions_on_ip_change);
174 EXPECT_TRUE(params->quic_migrate_sessions_on_network_change);
jrie68df0e2016-02-12 22:01:42175 EXPECT_TRUE(params->quic_migrate_sessions_early);
jric69a88422016-02-12 19:48:36176}
177
juliatuttle50d9c4b2016-08-23 22:49:19178// See stale_host_resolver_unittest.cc for test of StaleDNS options.
179
xunjielif24ee5f2015-11-23 18:05:26180} // namespace cronet