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

Side by Side Diff: components/autofill/core/browser/form_field_unittest.cc

Issue 2611453002: Remove ScopedVector from autofill::FormStructure (Closed)
Patch Set: Fix ios build Created 3 years, 11 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 unified diff | Download patch
OLDNEW
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 "base/memory/scoped_vector.h" 5 #include "base/memory/ptr_util.h"
6 #include "base/strings/string16.h" 6 #include "base/strings/string16.h"
7 #include "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
8 #include "components/autofill/core/browser/autofill_field.h" 8 #include "components/autofill/core/browser/autofill_field.h"
9 #include "components/autofill/core/browser/form_field.h" 9 #include "components/autofill/core/browser/form_field.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
11 11
12 using base::ASCIIToUTF16; 12 using base::ASCIIToUTF16;
13 13
14 namespace autofill { 14 namespace autofill {
15 15
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 EXPECT_FALSE(FormField::Match(&field, ASCIIToUTF16("\\bcon\\b"), 117 EXPECT_FALSE(FormField::Match(&field, ASCIIToUTF16("\\bcon\\b"),
118 FormField::MATCH_LABEL)); 118 FormField::MATCH_LABEL));
119 // Make sure the circumflex in 'crepe' is not treated as a word boundary. 119 // Make sure the circumflex in 'crepe' is not treated as a word boundary.
120 field.label = base::UTF8ToUTF16("cr" "\xC3\xAA" "pe"); 120 field.label = base::UTF8ToUTF16("cr" "\xC3\xAA" "pe");
121 EXPECT_FALSE(FormField::Match(&field, ASCIIToUTF16("\\bcr\\b"), 121 EXPECT_FALSE(FormField::Match(&field, ASCIIToUTF16("\\bcr\\b"),
122 FormField::MATCH_LABEL)); 122 FormField::MATCH_LABEL));
123 } 123 }
124 124
125 // Test that we ignore checkable elements. 125 // Test that we ignore checkable elements.
126 TEST(FormFieldTest, ParseFormFields) { 126 TEST(FormFieldTest, ParseFormFields) {
127 ScopedVector<AutofillField> fields; 127 std::vector<std::unique_ptr<AutofillField>> fields;
128 FormFieldData field_data; 128 FormFieldData field_data;
129 field_data.form_control_type = "text"; 129 field_data.form_control_type = "text";
130 130
131 field_data.label = ASCIIToUTF16("Address line1"); 131 field_data.label = ASCIIToUTF16("Address line1");
132 fields.push_back(new AutofillField(field_data, field_data.label)); 132 fields.push_back(
133 base::MakeUnique<AutofillField>(field_data, field_data.label));
133 134
134 field_data.check_status = FormFieldData::CHECKABLE_BUT_UNCHECKED; 135 field_data.check_status = FormFieldData::CHECKABLE_BUT_UNCHECKED;
135 field_data.label = ASCIIToUTF16("Is PO Box"); 136 field_data.label = ASCIIToUTF16("Is PO Box");
136 fields.push_back(new AutofillField(field_data, field_data.label)); 137 fields.push_back(
138 base::MakeUnique<AutofillField>(field_data, field_data.label));
137 139
138 // reset |is_checkable| to false. 140 // reset |is_checkable| to false.
139 field_data.check_status = FormFieldData::NOT_CHECKABLE; 141 field_data.check_status = FormFieldData::NOT_CHECKABLE;
140 142
141 field_data.label = ASCIIToUTF16("Address line2"); 143 field_data.label = ASCIIToUTF16("Address line2");
142 fields.push_back(new AutofillField(field_data, field_data.label)); 144 fields.push_back(
145 base::MakeUnique<AutofillField>(field_data, field_data.label));
143 146
144 // Does not parse since there are only 2 recognized fields. 147 // Does not parse since there are only 2 recognized fields.
145 ASSERT_TRUE(FormField::ParseFormFields(fields.get(), true).empty()); 148 ASSERT_TRUE(FormField::ParseFormFields(fields, true).empty());
146 149
147 field_data.label = ASCIIToUTF16("City"); 150 field_data.label = ASCIIToUTF16("City");
148 fields.push_back(new AutofillField(field_data, field_data.label)); 151 fields.push_back(
152 base::MakeUnique<AutofillField>(field_data, field_data.label));
149 153
150 // Checkable element shouldn't interfere with inference of Address line2. 154 // Checkable element shouldn't interfere with inference of Address line2.
151 const FieldCandidatesMap field_candidates_map = 155 const FieldCandidatesMap field_candidates_map =
152 FormField::ParseFormFields(fields.get(), true); 156 FormField::ParseFormFields(fields, true);
153 ASSERT_EQ(3U, field_candidates_map.size()); 157 ASSERT_EQ(3U, field_candidates_map.size());
154 158
155 EXPECT_EQ(ADDRESS_HOME_LINE1, 159 EXPECT_EQ(ADDRESS_HOME_LINE1,
156 field_candidates_map.find(ASCIIToUTF16("Address line1")) 160 field_candidates_map.find(ASCIIToUTF16("Address line1"))
157 ->second.BestHeuristicType()); 161 ->second.BestHeuristicType());
158 EXPECT_EQ(ADDRESS_HOME_LINE2, 162 EXPECT_EQ(ADDRESS_HOME_LINE2,
159 field_candidates_map.find(ASCIIToUTF16("Address line2")) 163 field_candidates_map.find(ASCIIToUTF16("Address line2"))
160 ->second.BestHeuristicType()); 164 ->second.BestHeuristicType());
161 } 165 }
162 166
163 // All parsers see the same form and should not modify it. 167 // All parsers see the same form and should not modify it.
164 // Furthermore, all parsers are allowed to cast their votes on what the 168 // Furthermore, all parsers are allowed to cast their votes on what the
165 // ServerFieldType for a given type should be, so for an ambiguous input more 169 // ServerFieldType for a given type should be, so for an ambiguous input more
166 // than one candidate is expected. 170 // than one candidate is expected.
167 TEST(FormFieldTest, ParseFormFieldsImmutableForm) { 171 TEST(FormFieldTest, ParseFormFieldsImmutableForm) {
168 const base::string16 unique_name = ASCIIToUTF16("blah"); 172 const base::string16 unique_name = ASCIIToUTF16("blah");
169 FormFieldData field_data; 173 FormFieldData field_data;
170 field_data.form_control_type = "text"; 174 field_data.form_control_type = "text";
171 field_data.name = ASCIIToUTF16("business_email_address"); 175 field_data.name = ASCIIToUTF16("business_email_address");
172 176
173 ScopedVector<AutofillField> fields; 177 std::vector<std::unique_ptr<AutofillField>> fields;
174 fields.push_back(new AutofillField(field_data, unique_name)); 178 fields.push_back(base::MakeUnique<AutofillField>(field_data, unique_name));
175 179
176 const FieldCandidatesMap field_candidates_map = 180 const FieldCandidatesMap field_candidates_map =
177 FormField::ParseFormFields(fields.get(), true); 181 FormField::ParseFormFields(fields, true);
178 182
179 // The input form should not be modified. 183 // The input form should not be modified.
180 EXPECT_EQ(1U, fields.size()); 184 EXPECT_EQ(1U, fields.size());
181 185
182 // The output should contain detected information for the sole field in the 186 // The output should contain detected information for the sole field in the
183 // input. 187 // input.
184 EXPECT_EQ(1U, field_candidates_map.size()); 188 EXPECT_EQ(1U, field_candidates_map.size());
185 EXPECT_TRUE(field_candidates_map.find(unique_name) != 189 EXPECT_TRUE(field_candidates_map.find(unique_name) !=
186 field_candidates_map.end()); 190 field_candidates_map.end());
187 191
188 // Because we use a handcrafted field name, we can expect it to match more 192 // Because we use a handcrafted field name, we can expect it to match more
189 // than just one parser (at least email, but probably some more from the other 193 // than just one parser (at least email, but probably some more from the other
190 // parsers). 194 // parsers).
191 EXPECT_LT(1U, field_candidates_map.at(unique_name).field_candidates().size()); 195 EXPECT_LT(1U, field_candidates_map.at(unique_name).field_candidates().size());
192 } 196 }
193 197
194 } // namespace autofill 198 } // namespace autofill
OLDNEW
« no previous file with comments | « components/autofill/core/browser/form_field.cc ('k') | components/autofill/core/browser/form_structure.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698