tor-browser

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

updateWith-method-pmi-handling-manual.https.html (4269B)


      1 <!DOCTYPE html>
      2 <meta charset="utf-8">
      3 <title>Test for validity of payment method identifiers when calling updateWith() method</title>
      4 <link rel="help" href="https://www.w3.org/TR/payment-request/#updatewith()-method">
      5 <script src="/resources/testharness.js"></script>
      6 <script src="/resources/testharnessreport.js"></script>
      7 <script>
      8 "use strict";
      9 setup({
     10  explicit_done: true,
     11  explicit_timeout: true,
     12  allow_uncaught_exception: true,
     13 });
     14 const applePay = Object.freeze({
     15  supportedMethods: "https://apple.com/apple-pay",
     16  data: {
     17    version: 3,
     18    merchantIdentifier: "merchant.com.example",
     19    countryCode: "US",
     20    merchantCapabilities: ["supports3DS"],
     21    supportedNetworks: ["visa"],
     22  },
     23 });
     24 const validMethod = Object.freeze({
     25  supportedMethods: "https://:@wpt.fyi:443/payment-request",
     26 });
     27 
     28 const validMethods = Object.freeze([
     29  validMethod,
     30  applePay,
     31  { supportedMethods: "basic-card" },
     32 ]);
     33 
     34 const validAmount = Object.freeze({
     35  currency: "USD",
     36  value: "1.0",
     37 });
     38 
     39 const validTotal = Object.freeze({
     40  label: "Default Total",
     41  amount: validAmount,
     42 });
     43 
     44 const validShippingOption = Object.freeze({
     45  id: "standard",
     46  label: "Shipping option",
     47  amount: validAmount,
     48  selected: true,
     49 });
     50 
     51 const validDetails = Object.freeze({
     52  total: validTotal,
     53  shippingOptions: [validShippingOption],
     54 });
     55 
     56 const validModifier = Object.freeze({
     57  supportedMethods: "basic-card",
     58  total: validTotal,
     59 });
     60 
     61 function manualTest(button, { invalidMethod }) {
     62  button.disabled = true;
     63  promise_test(async t => {
     64    const request = new PaymentRequest(validMethods, validDetails, {
     65      requestShipping: true,
     66    });
     67    const listener = ev => {
     68      const invalidModifier = Object.assign({}, validModifier, {
     69        supportedMethods: invalidMethod,
     70      });
     71      const invalidDetails = Object.assign({}, validDetails, {
     72        modifiers: [validModifier, invalidModifier],
     73      });
     74      ev.updateWith(invalidDetails);
     75    };
     76    // We test against a valid and an invalid modifier
     77    request.addEventListener("shippingaddresschange", listener, { once: true });
     78    const showPromise = request.show();
     79    await promise_rejects_js(t, RangeError, showPromise);
     80  }, button.textContent.trim());
     81 }
     82 </script>
     83 <h2>updateWith() method: test validity of payment method identifiers.</h2>
     84 <p>
     85  When shown a payment sheet, select a different address.
     86 </p>
     87 <ol>
     88  <li>
     89    <button onclick="manualTest(this, {invalidMethod: 'https://:password@example.com'});">
     90      Must throw if the URL has a password.
     91    </button>
     92  </li>
     93  <li>
     94    <button onclick="manualTest(this, {invalidMethod: 'https://username@example.com'});">
     95      Must throw if the URL has a username.
     96    </button>
     97  </li>
     98  <li>
     99    <button onclick="manualTest(this, {invalidMethod: 'https://username:password@example.com/pay'});">
    100      Must throw if the URL has a username and a password.
    101    </button>
    102  </li>
    103  <li>
    104    <button onclick="manualTest(this, {invalidMethod: 'http://username:password@example.com/pay'});">
    105      Must throw if it's http, and has a username and password.
    106    </button>
    107  </li>
    108  <li>
    109    <button onclick="manualTest(this, {invalidMethod: 'http://foo.com:100000000/pay'});">
    110      Must throw if the URL is invalid (port range).
    111    </button>
    112  </li>
    113  <li>
    114    <button onclick="manualTest(this, {invalidMethod: 'basic-💳'});">
    115      Must throw if the PMI contains characters that are out of range.
    116    </button>
    117  </li>
    118  <li>
    119    <button onclick="manualTest(this, {invalidMethod: 'not-https://wpt.fyi/payment-request'});">
    120      Must throw if not https.
    121    </button>
    122  </li>
    123  <li>
    124    <button onclick="manualTest(this, {invalidMethod: '¡basic-*-card!'});">
    125      Must throw if the standardized PMI contains characters outside the ascii range.
    126    </button>
    127  </li>
    128  <li>
    129    <button onclick="manualTest(this, {invalidMethod: 'Basic-Card'});">
    130      Must throw if standardized PMI has uppercase characters.
    131    </button>
    132  </li>
    133  <li>
    134    <button onclick="done();">Done!</button>
    135  </li>
    136 </ol>
    137 <small>
    138  If you find a buggy test, please <a href="https://github.com/web-platform-tests/wpt/issues">file a bug</a>
    139  and tag one of the <a href="https://github.com/web-platform-tests/wpt/blob/master/payment-request/META.yml">suggested reviewers</a>.
    140 </small>