tor-browser

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

updateWith-duplicate-shipping-options-manual.https.html (3127B)


      1 <!doctype html>
      2 <meta charset="utf8">
      3 <link rel="help" href="https://w3c.github.io/payment-request/#updatewith()-method">
      4 <title>
      5  updateWith() method - duplicate shippingOption ids
      6 </title>
      7 <script src="/resources/testharness.js"></script>
      8 <script src="/resources/testharnessreport.js"></script>
      9 <script>
     10 setup({ explicit_done: true, explicit_timeout: true });
     11 const applePay = Object.freeze({
     12  supportedMethods: "https://apple.com/apple-pay",
     13  data: {
     14    version: 3,
     15    merchantIdentifier: "merchant.com.example",
     16    countryCode: "US",
     17    merchantCapabilities: ["supports3DS"],
     18    supportedNetworks: ["visa"],
     19  }
     20 });
     21 const validMethod = Object.freeze({ supportedMethods: "basic-card" });
     22 const validMethods = [validMethod, applePay];
     23 const validAmount = Object.freeze({
     24  currency: "USD",
     25  value: "5.00",
     26 });
     27 const validShippingOption = Object.freeze({
     28  id: "option1",
     29  label: "Option 1",
     30  amount: validAmount,
     31  selected: true,
     32 });
     33 const validShippingOptions = Object.freeze([validShippingOption]);
     34 const validDetails = Object.freeze({
     35  total: {
     36    label: "Total due",
     37    amount: validAmount,
     38  },
     39  shippingOptions: validShippingOptions,
     40 });
     41 const validOptions = Object.freeze({
     42  requestShipping: true,
     43 });
     44 
     45 test(() => {
     46  try {
     47    const request = new PaymentRequest(validMethods, validDetails);
     48  } catch (err) {
     49    done();
     50    throw err;
     51  }
     52 }, "Must construct a PaymentRequest (smoke test)");
     53 
     54 function testFireEvents(button) {
     55  button.disabled = true;
     56  promise_test(async t => {
     57    const request = new PaymentRequest(
     58      validMethods,
     59      validDetails,
     60      validOptions
     61    );
     62    request.addEventListener("shippingaddresschange", event => {
     63      // Same option, so duplicate ids
     64      const otherShippingOption = Object.assign({}, validShippingOption, {
     65        id: "other",
     66      });
     67      const shippingOptions = [
     68        validShippingOption,
     69        otherShippingOption,
     70        validShippingOption,
     71      ];
     72      const newDetails = Object.assign({}, validDetails, { shippingOptions });
     73      event.updateWith(newDetails);
     74    });
     75    const acceptPromise = request.show();
     76    await promise_rejects_js(
     77      t,
     78      TypeError,
     79      acceptPromise,
     80      "Duplicate shippingOption ids must abort with TypeError"
     81    );
     82  }, button.textContent.trim());
     83  done();
     84 }
     85 </script>
     86 <h2>updateWith() method - duplicate shippingOptions ids</h2>
     87 <p>
     88  Click on each button in sequence from top to bottom without refreshing the page.
     89  Each button will bring up the Payment Request UI window.
     90 </p>
     91 <p>
     92  When the payment sheet is shown, select a different shipping address.
     93  If you have to manually abort the test from the payment sheet, then the
     94  test has failed.
     95 </p>
     96 <ol>
     97  <li>
     98    <button onclick="testFireEvents(this)">
     99      If there are duplicate shippingOption ids, then abort payment request.
    100    </button>
    101  </li>
    102 </ol>
    103 <small>
    104  If you find a buggy test, please <a href="https://github.com/web-platform-tests/wpt/issues">file a bug</a>
    105  and tag one of the <a href="https://github.com/web-platform-tests/wpt/blob/master/payment-request/META.yml">suggested reviewers</a>.
    106 </small>