OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/command_line.h" | 5 #include "base/command_line.h" |
6 #include "base/metrics/field_trial.h" | 6 #include "base/metrics/field_trial.h" |
7 #include "chrome/browser/io_thread.h" | 7 #include "chrome/browser/io_thread.h" |
8 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_param
s.h" | 8 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_param
s.h" |
9 #include "net/http/http_network_session.h" | 9 #include "net/http/http_network_session.h" |
10 #include "net/http/http_server_properties_impl.h" | 10 #include "net/http/http_server_properties_impl.h" |
(...skipping 19 matching lines...) Expand all Loading... |
30 public: | 30 public: |
31 static void ConfigureQuicGlobals( | 31 static void ConfigureQuicGlobals( |
32 const base::CommandLine& command_line, | 32 const base::CommandLine& command_line, |
33 base::StringPiece quic_trial_group, | 33 base::StringPiece quic_trial_group, |
34 const std::map<std::string, std::string>& quic_trial_params, | 34 const std::map<std::string, std::string>& quic_trial_params, |
35 IOThread::Globals* globals) { | 35 IOThread::Globals* globals) { |
36 IOThread::ConfigureQuicGlobals(command_line, quic_trial_group, | 36 IOThread::ConfigureQuicGlobals(command_line, quic_trial_group, |
37 quic_trial_params, globals); | 37 quic_trial_params, globals); |
38 } | 38 } |
39 | 39 |
| 40 static void ConfigureSpdyGlobals( |
| 41 const base::CommandLine& command_line, |
| 42 base::StringPiece spdy_trial_group, |
| 43 const std::map<std::string, std::string>& spdy_trial_params, |
| 44 IOThread::Globals* globals) { |
| 45 IOThread::ConfigureSpdyGlobals(command_line, spdy_trial_group, |
| 46 spdy_trial_params, globals); |
| 47 } |
| 48 |
40 static void InitializeNetworkSessionParamsFromGlobals( | 49 static void InitializeNetworkSessionParamsFromGlobals( |
41 const IOThread::Globals& globals, | 50 const IOThread::Globals& globals, |
42 net::HttpNetworkSession::Params* params) { | 51 net::HttpNetworkSession::Params* params) { |
43 IOThread::InitializeNetworkSessionParamsFromGlobals(globals, params); | 52 IOThread::InitializeNetworkSessionParamsFromGlobals(globals, params); |
44 } | 53 } |
45 | |
46 static void ConfigureSpdyFromTrial(const std::string& trial_group, | |
47 IOThread::Globals* globals) { | |
48 IOThread::ConfigureSpdyFromTrial(trial_group, globals); | |
49 } | |
50 }; | 54 }; |
51 | 55 |
52 class IOThreadTest : public testing::Test { | 56 class IOThreadTest : public testing::Test { |
53 public: | 57 public: |
54 IOThreadTest() : command_line_(base::CommandLine::NO_PROGRAM) { | 58 IOThreadTest() : command_line_(base::CommandLine::NO_PROGRAM) { |
55 globals_.http_server_properties.reset(new net::HttpServerPropertiesImpl()); | 59 globals_.http_server_properties.reset(new net::HttpServerPropertiesImpl()); |
56 } | 60 } |
57 | 61 |
58 void ConfigureQuicGlobals() { | 62 void ConfigureQuicGlobals() { |
59 IOThreadPeer::ConfigureQuicGlobals(command_line_, field_trial_group_, | 63 IOThreadPeer::ConfigureQuicGlobals(command_line_, field_trial_group_, |
60 field_trial_params_, &globals_); | 64 field_trial_params_, &globals_); |
61 } | 65 } |
62 | 66 |
| 67 void ConfigureSpdyGlobals() { |
| 68 IOThreadPeer::ConfigureSpdyGlobals(command_line_, field_trial_group_, |
| 69 field_trial_params_, &globals_); |
| 70 } |
| 71 |
63 void InitializeNetworkSessionParams(net::HttpNetworkSession::Params* params) { | 72 void InitializeNetworkSessionParams(net::HttpNetworkSession::Params* params) { |
64 IOThreadPeer::InitializeNetworkSessionParamsFromGlobals(globals_, params); | 73 IOThreadPeer::InitializeNetworkSessionParamsFromGlobals(globals_, params); |
65 } | 74 } |
66 | 75 |
67 base::CommandLine command_line_; | 76 base::CommandLine command_line_; |
68 IOThread::Globals globals_; | 77 IOThread::Globals globals_; |
69 std::string field_trial_group_; | 78 std::string field_trial_group_; |
70 std::map<std::string, std::string> field_trial_params_; | 79 std::map<std::string, std::string> field_trial_params_; |
71 }; | 80 }; |
72 | 81 |
73 TEST_F(IOThreadTest, InitializeNetworkSessionParamsFromGlobals) { | 82 TEST_F(IOThreadTest, InitializeNetworkSessionParamsFromGlobals) { |
74 globals_.quic_connection_options.push_back(net::kPACE); | 83 globals_.quic_connection_options.push_back(net::kPACE); |
75 globals_.quic_connection_options.push_back(net::kTBBR); | 84 globals_.quic_connection_options.push_back(net::kTBBR); |
76 globals_.quic_connection_options.push_back(net::kTIME); | 85 globals_.quic_connection_options.push_back(net::kTIME); |
77 | 86 |
78 net::HttpNetworkSession::Params params; | 87 net::HttpNetworkSession::Params params; |
79 InitializeNetworkSessionParams(¶ms); | 88 InitializeNetworkSessionParams(¶ms); |
80 EXPECT_EQ(globals_.quic_connection_options, | 89 EXPECT_EQ(globals_.quic_connection_options, |
81 params.quic_connection_options); | 90 params.quic_connection_options); |
82 } | 91 } |
83 | 92 |
84 TEST_F(IOThreadTest, SpdyFieldTrialHoldbackEnabled) { | 93 TEST_F(IOThreadTest, SpdyFieldTrialHoldbackEnabled) { |
85 net::HttpStreamFactory::set_spdy_enabled(true); | 94 net::HttpStreamFactory::set_spdy_enabled(true); |
86 IOThreadPeer::ConfigureSpdyFromTrial("SpdyDisabled", &globals_); | 95 field_trial_group_ = "SpdyDisabled"; |
| 96 ConfigureSpdyGlobals(); |
87 EXPECT_FALSE(net::HttpStreamFactory::spdy_enabled()); | 97 EXPECT_FALSE(net::HttpStreamFactory::spdy_enabled()); |
88 } | 98 } |
89 | 99 |
90 TEST_F(IOThreadTest, SpdyFieldTrialSpdy31Enabled) { | 100 TEST_F(IOThreadTest, SpdyFieldTrialSpdy31Enabled) { |
91 bool use_alternate_protocols = false; | 101 bool use_alternate_protocols = false; |
92 IOThreadPeer::ConfigureSpdyFromTrial("Spdy31Enabled", &globals_); | 102 field_trial_group_ = "Spdy31Enabled"; |
| 103 ConfigureSpdyGlobals(); |
93 EXPECT_THAT(globals_.next_protos, | 104 EXPECT_THAT(globals_.next_protos, |
94 ElementsAre(net::kProtoHTTP11, | 105 ElementsAre(net::kProtoHTTP11, |
95 net::kProtoQUIC1SPDY3, | |
96 net::kProtoSPDY31)); | 106 net::kProtoSPDY31)); |
97 globals_.use_alternate_protocols.CopyToIfSet(&use_alternate_protocols); | 107 globals_.use_alternate_protocols.CopyToIfSet(&use_alternate_protocols); |
98 EXPECT_TRUE(use_alternate_protocols); | 108 EXPECT_TRUE(use_alternate_protocols); |
99 } | 109 } |
100 | 110 |
101 TEST_F(IOThreadTest, SpdyFieldTrialSpdy4Enabled) { | 111 TEST_F(IOThreadTest, SpdyFieldTrialSpdy4Enabled) { |
102 bool use_alternate_protocols = false; | 112 bool use_alternate_protocols = false; |
103 IOThreadPeer::ConfigureSpdyFromTrial("Spdy4Enabled", &globals_); | 113 field_trial_group_ = "Spdy4Enabled"; |
104 EXPECT_THAT( | 114 ConfigureSpdyGlobals(); |
105 globals_.next_protos, | 115 EXPECT_THAT(globals_.next_protos, |
106 ElementsAre(net::kProtoHTTP11, net::kProtoQUIC1SPDY3, net::kProtoSPDY31, | 116 ElementsAre(net::kProtoHTTP11, net::kProtoSPDY31, |
107 net::kProtoSPDY4_14, net::kProtoSPDY4)); | 117 net::kProtoSPDY4_14, net::kProtoSPDY4)); |
108 globals_.use_alternate_protocols.CopyToIfSet(&use_alternate_protocols); | 118 globals_.use_alternate_protocols.CopyToIfSet(&use_alternate_protocols); |
109 EXPECT_TRUE(use_alternate_protocols); | 119 EXPECT_TRUE(use_alternate_protocols); |
110 } | 120 } |
111 | 121 |
| 122 TEST_F(IOThreadTest, SpdyFieldTrialDefault) { |
| 123 field_trial_group_ = ""; |
| 124 ConfigureSpdyGlobals(); |
| 125 EXPECT_THAT(globals_.next_protos, |
| 126 ElementsAre(net::kProtoHTTP11, net::kProtoSPDY31, |
| 127 net::kProtoSPDY4_14, net::kProtoSPDY4)); |
| 128 bool use_alternate_protocols = false; |
| 129 globals_.use_alternate_protocols.CopyToIfSet(&use_alternate_protocols); |
| 130 EXPECT_TRUE(use_alternate_protocols); |
| 131 } |
| 132 |
| 133 TEST_F(IOThreadTest, SpdyFieldTrialParametrized) { |
| 134 field_trial_params_["enable_spdy31"] = "false"; |
| 135 // Undefined parameter "h2_14_enabled" should default to false. |
| 136 field_trial_params_["h2_enabled"] = "true"; |
| 137 field_trial_group_ = "ParametrizedHTTP2Only"; |
| 138 ConfigureSpdyGlobals(); |
| 139 EXPECT_THAT(globals_.next_protos, |
| 140 ElementsAre(net::kProtoHTTP11, net::kProtoSPDY4)); |
| 141 bool use_alternate_protocols = false; |
| 142 globals_.use_alternate_protocols.CopyToIfSet(&use_alternate_protocols); |
| 143 EXPECT_TRUE(use_alternate_protocols); |
| 144 } |
| 145 |
| 146 TEST_F(IOThreadTest, SpdyCommandLineEnable) { |
| 147 command_line_.AppendSwitch("enable-spdy4"); |
| 148 // Command line should overwrite field trial group. |
| 149 field_trial_group_ = "SpdyDisabled"; |
| 150 ConfigureSpdyGlobals(); |
| 151 EXPECT_THAT(globals_.next_protos, |
| 152 ElementsAre(net::kProtoHTTP11, net::kProtoSPDY31, |
| 153 net::kProtoSPDY4_14, net::kProtoSPDY4)); |
| 154 bool use_alternate_protocols = false; |
| 155 globals_.use_alternate_protocols.CopyToIfSet(&use_alternate_protocols); |
| 156 EXPECT_TRUE(use_alternate_protocols); |
| 157 } |
| 158 |
| 159 TEST_F(IOThreadTest, SpdyCommandLineDisable) { |
| 160 command_line_.AppendSwitch("enable-npn-http"); |
| 161 // Command line should overwrite field trial group. |
| 162 field_trial_group_ = "Spdy4Enabled"; |
| 163 ConfigureSpdyGlobals(); |
| 164 EXPECT_THAT(globals_.next_protos, ElementsAre(net::kProtoHTTP11)); |
| 165 bool use_alternate_protocols = true; |
| 166 globals_.use_alternate_protocols.CopyToIfSet(&use_alternate_protocols); |
| 167 EXPECT_FALSE(use_alternate_protocols); |
| 168 } |
| 169 |
| 170 TEST_F(IOThreadTest, SpdyCommandLineUseSpdyOff) { |
| 171 command_line_.AppendSwitchASCII("use-spdy", "off"); |
| 172 // Command line should overwrite field trial group. |
| 173 field_trial_group_ = "Spdy4Enabled"; |
| 174 ConfigureSpdyGlobals(); |
| 175 EXPECT_EQ(0u, globals_.next_protos.size()); |
| 176 } |
| 177 |
| 178 TEST_F(IOThreadTest, SpdyCommandLineUseSpdySSL) { |
| 179 command_line_.AppendSwitchASCII("use-spdy", "ssl"); |
| 180 // Command line should overwrite field trial group. |
| 181 field_trial_group_ = "SpdyDisabled"; |
| 182 ConfigureSpdyGlobals(); |
| 183 bool force_spdy_over_ssl = false; |
| 184 globals_.force_spdy_over_ssl.CopyToIfSet(&force_spdy_over_ssl); |
| 185 EXPECT_TRUE(force_spdy_over_ssl); |
| 186 bool force_spdy_always = false; |
| 187 globals_.force_spdy_always.CopyToIfSet(&force_spdy_always); |
| 188 EXPECT_TRUE(force_spdy_always); |
| 189 } |
| 190 |
| 191 TEST_F(IOThreadTest, SpdyCommandLineUseSpdyDisableAltProtocols) { |
| 192 command_line_.AppendSwitchASCII("use-spdy", "no-alt-protocols"); |
| 193 ConfigureSpdyGlobals(); |
| 194 bool use_alternate_protocols = true; |
| 195 globals_.use_alternate_protocols.CopyToIfSet(&use_alternate_protocols); |
| 196 EXPECT_FALSE(use_alternate_protocols); |
| 197 } |
| 198 |
112 TEST_F(IOThreadTest, DisableQuicByDefault) { | 199 TEST_F(IOThreadTest, DisableQuicByDefault) { |
113 ConfigureQuicGlobals(); | 200 ConfigureQuicGlobals(); |
114 net::HttpNetworkSession::Params params; | 201 net::HttpNetworkSession::Params params; |
115 InitializeNetworkSessionParams(¶ms); | 202 InitializeNetworkSessionParams(¶ms); |
116 EXPECT_FALSE(params.enable_quic); | 203 EXPECT_FALSE(params.enable_quic); |
117 EXPECT_FALSE(params.enable_quic_for_proxies); | 204 EXPECT_FALSE(params.enable_quic_for_proxies); |
118 EXPECT_FALSE(IOThread::ShouldEnableQuicForDataReductionProxy()); | 205 EXPECT_FALSE(IOThread::ShouldEnableQuicForDataReductionProxy()); |
119 } | 206 } |
120 | 207 |
121 TEST_F(IOThreadTest, EnableQuicFromFieldTrialGroup) { | 208 TEST_F(IOThreadTest, EnableQuicFromFieldTrialGroup) { |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
362 field_trial_group_ = "Enabled"; | 449 field_trial_group_ = "Enabled"; |
363 field_trial_params_["alternate_protocol_probability_threshold"] = ".5"; | 450 field_trial_params_["alternate_protocol_probability_threshold"] = ".5"; |
364 | 451 |
365 ConfigureQuicGlobals(); | 452 ConfigureQuicGlobals(); |
366 net::HttpNetworkSession::Params params; | 453 net::HttpNetworkSession::Params params; |
367 InitializeNetworkSessionParams(¶ms); | 454 InitializeNetworkSessionParams(¶ms); |
368 EXPECT_EQ(.5, params.alternate_protocol_probability_threshold); | 455 EXPECT_EQ(.5, params.alternate_protocol_probability_threshold); |
369 } | 456 } |
370 | 457 |
371 } // namespace test | 458 } // namespace test |
OLD | NEW |