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 5f9f7b75eff4ff96f865f48c0a667d0ddbe04c1b..3a9802cd07e2d3e94f9a8d272dbac51bf23c3e09 100644 |
--- a/components/autofill/core/browser/autofill_field_unittest.cc |
+++ b/components/autofill/core/browser/autofill_field_unittest.cc |
@@ -878,5 +878,36 @@ TEST_F(AutofillFieldTest, FindShortestSubstringMatchInSelect) { |
EXPECT_EQ(-1, ret); |
} |
+// Tests that text state fields are filled correctly depending on their |
+// maxlength attribute value. |
+TEST_F(AutofillFieldTest, FillStateText) { |
+ typedef struct { |
+ HtmlFieldType field_type; |
+ size_t field_max_length; |
+ std::string value_to_fill; |
+ std::string expected_value; |
+ |
+ } TestCase; |
+ |
+ TestCase test_cases[] = { |
+ // Filling a state to a text field should fill the state value as is. |
+ {HTML_TYPE_ADDRESS_LEVEL1, /* default value */ 0, "New York", "New York"}, |
+ {HTML_TYPE_ADDRESS_LEVEL1, /* default value */ 0, "NY", "NY"}, |
+ // Filling a state to a text field with a maxlength of 2 should fill the |
+ // state abbreviation. |
+ {HTML_TYPE_ADDRESS_LEVEL1, 2, "New York", "NY"}, |
+ {HTML_TYPE_ADDRESS_LEVEL1, 2, "NY", "NY"}}; |
+ |
+ for (TestCase test_case : test_cases) { |
vabr (Chromium)
2016/03/16 16:38:45
nit: const TestCase& to avoid copies
sebsg
2016/03/16 23:41:01
Done.
|
+ AutofillField field; |
+ 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); |
+ } |
+} |
+ |
} // namespace |
} // namespace autofill |