[go: nahoru, domu]

blob: dfb82fa4a71c5d7241f8f63293fdc0d56097fe2e [file] [log] [blame]
Garrett Tanzer29de7112022-12-06 21:26:321// Copyright 2022 The Chromium Authors
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Dominic Farolino7ba87bfa2022-12-14 15:59:015#include <type_traits>
6
7#include "base/test/gtest_util.h"
Garrett Tanzer29de7112022-12-06 21:26:328#include "content/browser/fenced_frame/fenced_frame_config.h"
Matt Menke53563fd2023-01-24 23:04:279#include "content/browser/fenced_frame/fenced_frame_reporter.h"
Garrett Tanzer29de7112022-12-06 21:26:3210#include "mojo/public/cpp/test_support/test_utils.h"
Matt Menke53563fd2023-01-24 23:04:2711#include "services/network/public/cpp/weak_wrapper_shared_url_loader_factory.h"
Garrett Tanzer29de7112022-12-06 21:26:3212#include "testing/gtest/include/gtest/gtest.h"
13#include "third_party/blink/public/common/fenced_frame/redacted_fenced_frame_config.h"
Dominic Farolino7ba87bfa2022-12-14 15:59:0114#include "third_party/blink/public/common/fenced_frame/redacted_fenced_frame_config_mojom_traits.h"
Garrett Tanzer29de7112022-12-06 21:26:3215#include "third_party/blink/public/mojom/fenced_frame/fenced_frame_config.mojom.h"
Qingxin Wu723775e2023-02-23 19:15:4816#include "url/origin.h"
Garrett Tanzer29de7112022-12-06 21:26:3217
18namespace content {
19
20using RedactedFencedFrameConfig = blink::FencedFrame::RedactedFencedFrameConfig;
21using RedactedFencedFrameProperties =
22 blink::FencedFrame::RedactedFencedFrameProperties;
23using Entity = content::FencedFrameEntity;
24
25// This macro creates the following test pattern:
26// * Redact a config.
27// * Check that the desired property was redacted as expected.
28// * Serialize and deserialize the redacted config into a copy (using mojom type
29// mappings implicitly).
30// * Check that the desired property was copied correctly.
31//
Liam Bradyd7e3e962023-01-05 20:39:4132// Template Arguments:
33// `ClassName`: `FencedFrameConfig` or `FencedFrameProperties`
34// Which base class to use for this test.
35// `RedactedClassName`: `RedactedFencedFrameConfig` or
36// `RedactedFencedFrameProperties`
37// The redacted version of `ClassName`.
38// `TestType`: The type of the value being tested.
39// `RedactedTestType`: The type of the redacted value being tested. Sometimes
40// the type of variable being stored in the non-redacted and
41// its redacted equivalent can differ.
42// `UnredactedToRedactedCompare`: The shape of the function that will compare
43// an unredacted config value to a redacted
44// config value.
45// `RedactedToRedactedCompare`: The shape of the function that will compare
46// two redacted config values.
47//
Garrett Tanzer29de7112022-12-06 21:26:3248// Arguments:
Liam Bradyd7e3e962023-01-05 20:39:4149// `config`: The FencedFrameConfig or FencedFrameProperties object being tested.
50// `property`: A pointer to the class's field to test (e.g. `mapped_url_`)
Garrett Tanzer29de7112022-12-06 21:26:3251// `entity`: The entity (kEmbedder or kContent) that the config should be
52// redacted for in the test.
53// `is_defined`: Whether we expect the property to have a defined value.
54// `is_opaque`: Whether we expect the property's defined value to be opaque.
55// `unredacted_redacted_equality_fn`: A comparator function that has the
56// function signature is_eq(`type`, Redacted`type`). A return value of
57// `true` means equal; `false` means not equal.
58// `redacted_redacted_equality_fn`: A comparator function that has the function
59// signature is_eq(Redacted`type`, Redacted`type`). A return value of `true`
60// means equal; `false` means not equal.
Liam Bradyd7e3e962023-01-05 20:39:4161template <typename ClassName,
62 typename RedactedClassName,
63 typename TestType,
64 typename RedactedTestType,
65 typename UnredactedToRedactedCompare,
66 typename RedactedToRedactedCompare>
67void TestPropertyForEntityIsDefinedIsOpaque(
68 ClassName config,
69 absl::optional<FencedFrameProperty<TestType>> ClassName::*property,
70 absl::optional<
71 blink::FencedFrame::RedactedFencedFrameProperty<RedactedTestType>>
72 RedactedClassName::*redacted_property,
73 Entity entity,
74 bool is_defined,
75 bool is_opaque,
76 UnredactedToRedactedCompare unredacted_redacted_equality_fn,
77 RedactedToRedactedCompare redacted_redacted_equality_fn) {
78 // Redact the config.
79 RedactedClassName redacted_config = config.RedactFor(entity);
80 if (is_defined) {
81 // If the config has a value for the property, check that the redacted
82 // version does too.
83 ASSERT_TRUE((redacted_config.*redacted_property).has_value());
84 if (is_opaque) {
85 // If the value should be opaque, check that it is.
86 ASSERT_FALSE((redacted_config.*redacted_property)
87 ->potentially_opaque_value.has_value());
88 } else {
89 // If the value should be transparent, check that it is, and that the
90 // value was copied correctly.
91 ASSERT_TRUE((redacted_config.*redacted_property)
92 ->potentially_opaque_value.has_value());
93 ASSERT_TRUE(unredacted_redacted_equality_fn(
94 (config.*property)->GetValueIgnoringVisibility(),
95 (redacted_config.*redacted_property)
96 ->potentially_opaque_value.value()));
97 }
98 } else {
99 // If the config doesn't have a value for the property, check that the
100 // redacted version also doesn't.
101 ASSERT_FALSE((redacted_config.*redacted_property).has_value());
Garrett Tanzer29de7112022-12-06 21:26:32102 }
103
Liam Bradyd7e3e962023-01-05 20:39:41104 // Copy the config using mojom serialization/deserialization.
105 RedactedClassName copy;
106
107 // deduce the mojo class being used
108 using MojoClassName =
109 std::conditional_t<std::is_same<FencedFrameConfig, ClassName>::value,
110 blink::mojom::FencedFrameConfig,
111 blink::mojom::FencedFrameProperties>;
112
113 mojo::test::SerializeAndDeserialize<MojoClassName>(redacted_config, copy);
114 // Check that the value for the property in the copy is the same as the
115 // original.
116 if (is_defined) {
117 ASSERT_TRUE((copy.*redacted_property).has_value());
118 if (is_opaque) {
119 ASSERT_FALSE(
120 (copy.*redacted_property)->potentially_opaque_value.has_value());
121 } else {
122 ASSERT_TRUE(
123 (copy.*redacted_property)->potentially_opaque_value.has_value());
124 ASSERT_TRUE(redacted_redacted_equality_fn(
125 (redacted_config.*redacted_property)
126 ->potentially_opaque_value.value(),
127 (copy.*redacted_property)->potentially_opaque_value.value()));
128 }
129 } else {
130 ASSERT_FALSE((copy.*redacted_property).has_value());
131 }
132}
133
134// This helper function generates several test cases for a given property:
Garrett Tanzer29de7112022-12-06 21:26:32135// * An empty config (`property` has no value)
136// * A config with `dummy_value` for `property`, opaque to embedder and
137// transparent to content.
138// * A config with `dummy_value` for `property`, transparent to embedder and
139// opaque to content.
140//
Liam Bradyd7e3e962023-01-05 20:39:41141// Template Arguments:
142// `ClassName`: `FencedFrameConfig` or `FencedFrameProperties`
143// Which base class to use for this test.
144// `RedactedClassName`: `RedactedFencedFrameConfig` or
145// `RedactedFencedFrameProperties`
146// The redacted version of `ClassName`.
147// `TestType`: The type of the value being tested.
148// `RedactedTestType`: The type of the redacted value being tested. Sometimes
149// the type of variable being stored in the non-redacted and
150// its redacted equivalent can differ.
151// `UnredactedToRedactedCompare`: The shape of the function that will compare
152// an unredacted config value to a redacted
153// config value.
154// `RedactedToRedactedCompare`: The shape of the function that will compare
155// two redacted config values.
156//
Garrett Tanzer29de7112022-12-06 21:26:32157// Arguments:
Liam Bradyd7e3e962023-01-05 20:39:41158// `property`: A pointer to the name of the field to test (e.g. `mapped_url_`)
159// `redacted_property`: The redacted equivalent of the `property` field.
Garrett Tanzer29de7112022-12-06 21:26:32160// `dummy_value`: A value that can be emplaced into `property`.
161// `unredacted_redacted_equality_fn`: A comparator function that has the
162// function signature is_eq(`type`, Redacted`type`). A return value of
163// `true` means equal; `false` means not equal.
164// `redacted_redacted_equality_fn`: A comparator function that has the function
165// signature is_eq(Redacted`type`, Redacted`type`). A return value of `true`
166// means equal; `false` means not equal.
Liam Bradyd7e3e962023-01-05 20:39:41167template <typename ClassName,
168 typename RedactedClassName,
169 typename TestType,
170 typename RedactedTestType,
171 typename UnredactedToRedactedCompare,
172 typename RedactedToRedactedCompare>
173void TestProperty(
174 absl::optional<FencedFrameProperty<TestType>> ClassName::*property,
175 absl::optional<
176 blink::FencedFrame::RedactedFencedFrameProperty<RedactedTestType>>
177 RedactedClassName::*redacted_property,
178 TestType dummy_value,
179 UnredactedToRedactedCompare unredacted_redacted_equality_fn,
180 RedactedToRedactedCompare redacted_redacted_equality_fn) {
181 // Test an empty config
182 ClassName config;
183 if constexpr (std::is_same<FencedFrameConfig, ClassName>::value) {
184 config.urn_uuid_.emplace(GenerateUrnUuid());
Garrett Tanzer29de7112022-12-06 21:26:32185 }
Liam Bradyd7e3e962023-01-05 20:39:41186 TestPropertyForEntityIsDefinedIsOpaque<ClassName, RedactedClassName, TestType,
187 RedactedTestType>(
188 config, property, redacted_property, Entity::kEmbedder, false, false,
189 unredacted_redacted_equality_fn, redacted_redacted_equality_fn);
190 TestPropertyForEntityIsDefinedIsOpaque<ClassName, RedactedClassName, TestType,
191 RedactedTestType>(
192 config, property, redacted_property, Entity::kContent, false, false,
193 unredacted_redacted_equality_fn, redacted_redacted_equality_fn);
194
195 // Test when `property` is opaque to embedder and transparent to content.
196 (config.*property)
197 .emplace(dummy_value, VisibilityToEmbedder::kOpaque,
198 VisibilityToContent::kTransparent);
199 TestPropertyForEntityIsDefinedIsOpaque<ClassName, RedactedClassName, TestType,
200 RedactedTestType>(
201 config, property, redacted_property, Entity::kEmbedder, true, true,
202 unredacted_redacted_equality_fn, redacted_redacted_equality_fn);
203 TestPropertyForEntityIsDefinedIsOpaque<ClassName, RedactedClassName, TestType,
204 RedactedTestType>(
205 config, property, redacted_property, Entity::kContent, true, false,
206 unredacted_redacted_equality_fn, redacted_redacted_equality_fn);
207
208 // Test when `property` is transparent to embedder and opaque to content.
209 (config.*property)
210 .emplace(dummy_value, VisibilityToEmbedder::kTransparent,
211 VisibilityToContent::kOpaque);
212 TestPropertyForEntityIsDefinedIsOpaque<ClassName, RedactedClassName, TestType,
213 RedactedTestType>(
214 config, property, redacted_property, Entity::kEmbedder, true, false,
215 unredacted_redacted_equality_fn, redacted_redacted_equality_fn);
216 TestPropertyForEntityIsDefinedIsOpaque<ClassName, RedactedClassName, TestType,
217 RedactedTestType>(
218 config, property, redacted_property, Entity::kContent, true, true,
219 unredacted_redacted_equality_fn, redacted_redacted_equality_fn);
220}
Garrett Tanzer29de7112022-12-06 21:26:32221
222// Compare equality of two lists of nested configs.
223// Only compares the `mapped_url` field for convenience. (We don't need an
224// equality operator for configs outside of tests, so it would be wasteful to
225// declare it as default in the class declaration.)
226#define NESTED_CONFIG_EQ_FN(type1, accessor1, type2, accessor2) \
227 [](const std::vector<type1>& a, const std::vector<type2>& b) { \
228 if (a.size() != b.size()) { \
229 return false; \
230 } \
231 for (size_t i = 0; i < a.size(); ++i) { \
232 if (!a[i].mapped_url_.has_value() && !b[i].mapped_url_.has_value()) { \
233 continue; \
234 } else if (a[i].mapped_url_.has_value() && \
235 b[i].mapped_url_.has_value()) { \
236 if (a[i].mapped_url_->accessor1 == b[i].mapped_url_->accessor2) { \
237 continue; \
238 } \
239 return false; \
240 } else { \
241 return false; \
242 } \
243 } \
244 return true; \
245 }
246
247// Compare equality of two lists of (urn, nested config) pairs.
248// Only compares the `mapped_url` field for convenience.
249#define NESTED_URN_CONFIG_PAIR_EQ_FN(type1, accessor1, type2, accessor2) \
250 [](const std::vector<std::pair<GURL, type1>>& a, \
251 const std::vector<std::pair<GURL, type2>>& b) { \
252 if (a.size() != b.size()) { \
253 return false; \
254 } \
255 for (size_t i = 0; i < a.size(); ++i) { \
256 if (a[i].first != b[i].first) { \
257 return false; \
258 } \
259 if (!a[i].second.mapped_url_.has_value() && \
260 !b[i].second.mapped_url_.has_value()) { \
261 continue; \
262 } else if (a[i].second.mapped_url_.has_value() && \
263 b[i].second.mapped_url_.has_value()) { \
264 if (a[i].second.mapped_url_->accessor1 == \
265 b[i].second.mapped_url_->accessor2) { \
266 continue; \
267 } \
268 return false; \
269 } else { \
270 return false; \
271 } \
272 } \
273 return true; \
274 }
275
Dominic Farolino7ba87bfa2022-12-14 15:59:01276TEST(FencedFrameConfigMojomTraitsTest, ConfigMojomTraitsInternalUrnTest) {
277 GURL test_url("test_url");
278
279 struct TestCase {
280 GURL urn;
281 bool pass = false;
282 } test_cases[] = {
283 {GURL(), false},
284 {GURL("https://example.com"), false},
285 {GURL("data:text/html<h1>MyWebsite"), false},
286 {GURL("urn:abcd:f81d4fae-7dec-11d0-a765-00a0c91e6bf6"), false},
287 {GURL("urn:uuid:foo"), false},
288 {GURL("urn:uuid:f81d4faea7deca11d0aa765a00a0c91e6bf6"), false},
289 {GURL("urn:uuid:f81d4fae-7dec-11d0-a765-00a0c91e6bf6"), true},
290 {GenerateUrnUuid(), true},
291 };
292
293 for (const TestCase& test_case : test_cases) {
294 FencedFrameConfig browser_config(test_case.urn, test_url);
295 RedactedFencedFrameConfig input_config =
296 browser_config.RedactFor(FencedFrameEntity::kEmbedder);
297 RedactedFencedFrameConfig output_config;
298
299 if (test_case.pass) {
300 ASSERT_TRUE(
301 mojo::test::SerializeAndDeserialize<blink::mojom::FencedFrameConfig>(
302 input_config, output_config));
303 } else {
304 ASSERT_FALSE(
305 mojo::test::SerializeAndDeserialize<blink::mojom::FencedFrameConfig>(
306 input_config, output_config));
307 }
308 }
309}
310
Garrett Tanzerd7530762023-01-20 02:39:31311TEST(FencedFrameConfigMojomTraitsTest, ConfigMojomTraitsModeTest) {
312 std::vector<blink::FencedFrame::DeprecatedFencedFrameMode> modes = {
313 blink::FencedFrame::DeprecatedFencedFrameMode::kDefault,
314 blink::FencedFrame::DeprecatedFencedFrameMode::kOpaqueAds,
315 };
316 std::vector<FencedFrameEntity> entities = {
317 FencedFrameEntity::kEmbedder,
318 FencedFrameEntity::kContent,
319 };
320 GURL test_url("test_url");
321 GURL test_urn = GenerateUrnUuid();
322 for (blink::FencedFrame::DeprecatedFencedFrameMode& mode : modes) {
323 FencedFrameConfig browser_config(test_urn, test_url);
324 browser_config.mode_ = mode;
325 FencedFrameProperties browser_properties(browser_config);
326 for (FencedFrameEntity& entity : entities) {
327 RedactedFencedFrameConfig input_config = browser_config.RedactFor(entity);
328 ASSERT_TRUE(browser_config.mode_ == input_config.mode());
329
330 RedactedFencedFrameConfig output_config;
331 mojo::test::SerializeAndDeserialize<blink::mojom::FencedFrameConfig>(
332 input_config, output_config);
333 ASSERT_TRUE(input_config.mode() == output_config.mode());
334
335 RedactedFencedFrameProperties input_properties =
336 browser_properties.RedactFor(entity);
337 ASSERT_TRUE(browser_properties.mode_ == input_properties.mode());
338
339 RedactedFencedFrameProperties output_properties;
340 mojo::test::SerializeAndDeserialize<blink::mojom::FencedFrameProperties>(
341 input_properties, output_properties);
342 ASSERT_TRUE(input_properties.mode() == output_properties.mode());
343 }
344 }
345}
346
Dominic Farolino7ba87bfa2022-12-14 15:59:01347TEST(FencedFrameConfigMojomTraitsTest, ConfigMojomTraitsNullInternalUrnTest) {
348 FencedFrameConfig browser_config;
349 RedactedFencedFrameConfig input_config =
350 browser_config.RedactFor(FencedFrameEntity::kEmbedder);
351 RedactedFencedFrameConfig output_config;
Ian Vollick24b593e2023-02-14 15:29:17352 EXPECT_DEATH_IF_SUPPORTED(
Dominic Farolino7ba87bfa2022-12-14 15:59:01353 mojo::test::SerializeAndDeserialize<blink::mojom::FencedFrameConfig>(
354 input_config, output_config),
355 "");
356}
357
Garrett Tanzer29de7112022-12-06 21:26:32358TEST(FencedFrameConfigMojomTraitsTest, ConfigMojomTraitsTest) {
359 GURL test_url("test_url");
360
Dominic Farolino7ba87bfa2022-12-14 15:59:01361 // See the above tests for `urn`.
362
Garrett Tanzer29de7112022-12-06 21:26:32363 // Test `mapped_url`.
364 {
365 auto eq_fn = [](const GURL& a, const GURL& b) { return a == b; };
Liam Bradyd7e3e962023-01-05 20:39:41366 TestProperty(&FencedFrameConfig::mapped_url_,
367 &RedactedFencedFrameConfig::mapped_url_, test_url, eq_fn,
368 eq_fn);
369 TestProperty(&FencedFrameProperties::mapped_url_,
370 &RedactedFencedFrameProperties::mapped_url_, test_url, eq_fn,
371 eq_fn);
Garrett Tanzer29de7112022-12-06 21:26:32372 }
373
Garrett Tanzer6d6e2b972022-12-13 19:47:19374 // Test `container_size` and `content_size`.
375 {
376 gfx::Size test_size(100, 200);
377 auto eq_fn = [](const gfx::Size& a, const gfx::Size& b) { return a == b; };
378
Liam Bradyd7e3e962023-01-05 20:39:41379 TestProperty(&FencedFrameConfig::container_size_,
380 &RedactedFencedFrameConfig::container_size_, test_size, eq_fn,
381 eq_fn);
382 TestProperty(&FencedFrameProperties::container_size_,
383 &RedactedFencedFrameProperties::container_size_, test_size,
384 eq_fn, eq_fn);
Garrett Tanzer6d6e2b972022-12-13 19:47:19385
Liam Bradyd7e3e962023-01-05 20:39:41386 TestProperty(&FencedFrameConfig::content_size_,
387 &RedactedFencedFrameConfig::content_size_, test_size, eq_fn,
388 eq_fn);
389 TestProperty(&FencedFrameProperties::content_size_,
390 &RedactedFencedFrameProperties::content_size_, test_size,
391 eq_fn, eq_fn);
Garrett Tanzer6d6e2b972022-12-13 19:47:19392 }
393
394 // Test `deprecated_should_freeze_initial_size`.
395 {
396 auto eq_fn = [](const bool a, const bool b) { return a == b; };
Liam Bradyd7e3e962023-01-05 20:39:41397 TestProperty(
398 &FencedFrameConfig::deprecated_should_freeze_initial_size_,
399 &RedactedFencedFrameConfig::deprecated_should_freeze_initial_size_,
400 true, eq_fn, eq_fn);
401 TestProperty(
402 &FencedFrameProperties::deprecated_should_freeze_initial_size_,
403 &RedactedFencedFrameProperties::deprecated_should_freeze_initial_size_,
404 true, eq_fn, eq_fn);
405
406 TestProperty(
407 &FencedFrameConfig::deprecated_should_freeze_initial_size_,
408 &RedactedFencedFrameConfig::deprecated_should_freeze_initial_size_,
409 false, eq_fn, eq_fn);
410 TestProperty(
411 &FencedFrameProperties::deprecated_should_freeze_initial_size_,
412 &RedactedFencedFrameProperties::deprecated_should_freeze_initial_size_,
413 false, eq_fn, eq_fn);
Garrett Tanzer6d6e2b972022-12-13 19:47:19414 }
415
Garrett Tanzer29de7112022-12-06 21:26:32416 // Test `ad_auction_data`.
417 {
418 AdAuctionData test_ad_auction_data = {url::Origin::Create(test_url),
419 std::string("test_name")};
420 auto eq_fn = [](const AdAuctionData& a, const AdAuctionData& b) {
421 return a.interest_group_owner == b.interest_group_owner &&
422 a.interest_group_name == b.interest_group_name;
423 };
Liam Bradyd7e3e962023-01-05 20:39:41424
425 TestProperty(&FencedFrameConfig::ad_auction_data_,
426 &RedactedFencedFrameConfig::ad_auction_data_,
427 test_ad_auction_data, eq_fn, eq_fn);
428 TestProperty(&FencedFrameProperties::ad_auction_data_,
429 &RedactedFencedFrameProperties::ad_auction_data_,
430 test_ad_auction_data, eq_fn, eq_fn);
Garrett Tanzer29de7112022-12-06 21:26:32431 }
432
433 // Test `nested_configs`.
434 {
Dominic Farolino7ba87bfa2022-12-14 15:59:01435 FencedFrameConfig test_nested_config(GenerateUrnUuid(), test_url);
Garrett Tanzer29de7112022-12-06 21:26:32436
437 {
438 std::vector<FencedFrameConfig> test_nested_configs = {test_nested_config};
439 auto unredacted_redacted_eq_fn = NESTED_CONFIG_EQ_FN(
440 FencedFrameConfig, GetValueForEntity(Entity::kEmbedder),
441 RedactedFencedFrameConfig, potentially_opaque_value);
442 auto redacted_redacted_eq_fn = NESTED_CONFIG_EQ_FN(
443 RedactedFencedFrameConfig, potentially_opaque_value,
444 RedactedFencedFrameConfig, potentially_opaque_value);
Liam Bradyd7e3e962023-01-05 20:39:41445 TestProperty(&FencedFrameConfig::nested_configs_,
446 &RedactedFencedFrameConfig::nested_configs_,
447 test_nested_configs, unredacted_redacted_eq_fn,
448 redacted_redacted_eq_fn);
Garrett Tanzer29de7112022-12-06 21:26:32449 }
450
451 {
452 GURL test_urn("urn:uuid:abcd");
453 std::vector<std::pair<GURL, FencedFrameConfig>>
454 test_nested_urn_config_pairs = {{test_urn, test_nested_config}};
455 auto unredacted_redacted_eq_fn = NESTED_URN_CONFIG_PAIR_EQ_FN(
456 FencedFrameConfig, GetValueForEntity(Entity::kEmbedder),
457 RedactedFencedFrameConfig, potentially_opaque_value);
458 auto redacted_redacted_eq_fn = NESTED_URN_CONFIG_PAIR_EQ_FN(
459 RedactedFencedFrameConfig, potentially_opaque_value,
460 RedactedFencedFrameConfig, potentially_opaque_value);
Liam Bradyd7e3e962023-01-05 20:39:41461 TestProperty(&FencedFrameProperties::nested_urn_config_pairs_,
462 &RedactedFencedFrameProperties::nested_urn_config_pairs_,
463 test_nested_urn_config_pairs, unredacted_redacted_eq_fn,
464 redacted_redacted_eq_fn);
Garrett Tanzer29de7112022-12-06 21:26:32465 }
466 }
467
Liam Bradyd7e3e962023-01-05 20:39:41468 // Test `shared_storage_budget_metadata`.
Garrett Tanzer29de7112022-12-06 21:26:32469 {
470 SharedStorageBudgetMetadata test_shared_storage_budget_metadata = {
Camillia Smith Barnescc4801b2023-04-04 05:09:24471 url::Origin::Create(test_url), 0.5, /*top_navigated=*/true};
Garrett Tanzer29de7112022-12-06 21:26:32472 auto eq_fn = [](const SharedStorageBudgetMetadata& a,
473 const SharedStorageBudgetMetadata& b) {
Camillia Smith Barnesddaf5b12023-01-24 00:06:32474 return a.origin == b.origin && a.budget_to_charge == b.budget_to_charge &&
Camillia Smith Barnescc4801b2023-04-04 05:09:24475 a.top_navigated == b.top_navigated;
Garrett Tanzer29de7112022-12-06 21:26:32476 };
Liam Bradyd7e3e962023-01-05 20:39:41477 TestProperty(&FencedFrameConfig::shared_storage_budget_metadata_,
478 &RedactedFencedFrameConfig::shared_storage_budget_metadata_,
479 test_shared_storage_budget_metadata, eq_fn, eq_fn);
Garrett Tanzer29de7112022-12-06 21:26:32480
481 auto pointer_value_eq_fn =
482 [](const raw_ptr<const SharedStorageBudgetMetadata>& a,
483 const SharedStorageBudgetMetadata& b) {
484 return a->origin == b.origin &&
Camillia Smith Barnesddaf5b12023-01-24 00:06:32485 a->budget_to_charge == b.budget_to_charge &&
Camillia Smith Barnescc4801b2023-04-04 05:09:24486 a->top_navigated == b.top_navigated;
Garrett Tanzer29de7112022-12-06 21:26:32487 };
Liam Bradyd7e3e962023-01-05 20:39:41488 TestProperty(
489 &FencedFrameProperties::shared_storage_budget_metadata_,
490 &RedactedFencedFrameProperties::shared_storage_budget_metadata_,
491 static_cast<base::raw_ptr<const SharedStorageBudgetMetadata>>(
492 &test_shared_storage_budget_metadata),
493 pointer_value_eq_fn, eq_fn);
Garrett Tanzer29de7112022-12-06 21:26:32494 }
Matt Menke53563fd2023-01-24 23:04:27495}
Garrett Tanzer29de7112022-12-06 21:26:32496
Matt Menke53563fd2023-01-24 23:04:27497// Test `has_fenced_frame_reporting`, which only appears in
498// FencedFrameProperties, and does not use the redacted mechanism used by other
499// fields.
500TEST(FencedFrameConfigMojomTraitsTest, PropertiesHasFencedFrameReportingTest) {
501 FencedFrameProperties properties;
502 RedactedFencedFrameProperties input_properties =
503 properties.RedactFor(FencedFrameEntity::kEmbedder);
504 EXPECT_FALSE(input_properties.has_fenced_frame_reporting());
505 RedactedFencedFrameProperties output_properties;
506 mojo::test::SerializeAndDeserialize<blink::mojom::FencedFrameProperties>(
507 input_properties, output_properties);
508 EXPECT_FALSE(output_properties.has_fenced_frame_reporting());
509
510 // Create a reporting service with a dummy SharedURLLoaderFactory.
511 properties.fenced_frame_reporter_ = FencedFrameReporter::CreateForFledge(
Nan Lin7e115aba2023-02-09 19:50:45512 base::MakeRefCounted<network::WeakWrapperSharedURLLoaderFactory>(nullptr),
Nan Lin284f6fa2023-02-24 18:40:51513 /*attribution_manager=*/nullptr,
Qingxin Wu723775e2023-02-23 19:15:48514 /*direct_seller_is_seller=*/false,
515 /*private_aggregation_manager=*/nullptr,
516 /*main_frame_origin=*/url::Origin(),
517 /*winner_origin=*/url::Origin());
Matt Menke53563fd2023-01-24 23:04:27518 input_properties = properties.RedactFor(FencedFrameEntity::kEmbedder);
519 EXPECT_TRUE(input_properties.has_fenced_frame_reporting());
520 mojo::test::SerializeAndDeserialize<blink::mojom::FencedFrameProperties>(
521 input_properties, output_properties);
522 EXPECT_TRUE(output_properties.has_fenced_frame_reporting());
Garrett Tanzer29de7112022-12-06 21:26:32523}
524
525} // namespace content