Commit f0990340 authored by Liquan (Max) Gu's avatar Liquan (Max) Gu Committed by Commit Bot

[ExpandablePaymentHandler] Add tests: request.abort()

Context:
This CL adds a test for payment abortion. The test calls request.abort()
from the merchant side.

Expectation:
The test expects that the request.show() promise would be rejected with
the reason written in the exception message.

Bug: 1042892

Change-Id: Ib764ad689a6b114a45e86d8351086c9a4519fbfe
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2040440
Commit-Queue: Liquan (Max) Gu <maxlg@chromium.org>
Reviewed-by: default avatarLiquan (Max) Gu <maxlg@chromium.org>
Reviewed-by: default avatarRouslan Solomakhin <rouslan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#741551}
parent 1f5f5b37
......@@ -44,8 +44,8 @@ class ExpandablePaymentHandlerBrowserTest : public PlatformBrowserTest {
PlatformBrowserTest::SetUpOnMainThread();
}
GURL GetHttpPageUrl() {
return http_server_.GetURL("/maxpay.com/merchant.html");
GURL GetHttpPageUrl(const std::string path) {
return http_server_.GetURL(path);
}
content::WebContents* GetActiveWebContents() {
......@@ -116,7 +116,8 @@ IN_PROC_BROWSER_TEST_F(ExpandablePaymentHandlerBrowserTest,
EXPECT_EQ("open_window_failed",
content::EvalJs(
GetActiveWebContents(),
"launchAndWaitUntilReady('" + GetHttpPageUrl().spec() + "')"));
"launchAndWaitUntilReady('" +
GetHttpPageUrl("/maxpay.com/merchant.html").spec() + "')"));
}
// Make sure openWindow() can be resolved into window client.
......@@ -133,5 +134,22 @@ IN_PROC_BROWSER_TEST_F(ExpandablePaymentHandlerBrowserTest, WindowClientReady) {
content::EvalJs(test_controller_.GetPaymentHandlerWebContents(),
"isWindowClientReady()"));
}
// Make sure merchants can abort the payment.
IN_PROC_BROWSER_TEST_F(ExpandablePaymentHandlerBrowserTest, PaymentAborted) {
std::string expected = "success";
EXPECT_EQ(expected, content::EvalJs(GetActiveWebContents(), "install()"));
EXPECT_EQ("app_is_ready",
content::EvalJs(
GetActiveWebContents(),
"launchAndWaitUntilReady('./payment_handler_window.html')"));
DCHECK(test_controller_.GetPaymentHandlerWebContents());
EXPECT_EQ("aborted",
content::EvalJs(test_controller_.GetPaymentHandlerWebContents(),
"abort()"));
EXPECT_EQ("The website has aborted the payment",
content::EvalJs(GetActiveWebContents(), "getResult()"));
}
} // namespace
} // namespace payments
......@@ -90,7 +90,11 @@ function launchAndWaitUntilReady( // eslint-disable-line no-unused-vars
[{supportedMethods: methodName, data: {url}}],
{total: {label: 'Total', amount: {currency: 'USD', value: '0.01'}}});
request.onpaymentmethodchange = (event) => {
appReadyResolver(event.methodDetails.status);
const status = event.methodDetails.status;
if (status === 'abort') {
request.abort();
}
appReadyResolver(status);
};
resultPromise = request.show();
updateLogView('launched and waiting until app gets ready.');
......
......@@ -12,6 +12,10 @@ self.addEventListener('canmakepayment', (evt) => {
evt.respondWith(true);
});
self.addEventListener('abortpayment', (evt) => {
evt.respondWith(true);
});
self.addEventListener('message', (evt) => {
// Sent from the Payment app.
if (evt.data === 'confirm') {
......@@ -23,7 +27,7 @@ self.addEventListener('message', (evt) => {
} else if (evt.data === 'cancel') {
paymentRequestResponder({methodName, details: {status: 'unknown'}});
return;
} else if (evt.data === 'app_is_ready') {
} else if (evt.data === 'app_is_ready' || evt.data === 'abort') {
paymentRequestEvent.changePaymentMethod(methodName, {
status: evt.data,
});
......
......@@ -7,10 +7,12 @@ found in the LICENSE file.
<meta
name="viewport"
content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1">
<title>Max Pay test</title>
<body>
<button onclick="confirm()">confirm</button>
<button onclick="cancel()">cancel</button>
<button onclick="fail()">fail</button>
<button onclick="abort()">abort</button>
<div>Messages:</div>
<pre id="log"></pre>
</body>
......@@ -40,6 +42,12 @@ function fail() {
return 'failed';
}
function abort() {
navigator.serviceWorker.controller.postMessage('abort');
updateLogView('abort is invoked.');
return 'aborted';
}
function cancel() {
navigator.serviceWorker.controller.postMessage('cancel');
updateLogView('cancel is invoked.');
......@@ -57,7 +65,7 @@ window.onload = function() {
navigator.serviceWorker.addEventListener('message', (evt) => {
if (!evt.data) {
updateLogView('Received an empty message');
updateLogView('Received an empty message.');
return;
}
......
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