Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(216)

Side by Side Diff: components/data_reduction_proxy/core/browser/data_reduction_proxy_test_utils.h

Issue 1076853003: Refactor net::BackoffEntry to not require subclassing (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix ConnectionFactoryImplTest Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/capturing_net_log.h" 24 #include "net/log/capturing_net_log.h"
23 #include "testing/gmock/include/gmock/gmock.h" 25 #include "testing/gmock/include/gmock/gmock.h"
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 109
108 base::TimeDelta GetDelay() const; 110 base::TimeDelta GetDelay() const;
109 111
110 protected: 112 protected:
111 // Overrides of DataReductionProxyConfigServiceClient 113 // Overrides of DataReductionProxyConfigServiceClient
112 base::Time Now() const override; 114 base::Time Now() const override;
113 net::BackoffEntry* GetBackoffEntry() override; 115 net::BackoffEntry* GetBackoffEntry() override;
114 116
115 private: 117 private:
116 // A clock which returns a fixed value in both base::Time and base::TimeTicks. 118 // A clock which returns a fixed value in both base::Time and base::TimeTicks.
117 class TestTickClock { 119 class TestTickClock : public base::Clock, public base::TickClock {
118 public: 120 public:
119 TestTickClock(const base::Time& initial_time); 121 TestTickClock(const base::Time& initial_time);
120 122
121 // Returns the current base::TimeTicks 123 // base::TickClock implementation.
122 base::TimeTicks NowTicks() const; 124 base::TimeTicks NowTicks() override;
123 125
124 // Returns the current base::Time 126 // base::Clock implementation.
125 base::Time Now() const; 127 base::Time Now() override;
126 128
127 // Sets the current time. 129 // Sets the current time.
128 void SetTime(const base::Time& time); 130 void SetTime(const base::Time& time);
129 131
130 private: 132 private:
131 base::Time time_; 133 base::Time time_;
132 }; 134 };
133 135
134 // A net::BackoffEntry which uses an injected base::TickClock to control 136 mutable TestTickClock tick_clock_;
mmenke 2015/04/10 15:50:43 Why does this have to be mutable?
johnme 2015/04/10 16:23:36 It was because base::Clock::Now is non-const, henc
mmenke 2015/04/10 16:26:37 I'd go ahead and make DataReductionProxyConfigServ
135 // the backoff expiration time. 137 net::BackoffEntry test_backoff_entry_;
136 class TestBackoffEntry : public net::BackoffEntry {
137 public:
138 TestBackoffEntry(const BackoffEntry::Policy* const policy,
139 const TestTickClock* tick_clock);
140
141 protected:
142 // Override of net::BackoffEntry.
143 base::TimeTicks ImplGetTimeNow() const override;
144
145 private:
146 const TestTickClock* tick_clock_;
147 };
148
149 TestTickClock tick_clock_;
150 TestBackoffEntry test_backoff_entry_;
151 }; 138 };
152 139
153 // Test version of |DataReductionProxyService|, which permits mocking of various 140 // Test version of |DataReductionProxyService|, which permits mocking of various
154 // methods. 141 // methods.
155 class MockDataReductionProxyService : public DataReductionProxyService { 142 class MockDataReductionProxyService : public DataReductionProxyService {
156 public: 143 public:
157 MockDataReductionProxyService( 144 MockDataReductionProxyService(
158 scoped_ptr<DataReductionProxyCompressionStats> compression_stats, 145 scoped_ptr<DataReductionProxyCompressionStats> compression_stats,
159 DataReductionProxySettings* settings, 146 DataReductionProxySettings* settings,
160 net::URLRequestContextGetter* request_context); 147 net::URLRequestContextGetter* request_context);
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
418 scoped_ptr<DataReductionProxySettings> settings_; 405 scoped_ptr<DataReductionProxySettings> settings_;
419 406
420 TestDataReductionProxyParams* params_; 407 TestDataReductionProxyParams* params_;
421 408
422 DISALLOW_COPY_AND_ASSIGN(DataReductionProxyTestContext); 409 DISALLOW_COPY_AND_ASSIGN(DataReductionProxyTestContext);
423 }; 410 };
424 411
425 } // namespace data_reduction_proxy 412 } // namespace data_reduction_proxy
426 413
427 #endif // COMPONENTS_DATA_REDUCTION_PROXY_CORE_BROWSER_DATA_REDUCTION_PROXY_TES T_UTILS_H_ 414 #endif // COMPONENTS_DATA_REDUCTION_PROXY_CORE_BROWSER_DATA_REDUCTION_PROXY_TES T_UTILS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698