tor-browser

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

apply_the_modifiers.html (4910B)


      1 <!DOCTYPE html>
      2 <meta charset="utf-8" />
      3 <title>
      4  Payment Method Basic Card: apply the modifiers
      5 </title>
      6 <link
      7  rel="help"
      8  href="https://w3c.github.io/payment-method-basic-card/#applying-the-modifiers"
      9 />
     10 <script src="/resources/testharness.js"></script>
     11 <script src="/resources/testharnessreport.js"></script>
     12 <script>
     13  setup({ explicit_done: true, explicit_timeout: true });
     14  const basicCard = [{ supportedMethods: "basic-card" }];
     15  const defaultDetails = {
     16    total: {
     17      label: "FAIL - SHOWING DEFAULT!",
     18      amount: {
     19        currency: "USD",
     20        value: "0.0",
     21      },
     22    },
     23  };
     24 
     25  const failModifier = {
     26    supportedMethods: "basic-card",
     27    total: {
     28      label: "FAIL",
     29      amount: { currency: "USD", value: "test" },
     30    },
     31    additionalDisplayItems: [
     32      {
     33        label: "FAIL - ADDITIONAL DISPLAY ITEM",
     34        amount: { currency: "USD", value: "54321" },
     35      },
     36    ],
     37  };
     38 
     39  const notBasicCardModifier = {
     40    supportedMethods: "this-doesnt-apply",
     41    total: {
     42      label: "FAIL - this-doesnt-apply",
     43      amount: { currency: "USD", value: "54321" },
     44    },
     45  };
     46 
     47  const modifier = {
     48    supportedMethods: "basic-card",
     49    total: {
     50      label: "PASS",
     51      amount: { currency: "USD", value: "12345" },
     52    },
     53    additionalDisplayItems: [
     54      {
     55        label: "PASS - ADDITIONAL DISPLAY ITEM",
     56        amount: { currency: "USD", value: "12345" },
     57      },
     58    ],
     59  };
     60 
     61  function defaultModifierApplies(testableAssertion) {
     62    promise_test(async t => {
     63      const visaModifier = Object.assign({}, modifier, {
     64        data: { supportedNetworks: ["visa"] },
     65      });
     66      visaModifier.total.label = "PASS - VISA MODIFIED";
     67      const details = Object.assign({}, defaultDetails, {
     68        modifiers: [visaModifier],
     69      });
     70      const showPromise = new PaymentRequest(basicCard, defaultDetails).show();
     71      await promise_rejects_dom(t, "AbortError", showPromise);
     72    }, testableAssertion.trim());
     73  }
     74 
     75  function modifierWithNoDataAppliesToAll(testableAssertion) {
     76    promise_test(async t => {
     77      const details = Object.assign({}, defaultDetails, {
     78        modifiers: [modifier],
     79      });
     80      const showPromise = new PaymentRequest(basicCard, defaultDetails).show();
     81      await promise_rejects_dom(t, "AbortError", showPromise);
     82    }, testableAssertion.trim());
     83  }
     84 
     85  function modifierWithObjectAppliesToAll(testableAssertion) {
     86    promise_test(async t => {
     87      const modifiers = [Object.assign({}, modifier, { data: {} })];
     88      const details = Object.assign({}, defaultDetails, { modifiers });
     89      const showPromise = new PaymentRequest(basicCard, defaultDetails).show();
     90      await promise_rejects_dom(t, "AbortError", showPromise);
     91    }, testableAssertion.trim());
     92  }
     93 
     94  function modifierWithEmptySupportedNetworksAppliesToAll(testableAssertion) {
     95    promise_test(async t => {
     96      const modifiers = [
     97        Object.assign({}, modifier, { data: { supportedNetworks: [] } }),
     98      ];
     99      const details = Object.assign({}, defaultDetails, { modifiers });
    100      const showPromise = new PaymentRequest(basicCard, defaultDetails).show();
    101      await promise_rejects_dom(t, "AbortError", showPromise);
    102    }, testableAssertion.trim());
    103  }
    104 
    105  function modifierLastOneWins(testableAssertion) {
    106    promise_test(async t => {
    107      const modifiers = [failModifier, modifier, notBasicCardModifier];
    108      const details = Object.assign({}, defaultDetails, { modifiers });
    109      const showPromise = new PaymentRequest(basicCard, defaultDetails).show();
    110      await promise_rejects_dom(t, "AbortError", showPromise);
    111    }, testableAssertion.trim());
    112  }
    113 </script>
    114 <h1>Manual tests</h1>
    115 <p>
    116  <strong>Note:</strong> this test requires that there is at at least one
    117  registered "visa" card. If the payment-sheet total's
    118  label displays "PASS", and the value US$12345, then a test has passed.
    119 </p>
    120 <ol>
    121  <li>
    122    <button onclick="defaultModifierApplies(this.textContent.trim())">
    123      A modifier is applied by default to a card.
    124    </button>
    125  </li>
    126  <li>
    127    <button onclick="modifierWithNoDataAppliesToAll(this.textContent.trim())">
    128      Missing PaymentDetailsModifier.data is same as passing default
    129      BasicCardRequest.
    130    </button>
    131  </li>
    132  <li>
    133    <button onclick="modifierWithNoDataAppliesToAll(this.textContent.trim())">
    134      PaymentDetailsModifier.data with empty object is same as passing default
    135      BasicCardRequest.
    136    </button>
    137  </li>
    138  <li>
    139    <button
    140      onclick="modifierWithEmptySupportedNetworksAppliesToAll(this.textContent.trim())"
    141    >
    142      A modified with a BasicCardRequest whose supportedNetworks is an empty
    143      array applies to all.
    144    </button>
    145  </li>
    146  <li>
    147    <button onclick="modifierLastOneWins(this.textContent.trim())">
    148      Given a set of modifiers, the last applicable "basic-card" wins.
    149    </button>
    150  </li>
    151  <li><button onclick="done()">Done!</button></li>
    152 </ol>