Extend EnrollmentHandler to handle consumer management.
[chromium-blink-merge.git] / chrome / browser / io_thread_unittest.cc
blob92283974614ac4d8e51584abdc20b8487e2ab49f
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::kProtoSPDY3,
85 net::kProtoSPDY31));
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,
96 net::kProtoSPDY3,
97 net::kProtoSPDY31,
98 net::kProtoSPDY4));
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,
109 net::kProtoSPDY3,
110 net::kProtoSPDY31));
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(&params);
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(&params);
129 EXPECT_TRUE(params.enable_quic);
130 EXPECT_FALSE(params.enable_quic_pacing);
131 EXPECT_FALSE(params.enable_quic_time_based_loss_detection);
132 EXPECT_EQ(1200u, params.quic_max_packet_length);
133 EXPECT_EQ(default_params.quic_supported_versions,
134 params.quic_supported_versions);
135 EXPECT_EQ(net::QuicTagVector(), params.quic_connection_options);
138 TEST_F(IOThreadTest, EnableQuicFromCommandLine) {
139 base::CommandLine::StringVector args;
140 command_line_.AppendSwitch("enable-quic");
142 ConfigureQuicGlobals();
143 net::HttpNetworkSession::Params params;
144 InitializeNetworkSessionParams(&params);
145 EXPECT_TRUE(params.enable_quic);
148 TEST_F(IOThreadTest, EnablePacingFromCommandLine) {
149 base::CommandLine::StringVector args;
150 command_line_.AppendSwitch("enable-quic");
151 command_line_.AppendSwitch("enable-quic-pacing");
153 ConfigureQuicGlobals();
154 net::HttpNetworkSession::Params params;
155 InitializeNetworkSessionParams(&params);
156 EXPECT_TRUE(params.enable_quic_pacing);
159 TEST_F(IOThreadTest, EnablePacingFromFieldTrialGroup) {
160 field_trial_group_ = "EnabledWithPacing";
162 ConfigureQuicGlobals();
163 net::HttpNetworkSession::Params params;
164 InitializeNetworkSessionParams(&params);
165 EXPECT_TRUE(params.enable_quic_pacing);
168 TEST_F(IOThreadTest, EnablePacingFromFieldTrialParams) {
169 field_trial_group_ = "Enabled";
170 field_trial_params_["enable_pacing"] = "true";
172 ConfigureQuicGlobals();
173 net::HttpNetworkSession::Params params;
174 InitializeNetworkSessionParams(&params);
175 EXPECT_TRUE(params.enable_quic_pacing);
178 TEST_F(IOThreadTest, EnableTimeBasedLossDetectionFromCommandLine) {
179 base::CommandLine::StringVector args;
180 command_line_.AppendSwitch("enable-quic");
181 command_line_.AppendSwitch("enable-quic-time-based-loss-detection");
183 ConfigureQuicGlobals();
184 net::HttpNetworkSession::Params params;
185 InitializeNetworkSessionParams(&params);
186 EXPECT_TRUE(params.enable_quic_time_based_loss_detection);
189 TEST_F(IOThreadTest, EnableTimeBasedLossDetectionFromFieldTrialGroup) {
190 field_trial_group_ = "EnabledWithTimeBasedLossDetection";
192 ConfigureQuicGlobals();
193 net::HttpNetworkSession::Params params;
194 InitializeNetworkSessionParams(&params);
195 EXPECT_TRUE(params.enable_quic_time_based_loss_detection);
198 TEST_F(IOThreadTest, EnableTimeBasedLossDetectionFromFieldTrialParams) {
199 field_trial_group_ = "Enabled";
200 field_trial_params_["enable_time_based_loss_detection"] = "true";
202 ConfigureQuicGlobals();
203 net::HttpNetworkSession::Params params;
204 InitializeNetworkSessionParams(&params);
205 EXPECT_TRUE(params.enable_quic_time_based_loss_detection);
208 TEST_F(IOThreadTest, PacketLengthFromCommandLine) {
209 base::CommandLine::StringVector args;
210 command_line_.AppendSwitch("enable-quic");
211 command_line_.AppendSwitchASCII("quic-max-packet-length", "1350");
213 ConfigureQuicGlobals();
214 net::HttpNetworkSession::Params params;
215 InitializeNetworkSessionParams(&params);
216 EXPECT_EQ(1350u, params.quic_max_packet_length);
219 TEST_F(IOThreadTest, PacketLengthFromFieldTrialGroup) {
220 field_trial_group_ = "Enabled1350BytePackets";
222 ConfigureQuicGlobals();
223 net::HttpNetworkSession::Params params;
224 InitializeNetworkSessionParams(&params);
225 EXPECT_EQ(1350u, params.quic_max_packet_length);
228 TEST_F(IOThreadTest, PacketLengthFromFieldTrialParams) {
229 field_trial_group_ = "Enabled";
230 field_trial_params_["max_packet_length"] = "1350";
232 ConfigureQuicGlobals();
233 net::HttpNetworkSession::Params params;
234 InitializeNetworkSessionParams(&params);
235 EXPECT_EQ(1350u, params.quic_max_packet_length);
238 TEST_F(IOThreadTest, QuicVersionFromCommandLine) {
239 base::CommandLine::StringVector args;
240 command_line_.AppendSwitch("enable-quic");
241 std::string version =
242 net::QuicVersionToString(net::QuicSupportedVersions().back());
243 command_line_.AppendSwitchASCII("quic-version", version);
245 ConfigureQuicGlobals();
246 net::HttpNetworkSession::Params params;
247 InitializeNetworkSessionParams(&params);
248 net::QuicVersionVector supported_versions;
249 supported_versions.push_back(net::QuicSupportedVersions().back());
250 EXPECT_EQ(supported_versions,
251 params.quic_supported_versions);
254 TEST_F(IOThreadTest, QuicVersionFromFieldTrialParams) {
255 field_trial_group_ = "Enabled";
256 field_trial_params_["quic_version"] =
257 net::QuicVersionToString(net::QuicSupportedVersions().back());
259 ConfigureQuicGlobals();
260 net::HttpNetworkSession::Params params;
261 InitializeNetworkSessionParams(&params);
262 net::QuicVersionVector supported_versions;
263 supported_versions.push_back(net::QuicSupportedVersions().back());
264 EXPECT_EQ(supported_versions,
265 params.quic_supported_versions);
268 TEST_F(IOThreadTest, QuicConnectionOptionsFromCommandLine) {
269 base::CommandLine::StringVector args;
270 command_line_.AppendSwitch("enable-quic");
271 command_line_.AppendSwitchASCII("quic-connection-options",
272 "PACE,TIME,TBBR,REJ");
274 ConfigureQuicGlobals();
275 net::HttpNetworkSession::Params params;
276 InitializeNetworkSessionParams(&params);
278 net::QuicTagVector options;
279 options.push_back(net::kPACE);
280 options.push_back(net::kTIME);
281 options.push_back(net::kTBBR);
282 options.push_back(net::kREJ);
283 EXPECT_EQ(options, params.quic_connection_options);
286 TEST_F(IOThreadTest, QuicConnectionOptionsFromFieldTrialParams) {
287 field_trial_group_ = "Enabled";
288 field_trial_params_["congestion_options"] = "PACE,TIME,TBBR,REJ";
290 ConfigureQuicGlobals();
291 net::HttpNetworkSession::Params params;
292 InitializeNetworkSessionParams(&params);
294 net::QuicTagVector options;
295 options.push_back(net::kPACE);
296 options.push_back(net::kTIME);
297 options.push_back(net::kTBBR);
298 options.push_back(net::kREJ);
299 EXPECT_EQ(options, params.quic_connection_options);
302 } // namespace test