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