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