mirror of
https://github.com/servo/servo
synced 2026-05-10 17:12:23 +02:00
58 lines
2.2 KiB
HTML
58 lines
2.2 KiB
HTML
<!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 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>
|
|
'use strict';
|
|
const basicCard = Object.freeze({ supportedMethods: "basic-card" });
|
|
const defaultMethods = Object.freeze([basicCard]);
|
|
const defaultDetails = Object.freeze({
|
|
total: {
|
|
label: "Total",
|
|
amount: {
|
|
currency: "USD",
|
|
value: "1.00",
|
|
},
|
|
},
|
|
});
|
|
|
|
test(() => {
|
|
try {
|
|
new PaymentRequest(defaultMethods, defaultDetails);
|
|
} catch (err) {
|
|
done();
|
|
throw err;
|
|
}
|
|
}, "Must be possible to construct a payment request");
|
|
|
|
|
|
promise_test(async t => {
|
|
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(async t => {
|
|
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(async t => {
|
|
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.`);
|
|
</script>
|