summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/fledge/tentative/component-auction.https.window.js
blob: 63771d42b86d361634bf2408d48caf1538c64278 (plain)
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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
// META: script=/resources/testdriver.js
// META: script=/common/utils.js
// META: script=/common/subset-tests.js
// META: script=resources/fledge-util.sub.js
// META: timeout=long
// META: variant=?1-5
// META: variant=?6-10
// META: variant=?11-15
// META: variant=?16-last

"use strict";

// Creates an AuctionConfig with a single component auction.
function createComponentAuctionConfig(uuid) {
  let componentAuctionConfig = {
    seller: window.location.origin,
    decisionLogicURL: createDecisionScriptURL(uuid),
    interestGroupBuyers: [window.location.origin]
  };

  return {
    seller: window.location.origin,
    decisionLogicURL: createDecisionScriptURL(uuid),
    interestGroupBuyers: [],
    componentAuctions: [componentAuctionConfig]
  };
}

subsetTest(promise_test, async test => {
  const uuid = generateUuid(test);

  await joinInterestGroup(
      test, uuid,
      { biddingLogicURL: createBiddingScriptURL()});

  await runBasicFledgeTestExpectingNoWinner(test, uuid, createComponentAuctionConfig(uuid));
}, 'Component auction allowed not specified by bidder.');

subsetTest(promise_test, async test => {
  const uuid = generateUuid(test);

  await joinInterestGroup(
      test, uuid,
      { biddingLogicURL: createBiddingScriptURL(
        { allowComponentAuction: false })});

  await runBasicFledgeTestExpectingNoWinner(test, uuid, createComponentAuctionConfig(uuid));
}, 'Component auction not allowed by bidder.');

subsetTest(promise_test, async test => {
  const uuid = generateUuid(test);

  await joinInterestGroup(
      test, uuid,
      { biddingLogicURL: createBiddingScriptURL(
        { allowComponentAuction: true })});

  let auctionConfig = createComponentAuctionConfig(uuid);
  auctionConfig.componentAuctions[0].decisionLogicURL = createDecisionScriptURL(
      uuid,
      { scoreAd: "return 5;" });

  await runBasicFledgeTestExpectingNoWinner(test, uuid, auctionConfig);
}, 'Component auction allowed not specified by component seller.');

subsetTest(promise_test, async test => {
  const uuid = generateUuid(test);

  await joinInterestGroup(
      test, uuid,
      { biddingLogicURL: createBiddingScriptURL(
        { allowComponentAuction: true })});

  let auctionConfig = createComponentAuctionConfig(uuid);
  auctionConfig.componentAuctions[0].decisionLogicURL = createDecisionScriptURL(
      uuid,
      { scoreAd: "return {desirability: 5, allowComponentAuction: false};" });

  await runBasicFledgeTestExpectingNoWinner(test, uuid, auctionConfig);
}, 'Component auction not allowed by component seller.');

subsetTest(promise_test, async test => {
  const uuid = generateUuid(test);

  await joinInterestGroup(
      test, uuid,
      { biddingLogicURL: createBiddingScriptURL(
        { allowComponentAuction: true })});

  let auctionConfig = createComponentAuctionConfig(uuid);
  auctionConfig.decisionLogicURL = createDecisionScriptURL(
      uuid,
      { scoreAd: "return 5;" });

  await runBasicFledgeTestExpectingNoWinner(test, uuid, auctionConfig);
}, 'Component auction allowed not specified by top-level seller.');

subsetTest(promise_test, async test => {
  const uuid = generateUuid(test);

  await joinInterestGroup(
      test, uuid,
      { biddingLogicURL: createBiddingScriptURL(
        { allowComponentAuction: true })});

  let auctionConfig = createComponentAuctionConfig(uuid);
  auctionConfig.interestGroupBuyers = [window.location.origin];

  try {
    await runBasicFledgeAuction(test, uuid, auctionConfig);
  } catch (exception) {
    assert_true(exception instanceof TypeError, "did not get expected error: " + exception);
    return;
  }
  throw 'Exception unexpectedly not thrown.'
}, 'Component auction top-level auction cannot have buyers.');

