blob: c6e69d4c587602d51602aea41224731e692af2ae [file] [log] [blame]
<!DOCTYPE html>
<meta charset="utf-8">
<title>Test for PaymentRequest.show() method</title>
<link rel="help" href="https://w3c.github.io/browser-payment-api/#show-method">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
<script>
"use strict";
const defaultMethods = Object.freeze([
{ supportedMethods: "basic-card" },
{ supportedMethods: "https://apple.com/apple-pay" },
]);
const defaultDetails = Object.freeze({
total: {
label: "Total",
amount: {
currency: "USD",
value: "1.00",
},
},
});
promise_test(async t => {
const request = new PaymentRequest(defaultMethods, defaultDetails);
const acceptPromise = request.show();
await promise_rejects(t, "SecurityError", acceptPromise);
}, `Calling show() without being triggered by user interaction throws`);
promise_test(t => {
return test_driver.bless("show payment request", async () => {
const request = new PaymentRequest(defaultMethods, defaultDetails);
const acceptPromise = request.show(); // Sets state to "interactive"
await promise_rejects(t, "InvalidStateError", request.show());
await request.abort();
await promise_rejects(t, "AbortError", acceptPromise);
});
}, "Throws if the promise [[state]] is not 'created'.");
promise_test(t => {
return test_driver.bless("show payment request", async () => {
const request1 = new PaymentRequest(defaultMethods, defaultDetails);
const request2 = new PaymentRequest(defaultMethods, defaultDetails);
const acceptPromise1 = request1.show();
const acceptPromise2 = request2.show();
await promise_rejects(t, "AbortError", acceptPromise2);
await request1.abort();
await promise_rejects(t, "AbortError", acceptPromise1);
});
}, `If the user agent's "payment request is showing" boolean is true, then return a promise rejected with an "AbortError" DOMException.`);
promise_test(t => {
return test_driver.bless("show payment request", async () => {
const request = new PaymentRequest(
[{ supportedMethods: "this-is-not-supported" }],
defaultDetails
);
const acceptPromise = request.show();
await promise_rejects(t, "NotSupportedError", acceptPromise);
});
}, `If payment method consultation produces no supported method of payment, then return a promise rejected with a "NotSupportedError" DOMException.`);
promise_test(t => {
return test_driver.bless("show payment request", async () => {
const request = new PaymentRequest(
[{ supportedMethods: "basic-card" }],
defaultDetails
);
const promises = new Set([request.show(), request.show(), request.show()]);
await request.abort();
assert_equals(promises.size, 3, "Must have three unique objects");
});
}, "Calling show() multiple times is always a new object.");
</script>
<small>
If you find a buggy test, please <a href="https://github.com/web-platform-tests/wpt/issues">file a bug</a>
and tag one of the <a href="https://github.com/web-platform-tests/wpt/blob/master/payment-request/META.yml">suggested reviewers</a>.
</small>