Commit 15e05a11 authored by sebsg's avatar sebsg Committed by Commit bot

[Payments] Add detailed error messages and title for card unmask prompt.

BUG=661279

Review-Url: https://codereview.chromium.org/2538543002
Cr-Commit-Position: refs/heads/master@{#435598}
parent a6a331af
...@@ -112,4 +112,48 @@ public class PaymentRequestExpiredLocalCardTest extends PaymentRequestTestBase { ...@@ -112,4 +112,48 @@ public class PaymentRequestExpiredLocalCardTest extends PaymentRequestTestBase {
clickInCardEditorAndWait(R.id.payments_edit_done_button, mReadyToPay); clickInCardEditorAndWait(R.id.payments_edit_done_button, mReadyToPay);
} }
/**
* Tests the different card unmask error messages for an expired card.
*/
@MediumTest
@Feature({"Payments"})
public void testPromptErrorMessages()
throws InterruptedException, ExecutionException, TimeoutException {
// Click pay to get to the card unmask prompt.
triggerUIAndWait(mReadyToPay);
clickAndWait(R.id.button_primary, mReadyForUnmaskInput);
// Set valid arguments.
setTextInExpiredCardUnmaskDialogAndWait(
new int[] {R.id.expiration_month, R.id.expiration_year, R.id.card_unmask_input},
new String[] {"10", "26", "123"}, mUnmaskValidationDone);
assertTrue(getUnmaskPromptErrorMessage().equals(""));
// Set an invalid expiration date.
setTextInExpiredCardUnmaskDialogAndWait(
new int[] {R.id.expiration_month, R.id.expiration_year, R.id.card_unmask_input},
new String[] {"10", "14", "123"}, mUnmaskValidationDone);
assertTrue(getUnmaskPromptErrorMessage().equals(
"Check your expiration date and try again"));
// Set an invalid CVC and expiration date.
setTextInExpiredCardUnmaskDialogAndWait(
new int[] {R.id.expiration_month, R.id.expiration_year, R.id.card_unmask_input},
new String[] {"10", "14", "12312"}, mUnmaskValidationDone);
assertTrue(getUnmaskPromptErrorMessage().equals(
"Check your expiration date and CVC and try again"));
// Set an invalid CVC.
setTextInExpiredCardUnmaskDialogAndWait(
new int[] {R.id.expiration_month, R.id.expiration_year, R.id.card_unmask_input},
new String[] {"10", "26", "12312"}, mUnmaskValidationDone);
assertTrue(getUnmaskPromptErrorMessage().equals("Check your CVC and try again"));
// Set valid arguments again.
setTextInExpiredCardUnmaskDialogAndWait(
new int[] {R.id.expiration_month, R.id.expiration_year, R.id.card_unmask_input},
new String[] {"10", "26", "123"}, mUnmaskValidationDone);
assertTrue(getUnmaskPromptErrorMessage().equals(""));
}
} }
...@@ -218,4 +218,28 @@ public class PaymentRequestFreeShippingTest extends PaymentRequestTestBase { ...@@ -218,4 +218,28 @@ public class PaymentRequestFreeShippingTest extends PaymentRequestTestBase {
"PaymentRequest.RequestedInformation", i)); "PaymentRequest.RequestedInformation", i));
} }
} }
/**
* Tests the different card unmask error messages for a non expired card.
*/
@MediumTest
@Feature({"Payments"})
public void testPromptErrorMessages()
throws InterruptedException, ExecutionException, TimeoutException {
// Click pay to get to the card unmask prompt.
triggerUIAndWait(mReadyToPay);
clickAndWait(R.id.button_primary, mReadyForUnmaskInput);
// Set valid arguments.
setTextInCardUnmaskDialogAndWait(R.id.card_unmask_input, "123", mUnmaskValidationDone);
assertTrue(getUnmaskPromptErrorMessage().equals(""));
// Set an invalid CVC.
setTextInCardUnmaskDialogAndWait(R.id.card_unmask_input, "123123", mUnmaskValidationDone);
assertTrue(getUnmaskPromptErrorMessage().equals("Check your CVC and try again"));
// Set valid arguments again.
setTextInCardUnmaskDialogAndWait(R.id.card_unmask_input, "123", mUnmaskValidationDone);
assertTrue(getUnmaskPromptErrorMessage().equals(""));
}
} }
...@@ -80,6 +80,7 @@ abstract class PaymentRequestTestBase extends ChromeActivityTestCaseBase<ChromeT ...@@ -80,6 +80,7 @@ abstract class PaymentRequestTestBase extends ChromeActivityTestCaseBase<ChromeT
protected final PaymentsCallbackHelper<PaymentRequestUI> mResultReady; protected final PaymentsCallbackHelper<PaymentRequestUI> mResultReady;
protected final PaymentsCallbackHelper<CardUnmaskPrompt> mReadyForUnmaskInput; protected final PaymentsCallbackHelper<CardUnmaskPrompt> mReadyForUnmaskInput;
protected final PaymentsCallbackHelper<CardUnmaskPrompt> mReadyToUnmask; protected final PaymentsCallbackHelper<CardUnmaskPrompt> mReadyToUnmask;
protected final PaymentsCallbackHelper<CardUnmaskPrompt> mUnmaskValidationDone;
protected final CallbackHelper mReadyToEdit; protected final CallbackHelper mReadyToEdit;
protected final CallbackHelper mEditorValidationError; protected final CallbackHelper mEditorValidationError;
protected final CallbackHelper mEditorTextUpdate; protected final CallbackHelper mEditorTextUpdate;
...@@ -104,6 +105,7 @@ abstract class PaymentRequestTestBase extends ChromeActivityTestCaseBase<ChromeT ...@@ -104,6 +105,7 @@ abstract class PaymentRequestTestBase extends ChromeActivityTestCaseBase<ChromeT
mResultReady = new PaymentsCallbackHelper<>(); mResultReady = new PaymentsCallbackHelper<>();
mReadyForUnmaskInput = new PaymentsCallbackHelper<>(); mReadyForUnmaskInput = new PaymentsCallbackHelper<>();
mReadyToUnmask = new PaymentsCallbackHelper<>(); mReadyToUnmask = new PaymentsCallbackHelper<>();
mUnmaskValidationDone = new PaymentsCallbackHelper<>();
mReadyToEdit = new CallbackHelper(); mReadyToEdit = new CallbackHelper();
mEditorValidationError = new CallbackHelper(); mEditorValidationError = new CallbackHelper();
mEditorTextUpdate = new CallbackHelper(); mEditorTextUpdate = new CallbackHelper();
...@@ -443,6 +445,11 @@ abstract class PaymentRequestTestBase extends ChromeActivityTestCaseBase<ChromeT ...@@ -443,6 +445,11 @@ abstract class PaymentRequestTestBase extends ChromeActivityTestCaseBase<ChromeT
}); });
} }
/** Returns the error message visible to the user in the credit card unmask prompt. */
protected String getUnmaskPromptErrorMessage() {
return mCardUnmaskPrompt.getErrorMessage();
}
/** Selects the spinner value in the editor UI for credit cards. */ /** Selects the spinner value in the editor UI for credit cards. */
protected void setSpinnerSelectionsInCardEditorAndWait(final int[] selections, protected void setSpinnerSelectionsInCardEditorAndWait(final int[] selections,
CallbackHelper helper) throws InterruptedException, TimeoutException { CallbackHelper helper) throws InterruptedException, TimeoutException {
...@@ -529,8 +536,10 @@ abstract class PaymentRequestTestBase extends ChromeActivityTestCaseBase<ChromeT ...@@ -529,8 +536,10 @@ abstract class PaymentRequestTestBase extends ChromeActivityTestCaseBase<ChromeT
ThreadUtils.runOnUiThreadBlocking(new Runnable() { ThreadUtils.runOnUiThreadBlocking(new Runnable() {
@Override @Override
public void run() { public void run() {
((EditText) mCardUnmaskPrompt.getDialogForTest().findViewById(resourceId)) EditText editText =
.setText(input); ((EditText) mCardUnmaskPrompt.getDialogForTest().findViewById(resourceId));
editText.setText(input);
editText.getOnFocusChangeListener().onFocusChange(null, false);
} }
}); });
helper.waitForCallback(callCount); helper.waitForCallback(callCount);
...@@ -546,8 +555,10 @@ abstract class PaymentRequestTestBase extends ChromeActivityTestCaseBase<ChromeT ...@@ -546,8 +555,10 @@ abstract class PaymentRequestTestBase extends ChromeActivityTestCaseBase<ChromeT
@Override @Override
public void run() { public void run() {
for (int i = 0; i < resourceIds.length; ++i) { for (int i = 0; i < resourceIds.length; ++i) {
((EditText) mCardUnmaskPrompt.getDialogForTest().findViewById(resourceIds[i])) EditText editText = ((EditText) mCardUnmaskPrompt.getDialogForTest()
.setText(values[i]); .findViewById(resourceIds[i]));
editText.setText(values[i]);
editText.getOnFocusChangeListener().onFocusChange(null, false);
} }
} }
}); });
...@@ -675,6 +686,12 @@ abstract class PaymentRequestTestBase extends ChromeActivityTestCaseBase<ChromeT ...@@ -675,6 +686,12 @@ abstract class PaymentRequestTestBase extends ChromeActivityTestCaseBase<ChromeT
mReadyToUnmask.notifyCalled(prompt); mReadyToUnmask.notifyCalled(prompt);
} }
@Override
public void onCardUnmaskPromptValidationDone(CardUnmaskPrompt prompt) {
ThreadUtils.assertOnUiThread();
mUnmaskValidationDone.notifyCalled(prompt);
}
/** /**
* Listens for UI notifications. * Listens for UI notifications.
*/ */
......
...@@ -83,7 +83,7 @@ void CardUnmaskPromptControllerImpl::OnVerificationResult( ...@@ -83,7 +83,7 @@ void CardUnmaskPromptControllerImpl::OnVerificationResult(
case AutofillClient::TRY_AGAIN_FAILURE: { case AutofillClient::TRY_AGAIN_FAILURE: {
error_message = l10n_util::GetStringUTF16( error_message = l10n_util::GetStringUTF16(
IDS_AUTOFILL_CARD_UNMASK_PROMPT_ERROR_TRY_AGAIN); IDS_AUTOFILL_CARD_UNMASK_PROMPT_ERROR_TRY_AGAIN_CVC);
break; break;
} }
...@@ -219,15 +219,11 @@ base::string16 CardUnmaskPromptControllerImpl::GetWindowTitle() const { ...@@ -219,15 +219,11 @@ base::string16 CardUnmaskPromptControllerImpl::GetWindowTitle() const {
// The iOS UI has less room for the title so it shows a shorter string. // The iOS UI has less room for the title so it shows a shorter string.
return l10n_util::GetStringUTF16(IDS_AUTOFILL_CARD_UNMASK_PROMPT_TITLE); return l10n_util::GetStringUTF16(IDS_AUTOFILL_CARD_UNMASK_PROMPT_TITLE);
#else #else
int ids; return l10n_util::GetStringFUTF16(
if (reason_ == AutofillClient::UNMASK_FOR_AUTOFILL && ShouldRequestExpirationDate()
ShouldRequestExpirationDate()) { ? IDS_AUTOFILL_CARD_UNMASK_PROMPT_EXPIRED_TITLE
ids = IDS_AUTOFILL_CARD_UNMASK_PROMPT_UPDATE_TITLE; : IDS_AUTOFILL_CARD_UNMASK_PROMPT_TITLE,
} card_.TypeAndLastFourDigits());
else {
ids = IDS_AUTOFILL_CARD_UNMASK_PROMPT_TITLE;
}
return l10n_util::GetStringFUTF16(ids, card_.TypeAndLastFourDigits());
#endif #endif
} }
......
...@@ -230,10 +230,13 @@ ...@@ -230,10 +230,13 @@
</message> </message>
<!-- Autofill credit card unmask prompt --> <!-- Autofill credit card unmask prompt -->
<message name="IDS_AUTOFILL_CARD_UNMASK_PROMPT_ERROR_TRY_AGAIN" desc="Error message that encourages the user to try to re-enter their credit card CVC after a previous failed attempt."> <message name="IDS_AUTOFILL_CARD_UNMASK_PROMPT_ERROR_TRY_AGAIN_CVC" desc="Error message that encourages the user to try to re-enter their credit card CVC after a previous failed attempt." formatter_data="android_java">
Check your CVC and try again Check your CVC and try again
</message> </message>
<message name="IDS_AUTOFILL_CARD_UNMASK_PROMPT_ERROR_TRY_AGAIN_WITH_EXPIRATION" desc="Error message that encourages the user to try to re-enter their credit card expiration date and CVC after a previous failed attempt."> <message name="IDS_AUTOFILL_CARD_UNMASK_PROMPT_ERROR_TRY_AGAIN_EXPIRATION" desc="Error message that encourages the user to try to re-enter their credit card expiration date after a previous failed attempt." formatter_data="android_java">
Check your expiration date and try again
</message>
<message name="IDS_AUTOFILL_CARD_UNMASK_PROMPT_ERROR_TRY_AGAIN_CVC_AND_EXPIRATION" desc="Error message that encourages the user to try to re-enter their credit card expiration date and CVC after a previous failed attempt." formatter_data="android_java">
Check your expiration date and CVC and try again Check your expiration date and CVC and try again
</message> </message>
<if expr="_google_chrome"> <if expr="_google_chrome">
...@@ -253,8 +256,8 @@ ...@@ -253,8 +256,8 @@
<message name="IDS_AUTOFILL_CARD_UNMASK_PROMPT_TITLE" desc="Title for the credit card unmasking dialog."> <message name="IDS_AUTOFILL_CARD_UNMASK_PROMPT_TITLE" desc="Title for the credit card unmasking dialog.">
Enter the CVC for <ph name="CREDIT_CARD">$1<ex>Visa - 5679</ex></ph> Enter the CVC for <ph name="CREDIT_CARD">$1<ex>Visa - 5679</ex></ph>
</message> </message>
<message name="IDS_AUTOFILL_CARD_UNMASK_PROMPT_UPDATE_TITLE" desc="Title for the credit card unmasking dialog when the credit card is expired."> <message name="IDS_AUTOFILL_CARD_UNMASK_PROMPT_EXPIRED_TITLE" desc="Title for the credit card unmasking dialog when the credit card is expired.">
Enter the expiration date and CVC for <ph name="CREDIT_CARD">$1<ex>Visa - 5679</ex></ph> to update your card details Enter the expiration date and CVC for <ph name="CREDIT_CARD">$1<ex>Visa - 5679</ex></ph>
</message> </message>
<message name="IDS_AUTOFILL_CARD_UNMASK_PROMPT_INSTRUCTIONS" desc="Text explaining what the user should do in the card unmasking dialog."> <message name="IDS_AUTOFILL_CARD_UNMASK_PROMPT_INSTRUCTIONS" desc="Text explaining what the user should do in the card unmasking dialog.">
Once you confirm, your card details will be shared with this site Once you confirm, your card details will be shared with this site
......
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