tor-browser

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

constructor.tentative.https.html (5282B)


      1 <!DOCTYPE html>
      2 <!-- Copyright © 2017 Chromium authors and World Wide Web Consortium, (Massachusetts Institute of Technology, ERCIM, Keio University, Beihang). -->
      3 <meta charset="utf-8">
      4 <title>Test for MerchantValidationEvent Constructor</title>
      5 <link rel="help" href="https://w3c.github.io/browser-payment-api/#merchantvalidationevent-constructor">
      6 <script src="/resources/testharness.js"></script>
      7 <script src="/resources/testharnessreport.js"></script>
      8 <script>
      9 const applePay = Object.freeze({
     10  supportedMethods: "https://apple.com/apple-pay",
     11  data: {
     12    version: 3,
     13    merchantIdentifier: "merchant.com.example",
     14    countryCode: "US",
     15    merchantCapabilities: ["supports3DS"],
     16    supportedNetworks: ["visa"],
     17  }
     18 });
     19 const examplePay = Object.freeze({ supportedMethods: "https://example.com/pay" });
     20 const defaultMethods = Object.freeze([examplePay, applePay]);
     21 const defaultDetails = Object.freeze({
     22  total: {
     23    label: "Total",
     24    amount: {
     25      currency: "USD",
     26      value: "1.00",
     27    },
     28  },
     29 });
     30 
     31 test(() => {
     32  new MerchantValidationEvent("test");
     33 }, "MerchantValidationEvent can be constructed in secure-context.");
     34 
     35 test(() => {
     36  const ev = new MerchantValidationEvent("test", {
     37    bubbles: true,
     38    cancelable: true,
     39    composed: true,
     40  });
     41  assert_false(ev.isTrusted, "constructed in script, so not trusted");
     42  assert_true(ev.bubbles, "set by EventInitDict");
     43  assert_true(ev.cancelable, "set by EventInitDict");
     44  assert_true(ev.composed, "set by EventInitDict");
     45  assert_equals(ev.target, null, "initially null");
     46  assert_equals(ev.type, "test");
     47 }, "MerchantValidationEvent can be constructed with an EventInitDict, even if not trusted.");
     48 
     49 test(() => {
     50  const request = new PaymentRequest(defaultMethods, defaultDetails);
     51  const ev = new MerchantValidationEvent("test");
     52  request.addEventListener("test", evt => {
     53    assert_equals(ev, evt);
     54  });
     55  request.dispatchEvent(ev);
     56 }, "MerchantValidationEvent can be dispatched, even if not trusted.");
     57 
     58 test(() => {
     59  const validationURL = "https://pass.com";
     60  const event = new MerchantValidationEvent("test", { validationURL });
     61  assert_idl_attribute(event, "validationURL");
     62  assert_equals(event.validationURL, "https://pass.com/");
     63 }, "Must have a validationURL IDL attribute, which is initialized with to the validationURL dictionary value.");
     64 
     65 test(() => {
     66  const validationURL = "http://\u005B"; // invalid URL
     67  assert_throws_js(TypeError, () => {
     68    new MerchantValidationEvent("test", { validationURL });
     69  });
     70 }, "Must throw TypeError if initialized with an invalid URL.");
     71 
     72 test(() => {
     73  const validationURL = "";
     74  const relativePaths = ["", ".", "/test"];
     75  for (const path of relativePaths) {
     76    const event = new MerchantValidationEvent("test", { validationURL: path });
     77    const expected = new URL(path, document.location.href).href;
     78    assert_equals(event.validationURL, expected);
     79  }
     80 }, "Relative validationURLs use the document as the base.");
     81 
     82 test(() => {
     83  const validationURL = "pass";
     84  const base = document.createElement("base");
     85  base.href = "https://pass.com";
     86  document.head.append(base);
     87  const event = new MerchantValidationEvent("test", { validationURL });
     88  try {
     89    assert_idl_attribute(event, "validationURL");
     90    assert_equals(event.validationURL, "https://pass.com/pass");
     91  } finally {
     92    base.remove();
     93  }
     94 }, "Relative validationURLs use the document.baseURI as the base.");
     95 
     96 test(() => {
     97  const methodName = "https://pass.com";
     98  const event = new MerchantValidationEvent("test", { methodName });
     99  assert_idl_attribute(event, "methodName");
    100  assert_equals(event.methodName, "https://pass.com");
    101 }, "Must have a methodName IDL attribute, which is initialized with to the methodName dictionary value.");
    102 
    103 test(() => {
    104  const event = new MerchantValidationEvent("test", {});
    105  assert_equals(event.methodName, "");
    106 }, "When no methodName is passed, methodName attribute defaults to the empty string");
    107 
    108 test(() => {
    109  const validPMIs = [
    110    "https://example.com/pay",
    111    "https://example.com/pay?version=1",
    112    "https://example.com/pay/version/1",
    113    "secure-payment-confirmation",
    114    "https://apple.com/apple-pay",
    115    // special case for as default value
    116    "",
    117  ];
    118  for (const methodName of validPMIs) {
    119    const event = new MerchantValidationEvent("test", { methodName });
    120    assert_equals(event.methodName, methodName);
    121  }
    122 }, "MerchantValidationEvent can be constructed with valid PMIs");
    123 
    124 test(() => {
    125  const invalidPMIs = [
    126    // ❌ Contains Unicode character outside the valid ranges.
    127    "secure-💳",
    128    // ❌ Contains uppercase characters.
    129    "Secure-Payment-Confirmation",
    130    // ❌ Contains Unicode characters outside the valid ranges.
    131    "¡secure-*-payment-confirmation!",
    132    // ❌ Uses http://, a username, and a password.
    133    "http://username:password@example.com/pay",
    134    // ❌ Uses unknown URI scheme.
    135    "unknown://example.com/pay",
    136  ];
    137  for (const methodName of invalidPMIs) {
    138    assert_throws_js(
    139      RangeError,
    140      () => {
    141        const event = new MerchantValidationEvent("test", { methodName });
    142      },
    143      `expected to throw when constructed with invalid PMI: '${methodName}'`
    144    );
    145  }
    146 }, "MerchantValidationEvent can't be constructed with invalid PMIs");
    147 </script>