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

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

Issue 2159513002: NotSupportedError for payment apps without instruments. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@no-methods-supported
Patch Set: Rebase 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
« no previous file with comments | « chrome/android/java/src/org/chromium/chrome/browser/payments/PaymentRequestImpl.java ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/android/javatests/src/org/chromium/chrome/browser/payments/PaymentRequestPaymentAppTest.java
diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/payments/PaymentRequestPaymentAppTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/payments/PaymentRequestPaymentAppTest.java
index c47fd1709f8684886be99af13c9c4e4b53380992..63ad47f7d136117fa08499b1df42ba6a1e7d657f 100644
--- a/chrome/android/javatests/src/org/chromium/chrome/browser/payments/PaymentRequestPaymentAppTest.java
+++ b/chrome/android/javatests/src/org/chromium/chrome/browser/payments/PaymentRequestPaymentAppTest.java
@@ -10,7 +10,6 @@ import android.test.suitebuilder.annotation.MediumTest;
import org.chromium.base.ThreadUtils;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.payments.PaymentAppFactory.PaymentAppFactoryAddition;
-import org.chromium.chrome.browser.payments.ui.PaymentOption;
import org.chromium.content_public.browser.WebContents;
import org.chromium.mojom.payments.PaymentItem;
import org.json.JSONObject;
@@ -26,6 +25,9 @@ import java.util.concurrent.TimeoutException;
* A payment integration test for a merchant that requests payment via Bob Pay.
*/
public class PaymentRequestPaymentAppTest extends PaymentRequestTestBase {
+ private static final int NO_INSTRUMENTS = 0;
+ private static final int HAVE_INSTRUMENTS = 1;
+
private static final int IMMEDIATE_RESPONSE = 0;
private static final int DELAYED_RESPONSE = 1;
@@ -34,16 +36,42 @@ public class PaymentRequestPaymentAppTest extends PaymentRequestTestBase {
}
@Override
- public void onMainActivityStarted()
- throws InterruptedException, ExecutionException, TimeoutException {}
+ public void onMainActivityStarted() throws InterruptedException, ExecutionException,
+ TimeoutException {}
+
+ /** If no payment methods are supported, reject the show() promise. */
+ @MediumTest
+ public void testNoSupportedPaymentMethods() throws InterruptedException, ExecutionException,
+ TimeoutException {
+ triggerUIAndWait(mShowFailed);
+ expectResultContains(
+ new String[]{"show() rejected", "The payment method is not supported"});
+ }
+
+ /**
+ * If Bob Pay does not have any instruments, reject the show() promise. Here Bob Pay responds to
+ * Chrome immediately.
+ */
+ @MediumTest
+ public void testNoInstrumentsInFastBobPay() throws InterruptedException, ExecutionException,
+ TimeoutException {
+ installBobPay(NO_INSTRUMENTS, IMMEDIATE_RESPONSE);
+ triggerUIAndWait(mShowFailed);
+ expectResultContains(
+ new String[]{"show() rejected", "The payment method is not supported"});
+ }
- /** If no payment methods are supported, reject the show() promise before showing any UI. */
+ /**
+ * If Bob Pay does not have any instruments, reject the show() promise. Here Bob Pay responds to
+ * Chrome after a slight delay.
+ */
@MediumTest
- public void testNoSupportedPaymentMethods()
- throws InterruptedException, ExecutionException, TimeoutException {
+ public void testNoInstrumentsInSlowBobPay() throws InterruptedException, ExecutionException,
+ TimeoutException {
+ installBobPay(NO_INSTRUMENTS, DELAYED_RESPONSE);
triggerUIAndWait(mShowFailed);
expectResultContains(
- new String[] {"show() rejected", "The payment method is not supported"});
+ new String[]{"show() rejected", "The payment method is not supported"});
}
/**
@@ -51,12 +79,12 @@ public class PaymentRequestPaymentAppTest extends PaymentRequestTestBase {
* responds to Chrome immediately.
*/
@MediumTest
- public void testPayViaFastBobPay()
- throws InterruptedException, ExecutionException, TimeoutException {
- installBobPay(IMMEDIATE_RESPONSE);
+ public void testPayViaFastBobPay() throws InterruptedException, ExecutionException,
+ TimeoutException {
+ installBobPay(HAVE_INSTRUMENTS, IMMEDIATE_RESPONSE);
triggerUIAndWait(mReadyToPay);
clickAndWait(R.id.button_primary, mDismissed);
- expectResultContains(new String[] {"https://bobpay.com", "\"transaction\"", "1337"});
+ expectResultContains(new String[]{"https://bobpay.com", "\"transaction\"", "1337"});
}
/**
@@ -64,80 +92,94 @@ public class PaymentRequestPaymentAppTest extends PaymentRequestTestBase {
* responds to Chrome after a slight delay.
*/
@MediumTest
- public void testPayViaSlowBobPay()
- throws InterruptedException, ExecutionException, TimeoutException {
- installBobPay(DELAYED_RESPONSE);
+ public void testPayViaSlowBobPay() throws InterruptedException, ExecutionException,
+ TimeoutException {
+ installBobPay(HAVE_INSTRUMENTS, DELAYED_RESPONSE);
triggerUIAndWait(mReadyToPay);
clickAndWait(R.id.button_primary, mDismissed);
- expectResultContains(new String[] {"https://bobpay.com", "\"transaction\"", "1337"});
+ expectResultContains(new String[]{"https://bobpay.com", "\"transaction\"", "1337"});
}
/**
- * Installs Bob Pay as a payment app in Chrome.
+ * Installs a payment app for testing.
*
- * @param responseSpeed How quickly Bob Pay will respond to "get instruments" query. Either
- * IMMEDIATE_RESPONSE or DELAYED_RESPONSE.
+ * @param instrumentPresence Whether Bob Pay has any payment instruments. Either NO_INSTRUMENTS
+ * or HAVE_INSTRUMENTS.
+ * @param responseSpeed How quickly Bob Pay will respond to "get instruments" query. Either
+ * IMMEDIATE_RESPONSE or DELAYED_RESPONSE.
*/
- private void installBobPay(final int responseSpeed) {
+ private void installBobPay(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 PaymentApp() {
- private static final String METHOD_NAME = "https://bobpay.com";
-
- @Override
- public void getInstruments(
- JSONObject details, final InstrumentsCallback instrumentsCallback) {
- final List<PaymentInstrument> instruments = new ArrayList<>();
- instruments.add(new PaymentInstrument(
- METHOD_NAME, "Bob Pay", null, PaymentOption.NO_ICON) {
- @Override
- public String getMethodName() {
- return METHOD_NAME;
- }
-
- @Override
- public void getDetails(String merchantName, String origin,
- PaymentItem total, List<PaymentItem> cart, JSONObject details,
- DetailsCallback detailsCallback) {
- detailsCallback.onInstrumentDetailsReady(
- METHOD_NAME, "{\"transaction\": 1337}");
- }
-
- @Override
- public void dismiss() {}
- });
-
- final PaymentApp app = this;
- Runnable instrumentsReady = new Runnable() {
- @Override
- public void run() {
- ThreadUtils.assertOnUiThread();
- instrumentsCallback.onInstrumentsReady(app, instruments);
- }
- };
- if (responseSpeed == IMMEDIATE_RESPONSE) {
- instrumentsReady.run();
- } else {
- new Handler().postDelayed(instrumentsReady, 100);
- }
- }
-
- @Override
- public Set<String> getSupportedMethodNames() {
- Set<String> methodNames = new HashSet<>();
- methodNames.add(METHOD_NAME);
- return methodNames;
- }
-
- @Override
- public String getIdentifier() {
- return METHOD_NAME;
- }
- });
+ 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() {}
+ }
}
« no previous file with comments | « chrome/android/java/src/org/chromium/chrome/browser/payments/PaymentRequestImpl.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698