Commit 7a33788d authored by Rouslan Solomakhin's avatar Rouslan Solomakhin Committed by Commit Bot

[Web Payment][Android] Test skip-the-sheet failed transaction.

Bug: 952283
Change-Id: I462775028293c384f4e87a1a3afe88c844e792b8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1822720
Commit-Queue: Rouslan Solomakhin <rouslan@chromium.org>
Reviewed-by: default avatarSahel Sharify <sahel@chromium.org>
Cr-Commit-Position: refs/heads/master@{#699511}
parent 300b7ec0
...@@ -194,6 +194,12 @@ public class PaymentRequestImpl ...@@ -194,6 +194,12 @@ public class PaymentRequestImpl
* Called when the payment response is ready. * Called when the payment response is ready.
*/ */
void onPaymentResponseReady(); void onPaymentResponseReady();
/**
* Called when the browser acknowledges the renderer's complete call, which indicates that
* the browser UI has closed.
*/
void onCompleteReplied();
} }
/** /**
...@@ -2547,7 +2553,10 @@ public class PaymentRequestImpl ...@@ -2547,7 +2553,10 @@ public class PaymentRequestImpl
if (mUI != null) { if (mUI != null) {
mUI.close(immediateClose, () -> { mUI.close(immediateClose, () -> {
if (mClient != null) mClient.onComplete(); if (mClient != null) {
if (sObserverForTest != null) sObserverForTest.onCompleteReplied();
mClient.onComplete();
}
closeClient(); closeClient();
}); });
mUI = null; mUI = null;
......
...@@ -47,6 +47,24 @@ public class PaymentRequestPaymentAppUiSkipTest { ...@@ -47,6 +47,24 @@ public class PaymentRequestPaymentAppUiSkipTest {
public PaymentRequestTestRule mPaymentRequestTestRule = public PaymentRequestTestRule mPaymentRequestTestRule =
new PaymentRequestTestRule("payment_request_bobpay_ui_skip_test.html"); new PaymentRequestTestRule("payment_request_bobpay_ui_skip_test.html");
/** If the transaction fails, the browser shows an error message. */
@Test
@MediumTest
@Feature({"Payments"})
public void testFail() throws InterruptedException, TimeoutException {
mPaymentRequestTestRule.installPaymentApp(HAVE_INSTRUMENTS, IMMEDIATE_RESPONSE);
// Wait for the error message overlay.
mPaymentRequestTestRule.triggerUIAndWait(
"buyFail", mPaymentRequestTestRule.getResultReady());
// Dismiss the error message overlay.
mPaymentRequestTestRule.clickErrorOverlayAndWait(
R.id.ok_button, mPaymentRequestTestRule.getCompleteReplied());
mPaymentRequestTestRule.expectResultContains(new String[] {"Transaction failed"});
}
/** /**
* If Bob Pay is supported and installed, user should be able to pay with it. Here Bob Pay * If Bob Pay is supported and installed, user should be able to pay with it. Here Bob Pay
* responds to Chrome immediately. * responds to Chrome immediately.
......
...@@ -117,6 +117,7 @@ public class PaymentRequestTestRule extends ChromeTabbedActivityTestRule ...@@ -117,6 +117,7 @@ public class PaymentRequestTestRule extends ChromeTabbedActivityTestRule
final CallbackHelper mHasEnrolledInstrumentQueryResponded; final CallbackHelper mHasEnrolledInstrumentQueryResponded;
final CallbackHelper mExpirationMonthChange; final CallbackHelper mExpirationMonthChange;
final CallbackHelper mPaymentResponseReady; final CallbackHelper mPaymentResponseReady;
final CallbackHelper mCompleteReplied;
PaymentRequestImpl mPaymentRequest; PaymentRequestImpl mPaymentRequest;
PaymentRequestUI mUI; PaymentRequestUI mUI;
...@@ -156,6 +157,7 @@ public class PaymentRequestTestRule extends ChromeTabbedActivityTestRule ...@@ -156,6 +157,7 @@ public class PaymentRequestTestRule extends ChromeTabbedActivityTestRule
mShowFailed = new CallbackHelper(); mShowFailed = new CallbackHelper();
mCanMakePaymentQueryResponded = new CallbackHelper(); mCanMakePaymentQueryResponded = new CallbackHelper();
mHasEnrolledInstrumentQueryResponded = new CallbackHelper(); mHasEnrolledInstrumentQueryResponded = new CallbackHelper();
mCompleteReplied = new CallbackHelper();
mWebContentsRef = new AtomicReference<>(); mWebContentsRef = new AtomicReference<>();
mTestFilePath = testFileName.equals("about:blank") || testFileName.startsWith("data:") mTestFilePath = testFileName.equals("about:blank") || testFileName.startsWith("data:")
? testFileName ? testFileName
...@@ -242,6 +244,9 @@ public class PaymentRequestTestRule extends ChromeTabbedActivityTestRule ...@@ -242,6 +244,9 @@ public class PaymentRequestTestRule extends ChromeTabbedActivityTestRule
public CallbackHelper getPaymentResponseReady() { public CallbackHelper getPaymentResponseReady() {
return mPaymentResponseReady; return mPaymentResponseReady;
} }
public CallbackHelper getCompleteReplied() {
return mCompleteReplied;
}
public PaymentRequestUI getPaymentRequestUI() { public PaymentRequestUI getPaymentRequestUI() {
return mUI; return mUI;
} }
...@@ -323,6 +328,18 @@ public class PaymentRequestTestRule extends ChromeTabbedActivityTestRule ...@@ -323,6 +328,18 @@ public class PaymentRequestTestRule extends ChromeTabbedActivityTestRule
helper.waitForCallback(callCount); helper.waitForCallback(callCount);
} }
/** Clicks on an element in the error overlay. */
protected void clickErrorOverlayAndWait(int resourceId, CallbackHelper helper)
throws InterruptedException, TimeoutException {
int callCount = helper.getCallCount();
ThreadUtils.runOnUiThreadBlocking(() -> {
// Error overlay always allows clicks and is not taken into account in
// isAcceptingUserInput().
mUI.getDialogForTest().findViewById(resourceId).performClick();
});
helper.waitForCallback(callCount);
}
/** Clicks on an element in the "Order summary" section of the payments UI. */ /** Clicks on an element in the "Order summary" section of the payments UI. */
protected void clickInOrderSummaryAndWait(CallbackHelper helper) protected void clickInOrderSummaryAndWait(CallbackHelper helper)
throws InterruptedException, TimeoutException { throws InterruptedException, TimeoutException {
...@@ -1081,6 +1098,12 @@ public class PaymentRequestTestRule extends ChromeTabbedActivityTestRule ...@@ -1081,6 +1098,12 @@ public class PaymentRequestTestRule extends ChromeTabbedActivityTestRule
mPaymentResponseReady.notifyCalled(); mPaymentResponseReady.notifyCalled();
} }
@Override
public void onCompleteReplied() {
ThreadUtils.assertOnUiThread();
mCompleteReplied.notifyCalled();
}
/** /**
* Listens for UI notifications. * Listens for UI notifications.
*/ */
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
* the UI skip optimization, skipping its own UI enterily and going directly to * the UI skip optimization, skipping its own UI enterily and going directly to
* Bob Pay. * Bob Pay.
*/ */
function buy() { // eslint-disable-line no-unused-vars function buy() { // eslint-disable-line no-unused-vars
try { try {
new PaymentRequest( new PaymentRequest(
[{supportedMethods: 'https://bobpay.com'}], [{supportedMethods: 'https://bobpay.com'}],
...@@ -39,11 +39,38 @@ function buy() { // eslint-disable-line no-unused-vars ...@@ -39,11 +39,38 @@ function buy() { // eslint-disable-line no-unused-vars
} }
} }
/**
* Launches the PaymentRequest UI with Bob Pay as the only payment method, then
* tells the browser that the transaction has failed.
*/
function buyFail() { // eslint-disable-line no-unused-vars
try {
new PaymentRequest(
[{supportedMethods: 'https://bobpay.com'}],
{total: {label: 'Total', amount: {currency: 'USD', value: '5.00'}}})
.show()
.then(function(resp) {
resp.complete('fail')
.then(function() {
print('Transaction failed');
})
.catch(function(error) {
print('complete() rejected<br>' + error);
});
})
.catch(function(error) {
print('show() rejected<br>' + error);
});
} catch (error) {
print('exception thrown<br>' + error);
}
}
/** /**
* Launches the PaymentRequest UI with Bob Pay as the only payment method but * Launches the PaymentRequest UI with Bob Pay as the only payment method but
* requesting the payer's email as to disable skip ui. * requesting the payer's email as to disable skip ui.
*/ */
function buyWithRequestedEmail() { // eslint-disable-line no-unused-vars function buyWithRequestedEmail() { // eslint-disable-line no-unused-vars
try { try {
new PaymentRequest( new PaymentRequest(
[{supportedMethods: 'https://bobpay.com'}], [{supportedMethods: 'https://bobpay.com'}],
......
...@@ -13,6 +13,7 @@ found in the LICENSE file. ...@@ -13,6 +13,7 @@ found in the LICENSE file.
</head> </head>
<body> <body>
<div><button onclick="buy()" id="buy">Bob Pay Test</button></div> <div><button onclick="buy()" id="buy">Bob Pay Test</button></div>
<div><button onclick="buyFail()" id="buyFail">Failure Test</button></div>
<div><button onclick="buyWithRequestedEmail()" id="buyWithRequestedEmail">Bob Pay Test</button></div> <div><button onclick="buyWithRequestedEmail()" id="buyWithRequestedEmail">Bob Pay Test</button></div>
<pre id="result"></pre> <pre id="result"></pre>
<script src="util.js"></script> <script src="util.js"></script>
......
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