xunjieli | f24ee5f | 2015-11-23 18:05:26 | [diff] [blame] | 1 | // 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 | |
mmenke | 51629db1 | 2017-06-28 13:34:12 | [diff] [blame] | 7 | #include "base/test/scoped_task_environment.h" |
tfh | ef3618f | 2016-01-11 23:07:08 | [diff] [blame] | 8 | #include "base/values.h" |
pauljensen | 9041eb3c | 2015-12-09 12:29:01 | [diff] [blame] | 9 | #include "net/cert/cert_verifier.h" |
xunjieli | f24ee5f | 2015-11-23 18:05:26 | [diff] [blame] | 10 | #include "net/http/http_network_session.h" |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 11 | #include "net/log/net_log.h" |
| 12 | #include "net/log/net_log_with_source.h" |
xunjieli | f24ee5f | 2015-11-23 18:05:26 | [diff] [blame] | 13 | #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 | |
| 19 | namespace cronet { |
| 20 | |
mmenke | 51629db1 | 2017-06-28 13:34:12 | [diff] [blame] | 21 | TEST(URLRequestContextConfigTest, TestExperimentalOptionParsing) { |
| 22 | base::test::ScopedTaskEnvironment scoped_task_environment_( |
| 23 | base::test::ScopedTaskEnvironment::MainThreadType::IO); |
| 24 | |
pauljensen | 9041eb3c | 2015-12-09 12:29:01 | [diff] [blame] | 25 | URLRequestContextConfig config( |
| 26 | // Enable QUIC. |
| 27 | true, |
mef | c5da571 | 2016-02-09 20:14:23 | [diff] [blame] | 28 | // QUIC User Agent ID. |
| 29 | "Default QUIC User Agent ID", |
pauljensen | 9041eb3c | 2015-12-09 12:29:01 | [diff] [blame] | 30 | // Enable SPDY. |
| 31 | true, |
xunjieli | 186d2bf | 2017-04-18 13:45:47 | [diff] [blame] | 32 | // Enable Brotli. |
| 33 | false, |
pauljensen | 9041eb3c | 2015-12-09 12:29:01 | [diff] [blame] | 34 | // 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. |
rtenneti | 6971c17 | 2016-01-15 20:12:10 | [diff] [blame] | 46 | "{\"QUIC\":{\"max_server_configs_stored_in_properties\":2," |
mef | c5da571 | 2016-02-09 20:14:23 | [diff] [blame] | 47 | "\"user_agent_id\":\"Custom QUIC UAID\"," |
rtenneti | 64e809d0 | 2015-12-11 00:26:20 | [diff] [blame] | 48 | "\"idle_connection_timeout_seconds\":300," |
Jana Iyengar | 903dec2 | 2017-11-28 00:44:23 | [diff] [blame] | 49 | "\"close_sessions_on_ip_change\":true," |
rtenneti | d073dd2 | 2016-08-04 01:58:33 | [diff] [blame] | 50 | "\"race_cert_verification\":true," |
pauljensen | e92c409 | 2015-12-09 19:13:48 | [diff] [blame] | 51 | "\"connection_options\":\"TIME,TBBR,REJ\"}," |
mgersh | af2c12c | 2016-08-22 16:33:54 | [diff] [blame] | 52 | "\"AsyncDNS\":{\"enable\":true}," |
xunjieli | d67295e | 2017-03-16 21:05:41 | [diff] [blame] | 53 | "\"UnknownOption\":{\"foo\":true}," |
mgersh | af2c12c | 2016-08-22 16:33:54 | [diff] [blame] | 54 | "\"HostResolverRules\":{\"host_resolver_rules\":" |
mgersh | b3fe808 | 2017-02-28 20:09:20 | [diff] [blame] | 55 | "\"MAP * 127.0.0.1\"}," |
| 56 | // See http://crbug.com/696569. |
mgersh | af9a923 | 2017-04-13 20:19:03 | [diff] [blame] | 57 | "\"disable_ipv6_on_wifi\":true}", |
pauljensen | 9041eb3c | 2015-12-09 12:29:01 | [diff] [blame] | 58 | // MockCertVerifier to use for testing purposes. |
tbansal | 7018e2a | 2016-06-25 00:40:39 | [diff] [blame] | 59 | std::unique_ptr<net::CertVerifier>(), |
| 60 | // Enable network quality estimator. |
kapishnikov | 385aa42 | 2016-07-01 20:53:02 | [diff] [blame] | 61 | false, |
| 62 | // Enable Public Key Pinning bypass for local trust anchors. |
rtenneti | 121f9fa | 2016-07-07 23:49:28 | [diff] [blame] | 63 | true, |
| 64 | // Certificate verifier cache data. |
| 65 | ""); |
xunjieli | f24ee5f | 2015-11-23 18:05:26 | [diff] [blame] | 66 | |
xunjieli | f24ee5f | 2015-11-23 18:05:26 | [diff] [blame] | 67 | net::URLRequestContextBuilder builder; |
pauljensen | e92c409 | 2015-12-09 19:13:48 | [diff] [blame] | 68 | net::NetLog net_log; |
David Benjamin | dc2f4b0 | 2017-07-27 23:59:02 | [diff] [blame] | 69 | config.ConfigureURLRequestContextBuilder(&builder, &net_log); |
xunjieli | d67295e | 2017-03-16 21:05:41 | [diff] [blame] | 70 | EXPECT_FALSE(config.effective_experimental_options->HasKey("UnknownOption")); |
xunjieli | f24ee5f | 2015-11-23 18:05:26 | [diff] [blame] | 71 | // Set a ProxyConfigService to avoid DCHECK failure when building. |
ricea | 85ec5795 | 2016-08-31 09:34:10 | [diff] [blame] | 72 | builder.set_proxy_config_service( |
Lily Houghton | ef02885 | 2017-12-06 20:52:30 | [diff] [blame] | 73 | std::make_unique<net::ProxyConfigServiceFixed>( |
ricea | 85ec5795 | 2016-08-31 09:34:10 | [diff] [blame] | 74 | net::ProxyConfig::CreateDirect())); |
dcheng | fe3745e624 | 2016-04-21 23:49:58 | [diff] [blame] | 75 | std::unique_ptr<net::URLRequestContext> context(builder.Build()); |
xunjieli | f24ee5f | 2015-11-23 18:05:26 | [diff] [blame] | 76 | 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 | |
mef | c5da571 | 2016-02-09 20:14:23 | [diff] [blame] | 85 | // Check Custom QUIC User Agent Id. |
| 86 | EXPECT_EQ("Custom QUIC UAID", params->quic_user_agent_id); |
| 87 | |
rtenneti | 6971c17 | 2016-01-15 20:12:10 | [diff] [blame] | 88 | // Check max_server_configs_stored_in_properties. |
| 89 | EXPECT_EQ(2u, params->quic_max_server_configs_stored_in_properties); |
xunjieli | f24ee5f | 2015-11-23 18:05:26 | [diff] [blame] | 90 | |
rtenneti | 64e809d0 | 2015-12-11 00:26:20 | [diff] [blame] | 91 | // Check idle_connection_timeout_seconds. |
| 92 | EXPECT_EQ(300, params->quic_idle_connection_timeout_seconds); |
| 93 | |
Jana Iyengar | 903dec2 | 2017-11-28 00:44:23 | [diff] [blame] | 94 | EXPECT_TRUE(params->quic_close_sessions_on_ip_change); |
jri | c69a8842 | 2016-02-12 19:48:36 | [diff] [blame] | 95 | EXPECT_FALSE(params->quic_migrate_sessions_on_network_change); |
Zhongyi Shi | 6479562 | 2017-11-20 02:21:49 | [diff] [blame] | 96 | EXPECT_FALSE(params->quic_migrate_sessions_on_network_change_v2); |
Zhongyi Shi | f4683a3 | 2017-12-01 00:03:28 | [diff] [blame] | 97 | EXPECT_FALSE(params->quic_migrate_sessions_early_v2); |
jri | d2656695 | 2016-02-04 21:06:42 | [diff] [blame] | 98 | |
rtenneti | d073dd2 | 2016-08-04 01:58:33 | [diff] [blame] | 99 | // Check race_cert_verification. |
| 100 | EXPECT_TRUE(params->quic_race_cert_verification); |
| 101 | |
Misha Efimov | 6395791 | 2017-12-06 07:13:26 | [diff] [blame] | 102 | #if defined(ENABLE_BUILT_IN_DNS) |
| 103 | // Check AsyncDNS resolver is enabled (not supported on iOS). |
tfh | ef3618f | 2016-01-11 23:07:08 | [diff] [blame] | 104 | EXPECT_TRUE(context->host_resolver()->GetDnsConfigAsValue()); |
Misha Efimov | 6395791 | 2017-12-06 07:13:26 | [diff] [blame] | 105 | #endif // defined(ENABLE_BUILT_IN_DNS) |
mgersh | af2c12c | 2016-08-22 16:33:54 | [diff] [blame] | 106 | |
mgersh | af9a923 | 2017-04-13 20:19:03 | [diff] [blame] | 107 | // Check IPv6 is disabled when on wifi. |
| 108 | EXPECT_TRUE(context->host_resolver()->GetNoIPv6OnWifi()); |
mgersh | b3fe808 | 2017-02-28 20:09:20 | [diff] [blame] | 109 | |
mgersh | af2c12c | 2016-08-22 16:33:54 | [diff] [blame] | 110 | net::HostResolver::RequestInfo info(net::HostPortPair("abcde", 80)); |
| 111 | net::AddressList addresses; |
| 112 | EXPECT_EQ(net::OK, context->host_resolver()->ResolveFromCache( |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 113 | info, &addresses, net::NetLogWithSource())); |
xunjieli | f24ee5f | 2015-11-23 18:05:26 | [diff] [blame] | 114 | } |
| 115 | |
mmenke | 51629db1 | 2017-06-28 13:34:12 | [diff] [blame] | 116 | TEST(URLRequestContextConfigTest, SetQuicConnectionMigrationOptions) { |
| 117 | base::test::ScopedTaskEnvironment scoped_task_environment_( |
| 118 | base::test::ScopedTaskEnvironment::MainThreadType::IO); |
| 119 | |
jri | c69a8842 | 2016-02-12 19:48:36 | [diff] [blame] | 120 | URLRequestContextConfig config( |
| 121 | // Enable QUIC. |
| 122 | true, |
| 123 | // QUIC User Agent ID. |
| 124 | "Default QUIC User Agent ID", |
| 125 | // Enable SPDY. |
| 126 | true, |
xunjieli | 186d2bf | 2017-04-18 13:45:47 | [diff] [blame] | 127 | // Enable Brotli. |
| 128 | false, |
jri | c69a8842 | 2016-02-12 19:48:36 | [diff] [blame] | 129 | // 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. |
jri | e68df0e | 2016-02-12 22:01:42 | [diff] [blame] | 141 | "{\"QUIC\":{\"migrate_sessions_on_network_change\":true," |
| 142 | "\"migrate_sessions_early\":true}}", |
jri | c69a8842 | 2016-02-12 19:48:36 | [diff] [blame] | 143 | // MockCertVerifier to use for testing purposes. |
tbansal | 7018e2a | 2016-06-25 00:40:39 | [diff] [blame] | 144 | std::unique_ptr<net::CertVerifier>(), |
| 145 | // Enable network quality estimator. |
kapishnikov | 385aa42 | 2016-07-01 20:53:02 | [diff] [blame] | 146 | false, |
| 147 | // Enable Public Key Pinning bypass for local trust anchors. |
rtenneti | 121f9fa | 2016-07-07 23:49:28 | [diff] [blame] | 148 | true, |
| 149 | // Certificate verifier cache data. |
| 150 | ""); |
jri | c69a8842 | 2016-02-12 19:48:36 | [diff] [blame] | 151 | |
| 152 | net::URLRequestContextBuilder builder; |
| 153 | net::NetLog net_log; |
David Benjamin | dc2f4b0 | 2017-07-27 23:59:02 | [diff] [blame] | 154 | config.ConfigureURLRequestContextBuilder(&builder, &net_log); |
jri | c69a8842 | 2016-02-12 19:48:36 | [diff] [blame] | 155 | // Set a ProxyConfigService to avoid DCHECK failure when building. |
ricea | 85ec5795 | 2016-08-31 09:34:10 | [diff] [blame] | 156 | builder.set_proxy_config_service( |
Lily Houghton | ef02885 | 2017-12-06 20:52:30 | [diff] [blame] | 157 | std::make_unique<net::ProxyConfigServiceFixed>( |
ricea | 85ec5795 | 2016-08-31 09:34:10 | [diff] [blame] | 158 | net::ProxyConfig::CreateDirect())); |
dcheng | fe3745e624 | 2016-04-21 23:49:58 | [diff] [blame] | 159 | std::unique_ptr<net::URLRequestContext> context(builder.Build()); |
jri | c69a8842 | 2016-02-12 19:48:36 | [diff] [blame] | 160 | const net::HttpNetworkSession::Params* params = |
| 161 | context->GetNetworkSessionParams(); |
| 162 | |
Jana Iyengar | 903dec2 | 2017-11-28 00:44:23 | [diff] [blame] | 163 | EXPECT_FALSE(params->quic_close_sessions_on_ip_change); |
jri | c69a8842 | 2016-02-12 19:48:36 | [diff] [blame] | 164 | EXPECT_TRUE(params->quic_migrate_sessions_on_network_change); |
jri | e68df0e | 2016-02-12 22:01:42 | [diff] [blame] | 165 | EXPECT_TRUE(params->quic_migrate_sessions_early); |
jri | c69a8842 | 2016-02-12 19:48:36 | [diff] [blame] | 166 | } |
| 167 | |
Yixin Wang | 10f477ed | 2017-11-21 04:20:20 | [diff] [blame] | 168 | TEST(URLRequestContextConfigTest, SetQuicConnectionMigrationV2Options) { |
Zhongyi Shi | 6479562 | 2017-11-20 02:21:49 | [diff] [blame] | 169 | 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 Shi | f4683a3 | 2017-12-01 00:03:28 | [diff] [blame] | 193 | "{\"QUIC\":{\"migrate_sessions_on_network_change_v2\":true," |
Zhongyi Shi | 73f23ca87 | 2017-12-13 18:37:13 | [diff] [blame] | 194 | "\"migrate_sessions_early_v2\":true," |
Zhongyi Shi | 8b1e43f | 2017-12-13 20:46:30 | [diff] [blame^] | 195 | "\"max_time_on_non_default_network_seconds\":10," |
| 196 | "\"max_migrations_to_non_default_network_on_path_degrading\":4}}", |
Zhongyi Shi | 6479562 | 2017-11-20 02:21:49 | [diff] [blame] | 197 | // 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 Houghton | ef02885 | 2017-12-06 20:52:30 | [diff] [blame] | 211 | std::make_unique<net::ProxyConfigServiceFixed>( |
Zhongyi Shi | 6479562 | 2017-11-20 02:21:49 | [diff] [blame] | 212 | 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 Shi | f4683a3 | 2017-12-01 00:03:28 | [diff] [blame] | 218 | EXPECT_TRUE(params->quic_migrate_sessions_early_v2); |
Zhongyi Shi | 73f23ca87 | 2017-12-13 18:37:13 | [diff] [blame] | 219 | EXPECT_EQ(base::TimeDelta::FromSeconds(10), |
| 220 | params->quic_max_time_on_non_default_network); |
Zhongyi Shi | 8b1e43f | 2017-12-13 20:46:30 | [diff] [blame^] | 221 | EXPECT_EQ( |
| 222 | 4, params->quic_max_migrations_to_non_default_network_on_path_degrading); |
Zhongyi Shi | 6479562 | 2017-11-20 02:21:49 | [diff] [blame] | 223 | } |
| 224 | |
Yixin Wang | 10f477ed | 2017-11-21 04:20:20 | [diff] [blame] | 225 | TEST(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 Houghton | ef02885 | 2017-12-06 20:52:30 | [diff] [blame] | 265 | std::make_unique<net::ProxyConfigServiceFixed>( |
Yixin Wang | 10f477ed | 2017-11-21 04:20:20 | [diff] [blame] | 266 | 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 Wang | 98387515 | 2017-11-21 20:30:13 | [diff] [blame] | 277 | TEST(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 Houghton | ef02885 | 2017-12-06 20:52:30 | [diff] [blame] | 318 | std::make_unique<net::ProxyConfigServiceFixed>( |
Yixin Wang | 98387515 | 2017-11-21 20:30:13 | [diff] [blame] | 319 | 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 Wang | 1875fdb | 2017-12-06 02:26:49 | [diff] [blame] | 328 | TEST(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 | |
juliatuttle | 50d9c4b | 2016-08-23 22:49:19 | [diff] [blame] | 387 | // See stale_host_resolver_unittest.cc for test of StaleDNS options. |
| 388 | |
xunjieli | f24ee5f | 2015-11-23 18:05:26 | [diff] [blame] | 389 | } // namespace cronet |