Index: chrome/browser/io_thread_unittest.cc |
diff --git a/chrome/browser/io_thread_unittest.cc b/chrome/browser/io_thread_unittest.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..3a4b350e8201edcc5dc6920501b394f498737e53 |
--- /dev/null |
+++ b/chrome/browser/io_thread_unittest.cc |
@@ -0,0 +1,251 @@ |
+// Copyright 2014 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "base/command_line.h" |
+#include "chrome/browser/io_thread.h" |
+#include "net/http/http_network_session.h" |
+#include "net/http/http_server_properties_impl.h" |
+#include "net/quic/quic_protocol.h" |
+#include "testing/gtest/include/gtest/gtest.h" |
+ |
+namespace test { |
+ |
+class IOThreadPeer { |
+ public: |
+ static void ConfigureQuicGlobals( |
+ const base::CommandLine& command_line, |
+ base::StringPiece quic_trial_group, |
+ const std::map<std::string, std::string>& quic_trial_params, |
+ IOThread::Globals* globals) { |
+ IOThread::ConfigureQuicGlobals(command_line, quic_trial_group, |
+ quic_trial_params, globals); |
+ } |
+ |
+ static void InitializeNetworkSessionParamsFromGlobals( |
+ const IOThread::Globals& globals, |
+ net::HttpNetworkSession::Params* params) { |
+ IOThread::InitializeNetworkSessionParamsFromGlobals(globals, params); |
+ } |
+}; |
+ |
+class IOThreadTest : public testing::Test { |
+ public: |
+ IOThreadTest() : command_line_(base::CommandLine::NO_PROGRAM) { |
+ globals_.http_server_properties.reset(new net::HttpServerPropertiesImpl()); |
+ } |
+ |
+ void ConfigureQuicGlobals() { |
+ IOThreadPeer::ConfigureQuicGlobals(command_line_, field_trial_group_, |
+ field_trial_params_, &globals_); |
+ } |
+ |
+ void InitializeNetworkSessionParams(net::HttpNetworkSession::Params* params) { |
+ IOThreadPeer::InitializeNetworkSessionParamsFromGlobals(globals_, params); |
+ } |
+ |
+ base::CommandLine command_line_; |
+ IOThread::Globals globals_; |
+ std::string field_trial_group_; |
+ std::map<std::string, std::string> field_trial_params_; |
+}; |
+ |
+TEST_F(IOThreadTest, InitializeNetworkSessionParamsFromGlobals) { |
+ globals_.quic_connection_options.push_back(net::kPACE); |
+ globals_.quic_connection_options.push_back(net::kTBBR); |
+ globals_.quic_connection_options.push_back(net::kTIME); |
+ |
+ net::HttpNetworkSession::Params params; |
+ InitializeNetworkSessionParams(¶ms); |
+ EXPECT_EQ(globals_.quic_connection_options, |
+ params.quic_connection_options); |
+} |
+ |
+TEST_F(IOThreadTest, DisableQuicByDefault) { |
+ ConfigureQuicGlobals(); |
+ net::HttpNetworkSession::Params params; |
+ InitializeNetworkSessionParams(¶ms); |
+ EXPECT_FALSE(params.enable_quic); |
+} |
+ |
+TEST_F(IOThreadTest, EnableQuicFromFieldTrialGroup) { |
+ field_trial_group_ = "Enabled"; |
+ |
+ ConfigureQuicGlobals(); |
+ net::HttpNetworkSession::Params default_params; |
+ net::HttpNetworkSession::Params params; |
+ InitializeNetworkSessionParams(¶ms); |
+ EXPECT_TRUE(params.enable_quic); |
+ EXPECT_FALSE(params.enable_quic_pacing); |
+ EXPECT_FALSE(params.enable_quic_time_based_loss_detection); |
+ EXPECT_EQ(1200u, params.quic_max_packet_length); |
+ EXPECT_EQ(default_params.quic_supported_versions, |
+ params.quic_supported_versions); |
+ EXPECT_EQ(net::QuicTagVector(), params.quic_connection_options); |
+} |
+ |
+TEST_F(IOThreadTest, EnableQuicFromCommandLine) { |
+ base::CommandLine::StringVector args; |
+ command_line_.AppendSwitch("enable-quic"); |
+ |
+ ConfigureQuicGlobals(); |
+ net::HttpNetworkSession::Params params; |
+ InitializeNetworkSessionParams(¶ms); |
+ EXPECT_TRUE(params.enable_quic); |
+} |
+ |
+TEST_F(IOThreadTest, EnablePacingFromCommandLine) { |
+ base::CommandLine::StringVector args; |
+ command_line_.AppendSwitch("enable-quic"); |
+ command_line_.AppendSwitch("enable-quic-pacing"); |
+ |
+ ConfigureQuicGlobals(); |
+ net::HttpNetworkSession::Params params; |
+ InitializeNetworkSessionParams(¶ms); |
+ EXPECT_TRUE(params.enable_quic_pacing); |
+} |
+ |
+TEST_F(IOThreadTest, EnablePacingFromFieldTrialGroup) { |
+ field_trial_group_ = "EnabledWithPacing"; |
+ |
+ ConfigureQuicGlobals(); |
+ net::HttpNetworkSession::Params params; |
+ InitializeNetworkSessionParams(¶ms); |
+ EXPECT_TRUE(params.enable_quic_pacing); |
+} |
+ |
+TEST_F(IOThreadTest, EnablePacingFromFieldTrialParams) { |
+ field_trial_group_ = "Enabled"; |
+ field_trial_params_["enable_pacing"] = "true"; |
+ |
+ ConfigureQuicGlobals(); |
+ net::HttpNetworkSession::Params params; |
+ InitializeNetworkSessionParams(¶ms); |
+ EXPECT_TRUE(params.enable_quic_pacing); |
+} |
+ |
+TEST_F(IOThreadTest, EnableTimeBasedLossDetectionFromCommandLine) { |
+ base::CommandLine::StringVector args; |
+ command_line_.AppendSwitch("enable-quic"); |
+ command_line_.AppendSwitch("enable-quic-time-based-loss-detection"); |
+ |
+ ConfigureQuicGlobals(); |
+ net::HttpNetworkSession::Params params; |
+ InitializeNetworkSessionParams(¶ms); |
+ EXPECT_TRUE(params.enable_quic_time_based_loss_detection); |
+} |
+ |
+TEST_F(IOThreadTest, EnableTimeBasedLossDetectionFromFieldTrialGroup) { |
+ field_trial_group_ = "EnabledWithTimeBasedLossDetection"; |
+ |
+ ConfigureQuicGlobals(); |
+ net::HttpNetworkSession::Params params; |
+ InitializeNetworkSessionParams(¶ms); |
+ EXPECT_TRUE(params.enable_quic_time_based_loss_detection); |
+} |
+ |
+TEST_F(IOThreadTest, EnableTimeBasedLossDetectionFromFieldTrialParams) { |
+ field_trial_group_ = "Enabled"; |
+ field_trial_params_["enable_time_based_loss_detection"] = "true"; |
+ |
+ ConfigureQuicGlobals(); |
+ net::HttpNetworkSession::Params params; |
+ InitializeNetworkSessionParams(¶ms); |
+ EXPECT_TRUE(params.enable_quic_time_based_loss_detection); |
+} |
+ |
+TEST_F(IOThreadTest, PacketLengthFromCommandLine) { |
+ base::CommandLine::StringVector args; |
+ command_line_.AppendSwitch("enable-quic"); |
+ command_line_.AppendSwitchASCII("quic-max-packet-length", "1350"); |
+ |
+ ConfigureQuicGlobals(); |
+ net::HttpNetworkSession::Params params; |
+ InitializeNetworkSessionParams(¶ms); |
+ EXPECT_EQ(1350u, params.quic_max_packet_length); |
+} |
+ |
+TEST_F(IOThreadTest, PacketLengthFromFieldTrialGroup) { |
+ field_trial_group_ = "Enabled1350BytePackets"; |
+ |
+ ConfigureQuicGlobals(); |
+ net::HttpNetworkSession::Params params; |
+ InitializeNetworkSessionParams(¶ms); |
+ EXPECT_EQ(1350u, params.quic_max_packet_length); |
+} |
+ |
+TEST_F(IOThreadTest, PacketLengthFromFieldTrialParams) { |
+ field_trial_group_ = "Enabled"; |
+ field_trial_params_["max_packet_length"] = "1350"; |
+ |
+ ConfigureQuicGlobals(); |
+ net::HttpNetworkSession::Params params; |
+ InitializeNetworkSessionParams(¶ms); |
+ EXPECT_EQ(1350u, params.quic_max_packet_length); |
+} |
+ |
+TEST_F(IOThreadTest, QuicVersionFromCommandLine) { |
+ base::CommandLine::StringVector args; |
+ command_line_.AppendSwitch("enable-quic"); |
+ std::string version = |
+ net::QuicVersionToString(net::QuicSupportedVersions().back()); |
+ command_line_.AppendSwitchASCII("quic-version", version); |
+ |
+ ConfigureQuicGlobals(); |
+ net::HttpNetworkSession::Params params; |
+ InitializeNetworkSessionParams(¶ms); |
+ net::QuicVersionVector supported_versions; |
+ supported_versions.push_back(net::QuicSupportedVersions().back()); |
+ EXPECT_EQ(supported_versions, |
+ params.quic_supported_versions); |
+} |
+ |
+TEST_F(IOThreadTest, QuicVersionFromFieldTrialParams) { |
+ field_trial_group_ = "Enabled"; |
+ field_trial_params_["quic_version"] = |
+ net::QuicVersionToString(net::QuicSupportedVersions().back()); |
+ |
+ ConfigureQuicGlobals(); |
+ net::HttpNetworkSession::Params params; |
+ InitializeNetworkSessionParams(¶ms); |
+ net::QuicVersionVector supported_versions; |
+ supported_versions.push_back(net::QuicSupportedVersions().back()); |
+ EXPECT_EQ(supported_versions, |
+ params.quic_supported_versions); |
+} |
+ |
+TEST_F(IOThreadTest, QuicConnectionOptionsFromCommandLine) { |
+ base::CommandLine::StringVector args; |
+ command_line_.AppendSwitch("enable-quic"); |
+ command_line_.AppendSwitchASCII("quic-connection-options", |
+ "PACE,TIME,TBBR,REJ"); |
+ |
+ ConfigureQuicGlobals(); |
+ net::HttpNetworkSession::Params params; |
+ InitializeNetworkSessionParams(¶ms); |
+ |
+ net::QuicTagVector options; |
+ options.push_back(net::kPACE); |
+ options.push_back(net::kTIME); |
+ options.push_back(net::kTBBR); |
+ options.push_back(net::kREJ); |
+ EXPECT_EQ(options, params.quic_connection_options); |
+} |
+ |
+TEST_F(IOThreadTest, QuicConnectionOptionsFromFieldTrialParams) { |
+ field_trial_group_ = "Enabled"; |
+ field_trial_params_["congestion_options"] = "PACE,TIME,TBBR,REJ"; |
+ |
+ ConfigureQuicGlobals(); |
+ net::HttpNetworkSession::Params params; |
+ InitializeNetworkSessionParams(¶ms); |
+ |
+ net::QuicTagVector options; |
+ options.push_back(net::kPACE); |
+ options.push_back(net::kTIME); |
+ options.push_back(net::kTBBR); |
+ options.push_back(net::kREJ); |
+ EXPECT_EQ(options, params.quic_connection_options); |
+} |
+ |
+} // namespace test |