mirror of
https://github.com/HeyPuter/firefox.git
synced 2026-11-25 11:37:43 -10:00
Automatic update from web-platform-tests [PaymentRequest][WPT] Automate manual tests that need user click. Before this patch, test cases that need a user click were implemented as manual tests. This patch automates them using testdriver.bless() API, which simulates a user click action using WebDriver. Bug: 929773 Change-Id: I368e5867c2a889504a360d7d704aa83d3cf9c78e Reviewed-on: https://chromium-review.googlesource.com/c/1471297 Reviewed-by: Rouslan Solomakhin <[email protected]> Commit-Queue: Danyao Wang <[email protected]> Cr-Commit-Position: refs/heads/master@{#632259} -- wpt-commits: 85614961e6ee65fe339a7a8e770499c80cccae28 wpt-pr: 15386
95 lines
3.6 KiB
HTML
95 lines
3.6 KiB
HTML
<!DOCTYPE html>
|
|
<meta charset="utf-8">
|
|
<title>Test for PaymentRequest.abort() method</title>
|
|
<link rel="help" href="https://w3c.github.io/payment-request/#abort-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";
|
|
setup({
|
|
// Ignore unhandled rejections resulting from .show()'s acceptPromise
|
|
// not being explicitly handled.
|
|
allow_uncaught_exception: true,
|
|
explicit_timeout: true,
|
|
});
|
|
const basicCard = Object.freeze({ supportedMethods: "basic-card" });
|
|
const applePay = Object.freeze({
|
|
supportedMethods: "https://apple.com/apple-pay",
|
|
data: {
|
|
version: 3,
|
|
merchantIdentifier: "merchant.com.example",
|
|
countryCode: "US",
|
|
merchantCapabilities: ["supports3DS"],
|
|
supportedNetworks: ["visa"],
|
|
}
|
|
});
|
|
const defaultMethods = Object.freeze([basicCard, applePay]);
|
|
const defaultDetails = Object.freeze({
|
|
total: {
|
|
label: "Total",
|
|
amount: {
|
|
currency: "USD",
|
|
value: "1.00",
|
|
},
|
|
},
|
|
});
|
|
|
|
promise_test(async t => {
|
|
// request is in "created" state
|
|
const request = new PaymentRequest(defaultMethods, defaultDetails);
|
|
await promise_rejects(t, "InvalidStateError", request.abort());
|
|
}, `Throws if the promise [[state]] is not "interactive"`);
|
|
|
|
promise_test(async t => {
|
|
const request = new PaymentRequest(defaultMethods, defaultDetails);
|
|
const promises = new Set([request.abort(), request.abort(), request.abort()]);
|
|
assert_equals(promises.size, 3, "Must have three unique objects");
|
|
}, "Calling abort() multiple times is always a new object.");
|
|
|
|
promise_test(async t => {
|
|
const request = new PaymentRequest(defaultMethods, defaultDetails);
|
|
const [abortPromise, acceptPromise] = await test_driver.bless(
|
|
"show payment request",
|
|
() => {
|
|
const acceptPromise = request.show()
|
|
acceptPromise.catch(() => {}); // no-op, just to silence unhandled rejection in devtools.
|
|
const abortPromise = request.abort();
|
|
return [abortPromise, acceptPromise];
|
|
});
|
|
|
|
await abortPromise;
|
|
await promise_rejects(t, "AbortError", acceptPromise);
|
|
// As request is now "closed", trying to show it will fail
|
|
await promise_rejects(t, "InvalidStateError", request.show());
|
|
}, "The same request cannot be shown multiple times.");
|
|
|
|
promise_test(async t => {
|
|
// request is in "created" state.
|
|
const request = new PaymentRequest(defaultMethods, defaultDetails);
|
|
await promise_rejects(t, "InvalidStateError", request.abort());
|
|
// Call it again, for good measure.
|
|
await promise_rejects(t, "InvalidStateError", request.abort());
|
|
// The request's state is "created", so let's show it
|
|
// which changes the state to "interactive.".
|
|
const [abortPromise, acceptPromise] = await test_driver.bless(
|
|
"show payment request",
|
|
() => {
|
|
const acceptPromise = request.show()
|
|
// Let's set request the state to "closed" by calling .abort()
|
|
const abortPromise = request.abort();
|
|
return [abortPromise, acceptPromise];
|
|
});
|
|
|
|
await abortPromise;
|
|
// The request is now "closed", so...
|
|
await promise_rejects(t, "InvalidStateError", request.abort());
|
|
await promise_rejects(t, "AbortError", acceptPromise);
|
|
}, "Aborting a request before it is shown doesn't prevent it from being shown later.");
|
|
</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>
|