1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
content / browser / private_aggregation / private_aggregation_test_utils.h [blame]
// Copyright 2022 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CONTENT_BROWSER_PRIVATE_AGGREGATION_PRIVATE_AGGREGATION_TEST_UTILS_H_
#define CONTENT_BROWSER_PRIVATE_AGGREGATION_PRIVATE_AGGREGATION_TEST_UTILS_H_
#include <stddef.h>
#include <optional>
#include <set>
#include <string>
#include <vector>
#include "base/functional/callback_forward.h"
#include "base/time/time.h"
#include "content/browser/aggregation_service/aggregatable_report.h"
#include "content/browser/private_aggregation/private_aggregation_budget_key.h"
#include "content/browser/private_aggregation/private_aggregation_budgeter.h"
#include "content/browser/private_aggregation/private_aggregation_caller_api.h"
#include "content/browser/private_aggregation/private_aggregation_host.h"
#include "content/browser/private_aggregation/private_aggregation_manager_impl.h"
#include "content/public/browser/storage_partition.h"
#include "content/public/test/test_browser_context.h"
#include "content/test/test_content_browser_client.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "third_party/blink/public/mojom/aggregation_service/aggregatable_report.mojom-forward.h"
#include "third_party/blink/public/mojom/private_aggregation/private_aggregation_host.mojom-forward.h"
namespace url {
class Origin;
}
namespace content {
class StoragePartitionImpl;
class MockPrivateAggregationBudgeter : public PrivateAggregationBudgeter {
public:
MockPrivateAggregationBudgeter();
~MockPrivateAggregationBudgeter() override;
MOCK_METHOD(void,
ConsumeBudget,
(int,
const PrivateAggregationBudgetKey&,
int,
base::OnceCallback<void(RequestResult)>),
(override));
MOCK_METHOD(void,
ClearData,
(base::Time,
base::Time,
StoragePartition::StorageKeyMatcherFunction,
base::OnceClosure),
(override));
MOCK_METHOD(void,
GetAllDataKeys,
(base::OnceCallback<
void(std::set<PrivateAggregationDataModel::DataKey>)>),
(override));
MOCK_METHOD(void,
DeleteByDataKey,
(const PrivateAggregationDataModel::DataKey& key,
base::OnceClosure callback),
(override));
};
// Note: the `TestBrowserContext` may require a `BrowserTaskEnvironment` to be
// set up.
class MockPrivateAggregationHost : public PrivateAggregationHost {
public:
MockPrivateAggregationHost();
~MockPrivateAggregationHost() override;
MOCK_METHOD(bool,
BindNewReceiver,
(url::Origin,
url::Origin,
PrivateAggregationCallerApi,
std::optional<std::string>,
std::optional<base::TimeDelta>,
std::optional<url::Origin>,
size_t,
mojo::PendingReceiver<blink::mojom::PrivateAggregationHost>),
(override));
MOCK_METHOD(
void,
ContributeToHistogram,
(std::vector<blink::mojom::AggregatableReportHistogramContributionPtr>),
(override));
MOCK_METHOD(void, EnableDebugMode, (blink::mojom::DebugKeyPtr), (override));
private:
TestBrowserContext test_browser_context_;
};
class MockPrivateAggregationManagerImpl : public PrivateAggregationManagerImpl {
public:
explicit MockPrivateAggregationManagerImpl(StoragePartitionImpl* partition);
~MockPrivateAggregationManagerImpl() override;
MOCK_METHOD(bool,
BindNewReceiver,
(url::Origin,
url::Origin,
PrivateAggregationCallerApi,
std::optional<std::string>,
std::optional<base::TimeDelta>,
std::optional<url::Origin>,
size_t,
mojo::PendingReceiver<blink::mojom::PrivateAggregationHost>),
(override));
MOCK_METHOD(void,
ClearBudgetData,
(base::Time,
base::Time,
StoragePartition::StorageKeyMatcherFunction,
base::OnceClosure),
(override));
};
template <typename SuperClass>
class MockPrivateAggregationContentBrowserClientBase : public SuperClass {
public:
// ContentBrowserClient:
MOCK_METHOD(bool,
IsPrivateAggregationAllowed,
(content::BrowserContext * browser_context,
const url::Origin& top_frame_origin,
const url::Origin& reporting_origin,
bool* out_block_is_site_setting_specific),
(override));
MOCK_METHOD(bool,
IsPrivateAggregationDebugModeAllowed,
(content::BrowserContext * browser_context,
const url::Origin& top_frame_origin,
const url::Origin& reporting_origin),
(override));
MOCK_METHOD(void,
LogWebFeatureForCurrentPage,
(content::RenderFrameHost*, blink::mojom::WebFeature),
(override));
MOCK_METHOD(bool,
IsSharedStorageAllowed,
(content::BrowserContext * browser_context,
content::RenderFrameHost* rfh,
const url::Origin& top_frame_origin,
const url::Origin& accessing_origin,
std::string* out_debug_message,
bool* out_block_is_site_setting_specific),
(override));
MOCK_METHOD(bool,
IsFencedFramesLocalUnpartitionedDataAccessAllowed,
(content::BrowserContext * browser_context,
content::RenderFrameHost* rfh,
const url::Origin& top_frame_origin,
const url::Origin& accessing_origin),
(override));
MOCK_METHOD(bool,
IsPrivacySandboxReportingDestinationAttested,
(content::BrowserContext * browser_context,
const url::Origin& destination_origin,
content::PrivacySandboxInvokingAPI invoking_api),
(override));
};
using MockPrivateAggregationContentBrowserClient =
MockPrivateAggregationContentBrowserClientBase<TestContentBrowserClient>;
bool operator==(const PrivateAggregationBudgetKey::TimeWindow&,
const PrivateAggregationBudgetKey::TimeWindow&);
bool operator==(const PrivateAggregationBudgetKey&,
const PrivateAggregationBudgetKey&);
} // namespace content
#endif // CONTENT_BROWSER_PRIVATE_AGGREGATION_PRIVATE_AGGREGATION_TEST_UTILS_H_