Skip to content

Commit

Permalink
Reland: Test dismissing CVC prompt for PaymentRequest
Browse files Browse the repository at this point in the history
This is an integration test for PaymentRequest that performs the
following steps:
1) Launch PaymentRequest UI.
2) Click "Pay" in PaymentRequest UI.
3) Click "Cancel" in CVC prompt.
4) Click "OK" to dismiss the result dialog.

Originally landed in:
https://crrev.com/ae3e707b1e771518538a8f12de5cdf88e0aef865

Consequently reverted in:
https://crrev.com/ce49849aadf7c4378c99cc4da45b3ff7671cdde8
due to a StrictMode violation.

Investigations into StrictMode errors seems to point to unclosed Mojo
pipe on shutdown. As a result, this patch adds explicit Mojo pipe
closing to the Java implementation of PaymentRequest service.

BUG=608223

Review-Url: https://codereview.chromium.org/1964243002
Cr-Commit-Position: refs/heads/master@{#392789}
  • Loading branch information
rsolomakhin authored and Commit bot committed May 11, 2016
1 parent c549bc0 commit e3aede8
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ public void onDismiss() {
*/
@Override
public void abort() {
mClient = null;
closeClient();
closeUI(false);
}

Expand All @@ -489,7 +489,7 @@ public void complete(boolean success) {
*/
@Override
public void close() {
mClient = null;
closeClient();
closeUI(false);
}

Expand All @@ -498,7 +498,7 @@ public void close() {
*/
@Override
public void onConnectionError(MojoException e) {
mClient = null;
closeClient();
closeUI(false);
}

Expand Down Expand Up @@ -570,7 +570,7 @@ public void onInstrumentDetailsError() {
private void disconnectFromClientWithDebugMessage(String debugMessage) {
Log.d(TAG, debugMessage);
mClient.onError();
mClient = null;
closeClient();
}

/**
Expand All @@ -581,9 +581,8 @@ private void closeUI(boolean paymentSuccess) {
mUI.close(paymentSuccess, new Runnable() {
@Override
public void run() {
if (mClient == null) return;
mClient.onComplete();
mClient = null;
if (mClient != null) mClient.onComplete();
closeClient();
}
});
mUI = null;
Expand All @@ -598,4 +597,9 @@ public void run() {
mPaymentMethods = null;
}
}

private void closeClient() {
if (mClient != null) mClient.close();
mClient = null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,11 @@ public interface PaymentRequestObserverForTest {
*/
void onPaymentRequestReadyToPay(PaymentRequestUI ui);

/**
* Called when the result UI is showing.
*/
void onPaymentRequestResultReady(PaymentRequestUI ui);

/**
* Called when the UI is gone.
*/
Expand Down Expand Up @@ -352,6 +357,7 @@ public void run() {
if (callback != null) callback.run();
}
});
if (mObserverForTest != null) mObserverForTest.onPaymentRequestResultReady(this);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,14 @@ public void testEditAndCancelDialog() throws InterruptedException, ExecutionExce
clickAndWait(R.id.button_secondary, mDismissed);
expectResultContains(new String[] {"Request cancelled"});
}

@MediumTest
public void testPayAndCancelDialog() throws InterruptedException, ExecutionException,
TimeoutException {
triggerUIAndWait(mReadyToPay);
clickAndWait(R.id.button_primary, mReadyToUnmask);
cancelCardUnmaskDialogAndWait(mReadyToUnmask.getTarget(), mResultReady);
clickAndWait(R.id.ok_button, mDismissed);
expectResultContains(new String[] {"Request cancelled"});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ abstract class PaymentRequestTestBase extends ChromeActivityTestCaseBase<ChromeA
protected final PaymentsCallbackHelper<PaymentRequestUI> mReadyForInput;
protected final PaymentsCallbackHelper<PaymentRequestUI> mReadyToPay;
protected final PaymentsCallbackHelper<PaymentRequestUI> mReadyToClose;
protected final PaymentsCallbackHelper<PaymentRequestUI> mResultReady;
protected final PaymentsCallbackHelper<CardUnmaskPrompt> mReadyToUnmask;
protected final CallbackHelper mDismissed;
private final AtomicReference<ContentViewCore> mViewCoreRef;
Expand All @@ -48,6 +49,7 @@ protected PaymentRequestTestBase(String testFileName) {
mReadyForInput = new PaymentsCallbackHelper<>();
mReadyToPay = new PaymentsCallbackHelper<>();
mReadyToClose = new PaymentsCallbackHelper<>();
mResultReady = new PaymentsCallbackHelper<>();
mReadyToUnmask = new PaymentsCallbackHelper<>();
mDismissed = new CallbackHelper();
mViewCoreRef = new AtomicReference<>();
Expand Down Expand Up @@ -154,6 +156,13 @@ public void onPaymentRequestReadyToClose(PaymentRequestUI ui) {
mReadyToClose.notifyCalled(ui);
}

@Override
public void onPaymentRequestResultReady(PaymentRequestUI ui) {
ThreadUtils.assertOnUiThread();
mResultReady.notifyCalled(ui);
}


@Override
public void onPaymentRequestDismiss() {
ThreadUtils.assertOnUiThread();
Expand Down

0 comments on commit e3aede8

Please sign in to comment.