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 { |
31 | 32 |
32 class ReportingCache; | 33 class ReportingCache; |
33 struct ReportingClient; | 34 struct ReportingClient; |
| 35 class ReportingGarbageCollector; |
34 | 36 |
35 // Finds a particular client (by origin and endpoint) in the cache and returns | 37 // Finds a particular client (by origin and endpoint) in the cache and returns |
36 // it (or nullptr if not found). | 38 // it (or nullptr if not found). |
37 const ReportingClient* FindClientInCache(const ReportingCache* cache, | 39 const ReportingClient* FindClientInCache(const ReportingCache* cache, |
38 const url::Origin& origin, | 40 const url::Origin& origin, |
39 const GURL& endpoint); | 41 const GURL& endpoint); |
40 | 42 |
41 // A simple implementation of ReportingDelegate that only persists data in RAM. | 43 // A simple implementation of ReportingDelegate that only persists data in RAM. |
42 class TestReportingDelegate : public ReportingDelegate { | 44 class TestReportingDelegate : public ReportingDelegate { |
43 public: | 45 public: |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 | 103 |
102 TestReportingDelegate* test_delegate() { | 104 TestReportingDelegate* test_delegate() { |
103 return reinterpret_cast<TestReportingDelegate*>(delegate()); | 105 return reinterpret_cast<TestReportingDelegate*>(delegate()); |
104 } | 106 } |
105 base::SimpleTestClock* test_clock() { | 107 base::SimpleTestClock* test_clock() { |
106 return reinterpret_cast<base::SimpleTestClock*>(clock()); | 108 return reinterpret_cast<base::SimpleTestClock*>(clock()); |
107 } | 109 } |
108 base::SimpleTestTickClock* test_tick_clock() { | 110 base::SimpleTestTickClock* test_tick_clock() { |
109 return reinterpret_cast<base::SimpleTestTickClock*>(tick_clock()); | 111 return reinterpret_cast<base::SimpleTestTickClock*>(tick_clock()); |
110 } | 112 } |
| 113 base::MockTimer* test_garbage_collection_timer() { |
| 114 return garbage_collection_timer_; |
| 115 } |
111 TestReportingUploader* test_uploader() { | 116 TestReportingUploader* test_uploader() { |
112 return reinterpret_cast<TestReportingUploader*>(uploader()); | 117 return reinterpret_cast<TestReportingUploader*>(uploader()); |
113 } | 118 } |
114 | 119 |
115 private: | 120 private: |
| 121 // Owned by the garbage collector but referenced here to preserve type. |
| 122 base::MockTimer* garbage_collection_timer_; |
| 123 |
116 DISALLOW_COPY_AND_ASSIGN(TestReportingContext); | 124 DISALLOW_COPY_AND_ASSIGN(TestReportingContext); |
117 }; | 125 }; |
118 | 126 |
119 // A unit test base class that provides a TestReportingContext and shorthand | 127 // A unit test base class that provides a TestReportingContext and shorthand |
120 // getters. | 128 // getters. |
121 class ReportingTestBase : public ::testing::Test { | 129 class ReportingTestBase : public ::testing::Test { |
122 protected: | 130 protected: |
123 ReportingTestBase(); | 131 ReportingTestBase(); |
124 ~ReportingTestBase() override; | 132 ~ReportingTestBase() override; |
125 | 133 |
126 void UsePolicy(const ReportingPolicy& policy); | 134 void UsePolicy(const ReportingPolicy& policy); |
127 | 135 |
128 TestReportingContext* context() { return context_.get(); } | 136 TestReportingContext* context() { return context_.get(); } |
129 | 137 |
130 const ReportingPolicy& policy() { return context_->policy(); } | 138 const ReportingPolicy& policy() { return context_->policy(); } |
131 | 139 |
132 TestReportingDelegate* delegate() { return context_->test_delegate(); } | 140 TestReportingDelegate* delegate() { return context_->test_delegate(); } |
133 base::SimpleTestClock* clock() { return context_->test_clock(); } | 141 base::SimpleTestClock* clock() { return context_->test_clock(); } |
134 base::SimpleTestTickClock* tick_clock() { | 142 base::SimpleTestTickClock* tick_clock() { |
135 return context_->test_tick_clock(); | 143 return context_->test_tick_clock(); |
136 } | 144 } |
| 145 base::MockTimer* garbage_collection_timer() { |
| 146 return context_->test_garbage_collection_timer(); |
| 147 } |
137 TestReportingUploader* uploader() { return context_->test_uploader(); } | 148 TestReportingUploader* uploader() { return context_->test_uploader(); } |
138 | 149 |
139 ReportingCache* cache() { return context_->cache(); } | 150 ReportingCache* cache() { return context_->cache(); } |
140 ReportingEndpointManager* endpoint_manager() { | 151 ReportingEndpointManager* endpoint_manager() { |
141 return context_->endpoint_manager(); | 152 return context_->endpoint_manager(); |
142 } | 153 } |
143 ReportingDeliveryAgent* delivery_agent() { | 154 ReportingDeliveryAgent* delivery_agent() { |
144 return context_->delivery_agent(); | 155 return context_->delivery_agent(); |
145 } | 156 } |
| 157 ReportingGarbageCollector* garbage_collector() { |
| 158 return context_->garbage_collector(); |
| 159 } |
146 | 160 |
147 base::TimeTicks yesterday(); | 161 base::TimeTicks yesterday(); |
148 | 162 |
149 base::TimeTicks tomorrow(); | 163 base::TimeTicks tomorrow(); |
150 | 164 |
151 private: | 165 private: |
152 std::unique_ptr<TestReportingContext> context_; | 166 std::unique_ptr<TestReportingContext> context_; |
153 | 167 |
154 DISALLOW_COPY_AND_ASSIGN(ReportingTestBase); | 168 DISALLOW_COPY_AND_ASSIGN(ReportingTestBase); |
155 }; | 169 }; |
156 | 170 |
157 } // namespace net | 171 } // namespace net |
158 | 172 |
159 #endif // NET_REPORING_REPORTING_TEST_UTIL_H_ | 173 #endif // NET_REPORING_REPORTING_TEST_UTIL_H_ |
OLD | NEW |