subsetTest(promise_test, async test => {
  const uuid = generateUuid(test);

  await joinInterestGroup(
      test, uuid,
      { biddingLogicURL: createBiddingScriptURL(
        { allowComponentAuction: true })});

  let auctionConfig = createComponentAuctionConfig(uuid);
  auctionConfig.decisionLogicURL = createDecisionScriptURL(
      uuid,
      { scoreAd: "return {desirability: 5, allowComponentAuction: false};" });

  await runBasicFledgeTestExpectingNoWinner(test, uuid, auctionConfig);
}, 'Component auction not allowed by top-level seller.');

subsetTest(promise_test, async test => {
  const uuid = generateUuid(test);

  // Use distinct origins so can validate all origin parameters passed to worklets.
  let bidder = OTHER_ORIGIN1;
  let componentSeller = OTHER_ORIGIN2;
  let topLevelSeller = OTHER_ORIGIN3;

  let bidderReportURL = createBidderReportURL(uuid);
  let componentSellerReportURL = createSellerReportURL(uuid, /*id=*/"component");
  let topLevelSellerReportURL = createSellerReportURL(uuid, /*id=*/"top");

  // Note that generateBid() and reportWin() receive slightly different
  // "browserSignals" fields - only reportWin() gets "interestGroupOwner", so
  // need different sets of checks for them.
  await joinCrossOriginInterestGroup(
      test, uuid, bidder,
      { biddingLogicURL: createBiddingScriptURL(
        { origin: bidder,
          allowComponentAuction: true,
          generateBid:
            `if (browserSignals.seller !== "${componentSeller}")
               throw "Unexpected seller: " + browserSignals.seller;
             if (browserSignals.componentSeller !== undefined)
               throw "Unexpected componentSeller: " + browserSignals.componentSeller;
             if (browserSignals.topLevelSeller !== "${topLevelSeller}")
               throw "Unexpected topLevelSeller: " + browserSignals.topLevelSeller;
             if (browserSignals.interestGroupOwner !== undefined)
               throw "Unexpected interestGroupOwner: " + browserSignals.interestGroupOwner;
             if (browserSignals.topWindowHostname !== "${window.location.hostname}")
               throw "Unexpected topWindowHostname: " + browserSignals.topWindowHostname;`,
          reportWin:
            `if (browserSignals.seller !== "${componentSeller}")
               throw "Unexpected seller: " + browserSignals.seller;
             if (browserSignals.componentSeller !== undefined)
               throw "Unexpected componentSeller: " + browserSignals.componentSeller;
             if (browserSignals.topLevelSeller !== "${topLevelSeller}")
               throw "Unexpected topLevelSeller: " + browserSignals.topLevelSeller;
             if (browserSignals.interestGroupOwner !== "${bidder}")
               throw "Unexpected interestGroupOwner: " + browserSignals.interestGroupOwner;
             if (browserSignals.topWindowHostname !== "${window.location.hostname}")
               throw "Unexpected topWindowHostname: " + browserSignals.topWindowHostname;
             sendReportTo("${bidderReportURL}");`})});

  // Checks for scoreAd() and reportResult() for the component seller.
  let componentSellerChecks =
      `if (browserSignals.seller !== undefined)
         throw "Unexpected seller: " + browserSignals.seller;
       if (browserSignals.componentSeller !== undefined)
         throw "Unexpected componentSeller: " + browserSignals.componentSeller;
       if (browserSignals.topLevelSeller !== "${topLevelSeller}")
         throw "Unexpected topLevelSeller: " + browserSignals.topLevelSeller;
       if (browserSignals.interestGroupOwner !== "${bidder}")
         throw "Unexpected interestGroupOwner: " + browserSignals.interestGroupOwner;
       if (browserSignals.topWindowHostname !== "${window.location.hostname}")
         throw "Unexpected topWindowHostname: " + browserSignals.topWindowHostname;`;

  let componentAuctionConfig = {
    seller: componentSeller,
    decisionLogicURL: createDecisionScriptURL(
        uuid,
        { origin: componentSeller,
          scoreAd: componentSellerChecks,
          reportResult: `${componentSellerChecks}
                          sendReportTo("${componentSellerReportURL}");` }),
    interestGroupBuyers: [bidder]
  };

  // Checks for scoreAd() and reportResult() for the top-level seller.
  let topLevelSellerChecks =
      `if (browserSignals.seller !== undefined)
         throw "Unexpected seller: " + browserSignals.seller;
       if (browserSignals.componentSeller !== "${componentSeller}")
         throw "Unexpected componentSeller: " + browserSignals.componentSeller;
       if (browserSignals.topLevelSeller !== undefined)
         throw "Unexpected topLevelSeller: " + browserSignals.topLevelSeller;
       if (browserSignals.interestGroupOwner !== "${bidder}")
         throw "Unexpected interestGroupOwner: " + browserSignals.interestGroupOwner;
       if (browserSignals.topWindowHostname !== "${window.location.hostname}")
         throw "Unexpected topWindowHostname: " + browserSignals.topWindowHostname;`;

  let auctionConfigOverrides = {
    seller: topLevelSeller,
    decisionLogicURL: createDecisionScriptURL(
        uuid,
        { origin: topLevelSeller,
          scoreAd: topLevelSellerChecks,
          reportResult: `${topLevelSellerChecks}
                         sendReportTo("${topLevelSellerReportURL}");` }),
    interestGroupBuyers: [],
    componentAuctions: [componentAuctionConfig]
  };

  await runBasicFledgeAuctionAndNavigate(test, uuid, auctionConfigOverrides);
  await waitForObservedRequests(
      uuid,
      [bidderReportURL, componentSellerReportURL, topLevelSellerReportURL]);
}, 'Component auction browserSignals origins.');

