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_persistence_timer() { return persistence_timer_; } |
113 base::MockTimer* test_garbage_collection_timer() { | 114 base::MockTimer* test_garbage_collection_timer() { |
114 return garbage_collection_timer_; | 115 return garbage_collection_timer_; |
115 } | 116 } |
116 TestReportingUploader* test_uploader() { | 117 TestReportingUploader* test_uploader() { |
117 return reinterpret_cast<TestReportingUploader*>(uploader()); | 118 return reinterpret_cast<TestReportingUploader*>(uploader()); |
118 } | 119 } |
119 | 120 |
120 private: | 121 private: |
121 // Owned by the garbage collector but referenced here to preserve type. | 122 // Owned by the Persister and GarbageCollector, respectively, but referenced |
| 123 // here to preserve type: |
| 124 |
| 125 base::MockTimer* persistence_timer_; |
122 base::MockTimer* garbage_collection_timer_; | 126 base::MockTimer* garbage_collection_timer_; |
123 | 127 |
124 DISALLOW_COPY_AND_ASSIGN(TestReportingContext); | 128 DISALLOW_COPY_AND_ASSIGN(TestReportingContext); |
125 }; | 129 }; |
126 | 130 |
127 // A unit test base class that provides a TestReportingContext and shorthand | 131 // A unit test base class that provides a TestReportingContext and shorthand |
128 // getters. | 132 // getters. |
129 class ReportingTestBase : public ::testing::Test { | 133 class ReportingTestBase : public ::testing::Test { |
130 protected: | 134 protected: |
131 ReportingTestBase(); | 135 ReportingTestBase(); |
132 ~ReportingTestBase() override; | 136 ~ReportingTestBase() override; |
133 | 137 |
134 void UsePolicy(const ReportingPolicy& policy); | 138 void UsePolicy(const ReportingPolicy& policy); |
135 | 139 |
| 140 // Simulates an embedder restart, preserving the ReportingPolicy and any data |
| 141 // persisted via the TestReportingDelegate, but nothing else. |
| 142 // |
| 143 // Advances the Clock by |delta|, and the TickClock by |delta_ticks|. Both can |
| 144 // be zero or negative. |
| 145 void SimulateRestart(base::TimeDelta delta, base::TimeDelta delta_ticks); |
| 146 |
136 TestReportingContext* context() { return context_.get(); } | 147 TestReportingContext* context() { return context_.get(); } |
137 | 148 |
138 const ReportingPolicy& policy() { return context_->policy(); } | 149 const ReportingPolicy& policy() { return context_->policy(); } |
139 | 150 |
140 TestReportingDelegate* delegate() { return context_->test_delegate(); } | 151 TestReportingDelegate* delegate() { return context_->test_delegate(); } |
141 base::SimpleTestClock* clock() { return context_->test_clock(); } | 152 base::SimpleTestClock* clock() { return context_->test_clock(); } |
142 base::SimpleTestTickClock* tick_clock() { | 153 base::SimpleTestTickClock* tick_clock() { |
143 return context_->test_tick_clock(); | 154 return context_->test_tick_clock(); |
144 } | 155 } |
| 156 base::MockTimer* persistence_timer() { |
| 157 return context_->test_persistence_timer(); |
| 158 } |
145 base::MockTimer* garbage_collection_timer() { | 159 base::MockTimer* garbage_collection_timer() { |
146 return context_->test_garbage_collection_timer(); | 160 return context_->test_garbage_collection_timer(); |
147 } | 161 } |
148 TestReportingUploader* uploader() { return context_->test_uploader(); } | 162 TestReportingUploader* uploader() { return context_->test_uploader(); } |
149 | 163 |
150 ReportingCache* cache() { return context_->cache(); } | 164 ReportingCache* cache() { return context_->cache(); } |
151 ReportingEndpointManager* endpoint_manager() { | 165 ReportingEndpointManager* endpoint_manager() { |
152 return context_->endpoint_manager(); | 166 return context_->endpoint_manager(); |
153 } | 167 } |
154 ReportingDeliveryAgent* delivery_agent() { | 168 ReportingDeliveryAgent* delivery_agent() { |
155 return context_->delivery_agent(); | 169 return context_->delivery_agent(); |
156 } | 170 } |
157 ReportingGarbageCollector* garbage_collector() { | 171 ReportingGarbageCollector* garbage_collector() { |
158 return context_->garbage_collector(); | 172 return context_->garbage_collector(); |
159 } | 173 } |
160 | 174 |
| 175 ReportingPersister* persister() { return context_->persister(); } |
| 176 |
161 base::TimeTicks yesterday(); | 177 base::TimeTicks yesterday(); |
162 | 178 |
163 base::TimeTicks tomorrow(); | 179 base::TimeTicks tomorrow(); |
164 | 180 |
165 private: | 181 private: |
| 182 void CreateAndInitializeContext( |
| 183 const ReportingPolicy& policy, |
| 184 std::unique_ptr<const base::Value> persisted_data, |
| 185 base::Time now, |
| 186 base::TimeTicks now_ticks); |
| 187 |
166 std::unique_ptr<TestReportingContext> context_; | 188 std::unique_ptr<TestReportingContext> context_; |
167 | 189 |
168 DISALLOW_COPY_AND_ASSIGN(ReportingTestBase); | 190 DISALLOW_COPY_AND_ASSIGN(ReportingTestBase); |
169 }; | 191 }; |
170 | 192 |
171 } // namespace net | 193 } // namespace net |
172 | 194 |
173 #endif // NET_REPORING_REPORTING_TEST_UTIL_H_ | 195 #endif // NET_REPORING_REPORTING_TEST_UTIL_H_ |
OLD | NEW |