Bug 1526619 [wpt PR 15283] - [Payment Request][WPT] Fix abort() tests., a=testonly

Automatic update from web-platform-tests
[Payment Request][WPT] Fix abort() tests. (#15283)

Before this patch, the WPT tests for PaymentRequest.abort() were
expected to fail due to including the vendor testdriver JavaScript file
before the generic testdriver file. The vendor file was attempting to
use the objects defined in the generic file, but the incorrect include
order caused a JS error.

This patch reorders the vendor JS file to be after the generic JS file
and splits out the manual tests that require a user gesture for
PaymentRequest.show().

After this patch, the PaymentRequest.abort() tests are passing.

Bug: 929773
Change-Id: Ic0f8ff84b478116821e98775d1cec31cfad32d9f
--

wpt-commits: ba78e657cbc2648e1540216e5a7973bc91f221f0
wpt-pr: 15283
This commit is contained in:
Blink WPT Bot 2019-02-18 19:26:15 +00:00 коммит произвёл moz-wptsync-bot
Родитель 95a2da72fc
Коммит b395870e59
2 изменённых файлов: 101 добавлений и 40 удалений

Просмотреть файл

@ -0,0 +1,95 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>Manual tests 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>
"use strict";
setup({
explicit_done: 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",
},
},
});
function testShowSameRequestMultipleTimes() {
promise_test(async t => {
const request = new PaymentRequest(defaultMethods, defaultDetails);
const acceptPromise = request.show()
try {
await request.abort();
} catch (err) {
assert_unreached("Unexpected promise rejection: " + err.message);
}
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.");
}
function testAbortBeforeShow() {
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 acceptPromise = request.show()
// Let's set request the state to "closed" by calling .abort()
try {
await request.abort();
} catch (err) {
assert_unreached("Unexpected promise rejection: " + err.message);
}
// 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>
<h2>Manual tests for PaymentRequest.abort() method</h2>
<p>
Click on each button in sequence from top to bottom without refreshing the
page. Each button will bring up the Payment Request UI window and then will
close it automatically. (If a payment sheet stays open, the test has failed.)
</p>
<ol>
<li>
<button onclick="testShowSameRequestMultipleTimes()">
The same request cannot be shown multiple times.
</button>
</li>
<li>
<button onclick="testAbortBeforeShow()">
Aborting a request before it is shown doesn't prevent it from being shown
later.
</button>
</li>
<li><button onclick="done()">Done!</button></li>
</ol>
<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>

Просмотреть файл

@ -1,11 +1,11 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>Test for PaymentRequest.abort() method</title>
<link rel="help" href="https://w3c.github.io/browser-payment-api/#abort-method">
<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-vendor.js'></script>
<script src="/resources/testdriver.js"></script>
<script src='/resources/testdriver-vendor.js'></script>
<script>
"use strict";
setup({
@ -42,47 +42,13 @@ promise_test(async t => {
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 acceptPromise = test_driver.bless("show payment request", () =>
request.show()
);
try {
await request.abort();
} catch (err) {
assert_unreached("Unexpected promise rejection: " + err.message);
}
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 acceptPromise = test_driver.bless("show payment request", () =>
request.show()
);
// Let's set request the state to "closed" by calling .abort()
try {
await request.abort();
} catch (err) {
assert_unreached("Unexpected promise rejection: " + err.message);
}
// 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.");
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.");
</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>