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"
15 using ::testing::ElementsAre
;
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
{
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(¶ms
);
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
,
86 globals_
.use_alternate_protocols
.CopyToIfSet(&use_alternate_protocols
);
87 EXPECT_TRUE(use_alternate_protocols
);
90 TEST_F(IOThreadTest
, SpdyFieldTrialSpdy4Enabled
) {
91 bool use_alternate_protocols
= false;
92 IOThreadPeer::ConfigureSpdyFromTrial("Spdy4Enabled", &globals_
);
93 EXPECT_THAT(globals_
.next_protos
,
94 ElementsAre(net::kProtoHTTP11
,
95 net::kProtoQUIC1SPDY3
,
99 globals_
.use_alternate_protocols
.CopyToIfSet(&use_alternate_protocols
);
100 EXPECT_TRUE(use_alternate_protocols
);
103 TEST_F(IOThreadTest
, SpdyFieldTrialSpdy4Control
) {
104 bool use_alternate_protocols
= false;
105 IOThreadPeer::ConfigureSpdyFromTrial("Spdy4Control", &globals_
);
106 EXPECT_THAT(globals_
.next_protos
,
107 ElementsAre(net::kProtoHTTP11
,
108 net::kProtoQUIC1SPDY3
,
111 globals_
.use_alternate_protocols
.CopyToIfSet(&use_alternate_protocols
);
112 EXPECT_TRUE(use_alternate_protocols
);
115 TEST_F(IOThreadTest
, DisableQuicByDefault
) {
116 ConfigureQuicGlobals();
117 net::HttpNetworkSession::Params params
;
118 InitializeNetworkSessionParams(¶ms
);
119 EXPECT_FALSE(params
.enable_quic
);
122 TEST_F(IOThreadTest
, EnableQuicFromFieldTrialGroup
) {
123 field_trial_group_
= "Enabled";
125 ConfigureQuicGlobals();
126 net::HttpNetworkSession::Params default_params
;
127 net::HttpNetworkSession::Params params
;
128 InitializeNetworkSessionParams(¶ms
);
129 EXPECT_TRUE(params
.enable_quic
);
130 EXPECT_EQ(1350u, params
.quic_max_packet_length
);
131 EXPECT_EQ(1.0, params
.alternate_protocol_probability_threshold
);
132 EXPECT_EQ(default_params
.quic_supported_versions
,
133 params
.quic_supported_versions
);
134 EXPECT_EQ(net::QuicTagVector(), params
.quic_connection_options
);
135 EXPECT_FALSE(params
.quic_always_require_handshake_confirmation
);
136 EXPECT_FALSE(params
.quic_disable_connection_pooling
);
139 TEST_F(IOThreadTest
, EnableQuicFromCommandLine
) {
140 command_line_
.AppendSwitch("enable-quic");
142 ConfigureQuicGlobals();
143 net::HttpNetworkSession::Params params
;
144 InitializeNetworkSessionParams(¶ms
);
145 EXPECT_TRUE(params
.enable_quic
);
148 TEST_F(IOThreadTest
, EnablePacingFromCommandLine
) {
149 command_line_
.AppendSwitch("enable-quic");
150 command_line_
.AppendSwitch("enable-quic-pacing");
152 ConfigureQuicGlobals();
153 net::HttpNetworkSession::Params params
;
154 InitializeNetworkSessionParams(¶ms
);
155 net::QuicTagVector options
;
156 options
.push_back(net::kPACE
);
157 EXPECT_EQ(options
, params
.quic_connection_options
);
160 TEST_F(IOThreadTest
, EnablePacingFromFieldTrialGroup
) {
161 field_trial_group_
= "EnabledWithPacing";
163 ConfigureQuicGlobals();
164 net::HttpNetworkSession::Params params
;
165 InitializeNetworkSessionParams(¶ms
);
166 net::QuicTagVector options
;
167 options
.push_back(net::kPACE
);
168 EXPECT_EQ(options
, params
.quic_connection_options
);
171 TEST_F(IOThreadTest
, EnablePacingFromFieldTrialParams
) {
172 field_trial_group_
= "Enabled";
173 field_trial_params_
["enable_pacing"] = "true";
175 ConfigureQuicGlobals();
176 net::HttpNetworkSession::Params params
;
177 InitializeNetworkSessionParams(¶ms
);
178 net::QuicTagVector options
;
179 options
.push_back(net::kPACE
);
180 EXPECT_EQ(options
, params
.quic_connection_options
);
183 TEST_F(IOThreadTest
, PacketLengthFromCommandLine
) {
184 command_line_
.AppendSwitch("enable-quic");
185 command_line_
.AppendSwitchASCII("quic-max-packet-length", "1350");
187 ConfigureQuicGlobals();
188 net::HttpNetworkSession::Params params
;
189 InitializeNetworkSessionParams(¶ms
);
190 EXPECT_EQ(1350u, params
.quic_max_packet_length
);
193 TEST_F(IOThreadTest
, PacketLengthFromFieldTrialGroup
) {
194 field_trial_group_
= "Enabled1350BytePackets";
196 ConfigureQuicGlobals();
197 net::HttpNetworkSession::Params params
;
198 InitializeNetworkSessionParams(¶ms
);
199 EXPECT_EQ(1350u, params
.quic_max_packet_length
);
202 TEST_F(IOThreadTest
, PacketLengthFromFieldTrialParams
) {
203 field_trial_group_
= "Enabled";
204 field_trial_params_
["max_packet_length"] = "1350";
206 ConfigureQuicGlobals();
207 net::HttpNetworkSession::Params params
;
208 InitializeNetworkSessionParams(¶ms
);
209 EXPECT_EQ(1350u, params
.quic_max_packet_length
);
212 TEST_F(IOThreadTest
, QuicVersionFromCommandLine
) {
213 command_line_
.AppendSwitch("enable-quic");
214 std::string version
=
215 net::QuicVersionToString(net::QuicSupportedVersions().back());
216 command_line_
.AppendSwitchASCII("quic-version", version
);
218 ConfigureQuicGlobals();
219 net::HttpNetworkSession::Params params
;
220 InitializeNetworkSessionParams(¶ms
);
221 net::QuicVersionVector supported_versions
;
222 supported_versions
.push_back(net::QuicSupportedVersions().back());
223 EXPECT_EQ(supported_versions
,
224 params
.quic_supported_versions
);
227 TEST_F(IOThreadTest
, QuicVersionFromFieldTrialParams
) {
228 field_trial_group_
= "Enabled";
229 field_trial_params_
["quic_version"] =
230 net::QuicVersionToString(net::QuicSupportedVersions().back());
232 ConfigureQuicGlobals();
233 net::HttpNetworkSession::Params params
;
234 InitializeNetworkSessionParams(¶ms
);
235 net::QuicVersionVector supported_versions
;
236 supported_versions
.push_back(net::QuicSupportedVersions().back());
237 EXPECT_EQ(supported_versions
,
238 params
.quic_supported_versions
);
241 TEST_F(IOThreadTest
, QuicConnectionOptionsFromCommandLine
) {
242 command_line_
.AppendSwitch("enable-quic");
243 command_line_
.AppendSwitchASCII("quic-connection-options",
244 "PACE,TIME,TBBR,REJ");
246 ConfigureQuicGlobals();
247 net::HttpNetworkSession::Params params
;
248 InitializeNetworkSessionParams(¶ms
);
250 net::QuicTagVector options
;
251 options
.push_back(net::kPACE
);
252 options
.push_back(net::kTIME
);
253 options
.push_back(net::kTBBR
);
254 options
.push_back(net::kREJ
);
255 EXPECT_EQ(options
, params
.quic_connection_options
);
258 TEST_F(IOThreadTest
, QuicConnectionOptionsFromFieldTrialParams
) {
259 field_trial_group_
= "Enabled";
260 field_trial_params_
["connection_options"] = "PACE,TIME,TBBR,REJ";
262 ConfigureQuicGlobals();
263 net::HttpNetworkSession::Params params
;
264 InitializeNetworkSessionParams(¶ms
);
266 net::QuicTagVector options
;
267 options
.push_back(net::kPACE
);
268 options
.push_back(net::kTIME
);
269 options
.push_back(net::kTBBR
);
270 options
.push_back(net::kREJ
);
271 EXPECT_EQ(options
, params
.quic_connection_options
);
274 TEST_F(IOThreadTest
, QuicConnectionOptionsFromDeprecatedFieldTrialParams
) {
275 field_trial_group_
= "Enabled";
276 field_trial_params_
["congestion_options"] = "PACE,TIME,TBBR,REJ";
278 ConfigureQuicGlobals();
279 net::HttpNetworkSession::Params params
;
280 InitializeNetworkSessionParams(¶ms
);
282 net::QuicTagVector options
;
283 options
.push_back(net::kPACE
);
284 options
.push_back(net::kTIME
);
285 options
.push_back(net::kTBBR
);
286 options
.push_back(net::kREJ
);
287 EXPECT_EQ(options
, params
.quic_connection_options
);
291 QuicAlwaysRequireHandshakeConfirmationFromFieldTrialParams
) {
292 field_trial_group_
= "Enabled";
293 field_trial_params_
["always_require_handshake_confirmation"] = "true";
294 ConfigureQuicGlobals();
295 net::HttpNetworkSession::Params params
;
296 InitializeNetworkSessionParams(¶ms
);
297 EXPECT_TRUE(params
.quic_always_require_handshake_confirmation
);
301 QuicDisableConnectionPoolingFromFieldTrialParams
) {
302 field_trial_group_
= "Enabled";
303 field_trial_params_
["disable_connection_pooling"] = "true";
304 ConfigureQuicGlobals();
305 net::HttpNetworkSession::Params params
;
306 InitializeNetworkSessionParams(¶ms
);
307 EXPECT_TRUE(params
.quic_disable_connection_pooling
);
311 AlternateProtocolProbabilityThresholdFromFlag
) {
312 command_line_
.AppendSwitchASCII("alternate-protocol-probability-threshold",
315 ConfigureQuicGlobals();
316 net::HttpNetworkSession::Params params
;
317 InitializeNetworkSessionParams(¶ms
);
318 EXPECT_EQ(.5, params
.alternate_protocol_probability_threshold
);
322 AlternateProtocolProbabilityThresholdFromEnableQuicFlag
) {
323 command_line_
.AppendSwitch("enable-quic");
325 ConfigureQuicGlobals();
326 net::HttpNetworkSession::Params params
;
327 InitializeNetworkSessionParams(¶ms
);
328 EXPECT_EQ(0, params
.alternate_protocol_probability_threshold
);
332 AlternateProtocolProbabilityThresholdFromParams
) {
333 field_trial_group_
= "Enabled";
334 field_trial_params_
["alternate_protocol_probability_threshold"] = ".5";
336 ConfigureQuicGlobals();
337 net::HttpNetworkSession::Params params
;
338 InitializeNetworkSessionParams(¶ms
);
339 EXPECT_EQ(.5, params
.alternate_protocol_probability_threshold
);