Skip to content

Commit

Permalink
FLEDGE: Add mapping from ad to size groups to joinAdInterestGroup().
Browse files Browse the repository at this point in the history
In https://crrev.com/c/4167800, these mappings are added:
1. size groups --> ad size names
2. ad size names --> blink::AdSize

This CL adds the mapping: ad --> size group

Note:
1. FindMatchingAd is updated. Two ads are considered matching if:
  a. They have the same url, and neither has any size specified.
  b. They have the same url, and both have the same size specified.

2. Updated IDL, serialize/deserialize implementations, copy from IDL
   functions and InterestGroupAd mojom/mojom traits.

3. Added the builder pattern setters for ad size and size groups.
4. Added unit tests and browser tests.
5. The next CL will implement the macro substitution of sizes into
   the mapped url in fenced frame mapping, when auction is completed.

See Turtledove issue: WICG/turtledove#312
See Turtledove PR: WICG/turtledove#417

Bug: http://b/239866637

Related CL on adding sizes to joinAdInterestGroup():
https://crrev.com/c/4167800

Decouple nested blink::InterestGroup::Size:
https://crrev.com/c/4296777

Change-Id: I224c7285234e72ff5a7633b15c5ba256e43ef143
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4321037
Reviewed-by: Russ Hamilton <behamilton@google.com>
Reviewed-by: Liam Brady <lbrady@google.com>
Reviewed-by: Dominic Farolino <dom@chromium.org>
Commit-Queue: Xiaochen Zhou <xiaochenzh@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1118329}
  • Loading branch information