subsetTest(promise_test, async test => {
  const uuid = generateUuid(test);

  let bidderReportURL = createBidderReportURL(uuid);
  let componentSellerReportURL = createSellerReportURL(uuid, /*id=*/"component");
  let topLevelSellerReportURL = createSellerReportURL(uuid, /*id=*/"top");

  await joinInterestGroup(
      test, uuid,
      { biddingLogicURL: createBiddingScriptURL(
        { allowComponentAuction: true,
          bid: 5,
          reportWin:
            `if (browserSignals.bid !== 5)
               throw "Unexpected bid: " + browserSignals.bid;
             sendReportTo("${bidderReportURL}");`})});

  let auctionConfig = createComponentAuctionConfig(uuid);

  auctionConfig.componentAuctions[0].decisionLogicURL =
    createDecisionScriptURL(
        uuid,
        { scoreAd:
              `if (bid !== 5)
                 throw "Unexpected component bid: " + bid`,
          reportResult:
              `if (browserSignals.bid !== 5)
                 throw "Unexpected component bid: " + browserSignals.bid;
               if (browserSignals.modifiedBid !== undefined)
                 throw "Unexpected component modifiedBid: " + browserSignals.modifiedBid;
               sendReportTo("${componentSellerReportURL}");` });

  auctionConfig.decisionLogicURL =
    createDecisionScriptURL(
        uuid,
        { scoreAd:
              `if (bid !== 5)
                 throw "Unexpected top-level bid: " + bid`,
          reportResult:
              `if (browserSignals.bid !== 5)
                 throw "Unexpected top-level bid: " + browserSignals.bid;
               if (browserSignals.modifiedBid !== undefined)
                 throw "Unexpected top-level modifiedBid: " + browserSignals.modifiedBid;
               sendReportTo("${topLevelSellerReportURL}");` });

  await runBasicFledgeAuctionAndNavigate(test, uuid, auctionConfig);
  await waitForObservedRequests(
      uuid,
      [bidderReportURL, componentSellerReportURL, topLevelSellerReportURL]);
}, 'Component auction unmodified bid.');

subsetTest(promise_test, async test => {
  const uuid = generateUuid(test);

  let bidderReportURL = createBidderReportURL(uuid);
  let componentSellerReportURL = createSellerReportURL(uuid, /*id=*/"component");
  let topLevelSellerReportURL = createSellerReportURL(uuid, /*id=*/"top");

  await joinInterestGroup(
      test, uuid,
      { biddingLogicURL: createBiddingScriptURL(
        { allowComponentAuction: true,
          bid: 5,
          reportWin:
            `if (browserSignals.bid !== 5)
               throw "Unexpected bid: " + browserSignals.bid;
             sendReportTo("${bidderReportURL}");`})});

  let auctionConfig = createComponentAuctionConfig(uuid);

  auctionConfig.componentAuctions[0].decisionLogicURL =
      createDecisionScriptURL(
          uuid,
          { scoreAd:
                `if (bid !== 5)
                   throw "Unexpected component bid: " + bid
                 return {desirability: 5, allowComponentAuction: true, bid: 4};`,
            reportResult:
                `if (browserSignals.bid !== 5)
                   throw "Unexpected component bid: " + browserSignals.bid;
                 if (browserSignals.modifiedBid !== 4)
                   throw "Unexpected component modifiedBid: " + browserSignals.modifiedBid;
                 sendReportTo("${componentSellerReportURL}");` });

  auctionConfig.decisionLogicURL =
      createDecisionScriptURL(
          uuid,
          { scoreAd:
                `if (bid !== 4)
                   throw "Unexpected top-level bid: " + bid`,
            reportResult:
                `if (browserSignals.bid !== 4)
                   throw "Unexpected top-level bid: " + browserSignals.bid;
                 if (browserSignals.modifiedBid !== undefined)
                   throw "Unexpected top-level modifiedBid: " + browserSignals.modifiedBid;
                 sendReportTo("${topLevelSellerReportURL}");` });

  await runBasicFledgeAuctionAndNavigate(test, uuid, auctionConfig);
  await waitForObservedRequests(
      uuid,
      [bidderReportURL, componentSellerReportURL, topLevelSellerReportURL]);
}, 'Component auction modified bid.');

