Commit 7eada9b4 authored by Danyao Wang's avatar Danyao Wang Committed by Commit Bot

[PaymentRequest][WPT] Automate manual tests for show() method.

This patch uses test_driver.bless() to automate manual tests that need
a user activation to trigger .show().

The new automated tests pass on Chrome after this patch.

Bug: 929773
Change-Id: Ic220c89db48c12a594ff9f77d091ff952b0c9abc
Reviewed-on: https://chromium-review.googlesource.com/c/1474708Reviewed-by: default avatarRouslan Solomakhin <rouslan@chromium.org>
Commit-Queue: Danyao Wang <danyao@chromium.org>
Cr-Commit-Position: refs/heads/master@{#632789}
parent 355fa641
......@@ -2018,8 +2018,6 @@ external/wpt/payment-request/algorithms-manual.https.html [ WontFix ]
external/wpt/payment-request/change-shipping-option-manual.https.html [ WontFix ]
external/wpt/payment-request/change-shipping-option-select-last-manual.https.html [ WontFix ]
external/wpt/payment-request/payment-request-hasenrolledinstrument-method-manual.https.html [ WontFix ]
external/wpt/payment-request/payment-request-multiple-show-manual.https.html [ WontFix ]
external/wpt/payment-request/payment-request-show-method-manual.https.html [ WontFix ]
external/wpt/payment-request/payment-response/complete-method-manual.https.html [ WontFix ]
external/wpt/payment-request/payment-response/methodName-attribute-manual.https.html [ WontFix ]
external/wpt/payment-request/payment-response/onpayerdetailchange-attribute-manual.https.html [ WontFix ]
......
<!DOCTYPE html>
<meta charset="utf-8">
<title>Manual test for multiple PaymentRequest.show()</title>
<link rel="help" href="https://w3c.github.io/payment-request/#show-method">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
"use strict";
setup({
allow_uncaught_exception: true,
});
const defaultMethods = Object.freeze([
{ supportedMethods: "basic-card" },
{
supportedMethods: "https://apple.com/apple-pay",
data: {
version: 3,
merchantIdentifier: "merchant.com.example",
countryCode: "US",
merchantCapabilities: ["supports3DS"],
supportedNetworks: ["visa"],
}
},
]);
const defaultDetails = Object.freeze({
total: {
label: "Total",
amount: {
currency: "USD",
value: "1.00",
},
},
});
function testCallingShowMultipleTimes() {
promise_test(async t => {
const request = new PaymentRequest(defaultMethods, defaultDetails);
const p1 = request.show();
const p2 = request.show();
const p3 = request.show();
const promises = new Set([p1, p2, p3]);
await request.abort();
assert_equals(promises.size, 3, "Must have three unique objects");
await promise_rejects(t, "AbortError", p1);
await promise_rejects(t, "InvalidStateError", p2);
await promise_rejects(t, "InvalidStateError", p3);
}, "Calling show() multiple times is always a new object.");
}
</script>
<h2>Manual test for multiple PaymentRequest.show()</h2>
<p>
Click on the button to bring up the Payment Request UI window and then will
close it automatically. (If a payment sheet stays open, the test has failed.)
</p>
<ul>
<li>
<button onclick="testCallingShowMultipleTimes()">
Calling show() multiple times is always a new object.
</button>
</li>
</ul>
<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>
<!DOCTYPE html>
<meta charset="utf-8">
<title>Manual tests for PaymentRequest.show() method</title>
<link rel="help" href="https://w3c.github.io/payment-request/#show-method">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
"use strict";
setup({
explicit_done: true,
explicit_timeout: true,
});
const defaultMethods = Object.freeze([
{ supportedMethods: "basic-card" },
{
supportedMethods: "https://apple.com/apple-pay",
data: {
version: 3,
merchantIdentifier: "merchant.com.example",
countryCode: "US",
merchantCapabilities: ["supports3DS"],
supportedNetworks: ["visa"],
}
},
]);
const defaultDetails = Object.freeze({
total: {
label: "Total",
amount: {
currency: "USD",
value: "1.00",
},
},
});
function testThrowsIfStateIsNotCreated() {
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'.");
}
function testPaymentRequestIsShowingBoolean() {
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.`);
}
function testNotSupportedError() {
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>
<h2>Manual tests for PaymentRequest.show() 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="testThrowsIfStateIsNotCreated()">
Throws if the promise [[state]] is not 'created'.
</button>
</li>
<li>
<button onclick="testPaymentRequestIsShowingBoolean()">
If the user agent's "payment request is showing" boolean is true, then return a promise rejected with an "AbortError" DOMException.
</button>
</li>
<li>
<button onclick="testNotSupportedError()">
If payment method consultation produces no supported method of payment, then return a promise rejected with a "NotSupportedError" DOMException.
</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>
This is a testharness.js-based test.
Harness Error. harness_status.status = 1 , harness_status.message = Already called show() once
FAIL Calling show() without being triggered by user interaction throws assert_throws: function "function() { throw e }" threw object "UnknownError: Request failed" that is not a DOMException SecurityError: property "code" is equal to 0, expected 18
FAIL Throws if the promise [[state]] is not 'created'. promise_test: Unhandled rejection with value: object "InvalidStateError: No show() or retry() in progress, so nothing to abort"
FAIL If the user agent's "payment request is showing" boolean is true, then return a promise rejected with an "AbortError" DOMException. assert_throws: function "function() { throw e }" threw object "InvalidStateError: Already called show() once" that is not a DOMException AbortError: property "code" is equal to 11, expected 20
FAIL If payment method consultation produces no supported method of payment, then return a promise rejected with a "NotSupportedError" DOMException. assert_throws: function "function() { throw e }" threw object "InvalidStateError: Already called show() once" that is not a DOMException NotSupportedError: property "code" is equal to 11, expected 9
FAIL Calling show() multiple times always returns a new promise. promise_test: Unhandled rejection with value: object "InvalidStateError: No show() or retry() in progress, so nothing to abort"
Harness: the test ran to completion.
......@@ -4,6 +4,8 @@
<link rel="help" href="https://w3c.github.io/payment-request/#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([
......@@ -33,8 +35,80 @@ const defaultDetails = Object.freeze({
promise_test(async t => {
const request = new PaymentRequest(defaultMethods, defaultDetails);
const acceptPromise = request.show();
// Abort the request after 2 seconds if it has not rejected. This allows the
// other tests in this file to run even if a non-compliant browser shows the
// payment sheet without user activation.
t.step_timeout(() => {
t.force_timeout();
request.abort();
}, 2000);
await promise_rejects(t, "SecurityError", acceptPromise);
}, `Calling show() without being triggered by user interaction throws`);
promise_test(async t => {
const request = new PaymentRequest(defaultMethods, defaultDetails);
const [acceptPromise] = await test_driver.bless(
"test: throws if the promise [[state]] is not 'created'",
() => {
const acceptPromise = request.show(); // Sets state to "interactive"
return [acceptPromise];
});
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] = await test_driver.bless(
`test: reject promise with "AbortedError" if payment request is already showing`,
async () => {
const acceptPromise1 = request1.show();
const acceptPromise2 = request2.show();
await promise_rejects(t, "AbortError", acceptPromise2);
return [acceptPromise1];
});
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] = await test_driver.bless(
`test: reject promise with "NotSupportedError"`,
() => {
const acceptPromise = request.show();
return [acceptPromise];
});
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(async t => {
const request = new PaymentRequest(defaultMethods, defaultDetails);
const [p1, p2, p3] = await test_driver.bless(
`test: calling show() multiple times always returns a new promise`,
() => {
const p1 = request.show();
const p2 = request.show();
const p3 = request.show();
return [p1, p2, p3];
});
const promises = new Set([p1, p2, p3]);
assert_equals(promises.size, 3, "Must have three unique objects");
await promise_rejects(t, "InvalidStateError", p2);
await promise_rejects(t, "InvalidStateError", p3);
await request.abort();
await promise_rejects(t, "AbortError", p1);
}, "Calling show() multiple times always returns a new promise.");
</script>
<small>
If you find a buggy test, please <a href="https://github.com/web-platform-tests/wpt/issues">file a bug</a>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment