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_FALSE(params
.enable_quic_time_based_loss_detection
);
131 EXPECT_EQ(1350u, params
.quic_max_packet_length
);
132 EXPECT_EQ(default_params
.quic_supported_versions
,
133 params
.quic_supported_versions
);
134 EXPECT_EQ(net::QuicTagVector(), params
.quic_connection_options
);
137 TEST_F(IOThreadTest
, EnableQuicFromCommandLine
) {
138 base::CommandLine::StringVector args
;
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 base::CommandLine::StringVector args
;
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
, EnableTimeBasedLossDetectionFromCommandLine
) {
184 base::CommandLine::StringVector args
;
185 command_line_
.AppendSwitch("enable-quic");
186 command_line_
.AppendSwitch("enable-quic-time-based-loss-detection");
188 ConfigureQuicGlobals();
189 net::HttpNetworkSession::Params params
;
190 InitializeNetworkSessionParams(¶ms
);
191 EXPECT_TRUE(params
.enable_quic_time_based_loss_detection
);
194 TEST_F(IOThreadTest
, EnableTimeBasedLossDetectionFromFieldTrialGroup
) {
195 field_trial_group_
= "EnabledWithTimeBasedLossDetection";
197 ConfigureQuicGlobals();
198 net::HttpNetworkSession::Params params
;
199 InitializeNetworkSessionParams(¶ms
);
200 EXPECT_TRUE(params
.enable_quic_time_based_loss_detection
);
203 TEST_F(IOThreadTest
, EnableTimeBasedLossDetectionFromFieldTrialParams
) {
204 field_trial_group_
= "Enabled";
205 field_trial_params_
["enable_time_based_loss_detection"] = "true";
207 ConfigureQuicGlobals();
208 net::HttpNetworkSession::Params params
;
209 InitializeNetworkSessionParams(¶ms
);
210 EXPECT_TRUE(params
.enable_quic_time_based_loss_detection
);
213 TEST_F(IOThreadTest
, PacketLengthFromCommandLine
) {
214 base::CommandLine::StringVector args
;
215 command_line_
.AppendSwitch("enable-quic");
216 command_line_
.AppendSwitchASCII("quic-max-packet-length", "1350");
218 ConfigureQuicGlobals();
219 net::HttpNetworkSession::Params params
;
220 InitializeNetworkSessionParams(¶ms
);
221 EXPECT_EQ(1350u, params
.quic_max_packet_length
);
224 TEST_F(IOThreadTest
, PacketLengthFromFieldTrialGroup
) {
225 field_trial_group_
= "Enabled1350BytePackets";
227 ConfigureQuicGlobals();
228 net::HttpNetworkSession::Params params
;
229 InitializeNetworkSessionParams(¶ms
);
230 EXPECT_EQ(1350u, params
.quic_max_packet_length
);
233 TEST_F(IOThreadTest
, PacketLengthFromFieldTrialParams
) {
234 field_trial_group_
= "Enabled";
235 field_trial_params_
["max_packet_length"] = "1350";
237 ConfigureQuicGlobals();
238 net::HttpNetworkSession::Params params
;
239 InitializeNetworkSessionParams(¶ms
);
240 EXPECT_EQ(1350u, params
.quic_max_packet_length
);
243 TEST_F(IOThreadTest
, QuicVersionFromCommandLine
) {
244 base::CommandLine::StringVector args
;
245 command_line_
.AppendSwitch("enable-quic");
246 std::string version
=
247 net::QuicVersionToString(net::QuicSupportedVersions().back());
248 command_line_
.AppendSwitchASCII("quic-version", version
);
250 ConfigureQuicGlobals();
251 net::HttpNetworkSession::Params params
;
252 InitializeNetworkSessionParams(¶ms
);
253 net::QuicVersionVector supported_versions
;
254 supported_versions
.push_back(net::QuicSupportedVersions().back());
255 EXPECT_EQ(supported_versions
,
256 params
.quic_supported_versions
);
259 TEST_F(IOThreadTest
, QuicVersionFromFieldTrialParams
) {
260 field_trial_group_
= "Enabled";
261 field_trial_params_
["quic_version"] =
262 net::QuicVersionToString(net::QuicSupportedVersions().back());
264 ConfigureQuicGlobals();
265 net::HttpNetworkSession::Params params
;
266 InitializeNetworkSessionParams(¶ms
);
267 net::QuicVersionVector supported_versions
;
268 supported_versions
.push_back(net::QuicSupportedVersions().back());
269 EXPECT_EQ(supported_versions
,
270 params
.quic_supported_versions
);
273 TEST_F(IOThreadTest
, QuicConnectionOptionsFromCommandLine
) {
274 base::CommandLine::StringVector args
;
275 command_line_
.AppendSwitch("enable-quic");
276 command_line_
.AppendSwitchASCII("quic-connection-options",
277 "PACE,TIME,TBBR,REJ");
279 ConfigureQuicGlobals();
280 net::HttpNetworkSession::Params params
;
281 InitializeNetworkSessionParams(¶ms
);
283 net::QuicTagVector options
;
284 options
.push_back(net::kPACE
);
285 options
.push_back(net::kTIME
);
286 options
.push_back(net::kTBBR
);
287 options
.push_back(net::kREJ
);
288 EXPECT_EQ(options
, params
.quic_connection_options
);
291 TEST_F(IOThreadTest
, QuicConnectionOptionsFromFieldTrialParams
) {
292 field_trial_group_
= "Enabled";
293 field_trial_params_
["connection_options"] = "PACE,TIME,TBBR,REJ";
295 ConfigureQuicGlobals();
296 net::HttpNetworkSession::Params params
;
297 InitializeNetworkSessionParams(¶ms
);
299 net::QuicTagVector options
;
300 options
.push_back(net::kPACE
);
301 options
.push_back(net::kTIME
);
302 options
.push_back(net::kTBBR
);
303 options
.push_back(net::kREJ
);
304 EXPECT_EQ(options
, params
.quic_connection_options
);
307 TEST_F(IOThreadTest
, QuicConnectionOptionsFromDeprecatedFieldTrialParams
) {
308 field_trial_group_
= "Enabled";
309 field_trial_params_
["congestion_options"] = "PACE,TIME,TBBR,REJ";
311 ConfigureQuicGlobals();
312 net::HttpNetworkSession::Params params
;
313 InitializeNetworkSessionParams(¶ms
);
315 net::QuicTagVector options
;
316 options
.push_back(net::kPACE
);
317 options
.push_back(net::kTIME
);
318 options
.push_back(net::kTBBR
);
319 options
.push_back(net::kREJ
);
320 EXPECT_EQ(options
, params
.quic_connection_options
);