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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 // A test implementation of ReportingContext that uses test versions of | 97 // A test implementation of ReportingContext that uses test versions of |
96 // ReportingDelegate, Clock, TickClock, and ReportingUploader. | 98 // ReportingDelegate, Clock, TickClock, and ReportingUploader. |
97 class TestReportingContext : public ReportingContext { | 99 class TestReportingContext : public ReportingContext { |
98 public: | 100 public: |
99 TestReportingContext(const ReportingPolicy& policy); | 101 TestReportingContext(const ReportingPolicy& policy); |
100 ~TestReportingContext(); | 102 ~TestReportingContext(); |
101 | 103 |
102 TestReportingDelegate* test_delegate() { return test_delegate_; } | 104 TestReportingDelegate* test_delegate() { return test_delegate_; } |
103 base::SimpleTestClock* test_clock() { return test_clock_; } | 105 base::SimpleTestClock* test_clock() { return test_clock_; } |
104 base::SimpleTestTickClock* test_tick_clock() { return test_tick_clock_; } | 106 base::SimpleTestTickClock* test_tick_clock() { return test_tick_clock_; } |
| 107 base::MockTimer* test_garbage_collection_timer() { |
| 108 return test_garbage_collection_timer_; |
| 109 } |
105 TestReportingUploader* test_uploader() { return test_uploader_; } | 110 TestReportingUploader* test_uploader() { return test_uploader_; } |
106 | 111 |
107 private: | 112 private: |
108 // These pointers are owned by the superclass, not this class; they're here | 113 // These pointers are owned by the superclass, not this class; they're here |
109 // just to keep the more specific type. | 114 // just to keep the more specific type. |
110 TestReportingDelegate* test_delegate_; | 115 TestReportingDelegate* test_delegate_; |
111 base::SimpleTestClock* test_clock_; | 116 base::SimpleTestClock* test_clock_; |
112 base::SimpleTestTickClock* test_tick_clock_; | 117 base::SimpleTestTickClock* test_tick_clock_; |
| 118 base::MockTimer* test_garbage_collection_timer_; |
113 TestReportingUploader* test_uploader_; | 119 TestReportingUploader* test_uploader_; |
114 | 120 |
115 DISALLOW_COPY_AND_ASSIGN(TestReportingContext); | 121 DISALLOW_COPY_AND_ASSIGN(TestReportingContext); |
116 }; | 122 }; |
117 | 123 |
118 // A unit test base class that provides a TestReportingContext and shorthand | 124 // A unit test base class that provides a TestReportingContext and shorthand |
119 // getters. | 125 // getters. |
120 class ReportingTestBase : public ::testing::Test { | 126 class ReportingTestBase : public ::testing::Test { |
121 protected: | 127 protected: |
122 ReportingTestBase(); | 128 ReportingTestBase(); |
123 ~ReportingTestBase() override; | 129 ~ReportingTestBase() override; |
124 | 130 |
125 void UsePolicy(const ReportingPolicy& policy); | 131 void UsePolicy(const ReportingPolicy& policy); |
126 | 132 |
127 TestReportingContext* context() { return context_.get(); } | 133 TestReportingContext* context() { return context_.get(); } |
128 | 134 |
129 const ReportingPolicy& policy() { return context_->policy(); } | 135 const ReportingPolicy& policy() { return context_->policy(); } |
130 | 136 |
131 TestReportingDelegate* delegate() { return context_->test_delegate(); } | 137 TestReportingDelegate* delegate() { return context_->test_delegate(); } |
132 base::SimpleTestClock* clock() { return context_->test_clock(); } | 138 base::SimpleTestClock* clock() { return context_->test_clock(); } |
133 base::SimpleTestTickClock* tick_clock() { | 139 base::SimpleTestTickClock* tick_clock() { |
134 return context_->test_tick_clock(); | 140 return context_->test_tick_clock(); |
135 } | 141 } |
| 142 base::MockTimer* garbage_collection_timer() { |
| 143 return context_->test_garbage_collection_timer(); |
| 144 } |
136 TestReportingUploader* uploader() { return context_->test_uploader(); } | 145 TestReportingUploader* uploader() { return context_->test_uploader(); } |
137 | 146 |
138 ReportingCache* cache() { return context_->cache(); } | 147 ReportingCache* cache() { return context_->cache(); } |
139 ReportingEndpointManager* endpoint_manager() { | 148 ReportingEndpointManager* endpoint_manager() { |
140 return context_->endpoint_manager(); | 149 return context_->endpoint_manager(); |
141 } | 150 } |
142 ReportingDeliveryAgent* delivery_agent() { | 151 ReportingDeliveryAgent* delivery_agent() { |
143 return context_->delivery_agent(); | 152 return context_->delivery_agent(); |
144 } | 153 } |
| 154 ReportingGarbageCollector* garbage_collector() { |
| 155 return context_->garbage_collector(); |
| 156 } |
145 | 157 |
146 base::TimeTicks yesterday(); | 158 base::TimeTicks yesterday(); |
147 | 159 |
148 base::TimeTicks tomorrow(); | 160 base::TimeTicks tomorrow(); |
149 | 161 |
150 private: | 162 private: |
151 std::unique_ptr<TestReportingContext> context_; | 163 std::unique_ptr<TestReportingContext> context_; |
152 | 164 |
153 DISALLOW_COPY_AND_ASSIGN(ReportingTestBase); | 165 DISALLOW_COPY_AND_ASSIGN(ReportingTestBase); |
154 }; | 166 }; |
155 | 167 |
156 } // namespace net | 168 } // namespace net |
157 | 169 |
158 #endif // NET_REPORING_REPORTING_TEST_UTIL_H_ | 170 #endif // NET_REPORING_REPORTING_TEST_UTIL_H_ |
OLD | NEW |