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" |
Hans Wennborg | df87046c | 2020-04-28 11:06:24 | [diff] [blame] | 10 | #include "base/check.h" |
Julia Tuttle | 3cc27a4a | 2018-04-25 15:57:06 | [diff] [blame] | 11 | #include "base/json/json_writer.h" |
Hans Wennborg | df87046c | 2020-04-28 11:06:24 | [diff] [blame] | 12 | #include "base/notreached.h" |
Jan Wilken Dörrie | fb1d7b66 | 2020-02-04 11:10:23 | [diff] [blame] | 13 | #include "base/strings/strcat.h" |
Douglas Creager | a220947e | 2018-08-23 20:08:53 | [diff] [blame] | 14 | #include "base/strings/string_piece.h" |
Gabriel Charette | c710874 | 2019-08-23 03:31:40 | [diff] [blame] | 15 | #include "base/test/task_environment.h" |
Douglas Creager | a220947e | 2018-08-23 20:08:53 | [diff] [blame] | 16 | #include "base/test/values_test_util.h" |
tfh | ef3618f | 2016-01-11 23:07:08 | [diff] [blame] | 17 | #include "base/values.h" |
Zhongyi Shi | aa518c2 | 2018-06-15 04:37:36 | [diff] [blame] | 18 | #include "build/build_config.h" |
Eric Orth | e1cdd90 | 2019-02-26 02:52:46 | [diff] [blame] | 19 | #include "net/base/host_port_pair.h" |
Matt Menke | d732ea4 | 2019-03-08 12:05:00 | [diff] [blame] | 20 | #include "net/base/http_user_agent_settings.h" |
Eric Orth | e1cdd90 | 2019-02-26 02:52:46 | [diff] [blame] | 21 | #include "net/base/net_errors.h" |
Matt Menke | 32a243e | 2020-05-22 03:40:09 | [diff] [blame] | 22 | #include "net/base/network_isolation_key.h" |
pauljensen | 9041eb3c | 2015-12-09 12:29:01 | [diff] [blame] | 23 | #include "net/cert/cert_verifier.h" |
Eric Orth | e1cdd90 | 2019-02-26 02:52:46 | [diff] [blame] | 24 | #include "net/dns/host_resolver.h" |
Eric Orth | 607b6d8 | 2019-05-08 16:43:32 | [diff] [blame] | 25 | #include "net/dns/host_resolver_manager.h" |
xunjieli | f24ee5f | 2015-11-23 18:05:26 | [diff] [blame] | 26 | #include "net/http/http_network_session.h" |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 27 | #include "net/log/net_log_with_source.h" |
Lily Houghton | 582d462 | 2018-01-22 22:43:40 | [diff] [blame] | 28 | #include "net/proxy_resolution/proxy_config.h" |
| 29 | #include "net/proxy_resolution/proxy_config_service_fixed.h" |
xunjieli | f24ee5f | 2015-11-23 18:05:26 | [diff] [blame] | 30 | #include "net/url_request/url_request_context.h" |
| 31 | #include "net/url_request/url_request_context_builder.h" |
| 32 | #include "testing/gtest/include/gtest/gtest.h" |
| 33 | |
Douglas Creager | a220947e | 2018-08-23 20:08:53 | [diff] [blame] | 34 | #if BUILDFLAG(ENABLE_REPORTING) |
| 35 | #include "net/network_error_logging/network_error_logging_service.h" |
| 36 | #include "net/reporting/reporting_service.h" |
| 37 | #endif // BUILDFLAG(ENABLE_REPORTING) |
| 38 | |
xunjieli | f24ee5f | 2015-11-23 18:05:26 | [diff] [blame] | 39 | namespace cronet { |
| 40 | |
Douglas Creager | a220947e | 2018-08-23 20:08:53 | [diff] [blame] | 41 | namespace { |
| 42 | |
Douglas Creager | a220947e | 2018-08-23 20:08:53 | [diff] [blame] | 43 | std::string WrapJsonHeader(base::StringPiece value) { |
Jan Wilken Dörrie | fb1d7b66 | 2020-02-04 11:10:23 | [diff] [blame] | 44 | return base::StrCat({"[", value, "]"}); |
Douglas Creager | a220947e | 2018-08-23 20:08:53 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | // Returns whether two JSON-encoded headers contain the same content, ignoring |
| 48 | // irrelevant encoding issues like whitespace and map element ordering. |
| 49 | bool JsonHeaderEquals(base::StringPiece expected, base::StringPiece actual) { |
Lei Zhang | 9b9d579 | 2019-02-20 07:24:42 | [diff] [blame] | 50 | return base::test::ParseJson(WrapJsonHeader(expected)) == |
| 51 | base::test::ParseJson(WrapJsonHeader(actual)); |
Douglas Creager | a220947e | 2018-08-23 20:08:53 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | } // namespace |
| 55 | |
mmenke | 51629db1 | 2017-06-28 13:34:12 | [diff] [blame] | 56 | TEST(URLRequestContextConfigTest, TestExperimentalOptionParsing) { |
Gabriel Charette | dfa3604 | 2019-08-19 17:30:11 | [diff] [blame] | 57 | base::test::TaskEnvironment task_environment_( |
| 58 | base::test::TaskEnvironment::MainThreadType::IO); |
mmenke | 51629db1 | 2017-06-28 13:34:12 | [diff] [blame] | 59 | |
Julia Tuttle | 3cc27a4a | 2018-04-25 15:57:06 | [diff] [blame] | 60 | // Create JSON for experimental options. |
| 61 | base::DictionaryValue options; |
| 62 | options.SetPath({"QUIC", "max_server_configs_stored_in_properties"}, |
| 63 | base::Value(2)); |
| 64 | options.SetPath({"QUIC", "user_agent_id"}, base::Value("Custom QUIC UAID")); |
| 65 | options.SetPath({"QUIC", "idle_connection_timeout_seconds"}, |
| 66 | base::Value(300)); |
| 67 | options.SetPath({"QUIC", "close_sessions_on_ip_change"}, base::Value(true)); |
Julia Tuttle | 3cc27a4a | 2018-04-25 15:57:06 | [diff] [blame] | 68 | options.SetPath({"QUIC", "connection_options"}, base::Value("TIME,TBBR,REJ")); |
Ryan Hamilton | a31239f1 | 2019-09-25 21:01:00 | [diff] [blame] | 69 | options.SetPath( |
| 70 | {"QUIC", "set_quic_flags"}, |
David Schinazi | fb4bb56 | 2020-06-19 18:18:35 | [diff] [blame] | 71 | base::Value("FLAGS_quic_reloadable_flag_quic_testonly_default_false=true," |
| 72 | "FLAGS_quic_restart_flag_quic_testonly_default_true=false")); |
Julia Tuttle | 3cc27a4a | 2018-04-25 15:57:06 | [diff] [blame] | 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)); |
Yu Su | ca37f3c | 2020-10-09 20:02:23 | [diff] [blame] | 140 | options.SetPath({"QUIC", "ios_network_service_type"}, base::Value(2)); |
Julia Tuttle | 3cc27a4a | 2018-04-25 15:57:06 | [diff] [blame] | 141 | std::string options_json; |
| 142 | EXPECT_TRUE(base::JSONWriter::Write(options, &options_json)); |
| 143 | |
Ryan Hamilton | a31239f1 | 2019-09-25 21:01:00 | [diff] [blame] | 144 | // Initialize QUIC flags set by the config. |
David Schinazi | fb4bb56 | 2020-06-19 18:18:35 | [diff] [blame] | 145 | FLAGS_quic_reloadable_flag_quic_testonly_default_false = false; |
| 146 | FLAGS_quic_restart_flag_quic_testonly_default_true = true; |
Ryan Hamilton | a31239f1 | 2019-09-25 21:01:00 | [diff] [blame] | 147 | |
pauljensen | 9041eb3c | 2015-12-09 12:29:01 | [diff] [blame] | 148 | URLRequestContextConfig config( |
| 149 | // Enable QUIC. |
| 150 | true, |
mef | c5da571 | 2016-02-09 20:14:23 | [diff] [blame] | 151 | // QUIC User Agent ID. |
| 152 | "Default QUIC User Agent ID", |
pauljensen | 9041eb3c | 2015-12-09 12:29:01 | [diff] [blame] | 153 | // Enable SPDY. |
| 154 | true, |
xunjieli | 186d2bf | 2017-04-18 13:45:47 | [diff] [blame] | 155 | // Enable Brotli. |
| 156 | false, |
pauljensen | 9041eb3c | 2015-12-09 12:29:01 | [diff] [blame] | 157 | // Type of http cache. |
| 158 | URLRequestContextConfig::HttpCacheType::DISK, |
| 159 | // Max size of http cache in bytes. |
| 160 | 1024000, |
| 161 | // Disable caching for HTTP responses. Other information may be stored in |
| 162 | // the cache. |
| 163 | false, |
| 164 | // Storage path for http cache and cookie storage. |
| 165 | "/data/data/org.chromium.net/app_cronet_test/test_storage", |
Misha Efimov | d4ab3830 | 2018-01-30 23:56:42 | [diff] [blame] | 166 | // Accept-Language request header field. |
| 167 | "foreign-language", |
pauljensen | 9041eb3c | 2015-12-09 12:29:01 | [diff] [blame] | 168 | // User-Agent request header field. |
| 169 | "fake agent", |
| 170 | // JSON encoded experimental options. |
Julia Tuttle | 3cc27a4a | 2018-04-25 15:57:06 | [diff] [blame] | 171 | options_json, |
pauljensen | 9041eb3c | 2015-12-09 12:29:01 | [diff] [blame] | 172 | // MockCertVerifier to use for testing purposes. |
tbansal | 7018e2a | 2016-06-25 00:40:39 | [diff] [blame] | 173 | std::unique_ptr<net::CertVerifier>(), |
| 174 | // Enable network quality estimator. |
kapishnikov | 385aa42 | 2016-07-01 20:53:02 | [diff] [blame] | 175 | false, |
| 176 | // Enable Public Key Pinning bypass for local trust anchors. |
Paul Jensen | 6a1ea3a | 2018-08-24 14:46:41 | [diff] [blame] | 177 | true, |
| 178 | // Optional network thread priority. |
| 179 | base::Optional<double>(42.0)); |
xunjieli | f24ee5f | 2015-11-23 18:05:26 | [diff] [blame] | 180 | |
xunjieli | f24ee5f | 2015-11-23 18:05:26 | [diff] [blame] | 181 | net::URLRequestContextBuilder builder; |
Matt Mueller | de5dadf | 2019-11-27 20:11:58 | [diff] [blame] | 182 | config.ConfigureURLRequestContextBuilder(&builder); |
xunjieli | d67295e | 2017-03-16 21:05:41 | [diff] [blame] | 183 | EXPECT_FALSE(config.effective_experimental_options->HasKey("UnknownOption")); |
xunjieli | f24ee5f | 2015-11-23 18:05:26 | [diff] [blame] | 184 | // Set a ProxyConfigService to avoid DCHECK failure when building. |
ricea | 85ec5795 | 2016-08-31 09:34:10 | [diff] [blame] | 185 | builder.set_proxy_config_service( |
Lily Houghton | ef02885 | 2017-12-06 20:52:30 | [diff] [blame] | 186 | std::make_unique<net::ProxyConfigServiceFixed>( |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 187 | net::ProxyConfigWithAnnotation::CreateDirect())); |
dcheng | fe3745e624 | 2016-04-21 23:49:58 | [diff] [blame] | 188 | std::unique_ptr<net::URLRequestContext> context(builder.Build()); |
Victor Vasiliev | a1e66d7 | 2019-12-05 17:55:38 | [diff] [blame] | 189 | const net::QuicParams* quic_params = context->quic_context()->params(); |
xunjieli | f24ee5f | 2015-11-23 18:05:26 | [diff] [blame] | 190 | // Check Quic Connection options. |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 191 | quic::QuicTagVector quic_connection_options; |
| 192 | quic_connection_options.push_back(quic::kTIME); |
| 193 | quic_connection_options.push_back(quic::kTBBR); |
| 194 | quic_connection_options.push_back(quic::kREJ); |
Victor Vasiliev | a1e66d7 | 2019-12-05 17:55:38 | [diff] [blame] | 195 | EXPECT_EQ(quic_connection_options, quic_params->connection_options); |
xunjieli | f24ee5f | 2015-11-23 18:05:26 | [diff] [blame] | 196 | |
David Schinazi | fb4bb56 | 2020-06-19 18:18:35 | [diff] [blame] | 197 | // Check QUIC flags. |
| 198 | EXPECT_TRUE(FLAGS_quic_reloadable_flag_quic_testonly_default_false); |
| 199 | EXPECT_FALSE(FLAGS_quic_restart_flag_quic_testonly_default_true); |
Ryan Hamilton | a31239f1 | 2019-09-25 21:01:00 | [diff] [blame] | 200 | |
mef | c5da571 | 2016-02-09 20:14:23 | [diff] [blame] | 201 | // Check Custom QUIC User Agent Id. |
Victor Vasiliev | a1e66d7 | 2019-12-05 17:55:38 | [diff] [blame] | 202 | EXPECT_EQ("Custom QUIC UAID", quic_params->user_agent_id); |
mef | c5da571 | 2016-02-09 20:14:23 | [diff] [blame] | 203 | |
rtenneti | 6971c17 | 2016-01-15 20:12:10 | [diff] [blame] | 204 | // Check max_server_configs_stored_in_properties. |
Victor Vasiliev | a1e66d7 | 2019-12-05 17:55:38 | [diff] [blame] | 205 | EXPECT_EQ(2u, quic_params->max_server_configs_stored_in_properties); |
xunjieli | f24ee5f | 2015-11-23 18:05:26 | [diff] [blame] | 206 | |
Ryan Sleevi | 2e8255b | 2019-07-17 21:02:21 | [diff] [blame] | 207 | // Check idle_connection_timeout. |
Victor Vasiliev | a1e66d7 | 2019-12-05 17:55:38 | [diff] [blame] | 208 | EXPECT_EQ(300, quic_params->idle_connection_timeout.InSeconds()); |
rtenneti | 64e809d0 | 2015-12-11 00:26:20 | [diff] [blame] | 209 | |
Victor Vasiliev | a1e66d7 | 2019-12-05 17:55:38 | [diff] [blame] | 210 | EXPECT_TRUE(quic_params->close_sessions_on_ip_change); |
| 211 | EXPECT_FALSE(quic_params->goaway_sessions_on_ip_change); |
| 212 | EXPECT_FALSE(quic_params->allow_server_migration); |
| 213 | EXPECT_FALSE(quic_params->migrate_sessions_on_network_change_v2); |
| 214 | EXPECT_FALSE(quic_params->migrate_sessions_early_v2); |
| 215 | EXPECT_FALSE(quic_params->migrate_idle_sessions); |
| 216 | EXPECT_FALSE(quic_params->retry_on_alternate_network_before_handshake); |
| 217 | EXPECT_FALSE(quic_params->race_stale_dns_on_connection); |
| 218 | EXPECT_FALSE(quic_params->go_away_on_path_degrading); |
Renjie Tang | 55ba9ae | 2021-04-30 22:01:05 | [diff] [blame] | 219 | EXPECT_FALSE(quic_params->allow_port_migration); |
jri | d2656695 | 2016-02-04 21:06:42 | [diff] [blame] | 220 | |
Yu Su | ca37f3c | 2020-10-09 20:02:23 | [diff] [blame] | 221 | // Check network_service_type for iOS. |
| 222 | EXPECT_EQ(2, quic_params->ios_network_service_type); |
| 223 | |
Misha Efimov | 6395791 | 2017-12-06 07:13:26 | [diff] [blame] | 224 | #if defined(ENABLE_BUILT_IN_DNS) |
| 225 | // Check AsyncDNS resolver is enabled (not supported on iOS). |
tfh | ef3618f | 2016-01-11 23:07:08 | [diff] [blame] | 226 | EXPECT_TRUE(context->host_resolver()->GetDnsConfigAsValue()); |
Misha Efimov | 6395791 | 2017-12-06 07:13:26 | [diff] [blame] | 227 | #endif // defined(ENABLE_BUILT_IN_DNS) |
mgersh | af2c12c | 2016-08-22 16:33:54 | [diff] [blame] | 228 | |
Julia Tuttle | 9715d164 | 2018-01-29 17:02:26 | [diff] [blame] | 229 | #if BUILDFLAG(ENABLE_REPORTING) |
| 230 | // Check Reporting and Network Error Logging are enabled (can be disabled at |
| 231 | // build time). |
| 232 | EXPECT_TRUE(context->reporting_service()); |
Julia Tuttle | cba7d22 | 2018-02-23 19:37:27 | [diff] [blame] | 233 | EXPECT_TRUE(context->network_error_logging_service()); |
Julia Tuttle | 9715d164 | 2018-01-29 17:02:26 | [diff] [blame] | 234 | #endif // BUILDFLAG(ENABLE_REPORTING) |
| 235 | |
Douglas Creager | a220947e | 2018-08-23 20:08:53 | [diff] [blame] | 236 | ASSERT_EQ(2u, config.preloaded_report_to_headers.size()); |
| 237 | EXPECT_EQ(url::Origin::CreateFromNormalizedTuple("https", "test-origin", 443), |
| 238 | config.preloaded_report_to_headers[0].origin); |
| 239 | EXPECT_TRUE(JsonHeaderEquals( // |
| 240 | R"json( |
| 241 | { |
| 242 | "group": "test-group", |
| 243 | "max_age": 86400, |
| 244 | "endpoints": [ |
| 245 | {"url": "https://test-endpoint/"}, |
| 246 | ], |
| 247 | } |
| 248 | )json", |
| 249 | config.preloaded_report_to_headers[0].value)); |
| 250 | EXPECT_EQ( |
| 251 | url::Origin::CreateFromNormalizedTuple("https", "test-origin-2", 443), |
| 252 | config.preloaded_report_to_headers[1].origin); |
| 253 | EXPECT_TRUE(JsonHeaderEquals( // |
| 254 | R"json( |
| 255 | { |
| 256 | "group": "test-group-2", |
| 257 | "max_age": 86400, |
| 258 | "endpoints": [ |
| 259 | {"url": "https://test-endpoint-2/"}, |
| 260 | ], |
| 261 | }, |
| 262 | { |
| 263 | "group": "test-group-3", |
| 264 | "max_age": 86400, |
| 265 | "endpoints": [ |
| 266 | {"url": "https://test-endpoint-3/"}, |
| 267 | ], |
| 268 | } |
| 269 | )json", |
| 270 | config.preloaded_report_to_headers[1].value)); |
| 271 | |
| 272 | ASSERT_EQ(1u, config.preloaded_nel_headers.size()); |
| 273 | EXPECT_EQ(url::Origin::CreateFromNormalizedTuple("https", "test-origin", 443), |
| 274 | config.preloaded_nel_headers[0].origin); |
| 275 | EXPECT_TRUE(JsonHeaderEquals( // |
| 276 | R"json( |
| 277 | { |
| 278 | "report_to": "test-group", |
| 279 | "max_age": 86400, |
| 280 | } |
| 281 | )json", |
| 282 | config.preloaded_nel_headers[0].value)); |
| 283 | |
mgersh | af9a923 | 2017-04-13 20:19:03 | [diff] [blame] | 284 | // Check IPv6 is disabled when on wifi. |
Eric Orth | 607b6d8 | 2019-05-08 16:43:32 | [diff] [blame] | 285 | EXPECT_FALSE(context->host_resolver() |
| 286 | ->GetManagerForTesting() |
| 287 | ->check_ipv6_on_wifi_for_testing()); |
mgersh | b3fe808 | 2017-02-28 20:09:20 | [diff] [blame] | 288 | |
Eric Orth | e1cdd90 | 2019-02-26 02:52:46 | [diff] [blame] | 289 | // All host resolution expected to be mapped to an immediately-resolvable IP. |
| 290 | std::unique_ptr<net::HostResolver::ResolveHostRequest> resolve_request = |
Matt Menke | 32a243e | 2020-05-22 03:40:09 | [diff] [blame] | 291 | context->host_resolver()->CreateRequest( |
| 292 | net::HostPortPair("abcde", 80), net::NetworkIsolationKey(), |
| 293 | net::NetLogWithSource(), base::nullopt); |
Eric Orth | e1cdd90 | 2019-02-26 02:52:46 | [diff] [blame] | 294 | EXPECT_EQ(net::OK, resolve_request->Start( |
| 295 | base::BindOnce([](int error) { NOTREACHED(); }))); |
Paul Jensen | 6a1ea3a | 2018-08-24 14:46:41 | [diff] [blame] | 296 | |
| 297 | EXPECT_TRUE(config.network_thread_priority); |
| 298 | EXPECT_EQ(42.0, config.network_thread_priority.value()); |
xunjieli | f24ee5f | 2015-11-23 18:05:26 | [diff] [blame] | 299 | } |
| 300 | |
Zhongyi Shi | 5724796 | 2018-11-05 20:03:52 | [diff] [blame] | 301 | TEST(URLRequestContextConfigTest, SetSupportedQuicVersion) { |
David Schinazi | 84c58bb | 2020-06-04 20:14:33 | [diff] [blame] | 302 | // Note that this test covers the legacy mechanism which relies on |
| 303 | // QuicVersionToString. We should now be using ALPNs instead. |
Gabriel Charette | dfa3604 | 2019-08-19 17:30:11 | [diff] [blame] | 304 | base::test::TaskEnvironment task_environment_( |
| 305 | base::test::TaskEnvironment::MainThreadType::IO); |
Zhongyi Shi | 5724796 | 2018-11-05 20:03:52 | [diff] [blame] | 306 | |
David Schinazi | 84c58bb | 2020-06-04 20:14:33 | [diff] [blame] | 307 | quic::ParsedQuicVersion version = |
| 308 | quic::AllSupportedVersionsWithQuicCrypto().front(); |
| 309 | std::string experimental_options = |
| 310 | "{\"QUIC\":{\"quic_version\":\"" + |
| 311 | quic::QuicVersionToString(version.transport_version) + "\"}}"; |
| 312 | |
Zhongyi Shi | 5724796 | 2018-11-05 20:03:52 | [diff] [blame] | 313 | URLRequestContextConfig config( |
| 314 | // Enable QUIC. |
| 315 | true, |
| 316 | // QUIC User Agent ID. |
| 317 | "Default QUIC User Agent ID", |
| 318 | // Enable SPDY. |
| 319 | true, |
| 320 | // Enable Brotli. |
| 321 | false, |
| 322 | // Type of http cache. |
| 323 | URLRequestContextConfig::HttpCacheType::DISK, |
| 324 | // Max size of http cache in bytes. |
| 325 | 1024000, |
| 326 | // Disable caching for HTTP responses. Other information may be stored in |
| 327 | // the cache. |
| 328 | false, |
| 329 | // Storage path for http cache and cookie storage. |
| 330 | "/data/data/org.chromium.net/app_cronet_test/test_storage", |
| 331 | // Accept-Language request header field. |
| 332 | "foreign-language", |
| 333 | // User-Agent request header field. |
| 334 | "fake agent", |
| 335 | // JSON encoded experimental options. |
David Schinazi | 84c58bb | 2020-06-04 20:14:33 | [diff] [blame] | 336 | experimental_options, |
Zhongyi Shi | 5724796 | 2018-11-05 20:03:52 | [diff] [blame] | 337 | // MockCertVerifier to use for testing purposes. |
| 338 | std::unique_ptr<net::CertVerifier>(), |
| 339 | // Enable network quality estimator. |
| 340 | false, |
| 341 | // Enable Public Key Pinning bypass for local trust anchors. |
| 342 | true, |
| 343 | // Optional network thread priority. |
| 344 | base::Optional<double>()); |
| 345 | |
| 346 | net::URLRequestContextBuilder builder; |
Matt Mueller | de5dadf | 2019-11-27 20:11:58 | [diff] [blame] | 347 | config.ConfigureURLRequestContextBuilder(&builder); |
Zhongyi Shi | 5724796 | 2018-11-05 20:03:52 | [diff] [blame] | 348 | // Set a ProxyConfigService to avoid DCHECK failure when building. |
| 349 | builder.set_proxy_config_service( |
| 350 | std::make_unique<net::ProxyConfigServiceFixed>( |
| 351 | net::ProxyConfigWithAnnotation::CreateDirect())); |
| 352 | std::unique_ptr<net::URLRequestContext> context(builder.Build()); |
Victor Vasiliev | a1e66d7 | 2019-12-05 17:55:38 | [diff] [blame] | 353 | const net::QuicParams* quic_params = context->quic_context()->params(); |
| 354 | EXPECT_EQ(quic_params->supported_versions.size(), 1u); |
David Schinazi | 84c58bb | 2020-06-04 20:14:33 | [diff] [blame] | 355 | EXPECT_EQ(quic_params->supported_versions[0], version); |
Zhongyi Shi | 5724796 | 2018-11-05 20:03:52 | [diff] [blame] | 356 | } |
| 357 | |
Ryan Hamilton | 209227b | 2020-01-17 01:29:05 | [diff] [blame] | 358 | TEST(URLRequestContextConfigTest, SetSupportedQuicVersionByAlpn) { |
| 359 | base::test::TaskEnvironment task_environment_( |
| 360 | base::test::TaskEnvironment::MainThreadType::IO); |
| 361 | |
David Schinazi | 84c58bb | 2020-06-04 20:14:33 | [diff] [blame] | 362 | quic::ParsedQuicVersion version = quic::AllSupportedVersions().front(); |
| 363 | std::string experimental_options = |
| 364 | "{\"QUIC\":{\"quic_version\":\"" + quic::AlpnForVersion(version) + "\"}}"; |
| 365 | |
Ryan Hamilton | 209227b | 2020-01-17 01:29:05 | [diff] [blame] | 366 | URLRequestContextConfig config( |
| 367 | // Enable QUIC. |
| 368 | true, |
| 369 | // QUIC User Agent ID. |
| 370 | "Default QUIC User Agent ID", |
| 371 | // Enable SPDY. |
| 372 | true, |
| 373 | // Enable Brotli. |
| 374 | false, |
| 375 | // Type of http cache. |
| 376 | URLRequestContextConfig::HttpCacheType::DISK, |
| 377 | // Max size of http cache in bytes. |
| 378 | 1024000, |
| 379 | // Disable caching for HTTP responses. Other information may be stored in |
| 380 | // the cache. |
| 381 | false, |
| 382 | // Storage path for http cache and cookie storage. |
| 383 | "/data/data/org.chromium.net/app_cronet_test/test_storage", |
| 384 | // Accept-Language request header field. |
| 385 | "foreign-language", |
| 386 | // User-Agent request header field. |
| 387 | "fake agent", |
| 388 | // JSON encoded experimental options. |
David Schinazi | 84c58bb | 2020-06-04 20:14:33 | [diff] [blame] | 389 | experimental_options, |
Ryan Hamilton | 209227b | 2020-01-17 01:29:05 | [diff] [blame] | 390 | // MockCertVerifier to use for testing purposes. |
| 391 | std::unique_ptr<net::CertVerifier>(), |
| 392 | // Enable network quality estimator. |
| 393 | false, |
| 394 | // Enable Public Key Pinning bypass for local trust anchors. |
| 395 | true, |
| 396 | // Optional network thread priority. |
| 397 | base::Optional<double>()); |
| 398 | |
| 399 | net::URLRequestContextBuilder builder; |
| 400 | config.ConfigureURLRequestContextBuilder(&builder); |
| 401 | // Set a ProxyConfigService to avoid DCHECK failure when building. |
| 402 | builder.set_proxy_config_service( |
| 403 | std::make_unique<net::ProxyConfigServiceFixed>( |
| 404 | net::ProxyConfigWithAnnotation::CreateDirect())); |
| 405 | std::unique_ptr<net::URLRequestContext> context(builder.Build()); |
| 406 | const net::QuicParams* quic_params = context->quic_context()->params(); |
| 407 | EXPECT_EQ(quic_params->supported_versions.size(), 1u); |
David Schinazi | 84c58bb | 2020-06-04 20:14:33 | [diff] [blame] | 408 | EXPECT_EQ(quic_params->supported_versions[0], version); |
Ryan Hamilton | 209227b | 2020-01-17 01:29:05 | [diff] [blame] | 409 | } |
| 410 | |
Zhongyi Shi | 5724796 | 2018-11-05 20:03:52 | [diff] [blame] | 411 | TEST(URLRequestContextConfigTest, SetUnsupportedQuicVersion) { |
Gabriel Charette | dfa3604 | 2019-08-19 17:30:11 | [diff] [blame] | 412 | base::test::TaskEnvironment task_environment_( |
| 413 | base::test::TaskEnvironment::MainThreadType::IO); |
Zhongyi Shi | 5724796 | 2018-11-05 20:03:52 | [diff] [blame] | 414 | |
| 415 | URLRequestContextConfig config( |
| 416 | // Enable QUIC. |
| 417 | true, |
| 418 | // QUIC User Agent ID. |
| 419 | "Default QUIC User Agent ID", |
| 420 | // Enable SPDY. |
| 421 | true, |
| 422 | // Enable Brotli. |
| 423 | false, |
| 424 | // Type of http cache. |
| 425 | URLRequestContextConfig::HttpCacheType::DISK, |
| 426 | // Max size of http cache in bytes. |
| 427 | 1024000, |
| 428 | // Disable caching for HTTP responses. Other information may be stored in |
| 429 | // the cache. |
| 430 | false, |
| 431 | // Storage path for http cache and cookie storage. |
| 432 | "/data/data/org.chromium.net/app_cronet_test/test_storage", |
| 433 | // Accept-Language request header field. |
| 434 | "foreign-language", |
| 435 | // User-Agent request header field. |
| 436 | "fake agent", |
| 437 | // JSON encoded experimental options. |
David Schinazi | 84c58bb | 2020-06-04 20:14:33 | [diff] [blame] | 438 | "{\"QUIC\":{\"quic_version\":\"h3-Q047\"}}", |
Zhongyi Shi | 5724796 | 2018-11-05 20:03:52 | [diff] [blame] | 439 | // MockCertVerifier to use for testing purposes. |
| 440 | std::unique_ptr<net::CertVerifier>(), |
| 441 | // Enable network quality estimator. |
| 442 | false, |
| 443 | // Enable Public Key Pinning bypass for local trust anchors. |
| 444 | true, |
| 445 | // Optional network thread priority. |
| 446 | base::Optional<double>()); |
| 447 | |
| 448 | net::URLRequestContextBuilder builder; |
Matt Mueller | de5dadf | 2019-11-27 20:11:58 | [diff] [blame] | 449 | config.ConfigureURLRequestContextBuilder(&builder); |
Zhongyi Shi | 5724796 | 2018-11-05 20:03:52 | [diff] [blame] | 450 | // Set a ProxyConfigService to avoid DCHECK failure when building. |
| 451 | builder.set_proxy_config_service( |
| 452 | std::make_unique<net::ProxyConfigServiceFixed>( |
| 453 | net::ProxyConfigWithAnnotation::CreateDirect())); |
| 454 | std::unique_ptr<net::URLRequestContext> context(builder.Build()); |
Victor Vasiliev | a1e66d7 | 2019-12-05 17:55:38 | [diff] [blame] | 455 | const net::QuicParams* quic_params = context->quic_context()->params(); |
David Schinazi | 1c76e03 | 2020-09-19 00:54:14 | [diff] [blame] | 456 | EXPECT_EQ(quic_params->supported_versions, |
| 457 | net::DefaultSupportedQuicVersions()); |
Zhongyi Shi | 5724796 | 2018-11-05 20:03:52 | [diff] [blame] | 458 | } |
| 459 | |
David Schinazi | abbf0250 | 2020-09-25 10:29:31 | [diff] [blame] | 460 | TEST(URLRequestContextConfigTest, SetObsoleteQuicVersion) { |
| 461 | // This test configures cronet with an obsolete QUIC version and validates |
| 462 | // that cronet ignores that version and uses the default versions. |
| 463 | base::test::TaskEnvironment task_environment_( |
| 464 | base::test::TaskEnvironment::MainThreadType::IO); |
| 465 | |
| 466 | URLRequestContextConfig config( |
| 467 | // Enable QUIC. |
| 468 | true, |
| 469 | // QUIC User Agent ID. |
| 470 | "Default QUIC User Agent ID", |
| 471 | // Enable SPDY. |
| 472 | true, |
| 473 | // Enable Brotli. |
| 474 | false, |
| 475 | // Type of http cache. |
| 476 | URLRequestContextConfig::HttpCacheType::DISK, |
| 477 | // Max size of http cache in bytes. |
| 478 | 1024000, |
| 479 | // Disable caching for HTTP responses. Other information may be stored in |
| 480 | // the cache. |
| 481 | false, |
| 482 | // Storage path for http cache and cookie storage. |
| 483 | "/data/data/org.chromium.net/app_cronet_test/test_storage", |
| 484 | // Accept-Language request header field. |
| 485 | "foreign-language", |
| 486 | // User-Agent request header field. |
| 487 | "fake agent", |
| 488 | // JSON encoded experimental options. |
| 489 | std::string("{\"QUIC\":{\"quic_version\":\"") + |
| 490 | quic::AlpnForVersion(net::ObsoleteQuicVersions().back()) + "\"}}", |
| 491 | // MockCertVerifier to use for testing purposes. |
| 492 | std::unique_ptr<net::CertVerifier>(), |
| 493 | // Enable network quality estimator. |
| 494 | false, |
| 495 | // Enable Public Key Pinning bypass for local trust anchors. |
| 496 | true, |
| 497 | // Optional network thread priority. |
| 498 | base::Optional<double>()); |
| 499 | |
| 500 | net::URLRequestContextBuilder builder; |
| 501 | config.ConfigureURLRequestContextBuilder(&builder); |
| 502 | // Set a ProxyConfigService to avoid DCHECK failure when building. |
| 503 | builder.set_proxy_config_service( |
| 504 | std::make_unique<net::ProxyConfigServiceFixed>( |
| 505 | net::ProxyConfigWithAnnotation::CreateDirect())); |
| 506 | std::unique_ptr<net::URLRequestContext> context(builder.Build()); |
| 507 | const net::QuicParams* quic_params = context->quic_context()->params(); |
| 508 | EXPECT_EQ(quic_params->supported_versions, |
| 509 | net::DefaultSupportedQuicVersions()); |
| 510 | } |
| 511 | |
| 512 | TEST(URLRequestContextConfigTest, SetObsoleteQuicVersionWhenAllowed) { |
| 513 | // This test configures cronet with an obsolete QUIC version and explicitly |
| 514 | // allows it, then validates that cronet uses that version. |
| 515 | base::test::TaskEnvironment task_environment_( |
| 516 | base::test::TaskEnvironment::MainThreadType::IO); |
| 517 | |
| 518 | URLRequestContextConfig config( |
| 519 | // Enable QUIC. |
| 520 | true, |
| 521 | // QUIC User Agent ID. |
| 522 | "Default QUIC User Agent ID", |
| 523 | // Enable SPDY. |
| 524 | true, |
| 525 | // Enable Brotli. |
| 526 | false, |
| 527 | // Type of http cache. |
| 528 | URLRequestContextConfig::HttpCacheType::DISK, |
| 529 | // Max size of http cache in bytes. |
| 530 | 1024000, |
| 531 | // Disable caching for HTTP responses. Other information may be stored in |
| 532 | // the cache. |
| 533 | false, |
| 534 | // Storage path for http cache and cookie storage. |
| 535 | "/data/data/org.chromium.net/app_cronet_test/test_storage", |
| 536 | // Accept-Language request header field. |
| 537 | "foreign-language", |
| 538 | // User-Agent request header field. |
| 539 | "fake agent", |
| 540 | // JSON encoded experimental options. |
| 541 | std::string("{\"QUIC\":{\"quic_version\":\"") + |
| 542 | quic::AlpnForVersion(net::ObsoleteQuicVersions().back()) + |
| 543 | "\",\"obsolete_versions_allowed\":true}}", |
| 544 | // MockCertVerifier to use for testing purposes. |
| 545 | std::unique_ptr<net::CertVerifier>(), |
| 546 | // Enable network quality estimator. |
| 547 | false, |
| 548 | // Enable Public Key Pinning bypass for local trust anchors. |
| 549 | true, |
| 550 | // Optional network thread priority. |
| 551 | base::Optional<double>()); |
| 552 | |
| 553 | net::URLRequestContextBuilder builder; |
| 554 | config.ConfigureURLRequestContextBuilder(&builder); |
| 555 | // Set a ProxyConfigService to avoid DCHECK failure when building. |
| 556 | builder.set_proxy_config_service( |
| 557 | std::make_unique<net::ProxyConfigServiceFixed>( |
| 558 | net::ProxyConfigWithAnnotation::CreateDirect())); |
| 559 | std::unique_ptr<net::URLRequestContext> context(builder.Build()); |
| 560 | const net::QuicParams* quic_params = context->quic_context()->params(); |
| 561 | quic::ParsedQuicVersionVector supported_versions = { |
| 562 | net::ObsoleteQuicVersions().back()}; |
| 563 | EXPECT_EQ(quic_params->supported_versions, supported_versions); |
| 564 | } |
| 565 | |
Zhongyi Shi | 8ff38c1 | 2018-02-22 00:02:30 | [diff] [blame] | 566 | TEST(URLRequestContextConfigTest, SetQuicServerMigrationOptions) { |
Gabriel Charette | dfa3604 | 2019-08-19 17:30:11 | [diff] [blame] | 567 | base::test::TaskEnvironment task_environment_( |
| 568 | base::test::TaskEnvironment::MainThreadType::IO); |
Zhongyi Shi | 8ff38c1 | 2018-02-22 00:02:30 | [diff] [blame] | 569 | |
| 570 | URLRequestContextConfig config( |
| 571 | // Enable QUIC. |
| 572 | true, |
| 573 | // QUIC User Agent ID. |
| 574 | "Default QUIC User Agent ID", |
| 575 | // Enable SPDY. |
| 576 | true, |
| 577 | // Enable Brotli. |
| 578 | false, |
| 579 | // Type of http cache. |
| 580 | URLRequestContextConfig::HttpCacheType::DISK, |
| 581 | // Max size of http cache in bytes. |
| 582 | 1024000, |
| 583 | // Disable caching for HTTP responses. Other information may be stored in |
| 584 | // the cache. |
| 585 | false, |
| 586 | // Storage path for http cache and cookie storage. |
| 587 | "/data/data/org.chromium.net/app_cronet_test/test_storage", |
| 588 | // Accept-Language request header field. |
| 589 | "foreign-language", |
| 590 | // User-Agent request header field. |
| 591 | "fake agent", |
| 592 | // JSON encoded experimental options. |
| 593 | "{\"QUIC\":{\"allow_server_migration\":true}}", |
| 594 | // MockCertVerifier to use for testing purposes. |
| 595 | std::unique_ptr<net::CertVerifier>(), |
| 596 | // Enable network quality estimator. |
| 597 | false, |
| 598 | // Enable Public Key Pinning bypass for local trust anchors. |
Paul Jensen | 6a1ea3a | 2018-08-24 14:46:41 | [diff] [blame] | 599 | true, |
| 600 | // Optional network thread priority. |
| 601 | base::Optional<double>()); |
Zhongyi Shi | 8ff38c1 | 2018-02-22 00:02:30 | [diff] [blame] | 602 | |
| 603 | net::URLRequestContextBuilder builder; |
Matt Mueller | de5dadf | 2019-11-27 20:11:58 | [diff] [blame] | 604 | config.ConfigureURLRequestContextBuilder(&builder); |
Zhongyi Shi | 8ff38c1 | 2018-02-22 00:02:30 | [diff] [blame] | 605 | // Set a ProxyConfigService to avoid DCHECK failure when building. |
| 606 | builder.set_proxy_config_service( |
| 607 | std::make_unique<net::ProxyConfigServiceFixed>( |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 608 | net::ProxyConfigWithAnnotation::CreateDirect())); |
Zhongyi Shi | 8ff38c1 | 2018-02-22 00:02:30 | [diff] [blame] | 609 | std::unique_ptr<net::URLRequestContext> context(builder.Build()); |
Victor Vasiliev | a1e66d7 | 2019-12-05 17:55:38 | [diff] [blame] | 610 | const net::QuicParams* quic_params = context->quic_context()->params(); |
Zhongyi Shi | 8ff38c1 | 2018-02-22 00:02:30 | [diff] [blame] | 611 | |
Victor Vasiliev | a1e66d7 | 2019-12-05 17:55:38 | [diff] [blame] | 612 | EXPECT_FALSE(quic_params->close_sessions_on_ip_change); |
| 613 | EXPECT_TRUE(quic_params->allow_server_migration); |
Zhongyi Shi | 8ff38c1 | 2018-02-22 00:02:30 | [diff] [blame] | 614 | } |
| 615 | |
Zhongyi Shi | aa518c2 | 2018-06-15 04:37:36 | [diff] [blame] | 616 | // Test that goaway_sessions_on_ip_change is set on by default for iOS. |
| 617 | #if defined(OS_IOS) |
| 618 | #define MAYBE_SetQuicGoAwaySessionsOnIPChangeByDefault \ |
| 619 | SetQuicGoAwaySessionsOnIPChangeByDefault |
| 620 | #else |
| 621 | #define MAYBE_SetQuicGoAwaySessionsOnIPChangeByDefault \ |
| 622 | DISABLED_SetQuicGoAwaySessionsOnIPChangeByDefault |
| 623 | #endif |
| 624 | TEST(URLRequestContextConfigTest, |
| 625 | MAYBE_SetQuicGoAwaySessionsOnIPChangeByDefault) { |
Gabriel Charette | dfa3604 | 2019-08-19 17:30:11 | [diff] [blame] | 626 | base::test::TaskEnvironment task_environment_( |
| 627 | base::test::TaskEnvironment::MainThreadType::IO); |
Zhongyi Shi | aa518c2 | 2018-06-15 04:37:36 | [diff] [blame] | 628 | |
| 629 | URLRequestContextConfig config( |
| 630 | // Enable QUIC. |
| 631 | true, |
| 632 | // QUIC User Agent ID. |
| 633 | "Default QUIC User Agent ID", |
| 634 | // Enable SPDY. |
| 635 | true, |
| 636 | // Enable Brotli. |
| 637 | false, |
| 638 | // Type of http cache. |
| 639 | URLRequestContextConfig::HttpCacheType::DISK, |
| 640 | // Max size of http cache in bytes. |
| 641 | 1024000, |
| 642 | // Disable caching for HTTP responses. Other information may be stored in |
| 643 | // the cache. |
| 644 | false, |
| 645 | // Storage path for http cache and cookie storage. |
| 646 | "/data/data/org.chromium.net/app_cronet_test/test_storage", |
| 647 | // Accept-Language request header field. |
| 648 | "foreign-language", |
| 649 | // User-Agent request header field. |
| 650 | "fake agent", |
| 651 | // JSON encoded experimental options. |
| 652 | "{\"QUIC\":{}}", |
| 653 | // MockCertVerifier to use for testing purposes. |
| 654 | std::unique_ptr<net::CertVerifier>(), |
| 655 | // Enable network quality estimator. |
| 656 | false, |
| 657 | // Enable Public Key Pinning bypass for local trust anchors. |
Paul Jensen | 6a1ea3a | 2018-08-24 14:46:41 | [diff] [blame] | 658 | true, |
| 659 | // Optional network thread priority. |
| 660 | base::Optional<double>()); |
Zhongyi Shi | aa518c2 | 2018-06-15 04:37:36 | [diff] [blame] | 661 | |
| 662 | net::URLRequestContextBuilder builder; |
Matt Mueller | de5dadf | 2019-11-27 20:11:58 | [diff] [blame] | 663 | config.ConfigureURLRequestContextBuilder(&builder); |
Zhongyi Shi | aa518c2 | 2018-06-15 04:37:36 | [diff] [blame] | 664 | // Set a ProxyConfigService to avoid DCHECK failure when building. |
| 665 | builder.set_proxy_config_service( |
| 666 | std::make_unique<net::ProxyConfigServiceFixed>( |
| 667 | net::ProxyConfigWithAnnotation::CreateDirect())); |
| 668 | std::unique_ptr<net::URLRequestContext> context(builder.Build()); |
Victor Vasiliev | a1e66d7 | 2019-12-05 17:55:38 | [diff] [blame] | 669 | const net::QuicParams* quic_params = context->quic_context()->params(); |
Zhongyi Shi | aa518c2 | 2018-06-15 04:37:36 | [diff] [blame] | 670 | |
Victor Vasiliev | a1e66d7 | 2019-12-05 17:55:38 | [diff] [blame] | 671 | EXPECT_FALSE(quic_params->close_sessions_on_ip_change); |
| 672 | EXPECT_TRUE(quic_params->goaway_sessions_on_ip_change); |
Zhongyi Shi | aa518c2 | 2018-06-15 04:37:36 | [diff] [blame] | 673 | } |
| 674 | |
| 675 | // Tests that goaway_sessions_on_ip_changes can be set on via |
| 676 | // experimental options on non-iOS. |
| 677 | #if !defined(OS_IOS) |
| 678 | #define MAYBE_SetQuicGoAwaySessionsOnIPChangeViaExperimentOptions \ |
| 679 | SetQuicGoAwaySessionsOnIPChangeViaExperimentOptions |
| 680 | #else |
| 681 | #define MAYBE_SetQuicGoAwaySessionsOnIPChangeViaExperimentOptions \ |
| 682 | DISABLED_SetQuicGoAwaySessionsOnIPChangeViaExperimentOptions |
| 683 | #endif |
| 684 | TEST(URLRequestContextConfigTest, |
| 685 | MAYBE_SetQuicGoAwaySessionsOnIPChangeViaExperimentOptions) { |
Gabriel Charette | dfa3604 | 2019-08-19 17:30:11 | [diff] [blame] | 686 | base::test::TaskEnvironment task_environment_( |
| 687 | base::test::TaskEnvironment::MainThreadType::IO); |
Zhongyi Shi | 63574b7 | 2018-06-01 20:22:25 | [diff] [blame] | 688 | |
| 689 | URLRequestContextConfig config( |
| 690 | // Enable QUIC. |
| 691 | true, |
| 692 | // QUIC User Agent ID. |
| 693 | "Default QUIC User Agent ID", |
| 694 | // Enable SPDY. |
| 695 | true, |
| 696 | // Enable Brotli. |
| 697 | false, |
| 698 | // Type of http cache. |
| 699 | URLRequestContextConfig::HttpCacheType::DISK, |
| 700 | // Max size of http cache in bytes. |
| 701 | 1024000, |
| 702 | // Disable caching for HTTP responses. Other information may be stored in |
| 703 | // the cache. |
| 704 | false, |
| 705 | // Storage path for http cache and cookie storage. |
| 706 | "/data/data/org.chromium.net/app_cronet_test/test_storage", |
| 707 | // Accept-Language request header field. |
| 708 | "foreign-language", |
| 709 | // User-Agent request header field. |
| 710 | "fake agent", |
| 711 | // JSON encoded experimental options. |
| 712 | "{\"QUIC\":{\"goaway_sessions_on_ip_change\":true}}", |
| 713 | // MockCertVerifier to use for testing purposes. |
| 714 | std::unique_ptr<net::CertVerifier>(), |
| 715 | // Enable network quality estimator. |
| 716 | false, |
| 717 | // Enable Public Key Pinning bypass for local trust anchors. |
Paul Jensen | 6a1ea3a | 2018-08-24 14:46:41 | [diff] [blame] | 718 | true, |
| 719 | // Optional network thread priority. |
| 720 | base::Optional<double>()); |
Zhongyi Shi | 63574b7 | 2018-06-01 20:22:25 | [diff] [blame] | 721 | |
| 722 | net::URLRequestContextBuilder builder; |
Matt Mueller | de5dadf | 2019-11-27 20:11:58 | [diff] [blame] | 723 | config.ConfigureURLRequestContextBuilder(&builder); |
Zhongyi Shi | 63574b7 | 2018-06-01 20:22:25 | [diff] [blame] | 724 | // Set a ProxyConfigService to avoid DCHECK failure when building. |
| 725 | builder.set_proxy_config_service( |
| 726 | std::make_unique<net::ProxyConfigServiceFixed>( |
| 727 | net::ProxyConfigWithAnnotation::CreateDirect())); |
| 728 | std::unique_ptr<net::URLRequestContext> context(builder.Build()); |
Victor Vasiliev | a1e66d7 | 2019-12-05 17:55:38 | [diff] [blame] | 729 | const net::QuicParams* quic_params = context->quic_context()->params(); |
Zhongyi Shi | 63574b7 | 2018-06-01 20:22:25 | [diff] [blame] | 730 | |
Victor Vasiliev | a1e66d7 | 2019-12-05 17:55:38 | [diff] [blame] | 731 | EXPECT_FALSE(quic_params->close_sessions_on_ip_change); |
| 732 | EXPECT_TRUE(quic_params->goaway_sessions_on_ip_change); |
Zhongyi Shi | 63574b7 | 2018-06-01 20:22:25 | [diff] [blame] | 733 | } |
| 734 | |
Zhongyi Shi | aa518c2 | 2018-06-15 04:37:36 | [diff] [blame] | 735 | // Test that goaway_sessions_on_ip_change can be set to false via |
| 736 | // exprimental options on iOS. |
| 737 | #if defined(OS_IOS) |
| 738 | #define MAYBE_DisableQuicGoAwaySessionsOnIPChangeViaExperimentOptions \ |
| 739 | DisableQuicGoAwaySessionsOnIPChangeViaExperimentOptions |
| 740 | #else |
| 741 | #define MAYBE_DisableQuicGoAwaySessionsOnIPChangeViaExperimentOptions \ |
| 742 | DISABLED_DisableQuicGoAwaySessionsOnIPChangeViaExperimentOptions |
| 743 | #endif |
| 744 | TEST(URLRequestContextConfigTest, |
| 745 | MAYBE_DisableQuicGoAwaySessionsOnIPChangeViaExperimentOptions) { |
Gabriel Charette | dfa3604 | 2019-08-19 17:30:11 | [diff] [blame] | 746 | base::test::TaskEnvironment task_environment_( |
| 747 | base::test::TaskEnvironment::MainThreadType::IO); |
Zhongyi Shi | aa518c2 | 2018-06-15 04:37:36 | [diff] [blame] | 748 | |
| 749 | URLRequestContextConfig config( |
| 750 | // Enable QUIC. |
| 751 | true, |
| 752 | // QUIC User Agent ID. |
| 753 | "Default QUIC User Agent ID", |
| 754 | // Enable SPDY. |
| 755 | true, |
| 756 | // Enable Brotli. |
| 757 | false, |
| 758 | // Type of http cache. |
| 759 | URLRequestContextConfig::HttpCacheType::DISK, |
| 760 | // Max size of http cache in bytes. |
| 761 | 1024000, |
| 762 | // Disable caching for HTTP responses. Other information may be stored in |
| 763 | // the cache. |
| 764 | false, |
| 765 | // Storage path for http cache and cookie storage. |
| 766 | "/data/data/org.chromium.net/app_cronet_test/test_storage", |
| 767 | // Accept-Language request header field. |
| 768 | "foreign-language", |
| 769 | // User-Agent request header field. |
| 770 | "fake agent", |
| 771 | // JSON encoded experimental options. |
| 772 | "{\"QUIC\":{\"goaway_sessions_on_ip_change\":false}}", |
| 773 | // MockCertVerifier to use for testing purposes. |
| 774 | std::unique_ptr<net::CertVerifier>(), |
| 775 | // Enable network quality estimator. |
| 776 | false, |
| 777 | // Enable Public Key Pinning bypass for local trust anchors. |
Paul Jensen | 6a1ea3a | 2018-08-24 14:46:41 | [diff] [blame] | 778 | true, |
| 779 | // Optional network thread priority. |
| 780 | base::Optional<double>()); |
Zhongyi Shi | aa518c2 | 2018-06-15 04:37:36 | [diff] [blame] | 781 | |
| 782 | net::URLRequestContextBuilder builder; |
Matt Mueller | de5dadf | 2019-11-27 20:11:58 | [diff] [blame] | 783 | config.ConfigureURLRequestContextBuilder(&builder); |
Zhongyi Shi | aa518c2 | 2018-06-15 04:37:36 | [diff] [blame] | 784 | // Set a ProxyConfigService to avoid DCHECK failure when building. |
| 785 | builder.set_proxy_config_service( |
| 786 | std::make_unique<net::ProxyConfigServiceFixed>( |
| 787 | net::ProxyConfigWithAnnotation::CreateDirect())); |
| 788 | std::unique_ptr<net::URLRequestContext> context(builder.Build()); |
Victor Vasiliev | a1e66d7 | 2019-12-05 17:55:38 | [diff] [blame] | 789 | const net::QuicParams* quic_params = context->quic_context()->params(); |
Zhongyi Shi | aa518c2 | 2018-06-15 04:37:36 | [diff] [blame] | 790 | |
Victor Vasiliev | a1e66d7 | 2019-12-05 17:55:38 | [diff] [blame] | 791 | EXPECT_FALSE(quic_params->close_sessions_on_ip_change); |
| 792 | EXPECT_FALSE(quic_params->goaway_sessions_on_ip_change); |
Zhongyi Shi | aa518c2 | 2018-06-15 04:37:36 | [diff] [blame] | 793 | } |
| 794 | |
Yixin Wang | 10f477ed | 2017-11-21 04:20:20 | [diff] [blame] | 795 | TEST(URLRequestContextConfigTest, SetQuicConnectionMigrationV2Options) { |
Gabriel Charette | dfa3604 | 2019-08-19 17:30:11 | [diff] [blame] | 796 | base::test::TaskEnvironment task_environment_( |
| 797 | base::test::TaskEnvironment::MainThreadType::IO); |
Zhongyi Shi | 6479562 | 2017-11-20 02:21:49 | [diff] [blame] | 798 | |
| 799 | URLRequestContextConfig config( |
| 800 | // Enable QUIC. |
| 801 | true, |
| 802 | // QUIC User Agent ID. |
| 803 | "Default QUIC User Agent ID", |
| 804 | // Enable SPDY. |
| 805 | true, |
| 806 | // Enable Brotli. |
| 807 | false, |
| 808 | // Type of http cache. |
| 809 | URLRequestContextConfig::HttpCacheType::DISK, |
| 810 | // Max size of http cache in bytes. |
| 811 | 1024000, |
| 812 | // Disable caching for HTTP responses. Other information may be stored in |
| 813 | // the cache. |
| 814 | false, |
| 815 | // Storage path for http cache and cookie storage. |
| 816 | "/data/data/org.chromium.net/app_cronet_test/test_storage", |
Misha Efimov | d4ab3830 | 2018-01-30 23:56:42 | [diff] [blame] | 817 | // Accept-Language request header field. |
| 818 | "foreign-language", |
Zhongyi Shi | 6479562 | 2017-11-20 02:21:49 | [diff] [blame] | 819 | // User-Agent request header field. |
| 820 | "fake agent", |
| 821 | // JSON encoded experimental options. |
Zhongyi Shi | d02a48c | 2019-08-27 21:03:58 | [diff] [blame] | 822 | // Explicitly turn off "goaway_sessions_on_ip_change" which is default |
| 823 | // enabled on iOS but cannot be simultaneously set with migration option. |
Zhongyi Shi | f4683a3 | 2017-12-01 00:03:28 | [diff] [blame] | 824 | "{\"QUIC\":{\"migrate_sessions_on_network_change_v2\":true," |
Zhongyi Shi | d02a48c | 2019-08-27 21:03:58 | [diff] [blame] | 825 | "\"goaway_sessions_on_ip_change\":false," |
Zhongyi Shi | 73f23ca87 | 2017-12-13 18:37:13 | [diff] [blame] | 826 | "\"migrate_sessions_early_v2\":true," |
Zhongyi Shi | ff359581bc | 2018-09-26 18:11:48 | [diff] [blame] | 827 | "\"retry_on_alternate_network_before_handshake\":true," |
Zhongyi Shi | 32fe14d4 | 2019-02-28 00:25:36 | [diff] [blame] | 828 | "\"migrate_idle_sessions\":true," |
Zhongyi Shi | e01f2db | 2019-02-22 19:53:23 | [diff] [blame] | 829 | "\"retransmittable_on_wire_timeout_milliseconds\":1000," |
Zhongyi Shi | bc85e3e | 2019-02-12 19:34:42 | [diff] [blame] | 830 | "\"idle_session_migration_period_seconds\":15," |
Zhongyi Shi | 8b1e43f | 2017-12-13 20:46:30 | [diff] [blame] | 831 | "\"max_time_on_non_default_network_seconds\":10," |
Zhongyi Shi | ee76076 | 2018-08-01 00:54:29 | [diff] [blame] | 832 | "\"max_migrations_to_non_default_network_on_write_error\":3," |
Zhongyi Shi | 8b1e43f | 2017-12-13 20:46:30 | [diff] [blame] | 833 | "\"max_migrations_to_non_default_network_on_path_degrading\":4}}", |
Zhongyi Shi | 6479562 | 2017-11-20 02:21:49 | [diff] [blame] | 834 | // MockCertVerifier to use for testing purposes. |
| 835 | std::unique_ptr<net::CertVerifier>(), |
| 836 | // Enable network quality estimator. |
| 837 | false, |
| 838 | // Enable Public Key Pinning bypass for local trust anchors. |
Paul Jensen | 6a1ea3a | 2018-08-24 14:46:41 | [diff] [blame] | 839 | true, |
| 840 | // Optional network thread priority. |
| 841 | base::Optional<double>()); |
Zhongyi Shi | 6479562 | 2017-11-20 02:21:49 | [diff] [blame] | 842 | |
| 843 | net::URLRequestContextBuilder builder; |
Matt Mueller | de5dadf | 2019-11-27 20:11:58 | [diff] [blame] | 844 | config.ConfigureURLRequestContextBuilder(&builder); |
Zhongyi Shi | 6479562 | 2017-11-20 02:21:49 | [diff] [blame] | 845 | // Set a ProxyConfigService to avoid DCHECK failure when building. |
| 846 | builder.set_proxy_config_service( |
Lily Houghton | ef02885 | 2017-12-06 20:52:30 | [diff] [blame] | 847 | std::make_unique<net::ProxyConfigServiceFixed>( |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 848 | net::ProxyConfigWithAnnotation::CreateDirect())); |
Zhongyi Shi | 6479562 | 2017-11-20 02:21:49 | [diff] [blame] | 849 | std::unique_ptr<net::URLRequestContext> context(builder.Build()); |
Victor Vasiliev | a1e66d7 | 2019-12-05 17:55:38 | [diff] [blame] | 850 | const net::QuicParams* quic_params = context->quic_context()->params(); |
Zhongyi Shi | 6479562 | 2017-11-20 02:21:49 | [diff] [blame] | 851 | |
Victor Vasiliev | a1e66d7 | 2019-12-05 17:55:38 | [diff] [blame] | 852 | EXPECT_TRUE(quic_params->migrate_sessions_on_network_change_v2); |
| 853 | EXPECT_TRUE(quic_params->migrate_sessions_early_v2); |
| 854 | EXPECT_TRUE(quic_params->retry_on_alternate_network_before_handshake); |
| 855 | EXPECT_EQ(1000, |
| 856 | quic_params->retransmittable_on_wire_timeout.InMilliseconds()); |
| 857 | EXPECT_TRUE(quic_params->migrate_idle_sessions); |
Zhongyi Shi | bc85e3e | 2019-02-12 19:34:42 | [diff] [blame] | 858 | EXPECT_EQ(base::TimeDelta::FromSeconds(15), |
Victor Vasiliev | a1e66d7 | 2019-12-05 17:55:38 | [diff] [blame] | 859 | quic_params->idle_session_migration_period); |
Zhongyi Shi | 73f23ca87 | 2017-12-13 18:37:13 | [diff] [blame] | 860 | EXPECT_EQ(base::TimeDelta::FromSeconds(10), |
Victor Vasiliev | a1e66d7 | 2019-12-05 17:55:38 | [diff] [blame] | 861 | quic_params->max_time_on_non_default_network); |
| 862 | EXPECT_EQ(3, |
| 863 | quic_params->max_migrations_to_non_default_network_on_write_error); |
Zhongyi Shi | 8b1e43f | 2017-12-13 20:46:30 | [diff] [blame] | 864 | EXPECT_EQ( |
Victor Vasiliev | a1e66d7 | 2019-12-05 17:55:38 | [diff] [blame] | 865 | 4, quic_params->max_migrations_to_non_default_network_on_path_degrading); |
David Schinazi | 07c4661b | 2021-02-18 02:32:10 | [diff] [blame] | 866 | EXPECT_EQ(quic::ParsedQuicVersionVector{quic::ParsedQuicVersion::Q050()}, |
| 867 | quic_params->supported_versions); |
Zhongyi Shi | 6479562 | 2017-11-20 02:21:49 | [diff] [blame] | 868 | } |
| 869 | |
Renjie | 94b9071 | 2018-10-18 21:03:19 | [diff] [blame] | 870 | TEST(URLRequestContextConfigTest, SetQuicStaleDNSracing) { |
Gabriel Charette | dfa3604 | 2019-08-19 17:30:11 | [diff] [blame] | 871 | base::test::TaskEnvironment task_environment_( |
| 872 | base::test::TaskEnvironment::MainThreadType::IO); |
Renjie | 94b9071 | 2018-10-18 21:03:19 | [diff] [blame] | 873 | |
| 874 | URLRequestContextConfig config( |
| 875 | // Enable QUIC. |
| 876 | true, |
| 877 | // QUIC User Agent ID. |
| 878 | "Default QUIC User Agent ID", |
| 879 | // Enable SPDY. |
| 880 | true, |
| 881 | // Enable Brotli. |
| 882 | false, |
| 883 | // Type of http cache. |
| 884 | URLRequestContextConfig::HttpCacheType::DISK, |
| 885 | // Max size of http cache in bytes. |
| 886 | 1024000, |
| 887 | // Disable caching for HTTP responses. Other information may be stored in |
| 888 | // the cache. |
| 889 | false, |
| 890 | // Storage path for http cache and cookie storage. |
| 891 | "/data/data/org.chromium.net/app_cronet_test/test_storage", |
| 892 | // Accept-Language request header field. |
| 893 | "foreign-language", |
| 894 | // User-Agent request header field. |
| 895 | "fake agent", |
| 896 | // JSON encoded experimental options. |
| 897 | "{\"QUIC\":{\"race_stale_dns_on_connection\":true}}", |
| 898 | // MockCertVerifier to use for testing purposes. |
| 899 | std::unique_ptr<net::CertVerifier>(), |
| 900 | // Enable network quality estimator. |
| 901 | false, |
| 902 | // Enable Public Key Pinning bypass for local trust anchors. |
| 903 | true, |
| 904 | // Optional network thread priority. |
| 905 | base::Optional<double>()); |
| 906 | |
| 907 | net::URLRequestContextBuilder builder; |
Matt Mueller | de5dadf | 2019-11-27 20:11:58 | [diff] [blame] | 908 | config.ConfigureURLRequestContextBuilder(&builder); |
Renjie | 94b9071 | 2018-10-18 21:03:19 | [diff] [blame] | 909 | // Set a ProxyConfigService to avoid DCHECK failure when building. |
| 910 | builder.set_proxy_config_service( |
| 911 | std::make_unique<net::ProxyConfigServiceFixed>( |
| 912 | net::ProxyConfigWithAnnotation::CreateDirect())); |
| 913 | std::unique_ptr<net::URLRequestContext> context(builder.Build()); |
Victor Vasiliev | a1e66d7 | 2019-12-05 17:55:38 | [diff] [blame] | 914 | const net::QuicParams* quic_params = context->quic_context()->params(); |
Renjie | 94b9071 | 2018-10-18 21:03:19 | [diff] [blame] | 915 | |
Victor Vasiliev | a1e66d7 | 2019-12-05 17:55:38 | [diff] [blame] | 916 | EXPECT_TRUE(quic_params->race_stale_dns_on_connection); |
Renjie | 94b9071 | 2018-10-18 21:03:19 | [diff] [blame] | 917 | } |
| 918 | |
Renjie Tang | 55ba9ae | 2021-04-30 22:01:05 | [diff] [blame] | 919 | TEST(URLRequestContextConfigTest, SetQuicAllowPortMigration) { |
| 920 | base::test::TaskEnvironment task_environment_( |
| 921 | base::test::TaskEnvironment::MainThreadType::IO); |
| 922 | URLRequestContextConfig config( |
| 923 | // Enable QUIC. |
| 924 | true, |
| 925 | // QUIC User Agent ID. |
| 926 | "Default QUIC User Agent ID", |
| 927 | // Enable SPDY. |
| 928 | true, |
| 929 | // Enable Brotli. |
| 930 | false, |
| 931 | // Type of http cache. |
| 932 | URLRequestContextConfig::HttpCacheType::DISK, |
| 933 | // Max size of http cache in bytes. |
| 934 | 1024000, |
| 935 | // Disable caching for HTTP responses. Other information may be stored in |
| 936 | // the cache. |
| 937 | false, |
| 938 | // Storage path for http cache and cookie storage. |
| 939 | "/data/data/org.chromium.net/app_cronet_test/test_storage", |
| 940 | // Accept-Language request header field. |
| 941 | "foreign-language", |
| 942 | // User-Agent request header field. |
| 943 | "fake agent", |
| 944 | // JSON encoded experimental options. |
| 945 | "{\"QUIC\":{\"allow_port_migration\":true}}", |
| 946 | // MockCertVerifier to use for testing purposes. |
| 947 | std::unique_ptr<net::CertVerifier>(), |
| 948 | // Enable network quality estimator. |
| 949 | false, |
| 950 | // Enable Public Key Pinning bypass for local trust anchors. |
| 951 | true, |
| 952 | // Optional network thread priority. |
| 953 | base::Optional<double>()); |
| 954 | |
| 955 | net::URLRequestContextBuilder builder; |
| 956 | config.ConfigureURLRequestContextBuilder(&builder); |
| 957 | // Set a ProxyConfigService to avoid DCHECK failure when building. |
| 958 | builder.set_proxy_config_service( |
| 959 | std::make_unique<net::ProxyConfigServiceFixed>( |
| 960 | net::ProxyConfigWithAnnotation::CreateDirect())); |
| 961 | std::unique_ptr<net::URLRequestContext> context(builder.Build()); |
| 962 | const net::QuicParams* quic_params = context->quic_context()->params(); |
| 963 | |
| 964 | EXPECT_TRUE(quic_params->allow_port_migration); |
| 965 | } |
| 966 | |
Renjie Tang | cbbc84c | 2019-09-06 22:23:23 | [diff] [blame] | 967 | TEST(URLRequestContextConfigTest, SetQuicGoawayOnPathDegrading) { |
| 968 | base::test::TaskEnvironment task_environment_( |
| 969 | base::test::TaskEnvironment::MainThreadType::IO); |
| 970 | |
| 971 | URLRequestContextConfig config( |
| 972 | // Enable QUIC. |
| 973 | true, |
| 974 | // QUIC User Agent ID. |
| 975 | "Default QUIC User Agent ID", |
| 976 | // Enable SPDY. |
| 977 | true, |
| 978 | // Enable Brotli. |
| 979 | false, |
| 980 | // Type of http cache. |
| 981 | URLRequestContextConfig::HttpCacheType::DISK, |
| 982 | // Max size of http cache in bytes. |
| 983 | 1024000, |
| 984 | // Disable caching for HTTP responses. Other information may be stored in |
| 985 | // the cache. |
| 986 | false, |
| 987 | // Storage path for http cache and cookie storage. |
| 988 | "/data/data/org.chromium.net/app_cronet_test/test_storage", |
| 989 | // Accept-Language request header field. |
| 990 | "foreign-language", |
| 991 | // User-Agent request header field. |
| 992 | "fake agent", |
| 993 | // JSON encoded experimental options. |
| 994 | "{\"QUIC\":{\"go_away_on_path_degrading\":true}}", |
| 995 | // MockCertVerifier to use for testing purposes. |
| 996 | std::unique_ptr<net::CertVerifier>(), |
| 997 | // Enable network quality estimator. |
| 998 | false, |
| 999 | // Enable Public Key Pinning bypass for local trust anchors. |
| 1000 | true, |
| 1001 | // Optional network thread priority. |
| 1002 | base::Optional<double>()); |
| 1003 | |
| 1004 | net::URLRequestContextBuilder builder; |
Matt Mueller | de5dadf | 2019-11-27 20:11:58 | [diff] [blame] | 1005 | config.ConfigureURLRequestContextBuilder(&builder); |
Renjie Tang | cbbc84c | 2019-09-06 22:23:23 | [diff] [blame] | 1006 | // Set a ProxyConfigService to avoid DCHECK failure when building. |
| 1007 | builder.set_proxy_config_service( |
| 1008 | std::make_unique<net::ProxyConfigServiceFixed>( |
| 1009 | net::ProxyConfigWithAnnotation::CreateDirect())); |
| 1010 | std::unique_ptr<net::URLRequestContext> context(builder.Build()); |
Victor Vasiliev | a1e66d7 | 2019-12-05 17:55:38 | [diff] [blame] | 1011 | const net::QuicParams* quic_params = context->quic_context()->params(); |
Renjie Tang | cbbc84c | 2019-09-06 22:23:23 | [diff] [blame] | 1012 | |
Victor Vasiliev | a1e66d7 | 2019-12-05 17:55:38 | [diff] [blame] | 1013 | EXPECT_TRUE(quic_params->go_away_on_path_degrading); |
Renjie Tang | cbbc84c | 2019-09-06 22:23:23 | [diff] [blame] | 1014 | } |
| 1015 | |
Yixin Wang | 10f477ed | 2017-11-21 04:20:20 | [diff] [blame] | 1016 | TEST(URLRequestContextConfigTest, SetQuicHostWhitelist) { |
Gabriel Charette | dfa3604 | 2019-08-19 17:30:11 | [diff] [blame] | 1017 | base::test::TaskEnvironment task_environment_( |
| 1018 | base::test::TaskEnvironment::MainThreadType::IO); |
Yixin Wang | 10f477ed | 2017-11-21 04:20:20 | [diff] [blame] | 1019 | |
| 1020 | URLRequestContextConfig config( |
| 1021 | // Enable QUIC. |
| 1022 | true, |
| 1023 | // QUIC User Agent ID. |
| 1024 | "Default QUIC User Agent ID", |
| 1025 | // Enable SPDY. |
| 1026 | true, |
| 1027 | // Enable Brotli. |
| 1028 | false, |
| 1029 | // Type of http cache. |
| 1030 | URLRequestContextConfig::HttpCacheType::DISK, |
| 1031 | // Max size of http cache in bytes. |
| 1032 | 1024000, |
| 1033 | // Disable caching for HTTP responses. Other information may be stored in |
| 1034 | // the cache. |
| 1035 | false, |
| 1036 | // Storage path for http cache and cookie storage. |
| 1037 | "/data/data/org.chromium.net/app_cronet_test/test_storage", |
Misha Efimov | d4ab3830 | 2018-01-30 23:56:42 | [diff] [blame] | 1038 | // Accept-Language request header field. |
| 1039 | "foreign-language", |
Yixin Wang | 10f477ed | 2017-11-21 04:20:20 | [diff] [blame] | 1040 | // User-Agent request header field. |
| 1041 | "fake agent", |
| 1042 | // JSON encoded experimental options. |
| 1043 | "{\"QUIC\":{\"host_whitelist\":\"www.example.com,www.example.org\"}}", |
| 1044 | // MockCertVerifier to use for testing purposes. |
| 1045 | std::unique_ptr<net::CertVerifier>(), |
| 1046 | // Enable network quality estimator. |
| 1047 | false, |
| 1048 | // Enable Public Key Pinning bypass for local trust anchors. |
Paul Jensen | 6a1ea3a | 2018-08-24 14:46:41 | [diff] [blame] | 1049 | true, |
| 1050 | // Optional network thread priority. |
| 1051 | base::Optional<double>()); |
Yixin Wang | 10f477ed | 2017-11-21 04:20:20 | [diff] [blame] | 1052 | |
| 1053 | net::URLRequestContextBuilder builder; |
Matt Mueller | de5dadf | 2019-11-27 20:11:58 | [diff] [blame] | 1054 | config.ConfigureURLRequestContextBuilder(&builder); |
Yixin Wang | 10f477ed | 2017-11-21 04:20:20 | [diff] [blame] | 1055 | // Set a ProxyConfigService to avoid DCHECK failure when building. |
| 1056 | builder.set_proxy_config_service( |
Lily Houghton | ef02885 | 2017-12-06 20:52:30 | [diff] [blame] | 1057 | std::make_unique<net::ProxyConfigServiceFixed>( |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 1058 | net::ProxyConfigWithAnnotation::CreateDirect())); |
Yixin Wang | 10f477ed | 2017-11-21 04:20:20 | [diff] [blame] | 1059 | std::unique_ptr<net::URLRequestContext> context(builder.Build()); |
| 1060 | const net::HttpNetworkSession::Params* params = |
| 1061 | context->GetNetworkSessionParams(); |
| 1062 | |
Ryan Sleevi | a9d6aa6 | 2019-07-26 13:32:18 | [diff] [blame] | 1063 | EXPECT_TRUE(base::Contains(params->quic_host_allowlist, "www.example.com")); |
| 1064 | EXPECT_TRUE(base::Contains(params->quic_host_allowlist, "www.example.org")); |
Yixin Wang | 10f477ed | 2017-11-21 04:20:20 | [diff] [blame] | 1065 | } |
| 1066 | |
Yixin Wang | 98387515 | 2017-11-21 20:30:13 | [diff] [blame] | 1067 | TEST(URLRequestContextConfigTest, SetQuicMaxTimeBeforeCryptoHandshake) { |
Gabriel Charette | dfa3604 | 2019-08-19 17:30:11 | [diff] [blame] | 1068 | base::test::TaskEnvironment task_environment_( |
| 1069 | base::test::TaskEnvironment::MainThreadType::IO); |
Yixin Wang | 98387515 | 2017-11-21 20:30:13 | [diff] [blame] | 1070 | |
| 1071 | URLRequestContextConfig config( |
| 1072 | // Enable QUIC. |
| 1073 | true, |
| 1074 | // QUIC User Agent ID. |
| 1075 | "Default QUIC User Agent ID", |
| 1076 | // Enable SPDY. |
| 1077 | true, |
| 1078 | // Enable Brotli. |
| 1079 | false, |
| 1080 | // Type of http cache. |
| 1081 | URLRequestContextConfig::HttpCacheType::DISK, |
| 1082 | // Max size of http cache in bytes. |
| 1083 | 1024000, |
| 1084 | // Disable caching for HTTP responses. Other information may be stored in |
| 1085 | // the cache. |
| 1086 | false, |
| 1087 | // Storage path for http cache and cookie storage. |
| 1088 | "/data/data/org.chromium.net/app_cronet_test/test_storage", |
Misha Efimov | d4ab3830 | 2018-01-30 23:56:42 | [diff] [blame] | 1089 | // Accept-Language request header field. |
| 1090 | "foreign-language", |
Yixin Wang | 98387515 | 2017-11-21 20:30:13 | [diff] [blame] | 1091 | // User-Agent request header field. |
| 1092 | "fake agent", |
| 1093 | // JSON encoded experimental options. |
| 1094 | "{\"QUIC\":{\"max_time_before_crypto_handshake_seconds\":7," |
| 1095 | "\"max_idle_time_before_crypto_handshake_seconds\":11}}", |
| 1096 | // MockCertVerifier to use for testing purposes. |
| 1097 | std::unique_ptr<net::CertVerifier>(), |
| 1098 | // Enable network quality estimator. |
| 1099 | false, |
| 1100 | // Enable Public Key Pinning bypass for local trust anchors. |
Paul Jensen | 6a1ea3a | 2018-08-24 14:46:41 | [diff] [blame] | 1101 | true, |
| 1102 | // Optional network thread priority. |
| 1103 | base::Optional<double>()); |
Yixin Wang | 98387515 | 2017-11-21 20:30:13 | [diff] [blame] | 1104 | |
| 1105 | net::URLRequestContextBuilder builder; |
Matt Mueller | de5dadf | 2019-11-27 20:11:58 | [diff] [blame] | 1106 | config.ConfigureURLRequestContextBuilder(&builder); |
Yixin Wang | 98387515 | 2017-11-21 20:30:13 | [diff] [blame] | 1107 | // Set a ProxyConfigService to avoid DCHECK failure when building. |
| 1108 | builder.set_proxy_config_service( |
Lily Houghton | ef02885 | 2017-12-06 20:52:30 | [diff] [blame] | 1109 | std::make_unique<net::ProxyConfigServiceFixed>( |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 1110 | net::ProxyConfigWithAnnotation::CreateDirect())); |
Yixin Wang | 98387515 | 2017-11-21 20:30:13 | [diff] [blame] | 1111 | std::unique_ptr<net::URLRequestContext> context(builder.Build()); |
Victor Vasiliev | a1e66d7 | 2019-12-05 17:55:38 | [diff] [blame] | 1112 | const net::QuicParams* quic_params = context->quic_context()->params(); |
Yixin Wang | 98387515 | 2017-11-21 20:30:13 | [diff] [blame] | 1113 | |
Victor Vasiliev | a1e66d7 | 2019-12-05 17:55:38 | [diff] [blame] | 1114 | EXPECT_EQ(7, quic_params->max_time_before_crypto_handshake.InSeconds()); |
| 1115 | EXPECT_EQ(11, quic_params->max_idle_time_before_crypto_handshake.InSeconds()); |
Yixin Wang | 98387515 | 2017-11-21 20:30:13 | [diff] [blame] | 1116 | } |
| 1117 | |
Yixin Wang | 1875fdb | 2017-12-06 02:26:49 | [diff] [blame] | 1118 | TEST(URLURLRequestContextConfigTest, SetQuicConnectionOptions) { |
Gabriel Charette | dfa3604 | 2019-08-19 17:30:11 | [diff] [blame] | 1119 | base::test::TaskEnvironment task_environment_( |
| 1120 | base::test::TaskEnvironment::MainThreadType::IO); |
Yixin Wang | 1875fdb | 2017-12-06 02:26:49 | [diff] [blame] | 1121 | |
| 1122 | URLRequestContextConfig config( |
| 1123 | // Enable QUIC. |
| 1124 | true, |
| 1125 | // QUIC User Agent ID. |
| 1126 | "Default QUIC User Agent ID", |
| 1127 | // Enable SPDY. |
| 1128 | true, |
| 1129 | // Enable Brotli. |
| 1130 | false, |
| 1131 | // Type of http cache. |
| 1132 | URLRequestContextConfig::HttpCacheType::DISK, |
| 1133 | // Max size of http cache in bytes. |
| 1134 | 1024000, |
| 1135 | // Disable caching for HTTP responses. Other information may be stored in |
| 1136 | // the cache. |
| 1137 | false, |
| 1138 | // Storage path for http cache and cookie storage. |
| 1139 | "/data/data/org.chromium.net/app_cronet_test/test_storage", |
Misha Efimov | d4ab3830 | 2018-01-30 23:56:42 | [diff] [blame] | 1140 | // Accept-Language request header field. |
| 1141 | "foreign-language", |
Yixin Wang | 1875fdb | 2017-12-06 02:26:49 | [diff] [blame] | 1142 | // User-Agent request header field. |
| 1143 | "fake agent", |
| 1144 | // JSON encoded experimental options. |
| 1145 | "{\"QUIC\":{\"connection_options\":\"TIME,TBBR,REJ\"," |
| 1146 | "\"client_connection_options\":\"TBBR,1RTT\"}}", |
| 1147 | // MockCertVerifier to use for testing purposes. |
| 1148 | std::unique_ptr<net::CertVerifier>(), |
| 1149 | // Enable network quality estimator. |
| 1150 | false, |
| 1151 | // Enable Public Key Pinning bypass for local trust anchors. |
Paul Jensen | 6a1ea3a | 2018-08-24 14:46:41 | [diff] [blame] | 1152 | true, |
| 1153 | // Optional network thread priority. |
| 1154 | base::Optional<double>()); |
Yixin Wang | 1875fdb | 2017-12-06 02:26:49 | [diff] [blame] | 1155 | |
| 1156 | net::URLRequestContextBuilder builder; |
Matt Mueller | de5dadf | 2019-11-27 20:11:58 | [diff] [blame] | 1157 | config.ConfigureURLRequestContextBuilder(&builder); |
Yixin Wang | 1875fdb | 2017-12-06 02:26:49 | [diff] [blame] | 1158 | // Set a ProxyConfigService to avoid DCHECK failure when building. |
| 1159 | builder.set_proxy_config_service( |
Gyuyoung Kim | 6afb508 | 2018-01-19 13:35:57 | [diff] [blame] | 1160 | std::make_unique<net::ProxyConfigServiceFixed>( |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 1161 | net::ProxyConfigWithAnnotation::CreateDirect())); |
Yixin Wang | 1875fdb | 2017-12-06 02:26:49 | [diff] [blame] | 1162 | std::unique_ptr<net::URLRequestContext> context(builder.Build()); |
Victor Vasiliev | a1e66d7 | 2019-12-05 17:55:38 | [diff] [blame] | 1163 | const net::QuicParams* quic_params = context->quic_context()->params(); |
Yixin Wang | 1875fdb | 2017-12-06 02:26:49 | [diff] [blame] | 1164 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 1165 | quic::QuicTagVector connection_options; |
| 1166 | connection_options.push_back(quic::kTIME); |
| 1167 | connection_options.push_back(quic::kTBBR); |
| 1168 | connection_options.push_back(quic::kREJ); |
Victor Vasiliev | a1e66d7 | 2019-12-05 17:55:38 | [diff] [blame] | 1169 | EXPECT_EQ(connection_options, quic_params->connection_options); |
Yixin Wang | 1875fdb | 2017-12-06 02:26:49 | [diff] [blame] | 1170 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 1171 | quic::QuicTagVector client_connection_options; |
| 1172 | client_connection_options.push_back(quic::kTBBR); |
| 1173 | client_connection_options.push_back(quic::k1RTT); |
Victor Vasiliev | a1e66d7 | 2019-12-05 17:55:38 | [diff] [blame] | 1174 | EXPECT_EQ(client_connection_options, quic_params->client_connection_options); |
Yixin Wang | 1875fdb | 2017-12-06 02:26:49 | [diff] [blame] | 1175 | } |
| 1176 | |
Misha Efimov | d4ab3830 | 2018-01-30 23:56:42 | [diff] [blame] | 1177 | TEST(URLURLRequestContextConfigTest, SetAcceptLanguageAndUserAgent) { |
Gabriel Charette | dfa3604 | 2019-08-19 17:30:11 | [diff] [blame] | 1178 | base::test::TaskEnvironment task_environment_( |
| 1179 | base::test::TaskEnvironment::MainThreadType::IO); |
Misha Efimov | d4ab3830 | 2018-01-30 23:56:42 | [diff] [blame] | 1180 | |
| 1181 | URLRequestContextConfig config( |
| 1182 | // Enable QUIC. |
| 1183 | true, |
| 1184 | // QUIC User Agent ID. |
| 1185 | "Default QUIC User Agent ID", |
| 1186 | // Enable SPDY. |
| 1187 | true, |
| 1188 | // Enable Brotli. |
| 1189 | false, |
| 1190 | // Type of http cache. |
| 1191 | URLRequestContextConfig::HttpCacheType::DISK, |
| 1192 | // Max size of http cache in bytes. |
| 1193 | 1024000, |
| 1194 | // Disable caching for HTTP responses. Other information may be stored in |
| 1195 | // the cache. |
| 1196 | false, |
| 1197 | // Storage path for http cache and cookie storage. |
| 1198 | "/data/data/org.chromium.net/app_cronet_test/test_storage", |
| 1199 | // Accept-Language request header field. |
| 1200 | "foreign-language", |
| 1201 | // User-Agent request header field. |
| 1202 | "fake agent", |
| 1203 | // JSON encoded experimental options. |
| 1204 | "{}", |
| 1205 | // MockCertVerifier to use for testing purposes. |
| 1206 | std::unique_ptr<net::CertVerifier>(), |
| 1207 | // Enable network quality estimator. |
| 1208 | false, |
| 1209 | // Enable Public Key Pinning bypass for local trust anchors. |
Paul Jensen | 6a1ea3a | 2018-08-24 14:46:41 | [diff] [blame] | 1210 | true, |
| 1211 | // Optional network thread priority. |
| 1212 | base::Optional<double>()); |
Misha Efimov | d4ab3830 | 2018-01-30 23:56:42 | [diff] [blame] | 1213 | |
| 1214 | net::URLRequestContextBuilder builder; |
Matt Mueller | de5dadf | 2019-11-27 20:11:58 | [diff] [blame] | 1215 | config.ConfigureURLRequestContextBuilder(&builder); |
Misha Efimov | d4ab3830 | 2018-01-30 23:56:42 | [diff] [blame] | 1216 | // Set a ProxyConfigService to avoid DCHECK failure when building. |
| 1217 | builder.set_proxy_config_service( |
| 1218 | std::make_unique<net::ProxyConfigServiceFixed>( |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 1219 | net::ProxyConfigWithAnnotation::CreateDirect())); |
Misha Efimov | d4ab3830 | 2018-01-30 23:56:42 | [diff] [blame] | 1220 | std::unique_ptr<net::URLRequestContext> context(builder.Build()); |
| 1221 | EXPECT_EQ("foreign-language", |
| 1222 | context->http_user_agent_settings()->GetAcceptLanguage()); |
| 1223 | EXPECT_EQ("fake agent", context->http_user_agent_settings()->GetUserAgent()); |
| 1224 | } |
| 1225 | |
Renjie Tang | 8c3a1d0 | 2020-04-23 17:42:30 | [diff] [blame] | 1226 | TEST(URLURLRequestContextConfigTest, TurningOffQuic) { |
| 1227 | base::test::TaskEnvironment task_environment_( |
| 1228 | base::test::TaskEnvironment::MainThreadType::IO); |
| 1229 | |
| 1230 | URLRequestContextConfig config( |
| 1231 | // Enable QUIC. |
| 1232 | false, |
| 1233 | // QUIC User Agent ID. |
| 1234 | "Default QUIC User Agent ID", |
| 1235 | // Enable SPDY. |
| 1236 | true, |
| 1237 | // Enable Brotli. |
| 1238 | false, |
| 1239 | // Type of http cache. |
| 1240 | URLRequestContextConfig::HttpCacheType::DISK, |
| 1241 | // Max size of http cache in bytes. |
| 1242 | 1024000, |
| 1243 | // Disable caching for HTTP responses. Other information may be stored in |
| 1244 | // the cache. |
| 1245 | false, |
| 1246 | // Storage path for http cache and cookie storage. |
| 1247 | "/data/data/org.chromium.net/app_cronet_test/test_storage", |
| 1248 | // Accept-Language request header field. |
| 1249 | "foreign-language", |
| 1250 | // User-Agent request header field. |
| 1251 | "fake agent", |
| 1252 | // JSON encoded experimental options. |
| 1253 | "{}", |
| 1254 | // MockCertVerifier to use for testing purposes. |
| 1255 | std::unique_ptr<net::CertVerifier>(), |
| 1256 | // Enable network quality estimator. |
| 1257 | false, |
| 1258 | // Enable Public Key Pinning bypass for local trust anchors. |
| 1259 | true, |
| 1260 | // Optional network thread priority. |
| 1261 | base::Optional<double>()); |
| 1262 | |
| 1263 | net::URLRequestContextBuilder builder; |
| 1264 | config.ConfigureURLRequestContextBuilder(&builder); |
| 1265 | // Set a ProxyConfigService to avoid DCHECK failure when building. |
| 1266 | builder.set_proxy_config_service( |
| 1267 | std::make_unique<net::ProxyConfigServiceFixed>( |
| 1268 | net::ProxyConfigWithAnnotation::CreateDirect())); |
| 1269 | std::unique_ptr<net::URLRequestContext> context(builder.Build()); |
| 1270 | const net::HttpNetworkSession::Params* params = |
| 1271 | context->GetNetworkSessionParams(); |
| 1272 | EXPECT_EQ(false, params->enable_quic); |
| 1273 | } |
| 1274 | |
Renjie Tang | 1c71894 | 2020-06-11 23:05:38 | [diff] [blame] | 1275 | TEST(URLURLRequestContextConfigTest, DefaultEnableQuic) { |
| 1276 | base::test::TaskEnvironment task_environment_( |
| 1277 | base::test::TaskEnvironment::MainThreadType::IO); |
| 1278 | |
| 1279 | URLRequestContextConfigBuilder config_builder; |
| 1280 | std::unique_ptr<URLRequestContextConfig> config = config_builder.Build(); |
| 1281 | net::URLRequestContextBuilder builder; |
| 1282 | config->ConfigureURLRequestContextBuilder(&builder); |
| 1283 | // Set a ProxyConfigService to avoid DCHECK failure when building. |
| 1284 | builder.set_proxy_config_service( |
| 1285 | std::make_unique<net::ProxyConfigServiceFixed>( |
| 1286 | net::ProxyConfigWithAnnotation::CreateDirect())); |
| 1287 | std::unique_ptr<net::URLRequestContext> context(builder.Build()); |
| 1288 | const net::HttpNetworkSession::Params* params = |
| 1289 | context->GetNetworkSessionParams(); |
| 1290 | EXPECT_EQ(true, params->enable_quic); |
| 1291 | } |
| 1292 | |
juliatuttle | 50d9c4b | 2016-08-23 22:49:19 | [diff] [blame] | 1293 | // See stale_host_resolver_unittest.cc for test of StaleDNS options. |
| 1294 | |
xunjieli | f24ee5f | 2015-11-23 18:05:26 | [diff] [blame] | 1295 | } // namespace cronet |