blob: 56025cd4246e4122a9d6eedfb9dac42d4a615d29 [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
jri7c5cef62016-02-05 12:18:3919TEST(URLRequestContextConfigTest, SetQuicExperimentalOptions) {
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,"
pauljensen9041eb3c2015-12-09 12:29:0143 "\"max_number_of_lossy_connections\":10,"
mefc5da5712016-02-09 20:14:2344 "\"prefer_aes\":true,"
45 "\"user_agent_id\":\"Custom QUIC UAID\","
pauljensen9041eb3c2015-12-09 12:29:0146 "\"packet_loss_threshold\":0.5,"
rtenneti64e809d02015-12-11 00:26:2047 "\"idle_connection_timeout_seconds\":300,"
jrid26566952016-02-04 21:06:4248 "\"close_sessions_on_ip_change\":true,"
pauljensene92c4092015-12-09 19:13:4849 "\"connection_options\":\"TIME,TBBR,REJ\"},"
50 "\"AsyncDNS\":{\"enable\":true}}",
pauljensen9041eb3c2015-12-09 12:29:0151 // Data reduction proxy key.
52 "",
53 // Data reduction proxy.
54 "",
55 // Fallback data reduction proxy.
56 "",
57 // Data reduction proxy secure proxy check URL.
58 "",
59 // MockCertVerifier to use for testing purposes.
tbansal7018e2a2016-06-25 00:40:3960 std::unique_ptr<net::CertVerifier>(),
61 // Enable network quality estimator.
kapishnikov385aa422016-07-01 20:53:0262 false,
63 // Enable Public Key Pinning bypass for local trust anchors.
64 true);
xunjielif24ee5f2015-11-23 18:05:2665
xunjielif24ee5f2015-11-23 18:05:2666 net::URLRequestContextBuilder builder;
pauljensene92c4092015-12-09 19:13:4867 net::NetLog net_log;
xunjielida7f77022016-03-28 16:36:3668 config.ConfigureURLRequestContextBuilder(&builder, &net_log, nullptr);
xunjielif24ee5f2015-11-23 18:05:2669 // Set a ProxyConfigService to avoid DCHECK failure when building.
dchengfe3745e6242016-04-21 23:49:5870 builder.set_proxy_config_service(base::WrapUnique(
xunjielif24ee5f2015-11-23 18:05:2671 new net::ProxyConfigServiceFixed(net::ProxyConfig::CreateDirect())));
dchengfe3745e6242016-04-21 23:49:5872 std::unique_ptr<net::URLRequestContext> context(builder.Build());
xunjielif24ee5f2015-11-23 18:05:2673 const net::HttpNetworkSession::Params* params =
74 context->GetNetworkSessionParams();
75 // Check Quic Connection options.
76 net::QuicTagVector quic_connection_options;
77 quic_connection_options.push_back(net::kTIME);
78 quic_connection_options.push_back(net::kTBBR);
79 quic_connection_options.push_back(net::kREJ);
80 EXPECT_EQ(quic_connection_options, params->quic_connection_options);
81
mefc5da5712016-02-09 20:14:2382 // Check Custom QUIC User Agent Id.
83 EXPECT_EQ("Custom QUIC UAID", params->quic_user_agent_id);
84
rtenneti6971c172016-01-15 20:12:1085 // Check max_server_configs_stored_in_properties.
86 EXPECT_EQ(2u, params->quic_max_server_configs_stored_in_properties);
xunjielif24ee5f2015-11-23 18:05:2687
rtennetib8e80fb2016-05-16 00:12:0988 // Check delay_tcp_race.
89 EXPECT_TRUE(params->quic_delay_tcp_race);
90
mefc5da5712016-02-09 20:14:2391 // Check prefer_aes.
92 EXPECT_TRUE(params->quic_prefer_aes);
93
xunjielif24ee5f2015-11-23 18:05:2694 // Check max_number_of_lossy_connections and packet_loss_threshold.
95 EXPECT_EQ(10, params->quic_max_number_of_lossy_connections);
96 EXPECT_FLOAT_EQ(0.5f, params->quic_packet_loss_threshold);
pauljensene92c4092015-12-09 19:13:4897
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
pauljensene92c4092015-12-09 19:13:48104 // Check AsyncDNS resolver is enabled.
tfhef3618f2016-01-11 23:07:08105 EXPECT_TRUE(context->host_resolver()->GetDnsConfigAsValue());
xunjielif24ee5f2015-11-23 18:05:26106}
107
jric69a88422016-02-12 19:48:36108TEST(URLRequestContextConfigTest, SetQuicConnectionMigrationOptions) {
109 URLRequestContextConfig config(
110 // Enable QUIC.
111 true,
112 // QUIC User Agent ID.
113 "Default QUIC User Agent ID",
114 // Enable SPDY.
115 true,
116 // Enable SDCH.
117 false,
118 // Type of http cache.
119 URLRequestContextConfig::HttpCacheType::DISK,
120 // Max size of http cache in bytes.
121 1024000,
122 // Disable caching for HTTP responses. Other information may be stored in
123 // the cache.
124 false,
125 // Storage path for http cache and cookie storage.
126 "/data/data/org.chromium.net/app_cronet_test/test_storage",
127 // User-Agent request header field.
128 "fake agent",
129 // JSON encoded experimental options.
jrie68df0e2016-02-12 22:01:42130 "{\"QUIC\":{\"migrate_sessions_on_network_change\":true,"
131 "\"migrate_sessions_early\":true}}",
jric69a88422016-02-12 19:48:36132 // Data reduction proxy key.
133 "",
134 // Data reduction proxy.
135 "",
136 // Fallback data reduction proxy.
137 "",
138 // Data reduction proxy secure proxy check URL.
139 "",
140 // MockCertVerifier to use for testing purposes.
tbansal7018e2a2016-06-25 00:40:39141 std::unique_ptr<net::CertVerifier>(),
142 // Enable network quality estimator.
kapishnikov385aa422016-07-01 20:53:02143 false,
144 // Enable Public Key Pinning bypass for local trust anchors.
145 true);
jric69a88422016-02-12 19:48:36146
147 net::URLRequestContextBuilder builder;
148 net::NetLog net_log;
xunjielida7f77022016-03-28 16:36:36149 config.ConfigureURLRequestContextBuilder(&builder, &net_log, nullptr);
jric69a88422016-02-12 19:48:36150 // Set a ProxyConfigService to avoid DCHECK failure when building.
dchengfe3745e6242016-04-21 23:49:58151 builder.set_proxy_config_service(base::WrapUnique(
jric69a88422016-02-12 19:48:36152 new net::ProxyConfigServiceFixed(net::ProxyConfig::CreateDirect())));
dchengfe3745e6242016-04-21 23:49:58153 std::unique_ptr<net::URLRequestContext> context(builder.Build());
jric69a88422016-02-12 19:48:36154 const net::HttpNetworkSession::Params* params =
155 context->GetNetworkSessionParams();
156
157 EXPECT_FALSE(params->quic_close_sessions_on_ip_change);
158 EXPECT_TRUE(params->quic_migrate_sessions_on_network_change);
jrie68df0e2016-02-12 22:01:42159 EXPECT_TRUE(params->quic_migrate_sessions_early);
jric69a88422016-02-12 19:48:36160}
161
xunjielif24ee5f2015-11-23 18:05:26162} // namespace cronet