subsetTest(promise_test, async test => {
  const uuid = generateUuid(test);

  let bidderReportURL = createBidderReportURL(uuid);
  let componentSellerReportURL = createSellerReportURL(uuid, /*id=*/"component");
  let topLevelSellerReportURL = createSellerReportURL(uuid, /*id=*/"top");

  await joinInterestGroup(
      test, uuid,
      { biddingLogicURL: createBiddingScriptURL(
        { allowComponentAuction: true,
          bid: 5,
          reportWin:
            `if (browserSignals.bid !== 5)
               throw "Unexpected bid: " + browserSignals.bid;
             sendReportTo("${bidderReportURL}");`})});

  let auctionConfig = createComponentAuctionConfig(uuid);

  auctionConfig.componentAuctions[0].decisionLogicURL =
      createDecisionScriptURL(
          uuid,
          { scoreAd:
                `if (bid !== 5)
                   throw "Unexpected component bid: " + bid
                 return {desirability: 5, allowComponentAuction: true, bid: 5};`,
            reportResult:
                `if (browserSignals.bid !== 5)
                   throw "Unexpected component bid: " + browserSignals.bid;
                 if (browserSignals.modifiedBid !== 5)
                   throw "Unexpected component modifiedBid: " + browserSignals.modifiedBid;
                 sendReportTo("${componentSellerReportURL}");` });

  auctionConfig.decisionLogicURL =
      createDecisionScriptURL(
          uuid,
          { scoreAd:
                `if (bid !== 5)
                   throw "Unexpected top-level bid: " + bid`,
            reportResult:
                `if (browserSignals.bid !== 5)
                   throw "Unexpected top-level bid: " + browserSignals.bid;
                 if (browserSignals.modifiedBid !== undefined)
                   throw "Unexpected top-level modifiedBid: " + browserSignals.modifiedBid;
                 sendReportTo("${topLevelSellerReportURL}");` });

  await runBasicFledgeAuctionAndNavigate(test, uuid, auctionConfig);
  await waitForObservedRequests(
      uuid,
      [bidderReportURL, componentSellerReportURL, topLevelSellerReportURL]);
}, 'Component auction modified bid to same value.');

subsetTest(promise_test, async test => {
  const uuid = generateUuid(test);

  let bidderReportURL = createBidderReportURL(uuid);
  let componentSellerReportURL = createSellerReportURL(uuid, /*id=*/"component");
  let topLevelSellerReportURL = createSellerReportURL(uuid, /*id=*/"top");

  await joinInterestGroup(
      test, uuid,
      { biddingLogicURL: createBiddingScriptURL(
        { allowComponentAuction: true,
          bid: 5,
          reportWin:
            `if (browserSignals.bid !== 5)
               throw "Unexpected bid: " + browserSignals.bid;
             sendReportTo("${bidderReportURL}");`})});

  let auctionConfig = createComponentAuctionConfig(uuid);

  auctionConfig.componentAuctions[0].decisionLogicURL =
      createDecisionScriptURL(
          uuid,
          { scoreAd:
                `if (bid !== 5)
                   throw "Unexpected component bid: " + bid`,
            reportResult:
                `if (browserSignals.bid !== 5)
                   throw "Unexpected component bid: " + browserSignals.bid;
                 if (browserSignals.modifiedBid !== undefined)
                   throw "Unexpected component modifiedBid: " + browserSignals.modifiedBid;
                 sendReportTo("${componentSellerReportURL}");` });

  auctionConfig.decisionLogicURL =
      createDecisionScriptURL(
          uuid,
          { scoreAd:
                `if (bid !== 5)
                   throw "Unexpected top-level bid: " + bid
                 return {desirability: 5, allowComponentAuction: true, bid: 4};`,
            reportResult:
                `if (browserSignals.bid !== 5)
                   throw "Unexpected top-level bid: " + browserSignals.bid;
                 if (browserSignals.modifiedBid !== undefined)
                   throw "Unexpected top-level modifiedBid: " + browserSignals.modifiedBid;
                 sendReportTo("${topLevelSellerReportURL}");` });

  await runBasicFledgeAuctionAndNavigate(test, uuid, auctionConfig);
  await waitForObservedRequests(
      uuid,
      [bidderReportURL, componentSellerReportURL, topLevelSellerReportURL]);
}, 'Top-level auction cannot modify bid.');

