| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.chrome.browser.payments; | 5 package org.chromium.chrome.browser.payments; |
| 6 | 6 |
| 7 import android.os.Handler; | 7 import android.os.Handler; |
| 8 import android.view.View; | 8 import android.view.View; |
| 9 import android.view.ViewGroup; | 9 import android.view.ViewGroup; |
| 10 import android.widget.CheckBox; | 10 import android.widget.CheckBox; |
| 11 import android.widget.EditText; | 11 import android.widget.EditText; |
| 12 import android.widget.Spinner; | 12 import android.widget.Spinner; |
| 13 | 13 |
| 14 import org.chromium.base.ThreadUtils; | 14 import org.chromium.base.ThreadUtils; |
| 15 import org.chromium.base.test.util.UrlUtils; | 15 import org.chromium.base.test.util.UrlUtils; |
| 16 import org.chromium.chrome.R; | 16 import org.chromium.chrome.R; |
| 17 import org.chromium.chrome.browser.ChromeActivity; | 17 import org.chromium.chrome.browser.ChromeTabbedActivity; |
| 18 import org.chromium.chrome.browser.autofill.CardUnmaskPrompt; | 18 import org.chromium.chrome.browser.autofill.CardUnmaskPrompt; |
| 19 import org.chromium.chrome.browser.autofill.CardUnmaskPrompt.CardUnmaskObserverF
orTest; | 19 import org.chromium.chrome.browser.autofill.CardUnmaskPrompt.CardUnmaskObserverF
orTest; |
| 20 import org.chromium.chrome.browser.payments.PaymentAppFactory.PaymentAppFactoryA
ddition; | 20 import org.chromium.chrome.browser.payments.PaymentAppFactory.PaymentAppFactoryA
ddition; |
| 21 import org.chromium.chrome.browser.payments.PaymentRequestImpl.PaymentRequestSer
viceObserverForTest; | 21 import org.chromium.chrome.browser.payments.PaymentRequestImpl.PaymentRequestSer
viceObserverForTest; |
| 22 import org.chromium.chrome.browser.payments.ui.EditorTextField; | 22 import org.chromium.chrome.browser.payments.ui.EditorTextField; |
| 23 import org.chromium.chrome.browser.payments.ui.PaymentRequestSection.OptionSecti
on; | 23 import org.chromium.chrome.browser.payments.ui.PaymentRequestSection.OptionSecti
on; |
| 24 import org.chromium.chrome.browser.payments.ui.PaymentRequestSection.OptionSecti
on.OptionRow; | 24 import org.chromium.chrome.browser.payments.ui.PaymentRequestSection.OptionSecti
on.OptionRow; |
| 25 import org.chromium.chrome.browser.payments.ui.PaymentRequestUI; | 25 import org.chromium.chrome.browser.payments.ui.PaymentRequestUI; |
| 26 import org.chromium.chrome.browser.payments.ui.PaymentRequestUI.PaymentRequestOb
serverForTest; | 26 import org.chromium.chrome.browser.payments.ui.PaymentRequestUI.PaymentRequestOb
serverForTest; |
| 27 import org.chromium.chrome.test.ChromeActivityTestCaseBase; | 27 import org.chromium.chrome.test.ChromeActivityTestCaseBase; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 39 import java.util.List; | 39 import java.util.List; |
| 40 import java.util.Set; | 40 import java.util.Set; |
| 41 import java.util.concurrent.Callable; | 41 import java.util.concurrent.Callable; |
| 42 import java.util.concurrent.ExecutionException; | 42 import java.util.concurrent.ExecutionException; |
| 43 import java.util.concurrent.TimeoutException; | 43 import java.util.concurrent.TimeoutException; |
| 44 import java.util.concurrent.atomic.AtomicReference; | 44 import java.util.concurrent.atomic.AtomicReference; |
| 45 | 45 |
| 46 /** | 46 /** |
| 47 * A base integration test for payments. | 47 * A base integration test for payments. |
| 48 */ | 48 */ |
| 49 abstract class PaymentRequestTestBase extends ChromeActivityTestCaseBase<ChromeA
ctivity> | 49 abstract class PaymentRequestTestBase extends ChromeActivityTestCaseBase<ChromeT
abbedActivity> |
| 50 implements PaymentRequestObserverForTest, PaymentRequestServiceObserverF
orTest, | 50 implements PaymentRequestObserverForTest, PaymentRequestServiceObserverF
orTest, |
| 51 CardUnmaskObserverForTest { | 51 CardUnmaskObserverForTest { |
| 52 /** Flag for installing a payment app without instruments. */ | 52 /** Flag for installing a payment app without instruments. */ |
| 53 protected static final int NO_INSTRUMENTS = 0; | 53 protected static final int NO_INSTRUMENTS = 0; |
| 54 | 54 |
| 55 /** Flag for installing a payment app with instruments. */ | 55 /** Flag for installing a payment app with instruments. */ |
| 56 protected static final int HAVE_INSTRUMENTS = 1; | 56 protected static final int HAVE_INSTRUMENTS = 1; |
| 57 | 57 |
| 58 /** Flag for installing a fast payment app. */ | 58 /** Flag for installing a fast payment app. */ |
| 59 protected static final int IMMEDIATE_RESPONSE = 0; | 59 protected static final int IMMEDIATE_RESPONSE = 0; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 75 protected final CallbackHelper mBillingAddressChangeProcessed; | 75 protected final CallbackHelper mBillingAddressChangeProcessed; |
| 76 protected final CallbackHelper mShowFailed; | 76 protected final CallbackHelper mShowFailed; |
| 77 protected PaymentRequestUI mUI; | 77 protected PaymentRequestUI mUI; |
| 78 | 78 |
| 79 private final AtomicReference<ContentViewCore> mViewCoreRef; | 79 private final AtomicReference<ContentViewCore> mViewCoreRef; |
| 80 private final AtomicReference<WebContents> mWebContentsRef; | 80 private final AtomicReference<WebContents> mWebContentsRef; |
| 81 private final String mTestFilePath; | 81 private final String mTestFilePath; |
| 82 private CardUnmaskPrompt mCardUnmaskPrompt; | 82 private CardUnmaskPrompt mCardUnmaskPrompt; |
| 83 | 83 |
| 84 protected PaymentRequestTestBase(String testFileName) { | 84 protected PaymentRequestTestBase(String testFileName) { |
| 85 super(ChromeActivity.class); | 85 super(ChromeTabbedActivity.class); |
| 86 mReadyForInput = new PaymentsCallbackHelper<>(); | 86 mReadyForInput = new PaymentsCallbackHelper<>(); |
| 87 mReadyToPay = new PaymentsCallbackHelper<>(); | 87 mReadyToPay = new PaymentsCallbackHelper<>(); |
| 88 mSelectionChecked = new PaymentsCallbackHelper<>(); | 88 mSelectionChecked = new PaymentsCallbackHelper<>(); |
| 89 mResultReady = new PaymentsCallbackHelper<>(); | 89 mResultReady = new PaymentsCallbackHelper<>(); |
| 90 mReadyForUnmaskInput = new PaymentsCallbackHelper<>(); | 90 mReadyForUnmaskInput = new PaymentsCallbackHelper<>(); |
| 91 mReadyToUnmask = new PaymentsCallbackHelper<>(); | 91 mReadyToUnmask = new PaymentsCallbackHelper<>(); |
| 92 mReadyToEdit = new CallbackHelper(); | 92 mReadyToEdit = new CallbackHelper(); |
| 93 mEditorValidationError = new CallbackHelper(); | 93 mEditorValidationError = new CallbackHelper(); |
| 94 mEditorTextUpdate = new CallbackHelper(); | 94 mEditorTextUpdate = new CallbackHelper(); |
| 95 mDismissed = new CallbackHelper(); | 95 mDismissed = new CallbackHelper(); |
| 96 mUnableToAbort = new CallbackHelper(); | 96 mUnableToAbort = new CallbackHelper(); |
| 97 mBillingAddressChangeProcessed = new CallbackHelper(); | 97 mBillingAddressChangeProcessed = new CallbackHelper(); |
| 98 mShowFailed = new CallbackHelper(); | 98 mShowFailed = new CallbackHelper(); |
| 99 mViewCoreRef = new AtomicReference<>(); | 99 mViewCoreRef = new AtomicReference<>(); |
| 100 mWebContentsRef = new AtomicReference<>(); | 100 mWebContentsRef = new AtomicReference<>(); |
| 101 mTestFilePath = UrlUtils.getIsolatedTestFilePath( | 101 mTestFilePath = UrlUtils.getIsolatedTestFilePath( |
| 102 String.format("chrome/test/data/android/payments/%s", testFileNa
me)); | 102 String.format("chrome/test/data/android/payments/%s", testFileNa
me)); |
| 103 } | 103 } |
| 104 | 104 |
| 105 @Override | 105 @Override |
| 106 public void startMainActivity() throws InterruptedException {} | 106 public void startMainActivity() throws InterruptedException {} |
| 107 | 107 |
| 108 protected abstract void onMainActivityStarted() | 108 protected abstract void onMainActivityStarted() |
| 109 throws InterruptedException, ExecutionException, TimeoutException; | 109 throws InterruptedException, ExecutionException, TimeoutException; |
| 110 | 110 |
| 111 protected void triggerUIAndWait(PaymentsCallbackHelper<PaymentRequestUI> hel
per) | 111 protected void triggerUIAndWait(PaymentsCallbackHelper<PaymentRequestUI> hel
per) |
| 112 throws InterruptedException, ExecutionException, TimeoutException { | 112 throws InterruptedException, ExecutionException, TimeoutException { |
| 113 triggerUIAndWait((CallbackHelper) helper); | 113 triggerUIAndWait("buy", (CallbackHelper) helper); |
| 114 mUI = helper.getTarget(); | 114 mUI = helper.getTarget(); |
| 115 } | 115 } |
| 116 | 116 |
| 117 protected void triggerUIAndWait(CallbackHelper helper) | 117 protected void triggerUIAndWait(CallbackHelper helper) |
| 118 throws InterruptedException, ExecutionException, TimeoutException { | 118 throws InterruptedException, ExecutionException, TimeoutException { |
| 119 triggerUIAndWait("buy", helper); |
| 120 } |
| 121 |
| 122 protected void triggerUIAndWait(String nodeId, CallbackHelper helper) |
| 123 throws InterruptedException, ExecutionException, TimeoutException { |
| 119 startMainActivityWithURL(mTestFilePath); | 124 startMainActivityWithURL(mTestFilePath); |
| 120 onMainActivityStarted(); | 125 onMainActivityStarted(); |
| 121 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | 126 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
| 122 @Override | 127 @Override |
| 123 public void run() { | 128 public void run() { |
| 124 mViewCoreRef.set(getActivity().getCurrentContentViewCore()); | 129 mViewCoreRef.set(getActivity().getCurrentContentViewCore()); |
| 125 mWebContentsRef.set(mViewCoreRef.get().getWebContents()); | 130 mWebContentsRef.set(mViewCoreRef.get().getWebContents()); |
| 126 PaymentRequestUI.setObserverForTest(PaymentRequestTestBase.this)
; | 131 PaymentRequestUI.setObserverForTest(PaymentRequestTestBase.this)
; |
| 127 PaymentRequestImpl.setObserverForTest(PaymentRequestTestBase.thi
s); | 132 PaymentRequestImpl.setObserverForTest(PaymentRequestTestBase.thi
s); |
| 128 CardUnmaskPrompt.setObserverForTest(PaymentRequestTestBase.this)
; | 133 CardUnmaskPrompt.setObserverForTest(PaymentRequestTestBase.this)
; |
| 129 } | 134 } |
| 130 }); | 135 }); |
| 131 assertWaitForPageScaleFactorMatch(1); | 136 assertWaitForPageScaleFactorMatch(1); |
| 132 clickNodeAndWait("buy", helper); | 137 clickNodeAndWait(nodeId, helper); |
| 133 } | 138 } |
| 134 | 139 |
| 135 /** Clicks on an HTML node. */ | 140 /** Clicks on an HTML node. */ |
| 136 protected void clickNodeAndWait(String nodeId, CallbackHelper helper) | 141 protected void clickNodeAndWait(String nodeId, CallbackHelper helper) |
| 137 throws InterruptedException, ExecutionException, TimeoutException { | 142 throws InterruptedException, ExecutionException, TimeoutException { |
| 138 int callCount = helper.getCallCount(); | 143 int callCount = helper.getCallCount(); |
| 139 DOMUtils.clickNode(this, mViewCoreRef.get(), nodeId); | 144 DOMUtils.clickNode(this, mViewCoreRef.get(), nodeId); |
| 140 helper.waitForCallback(callCount); | 145 helper.waitForCallback(callCount); |
| 141 } | 146 } |
| 142 | 147 |
| (...skipping 540 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 683 public void getDetails(String merchantName, String origin, PaymentItem t
otal, | 688 public void getDetails(String merchantName, String origin, PaymentItem t
otal, |
| 684 List<PaymentItem> cart, JSONObject details, DetailsCallback deta
ilsCallback) { | 689 List<PaymentItem> cart, JSONObject details, DetailsCallback deta
ilsCallback) { |
| 685 detailsCallback.onInstrumentDetailsReady( | 690 detailsCallback.onInstrumentDetailsReady( |
| 686 "https://bobpay.com", "{\"transaction\": 1337}"); | 691 "https://bobpay.com", "{\"transaction\": 1337}"); |
| 687 } | 692 } |
| 688 | 693 |
| 689 @Override | 694 @Override |
| 690 public void dismiss() {} | 695 public void dismiss() {} |
| 691 } | 696 } |
| 692 } | 697 } |
| OLD | NEW |