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
,
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
,
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
,
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(¶ms
);
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(¶ms
);
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(¶ms
);
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(¶ms
);
154 net::QuicTagVector options
;
155 options
.push_back(net::kPACE
);
156 EXPECT_EQ(options
, params
.quic_connection_options
);
159 TEST_F(IOThreadTest
, EnablePacingFromFieldTrialGroup
) {
160 field_trial_group_
= "EnabledWithPacing";
162 ConfigureQuicGlobals();
163 net::HttpNetworkSession::Params params
;
164 InitializeNetworkSessionParams(¶ms
);
165 net::QuicTagVector options
;
166 options
.push_back(net::kPACE
);
167 EXPECT_EQ(options
, params
.quic_connection_options
);
170 TEST_F(IOThreadTest
, EnablePacingFromFieldTrialParams
) {
171 field_trial_group_
= "Enabled";
172 field_trial_params_
["enable_pacing"] = "true";
174 ConfigureQuicGlobals();
175 net::HttpNetworkSession::Params params
;
176 InitializeNetworkSessionParams(¶ms
);
177 net::QuicTagVector options
;
178 options
.push_back(net::kPACE
);
179 EXPECT_EQ(options
, params
.quic_connection_options
);
182 TEST_F(IOThreadTest
, PacketLengthFromCommandLine
) {
183 command_line_
.AppendSwitch("enable-quic");
184 command_line_
.AppendSwitchASCII("quic-max-packet-length", "1350");
186 ConfigureQuicGlobals();
187 net::HttpNetworkSession::Params params
;
188 InitializeNetworkSessionParams(¶ms
);
189 EXPECT_EQ(1350u, params
.quic_max_packet_length
);
192 TEST_F(IOThreadTest
, PacketLengthFromFieldTrialGroup
) {
193 field_trial_group_
= "Enabled1350BytePackets";
195 ConfigureQuicGlobals();
196 net::HttpNetworkSession::Params params
;
197 InitializeNetworkSessionParams(¶ms
);
198 EXPECT_EQ(1350u, params
.quic_max_packet_length
);
201 TEST_F(IOThreadTest
, PacketLengthFromFieldTrialParams
) {
202 field_trial_group_
= "Enabled";
203 field_trial_params_
["max_packet_length"] = "1350";
205 ConfigureQuicGlobals();
206 net::HttpNetworkSession::Params params
;
207 InitializeNetworkSessionParams(¶ms
);
208 EXPECT_EQ(1350u, params
.quic_max_packet_length
);
211 TEST_F(IOThreadTest
, QuicVersionFromCommandLine
) {
212 command_line_
.AppendSwitch("enable-quic");
213 std::string version
=
214 net::QuicVersionToString(net::QuicSupportedVersions().back());
215 command_line_
.AppendSwitchASCII("quic-version", version
);
217 ConfigureQuicGlobals();
218 net::HttpNetworkSession::Params params
;
219 InitializeNetworkSessionParams(¶ms
);
220 net::QuicVersionVector supported_versions
;
221 supported_versions
.push_back(net::QuicSupportedVersions().back());
222 EXPECT_EQ(supported_versions
,
223 params
.quic_supported_versions
);
226 TEST_F(IOThreadTest
, QuicVersionFromFieldTrialParams
) {
227 field_trial_group_
= "Enabled";
228 field_trial_params_
["quic_version"] =
229 net::QuicVersionToString(net::QuicSupportedVersions().back());
231 ConfigureQuicGlobals();
232 net::HttpNetworkSession::Params params
;
233 InitializeNetworkSessionParams(¶ms
);
234 net::QuicVersionVector supported_versions
;
235 supported_versions
.push_back(net::QuicSupportedVersions().back());
236 EXPECT_EQ(supported_versions
,
237 params
.quic_supported_versions
);
240 TEST_F(IOThreadTest
, QuicConnectionOptionsFromCommandLine
) {
241 command_line_
.AppendSwitch("enable-quic");
242 command_line_
.AppendSwitchASCII("quic-connection-options",
243 "PACE,TIME,TBBR,REJ");
245 ConfigureQuicGlobals();
246 net::HttpNetworkSession::Params params
;
247 InitializeNetworkSessionParams(¶ms
);
249 net::QuicTagVector options
;
250 options
.push_back(net::kPACE
);
251 options
.push_back(net::kTIME
);
252 options
.push_back(net::kTBBR
);
253 options
.push_back(net::kREJ
);
254 EXPECT_EQ(options
, params
.quic_connection_options
);
257 TEST_F(IOThreadTest
, QuicConnectionOptionsFromFieldTrialParams
) {
258 field_trial_group_
= "Enabled";
259 field_trial_params_
["connection_options"] = "PACE,TIME,TBBR,REJ";
261 ConfigureQuicGlobals();
262 net::HttpNetworkSession::Params params
;
263 InitializeNetworkSessionParams(¶ms
);
265 net::QuicTagVector options
;
266 options
.push_back(net::kPACE
);
267 options
.push_back(net::kTIME
);
268 options
.push_back(net::kTBBR
);
269 options
.push_back(net::kREJ
);
270 EXPECT_EQ(options
, params
.quic_connection_options
);
273 TEST_F(IOThreadTest
, QuicConnectionOptionsFromDeprecatedFieldTrialParams
) {
274 field_trial_group_
= "Enabled";
275 field_trial_params_
["congestion_options"] = "PACE,TIME,TBBR,REJ";
277 ConfigureQuicGlobals();
278 net::HttpNetworkSession::Params params
;
279 InitializeNetworkSessionParams(¶ms
);
281 net::QuicTagVector options
;
282 options
.push_back(net::kPACE
);
283 options
.push_back(net::kTIME
);
284 options
.push_back(net::kTBBR
);
285 options
.push_back(net::kREJ
);
286 EXPECT_EQ(options
, params
.quic_connection_options
);
290 QuicAlwaysRequireHandshakeConfirmationFromFieldTrialParams
) {
291 field_trial_group_
= "Enabled";
292 field_trial_params_
["always_require_handshake_confirmation"] = "true";
293 ConfigureQuicGlobals();
294 net::HttpNetworkSession::Params params
;
295 InitializeNetworkSessionParams(¶ms
);
296 EXPECT_TRUE(params
.quic_always_require_handshake_confirmation
);
300 QuicDisableConnectionPoolingFromFieldTrialParams
) {
301 field_trial_group_
= "Enabled";
302 field_trial_params_
["disable_connection_pooling"] = "true";
303 ConfigureQuicGlobals();
304 net::HttpNetworkSession::Params params
;
305 InitializeNetworkSessionParams(¶ms
);
306 EXPECT_TRUE(params
.quic_disable_connection_pooling
);
309 TEST_F(IOThreadTest
, QuicLoadServerInfoTimeoutFromFieldTrialParams
) {
310 field_trial_group_
= "Enabled";
311 field_trial_params_
["load_server_info_timeout"] = "50";
312 ConfigureQuicGlobals();
313 net::HttpNetworkSession::Params params
;
314 InitializeNetworkSessionParams(¶ms
);
315 EXPECT_EQ(50, params
.quic_load_server_info_timeout_ms
);
319 AlternateProtocolProbabilityThresholdFromFlag
) {
320 command_line_
.AppendSwitchASCII("alternate-protocol-probability-threshold",
323 ConfigureQuicGlobals();
324 net::HttpNetworkSession::Params params
;
325 InitializeNetworkSessionParams(¶ms
);
326 EXPECT_EQ(.5, params
.alternate_protocol_probability_threshold
);
330 AlternateProtocolProbabilityThresholdFromEnableQuicFlag
) {
331 command_line_
.AppendSwitch("enable-quic");
333 ConfigureQuicGlobals();
334 net::HttpNetworkSession::Params params
;
335 InitializeNetworkSessionParams(¶ms
);
336 EXPECT_EQ(0, params
.alternate_protocol_probability_threshold
);
340 AlternateProtocolProbabilityThresholdFromParams
) {
341 field_trial_group_
= "Enabled";
342 field_trial_params_
["alternate_protocol_probability_threshold"] = ".5";
344 ConfigureQuicGlobals();
345 net::HttpNetworkSession::Params params
;
346 InitializeNetworkSessionParams(¶ms
);
347 EXPECT_EQ(.5, params
.alternate_protocol_probability_threshold
);