subsetTest(promise_test, async test => {
  const uuid = generateUuid(test);

  let bidderReportURL = createBidderReportURL(uuid);
  let componentSellerReportURL = createSellerReportURL(uuid, /*id=*/"component");
  let topLevelSellerReportURL = createSellerReportURL(uuid, /*id=*/"top");

  await joinInterestGroup(
      test, uuid,
      { biddingLogicURL: createBiddingScriptURL(
        { allowComponentAuction: true,
          reportWin:
            `if (browserSignals.desirability !== undefined)
               throw "Unexpected desirability: " + browserSignals.desirability;
             sendReportTo("${bidderReportURL}");`})});

  let auctionConfig = createComponentAuctionConfig(uuid);

  auctionConfig.componentAuctions[0].decisionLogicURL =
      createDecisionScriptURL(
          uuid,
          { scoreAd:
                `return {desirability: 3, allowComponentAuction: true};`,
            reportResult:
                `if (browserSignals.desirability !== 3)
                  throw "Unexpected component desirability: " + browserSignals.desirability;
                 sendReportTo("${componentSellerReportURL}");` });

  auctionConfig.decisionLogicURL =
      createDecisionScriptURL(
          uuid,
          { scoreAd:
                `return {desirability: 4, allowComponentAuction: true};`,
            reportResult:
                `if (browserSignals.desirability !== 4)
                  throw "Unexpected component desirability: " + browserSignals.desirability;
                 sendReportTo("${topLevelSellerReportURL}");` });

  await runBasicFledgeAuctionAndNavigate(test, uuid, auctionConfig);
  await waitForObservedRequests(
      uuid,
      [bidderReportURL, componentSellerReportURL, topLevelSellerReportURL]);
}, 'Component auction desirability.');

subsetTest(promise_test, async test => {
  const uuid = generateUuid(test);

  // An auction with two components, each of which has a distinct bidder origin,
  // so the bidder in the second component is OTHER_ORIGIN1). The bidder in the
  // first component auction bids more and is given the highest of all
  // desirability scores in the auction by its component seller, but the
  // top-level seller prefers bidder 2.
  let bidder1ReportURL = createBidderReportURL(uuid, /*id=*/1);
  let bidder2ReportURL = createBidderReportURL(uuid, /*id=*/2);
  let componentSeller1ReportURL = createSellerReportURL(uuid, /*id=*/"component1");
  let componentSeller2ReportURL = createSellerReportURL(uuid, /*id=*/"component2");
  let topLevelSellerReportURL = createSellerReportURL(uuid, /*id=*/"top");

  await Promise.all([
      joinInterestGroup(
          test, uuid,
          { biddingLogicURL: createBiddingScriptURL(
            { bid: 10,
              allowComponentAuction: true,
              reportWin:
                `sendReportTo("${bidder1ReportURL}");`})}),
      joinCrossOriginInterestGroup(test, uuid, OTHER_ORIGIN1,
        { biddingLogicURL: createBiddingScriptURL(
          { origin: OTHER_ORIGIN1,
            bid: 2,
            allowComponentAuction: true,
            reportWin:
              `if (browserSignals.bid !== 2)
                 throw "Unexpected bid: " + browserSignals.bid;
               sendReportTo("${bidder2ReportURL}");`})})
  ]);

  let auctionConfig = createComponentAuctionConfig(uuid);

  auctionConfig.componentAuctions[0].decisionLogicURL =
      createDecisionScriptURL(
          uuid,
          { scoreAd:
                `return {desirability: 10, allowComponentAuction: true};`,
            reportResult:
                `sendReportTo("${componentSeller1ReportURL}");` });

  auctionConfig.componentAuctions[1] = {
    ...auctionConfig.componentAuctions[0],
    interestGroupBuyers: [OTHER_ORIGIN1],
    decisionLogicURL: createDecisionScriptURL(
        uuid,
        { scoreAd:
              `return {desirability: 1, allowComponentAuction: true};`,
          reportResult:
              `if (browserSignals.desirability !== 1)
                 throw "Unexpected component desirability: " + browserSignals.desirability;
               sendReportTo("${componentSeller2ReportURL}");` })
  }

  auctionConfig.decisionLogicURL =
      createDecisionScriptURL(
          uuid,
          { scoreAd:
                `return {desirability: 11 - bid, allowComponentAuction: true};`,
            reportResult:
                `if (browserSignals.desirability !== 9)
                   throw "Unexpected component desirability: " + browserSignals.desirability;
                 sendReportTo("${topLevelSellerReportURL}");` });

  await runBasicFledgeAuctionAndNavigate(test, uuid, auctionConfig);
  await waitForObservedRequests(
      uuid,
      [bidder2ReportURL, componentSeller2ReportURL, topLevelSellerReportURL]);
}, 'Component auction desirability two sellers, two bidders.');

