| 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 "base/test/mock_entropy_provider.h" | 7 #include "base/test/mock_entropy_provider.h" |
| 8 #include "chrome/browser/io_thread.h" | 8 #include "chrome/browser/io_thread.h" |
| 9 #include "chrome/common/chrome_switches.h" |
| 9 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_param
s.h" | 10 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_param
s.h" |
| 10 #include "net/http/http_network_session.h" | 11 #include "net/http/http_network_session.h" |
| 11 #include "net/http/http_server_properties_impl.h" | 12 #include "net/http/http_server_properties_impl.h" |
| 12 #include "net/quic/quic_protocol.h" | 13 #include "net/quic/quic_protocol.h" |
| 13 #include "testing/gmock/include/gmock/gmock.h" | 14 #include "testing/gmock/include/gmock/gmock.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 15 | 16 |
| 16 namespace test { | 17 namespace test { |
| 17 | 18 |
| 18 using ::testing::ElementsAre; | 19 using ::testing::ElementsAre; |
| 19 | 20 |
| 20 class IOThreadPeer { | 21 class IOThreadPeer { |
| 21 public: | 22 public: |
| 22 static void ConfigureQuicGlobals( | 23 static void ConfigureQuicGlobals( |
| 23 const base::CommandLine& command_line, | 24 const base::CommandLine& command_line, |
| 24 base::StringPiece quic_trial_group, | 25 base::StringPiece quic_trial_group, |
| 25 const std::map<std::string, std::string>& quic_trial_params, | 26 const std::map<std::string, std::string>& quic_trial_params, |
| 27 bool is_quic_allowed_by_policy, |
| 26 IOThread::Globals* globals) { | 28 IOThread::Globals* globals) { |
| 27 IOThread::ConfigureQuicGlobals(command_line, quic_trial_group, | 29 IOThread::ConfigureQuicGlobals(command_line, quic_trial_group, |
| 28 quic_trial_params, globals); | 30 quic_trial_params, is_quic_allowed_by_policy, |
| 31 globals); |
| 29 } | 32 } |
| 30 | 33 |
| 31 static void ConfigureSpdyGlobals( | 34 static void ConfigureSpdyGlobals( |
| 32 const base::CommandLine& command_line, | 35 const base::CommandLine& command_line, |
| 33 base::StringPiece spdy_trial_group, | 36 base::StringPiece spdy_trial_group, |
| 34 const std::map<std::string, std::string>& spdy_trial_params, | 37 const std::map<std::string, std::string>& spdy_trial_params, |
| 35 IOThread::Globals* globals) { | 38 IOThread::Globals* globals) { |
| 36 IOThread::ConfigureSpdyGlobals(command_line, spdy_trial_group, | 39 IOThread::ConfigureSpdyGlobals(command_line, spdy_trial_group, |
| 37 spdy_trial_params, globals); | 40 spdy_trial_params, globals); |
| 38 } | 41 } |
| 39 | 42 |
| 40 static void InitializeNetworkSessionParamsFromGlobals( | 43 static void InitializeNetworkSessionParamsFromGlobals( |
| 41 const IOThread::Globals& globals, | 44 const IOThread::Globals& globals, |
| 42 net::HttpNetworkSession::Params* params) { | 45 net::HttpNetworkSession::Params* params) { |
| 43 IOThread::InitializeNetworkSessionParamsFromGlobals(globals, params); | 46 IOThread::InitializeNetworkSessionParamsFromGlobals(globals, params); |
| 44 } | 47 } |
| 45 }; | 48 }; |
| 46 | 49 |
| 47 class IOThreadTest : public testing::Test { | 50 class IOThreadTest : public testing::Test { |
| 48 public: | 51 public: |
| 49 IOThreadTest() : command_line_(base::CommandLine::NO_PROGRAM) { | 52 IOThreadTest() |
| 53 : command_line_(base::CommandLine::NO_PROGRAM), |
| 54 is_quic_allowed_by_policy_(true) { |
| 50 globals_.http_server_properties.reset(new net::HttpServerPropertiesImpl()); | 55 globals_.http_server_properties.reset(new net::HttpServerPropertiesImpl()); |
| 51 } | 56 } |
| 52 | 57 |
| 53 void ConfigureQuicGlobals() { | 58 void ConfigureQuicGlobals() { |
| 54 IOThreadPeer::ConfigureQuicGlobals(command_line_, field_trial_group_, | 59 IOThreadPeer::ConfigureQuicGlobals(command_line_, |
| 55 field_trial_params_, &globals_); | 60 field_trial_group_, |
| 61 field_trial_params_, |
| 62 is_quic_allowed_by_policy_, |
| 63 &globals_); |
| 56 } | 64 } |
| 57 | 65 |
| 58 void ConfigureSpdyGlobals() { | 66 void ConfigureSpdyGlobals() { |
| 59 IOThreadPeer::ConfigureSpdyGlobals(command_line_, field_trial_group_, | 67 IOThreadPeer::ConfigureSpdyGlobals(command_line_, field_trial_group_, |
| 60 field_trial_params_, &globals_); | 68 field_trial_params_, &globals_); |
| 61 } | 69 } |
| 62 | 70 |
| 63 void InitializeNetworkSessionParams(net::HttpNetworkSession::Params* params) { | 71 void InitializeNetworkSessionParams(net::HttpNetworkSession::Params* params) { |
| 64 IOThreadPeer::InitializeNetworkSessionParamsFromGlobals(globals_, params); | 72 IOThreadPeer::InitializeNetworkSessionParamsFromGlobals(globals_, params); |
| 65 } | 73 } |
| 66 | 74 |
| 67 base::CommandLine command_line_; | 75 base::CommandLine command_line_; |
| 68 IOThread::Globals globals_; | 76 IOThread::Globals globals_; |
| 69 std::string field_trial_group_; | 77 std::string field_trial_group_; |
| 78 bool is_quic_allowed_by_policy_; |
| 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); |
| (...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 446 AlternateProtocolProbabilityThresholdFromParams) { | 455 AlternateProtocolProbabilityThresholdFromParams) { |
| 447 field_trial_group_ = "Enabled"; | 456 field_trial_group_ = "Enabled"; |
| 448 field_trial_params_["alternate_protocol_probability_threshold"] = ".5"; | 457 field_trial_params_["alternate_protocol_probability_threshold"] = ".5"; |
| 449 | 458 |
| 450 ConfigureQuicGlobals(); | 459 ConfigureQuicGlobals(); |
| 451 net::HttpNetworkSession::Params params; | 460 net::HttpNetworkSession::Params params; |
| 452 InitializeNetworkSessionParams(¶ms); | 461 InitializeNetworkSessionParams(¶ms); |
| 453 EXPECT_EQ(.5, params.alternate_protocol_probability_threshold); | 462 EXPECT_EQ(.5, params.alternate_protocol_probability_threshold); |
| 454 } | 463 } |
| 455 | 464 |
| 465 TEST_F(IOThreadTest, QuicDisallowedByPolicy) { |
| 466 command_line_.AppendSwitch(switches::kEnableQuic); |
| 467 is_quic_allowed_by_policy_ = false; |
| 468 ConfigureQuicGlobals(); |
| 469 |
| 470 net::HttpNetworkSession::Params params; |
| 471 InitializeNetworkSessionParams(¶ms); |
| 472 EXPECT_FALSE(params.enable_quic); |
| 473 } |
| 474 |
| 456 } // namespace test | 475 } // namespace test |
| OLD | NEW |