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