-
Notifications
You must be signed in to change notification settings - Fork 3.3k
/
Copy pathget-interest-group-auction-data.https.window.js
849 lines (721 loc) · 32.3 KB
/
get-interest-group-auction-data.https.window.js
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
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
// META: script=/resources/testdriver.js
// META: script=/resources/testdriver-vendor.js
// META: script=/common/utils.js
// META: script=resources/ba-fledge-util.sub.js
// META: script=resources/fledge-util.sub.js
// META: script=third_party/cbor-js/cbor.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-last
"use strict";
// These tests focus on the navigator.getInterestGroupAdAuctionData() method.
// Checks various fields for decoded InterestGroupAdAuctionData that's
// one IG owned by this origin, and returns that IG's info.
function validateWithOneIg(decoded) {
assert_equals(decoded.message.version, 0);
assert_equals(decoded.message.publisher, window.location.hostname);
assert_equals(typeof decoded.message.generationId, 'string');
let igMapKeys = Object.getOwnPropertyNames(decoded.message.interestGroups);
assert_array_equals(igMapKeys, [window.location.origin]);
let igInfo = decoded.message.interestGroups[window.location.origin];
assert_true(igInfo instanceof Array);
assert_equals(igInfo.length, 1, 'number of IGs');
return igInfo[0];
}
subsetTest(promise_test, async test => {
const result = await navigator.getInterestGroupAdAuctionData({
coordinatorOrigin: await BA.configureCoordinator(),
seller: window.location.origin
});
assert_true(result.requestId !== null);
assert_true(result.request.length === 0);
}, 'getInterestGroupAdAuctionData() with no interest groups returns a zero length result.');
async function testInvalidConfig(test, configObj, desc) {
if (!configObj.coordinatorOrigin) {
configObj.coordinatorOrigin = await BA.configureCoordinator();
}
await promise_rejects_js(
test, TypeError, navigator.getInterestGroupAdAuctionData(configObj),
desc);
}
subsetTest(promise_test, async test => {
await testInvalidConfig(test, {}, 'no seller');
await testInvalidConfig(test, {seller: 'example'}, 'invalid seller 1');
await testInvalidConfig(
test, {seller: 'http://example.org'}, 'invalid seller 2');
await testInvalidConfig(
test, {seller: 'https://example.org', coordinatorOrigin: 'example'},
'invalid coordinator 1');
await testInvalidConfig(
test, {seller: 'https://example.org', coordinatorOrigin: 'example.org'},
'invalid coordinator 2');
await testInvalidConfig(
test, {seller: 'https://example.org', perBuyerConfig: {'a': {}}},
'invalid buyer 1');
await testInvalidConfig(
test,
{seller: 'https://example.org', perBuyerConfig: {'http://a.com': {}}},
'invalid buyer 2');
await testInvalidConfig(
test, {
seller: 'https://example.org',
perBuyerConfig: {'https://a.com': {}, 'http://b.com': {}}
},
'invalid buyer 3');
await testInvalidConfig(
test, {
seller: 'https://example.org',
perBuyerConfig: {'https://a.com': {}, 'https://b.com': {}}
},
'missing size info w/per-buyer config 1');
await testInvalidConfig(
test, {
seller: 'https://example.org',
perBuyerConfig:
{'https://a.com': {targetSize: 400}, 'https://b.com': {}}
},
'missing size info w/per-buyer config 2');
// These two actually succeed.
let result = await navigator.getInterestGroupAdAuctionData({
coordinatorOrigin: await BA.configureCoordinator(),
seller: 'https://example.org',
perBuyerConfig:
{'https://a.com': {targetSize: 400}, 'https://b.com': {targetSize: 500}}
});
assert_true(result.requestId !== null);
result = await navigator.getInterestGroupAdAuctionData({
coordinatorOrigin: await BA.configureCoordinator(),
seller: 'https://example.org',
perBuyerConfig: {'https://a.com': {targetSize: 400}, 'https://b.com': {}},
requestSize: 5000
});
assert_true(result.requestId !== null);
}, 'getInterestGroupAdAuctionData() config checks');
subsetTest(promise_test, async test => {
const uuid = generateUuid(test);
await joinInterestGroup(test, uuid);
const result = await navigator.getInterestGroupAdAuctionData({
coordinatorOrigin: await BA.configureCoordinator(),
seller: window.location.origin
});
assert_true(result.requestId !== null);
assert_true(result.request.length > 0);
let decoded = await BA.decodeInterestGroupData(result.request);
// Check that the required field and one IG (but no ad data) are here,
// since we neither provided adRenderIds or asked for full data to be
// included.
let ig = validateWithOneIg(decoded);
assert_equals(ig.name, DEFAULT_INTEREST_GROUP_NAME);
assert_array_equals(ig.ads, []);
assert_equals(ig.browserSignals.joinCount, 1, 'joinCount');
assert_equals(ig.browserSignals.bidCount, 0, 'bidCount');
assert_array_equals(ig.browserSignals.prevWins, []);
}, 'getInterestGroupAdAuctionData() with one interest group returns a valid result.');
subsetTest(promise_test, async test => {
const uuid = generateUuid(test);
await joinInterestGroup(test, uuid, {
ads: [
{renderURL: createRenderURL(uuid) + '&a', adRenderId: 'a'},
{renderURL: createRenderURL(uuid) + '&a', adRenderId: 'b'}
]
});
const result = await navigator.getInterestGroupAdAuctionData({
coordinatorOrigin: await BA.configureCoordinator(),
seller: window.location.origin
});
assert_true(result.requestId !== null);
assert_true(result.request.length > 0);
let decoded = await BA.decodeInterestGroupData(result.request);
let ig = validateWithOneIg(decoded);
// This ig should have two ads with adRenderIds, but not URLs.
assert_equals(ig.name, DEFAULT_INTEREST_GROUP_NAME);
assert_array_equals(ig.ads, ['a', 'b']);
assert_equals(ig.browserSignals.joinCount, 1, 'joinCount');
assert_equals(ig.browserSignals.bidCount, 0, 'bidCount');
assert_array_equals(ig.browserSignals.prevWins, []);
}, 'getInterestGroupAdAuctionData() with one interest group with two ads w/renderIds.');
subsetTest(promise_test, async test => {
const uuid = generateUuid(test);
await joinInterestGroup(test, uuid, {
auctionServerRequestFlags: ['omit-ads'],
ads: [
{renderURL: createRenderURL(uuid) + '&a', adRenderId: 'a'},
{renderURL: createRenderURL(uuid) + '&a', adRenderId: 'b'}
]
});
const result = await navigator.getInterestGroupAdAuctionData({
coordinatorOrigin: await BA.configureCoordinator(),
seller: window.location.origin
});
assert_true(result.requestId !== null);
assert_true(result.request.length > 0);
let decoded = await BA.decodeInterestGroupData(result.request);
let ig = validateWithOneIg(decoded);
assert_equals(ig.name, DEFAULT_INTEREST_GROUP_NAME);
assert_not_own_property(ig, 'ads', 'no ads expected');
assert_equals(ig.browserSignals.joinCount, 1, 'joinCount');
}, 'getInterestGroupAdAuctionData() with one interest group with two ads w/renderIds and omit-ads.');
subsetTest(promise_test, async test => {
const uuid = generateUuid(test);
const adsArray = [
{renderURL: createRenderURL(uuid) + '&a', adRenderId: 'a'},
{renderURL: createRenderURL(uuid) + '&a', adRenderId: 'b'}
];
await joinInterestGroup(
test, uuid,
{auctionServerRequestFlags: ['include-full-ads'], ads: adsArray});
const result = await navigator.getInterestGroupAdAuctionData({
coordinatorOrigin: await BA.configureCoordinator(),
seller: window.location.origin
});
assert_true(result.requestId !== null);
assert_true(result.request.length > 0);
let decoded = await BA.decodeInterestGroupData(result.request);
let ig = validateWithOneIg(decoded);
// Since include-full-ads is on, this gets entire objects, not just
// adRenderId.
assert_equals(ig.name, DEFAULT_INTEREST_GROUP_NAME);
assert_equals(ig.ads.length, 2, '# of ads');
assert_equals(ig.ads[0].renderURL, adsArray[0].renderURL, 'renderURL 0');
assert_equals(ig.ads[1].renderURL, adsArray[1].renderURL, 'renderURL 1');
assert_equals(ig.ads[0].adRenderId, adsArray[0].adRenderId, 'adRenderId 0');
assert_equals(ig.ads[1].adRenderId, adsArray[1].adRenderId, 'adRenderId 1');
assert_equals(ig.browserSignals.joinCount, 1, 'joinCount');
}, 'getInterestGroupAdAuctionData() with one interest group with two ads w/renderIds and include-full-ads.');
// Returns an AuctionAdInterestGroup that sets all fields that can be exported
// via getInterestGroupAdAuctionData().
function makeTemplateIgConfig(uuid) {
const adsArray = [
{
renderURL: createRenderURL(uuid) + '&a',
adRenderId: 'a',
metadata: 'ada',
sizeGroup: 'small'
},
{
renderURL: createRenderURL(uuid) + '&b',
adRenderId: 'b',
metadata: 'adb',
sizeGroup: 'big'
}
];
const adComponentsArray = [
{
renderURL: 'https://example.org/ca',
adRenderId: 'ca',
metadata: 'compa',
sizeGroup: 'big'
},
{
renderURL: 'https://example.org/cb',
adRenderId: 'cb',
metadata: 'compb',
sizeGroup: 'small'
},
{
renderURL: 'https://example.org/cc',
adRenderId: 'cc',
metadata: 'compc',
sizeGroup: 'big'
},
];
return {
ads: adsArray,
adComponents: adComponentsArray,
adSizes: {
's': {width: '100px', height: '30px'},
'xl': {width: '1000px', height: '300px'}
},
sizeGroups: {'small': ['s'], 'big': ['xl']},
trustedBiddingSignalsKeys: ['alpha', 'beta'],
userBiddingSignals: 14
};
}
subsetTest(promise_test, async test => {
const uuid = generateUuid(test);
const igConfig = makeTemplateIgConfig(uuid);
igConfig.auctionServerRequestFlags = ['include-full-ads'];
await joinInterestGroup(test, uuid, igConfig);
const result = await navigator.getInterestGroupAdAuctionData({
coordinatorOrigin: await BA.configureCoordinator(),
seller: window.location.origin
});
assert_true(result.requestId !== null);
assert_true(result.request.length > 0);
let decoded = await BA.decodeInterestGroupData(result.request);
let ig = validateWithOneIg(decoded);
assert_equals(ig.name, DEFAULT_INTEREST_GROUP_NAME);
assert_true(ig.ads instanceof Array);
assert_equals(ig.ads.length, 2, '# of ads');
assert_equals(ig.ads[0].renderURL, igConfig.ads[0].renderURL, 'renderURL 0');
assert_equals(ig.ads[1].renderURL, igConfig.ads[1].renderURL, 'renderURL 1');
assert_equals(ig.ads[0].adRenderId, 'a', 'adRenderId 0');
assert_equals(ig.ads[1].adRenderId, 'b', 'adRenderId 1');
assert_equals(ig.ads[0].metadata, '"ada"', 'metadata 0');
assert_equals(ig.ads[1].metadata, '"adb"', 'metadata 1');
assert_equals(ig.ads[0].sizeGroup, 'small', 'sizegroup 0');
assert_equals(ig.ads[1].sizeGroup, 'big', 'sizegroup 1');
assert_true(ig.components instanceof Array);
assert_equals(ig.components.length, 3, '# of component ads');
assert_equals(
ig.components[0].renderURL, igConfig.adComponents[0].renderURL,
'component renderURL 0');
assert_equals(
ig.components[1].renderURL, igConfig.adComponents[1].renderURL,
'component renderURL 1');
assert_equals(
ig.components[2].renderURL, igConfig.adComponents[2].renderURL,
'component renderURL 2');
assert_equals(ig.components[0].adRenderId, 'ca', 'component adRenderId 0');
assert_equals(ig.components[1].adRenderId, 'cb', 'component adRenderId 1');
assert_equals(ig.components[2].adRenderId, 'cc', 'component adRenderId 2');
assert_equals(ig.components[0].metadata, '"compa"', 'component metadata 0');
assert_equals(ig.components[1].metadata, '"compb"', 'component metadata 1');
assert_equals(ig.components[2].metadata, '"compc"', 'component metadata 2');
assert_equals(ig.components[0].sizeGroup, 'big', 'component sizegroup 0');
assert_equals(ig.components[1].sizeGroup, 'small', 'component sizegroup 1');
assert_equals(ig.components[2].sizeGroup, 'big', 'component sizegroup 2');
assert_true(ig.biddingSignalsKeys instanceof Array);
assert_array_equals(ig.biddingSignalsKeys, ['alpha', 'beta']);
assert_equals(ig.userBiddingSignals, '14');
}, 'getInterestGroupAdAuctionData() all IG data fields, with include-full-ads');
subsetTest(promise_test, async test => {
const uuid = generateUuid(test);
const igConfig = makeTemplateIgConfig(uuid);
await joinInterestGroup(test, uuid, igConfig);
const result = await navigator.getInterestGroupAdAuctionData({
coordinatorOrigin: await BA.configureCoordinator(),
seller: window.location.origin
});
assert_true(result.requestId !== null);
assert_true(result.request.length > 0);
let decoded = await BA.decodeInterestGroupData(result.request);
let ig = validateWithOneIg(decoded);
assert_equals(ig.name, DEFAULT_INTEREST_GROUP_NAME);
assert_array_equals(ig.ads, ['a', 'b']);
assert_true(ig.components instanceof Array);
assert_array_equals(ig.ads, ['a', 'b']);
assert_array_equals(ig.components, ['ca', 'cb', 'cc']);
assert_array_equals(ig.biddingSignalsKeys, ['alpha', 'beta']);
assert_equals(ig.userBiddingSignals, '14');
}, 'getInterestGroupAdAuctionData() all IG data fields, w/o include-full-ads');
subsetTest(promise_test, async test => {
const uuid = generateUuid(test);
const igConfig = makeTemplateIgConfig(uuid);
igConfig.auctionServerRequestFlags = ['omit-user-bidding-signals'];
await joinInterestGroup(test, uuid, igConfig);
const result = await navigator.getInterestGroupAdAuctionData({
coordinatorOrigin: await BA.configureCoordinator(),
seller: window.location.origin
});
assert_true(result.requestId !== null);
assert_true(result.request.length > 0);
let decoded = await BA.decodeInterestGroupData(result.request);
let ig = validateWithOneIg(decoded);
assert_equals(ig.name, DEFAULT_INTEREST_GROUP_NAME);
assert_array_equals(ig.ads, ['a', 'b']);
assert_true(ig.components instanceof Array);
assert_array_equals(ig.ads, ['a', 'b']);
assert_array_equals(ig.components, ['ca', 'cb', 'cc']);
assert_array_equals(ig.biddingSignalsKeys, ['alpha', 'beta']);
assert_false('userBiddingSignals' in ig, 'userBiddingSignals');
}, 'getInterestGroupAdAuctionData() all IG data fields, with omit-user-bidding-signals');
subsetTest(promise_test, async test => {
const uuid = generateUuid(test);
const igConfig = makeTemplateIgConfig(uuid);
// Join twice.
await joinInterestGroup(test, uuid, igConfig);
await joinInterestGroup(test, uuid, igConfig);
// And run an auction. This is a local auction, not a B&A one, run to update
// bid/win stats.
await runBasicFledgeAuctionAndNavigate(test, uuid);
await waitForObservedRequests(
uuid, [createBidderReportURL(uuid), createSellerReportURL(uuid)]);
const result = await navigator.getInterestGroupAdAuctionData({
coordinatorOrigin: await BA.configureCoordinator(),
seller: window.location.origin
});
assert_true(result.requestId !== null);
assert_true(result.request.length > 0);
let decoded = await BA.decodeInterestGroupData(result.request);
let ig = validateWithOneIg(decoded);
assert_equals(ig.browserSignals.joinCount, 2, 'joinCount');
assert_equals(ig.browserSignals.bidCount, 1, 'bidCount');
// RecencyMs is the # of milliseconds since the join. We can't exactly say
// what it is, but it shouldn't be too huge.
assert_true(typeof ig.browserSignals.recencyMs === 'number');
assert_between_inclusive(
ig.browserSignals.recencyMs, 0, 60000,
'RecencyMs is between 0 and 60 seconds');
// It's also supposed to be an integer.
assert_equals(
ig.browserSignals.recencyMs, Math.round(ig.browserSignals.recencyMs),
'RecencyMs is an integer');
// One win. The format here depends highly on whether full ads are used or
// not.
assert_true(
ig.browserSignals.prevWins instanceof Array, 'prevWins is an array');
assert_equals(ig.browserSignals.prevWins.length, 1, 'prevWins length');
assert_true(
ig.browserSignals.prevWins[0] instanceof Array,
'prevWins[0] is an array');
assert_equals(ig.browserSignals.prevWins[0].length, 2, 'prevWins[0] length');
// prevWins[0][0] is the time delta in second again.
let prevWinTime = ig.browserSignals.prevWins[0][0];
assert_true(typeof prevWinTime === 'number');
assert_between_inclusive(
prevWinTime, 0, 60, 'prevWinTime is between 0 and 60 seconds');
// It's also supposed to be an integer.
assert_equals(
prevWinTime, Math.round(prevWinTime), 'prevWinTime is an integer');
// prevWins[0][1] is the adRenderId of the winner.
assert_equals(ig.browserSignals.prevWins[0][1], 'a');
}, 'getInterestGroupAdAuctionData() browserSignals');
subsetTest(promise_test, async test => {
const uuid = generateUuid(test);
const igConfig = makeTemplateIgConfig(uuid);
igConfig.auctionServerRequestFlags = ['include-full-ads'];
// Join twice.
await joinInterestGroup(test, uuid, igConfig);
await joinInterestGroup(test, uuid, igConfig);
// And run an auction. This is a local auction, not a B&A one, run to update
// bid/win stats.
await runBasicFledgeAuctionAndNavigate(test, uuid);
await waitForObservedRequests(
uuid, [createBidderReportURL(uuid), createSellerReportURL(uuid)]);
const result = await navigator.getInterestGroupAdAuctionData({
coordinatorOrigin: await BA.configureCoordinator(),
seller: window.location.origin
});
assert_true(result.requestId !== null);
assert_true(result.request.length > 0);
let decoded = await BA.decodeInterestGroupData(result.request);
let ig = validateWithOneIg(decoded);
assert_equals(ig.browserSignals.joinCount, 2, 'joinCount');
assert_equals(ig.browserSignals.bidCount, 1, 'bidCount');
// RecencyMs is the # of milliseconds since the join. We can't exactly say
// what it is, but it shouldn't be too huge.
assert_true(typeof ig.browserSignals.recencyMs === 'number');
assert_between_inclusive(
ig.browserSignals.recencyMs, 0, 60000,
'RecencyMs is between 0 and 60 seconds');
// It's also supposed to be an integer.
assert_equals(
ig.browserSignals.recencyMs, Math.round(ig.browserSignals.recencyMs),
'RecencyMs is an integer');
// One win. The format here depends highly on whether full ads are used or
// not.
assert_true(
ig.browserSignals.prevWins instanceof Array, 'prevWins is an array');
assert_equals(ig.browserSignals.prevWins.length, 1, 'prevWins length');
assert_true(
ig.browserSignals.prevWins[0] instanceof Array,
'prevWins[0] is an array');
assert_equals(ig.browserSignals.prevWins[0].length, 2, 'prevWins[0] length');
// prevWins[0][0] is the time delta in second again.
let prevWinTime = ig.browserSignals.prevWins[0][0];
assert_true(typeof prevWinTime === 'number');
assert_between_inclusive(
prevWinTime, 0, 60, 'prevWinTime is between 0 and 60 seconds');
// It's also supposed to be an integer.
assert_equals(
prevWinTime, Math.round(prevWinTime), 'prevWinTime is an integer');
// prevWins[0][1] is an ad object w/include-full-ads on (with renderURL,
// metadata, and adRenderId).
let prevWinAd = ig.browserSignals.prevWins[0][1];
assert_equals(
prevWinAd.renderURL, igConfig.ads[0].renderURL, 'prevWin ad renderURL');
assert_equals(prevWinAd.metadata, '"ada"', 'prevWin ad metadata');
assert_equals(prevWinAd.adRenderId, 'a', 'prevWin ad adRenderId');
}, 'getInterestGroupAdAuctionData() browserSignals with include-full-ads');
subsetTest(promise_test, async test => {
const uuid = generateUuid(test);
const igTemplate = makeTemplateIgConfig(uuid);
await joinInterestGroup(test, uuid, {...igTemplate, name: 'first'});
await joinInterestGroup(test, uuid, {...igTemplate, name: 'second'});
const result = await navigator.getInterestGroupAdAuctionData({
coordinatorOrigin: await BA.configureCoordinator(),
seller: window.location.origin
});
assert_true(result.requestId !== null);
assert_true(result.request.length > 0);
let decoded = await BA.decodeInterestGroupData(result.request);
assert_equals(decoded.message.version, 0);
assert_equals(decoded.message.publisher, window.location.hostname);
assert_equals(typeof decoded.message.generationId, 'string');
let origin = window.location.origin;
let igMapKeys = Object.getOwnPropertyNames(decoded.message.interestGroups);
assert_array_equals(igMapKeys, [origin]);
assert_equals(decoded.message.interestGroups[origin].length, 2);
let names = [
decoded.message.interestGroups[origin][0].name,
decoded.message.interestGroups[origin][1].name
];
assert_array_equals(names.sort(), ['first', 'second']);
}, 'getInterestGroupAdAuctionData() with multiple interest groups');
async function joinCrossOriginIG(test, uuid, origin, name) {
let iframe = await createIframe(test, origin, 'join-ad-interest-group');
await runInFrame(
test, iframe,
`await joinInterestGroup(test_instance, "${uuid}", {name: "${name}"});`);
}
subsetTest(promise_test, async test => {
const uuid = generateUuid(test);
await joinCrossOriginIG(test, uuid, OTHER_ORIGIN1, 'o1');
await joinCrossOriginIG(test, uuid, OTHER_ORIGIN2, 'o2');
await joinCrossOriginIG(test, uuid, OTHER_ORIGIN3, 'o3');
await joinCrossOriginIG(test, uuid, OTHER_ORIGIN4, 'o4');
const result = await navigator.getInterestGroupAdAuctionData({
coordinatorOrigin: await BA.configureCoordinator(),
seller: window.location.origin
});
assert_true(result.requestId !== null);
assert_true(result.request.length > 0);
let decoded = await BA.decodeInterestGroupData(result.request);
assert_equals(decoded.message.version, 0);
assert_equals(decoded.message.publisher, window.location.hostname);
assert_equals(typeof decoded.message.generationId, 'string');
let igMapKeys = Object.getOwnPropertyNames(decoded.message.interestGroups);
assert_array_equals(
igMapKeys.sort(),
[OTHER_ORIGIN1, OTHER_ORIGIN2, OTHER_ORIGIN3, OTHER_ORIGIN4].sort());
assert_equals(decoded.message.interestGroups[OTHER_ORIGIN1].length, 1);
assert_equals(decoded.message.interestGroups[OTHER_ORIGIN1][0].name, 'o1');
assert_equals(decoded.message.interestGroups[OTHER_ORIGIN2].length, 1);
assert_equals(decoded.message.interestGroups[OTHER_ORIGIN2][0].name, 'o2');
assert_equals(decoded.message.interestGroups[OTHER_ORIGIN3].length, 1);
assert_equals(decoded.message.interestGroups[OTHER_ORIGIN3][0].name, 'o3');
assert_equals(decoded.message.interestGroups[OTHER_ORIGIN4].length, 1);
assert_equals(decoded.message.interestGroups[OTHER_ORIGIN4][0].name, 'o4');
}, 'getInterestGroupAdAuctionData() with multiple buyers');
subsetTest(promise_test, async test => {
const uuid = generateUuid(test);
let renderURL = createRenderURL(uuid);
let bidderDebugReportURL =
createBidderReportURL(uuid, /*id=*/ 'forDebuggingOnly');
let biddingLogicURL = createBiddingScriptURL({
generateBid: `
forDebuggingOnly.reportAdAuctionWin('${bidderDebugReportURL}');
return {bid: 1, render: '${renderURL}'};`
});
await Promise.all([
joinInterestGroup(
test, uuid,
{name: 'o1', ads: [{renderURL: renderURL}], biddingLogicURL}),
joinInterestGroup(
test, uuid,
{name: 'o2', ads: [{renderURL: renderURL}], biddingLogicURL})
]);
// Run an auction to put the origin to cooldown, or lockout.
await runBasicFledgeAuctionAndNavigate(test, uuid);
const result = await navigator.getInterestGroupAdAuctionData({
coordinatorOrigin: await BA.configureCoordinator(),
seller: window.location.origin
});
assert_true(result.requestId !== null);
assert_true(result.request.length > 0);
let decoded = await BA.decodeInterestGroupData(result.request);
assert_equals(decoded.message.version, 0);
assert_equals(decoded.message.publisher, window.location.hostname);
assert_equals(typeof decoded.message.generationId, 'string');
assert_equals(
decoded.message.interestGroups[window.location.origin].length, 2);
assert_equals(
decoded.message.interestGroups[window.location.origin][0]
.inCooldownOrLockout,
true);
assert_equals(
decoded.message.interestGroups[window.location.origin][1]
.inCooldownOrLockout,
true);
}, 'getInterestGroupAdAuctionData() InCooldownOrLockout in each IG');
subsetTest(promise_test, async test => {
const uuid = generateUuid(test);
await joinCrossOriginIG(test, uuid, OTHER_ORIGIN1, 'o1');
await joinCrossOriginIG(test, uuid, OTHER_ORIGIN2, 'o2');
await joinCrossOriginIG(test, uuid, OTHER_ORIGIN3, 'o3');
await joinCrossOriginIG(test, uuid, OTHER_ORIGIN4, 'o4');
let config = {
coordinatorOrigin: await BA.configureCoordinator(),
seller: window.location.origin,
perBuyerConfig: {},
requestSize: 5000
};
config.perBuyerConfig[OTHER_ORIGIN2] = {};
config.perBuyerConfig[OTHER_ORIGIN3] = {};
const result = await navigator.getInterestGroupAdAuctionData(config);
assert_true(result.requestId !== null);
assert_true(result.request.length > 0);
let decoded = await BA.decodeInterestGroupData(result.request);
assert_equals(decoded.message.version, 0);
assert_equals(decoded.message.publisher, window.location.hostname);
assert_equals(typeof decoded.message.generationId, 'string');
let igMapKeys = Object.getOwnPropertyNames(decoded.message.interestGroups);
assert_array_equals(igMapKeys.sort(), [OTHER_ORIGIN2, OTHER_ORIGIN3].sort());
assert_equals(decoded.message.interestGroups[OTHER_ORIGIN2].length, 1);
assert_equals(decoded.message.interestGroups[OTHER_ORIGIN2][0].name, 'o2');
assert_equals(decoded.message.interestGroups[OTHER_ORIGIN3].length, 1);
assert_equals(decoded.message.interestGroups[OTHER_ORIGIN3][0].name, 'o3');
}, 'getInterestGroupAdAuctionData() uses perBuyerConfig to select buyers');
subsetTest(promise_test, async test => {
const uuid = generateUuid(test);
await joinInterestGroup(test, uuid);
const result = await navigator.getInterestGroupAdAuctionData({
coordinatorOrigin: await BA.configureCoordinator(),
seller: window.location.origin
});
assert_true(result.requestId !== null);
assert_true(result.request.length > 0);
let decoded = await BA.decodeInterestGroupData(result.request);
assert_own_property(decoded.message, 'enforceKAnon');
assert_equals(decoded.message.enforceKAnon, true);
}, 'getInterestGroupAdAuctionData() requests k-anon.');
/*************************************************************************
* Tests for the multi-seller variant of the API
*************************************************************************/
async function validateForSeller(adAuctionData, seller) {
assert_equals(adAuctionData.seller, seller);
assert_not_own_property(adAuctionData, 'error');
assert_own_property(adAuctionData, 'request');
assert_true(adAuctionData.request.length > 0);
let decoded = await BA.decodeInterestGroupData(adAuctionData.request);
let ig = validateWithOneIg(decoded);
assert_equals(ig.name, DEFAULT_INTEREST_GROUP_NAME);
assert_array_equals(ig.ads, ['a', 'b']);
assert_true(ig.components instanceof Array);
assert_array_equals(ig.components, ['ca', 'cb', 'cc']);
assert_array_equals(ig.biddingSignalsKeys, ['alpha', 'beta']);
assert_equals(ig.userBiddingSignals, '14');
}
subsetTest(promise_test, async test => {
const uuid = generateUuid(test);
const igConfig = makeTemplateIgConfig(uuid);
await joinInterestGroup(test, uuid, igConfig);
const result = await navigator.getInterestGroupAdAuctionData({
sellers: [{
coordinatorOrigin: await BA.configureCoordinator(),
seller: window.location.origin,
}]
});
assert_true(result.requestId !== null);
assert_own_property(result, 'requests');
assert_equals(result.requests.length, 1);
await validateForSeller(result.requests[0], window.location.origin);
}, 'getInterestGroupAdAuctionData() multi-seller with single seller');
subsetTest(promise_test, async test => {
const uuid = generateUuid(test);
const igConfig = makeTemplateIgConfig(uuid);
await joinInterestGroup(test, uuid, igConfig);
const result = await navigator.getInterestGroupAdAuctionData({
sellers: [{
coordinatorOrigin: await BA.configureCoordinator(),
seller: window.location.origin,
}, {
coordinatorOrigin: await BA.configureCoordinator(),
seller: OTHER_ORIGIN1,
}]
});
assert_true(result.requestId !== null);
assert_own_property(result, 'requests');
assert_equals(result.requests.length, 2, JSON.stringify(result));
result.requests.sort((a,b)=> (a.seller < b.seller ? -1 : +(a.seller > b.seller)));
await validateForSeller(result.requests[0], OTHER_ORIGIN1);
await validateForSeller(result.requests[1], window.location.origin);
assert_not_equals(result.requests[0].request.toString(), result.requests[1].request.toString());
}, 'getInterestGroupAdAuctionData() multi-seller with multiple sellers - valid');
subsetTest(promise_test, async test => {
const uuid = generateUuid(test);
const igConfig = makeTemplateIgConfig(uuid);
await joinInterestGroup(test, uuid, igConfig);
const result = await navigator.getInterestGroupAdAuctionData({
sellers: [{
coordinatorOrigin: await BA.configureCoordinator(),
seller: window.location.origin,
}, {
coordinatorOrigin: "https://invalid.coordinator.test/",
seller: OTHER_ORIGIN1,
}]
});
assert_true(result.requestId !== null);
assert_own_property(result, 'requests');
assert_equals(result.requests.length, 2, JSON.stringify(result));
result.requests.sort((a,b)=> (a.seller < b.seller ? -1 : +(a.seller > b.seller)));
assert_equals(result.requests[0].seller, OTHER_ORIGIN1);
assert_own_property(result.requests[0], 'error');
assert_not_own_property(result.requests[0], 'request');
await validateForSeller(result.requests[1], window.location.origin);
}, 'getInterestGroupAdAuctionData() multi-seller with multiple sellers - one invalid coordinator');
subsetTest(promise_test, async test => {
const uuid = generateUuid(test);
const igConfig = makeTemplateIgConfig(uuid);
await joinInterestGroup(test, uuid, igConfig);
await promise_rejects_js(test, TypeError, navigator.getInterestGroupAdAuctionData({
sellers: [{
coordinatorOrigin: await BA.configureCoordinator(),
seller: window.location.origin,
}, {
coordinatorOrigin: await BA.configureCoordinator(),
seller: "http://not.secure.test/",
}]
}));
}, 'getInterestGroupAdAuctionData() multi-seller with multiple sellers - one invalid seller');
subsetTest(promise_test, async test => {
const uuid = generateUuid(test);
const igConfig = makeTemplateIgConfig(uuid);
await joinInterestGroup(test, uuid, igConfig);
await promise_rejects_js(test, TypeError, navigator.getInterestGroupAdAuctionData({
}));
}, 'getInterestGroupAdAuctionData() one of "seller" and "sellers" is required');
subsetTest(promise_test, async test => {
const uuid = generateUuid(test);
const igConfig = makeTemplateIgConfig(uuid);
await joinInterestGroup(test, uuid, igConfig);
await promise_rejects_js(test, TypeError, navigator.getInterestGroupAdAuctionData({
seller: window.location.origin,
sellers: [{
coordinatorOrigin: await BA.configureCoordinator(),
seller: window.location.origin,
}]
}));
}, 'getInterestGroupAdAuctionData() doesn\'t allow "seller" and "sellers" fields');
subsetTest(promise_test, async test => {
const uuid = generateUuid(test);
const igConfig = makeTemplateIgConfig(uuid);
await joinInterestGroup(test, uuid, igConfig);
await promise_rejects_js(test, TypeError, navigator.getInterestGroupAdAuctionData({
coordinatorOrigin: window.location.origin,
sellers: [{
coordinatorOrigin: await BA.configureCoordinator(),
seller: window.location.origin,
}]
}));
}, 'getInterestGroupAdAuctionData() doesn\'t allow "coordinatorOrigin" and "sellers" fields');
subsetTest(promise_test, async test => {
const uuid = generateUuid(test);
const igConfig = makeTemplateIgConfig(uuid);
await joinInterestGroup(test, uuid, igConfig);
await promise_rejects_js(test, TypeError, navigator.getInterestGroupAdAuctionData({
sellers: [{
coordinatorOrigin: await BA.configureCoordinator(),
seller: window.location.origin,
}, {
coordinatorOrigin: await BA.configureCoordinator(),
seller: window.location.origin,
}
]
}));
}, 'getInterestGroupAdAuctionData() doesn\'t allow duplicate sellers in "sellers" field');
subsetTest(promise_test, async test => {
const uuid = generateUuid(test);
const igConfig = makeTemplateIgConfig(uuid);
await joinInterestGroup(test, uuid, igConfig);
const result = await navigator.getInterestGroupAdAuctionData({
sellers: []
});
assert_equals(result.requestId, "");
assert_array_equals(result.requests, []);
}, 'getInterestGroupAdAuctionData() with no sellers');