| 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.widget.EditText; | 7 import android.widget.EditText; |
| 8 import android.widget.TextView; | 8 import android.widget.TextView; |
| 9 | 9 |
| 10 import org.chromium.base.ThreadUtils; | 10 import org.chromium.base.ThreadUtils; |
| 11 import org.chromium.base.test.util.CommandLineFlags; | 11 import org.chromium.base.test.util.CommandLineFlags; |
| 12 import org.chromium.base.test.util.UrlUtils; | 12 import org.chromium.base.test.util.UrlUtils; |
| 13 import org.chromium.chrome.R; | 13 import org.chromium.chrome.R; |
| 14 import org.chromium.chrome.browser.ChromeActivity; | 14 import org.chromium.chrome.browser.ChromeActivity; |
| 15 import org.chromium.chrome.browser.ChromeSwitches; | 15 import org.chromium.chrome.browser.ChromeSwitches; |
| 16 import org.chromium.chrome.browser.autofill.CardUnmaskPrompt; | 16 import org.chromium.chrome.browser.autofill.CardUnmaskPrompt; |
| 17 import org.chromium.chrome.browser.autofill.CardUnmaskPrompt.CardUnmaskObserverF
orTest; | 17 import org.chromium.chrome.browser.autofill.CardUnmaskPrompt.CardUnmaskObserverF
orTest; |
| 18 import org.chromium.chrome.browser.payments.PaymentRequestImpl.PaymentRequestSer
viceObserverForTest; |
| 18 import org.chromium.chrome.browser.payments.ui.PaymentRequestUI; | 19 import org.chromium.chrome.browser.payments.ui.PaymentRequestUI; |
| 19 import org.chromium.chrome.browser.payments.ui.PaymentRequestUI.PaymentRequestOb
serverForTest; | 20 import org.chromium.chrome.browser.payments.ui.PaymentRequestUI.PaymentRequestOb
serverForTest; |
| 20 import org.chromium.chrome.test.ChromeActivityTestCaseBase; | 21 import org.chromium.chrome.test.ChromeActivityTestCaseBase; |
| 21 import org.chromium.content.browser.ContentViewCore; | 22 import org.chromium.content.browser.ContentViewCore; |
| 22 import org.chromium.content.browser.test.util.CallbackHelper; | 23 import org.chromium.content.browser.test.util.CallbackHelper; |
| 23 import org.chromium.content.browser.test.util.Criteria; | 24 import org.chromium.content.browser.test.util.Criteria; |
| 24 import org.chromium.content.browser.test.util.CriteriaHelper; | 25 import org.chromium.content.browser.test.util.CriteriaHelper; |
| 25 import org.chromium.content.browser.test.util.DOMUtils; | 26 import org.chromium.content.browser.test.util.DOMUtils; |
| 26 import org.chromium.content_public.browser.WebContents; | 27 import org.chromium.content_public.browser.WebContents; |
| 27 | 28 |
| 28 import java.util.concurrent.Callable; | 29 import java.util.concurrent.Callable; |
| 29 import java.util.concurrent.ExecutionException; | 30 import java.util.concurrent.ExecutionException; |
| 30 import java.util.concurrent.TimeoutException; | 31 import java.util.concurrent.TimeoutException; |
| 31 import java.util.concurrent.atomic.AtomicReference; | 32 import java.util.concurrent.atomic.AtomicReference; |
| 32 | 33 |
| 33 /** | 34 /** |
| 34 * A base integration test for payments. | 35 * A base integration test for payments. |
| 35 */ | 36 */ |
| 36 @CommandLineFlags.Add({ChromeSwitches.EXPERIMENTAL_WEB_PLAFTORM_FEATURES}) | 37 @CommandLineFlags.Add({ChromeSwitches.EXPERIMENTAL_WEB_PLAFTORM_FEATURES}) |
| 37 abstract class PaymentRequestTestBase extends ChromeActivityTestCaseBase<ChromeA
ctivity> | 38 abstract class PaymentRequestTestBase extends ChromeActivityTestCaseBase<ChromeA
ctivity> |
| 38 implements PaymentRequestObserverForTest, CardUnmaskObserverForTest { | 39 implements PaymentRequestObserverForTest, PaymentRequestServiceObserverF
orTest, |
| 40 CardUnmaskObserverForTest { |
| 39 protected final PaymentsCallbackHelper<PaymentRequestUI> mReadyForInput; | 41 protected final PaymentsCallbackHelper<PaymentRequestUI> mReadyForInput; |
| 40 protected final PaymentsCallbackHelper<PaymentRequestUI> mReadyToPay; | 42 protected final PaymentsCallbackHelper<PaymentRequestUI> mReadyToPay; |
| 41 protected final PaymentsCallbackHelper<PaymentRequestUI> mReadyToClose; | 43 protected final PaymentsCallbackHelper<PaymentRequestUI> mReadyToClose; |
| 42 protected final PaymentsCallbackHelper<PaymentRequestUI> mResultReady; | 44 protected final PaymentsCallbackHelper<PaymentRequestUI> mResultReady; |
| 43 protected final PaymentsCallbackHelper<CardUnmaskPrompt> mReadyForUnmaskInpu
t; | 45 protected final PaymentsCallbackHelper<CardUnmaskPrompt> mReadyForUnmaskInpu
t; |
| 44 protected final PaymentsCallbackHelper<CardUnmaskPrompt> mReadyToUnmask; | 46 protected final PaymentsCallbackHelper<CardUnmaskPrompt> mReadyToUnmask; |
| 45 protected final CallbackHelper mDismissed; | 47 protected final CallbackHelper mDismissed; |
| 48 protected final CallbackHelper mUnableToAbort; |
| 46 private final AtomicReference<ContentViewCore> mViewCoreRef; | 49 private final AtomicReference<ContentViewCore> mViewCoreRef; |
| 47 private final AtomicReference<WebContents> mWebContentsRef; | 50 private final AtomicReference<WebContents> mWebContentsRef; |
| 48 private final String mTestFilePath; | 51 private final String mTestFilePath; |
| 49 private PaymentRequestUI mUI; | 52 private PaymentRequestUI mUI; |
| 50 | 53 |
| 51 protected PaymentRequestTestBase(String testFileName) { | 54 protected PaymentRequestTestBase(String testFileName) { |
| 52 super(ChromeActivity.class); | 55 super(ChromeActivity.class); |
| 53 mReadyForInput = new PaymentsCallbackHelper<>(); | 56 mReadyForInput = new PaymentsCallbackHelper<>(); |
| 54 mReadyToPay = new PaymentsCallbackHelper<>(); | 57 mReadyToPay = new PaymentsCallbackHelper<>(); |
| 55 mReadyToClose = new PaymentsCallbackHelper<>(); | 58 mReadyToClose = new PaymentsCallbackHelper<>(); |
| 56 mResultReady = new PaymentsCallbackHelper<>(); | 59 mResultReady = new PaymentsCallbackHelper<>(); |
| 57 mReadyForUnmaskInput = new PaymentsCallbackHelper<>(); | 60 mReadyForUnmaskInput = new PaymentsCallbackHelper<>(); |
| 58 mReadyToUnmask = new PaymentsCallbackHelper<>(); | 61 mReadyToUnmask = new PaymentsCallbackHelper<>(); |
| 59 mDismissed = new CallbackHelper(); | 62 mDismissed = new CallbackHelper(); |
| 63 mUnableToAbort = new CallbackHelper(); |
| 60 mViewCoreRef = new AtomicReference<>(); | 64 mViewCoreRef = new AtomicReference<>(); |
| 61 mWebContentsRef = new AtomicReference<>(); | 65 mWebContentsRef = new AtomicReference<>(); |
| 62 mTestFilePath = UrlUtils.getIsolatedTestFilePath( | 66 mTestFilePath = UrlUtils.getIsolatedTestFilePath( |
| 63 String.format("chrome/test/data/android/payments/%s", testFileNa
me)); | 67 String.format("chrome/test/data/android/payments/%s", testFileNa
me)); |
| 64 } | 68 } |
| 65 | 69 |
| 66 @Override | 70 @Override |
| 67 public void startMainActivity() throws InterruptedException {} | 71 public void startMainActivity() throws InterruptedException {} |
| 68 | 72 |
| 69 protected abstract void onMainActivityStarted() | 73 protected abstract void onMainActivityStarted() |
| 70 throws InterruptedException, ExecutionException, TimeoutException; | 74 throws InterruptedException, ExecutionException, TimeoutException; |
| 71 | 75 |
| 72 protected void triggerUIAndWait(PaymentsCallbackHelper<PaymentRequestUI> hel
per) | 76 protected void triggerUIAndWait(PaymentsCallbackHelper<PaymentRequestUI> hel
per) |
| 73 throws InterruptedException, ExecutionException, TimeoutException { | 77 throws InterruptedException, ExecutionException, TimeoutException { |
| 74 startMainActivityWithURL(mTestFilePath); | 78 startMainActivityWithURL(mTestFilePath); |
| 75 onMainActivityStarted(); | 79 onMainActivityStarted(); |
| 76 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | 80 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
| 77 @Override | 81 @Override |
| 78 public void run() { | 82 public void run() { |
| 79 mViewCoreRef.set(getActivity().getCurrentContentViewCore()); | 83 mViewCoreRef.set(getActivity().getCurrentContentViewCore()); |
| 80 mWebContentsRef.set(mViewCoreRef.get().getWebContents()); | 84 mWebContentsRef.set(mViewCoreRef.get().getWebContents()); |
| 81 PaymentRequestUI.setObserverForTest(PaymentRequestTestBase.this)
; | 85 PaymentRequestUI.setObserverForTest(PaymentRequestTestBase.this)
; |
| 86 PaymentRequestImpl.setObserverForTest(PaymentRequestTestBase.thi
s); |
| 82 CardUnmaskPrompt.setObserverForTest(PaymentRequestTestBase.this)
; | 87 CardUnmaskPrompt.setObserverForTest(PaymentRequestTestBase.this)
; |
| 83 } | 88 } |
| 84 }); | 89 }); |
| 85 assertWaitForPageScaleFactorMatch(1); | 90 assertWaitForPageScaleFactorMatch(1); |
| 86 | 91 clickNodeAndWait("buy", helper); |
| 87 int callCount = helper.getCallCount(); | |
| 88 DOMUtils.clickNode(this, mViewCoreRef.get(), "buy"); | |
| 89 helper.waitForCallback(callCount); | |
| 90 mUI = helper.getTarget(); | 92 mUI = helper.getTarget(); |
| 91 } | 93 } |
| 92 | 94 |
| 95 protected void clickNodeAndWait(String nodeId, CallbackHelper helper) |
| 96 throws InterruptedException, ExecutionException, TimeoutException { |
| 97 int callCount = helper.getCallCount(); |
| 98 DOMUtils.clickNode(this, mViewCoreRef.get(), nodeId); |
| 99 helper.waitForCallback(callCount); |
| 100 } |
| 101 |
| 93 protected void clickAndWait(final int resourceId, CallbackHelper helper) | 102 protected void clickAndWait(final int resourceId, CallbackHelper helper) |
| 94 throws InterruptedException, TimeoutException { | 103 throws InterruptedException, TimeoutException { |
| 95 int callCount = helper.getCallCount(); | 104 int callCount = helper.getCallCount(); |
| 96 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | 105 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
| 97 @Override | 106 @Override |
| 98 public void run() { | 107 public void run() { |
| 99 mUI.getDialogForTest().findViewById(resourceId).performClick(); | 108 mUI.getDialogForTest().findViewById(resourceId).performClick(); |
| 100 } | 109 } |
| 101 }); | 110 }); |
| 102 helper.waitForCallback(callCount); | 111 helper.waitForCallback(callCount); |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 ThreadUtils.assertOnUiThread(); | 193 ThreadUtils.assertOnUiThread(); |
| 185 mReadyToClose.notifyCalled(ui); | 194 mReadyToClose.notifyCalled(ui); |
| 186 } | 195 } |
| 187 | 196 |
| 188 @Override | 197 @Override |
| 189 public void onPaymentRequestResultReady(PaymentRequestUI ui) { | 198 public void onPaymentRequestResultReady(PaymentRequestUI ui) { |
| 190 ThreadUtils.assertOnUiThread(); | 199 ThreadUtils.assertOnUiThread(); |
| 191 mResultReady.notifyCalled(ui); | 200 mResultReady.notifyCalled(ui); |
| 192 } | 201 } |
| 193 | 202 |
| 194 | |
| 195 @Override | 203 @Override |
| 196 public void onPaymentRequestDismiss() { | 204 public void onPaymentRequestDismiss() { |
| 197 ThreadUtils.assertOnUiThread(); | 205 ThreadUtils.assertOnUiThread(); |
| 198 mDismissed.notifyCalled(); | 206 mDismissed.notifyCalled(); |
| 199 } | 207 } |
| 200 | 208 |
| 201 @Override | 209 @Override |
| 210 public void onPaymentRequestServiceUnableToAbort() { |
| 211 ThreadUtils.assertOnUiThread(); |
| 212 mUnableToAbort.notifyCalled(); |
| 213 } |
| 214 |
| 215 @Override |
| 202 public void onCardUnmaskPromptReadyForInput(CardUnmaskPrompt prompt) { | 216 public void onCardUnmaskPromptReadyForInput(CardUnmaskPrompt prompt) { |
| 203 ThreadUtils.assertOnUiThread(); | 217 ThreadUtils.assertOnUiThread(); |
| 204 mReadyForUnmaskInput.notifyCalled(prompt); | 218 mReadyForUnmaskInput.notifyCalled(prompt); |
| 205 } | 219 } |
| 206 | 220 |
| 207 @Override | 221 @Override |
| 208 public void onCardUnmaskPromptReadyToUnmask(CardUnmaskPrompt prompt) { | 222 public void onCardUnmaskPromptReadyToUnmask(CardUnmaskPrompt prompt) { |
| 209 ThreadUtils.assertOnUiThread(); | 223 ThreadUtils.assertOnUiThread(); |
| 210 mReadyToUnmask.notifyCalled(prompt); | 224 mReadyToUnmask.notifyCalled(prompt); |
| 211 } | 225 } |
| (...skipping 18 matching lines...) Expand all Loading... |
| 230 * | 244 * |
| 231 * @param ui The UI that is ready for input. | 245 * @param ui The UI that is ready for input. |
| 232 */ | 246 */ |
| 233 public void notifyCalled(T target) { | 247 public void notifyCalled(T target) { |
| 234 ThreadUtils.assertOnUiThread(); | 248 ThreadUtils.assertOnUiThread(); |
| 235 mTarget = target; | 249 mTarget = target; |
| 236 notifyCalled(); | 250 notifyCalled(); |
| 237 } | 251 } |
| 238 } | 252 } |
| 239 } | 253 } |
| OLD | NEW |