Bug 1826620 [wpt PR 39397] - Add WPTs for AuctionConfig, a=testonly
[gecko.git] / testing / web-platform / tests / fledge / tentative / auction-config.https.sub.window.js
blob1455871dad6ccf8cb9b7431e49c19a0e9af4f9f2
1 // META: script=/resources/testdriver.js
2 // META: script=/common/utils.js
3 // META: script=resources/fledge-util.js
5 "use strict;"
7 // The tests in this file focus on calls to runAdAuction with various
8 // auctionConfigs.
10 const makeTest = ({
11   // Test name
12   name,
13   // Expectation function (EXPECT_NULL, etc.)
14   expect,
15   // Overrides to the auction config.
16   auctionConfigOverrides = {},
17 }) => {
18   promise_test(async test => {
19     const uuid = generateUuid(test);
20     // Join an interest group so the auction actually runs.
21     await joinInterestGroup(test, uuid);
22     let auctionResult;
23     try {
24       auctionResult = await runBasicFledgeAuction(test, uuid, auctionConfigOverrides);
25     } catch (e) {
26       auctionResult = e;
27     }
28     expect(auctionResult);
29   }, name);
32 // Expect an unsuccessful auction (yielding null).
33 const EXPECT_NO_WINNER = auctionResult => {
34   assert_equals(auctionResult, null, 'Auction unexpected had a winner');
37 // Expect an exception of the given type.
38 const EXPECT_EXCEPTION = exceptionType => auctionResult => {
39   assert_not_equals(auctionResult, null, "got null instead of expected error");
40   assert_true(auctionResult instanceof Error, "did not get expected error: " + auctionResult);
41   assert_throws_js(exceptionType, () => { throw auctionResult; });
44 makeTest({
45   name: 'no buyers => no winners',
46   expect: EXPECT_NO_WINNER,
47   auctionConfigOverrides: {interestGroupBuyers: []},
48 });
50 makeTest({
51   name: 'seller is not an https URL',
52   expect: EXPECT_EXCEPTION(TypeError),
53   auctionConfigOverrides: {seller: "ftp://not-https"},
54 });
56 makeTest({
57   name: 'decisionLogicUrl is invalid',
58   expect: EXPECT_EXCEPTION(TypeError),
59   auctionConfigOverrides: { decisionLogicUrl: "https://foo:99999999999" },
60 });
62 makeTest({
63   name: 'decisionLogicUrl is cross-origin with seller',
64   expect: EXPECT_EXCEPTION(TypeError),
65   auctionConfigOverrides: { decisionLogicUrl: "https://example.com" },
66 });
68 makeTest({
69   name: 'trustedScoringSignalsUrl is invalid',
70   expect: EXPECT_EXCEPTION(TypeError),
71   auctionConfigOverrides: { trustedScoringSignalsUrl: "https://foo:99999999999" },
72 });
74 makeTest({
75   name: 'trustedScoringSignalsUrl is cross-origin with seller',
76   expect: EXPECT_EXCEPTION(TypeError),
77   auctionConfigOverrides: { trustedScoringSignalsUrl: "https://example.com" },
78 });
80 makeTest({
81   name: 'interestGroupBuyer is invalid',
82   expect: EXPECT_EXCEPTION(TypeError),
83   auctionConfigOverrides: { interestGroupBuyers: ["https://foo:99999999999"] },
84 });
86 makeTest({
87   name: 'interestGroupBuyer is not https',
88   expect: EXPECT_EXCEPTION(TypeError),
89   auctionConfigOverrides: { interestGroupBuyers: ["http://example.com"] },
90 });
92 makeTest({
93   name: 'only one interestGroupBuyer is invalid',
94   expect: EXPECT_EXCEPTION(TypeError),
95   auctionConfigOverrides: {
96     interestGroupBuyers: ["https://example.com", "https://foo:99999999999"],
97   },
98 });
100 makeTest({
101   name: 'only one interestGroupBuyer is not https',
102   expect: EXPECT_EXCEPTION(TypeError),
103   auctionConfigOverrides: {
104     interestGroupBuyers: ["https://example.com", "http://example.com"],
105   },
108 makeTest({
109   name: 'auctionSignals is invalid as JSON',
110   expect: EXPECT_EXCEPTION(TypeError),
111   auctionConfigOverrides: { auctionSignals: { sig: BigInt(13) } },
114 makeTest({
115   name: 'sellerSignals is invalid as JSON',
116   expect: EXPECT_EXCEPTION(TypeError),
117   auctionConfigOverrides: { sellerSignals: { sig: BigInt(13) } },
120 makeTest({
121   name: 'directFromSellerSignals is invalid',
122   expect: EXPECT_EXCEPTION(TypeError),
123   auctionConfigOverrides: { directFromSellerSignals: "https://foo:99999999999" },
126 makeTest({
127   name: 'directFromSellerSignals is cross-origin with seller',
128   expect: EXPECT_EXCEPTION(TypeError),
129   auctionConfigOverrides: { directFromSellerSignals: "https://example.com" },
132 makeTest({
133   name: 'directFromSellerSignals has nonempty query',
134   expect: EXPECT_EXCEPTION(TypeError),
135   auctionConfigOverrides: { directFromSellerSignals: window.location.origin + "?foo=bar" },
138 makeTest({
139   name: 'perBuyerSignals has invalid URL in a key',
140   expect: EXPECT_EXCEPTION(TypeError),
141   auctionConfigOverrides: { perBuyerSignals: { "https://foo:99999999999" : {} }},
144 makeTest({
145   name: 'perBuyerSignals value is invalid as JSON',
146   expect: EXPECT_EXCEPTION(TypeError),
147   auctionConfigOverrides: {
148     perBuyerSignals: { "https://example.com" : { sig: BigInt(1) },
149   }},
152 makeTest({
153   name: 'perBuyerGroupLimits has invalid URL in a key',
154   expect: EXPECT_EXCEPTION(TypeError),
155   auctionConfigOverrides: { perBuyerGroupLimits: { "https://foo:99999999999" : 5 }},
158 makeTest({
159   name: 'perBuyerExperimentGroupIds has invalid URL in a key',
160   expect: EXPECT_EXCEPTION(TypeError),
161   auctionConfigOverrides: { perBuyerExperimentGroupIds: { "https://foo:99999999999" : 11 }},
164 makeTest({
165   name: 'perBuyerPrioritySignals has invalid URL in a key',
166   expect: EXPECT_EXCEPTION(TypeError),
167   auctionConfigOverrides: {
168     perBuyerPrioritySignals: { "https://foo:99999999999" : { sig: 2.5} },
169   },
172 makeTest({
173   name: 'perBuyerPrioritySignals has a value with a key with prefix "browserSignals"',
174   expect: EXPECT_EXCEPTION(TypeError),
175   auctionConfigOverrides: {
176     perBuyerPrioritySignals: { "https://example.com" : { "browserSignals.foo" : true } },
177   },
180 makeTest({
181   name: 'component auctions are not allowed within component auctions',
182   expect: EXPECT_EXCEPTION(TypeError),
183   auctionConfigOverrides: {
184     interestGroupBuyers: undefined,
185     componentAuctions: [
186       {
187         seller: window.location.origin,
188         decisionLogicUrl: window.location.origin,
189         interestGroupBuyers: undefined,
190         componentAuctions: [
191           {
192             seller: window.location.origin,
193             decisionLogicUrl: window.location.origin,
194           }
195         ],
196       },
197     ],
198   },
201 makeTest({
202   name: 'component auctions are not allowed with interestGroupBuyers',
203   expect: EXPECT_EXCEPTION(TypeError),
204   auctionConfigOverrides: {
205     interestGroupBuyers: ["https://example.com"],
206     componentAuctions: [
207       {
208         seller: window.location.origin,
209         decisionLogicUrl: window.location.origin,
210         interestGroupBuyers: [],
211       },
212     ],
213   },