Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1025)

Unified Diff: chrome/browser/ui/views/payments/payment_request_credit_card_editor_interactive_uitest.cc

Issue 2715533002: [Payments] Add error messages to credit card editor. (Closed)
Patch Set: clean Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/views/payments/payment_request_credit_card_editor_interactive_uitest.cc
diff --git a/chrome/browser/ui/views/payments/payment_request_credit_card_editor_interactive_uitest.cc b/chrome/browser/ui/views/payments/payment_request_credit_card_editor_interactive_uitest.cc
index 3e7b5f34d813583e747aebb1c0d0e614ac4df347..d41a30e5c13e8f98ea427bf2420817e9620c189f 100644
--- a/chrome/browser/ui/views/payments/payment_request_credit_card_editor_interactive_uitest.cc
+++ b/chrome/browser/ui/views/payments/payment_request_credit_card_editor_interactive_uitest.cc
@@ -15,9 +15,11 @@
#include "components/autofill/core/browser/personal_data_manager_observer.h"
#include "components/autofill/core/browser/test_autofill_clock.h"
#include "components/payments/payment_request.h"
+#include "components/strings/grit/components_strings.h"
#include "content/public/test/browser_test_utils.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
+#include "ui/base/l10n/l10n_util.h"
namespace payments {
@@ -130,6 +132,42 @@ IN_PROC_BROWSER_TEST_F(PaymentRequestCreditCardEditorTest,
}
IN_PROC_BROWSER_TEST_F(PaymentRequestCreditCardEditorTest,
+ EnteringNothingInARequiredField) {
+ autofill::TestAutofillClock test_clock;
+ test_clock.SetNow(kJune2017);
+
+ InvokePaymentRequestUI();
+
+ OpenPaymentMethodScreen();
+
+ OpenCreditCardEditorScreen();
+
+ // This field is required. Entering nothing and blurring out will show
+ // "Required field".
+ SetEditorTextfieldValue(base::ASCIIToUTF16(""), autofill::CREDIT_CARD_NUMBER);
+ EXPECT_TRUE(IsEditorTextfieldInvalid(autofill::CREDIT_CARD_NUMBER));
+ EXPECT_EQ(
+ l10n_util::GetStringUTF16(IDS_PAYMENTS_FIELD_REQUIRED_VALIDATION_MESSAGE),
+ GetErrorLabelForType(autofill::CREDIT_CARD_NUMBER));
+
+ // Set the value to something which is not a valid card number. The "invalid
+ // card number" string takes precedence over "required field"
+ SetEditorTextfieldValue(base::ASCIIToUTF16("41111111invalidcard"),
+ autofill::CREDIT_CARD_NUMBER);
+ EXPECT_TRUE(IsEditorTextfieldInvalid(autofill::CREDIT_CARD_NUMBER));
+ EXPECT_EQ(l10n_util::GetStringUTF16(
+ IDS_PAYMENTS_CARD_NUMBER_INVALID_VALIDATION_MESSAGE),
+ GetErrorLabelForType(autofill::CREDIT_CARD_NUMBER));
+
+ // Set the value to a valid number now. No more errors!
+ SetEditorTextfieldValue(base::ASCIIToUTF16("4111111111111111"),
+ autofill::CREDIT_CARD_NUMBER);
+ EXPECT_FALSE(IsEditorTextfieldInvalid(autofill::CREDIT_CARD_NUMBER));
+ EXPECT_EQ(base::ASCIIToUTF16(""),
+ GetErrorLabelForType(autofill::CREDIT_CARD_NUMBER));
+}
+
+IN_PROC_BROWSER_TEST_F(PaymentRequestCreditCardEditorTest,
EnteringInvalidCardNumber) {
autofill::TestAutofillClock test_clock;
test_clock.SetNow(kJune2017);
@@ -144,6 +182,9 @@ IN_PROC_BROWSER_TEST_F(PaymentRequestCreditCardEditorTest,
autofill::CREDIT_CARD_NAME_FULL);
SetEditorTextfieldValue(base::ASCIIToUTF16("41111111invalidcard"),
autofill::CREDIT_CARD_NUMBER);
+ EXPECT_EQ(l10n_util::GetStringUTF16(
+ IDS_PAYMENTS_CARD_NUMBER_INVALID_VALIDATION_MESSAGE),
+ GetErrorLabelForType(autofill::CREDIT_CARD_NUMBER));
SetComboboxValue(base::ASCIIToUTF16("05"), autofill::CREDIT_CARD_EXP_MONTH);
SetComboboxValue(base::ASCIIToUTF16("2026"),
autofill::CREDIT_CARD_EXP_4_DIGIT_YEAR);
@@ -160,6 +201,66 @@ IN_PROC_BROWSER_TEST_F(PaymentRequestCreditCardEditorTest,
EXPECT_EQ(0u, personal_data_manager->GetCreditCards().size());
}
+IN_PROC_BROWSER_TEST_F(PaymentRequestCreditCardEditorTest,
+ EnteringInvalidCardNumber_AndFixingIt) {
+ autofill::TestAutofillClock test_clock;
+ test_clock.SetNow(kJune2017);
+
+ InvokePaymentRequestUI();
+
+ OpenPaymentMethodScreen();
+
+ OpenCreditCardEditorScreen();
+
+ SetEditorTextfieldValue(base::ASCIIToUTF16("Bob Jones"),
+ autofill::CREDIT_CARD_NAME_FULL);
+ SetEditorTextfieldValue(base::ASCIIToUTF16("41111111invalidcard"),
+ autofill::CREDIT_CARD_NUMBER);
+ EXPECT_EQ(l10n_util::GetStringUTF16(
+ IDS_PAYMENTS_CARD_NUMBER_INVALID_VALIDATION_MESSAGE),
+ GetErrorLabelForType(autofill::CREDIT_CARD_NUMBER));
+ SetComboboxValue(base::ASCIIToUTF16("05"), autofill::CREDIT_CARD_EXP_MONTH);
+ SetComboboxValue(base::ASCIIToUTF16("2026"),
+ autofill::CREDIT_CARD_EXP_4_DIGIT_YEAR);
+
+ ClickOnDialogViewAndWait(DialogViewID::EDITOR_SAVE_BUTTON);
+
+ EXPECT_FALSE(IsEditorTextfieldInvalid(autofill::CREDIT_CARD_NAME_FULL));
+ EXPECT_TRUE(IsEditorTextfieldInvalid(autofill::CREDIT_CARD_NUMBER));
+ EXPECT_FALSE(IsEditorComboboxInvalid(autofill::CREDIT_CARD_EXP_MONTH));
+ EXPECT_FALSE(IsEditorComboboxInvalid(autofill::CREDIT_CARD_EXP_4_DIGIT_YEAR));
+
+ // Fixing the card number.
+ SetEditorTextfieldValue(base::ASCIIToUTF16("4111111111111111"),
+ autofill::CREDIT_CARD_NUMBER);
+ // The error message has gone.
+ EXPECT_EQ(base::ASCIIToUTF16(""),
+ GetErrorLabelForType(autofill::CREDIT_CARD_NUMBER));
+
+ // Verifying the data is in the DB.
+ autofill::PersonalDataManager* personal_data_manager =
+ GetPaymentRequests(GetActiveWebContents())[0]->personal_data_manager();
+ personal_data_manager->AddObserver(&personal_data_observer_);
+
+ ResetEventObserver(DialogEvent::BACK_NAVIGATION);
+
+ // Wait until the web database has been updated and the notification sent.
+ base::RunLoop data_loop;
+ EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
+ .WillOnce(QuitMessageLoop(&data_loop));
+ ClickOnDialogViewAndWait(DialogViewID::EDITOR_SAVE_BUTTON);
+ data_loop.Run();
+
+ EXPECT_EQ(1u, personal_data_manager->GetCreditCards().size());
+ autofill::CreditCard* credit_card =
+ personal_data_manager->GetCreditCards()[0];
+ EXPECT_EQ(5, credit_card->expiration_month());
+ EXPECT_EQ(2026, credit_card->expiration_year());
+ EXPECT_EQ(base::ASCIIToUTF16("1111"), credit_card->LastFourDigits());
+ EXPECT_EQ(base::ASCIIToUTF16("Bob Jones"),
+ credit_card->GetRawInfo(autofill::CREDIT_CARD_NAME_FULL));
+}
+
IN_PROC_BROWSER_TEST_F(PaymentRequestCreditCardEditorTest, EnteringEmptyData) {
InvokePaymentRequestUI();

Powered by Google App Engine
This is Rietveld 408576698