tor-browser

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

change-shipping-address-manual.https.html (5492B)


      1 <!DOCTYPE html>
      2 <meta charset="utf-8" />
      3 <title>Tests for PaymentRequestEvent.changeShippingAddress()</title>
      4 <link
      5  rel="help"
      6  href="https://w3c.github.io/payment-handler/#changeshippingaddress-method"
      7 />
      8 
      9 <script src="/resources/testharness.js"></script>
     10 <script src="/resources/testharnessreport.js"></script>
     11 <script src="/resources/testdriver.js"></script>
     12 <script src="/resources/testdriver-vendor.js"></script>
     13 <p>If the payment sheet is shown, please authorize the mock payment.</p>
     14 <script>
     15 const methodName = window.location.origin
     16    + '/payment-handler/change-shipping-address-manual-manifest.json';
     17 function createRequest() {
     18  return new PaymentRequest([{supportedMethods: methodName}], {
     19      total: {label: 'Total', amount: {currency: 'USD', value: '0.01'}},
     20      shippingOptions: [{
     21        id: 'freeShippingOption',
     22        label: 'Free global shipping',
     23        amount: {
     24          currency: 'USD',
     25          value: '0',
     26        },
     27        selected: false,
     28      }],
     29    }, {requestShipping: true});
     30 }
     31 
     32 promise_test(async (t) => {
     33  const request = createRequest();
     34  // Intentionally do not respond to the 'shippingaddresschange' event.
     35  const response = await test_driver.bless('showing a payment sheet', () =>
     36    request.show()
     37  );
     38  const complete_promise = response.complete('success');
     39 
     40  assert_equals(response.details.changeShippingAddressReturned, null);
     41 
     42  return complete_promise;
     43 }, 'If updateWith(details) is not run, changeShippingAddress() returns null.');
     44 
     45 promise_test(async (t) => {
     46  const request = createRequest();
     47  request.addEventListener('shippingaddresschange', (event) => {
     48    assert_equals(request.shippingAddress.organization, '', 'organization should be redacted');
     49    assert_equals(request.shippingAddress.phone, '', 'phone should be redacted');
     50    assert_equals(request.shippingAddress.recipient, '', 'recipient should be redacted');
     51    assert_equals(request.shippingAddress.addressLine.length, 0, 'addressLine should be redacted');
     52    assert_equals(request.shippingAddress.city, 'Reston');
     53    assert_equals(request.shippingAddress.country, 'US');
     54    assert_equals(request.shippingAddress.postalCode, '20190');
     55    assert_equals(request.shippingAddress.region, 'VA');
     56    event.updateWith({
     57      total: {label: 'Total', amount: {currency: 'GBP', value: '0.02'}},
     58      error: 'Error for test',
     59      modifiers: [
     60        {
     61          supportedMethods: methodName,
     62          data: {soup: 'potato'},
     63          total: {
     64            label: 'Modified total',
     65            amount: {currency: 'EUR', value: '0.03'},
     66          },
     67          additionalDisplayItems: [
     68            {
     69              label: 'Modified display item',
     70              amount: {currency: 'INR', value: '0.06'},
     71            },
     72          ],
     73        },
     74        {
     75          supportedMethods: methodName + '2',
     76          data: {soup: 'tomato'},
     77          total: {
     78            label: 'Modified total #2',
     79            amount: {currency: 'CHF', value: '0.07'},
     80          },
     81          additionalDisplayItems: [
     82            {
     83              label: 'Modified display item #2',
     84              amount: {currency: 'CAD', value: '0.08'},
     85            },
     86          ],
     87        },
     88      ],
     89      displayItems: [
     90        {
     91          label: 'Display item',
     92          amount: {currency: 'CNY', value: '0.04'},
     93        },
     94      ],
     95      shippingOptions: [
     96        {
     97          id: 'freeShippingOption',
     98          label: 'express global shipping',
     99          amount: {
    100            currency: 'USD',
    101            value: '0',
    102          },
    103          selected: true,
    104        }
    105      ],
    106        shippingAddressErrors: {
    107        country: 'US only shipping',
    108      }
    109    });
    110  });
    111  const response = await test_driver.bless('showing a payment sheet', () =>
    112    request.show()
    113  );
    114  const complete_promise = response.complete('success');
    115  const changeShippingAddressReturned =
    116    response.details.changeShippingAddressReturned;
    117 
    118  assert_equals(changeShippingAddressReturned.total.currency, 'GBP');
    119  assert_equals(changeShippingAddressReturned.total.value, '0.02');
    120  assert_equals(changeShippingAddressReturned.total.label, undefined);
    121  assert_equals(changeShippingAddressReturned.error, 'Error for test');
    122  assert_equals(changeShippingAddressReturned.modifiers.length, 1);
    123  assert_equals(changeShippingAddressReturned.displayItems, undefined);
    124  assert_equals(changeShippingAddressReturned.shippingOptions.length, 1);
    125  assert_equals(changeShippingAddressReturned.paymentMethodErrors, undefined);
    126  assert_equals(changeShippingAddressReturned.shippingAddressErrors.country, 'US only shipping');
    127 
    128  const shipping_option = changeShippingAddressReturned.shippingOptions[0];
    129  assert_equals(shipping_option.id, 'freeShippingOption' );
    130  assert_equals(shipping_option.label, 'express global shipping');
    131  assert_equals(shipping_option.amount.currency, 'USD');
    132  assert_equals(shipping_option.amount.value, '0');
    133  assert_true(shipping_option.selected);
    134 
    135  const modifier = changeShippingAddressReturned.modifiers[0];
    136  assert_equals(modifier.supportedMethods, methodName);
    137  assert_equals(modifier.data.soup, 'potato');
    138  assert_equals(modifier.total.label, '');
    139  assert_equals(modifier.total.amount.currency, 'EUR');
    140  assert_equals(modifier.total.amount.value, '0.03');
    141  assert_equals(modifier.additionalDisplayItems, undefined);
    142 
    143  return complete_promise;
    144 }, 'The changeShippingAddress() returns some details from the "shippingaddresschange" event\'s updateWith(details) call.');
    145 </script>