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> |
11 | 11 |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "net/reporting/reporting_context.h" | 13 #include "net/reporting/reporting_context.h" |
14 #include "net/reporting/reporting_delegate.h" | 14 #include "net/reporting/reporting_delegate.h" |
15 #include "net/reporting/reporting_uploader.h" | 15 #include "net/reporting/reporting_uploader.h" |
16 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
17 | 17 |
18 class GURL; | 18 class GURL; |
19 | 19 |
20 namespace base { | 20 namespace base { |
| 21 class MockTimer; |
21 class SimpleTestClock; | 22 class SimpleTestClock; |
22 class SimpleTestTickClock; | 23 class SimpleTestTickClock; |
23 class Value; | 24 class Value; |
24 } // namespace base | 25 } // namespace base |
25 | 26 |
26 namespace url { | 27 namespace url { |
27 class Origin; | 28 class Origin; |
28 } // namespace url | 29 } // namespace url |
29 | 30 |
30 namespace net { | 31 namespace net { |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 | 102 |
102 TestReportingDelegate* test_delegate() { | 103 TestReportingDelegate* test_delegate() { |
103 return reinterpret_cast<TestReportingDelegate*>(delegate()); | 104 return reinterpret_cast<TestReportingDelegate*>(delegate()); |
104 } | 105 } |
105 base::SimpleTestClock* test_clock() { | 106 base::SimpleTestClock* test_clock() { |
106 return reinterpret_cast<base::SimpleTestClock*>(clock()); | 107 return reinterpret_cast<base::SimpleTestClock*>(clock()); |
107 } | 108 } |
108 base::SimpleTestTickClock* test_tick_clock() { | 109 base::SimpleTestTickClock* test_tick_clock() { |
109 return reinterpret_cast<base::SimpleTestTickClock*>(tick_clock()); | 110 return reinterpret_cast<base::SimpleTestTickClock*>(tick_clock()); |
110 } | 111 } |
| 112 base::MockTimer* test_persistence_timer() { return persistence_timer_; } |
111 TestReportingUploader* test_uploader() { | 113 TestReportingUploader* test_uploader() { |
112 return reinterpret_cast<TestReportingUploader*>(uploader()); | 114 return reinterpret_cast<TestReportingUploader*>(uploader()); |
113 } | 115 } |
114 | 116 |
115 private: | 117 private: |
| 118 base::MockTimer* persistence_timer_; |
| 119 |
116 DISALLOW_COPY_AND_ASSIGN(TestReportingContext); | 120 DISALLOW_COPY_AND_ASSIGN(TestReportingContext); |
117 }; | 121 }; |
118 | 122 |
119 // A unit test base class that provides a TestReportingContext and shorthand | 123 // A unit test base class that provides a TestReportingContext and shorthand |
120 // getters. | 124 // getters. |
121 class ReportingTestBase : public ::testing::Test { | 125 class ReportingTestBase : public ::testing::Test { |
122 protected: | 126 protected: |
123 ReportingTestBase(); | 127 ReportingTestBase(); |
124 ~ReportingTestBase() override; | 128 ~ReportingTestBase() override; |
125 | 129 |
126 void UsePolicy(const ReportingPolicy& policy); | 130 void UsePolicy(const ReportingPolicy& policy); |
127 | 131 |
| 132 // Simulates an embedder restart, preserving the ReportingPolicy and any data |
| 133 // persisted via the TestReportingDelegate, but nothing else. |
| 134 // |
| 135 // Advances the Clock by |delta|, and the TickClock by |delta_ticks|. Both can |
| 136 // be zero or negative. |
| 137 void SimulateRestart(base::TimeDelta delta, base::TimeDelta delta_ticks); |
| 138 |
128 TestReportingContext* context() { return context_.get(); } | 139 TestReportingContext* context() { return context_.get(); } |
129 | 140 |
130 const ReportingPolicy& policy() { return context_->policy(); } | 141 const ReportingPolicy& policy() { return context_->policy(); } |
131 | 142 |
132 TestReportingDelegate* delegate() { return context_->test_delegate(); } | 143 TestReportingDelegate* delegate() { return context_->test_delegate(); } |
133 base::SimpleTestClock* clock() { return context_->test_clock(); } | 144 base::SimpleTestClock* clock() { return context_->test_clock(); } |
134 base::SimpleTestTickClock* tick_clock() { | 145 base::SimpleTestTickClock* tick_clock() { |
135 return context_->test_tick_clock(); | 146 return context_->test_tick_clock(); |
136 } | 147 } |
| 148 base::MockTimer* persistence_timer() { |
| 149 return context_->test_persistence_timer(); |
| 150 } |
137 TestReportingUploader* uploader() { return context_->test_uploader(); } | 151 TestReportingUploader* uploader() { return context_->test_uploader(); } |
138 | 152 |
139 ReportingCache* cache() { return context_->cache(); } | 153 ReportingCache* cache() { return context_->cache(); } |
140 ReportingEndpointManager* endpoint_manager() { | 154 ReportingEndpointManager* endpoint_manager() { |
141 return context_->endpoint_manager(); | 155 return context_->endpoint_manager(); |
142 } | 156 } |
143 ReportingDeliveryAgent* delivery_agent() { | 157 ReportingDeliveryAgent* delivery_agent() { |
144 return context_->delivery_agent(); | 158 return context_->delivery_agent(); |
145 } | 159 } |
146 | 160 |
| 161 ReportingPersister* persister() { return context_->persister(); } |
| 162 |
147 base::TimeTicks yesterday(); | 163 base::TimeTicks yesterday(); |
148 | 164 |
149 base::TimeTicks tomorrow(); | 165 base::TimeTicks tomorrow(); |
150 | 166 |
151 private: | 167 private: |
| 168 void CreateAndInitializeContext( |
| 169 const ReportingPolicy& policy, |
| 170 std::unique_ptr<const base::Value> persisted_data, |
| 171 base::Time now, |
| 172 base::TimeTicks now_ticks); |
| 173 |
152 std::unique_ptr<TestReportingContext> context_; | 174 std::unique_ptr<TestReportingContext> context_; |
153 | 175 |
154 DISALLOW_COPY_AND_ASSIGN(ReportingTestBase); | 176 DISALLOW_COPY_AND_ASSIGN(ReportingTestBase); |
155 }; | 177 }; |
156 | 178 |
157 } // namespace net | 179 } // namespace net |
158 | 180 |
159 #endif // NET_REPORING_REPORTING_TEST_UTIL_H_ | 181 #endif // NET_REPORING_REPORTING_TEST_UTIL_H_ |
OLD | NEW |