subsetTest(promise_test, async test => {
  const uuid = generateUuid(test);

  let renderURL1 = createRenderURL(uuid);
  let renderURL2 = createRenderURL(uuid, /*script=*/';');

  // The same bidder uses different ads, bids, and reporting URLs for different
  // component sellers.
  let bidderReportURL1 = createBidderReportURL(uuid, /*id=*/1);
  let bidderReportURL2 = createBidderReportURL(uuid, /*id=*/2);
  let componentSeller1ReportURL = createSellerReportURL(uuid, /*id=*/"component1");
  let componentSeller2ReportURL = createSellerReportURL(uuid, /*id=*/"component2");
  let topLevelSellerReportURL = createSellerReportURL(uuid, /*id=*/"top");

  await joinInterestGroup(
        test, uuid,
        { ads: [{ renderURL: renderURL1 }, { renderURL: renderURL2 }],
          biddingLogicURL: createBiddingScriptURL(
          { allowComponentAuction: true,
            generateBid:
              // "auctionSignals" contains the bid and the report URL, to
              // make the same bidder behave differently in the two
              // auctions.
              'return auctionSignals;',
            reportWin:
              `if (browserSignals.renderURL !== "${renderURL2}")
                 throw "Wrong winner: " + browserSignals.renderURL;
               sendReportTo(auctionSignals.reportURL);`})});

  let auctionConfig = createComponentAuctionConfig(uuid);

  auctionConfig.componentAuctions[0].decisionLogicURL =
      createDecisionScriptURL(
          uuid,
          { scoreAd:
                `return {desirability: 10, allowComponentAuction: true};`,
            reportResult:
                `sendReportTo("${componentSeller1ReportURL}");` });
  // "auctionSignals" contains the bid and the report URL, to
  // make the same bidder behave differently in the two
  // auctions.
  auctionConfig.componentAuctions[0].auctionSignals = {
    bid: 10,
    allowComponentAuction: true,
    render: renderURL1,
    reportURL: bidderReportURL1
  };

  auctionConfig.componentAuctions[1] = {
    ...auctionConfig.componentAuctions[0],
    auctionSignals: {
      bid: 2,
      allowComponentAuction: true,
      render: renderURL2,
      reportURL: bidderReportURL2
    },
    decisionLogicURL: createDecisionScriptURL(
        uuid,
        { scoreAd:
              `return {desirability: 1, allowComponentAuction: true};`,
          reportResult:
              `if (browserSignals.desirability !== 1)
                 throw "Unexpected component desirability: " + browserSignals.desirability;
               if (browserSignals.renderURL !== "${renderURL2}")
                 throw "Wrong winner: " + browserSignals.renderURL;
               sendReportTo("${componentSeller2ReportURL}");` })
  }

  auctionConfig.decisionLogicURL =
      createDecisionScriptURL(
          uuid,
          { scoreAd:
                `return {desirability: 11 - bid, allowComponentAuction: true};`,
            reportResult:
                `if (browserSignals.desirability !== 9)
                   throw "Unexpected component desirability: " + browserSignals.desirability;
                 if (browserSignals.renderURL !== "${renderURL2}")
                   throw "Wrong winner: " + browserSignals.renderURL;
                 sendReportTo("${topLevelSellerReportURL}");` });

  await runBasicFledgeAuctionAndNavigate(test, uuid, auctionConfig);
  await waitForObservedRequests(
      uuid,
      [bidderReportURL2, componentSeller2ReportURL, topLevelSellerReportURL]);
}, 'Component auction desirability and renderURL two sellers, one bidder.');

