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 bool should_fill; |
| 890 } TestCase; |
| 891 |
| 892 TestCase test_cases[] = { |
| 893 // Filling a state to a text field with the default maxlength value should |
| 894 // fill the state value as is. |
| 895 {HTML_TYPE_ADDRESS_LEVEL1, /* default value */ 0, "New York", "New York", |
| 896 true}, |
| 897 {HTML_TYPE_ADDRESS_LEVEL1, /* default value */ 0, "NY", "NY", true}, |
| 898 // Filling a state to a text field with a maxlength value equal to the |
| 899 // value's length should fill the state value as is. |
| 900 {HTML_TYPE_ADDRESS_LEVEL1, 8, "New York", "New York", true}, |
| 901 // Filling a state to a text field with a maxlength value lower than the |
| 902 // value's length but higher than the value's abbreviation should fill the |
| 903 // state abbreviation. |
| 904 {HTML_TYPE_ADDRESS_LEVEL1, 2, "New York", "NY", true}, |
| 905 {HTML_TYPE_ADDRESS_LEVEL1, 2, "NY", "NY", true}, |
| 906 // Filling a state to a text field with a maxlength value lower than the |
| 907 // value's length and the value's abbreviation should not fill at all. |
| 908 {HTML_TYPE_ADDRESS_LEVEL1, 1, "New York", "", false}, |
| 909 {HTML_TYPE_ADDRESS_LEVEL1, 1, "NY", "", false}, |
| 910 // Filling a state to a text field with a maxlength value lower than the |
| 911 // value's length and that has no associated abbreviation should not fill |
| 912 // at all. |
| 913 {HTML_TYPE_ADDRESS_LEVEL1, 3, "Quebec", "", false}}; |
| 914 |
| 915 for (const TestCase& test_case : test_cases) { |
| 916 AutofillField field; |
| 917 field.SetHtmlType(test_case.field_type, HtmlFieldMode()); |
| 918 field.max_length = test_case.field_max_length; |
| 919 |
| 920 bool has_filled = AutofillField::FillFormField( |
| 921 field, ASCIIToUTF16(test_case.value_to_fill), "en-US", "en-US", &field); |
| 922 |
| 923 EXPECT_EQ(test_case.should_fill, has_filled); |
| 924 EXPECT_EQ(ASCIIToUTF16(test_case.expected_value), field.value); |
| 925 } |
| 926 } |
| 927 |
881 } // namespace | 928 } // namespace |
882 } // namespace autofill | 929 } // namespace autofill |
OLD | NEW |