Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2904)

Unified Diff: chrome/android/javatests/src/org/chromium/chrome/browser/payments/PaymentRequestTestBase.java

Issue 2165163002: Autofill cards at the bottom of the PaymentRequest UI (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Static comparator and faux-parameterized test Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/android/javatests/src/org/chromium/chrome/browser/payments/PaymentRequestTestBase.java
diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/payments/PaymentRequestTestBase.java b/chrome/android/javatests/src/org/chromium/chrome/browser/payments/PaymentRequestTestBase.java
index a138fb42285c69fb0b5e54d514be78f3174df255..8766cc78492295c99777f0dfd1ea611c0d19d32d 100644
--- a/chrome/android/javatests/src/org/chromium/chrome/browser/payments/PaymentRequestTestBase.java
+++ b/chrome/android/javatests/src/org/chromium/chrome/browser/payments/PaymentRequestTestBase.java
@@ -4,6 +4,7 @@
package org.chromium.chrome.browser.payments;
+import android.os.Handler;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
@@ -17,6 +18,7 @@ import org.chromium.chrome.R;
import org.chromium.chrome.browser.ChromeActivity;
import org.chromium.chrome.browser.autofill.CardUnmaskPrompt;
import org.chromium.chrome.browser.autofill.CardUnmaskPrompt.CardUnmaskObserverForTest;
+import org.chromium.chrome.browser.payments.PaymentAppFactory.PaymentAppFactoryAddition;
import org.chromium.chrome.browser.payments.PaymentRequestImpl.PaymentRequestServiceObserverForTest;
import org.chromium.chrome.browser.payments.ui.EditorTextField;
import org.chromium.chrome.browser.payments.ui.PaymentRequestSection.OptionSection;
@@ -29,8 +31,13 @@ import org.chromium.content.browser.test.util.Criteria;
import org.chromium.content.browser.test.util.CriteriaHelper;
import org.chromium.content.browser.test.util.DOMUtils;
import org.chromium.content_public.browser.WebContents;
+import org.chromium.mojom.payments.PaymentItem;
+import org.json.JSONObject;
+import java.util.ArrayList;
+import java.util.HashSet;
import java.util.List;
+import java.util.Set;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeoutException;
@@ -42,6 +49,18 @@ import java.util.concurrent.atomic.AtomicReference;
abstract class PaymentRequestTestBase extends ChromeActivityTestCaseBase<ChromeActivity>
implements PaymentRequestObserverForTest, PaymentRequestServiceObserverForTest,
CardUnmaskObserverForTest {
+ /** Flag for installing a payment app without instruments. */
+ protected static final int NO_INSTRUMENTS = 0;
+
+ /** Flag for installing a payment app with instruments. */
+ protected static final int HAVE_INSTRUMENTS = 1;
+
+ /** Flag for installing a fast payment app. */
+ protected static final int IMMEDIATE_RESPONSE = 0;
+
+ /** Flag for installing a slow payment app. */
+ protected static final int DELAYED_RESPONSE = 1;
+
protected final PaymentsCallbackHelper<PaymentRequestUI> mReadyForInput;
protected final PaymentsCallbackHelper<PaymentRequestUI> mReadyToPay;
protected final PaymentsCallbackHelper<PaymentRequestUI> mReadyToClose;
@@ -240,14 +259,23 @@ abstract class PaymentRequestTestBase extends ChromeActivityTestCaseBase<ChromeA
});
}
+ /** Returns the label corresponding to the payment instrument at the specified |index|. */
+ protected String getPaymentInstrumentLabel(final int index) throws ExecutionException {
+ return ThreadUtils.runOnUiThreadBlocking(new Callable<String>() {
+ @Override
+ public String call() {
+ return ((OptionSection) mUI.getPaymentMethodSectionForTest())
+ .getOptionLabelsForTest(index).getText().toString();
+ }
+ });
+ }
+
/**
* Returns the label corresponding to the contact detail suggestion at the specified
* |suggestionIndex|.
*/
protected String getContactDetailsSuggestionLabel(final int suggestionIndex)
throws ExecutionException {
- assert (suggestionIndex < getNumberOfContactDetailSuggestions());
-
return ThreadUtils.runOnUiThreadBlocking(new Callable<String>() {
@Override
public String call() {
@@ -257,9 +285,18 @@ abstract class PaymentRequestTestBase extends ChromeActivityTestCaseBase<ChromeA
});
}
- /**
- * Returns the the number of contact detail suggestions,
- */
+ /** Returns the the number of payment instruments. */
+ protected int getNumberOfPaymentInstruments() throws ExecutionException {
+ return ThreadUtils.runOnUiThreadBlocking(new Callable<Integer>() {
+ @Override
+ public Integer call() {
+ return ((OptionSection) mUI.getPaymentMethodSectionForTest())
+ .getNumberOfOptionLabelsForTest();
+ }
+ });
+ }
+
+ /** Returns the the number of contact detail suggestions. */
protected int getNumberOfContactDetailSuggestions() throws ExecutionException {
return ThreadUtils.runOnUiThreadBlocking(new Callable<Integer>() {
@Override
@@ -528,4 +565,87 @@ abstract class PaymentRequestTestBase extends ChromeActivityTestCaseBase<ChromeA
notifyCalled();
}
}
+
+ /**
+ * Installs a payment app for testing.
+ *
+ * @param instrumentPresence Whether the app has any payment instruments. Either NO_INSTRUMENTS
+ * or HAVE_INSTRUMENTS.
+ * @param responseSpeed How quickly the app will respond to "get instruments" query. Either
+ * IMMEDIATE_RESPONSE or DELAYED_RESPONSE.
+ */
+ protected void installPaymentApp(final int instrumentPresence, final int responseSpeed) {
+ PaymentAppFactory.setAdditionalFactory(new PaymentAppFactoryAddition() {
+ @Override
+ public List<PaymentApp> create(WebContents webContents) {
+ List<PaymentApp> additionalApps = new ArrayList<>();
+ additionalApps.add(new BobPay(instrumentPresence, responseSpeed));
+ return additionalApps;
+ }
+ });
+ }
+
+ /** A payment app implementation for test. */
+ private static class BobPay implements PaymentApp {
+ private final int mInstrumentPresence;
+ private final int mResponseSpeed;
+
+ BobPay(int instrumentPresence, int responseSpeed) {
+ mInstrumentPresence = instrumentPresence;
+ mResponseSpeed = responseSpeed;
+ }
+
+ @Override
+ public void getInstruments(JSONObject details, final InstrumentsCallback
+ instrumentsCallback) {
+ final List<PaymentInstrument> instruments = new ArrayList<>();
+ if (mInstrumentPresence == HAVE_INSTRUMENTS) instruments.add(new BobPayInstrument());
+ Runnable instrumentsReady = new Runnable() {
+ @Override
+ public void run() {
+ ThreadUtils.assertOnUiThread();
+ instrumentsCallback.onInstrumentsReady(BobPay.this, instruments);
+ }
+ };
+ if (mResponseSpeed == IMMEDIATE_RESPONSE) {
+ instrumentsReady.run();
+ } else {
+ new Handler().postDelayed(instrumentsReady, 100);
+ }
+ }
+
+ @Override
+ public Set<String> getSupportedMethodNames() {
+ Set<String> methodNames = new HashSet<>();
+ methodNames.add("https://bobpay.com");
+ return methodNames;
+ }
+
+ @Override
+ public String getIdentifier() {
+ return "https://bobpay.com";
+ }
+ }
+
+ /** A payment instrument implementation for test. */
+ private static class BobPayInstrument extends PaymentInstrument {
+ BobPayInstrument() {
+ super("https://bobpay.com", "Bob Pay", null, NO_ICON);
+ }
+
+ @Override
+ public String getMethodName() {
+ return "https://bobpay.com";
+ }
+
+ @Override
+ public void getDetails(String merchantName, String origin, PaymentItem total,
+ List<PaymentItem> cart, JSONObject details, DetailsCallback detailsCallback) {
+ detailsCallback.onInstrumentDetailsReady(
+ "https://bobpay.com", "{\"transaction\": 1337}");
+ }
+
+ @Override
+ public void dismiss() {}
+ }
}

Powered by Google App Engine
This is Rietveld 408576698