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

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

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