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