Commit 63a3c615 authored by Sahel Sharify's avatar Sahel Sharify Committed by Commit Bot

Calculate skip UI and build UI after payment instruments are ready.

This cl cleans up the order in which we calculate whether or not should
skip UI, building UI, and showing it on Android.
Without this change it is possible that ShouldSkipUI is true but we
still show the payment sheet UI.

After this change we build the UI and calculate ShouldSkipUI after both
of the following conditions are met:
1-request.show is called.
2-All instruments are ready.

To properly handle concurrent request.show attempts, both setting and
reading "sShowingPaymentRequest" should happen in .show().

Bug: 984694
Change-Id: I7ccae4b1346c5206184217f7c721bcc9db9b3df5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1877047Reviewed-by: default avatarRouslan Solomakhin <rouslan@chromium.org>
Commit-Queue: Sahel Sharify <sahel@chromium.org>
Cr-Commit-Position: refs/heads/master@{#711692}
parent e049e13f
......@@ -352,8 +352,8 @@ public class PaymentRequestMetricsTest implements MainActivityStartCallback {
"PaymentRequest.TransactionAmount.Completed"));
// Make sure the events were logged correctly.
int expectedSample = Event.HAD_NECESSARY_COMPLETE_SUGGESTIONS | Event.REQUEST_SHIPPING
| Event.REQUEST_METHOD_GOOGLE | Event.COULD_NOT_SHOW;
int expectedSample =
Event.REQUEST_SHIPPING | Event.REQUEST_METHOD_GOOGLE | Event.COULD_NOT_SHOW;
Assert.assertEquals(1,
RecordHistogram.getHistogramValueCountForTesting(
"PaymentRequest.Events", expectedSample));
......@@ -393,8 +393,8 @@ public class PaymentRequestMetricsTest implements MainActivityStartCallback {
"PaymentRequest.TransactionAmount.Completed"));
// Make sure the events were logged correctly.
int expectedSample = Event.HAD_NECESSARY_COMPLETE_SUGGESTIONS | Event.REQUEST_SHIPPING
| Event.REQUEST_METHOD_OTHER | Event.COULD_NOT_SHOW;
int expectedSample =
Event.REQUEST_SHIPPING | Event.REQUEST_METHOD_OTHER | Event.COULD_NOT_SHOW;
Assert.assertEquals(1,
RecordHistogram.getHistogramValueCountForTesting(
"PaymentRequest.Events", expectedSample));
......
......@@ -41,7 +41,7 @@ public class PaymentRequestShowPromiseInvalidDetailsTest implements MainActivity
@MediumTest
@Feature({"Payments"})
public void testReject() throws TimeoutException {
mRule.openPageAndClickNodeAndWait("buy", mRule.getDismissed());
mRule.openPageAndClickNodeAndWait("buy", mRule.getRendererClosedMojoConnection());
mRule.expectResultContains(new String[] {"Total amount value should be non-negative"});
}
}
......@@ -43,7 +43,7 @@ public class PaymentRequestShowPromiseRejectTest implements MainActivityStartCal
public void testReject() throws TimeoutException {
mRule.installPaymentApp("basic-card", PaymentRequestTestRule.HAVE_INSTRUMENTS,
PaymentRequestTestRule.IMMEDIATE_RESPONSE);
mRule.openPageAndClickNodeAndWait("buy", mRule.getDismissed());
mRule.openPageAndClickNodeAndWait("buy", mRule.getRendererClosedMojoConnection());
mRule.expectResultContains(new String[] {"AbortError"});
}
}
......@@ -41,7 +41,7 @@ public class PaymentRequestShowPromiseUnsupportedTest implements MainActivitySta
@MediumTest
@Feature({"Payments"})
public void testReject() throws TimeoutException {
mRule.openPageAndClickNodeAndWait("buy", mRule.getDismissed());
mRule.openPageAndClickNodeAndWait("buy", mRule.getShowFailed());
mRule.expectResultContains(
new String[] {"NotSupportedError: Payment method not supported"});
}
......
......@@ -118,6 +118,7 @@ public class PaymentRequestTestRule extends ChromeTabbedActivityTestRule
final CallbackHelper mExpirationMonthChange;
final CallbackHelper mPaymentResponseReady;
final CallbackHelper mCompleteReplied;
final CallbackHelper mRendererClosedMojoConnection;
PaymentRequestImpl mPaymentRequest;
PaymentRequestUI mUI;
......@@ -158,6 +159,7 @@ public class PaymentRequestTestRule extends ChromeTabbedActivityTestRule
mCanMakePaymentQueryResponded = new CallbackHelper();
mHasEnrolledInstrumentQueryResponded = new CallbackHelper();
mCompleteReplied = new CallbackHelper();
mRendererClosedMojoConnection = new CallbackHelper();
mWebContentsRef = new AtomicReference<>();
mTestFilePath = testFileName.equals("about:blank") || testFileName.startsWith("data:")
? testFileName
......@@ -247,6 +249,9 @@ public class PaymentRequestTestRule extends ChromeTabbedActivityTestRule
public CallbackHelper getCompleteReplied() {
return mCompleteReplied;
}
public CallbackHelper getRendererClosedMojoConnection() {
return mRendererClosedMojoConnection;
}
public PaymentRequestUI getPaymentRequestUI() {
return mUI;
}
......@@ -1090,6 +1095,12 @@ public class PaymentRequestTestRule extends ChromeTabbedActivityTestRule
mCompleteReplied.notifyCalled();
}
@Override
public void onRendererClosedMojoConnection() {
ThreadUtils.assertOnUiThread();
mRendererClosedMojoConnection.notifyCalled();
}
/**
* Listens for UI notifications.
*/
......
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