summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/payment-request/PaymentRequestUpdateEvent/constructor.https.html
blob: 3de0469e9c4b9cb30a864e44aca479d1e0e4099c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<!DOCTYPE html>
<!-- Copyright © 2017 Chromium authors and World Wide Web Consortium, (Massachusetts Institute of Technology, ERCIM, Keio University, Beihang). -->
<meta charset="utf-8">
<title>Test for PaymentRequestUpdateEvent Constructor</title>
<link rel="help" href="https://w3c.github.io/browser-payment-api/#constructor">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
const examplePay = Object.freeze({ supportedMethods: "https://example.com/pay" });
const defaultMethods = Object.freeze([examplePay]);
const defaultDetails = Object.freeze({
  total: {
    label: "Total",
    amount: {
      currency: "USD",
      value: "1.00",
    },
  },
});

test(() => {
  try {
    new PaymentRequestUpdateEvent("test");
  } catch (err) {
    assert_unreached(`Unexpected exception: ${err.message}`);
  }
}, "PaymentRequestUpdateEvent can be constructed in secure-context");

test(() => {
  const ev = new PaymentRequestUpdateEvent("test", {
    bubbles: true,
    cancelable: true,
    composed: true,
  });
  assert_false(ev.isTrusted, "constructed in script, so not be trusted");
  assert_true(ev.bubbles, "set by EventInitDict");
  assert_true(ev.cancelable, "set by EventInitDict");
  assert_true(ev.composed, "set by EventInitDict");
  assert_equals(ev.target, null, "initially null");
  assert_equals(ev.type, "test");
}, "PaymentRequestUpdateEvent can be constructed with an EventInitDict, even if not trusted");

test(() => {
  const request = new PaymentRequest(defaultMethods, defaultDetails);
  const ev = new PaymentRequestUpdateEvent("test");
  request.addEventListener("test", evt => {
    assert_equals(ev, evt);
  });
  request.dispatchEvent(ev);
}, "PaymentRequestUpdateEvent can be dispatched, even if not trusted");

</script>