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_uploader.h" | 15 #include "net/reporting/reporting_uploader.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
16 | 17 |
17 class GURL; | 18 class GURL; |
18 | 19 |
19 namespace base { | 20 namespace base { |
20 class MockTimer; | 21 class MockTimer; |
21 class SimpleTestClock; | 22 class SimpleTestClock; |
22 class SimpleTestTickClock; | 23 class SimpleTestTickClock; |
23 class Value; | 24 class Value; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 void StartUpload(const GURL& url, | 70 void StartUpload(const GURL& url, |
70 const std::string& json, | 71 const std::string& json, |
71 const Callback& callback) override; | 72 const Callback& callback) override; |
72 | 73 |
73 private: | 74 private: |
74 std::vector<std::unique_ptr<PendingUpload>> pending_uploads_; | 75 std::vector<std::unique_ptr<PendingUpload>> pending_uploads_; |
75 | 76 |
76 DISALLOW_COPY_AND_ASSIGN(TestReportingUploader); | 77 DISALLOW_COPY_AND_ASSIGN(TestReportingUploader); |
77 }; | 78 }; |
78 | 79 |
| 80 class TestReportingDelegate : public ReportingDelegate { |
| 81 public: |
| 82 TestReportingDelegate(); |
| 83 |
| 84 // ReportingDelegate implementation: |
| 85 |
| 86 ~TestReportingDelegate() override; |
| 87 |
| 88 bool CanQueueReport(const url::Origin& origin) const override; |
| 89 |
| 90 bool CanSendReport(const url::Origin& origin) const override; |
| 91 |
| 92 bool CanSetClient(const url::Origin& origin, |
| 93 const GURL& endpoint) const override; |
| 94 |
| 95 bool CanUseClient(const url::Origin& origin, |
| 96 const GURL& endpoint) const override; |
| 97 |
| 98 private: |
| 99 DISALLOW_COPY_AND_ASSIGN(TestReportingDelegate); |
| 100 }; |
| 101 |
79 // A test implementation of ReportingContext that uses test versions of | 102 // A test implementation of ReportingContext that uses test versions of |
80 // Clock, TickClock, Timer, and ReportingUploader. | 103 // Clock, TickClock, Timer, and ReportingUploader. |
81 class TestReportingContext : public ReportingContext { | 104 class TestReportingContext : public ReportingContext { |
82 public: | 105 public: |
83 TestReportingContext(const ReportingPolicy& policy); | 106 TestReportingContext(const ReportingPolicy& policy); |
84 ~TestReportingContext(); | 107 ~TestReportingContext(); |
85 | 108 |
86 base::SimpleTestClock* test_clock() { | 109 base::SimpleTestClock* test_clock() { |
87 return reinterpret_cast<base::SimpleTestClock*>(clock()); | 110 return reinterpret_cast<base::SimpleTestClock*>(clock()); |
88 } | 111 } |
89 base::SimpleTestTickClock* test_tick_clock() { | 112 base::SimpleTestTickClock* test_tick_clock() { |
90 return reinterpret_cast<base::SimpleTestTickClock*>(tick_clock()); | 113 return reinterpret_cast<base::SimpleTestTickClock*>(tick_clock()); |
91 } | 114 } |
92 base::MockTimer* test_delivery_timer() { return delivery_timer_; } | 115 base::MockTimer* test_delivery_timer() { return delivery_timer_; } |
93 base::MockTimer* test_garbage_collection_timer() { | 116 base::MockTimer* test_garbage_collection_timer() { |
94 return garbage_collection_timer_; | 117 return garbage_collection_timer_; |
95 } | 118 } |
96 TestReportingUploader* test_uploader() { | 119 TestReportingUploader* test_uploader() { |
97 return reinterpret_cast<TestReportingUploader*>(uploader()); | 120 return reinterpret_cast<TestReportingUploader*>(uploader()); |
98 } | 121 } |
| 122 TestReportingDelegate* test_delegate() { |
| 123 return reinterpret_cast<TestReportingDelegate*>(delegate()); |
| 124 } |
99 | 125 |
100 private: | 126 private: |
101 // Owned by the Persister and GarbageCollector, respectively, but referenced | 127 // Owned by the Persister and GarbageCollector, respectively, but referenced |
102 // here to preserve type: | 128 // here to preserve type: |
103 | 129 |
104 base::MockTimer* delivery_timer_; | 130 base::MockTimer* delivery_timer_; |
105 base::MockTimer* garbage_collection_timer_; | 131 base::MockTimer* garbage_collection_timer_; |
106 | 132 |
107 DISALLOW_COPY_AND_ASSIGN(TestReportingContext); | 133 DISALLOW_COPY_AND_ASSIGN(TestReportingContext); |
108 }; | 134 }; |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 base::TimeTicks now_ticks); | 193 base::TimeTicks now_ticks); |
168 | 194 |
169 std::unique_ptr<TestReportingContext> context_; | 195 std::unique_ptr<TestReportingContext> context_; |
170 | 196 |
171 DISALLOW_COPY_AND_ASSIGN(ReportingTestBase); | 197 DISALLOW_COPY_AND_ASSIGN(ReportingTestBase); |
172 }; | 198 }; |
173 | 199 |
174 } // namespace net | 200 } // namespace net |
175 | 201 |
176 #endif // NET_REPORING_REPORTING_TEST_UTIL_H_ | 202 #endif // NET_REPORING_REPORTING_TEST_UTIL_H_ |
OLD | NEW |