juliatuttle | 58684333 | 2017-03-27 16:22:37 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "net/reporting/reporting_test_util.h" |
| 6 | |
juliatuttle | ee4b55e | 2017-04-07 17:09:45 | [diff] [blame] | 7 | #include <memory> |
| 8 | #include <string> |
juliatuttle | 58684333 | 2017-03-27 16:22:37 | [diff] [blame] | 9 | #include <vector> |
| 10 | |
juliatuttle | ee4b55e | 2017-04-07 17:09:45 | [diff] [blame] | 11 | #include "base/bind.h" |
Hans Wennborg | 0924470b | 2020-04-27 21:08:05 | [diff] [blame] | 12 | #include "base/check_op.h" |
juliatuttle | ee4b55e | 2017-04-07 17:09:45 | [diff] [blame] | 13 | #include "base/json/json_reader.h" |
| 14 | #include "base/memory/ptr_util.h" |
Hans Wennborg | 0924470b | 2020-04-27 21:08:05 | [diff] [blame] | 15 | #include "base/notreached.h" |
Lily Chen | efb6fcf | 2019-04-19 04:17:54 | [diff] [blame] | 16 | #include "base/strings/stringprintf.h" |
juliatuttle | ee4b55e | 2017-04-07 17:09:45 | [diff] [blame] | 17 | #include "base/test/simple_test_clock.h" |
| 18 | #include "base/test/simple_test_tick_clock.h" |
juliatuttle | 9f970c0 | 2017-04-10 19:26:37 | [diff] [blame] | 19 | #include "base/timer/mock_timer.h" |
Ian Clelland | 52035be | 2021-10-07 16:38:50 | [diff] [blame] | 20 | #include "net/base/isolation_info.h" |
Matt Menke | 5577421a | 2019-10-10 00:04:49 | [diff] [blame] | 21 | #include "net/base/network_isolation_key.h" |
juliatuttle | 58684333 | 2017-03-27 16:22:37 | [diff] [blame] | 22 | #include "net/reporting/reporting_cache.h" |
juliatuttle | ee4b55e | 2017-04-07 17:09:45 | [diff] [blame] | 23 | #include "net/reporting/reporting_context.h" |
juliatuttle | fcf4720 | 2017-05-23 15:53:02 | [diff] [blame] | 24 | #include "net/reporting/reporting_delegate.h" |
juliatuttle | 830962a | 2017-04-19 17:50:04 | [diff] [blame] | 25 | #include "net/reporting/reporting_delivery_agent.h" |
Lily Chen | fc92ff4 | 2019-05-06 22:59:10 | [diff] [blame] | 26 | #include "net/reporting/reporting_endpoint.h" |
juliatuttle | 9f970c0 | 2017-04-10 19:26:37 | [diff] [blame] | 27 | #include "net/reporting/reporting_garbage_collector.h" |
juliatuttle | ee4b55e | 2017-04-07 17:09:45 | [diff] [blame] | 28 | #include "net/reporting/reporting_policy.h" |
| 29 | #include "net/reporting/reporting_uploader.h" |
| 30 | #include "testing/gtest/include/gtest/gtest.h" |
juliatuttle | 58684333 | 2017-03-27 16:22:37 | [diff] [blame] | 31 | #include "url/gurl.h" |
| 32 | #include "url/origin.h" |
| 33 | |
| 34 | namespace net { |
| 35 | |
juliatuttle | ee4b55e | 2017-04-07 17:09:45 | [diff] [blame] | 36 | namespace { |
| 37 | |
| 38 | class PendingUploadImpl : public TestReportingUploader::PendingUpload { |
| 39 | public: |
Douglas Creager | 3428d81 | 2018-07-13 03:59:56 | [diff] [blame] | 40 | PendingUploadImpl(const url::Origin& report_origin, |
| 41 | const GURL& url, |
Ian Clelland | 52035be | 2021-10-07 16:38:50 | [diff] [blame] | 42 | const IsolationInfo& isolation_info, |
Julia Tuttle | ed8d84b | 2017-12-05 18:54:53 | [diff] [blame] | 43 | const std::string& json, |
| 44 | ReportingUploader::UploadCallback callback, |
| 45 | base::OnceCallback<void(PendingUpload*)> complete_callback) |
Douglas Creager | 3428d81 | 2018-07-13 03:59:56 | [diff] [blame] | 46 | : report_origin_(report_origin), |
| 47 | url_(url), |
Ian Clelland | 52035be | 2021-10-07 16:38:50 | [diff] [blame] | 48 | isolation_info_(isolation_info), |
juliatuttle | ee4b55e | 2017-04-07 17:09:45 | [diff] [blame] | 49 | json_(json), |
Julia Tuttle | ed8d84b | 2017-12-05 18:54:53 | [diff] [blame] | 50 | callback_(std::move(callback)), |
| 51 | complete_callback_(std::move(complete_callback)) {} |
juliatuttle | ee4b55e | 2017-04-07 17:09:45 | [diff] [blame] | 52 | |
Chris Watkins | 806691b | 2017-12-01 06:01:22 | [diff] [blame] | 53 | ~PendingUploadImpl() override = default; |
juliatuttle | ee4b55e | 2017-04-07 17:09:45 | [diff] [blame] | 54 | |
Julia Tuttle | 107e3067 | 2018-03-29 18:48:42 | [diff] [blame] | 55 | // PendingUpload implementation: |
Douglas Creager | 3428d81 | 2018-07-13 03:59:56 | [diff] [blame] | 56 | const url::Origin& report_origin() const override { return report_origin_; } |
juliatuttle | ee4b55e | 2017-04-07 17:09:45 | [diff] [blame] | 57 | const GURL& url() const override { return url_; } |
| 58 | const std::string& json() const override { return json_; } |
| 59 | std::unique_ptr<base::Value> GetValue() const override { |
Lei Zhang | a8b4c5fb | 2019-02-16 03:02:03 | [diff] [blame] | 60 | return base::JSONReader::ReadDeprecated(json_); |
juliatuttle | ee4b55e | 2017-04-07 17:09:45 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | void Complete(ReportingUploader::Outcome outcome) override { |
Julia Tuttle | ed8d84b | 2017-12-05 18:54:53 | [diff] [blame] | 64 | std::move(callback_).Run(outcome); |
juliatuttle | ee4b55e | 2017-04-07 17:09:45 | [diff] [blame] | 65 | // Deletes |this|. |
Julia Tuttle | ed8d84b | 2017-12-05 18:54:53 | [diff] [blame] | 66 | std::move(complete_callback_).Run(this); |
juliatuttle | ee4b55e | 2017-04-07 17:09:45 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | private: |
Douglas Creager | 3428d81 | 2018-07-13 03:59:56 | [diff] [blame] | 70 | url::Origin report_origin_; |
juliatuttle | ee4b55e | 2017-04-07 17:09:45 | [diff] [blame] | 71 | GURL url_; |
Ian Clelland | 52035be | 2021-10-07 16:38:50 | [diff] [blame] | 72 | IsolationInfo isolation_info_; |
juliatuttle | ee4b55e | 2017-04-07 17:09:45 | [diff] [blame] | 73 | std::string json_; |
Julia Tuttle | ed8d84b | 2017-12-05 18:54:53 | [diff] [blame] | 74 | ReportingUploader::UploadCallback callback_; |
| 75 | base::OnceCallback<void(PendingUpload*)> complete_callback_; |
juliatuttle | ee4b55e | 2017-04-07 17:09:45 | [diff] [blame] | 76 | }; |
| 77 | |
| 78 | void ErasePendingUpload( |
| 79 | std::vector<std::unique_ptr<TestReportingUploader::PendingUpload>>* uploads, |
| 80 | TestReportingUploader::PendingUpload* upload) { |
| 81 | for (auto it = uploads->begin(); it != uploads->end(); ++it) { |
| 82 | if (it->get() == upload) { |
| 83 | uploads->erase(it); |
| 84 | return; |
| 85 | } |
| 86 | } |
| 87 | NOTREACHED(); |
| 88 | } |
| 89 | |
| 90 | } // namespace |
| 91 | |
Matt Menke | 515136d | 2019-10-05 00:27:09 | [diff] [blame] | 92 | RandIntCallback TestReportingRandIntCallback() { |
| 93 | return base::BindRepeating( |
| 94 | [](int* rand_counter, int min, int max) { |
| 95 | DCHECK_LE(min, max); |
| 96 | return min + ((*rand_counter)++ % (max - min + 1)); |
| 97 | }, |
| 98 | base::Owned(std::make_unique<int>(0))); |
| 99 | } |
| 100 | |
Chris Watkins | 806691b | 2017-12-01 06:01:22 | [diff] [blame] | 101 | TestReportingUploader::PendingUpload::~PendingUpload() = default; |
| 102 | TestReportingUploader::PendingUpload::PendingUpload() = default; |
juliatuttle | ee4b55e | 2017-04-07 17:09:45 | [diff] [blame] | 103 | |
Chris Watkins | 806691b | 2017-12-01 06:01:22 | [diff] [blame] | 104 | TestReportingUploader::TestReportingUploader() = default; |
| 105 | TestReportingUploader::~TestReportingUploader() = default; |
juliatuttle | ee4b55e | 2017-04-07 17:09:45 | [diff] [blame] | 106 | |
Ian Clelland | 52035be | 2021-10-07 16:38:50 | [diff] [blame] | 107 | void TestReportingUploader::StartUpload(const url::Origin& report_origin, |
| 108 | const GURL& url, |
| 109 | const IsolationInfo& isolation_info, |
| 110 | const std::string& json, |
| 111 | int max_depth, |
| 112 | bool eligible_for_credentials, |
| 113 | UploadCallback callback) { |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 114 | pending_uploads_.push_back(std::make_unique<PendingUploadImpl>( |
Ian Clelland | 52035be | 2021-10-07 16:38:50 | [diff] [blame] | 115 | report_origin, url, isolation_info, json, std::move(callback), |
Julia Tuttle | ed8d84b | 2017-12-05 18:54:53 | [diff] [blame] | 116 | base::BindOnce(&ErasePendingUpload, &pending_uploads_))); |
juliatuttle | ee4b55e | 2017-04-07 17:09:45 | [diff] [blame] | 117 | } |
| 118 | |
Lily Chen | 91b51e6 | 2019-03-01 16:46:07 | [diff] [blame] | 119 | void TestReportingUploader::OnShutdown() { |
| 120 | pending_uploads_.clear(); |
| 121 | } |
| 122 | |
| 123 | int TestReportingUploader::GetPendingUploadCountForTesting() const { |
| 124 | return pending_uploads_.size(); |
| 125 | } |
| 126 | |
Matt Menke | 515136d | 2019-10-05 00:27:09 | [diff] [blame] | 127 | TestReportingDelegate::TestReportingDelegate() = default; |
juliatuttle | fcf4720 | 2017-05-23 15:53:02 | [diff] [blame] | 128 | |
Chris Watkins | 806691b | 2017-12-01 06:01:22 | [diff] [blame] | 129 | TestReportingDelegate::~TestReportingDelegate() = default; |
juliatuttle | fcf4720 | 2017-05-23 15:53:02 | [diff] [blame] | 130 | |
| 131 | bool TestReportingDelegate::CanQueueReport(const url::Origin& origin) const { |
| 132 | return true; |
| 133 | } |
| 134 | |
Douglas Creager | 7b07ea4 | 2018-02-27 21:08:08 | [diff] [blame] | 135 | void TestReportingDelegate::CanSendReports( |
| 136 | std::set<url::Origin> origins, |
| 137 | base::OnceCallback<void(std::set<url::Origin>)> result_callback) const { |
Douglas Creager | 66494e1 | 2018-03-05 22:21:00 | [diff] [blame] | 138 | if (pause_permissions_check_) { |
| 139 | saved_origins_ = std::move(origins); |
| 140 | permissions_check_callback_ = std::move(result_callback); |
| 141 | return; |
| 142 | } |
| 143 | |
Douglas Creager | 7b07ea4 | 2018-02-27 21:08:08 | [diff] [blame] | 144 | if (disallow_report_uploads_) |
| 145 | origins.clear(); |
| 146 | std::move(result_callback).Run(std::move(origins)); |
juliatuttle | fcf4720 | 2017-05-23 15:53:02 | [diff] [blame] | 147 | } |
| 148 | |
Douglas Creager | 66494e1 | 2018-03-05 22:21:00 | [diff] [blame] | 149 | bool TestReportingDelegate::PermissionsCheckPaused() const { |
| 150 | return !permissions_check_callback_.is_null(); |
| 151 | } |
| 152 | |
| 153 | void TestReportingDelegate::ResumePermissionsCheck() { |
| 154 | if (disallow_report_uploads_) |
| 155 | saved_origins_.clear(); |
| 156 | std::move(permissions_check_callback_).Run(std::move(saved_origins_)); |
| 157 | } |
| 158 | |
juliatuttle | fcf4720 | 2017-05-23 15:53:02 | [diff] [blame] | 159 | bool TestReportingDelegate::CanSetClient(const url::Origin& origin, |
| 160 | const GURL& endpoint) const { |
| 161 | return true; |
| 162 | } |
| 163 | |
| 164 | bool TestReportingDelegate::CanUseClient(const url::Origin& origin, |
| 165 | const GURL& endpoint) const { |
| 166 | return true; |
| 167 | } |
| 168 | |
Lily Chen | 731a95c | 2019-05-06 22:27:22 | [diff] [blame] | 169 | TestReportingContext::TestReportingContext( |
| 170 | base::Clock* clock, |
| 171 | const base::TickClock* tick_clock, |
| 172 | const ReportingPolicy& policy, |
| 173 | ReportingCache::PersistentReportingStore* store) |
Matt Menke | 515136d | 2019-10-05 00:27:09 | [diff] [blame] | 174 | : ReportingContext(policy, |
| 175 | clock, |
| 176 | tick_clock, |
| 177 | TestReportingRandIntCallback(), |
| 178 | std::make_unique<TestReportingUploader>(), |
| 179 | std::make_unique<TestReportingDelegate>(), |
| 180 | store), |
tzik | 35945aa | 2018-06-22 00:33:26 | [diff] [blame] | 181 | delivery_timer_(new base::MockOneShotTimer()), |
| 182 | garbage_collection_timer_(new base::MockOneShotTimer()) { |
juliatuttle | 9f970c0 | 2017-04-10 19:26:37 | [diff] [blame] | 183 | garbage_collector()->SetTimerForTesting( |
| 184 | base::WrapUnique(garbage_collection_timer_)); |
juliatuttle | 830962a | 2017-04-19 17:50:04 | [diff] [blame] | 185 | delivery_agent()->SetTimerForTesting(base::WrapUnique(delivery_timer_)); |
juliatuttle | 9f970c0 | 2017-04-10 19:26:37 | [diff] [blame] | 186 | } |
juliatuttle | ee4b55e | 2017-04-07 17:09:45 | [diff] [blame] | 187 | |
juliatuttle | 9f970c0 | 2017-04-10 19:26:37 | [diff] [blame] | 188 | TestReportingContext::~TestReportingContext() { |
juliatuttle | 830962a | 2017-04-19 17:50:04 | [diff] [blame] | 189 | delivery_timer_ = nullptr; |
juliatuttle | 9f970c0 | 2017-04-10 19:26:37 | [diff] [blame] | 190 | garbage_collection_timer_ = nullptr; |
| 191 | } |
juliatuttle | ee4b55e | 2017-04-07 17:09:45 | [diff] [blame] | 192 | |
Lily Chen | 731a95c | 2019-05-06 22:27:22 | [diff] [blame] | 193 | ReportingTestBase::ReportingTestBase() : store_(nullptr) { |
juliatuttle | ee4b55e | 2017-04-07 17:09:45 | [diff] [blame] | 194 | // For tests, disable jitter. |
| 195 | ReportingPolicy policy; |
| 196 | policy.endpoint_backoff_policy.jitter_factor = 0.0; |
juliatuttle | 7da1381 | 2017-04-13 19:18:19 | [diff] [blame] | 197 | |
juliatuttle | 42c5731 | 2017-04-28 03:01:30 | [diff] [blame] | 198 | CreateContext(policy, base::Time::Now(), base::TimeTicks::Now()); |
juliatuttle | ee4b55e | 2017-04-07 17:09:45 | [diff] [blame] | 199 | } |
| 200 | |
Chris Watkins | 806691b | 2017-12-01 06:01:22 | [diff] [blame] | 201 | ReportingTestBase::~ReportingTestBase() = default; |
juliatuttle | ee4b55e | 2017-04-07 17:09:45 | [diff] [blame] | 202 | |
juliatuttle | 7da1381 | 2017-04-13 19:18:19 | [diff] [blame] | 203 | void ReportingTestBase::UsePolicy(const ReportingPolicy& new_policy) { |
juliatuttle | 42c5731 | 2017-04-28 03:01:30 | [diff] [blame] | 204 | CreateContext(new_policy, clock()->Now(), tick_clock()->NowTicks()); |
juliatuttle | 7da1381 | 2017-04-13 19:18:19 | [diff] [blame] | 205 | } |
| 206 | |
Lily Chen | 731a95c | 2019-05-06 22:27:22 | [diff] [blame] | 207 | void ReportingTestBase::UseStore( |
| 208 | ReportingCache::PersistentReportingStore* store) { |
| 209 | store_ = store; |
| 210 | CreateContext(policy(), clock()->Now(), tick_clock()->NowTicks()); |
| 211 | } |
| 212 | |
Lily Chen | fc92ff4 | 2019-05-06 22:59:10 | [diff] [blame] | 213 | const ReportingEndpoint ReportingTestBase::FindEndpointInCache( |
Lily Chen | ad5dd080 | 2020-03-10 21:58:09 | [diff] [blame] | 214 | const ReportingEndpointGroupKey& group_key, |
Lily Chen | efb6fcf | 2019-04-19 04:17:54 | [diff] [blame] | 215 | const GURL& url) { |
Lily Chen | ad5dd080 | 2020-03-10 21:58:09 | [diff] [blame] | 216 | return cache()->GetEndpointForTesting(group_key, url); |
Lily Chen | efb6fcf | 2019-04-19 04:17:54 | [diff] [blame] | 217 | } |
| 218 | |
Lily Chen | ad5dd080 | 2020-03-10 21:58:09 | [diff] [blame] | 219 | bool ReportingTestBase::SetEndpointInCache( |
| 220 | const ReportingEndpointGroupKey& group_key, |
| 221 | const GURL& url, |
| 222 | base::Time expires, |
| 223 | OriginSubdomains include_subdomains, |
| 224 | int priority, |
| 225 | int weight) { |
| 226 | cache()->SetEndpointForTesting(group_key, url, include_subdomains, expires, |
| 227 | priority, weight); |
| 228 | const ReportingEndpoint endpoint = FindEndpointInCache(group_key, url); |
Lily Chen | efb6fcf | 2019-04-19 04:17:54 | [diff] [blame] | 229 | return endpoint.is_valid(); |
| 230 | } |
| 231 | |
Ian Clelland | a52d547 | 2021-08-23 18:33:53 | [diff] [blame] | 232 | void ReportingTestBase::SetV1EndpointInCache( |
| 233 | const ReportingEndpointGroupKey& group_key, |
| 234 | const base::UnguessableToken& reporting_source, |
Ian Clelland | 52035be | 2021-10-07 16:38:50 | [diff] [blame] | 235 | const IsolationInfo& isolation_info, |
Ian Clelland | a52d547 | 2021-08-23 18:33:53 | [diff] [blame] | 236 | const GURL& url) { |
Ian Clelland | 52035be | 2021-10-07 16:38:50 | [diff] [blame] | 237 | cache()->SetV1EndpointForTesting(group_key, reporting_source, isolation_info, |
| 238 | url); |
Ian Clelland | a52d547 | 2021-08-23 18:33:53 | [diff] [blame] | 239 | } |
| 240 | |
Lily Chen | ad5dd080 | 2020-03-10 21:58:09 | [diff] [blame] | 241 | bool ReportingTestBase::EndpointExistsInCache( |
| 242 | const ReportingEndpointGroupKey& group_key, |
| 243 | const GURL& url) { |
| 244 | ReportingEndpoint endpoint = cache()->GetEndpointForTesting(group_key, url); |
Lily Chen | efb6fcf | 2019-04-19 04:17:54 | [diff] [blame] | 245 | return endpoint.is_valid(); |
| 246 | } |
| 247 | |
Lily Chen | fc92ff4 | 2019-05-06 22:59:10 | [diff] [blame] | 248 | ReportingEndpoint::Statistics ReportingTestBase::GetEndpointStatistics( |
Lily Chen | ad5dd080 | 2020-03-10 21:58:09 | [diff] [blame] | 249 | const ReportingEndpointGroupKey& group_key, |
Lily Chen | efb6fcf | 2019-04-19 04:17:54 | [diff] [blame] | 250 | const GURL& url) { |
Rodney Ding | 1e75846 | 2021-09-16 13:59:07 | [diff] [blame] | 251 | ReportingEndpoint endpoint; |
| 252 | if (group_key.IsDocumentEndpoint()) { |
| 253 | endpoint = cache()->GetV1EndpointForTesting( |
| 254 | group_key.reporting_source.value(), group_key.group_name); |
| 255 | } else { |
| 256 | endpoint = cache()->GetEndpointForTesting(group_key, url); |
| 257 | } |
Lily Chen | efb6fcf | 2019-04-19 04:17:54 | [diff] [blame] | 258 | if (endpoint) |
| 259 | return endpoint.stats; |
Lily Chen | fc92ff4 | 2019-05-06 22:59:10 | [diff] [blame] | 260 | return ReportingEndpoint::Statistics(); |
Lily Chen | efb6fcf | 2019-04-19 04:17:54 | [diff] [blame] | 261 | } |
| 262 | |
| 263 | bool ReportingTestBase::EndpointGroupExistsInCache( |
Lily Chen | ad5dd080 | 2020-03-10 21:58:09 | [diff] [blame] | 264 | const ReportingEndpointGroupKey& group_key, |
Lily Chen | efb6fcf | 2019-04-19 04:17:54 | [diff] [blame] | 265 | OriginSubdomains include_subdomains, |
| 266 | base::Time expires) { |
Lily Chen | ad5dd080 | 2020-03-10 21:58:09 | [diff] [blame] | 267 | return cache()->EndpointGroupExistsForTesting(group_key, include_subdomains, |
| 268 | expires); |
Lily Chen | efb6fcf | 2019-04-19 04:17:54 | [diff] [blame] | 269 | } |
| 270 | |
Lily Chen | ad5dd080 | 2020-03-10 21:58:09 | [diff] [blame] | 271 | bool ReportingTestBase::ClientExistsInCacheForOrigin( |
| 272 | const url::Origin& origin) { |
| 273 | std::set<url::Origin> all_origins = cache()->GetAllOrigins(); |
| 274 | return all_origins.find(origin) != all_origins.end(); |
Lily Chen | efb6fcf | 2019-04-19 04:17:54 | [diff] [blame] | 275 | } |
| 276 | |
| 277 | GURL ReportingTestBase::MakeURL(size_t index) { |
| 278 | return GURL(base::StringPrintf("https://example%zd.test", index)); |
| 279 | } |
| 280 | |
juliatuttle | 7da1381 | 2017-04-13 19:18:19 | [diff] [blame] | 281 | void ReportingTestBase::SimulateRestart(base::TimeDelta delta, |
| 282 | base::TimeDelta delta_ticks) { |
juliatuttle | 42c5731 | 2017-04-28 03:01:30 | [diff] [blame] | 283 | CreateContext(policy(), clock()->Now() + delta, |
| 284 | tick_clock()->NowTicks() + delta_ticks); |
juliatuttle | 7da1381 | 2017-04-13 19:18:19 | [diff] [blame] | 285 | } |
| 286 | |
juliatuttle | 42c5731 | 2017-04-28 03:01:30 | [diff] [blame] | 287 | void ReportingTestBase::CreateContext(const ReportingPolicy& policy, |
| 288 | base::Time now, |
| 289 | base::TimeTicks now_ticks) { |
Lily Chen | 731a95c | 2019-05-06 22:27:22 | [diff] [blame] | 290 | context_ = std::make_unique<TestReportingContext>(&clock_, &tick_clock_, |
| 291 | policy, store_); |
juliatuttle | 7da1381 | 2017-04-13 19:18:19 | [diff] [blame] | 292 | clock()->SetNow(now); |
| 293 | tick_clock()->SetNowTicks(now_ticks); |
juliatuttle | ee4b55e | 2017-04-07 17:09:45 | [diff] [blame] | 294 | } |
| 295 | |
| 296 | base::TimeTicks ReportingTestBase::yesterday() { |
Peter Kasting | e5a38ed | 2021-10-02 03:06:35 | [diff] [blame] | 297 | return tick_clock()->NowTicks() - base::Days(1); |
juliatuttle | ee4b55e | 2017-04-07 17:09:45 | [diff] [blame] | 298 | } |
| 299 | |
juliatuttle | 830962a | 2017-04-19 17:50:04 | [diff] [blame] | 300 | base::TimeTicks ReportingTestBase::now() { |
| 301 | return tick_clock()->NowTicks(); |
| 302 | } |
| 303 | |
juliatuttle | ee4b55e | 2017-04-07 17:09:45 | [diff] [blame] | 304 | base::TimeTicks ReportingTestBase::tomorrow() { |
Peter Kasting | e5a38ed | 2021-10-02 03:06:35 | [diff] [blame] | 305 | return tick_clock()->NowTicks() + base::Days(1); |
juliatuttle | ee4b55e | 2017-04-07 17:09:45 | [diff] [blame] | 306 | } |
| 307 | |
Lily Chen | 8a9e5372 | 2019-04-26 15:16:02 | [diff] [blame] | 308 | TestReportingService::Report::Report() = default; |
| 309 | |
Matt Menke | 643ae97 | 2020-10-22 13:47:02 | [diff] [blame] | 310 | TestReportingService::Report::Report(Report&& other) = default; |
Lily Chen | 8a9e5372 | 2019-04-26 15:16:02 | [diff] [blame] | 311 | |
Matt Menke | dd2ed7a | 2020-10-22 04:09:20 | [diff] [blame] | 312 | TestReportingService::Report::Report( |
| 313 | const GURL& url, |
| 314 | const NetworkIsolationKey& network_isolation_key, |
| 315 | const std::string& user_agent, |
| 316 | const std::string& group, |
| 317 | const std::string& type, |
| 318 | std::unique_ptr<const base::Value> body, |
| 319 | int depth) |
Lily Chen | 8a9e5372 | 2019-04-26 15:16:02 | [diff] [blame] | 320 | : url(url), |
Matt Menke | dd2ed7a | 2020-10-22 04:09:20 | [diff] [blame] | 321 | network_isolation_key(network_isolation_key), |
Lily Chen | 8a9e5372 | 2019-04-26 15:16:02 | [diff] [blame] | 322 | user_agent(user_agent), |
| 323 | group(group), |
| 324 | type(type), |
| 325 | body(std::move(body)), |
| 326 | depth(depth) {} |
| 327 | |
| 328 | TestReportingService::Report::~Report() = default; |
| 329 | |
| 330 | TestReportingService::TestReportingService() = default; |
| 331 | |
| 332 | TestReportingService::~TestReportingService() = default; |
| 333 | |
Matt Menke | dd2ed7a | 2020-10-22 04:09:20 | [diff] [blame] | 334 | void TestReportingService::QueueReport( |
| 335 | const GURL& url, |
Ian Clelland | e07e64b | 2021-08-23 16:29:43 | [diff] [blame] | 336 | const absl::optional<base::UnguessableToken>& reporting_source, |
Matt Menke | dd2ed7a | 2020-10-22 04:09:20 | [diff] [blame] | 337 | const NetworkIsolationKey& network_isolation_key, |
| 338 | const std::string& user_agent, |
| 339 | const std::string& group, |
| 340 | const std::string& type, |
| 341 | std::unique_ptr<const base::Value> body, |
| 342 | int depth) { |
| 343 | reports_.emplace_back(Report(url, network_isolation_key, user_agent, group, |
| 344 | type, std::move(body), depth)); |
Lily Chen | 8a9e5372 | 2019-04-26 15:16:02 | [diff] [blame] | 345 | } |
| 346 | |
Rodney Ding | 329e4bb | 2021-03-19 22:21:53 | [diff] [blame] | 347 | void TestReportingService::ProcessReportToHeader( |
Matt Menke | e439902 | 2021-10-21 18:04:42 | [diff] [blame] | 348 | const url::Origin& origin, |
Matt Menke | 17b23c4 | 2020-10-22 05:14:57 | [diff] [blame] | 349 | const NetworkIsolationKey& network_isolation_key, |
| 350 | const std::string& header_value) { |
Lily Chen | 8a9e5372 | 2019-04-26 15:16:02 | [diff] [blame] | 351 | NOTREACHED(); |
| 352 | } |
| 353 | |
| 354 | void TestReportingService::RemoveBrowsingData( |
Marcus Pasell | c3305c04 | 2020-06-03 22:14:36 | [diff] [blame] | 355 | uint64_t data_type_mask, |
Lily Chen | 8a9e5372 | 2019-04-26 15:16:02 | [diff] [blame] | 356 | const base::RepeatingCallback<bool(const GURL&)>& origin_filter) { |
| 357 | NOTREACHED(); |
| 358 | } |
| 359 | |
Marcus Pasell | c3305c04 | 2020-06-03 22:14:36 | [diff] [blame] | 360 | void TestReportingService::RemoveAllBrowsingData(uint64_t data_type_mask) { |
Lily Chen | 8a9e5372 | 2019-04-26 15:16:02 | [diff] [blame] | 361 | NOTREACHED(); |
| 362 | } |
| 363 | |
| 364 | void TestReportingService::OnShutdown() {} |
| 365 | |
| 366 | const ReportingPolicy& TestReportingService::GetPolicy() const { |
| 367 | NOTREACHED(); |
| 368 | return dummy_policy_; |
| 369 | } |
| 370 | |
| 371 | ReportingContext* TestReportingService::GetContextForTesting() const { |
| 372 | NOTREACHED(); |
| 373 | return nullptr; |
| 374 | } |
| 375 | |
Wolfgang Beyer | 14d8d41b8 | 2021-08-17 15:52:07 | [diff] [blame] | 376 | std::vector<const ReportingReport*> TestReportingService::GetReports() const { |
| 377 | NOTREACHED(); |
| 378 | return std::vector<const ReportingReport*>(); |
| 379 | } |
| 380 | |
Wolfgang Beyer | ba1bf70 | 2021-11-15 12:49:47 | [diff] [blame^] | 381 | base::flat_map<url::Origin, std::vector<ReportingEndpoint>> |
| 382 | TestReportingService::GetV1ReportingEndpointsByOrigin() const { |
| 383 | NOTREACHED(); |
| 384 | return base::flat_map<url::Origin, std::vector<ReportingEndpoint>>(); |
| 385 | } |
| 386 | |
Wolfgang Beyer | 14d8d41b8 | 2021-08-17 15:52:07 | [diff] [blame] | 387 | void TestReportingService::AddReportingCacheObserver( |
| 388 | ReportingCacheObserver* observer) { |
| 389 | NOTREACHED(); |
| 390 | } |
| 391 | |
| 392 | void TestReportingService::RemoveReportingCacheObserver( |
| 393 | ReportingCacheObserver* observer) { |
| 394 | NOTREACHED(); |
| 395 | } |
| 396 | |
juliatuttle | 58684333 | 2017-03-27 16:22:37 | [diff] [blame] | 397 | } // namespace net |