| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #ifndef COMPONENTS_DATA_REDUCTION_PROXY_CORE_BROWSER_DATA_REDUCTION_PROXY_TEST_U
TILS_H_ | 5 #ifndef COMPONENTS_DATA_REDUCTION_PROXY_CORE_BROWSER_DATA_REDUCTION_PROXY_TEST_U
TILS_H_ |
| 6 #define COMPONENTS_DATA_REDUCTION_PROXY_CORE_BROWSER_DATA_REDUCTION_PROXY_TEST_U
TILS_H_ | 6 #define COMPONENTS_DATA_REDUCTION_PROXY_CORE_BROWSER_DATA_REDUCTION_PROXY_TEST_U
TILS_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/single_thread_task_runner.h" | 13 #include "base/single_thread_task_runner.h" |
| 14 #include "base/time/clock.h" |
| 15 #include "base/time/tick_clock.h" |
| 14 #include "base/time/time.h" | 16 #include "base/time/time.h" |
| 15 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_bypa
ss_stats.h" | 17 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_bypa
ss_stats.h" |
| 16 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_conf
ig_service_client.h" | 18 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_conf
ig_service_client.h" |
| 17 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_io_d
ata.h" | 19 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_io_d
ata.h" |
| 18 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_requ
est_options.h" | 20 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_requ
est_options.h" |
| 19 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_serv
ice.h" | 21 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_serv
ice.h" |
| 20 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_sett
ings_test_utils.h" | 22 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_sett
ings_test_utils.h" |
| 21 #include "net/base/backoff_entry.h" | 23 #include "net/base/backoff_entry.h" |
| 22 #include "net/log/test_net_log.h" | 24 #include "net/log/test_net_log.h" |
| 23 #include "testing/gmock/include/gmock/gmock.h" | 25 #include "testing/gmock/include/gmock/gmock.h" |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 ~TestDataReductionProxyConfigServiceClient() override; | 99 ~TestDataReductionProxyConfigServiceClient() override; |
| 98 | 100 |
| 99 void SetNow(const base::Time& time); | 101 void SetNow(const base::Time& time); |
| 100 | 102 |
| 101 void SetCustomReleaseTime(const base::TimeTicks& release_time); | 103 void SetCustomReleaseTime(const base::TimeTicks& release_time); |
| 102 | 104 |
| 103 base::TimeDelta GetDelay() const; | 105 base::TimeDelta GetDelay() const; |
| 104 | 106 |
| 105 protected: | 107 protected: |
| 106 // Overrides of DataReductionProxyConfigServiceClient | 108 // Overrides of DataReductionProxyConfigServiceClient |
| 107 base::Time Now() const override; | 109 base::Time Now() override; |
| 108 net::BackoffEntry* GetBackoffEntry() override; | 110 net::BackoffEntry* GetBackoffEntry() override; |
| 109 | 111 |
| 110 private: | 112 private: |
| 111 // A clock which returns a fixed value in both base::Time and base::TimeTicks. | 113 // A clock which returns a fixed value in both base::Time and base::TimeTicks. |
| 112 class TestTickClock { | 114 class TestTickClock : public base::Clock, public base::TickClock { |
| 113 public: | 115 public: |
| 114 TestTickClock(const base::Time& initial_time); | 116 TestTickClock(const base::Time& initial_time); |
| 115 | 117 |
| 116 // Returns the current base::TimeTicks | 118 // base::TickClock implementation. |
| 117 base::TimeTicks NowTicks() const; | 119 base::TimeTicks NowTicks() override; |
| 118 | 120 |
| 119 // Returns the current base::Time | 121 // base::Clock implementation. |
| 120 base::Time Now() const; | 122 base::Time Now() override; |
| 121 | 123 |
| 122 // Sets the current time. | 124 // Sets the current time. |
| 123 void SetTime(const base::Time& time); | 125 void SetTime(const base::Time& time); |
| 124 | 126 |
| 125 private: | 127 private: |
| 126 base::Time time_; | 128 base::Time time_; |
| 127 }; | 129 }; |
| 128 | 130 |
| 129 // A net::BackoffEntry which uses an injected base::TickClock to control | |
| 130 // the backoff expiration time. | |
| 131 class TestBackoffEntry : public net::BackoffEntry { | |
| 132 public: | |
| 133 TestBackoffEntry(const BackoffEntry::Policy* const policy, | |
| 134 const TestTickClock* tick_clock); | |
| 135 | |
| 136 protected: | |
| 137 // Override of net::BackoffEntry. | |
| 138 base::TimeTicks ImplGetTimeNow() const override; | |
| 139 | |
| 140 private: | |
| 141 const TestTickClock* tick_clock_; | |
| 142 }; | |
| 143 | |
| 144 TestTickClock tick_clock_; | 131 TestTickClock tick_clock_; |
| 145 TestBackoffEntry test_backoff_entry_; | 132 net::BackoffEntry test_backoff_entry_; |
| 146 }; | 133 }; |
| 147 | 134 |
| 148 // Test version of |DataReductionProxyService|, which permits mocking of various | 135 // Test version of |DataReductionProxyService|, which permits mocking of various |
| 149 // methods. | 136 // methods. |
| 150 class MockDataReductionProxyService : public DataReductionProxyService { | 137 class MockDataReductionProxyService : public DataReductionProxyService { |
| 151 public: | 138 public: |
| 152 MockDataReductionProxyService( | 139 MockDataReductionProxyService( |
| 153 scoped_ptr<DataReductionProxyCompressionStats> compression_stats, | 140 scoped_ptr<DataReductionProxyCompressionStats> compression_stats, |
| 154 DataReductionProxySettings* settings, | 141 DataReductionProxySettings* settings, |
| 155 net::URLRequestContextGetter* request_context, | 142 net::URLRequestContextGetter* request_context, |
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 420 scoped_ptr<DataReductionProxySettings> settings_; | 407 scoped_ptr<DataReductionProxySettings> settings_; |
| 421 | 408 |
| 422 TestDataReductionProxyParams* params_; | 409 TestDataReductionProxyParams* params_; |
| 423 | 410 |
| 424 DISALLOW_COPY_AND_ASSIGN(DataReductionProxyTestContext); | 411 DISALLOW_COPY_AND_ASSIGN(DataReductionProxyTestContext); |
| 425 }; | 412 }; |
| 426 | 413 |
| 427 } // namespace data_reduction_proxy | 414 } // namespace data_reduction_proxy |
| 428 | 415 |
| 429 #endif // COMPONENTS_DATA_REDUCTION_PROXY_CORE_BROWSER_DATA_REDUCTION_PROXY_TES
T_UTILS_H_ | 416 #endif // COMPONENTS_DATA_REDUCTION_PROXY_CORE_BROWSER_DATA_REDUCTION_PROXY_TES
T_UTILS_H_ |
| OLD | NEW |