OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "components/autofill/core/browser/autofill_field.h" | 5 #include "components/autofill/core/browser/autofill_field.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
(...skipping 860 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
871 ret = AutofillField::FindShortestSubstringMatchInSelect( | 871 ret = AutofillField::FindShortestSubstringMatchInSelect( |
872 ASCIIToUTF16("Ca Na Da"), false, &field); | 872 ASCIIToUTF16("Ca Na Da"), false, &field); |
873 EXPECT_EQ(-1, ret); | 873 EXPECT_EQ(-1, ret); |
874 | 874 |
875 // Case 7: No match (not present) | 875 // Case 7: No match (not present) |
876 ret = AutofillField::FindShortestSubstringMatchInSelect( | 876 ret = AutofillField::FindShortestSubstringMatchInSelect( |
877 ASCIIToUTF16("Canadia"), true, &field); | 877 ASCIIToUTF16("Canadia"), true, &field); |
878 EXPECT_EQ(-1, ret); | 878 EXPECT_EQ(-1, ret); |
879 } | 879 } |
880 | 880 |
881 // Tests that text state fields are filled correctly depending on their | |
882 // maxlength attribute value. | |
883 TEST_F(AutofillFieldTest, FillStateText) { | |
884 typedef struct { | |
885 HtmlFieldType field_type; | |
886 size_t field_max_length; | |
887 std::string value_to_fill; | |
888 std::string expected_value; | |
889 | |
890 } TestCase; | |
891 | |
892 TestCase test_cases[] = { | |
893 // Filling a state to a text field should fill the state value as is. | |
894 {HTML_TYPE_ADDRESS_LEVEL1, /* default value */ 0, "New York", "New York"}, | |
895 {HTML_TYPE_ADDRESS_LEVEL1, /* default value */ 0, "NY", "NY"}, | |
896 // Filling a state to a text field with a maxlength of 2 should fill the | |
897 // state abbreviation. | |
898 {HTML_TYPE_ADDRESS_LEVEL1, 2, "New York", "NY"}, | |
899 {HTML_TYPE_ADDRESS_LEVEL1, 2, "NY", "NY"}}; | |
900 | |
901 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.
| |
902 AutofillField field; | |
903 field.SetHtmlType(test_case.field_type, HtmlFieldMode()); | |
904 field.max_length = test_case.field_max_length; | |
905 | |
906 AutofillField::FillFormField(field, ASCIIToUTF16(test_case.value_to_fill), | |
907 "en-US", "en-US", &field); | |
908 EXPECT_EQ(ASCIIToUTF16(test_case.expected_value), field.value); | |
909 } | |
910 } | |
911 | |
881 } // namespace | 912 } // namespace |
882 } // namespace autofill | 913 } // namespace autofill |
OLD | NEW |