Roll src/third_party/WebKit 8b42d1d:744641d (svn 186770:186771)
[chromium-blink-merge.git] / chrome / browser / io_thread_unittest.cc
blobe11676a6f81367be8dc6ddf5a0e37417a5c5c2af
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 "chrome/browser/io_thread.h"
7 #include "net/http/http_network_session.h"
8 #include "net/http/http_server_properties_impl.h"
9 #include "net/quic/quic_protocol.h"
10 #include "testing/gmock/include/gmock/gmock.h"
11 #include "testing/gtest/include/gtest/gtest.h"
13 namespace test {
15 using ::testing::ElementsAre;
17 class IOThreadPeer {
18 public:
19 static void ConfigureQuicGlobals(
20 const base::CommandLine& command_line,
21 base::StringPiece quic_trial_group,
22 const std::map<std::string, std::string>& quic_trial_params,
23 IOThread::Globals* globals) {
24 IOThread::ConfigureQuicGlobals(command_line, quic_trial_group,
25 quic_trial_params, globals);
28 static void InitializeNetworkSessionParamsFromGlobals(
29 const IOThread::Globals& globals,
30 net::HttpNetworkSession::Params* params) {
31 IOThread::InitializeNetworkSessionParamsFromGlobals(globals, params);
34 static void ConfigureSpdyFromTrial(const std::string& trial_group,
35 IOThread::Globals* globals) {
36 IOThread::ConfigureSpdyFromTrial(trial_group, globals);
40 class IOThreadTest : public testing::Test {
41 public:
42 IOThreadTest() : command_line_(base::CommandLine::NO_PROGRAM) {
43 globals_.http_server_properties.reset(new net::HttpServerPropertiesImpl());
46 void ConfigureQuicGlobals() {
47 IOThreadPeer::ConfigureQuicGlobals(command_line_, field_trial_group_,
48 field_trial_params_, &globals_);
51 void InitializeNetworkSessionParams(net::HttpNetworkSession::Params* params) {
52 IOThreadPeer::InitializeNetworkSessionParamsFromGlobals(globals_, params);
55 base::CommandLine command_line_;
56 IOThread::Globals globals_;
57 std::string field_trial_group_;
58 std::map<std::string, std::string> field_trial_params_;
61 TEST_F(IOThreadTest, InitializeNetworkSessionParamsFromGlobals) {
62 globals_.quic_connection_options.push_back(net::kPACE);
63 globals_.quic_connection_options.push_back(net::kTBBR);
64 globals_.quic_connection_options.push_back(net::kTIME);
66 net::HttpNetworkSession::Params params;
67 InitializeNetworkSessionParams(&params);
68 EXPECT_EQ(globals_.quic_connection_options,
69 params.quic_connection_options);
72 TEST_F(IOThreadTest, SpdyFieldTrialHoldbackEnabled) {
73 net::HttpStreamFactory::set_spdy_enabled(true);
74 IOThreadPeer::ConfigureSpdyFromTrial("SpdyDisabled", &globals_);
75 EXPECT_FALSE(net::HttpStreamFactory::spdy_enabled());
78 TEST_F(IOThreadTest, SpdyFieldTrialHoldbackControl) {
79 bool use_alternate_protocols = false;
80 IOThreadPeer::ConfigureSpdyFromTrial("Control", &globals_);
81 EXPECT_THAT(globals_.next_protos,
82 ElementsAre(net::kProtoHTTP11,
83 net::kProtoQUIC1SPDY3,
84 net::kProtoSPDY31));
85 globals_.use_alternate_protocols.CopyToIfSet(&use_alternate_protocols);
86 EXPECT_TRUE(use_alternate_protocols);
89 TEST_F(IOThreadTest, SpdyFieldTrialSpdy4Enabled) {
90 bool use_alternate_protocols = false;
91 IOThreadPeer::ConfigureSpdyFromTrial("Spdy4Enabled", &globals_);
92 EXPECT_THAT(globals_.next_protos,
93 ElementsAre(net::kProtoHTTP11,
94 net::kProtoQUIC1SPDY3,
95 net::kProtoSPDY31,
96 net::kProtoSPDY4_14,
97 net::kProtoSPDY4_15));
98 globals_.use_alternate_protocols.CopyToIfSet(&use_alternate_protocols);
99 EXPECT_TRUE(use_alternate_protocols);
102 TEST_F(IOThreadTest, SpdyFieldTrialSpdy4Control) {
103 bool use_alternate_protocols = false;
104 IOThreadPeer::ConfigureSpdyFromTrial("Spdy4Control", &globals_);
105 EXPECT_THAT(globals_.next_protos,
106 ElementsAre(net::kProtoHTTP11,
107 net::kProtoQUIC1SPDY3,
108 net::kProtoSPDY31));
109 globals_.use_alternate_protocols.CopyToIfSet(&use_alternate_protocols);
110 EXPECT_TRUE(use_alternate_protocols);
113 TEST_F(IOThreadTest, DisableQuicByDefault) {
114 ConfigureQuicGlobals();
115 net::HttpNetworkSession::Params params;
116 InitializeNetworkSessionParams(&params);
117 EXPECT_FALSE(params.enable_quic);
120 TEST_F(IOThreadTest, EnableQuicFromFieldTrialGroup) {
121 field_trial_group_ = "Enabled";
123 ConfigureQuicGlobals();
124 net::HttpNetworkSession::Params default_params;
125 net::HttpNetworkSession::Params params;
126 InitializeNetworkSessionParams(&params);
127 EXPECT_TRUE(params.enable_quic);
128 EXPECT_EQ(1350u, params.quic_max_packet_length);
129 EXPECT_EQ(1.0, params.alternate_protocol_probability_threshold);
130 EXPECT_EQ(default_params.quic_supported_versions,
131 params.quic_supported_versions);
132 EXPECT_EQ(net::QuicTagVector(), params.quic_connection_options);
133 EXPECT_FALSE(params.quic_always_require_handshake_confirmation);
134 EXPECT_FALSE(params.quic_disable_connection_pooling);
135 EXPECT_EQ(0, params.quic_load_server_info_timeout_ms);
138 TEST_F(IOThreadTest, EnableQuicFromCommandLine) {
139 command_line_.AppendSwitch("enable-quic");
141 ConfigureQuicGlobals();
142 net::HttpNetworkSession::Params params;
143 InitializeNetworkSessionParams(&params);
144 EXPECT_TRUE(params.enable_quic);
147 TEST_F(IOThreadTest, EnablePacingFromCommandLine) {
148 command_line_.AppendSwitch("enable-quic");
149 command_line_.AppendSwitch("enable-quic-pacing");
151 ConfigureQuicGlobals();
152 net::HttpNetworkSession::Params params;
153 InitializeNetworkSessionParams(&params);
154 net::QuicTagVector options;
155 options.push_back(net::kPACE);
156 EXPECT_EQ(options, params.quic_connection_options);
159 TEST_F(IOThreadTest, EnablePacingFromFieldTrialParams) {
160 field_trial_group_ = "Enabled";
161 field_trial_params_["enable_pacing"] = "true";
163 ConfigureQuicGlobals();
164 net::HttpNetworkSession::Params params;
165 InitializeNetworkSessionParams(&params);
166 net::QuicTagVector options;
167 options.push_back(net::kPACE);
168 EXPECT_EQ(options, params.quic_connection_options);
171 TEST_F(IOThreadTest, PacketLengthFromCommandLine) {
172 command_line_.AppendSwitch("enable-quic");
173 command_line_.AppendSwitchASCII("quic-max-packet-length", "1450");
175 ConfigureQuicGlobals();
176 net::HttpNetworkSession::Params params;
177 InitializeNetworkSessionParams(&params);
178 EXPECT_EQ(1450u, params.quic_max_packet_length);
181 TEST_F(IOThreadTest, PacketLengthFromFieldTrialParams) {
182 field_trial_group_ = "Enabled";
183 field_trial_params_["max_packet_length"] = "1450";
185 ConfigureQuicGlobals();
186 net::HttpNetworkSession::Params params;
187 InitializeNetworkSessionParams(&params);
188 EXPECT_EQ(1450u, params.quic_max_packet_length);
191 TEST_F(IOThreadTest, QuicVersionFromCommandLine) {
192 command_line_.AppendSwitch("enable-quic");
193 std::string version =
194 net::QuicVersionToString(net::QuicSupportedVersions().back());
195 command_line_.AppendSwitchASCII("quic-version", version);
197 ConfigureQuicGlobals();
198 net::HttpNetworkSession::Params params;
199 InitializeNetworkSessionParams(&params);
200 net::QuicVersionVector supported_versions;
201 supported_versions.push_back(net::QuicSupportedVersions().back());
202 EXPECT_EQ(supported_versions,
203 params.quic_supported_versions);
206 TEST_F(IOThreadTest, QuicVersionFromFieldTrialParams) {
207 field_trial_group_ = "Enabled";
208 field_trial_params_["quic_version"] =
209 net::QuicVersionToString(net::QuicSupportedVersions().back());
211 ConfigureQuicGlobals();
212 net::HttpNetworkSession::Params params;
213 InitializeNetworkSessionParams(&params);
214 net::QuicVersionVector supported_versions;
215 supported_versions.push_back(net::QuicSupportedVersions().back());
216 EXPECT_EQ(supported_versions,
217 params.quic_supported_versions);
220 TEST_F(IOThreadTest, QuicConnectionOptionsFromCommandLine) {
221 command_line_.AppendSwitch("enable-quic");
222 command_line_.AppendSwitchASCII("quic-connection-options",
223 "PACE,TIME,TBBR,REJ");
225 ConfigureQuicGlobals();
226 net::HttpNetworkSession::Params params;
227 InitializeNetworkSessionParams(&params);
229 net::QuicTagVector options;
230 options.push_back(net::kPACE);
231 options.push_back(net::kTIME);
232 options.push_back(net::kTBBR);
233 options.push_back(net::kREJ);
234 EXPECT_EQ(options, params.quic_connection_options);
237 TEST_F(IOThreadTest, QuicConnectionOptionsFromFieldTrialParams) {
238 field_trial_group_ = "Enabled";
239 field_trial_params_["connection_options"] = "PACE,TIME,TBBR,REJ";
241 ConfigureQuicGlobals();
242 net::HttpNetworkSession::Params params;
243 InitializeNetworkSessionParams(&params);
245 net::QuicTagVector options;
246 options.push_back(net::kPACE);
247 options.push_back(net::kTIME);
248 options.push_back(net::kTBBR);
249 options.push_back(net::kREJ);
250 EXPECT_EQ(options, params.quic_connection_options);
253 TEST_F(IOThreadTest, QuicConnectionOptionsFromDeprecatedFieldTrialParams) {
254 field_trial_group_ = "Enabled";
255 field_trial_params_["congestion_options"] = "PACE,TIME,TBBR,REJ";
257 ConfigureQuicGlobals();
258 net::HttpNetworkSession::Params params;
259 InitializeNetworkSessionParams(&params);
261 net::QuicTagVector options;
262 options.push_back(net::kPACE);
263 options.push_back(net::kTIME);
264 options.push_back(net::kTBBR);
265 options.push_back(net::kREJ);
266 EXPECT_EQ(options, params.quic_connection_options);
269 TEST_F(IOThreadTest,
270 QuicAlwaysRequireHandshakeConfirmationFromFieldTrialParams) {
271 field_trial_group_ = "Enabled";
272 field_trial_params_["always_require_handshake_confirmation"] = "true";
273 ConfigureQuicGlobals();
274 net::HttpNetworkSession::Params params;
275 InitializeNetworkSessionParams(&params);
276 EXPECT_TRUE(params.quic_always_require_handshake_confirmation);
279 TEST_F(IOThreadTest,
280 QuicDisableConnectionPoolingFromFieldTrialParams) {
281 field_trial_group_ = "Enabled";
282 field_trial_params_["disable_connection_pooling"] = "true";
283 ConfigureQuicGlobals();
284 net::HttpNetworkSession::Params params;
285 InitializeNetworkSessionParams(&params);
286 EXPECT_TRUE(params.quic_disable_connection_pooling);
289 TEST_F(IOThreadTest, QuicLoadServerInfoTimeoutFromFieldTrialParams) {
290 field_trial_group_ = "Enabled";
291 field_trial_params_["load_server_info_timeout"] = "50";
292 ConfigureQuicGlobals();
293 net::HttpNetworkSession::Params params;
294 InitializeNetworkSessionParams(&params);
295 EXPECT_EQ(50, params.quic_load_server_info_timeout_ms);
298 TEST_F(IOThreadTest,
299 AlternateProtocolProbabilityThresholdFromFlag) {
300 command_line_.AppendSwitchASCII("alternate-protocol-probability-threshold",
301 ".5");
303 ConfigureQuicGlobals();
304 net::HttpNetworkSession::Params params;
305 InitializeNetworkSessionParams(&params);
306 EXPECT_EQ(.5, params.alternate_protocol_probability_threshold);
309 TEST_F(IOThreadTest,
310 AlternateProtocolProbabilityThresholdFromEnableQuicFlag) {
311 command_line_.AppendSwitch("enable-quic");
313 ConfigureQuicGlobals();
314 net::HttpNetworkSession::Params params;
315 InitializeNetworkSessionParams(&params);
316 EXPECT_EQ(0, params.alternate_protocol_probability_threshold);
319 TEST_F(IOThreadTest,
320 AlternateProtocolProbabilityThresholdFromParams) {
321 field_trial_group_ = "Enabled";
322 field_trial_params_["alternate_protocol_probability_threshold"] = ".5";
324 ConfigureQuicGlobals();
325 net::HttpNetworkSession::Params params;
326 InitializeNetworkSessionParams(&params);
327 EXPECT_EQ(.5, params.alternate_protocol_probability_threshold);
330 } // namespace test