tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

auction-config-passed-to-worklets.https.window.js (8612B)


      1 // META: script=/resources/testdriver.js
      2 // META: script=/resources/testdriver-vendor.js
      3 // META: script=/common/utils.js
      4 // META: script=resources/fledge-util.sub.js
      5 // META: script=/common/subset-tests.js
      6 // META: timeout=long
      7 // META: variant=?1-5
      8 // META: variant=?6-10
      9 // META: variant=?11-15
     10 // META: variant=?16-20
     11 // META: variant=?21-25
     12 // META: variant=?26-30
     13 // META: variant=?30-last
     14 
     15 "use strict";
     16 
     17 // These tests focus on making sure AuctionConfig fields are passed to seller worklets,
     18 // and are normalized if necessary. This test does not check the behaviors of the
     19 // fields.
     20 
     21 const makeTest = ({
     22  // Test name.
     23  name,
     24  // AuctionConfig field name.
     25  fieldName,
     26  // AuctionConfig field value, both expected in worklets and acution in the
     27  // auction. If undefined, value will not be set in auctionConfig, and will
     28  // be expected to also not be set in the auctionConfig passed to worklets.
     29  fieldValue,
     30  // Additional values to use in the AuctionConfig passed to runAdAuction().
     31  // If it contains a value for the key specified in `fieldName`, that takes
     32  // precedent over `fieldValue`.
     33  auctionConfigOverrides = {}
     34 }) => {
     35  subsetTest(promise_test, async test => {
     36    const uuid = generateUuid(test);
     37 
     38    if (!(fieldName in auctionConfigOverrides) && fieldValue !== undefined)
     39      auctionConfigOverrides[fieldName] = fieldValue;
     40 
     41    let comparison = `deepEquals(auctionConfig["${fieldName}"], ${JSON.stringify(fieldValue)})`;
     42    // In the case it's undefined, require value not to be set.
     43    if (fieldValue === undefined)
     44      comparison = `!("${fieldName}" in auctionConfig)`;
     45 
     46    // Prefer to use `auctionConfigOverrides.seller` if present. Treat it as a URL
     47    // and then convert it to an origin because one test passes in a URL.
     48    let origin = location.origin;
     49    if (auctionConfigOverrides.seller)
     50      origin = new URL(auctionConfigOverrides.seller).origin;
     51 
     52    auctionConfigOverrides.decisionLogicURL = createDecisionScriptURL(
     53      uuid,
     54      { origin: origin,
     55        scoreAd:
     56            `if (!${comparison})
     57               throw "Unexpected value: " + JSON.stringify(auctionConfig["${fieldName}"]);`,
     58        reportResult:
     59            `let error = '';
     60             if (!${comparison})
     61               error += "_unexpected_value:" + JSON.stringify(auctionConfig["${fieldName}"]);
     62             sendReportTo("${createSellerReportURL(uuid)}" + error);` }),
     63 
     64    // Join an interest group so the auction has a winner. The details of the
     65    // interest group do not matter.
     66    await joinInterestGroup(test, uuid);
     67    await runBasicFledgeAuctionAndNavigate(test, uuid, auctionConfigOverrides);
     68    await waitForObservedRequests(
     69        uuid, [createBidderReportURL(uuid), createSellerReportURL(uuid)]);
     70  }, name);
     71 };
     72 
     73 makeTest({
     74  name: 'AuctionConfig.seller.',
     75  fieldName: 'seller',
     76  fieldValue: OTHER_ORIGIN1
     77 });
     78 
     79 makeTest({
     80  name: 'AuctionConfig.seller with non-normalized origin.',
     81  fieldName: 'seller',
     82  fieldValue: OTHER_ORIGIN1,
     83  auctionConfigOverrides: {seller: ` ${OTHER_ORIGIN1.toUpperCase()} `}
     84 });
     85 
     86 makeTest({
     87  name: 'AuctionConfig.deprecatedRenderURLReplacements with brackets.',
     88  fieldName: 'deprecatedRenderURLReplacements',
     89  fieldValue: {'${EXAMPLE_MACRO}': 'SSP'},
     90 });
     91 
     92 makeTest({
     93  name: 'AuctionConfig.deprecatedRenderURLReplacements with percents.',
     94  fieldName: 'deprecatedRenderURLReplacements',
     95  fieldValue: {'%%EXAMPLE_MACRO%%': 'SSP'},
     96 });
     97 
     98 makeTest({
     99  name: 'AuctionConfig.seller is URL.',
    100  fieldName: 'seller',
    101  fieldValue: OTHER_ORIGIN1,
    102  auctionConfigOverrides: {seller: OTHER_ORIGIN1 + "/Foopy"}
    103 });
    104 
    105 makeTest({
    106  name: 'AuctionConfig.trustedScoringSignalsURL passed to seller worklets.',
    107  fieldName: 'trustedScoringSignalsURL',
    108  fieldValue: `${OTHER_ORIGIN1}${BASE_PATH}this-file-does-not-exist.json`,
    109  auctionConfigOverrides: {seller: OTHER_ORIGIN1}
    110 });
    111 
    112 makeTest({
    113  name: 'AuctionConfig.trustedScoringSignalsURL with non-normalized values.',
    114  fieldName: 'trustedScoringSignalsURL',
    115  fieldValue: `${OTHER_ORIGIN1}${BASE_PATH}this-file-does-not-exist.json`,
    116  auctionConfigOverrides: {
    117    seller: OTHER_ORIGIN1,
    118    trustedScoringSignalsURL:
    119        `${OTHER_ORIGIN1.toUpperCase()}${BASE_PATH}this-file-does-not-exist.json`
    120  }
    121 });
    122 
    123 makeTest({
    124  name: 'AuctionConfig.trustedScoringSignalsKeys not set.',
    125  fieldName: 'trustedScoringSignalsKeys',
    126  fieldValue: undefined
    127 });
    128 
    129 makeTest({
    130  name: 'AuctionConfig.interestGroupBuyers.',
    131  fieldName: 'interestGroupBuyers',
    132  fieldValue: [OTHER_ORIGIN1, location.origin, OTHER_ORIGIN2]
    133 });
    134 
    135 makeTest({
    136  name: 'AuctionConfig.interestGroupBuyers with non-normalized values.',
    137  fieldName: 'interestGroupBuyers',
    138  fieldValue: [OTHER_ORIGIN1, location.origin, OTHER_ORIGIN2],
    139  auctionConfigOverrides: {
    140    interestGroupBuyers: [
    141        ` ${OTHER_ORIGIN1} `,
    142        location.origin.toUpperCase(),
    143        `${OTHER_ORIGIN2}/Foo`]
    144  }
    145 });
    146 
    147 makeTest({
    148  name: 'AuctionConfig.nonStandardField.',
    149  fieldName: 'nonStandardField',
    150  fieldValue: undefined,
    151  aucitonConfigOverrides: {nonStandardField: 'This value should not be passed to worklets'}
    152 });
    153 
    154 makeTest({
    155  name: 'AuctionConfig.requestedSize not set.',
    156  fieldName: 'requestedSize',
    157  fieldValue: undefined
    158 });
    159 
    160 makeTest({
    161  name: 'AuctionConfig.requestedSize in pixels.',
    162  fieldName: 'requestedSize',
    163  fieldValue: {width: '100px', height: '200px'}
    164 });
    165 
    166 makeTest({
    167  name: 'AuctionConfig.requestedSize in implicit pixels.',
    168  fieldName: 'requestedSize',
    169  fieldValue: {width: '100px', height: '200px'},
    170  auctionConfigOverrides: {fieldValue: {width: '100', height: '200'}}
    171 });
    172 
    173 makeTest({
    174  name: 'AuctionConfig.requestedSize in screen units.',
    175  fieldName: 'requestedSize',
    176  fieldValue: {width: '70sw', height: '80sh'}
    177 });
    178 
    179 makeTest({
    180  name: 'AuctionConfig.requestedSize in inverse screen units.',
    181  fieldName: 'requestedSize',
    182  fieldValue: {width: '70sh', height: '80sw'}
    183 });
    184 
    185 makeTest({
    186  name: 'AuctionConfig.requestedSize in mixed units.',
    187  fieldName: 'requestedSize',
    188  fieldValue: {width: '100px', height: '80sh'}
    189 });
    190 
    191 makeTest({
    192  name: 'AuctionConfig.requestedSize with decimals.',
    193  fieldName: 'requestedSize',
    194  fieldValue: {width: '70.5sw', height: '80.56sh'}
    195 });
    196 
    197 makeTest({
    198  name: 'AuctionConfig.requestedSize with non-normalized values.',
    199  fieldName: 'requestedSize',
    200  fieldValue: {width: '100px', height: '200.5px'},
    201  auctionConfigOverrides: {fieldValue: {width: ' 100.0px', height: '200.50px'}}
    202 });
    203 
    204 makeTest({
    205  name: 'Unset AuctionConfig.allSlotsRequestedSizes.',
    206  fieldName: 'allSlotsRequestedSizes',
    207  fieldValue: undefined
    208 });
    209 
    210 makeTest({
    211  name: 'AuctionConfig.allSlotsRequestedSizes.',
    212  fieldName: 'allSlotsRequestedSizes',
    213  fieldValue: [{width: '100px', height: '200px'}, {width: '70sh', height: '80sw'}]
    214 });
    215 
    216 makeTest({
    217  name: 'AuctionConfig.allSlotsRequestedSizes with non-normalized values.',
    218  fieldName: 'allSlotsRequestedSizes',
    219  fieldValue: [{width: '100px', height: '200.5px'},
    220               {width: '70sh', height: '80.5sw'}],
    221  auctionConfigOverrides: {fieldValue:
    222              [{width: ' 100', height: '200.50px '},
    223               {width: ' 70.00sh ', height: '80.50sw'}]}
    224 });
    225 
    226 makeTest({
    227  name: 'AuctionConfig.reportingTimeout with positive within-cap value.',
    228  fieldName: 'reportingTimeout',
    229  fieldValue: 100,
    230 });
    231 
    232 makeTest({
    233  name: 'AuctionConfig.reportingTimeout above the cap value.',
    234  fieldName: 'reportingTimeout',
    235  fieldValue: 5000,
    236  auctionConfigOverrides: {fieldValue: 1234567890}
    237 });
    238 
    239 makeTest({
    240  name: 'AuctionConfig.reportingTimeout not provided',
    241  fieldName: 'reportingTimeout',
    242  fieldValue: 50,
    243  auctionConfigOverrides: {fieldValue: undefined}
    244 });
    245 
    246 makeTest({
    247  name: 'AuctionConfig.sellerSignals is null',
    248  fieldName: 'sellerSignals',
    249  fieldValue: undefined,
    250  auctionConfigOverrides: {sellerSignals: null}
    251 });
    252 
    253 makeTest({
    254  name: 'AuctionConfig.sellerSignals is explicit undefined',
    255  fieldName: 'sellerSignals',
    256  fieldValue: undefined,
    257  auctionConfigOverrides: {sellerSignals: Promise.resolve(undefined)}
    258 });
    259 
    260 makeTest({
    261  name: 'AuctionConfig.sellerSignals is "null"',
    262  fieldName: 'sellerSignals',
    263  fieldValue: 'null',
    264 });
    265 
    266 makeTest({
    267  name: 'AuctionConfig.auctionSignals is null',
    268  fieldName: 'auctionSignals',
    269  fieldValue: undefined,
    270  auctionConfigOverrides: {sellerSignals: null}
    271 });
    272 
    273 makeTest({
    274  name: 'AuctionConfig.auctionSignals is explicit undefined',
    275  fieldName: 'auctionSignals',
    276  fieldValue: undefined,
    277  auctionConfigOverrides: {auctionSignals: Promise.resolve(undefined)}
    278 });
    279 
    280 makeTest({
    281  name: 'AuctionConfig.auctionSignals is "null"',
    282  fieldName: 'auctionSignals',
    283  fieldValue: 'null',
    284 });