Update broken references to image assets
[chromium-blink-merge.git] / chrome / browser / io_thread_unittest.cc
bloba88d6f52299897353a2608545cac008058e7aa06
1 // Copyright 2014 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.
5 #include "base/command_line.h"
6 #include "base/metrics/field_trial.h"
7 #include "base/test/mock_entropy_provider.h"
8 #include "chrome/browser/io_thread.h"
9 #include "chrome/common/chrome_switches.h"
10 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_params.h"
11 #include "net/http/http_network_session.h"
12 #include "net/http/http_server_properties_impl.h"
13 #include "net/quic/quic_protocol.h"
14 #include "testing/gmock/include/gmock/gmock.h"
15 #include "testing/gtest/include/gtest/gtest.h"
17 namespace test {
19 using ::testing::ElementsAre;
21 class IOThreadPeer {
22 public:
23 static void ConfigureQuicGlobals(
24 const base::CommandLine& command_line,
25 base::StringPiece quic_trial_group,
26 const std::map<std::string, std::string>& quic_trial_params,
27 bool is_quic_allowed_by_policy,
28 IOThread::Globals* globals) {
29 IOThread::ConfigureQuicGlobals(command_line, quic_trial_group,
30 quic_trial_params, is_quic_allowed_by_policy,
31 globals);
34 static void ConfigureSpdyGlobals(
35 const base::CommandLine& command_line,
36 base::StringPiece spdy_trial_group,
37 const std::map<std::string, std::string>& spdy_trial_params,
38 IOThread::Globals* globals) {
39 IOThread::ConfigureSpdyGlobals(command_line, spdy_trial_group,
40 spdy_trial_params, globals);
43 static void InitializeNetworkSessionParamsFromGlobals(
44 const IOThread::Globals& globals,
45 net::HttpNetworkSession::Params* params) {
46 IOThread::InitializeNetworkSessionParamsFromGlobals(globals, params);
50 class IOThreadTest : public testing::Test {
51 public:
52 IOThreadTest()
53 : command_line_(base::CommandLine::NO_PROGRAM),
54 is_quic_allowed_by_policy_(true) {
55 globals_.http_server_properties.reset(new net::HttpServerPropertiesImpl());
58 void ConfigureQuicGlobals() {
59 IOThreadPeer::ConfigureQuicGlobals(command_line_,
60 field_trial_group_,
61 field_trial_params_,
62 is_quic_allowed_by_policy_,
63 &globals_);
66 void ConfigureSpdyGlobals() {
67 IOThreadPeer::ConfigureSpdyGlobals(command_line_, field_trial_group_,
68 field_trial_params_, &globals_);
71 void InitializeNetworkSessionParams(net::HttpNetworkSession::Params* params) {
72 IOThreadPeer::InitializeNetworkSessionParamsFromGlobals(globals_, params);
75 base::CommandLine command_line_;
76 IOThread::Globals globals_;
77 std::string field_trial_group_;
78 bool is_quic_allowed_by_policy_;
79 std::map<std::string, std::string> field_trial_params_;
82 TEST_F(IOThreadTest, InitializeNetworkSessionParamsFromGlobals) {
83 globals_.quic_connection_options.push_back(net::kTBBR);
84 globals_.quic_connection_options.push_back(net::kTIME);
86 net::HttpNetworkSession::Params params;
87 InitializeNetworkSessionParams(&params);
88 EXPECT_EQ(globals_.quic_connection_options,
89 params.quic_connection_options);
92 TEST_F(IOThreadTest, SpdyFieldTrialHoldbackEnabled) {
93 net::HttpStreamFactory::set_spdy_enabled(true);
94 field_trial_group_ = "SpdyDisabled";
95 ConfigureSpdyGlobals();
96 EXPECT_FALSE(net::HttpStreamFactory::spdy_enabled());
99 TEST_F(IOThreadTest, SpdyFieldTrialSpdy31Enabled) {
100 bool use_alternative_services = false;
101 field_trial_group_ = "Spdy31Enabled";
102 ConfigureSpdyGlobals();
103 EXPECT_THAT(globals_.next_protos,
104 ElementsAre(net::kProtoHTTP11,
105 net::kProtoSPDY31));
106 globals_.use_alternative_services.CopyToIfSet(&use_alternative_services);
107 EXPECT_TRUE(use_alternative_services);
110 TEST_F(IOThreadTest, SpdyFieldTrialSpdy4Enabled) {
111 bool use_alternative_services = false;
112 field_trial_group_ = "Spdy4Enabled";
113 ConfigureSpdyGlobals();
114 EXPECT_THAT(globals_.next_protos,
115 ElementsAre(net::kProtoHTTP11, net::kProtoSPDY31,
116 net::kProtoHTTP2_14, net::kProtoHTTP2));
117 globals_.use_alternative_services.CopyToIfSet(&use_alternative_services);
118 EXPECT_TRUE(use_alternative_services);
121 TEST_F(IOThreadTest, SpdyFieldTrialDefault) {
122 field_trial_group_ = "";
123 ConfigureSpdyGlobals();
124 EXPECT_THAT(globals_.next_protos,
125 ElementsAre(net::kProtoHTTP11, net::kProtoSPDY31,
126 net::kProtoHTTP2_14, net::kProtoHTTP2));
127 bool use_alternative_services = false;
128 globals_.use_alternative_services.CopyToIfSet(&use_alternative_services);
129 EXPECT_TRUE(use_alternative_services);
132 TEST_F(IOThreadTest, SpdyFieldTrialParametrized) {
133 field_trial_params_["enable_spdy31"] = "false";
134 // Undefined parameter "enable_http2_14" should default to false.
135 field_trial_params_["enable_http2"] = "true";
136 field_trial_group_ = "ParametrizedHTTP2Only";
137 ConfigureSpdyGlobals();
138 EXPECT_THAT(globals_.next_protos,
139 ElementsAre(net::kProtoHTTP11, net::kProtoHTTP2));
140 bool use_alternative_services = false;
141 globals_.use_alternative_services.CopyToIfSet(&use_alternative_services);
142 EXPECT_TRUE(use_alternative_services);
145 TEST_F(IOThreadTest, SpdyCommandLineUseSpdyOff) {
146 command_line_.AppendSwitchASCII("use-spdy", "off");
147 // Command line should overwrite field trial group.
148 field_trial_group_ = "Spdy4Enabled";
149 ConfigureSpdyGlobals();
150 EXPECT_EQ(0u, globals_.next_protos.size());
153 TEST_F(IOThreadTest, SpdyCommandLineUseSpdyDisableAltProtocols) {
154 command_line_.AppendSwitchASCII("use-spdy", "no-alt-protocols");
155 ConfigureSpdyGlobals();
156 bool use_alternative_services = true;
157 globals_.use_alternative_services.CopyToIfSet(&use_alternative_services);
158 EXPECT_FALSE(use_alternative_services);
161 TEST_F(IOThreadTest, DisableQuicByDefault) {
162 ConfigureQuicGlobals();
163 net::HttpNetworkSession::Params params;
164 InitializeNetworkSessionParams(&params);
165 EXPECT_FALSE(params.enable_quic);
166 EXPECT_FALSE(params.enable_quic_for_proxies);
167 EXPECT_FALSE(IOThread::ShouldEnableQuicForDataReductionProxy());
170 TEST_F(IOThreadTest, EnableQuicFromFieldTrialGroup) {
171 field_trial_group_ = "Enabled";
173 ConfigureQuicGlobals();
174 net::HttpNetworkSession::Params default_params;
175 net::HttpNetworkSession::Params params;
176 InitializeNetworkSessionParams(&params);
177 EXPECT_TRUE(params.enable_quic);
178 EXPECT_FALSE(params.enable_insecure_quic);
179 EXPECT_TRUE(params.enable_quic_for_proxies);
180 EXPECT_EQ(1350u, params.quic_max_packet_length);
181 EXPECT_EQ(1.0, params.alternative_service_probability_threshold);
182 EXPECT_EQ(default_params.quic_supported_versions,
183 params.quic_supported_versions);
184 EXPECT_EQ(net::QuicTagVector(), params.quic_connection_options);
185 EXPECT_FALSE(params.quic_always_require_handshake_confirmation);
186 EXPECT_FALSE(params.quic_disable_connection_pooling);
187 EXPECT_EQ(0.25f, params.quic_load_server_info_timeout_srtt_multiplier);
188 EXPECT_FALSE(params.quic_enable_connection_racing);
189 EXPECT_FALSE(params.quic_enable_non_blocking_io);
190 EXPECT_FALSE(params.quic_disable_disk_cache);
191 EXPECT_FALSE(params.quic_prefer_aes);
192 EXPECT_EQ(0, params.quic_max_number_of_lossy_connections);
193 EXPECT_EQ(1.0f, params.quic_packet_loss_threshold);
194 EXPECT_FALSE(IOThread::ShouldEnableQuicForDataReductionProxy());
197 TEST_F(IOThreadTest, EnableQuicFromQuicProxyFieldTrialGroup) {
198 base::FieldTrialList field_trial_list(new base::MockEntropyProvider());
199 base::FieldTrialList::CreateFieldTrial(
200 data_reduction_proxy::params::GetQuicFieldTrialName(), "Enabled");
202 ConfigureQuicGlobals();
203 net::HttpNetworkSession::Params params;
204 InitializeNetworkSessionParams(&params);
205 EXPECT_FALSE(params.enable_quic);
206 EXPECT_TRUE(params.enable_quic_for_proxies);
207 EXPECT_TRUE(IOThread::ShouldEnableQuicForDataReductionProxy());
208 EXPECT_EQ(1024 * 1024, params.quic_socket_receive_buffer_size);
211 TEST_F(IOThreadTest, EnableQuicFromCommandLine) {
212 command_line_.AppendSwitch("enable-quic");
214 ConfigureQuicGlobals();
215 net::HttpNetworkSession::Params params;
216 InitializeNetworkSessionParams(&params);
217 EXPECT_TRUE(params.enable_quic);
218 EXPECT_TRUE(params.enable_quic_for_proxies);
219 EXPECT_FALSE(IOThread::ShouldEnableQuicForDataReductionProxy());
222 TEST_F(IOThreadTest, EnableInsecureQuicFromFieldTrialParams) {
223 field_trial_group_ = "Enabled";
224 field_trial_params_["enable_insecure_quic"] = "true";
226 ConfigureQuicGlobals();
227 net::HttpNetworkSession::Params params;
228 InitializeNetworkSessionParams(&params);
229 EXPECT_TRUE(params.enable_insecure_quic);
232 TEST_F(IOThreadTest, EnableInsecureQuicCommandLine) {
233 command_line_.AppendSwitch("enable-quic");
234 command_line_.AppendSwitch("enable-insecure-quic");
236 ConfigureQuicGlobals();
237 net::HttpNetworkSession::Params params;
238 InitializeNetworkSessionParams(&params);
239 EXPECT_TRUE(params.enable_insecure_quic);
242 TEST_F(IOThreadTest, PacketLengthFromCommandLine) {
243 command_line_.AppendSwitch("enable-quic");
244 command_line_.AppendSwitchASCII("quic-max-packet-length", "1450");
246 ConfigureQuicGlobals();
247 net::HttpNetworkSession::Params params;
248 InitializeNetworkSessionParams(&params);
249 EXPECT_EQ(1450u, params.quic_max_packet_length);
252 TEST_F(IOThreadTest, PacketLengthFromFieldTrialParams) {
253 field_trial_group_ = "Enabled";
254 field_trial_params_["max_packet_length"] = "1450";
256 ConfigureQuicGlobals();
257 net::HttpNetworkSession::Params params;
258 InitializeNetworkSessionParams(&params);
259 EXPECT_EQ(1450u, params.quic_max_packet_length);
262 TEST_F(IOThreadTest, QuicVersionFromCommandLine) {
263 command_line_.AppendSwitch("enable-quic");
264 std::string version =
265 net::QuicVersionToString(net::QuicSupportedVersions().back());
266 command_line_.AppendSwitchASCII("quic-version", version);
268 ConfigureQuicGlobals();
269 net::HttpNetworkSession::Params params;
270 InitializeNetworkSessionParams(&params);
271 net::QuicVersionVector supported_versions;
272 supported_versions.push_back(net::QuicSupportedVersions().back());
273 EXPECT_EQ(supported_versions, params.quic_supported_versions);
276 TEST_F(IOThreadTest, QuicVersionFromFieldTrialParams) {
277 field_trial_group_ = "Enabled";
278 field_trial_params_["quic_version"] =
279 net::QuicVersionToString(net::QuicSupportedVersions().back());
281 ConfigureQuicGlobals();
282 net::HttpNetworkSession::Params params;
283 InitializeNetworkSessionParams(&params);
284 net::QuicVersionVector supported_versions;
285 supported_versions.push_back(net::QuicSupportedVersions().back());
286 EXPECT_EQ(supported_versions, params.quic_supported_versions);
289 TEST_F(IOThreadTest, QuicConnectionOptionsFromCommandLine) {
290 command_line_.AppendSwitch("enable-quic");
291 command_line_.AppendSwitchASCII("quic-connection-options",
292 "TIME,TBBR,REJ");
294 ConfigureQuicGlobals();
295 net::HttpNetworkSession::Params params;
296 InitializeNetworkSessionParams(&params);
298 net::QuicTagVector options;
299 options.push_back(net::kTIME);
300 options.push_back(net::kTBBR);
301 options.push_back(net::kREJ);
302 EXPECT_EQ(options, params.quic_connection_options);
305 TEST_F(IOThreadTest, QuicConnectionOptionsFromFieldTrialParams) {
306 field_trial_group_ = "Enabled";
307 field_trial_params_["connection_options"] = "TIME,TBBR,REJ";
309 ConfigureQuicGlobals();
310 net::HttpNetworkSession::Params params;
311 InitializeNetworkSessionParams(&params);
313 net::QuicTagVector options;
314 options.push_back(net::kTIME);
315 options.push_back(net::kTBBR);
316 options.push_back(net::kREJ);
317 EXPECT_EQ(options, params.quic_connection_options);
320 TEST_F(IOThreadTest,
321 QuicAlwaysRequireHandshakeConfirmationFromFieldTrialParams) {
322 field_trial_group_ = "Enabled";
323 field_trial_params_["always_require_handshake_confirmation"] = "true";
324 ConfigureQuicGlobals();
325 net::HttpNetworkSession::Params params;
326 InitializeNetworkSessionParams(&params);
327 EXPECT_TRUE(params.quic_always_require_handshake_confirmation);
330 TEST_F(IOThreadTest,
331 QuicDisableConnectionPoolingFromFieldTrialParams) {
332 field_trial_group_ = "Enabled";
333 field_trial_params_["disable_connection_pooling"] = "true";
334 ConfigureQuicGlobals();
335 net::HttpNetworkSession::Params params;
336 InitializeNetworkSessionParams(&params);
337 EXPECT_TRUE(params.quic_disable_connection_pooling);
340 TEST_F(IOThreadTest, QuicLoadServerInfoTimeToSmoothedRttFromFieldTrialParams) {
341 field_trial_group_ = "Enabled";
342 field_trial_params_["load_server_info_time_to_srtt"] = "0.5";
343 ConfigureQuicGlobals();
344 net::HttpNetworkSession::Params params;
345 InitializeNetworkSessionParams(&params);
346 EXPECT_EQ(0.5f, params.quic_load_server_info_timeout_srtt_multiplier);
349 TEST_F(IOThreadTest, QuicEnableConnectionRacing) {
350 field_trial_group_ = "Enabled";
351 field_trial_params_["enable_connection_racing"] = "true";
352 ConfigureQuicGlobals();
353 net::HttpNetworkSession::Params params;
354 InitializeNetworkSessionParams(&params);
355 EXPECT_TRUE(params.quic_enable_connection_racing);
358 TEST_F(IOThreadTest, QuicEnableNonBlockingIO) {
359 field_trial_group_ = "Enabled";
360 field_trial_params_["enable_non_blocking_io"] = "true";
361 ConfigureQuicGlobals();
362 net::HttpNetworkSession::Params params;
363 InitializeNetworkSessionParams(&params);
364 EXPECT_TRUE(params.quic_enable_non_blocking_io);
367 TEST_F(IOThreadTest, QuicDisableDiskCache) {
368 field_trial_group_ = "Enabled";
369 field_trial_params_["disable_disk_cache"] = "true";
370 ConfigureQuicGlobals();
371 net::HttpNetworkSession::Params params;
372 InitializeNetworkSessionParams(&params);
373 EXPECT_TRUE(params.quic_disable_disk_cache);
376 TEST_F(IOThreadTest, QuicPreferAes) {
377 field_trial_group_ = "Enabled";
378 field_trial_params_["prefer_aes"] = "true";
379 ConfigureQuicGlobals();
380 net::HttpNetworkSession::Params params;
381 InitializeNetworkSessionParams(&params);
382 EXPECT_TRUE(params.quic_prefer_aes);
385 TEST_F(IOThreadTest, QuicMaxNumberOfLossyConnectionsFieldTrialParams) {
386 field_trial_group_ = "Enabled";
387 field_trial_params_["max_number_of_lossy_connections"] = "5";
388 ConfigureQuicGlobals();
389 net::HttpNetworkSession::Params params;
390 InitializeNetworkSessionParams(&params);
391 EXPECT_EQ(5, params.quic_max_number_of_lossy_connections);
394 TEST_F(IOThreadTest, QuicPacketLossThresholdFieldTrialParams) {
395 field_trial_group_ = "Enabled";
396 field_trial_params_["packet_loss_threshold"] = "0.5";
397 ConfigureQuicGlobals();
398 net::HttpNetworkSession::Params params;
399 InitializeNetworkSessionParams(&params);
400 EXPECT_EQ(0.5f, params.quic_packet_loss_threshold);
403 TEST_F(IOThreadTest, QuicReceiveBufferSize) {
404 field_trial_group_ = "Enabled";
405 field_trial_params_["receive_buffer_size"] = "2097152";
406 ConfigureQuicGlobals();
407 net::HttpNetworkSession::Params params;
408 InitializeNetworkSessionParams(&params);
409 EXPECT_EQ(2097152, params.quic_socket_receive_buffer_size);
412 TEST_F(IOThreadTest, AlternativeServiceProbabilityThresholdFromFlag) {
413 command_line_.AppendSwitchASCII("alternative-service-probability-threshold",
414 "0.5");
416 ConfigureQuicGlobals();
417 net::HttpNetworkSession::Params params;
418 InitializeNetworkSessionParams(&params);
419 EXPECT_EQ(.5, params.alternative_service_probability_threshold);
422 TEST_F(IOThreadTest, AlternativeServiceProbabilityThresholdFromEnableQuicFlag) {
423 command_line_.AppendSwitch("enable-quic");
425 ConfigureQuicGlobals();
426 net::HttpNetworkSession::Params params;
427 InitializeNetworkSessionParams(&params);
428 EXPECT_EQ(0, params.alternative_service_probability_threshold);
431 // TODO(bnc): Remove when new parameter name rolls out and server configuration
432 // is changed.
433 TEST_F(IOThreadTest, AlternativeServiceProbabilityThresholdFromOldParams) {
434 field_trial_group_ = "Enabled";
435 field_trial_params_["alternate_protocol_probability_threshold"] = ".5";
437 ConfigureQuicGlobals();
438 net::HttpNetworkSession::Params params;
439 InitializeNetworkSessionParams(&params);
440 EXPECT_EQ(.5, params.alternative_service_probability_threshold);
443 TEST_F(IOThreadTest, AlternativeServiceProbabilityThresholdFromParams) {
444 field_trial_group_ = "Enabled";
445 field_trial_params_["alternative_service_probability_threshold"] = ".5";
447 ConfigureQuicGlobals();
448 net::HttpNetworkSession::Params params;
449 InitializeNetworkSessionParams(&params);
450 EXPECT_EQ(.5, params.alternative_service_probability_threshold);
453 TEST_F(IOThreadTest, QuicDisallowedByPolicy) {
454 command_line_.AppendSwitch(switches::kEnableQuic);
455 is_quic_allowed_by_policy_ = false;
456 ConfigureQuicGlobals();
458 net::HttpNetworkSession::Params params;
459 InitializeNetworkSessionParams(&params);
460 EXPECT_FALSE(params.enable_quic);
463 } // namespace test