summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/fledge/tentative/direct-from-seller-signals.https.window.js
blob: d0c0e550c4232bd4dad1661b0b418084111a48a6 (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
// META: script=/resources/testdriver.js
// META: script=/common/utils.js
// META: script=resources/fledge-util.sub.js
// META: script=/common/subset-tests.js
// META: timeout=long
// META: variant=?1-4
// META: variant=?5-8
// META: variant=?9-12
// META: variant=?13-16
// META: variant=?17-20
// META: variant=?21-24
// META: variant=?25-28
// META: variant=?29-last

"use strict;"

subsetTest(promise_test, async test => {
  const uuid = generateUuid(test);
  await fetchDirectFromSellerSignals({ 'Buyer-Origin': window.location.origin });
  await runReportTest(
      test, uuid,
      directFromSellerSignalsValidatorCode(
          uuid, /*expectedSellerSignals=*/ null,
          /*expectedAuctionSignals=*/ null, /*expectedPerBuyerSignals=*/ null),
      // expectedReportURLs
      [createSellerReportURL(uuid), createBidderReportURL(uuid)],
      // renderURLOverride
      null,
      // auctionConfigOverrides
      {directFromSellerSignalsHeaderAdSlot: 'adSlot/0'});
}, 'Test directFromSellerSignals with empty Ad-Auction-Signals header.');

subsetTest(promise_test, async test => {
  const uuid = generateUuid(test);
  await fetchDirectFromSellerSignals({ 'Buyer-Origin': window.location.origin });
  await runReportTest(
      test, uuid,
      directFromSellerSignalsValidatorCode(
          uuid, 'sellerSignals/1',
          /*expectedAuctionSignals=*/null, /*expectedPerBuyerSignals=*/null),
      // expectedReportURLs
      [createSellerReportURL(uuid), createBidderReportURL(uuid)],
      // renderURLOverride
      null,
      // auctionConfigOverrides
      { directFromSellerSignalsHeaderAdSlot: 'adSlot/1' }
  );
}, 'Test directFromSellerSignals with only sellerSignals.');

subsetTest(promise_test, async test => {
  const uuid = generateUuid(test);
  await fetchDirectFromSellerSignals({ 'Buyer-Origin': window.location.origin });
  await runReportTest(
      test, uuid,
      directFromSellerSignalsValidatorCode(
          uuid, /*expectedSellerSignals=*/null,
          'auctionSignals/2', /*expectedPerBuyerSignals=*/null),
      // expectedReportURLs
      [createSellerReportURL(uuid), createBidderReportURL(uuid)],
      // renderURLOverride
      null,
      // auctionConfigOverrides
      { directFromSellerSignalsHeaderAdSlot: 'adSlot/2' }
  );
}, 'Test directFromSellerSignals with only auctionSignals.');

subsetTest(promise_test, async test => {
  const uuid = generateUuid(test);
  await fetchDirectFromSellerSignals({ 'Buyer-Origin': window.location.origin });
  await runReportTest(
      test, uuid,
      directFromSellerSignalsValidatorCode(
          uuid, /*expectedSellerSignals=*/null,
          /*expectedAuctionSignals=*/null, 'perBuyerSignals/3'),
      // expectedReportURLs
      [createSellerReportURL(uuid), createBidderReportURL(uuid)],
      // renderURLOverride
      null,
      // auctionConfigOverrides
      { directFromSellerSignalsHeaderAdSlot: 'adSlot/3' }
  );
}, 'Test directFromSellerSignals with only perBuyerSignals.');

subsetTest(promise_test, async test => {
  const uuid = generateUuid(test);
  await fetchDirectFromSellerSignals({ 'Buyer-Origin': window.location.origin });
  await runReportTest(
      test, uuid,
      directFromSellerSignalsValidatorCode(
          uuid, 'sellerSignals/4',
          'auctionSignals/4', 'perBuyerSignals/4'),
      // expectedReportURLs
      [createSellerReportURL(uuid), createBidderReportURL(uuid)],
      // renderURLOverride
      null,
      // auctionConfigOverrides
      { directFromSellerSignalsHeaderAdSlot: 'adSlot/4' }
  );
}, 'Test directFromSellerSignals with sellerSignals, auctionSignals and perBuyerSignals.');

subsetTest(promise_test, async test => {
  const uuid = generateUuid(test);
  await fetchDirectFromSellerSignals({ 'Buyer-Origin': window.location.origin });
  await runReportTest(
      test, uuid,
      directFromSellerSignalsValidatorCode(
          uuid, 'sellerSignals/1',
          /*expectedAuctionSignals=*/null, /*expectedPerBuyerSignals=*/null),
      // expectedReportURLs
      [createSellerReportURL(uuid), createBidderReportURL(uuid)],
      // renderURLOverride
      null,
      // auctionConfigOverrides
    { directFromSellerSignalsHeaderAdSlot: 'adSlot/1' }
  );

  await runReportTest(
      test, uuid,
      directFromSellerSignalsValidatorCode(
          uuid, /*expectedSellerSignals=*/null,
          'auctionSignals/2', /*expectedPerBuyerSignals=*/null),
      // expectedReportURLs
      [createSellerReportURL(uuid), createBidderReportURL(uuid)],
      // renderURLOverride
      null,
      // auctionConfigOverrides
      { directFromSellerSignalsHeaderAdSlot: 'adSlot/2' }
  );
}, 'Test directFromSellerSignals with single fetch and multiple auctions');

subsetTest(promise_test, async test => {
  const uuid = generateUuid(test);
  const ad_slot = Promise.resolve('adSlot/4');
  await fetchDirectFromSellerSignals({ 'Buyer-Origin': window.location.origin });
  await runReportTest(
      test, uuid,
      directFromSellerSignalsValidatorCode(
          uuid, 'sellerSignals/4',
          'auctionSignals/4', 'perBuyerSignals/4'),
      // expectedReportURLs
      [createSellerReportURL(uuid), createBidderReportURL(uuid)],
      // renderURLOverride
      null,
      // auctionConfigOverrides
      { directFromSellerSignalsHeaderAdSlot: ad_slot }
  );
}, 'Test directFromSellerSignals with resolved promise ad slot.');

subsetTest(promise_test, async test => {
  const uuid = generateUuid(test);
  await fetchDirectFromSellerSignals({ 'Buyer-Origin': window.location.origin });
  await joinInterestGroup(test, uuid);

  const adSlot = Promise.reject(new Error('This is a rejected promise.'));
  let auctionConfig =
      { seller: window.location.origin,
        interestGroupBuyers: [window.location.origin],
        resolveToConfig: true,
        decisionLogicURL: createDecisionScriptURL(uuid),
        directFromSellerSignalsHeaderAdSlot: adSlot };

  try {
    await navigator.runAdAuction(auctionConfig);
  } catch(e) {
    assert_true(e instanceof TypeError);
    return;
  }
  throw "Exception unexpectedly not thrown.";
}, 'Test directFromSellerSignals with rejected promise ad slot.');

subsetTest(promise_test, async test => {
  const uuid = generateUuid(test);
  const validator = directFromSellerSignalsValidatorCode(
      uuid, 'sellerSignals/4',
      'auctionSignals/4', 'perBuyerSignals/4');
  let reportResult = `if (!(${validator.reportResultSuccessCondition})) {
                        sendReportTo('${createSellerReportURL(uuid, 'error')}');
                        return false;
                      }
                      ${validator.reportResult}`;
  let reportWin = `if (!(${validator.reportWinSuccessCondition})) {
                     sendReportTo('${createBidderReportURL(uuid, 'error')}');
                     return false;
                   }
                   ${validator.reportWin}`;
  let decisionScriptURLParams = { scoreAd : validator.scoreAd,
                                  reportResult : reportResult };
  let biddingScriptURLParams = { generateBid : validator.generateBid,
                                 reportWin : reportWin };
  let interestGroupOverrides =
      { biddingLogicURL: createBiddingScriptURL(biddingScriptURLParams) };
  await joinInterestGroup(test, uuid, interestGroupOverrides);

  let adSlotResolve = null;
  const adSlotPromise = new Promise((resolve, reject) => { adSlotResolve = resolve });
  let auctionConfig =
      { seller: window.location.origin,
        interestGroupBuyers: [window.location.origin],
        resolveToConfig: true,
        decisionLogicURL: createDecisionScriptURL(uuid, decisionScriptURLParams),
        directFromSellerSignalsHeaderAdSlot: adSlotPromise };
  let resultPromise = navigator.runAdAuction(auctionConfig);

  await fetchDirectFromSellerSignals({ 'Buyer-Origin': window.location.origin });
  adSlotResolve('adSlot/4');
  let result = await resultPromise;
  createAndNavigateFencedFrame(test, result);
  await waitForObservedRequests(uuid, [createSellerReportURL(uuid), createBidderReportURL(uuid)]);
}, 'Test directFromSellerSignals that runAdAuction will wait until the promise of fetch is resolved.');

subsetTest(promise_test, async test => {
  const uuid = generateUuid(test);
  await fetchDirectFromSellerSignals({ 'Buyer-Origin': window.location.origin });
  await runReportTest(
      test, uuid,
      directFromSellerSignalsValidatorCode(
          uuid, 'sellerSignals/5',
          'auctionSignals/5', /*expectedPerBuyerSignals=*/null),
      // expectedReportURLs
      [createSellerReportURL(uuid), createBidderReportURL(uuid)],
      // renderURLOverride
      null,
      // auctionConfigOverrides
      { directFromSellerSignalsHeaderAdSlot: 'adSlot/5' }
  );
}, 'Test directFromSellerSignals with mismatched perBuyerSignals.');

subsetTest(promise_test, async test => {
  const uuid = generateUuid(test);
  await fetchDirectFromSellerSignals({ 'Buyer-Origin': '*' });
  await runReportTest(
      test, uuid,
      directFromSellerSignalsValidatorCode(
        uuid, 'sellerSignals/5',
        'auctionSignals/5', /*expectedPerBuyerSignals=*/null),
      // expectedReportURLs
      [createSellerReportURL(uuid), createBidderReportURL(uuid)],
      // renderURLOverride
      null,
      // auctionConfigOverrides
      { directFromSellerSignalsHeaderAdSlot: 'adSlot/5' }
  );
}, 'Test directFromSellerSignals does not support wildcard for buyerOrigin of perBuyerSignals.');

subsetTest(promise_test, async test => {
  const uuid = generateUuid(test);
  await fetchDirectFromSellerSignals({ 'Buyer-Origin': window.location.origin });
  await runReportTest(
      test, uuid,
      directFromSellerSignalsValidatorCode(
          uuid, /*expectedSellerSignals=*/null,
          /*expectedAuctionSignals=*/null, /*expectedPerBuyerSignals=*/null),
      // expectedReportURLs
      [createSellerReportURL(uuid), createBidderReportURL(uuid)],
      // renderURLOverride
      null,
      // auctionConfigOverrides
      { directFromSellerSignalsHeaderAdSlot: 'adSlot/non-exist' }
  );
}, 'Test directFromSellerSignals with non-existent adSlot.');

subsetTest(promise_test, async test => {
  const uuid = generateUuid(test);
  await fetchDirectFromSellerSignals({ 'Buyer-Origin': window.location.origin });
  await runReportTest(
      test, uuid,
      directFromSellerSignalsValidatorCode(
          uuid, /*expectedSellerSignals=*/null,
          /*expectedAuctionSignals=*/null, /*expectedPerBuyerSignals=*/null),
      [createSellerReportURL(uuid), createBidderReportURL(uuid)],
      // renderURLOverride
      null,
      // auctionConfigOverrides
      { directFromSellerSignalsHeaderAdSlot: null }
  );
}, 'Test directFromSellerSignals with null directFromSellerSignalsHeaderAdSlot.');

subsetTest(promise_test, async test => {
  const uuid = generateUuid(test);
  await fetchDirectFromSellerSignals({ 'Buyer-Origin': window.location.origin });
  await runReportTest(
      test, uuid,
      directFromSellerSignalsValidatorCode(
          uuid, /*expectedSellerSignals=*/null,
          /*expectedAuctionSignals=*/null, /*expectedPerBuyerSignals=*/null),
      [createSellerReportURL(uuid), createBidderReportURL(uuid)]
  );
}, 'Test directFromSellerSignals with no directFromSellerSignalsHeaderAdSlot.');

subsetTest(promise_test, async test => {
  const uuid = generateUuid(test);
  await fetchDirectFromSellerSignals({ 'Negative-Test-Option': 'HTTP Error' });
  await runReportTest(
      test, uuid,
      directFromSellerSignalsValidatorCode(
          uuid, /*expectedSellerSignals=*/null,
          /*expectedAuctionSignals=*/null, /*expectedPerBuyerSignals=*/null),
      // expectedReportURLs
      [createSellerReportURL(uuid), createBidderReportURL(uuid)],
      // renderURLOverride
      null,
      // auctionConfigOverrides
      { directFromSellerSignalsHeaderAdSlot: 'adSlot' }
  );
}, 'Test directFromSellerSignals with HTTP error.');

subsetTest(promise_test, async test => {
  const uuid = generateUuid(test);
  await fetchDirectFromSellerSignals({ 'Negative-Test-Option': 'No Ad-Auction-Signals Header' });
  await runReportTest(
      test, uuid,
      directFromSellerSignalsValidatorCode(
          uuid, /*expectedSellerSignals=*/null,
          /*expectedAuctionSignals=*/null, /*expectedPerBuyerSignals=*/null),
      // expectedReportURLs
      [createSellerReportURL(uuid), createBidderReportURL(uuid)],
      // renderURLOverride
      null,
      // auctionConfigOverrides
      { directFromSellerSignalsHeaderAdSlot: 'adSlot' }
  );
}, 'Test directFromSellerSignals with no returned Ad-Auction-Signals Header.');

subsetTest(promise_test, async test => {
  const uuid = generateUuid(test);
  await fetchDirectFromSellerSignals({ 'Negative-Test-Option': 'Invalid Json' });
  await runReportTest(
      test, uuid,
      directFromSellerSignalsValidatorCode(
          uuid, /*expectedSellerSignals=*/null,
          /*expectedAuctionSignals=*/null, /*expectedPerBuyerSignals=*/null),
      // expectedReportURLs
      [createSellerReportURL(uuid), createBidderReportURL(uuid)],
      // renderURLOverride
      null,
      // auctionConfigOverrides
      { directFromSellerSignalsHeaderAdSlot: 'adSlot' }
  );
}, 'Test directFromSellerSignals with invalid json in Ad-Auction-Signals header.');

subsetTest(promise_test, async test => {
  const uuid = generateUuid(test);
  let codeToInsert = directFromSellerSignalsValidatorCode(
      uuid, /*expectedSellerSignals=*/null,
      /*expectedAuctionSignals=*/null, /*expectedPerBuyerSignals=*/null);
  codeToInsert.decisionScriptURLOrigin = OTHER_ORIGIN1;
  await fetchDirectFromSellerSignals({ 'Buyer-Origin': window.location.origin });
  await runReportTest(
      test, uuid, codeToInsert,
      // expectedReportURLs
      [createSellerReportURL(uuid), createBidderReportURL(uuid)],
      // renderURLOverride
      null,
      // auctionConfigOverrides
      { directFromSellerSignalsHeaderAdSlot: 'adSlot/4',
        seller: OTHER_ORIGIN1 }
  );
}, 'Test directFromSellerSignals with different fetch and seller origins.');

subsetTest(promise_test, async test => {
  const uuid = generateUuid(test);
  let codeToInsert = directFromSellerSignalsValidatorCode(
      uuid, 'sellerSignals/4',
      'auctionSignals/4', 'perBuyerSignals/4');
  codeToInsert.decisionScriptURLOrigin = OTHER_ORIGIN1;
  await fetchDirectFromSellerSignals({ 'Buyer-Origin': window.location.origin }, OTHER_ORIGIN1);
  await runReportTest(
      test, uuid, codeToInsert,
      // expectedReportURLs
      [createSellerReportURL(uuid), createBidderReportURL(uuid)],
      // renderURLOverride
      null,
      // auctionConfigOverrides
      { directFromSellerSignalsHeaderAdSlot: 'adSlot/4',
        seller: OTHER_ORIGIN1 }
  );
}, 'Test directFromSellerSignals with same fetch and seller origins.');

subsetTest(promise_test, async test => {
  const uuid = generateUuid(test);
  let iframe = await createIframe(test, OTHER_ORIGIN1);
  await runInFrame(test, iframe, `await joinInterestGroup(test_instance, "${uuid}");`);
  await fetchDirectFromSellerSignals({ 'Buyer-Origin': OTHER_ORIGIN1 });
  await runReportTest(
      test, uuid,
      directFromSellerSignalsValidatorCode(
        uuid, 'sellerSignals/4',
        'auctionSignals/4', 'perBuyerSignals/4'),
      // expectedReportURLs
      [createSellerReportURL(uuid), createBidderReportURL(uuid, '1', OTHER_ORIGIN1)],
      // renderURLOverride
      null,
      // auctionConfigOverrides
      { directFromSellerSignalsHeaderAdSlot: 'adSlot/4',
        interestGroupBuyers: [OTHER_ORIGIN1] }
  );
}, 'Test directFromSellerSignals different interest group owner origin from top frame.');

subsetTest(promise_test, async test => {
  const uuid = generateUuid(test);
  let iframe = await createIframe(test, OTHER_ORIGIN1, "join-ad-interest-group; run-ad-auction");
  await fetchDirectFromSellerSignals({ 'Buyer-Origin': OTHER_ORIGIN1 }, OTHER_ORIGIN1);
  await runInFrame(
      test, iframe,
      `await runReportTest(
          test_instance, "${uuid}",
          directFromSellerSignalsValidatorCode(
              "${uuid}", 'sellerSignals/4', 'auctionSignals/4', 'perBuyerSignals/4'),
          // expectedReportURLs
          [createSellerReportURL("${uuid}"), createBidderReportURL("${uuid}")],
          // renderURLOverride
          null,
          // auctionConfigOverrides
          { directFromSellerSignalsHeaderAdSlot: 'adSlot/4' })`);
}, 'Test directFromSellerSignals with fetching in top frame and running auction in iframe.');

subsetTest(promise_test, async test => {
  const uuid = generateUuid(test);
  let iframe = await createIframe(test, OTHER_ORIGIN1, "join-ad-interest-group; run-ad-auction");
  await runInFrame(
      test, iframe,
      `await fetchDirectFromSellerSignals({ 'Buyer-Origin': window.location.origin });
       await runReportTest(
          test_instance, "${uuid}",
          directFromSellerSignalsValidatorCode(
              "${uuid}", 'sellerSignals/4',
              'auctionSignals/4', 'perBuyerSignals/4'),
          // expectedReportURLs
          [createSellerReportURL("${uuid}"), createBidderReportURL("${uuid}")],
          // renderURLOverride
          null,
          // auctionConfigOverrides
          { directFromSellerSignalsHeaderAdSlot: 'adSlot/4' })`);
}, 'Test directFromSellerSignals with fetching and running auction in the same iframe.');

subsetTest(promise_test, async test => {
  const uuid = generateUuid(test);
  let iframe1 = await createIframe(test, OTHER_ORIGIN1);
  let iframe2 = await createIframe(test, OTHER_ORIGIN2, "join-ad-interest-group; run-ad-auction");
  await runInFrame(
      test, iframe1,
      `await fetchDirectFromSellerSignals({ 'Buyer-Origin': OTHER_ORIGIN2 }, OTHER_ORIGIN2);`);
  await runInFrame(
      test, iframe2,
      `await runReportTest(
          test_instance, "${uuid}",
          directFromSellerSignalsValidatorCode(
              "${uuid}", 'sellerSignals/4',
              'auctionSignals/4', 'perBuyerSignals/4'),
          // expectedReportURLs
          [createSellerReportURL("${uuid}"), createBidderReportURL("${uuid}")],
          // renderURLOverride
          null,
          // auctionConfigOverrides
          { directFromSellerSignalsHeaderAdSlot: 'adSlot/4' })`);
}, 'Test directFromSellerSignals with fetching in iframe 1 and running auction in iframe 2.');

subsetTest(promise_test, async test => {
  const uuid = generateUuid(test);
  let iframe = await createIframe(test, OTHER_ORIGIN1);
  await runInFrame(
      test, iframe,
      `await fetchDirectFromSellerSignals(
          { 'Buyer-Origin': "${window.location.origin}" }, "${window.location.origin}");`);
  await runReportTest(
      test, uuid,
      directFromSellerSignalsValidatorCode(
          uuid, 'sellerSignals/4',
          'auctionSignals/4', 'perBuyerSignals/4'),
      // expectedReportURLs
      [createSellerReportURL(uuid), createBidderReportURL(uuid)],
      // renderURLOverride
      null,
      // auctionConfigOverrides
      { directFromSellerSignalsHeaderAdSlot: 'adSlot/4'}
  );
}, 'Test directFromSellerSignals with fetching in iframe and running auction in top frame.');

subsetTest(promise_test, async test => {
  const uuid = generateUuid(test);
  await fetchDirectFromSellerSignals({ 'Negative-Test-Option': 'Network Error' });
  await runReportTest(
      test, uuid,
      directFromSellerSignalsValidatorCode(
          uuid, 'sellerSignals',
          'auctionSignals', /*expectedPerBuyerSignals=*/null),
      // expectedReportURLs
      [createSellerReportURL(uuid), createBidderReportURL(uuid)],
      // renderURLOverride
      null,
      // auctionConfigOverrides
      { directFromSellerSignalsHeaderAdSlot: 'adSlot' }
  );
}, 'Test directFromSellerSignals with network error.');

subsetTest(promise_test, async test => {
  let dfss = false;
  navigator.runAdAuction({
      get directFromSellerSignalsHeaderAdSlot() { dfss = true; }
  }).catch((e) => {});
  assert_true(dfss);
}, 'Test directFromSellerSignals feature detection.');

subsetTest(promise_test, async test => {
  const uuid = generateUuid(test);
  await fetchDirectFromSellerSignals({ 'Buyer-Origin': window.location.origin });
  await fetchDirectFromSellerSignals(
      { 'Buyer-Origin': window.location.origin, 'Alternative-Response': 'Overwrite adSlot/1'});
  await runReportTest(
      test, uuid,
      directFromSellerSignalsValidatorCode(
          uuid, 'altSellerSignals/1',
          /*expectedAuctionSignals=*/null, /*expectedPerBuyerSignals=*/null),
      // expectedReportURLs
      [createSellerReportURL(uuid), createBidderReportURL(uuid)],
      // renderURLOverride
      null,
      // auctionConfigOverrides
      { directFromSellerSignalsHeaderAdSlot: 'adSlot/1' }
  );
}, 'Test directFromSellerSignals with 2 responses -- the later overwrites the former.');

subsetTest(promise_test, async test => {
  const uuid = generateUuid(test);
  await fetchDirectFromSellerSignals({ 'Buyer-Origin': window.location.origin });
  await fetchDirectFromSellerSignals(
      { 'Buyer-Origin': window.location.origin, 'Alternative-Response': 'Overwrite adSlot/1'});
  await fetchDirectFromSellerSignals(
      { 'Buyer-Origin': window.location.origin, 'Alternative-Response': 'Overwrite adSlot/1 v2'});
  await runReportTest(
      test, uuid,
      directFromSellerSignalsValidatorCode(
          uuid, 'altV2SellerSignals/1',
          /*expectedAuctionSignals=*/null, /*expectedPerBuyerSignals=*/null),
      // expectedReportURLs
      [createSellerReportURL(uuid), createBidderReportURL(uuid)],
      // renderURLOverride
      null,
      // auctionConfigOverrides
      { directFromSellerSignalsHeaderAdSlot: 'adSlot/1' }
  );
}, 'Test directFromSellerSignals with 3 responses -- the last response overwrites the former responses.');

subsetTest(promise_test, async test => {
  const uuid = generateUuid(test);
  await fetchDirectFromSellerSignals({ 'Buyer-Origin': window.location.origin });
  await fetchDirectFromSellerSignals(
      { 'Buyer-Origin': window.location.origin, 'Alternative-Response': 'Overwrite adSlot/1'});
  await runReportTest(
      test, uuid,
      directFromSellerSignalsValidatorCode(
          uuid, /*expectedSellerSignals=*/null,
          'auctionSignals/2', /*expectedPerBuyerSignals=*/null),
      // expectedReportURLs
      [createSellerReportURL(uuid), createBidderReportURL(uuid)],
      // renderURLOverride
      null,
      // auctionConfigOverrides
      { directFromSellerSignalsHeaderAdSlot: 'adSlot/2' }
  );
}, 'Test directFromSellerSignals with 2 responses -- old non-overwritten ad slot remains.');

subsetTest(promise_test, async test => {
  const uuid = generateUuid(test);
  await fetchDirectFromSellerSignals(
      { 'Buyer-Origin': window.location.origin, 'Alternative-Response': 'Duplicate adSlot/1'});
  await runReportTest(
      test, uuid,
      directFromSellerSignalsValidatorCode(
          uuid, 'firstSellerSignals/1',
          /*expectedAuctionSignals=*/null, /*expectedPerBuyerSignals=*/null),
      // expectedReportURLs
      [createSellerReportURL(uuid), createBidderReportURL(uuid)],
      // renderURLOverride
      null,
      // auctionConfigOverrides
      { directFromSellerSignalsHeaderAdSlot: 'adSlot/1' }
  );
}, 'Test invalid directFromSellerSignals with duplicate adSlot in response -- the second is ignored.');

subsetTest(promise_test, async test => {
  const uuid = generateUuid(test);
  await fetchDirectFromSellerSignals(
      { 'Buyer-Origin': window.location.origin, 'Alternative-Response': 'Duplicate adSlot/1'});
  await runReportTest(
      test, uuid,
      directFromSellerSignalsValidatorCode(
          uuid, 'nonDupSellerSignals/2',
          /*expectedAuctionSignals=*/null, /*expectedPerBuyerSignals=*/null),
      // expectedReportURLs
      [createSellerReportURL(uuid), createBidderReportURL(uuid)],
      // renderURLOverride
      null,
      // auctionConfigOverrides
      { directFromSellerSignalsHeaderAdSlot: 'adSlot/2' }
  );
}, 'Test invalid directFromSellerSignals with duplicate adSlot in response, selecting a non duplicated adSlot.');

subsetTest(promise_test, async test => {
  const uuid = generateUuid(test);
  await fetchDirectFromSellerSignals(
      { 'Buyer-Origin': window.location.origin,
        'Alternative-Response': 'Two keys with same values'});
  await runReportTest(
      test, uuid,
      directFromSellerSignalsValidatorCode(
          uuid, 'sameSellerSignals',
          'sameAuctionSignals', 'samePerBuyerSignals'),
      // expectedReportURLs
      [createSellerReportURL(uuid), createBidderReportURL(uuid)],
      // renderURLOverride
      null,
      // auctionConfigOverrides
      { directFromSellerSignalsHeaderAdSlot: 'adSlot/1' }
  );
}, 'Test invalid directFromSellerSignals with duplicate values in response.');