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