subsetTest(promise_test, async test => {
  const uuid = generateUuid(test);

  // The renderURLs / report URLs for the first/second iterations of the auction.
  let renderURL1 = createRenderURL(uuid);
  let renderURL2 = createRenderURL(uuid, /*script=*/';');
  let bidderReportURL1 = createBidderReportURL(uuid, /*id=*/1);
  let bidderReportURL2 = createBidderReportURL(uuid, /*id=*/2);
  let seller1ReportURL = createSellerReportURL(uuid, /*id=*/1);
  let seller2ReportURL = createSellerReportURL(uuid, /*id=*/2);

  await joinInterestGroup(
        test, uuid,
        { ads: [{ renderURL: renderURL1 }, { renderURL: renderURL2 }],
          biddingLogicURL: createBiddingScriptURL(
          { allowComponentAuction: true,
            generateBid:
              `// If this is the first recorded win, use "renderURL1"
               if (browserSignals.bidCount === 0 &&
                   browserSignals.prevWinsMs.length === 0) {
                 return {bid: 2, allowComponentAuction: true, render: "${renderURL1}"};
               }

               // Otherwise, check that a single bid and win were reported, despite the
               // bidder bidding twice in the first auction, once for each component
               // auction.
               if (browserSignals.bidCount === 1 &&
                   browserSignals.prevWinsMs.length === 1 &&
                   typeof browserSignals.prevWinsMs[0][0] === "number" &&
                   browserSignals.prevWinsMs[0][1].renderURL === "${renderURL1}") {
                 return {bid: 1, allowComponentAuction: true, render: "${renderURL2}"};
               }
               throw "Unexpected biddingSignals: " + JSON.stringify(browserSignals);`,
            reportWin:
              `if (browserSignals.renderURL === "${renderURL1}")
                 sendReportTo("${bidderReportURL1}");
               if (browserSignals.renderURL === "${renderURL2}")
                 sendReportTo("${bidderReportURL2}");`})});

  // Auction has two component auctions with different sellers but the same
  // single bidder. The first component auction only accepts bids with
  // "renderURL1", the second only accepts bids with "renderURL2".
  let auctionConfig = createComponentAuctionConfig(uuid);
  auctionConfig.componentAuctions[0].decisionLogicURL =
      createDecisionScriptURL(
          uuid,
          { scoreAd: `if (browserSignals.renderURL != '${renderURL1}')
                        throw 'Wrong ad';`,
            reportResult: `sendReportTo('${seller1ReportURL}');`}
      );

  auctionConfig.componentAuctions[1] = {
      seller: OTHER_ORIGIN1,
      interestGroupBuyers: [window.location.origin],
      decisionLogicURL: createDecisionScriptURL(
          uuid,
          { origin: OTHER_ORIGIN1,
            scoreAd: `if (browserSignals.renderURL != '${renderURL2}')
                        throw 'Wrong ad';`,
            reportResult: `sendReportTo('${seller2ReportURL}');`}
      )
  };

  // In the first auction, the bidder should use "renderURL1", which the first
  // component auction allows. `prevWinsMs` and `numBids` should be updated.
  await runBasicFledgeAuctionAndNavigate(test, uuid, auctionConfig);
  await waitForObservedRequests(
      uuid,
      [bidderReportURL1, seller1ReportURL]);

  // In the second auction, the bidder should use "renderURL2", which the second
  // component auction allows. `prevWinsMs` and `numBids` should reflect the updated
  // value.
  await runBasicFledgeAuctionAndNavigate(test, uuid, auctionConfig);
  await waitForObservedRequests(
      uuid,
      [bidderReportURL1, seller1ReportURL, bidderReportURL2, seller2ReportURL]);
}, `Component auction prevWinsMs and numBids updating in one component seller's auction, read in another's.`);