| 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 4411f34b07efed7bb497d238dbfc922e33e254a9..d404ed4d74822808dbe8afabae0543cea9881848 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,17 +4,16 @@
|
|
|
| package org.chromium.chrome.browser.payments;
|
|
|
| -import android.view.View;
|
| -
|
| import org.chromium.base.ThreadUtils;
|
| import org.chromium.base.test.util.CommandLineFlags;
|
| import org.chromium.base.test.util.UrlUtils;
|
| -import org.chromium.chrome.R;
|
| import org.chromium.chrome.browser.ChromeActivity;
|
| import org.chromium.chrome.browser.ChromeSwitches;
|
| import org.chromium.chrome.browser.payments.ui.PaymentRequestUI;
|
| +import org.chromium.chrome.browser.payments.ui.PaymentRequestUI.PaymentRequestObserverForTest;
|
| import org.chromium.chrome.test.ChromeActivityTestCaseBase;
|
| import org.chromium.content.browser.ContentViewCore;
|
| +import org.chromium.content.browser.test.util.CallbackHelper;
|
| import org.chromium.content.browser.test.util.Criteria;
|
| import org.chromium.content.browser.test.util.CriteriaHelper;
|
| import org.chromium.content.browser.test.util.DOMUtils;
|
| @@ -28,11 +27,16 @@ import java.util.concurrent.atomic.AtomicReference;
|
| * A base integration test for payments.
|
| */
|
| @CommandLineFlags.Add({ChromeSwitches.EXPERIMENTAL_WEB_PLAFTORM_FEATURES})
|
| -abstract class PaymentRequestTestBase extends ChromeActivityTestCaseBase<ChromeActivity> {
|
| +abstract class PaymentRequestTestBase extends ChromeActivityTestCaseBase<ChromeActivity>
|
| + implements PaymentRequestObserverForTest {
|
| + protected final PaymentsCallbackHelper mReadyForInput = new PaymentsCallbackHelper();
|
| + protected final PaymentsCallbackHelper mReadyToClose = new PaymentsCallbackHelper();
|
| + protected final CallbackHelper mDismissed = new CallbackHelper();
|
| private final AtomicReference<ContentViewCore> mViewCoreRef =
|
| new AtomicReference<ContentViewCore>();
|
| private final AtomicReference<WebContents> mWebContentsRef = new AtomicReference<WebContents>();
|
| private final String mTestFilePath;
|
| + private PaymentRequestUI mUI;
|
|
|
| protected PaymentRequestTestBase(String testFileName) {
|
| super(ChromeActivity.class);
|
| @@ -46,8 +50,8 @@ abstract class PaymentRequestTestBase extends ChromeActivityTestCaseBase<ChromeA
|
| protected abstract void onMainActivityStarted()
|
| throws InterruptedException, ExecutionException, TimeoutException;
|
|
|
| - protected void triggerPaymentUI()
|
| - throws InterruptedException, ExecutionException, TimeoutException {
|
| + protected void triggerUIAndWait(PaymentsCallbackHelper helper) throws InterruptedException,
|
| + ExecutionException, TimeoutException {
|
| startMainActivityWithURL(mTestFilePath);
|
| onMainActivityStarted();
|
| ThreadUtils.runOnUiThreadBlocking(new Runnable() {
|
| @@ -55,86 +59,27 @@ abstract class PaymentRequestTestBase extends ChromeActivityTestCaseBase<ChromeA
|
| public void run() {
|
| mViewCoreRef.set(getActivity().getCurrentContentViewCore());
|
| mWebContentsRef.set(mViewCoreRef.get().getWebContents());
|
| + PaymentRequestUI.setObserverForTest(PaymentRequestTestBase.this);
|
| }
|
| });
|
| assertWaitForPageScaleFactorMatch(1);
|
| - DOMUtils.waitForNonZeroNodeBounds(mWebContentsRef.get(), "buy");
|
| - DOMUtils.clickNode(this, mViewCoreRef.get(), "buy");
|
| -
|
| - waitForDialogToAllowUserInput();
|
| - }
|
| -
|
| - /** Waits for the dialog to allow user input. */
|
| - protected void waitForDialogToAllowUserInput() throws InterruptedException {
|
| - CriteriaHelper.pollUiThread(new Criteria() {
|
| - @Override
|
| - public boolean isSatisfied() {
|
| - PaymentRequestUI ui = PaymentRequestUI.getCurrentUIForTest();
|
| - if (ui == null) {
|
| - updateFailureReason("Payment UI was not shown");
|
| - return false;
|
| - }
|
| -
|
| - if (!ui.isAcceptingUserInput()) {
|
| - updateFailureReason("Dialog took too long to become clickable");
|
| - return false;
|
| - }
|
| -
|
| - return true;
|
| - }
|
| - });
|
| - }
|
| -
|
| - protected void clickClosePaymentUIButton() throws InterruptedException {
|
| - clickPaymentUIButton("close", R.id.close_button);
|
| - }
|
| -
|
| - protected void clickSecondaryPaymentUIButton() throws InterruptedException {
|
| - clickPaymentUIButton("secondary", R.id.button_secondary);
|
| - }
|
|
|
| - private void clickPaymentUIButton(final String buttonName, final int resourceId)
|
| - throws InterruptedException {
|
| - CriteriaHelper.pollUiThread(new Criteria() {
|
| - @Override
|
| - public boolean isSatisfied() {
|
| - PaymentRequestUI ui = PaymentRequestUI.getCurrentUIForTest();
|
| - if (ui == null) {
|
| - updateFailureReason("Payment UI was not shown");
|
| - return false;
|
| - }
|
| -
|
| - if (!ui.isAcceptingUserInput()) {
|
| - updateFailureReason("Dialog took too long to become clickable");
|
| - return false;
|
| - }
|
| -
|
| - View button = ui.getDialogForTest().findViewById(resourceId);
|
| - if (button == null) {
|
| - updateFailureReason(
|
| - String.format("Cannot find the %s button on payment UI", buttonName));
|
| - return false;
|
| - }
|
| -
|
| - if (!button.isEnabled()) {
|
| - updateFailureReason(
|
| - String.format("The %s button on payment UI is disabled", buttonName));
|
| - return false;
|
| - }
|
| -
|
| - button.performClick();
|
| - return true;
|
| - }
|
| - });
|
| + int callCount = helper.getCallCount();
|
| + DOMUtils.clickNode(this, mViewCoreRef.get(), "buy");
|
| + helper.waitForCallback(callCount);
|
| + mUI = helper.getUI();
|
| }
|
|
|
| - protected void waitForPaymentUIHidden() throws InterruptedException {
|
| - CriteriaHelper.pollUiThread(new Criteria("Payment UI should be hidden") {
|
| + protected void clickAndWait(final int resourceId, CallbackHelper helper)
|
| + throws InterruptedException, TimeoutException {
|
| + int callCount = helper.getCallCount();
|
| + ThreadUtils.runOnUiThreadBlocking(new Runnable() {
|
| @Override
|
| - public boolean isSatisfied() {
|
| - return PaymentRequestUI.getCurrentUIForTest() == null;
|
| + public void run() {
|
| + mUI.getDialogForTest().findViewById(resourceId).performClick();
|
| }
|
| });
|
| + helper.waitForCallback(callCount);
|
| }
|
|
|
| protected void expectResultContains(final String[] contents) throws InterruptedException {
|
| @@ -165,4 +110,50 @@ abstract class PaymentRequestTestBase extends ChromeActivityTestCaseBase<ChromeA
|
| }
|
| });
|
| }
|
| +
|
| + @Override
|
| + public void onPaymentRequestReadyForInput(PaymentRequestUI ui) {
|
| + ThreadUtils.assertOnUiThread();
|
| + mReadyForInput.notifyCalled(ui);
|
| + }
|
| +
|
| + @Override
|
| + public void onPaymentRequestReadyToClose(PaymentRequestUI ui) {
|
| + ThreadUtils.assertOnUiThread();
|
| + mReadyToClose.notifyCalled(ui);
|
| + }
|
| +
|
| + @Override
|
| + public void onPaymentRequestDismiss() {
|
| + ThreadUtils.assertOnUiThread();
|
| + mDismissed.notifyCalled();
|
| + }
|
| +
|
| + /**
|
| + * Listens for payments UI being ready for input or closing.
|
| + */
|
| + protected static class PaymentsCallbackHelper extends CallbackHelper {
|
| + private PaymentRequestUI mUI;
|
| +
|
| + /**
|
| + * Returns the payments UI that is ready for input.
|
| + *
|
| + * @return The payments UI that is ready for input.
|
| + */
|
| + public PaymentRequestUI getUI() {
|
| + ThreadUtils.assertOnUiThread();
|
| + return mUI;
|
| + }
|
| +
|
| + /**
|
| + * Called when the payments UI is ready for input.
|
| + *
|
| + * @param ui The payments UI that is ready for input or closing.
|
| + */
|
| + public void notifyCalled(PaymentRequestUI ui) {
|
| + ThreadUtils.assertOnUiThread();
|
| + mUI = ui;
|
| + notifyCalled();
|
| + }
|
| + }
|
| }
|
|
|