xiaochen-z authored and Chromium LUCI CQ committed Mar 16, 2023
1 parent fd3287d commit 2ff6cd7
Show file tree
Hide file tree
Showing 22 changed files with 818 additions and 89 deletions.
11 changes: 11 additions & 0 deletions content/browser/interest_group/ad_auction_service_impl_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1133,9 +1133,11 @@ TEST_F(AdAuctionServiceImplTest, UpdateAllUpdatableFields) {
"%s/interest_group/new_trusted_bidding_signals_url.json",
"trustedBiddingSignalsKeys": ["new_key"],
"ads": [{"renderUrl": "%s/new_ad_render_url",
"sizeGroup": "group_new",
"metadata": {"new_a": "b"}
}],
"adComponents": [{"renderUrl": "https://example.com/component_url",
"sizeGroup": "group_new",
"metadata": {"new_c": "d"}
}],
"adSizes": {"size_new": {"width": "300px", "height": "150px"}},
Expand All @@ -1162,8 +1164,15 @@ TEST_F(AdAuctionServiceImplTest, UpdateAllUpdatableFields) {
interest_group.ads.emplace();
blink::InterestGroup::Ad ad(
/*render_url=*/GURL("https://example.com/render"),
/*size_group=*/"group_old",
/*metadata=*/"{\"ad\":\"metadata\",\"here\":[1,2,3]}");
interest_group.ads->emplace_back(std::move(ad));
interest_group.ad_components.emplace();
blink::InterestGroup::Ad ad_component(
/*render_url=*/GURL("https://example.com/render"),
/*size_group=*/"group_old",
/*metadata=*/"{\"ad\":\"metadata\",\"here\":[1,2,3]}");
interest_group.ad_components->emplace_back(std::move(ad_component));
interest_group.ad_sizes.emplace();
interest_group.ad_sizes->emplace(
"size_old", blink::AdSize(640, blink::AdSize::LengthUnit::kPixels, 480,
Expand Down Expand Up @@ -1227,11 +1236,13 @@ TEST_F(AdAuctionServiceImplTest, UpdateAllUpdatableFields) {
ASSERT_EQ(group.ads->size(), 1u);
EXPECT_EQ(group.ads.value()[0].render_url.spec(),
base::StringPrintf("%s/new_ad_render_url", kOriginStringA));
EXPECT_EQ(group.ads.value()[0].size_group, "group_new");
EXPECT_EQ(group.ads.value()[0].metadata, "{\"new_a\":\"b\"}");
ASSERT_TRUE(group.ad_components.has_value());
ASSERT_EQ(group.ad_components->size(), 1u);
EXPECT_EQ(group.ad_components.value()[0].render_url.spec(),
"https://example.com/component_url");
EXPECT_EQ(group.ad_components.value()[0].size_group, "group_new");
EXPECT_EQ(group.ad_components.value()[0].metadata, "{\"new_c\":\"d\"}");
ASSERT_TRUE(group.ad_sizes.has_value());
ASSERT_EQ(group.ad_sizes->size(), 1u);
Expand Down
137 changes: 104 additions & 33 deletions content/browser/interest_group/auction_runner_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7869,108 +7869,180 @@ TEST_F(AuctionRunnerTest, BadBid) {
const struct TestCase {
const char* expected_error_message;
double bid;
GURL render_url;
absl::optional<std::vector<blink::AdDescriptor>> ad_component_urls;
blink::AdDescriptor ad_descriptor;
absl::optional<std::vector<blink::AdDescriptor>> ad_component_descriptors;
base::TimeDelta duration;
} kTestCases[] = {
// Bids that aren't positive integers.
{
"Invalid bid value",
-10,
GURL("https://ad1.com"),
blink::AdDescriptor(GURL("https://ad1.com")),
absl::nullopt,
base::TimeDelta(),
},
{
"Invalid bid value",
0,
GURL("https://ad1.com"),
blink::AdDescriptor(GURL("https://ad1.com")),
absl::nullopt,
base::TimeDelta(),
},
{
"Invalid bid value",
std::numeric_limits<double>::infinity(),
GURL("https://ad1.com"),
blink::AdDescriptor(GURL("https://ad1.com")),
absl::nullopt,
base::TimeDelta(),
},
{
"Invalid bid value",
std::numeric_limits<double>::quiet_NaN(),
GURL("https://ad1.com"),
blink::AdDescriptor(GURL("https://ad1.com")),
absl::nullopt,
base::TimeDelta(),
},

// Invalid render URL.
{
"Bid render URL must be a valid ad URL",
"Bid render ad must have a valid URL and size (if specified)",
1,
GURL(":"),
blink::AdDescriptor(GURL(":")),
absl::nullopt,
base::TimeDelta(),
},

// Non-HTTPS render URLs.
{
"Bid render URL must be a valid ad URL",
"Bid render ad must have a valid URL and size (if specified)",
1,
GURL("data:,foo"),
blink::AdDescriptor(GURL("data:,foo")),
absl::nullopt,
base::TimeDelta(),
},
{
"Bid render URL must be a valid ad URL",
"Bid render ad must have a valid URL and size (if specified)",
1,
GURL("http://ad1.com"),
blink::AdDescriptor(GURL("http://ad1.com")),
absl::nullopt,
base::TimeDelta(),
},

// HTTPS render URL that's not in the list of allowed renderUrls.
{
"Bid render URL must be a valid ad URL",
"Bid render ad must have a valid URL and size (if specified)",
1,
GURL("https://ad2.com"),
blink::AdDescriptor(GURL("https://ad2.com")),
absl::nullopt,
base::TimeDelta(),
},

// HTTPS render URL with an invalid size value.
{
"Bid render ad must have a valid URL and size (if specified)",
1,
blink::AdDescriptor(
GURL("https://ad1.com"),
blink::AdSize(0, blink::AdSize::LengthUnit::kPixels, 100,
blink::AdSize::LengthUnit::kPixels)),
absl::nullopt,
base::TimeDelta(),
},

// HTTPS render URL with an invalid size unit.
{
"Bid render ad must have a valid URL and size (if specified)",
1,
blink::AdDescriptor(
GURL("https://ad1.com"),
blink::AdSize(100, blink::AdSize::LengthUnit::kInvalid, 100,
blink::AdSize::LengthUnit::kPixels)),
absl::nullopt,
base::TimeDelta(),
},

// HTTPS render URL with a size specification that does not match any
// allowed ad descriptors.
{
"Bid render ad must have a valid URL and size (if specified)",
1,
blink::AdDescriptor(
GURL("https://ad1.com"),
blink::AdSize(100, blink::AdSize::LengthUnit::kPixels, 100,
blink::AdSize::LengthUnit::kPixels)),
absl::nullopt,
base::TimeDelta(),
},

// Invalid component URL.
{
"Bid ad components URL must match a valid ad component URL",
"Bid ad component must have a valid URL and size (if specified)",
1,
GURL("https://ad1.com"),
blink::AdDescriptor(GURL("https://ad1.com")),
std::vector<blink::AdDescriptor>{blink::AdDescriptor(GURL(":"))},
base::TimeDelta(),
},

// HTTPS component URL that's not in the list of allowed ad component
// URLs.
{
"Bid ad components URL must match a valid ad component URL",
"Bid ad component must have a valid URL and size (if specified)",
1,
GURL("https://ad1.com"),
blink::AdDescriptor(GURL("https://ad1.com")),
std::vector<blink::AdDescriptor>{
blink::AdDescriptor(GURL("https://ad2.com-component1.com"))},
base::TimeDelta(),
},
{
"Bid ad components URL must match a valid ad component URL",
"Bid ad component must have a valid URL and size (if specified)",
1,
GURL("https://ad1.com"),
blink::AdDescriptor(GURL("https://ad1.com")),
std::vector<blink::AdDescriptor>{
blink::AdDescriptor(GURL("https://ad1.com-component1.com")),
blink::AdDescriptor(GURL("https://ad2.com-component1.com"))},
base::TimeDelta(),
},

// HTTPS component URL with an invalid size value.
{
"Bid ad component must have a valid URL and size (if specified)",
1,
blink::AdDescriptor(GURL("https://ad1.com")),
std::vector<blink::AdDescriptor>{blink::AdDescriptor(
GURL("https://ad1.com-component1.com"),
blink::AdSize(0, blink::AdSize::LengthUnit::kPixels, 100,
blink::AdSize::LengthUnit::kPixels))},
base::TimeDelta(),
},
// HTTPS component URL with an invalid size unit.
{
"Bid ad component must have a valid URL and size (if specified)",
1,
blink::AdDescriptor(GURL("https://ad1.com")),
std::vector<blink::AdDescriptor>{blink::AdDescriptor(
GURL("https://ad1.com-component1.com"),
blink::AdSize(100, blink::AdSize::LengthUnit::kInvalid, 100,
blink::AdSize::LengthUnit::kPixels))},
base::TimeDelta(),
},
// HTTPS component URL with a size specification that does not match any
// allowed ad descriptors.
{
"Bid ad component must have a valid URL and size (if specified)",
1,
blink::AdDescriptor(GURL("https://ad1.com")),
std::vector<blink::AdDescriptor>{blink::AdDescriptor(
GURL("https://ad1.com-component1.com"),
blink::AdSize(100, blink::AdSize::LengthUnit::kPixels, 100,
blink::AdSize::LengthUnit::kPixels))},
base::TimeDelta(),
},

// Negative time.
{
"Invalid bid duration",
1,
GURL("https://ad2.com"),
blink::AdDescriptor(GURL("https://ad2.com")),
absl::nullopt,
base::Milliseconds(-1),
},
Expand All @@ -7989,8 +8061,8 @@ TEST_F(AuctionRunnerTest, BadBid) {
ASSERT_TRUE(bidder2_worklet);

bidder1_worklet->InvokeGenerateBidCallback(
test_case.bid, blink::AdDescriptor(test_case.render_url),
/*mojo_kanon_bid=*/nullptr, test_case.ad_component_urls,
test_case.bid, test_case.ad_descriptor,
/*mojo_kanon_bid=*/nullptr, test_case.ad_component_descriptors,
test_case.duration);
// Bidder 2 doesn't bid.
bidder2_worklet->InvokeGenerateBidCallback(/*bid=*/absl::nullopt);
Expand Down Expand Up @@ -13820,7 +13892,7 @@ TEST_P(AuctionRunnerKAnonTest, MojoValidation) {
const struct TestCase {
std::set<auction_worklet::mojom::KAnonymityBidMode> run_in_modes;
const char* expected_error_message;
GURL render_url;
blink::AdDescriptor ad_descriptor;
auction_worklet::mojom::BidderWorkletKAnonEnforcedBidPtr mojo_bid;
bool expect_winner;
} kTestCases[] = {
Expand All @@ -13829,7 +13901,7 @@ TEST_P(AuctionRunnerKAnonTest, MojoValidation) {
{{auction_worklet::mojom::KAnonymityBidMode::kEnforce,
auction_worklet::mojom::KAnonymityBidMode::kSimulate},
"Received different k-anon bid when unenforced bid already k-anon",
GURL("https://ad1.com"),
blink::AdDescriptor(GURL("https://ad1.com")),
auction_worklet::mojom::BidderWorkletKAnonEnforcedBid::NewBid(
auction_worklet::mojom::BidderWorkletBid::New(
"ad", 5.0, /*ad_cost=*/absl::nullopt,
Expand All @@ -13839,8 +13911,8 @@ TEST_P(AuctionRunnerKAnonTest, MojoValidation) {
// A non-k-anon bid as k-anon one. Enforced, so auction fails.
{
{auction_worklet::mojom::KAnonymityBidMode::kEnforce},
"Bid render URL must be a valid ad URL",
GURL("https://ad2.com"),
"Bid render ad must have a valid URL and size (if specified)",
blink::AdDescriptor(GURL("https://ad2.com")),
auction_worklet::mojom::BidderWorkletKAnonEnforcedBid::NewBid(
auction_worklet::mojom::BidderWorkletBid::New(
"ad", 5.0, /*ad_cost=*/absl::nullopt,
Expand All @@ -13851,8 +13923,8 @@ TEST_P(AuctionRunnerKAnonTest, MojoValidation) {
// A non-k-anon bid as k-anon one. Simulate, so auction succeeds.
{
{auction_worklet::mojom::KAnonymityBidMode::kSimulate},
"Bid render URL must be a valid ad URL",
GURL("https://ad2.com"),
"Bid render ad must have a valid URL and size (if specified)",
blink::AdDescriptor(GURL("https://ad2.com")),
auction_worklet::mojom::BidderWorkletKAnonEnforcedBid::NewBid(
auction_worklet::mojom::BidderWorkletBid::New(
"ad", 5.0, /*ad_cost=*/absl::nullopt,
Expand All @@ -13864,7 +13936,7 @@ TEST_P(AuctionRunnerKAnonTest, MojoValidation) {
{
{auction_worklet::mojom::KAnonymityBidMode::kNone},
"Received k-anon bid data when not considering k-anon",
GURL("https://ad1.com"),
blink::AdDescriptor(GURL("https://ad1.com")),
auction_worklet::mojom::BidderWorkletKAnonEnforcedBid::
NewSameAsNonEnforced(nullptr),
/*expect_winner=*/true,
Expand Down Expand Up @@ -13894,9 +13966,8 @@ TEST_P(AuctionRunnerKAnonTest, MojoValidation) {
ASSERT_TRUE(seller_worklet);
auto bidder1_worklet =
mock_auction_process_manager_->TakeBidderWorklet(kBidder1Url);
bidder1_worklet->InvokeGenerateBidCallback(
1.0, blink::AdDescriptor(test_case.render_url),
test_case.mojo_bid.Clone());
bidder1_worklet->InvokeGenerateBidCallback(1.0, test_case.ad_descriptor,
test_case.mojo_bid.Clone());

// All of these tests only get one scoreAd, since k-anon bid is invalid.
auto score_ad_params = seller_worklet->WaitForScoreAd();
Expand Down

0 comments on commit 2ff6cd7

Please sign in to comment.