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 #include "net/reporting/reporting_test_util.h" | 5 #include "net/reporting/reporting_test_util.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/json/json_reader.h" | 12 #include "base/json/json_reader.h" |
13 #include "base/memory/ptr_util.h" | 13 #include "base/memory/ptr_util.h" |
14 #include "base/test/simple_test_clock.h" | 14 #include "base/test/simple_test_clock.h" |
15 #include "base/test/simple_test_tick_clock.h" | 15 #include "base/test/simple_test_tick_clock.h" |
16 #include "base/timer/mock_timer.h" | 16 #include "base/timer/mock_timer.h" |
17 #include "net/reporting/reporting_cache.h" | 17 #include "net/reporting/reporting_cache.h" |
18 #include "net/reporting/reporting_client.h" | 18 #include "net/reporting/reporting_client.h" |
19 #include "net/reporting/reporting_context.h" | 19 #include "net/reporting/reporting_context.h" |
| 20 #include "net/reporting/reporting_delegate.h" |
20 #include "net/reporting/reporting_delivery_agent.h" | 21 #include "net/reporting/reporting_delivery_agent.h" |
21 #include "net/reporting/reporting_garbage_collector.h" | 22 #include "net/reporting/reporting_garbage_collector.h" |
22 #include "net/reporting/reporting_persister.h" | 23 #include "net/reporting/reporting_persister.h" |
23 #include "net/reporting/reporting_policy.h" | 24 #include "net/reporting/reporting_policy.h" |
24 #include "net/reporting/reporting_uploader.h" | 25 #include "net/reporting/reporting_uploader.h" |
25 #include "testing/gtest/include/gtest/gtest.h" | 26 #include "testing/gtest/include/gtest/gtest.h" |
26 #include "url/gurl.h" | 27 #include "url/gurl.h" |
27 #include "url/origin.h" | 28 #include "url/origin.h" |
28 | 29 |
29 namespace net { | 30 namespace net { |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 TestReportingUploader::TestReportingUploader() {} | 97 TestReportingUploader::TestReportingUploader() {} |
97 TestReportingUploader::~TestReportingUploader() {} | 98 TestReportingUploader::~TestReportingUploader() {} |
98 | 99 |
99 void TestReportingUploader::StartUpload(const GURL& url, | 100 void TestReportingUploader::StartUpload(const GURL& url, |
100 const std::string& json, | 101 const std::string& json, |
101 const Callback& callback) { | 102 const Callback& callback) { |
102 pending_uploads_.push_back(base::MakeUnique<PendingUploadImpl>( | 103 pending_uploads_.push_back(base::MakeUnique<PendingUploadImpl>( |
103 url, json, callback, base::Bind(&ErasePendingUpload, &pending_uploads_))); | 104 url, json, callback, base::Bind(&ErasePendingUpload, &pending_uploads_))); |
104 } | 105 } |
105 | 106 |
| 107 TestReportingDelegate::TestReportingDelegate() {} |
| 108 |
| 109 TestReportingDelegate::~TestReportingDelegate() {} |
| 110 |
| 111 bool TestReportingDelegate::CanQueueReport(const url::Origin& origin) const { |
| 112 return true; |
| 113 } |
| 114 |
| 115 bool TestReportingDelegate::CanSendReport(const url::Origin& origin) const { |
| 116 return true; |
| 117 } |
| 118 |
| 119 bool TestReportingDelegate::CanSetClient(const url::Origin& origin, |
| 120 const GURL& endpoint) const { |
| 121 return true; |
| 122 } |
| 123 |
| 124 bool TestReportingDelegate::CanUseClient(const url::Origin& origin, |
| 125 const GURL& endpoint) const { |
| 126 return true; |
| 127 } |
| 128 |
106 TestReportingContext::TestReportingContext(const ReportingPolicy& policy) | 129 TestReportingContext::TestReportingContext(const ReportingPolicy& policy) |
107 : ReportingContext(policy, | 130 : ReportingContext(policy, |
108 base::MakeUnique<base::SimpleTestClock>(), | 131 base::MakeUnique<base::SimpleTestClock>(), |
109 base::MakeUnique<base::SimpleTestTickClock>(), | 132 base::MakeUnique<base::SimpleTestTickClock>(), |
110 base::MakeUnique<TestReportingUploader>()), | 133 base::MakeUnique<TestReportingUploader>(), |
| 134 base::MakeUnique<TestReportingDelegate>()), |
111 delivery_timer_(new base::MockTimer(/* retain_user_task= */ false, | 135 delivery_timer_(new base::MockTimer(/* retain_user_task= */ false, |
112 /* is_repeating= */ false)), | 136 /* is_repeating= */ false)), |
113 garbage_collection_timer_( | 137 garbage_collection_timer_( |
114 new base::MockTimer(/* retain_user_task= */ false, | 138 new base::MockTimer(/* retain_user_task= */ false, |
115 /* is_repeating= */ false)) { | 139 /* is_repeating= */ false)) { |
116 garbage_collector()->SetTimerForTesting( | 140 garbage_collector()->SetTimerForTesting( |
117 base::WrapUnique(garbage_collection_timer_)); | 141 base::WrapUnique(garbage_collection_timer_)); |
118 delivery_agent()->SetTimerForTesting(base::WrapUnique(delivery_timer_)); | 142 delivery_agent()->SetTimerForTesting(base::WrapUnique(delivery_timer_)); |
119 } | 143 } |
120 | 144 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 | 181 |
158 base::TimeTicks ReportingTestBase::now() { | 182 base::TimeTicks ReportingTestBase::now() { |
159 return tick_clock()->NowTicks(); | 183 return tick_clock()->NowTicks(); |
160 } | 184 } |
161 | 185 |
162 base::TimeTicks ReportingTestBase::tomorrow() { | 186 base::TimeTicks ReportingTestBase::tomorrow() { |
163 return tick_clock()->NowTicks() + base::TimeDelta::FromDays(1); | 187 return tick_clock()->NowTicks() + base::TimeDelta::FromDays(1); |
164 } | 188 } |
165 | 189 |
166 } // namespace net | 190 } // namespace net |
OLD | NEW |