Chromium Code Reviews| Index: components/data_reduction_proxy/core/browser/data_reduction_proxy_test_utils.h |
| diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_test_utils.h b/components/data_reduction_proxy/core/browser/data_reduction_proxy_test_utils.h |
| index 9e0695ef81331edf00f401b104e8ddd418de5456..52d396b9aac445688e4b5ca956545918f0a5cbad 100644 |
| --- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_test_utils.h |
| +++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_test_utils.h |
| @@ -11,12 +11,15 @@ |
| #include "base/memory/ref_counted.h" |
| #include "base/memory/scoped_ptr.h" |
| #include "base/single_thread_task_runner.h" |
| +#include "base/time/tick_clock.h" |
| #include "base/time/time.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_io_data.h" |
| #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_request_options.h" |
| #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_service.h" |
| #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_settings_test_utils.h" |
| #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_usage_stats.h" |
| +#include "net/base/backoff_entry.h" |
| #include "net/base/capturing_net_log.h" |
| #include "testing/gmock/include/gmock/gmock.h" |
| @@ -38,6 +41,7 @@ namespace data_reduction_proxy { |
| class DataReductionProxyConfigurator; |
| class DataReductionProxyEventStore; |
| +class DataReductionProxyMutableConfigValues; |
| class DataReductionProxyRequestOptions; |
| class DataReductionProxySettings; |
| class DataReductionProxyStatisticsPrefs; |
| @@ -83,6 +87,70 @@ class MockDataReductionProxyRequestOptions |
| void(base::DictionaryValue* response)); |
| }; |
| +// Test version of |DataReductionProxyConfigServiceClient|, which permits |
| +// mocking of various methods and finely controlling the backoff timer. |
| +class MockDataReductionProxyConfigServiceClient |
| + : public DataReductionProxyConfigServiceClient { |
| + public: |
| + MockDataReductionProxyConfigServiceClient( |
| + scoped_ptr<DataReductionProxyParams> params, |
| + DataReductionProxyRequestOptions* request_options, |
| + DataReductionProxyMutableConfigValues* config_values, |
| + DataReductionProxyConfig* config, |
| + scoped_refptr<base::SingleThreadTaskRunner> io_task_runner); |
| + |
| + ~MockDataReductionProxyConfigServiceClient(); |
| + |
| + MOCK_METHOD1(SetConfigRefreshTimer, void(const base::TimeDelta& delay)); |
|
sclittle
2015/03/24 21:34:56
These methods aren't part of any public interface,
jeremyim
2015/03/24 23:20:29
Done.
|
| + |
| + MOCK_CONST_METHOD0(ConstructStaticResponse, std::string(void)); |
| + |
| + void SetNow(const base::Time& time); |
| + |
| + void SetCustomReleaseTime(const base::TimeTicks& release_time); |
| + |
| + protected: |
| + // Overrides of DataReductionProxyConfigServiceClient |
| + base::Time Now() const override; |
| + const net::BackoffEntry* GetBackoffEntry() const override; |
| + net::BackoffEntry* GetBackoffEntry() override; |
| + |
| + private: |
| + // A base::TickClock which returns a fixed value. |
| + class TestTickClock : public base::TickClock { |
| + public: |
| + TestTickClock(const base::TimeTicks& initial_time); |
| + |
| + // Override of base::TickClock |
| + base::TimeTicks NowTicks() override; |
| + |
| + // Sets the time to return when NowTicks is called. |
| + void SetNowTicks(const base::TimeTicks& time); |
| + |
| + private: |
| + base::TimeTicks time_; |
| + }; |
| + |
| + // A net::BackoffEntry which uses an injected base::TickClock to control |
| + // the backoff expiration time. |
| + class TestBackoffEntry : public net::BackoffEntry { |
| + public: |
| + TestBackoffEntry(const BackoffEntry::Policy* const policy, |
| + base::TickClock* tick_clock); |
| + |
| + protected: |
| + // Override of net::BackoffEntry. |
| + base::TimeTicks ImplGetTimeNow() const override; |
| + |
| + private: |
| + base::TickClock* tick_clock_; |
| + }; |
| + |
| + base::Time now_; |
| + TestTickClock tick_clock_; |
| + TestBackoffEntry test_backoff_entry_; |
| +}; |
| + |
| // Test version of |DataReductionProxyService|, which permits mocking of various |
| // methods. |
| class MockDataReductionProxyService : public DataReductionProxyService { |
| @@ -105,15 +173,20 @@ class TestDataReductionProxyIOData : public DataReductionProxyIOData { |
| public: |
| 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); |
| ~TestDataReductionProxyIOData() override; |
| DataReductionProxyConfigurator* configurator() const { |
| return configurator_.get(); |
| } |
| + |
| + DataReductionProxyConfigServiceClient* config_client() const { |
| + return config_client_.get(); |
| + } |
| }; |
| // Builds a test version of the Data Reduction Proxy stack for use in tests. |
| @@ -165,6 +238,13 @@ class DataReductionProxyTestContext { |
| // |DataReductionProxyRequestOptions|. |
| Builder& WithMockRequestOptions(); |
| + // Specifies the use of the |DataReductionProxyConfigServiceClient|. |
| + Builder& WithConfigClient(); |
| + |
| + // Specifies the use of the a |MockDataReductionProxyConfigServiceClient| |
| + // instead of a |DataReductionProxyConfigServiceClient|. |
| + Builder& WithMockConfigClient(); |
| + |
| // Construct, but do not initialize the |DataReductionProxySettings| object. |
| Builder& SkipSettingsInitialization(); |
| @@ -182,6 +262,8 @@ class DataReductionProxyTestContext { |
| bool use_test_configurator_; |
| bool use_mock_service_; |
| bool use_mock_request_options_; |
| + bool use_config_client_; |
| + bool use_mock_config_client_; |
| bool skip_settings_initialization_; |
| }; |
| @@ -231,6 +313,17 @@ class DataReductionProxyTestContext { |
| // only be called if built with WithMockRequestOptions. |
| MockDataReductionProxyRequestOptions* mock_request_options() const; |
| + // Returns the underlying |TestDataReductionProxyConfig|. |
| + TestDataReductionProxyConfig* config() const; |
| + |
| + // Returns the underlying |DataReductionProxyMutableConfigValues|. This can |
| + // only be called if built with WithConfigClient. |
| + DataReductionProxyMutableConfigValues* mutable_config_values(); |
| + |
| + // Returns the underlying |MockDataReductionProxyConfigServiceClient|. This |
| + // can only be called if built with WithMockConfigClient. |
| + MockDataReductionProxyConfigServiceClient* mock_config_client(); |
| + |
| // Obtains a callback for notifying that the Data Reduction Proxy is no |
| // longer reachable. |
| DataReductionProxyUsageStats::UnreachableCallback |
| @@ -260,10 +353,6 @@ class DataReductionProxyTestContext { |
| return io_data_->configurator(); |
| } |
| - TestDataReductionProxyConfig* config() const { |
| - return reinterpret_cast<TestDataReductionProxyConfig*>(io_data_->config()); |
| - } |
| - |
| TestDataReductionProxyIOData* io_data() const { |
| return io_data_.get(); |
| } |
| @@ -287,6 +376,10 @@ class DataReductionProxyTestContext { |
| USE_MOCK_SERVICE = 0x8, |
| // Permits mocking of the underlying |DataReductionProxyRequestOptions|. |
| USE_MOCK_REQUEST_OPTIONS = 0x10, |
| + // Specifies the use of the |DataReductionProxyConfigServiceClient|. |
| + USE_CONFIG_CLIENT = 0x20, |
| + // Specifies the use of the |MockDataReductionProxyConfigServiceClient|. |
| + USE_MOCK_CONFIG_CLIENT = 0x40, |
| }; |
| DataReductionProxyTestContext( |