tor-browser

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

change-shipping-option-select-last-manual.https.html (3042B)


      1 <!DOCTYPE html>
      2 <meta charset="utf-8">
      3 <title>Test for PaymentDetailsBase's shippingOptions member</title>
      4 <link rel="help" href="https://w3c.github.io/payment-request/#dom-paymentdetailsbase-shippingoptions">
      5 <script src="/resources/testharness.js"></script>
      6 <script src="/resources/testharnessreport.js"></script>
      7 <script>
      8 setup({ explicit_done: true, explicit_timeout: true });
      9 const validMethods = Object.freeze([
     10  { supportedMethods: "basic-card" },
     11  {
     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 ]);
     22 const validAmount = Object.freeze({ currency: "USD", value: "5.00" });
     23 const validTotal = Object.freeze({
     24  label: "label",
     25  amount: validAmount,
     26 });
     27 const validDetails = Object.freeze({ total: validTotal });
     28 
     29 const validShippingOption1 = Object.freeze({
     30  id: "fail-if-selected-1",
     31  label: "FAIL if selected 1",
     32  amount: validAmount,
     33  selected: true,
     34 });
     35 
     36 const validShippingOption2 = Object.freeze({
     37  id: "fail-if-selected-2",
     38  label: "FAIL if selected 2",
     39  amount: validAmount,
     40  selected: false,
     41 });
     42 
     43 const validShippingOption3 = Object.freeze({
     44  id: "pass-if-selected",
     45  label: "THIS MUST BE AUTOMATICALLY SELECTED",
     46  amount: validAmount,
     47  selected: true,
     48 });
     49 
     50 function testShippingOptionChanged(button) {
     51  button.disabled = true;
     52  promise_test(async t => {
     53    const detailsWithShippingOptions = {
     54      ...validDetails,
     55      shippingOptions: [
     56        validShippingOption1,
     57        validShippingOption2,
     58        validShippingOption3,
     59      ],
     60    };
     61    const request = new PaymentRequest(
     62      validMethods,
     63      detailsWithShippingOptions,
     64      { requestShipping: true }
     65    );
     66    assert_equals(
     67      request.shippingOption,
     68      "pass-if-selected",
     69      "Must be 'pass-if-selected', as the selected member is true"
     70    );
     71    request.onshippingoptionchange = () => {
     72      assert_unreached("onshippingoptionchange fired unexpectedly");
     73    };
     74    const response = await request.show();
     75    assert_equals(response.shippingOption, "pass-if-selected");
     76    response.complete();
     77  }, button.textContent.trim());
     78  done();
     79 }
     80 </script>
     81 
     82 <h2>PaymentRequest shippingOption attribute</h2>
     83 <p>
     84  Click on each button in sequence from top to bottom without refreshing the page.
     85  Each button will bring up the Payment Request UI window.
     86 </p>
     87 <p>
     88  When the payment sheet is presented, hit pay.
     89 </p>
     90 <ol>
     91  <li>
     92    <button onclick="testShippingOptionChanged(this)">
     93      When default shipping option is pre-selected, must not fire onshippingoptionchange
     94      and PaymentResponse must reflect the pre-selected option.
     95    </button>
     96  </li>
     97 </ol>
     98 <small>
     99  If you find a buggy test, please <a href="https://github.com/web-platform-tests/wpt/issues">file a bug</a>
    100  and tag one of the <a href="https://github.com/web-platform-tests/wpt/blob/master/payment-request/META.yml">suggested reviewers</a>.
    101 </small>