Chromium Code Reviews| Index: components/data_reduction_proxy/core/browser/data_reduction_proxy_test_utils.cc |
| diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_test_utils.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_test_utils.cc |
| index e9ea65ee061dfa2742900b986caceec3b973f8ae..d5125d836a0164229ab29a39139ef73ed4afbea7 100644 |
| --- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_test_utils.cc |
| +++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_test_utils.cc |
| @@ -6,9 +6,11 @@ |
| #include "base/message_loop/message_loop.h" |
| #include "base/prefs/testing_pref_service.h" |
| +#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_config_service_client.h" |
| #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_config_test_utils.h" |
| #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_configurator_test_utils.h" |
| #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_interceptor.h" |
| +#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_mutable_config_values.h" |
| #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_network_delegate.h" |
| #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_prefs.h" |
| #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_settings.h" |
| @@ -26,6 +28,16 @@ namespace { |
| const char kTestKey[] = "test-key"; |
| +const net::BackoffEntry::Policy kTestBackoffPolicy = { |
| + 0, // num_errors_to_ignore |
| + 10 * 1000, // initial_delay_ms |
| + 2, // multiply_factor |
| + 0, // jitter_factor |
| + 30 * 60 * 1000, // maximum_backoff_ms |
| + -1, // entry_lifetime_ms |
| + true, // always_use_initial_delay |
| +}; |
| + |
| } // namespace |
| namespace data_reduction_proxy { |
| @@ -71,6 +83,86 @@ MockDataReductionProxyRequestOptions::MockDataReductionProxyRequestOptions( |
| MockDataReductionProxyRequestOptions::~MockDataReductionProxyRequestOptions() { |
| } |
| +TestDataReductionProxyConfigServiceClient:: |
| + TestDataReductionProxyConfigServiceClient( |
| + scoped_ptr<DataReductionProxyParams> params, |
| + DataReductionProxyRequestOptions* request_options, |
| + DataReductionProxyMutableConfigValues* config_values, |
| + DataReductionProxyConfig* config, |
| + scoped_refptr<base::SingleThreadTaskRunner> io_task_runner) |
| + : DataReductionProxyConfigServiceClient(params.Pass(), |
| + kTestBackoffPolicy, |
| + request_options, |
| + config_values, |
| + config, |
| + io_task_runner), |
| + tick_clock_(base::Time::UnixEpoch()), |
| + test_backoff_entry_(&kTestBackoffPolicy, &tick_clock_) { |
| +} |
| + |
| +TestDataReductionProxyConfigServiceClient:: |
| + ~TestDataReductionProxyConfigServiceClient() { |
| +} |
| + |
| +void TestDataReductionProxyConfigServiceClient::SetNow(const base::Time& time) { |
| + tick_clock_.SetTime(time); |
| +} |
| + |
| +void TestDataReductionProxyConfigServiceClient::SetCustomReleaseTime( |
| + const base::TimeTicks& release_time) { |
| + test_backoff_entry_.SetCustomReleaseTime(release_time); |
| +} |
| + |
| +base::TimeDelta TestDataReductionProxyConfigServiceClient::GetDelay() const { |
| + return config_refresh_timer_.GetCurrentDelay(); |
| +} |
| + |
| +base::Time TestDataReductionProxyConfigServiceClient::Now() const { |
| + return tick_clock_.Now(); |
| +} |
| + |
| +const net::BackoffEntry* |
| +TestDataReductionProxyConfigServiceClient::GetBackoffEntry() const { |
| + return &test_backoff_entry_; |
| +} |
| + |
| +net::BackoffEntry* |
| +TestDataReductionProxyConfigServiceClient::GetBackoffEntry() { |
| + return &test_backoff_entry_; |
| +} |
| + |
| +TestDataReductionProxyConfigServiceClient::TestTickClock::TestTickClock( |
| + const base::Time& initial_time) |
| + : time_(initial_time) { |
| +} |
| + |
| +base::TimeTicks |
| +TestDataReductionProxyConfigServiceClient::TestTickClock::NowTicks() { |
| + return base::TimeTicks::UnixEpoch() + (time_ - base::Time::UnixEpoch()); |
| +} |
| + |
| +base::Time TestDataReductionProxyConfigServiceClient::TestTickClock::Now() |
|
bengr
2015/03/25 17:15:11
Put the return type on a separate line and move 'c
jeremyim
2015/03/25 17:54:19
Done.
FWIW, I believe the git cl format prefers c
|
| +const { |
| + return time_; |
| +} |
| + |
| +void TestDataReductionProxyConfigServiceClient::TestTickClock::SetTime( |
| + const base::Time& time) { |
| + time_ = time; |
| +} |
| + |
| +TestDataReductionProxyConfigServiceClient::TestBackoffEntry::TestBackoffEntry( |
| + const net::BackoffEntry::Policy* const policy, |
| + base::TickClock* tick_clock) |
| + : net::BackoffEntry(policy), tick_clock_(tick_clock) { |
| +} |
| + |
| +base::TimeTicks |
| +TestDataReductionProxyConfigServiceClient::TestBackoffEntry::ImplGetTimeNow() |
| + const { |
| + return tick_clock_->NowTicks(); |
| +} |
| + |
| MockDataReductionProxyService::MockDataReductionProxyService( |
| scoped_ptr<DataReductionProxyStatisticsPrefs> statistics_prefs, |
| DataReductionProxySettings* settings, |
| @@ -84,10 +176,11 @@ MockDataReductionProxyService::~MockDataReductionProxyService() { |
| TestDataReductionProxyIOData::TestDataReductionProxyIOData( |
| scoped_refptr<base::SingleThreadTaskRunner> task_runner, |
| - scoped_ptr<TestDataReductionProxyConfig> config, |
| + scoped_ptr<DataReductionProxyConfig> config, |
| scoped_ptr<DataReductionProxyEventStore> event_store, |
| scoped_ptr<DataReductionProxyRequestOptions> request_options, |
| - scoped_ptr<DataReductionProxyConfigurator> configurator) |
| + scoped_ptr<DataReductionProxyConfigurator> configurator, |
| + scoped_ptr<DataReductionProxyConfigServiceClient> config_client) |
| : DataReductionProxyIOData() { |
| io_task_runner_ = task_runner; |
| ui_task_runner_ = task_runner; |
| @@ -95,6 +188,7 @@ TestDataReductionProxyIOData::TestDataReductionProxyIOData( |
| event_store_ = event_store.Pass(); |
| request_options_ = request_options.Pass(); |
| configurator_ = configurator.Pass(); |
| + config_client_ = config_client.Pass(); |
| io_task_runner_ = task_runner; |
| ui_task_runner_ = task_runner; |
| } |
| @@ -113,6 +207,8 @@ DataReductionProxyTestContext::Builder::Builder() |
| use_test_configurator_(false), |
| use_mock_service_(false), |
| use_mock_request_options_(false), |
| + use_config_client_(false), |
| + use_test_config_client_(false), |
| skip_settings_initialization_(false) { |
| } |
| @@ -174,6 +270,19 @@ DataReductionProxyTestContext::Builder::WithMockRequestOptions() { |
| } |
| DataReductionProxyTestContext::Builder& |
| +DataReductionProxyTestContext::Builder::WithConfigClient() { |
| + use_config_client_ = true; |
| + return *this; |
| +} |
| + |
| +DataReductionProxyTestContext::Builder& |
| +DataReductionProxyTestContext::Builder::WithTestConfigClient() { |
| + use_config_client_ = true; |
| + use_test_config_client_ = true; |
| + return *this; |
| +} |
| + |
| +DataReductionProxyTestContext::Builder& |
| DataReductionProxyTestContext::Builder::SkipSettingsInitialization() { |
| skip_settings_initialization_ = true; |
| return *this; |
| @@ -181,6 +290,8 @@ DataReductionProxyTestContext::Builder::SkipSettingsInitialization() { |
| scoped_ptr<DataReductionProxyTestContext> |
| DataReductionProxyTestContext::Builder::Build() { |
| + // Check for invalid builder combinations. |
| + DCHECK(!(use_mock_config_ && use_config_client_)); |
| scoped_ptr<base::MessageLoopForIO> loop(new base::MessageLoopForIO()); |
| unsigned int test_context_flags = 0; |
| @@ -216,15 +327,29 @@ DataReductionProxyTestContext::Builder::Build() { |
| } |
| scoped_ptr<TestDataReductionProxyConfig> config; |
| - if (use_mock_config_) { |
| + scoped_ptr<DataReductionProxyConfigServiceClient> config_client; |
| + DataReductionProxyMutableConfigValues* raw_mutable_config = nullptr; |
| + scoped_ptr<TestDataReductionProxyParams> params( |
| + new TestDataReductionProxyParams(params_flags_, params_definitions_)); |
| + TestDataReductionProxyParams* raw_params = params.get(); |
| + if (use_config_client_) { |
| + test_context_flags |= USE_CONFIG_CLIENT; |
| + scoped_ptr<DataReductionProxyMutableConfigValues> mutable_config = |
| + DataReductionProxyMutableConfigValues::CreateFromParams(task_runner, |
| + params.get()); |
| + raw_mutable_config = mutable_config.get(); |
| + config.reset(new TestDataReductionProxyConfig( |
| + mutable_config.Pass(), task_runner, net_log.get(), configurator.get(), |
| + event_store.get())); |
| + } else if (use_mock_config_) { |
| test_context_flags |= USE_MOCK_CONFIG; |
| config.reset(new MockDataReductionProxyConfig( |
| - params_flags_, params_definitions_, task_runner, net_log.get(), |
| - configurator.get(), event_store.get())); |
| + params.Pass(), task_runner, net_log.get(), configurator.get(), |
| + event_store.get())); |
| } else { |
| config.reset(new TestDataReductionProxyConfig( |
| - params_flags_, params_definitions_, task_runner, net_log.get(), |
| - configurator.get(), event_store.get())); |
| + params.Pass(), task_runner, net_log.get(), configurator.get(), |
| + event_store.get())); |
| } |
| scoped_ptr<DataReductionProxyRequestOptions> request_options; |
| @@ -237,6 +362,17 @@ DataReductionProxyTestContext::Builder::Build() { |
| client_, config.get(), task_runner)); |
| } |
| + if (use_test_config_client_) { |
| + test_context_flags |= USE_TEST_CONFIG_CLIENT; |
| + config_client.reset(new TestDataReductionProxyConfigServiceClient( |
| + params.Pass(), request_options.get(), raw_mutable_config, config.get(), |
| + task_runner)); |
| + } else if (use_config_client_) { |
| + config_client.reset(new DataReductionProxyConfigServiceClient( |
| + params.Pass(), GetBackoffPolicy(), request_options.get(), |
| + raw_mutable_config, config.get(), task_runner)); |
| + } |
| + |
| scoped_ptr<DataReductionProxySettings> settings( |
| new DataReductionProxySettings()); |
| if (skip_settings_initialization_) |
| @@ -250,14 +386,14 @@ DataReductionProxyTestContext::Builder::Build() { |
| scoped_ptr<TestDataReductionProxyIOData> io_data( |
| new TestDataReductionProxyIOData( |
| task_runner, config.Pass(), event_store.Pass(), |
| - request_options.Pass(), configurator.Pass())); |
| + request_options.Pass(), configurator.Pass(), config_client.Pass())); |
| io_data->InitOnUIThread(pref_service.get()); |
| scoped_ptr<DataReductionProxyTestContext> test_context( |
| new DataReductionProxyTestContext( |
| loop.Pass(), task_runner, pref_service.Pass(), net_log.Pass(), |
| request_context_getter, mock_socket_factory_, io_data.Pass(), |
| - settings.Pass(), test_context_flags)); |
| + settings.Pass(), raw_params, test_context_flags)); |
| if (!skip_settings_initialization_) |
| test_context->InitSettingsWithoutCheck(); |
| @@ -274,6 +410,7 @@ DataReductionProxyTestContext::DataReductionProxyTestContext( |
| net::MockClientSocketFactory* mock_socket_factory, |
| scoped_ptr<TestDataReductionProxyIOData> io_data, |
| scoped_ptr<DataReductionProxySettings> settings, |
| + TestDataReductionProxyParams* params, |
| unsigned int test_context_flags) |
| : test_context_flags_(test_context_flags), |
| loop_(loop.Pass()), |
| @@ -283,7 +420,8 @@ DataReductionProxyTestContext::DataReductionProxyTestContext( |
| request_context_getter_(request_context_getter), |
| mock_socket_factory_(mock_socket_factory), |
| io_data_(io_data.Pass()), |
| - settings_(settings.Pass()) { |
| + settings_(settings.Pass()), |
| + params_(params) { |
| } |
| DataReductionProxyTestContext::~DataReductionProxyTestContext() { |
| @@ -413,6 +551,26 @@ DataReductionProxyTestContext::mock_request_options() const { |
| io_data_->request_options()); |
| } |
| +TestDataReductionProxyConfig* DataReductionProxyTestContext::config() const { |
| + return reinterpret_cast<TestDataReductionProxyConfig*>(io_data_->config()); |
| +} |
| + |
| +DataReductionProxyMutableConfigValues* |
| +DataReductionProxyTestContext::mutable_config_values() { |
| + DCHECK(test_context_flags_ & |
| + DataReductionProxyTestContext::USE_CONFIG_CLIENT); |
| + return reinterpret_cast<DataReductionProxyMutableConfigValues*>( |
| + config()->config_values()); |
| +} |
| + |
| +TestDataReductionProxyConfigServiceClient* |
| +DataReductionProxyTestContext::test_config_client() { |
| + DCHECK(test_context_flags_ & |
| + DataReductionProxyTestContext::USE_TEST_CONFIG_CLIENT); |
| + return reinterpret_cast<TestDataReductionProxyConfigServiceClient*>( |
| + io_data_->config_client()); |
| +} |
| + |
| DataReductionProxyUsageStats::UnreachableCallback |
| DataReductionProxyTestContext::unreachable_callback() const { |
| return base::Bind(&DataReductionProxySettings::SetUnreachable, |