OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 NET_REPORTING_REPORTING_TEST_UTIL_H_ | 5 #ifndef NET_REPORTING_REPORTING_TEST_UTIL_H_ |
6 #define NET_REPORTING_REPORTING_TEST_UTIL_H_ | 6 #define NET_REPORTING_REPORTING_TEST_UTIL_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 | 103 |
104 TestReportingDelegate* test_delegate() { | 104 TestReportingDelegate* test_delegate() { |
105 return reinterpret_cast<TestReportingDelegate*>(delegate()); | 105 return reinterpret_cast<TestReportingDelegate*>(delegate()); |
106 } | 106 } |
107 base::SimpleTestClock* test_clock() { | 107 base::SimpleTestClock* test_clock() { |
108 return reinterpret_cast<base::SimpleTestClock*>(clock()); | 108 return reinterpret_cast<base::SimpleTestClock*>(clock()); |
109 } | 109 } |
110 base::SimpleTestTickClock* test_tick_clock() { | 110 base::SimpleTestTickClock* test_tick_clock() { |
111 return reinterpret_cast<base::SimpleTestTickClock*>(tick_clock()); | 111 return reinterpret_cast<base::SimpleTestTickClock*>(tick_clock()); |
112 } | 112 } |
| 113 base::MockTimer* test_delivery_timer() { return delivery_timer_; } |
113 base::MockTimer* test_persistence_timer() { return persistence_timer_; } | 114 base::MockTimer* test_persistence_timer() { return persistence_timer_; } |
114 base::MockTimer* test_garbage_collection_timer() { | 115 base::MockTimer* test_garbage_collection_timer() { |
115 return garbage_collection_timer_; | 116 return garbage_collection_timer_; |
116 } | 117 } |
117 TestReportingUploader* test_uploader() { | 118 TestReportingUploader* test_uploader() { |
118 return reinterpret_cast<TestReportingUploader*>(uploader()); | 119 return reinterpret_cast<TestReportingUploader*>(uploader()); |
119 } | 120 } |
120 | 121 |
121 private: | 122 private: |
122 // Owned by the Persister and GarbageCollector, respectively, but referenced | 123 // Owned by the Persister and GarbageCollector, respectively, but referenced |
123 // here to preserve type: | 124 // here to preserve type: |
124 | 125 |
| 126 base::MockTimer* delivery_timer_; |
125 base::MockTimer* persistence_timer_; | 127 base::MockTimer* persistence_timer_; |
126 base::MockTimer* garbage_collection_timer_; | 128 base::MockTimer* garbage_collection_timer_; |
127 | 129 |
128 DISALLOW_COPY_AND_ASSIGN(TestReportingContext); | 130 DISALLOW_COPY_AND_ASSIGN(TestReportingContext); |
129 }; | 131 }; |
130 | 132 |
131 // A unit test base class that provides a TestReportingContext and shorthand | 133 // A unit test base class that provides a TestReportingContext and shorthand |
132 // getters. | 134 // getters. |
133 class ReportingTestBase : public ::testing::Test { | 135 class ReportingTestBase : public ::testing::Test { |
134 protected: | 136 protected: |
(...skipping 11 matching lines...) Expand all Loading... |
146 | 148 |
147 TestReportingContext* context() { return context_.get(); } | 149 TestReportingContext* context() { return context_.get(); } |
148 | 150 |
149 const ReportingPolicy& policy() { return context_->policy(); } | 151 const ReportingPolicy& policy() { return context_->policy(); } |
150 | 152 |
151 TestReportingDelegate* delegate() { return context_->test_delegate(); } | 153 TestReportingDelegate* delegate() { return context_->test_delegate(); } |
152 base::SimpleTestClock* clock() { return context_->test_clock(); } | 154 base::SimpleTestClock* clock() { return context_->test_clock(); } |
153 base::SimpleTestTickClock* tick_clock() { | 155 base::SimpleTestTickClock* tick_clock() { |
154 return context_->test_tick_clock(); | 156 return context_->test_tick_clock(); |
155 } | 157 } |
| 158 base::MockTimer* delivery_timer() { return context_->test_delivery_timer(); } |
156 base::MockTimer* persistence_timer() { | 159 base::MockTimer* persistence_timer() { |
157 return context_->test_persistence_timer(); | 160 return context_->test_persistence_timer(); |
158 } | 161 } |
159 base::MockTimer* garbage_collection_timer() { | 162 base::MockTimer* garbage_collection_timer() { |
160 return context_->test_garbage_collection_timer(); | 163 return context_->test_garbage_collection_timer(); |
161 } | 164 } |
162 TestReportingUploader* uploader() { return context_->test_uploader(); } | 165 TestReportingUploader* uploader() { return context_->test_uploader(); } |
163 | 166 |
164 ReportingCache* cache() { return context_->cache(); } | 167 ReportingCache* cache() { return context_->cache(); } |
165 ReportingEndpointManager* endpoint_manager() { | 168 ReportingEndpointManager* endpoint_manager() { |
166 return context_->endpoint_manager(); | 169 return context_->endpoint_manager(); |
167 } | 170 } |
168 ReportingDeliveryAgent* delivery_agent() { | 171 ReportingDeliveryAgent* delivery_agent() { |
169 return context_->delivery_agent(); | 172 return context_->delivery_agent(); |
170 } | 173 } |
171 ReportingGarbageCollector* garbage_collector() { | 174 ReportingGarbageCollector* garbage_collector() { |
172 return context_->garbage_collector(); | 175 return context_->garbage_collector(); |
173 } | 176 } |
174 | 177 |
175 ReportingPersister* persister() { return context_->persister(); } | 178 ReportingPersister* persister() { return context_->persister(); } |
176 | 179 |
177 base::TimeTicks yesterday(); | 180 base::TimeTicks yesterday(); |
| 181 base::TimeTicks now(); |
| 182 base::TimeTicks tomorrow(); |
178 | 183 |
179 base::TimeTicks tomorrow(); | 184 const std::vector<std::unique_ptr<TestReportingUploader::PendingUpload>>& |
| 185 pending_uploads() { |
| 186 return uploader()->pending_uploads(); |
| 187 } |
180 | 188 |
181 private: | 189 private: |
182 void CreateAndInitializeContext( | 190 void CreateAndInitializeContext( |
183 const ReportingPolicy& policy, | 191 const ReportingPolicy& policy, |
184 std::unique_ptr<const base::Value> persisted_data, | 192 std::unique_ptr<const base::Value> persisted_data, |
185 base::Time now, | 193 base::Time now, |
186 base::TimeTicks now_ticks); | 194 base::TimeTicks now_ticks); |
187 | 195 |
188 std::unique_ptr<TestReportingContext> context_; | 196 std::unique_ptr<TestReportingContext> context_; |
189 | 197 |
190 DISALLOW_COPY_AND_ASSIGN(ReportingTestBase); | 198 DISALLOW_COPY_AND_ASSIGN(ReportingTestBase); |
191 }; | 199 }; |
192 | 200 |
193 } // namespace net | 201 } // namespace net |
194 | 202 |
195 #endif // NET_REPORING_REPORTING_TEST_UTIL_H_ | 203 #endif // NET_REPORING_REPORTING_TEST_UTIL_H_ |
OLD | NEW |