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
* Called when the payment response is ready.
*/
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
if (mUI != null) {
mUI.close(immediateClose, () -> {
if (mClient != null) mClient.onComplete();
if (mClient != null) {
if (sObserverForTest != null) sObserverForTest.onCompleteReplied();
mClient.onComplete();
}
closeClient();
});
mUI = null;
......
......@@ -47,6 +47,24 @@ public class PaymentRequestPaymentAppUiSkipTest {
public PaymentRequestTestRule mPaymentRequestTestRule =
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
* responds to Chrome immediately.
......
......@@ -117,6 +117,7 @@ public class PaymentRequestTestRule extends ChromeTabbedActivityTestRule
final CallbackHelper mHasEnrolledInstrumentQueryResponded;
final CallbackHelper mExpirationMonthChange;
final CallbackHelper mPaymentResponseReady;
final CallbackHelper mCompleteReplied;
PaymentRequestImpl mPaymentRequest;
PaymentRequestUI mUI;
......@@ -156,6 +157,7 @@ public class PaymentRequestTestRule extends ChromeTabbedActivityTestRule
mShowFailed = new CallbackHelper();
mCanMakePaymentQueryResponded = new CallbackHelper();
mHasEnrolledInstrumentQueryResponded = new CallbackHelper();
mCompleteReplied = new CallbackHelper();
mWebContentsRef = new AtomicReference<>();
mTestFilePath = testFileName.equals("about:blank") || testFileName.startsWith("data:")
? testFileName
......@@ -242,6 +244,9 @@ public class PaymentRequestTestRule extends ChromeTabbedActivityTestRule
public CallbackHelper getPaymentResponseReady() {
return mPaymentResponseReady;
}
public CallbackHelper getCompleteReplied() {
return mCompleteReplied;
}
public PaymentRequestUI getPaymentRequestUI() {
return mUI;
}
......@@ -323,6 +328,18 @@ public class PaymentRequestTestRule extends ChromeTabbedActivityTestRule
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. */
protected void clickInOrderSummaryAndWait(CallbackHelper helper)
throws InterruptedException, TimeoutException {
......@@ -1081,6 +1098,12 @@ public class PaymentRequestTestRule extends ChromeTabbedActivityTestRule
mPaymentResponseReady.notifyCalled();
}
@Override
public void onCompleteReplied() {
ThreadUtils.assertOnUiThread();
mCompleteReplied.notifyCalled();
}
/**
* Listens for UI notifications.
*/
......
......@@ -14,7 +14,7 @@
* the UI skip optimization, skipping its own UI enterily and going directly to
* Bob Pay.
*/
function buy() { // eslint-disable-line no-unused-vars
function buy() { // eslint-disable-line no-unused-vars
try {
new PaymentRequest(
[{supportedMethods: 'https://bobpay.com'}],
......@@ -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
* 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 {
new PaymentRequest(
[{supportedMethods: 'https://bobpay.com'}],
......
......@@ -13,6 +13,7 @@ found in the LICENSE file.
</head>
<body>
<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>
<pre id="result"></pre>
<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