| Index: chrome/android/java/src/org/chromium/chrome/browser/payments/ui/PaymentRequestUI.java
|
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/payments/ui/PaymentRequestUI.java b/chrome/android/java/src/org/chromium/chrome/browser/payments/ui/PaymentRequestUI.java
|
| index 2fcc5205783b698432579949fc2cf20e62a5fd6d..87971118b28e7643e8f538321f8dd4763fc37d07 100644
|
| --- a/chrome/android/java/src/org/chromium/chrome/browser/payments/ui/PaymentRequestUI.java
|
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/payments/ui/PaymentRequestUI.java
|
| @@ -24,6 +24,7 @@ import android.widget.LinearLayout;
|
| import android.widget.TextView;
|
|
|
| import org.chromium.base.Callback;
|
| +import org.chromium.base.VisibleForTesting;
|
| import org.chromium.chrome.R;
|
| import org.chromium.chrome.browser.payments.ui.PaymentRequestSection.ExtraTextSection;
|
| import org.chromium.chrome.browser.payments.ui.PaymentRequestSection.LineItemBreakdownSection;
|
| @@ -105,8 +106,11 @@ public class PaymentRequestUI implements DialogInterface.OnDismissListener, View
|
| */
|
| private static final int SHOW_RESULT_DELAY_MS = 3000;
|
|
|
| + private static PaymentRequestUI sCurrentUIForTest;
|
| +
|
| private final Context mContext;
|
| private final Client mClient;
|
| + private final Runnable mDismissCallback;
|
| private final boolean mRequestShipping;
|
|
|
| private final Dialog mDialog;
|
| @@ -131,6 +135,8 @@ public class PaymentRequestUI implements DialogInterface.OnDismissListener, View
|
|
|
| private ViewGroup mSelectedSection;
|
| private boolean mIsShowingEditDialog;
|
| + private int mShowResultDelayMs = SHOW_RESULT_DELAY_MS;
|
| + private boolean mIsClientClosing;
|
|
|
| private List<LineItem> mLineItems;
|
| private SectionInformation mPaymentMethodSectionInformation;
|
| @@ -150,11 +156,27 @@ public class PaymentRequestUI implements DialogInterface.OnDismissListener, View
|
| * “https://shop.momandpop.com”. If the origin is too long for the UI,
|
| * it should elide according to:
|
| * https://www.chromium.org/Home/chromium-security/enamel#TOC-Eliding-Origin-Names-And-Hostnames
|
| + * @return The UI for PaymentRequest.
|
| */
|
| - public PaymentRequestUI(Activity activity, Client client, boolean requestShipping, String title,
|
| - String origin) {
|
| + public static PaymentRequestUI show(Activity activity, Client client, boolean requestShipping,
|
| + String title, String origin) {
|
| + assert sCurrentUIForTest == null;
|
| + PaymentRequestUI ui = new PaymentRequestUI(activity, client, requestShipping, title, origin,
|
| + new Runnable() {
|
| + @Override
|
| + public void run() {
|
| + sCurrentUIForTest = null;
|
| + }
|
| + });
|
| + sCurrentUIForTest = ui;
|
| + return ui;
|
| + }
|
| +
|
| + private PaymentRequestUI(Activity activity, Client client, boolean requestShipping,
|
| + String title, String origin, Runnable dismissCallback) {
|
| mContext = activity;
|
| mClient = client;
|
| + mDismissCallback = dismissCallback;
|
| mRequestShipping = requestShipping;
|
|
|
| mContainer =
|
| @@ -282,7 +304,7 @@ public class PaymentRequestUI implements DialogInterface.OnDismissListener, View
|
| * @param callback The callback to notify of finished animations.
|
| */
|
| public void close(boolean paymentSuccess, final Runnable callback) {
|
| - mDialog.setOnDismissListener(null);
|
| + mIsClientClosing = true;
|
|
|
| if (mWaitingOverlay.getVisibility() == View.GONE) {
|
| mDialog.dismiss();
|
| @@ -305,7 +327,7 @@ public class PaymentRequestUI implements DialogInterface.OnDismissListener, View
|
| mDialog.dismiss();
|
| if (callback != null) callback.run();
|
| }
|
| - }, SHOW_RESULT_DELAY_MS);
|
| + }, mShowResultDelayMs);
|
| }
|
|
|
| /**
|
| @@ -506,11 +528,30 @@ public class PaymentRequestUI implements DialogInterface.OnDismissListener, View
|
| }
|
|
|
| /**
|
| - * Called when the user dismisses the dialog by clicking the "back" button on the phone or the
|
| - * "X" button in the top-right corner of the dialog.
|
| + * Called when the dialog is dismissed. Can be caused by:
|
| + * <ul>
|
| + * <li>User click on the "back" button on the phone.</li>
|
| + * <li>User click on the "X" button in the top-right corner of the dialog.</li>
|
| + * <li>User click on the "CANCEL" button on the bottom of the dialog.</li>
|
| + * <li>Successfully processing the payment.</li>
|
| + * <li>Failure to process the payment.</li>
|
| + * <li>The JavaScript calling the abort() method in PaymentRequest API.</li>
|
| + * <li>The PaymentRequest JavaScript object being destroyed.</li>
|
| + * </ul>
|
| */
|
| @Override
|
| public void onDismiss(DialogInterface dialog) {
|
| - mClient.onDismiss();
|
| + mDismissCallback.run();
|
| + if (!mIsClientClosing) mClient.onDismiss();
|
| + }
|
| +
|
| + @VisibleForTesting
|
| + public static PaymentRequestUI getCurrentUIForTest() {
|
| + return sCurrentUIForTest;
|
| + }
|
| +
|
| + @VisibleForTesting
|
| + public Dialog getDialogForTest() {
|
| + return mDialog;
|
| }
|
| }
|
|
|