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 | |
Gyuyoung Kim | 6afb508 | 2018-01-19 13:35:57 | [diff] [blame^] | 7 | #include <memory> |
| 8 | |
mmenke | 51629db1 | 2017-06-28 13:34:12 | [diff] [blame] | 9 | #include "base/test/scoped_task_environment.h" |
tfh | ef3618f | 2016-01-11 23:07:08 | [diff] [blame] | 10 | #include "base/values.h" |
pauljensen | 9041eb3c | 2015-12-09 12:29:01 | [diff] [blame] | 11 | #include "net/cert/cert_verifier.h" |
xunjieli | f24ee5f | 2015-11-23 18:05:26 | [diff] [blame] | 12 | #include "net/http/http_network_session.h" |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 13 | #include "net/log/net_log.h" |
| 14 | #include "net/log/net_log_with_source.h" |
xunjieli | f24ee5f | 2015-11-23 18:05:26 | [diff] [blame] | 15 | #include "net/proxy/proxy_config.h" |
| 16 | #include "net/proxy/proxy_config_service_fixed.h" |
| 17 | #include "net/url_request/url_request_context.h" |
| 18 | #include "net/url_request/url_request_context_builder.h" |
| 19 | #include "testing/gtest/include/gtest/gtest.h" |
| 20 | |
| 21 | namespace cronet { |
| 22 | |
mmenke | 51629db1 | 2017-06-28 13:34:12 | [diff] [blame] | 23 | TEST(URLRequestContextConfigTest, TestExperimentalOptionParsing) { |
| 24 | base::test::ScopedTaskEnvironment scoped_task_environment_( |
| 25 | base::test::ScopedTaskEnvironment::MainThreadType::IO); |
| 26 | |
pauljensen | 9041eb3c | 2015-12-09 12:29:01 | [diff] [blame] | 27 | URLRequestContextConfig config( |
| 28 | // Enable QUIC. |
| 29 | true, |
mef | c5da571 | 2016-02-09 20:14:23 | [diff] [blame] | 30 | // QUIC User Agent ID. |
| 31 | "Default QUIC User Agent ID", |
pauljensen | 9041eb3c | 2015-12-09 12:29:01 | [diff] [blame] | 32 | // Enable SPDY. |
| 33 | true, |
xunjieli | 186d2bf | 2017-04-18 13:45:47 | [diff] [blame] | 34 | // Enable Brotli. |
| 35 | false, |
pauljensen | 9041eb3c | 2015-12-09 12:29:01 | [diff] [blame] | 36 | // Type of http cache. |
| 37 | URLRequestContextConfig::HttpCacheType::DISK, |
| 38 | // Max size of http cache in bytes. |
| 39 | 1024000, |
| 40 | // Disable caching for HTTP responses. Other information may be stored in |
| 41 | // the cache. |
| 42 | false, |
| 43 | // Storage path for http cache and cookie storage. |
| 44 | "/data/data/org.chromium.net/app_cronet_test/test_storage", |
| 45 | // User-Agent request header field. |
| 46 | "fake agent", |
| 47 | // JSON encoded experimental options. |
rtenneti | 6971c17 | 2016-01-15 20:12:10 | [diff] [blame] | 48 | "{\"QUIC\":{\"max_server_configs_stored_in_properties\":2," |
mef | c5da571 | 2016-02-09 20:14:23 | [diff] [blame] | 49 | "\"user_agent_id\":\"Custom QUIC UAID\"," |
rtenneti | 64e809d0 | 2015-12-11 00:26:20 | [diff] [blame] | 50 | "\"idle_connection_timeout_seconds\":300," |
Jana Iyengar | 903dec2 | 2017-11-28 00:44:23 | [diff] [blame] | 51 | "\"close_sessions_on_ip_change\":true," |
rtenneti | d073dd2 | 2016-08-04 01:58:33 | [diff] [blame] | 52 | "\"race_cert_verification\":true," |
pauljensen | e92c409 | 2015-12-09 19:13:48 | [diff] [blame] | 53 | "\"connection_options\":\"TIME,TBBR,REJ\"}," |
mgersh | af2c12c | 2016-08-22 16:33:54 | [diff] [blame] | 54 | "\"AsyncDNS\":{\"enable\":true}," |
xunjieli | d67295e | 2017-03-16 21:05:41 | [diff] [blame] | 55 | "\"UnknownOption\":{\"foo\":true}," |
mgersh | af2c12c | 2016-08-22 16:33:54 | [diff] [blame] | 56 | "\"HostResolverRules\":{\"host_resolver_rules\":" |
mgersh | b3fe808 | 2017-02-28 20:09:20 | [diff] [blame] | 57 | "\"MAP * 127.0.0.1\"}," |
| 58 | // See http://crbug.com/696569. |
mgersh | af9a923 | 2017-04-13 20:19:03 | [diff] [blame] | 59 | "\"disable_ipv6_on_wifi\":true}", |
pauljensen | 9041eb3c | 2015-12-09 12:29:01 | [diff] [blame] | 60 | // MockCertVerifier to use for testing purposes. |
tbansal | 7018e2a | 2016-06-25 00:40:39 | [diff] [blame] | 61 | std::unique_ptr<net::CertVerifier>(), |
| 62 | // Enable network quality estimator. |
kapishnikov | 385aa42 | 2016-07-01 20:53:02 | [diff] [blame] | 63 | false, |
| 64 | // Enable Public Key Pinning bypass for local trust anchors. |
rtenneti | 121f9fa | 2016-07-07 23:49:28 | [diff] [blame] | 65 | true, |
| 66 | // Certificate verifier cache data. |
| 67 | ""); |
xunjieli | f24ee5f | 2015-11-23 18:05:26 | [diff] [blame] | 68 | |
xunjieli | f24ee5f | 2015-11-23 18:05:26 | [diff] [blame] | 69 | net::URLRequestContextBuilder builder; |
pauljensen | e92c409 | 2015-12-09 19:13:48 | [diff] [blame] | 70 | net::NetLog net_log; |
David Benjamin | dc2f4b0 | 2017-07-27 23:59:02 | [diff] [blame] | 71 | config.ConfigureURLRequestContextBuilder(&builder, &net_log); |
xunjieli | d67295e | 2017-03-16 21:05:41 | [diff] [blame] | 72 | EXPECT_FALSE(config.effective_experimental_options->HasKey("UnknownOption")); |
xunjieli | f24ee5f | 2015-11-23 18:05:26 | [diff] [blame] | 73 | // Set a ProxyConfigService to avoid DCHECK failure when building. |
ricea | 85ec5795 | 2016-08-31 09:34:10 | [diff] [blame] | 74 | builder.set_proxy_config_service( |
Lily Houghton | ef02885 | 2017-12-06 20:52:30 | [diff] [blame] | 75 | std::make_unique<net::ProxyConfigServiceFixed>( |
ricea | 85ec5795 | 2016-08-31 09:34:10 | [diff] [blame] | 76 | net::ProxyConfig::CreateDirect())); |
dcheng | fe3745e624 | 2016-04-21 23:49:58 | [diff] [blame] | 77 | std::unique_ptr<net::URLRequestContext> context(builder.Build()); |
xunjieli | f24ee5f | 2015-11-23 18:05:26 | [diff] [blame] | 78 | const net::HttpNetworkSession::Params* params = |
| 79 | context->GetNetworkSessionParams(); |
| 80 | // Check Quic Connection options. |
| 81 | net::QuicTagVector quic_connection_options; |
| 82 | quic_connection_options.push_back(net::kTIME); |
| 83 | quic_connection_options.push_back(net::kTBBR); |
| 84 | quic_connection_options.push_back(net::kREJ); |
| 85 | EXPECT_EQ(quic_connection_options, params->quic_connection_options); |
| 86 | |
mef | c5da571 | 2016-02-09 20:14:23 | [diff] [blame] | 87 | // Check Custom QUIC User Agent Id. |
| 88 | EXPECT_EQ("Custom QUIC UAID", params->quic_user_agent_id); |
| 89 | |
rtenneti | 6971c17 | 2016-01-15 20:12:10 | [diff] [blame] | 90 | // Check max_server_configs_stored_in_properties. |
| 91 | EXPECT_EQ(2u, params->quic_max_server_configs_stored_in_properties); |
xunjieli | f24ee5f | 2015-11-23 18:05:26 | [diff] [blame] | 92 | |
rtenneti | 64e809d0 | 2015-12-11 00:26:20 | [diff] [blame] | 93 | // Check idle_connection_timeout_seconds. |
| 94 | EXPECT_EQ(300, params->quic_idle_connection_timeout_seconds); |
| 95 | |
Jana Iyengar | 903dec2 | 2017-11-28 00:44:23 | [diff] [blame] | 96 | EXPECT_TRUE(params->quic_close_sessions_on_ip_change); |
jri | c69a8842 | 2016-02-12 19:48:36 | [diff] [blame] | 97 | EXPECT_FALSE(params->quic_migrate_sessions_on_network_change); |
Zhongyi Shi | 6479562 | 2017-11-20 02:21:49 | [diff] [blame] | 98 | EXPECT_FALSE(params->quic_migrate_sessions_on_network_change_v2); |
Zhongyi Shi | f4683a3 | 2017-12-01 00:03:28 | [diff] [blame] | 99 | EXPECT_FALSE(params->quic_migrate_sessions_early_v2); |
jri | d2656695 | 2016-02-04 21:06:42 | [diff] [blame] | 100 | |
rtenneti | d073dd2 | 2016-08-04 01:58:33 | [diff] [blame] | 101 | // Check race_cert_verification. |
| 102 | EXPECT_TRUE(params->quic_race_cert_verification); |
| 103 | |
Misha Efimov | 6395791 | 2017-12-06 07:13:26 | [diff] [blame] | 104 | #if defined(ENABLE_BUILT_IN_DNS) |
| 105 | // Check AsyncDNS resolver is enabled (not supported on iOS). |
tfh | ef3618f | 2016-01-11 23:07:08 | [diff] [blame] | 106 | EXPECT_TRUE(context->host_resolver()->GetDnsConfigAsValue()); |
Misha Efimov | 6395791 | 2017-12-06 07:13:26 | [diff] [blame] | 107 | #endif // defined(ENABLE_BUILT_IN_DNS) |
mgersh | af2c12c | 2016-08-22 16:33:54 | [diff] [blame] | 108 | |
mgersh | af9a923 | 2017-04-13 20:19:03 | [diff] [blame] | 109 | // Check IPv6 is disabled when on wifi. |
| 110 | EXPECT_TRUE(context->host_resolver()->GetNoIPv6OnWifi()); |
mgersh | b3fe808 | 2017-02-28 20:09:20 | [diff] [blame] | 111 | |
mgersh | af2c12c | 2016-08-22 16:33:54 | [diff] [blame] | 112 | net::HostResolver::RequestInfo info(net::HostPortPair("abcde", 80)); |
| 113 | net::AddressList addresses; |
| 114 | EXPECT_EQ(net::OK, context->host_resolver()->ResolveFromCache( |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 115 | info, &addresses, net::NetLogWithSource())); |
xunjieli | f24ee5f | 2015-11-23 18:05:26 | [diff] [blame] | 116 | } |
| 117 | |
mmenke | 51629db1 | 2017-06-28 13:34:12 | [diff] [blame] | 118 | TEST(URLRequestContextConfigTest, SetQuicConnectionMigrationOptions) { |
| 119 | base::test::ScopedTaskEnvironment scoped_task_environment_( |
| 120 | base::test::ScopedTaskEnvironment::MainThreadType::IO); |
| 121 | |
jri | c69a8842 | 2016-02-12 19:48:36 | [diff] [blame] | 122 | URLRequestContextConfig config( |
| 123 | // Enable QUIC. |
| 124 | true, |
| 125 | // QUIC User Agent ID. |
| 126 | "Default QUIC User Agent ID", |
| 127 | // Enable SPDY. |
| 128 | true, |
xunjieli | 186d2bf | 2017-04-18 13:45:47 | [diff] [blame] | 129 | // Enable Brotli. |
| 130 | false, |
jri | c69a8842 | 2016-02-12 19:48:36 | [diff] [blame] | 131 | // Type of http cache. |
| 132 | URLRequestContextConfig::HttpCacheType::DISK, |
| 133 | // Max size of http cache in bytes. |
| 134 | 1024000, |
| 135 | // Disable caching for HTTP responses. Other information may be stored in |
| 136 | // the cache. |
| 137 | false, |
| 138 | // Storage path for http cache and cookie storage. |
| 139 | "/data/data/org.chromium.net/app_cronet_test/test_storage", |
| 140 | // User-Agent request header field. |
| 141 | "fake agent", |
| 142 | // JSON encoded experimental options. |
jri | e68df0e | 2016-02-12 22:01:42 | [diff] [blame] | 143 | "{\"QUIC\":{\"migrate_sessions_on_network_change\":true," |
| 144 | "\"migrate_sessions_early\":true}}", |
jri | c69a8842 | 2016-02-12 19:48:36 | [diff] [blame] | 145 | // MockCertVerifier to use for testing purposes. |
tbansal | 7018e2a | 2016-06-25 00:40:39 | [diff] [blame] | 146 | std::unique_ptr<net::CertVerifier>(), |
| 147 | // Enable network quality estimator. |
kapishnikov | 385aa42 | 2016-07-01 20:53:02 | [diff] [blame] | 148 | false, |
| 149 | // Enable Public Key Pinning bypass for local trust anchors. |
rtenneti | 121f9fa | 2016-07-07 23:49:28 | [diff] [blame] | 150 | true, |
| 151 | // Certificate verifier cache data. |
| 152 | ""); |
jri | c69a8842 | 2016-02-12 19:48:36 | [diff] [blame] | 153 | |
| 154 | net::URLRequestContextBuilder builder; |
| 155 | net::NetLog net_log; |
David Benjamin | dc2f4b0 | 2017-07-27 23:59:02 | [diff] [blame] | 156 | config.ConfigureURLRequestContextBuilder(&builder, &net_log); |
jri | c69a8842 | 2016-02-12 19:48:36 | [diff] [blame] | 157 | // Set a ProxyConfigService to avoid DCHECK failure when building. |
ricea | 85ec5795 | 2016-08-31 09:34:10 | [diff] [blame] | 158 | builder.set_proxy_config_service( |
Lily Houghton | ef02885 | 2017-12-06 20:52:30 | [diff] [blame] | 159 | std::make_unique<net::ProxyConfigServiceFixed>( |
ricea | 85ec5795 | 2016-08-31 09:34:10 | [diff] [blame] | 160 | net::ProxyConfig::CreateDirect())); |
dcheng | fe3745e624 | 2016-04-21 23:49:58 | [diff] [blame] | 161 | std::unique_ptr<net::URLRequestContext> context(builder.Build()); |
jri | c69a8842 | 2016-02-12 19:48:36 | [diff] [blame] | 162 | const net::HttpNetworkSession::Params* params = |
| 163 | context->GetNetworkSessionParams(); |
| 164 | |
Jana Iyengar | 903dec2 | 2017-11-28 00:44:23 | [diff] [blame] | 165 | EXPECT_FALSE(params->quic_close_sessions_on_ip_change); |
jri | c69a8842 | 2016-02-12 19:48:36 | [diff] [blame] | 166 | EXPECT_TRUE(params->quic_migrate_sessions_on_network_change); |
jri | e68df0e | 2016-02-12 22:01:42 | [diff] [blame] | 167 | EXPECT_TRUE(params->quic_migrate_sessions_early); |
jri | c69a8842 | 2016-02-12 19:48:36 | [diff] [blame] | 168 | } |
| 169 | |
Yixin Wang | 10f477ed | 2017-11-21 04:20:20 | [diff] [blame] | 170 | TEST(URLRequestContextConfigTest, SetQuicConnectionMigrationV2Options) { |
Zhongyi Shi | 6479562 | 2017-11-20 02:21:49 | [diff] [blame] | 171 | base::test::ScopedTaskEnvironment scoped_task_environment_( |
| 172 | base::test::ScopedTaskEnvironment::MainThreadType::IO); |
| 173 | |
| 174 | URLRequestContextConfig config( |
| 175 | // Enable QUIC. |
| 176 | true, |
| 177 | // QUIC User Agent ID. |
| 178 | "Default QUIC User Agent ID", |
| 179 | // Enable SPDY. |
| 180 | true, |
| 181 | // Enable Brotli. |
| 182 | false, |
| 183 | // Type of http cache. |
| 184 | URLRequestContextConfig::HttpCacheType::DISK, |
| 185 | // Max size of http cache in bytes. |
| 186 | 1024000, |
| 187 | // Disable caching for HTTP responses. Other information may be stored in |
| 188 | // the cache. |
| 189 | false, |
| 190 | // Storage path for http cache and cookie storage. |
| 191 | "/data/data/org.chromium.net/app_cronet_test/test_storage", |
| 192 | // User-Agent request header field. |
| 193 | "fake agent", |
| 194 | // JSON encoded experimental options. |
Zhongyi Shi | f4683a3 | 2017-12-01 00:03:28 | [diff] [blame] | 195 | "{\"QUIC\":{\"migrate_sessions_on_network_change_v2\":true," |
Zhongyi Shi | 73f23ca87 | 2017-12-13 18:37:13 | [diff] [blame] | 196 | "\"migrate_sessions_early_v2\":true," |
Zhongyi Shi | 8b1e43f | 2017-12-13 20:46:30 | [diff] [blame] | 197 | "\"max_time_on_non_default_network_seconds\":10," |
| 198 | "\"max_migrations_to_non_default_network_on_path_degrading\":4}}", |
Zhongyi Shi | 6479562 | 2017-11-20 02:21:49 | [diff] [blame] | 199 | // MockCertVerifier to use for testing purposes. |
| 200 | std::unique_ptr<net::CertVerifier>(), |
| 201 | // Enable network quality estimator. |
| 202 | false, |
| 203 | // Enable Public Key Pinning bypass for local trust anchors. |
| 204 | true, |
| 205 | // Certificate verifier cache data. |
| 206 | ""); |
| 207 | |
| 208 | net::URLRequestContextBuilder builder; |
| 209 | net::NetLog net_log; |
| 210 | config.ConfigureURLRequestContextBuilder(&builder, &net_log); |
| 211 | // Set a ProxyConfigService to avoid DCHECK failure when building. |
| 212 | builder.set_proxy_config_service( |
Lily Houghton | ef02885 | 2017-12-06 20:52:30 | [diff] [blame] | 213 | std::make_unique<net::ProxyConfigServiceFixed>( |
Zhongyi Shi | 6479562 | 2017-11-20 02:21:49 | [diff] [blame] | 214 | net::ProxyConfig::CreateDirect())); |
| 215 | std::unique_ptr<net::URLRequestContext> context(builder.Build()); |
| 216 | const net::HttpNetworkSession::Params* params = |
| 217 | context->GetNetworkSessionParams(); |
| 218 | |
| 219 | EXPECT_TRUE(params->quic_migrate_sessions_on_network_change_v2); |
Zhongyi Shi | f4683a3 | 2017-12-01 00:03:28 | [diff] [blame] | 220 | EXPECT_TRUE(params->quic_migrate_sessions_early_v2); |
Zhongyi Shi | 73f23ca87 | 2017-12-13 18:37:13 | [diff] [blame] | 221 | EXPECT_EQ(base::TimeDelta::FromSeconds(10), |
| 222 | params->quic_max_time_on_non_default_network); |
Zhongyi Shi | 8b1e43f | 2017-12-13 20:46:30 | [diff] [blame] | 223 | EXPECT_EQ( |
| 224 | 4, params->quic_max_migrations_to_non_default_network_on_path_degrading); |
Zhongyi Shi | 6479562 | 2017-11-20 02:21:49 | [diff] [blame] | 225 | } |
| 226 | |
Yixin Wang | 10f477ed | 2017-11-21 04:20:20 | [diff] [blame] | 227 | TEST(URLRequestContextConfigTest, SetQuicHostWhitelist) { |
| 228 | base::test::ScopedTaskEnvironment scoped_task_environment_( |
| 229 | base::test::ScopedTaskEnvironment::MainThreadType::IO); |
| 230 | |
| 231 | URLRequestContextConfig config( |
| 232 | // Enable QUIC. |
| 233 | true, |
| 234 | // QUIC User Agent ID. |
| 235 | "Default QUIC User Agent ID", |
| 236 | // Enable SPDY. |
| 237 | true, |
| 238 | // Enable Brotli. |
| 239 | false, |
| 240 | // Type of http cache. |
| 241 | URLRequestContextConfig::HttpCacheType::DISK, |
| 242 | // Max size of http cache in bytes. |
| 243 | 1024000, |
| 244 | // Disable caching for HTTP responses. Other information may be stored in |
| 245 | // the cache. |
| 246 | false, |
| 247 | // Storage path for http cache and cookie storage. |
| 248 | "/data/data/org.chromium.net/app_cronet_test/test_storage", |
| 249 | // User-Agent request header field. |
| 250 | "fake agent", |
| 251 | // JSON encoded experimental options. |
| 252 | "{\"QUIC\":{\"host_whitelist\":\"www.example.com,www.example.org\"}}", |
| 253 | // MockCertVerifier to use for testing purposes. |
| 254 | std::unique_ptr<net::CertVerifier>(), |
| 255 | // Enable network quality estimator. |
| 256 | false, |
| 257 | // Enable Public Key Pinning bypass for local trust anchors. |
| 258 | true, |
| 259 | // Certificate verifier cache data. |
| 260 | ""); |
| 261 | |
| 262 | net::URLRequestContextBuilder builder; |
| 263 | net::NetLog net_log; |
| 264 | config.ConfigureURLRequestContextBuilder(&builder, &net_log); |
| 265 | // Set a ProxyConfigService to avoid DCHECK failure when building. |
| 266 | builder.set_proxy_config_service( |
Lily Houghton | ef02885 | 2017-12-06 20:52:30 | [diff] [blame] | 267 | std::make_unique<net::ProxyConfigServiceFixed>( |
Yixin Wang | 10f477ed | 2017-11-21 04:20:20 | [diff] [blame] | 268 | net::ProxyConfig::CreateDirect())); |
| 269 | std::unique_ptr<net::URLRequestContext> context(builder.Build()); |
| 270 | const net::HttpNetworkSession::Params* params = |
| 271 | context->GetNetworkSessionParams(); |
| 272 | |
| 273 | EXPECT_TRUE( |
| 274 | base::ContainsKey(params->quic_host_whitelist, "www.example.com")); |
| 275 | EXPECT_TRUE( |
| 276 | base::ContainsKey(params->quic_host_whitelist, "www.example.org")); |
| 277 | } |
| 278 | |
Yixin Wang | 98387515 | 2017-11-21 20:30:13 | [diff] [blame] | 279 | TEST(URLRequestContextConfigTest, SetQuicMaxTimeBeforeCryptoHandshake) { |
| 280 | base::test::ScopedTaskEnvironment scoped_task_environment_( |
| 281 | base::test::ScopedTaskEnvironment::MainThreadType::IO); |
| 282 | |
| 283 | URLRequestContextConfig config( |
| 284 | // Enable QUIC. |
| 285 | true, |
| 286 | // QUIC User Agent ID. |
| 287 | "Default QUIC User Agent ID", |
| 288 | // Enable SPDY. |
| 289 | true, |
| 290 | // Enable Brotli. |
| 291 | false, |
| 292 | // Type of http cache. |
| 293 | URLRequestContextConfig::HttpCacheType::DISK, |
| 294 | // Max size of http cache in bytes. |
| 295 | 1024000, |
| 296 | // Disable caching for HTTP responses. Other information may be stored in |
| 297 | // the cache. |
| 298 | false, |
| 299 | // Storage path for http cache and cookie storage. |
| 300 | "/data/data/org.chromium.net/app_cronet_test/test_storage", |
| 301 | // User-Agent request header field. |
| 302 | "fake agent", |
| 303 | // JSON encoded experimental options. |
| 304 | "{\"QUIC\":{\"max_time_before_crypto_handshake_seconds\":7," |
| 305 | "\"max_idle_time_before_crypto_handshake_seconds\":11}}", |
| 306 | // MockCertVerifier to use for testing purposes. |
| 307 | std::unique_ptr<net::CertVerifier>(), |
| 308 | // Enable network quality estimator. |
| 309 | false, |
| 310 | // Enable Public Key Pinning bypass for local trust anchors. |
| 311 | true, |
| 312 | // Certificate verifier cache data. |
| 313 | ""); |
| 314 | |
| 315 | net::URLRequestContextBuilder builder; |
| 316 | net::NetLog net_log; |
| 317 | config.ConfigureURLRequestContextBuilder(&builder, &net_log); |
| 318 | // Set a ProxyConfigService to avoid DCHECK failure when building. |
| 319 | builder.set_proxy_config_service( |
Lily Houghton | ef02885 | 2017-12-06 20:52:30 | [diff] [blame] | 320 | std::make_unique<net::ProxyConfigServiceFixed>( |
Yixin Wang | 98387515 | 2017-11-21 20:30:13 | [diff] [blame] | 321 | net::ProxyConfig::CreateDirect())); |
| 322 | std::unique_ptr<net::URLRequestContext> context(builder.Build()); |
| 323 | const net::HttpNetworkSession::Params* params = |
| 324 | context->GetNetworkSessionParams(); |
| 325 | |
| 326 | EXPECT_EQ(7, params->quic_max_time_before_crypto_handshake_seconds); |
| 327 | EXPECT_EQ(11, params->quic_max_idle_time_before_crypto_handshake_seconds); |
| 328 | } |
| 329 | |
Yixin Wang | 1875fdb | 2017-12-06 02:26:49 | [diff] [blame] | 330 | TEST(URLURLRequestContextConfigTest, SetQuicConnectionOptions) { |
| 331 | base::test::ScopedTaskEnvironment scoped_task_environment_( |
| 332 | base::test::ScopedTaskEnvironment::MainThreadType::IO); |
| 333 | |
| 334 | URLRequestContextConfig config( |
| 335 | // Enable QUIC. |
| 336 | true, |
| 337 | // QUIC User Agent ID. |
| 338 | "Default QUIC User Agent ID", |
| 339 | // Enable SPDY. |
| 340 | true, |
| 341 | // Enable Brotli. |
| 342 | false, |
| 343 | // Type of http cache. |
| 344 | URLRequestContextConfig::HttpCacheType::DISK, |
| 345 | // Max size of http cache in bytes. |
| 346 | 1024000, |
| 347 | // Disable caching for HTTP responses. Other information may be stored in |
| 348 | // the cache. |
| 349 | false, |
| 350 | // Storage path for http cache and cookie storage. |
| 351 | "/data/data/org.chromium.net/app_cronet_test/test_storage", |
| 352 | // User-Agent request header field. |
| 353 | "fake agent", |
| 354 | // JSON encoded experimental options. |
| 355 | "{\"QUIC\":{\"connection_options\":\"TIME,TBBR,REJ\"," |
| 356 | "\"client_connection_options\":\"TBBR,1RTT\"}}", |
| 357 | // MockCertVerifier to use for testing purposes. |
| 358 | std::unique_ptr<net::CertVerifier>(), |
| 359 | // Enable network quality estimator. |
| 360 | false, |
| 361 | // Enable Public Key Pinning bypass for local trust anchors. |
| 362 | true, |
| 363 | // Certificate verifier cache data. |
| 364 | ""); |
| 365 | |
| 366 | net::URLRequestContextBuilder builder; |
| 367 | net::NetLog net_log; |
| 368 | config.ConfigureURLRequestContextBuilder(&builder, &net_log); |
| 369 | // Set a ProxyConfigService to avoid DCHECK failure when building. |
| 370 | builder.set_proxy_config_service( |
Gyuyoung Kim | 6afb508 | 2018-01-19 13:35:57 | [diff] [blame^] | 371 | std::make_unique<net::ProxyConfigServiceFixed>( |
Yixin Wang | 1875fdb | 2017-12-06 02:26:49 | [diff] [blame] | 372 | net::ProxyConfig::CreateDirect())); |
| 373 | std::unique_ptr<net::URLRequestContext> context(builder.Build()); |
| 374 | const net::HttpNetworkSession::Params* params = |
| 375 | context->GetNetworkSessionParams(); |
| 376 | |
| 377 | net::QuicTagVector connection_options; |
| 378 | connection_options.push_back(net::kTIME); |
| 379 | connection_options.push_back(net::kTBBR); |
| 380 | connection_options.push_back(net::kREJ); |
| 381 | EXPECT_EQ(connection_options, params->quic_connection_options); |
| 382 | |
| 383 | net::QuicTagVector client_connection_options; |
| 384 | client_connection_options.push_back(net::kTBBR); |
| 385 | client_connection_options.push_back(net::k1RTT); |
| 386 | EXPECT_EQ(client_connection_options, params->quic_client_connection_options); |
| 387 | } |
| 388 | |
juliatuttle | 50d9c4b | 2016-08-23 22:49:19 | [diff] [blame] | 389 | // See stale_host_resolver_unittest.cc for test of StaleDNS options. |
| 390 | |
xunjieli | f24ee5f | 2015-11-23 18:05:26 | [diff] [blame] | 391 | } // namespace cronet |