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 | |
Julia Tuttle | 3cc27a4a | 2018-04-25 15:57:06 | [diff] [blame] | 9 | #include "base/json/json_writer.h" |
Douglas Creager | a220947e | 2018-08-23 20:08:53 | [diff] [blame] | 10 | #include "base/strings/string_piece.h" |
mmenke | 51629db1 | 2017-06-28 13:34:12 | [diff] [blame] | 11 | #include "base/test/scoped_task_environment.h" |
Douglas Creager | a220947e | 2018-08-23 20:08:53 | [diff] [blame] | 12 | #include "base/test/values_test_util.h" |
tfh | ef3618f | 2016-01-11 23:07:08 | [diff] [blame] | 13 | #include "base/values.h" |
Zhongyi Shi | aa518c2 | 2018-06-15 04:37:36 | [diff] [blame] | 14 | #include "build/build_config.h" |
pauljensen | 9041eb3c | 2015-12-09 12:29:01 | [diff] [blame] | 15 | #include "net/cert/cert_verifier.h" |
xunjieli | f24ee5f | 2015-11-23 18:05:26 | [diff] [blame] | 16 | #include "net/http/http_network_session.h" |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 17 | #include "net/log/net_log.h" |
| 18 | #include "net/log/net_log_with_source.h" |
Lily Houghton | 582d462 | 2018-01-22 22:43:40 | [diff] [blame] | 19 | #include "net/proxy_resolution/proxy_config.h" |
| 20 | #include "net/proxy_resolution/proxy_config_service_fixed.h" |
Misha Efimov | d4ab3830 | 2018-01-30 23:56:42 | [diff] [blame] | 21 | #include "net/url_request/http_user_agent_settings.h" |
xunjieli | f24ee5f | 2015-11-23 18:05:26 | [diff] [blame] | 22 | #include "net/url_request/url_request_context.h" |
| 23 | #include "net/url_request/url_request_context_builder.h" |
| 24 | #include "testing/gtest/include/gtest/gtest.h" |
| 25 | |
Douglas Creager | a220947e | 2018-08-23 20:08:53 | [diff] [blame] | 26 | #if BUILDFLAG(ENABLE_REPORTING) |
| 27 | #include "net/network_error_logging/network_error_logging_service.h" |
| 28 | #include "net/reporting/reporting_service.h" |
| 29 | #endif // BUILDFLAG(ENABLE_REPORTING) |
| 30 | |
xunjieli | f24ee5f | 2015-11-23 18:05:26 | [diff] [blame] | 31 | namespace cronet { |
| 32 | |
Douglas Creager | a220947e | 2018-08-23 20:08:53 | [diff] [blame] | 33 | namespace { |
| 34 | |
Douglas Creager | a220947e | 2018-08-23 20:08:53 | [diff] [blame] | 35 | std::string WrapJsonHeader(base::StringPiece value) { |
| 36 | std::string result; |
| 37 | result.reserve(value.size() + 2); |
| 38 | result.push_back('['); |
| 39 | value.AppendToString(&result); |
| 40 | result.push_back(']'); |
| 41 | return result; |
| 42 | } |
| 43 | |
| 44 | // Returns whether two JSON-encoded headers contain the same content, ignoring |
| 45 | // irrelevant encoding issues like whitespace and map element ordering. |
| 46 | bool JsonHeaderEquals(base::StringPiece expected, base::StringPiece actual) { |
Lei Zhang | 9b9d579 | 2019-02-20 07:24:42 | [diff] [blame] | 47 | return base::test::ParseJson(WrapJsonHeader(expected)) == |
| 48 | base::test::ParseJson(WrapJsonHeader(actual)); |
Douglas Creager | a220947e | 2018-08-23 20:08:53 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | } // namespace |
| 52 | |
mmenke | 51629db1 | 2017-06-28 13:34:12 | [diff] [blame] | 53 | TEST(URLRequestContextConfigTest, TestExperimentalOptionParsing) { |
| 54 | base::test::ScopedTaskEnvironment scoped_task_environment_( |
| 55 | base::test::ScopedTaskEnvironment::MainThreadType::IO); |
| 56 | |
Julia Tuttle | 3cc27a4a | 2018-04-25 15:57:06 | [diff] [blame] | 57 | // Create JSON for experimental options. |
| 58 | base::DictionaryValue options; |
| 59 | options.SetPath({"QUIC", "max_server_configs_stored_in_properties"}, |
| 60 | base::Value(2)); |
| 61 | options.SetPath({"QUIC", "user_agent_id"}, base::Value("Custom QUIC UAID")); |
| 62 | options.SetPath({"QUIC", "idle_connection_timeout_seconds"}, |
| 63 | base::Value(300)); |
| 64 | options.SetPath({"QUIC", "close_sessions_on_ip_change"}, base::Value(true)); |
| 65 | options.SetPath({"QUIC", "race_cert_verification"}, base::Value(true)); |
| 66 | options.SetPath({"QUIC", "connection_options"}, base::Value("TIME,TBBR,REJ")); |
| 67 | options.SetPath({"AsyncDNS", "enable"}, base::Value(true)); |
| 68 | options.SetPath({"NetworkErrorLogging", "enable"}, base::Value(true)); |
Douglas Creager | a220947e | 2018-08-23 20:08:53 | [diff] [blame] | 69 | options.SetPath({"NetworkErrorLogging", "preloaded_report_to_headers"}, |
Lei Zhang | 9b9d579 | 2019-02-20 07:24:42 | [diff] [blame] | 70 | base::test::ParseJson(R"json( |
Douglas Creager | a220947e | 2018-08-23 20:08:53 | [diff] [blame] | 71 | [ |
| 72 | { |
| 73 | "origin": "https://test-origin/", |
| 74 | "value": { |
| 75 | "group": "test-group", |
| 76 | "max_age": 86400, |
| 77 | "endpoints": [ |
| 78 | {"url": "https://test-endpoint/"}, |
| 79 | ], |
| 80 | }, |
| 81 | }, |
| 82 | { |
| 83 | "origin": "https://test-origin-2/", |
| 84 | "value": [ |
| 85 | { |
| 86 | "group": "test-group-2", |
| 87 | "max_age": 86400, |
| 88 | "endpoints": [ |
| 89 | {"url": "https://test-endpoint-2/"}, |
| 90 | ], |
| 91 | }, |
| 92 | { |
| 93 | "group": "test-group-3", |
| 94 | "max_age": 86400, |
| 95 | "endpoints": [ |
| 96 | {"url": "https://test-endpoint-3/"}, |
| 97 | ], |
| 98 | }, |
| 99 | ], |
| 100 | }, |
| 101 | { |
| 102 | "origin": "https://value-is-missing/", |
| 103 | }, |
| 104 | { |
| 105 | "value": "origin is missing", |
| 106 | }, |
| 107 | { |
| 108 | "origin": 123, |
| 109 | "value": "origin is not a string", |
| 110 | }, |
| 111 | { |
| 112 | "origin": "this is not a URL", |
| 113 | "value": "origin not a URL", |
| 114 | }, |
| 115 | ] |
| 116 | )json")); |
| 117 | options.SetPath({"NetworkErrorLogging", "preloaded_nel_headers"}, |
Lei Zhang | 9b9d579 | 2019-02-20 07:24:42 | [diff] [blame] | 118 | base::test::ParseJson(R"json( |
Douglas Creager | a220947e | 2018-08-23 20:08:53 | [diff] [blame] | 119 | [ |
| 120 | { |
| 121 | "origin": "https://test-origin/", |
| 122 | "value": { |
| 123 | "report_to": "test-group", |
| 124 | "max_age": 86400, |
| 125 | }, |
| 126 | }, |
| 127 | ] |
| 128 | )json")); |
Julia Tuttle | 3cc27a4a | 2018-04-25 15:57:06 | [diff] [blame] | 129 | options.SetPath({"UnknownOption", "foo"}, base::Value(true)); |
| 130 | options.SetPath({"HostResolverRules", "host_resolver_rules"}, |
| 131 | base::Value("MAP * 127.0.0.1")); |
| 132 | // See http://crbug.com/696569. |
| 133 | options.SetKey("disable_ipv6_on_wifi", base::Value(true)); |
| 134 | std::string options_json; |
| 135 | EXPECT_TRUE(base::JSONWriter::Write(options, &options_json)); |
| 136 | |
pauljensen | 9041eb3c | 2015-12-09 12:29:01 | [diff] [blame] | 137 | URLRequestContextConfig config( |
| 138 | // Enable QUIC. |
| 139 | true, |
mef | c5da571 | 2016-02-09 20:14:23 | [diff] [blame] | 140 | // QUIC User Agent ID. |
| 141 | "Default QUIC User Agent ID", |
pauljensen | 9041eb3c | 2015-12-09 12:29:01 | [diff] [blame] | 142 | // Enable SPDY. |
| 143 | true, |
xunjieli | 186d2bf | 2017-04-18 13:45:47 | [diff] [blame] | 144 | // Enable Brotli. |
| 145 | false, |
pauljensen | 9041eb3c | 2015-12-09 12:29:01 | [diff] [blame] | 146 | // Type of http cache. |
| 147 | URLRequestContextConfig::HttpCacheType::DISK, |
| 148 | // Max size of http cache in bytes. |
| 149 | 1024000, |
| 150 | // Disable caching for HTTP responses. Other information may be stored in |
| 151 | // the cache. |
| 152 | false, |
| 153 | // Storage path for http cache and cookie storage. |
| 154 | "/data/data/org.chromium.net/app_cronet_test/test_storage", |
Misha Efimov | d4ab3830 | 2018-01-30 23:56:42 | [diff] [blame] | 155 | // Accept-Language request header field. |
| 156 | "foreign-language", |
pauljensen | 9041eb3c | 2015-12-09 12:29:01 | [diff] [blame] | 157 | // User-Agent request header field. |
| 158 | "fake agent", |
| 159 | // JSON encoded experimental options. |
Julia Tuttle | 3cc27a4a | 2018-04-25 15:57:06 | [diff] [blame] | 160 | options_json, |
pauljensen | 9041eb3c | 2015-12-09 12:29:01 | [diff] [blame] | 161 | // MockCertVerifier to use for testing purposes. |
tbansal | 7018e2a | 2016-06-25 00:40:39 | [diff] [blame] | 162 | std::unique_ptr<net::CertVerifier>(), |
| 163 | // Enable network quality estimator. |
kapishnikov | 385aa42 | 2016-07-01 20:53:02 | [diff] [blame] | 164 | false, |
| 165 | // Enable Public Key Pinning bypass for local trust anchors. |
Paul Jensen | 6a1ea3a | 2018-08-24 14:46:41 | [diff] [blame] | 166 | true, |
| 167 | // Optional network thread priority. |
| 168 | base::Optional<double>(42.0)); |
xunjieli | f24ee5f | 2015-11-23 18:05:26 | [diff] [blame] | 169 | |
xunjieli | f24ee5f | 2015-11-23 18:05:26 | [diff] [blame] | 170 | net::URLRequestContextBuilder builder; |
pauljensen | e92c409 | 2015-12-09 19:13:48 | [diff] [blame] | 171 | net::NetLog net_log; |
David Benjamin | dc2f4b0 | 2017-07-27 23:59:02 | [diff] [blame] | 172 | config.ConfigureURLRequestContextBuilder(&builder, &net_log); |
xunjieli | d67295e | 2017-03-16 21:05:41 | [diff] [blame] | 173 | EXPECT_FALSE(config.effective_experimental_options->HasKey("UnknownOption")); |
xunjieli | f24ee5f | 2015-11-23 18:05:26 | [diff] [blame] | 174 | // Set a ProxyConfigService to avoid DCHECK failure when building. |
ricea | 85ec5795 | 2016-08-31 09:34:10 | [diff] [blame] | 175 | builder.set_proxy_config_service( |
Lily Houghton | ef02885 | 2017-12-06 20:52:30 | [diff] [blame] | 176 | std::make_unique<net::ProxyConfigServiceFixed>( |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 177 | net::ProxyConfigWithAnnotation::CreateDirect())); |
dcheng | fe3745e624 | 2016-04-21 23:49:58 | [diff] [blame] | 178 | std::unique_ptr<net::URLRequestContext> context(builder.Build()); |
xunjieli | f24ee5f | 2015-11-23 18:05:26 | [diff] [blame] | 179 | const net::HttpNetworkSession::Params* params = |
| 180 | context->GetNetworkSessionParams(); |
| 181 | // Check Quic Connection options. |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 182 | quic::QuicTagVector quic_connection_options; |
| 183 | quic_connection_options.push_back(quic::kTIME); |
| 184 | quic_connection_options.push_back(quic::kTBBR); |
| 185 | quic_connection_options.push_back(quic::kREJ); |
xunjieli | f24ee5f | 2015-11-23 18:05:26 | [diff] [blame] | 186 | EXPECT_EQ(quic_connection_options, params->quic_connection_options); |
| 187 | |
mef | c5da571 | 2016-02-09 20:14:23 | [diff] [blame] | 188 | // Check Custom QUIC User Agent Id. |
| 189 | EXPECT_EQ("Custom QUIC UAID", params->quic_user_agent_id); |
| 190 | |
rtenneti | 6971c17 | 2016-01-15 20:12:10 | [diff] [blame] | 191 | // Check max_server_configs_stored_in_properties. |
| 192 | EXPECT_EQ(2u, params->quic_max_server_configs_stored_in_properties); |
xunjieli | f24ee5f | 2015-11-23 18:05:26 | [diff] [blame] | 193 | |
rtenneti | 64e809d0 | 2015-12-11 00:26:20 | [diff] [blame] | 194 | // Check idle_connection_timeout_seconds. |
| 195 | EXPECT_EQ(300, params->quic_idle_connection_timeout_seconds); |
| 196 | |
Jana Iyengar | 903dec2 | 2017-11-28 00:44:23 | [diff] [blame] | 197 | EXPECT_TRUE(params->quic_close_sessions_on_ip_change); |
Zhongyi Shi | 63574b7 | 2018-06-01 20:22:25 | [diff] [blame] | 198 | EXPECT_FALSE(params->quic_goaway_sessions_on_ip_change); |
Zhongyi Shi | 8ff38c1 | 2018-02-22 00:02:30 | [diff] [blame] | 199 | EXPECT_FALSE(params->quic_allow_server_migration); |
Zhongyi Shi | 6479562 | 2017-11-20 02:21:49 | [diff] [blame] | 200 | EXPECT_FALSE(params->quic_migrate_sessions_on_network_change_v2); |
Zhongyi Shi | f4683a3 | 2017-12-01 00:03:28 | [diff] [blame] | 201 | EXPECT_FALSE(params->quic_migrate_sessions_early_v2); |
Zhongyi Shi | ff359581bc | 2018-09-26 18:11:48 | [diff] [blame] | 202 | EXPECT_FALSE(params->quic_retry_on_alternate_network_before_handshake); |
Renjie | 94b9071 | 2018-10-18 21:03:19 | [diff] [blame] | 203 | EXPECT_FALSE(params->quic_race_stale_dns_on_connection); |
jri | d2656695 | 2016-02-04 21:06:42 | [diff] [blame] | 204 | |
rtenneti | d073dd2 | 2016-08-04 01:58:33 | [diff] [blame] | 205 | // Check race_cert_verification. |
| 206 | EXPECT_TRUE(params->quic_race_cert_verification); |
| 207 | |
Misha Efimov | 6395791 | 2017-12-06 07:13:26 | [diff] [blame] | 208 | #if defined(ENABLE_BUILT_IN_DNS) |
| 209 | // Check AsyncDNS resolver is enabled (not supported on iOS). |
tfh | ef3618f | 2016-01-11 23:07:08 | [diff] [blame] | 210 | EXPECT_TRUE(context->host_resolver()->GetDnsConfigAsValue()); |
Misha Efimov | 6395791 | 2017-12-06 07:13:26 | [diff] [blame] | 211 | #endif // defined(ENABLE_BUILT_IN_DNS) |
mgersh | af2c12c | 2016-08-22 16:33:54 | [diff] [blame] | 212 | |
Julia Tuttle | 9715d164 | 2018-01-29 17:02:26 | [diff] [blame] | 213 | #if BUILDFLAG(ENABLE_REPORTING) |
| 214 | // Check Reporting and Network Error Logging are enabled (can be disabled at |
| 215 | // build time). |
| 216 | EXPECT_TRUE(context->reporting_service()); |
Julia Tuttle | cba7d22 | 2018-02-23 19:37:27 | [diff] [blame] | 217 | EXPECT_TRUE(context->network_error_logging_service()); |
Julia Tuttle | 9715d164 | 2018-01-29 17:02:26 | [diff] [blame] | 218 | #endif // BUILDFLAG(ENABLE_REPORTING) |
| 219 | |
Douglas Creager | a220947e | 2018-08-23 20:08:53 | [diff] [blame] | 220 | ASSERT_EQ(2u, config.preloaded_report_to_headers.size()); |
| 221 | EXPECT_EQ(url::Origin::CreateFromNormalizedTuple("https", "test-origin", 443), |
| 222 | config.preloaded_report_to_headers[0].origin); |
| 223 | EXPECT_TRUE(JsonHeaderEquals( // |
| 224 | R"json( |
| 225 | { |
| 226 | "group": "test-group", |
| 227 | "max_age": 86400, |
| 228 | "endpoints": [ |
| 229 | {"url": "https://test-endpoint/"}, |
| 230 | ], |
| 231 | } |
| 232 | )json", |
| 233 | config.preloaded_report_to_headers[0].value)); |
| 234 | EXPECT_EQ( |
| 235 | url::Origin::CreateFromNormalizedTuple("https", "test-origin-2", 443), |
| 236 | config.preloaded_report_to_headers[1].origin); |
| 237 | EXPECT_TRUE(JsonHeaderEquals( // |
| 238 | R"json( |
| 239 | { |
| 240 | "group": "test-group-2", |
| 241 | "max_age": 86400, |
| 242 | "endpoints": [ |
| 243 | {"url": "https://test-endpoint-2/"}, |
| 244 | ], |
| 245 | }, |
| 246 | { |
| 247 | "group": "test-group-3", |
| 248 | "max_age": 86400, |
| 249 | "endpoints": [ |
| 250 | {"url": "https://test-endpoint-3/"}, |
| 251 | ], |
| 252 | } |
| 253 | )json", |
| 254 | config.preloaded_report_to_headers[1].value)); |
| 255 | |
| 256 | ASSERT_EQ(1u, config.preloaded_nel_headers.size()); |
| 257 | EXPECT_EQ(url::Origin::CreateFromNormalizedTuple("https", "test-origin", 443), |
| 258 | config.preloaded_nel_headers[0].origin); |
| 259 | EXPECT_TRUE(JsonHeaderEquals( // |
| 260 | R"json( |
| 261 | { |
| 262 | "report_to": "test-group", |
| 263 | "max_age": 86400, |
| 264 | } |
| 265 | )json", |
| 266 | config.preloaded_nel_headers[0].value)); |
| 267 | |
mgersh | af9a923 | 2017-04-13 20:19:03 | [diff] [blame] | 268 | // Check IPv6 is disabled when on wifi. |
| 269 | EXPECT_TRUE(context->host_resolver()->GetNoIPv6OnWifi()); |
mgersh | b3fe808 | 2017-02-28 20:09:20 | [diff] [blame] | 270 | |
mgersh | af2c12c | 2016-08-22 16:33:54 | [diff] [blame] | 271 | net::HostResolver::RequestInfo info(net::HostPortPair("abcde", 80)); |
| 272 | net::AddressList addresses; |
| 273 | EXPECT_EQ(net::OK, context->host_resolver()->ResolveFromCache( |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 274 | info, &addresses, net::NetLogWithSource())); |
Paul Jensen | 6a1ea3a | 2018-08-24 14:46:41 | [diff] [blame] | 275 | |
| 276 | EXPECT_TRUE(config.network_thread_priority); |
| 277 | EXPECT_EQ(42.0, config.network_thread_priority.value()); |
xunjieli | f24ee5f | 2015-11-23 18:05:26 | [diff] [blame] | 278 | } |
| 279 | |
Zhongyi Shi | 5724796 | 2018-11-05 20:03:52 | [diff] [blame] | 280 | TEST(URLRequestContextConfigTest, SetSupportedQuicVersion) { |
| 281 | base::test::ScopedTaskEnvironment scoped_task_environment_( |
| 282 | base::test::ScopedTaskEnvironment::MainThreadType::IO); |
| 283 | |
| 284 | URLRequestContextConfig config( |
| 285 | // Enable QUIC. |
| 286 | true, |
| 287 | // QUIC User Agent ID. |
| 288 | "Default QUIC User Agent ID", |
| 289 | // Enable SPDY. |
| 290 | true, |
| 291 | // Enable Brotli. |
| 292 | false, |
| 293 | // Type of http cache. |
| 294 | URLRequestContextConfig::HttpCacheType::DISK, |
| 295 | // Max size of http cache in bytes. |
| 296 | 1024000, |
| 297 | // Disable caching for HTTP responses. Other information may be stored in |
| 298 | // the cache. |
| 299 | false, |
| 300 | // Storage path for http cache and cookie storage. |
| 301 | "/data/data/org.chromium.net/app_cronet_test/test_storage", |
| 302 | // Accept-Language request header field. |
| 303 | "foreign-language", |
| 304 | // User-Agent request header field. |
| 305 | "fake agent", |
| 306 | // JSON encoded experimental options. |
| 307 | "{\"QUIC\":{\"quic_version\":\"QUIC_VERSION_44\"}}", |
| 308 | // MockCertVerifier to use for testing purposes. |
| 309 | std::unique_ptr<net::CertVerifier>(), |
| 310 | // Enable network quality estimator. |
| 311 | false, |
| 312 | // Enable Public Key Pinning bypass for local trust anchors. |
| 313 | true, |
| 314 | // Optional network thread priority. |
| 315 | base::Optional<double>()); |
| 316 | |
| 317 | net::URLRequestContextBuilder builder; |
| 318 | net::NetLog net_log; |
| 319 | config.ConfigureURLRequestContextBuilder(&builder, &net_log); |
| 320 | // Set a ProxyConfigService to avoid DCHECK failure when building. |
| 321 | builder.set_proxy_config_service( |
| 322 | std::make_unique<net::ProxyConfigServiceFixed>( |
| 323 | net::ProxyConfigWithAnnotation::CreateDirect())); |
| 324 | std::unique_ptr<net::URLRequestContext> context(builder.Build()); |
| 325 | const net::HttpNetworkSession::Params* params = |
| 326 | context->GetNetworkSessionParams(); |
| 327 | EXPECT_EQ(params->quic_supported_versions.size(), 1u); |
| 328 | EXPECT_EQ(params->quic_supported_versions[0], quic::QUIC_VERSION_44); |
| 329 | } |
| 330 | |
| 331 | TEST(URLRequestContextConfigTest, SetUnsupportedQuicVersion) { |
| 332 | base::test::ScopedTaskEnvironment scoped_task_environment_( |
| 333 | base::test::ScopedTaskEnvironment::MainThreadType::IO); |
| 334 | |
| 335 | URLRequestContextConfig config( |
| 336 | // Enable QUIC. |
| 337 | true, |
| 338 | // QUIC User Agent ID. |
| 339 | "Default QUIC User Agent ID", |
| 340 | // Enable SPDY. |
| 341 | true, |
| 342 | // Enable Brotli. |
| 343 | false, |
| 344 | // Type of http cache. |
| 345 | URLRequestContextConfig::HttpCacheType::DISK, |
| 346 | // Max size of http cache in bytes. |
| 347 | 1024000, |
| 348 | // Disable caching for HTTP responses. Other information may be stored in |
| 349 | // the cache. |
| 350 | false, |
| 351 | // Storage path for http cache and cookie storage. |
| 352 | "/data/data/org.chromium.net/app_cronet_test/test_storage", |
| 353 | // Accept-Language request header field. |
| 354 | "foreign-language", |
| 355 | // User-Agent request header field. |
| 356 | "fake agent", |
| 357 | // JSON encoded experimental options. |
| 358 | "{\"QUIC\":{\"quic_version\":\"QUIC_VERSION_33\"}}", |
| 359 | // MockCertVerifier to use for testing purposes. |
| 360 | std::unique_ptr<net::CertVerifier>(), |
| 361 | // Enable network quality estimator. |
| 362 | false, |
| 363 | // Enable Public Key Pinning bypass for local trust anchors. |
| 364 | true, |
| 365 | // Optional network thread priority. |
| 366 | base::Optional<double>()); |
| 367 | |
| 368 | net::URLRequestContextBuilder builder; |
| 369 | net::NetLog net_log; |
| 370 | config.ConfigureURLRequestContextBuilder(&builder, &net_log); |
| 371 | // Set a ProxyConfigService to avoid DCHECK failure when building. |
| 372 | builder.set_proxy_config_service( |
| 373 | std::make_unique<net::ProxyConfigServiceFixed>( |
| 374 | net::ProxyConfigWithAnnotation::CreateDirect())); |
| 375 | std::unique_ptr<net::URLRequestContext> context(builder.Build()); |
| 376 | const net::HttpNetworkSession::Params* params = |
| 377 | context->GetNetworkSessionParams(); |
| 378 | EXPECT_EQ(params->quic_supported_versions.size(), 1u); |
| 379 | EXPECT_EQ(params->quic_supported_versions[0], quic::QUIC_VERSION_43); |
| 380 | } |
| 381 | |
Zhongyi Shi | 8ff38c1 | 2018-02-22 00:02:30 | [diff] [blame] | 382 | TEST(URLRequestContextConfigTest, SetQuicServerMigrationOptions) { |
| 383 | base::test::ScopedTaskEnvironment scoped_task_environment_( |
| 384 | base::test::ScopedTaskEnvironment::MainThreadType::IO); |
| 385 | |
| 386 | URLRequestContextConfig config( |
| 387 | // Enable QUIC. |
| 388 | true, |
| 389 | // QUIC User Agent ID. |
| 390 | "Default QUIC User Agent ID", |
| 391 | // Enable SPDY. |
| 392 | true, |
| 393 | // Enable Brotli. |
| 394 | false, |
| 395 | // Type of http cache. |
| 396 | URLRequestContextConfig::HttpCacheType::DISK, |
| 397 | // Max size of http cache in bytes. |
| 398 | 1024000, |
| 399 | // Disable caching for HTTP responses. Other information may be stored in |
| 400 | // the cache. |
| 401 | false, |
| 402 | // Storage path for http cache and cookie storage. |
| 403 | "/data/data/org.chromium.net/app_cronet_test/test_storage", |
| 404 | // Accept-Language request header field. |
| 405 | "foreign-language", |
| 406 | // User-Agent request header field. |
| 407 | "fake agent", |
| 408 | // JSON encoded experimental options. |
| 409 | "{\"QUIC\":{\"allow_server_migration\":true}}", |
| 410 | // MockCertVerifier to use for testing purposes. |
| 411 | std::unique_ptr<net::CertVerifier>(), |
| 412 | // Enable network quality estimator. |
| 413 | false, |
| 414 | // Enable Public Key Pinning bypass for local trust anchors. |
Paul Jensen | 6a1ea3a | 2018-08-24 14:46:41 | [diff] [blame] | 415 | true, |
| 416 | // Optional network thread priority. |
| 417 | base::Optional<double>()); |
Zhongyi Shi | 8ff38c1 | 2018-02-22 00:02:30 | [diff] [blame] | 418 | |
| 419 | net::URLRequestContextBuilder builder; |
| 420 | net::NetLog net_log; |
| 421 | config.ConfigureURLRequestContextBuilder(&builder, &net_log); |
| 422 | // Set a ProxyConfigService to avoid DCHECK failure when building. |
| 423 | builder.set_proxy_config_service( |
| 424 | std::make_unique<net::ProxyConfigServiceFixed>( |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 425 | net::ProxyConfigWithAnnotation::CreateDirect())); |
Zhongyi Shi | 8ff38c1 | 2018-02-22 00:02:30 | [diff] [blame] | 426 | std::unique_ptr<net::URLRequestContext> context(builder.Build()); |
| 427 | const net::HttpNetworkSession::Params* params = |
| 428 | context->GetNetworkSessionParams(); |
| 429 | |
| 430 | EXPECT_FALSE(params->quic_close_sessions_on_ip_change); |
| 431 | EXPECT_TRUE(params->quic_allow_server_migration); |
| 432 | } |
| 433 | |
Zhongyi Shi | aa518c2 | 2018-06-15 04:37:36 | [diff] [blame] | 434 | // Test that goaway_sessions_on_ip_change is set on by default for iOS. |
| 435 | #if defined(OS_IOS) |
| 436 | #define MAYBE_SetQuicGoAwaySessionsOnIPChangeByDefault \ |
| 437 | SetQuicGoAwaySessionsOnIPChangeByDefault |
| 438 | #else |
| 439 | #define MAYBE_SetQuicGoAwaySessionsOnIPChangeByDefault \ |
| 440 | DISABLED_SetQuicGoAwaySessionsOnIPChangeByDefault |
| 441 | #endif |
| 442 | TEST(URLRequestContextConfigTest, |
| 443 | MAYBE_SetQuicGoAwaySessionsOnIPChangeByDefault) { |
| 444 | base::test::ScopedTaskEnvironment scoped_task_environment_( |
| 445 | base::test::ScopedTaskEnvironment::MainThreadType::IO); |
| 446 | |
| 447 | URLRequestContextConfig config( |
| 448 | // Enable QUIC. |
| 449 | true, |
| 450 | // QUIC User Agent ID. |
| 451 | "Default QUIC User Agent ID", |
| 452 | // Enable SPDY. |
| 453 | true, |
| 454 | // Enable Brotli. |
| 455 | false, |
| 456 | // Type of http cache. |
| 457 | URLRequestContextConfig::HttpCacheType::DISK, |
| 458 | // Max size of http cache in bytes. |
| 459 | 1024000, |
| 460 | // Disable caching for HTTP responses. Other information may be stored in |
| 461 | // the cache. |
| 462 | false, |
| 463 | // Storage path for http cache and cookie storage. |
| 464 | "/data/data/org.chromium.net/app_cronet_test/test_storage", |
| 465 | // Accept-Language request header field. |
| 466 | "foreign-language", |
| 467 | // User-Agent request header field. |
| 468 | "fake agent", |
| 469 | // JSON encoded experimental options. |
| 470 | "{\"QUIC\":{}}", |
| 471 | // MockCertVerifier to use for testing purposes. |
| 472 | std::unique_ptr<net::CertVerifier>(), |
| 473 | // Enable network quality estimator. |
| 474 | false, |
| 475 | // Enable Public Key Pinning bypass for local trust anchors. |
Paul Jensen | 6a1ea3a | 2018-08-24 14:46:41 | [diff] [blame] | 476 | true, |
| 477 | // Optional network thread priority. |
| 478 | base::Optional<double>()); |
Zhongyi Shi | aa518c2 | 2018-06-15 04:37:36 | [diff] [blame] | 479 | |
| 480 | net::URLRequestContextBuilder builder; |
| 481 | net::NetLog net_log; |
| 482 | config.ConfigureURLRequestContextBuilder(&builder, &net_log); |
| 483 | // Set a ProxyConfigService to avoid DCHECK failure when building. |
| 484 | builder.set_proxy_config_service( |
| 485 | std::make_unique<net::ProxyConfigServiceFixed>( |
| 486 | net::ProxyConfigWithAnnotation::CreateDirect())); |
| 487 | std::unique_ptr<net::URLRequestContext> context(builder.Build()); |
| 488 | const net::HttpNetworkSession::Params* params = |
| 489 | context->GetNetworkSessionParams(); |
| 490 | |
| 491 | EXPECT_FALSE(params->quic_close_sessions_on_ip_change); |
| 492 | EXPECT_TRUE(params->quic_goaway_sessions_on_ip_change); |
| 493 | } |
| 494 | |
| 495 | // Tests that goaway_sessions_on_ip_changes can be set on via |
| 496 | // experimental options on non-iOS. |
| 497 | #if !defined(OS_IOS) |
| 498 | #define MAYBE_SetQuicGoAwaySessionsOnIPChangeViaExperimentOptions \ |
| 499 | SetQuicGoAwaySessionsOnIPChangeViaExperimentOptions |
| 500 | #else |
| 501 | #define MAYBE_SetQuicGoAwaySessionsOnIPChangeViaExperimentOptions \ |
| 502 | DISABLED_SetQuicGoAwaySessionsOnIPChangeViaExperimentOptions |
| 503 | #endif |
| 504 | TEST(URLRequestContextConfigTest, |
| 505 | MAYBE_SetQuicGoAwaySessionsOnIPChangeViaExperimentOptions) { |
Zhongyi Shi | 63574b7 | 2018-06-01 20:22:25 | [diff] [blame] | 506 | base::test::ScopedTaskEnvironment scoped_task_environment_( |
| 507 | base::test::ScopedTaskEnvironment::MainThreadType::IO); |
| 508 | |
| 509 | URLRequestContextConfig config( |
| 510 | // Enable QUIC. |
| 511 | true, |
| 512 | // QUIC User Agent ID. |
| 513 | "Default QUIC User Agent ID", |
| 514 | // Enable SPDY. |
| 515 | true, |
| 516 | // Enable Brotli. |
| 517 | false, |
| 518 | // Type of http cache. |
| 519 | URLRequestContextConfig::HttpCacheType::DISK, |
| 520 | // Max size of http cache in bytes. |
| 521 | 1024000, |
| 522 | // Disable caching for HTTP responses. Other information may be stored in |
| 523 | // the cache. |
| 524 | false, |
| 525 | // Storage path for http cache and cookie storage. |
| 526 | "/data/data/org.chromium.net/app_cronet_test/test_storage", |
| 527 | // Accept-Language request header field. |
| 528 | "foreign-language", |
| 529 | // User-Agent request header field. |
| 530 | "fake agent", |
| 531 | // JSON encoded experimental options. |
| 532 | "{\"QUIC\":{\"goaway_sessions_on_ip_change\":true}}", |
| 533 | // MockCertVerifier to use for testing purposes. |
| 534 | std::unique_ptr<net::CertVerifier>(), |
| 535 | // Enable network quality estimator. |
| 536 | false, |
| 537 | // Enable Public Key Pinning bypass for local trust anchors. |
Paul Jensen | 6a1ea3a | 2018-08-24 14:46:41 | [diff] [blame] | 538 | true, |
| 539 | // Optional network thread priority. |
| 540 | base::Optional<double>()); |
Zhongyi Shi | 63574b7 | 2018-06-01 20:22:25 | [diff] [blame] | 541 | |
| 542 | net::URLRequestContextBuilder builder; |
| 543 | net::NetLog net_log; |
| 544 | config.ConfigureURLRequestContextBuilder(&builder, &net_log); |
| 545 | // Set a ProxyConfigService to avoid DCHECK failure when building. |
| 546 | builder.set_proxy_config_service( |
| 547 | std::make_unique<net::ProxyConfigServiceFixed>( |
| 548 | net::ProxyConfigWithAnnotation::CreateDirect())); |
| 549 | std::unique_ptr<net::URLRequestContext> context(builder.Build()); |
| 550 | const net::HttpNetworkSession::Params* params = |
| 551 | context->GetNetworkSessionParams(); |
| 552 | |
| 553 | EXPECT_FALSE(params->quic_close_sessions_on_ip_change); |
| 554 | EXPECT_TRUE(params->quic_goaway_sessions_on_ip_change); |
| 555 | } |
| 556 | |
Zhongyi Shi | aa518c2 | 2018-06-15 04:37:36 | [diff] [blame] | 557 | // Test that goaway_sessions_on_ip_change can be set to false via |
| 558 | // exprimental options on iOS. |
| 559 | #if defined(OS_IOS) |
| 560 | #define MAYBE_DisableQuicGoAwaySessionsOnIPChangeViaExperimentOptions \ |
| 561 | DisableQuicGoAwaySessionsOnIPChangeViaExperimentOptions |
| 562 | #else |
| 563 | #define MAYBE_DisableQuicGoAwaySessionsOnIPChangeViaExperimentOptions \ |
| 564 | DISABLED_DisableQuicGoAwaySessionsOnIPChangeViaExperimentOptions |
| 565 | #endif |
| 566 | TEST(URLRequestContextConfigTest, |
| 567 | MAYBE_DisableQuicGoAwaySessionsOnIPChangeViaExperimentOptions) { |
| 568 | base::test::ScopedTaskEnvironment scoped_task_environment_( |
| 569 | base::test::ScopedTaskEnvironment::MainThreadType::IO); |
| 570 | |
| 571 | URLRequestContextConfig config( |
| 572 | // Enable QUIC. |
| 573 | true, |
| 574 | // QUIC User Agent ID. |
| 575 | "Default QUIC User Agent ID", |
| 576 | // Enable SPDY. |
| 577 | true, |
| 578 | // Enable Brotli. |
| 579 | false, |
| 580 | // Type of http cache. |
| 581 | URLRequestContextConfig::HttpCacheType::DISK, |
| 582 | // Max size of http cache in bytes. |
| 583 | 1024000, |
| 584 | // Disable caching for HTTP responses. Other information may be stored in |
| 585 | // the cache. |
| 586 | false, |
| 587 | // Storage path for http cache and cookie storage. |
| 588 | "/data/data/org.chromium.net/app_cronet_test/test_storage", |
| 589 | // Accept-Language request header field. |
| 590 | "foreign-language", |
| 591 | // User-Agent request header field. |
| 592 | "fake agent", |
| 593 | // JSON encoded experimental options. |
| 594 | "{\"QUIC\":{\"goaway_sessions_on_ip_change\":false}}", |
| 595 | // MockCertVerifier to use for testing purposes. |
| 596 | std::unique_ptr<net::CertVerifier>(), |
| 597 | // Enable network quality estimator. |
| 598 | false, |
| 599 | // Enable Public Key Pinning bypass for local trust anchors. |
Paul Jensen | 6a1ea3a | 2018-08-24 14:46:41 | [diff] [blame] | 600 | true, |
| 601 | // Optional network thread priority. |
| 602 | base::Optional<double>()); |
Zhongyi Shi | aa518c2 | 2018-06-15 04:37:36 | [diff] [blame] | 603 | |
| 604 | net::URLRequestContextBuilder builder; |
| 605 | net::NetLog net_log; |
| 606 | config.ConfigureURLRequestContextBuilder(&builder, &net_log); |
| 607 | // Set a ProxyConfigService to avoid DCHECK failure when building. |
| 608 | builder.set_proxy_config_service( |
| 609 | std::make_unique<net::ProxyConfigServiceFixed>( |
| 610 | net::ProxyConfigWithAnnotation::CreateDirect())); |
| 611 | std::unique_ptr<net::URLRequestContext> context(builder.Build()); |
| 612 | const net::HttpNetworkSession::Params* params = |
| 613 | context->GetNetworkSessionParams(); |
| 614 | |
| 615 | EXPECT_FALSE(params->quic_close_sessions_on_ip_change); |
| 616 | EXPECT_FALSE(params->quic_goaway_sessions_on_ip_change); |
| 617 | } |
| 618 | |
Yixin Wang | 10f477ed | 2017-11-21 04:20:20 | [diff] [blame] | 619 | TEST(URLRequestContextConfigTest, SetQuicConnectionMigrationV2Options) { |
Zhongyi Shi | 6479562 | 2017-11-20 02:21:49 | [diff] [blame] | 620 | base::test::ScopedTaskEnvironment scoped_task_environment_( |
| 621 | base::test::ScopedTaskEnvironment::MainThreadType::IO); |
| 622 | |
| 623 | URLRequestContextConfig config( |
| 624 | // Enable QUIC. |
| 625 | true, |
| 626 | // QUIC User Agent ID. |
| 627 | "Default QUIC User Agent ID", |
| 628 | // Enable SPDY. |
| 629 | true, |
| 630 | // Enable Brotli. |
| 631 | false, |
| 632 | // Type of http cache. |
| 633 | URLRequestContextConfig::HttpCacheType::DISK, |
| 634 | // Max size of http cache in bytes. |
| 635 | 1024000, |
| 636 | // Disable caching for HTTP responses. Other information may be stored in |
| 637 | // the cache. |
| 638 | false, |
| 639 | // Storage path for http cache and cookie storage. |
| 640 | "/data/data/org.chromium.net/app_cronet_test/test_storage", |
Misha Efimov | d4ab3830 | 2018-01-30 23:56:42 | [diff] [blame] | 641 | // Accept-Language request header field. |
| 642 | "foreign-language", |
Zhongyi Shi | 6479562 | 2017-11-20 02:21:49 | [diff] [blame] | 643 | // User-Agent request header field. |
| 644 | "fake agent", |
| 645 | // JSON encoded experimental options. |
Zhongyi Shi | f4683a3 | 2017-12-01 00:03:28 | [diff] [blame] | 646 | "{\"QUIC\":{\"migrate_sessions_on_network_change_v2\":true," |
Zhongyi Shi | 73f23ca87 | 2017-12-13 18:37:13 | [diff] [blame] | 647 | "\"migrate_sessions_early_v2\":true," |
Zhongyi Shi | ff359581bc | 2018-09-26 18:11:48 | [diff] [blame] | 648 | "\"retry_on_alternate_network_before_handshake\":true," |
Zhongyi Shi | e01f2db | 2019-02-22 19:53:23 | [diff] [blame^] | 649 | "\"retransmittable_on_wire_timeout_milliseconds\":1000," |
Zhongyi Shi | bc85e3e | 2019-02-12 19:34:42 | [diff] [blame] | 650 | "\"idle_session_migration_period_seconds\":15," |
Zhongyi Shi | 8b1e43f | 2017-12-13 20:46:30 | [diff] [blame] | 651 | "\"max_time_on_non_default_network_seconds\":10," |
Zhongyi Shi | ee76076 | 2018-08-01 00:54:29 | [diff] [blame] | 652 | "\"max_migrations_to_non_default_network_on_write_error\":3," |
Zhongyi Shi | 8b1e43f | 2017-12-13 20:46:30 | [diff] [blame] | 653 | "\"max_migrations_to_non_default_network_on_path_degrading\":4}}", |
Zhongyi Shi | 6479562 | 2017-11-20 02:21:49 | [diff] [blame] | 654 | // MockCertVerifier to use for testing purposes. |
| 655 | std::unique_ptr<net::CertVerifier>(), |
| 656 | // Enable network quality estimator. |
| 657 | false, |
| 658 | // Enable Public Key Pinning bypass for local trust anchors. |
Paul Jensen | 6a1ea3a | 2018-08-24 14:46:41 | [diff] [blame] | 659 | true, |
| 660 | // Optional network thread priority. |
| 661 | base::Optional<double>()); |
Zhongyi Shi | 6479562 | 2017-11-20 02:21:49 | [diff] [blame] | 662 | |
| 663 | net::URLRequestContextBuilder builder; |
| 664 | net::NetLog net_log; |
| 665 | config.ConfigureURLRequestContextBuilder(&builder, &net_log); |
| 666 | // Set a ProxyConfigService to avoid DCHECK failure when building. |
| 667 | builder.set_proxy_config_service( |
Lily Houghton | ef02885 | 2017-12-06 20:52:30 | [diff] [blame] | 668 | std::make_unique<net::ProxyConfigServiceFixed>( |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 669 | net::ProxyConfigWithAnnotation::CreateDirect())); |
Zhongyi Shi | 6479562 | 2017-11-20 02:21:49 | [diff] [blame] | 670 | std::unique_ptr<net::URLRequestContext> context(builder.Build()); |
| 671 | const net::HttpNetworkSession::Params* params = |
| 672 | context->GetNetworkSessionParams(); |
| 673 | |
| 674 | EXPECT_TRUE(params->quic_migrate_sessions_on_network_change_v2); |
Zhongyi Shi | f4683a3 | 2017-12-01 00:03:28 | [diff] [blame] | 675 | EXPECT_TRUE(params->quic_migrate_sessions_early_v2); |
Zhongyi Shi | ff359581bc | 2018-09-26 18:11:48 | [diff] [blame] | 676 | EXPECT_TRUE(params->quic_retry_on_alternate_network_before_handshake); |
Zhongyi Shi | e01f2db | 2019-02-22 19:53:23 | [diff] [blame^] | 677 | EXPECT_EQ(1000, params->quic_retransmittable_on_wire_timeout_milliseconds); |
Zhongyi Shi | bc85e3e | 2019-02-12 19:34:42 | [diff] [blame] | 678 | EXPECT_EQ(base::TimeDelta::FromSeconds(15), |
| 679 | params->quic_idle_session_migration_period); |
Zhongyi Shi | 73f23ca87 | 2017-12-13 18:37:13 | [diff] [blame] | 680 | EXPECT_EQ(base::TimeDelta::FromSeconds(10), |
| 681 | params->quic_max_time_on_non_default_network); |
Zhongyi Shi | ee76076 | 2018-08-01 00:54:29 | [diff] [blame] | 682 | EXPECT_EQ(3, |
| 683 | params->quic_max_migrations_to_non_default_network_on_write_error); |
Zhongyi Shi | 8b1e43f | 2017-12-13 20:46:30 | [diff] [blame] | 684 | EXPECT_EQ( |
| 685 | 4, params->quic_max_migrations_to_non_default_network_on_path_degrading); |
Zhongyi Shi | 6479562 | 2017-11-20 02:21:49 | [diff] [blame] | 686 | } |
| 687 | |
Renjie | 94b9071 | 2018-10-18 21:03:19 | [diff] [blame] | 688 | TEST(URLRequestContextConfigTest, SetQuicStaleDNSracing) { |
| 689 | base::test::ScopedTaskEnvironment scoped_task_environment_( |
| 690 | base::test::ScopedTaskEnvironment::MainThreadType::IO); |
| 691 | |
| 692 | URLRequestContextConfig config( |
| 693 | // Enable QUIC. |
| 694 | true, |
| 695 | // QUIC User Agent ID. |
| 696 | "Default QUIC User Agent ID", |
| 697 | // Enable SPDY. |
| 698 | true, |
| 699 | // Enable Brotli. |
| 700 | false, |
| 701 | // Type of http cache. |
| 702 | URLRequestContextConfig::HttpCacheType::DISK, |
| 703 | // Max size of http cache in bytes. |
| 704 | 1024000, |
| 705 | // Disable caching for HTTP responses. Other information may be stored in |
| 706 | // the cache. |
| 707 | false, |
| 708 | // Storage path for http cache and cookie storage. |
| 709 | "/data/data/org.chromium.net/app_cronet_test/test_storage", |
| 710 | // Accept-Language request header field. |
| 711 | "foreign-language", |
| 712 | // User-Agent request header field. |
| 713 | "fake agent", |
| 714 | // JSON encoded experimental options. |
| 715 | "{\"QUIC\":{\"race_stale_dns_on_connection\":true}}", |
| 716 | // MockCertVerifier to use for testing purposes. |
| 717 | std::unique_ptr<net::CertVerifier>(), |
| 718 | // Enable network quality estimator. |
| 719 | false, |
| 720 | // Enable Public Key Pinning bypass for local trust anchors. |
| 721 | true, |
| 722 | // Optional network thread priority. |
| 723 | base::Optional<double>()); |
| 724 | |
| 725 | net::URLRequestContextBuilder builder; |
| 726 | net::NetLog net_log; |
| 727 | config.ConfigureURLRequestContextBuilder(&builder, &net_log); |
| 728 | // Set a ProxyConfigService to avoid DCHECK failure when building. |
| 729 | builder.set_proxy_config_service( |
| 730 | std::make_unique<net::ProxyConfigServiceFixed>( |
| 731 | net::ProxyConfigWithAnnotation::CreateDirect())); |
| 732 | std::unique_ptr<net::URLRequestContext> context(builder.Build()); |
| 733 | const net::HttpNetworkSession::Params* params = |
| 734 | context->GetNetworkSessionParams(); |
| 735 | |
| 736 | EXPECT_TRUE(params->quic_race_stale_dns_on_connection); |
| 737 | } |
| 738 | |
Yixin Wang | 10f477ed | 2017-11-21 04:20:20 | [diff] [blame] | 739 | TEST(URLRequestContextConfigTest, SetQuicHostWhitelist) { |
| 740 | base::test::ScopedTaskEnvironment scoped_task_environment_( |
| 741 | base::test::ScopedTaskEnvironment::MainThreadType::IO); |
| 742 | |
| 743 | URLRequestContextConfig config( |
| 744 | // Enable QUIC. |
| 745 | true, |
| 746 | // QUIC User Agent ID. |
| 747 | "Default QUIC User Agent ID", |
| 748 | // Enable SPDY. |
| 749 | true, |
| 750 | // Enable Brotli. |
| 751 | false, |
| 752 | // Type of http cache. |
| 753 | URLRequestContextConfig::HttpCacheType::DISK, |
| 754 | // Max size of http cache in bytes. |
| 755 | 1024000, |
| 756 | // Disable caching for HTTP responses. Other information may be stored in |
| 757 | // the cache. |
| 758 | false, |
| 759 | // Storage path for http cache and cookie storage. |
| 760 | "/data/data/org.chromium.net/app_cronet_test/test_storage", |
Misha Efimov | d4ab3830 | 2018-01-30 23:56:42 | [diff] [blame] | 761 | // Accept-Language request header field. |
| 762 | "foreign-language", |
Yixin Wang | 10f477ed | 2017-11-21 04:20:20 | [diff] [blame] | 763 | // User-Agent request header field. |
| 764 | "fake agent", |
| 765 | // JSON encoded experimental options. |
| 766 | "{\"QUIC\":{\"host_whitelist\":\"www.example.com,www.example.org\"}}", |
| 767 | // MockCertVerifier to use for testing purposes. |
| 768 | std::unique_ptr<net::CertVerifier>(), |
| 769 | // Enable network quality estimator. |
| 770 | false, |
| 771 | // Enable Public Key Pinning bypass for local trust anchors. |
Paul Jensen | 6a1ea3a | 2018-08-24 14:46:41 | [diff] [blame] | 772 | true, |
| 773 | // Optional network thread priority. |
| 774 | base::Optional<double>()); |
Yixin Wang | 10f477ed | 2017-11-21 04:20:20 | [diff] [blame] | 775 | |
| 776 | net::URLRequestContextBuilder builder; |
| 777 | net::NetLog net_log; |
| 778 | config.ConfigureURLRequestContextBuilder(&builder, &net_log); |
| 779 | // Set a ProxyConfigService to avoid DCHECK failure when building. |
| 780 | builder.set_proxy_config_service( |
Lily Houghton | ef02885 | 2017-12-06 20:52:30 | [diff] [blame] | 781 | std::make_unique<net::ProxyConfigServiceFixed>( |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 782 | net::ProxyConfigWithAnnotation::CreateDirect())); |
Yixin Wang | 10f477ed | 2017-11-21 04:20:20 | [diff] [blame] | 783 | std::unique_ptr<net::URLRequestContext> context(builder.Build()); |
| 784 | const net::HttpNetworkSession::Params* params = |
| 785 | context->GetNetworkSessionParams(); |
| 786 | |
| 787 | EXPECT_TRUE( |
| 788 | base::ContainsKey(params->quic_host_whitelist, "www.example.com")); |
| 789 | EXPECT_TRUE( |
| 790 | base::ContainsKey(params->quic_host_whitelist, "www.example.org")); |
| 791 | } |
| 792 | |
Yixin Wang | 98387515 | 2017-11-21 20:30:13 | [diff] [blame] | 793 | TEST(URLRequestContextConfigTest, SetQuicMaxTimeBeforeCryptoHandshake) { |
| 794 | base::test::ScopedTaskEnvironment scoped_task_environment_( |
| 795 | base::test::ScopedTaskEnvironment::MainThreadType::IO); |
| 796 | |
| 797 | URLRequestContextConfig config( |
| 798 | // Enable QUIC. |
| 799 | true, |
| 800 | // QUIC User Agent ID. |
| 801 | "Default QUIC User Agent ID", |
| 802 | // Enable SPDY. |
| 803 | true, |
| 804 | // Enable Brotli. |
| 805 | false, |
| 806 | // Type of http cache. |
| 807 | URLRequestContextConfig::HttpCacheType::DISK, |
| 808 | // Max size of http cache in bytes. |
| 809 | 1024000, |
| 810 | // Disable caching for HTTP responses. Other information may be stored in |
| 811 | // the cache. |
| 812 | false, |
| 813 | // Storage path for http cache and cookie storage. |
| 814 | "/data/data/org.chromium.net/app_cronet_test/test_storage", |
Misha Efimov | d4ab3830 | 2018-01-30 23:56:42 | [diff] [blame] | 815 | // Accept-Language request header field. |
| 816 | "foreign-language", |
Yixin Wang | 98387515 | 2017-11-21 20:30:13 | [diff] [blame] | 817 | // User-Agent request header field. |
| 818 | "fake agent", |
| 819 | // JSON encoded experimental options. |
| 820 | "{\"QUIC\":{\"max_time_before_crypto_handshake_seconds\":7," |
| 821 | "\"max_idle_time_before_crypto_handshake_seconds\":11}}", |
| 822 | // MockCertVerifier to use for testing purposes. |
| 823 | std::unique_ptr<net::CertVerifier>(), |
| 824 | // Enable network quality estimator. |
| 825 | false, |
| 826 | // Enable Public Key Pinning bypass for local trust anchors. |
Paul Jensen | 6a1ea3a | 2018-08-24 14:46:41 | [diff] [blame] | 827 | true, |
| 828 | // Optional network thread priority. |
| 829 | base::Optional<double>()); |
Yixin Wang | 98387515 | 2017-11-21 20:30:13 | [diff] [blame] | 830 | |
| 831 | net::URLRequestContextBuilder builder; |
| 832 | net::NetLog net_log; |
| 833 | config.ConfigureURLRequestContextBuilder(&builder, &net_log); |
| 834 | // Set a ProxyConfigService to avoid DCHECK failure when building. |
| 835 | builder.set_proxy_config_service( |
Lily Houghton | ef02885 | 2017-12-06 20:52:30 | [diff] [blame] | 836 | std::make_unique<net::ProxyConfigServiceFixed>( |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 837 | net::ProxyConfigWithAnnotation::CreateDirect())); |
Yixin Wang | 98387515 | 2017-11-21 20:30:13 | [diff] [blame] | 838 | std::unique_ptr<net::URLRequestContext> context(builder.Build()); |
| 839 | const net::HttpNetworkSession::Params* params = |
| 840 | context->GetNetworkSessionParams(); |
| 841 | |
| 842 | EXPECT_EQ(7, params->quic_max_time_before_crypto_handshake_seconds); |
| 843 | EXPECT_EQ(11, params->quic_max_idle_time_before_crypto_handshake_seconds); |
| 844 | } |
| 845 | |
Yixin Wang | 1875fdb | 2017-12-06 02:26:49 | [diff] [blame] | 846 | TEST(URLURLRequestContextConfigTest, SetQuicConnectionOptions) { |
| 847 | base::test::ScopedTaskEnvironment scoped_task_environment_( |
| 848 | base::test::ScopedTaskEnvironment::MainThreadType::IO); |
| 849 | |
| 850 | URLRequestContextConfig config( |
| 851 | // Enable QUIC. |
| 852 | true, |
| 853 | // QUIC User Agent ID. |
| 854 | "Default QUIC User Agent ID", |
| 855 | // Enable SPDY. |
| 856 | true, |
| 857 | // Enable Brotli. |
| 858 | false, |
| 859 | // Type of http cache. |
| 860 | URLRequestContextConfig::HttpCacheType::DISK, |
| 861 | // Max size of http cache in bytes. |
| 862 | 1024000, |
| 863 | // Disable caching for HTTP responses. Other information may be stored in |
| 864 | // the cache. |
| 865 | false, |
| 866 | // Storage path for http cache and cookie storage. |
| 867 | "/data/data/org.chromium.net/app_cronet_test/test_storage", |
Misha Efimov | d4ab3830 | 2018-01-30 23:56:42 | [diff] [blame] | 868 | // Accept-Language request header field. |
| 869 | "foreign-language", |
Yixin Wang | 1875fdb | 2017-12-06 02:26:49 | [diff] [blame] | 870 | // User-Agent request header field. |
| 871 | "fake agent", |
| 872 | // JSON encoded experimental options. |
| 873 | "{\"QUIC\":{\"connection_options\":\"TIME,TBBR,REJ\"," |
| 874 | "\"client_connection_options\":\"TBBR,1RTT\"}}", |
| 875 | // MockCertVerifier to use for testing purposes. |
| 876 | std::unique_ptr<net::CertVerifier>(), |
| 877 | // Enable network quality estimator. |
| 878 | false, |
| 879 | // Enable Public Key Pinning bypass for local trust anchors. |
Paul Jensen | 6a1ea3a | 2018-08-24 14:46:41 | [diff] [blame] | 880 | true, |
| 881 | // Optional network thread priority. |
| 882 | base::Optional<double>()); |
Yixin Wang | 1875fdb | 2017-12-06 02:26:49 | [diff] [blame] | 883 | |
| 884 | net::URLRequestContextBuilder builder; |
| 885 | net::NetLog net_log; |
| 886 | config.ConfigureURLRequestContextBuilder(&builder, &net_log); |
| 887 | // Set a ProxyConfigService to avoid DCHECK failure when building. |
| 888 | builder.set_proxy_config_service( |
Gyuyoung Kim | 6afb508 | 2018-01-19 13:35:57 | [diff] [blame] | 889 | std::make_unique<net::ProxyConfigServiceFixed>( |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 890 | net::ProxyConfigWithAnnotation::CreateDirect())); |
Yixin Wang | 1875fdb | 2017-12-06 02:26:49 | [diff] [blame] | 891 | std::unique_ptr<net::URLRequestContext> context(builder.Build()); |
| 892 | const net::HttpNetworkSession::Params* params = |
| 893 | context->GetNetworkSessionParams(); |
| 894 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 895 | quic::QuicTagVector connection_options; |
| 896 | connection_options.push_back(quic::kTIME); |
| 897 | connection_options.push_back(quic::kTBBR); |
| 898 | connection_options.push_back(quic::kREJ); |
Yixin Wang | 1875fdb | 2017-12-06 02:26:49 | [diff] [blame] | 899 | EXPECT_EQ(connection_options, params->quic_connection_options); |
| 900 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 901 | quic::QuicTagVector client_connection_options; |
| 902 | client_connection_options.push_back(quic::kTBBR); |
| 903 | client_connection_options.push_back(quic::k1RTT); |
Yixin Wang | 1875fdb | 2017-12-06 02:26:49 | [diff] [blame] | 904 | EXPECT_EQ(client_connection_options, params->quic_client_connection_options); |
| 905 | } |
| 906 | |
Misha Efimov | d4ab3830 | 2018-01-30 23:56:42 | [diff] [blame] | 907 | TEST(URLURLRequestContextConfigTest, SetAcceptLanguageAndUserAgent) { |
| 908 | base::test::ScopedTaskEnvironment scoped_task_environment_( |
| 909 | base::test::ScopedTaskEnvironment::MainThreadType::IO); |
| 910 | |
| 911 | URLRequestContextConfig config( |
| 912 | // Enable QUIC. |
| 913 | true, |
| 914 | // QUIC User Agent ID. |
| 915 | "Default QUIC User Agent ID", |
| 916 | // Enable SPDY. |
| 917 | true, |
| 918 | // Enable Brotli. |
| 919 | false, |
| 920 | // Type of http cache. |
| 921 | URLRequestContextConfig::HttpCacheType::DISK, |
| 922 | // Max size of http cache in bytes. |
| 923 | 1024000, |
| 924 | // Disable caching for HTTP responses. Other information may be stored in |
| 925 | // the cache. |
| 926 | false, |
| 927 | // Storage path for http cache and cookie storage. |
| 928 | "/data/data/org.chromium.net/app_cronet_test/test_storage", |
| 929 | // Accept-Language request header field. |
| 930 | "foreign-language", |
| 931 | // User-Agent request header field. |
| 932 | "fake agent", |
| 933 | // JSON encoded experimental options. |
| 934 | "{}", |
| 935 | // MockCertVerifier to use for testing purposes. |
| 936 | std::unique_ptr<net::CertVerifier>(), |
| 937 | // Enable network quality estimator. |
| 938 | false, |
| 939 | // Enable Public Key Pinning bypass for local trust anchors. |
Paul Jensen | 6a1ea3a | 2018-08-24 14:46:41 | [diff] [blame] | 940 | true, |
| 941 | // Optional network thread priority. |
| 942 | base::Optional<double>()); |
Misha Efimov | d4ab3830 | 2018-01-30 23:56:42 | [diff] [blame] | 943 | |
| 944 | net::URLRequestContextBuilder builder; |
| 945 | net::NetLog net_log; |
| 946 | config.ConfigureURLRequestContextBuilder(&builder, &net_log); |
| 947 | // Set a ProxyConfigService to avoid DCHECK failure when building. |
| 948 | builder.set_proxy_config_service( |
| 949 | std::make_unique<net::ProxyConfigServiceFixed>( |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 950 | net::ProxyConfigWithAnnotation::CreateDirect())); |
Misha Efimov | d4ab3830 | 2018-01-30 23:56:42 | [diff] [blame] | 951 | std::unique_ptr<net::URLRequestContext> context(builder.Build()); |
| 952 | EXPECT_EQ("foreign-language", |
| 953 | context->http_user_agent_settings()->GetAcceptLanguage()); |
| 954 | EXPECT_EQ("fake agent", context->http_user_agent_settings()->GetUserAgent()); |
| 955 | } |
| 956 | |
juliatuttle | 50d9c4b | 2016-08-23 22:49:19 | [diff] [blame] | 957 | // See stale_host_resolver_unittest.cc for test of StaleDNS options. |
| 958 | |
xunjieli | f24ee5f | 2015-11-23 18:05:26 | [diff] [blame] | 959 | } // namespace cronet |