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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
content / test / data / interest_group / component_auction_component_decision_argument_validator.js [blame]
// Copyright 2021 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
function scoreAd(adMetadata, bid, auctionConfig, trustedScoringSignals,
browserSignals, directFromSellerSignals) {
validateAdMetadata(adMetadata);
validateBid(bid);
validateAuctionConfig(auctionConfig);
validateTrustedScoringSignals(trustedScoringSignals);
validateBrowserSignals(browserSignals, /*isScoreAd=*/true);
validateDirectFromSellerSignals(directFromSellerSignals);
return {desirability: 13, allowComponentAuction: true,
bid:42, bidCurrency: 'CAD', ad:['Replaced metadata']};
}
function reportResult(auctionConfig, browserSignals, directFromSellerSignals) {
validateAuctionConfig(auctionConfig);
validateBrowserSignals(browserSignals, /*isScoreAd=*/false);
validateDirectFromSellerSignals(directFromSellerSignals);
sendReportTo(auctionConfig.seller + '/echo?report_component_seller');
return ['component seller signals for winner'];
}
function validateAdMetadata(adMetadata) {
const adMetadataJSON = JSON.stringify(adMetadata);
if (adMetadataJSON !==
'{"renderURL":"https://example.com/render",' +
'"renderUrl":"https://example.com/render",' +
'"metadata":{"ad":"metadata","here":[1,2,3]}}') {
throw 'Wrong adMetadata ' + adMetadataJSON;
}
}
function validateBid(bid) {
if (bid !== 2)
throw 'Wrong bid ' + bid;
}
function validateAuctionConfig(auctionConfig) {
if (Object.keys(auctionConfig).length !== 16) {
throw 'Wrong number of auctionConfig fields ' +
JSON.stringify(auctionConfig);
}
if (!auctionConfig.seller.includes('d.test'))
throw 'Wrong seller ' + auctionConfig.seller;
if (auctionConfig.decisionLogicURL !==
auctionConfig.seller + '/interest_group' +
'/component_auction_component_decision_argument_validator.js') {
throw 'Wrong decisionLogicURL ' + auctionConfig.decisionLogicURL;
}
if (auctionConfig.decisionLogicUrl !==
auctionConfig.seller + '/interest_group' +
'/component_auction_component_decision_argument_validator.js') {
throw 'Wrong decisionLogicUrl ' + auctionConfig.decisionLogicUrl;
}
if (auctionConfig.trustedScoringSignalsURL !==
auctionConfig.seller + '/interest_group/trusted_scoring_signals2.json') {
throw 'Wrong trustedScoringSignalsURL ' +
auctionConfig.trustedScoringSignalsURL;
}
if (auctionConfig.trustedScoringSignalsUrl !==
auctionConfig.seller + '/interest_group/trusted_scoring_signals2.json') {
throw 'Wrong trustedScoringSignalsUrl ' +
auctionConfig.trustedScoringSignalsUrl;
}
if (auctionConfig.interestGroupBuyers.length !== 1 ||
!auctionConfig.interestGroupBuyers[0].startsWith('https://a.test')) {
throw 'Wrong interestGroupBuyers ' + auctionConfig.interestGroupBuyers;
}
const buyerOrigin = auctionConfig.interestGroupBuyers[0];
// If auctionSignals is passed as a JSON string instead of an object,
// stringify() will wrap it in another layer of quotes, causing the test to
// fail.
const auctionSignalsJson = JSON.stringify(auctionConfig.auctionSignals);
if (auctionSignalsJson !== '["component auction signals"]')
throw 'Wrong auctionSignals ' + auctionConfig.auctionSignals;
const sellerSignalsJson = JSON.stringify(auctionConfig.sellerSignals);
if (sellerSignalsJson !== '["component seller signals"]')
throw 'Wrong sellerSignals ' + auctionConfig.sellerSignalsJson;
if (auctionConfig.sellerTimeout !== 20000)
throw 'Wrong sellerTimeout ' + auctionConfig.sellerTimeout;
if (JSON.stringify(auctionConfig.perBuyerSignals[buyerOrigin]) !==
'["component buyer signals"]') {
throw 'Wrong perBuyerSignals ' +
JSON.stringify(auctionConfig.perBuyerSignals);
}
if (auctionConfig.perBuyerTimeouts[buyerOrigin] !== 20000) {
throw 'Wrong perBuyerTimeouts ' +
JSON.stringify(auctionConfig.perBuyerTimeouts);
}
if (auctionConfig.perBuyerCumulativeTimeouts[buyerOrigin] !== 20100) {
throw 'Wrong perBuyerCumulativeTimeouts ' +
JSON.stringify(auctionConfig.perBuyerCumulativeTimeouts);
}
if (auctionConfig.reportingTimeout !== 2000)
throw 'Wrong reportingTimeout ' + auctionConfig.reportingTimeout;
if (auctionConfig.perBuyerCurrencies[buyerOrigin] !== 'USD') {
throw 'Wrong perBuyerCurrencies ' +
JSON.stringify(auctionConfig.perBuyerCurrencies);
}
if (auctionConfig.sellerCurrency !== 'CAD') {
throw 'Wrong sellerCurrency' + JSON.stringify(auctionConfig.sellerCurrency);
}
const perBuyerPrioritySignals = auctionConfig.perBuyerPrioritySignals;
if (Object.keys(perBuyerPrioritySignals).length !== 2 ||
JSON.stringify(perBuyerPrioritySignals[buyerOrigin]) !==
'{"bar":1}' ||
JSON.stringify(perBuyerPrioritySignals['*']) !==
'{"BaZ":-2}') {
throw 'Wrong perBuyerPrioritySignals ' +
JSON.stringify(perBuyerPrioritySignals);
}
if ('componentAuctions' in auctionConfig) {
throw 'Unexpected componentAuctions ' +
JSON.stringify(auctionConfig.componentAuctions);
}
}
function validateTrustedScoringSignals(signals) {
if (signals.renderURL["https://example.com/render"] !== "bar") {
throw 'Wrong trustedScoringSignals.renderURL ' +
signals.renderURL["https://example.com/render"];
}
if (signals.adComponentRenderURLs["https://example.com/render-component"] !==
2) {
throw 'Wrong trustedScoringSignals.adComponentRenderURLs ' +
signals.adComponentRenderURLs["https://example.com/render-component"];
}
if (signals.renderUrl["https://example.com/render"] !== "bar") {
throw 'Wrong trustedScoringSignals.renderUrl ' +
signals.renderUrl["https://example.com/render"];
}
if (signals.adComponentRenderUrls["https://example.com/render-component"] !==
2) {
throw 'Wrong trustedScoringSignals.adComponentRenderUrls ' +
signals.adComponentRenderUrls["https://example.com/render-component"];
}
}
// Used for both scoreAd() and reportResult().
function validateBrowserSignals(browserSignals, isScoreAd) {
// Fields common to scoreAd() and reportResult().
if (browserSignals.topWindowHostname !== 'c.test')
throw 'Wrong topWindowHostname ' + browserSignals.topWindowHostname;
if (!browserSignals.topLevelSeller.startsWith('https://b.test'))
throw 'Wrong topLevelSeller ' + browserSignals.topLevelSeller;
if ('componentSeller' in browserSignals)
throw 'Wrong componentSeller ' + browserSignals.componentSeller;
if (!browserSignals.interestGroupOwner.startsWith('https://a.test'))
throw 'Wrong interestGroupOwner ' + browserSignals.interestGroupOwner;
if (browserSignals.renderURL !== "https://example.com/render")
throw 'Wrong renderURL ' + browserSignals.renderURL;
if (browserSignals.renderUrl !== "https://example.com/render")
throw 'Wrong renderUrl ' + browserSignals.renderUrl;
if (browserSignals.bidCurrency != 'USD')
throw 'Wrong bidCurrency ' + browserSignals.bidCurrency;
// Fields that vary by method.
if (isScoreAd) {
if (Object.keys(browserSignals).length !== 10) {
throw 'Wrong number of browser signals fields ' +
JSON.stringify(browserSignals);
}
const adComponentsJson = JSON.stringify(browserSignals.adComponents);
if (adComponentsJson !== '["https://example.com/render-component"]')
throw 'Wrong adComponents ' + adComponentsJson;
if (browserSignals.biddingDurationMsec < 0)
throw 'Wrong biddingDurationMsec ' + browserSignals.biddingDurationMsec;
if (browserSignals.dataVersion !== 5678)
throw 'Wrong dataVersion ' + browserSignals.dataVersion;
if (browserSignals.forDebuggingOnlyInCooldownOrLockout)
throw 'Wrong forDebuggingOnlyInCooldownOrLockout ' +
browserSignals.forDebuggingOnlyInCooldownOrLockout;
} else {
if (Object.keys(browserSignals).length !== 13) {
throw 'Wrong number of browser signals fields ' +
JSON.stringify(browserSignals);
}
if (browserSignals.bid !== 2)
throw 'Wrong bid ' + browserSignals.bid;
if (browserSignals.desirability !== 13)
throw 'Wrong desireability ' + browserSignals.desirability;
if (browserSignals.highestScoringOtherBid !== 0) {
throw 'Wrong highestScoringOtherBid ' +
browserSignals.highestScoringOtherBid;
}
if (browserSignals.highestScoringOtherBidCurrency !== 'CAD') {
throw 'Wrong highestScoringOtherBidCurrency ' +
browserSignals.highestScoringOtherBidCurrency;
}
if (browserSignals.dataVersion !== 5678)
throw 'Wrong dataVersion ' + browserSignals.dataVersion;
if (browserSignals.modifiedBid !== 42)
throw 'Wrong modifiedBid ' + browserSignals.modifiedBid;
const topLevelSellerSignals =
JSON.stringify(browserSignals.topLevelSellerSignals);
if (topLevelSellerSignals !== '["top-level seller signals for winner"]')
throw 'Wrong topLevelSellerSignals ' + topLevelSellerSignals;
}
}
function validateDirectFromSellerSignals(directFromSellerSignals) {
const sellerSignalsJSON =
JSON.stringify(directFromSellerSignals.sellerSignals);
if (sellerSignalsJSON !==
'{"from":"component","json":"for","the":["seller"]}') {
throw 'Wrong directFromSellerSignals.sellerSignals ' +
sellerSignalsJSON;
}
const auctionSignalsJSON =
JSON.stringify(directFromSellerSignals.auctionSignals);
if (auctionSignalsJSON !==
'{"from":"component","json":"for","all":["parties"]}' &&
auctionSignalsJSON !==
'{"all":["parties"],"from":"component","json":"for"}') {
throw 'Wrong directFromSellerSignals.auctionSignals ' +
auctionSignalsJSON;
}
}