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

Unified Diff: components/autofill/core/browser/autofill_field_unittest.cc

Issue 2025063002: [Autofill] Truncate expiration year based on prediction and max length. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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
« no previous file with comments | « components/autofill/core/browser/autofill_field.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/autofill/core/browser/autofill_field_unittest.cc
diff --git a/components/autofill/core/browser/autofill_field_unittest.cc b/components/autofill/core/browser/autofill_field_unittest.cc
index b488dd73629bb32d14a9e788e9f9531e2715bc9b..91bae45846b40b2d403ca8fec9a6fb59875c7add 100644
--- a/components/autofill/core/browser/autofill_field_unittest.cc
+++ b/components/autofill/core/browser/autofill_field_unittest.cc
@@ -330,6 +330,53 @@ TEST_F(AutofillFieldTest, FillPhoneNumber) {
}
}
+TEST_F(AutofillFieldTest, FillExpirationYearInput) {
+ typedef struct {
+ HtmlFieldType field_type;
+ size_t field_max_length;
+ std::string value_to_fill;
+ std::string expected_value;
+
+ } TestCase;
+
+ TestCase test_cases[] = {
+ // A field predicted as a 2 digits expiration year should fill the last 2
+ // digits of the expiration year if the field has an unspecified max
+ // length (0) or if it's greater than 1.
+ {HTML_TYPE_CREDIT_CARD_EXP_2_DIGIT_YEAR, /* default value */ 0, "2023",
+ "23"},
+ {HTML_TYPE_CREDIT_CARD_EXP_2_DIGIT_YEAR, 2, "2023", "23"},
+ {HTML_TYPE_CREDIT_CARD_EXP_2_DIGIT_YEAR, 12, "2023", "23"},
+ // A field predicted as a 2 digits expiration year should fill the last
+ // digit of the expiration year if the field has a max length of 1.
+ {HTML_TYPE_CREDIT_CARD_EXP_2_DIGIT_YEAR, 1, "2023", "3"},
+ // A field predicted as a 4 digits expiration year should fill the 4
+ // digits of the expiration year if the field has an unspecified max
+ // length (0) or if it's greater than 3 .
+ {HTML_TYPE_CREDIT_CARD_EXP_4_DIGIT_YEAR, /* default value */ 0, "2023",
+ "2023"},
+ {HTML_TYPE_CREDIT_CARD_EXP_4_DIGIT_YEAR, 4, "2023", "2023"},
+ {HTML_TYPE_CREDIT_CARD_EXP_4_DIGIT_YEAR, 12, "2023", "2023"},
+ // A field predicted as a 4 digits expiration year should fill the last 2
+ // digits of the expiration year if the field has a max length of 2.
+ {HTML_TYPE_CREDIT_CARD_EXP_4_DIGIT_YEAR, 2, "2023", "23"},
+ // A field predicted as a 4 digits expiration year should fill the last
+ // digit of the expiration year if the field has a max length of 1.
+ {HTML_TYPE_CREDIT_CARD_EXP_4_DIGIT_YEAR, 1, "2023", "3"},
+ };
+
+ for (TestCase test_case : test_cases) {
+ AutofillField field;
+ field.form_control_type = "input";
+ field.SetHtmlType(test_case.field_type, HtmlFieldMode());
+ field.max_length = test_case.field_max_length;
+
+ AutofillField::FillFormField(field, ASCIIToUTF16(test_case.value_to_fill),
+ "en-US", "en-US", &field);
+ EXPECT_EQ(ASCIIToUTF16(test_case.expected_value), field.value);
+ }
+}
+
TEST_F(AutofillFieldTest, FillSelectControlByValue) {
std::vector<const char*> kOptions = {
"Eenie", "Meenie", "Miney", "Mo",
« no previous file with comments | « components/autofill/core/browser/autofill_field.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698