tor-browser

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

updatewith-method.https.html (2462B)


      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 PaymentRequestUpdateEvent's updateWith() method</title>
      5 <link rel="help" href="https://w3c.github.io/browser-payment-api/#updatewith-method">
      6 <script src="/resources/testharness.js"></script>
      7 <script src="/resources/testharnessreport.js"></script>
      8 <script>
      9 const examplePay = Object.freeze({ supportedMethods: "https://example.com/pay" });
     10 const defaultMethods = Object.freeze([examplePay]);
     11 const defaultDetails = Object.freeze({
     12  total: {
     13    label: "Total",
     14    amount: {
     15      currency: "USD",
     16      value: "1.00",
     17    },
     18  },
     19 });
     20 
     21 test(() => {
     22  // Smoke test - checks target is set as expected
     23  const request = new PaymentRequest(defaultMethods, defaultDetails);
     24  const ev = new PaymentRequestUpdateEvent("test");
     25  request.dispatchEvent(ev);
     26  assert_equals(ev.target, request, "The request and the target at the same");
     27 }, "Let target be the request which is dispatching the event.");
     28 
     29 // Github issue: https://github.com/w3c/browser-payment-api/issues/546
     30 test(() => {
     31  const untrustedEvents = [
     32    new PaymentRequestUpdateEvent("just a test"),
     33    new PaymentRequestUpdateEvent("shippingaddresschange"),
     34    new PaymentRequestUpdateEvent("shippingoptionchange"),
     35  ].forEach(ev => {
     36    assert_throws_dom(
     37      "InvalidStateError",
     38      () => {
     39        ev.updateWith(Promise.resolve());
     40      },
     41      `untrusted event of type "${ev.type}" must throw "InvalidStateError"`
     42    );
     43  });
     44 }, `Calling .updateWith() with an undispatched untrusted event throws "InvalidStateError"`);
     45 
     46 // Github issue: https://github.com/w3c/browser-payment-api/issues/546
     47 test(() => {
     48  const request = new PaymentRequest(defaultMethods, defaultDetails);
     49  const untrustedEvents = [
     50    new PaymentRequestUpdateEvent("just a test"),
     51    new PaymentRequestUpdateEvent("shippingaddresschange"),
     52    new PaymentRequestUpdateEvent("shippingoptionchange"),
     53  ].map(ev => {
     54    request.dispatchEvent(ev); // set .target and dispatch flag
     55    // unstrusted event.
     56    assert_throws_dom(
     57      "InvalidStateError",
     58      () => {
     59        ev.updateWith(Promise.resolve())
     60      },
     61      `untrusted event of type "${ev.type}" must throw "InvalidStateError"`
     62    );
     63  });
     64 }, `Calling .updateWith() with a dispatched, untrusted event, throws "InvalidStateError"`);
     65 
     66 </script>