Commit 96f67026 authored by Stephane Zermatten's avatar Stephane Zermatten Committed by Commit Bot

Only confirm CVC dialog from virtual keyboard if input is valid.

Before this change, it was possible to successfully submit an invalid
CVC from CardUnmaskPrompt, by using the virtual keyboard submit button
instead of hitting "Confirm".

After this change, hitting the submit button on the virtual keyboard
only works once a valid CVC has been input.

Bug: b/129732958
Change-Id: I0318d805f30d81a8ffbff7c823e5f41d5c2f881a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1587877Reviewed-by: default avatarRouslan Solomakhin <rouslan@chromium.org>
Commit-Queue: Stephane Zermatten <szermatt@chromium.org>
Cr-Commit-Position: refs/heads/master@{#654822}
parent d5e7514d
......@@ -132,6 +132,11 @@ public class CardUnmaskPrompt
* Called when the input values in the unmask prompt have been validated.
*/
void onCardUnmaskPromptValidationDone(CardUnmaskPrompt prompt);
/**
* Called when submitting through the soft keyboard was disallowed.
*/
void onCardUnmaskPromptSubmitRejected(CardUnmaskPrompt prompt);
}
public CardUnmaskPrompt(Context context, CardUnmaskPromptDelegate delegate, String title,
......@@ -189,7 +194,11 @@ public class CardUnmaskPrompt
// Hitting the "submit" button on the software keyboard should submit the form if valid.
mCardUnmaskInput.setOnEditorActionListener((v14, actionId, event) -> {
if (actionId == EditorInfo.IME_ACTION_DONE) {
onClick(mDialogModel, ModalDialogProperties.ButtonType.POSITIVE);
if (!mDialogModel.get(ModalDialogProperties.POSITIVE_BUTTON_DISABLED)) {
onClick(mDialogModel, ModalDialogProperties.ButtonType.POSITIVE);
} else if (sObserverForTest != null) {
sObserverForTest.onCardUnmaskPromptSubmitRejected(this);
}
return true;
}
return false;
......
......@@ -219,4 +219,20 @@ public class PaymentRequestExpiredLocalCardTest implements MainActivityStartCall
mRule.hitSoftwareKeyboardSubmitButtonAndWait(R.id.card_unmask_input, mRule.getDismissed());
}
/**
* Tests that hitting "submit" on the software keyboard in the CVC number field with no CVC set
* will not submit the CVC unmask dialog.
*/
@MediumTest
@Feature({"Payments"})
@Test
public void testNoSoftwareKeyboardSubmitInCvcNumberFieldIfInvalid()
throws InterruptedException, ExecutionException, TimeoutException {
mRule.triggerUIAndWait(mRule.getReadyToPay());
mRule.clickAndWait(R.id.button_primary, mRule.getReadyForUnmaskInput());
mRule.hitSoftwareKeyboardSubmitButtonAndWait(
R.id.card_unmask_input, mRule.getSubmitRejected());
}
}
......@@ -107,6 +107,7 @@ public class PaymentRequestTestRule extends ChromeTabbedActivityTestRule
final PaymentsCallbackHelper<CardUnmaskPrompt> mReadyForUnmaskInput;
final PaymentsCallbackHelper<CardUnmaskPrompt> mReadyToUnmask;
final PaymentsCallbackHelper<CardUnmaskPrompt> mUnmaskValidationDone;
final PaymentsCallbackHelper<CardUnmaskPrompt> mSubmitRejected;
final CallbackHelper mReadyToEdit;
final CallbackHelper mEditorValidationError;
final CallbackHelper mEditorTextUpdate;
......@@ -138,6 +139,7 @@ public class PaymentRequestTestRule extends ChromeTabbedActivityTestRule
mReadyForUnmaskInput = new PaymentsCallbackHelper<>();
mReadyToUnmask = new PaymentsCallbackHelper<>();
mUnmaskValidationDone = new PaymentsCallbackHelper<>();
mSubmitRejected = new PaymentsCallbackHelper<>();
mReadyToEdit = new CallbackHelper();
mEditorValidationError = new CallbackHelper();
mEditorTextUpdate = new CallbackHelper();
......@@ -198,6 +200,9 @@ public class PaymentRequestTestRule extends ChromeTabbedActivityTestRule
public PaymentsCallbackHelper<CardUnmaskPrompt> getUnmaskValidationDone() {
return mUnmaskValidationDone;
}
public PaymentsCallbackHelper<CardUnmaskPrompt> getSubmitRejected() {
return mSubmitRejected;
}
public CallbackHelper getReadyToEdit() {
return mReadyToEdit;
}
......@@ -1010,6 +1015,12 @@ public class PaymentRequestTestRule extends ChromeTabbedActivityTestRule
mUnmaskValidationDone.notifyCalled(prompt);
}
@Override
public void onCardUnmaskPromptSubmitRejected(CardUnmaskPrompt prompt) {
ThreadUtils.assertOnUiThread();
mSubmitRejected.notifyCalled(prompt);
}
@Override
public void onPaymentResponseReady() {
ThreadUtils.assertOnUiThread();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment