OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/browser/form_structure.h" | 5 #include "components/autofill/browser/form_structure.h" |
6 | 6 |
7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "components/autofill/browser/autofill_metrics.h" | 10 #include "components/autofill/browser/autofill_metrics.h" |
(...skipping 1119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1130 // Address Line 1. | 1130 // Address Line 1. |
1131 EXPECT_EQ(ADDRESS_HOME_LINE1, form_structure->field(0)->heuristic_type()); | 1131 EXPECT_EQ(ADDRESS_HOME_LINE1, form_structure->field(0)->heuristic_type()); |
1132 // Address Line 2. | 1132 // Address Line 2. |
1133 EXPECT_EQ(ADDRESS_HOME_LINE2, form_structure->field(1)->heuristic_type()); | 1133 EXPECT_EQ(ADDRESS_HOME_LINE2, form_structure->field(1)->heuristic_type()); |
1134 // Address Line 1. | 1134 // Address Line 1. |
1135 EXPECT_EQ(ADDRESS_BILLING_LINE1, form_structure->field(2)->heuristic_type()); | 1135 EXPECT_EQ(ADDRESS_BILLING_LINE1, form_structure->field(2)->heuristic_type()); |
1136 // Address Line 2. | 1136 // Address Line 2. |
1137 EXPECT_EQ(ADDRESS_BILLING_LINE2, form_structure->field(3)->heuristic_type()); | 1137 EXPECT_EQ(ADDRESS_BILLING_LINE2, form_structure->field(3)->heuristic_type()); |
1138 } | 1138 } |
1139 | 1139 |
| 1140 // Numbered address lines after line two are ignored. |
| 1141 TEST(FormStructureTest, SurplusAddressLinesIgnored) { |
| 1142 scoped_ptr<FormStructure> form_structure; |
| 1143 FormData form; |
| 1144 form.method = ASCIIToUTF16("post"); |
| 1145 |
| 1146 FormFieldData field; |
| 1147 field.form_control_type = "text"; |
| 1148 |
| 1149 field.label = ASCIIToUTF16("Address Line1"); |
| 1150 field.name = ASCIIToUTF16("shipping.address.addressLine1"); |
| 1151 form.fields.push_back(field); |
| 1152 |
| 1153 field.label = ASCIIToUTF16("Address Line2"); |
| 1154 field.name = ASCIIToUTF16("shipping.address.addressLine2"); |
| 1155 form.fields.push_back(field); |
| 1156 |
| 1157 field.label = ASCIIToUTF16("Address Line3"); |
| 1158 field.name = ASCIIToUTF16("billing.address.addressLine3"); |
| 1159 form.fields.push_back(field); |
| 1160 |
| 1161 field.label = ASCIIToUTF16("Address Line4"); |
| 1162 field.name = ASCIIToUTF16("billing.address.addressLine4"); |
| 1163 form.fields.push_back(field); |
| 1164 |
| 1165 form_structure.reset(new FormStructure(form, std::string())); |
| 1166 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); |
| 1167 ASSERT_EQ(4U, form_structure->field_count()); |
| 1168 ASSERT_EQ(2U, form_structure->autofill_count()); |
| 1169 |
| 1170 // Address Line 1. |
| 1171 EXPECT_EQ(ADDRESS_HOME_LINE1, form_structure->field(0)->heuristic_type()); |
| 1172 // Address Line 2. |
| 1173 EXPECT_EQ(ADDRESS_HOME_LINE2, form_structure->field(1)->heuristic_type()); |
| 1174 // Address Line 3 (ignored). |
| 1175 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(2)->heuristic_type()); |
| 1176 // Address Line 4 (ignored). |
| 1177 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(3)->heuristic_type()); |
| 1178 } |
1140 | 1179 |
1141 // This example comes from expedia.com where they use a "Suite" label to | 1180 // This example comes from expedia.com where they use a "Suite" label to |
1142 // indicate a suite or apartment number. We interpret this as address line 2. | 1181 // indicate a suite or apartment number. We interpret this as address line 2. |
1143 // And the following "Street address second line" we interpret as address line | 1182 // And the following "Street address second line" we interpret as address line |
1144 // 3 and discard. | 1183 // 3 and discard. |
1145 // See http://crbug.com/48197 for details. | 1184 // See http://crbug.com/48197 for details. |
1146 TEST(FormStructureTest, ThreeAddressLinesExpedia) { | 1185 TEST(FormStructureTest, ThreeAddressLinesExpedia) { |
1147 scoped_ptr<FormStructure> form_structure; | 1186 scoped_ptr<FormStructure> form_structure; |
1148 FormData form; | 1187 FormData form; |
1149 form.method = ASCIIToUTF16("post"); | 1188 form.method = ASCIIToUTF16("post"); |
(...skipping 1066 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2216 | 2255 |
2217 EXPECT_EQ(form, FormStructure(form, std::string()).ToFormData()); | 2256 EXPECT_EQ(form, FormStructure(form, std::string()).ToFormData()); |
2218 | 2257 |
2219 // Currently |FormStructure(form_data)ToFormData().user_submitted| is always | 2258 // Currently |FormStructure(form_data)ToFormData().user_submitted| is always |
2220 // false. This forces a future author that changes this to update this test. | 2259 // false. This forces a future author that changes this to update this test. |
2221 form.user_submitted = true; | 2260 form.user_submitted = true; |
2222 EXPECT_NE(form, FormStructure(form, std::string()).ToFormData()); | 2261 EXPECT_NE(form, FormStructure(form, std::string()).ToFormData()); |
2223 } | 2262 } |
2224 | 2263 |
2225 } // namespace autofill | 2264 } // namespace autofill |
OLD | NEW |