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..9ecb59329287019419b4de4dabfa4477bac0d0e8 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,23 @@ namespace { |
| const char kTestKey[] = "test-key"; |
| +const net::BackoffEntry::Policy kTestBackoffPolicy = { |
| + // num_errors_to_ignore |
| + 0, |
| + // initial_delay_ms |
| + 10 * 1000, |
| + // multiply_factor |
| + 2, |
| + // jitter_factor, |
| + 0, |
| + // maximum_backoff_ms |
| + 30 * 60 * 1000, |
| + // entry_lifetime_ms |
| + -1, |
| + // always_use_initial_delay |
| + true, |
| +}; |
| + |
| } // namespace |
| namespace data_reduction_proxy { |
| @@ -71,6 +90,78 @@ MockDataReductionProxyRequestOptions::MockDataReductionProxyRequestOptions( |
| MockDataReductionProxyRequestOptions::~MockDataReductionProxyRequestOptions() { |
| } |
| +MockDataReductionProxyConfigServiceClient:: |
| + MockDataReductionProxyConfigServiceClient( |
| + 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), |
| + now_(base::Time::UnixEpoch()), |
| + tick_clock_(base::TimeTicks::UnixEpoch()), |
| + test_backoff_entry_(&kTestBackoffPolicy, &tick_clock_) { |
| +} |
| + |
| +MockDataReductionProxyConfigServiceClient:: |
| + ~MockDataReductionProxyConfigServiceClient() { |
| +} |
| + |
| +void MockDataReductionProxyConfigServiceClient::SetNow(const base::Time& time) { |
| + now_ = time; |
| +} |
| + |
| +void MockDataReductionProxyConfigServiceClient::SetCustomReleaseTime( |
| + const base::TimeTicks& release_time) { |
| + test_backoff_entry_.SetCustomReleaseTime(release_time); |
| +} |
| + |
| +base::Time MockDataReductionProxyConfigServiceClient::Now() const { |
| + return now_; |
| +} |
| + |
| +const net::BackoffEntry* |
| +MockDataReductionProxyConfigServiceClient::GetBackoffEntry() const { |
| + return &test_backoff_entry_; |
| +} |
| + |
| +net::BackoffEntry* |
| +MockDataReductionProxyConfigServiceClient::GetBackoffEntry() { |
| + return &test_backoff_entry_; |
| +} |
| + |
| +MockDataReductionProxyConfigServiceClient::TestTickClock::TestTickClock( |
| + const base::TimeTicks& initial_time) |
| + : time_(initial_time) { |
| +} |
| + |
| +base::TimeTicks |
| +MockDataReductionProxyConfigServiceClient::TestTickClock::NowTicks() { |
| + return time_; |
| +} |
| + |
| +void MockDataReductionProxyConfigServiceClient::TestTickClock::SetNowTicks( |
| + const base::TimeTicks& time) { |
| + time_ = time; |
| +} |
| + |
| +MockDataReductionProxyConfigServiceClient::TestBackoffEntry::TestBackoffEntry( |
| + const net::BackoffEntry::Policy* const policy, |
| + base::TickClock* tick_clock) |
| + : net::BackoffEntry(policy), tick_clock_(tick_clock) { |
| +} |
| + |
| +base::TimeTicks |
| +MockDataReductionProxyConfigServiceClient::TestBackoffEntry::ImplGetTimeNow() |
| + const { |
| + return tick_clock_->NowTicks(); |
| +} |
| + |
| MockDataReductionProxyService::MockDataReductionProxyService( |
| scoped_ptr<DataReductionProxyStatisticsPrefs> statistics_prefs, |
| DataReductionProxySettings* settings, |
| @@ -84,10 +175,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 +187,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 +206,8 @@ DataReductionProxyTestContext::Builder::Builder() |
| use_test_configurator_(false), |
| use_mock_service_(false), |
| use_mock_request_options_(false), |
| + use_config_client_(false), |
| + use_mock_config_client_(false), |
| skip_settings_initialization_(false) { |
| } |
| @@ -174,6 +269,19 @@ DataReductionProxyTestContext::Builder::WithMockRequestOptions() { |
| } |
| DataReductionProxyTestContext::Builder& |
| +DataReductionProxyTestContext::Builder::WithConfigClient() { |
| + use_config_client_ = true; |
| + return *this; |
| +} |
| + |
| +DataReductionProxyTestContext::Builder& |
| +DataReductionProxyTestContext::Builder::WithMockConfigClient() { |
| + use_config_client_ = true; |
| + use_mock_config_client_ = true; |
| + return *this; |
| +} |
| + |
| +DataReductionProxyTestContext::Builder& |
| DataReductionProxyTestContext::Builder::SkipSettingsInitialization() { |
| skip_settings_initialization_ = true; |
| return *this; |
| @@ -216,15 +324,28 @@ DataReductionProxyTestContext::Builder::Build() { |
| } |
| scoped_ptr<TestDataReductionProxyConfig> config; |
| - if (use_mock_config_) { |
| + scoped_ptr<DataReductionProxyConfigServiceClient> config_client; |
| + DataReductionProxyMutableConfigValues* raw_mutable_config = nullptr; |
| + scoped_ptr<DataReductionProxyParams> params( |
| + new TestDataReductionProxyParams(params_flags_, params_definitions_)); |
| + if (use_config_client_) { |
|
sclittle
2015/03/24 21:34:56
Maybe DCHECK(!(use_mock_config_ && use_config_clie
jeremyim
2015/03/24 23:20:28
Done.
|
| + 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 +358,17 @@ DataReductionProxyTestContext::Builder::Build() { |
| client_, config.get(), task_runner)); |
| } |
| + if (use_mock_config_client_) { |
| + test_context_flags |= USE_MOCK_CONFIG_CLIENT; |
| + config_client.reset(new MockDataReductionProxyConfigServiceClient( |
| + 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,7 +382,7 @@ 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( |
| @@ -413,6 +545,25 @@ 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 config()->mutable_config_values(); |
| +} |
| + |
| +MockDataReductionProxyConfigServiceClient* |
| +DataReductionProxyTestContext::mock_config_client() { |
| + DCHECK(test_context_flags_ & |
| + DataReductionProxyTestContext::USE_MOCK_CONFIG_CLIENT); |
| + return reinterpret_cast<MockDataReductionProxyConfigServiceClient*>( |
| + io_data_->config_client()); |
| +} |
| + |
| DataReductionProxyUsageStats::UnreachableCallback |
| DataReductionProxyTestContext::unreachable_callback() const { |
| return base::Bind(&DataReductionProxySettings::SetUnreachable, |