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

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

Issue 365783002: Autofill: don't require POST method. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: remove method_ member Created 6 years, 5 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 | Annotate | Revision Log
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 "components/autofill/core/browser/form_structure.h" 5 #include "components/autofill/core/browser/form_structure.h"
6 6
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/strings/string_util.h" 8 #include "base/strings/string_util.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "components/autofill/core/browser/autofill_metrics.h" 10 #include "components/autofill/core/browser/autofill_metrics.h"
(...skipping 17 matching lines...) Expand all
28 }; 28 };
29 29
30 } // anonymous namespace 30 } // anonymous namespace
31 31
32 32
33 namespace content { 33 namespace content {
34 34
35 std::ostream& operator<<(std::ostream& os, const FormData& form) { 35 std::ostream& operator<<(std::ostream& os, const FormData& form) {
36 os << base::UTF16ToUTF8(form.name) 36 os << base::UTF16ToUTF8(form.name)
37 << " " 37 << " "
38 << base::UTF16ToUTF8(form.method)
39 << " "
40 << form.origin.spec() 38 << form.origin.spec()
41 << " " 39 << " "
42 << form.action.spec() 40 << form.action.spec()
43 << " "; 41 << " ";
44 42
45 for (std::vector<FormFieldData>::const_iterator iter = 43 for (std::vector<FormFieldData>::const_iterator iter =
46 form.fields.begin(); 44 form.fields.begin();
47 iter != form.fields.end(); ++iter) { 45 iter != form.fields.end(); ++iter) {
48 os << *iter 46 os << *iter
49 << " "; 47 << " ";
50 } 48 }
51 49
52 return os; 50 return os;
53 } 51 }
54 52
55 } // namespace content 53 } // namespace content
56 54
57 class FormStructureTest { 55 class FormStructureTest {
58 public: 56 public:
59 static std::string Hash64Bit(const std::string& str) { 57 static std::string Hash64Bit(const std::string& str) {
60 return FormStructure::Hash64Bit(str); 58 return FormStructure::Hash64Bit(str);
61 } 59 }
62 }; 60 };
63 61
64 TEST(FormStructureTest, FieldCount) { 62 TEST(FormStructureTest, FieldCount) {
65 scoped_ptr<FormStructure> form_structure; 63 scoped_ptr<FormStructure> form_structure;
66 FormData form; 64 FormData form;
67 form.method = ASCIIToUTF16("post");
68 65
69 FormFieldData field; 66 FormFieldData field;
70 field.label = ASCIIToUTF16("username"); 67 field.label = ASCIIToUTF16("username");
71 field.name = ASCIIToUTF16("username"); 68 field.name = ASCIIToUTF16("username");
72 field.form_control_type = "text"; 69 field.form_control_type = "text";
73 form.fields.push_back(field); 70 form.fields.push_back(field);
74 71
75 field.label = ASCIIToUTF16("password"); 72 field.label = ASCIIToUTF16("password");
76 field.name = ASCIIToUTF16("password"); 73 field.name = ASCIIToUTF16("password");
77 field.form_control_type = "password"; 74 field.form_control_type = "password";
(...skipping 12 matching lines...) Expand all
90 87
91 // The render process sends all fields to browser including fields with 88 // The render process sends all fields to browser including fields with
92 // autocomplete=off 89 // autocomplete=off
93 form_structure.reset(new FormStructure(form)); 90 form_structure.reset(new FormStructure(form));
94 EXPECT_EQ(4U, form_structure->field_count()); 91 EXPECT_EQ(4U, form_structure->field_count());
95 } 92 }
96 93
97 TEST(FormStructureTest, AutofillCount) { 94 TEST(FormStructureTest, AutofillCount) {
98 scoped_ptr<FormStructure> form_structure; 95 scoped_ptr<FormStructure> form_structure;
99 FormData form; 96 FormData form;
100 form.method = ASCIIToUTF16("post");
101 97
102 FormFieldData field; 98 FormFieldData field;
103 field.label = ASCIIToUTF16("username"); 99 field.label = ASCIIToUTF16("username");
104 field.name = ASCIIToUTF16("username"); 100 field.name = ASCIIToUTF16("username");
105 field.form_control_type = "text"; 101 field.form_control_type = "text";
106 form.fields.push_back(field); 102 form.fields.push_back(field);
107 103
108 field.label = ASCIIToUTF16("password"); 104 field.label = ASCIIToUTF16("password");
109 field.name = ASCIIToUTF16("password"); 105 field.name = ASCIIToUTF16("password");
110 field.form_control_type = "password"; 106 field.form_control_type = "password";
(...skipping 23 matching lines...) Expand all
134 form.fields.push_back(field); 130 form.fields.push_back(field);
135 131
136 form_structure.reset(new FormStructure(form)); 132 form_structure.reset(new FormStructure(form));
137 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); 133 form_structure->DetermineHeuristicTypes(TestAutofillMetrics());
138 EXPECT_EQ(1U, form_structure->autofill_count()); 134 EXPECT_EQ(1U, form_structure->autofill_count());
139 } 135 }
140 136
141 TEST(FormStructureTest, SourceURL) { 137 TEST(FormStructureTest, SourceURL) {
142 FormData form; 138 FormData form;
143 form.origin = GURL("http://www.foo.com/"); 139 form.origin = GURL("http://www.foo.com/");
144 form.method = ASCIIToUTF16("post");
145 FormStructure form_structure(form); 140 FormStructure form_structure(form);
146 141
147 EXPECT_EQ(form.origin, form_structure.source_url()); 142 EXPECT_EQ(form.origin, form_structure.source_url());
148 } 143 }
149 144
150 TEST(FormStructureTest, IsAutofillable) { 145 TEST(FormStructureTest, IsAutofillable) {
151 scoped_ptr<FormStructure> form_structure; 146 scoped_ptr<FormStructure> form_structure;
152 FormData form; 147 FormData form;
153 148
154 // We need at least three text fields to be auto-fillable. 149 // We need at least three text fields to be auto-fillable.
155 form.method = ASCIIToUTF16("post");
156
157 FormFieldData field; 150 FormFieldData field;
158 151
159 field.label = ASCIIToUTF16("username"); 152 field.label = ASCIIToUTF16("username");
160 field.name = ASCIIToUTF16("username"); 153 field.name = ASCIIToUTF16("username");
161 field.form_control_type = "text"; 154 field.form_control_type = "text";
162 form.fields.push_back(field); 155 form.fields.push_back(field);
163 156
164 field.label = ASCIIToUTF16("password"); 157 field.label = ASCIIToUTF16("password");
165 field.name = ASCIIToUTF16("password"); 158 field.name = ASCIIToUTF16("password");
166 field.form_control_type = "password"; 159 field.form_control_type = "password";
167 form.fields.push_back(field); 160 form.fields.push_back(field);
168 161
169 field.label = base::string16(); 162 field.label = base::string16();
170 field.name = ASCIIToUTF16("Submit"); 163 field.name = ASCIIToUTF16("Submit");
171 field.form_control_type = "submit"; 164 field.form_control_type = "submit";
172 form.fields.push_back(field); 165 form.fields.push_back(field);
173 166
174 form_structure.reset(new FormStructure(form)); 167 form_structure.reset(new FormStructure(form));
175 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); 168 form_structure->DetermineHeuristicTypes(TestAutofillMetrics());
176 EXPECT_FALSE(form_structure->IsAutofillable(true)); 169 EXPECT_FALSE(form_structure->IsAutofillable());
177 170
178 // We now have three text fields, but only two auto-fillable fields. 171 // We now have three text fields, but only two auto-fillable fields.
179 field.label = ASCIIToUTF16("First Name"); 172 field.label = ASCIIToUTF16("First Name");
180 field.name = ASCIIToUTF16("firstname"); 173 field.name = ASCIIToUTF16("firstname");
181 field.form_control_type = "text"; 174 field.form_control_type = "text";
182 form.fields.push_back(field); 175 form.fields.push_back(field);
183 176
184 field.label = ASCIIToUTF16("Last Name"); 177 field.label = ASCIIToUTF16("Last Name");
185 field.name = ASCIIToUTF16("lastname"); 178 field.name = ASCIIToUTF16("lastname");
186 field.form_control_type = "text"; 179 field.form_control_type = "text";
187 form.fields.push_back(field); 180 form.fields.push_back(field);
188 181
189 form_structure.reset(new FormStructure(form)); 182 form_structure.reset(new FormStructure(form));
190 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); 183 form_structure->DetermineHeuristicTypes(TestAutofillMetrics());
191 EXPECT_FALSE(form_structure->IsAutofillable(true)); 184 EXPECT_FALSE(form_structure->IsAutofillable());
192 185
193 // We now have three auto-fillable fields. 186 // We now have three auto-fillable fields.
194 field.label = ASCIIToUTF16("Email"); 187 field.label = ASCIIToUTF16("Email");
195 field.name = ASCIIToUTF16("email"); 188 field.name = ASCIIToUTF16("email");
196 field.form_control_type = "email"; 189 field.form_control_type = "email";
197 form.fields.push_back(field); 190 form.fields.push_back(field);
198 191
199 form_structure.reset(new FormStructure(form)); 192 form_structure.reset(new FormStructure(form));
200 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); 193 form_structure->DetermineHeuristicTypes(TestAutofillMetrics());
201 EXPECT_TRUE(form_structure->IsAutofillable(true)); 194 EXPECT_TRUE(form_structure->IsAutofillable());
202
203 // The method must be 'post', though we can intentionally ignore this
204 // criterion for the sake of providing a helpful warning message to the user.
205 form.method = ASCIIToUTF16("get");
206 form_structure.reset(new FormStructure(form));
207 form_structure->DetermineHeuristicTypes(TestAutofillMetrics());
208 EXPECT_FALSE(form_structure->IsAutofillable(true));
209 EXPECT_TRUE(form_structure->IsAutofillable(false));
210 195
211 // The target cannot include http(s)://*/search... 196 // The target cannot include http(s)://*/search...
212 form.method = ASCIIToUTF16("post");
213 form.action = GURL("http://google.com/search?q=hello"); 197 form.action = GURL("http://google.com/search?q=hello");
214 form_structure.reset(new FormStructure(form)); 198 form_structure.reset(new FormStructure(form));
215 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); 199 form_structure->DetermineHeuristicTypes(TestAutofillMetrics());
216 EXPECT_FALSE(form_structure->IsAutofillable(true)); 200 EXPECT_FALSE(form_structure->IsAutofillable());
217 201
218 // But search can be in the URL. 202 // But search can be in the URL.
219 form.action = GURL("http://search.com/?q=hello"); 203 form.action = GURL("http://search.com/?q=hello");
220 form_structure.reset(new FormStructure(form)); 204 form_structure.reset(new FormStructure(form));
221 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); 205 form_structure->DetermineHeuristicTypes(TestAutofillMetrics());
222 EXPECT_TRUE(form_structure->IsAutofillable(true)); 206 EXPECT_TRUE(form_structure->IsAutofillable());
223 } 207 }
224 208
225 TEST(FormStructureTest, ShouldBeParsed) { 209 TEST(FormStructureTest, ShouldBeParsed) {
226 scoped_ptr<FormStructure> form_structure; 210 scoped_ptr<FormStructure> form_structure;
227 FormData form; 211 FormData form;
228 212
229 // We need at least three text fields to be parseable. 213 // We need at least three text fields to be parseable.
230 form.method = ASCIIToUTF16("post");
231
232 FormFieldData field; 214 FormFieldData field;
233 field.label = ASCIIToUTF16("username"); 215 field.label = ASCIIToUTF16("username");
234 field.name = ASCIIToUTF16("username"); 216 field.name = ASCIIToUTF16("username");
235 field.form_control_type = "text"; 217 field.form_control_type = "text";
236 form.fields.push_back(field); 218 form.fields.push_back(field);
237 219
238 FormFieldData checkable_field; 220 FormFieldData checkable_field;
239 checkable_field.is_checkable = true; 221 checkable_field.is_checkable = true;
240 checkable_field.name = ASCIIToUTF16("radiobtn"); 222 checkable_field.name = ASCIIToUTF16("radiobtn");
241 checkable_field.form_control_type = "radio"; 223 checkable_field.form_control_type = "radio";
242 form.fields.push_back(checkable_field); 224 form.fields.push_back(checkable_field);
243 225
244 checkable_field.name = ASCIIToUTF16("checkbox"); 226 checkable_field.name = ASCIIToUTF16("checkbox");
245 checkable_field.form_control_type = "checkbox"; 227 checkable_field.form_control_type = "checkbox";
246 form.fields.push_back(checkable_field); 228 form.fields.push_back(checkable_field);
247 229
248 // We have only one text field, should not be parsed. 230 // We have only one text field, should not be parsed.
249 form_structure.reset(new FormStructure(form)); 231 form_structure.reset(new FormStructure(form));
250 EXPECT_FALSE(form_structure->ShouldBeParsed(true)); 232 EXPECT_FALSE(form_structure->ShouldBeParsed());
251 233
252 // We now have three text fields, though only two are auto-fillable. 234 // We now have three text fields, though only two are auto-fillable.
253 field.label = ASCIIToUTF16("First Name"); 235 field.label = ASCIIToUTF16("First Name");
254 field.name = ASCIIToUTF16("firstname"); 236 field.name = ASCIIToUTF16("firstname");
255 field.form_control_type = "text"; 237 field.form_control_type = "text";
256 form.fields.push_back(field); 238 form.fields.push_back(field);
257 239
258 field.label = ASCIIToUTF16("Last Name"); 240 field.label = ASCIIToUTF16("Last Name");
259 field.name = ASCIIToUTF16("lastname"); 241 field.name = ASCIIToUTF16("lastname");
260 field.form_control_type = "text"; 242 field.form_control_type = "text";
261 form.fields.push_back(field); 243 form.fields.push_back(field);
262 244
263 form_structure.reset(new FormStructure(form)); 245 form_structure.reset(new FormStructure(form));
264 EXPECT_TRUE(form_structure->ShouldBeParsed(true)); 246 EXPECT_TRUE(form_structure->ShouldBeParsed());
265 247
266 // The method must be 'post', though we can intentionally ignore this
267 // criterion for the sake of providing a helpful warning message to the user.
268 form.method = ASCIIToUTF16("get");
269 form_structure.reset(new FormStructure(form)); 248 form_structure.reset(new FormStructure(form));
270 EXPECT_FALSE(form_structure->IsAutofillable(true)); 249 EXPECT_FALSE(form_structure->IsAutofillable());
271 EXPECT_TRUE(form_structure->ShouldBeParsed(false)); 250 EXPECT_TRUE(form_structure->ShouldBeParsed());
272 251
273 // The target cannot include http(s)://*/search... 252 // The target cannot include http(s)://*/search...
274 form.method = ASCIIToUTF16("post");
275 form.action = GURL("http://google.com/search?q=hello"); 253 form.action = GURL("http://google.com/search?q=hello");
276 form_structure.reset(new FormStructure(form)); 254 form_structure.reset(new FormStructure(form));
277 EXPECT_FALSE(form_structure->ShouldBeParsed(true)); 255 EXPECT_FALSE(form_structure->ShouldBeParsed());
278 256
279 // But search can be in the URL. 257 // But search can be in the URL.
280 form.action = GURL("http://search.com/?q=hello"); 258 form.action = GURL("http://search.com/?q=hello");
281 form_structure.reset(new FormStructure(form)); 259 form_structure.reset(new FormStructure(form));
282 EXPECT_TRUE(form_structure->ShouldBeParsed(true)); 260 EXPECT_TRUE(form_structure->ShouldBeParsed());
283 261
284 // The form need only have three fields, but at least one must be a text 262 // The form need only have three fields, but at least one must be a text
285 // field. 263 // field.
286 form.fields.clear(); 264 form.fields.clear();
287 265
288 field.label = ASCIIToUTF16("Email"); 266 field.label = ASCIIToUTF16("Email");
289 field.name = ASCIIToUTF16("email"); 267 field.name = ASCIIToUTF16("email");
290 field.form_control_type = "email"; 268 field.form_control_type = "email";
291 form.fields.push_back(field); 269 form.fields.push_back(field);
292 270
293 field.label = ASCIIToUTF16("State"); 271 field.label = ASCIIToUTF16("State");
294 field.name = ASCIIToUTF16("state"); 272 field.name = ASCIIToUTF16("state");
295 field.form_control_type = "select-one"; 273 field.form_control_type = "select-one";
296 form.fields.push_back(field); 274 form.fields.push_back(field);
297 275
298 field.label = ASCIIToUTF16("Country"); 276 field.label = ASCIIToUTF16("Country");
299 field.name = ASCIIToUTF16("country"); 277 field.name = ASCIIToUTF16("country");
300 field.form_control_type = "select-one"; 278 field.form_control_type = "select-one";
301 form.fields.push_back(field); 279 form.fields.push_back(field);
302 280
303 form_structure.reset(new FormStructure(form)); 281 form_structure.reset(new FormStructure(form));
304 EXPECT_TRUE(form_structure->ShouldBeParsed(true)); 282 EXPECT_TRUE(form_structure->ShouldBeParsed());
305 283
306 form.fields[0].form_control_type = "select-one"; 284 form.fields[0].form_control_type = "select-one";
307 // Now, no text fields. 285 // Now, no text fields.
308 form_structure.reset(new FormStructure(form)); 286 form_structure.reset(new FormStructure(form));
309 EXPECT_FALSE(form_structure->ShouldBeParsed(true)); 287 EXPECT_FALSE(form_structure->ShouldBeParsed());
310 } 288 }
311 289
312 TEST(FormStructureTest, HeuristicsContactInfo) { 290 TEST(FormStructureTest, HeuristicsContactInfo) {
313 scoped_ptr<FormStructure> form_structure; 291 scoped_ptr<FormStructure> form_structure;
314 FormData form; 292 FormData form;
315 form.method = ASCIIToUTF16("post");
316 293
317 FormFieldData field; 294 FormFieldData field;
318 field.form_control_type = "text"; 295 field.form_control_type = "text";
319 296
320 field.label = ASCIIToUTF16("First Name"); 297 field.label = ASCIIToUTF16("First Name");
321 field.name = ASCIIToUTF16("firstname"); 298 field.name = ASCIIToUTF16("firstname");
322 form.fields.push_back(field); 299 form.fields.push_back(field);
323 300
324 field.label = ASCIIToUTF16("Last Name"); 301 field.label = ASCIIToUTF16("Last Name");
325 field.name = ASCIIToUTF16("lastname"); 302 field.name = ASCIIToUTF16("lastname");
(...skipping 19 matching lines...) Expand all
345 field.name = ASCIIToUTF16("zipcode"); 322 field.name = ASCIIToUTF16("zipcode");
346 form.fields.push_back(field); 323 form.fields.push_back(field);
347 324
348 field.label = base::string16(); 325 field.label = base::string16();
349 field.name = ASCIIToUTF16("Submit"); 326 field.name = ASCIIToUTF16("Submit");
350 field.form_control_type = "submit"; 327 field.form_control_type = "submit";
351 form.fields.push_back(field); 328 form.fields.push_back(field);
352 329
353 form_structure.reset(new FormStructure(form)); 330 form_structure.reset(new FormStructure(form));
354 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); 331 form_structure->DetermineHeuristicTypes(TestAutofillMetrics());
355 EXPECT_TRUE(form_structure->IsAutofillable(true)); 332 EXPECT_TRUE(form_structure->IsAutofillable());
356 333
357 // Expect the correct number of fields. 334 // Expect the correct number of fields.
358 ASSERT_EQ(8U, form_structure->field_count()); 335 ASSERT_EQ(8U, form_structure->field_count());
359 ASSERT_EQ(7U, form_structure->autofill_count()); 336 ASSERT_EQ(7U, form_structure->autofill_count());
360 337
361 // First name. 338 // First name.
362 EXPECT_EQ(NAME_FIRST, form_structure->field(0)->heuristic_type()); 339 EXPECT_EQ(NAME_FIRST, form_structure->field(0)->heuristic_type());
363 // Last name. 340 // Last name.
364 EXPECT_EQ(NAME_LAST, form_structure->field(1)->heuristic_type()); 341 EXPECT_EQ(NAME_LAST, form_structure->field(1)->heuristic_type());
365 // Email. 342 // Email.
366 EXPECT_EQ(EMAIL_ADDRESS, form_structure->field(2)->heuristic_type()); 343 EXPECT_EQ(EMAIL_ADDRESS, form_structure->field(2)->heuristic_type());
367 // Phone. 344 // Phone.
368 EXPECT_EQ(PHONE_HOME_WHOLE_NUMBER, 345 EXPECT_EQ(PHONE_HOME_WHOLE_NUMBER,
369 form_structure->field(3)->heuristic_type()); 346 form_structure->field(3)->heuristic_type());
370 // Address. 347 // Address.
371 EXPECT_EQ(ADDRESS_HOME_LINE1, form_structure->field(4)->heuristic_type()); 348 EXPECT_EQ(ADDRESS_HOME_LINE1, form_structure->field(4)->heuristic_type());
372 // City. 349 // City.
373 EXPECT_EQ(ADDRESS_HOME_CITY, form_structure->field(5)->heuristic_type()); 350 EXPECT_EQ(ADDRESS_HOME_CITY, form_structure->field(5)->heuristic_type());
374 // Zip. 351 // Zip.
375 EXPECT_EQ(ADDRESS_HOME_ZIP, form_structure->field(6)->heuristic_type()); 352 EXPECT_EQ(ADDRESS_HOME_ZIP, form_structure->field(6)->heuristic_type());
376 // Submit. 353 // Submit.
377 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(7)->heuristic_type()); 354 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(7)->heuristic_type());
378 } 355 }
379 356
380 // Verify that we can correctly process the |autocomplete| attribute. 357 // Verify that we can correctly process the |autocomplete| attribute.
381 TEST(FormStructureTest, HeuristicsAutocompleteAttribute) { 358 TEST(FormStructureTest, HeuristicsAutocompleteAttribute) {
382 scoped_ptr<FormStructure> form_structure; 359 scoped_ptr<FormStructure> form_structure;
383 FormData form; 360 FormData form;
384 form.method = ASCIIToUTF16("post");
385 361
386 FormFieldData field; 362 FormFieldData field;
387 field.form_control_type = "text"; 363 field.form_control_type = "text";
388 364
389 field.label = base::string16(); 365 field.label = base::string16();
390 field.name = ASCIIToUTF16("field1"); 366 field.name = ASCIIToUTF16("field1");
391 field.autocomplete_attribute = "given-name"; 367 field.autocomplete_attribute = "given-name";
392 form.fields.push_back(field); 368 form.fields.push_back(field);
393 369
394 field.label = base::string16(); 370 field.label = base::string16();
395 field.name = ASCIIToUTF16("field2"); 371 field.name = ASCIIToUTF16("field2");
396 field.autocomplete_attribute = "family-name"; 372 field.autocomplete_attribute = "family-name";
397 form.fields.push_back(field); 373 form.fields.push_back(field);
398 374
399 field.label = base::string16(); 375 field.label = base::string16();
400 field.name = ASCIIToUTF16("field3"); 376 field.name = ASCIIToUTF16("field3");
401 field.autocomplete_attribute = "email"; 377 field.autocomplete_attribute = "email";
402 form.fields.push_back(field); 378 form.fields.push_back(field);
403 379
404 form_structure.reset(new FormStructure(form)); 380 form_structure.reset(new FormStructure(form));
405 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); 381 form_structure->DetermineHeuristicTypes(TestAutofillMetrics());
406 EXPECT_TRUE(form_structure->IsAutofillable(true)); 382 EXPECT_TRUE(form_structure->IsAutofillable());
407 383
408 // Expect the correct number of fields. 384 // Expect the correct number of fields.
409 ASSERT_EQ(3U, form_structure->field_count()); 385 ASSERT_EQ(3U, form_structure->field_count());
410 ASSERT_EQ(3U, form_structure->autofill_count()); 386 ASSERT_EQ(3U, form_structure->autofill_count());
411 387
412 EXPECT_EQ(HTML_TYPE_GIVEN_NAME, form_structure->field(0)->html_type()); 388 EXPECT_EQ(HTML_TYPE_GIVEN_NAME, form_structure->field(0)->html_type());
413 EXPECT_EQ(HTML_TYPE_FAMILY_NAME, form_structure->field(1)->html_type()); 389 EXPECT_EQ(HTML_TYPE_FAMILY_NAME, form_structure->field(1)->html_type());
414 EXPECT_EQ(HTML_TYPE_EMAIL, form_structure->field(2)->html_type()); 390 EXPECT_EQ(HTML_TYPE_EMAIL, form_structure->field(2)->html_type());
415 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(0)->heuristic_type()); 391 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(0)->heuristic_type());
416 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(1)->heuristic_type()); 392 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(1)->heuristic_type());
417 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(2)->heuristic_type()); 393 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(2)->heuristic_type());
418 } 394 }
419 395
420 // Verify that we can correctly process the 'autocomplete' attribute for phone 396 // Verify that we can correctly process the 'autocomplete' attribute for phone
421 // number types (especially phone prefixes and suffixes). 397 // number types (especially phone prefixes and suffixes).
422 TEST(FormStructureTest, HeuristicsAutocompleteAttributePhoneTypes) { 398 TEST(FormStructureTest, HeuristicsAutocompleteAttributePhoneTypes) {
423 scoped_ptr<FormStructure> form_structure; 399 scoped_ptr<FormStructure> form_structure;
424 FormData form; 400 FormData form;
425 form.method = ASCIIToUTF16("post");
426 401
427 FormFieldData field; 402 FormFieldData field;
428 field.form_control_type = "text"; 403 field.form_control_type = "text";
429 404
430 field.label = base::string16(); 405 field.label = base::string16();
431 field.name = ASCIIToUTF16("field1"); 406 field.name = ASCIIToUTF16("field1");
432 field.autocomplete_attribute = "tel-local"; 407 field.autocomplete_attribute = "tel-local";
433 form.fields.push_back(field); 408 form.fields.push_back(field);
434 409
435 field.label = base::string16(); 410 field.label = base::string16();
436 field.name = ASCIIToUTF16("field2"); 411 field.name = ASCIIToUTF16("field2");
437 field.autocomplete_attribute = "tel-local-prefix"; 412 field.autocomplete_attribute = "tel-local-prefix";
438 form.fields.push_back(field); 413 form.fields.push_back(field);
439 414
440 field.label = base::string16(); 415 field.label = base::string16();
441 field.name = ASCIIToUTF16("field3"); 416 field.name = ASCIIToUTF16("field3");
442 field.autocomplete_attribute = "tel-local-suffix"; 417 field.autocomplete_attribute = "tel-local-suffix";
443 form.fields.push_back(field); 418 form.fields.push_back(field);
444 419
445 form_structure.reset(new FormStructure(form)); 420 form_structure.reset(new FormStructure(form));
446 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); 421 form_structure->DetermineHeuristicTypes(TestAutofillMetrics());
447 EXPECT_TRUE(form_structure->IsAutofillable(true)); 422 EXPECT_TRUE(form_structure->IsAutofillable());
448 423
449 // Expect the correct number of fields. 424 // Expect the correct number of fields.
450 ASSERT_EQ(3U, form_structure->field_count()); 425 ASSERT_EQ(3U, form_structure->field_count());
451 EXPECT_EQ(3U, form_structure->autofill_count()); 426 EXPECT_EQ(3U, form_structure->autofill_count());
452 427
453 EXPECT_EQ(HTML_TYPE_TEL_LOCAL, form_structure->field(0)->html_type()); 428 EXPECT_EQ(HTML_TYPE_TEL_LOCAL, form_structure->field(0)->html_type());
454 EXPECT_EQ(AutofillField::IGNORED, form_structure->field(0)->phone_part()); 429 EXPECT_EQ(AutofillField::IGNORED, form_structure->field(0)->phone_part());
455 EXPECT_EQ(HTML_TYPE_TEL_LOCAL_PREFIX, form_structure->field(1)->html_type()); 430 EXPECT_EQ(HTML_TYPE_TEL_LOCAL_PREFIX, form_structure->field(1)->html_type());
456 EXPECT_EQ(AutofillField::PHONE_PREFIX, 431 EXPECT_EQ(AutofillField::PHONE_PREFIX,
457 form_structure->field(1)->phone_part()); 432 form_structure->field(1)->phone_part());
458 EXPECT_EQ(HTML_TYPE_TEL_LOCAL_SUFFIX, form_structure->field(2)->html_type()); 433 EXPECT_EQ(HTML_TYPE_TEL_LOCAL_SUFFIX, form_structure->field(2)->html_type());
459 EXPECT_EQ(AutofillField::PHONE_SUFFIX, 434 EXPECT_EQ(AutofillField::PHONE_SUFFIX,
460 form_structure->field(2)->phone_part()); 435 form_structure->field(2)->phone_part());
461 } 436 }
462 437
463 // If at least one field includes type hints in the 'autocomplete' attribute, we 438 // If at least one field includes type hints in the 'autocomplete' attribute, we
464 // should not try to apply any other heuristics. 439 // should not try to apply any other heuristics.
465 TEST(FormStructureTest, AutocompleteAttributeOverridesOtherHeuristics) { 440 TEST(FormStructureTest, AutocompleteAttributeOverridesOtherHeuristics) {
466 scoped_ptr<FormStructure> form_structure; 441 scoped_ptr<FormStructure> form_structure;
467 FormData form; 442 FormData form;
468 form.method = ASCIIToUTF16("post");
469 443
470 // Start with a regular contact form. 444 // Start with a regular contact form.
471 FormFieldData field; 445 FormFieldData field;
472 field.form_control_type = "text"; 446 field.form_control_type = "text";
473 447
474 field.label = ASCIIToUTF16("First Name"); 448 field.label = ASCIIToUTF16("First Name");
475 field.name = ASCIIToUTF16("firstname"); 449 field.name = ASCIIToUTF16("firstname");
476 form.fields.push_back(field); 450 form.fields.push_back(field);
477 451
478 field.label = ASCIIToUTF16("Last Name"); 452 field.label = ASCIIToUTF16("Last Name");
479 field.name = ASCIIToUTF16("lastname"); 453 field.name = ASCIIToUTF16("lastname");
480 form.fields.push_back(field); 454 form.fields.push_back(field);
481 455
482 field.label = ASCIIToUTF16("Email"); 456 field.label = ASCIIToUTF16("Email");
483 field.name = ASCIIToUTF16("email"); 457 field.name = ASCIIToUTF16("email");
484 form.fields.push_back(field); 458 form.fields.push_back(field);
485 459
486 form_structure.reset(new FormStructure(form)); 460 form_structure.reset(new FormStructure(form));
487 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); 461 form_structure->DetermineHeuristicTypes(TestAutofillMetrics());
488 EXPECT_TRUE(form_structure->IsAutofillable(true)); 462 EXPECT_TRUE(form_structure->IsAutofillable());
489 EXPECT_TRUE(form_structure->ShouldBeCrowdsourced()); 463 EXPECT_TRUE(form_structure->ShouldBeCrowdsourced());
490 464
491 ASSERT_EQ(3U, form_structure->field_count()); 465 ASSERT_EQ(3U, form_structure->field_count());
492 ASSERT_EQ(3U, form_structure->autofill_count()); 466 ASSERT_EQ(3U, form_structure->autofill_count());
493 467
494 EXPECT_EQ(NAME_FIRST, form_structure->field(0)->heuristic_type()); 468 EXPECT_EQ(NAME_FIRST, form_structure->field(0)->heuristic_type());
495 EXPECT_EQ(NAME_LAST, form_structure->field(1)->heuristic_type()); 469 EXPECT_EQ(NAME_LAST, form_structure->field(1)->heuristic_type());
496 EXPECT_EQ(EMAIL_ADDRESS, form_structure->field(2)->heuristic_type()); 470 EXPECT_EQ(EMAIL_ADDRESS, form_structure->field(2)->heuristic_type());
497 471
498 // Now update the first form field to include an 'autocomplete' attribute. 472 // Now update the first form field to include an 'autocomplete' attribute.
499 form.fields.front().autocomplete_attribute = "x-other"; 473 form.fields.front().autocomplete_attribute = "x-other";
500 form_structure.reset(new FormStructure(form)); 474 form_structure.reset(new FormStructure(form));
501 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); 475 form_structure->DetermineHeuristicTypes(TestAutofillMetrics());
502 EXPECT_FALSE(form_structure->IsAutofillable(true)); 476 EXPECT_FALSE(form_structure->IsAutofillable());
503 EXPECT_FALSE(form_structure->ShouldBeCrowdsourced()); 477 EXPECT_FALSE(form_structure->ShouldBeCrowdsourced());
504 478
505 ASSERT_EQ(3U, form_structure->field_count()); 479 ASSERT_EQ(3U, form_structure->field_count());
506 ASSERT_EQ(0U, form_structure->autofill_count()); 480 ASSERT_EQ(0U, form_structure->autofill_count());
507 481
508 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(0)->heuristic_type()); 482 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(0)->heuristic_type());
509 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(1)->heuristic_type()); 483 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(1)->heuristic_type());
510 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(2)->heuristic_type()); 484 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(2)->heuristic_type());
511 } 485 }
512 486
513 // Verify that we can correctly process sections listed in the |autocomplete| 487 // Verify that we can correctly process sections listed in the |autocomplete|
514 // attribute. 488 // attribute.
515 TEST(FormStructureTest, HeuristicsAutocompleteAttributeWithSections) { 489 TEST(FormStructureTest, HeuristicsAutocompleteAttributeWithSections) {
516 FormData form; 490 FormData form;
517 form.method = ASCIIToUTF16("post");
518 491
519 FormFieldData field; 492 FormFieldData field;
520 field.form_control_type = "text"; 493 field.form_control_type = "text";
521 494
522 // Some fields will have no section specified. These fall into the default 495 // Some fields will have no section specified. These fall into the default
523 // section. 496 // section.
524 field.autocomplete_attribute = "email"; 497 field.autocomplete_attribute = "email";
525 form.fields.push_back(field); 498 form.fields.push_back(field);
526 499
527 // We allow arbitrary section names. 500 // We allow arbitrary section names.
(...skipping 24 matching lines...) Expand all
552 // the implementation for more details. 525 // the implementation for more details.
553 field.autocomplete_attribute = "section--shipping email"; 526 field.autocomplete_attribute = "section--shipping email";
554 form.fields.push_back(field); 527 form.fields.push_back(field);
555 528
556 // Credit card fields are implicitly in a separate section from other fields. 529 // Credit card fields are implicitly in a separate section from other fields.
557 field.autocomplete_attribute = "section-foo cc-number"; 530 field.autocomplete_attribute = "section-foo cc-number";
558 form.fields.push_back(field); 531 form.fields.push_back(field);
559 532
560 FormStructure form_structure(form); 533 FormStructure form_structure(form);
561 form_structure.DetermineHeuristicTypes(TestAutofillMetrics()); 534 form_structure.DetermineHeuristicTypes(TestAutofillMetrics());
562 EXPECT_TRUE(form_structure.IsAutofillable(true)); 535 EXPECT_TRUE(form_structure.IsAutofillable());
563 536
564 // Expect the correct number of fields. 537 // Expect the correct number of fields.
565 ASSERT_EQ(9U, form_structure.field_count()); 538 ASSERT_EQ(9U, form_structure.field_count());
566 EXPECT_EQ(9U, form_structure.autofill_count()); 539 EXPECT_EQ(9U, form_structure.autofill_count());
567 540
568 // All of the fields in this form should be parsed as belonging to different 541 // All of the fields in this form should be parsed as belonging to different
569 // sections. 542 // sections.
570 std::set<std::string> section_names; 543 std::set<std::string> section_names;
571 for (size_t i = 0; i < 9; ++i) { 544 for (size_t i = 0; i < 9; ++i) {
572 section_names.insert(form_structure.field(i)->section()); 545 section_names.insert(form_structure.field(i)->section());
573 } 546 }
574 EXPECT_EQ(9U, section_names.size()); 547 EXPECT_EQ(9U, section_names.size());
575 } 548 }
576 549
577 // Verify that we can correctly process a degenerate section listed in the 550 // Verify that we can correctly process a degenerate section listed in the
578 // |autocomplete| attribute. 551 // |autocomplete| attribute.
579 TEST(FormStructureTest, HeuristicsAutocompleteAttributeWithSectionsDegenerate) { 552 TEST(FormStructureTest, HeuristicsAutocompleteAttributeWithSectionsDegenerate) {
580 FormData form; 553 FormData form;
581 form.method = ASCIIToUTF16("post");
582 554
583 FormFieldData field; 555 FormFieldData field;
584 field.form_control_type = "text"; 556 field.form_control_type = "text";
585 557
586 // Some fields will have no section specified. These fall into the default 558 // Some fields will have no section specified. These fall into the default
587 // section. 559 // section.
588 field.autocomplete_attribute = "email"; 560 field.autocomplete_attribute = "email";
589 form.fields.push_back(field); 561 form.fields.push_back(field);
590 562
591 // Specifying "section-" is equivalent to not specifying a section. 563 // Specifying "section-" is equivalent to not specifying a section.
(...skipping 23 matching lines...) Expand all
615 for (size_t i = 0; i < 6; ++i) { 587 for (size_t i = 0; i < 6; ++i) {
616 section_names.insert(form_structure.field(i)->section()); 588 section_names.insert(form_structure.field(i)->section());
617 } 589 }
618 EXPECT_EQ(1U, section_names.size()); 590 EXPECT_EQ(1U, section_names.size());
619 } 591 }
620 592
621 // Verify that we can correctly process repeated sections listed in the 593 // Verify that we can correctly process repeated sections listed in the
622 // |autocomplete| attribute. 594 // |autocomplete| attribute.
623 TEST(FormStructureTest, HeuristicsAutocompleteAttributeWithSectionsRepeated) { 595 TEST(FormStructureTest, HeuristicsAutocompleteAttributeWithSectionsRepeated) {
624 FormData form; 596 FormData form;
625 form.method = ASCIIToUTF16("post");
626 597
627 FormFieldData field; 598 FormFieldData field;
628 field.form_control_type = "text"; 599 field.form_control_type = "text";
629 600
630 field.autocomplete_attribute = "section-foo email"; 601 field.autocomplete_attribute = "section-foo email";
631 form.fields.push_back(field); 602 form.fields.push_back(field);
632 field.autocomplete_attribute = "section-foo address-line1"; 603 field.autocomplete_attribute = "section-foo address-line1";
633 form.fields.push_back(field); 604 form.fields.push_back(field);
634 605
635 FormStructure form_structure(form); 606 FormStructure form_structure(form);
636 form_structure.DetermineHeuristicTypes(TestAutofillMetrics()); 607 form_structure.DetermineHeuristicTypes(TestAutofillMetrics());
637 608
638 // Expect the correct number of fields. 609 // Expect the correct number of fields.
639 ASSERT_EQ(2U, form_structure.field_count()); 610 ASSERT_EQ(2U, form_structure.field_count());
640 EXPECT_EQ(2U, form_structure.autofill_count()); 611 EXPECT_EQ(2U, form_structure.autofill_count());
641 612
642 // All of the fields in this form should be parsed as belonging to the same 613 // All of the fields in this form should be parsed as belonging to the same
643 // section. 614 // section.
644 std::set<std::string> section_names; 615 std::set<std::string> section_names;
645 for (size_t i = 0; i < 2; ++i) { 616 for (size_t i = 0; i < 2; ++i) {
646 section_names.insert(form_structure.field(i)->section()); 617 section_names.insert(form_structure.field(i)->section());
647 } 618 }
648 EXPECT_EQ(1U, section_names.size()); 619 EXPECT_EQ(1U, section_names.size());
649 } 620 }
650 621
651 // Verify that we do not override the author-specified sections from a form with 622 // Verify that we do not override the author-specified sections from a form with
652 // local heuristics. 623 // local heuristics.
653 TEST(FormStructureTest, HeuristicsDontOverrideAutocompleteAttributeSections) { 624 TEST(FormStructureTest, HeuristicsDontOverrideAutocompleteAttributeSections) {
654 FormData form; 625 FormData form;
655 form.method = ASCIIToUTF16("post");
656 626
657 FormFieldData field; 627 FormFieldData field;
658 field.form_control_type = "text"; 628 field.form_control_type = "text";
659 629
660 field.name = ASCIIToUTF16("one"); 630 field.name = ASCIIToUTF16("one");
661 field.autocomplete_attribute = "address-line1"; 631 field.autocomplete_attribute = "address-line1";
662 form.fields.push_back(field); 632 form.fields.push_back(field);
663 field.name = base::string16(); 633 field.name = base::string16();
664 field.autocomplete_attribute = "section-foo email"; 634 field.autocomplete_attribute = "section-foo email";
665 form.fields.push_back(field); 635 form.fields.push_back(field);
(...skipping 16 matching lines...) Expand all
682 // form, we do not apply these usual heuristics. 652 // form, we do not apply these usual heuristics.
683 EXPECT_EQ(ASCIIToUTF16("one"), form_structure.field(0)->name); 653 EXPECT_EQ(ASCIIToUTF16("one"), form_structure.field(0)->name);
684 EXPECT_EQ(ASCIIToUTF16("two"), form_structure.field(3)->name); 654 EXPECT_EQ(ASCIIToUTF16("two"), form_structure.field(3)->name);
685 EXPECT_EQ(form_structure.field(0)->section(), 655 EXPECT_EQ(form_structure.field(0)->section(),
686 form_structure.field(3)->section()); 656 form_structure.field(3)->section());
687 } 657 }
688 658
689 TEST(FormStructureTest, HeuristicsSample8) { 659 TEST(FormStructureTest, HeuristicsSample8) {
690 scoped_ptr<FormStructure> form_structure; 660 scoped_ptr<FormStructure> form_structure;
691 FormData form; 661 FormData form;
692 form.method = ASCIIToUTF16("post");
693 662
694 FormFieldData field; 663 FormFieldData field;
695 field.form_control_type = "text"; 664 field.form_control_type = "text";
696 665
697 field.label = ASCIIToUTF16("Your First Name:"); 666 field.label = ASCIIToUTF16("Your First Name:");
698 field.name = ASCIIToUTF16("bill.first"); 667 field.name = ASCIIToUTF16("bill.first");
699 form.fields.push_back(field); 668 form.fields.push_back(field);
700 669
701 field.label = ASCIIToUTF16("Your Last Name:"); 670 field.label = ASCIIToUTF16("Your Last Name:");
702 field.name = ASCIIToUTF16("bill.last"); 671 field.name = ASCIIToUTF16("bill.last");
(...skipping 27 matching lines...) Expand all
730 field.name = ASCIIToUTF16("BillTo.Phone"); 699 field.name = ASCIIToUTF16("BillTo.Phone");
731 form.fields.push_back(field); 700 form.fields.push_back(field);
732 701
733 field.label = base::string16(); 702 field.label = base::string16();
734 field.name = ASCIIToUTF16("Submit"); 703 field.name = ASCIIToUTF16("Submit");
735 field.form_control_type = "submit"; 704 field.form_control_type = "submit";
736 form.fields.push_back(field); 705 form.fields.push_back(field);
737 706
738 form_structure.reset(new FormStructure(form)); 707 form_structure.reset(new FormStructure(form));
739 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); 708 form_structure->DetermineHeuristicTypes(TestAutofillMetrics());
740 EXPECT_TRUE(form_structure->IsAutofillable(true)); 709 EXPECT_TRUE(form_structure->IsAutofillable());
741 ASSERT_EQ(10U, form_structure->field_count()); 710 ASSERT_EQ(10U, form_structure->field_count());
742 ASSERT_EQ(9U, form_structure->autofill_count()); 711 ASSERT_EQ(9U, form_structure->autofill_count());
743 712
744 // First name. 713 // First name.
745 EXPECT_EQ(NAME_FIRST, form_structure->field(0)->heuristic_type()); 714 EXPECT_EQ(NAME_FIRST, form_structure->field(0)->heuristic_type());
746 // Last name. 715 // Last name.
747 EXPECT_EQ(NAME_LAST, form_structure->field(1)->heuristic_type()); 716 EXPECT_EQ(NAME_LAST, form_structure->field(1)->heuristic_type());
748 // Address. 717 // Address.
749 EXPECT_EQ(ADDRESS_HOME_LINE1, form_structure->field(2)->heuristic_type()); 718 EXPECT_EQ(ADDRESS_HOME_LINE1, form_structure->field(2)->heuristic_type());
750 // Address. 719 // Address.
751 EXPECT_EQ(ADDRESS_HOME_LINE2, form_structure->field(3)->heuristic_type()); 720 EXPECT_EQ(ADDRESS_HOME_LINE2, form_structure->field(3)->heuristic_type());
752 // City. 721 // City.
753 EXPECT_EQ(ADDRESS_HOME_CITY, form_structure->field(4)->heuristic_type()); 722 EXPECT_EQ(ADDRESS_HOME_CITY, form_structure->field(4)->heuristic_type());
754 // State. 723 // State.
755 EXPECT_EQ(ADDRESS_HOME_STATE, form_structure->field(5)->heuristic_type()); 724 EXPECT_EQ(ADDRESS_HOME_STATE, form_structure->field(5)->heuristic_type());
756 // Zip. 725 // Zip.
757 EXPECT_EQ(ADDRESS_HOME_ZIP, form_structure->field(6)->heuristic_type()); 726 EXPECT_EQ(ADDRESS_HOME_ZIP, form_structure->field(6)->heuristic_type());
758 // Country. 727 // Country.
759 EXPECT_EQ(ADDRESS_HOME_COUNTRY, form_structure->field(7)->heuristic_type()); 728 EXPECT_EQ(ADDRESS_HOME_COUNTRY, form_structure->field(7)->heuristic_type());
760 // Phone. 729 // Phone.
761 EXPECT_EQ(PHONE_HOME_WHOLE_NUMBER, 730 EXPECT_EQ(PHONE_HOME_WHOLE_NUMBER,
762 form_structure->field(8)->heuristic_type()); 731 form_structure->field(8)->heuristic_type());
763 // Submit. 732 // Submit.
764 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(9)->heuristic_type()); 733 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(9)->heuristic_type());
765 } 734 }
766 735
767 TEST(FormStructureTest, HeuristicsSample6) { 736 TEST(FormStructureTest, HeuristicsSample6) {
768 scoped_ptr<FormStructure> form_structure; 737 scoped_ptr<FormStructure> form_structure;
769 FormData form; 738 FormData form;
770 form.method = ASCIIToUTF16("post");
771 739
772 FormFieldData field; 740 FormFieldData field;
773 field.form_control_type = "text"; 741 field.form_control_type = "text";
774 742
775 field.label = ASCIIToUTF16("E-mail address"); 743 field.label = ASCIIToUTF16("E-mail address");
776 field.name = ASCIIToUTF16("email"); 744 field.name = ASCIIToUTF16("email");
777 form.fields.push_back(field); 745 form.fields.push_back(field);
778 746
779 field.label = ASCIIToUTF16("Full name"); 747 field.label = ASCIIToUTF16("Full name");
780 field.name = ASCIIToUTF16("name"); 748 field.name = ASCIIToUTF16("name");
(...skipping 16 matching lines...) Expand all
797 form.fields.push_back(field); 765 form.fields.push_back(field);
798 766
799 field.label = base::string16(); 767 field.label = base::string16();
800 field.name = ASCIIToUTF16("Submit"); 768 field.name = ASCIIToUTF16("Submit");
801 field.value = ASCIIToUTF16("continue"); 769 field.value = ASCIIToUTF16("continue");
802 field.form_control_type = "submit"; 770 field.form_control_type = "submit";
803 form.fields.push_back(field); 771 form.fields.push_back(field);
804 772
805 form_structure.reset(new FormStructure(form)); 773 form_structure.reset(new FormStructure(form));
806 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); 774 form_structure->DetermineHeuristicTypes(TestAutofillMetrics());
807 EXPECT_TRUE(form_structure->IsAutofillable(true)); 775 EXPECT_TRUE(form_structure->IsAutofillable());
808 ASSERT_EQ(7U, form_structure->field_count()); 776 ASSERT_EQ(7U, form_structure->field_count());
809 ASSERT_EQ(6U, form_structure->autofill_count()); 777 ASSERT_EQ(6U, form_structure->autofill_count());
810 778
811 // Email. 779 // Email.
812 EXPECT_EQ(EMAIL_ADDRESS, form_structure->field(0)->heuristic_type()); 780 EXPECT_EQ(EMAIL_ADDRESS, form_structure->field(0)->heuristic_type());
813 // Full name. 781 // Full name.
814 EXPECT_EQ(NAME_FULL, form_structure->field(1)->heuristic_type()); 782 EXPECT_EQ(NAME_FULL, form_structure->field(1)->heuristic_type());
815 // Company 783 // Company
816 EXPECT_EQ(COMPANY_NAME, form_structure->field(2)->heuristic_type()); 784 EXPECT_EQ(COMPANY_NAME, form_structure->field(2)->heuristic_type());
817 // Address. 785 // Address.
818 EXPECT_EQ(ADDRESS_HOME_LINE1, form_structure->field(3)->heuristic_type()); 786 EXPECT_EQ(ADDRESS_HOME_LINE1, form_structure->field(3)->heuristic_type());
819 // City. 787 // City.
820 EXPECT_EQ(ADDRESS_HOME_CITY, form_structure->field(4)->heuristic_type()); 788 EXPECT_EQ(ADDRESS_HOME_CITY, form_structure->field(4)->heuristic_type());
821 // Zip. 789 // Zip.
822 EXPECT_EQ(ADDRESS_HOME_ZIP, form_structure->field(5)->heuristic_type()); 790 EXPECT_EQ(ADDRESS_HOME_ZIP, form_structure->field(5)->heuristic_type());
823 // Submit. 791 // Submit.
824 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(6)->heuristic_type()); 792 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(6)->heuristic_type());
825 } 793 }
826 794
827 // Tests a sequence of FormFields where only labels are supplied to heuristics 795 // Tests a sequence of FormFields where only labels are supplied to heuristics
828 // for matching. This works because FormFieldData labels are matched in the 796 // for matching. This works because FormFieldData labels are matched in the
829 // case that input element ids (or |name| fields) are missing. 797 // case that input element ids (or |name| fields) are missing.
830 TEST(FormStructureTest, HeuristicsLabelsOnly) { 798 TEST(FormStructureTest, HeuristicsLabelsOnly) {
831 scoped_ptr<FormStructure> form_structure; 799 scoped_ptr<FormStructure> form_structure;
832 FormData form; 800 FormData form;
833 form.method = ASCIIToUTF16("post");
834 801
835 FormFieldData field; 802 FormFieldData field;
836 field.form_control_type = "text"; 803 field.form_control_type = "text";
837 804
838 field.label = ASCIIToUTF16("First Name"); 805 field.label = ASCIIToUTF16("First Name");
839 field.name = base::string16(); 806 field.name = base::string16();
840 form.fields.push_back(field); 807 form.fields.push_back(field);
841 808
842 field.label = ASCIIToUTF16("Last Name"); 809 field.label = ASCIIToUTF16("Last Name");
843 field.name = base::string16(); 810 field.name = base::string16();
(...skipping 19 matching lines...) Expand all
863 field.name = base::string16(); 830 field.name = base::string16();
864 form.fields.push_back(field); 831 form.fields.push_back(field);
865 832
866 field.label = base::string16(); 833 field.label = base::string16();
867 field.name = ASCIIToUTF16("Submit"); 834 field.name = ASCIIToUTF16("Submit");
868 field.form_control_type = "submit"; 835 field.form_control_type = "submit";
869 form.fields.push_back(field); 836 form.fields.push_back(field);
870 837
871 form_structure.reset(new FormStructure(form)); 838 form_structure.reset(new FormStructure(form));
872 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); 839 form_structure->DetermineHeuristicTypes(TestAutofillMetrics());
873 EXPECT_TRUE(form_structure->IsAutofillable(true)); 840 EXPECT_TRUE(form_structure->IsAutofillable());
874 ASSERT_EQ(8U, form_structure->field_count()); 841 ASSERT_EQ(8U, form_structure->field_count());
875 ASSERT_EQ(7U, form_structure->autofill_count()); 842 ASSERT_EQ(7U, form_structure->autofill_count());
876 843
877 // First name. 844 // First name.
878 EXPECT_EQ(NAME_FIRST, form_structure->field(0)->heuristic_type()); 845 EXPECT_EQ(NAME_FIRST, form_structure->field(0)->heuristic_type());
879 // Last name. 846 // Last name.
880 EXPECT_EQ(NAME_LAST, form_structure->field(1)->heuristic_type()); 847 EXPECT_EQ(NAME_LAST, form_structure->field(1)->heuristic_type());
881 // Email. 848 // Email.
882 EXPECT_EQ(EMAIL_ADDRESS, form_structure->field(2)->heuristic_type()); 849 EXPECT_EQ(EMAIL_ADDRESS, form_structure->field(2)->heuristic_type());
883 // Phone. 850 // Phone.
884 EXPECT_EQ(PHONE_HOME_WHOLE_NUMBER, 851 EXPECT_EQ(PHONE_HOME_WHOLE_NUMBER,
885 form_structure->field(3)->heuristic_type()); 852 form_structure->field(3)->heuristic_type());
886 // Address. 853 // Address.
887 EXPECT_EQ(ADDRESS_HOME_LINE1, form_structure->field(4)->heuristic_type()); 854 EXPECT_EQ(ADDRESS_HOME_LINE1, form_structure->field(4)->heuristic_type());
888 // Address Line 2. 855 // Address Line 2.
889 EXPECT_EQ(ADDRESS_HOME_LINE2, form_structure->field(5)->heuristic_type()); 856 EXPECT_EQ(ADDRESS_HOME_LINE2, form_structure->field(5)->heuristic_type());
890 // Zip. 857 // Zip.
891 EXPECT_EQ(ADDRESS_HOME_ZIP, form_structure->field(6)->heuristic_type()); 858 EXPECT_EQ(ADDRESS_HOME_ZIP, form_structure->field(6)->heuristic_type());
892 // Submit. 859 // Submit.
893 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(7)->heuristic_type()); 860 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(7)->heuristic_type());
894 } 861 }
895 862
896 TEST(FormStructureTest, HeuristicsCreditCardInfo) { 863 TEST(FormStructureTest, HeuristicsCreditCardInfo) {
897 scoped_ptr<FormStructure> form_structure; 864 scoped_ptr<FormStructure> form_structure;
898 FormData form; 865 FormData form;
899 form.method = ASCIIToUTF16("post");
900 866
901 FormFieldData field; 867 FormFieldData field;
902 field.form_control_type = "text"; 868 field.form_control_type = "text";
903 869
904 field.label = ASCIIToUTF16("Name on Card"); 870 field.label = ASCIIToUTF16("Name on Card");
905 field.name = ASCIIToUTF16("name_on_card"); 871 field.name = ASCIIToUTF16("name_on_card");
906 form.fields.push_back(field); 872 form.fields.push_back(field);
907 873
908 field.label = ASCIIToUTF16("Card Number"); 874 field.label = ASCIIToUTF16("Card Number");
909 field.name = ASCIIToUTF16("card_number"); 875 field.name = ASCIIToUTF16("card_number");
(...skipping 11 matching lines...) Expand all
921 field.name = ASCIIToUTF16("verification"); 887 field.name = ASCIIToUTF16("verification");
922 form.fields.push_back(field); 888 form.fields.push_back(field);
923 889
924 field.label = base::string16(); 890 field.label = base::string16();
925 field.name = ASCIIToUTF16("Submit"); 891 field.name = ASCIIToUTF16("Submit");
926 field.form_control_type = "submit"; 892 field.form_control_type = "submit";
927 form.fields.push_back(field); 893 form.fields.push_back(field);
928 894
929 form_structure.reset(new FormStructure(form)); 895 form_structure.reset(new FormStructure(form));
930 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); 896 form_structure->DetermineHeuristicTypes(TestAutofillMetrics());
931 EXPECT_TRUE(form_structure->IsAutofillable(true)); 897 EXPECT_TRUE(form_structure->IsAutofillable());
932 ASSERT_EQ(6U, form_structure->field_count()); 898 ASSERT_EQ(6U, form_structure->field_count());
933 ASSERT_EQ(5U, form_structure->autofill_count()); 899 ASSERT_EQ(5U, form_structure->autofill_count());
934 900
935 // Credit card name. 901 // Credit card name.
936 EXPECT_EQ(CREDIT_CARD_NAME, form_structure->field(0)->heuristic_type()); 902 EXPECT_EQ(CREDIT_CARD_NAME, form_structure->field(0)->heuristic_type());
937 // Credit card number. 903 // Credit card number.
938 EXPECT_EQ(CREDIT_CARD_NUMBER, form_structure->field(1)->heuristic_type()); 904 EXPECT_EQ(CREDIT_CARD_NUMBER, form_structure->field(1)->heuristic_type());
939 // Credit card expiration month. 905 // Credit card expiration month.
940 EXPECT_EQ(CREDIT_CARD_EXP_MONTH, form_structure->field(2)->heuristic_type()); 906 EXPECT_EQ(CREDIT_CARD_EXP_MONTH, form_structure->field(2)->heuristic_type());
941 // Credit card expiration year. 907 // Credit card expiration year.
942 EXPECT_EQ(CREDIT_CARD_EXP_4_DIGIT_YEAR, 908 EXPECT_EQ(CREDIT_CARD_EXP_4_DIGIT_YEAR,
943 form_structure->field(3)->heuristic_type()); 909 form_structure->field(3)->heuristic_type());
944 // CVV. 910 // CVV.
945 EXPECT_EQ(CREDIT_CARD_VERIFICATION_CODE, 911 EXPECT_EQ(CREDIT_CARD_VERIFICATION_CODE,
946 form_structure->field(4)->heuristic_type()); 912 form_structure->field(4)->heuristic_type());
947 // Submit. 913 // Submit.
948 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(5)->heuristic_type()); 914 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(5)->heuristic_type());
949 } 915 }
950 916
951 TEST(FormStructureTest, HeuristicsCreditCardInfoWithUnknownCardField) { 917 TEST(FormStructureTest, HeuristicsCreditCardInfoWithUnknownCardField) {
952 scoped_ptr<FormStructure> form_structure; 918 scoped_ptr<FormStructure> form_structure;
953 FormData form; 919 FormData form;
954 form.method = ASCIIToUTF16("post");
955 920
956 FormFieldData field; 921 FormFieldData field;
957 field.form_control_type = "text"; 922 field.form_control_type = "text";
958 923
959 field.label = ASCIIToUTF16("Name on Card"); 924 field.label = ASCIIToUTF16("Name on Card");
960 field.name = ASCIIToUTF16("name_on_card"); 925 field.name = ASCIIToUTF16("name_on_card");
961 form.fields.push_back(field); 926 form.fields.push_back(field);
962 927
963 // This is not a field we know how to process. But we should skip over it 928 // This is not a field we know how to process. But we should skip over it
964 // and process the other fields in the card block. 929 // and process the other fields in the card block.
(...skipping 17 matching lines...) Expand all
982 field.name = ASCIIToUTF16("verification"); 947 field.name = ASCIIToUTF16("verification");
983 form.fields.push_back(field); 948 form.fields.push_back(field);
984 949
985 field.label = base::string16(); 950 field.label = base::string16();
986 field.name = ASCIIToUTF16("Submit"); 951 field.name = ASCIIToUTF16("Submit");
987 field.form_control_type = "submit"; 952 field.form_control_type = "submit";
988 form.fields.push_back(field); 953 form.fields.push_back(field);
989 954
990 form_structure.reset(new FormStructure(form)); 955 form_structure.reset(new FormStructure(form));
991 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); 956 form_structure->DetermineHeuristicTypes(TestAutofillMetrics());
992 EXPECT_TRUE(form_structure->IsAutofillable(true)); 957 EXPECT_TRUE(form_structure->IsAutofillable());
993 ASSERT_EQ(7U, form_structure->field_count()); 958 ASSERT_EQ(7U, form_structure->field_count());
994 ASSERT_EQ(5U, form_structure->autofill_count()); 959 ASSERT_EQ(5U, form_structure->autofill_count());
995 960
996 // Credit card name. 961 // Credit card name.
997 EXPECT_EQ(CREDIT_CARD_NAME, form_structure->field(0)->heuristic_type()); 962 EXPECT_EQ(CREDIT_CARD_NAME, form_structure->field(0)->heuristic_type());
998 // Credit card type. This is an unknown type but related to the credit card. 963 // Credit card type. This is an unknown type but related to the credit card.
999 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(1)->heuristic_type()); 964 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(1)->heuristic_type());
1000 // Credit card number. 965 // Credit card number.
1001 EXPECT_EQ(CREDIT_CARD_NUMBER, form_structure->field(2)->heuristic_type()); 966 EXPECT_EQ(CREDIT_CARD_NUMBER, form_structure->field(2)->heuristic_type());
1002 // Credit card expiration month. 967 // Credit card expiration month.
1003 EXPECT_EQ(CREDIT_CARD_EXP_MONTH, form_structure->field(3)->heuristic_type()); 968 EXPECT_EQ(CREDIT_CARD_EXP_MONTH, form_structure->field(3)->heuristic_type());
1004 // Credit card expiration year. 969 // Credit card expiration year.
1005 EXPECT_EQ(CREDIT_CARD_EXP_4_DIGIT_YEAR, 970 EXPECT_EQ(CREDIT_CARD_EXP_4_DIGIT_YEAR,
1006 form_structure->field(4)->heuristic_type()); 971 form_structure->field(4)->heuristic_type());
1007 // CVV. 972 // CVV.
1008 EXPECT_EQ(CREDIT_CARD_VERIFICATION_CODE, 973 EXPECT_EQ(CREDIT_CARD_VERIFICATION_CODE,
1009 form_structure->field(5)->heuristic_type()); 974 form_structure->field(5)->heuristic_type());
1010 // Submit. 975 // Submit.
1011 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(6)->heuristic_type()); 976 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(6)->heuristic_type());
1012 } 977 }
1013 978
1014 TEST(FormStructureTest, ThreeAddressLines) { 979 TEST(FormStructureTest, ThreeAddressLines) {
1015 scoped_ptr<FormStructure> form_structure; 980 scoped_ptr<FormStructure> form_structure;
1016 FormData form; 981 FormData form;
1017 form.method = ASCIIToUTF16("post");
1018 982
1019 FormFieldData field; 983 FormFieldData field;
1020 field.form_control_type = "text"; 984 field.form_control_type = "text";
1021 985
1022 field.label = ASCIIToUTF16("Address Line1"); 986 field.label = ASCIIToUTF16("Address Line1");
1023 field.name = ASCIIToUTF16("Address"); 987 field.name = ASCIIToUTF16("Address");
1024 form.fields.push_back(field); 988 form.fields.push_back(field);
1025 989
1026 field.label = ASCIIToUTF16("Address Line2"); 990 field.label = ASCIIToUTF16("Address Line2");
1027 field.name = ASCIIToUTF16("Address"); 991 field.name = ASCIIToUTF16("Address");
1028 form.fields.push_back(field); 992 form.fields.push_back(field);
1029 993
1030 field.label = ASCIIToUTF16("Address Line3"); 994 field.label = ASCIIToUTF16("Address Line3");
1031 field.name = ASCIIToUTF16("Address"); 995 field.name = ASCIIToUTF16("Address");
1032 form.fields.push_back(field); 996 form.fields.push_back(field);
1033 997
1034 field.label = ASCIIToUTF16("City"); 998 field.label = ASCIIToUTF16("City");
1035 field.name = ASCIIToUTF16("city"); 999 field.name = ASCIIToUTF16("city");
1036 form.fields.push_back(field); 1000 form.fields.push_back(field);
1037 1001
1038 form_structure.reset(new FormStructure(form)); 1002 form_structure.reset(new FormStructure(form));
1039 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); 1003 form_structure->DetermineHeuristicTypes(TestAutofillMetrics());
1040 EXPECT_TRUE(form_structure->IsAutofillable(true)); 1004 EXPECT_TRUE(form_structure->IsAutofillable());
1041 ASSERT_EQ(4U, form_structure->field_count()); 1005 ASSERT_EQ(4U, form_structure->field_count());
1042 ASSERT_EQ(3U, form_structure->autofill_count()); 1006 ASSERT_EQ(3U, form_structure->autofill_count());
1043 1007
1044 // Address Line 1. 1008 // Address Line 1.
1045 EXPECT_EQ(ADDRESS_HOME_LINE1, form_structure->field(0)->heuristic_type()); 1009 EXPECT_EQ(ADDRESS_HOME_LINE1, form_structure->field(0)->heuristic_type());
1046 // Address Line 2. 1010 // Address Line 2.
1047 EXPECT_EQ(ADDRESS_HOME_LINE2, form_structure->field(1)->heuristic_type()); 1011 EXPECT_EQ(ADDRESS_HOME_LINE2, form_structure->field(1)->heuristic_type());
1048 // Address Line 3. 1012 // Address Line 3.
1049 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(2)->heuristic_type()); 1013 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(2)->heuristic_type());
1050 // City. 1014 // City.
1051 EXPECT_EQ(ADDRESS_HOME_CITY, form_structure->field(3)->heuristic_type()); 1015 EXPECT_EQ(ADDRESS_HOME_CITY, form_structure->field(3)->heuristic_type());
1052 } 1016 }
1053 1017
1054 // Numbered address lines after line two are ignored. 1018 // Numbered address lines after line two are ignored.
1055 TEST(FormStructureTest, SurplusAddressLinesIgnored) { 1019 TEST(FormStructureTest, SurplusAddressLinesIgnored) {
1056 scoped_ptr<FormStructure> form_structure; 1020 scoped_ptr<FormStructure> form_structure;
1057 FormData form; 1021 FormData form;
1058 form.method = ASCIIToUTF16("post");
1059 1022
1060 FormFieldData field; 1023 FormFieldData field;
1061 field.form_control_type = "text"; 1024 field.form_control_type = "text";
1062 1025
1063 field.label = ASCIIToUTF16("Address Line1"); 1026 field.label = ASCIIToUTF16("Address Line1");
1064 field.name = ASCIIToUTF16("shipping.address.addressLine1"); 1027 field.name = ASCIIToUTF16("shipping.address.addressLine1");
1065 form.fields.push_back(field); 1028 form.fields.push_back(field);
1066 1029
1067 field.label = ASCIIToUTF16("Address Line2"); 1030 field.label = ASCIIToUTF16("Address Line2");
1068 field.name = ASCIIToUTF16("shipping.address.addressLine2"); 1031 field.name = ASCIIToUTF16("shipping.address.addressLine2");
(...skipping 23 matching lines...) Expand all
1092 } 1055 }
1093 1056
1094 // This example comes from expedia.com where they use a "Suite" label to 1057 // This example comes from expedia.com where they use a "Suite" label to
1095 // indicate a suite or apartment number. We interpret this as address line 2. 1058 // indicate a suite or apartment number. We interpret this as address line 2.
1096 // And the following "Street address second line" we interpret as address line 1059 // And the following "Street address second line" we interpret as address line
1097 // 3 and discard. 1060 // 3 and discard.
1098 // See http://crbug.com/48197 for details. 1061 // See http://crbug.com/48197 for details.
1099 TEST(FormStructureTest, ThreeAddressLinesExpedia) { 1062 TEST(FormStructureTest, ThreeAddressLinesExpedia) {
1100 scoped_ptr<FormStructure> form_structure; 1063 scoped_ptr<FormStructure> form_structure;
1101 FormData form; 1064 FormData form;
1102 form.method = ASCIIToUTF16("post");
1103 1065
1104 FormFieldData field; 1066 FormFieldData field;
1105 field.form_control_type = "text"; 1067 field.form_control_type = "text";
1106 1068
1107 field.label = ASCIIToUTF16("Street:"); 1069 field.label = ASCIIToUTF16("Street:");
1108 field.name = ASCIIToUTF16("FOPIH_RgWebCC_0_IHAddress_ads1"); 1070 field.name = ASCIIToUTF16("FOPIH_RgWebCC_0_IHAddress_ads1");
1109 form.fields.push_back(field); 1071 form.fields.push_back(field);
1110 1072
1111 field.label = ASCIIToUTF16("Suite or Apt:"); 1073 field.label = ASCIIToUTF16("Suite or Apt:");
1112 field.name = ASCIIToUTF16("FOPIH_RgWebCC_0_IHAddress_adap"); 1074 field.name = ASCIIToUTF16("FOPIH_RgWebCC_0_IHAddress_adap");
1113 form.fields.push_back(field); 1075 form.fields.push_back(field);
1114 1076
1115 field.label = ASCIIToUTF16("Street address second line"); 1077 field.label = ASCIIToUTF16("Street address second line");
1116 field.name = ASCIIToUTF16("FOPIH_RgWebCC_0_IHAddress_ads2"); 1078 field.name = ASCIIToUTF16("FOPIH_RgWebCC_0_IHAddress_ads2");
1117 form.fields.push_back(field); 1079 form.fields.push_back(field);
1118 1080
1119 field.label = ASCIIToUTF16("City:"); 1081 field.label = ASCIIToUTF16("City:");
1120 field.name = ASCIIToUTF16("FOPIH_RgWebCC_0_IHAddress_adct"); 1082 field.name = ASCIIToUTF16("FOPIH_RgWebCC_0_IHAddress_adct");
1121 form.fields.push_back(field); 1083 form.fields.push_back(field);
1122 1084
1123 form_structure.reset(new FormStructure(form)); 1085 form_structure.reset(new FormStructure(form));
1124 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); 1086 form_structure->DetermineHeuristicTypes(TestAutofillMetrics());
1125 EXPECT_TRUE(form_structure->IsAutofillable(true)); 1087 EXPECT_TRUE(form_structure->IsAutofillable());
1126 ASSERT_EQ(4U, form_structure->field_count()); 1088 ASSERT_EQ(4U, form_structure->field_count());
1127 EXPECT_EQ(3U, form_structure->autofill_count()); 1089 EXPECT_EQ(3U, form_structure->autofill_count());
1128 1090
1129 // Address Line 1. 1091 // Address Line 1.
1130 EXPECT_EQ(ADDRESS_HOME_LINE1, form_structure->field(0)->heuristic_type()); 1092 EXPECT_EQ(ADDRESS_HOME_LINE1, form_structure->field(0)->heuristic_type());
1131 // Suite / Apt. 1093 // Suite / Apt.
1132 EXPECT_EQ(ADDRESS_HOME_LINE2, form_structure->field(1)->heuristic_type()); 1094 EXPECT_EQ(ADDRESS_HOME_LINE2, form_structure->field(1)->heuristic_type());
1133 // Address Line 3. 1095 // Address Line 3.
1134 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(2)->heuristic_type()); 1096 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(2)->heuristic_type());
1135 // City. 1097 // City.
1136 EXPECT_EQ(ADDRESS_HOME_CITY, form_structure->field(3)->heuristic_type()); 1098 EXPECT_EQ(ADDRESS_HOME_CITY, form_structure->field(3)->heuristic_type());
1137 } 1099 }
1138 1100
1139 // This example comes from ebay.com where the word "suite" appears in the label 1101 // This example comes from ebay.com where the word "suite" appears in the label
1140 // and the name "address2" clearly indicates that this is the address line 2. 1102 // and the name "address2" clearly indicates that this is the address line 2.
1141 // See http://crbug.com/48197 for details. 1103 // See http://crbug.com/48197 for details.
1142 TEST(FormStructureTest, TwoAddressLinesEbay) { 1104 TEST(FormStructureTest, TwoAddressLinesEbay) {
1143 scoped_ptr<FormStructure> form_structure; 1105 scoped_ptr<FormStructure> form_structure;
1144 FormData form; 1106 FormData form;
1145 form.method = ASCIIToUTF16("post");
1146 1107
1147 FormFieldData field; 1108 FormFieldData field;
1148 field.form_control_type = "text"; 1109 field.form_control_type = "text";
1149 1110
1150 field.label = ASCIIToUTF16("Address Line1"); 1111 field.label = ASCIIToUTF16("Address Line1");
1151 field.name = ASCIIToUTF16("address1"); 1112 field.name = ASCIIToUTF16("address1");
1152 form.fields.push_back(field); 1113 form.fields.push_back(field);
1153 1114
1154 field.label = ASCIIToUTF16("Floor number, suite number, etc"); 1115 field.label = ASCIIToUTF16("Floor number, suite number, etc");
1155 field.name = ASCIIToUTF16("address2"); 1116 field.name = ASCIIToUTF16("address2");
1156 form.fields.push_back(field); 1117 form.fields.push_back(field);
1157 1118
1158 field.label = ASCIIToUTF16("City:"); 1119 field.label = ASCIIToUTF16("City:");
1159 field.name = ASCIIToUTF16("city"); 1120 field.name = ASCIIToUTF16("city");
1160 form.fields.push_back(field); 1121 form.fields.push_back(field);
1161 1122
1162 form_structure.reset(new FormStructure(form)); 1123 form_structure.reset(new FormStructure(form));
1163 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); 1124 form_structure->DetermineHeuristicTypes(TestAutofillMetrics());
1164 EXPECT_TRUE(form_structure->IsAutofillable(true)); 1125 EXPECT_TRUE(form_structure->IsAutofillable());
1165 ASSERT_EQ(3U, form_structure->field_count()); 1126 ASSERT_EQ(3U, form_structure->field_count());
1166 ASSERT_EQ(3U, form_structure->autofill_count()); 1127 ASSERT_EQ(3U, form_structure->autofill_count());
1167 1128
1168 // Address Line 1. 1129 // Address Line 1.
1169 EXPECT_EQ(ADDRESS_HOME_LINE1, form_structure->field(0)->heuristic_type()); 1130 EXPECT_EQ(ADDRESS_HOME_LINE1, form_structure->field(0)->heuristic_type());
1170 // Address Line 2. 1131 // Address Line 2.
1171 EXPECT_EQ(ADDRESS_HOME_LINE2, form_structure->field(1)->heuristic_type()); 1132 EXPECT_EQ(ADDRESS_HOME_LINE2, form_structure->field(1)->heuristic_type());
1172 // City. 1133 // City.
1173 EXPECT_EQ(ADDRESS_HOME_CITY, form_structure->field(2)->heuristic_type()); 1134 EXPECT_EQ(ADDRESS_HOME_CITY, form_structure->field(2)->heuristic_type());
1174 } 1135 }
1175 1136
1176 TEST(FormStructureTest, HeuristicsStateWithProvince) { 1137 TEST(FormStructureTest, HeuristicsStateWithProvince) {
1177 scoped_ptr<FormStructure> form_structure; 1138 scoped_ptr<FormStructure> form_structure;
1178 FormData form; 1139 FormData form;
1179 form.method = ASCIIToUTF16("post");
1180 1140
1181 FormFieldData field; 1141 FormFieldData field;
1182 field.form_control_type = "text"; 1142 field.form_control_type = "text";
1183 1143
1184 field.label = ASCIIToUTF16("Address Line1"); 1144 field.label = ASCIIToUTF16("Address Line1");
1185 field.name = ASCIIToUTF16("Address"); 1145 field.name = ASCIIToUTF16("Address");
1186 form.fields.push_back(field); 1146 form.fields.push_back(field);
1187 1147
1188 field.label = ASCIIToUTF16("Address Line2"); 1148 field.label = ASCIIToUTF16("Address Line2");
1189 field.name = ASCIIToUTF16("Address"); 1149 field.name = ASCIIToUTF16("Address");
1190 form.fields.push_back(field); 1150 form.fields.push_back(field);
1191 1151
1192 field.label = ASCIIToUTF16("State/Province/Region"); 1152 field.label = ASCIIToUTF16("State/Province/Region");
1193 field.name = ASCIIToUTF16("State"); 1153 field.name = ASCIIToUTF16("State");
1194 form.fields.push_back(field); 1154 form.fields.push_back(field);
1195 1155
1196 form_structure.reset(new FormStructure(form)); 1156 form_structure.reset(new FormStructure(form));
1197 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); 1157 form_structure->DetermineHeuristicTypes(TestAutofillMetrics());
1198 EXPECT_TRUE(form_structure->IsAutofillable(true)); 1158 EXPECT_TRUE(form_structure->IsAutofillable());
1199 ASSERT_EQ(3U, form_structure->field_count()); 1159 ASSERT_EQ(3U, form_structure->field_count());
1200 ASSERT_EQ(3U, form_structure->autofill_count()); 1160 ASSERT_EQ(3U, form_structure->autofill_count());
1201 1161
1202 // Address Line 1. 1162 // Address Line 1.
1203 EXPECT_EQ(ADDRESS_HOME_LINE1, form_structure->field(0)->heuristic_type()); 1163 EXPECT_EQ(ADDRESS_HOME_LINE1, form_structure->field(0)->heuristic_type());
1204 // Address Line 2. 1164 // Address Line 2.
1205 EXPECT_EQ(ADDRESS_HOME_LINE2, form_structure->field(1)->heuristic_type()); 1165 EXPECT_EQ(ADDRESS_HOME_LINE2, form_structure->field(1)->heuristic_type());
1206 // State. 1166 // State.
1207 EXPECT_EQ(ADDRESS_HOME_STATE, form_structure->field(2)->heuristic_type()); 1167 EXPECT_EQ(ADDRESS_HOME_STATE, form_structure->field(2)->heuristic_type());
1208 } 1168 }
1209 1169
1210 // This example comes from lego.com's checkout page. 1170 // This example comes from lego.com's checkout page.
1211 TEST(FormStructureTest, HeuristicsWithBilling) { 1171 TEST(FormStructureTest, HeuristicsWithBilling) {
1212 scoped_ptr<FormStructure> form_structure; 1172 scoped_ptr<FormStructure> form_structure;
1213 FormData form; 1173 FormData form;
1214 form.method = ASCIIToUTF16("post");
1215 1174
1216 FormFieldData field; 1175 FormFieldData field;
1217 field.form_control_type = "text"; 1176 field.form_control_type = "text";
1218 1177
1219 field.label = ASCIIToUTF16("First Name*:"); 1178 field.label = ASCIIToUTF16("First Name*:");
1220 field.name = ASCIIToUTF16("editBillingAddress$firstNameBox"); 1179 field.name = ASCIIToUTF16("editBillingAddress$firstNameBox");
1221 form.fields.push_back(field); 1180 form.fields.push_back(field);
1222 1181
1223 field.label = ASCIIToUTF16("Last Name*:"); 1182 field.label = ASCIIToUTF16("Last Name*:");
1224 field.name = ASCIIToUTF16("editBillingAddress$lastNameBox"); 1183 field.name = ASCIIToUTF16("editBillingAddress$lastNameBox");
(...skipping 30 matching lines...) Expand all
1255 field.label = ASCIIToUTF16("Phone*:"); 1214 field.label = ASCIIToUTF16("Phone*:");
1256 field.name = ASCIIToUTF16("editBillingAddress$phoneBox"); 1215 field.name = ASCIIToUTF16("editBillingAddress$phoneBox");
1257 form.fields.push_back(field); 1216 form.fields.push_back(field);
1258 1217
1259 field.label = ASCIIToUTF16("Email Address*:"); 1218 field.label = ASCIIToUTF16("Email Address*:");
1260 field.name = ASCIIToUTF16("email$emailBox"); 1219 field.name = ASCIIToUTF16("email$emailBox");
1261 form.fields.push_back(field); 1220 form.fields.push_back(field);
1262 1221
1263 form_structure.reset(new FormStructure(form)); 1222 form_structure.reset(new FormStructure(form));
1264 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); 1223 form_structure->DetermineHeuristicTypes(TestAutofillMetrics());
1265 EXPECT_TRUE(form_structure->IsAutofillable(true)); 1224 EXPECT_TRUE(form_structure->IsAutofillable());
1266 ASSERT_EQ(11U, form_structure->field_count()); 1225 ASSERT_EQ(11U, form_structure->field_count());
1267 ASSERT_EQ(11U, form_structure->autofill_count()); 1226 ASSERT_EQ(11U, form_structure->autofill_count());
1268 1227
1269 EXPECT_EQ(NAME_FIRST, form_structure->field(0)->heuristic_type()); 1228 EXPECT_EQ(NAME_FIRST, form_structure->field(0)->heuristic_type());
1270 EXPECT_EQ(NAME_LAST, form_structure->field(1)->heuristic_type()); 1229 EXPECT_EQ(NAME_LAST, form_structure->field(1)->heuristic_type());
1271 EXPECT_EQ(COMPANY_NAME, form_structure->field(2)->heuristic_type()); 1230 EXPECT_EQ(COMPANY_NAME, form_structure->field(2)->heuristic_type());
1272 EXPECT_EQ(ADDRESS_HOME_LINE1, form_structure->field(3)->heuristic_type()); 1231 EXPECT_EQ(ADDRESS_HOME_LINE1, form_structure->field(3)->heuristic_type());
1273 EXPECT_EQ(ADDRESS_HOME_LINE2, form_structure->field(4)->heuristic_type()); 1232 EXPECT_EQ(ADDRESS_HOME_LINE2, form_structure->field(4)->heuristic_type());
1274 EXPECT_EQ(ADDRESS_HOME_CITY, form_structure->field(5)->heuristic_type()); 1233 EXPECT_EQ(ADDRESS_HOME_CITY, form_structure->field(5)->heuristic_type());
1275 EXPECT_EQ(ADDRESS_HOME_STATE, form_structure->field(6)->heuristic_type()); 1234 EXPECT_EQ(ADDRESS_HOME_STATE, form_structure->field(6)->heuristic_type());
1276 EXPECT_EQ(ADDRESS_HOME_COUNTRY, form_structure->field(7)->heuristic_type()); 1235 EXPECT_EQ(ADDRESS_HOME_COUNTRY, form_structure->field(7)->heuristic_type());
1277 EXPECT_EQ(ADDRESS_HOME_ZIP, form_structure->field(8)->heuristic_type()); 1236 EXPECT_EQ(ADDRESS_HOME_ZIP, form_structure->field(8)->heuristic_type());
1278 EXPECT_EQ(PHONE_HOME_WHOLE_NUMBER, 1237 EXPECT_EQ(PHONE_HOME_WHOLE_NUMBER,
1279 form_structure->field(9)->heuristic_type()); 1238 form_structure->field(9)->heuristic_type());
1280 EXPECT_EQ(EMAIL_ADDRESS, form_structure->field(10)->heuristic_type()); 1239 EXPECT_EQ(EMAIL_ADDRESS, form_structure->field(10)->heuristic_type());
1281 } 1240 }
1282 1241
1283 TEST(FormStructureTest, ThreePartPhoneNumber) { 1242 TEST(FormStructureTest, ThreePartPhoneNumber) {
1284 scoped_ptr<FormStructure> form_structure; 1243 scoped_ptr<FormStructure> form_structure;
1285 FormData form; 1244 FormData form;
1286 form.method = ASCIIToUTF16("post");
1287 1245
1288 FormFieldData field; 1246 FormFieldData field;
1289 field.form_control_type = "text"; 1247 field.form_control_type = "text";
1290 1248
1291 field.label = ASCIIToUTF16("Phone:"); 1249 field.label = ASCIIToUTF16("Phone:");
1292 field.name = ASCIIToUTF16("dayphone1"); 1250 field.name = ASCIIToUTF16("dayphone1");
1293 field.max_length = 0; 1251 field.max_length = 0;
1294 form.fields.push_back(field); 1252 form.fields.push_back(field);
1295 1253
1296 field.label = ASCIIToUTF16("-"); 1254 field.label = ASCIIToUTF16("-");
1297 field.name = ASCIIToUTF16("dayphone2"); 1255 field.name = ASCIIToUTF16("dayphone2");
1298 field.max_length = 3; // Size of prefix is 3. 1256 field.max_length = 3; // Size of prefix is 3.
1299 form.fields.push_back(field); 1257 form.fields.push_back(field);
1300 1258
1301 field.label = ASCIIToUTF16("-"); 1259 field.label = ASCIIToUTF16("-");
1302 field.name = ASCIIToUTF16("dayphone3"); 1260 field.name = ASCIIToUTF16("dayphone3");
1303 field.max_length = 4; // Size of suffix is 4. If unlimited size is 1261 field.max_length = 4; // Size of suffix is 4. If unlimited size is
1304 // passed, phone will be parsed as 1262 // passed, phone will be parsed as
1305 // <country code> - <area code> - <phone>. 1263 // <country code> - <area code> - <phone>.
1306 form.fields.push_back(field); 1264 form.fields.push_back(field);
1307 1265
1308 field.label = ASCIIToUTF16("ext.:"); 1266 field.label = ASCIIToUTF16("ext.:");
1309 field.name = ASCIIToUTF16("dayphone4"); 1267 field.name = ASCIIToUTF16("dayphone4");
1310 field.max_length = 0; 1268 field.max_length = 0;
1311 form.fields.push_back(field); 1269 form.fields.push_back(field);
1312 1270
1313 form_structure.reset(new FormStructure(form)); 1271 form_structure.reset(new FormStructure(form));
1314 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); 1272 form_structure->DetermineHeuristicTypes(TestAutofillMetrics());
1315 EXPECT_TRUE(form_structure->IsAutofillable(true)); 1273 EXPECT_TRUE(form_structure->IsAutofillable());
1316 ASSERT_EQ(4U, form_structure->field_count()); 1274 ASSERT_EQ(4U, form_structure->field_count());
1317 ASSERT_EQ(3U, form_structure->autofill_count()); 1275 ASSERT_EQ(3U, form_structure->autofill_count());
1318 1276
1319 // Area code. 1277 // Area code.
1320 EXPECT_EQ(PHONE_HOME_CITY_CODE, form_structure->field(0)->heuristic_type()); 1278 EXPECT_EQ(PHONE_HOME_CITY_CODE, form_structure->field(0)->heuristic_type());
1321 // Phone number suffix. 1279 // Phone number suffix.
1322 EXPECT_EQ(PHONE_HOME_NUMBER, 1280 EXPECT_EQ(PHONE_HOME_NUMBER,
1323 form_structure->field(1)->heuristic_type()); 1281 form_structure->field(1)->heuristic_type());
1324 // Phone number suffix. 1282 // Phone number suffix.
1325 EXPECT_EQ(PHONE_HOME_NUMBER, 1283 EXPECT_EQ(PHONE_HOME_NUMBER,
1326 form_structure->field(2)->heuristic_type()); 1284 form_structure->field(2)->heuristic_type());
1327 // Unknown. 1285 // Unknown.
1328 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(3)->heuristic_type()); 1286 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(3)->heuristic_type());
1329 } 1287 }
1330 1288
1331 TEST(FormStructureTest, HeuristicsInfernoCC) { 1289 TEST(FormStructureTest, HeuristicsInfernoCC) {
1332 scoped_ptr<FormStructure> form_structure; 1290 scoped_ptr<FormStructure> form_structure;
1333 FormData form; 1291 FormData form;
1334 form.method = ASCIIToUTF16("post");
1335 1292
1336 FormFieldData field; 1293 FormFieldData field;
1337 field.form_control_type = "text"; 1294 field.form_control_type = "text";
1338 1295
1339 field.label = ASCIIToUTF16("Name on Card"); 1296 field.label = ASCIIToUTF16("Name on Card");
1340 field.name = ASCIIToUTF16("name_on_card"); 1297 field.name = ASCIIToUTF16("name_on_card");
1341 form.fields.push_back(field); 1298 form.fields.push_back(field);
1342 1299
1343 field.label = ASCIIToUTF16("Address"); 1300 field.label = ASCIIToUTF16("Address");
1344 field.name = ASCIIToUTF16("billing_address"); 1301 field.name = ASCIIToUTF16("billing_address");
1345 form.fields.push_back(field); 1302 form.fields.push_back(field);
1346 1303
1347 field.label = ASCIIToUTF16("Card Number"); 1304 field.label = ASCIIToUTF16("Card Number");
1348 field.name = ASCIIToUTF16("card_number"); 1305 field.name = ASCIIToUTF16("card_number");
1349 form.fields.push_back(field); 1306 form.fields.push_back(field);
1350 1307
1351 field.label = ASCIIToUTF16("Expiration Date"); 1308 field.label = ASCIIToUTF16("Expiration Date");
1352 field.name = ASCIIToUTF16("expiration_month"); 1309 field.name = ASCIIToUTF16("expiration_month");
1353 form.fields.push_back(field); 1310 form.fields.push_back(field);
1354 1311
1355 field.label = ASCIIToUTF16("Expiration Year"); 1312 field.label = ASCIIToUTF16("Expiration Year");
1356 field.name = ASCIIToUTF16("expiration_year"); 1313 field.name = ASCIIToUTF16("expiration_year");
1357 form.fields.push_back(field); 1314 form.fields.push_back(field);
1358 1315
1359 form_structure.reset(new FormStructure(form)); 1316 form_structure.reset(new FormStructure(form));
1360 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); 1317 form_structure->DetermineHeuristicTypes(TestAutofillMetrics());
1361 EXPECT_TRUE(form_structure->IsAutofillable(true)); 1318 EXPECT_TRUE(form_structure->IsAutofillable());
1362 1319
1363 // Expect the correct number of fields. 1320 // Expect the correct number of fields.
1364 ASSERT_EQ(5U, form_structure->field_count()); 1321 ASSERT_EQ(5U, form_structure->field_count());
1365 EXPECT_EQ(5U, form_structure->autofill_count()); 1322 EXPECT_EQ(5U, form_structure->autofill_count());
1366 1323
1367 // Name on Card. 1324 // Name on Card.
1368 EXPECT_EQ(CREDIT_CARD_NAME, form_structure->field(0)->heuristic_type()); 1325 EXPECT_EQ(CREDIT_CARD_NAME, form_structure->field(0)->heuristic_type());
1369 // Address. 1326 // Address.
1370 EXPECT_EQ(ADDRESS_HOME_LINE1, form_structure->field(1)->heuristic_type()); 1327 EXPECT_EQ(ADDRESS_HOME_LINE1, form_structure->field(1)->heuristic_type());
1371 // Card Number. 1328 // Card Number.
1372 EXPECT_EQ(CREDIT_CARD_NUMBER, form_structure->field(2)->heuristic_type()); 1329 EXPECT_EQ(CREDIT_CARD_NUMBER, form_structure->field(2)->heuristic_type());
1373 // Expiration Date. 1330 // Expiration Date.
1374 EXPECT_EQ(CREDIT_CARD_EXP_MONTH, form_structure->field(3)->heuristic_type()); 1331 EXPECT_EQ(CREDIT_CARD_EXP_MONTH, form_structure->field(3)->heuristic_type());
1375 // Expiration Year. 1332 // Expiration Year.
1376 EXPECT_EQ(CREDIT_CARD_EXP_4_DIGIT_YEAR, 1333 EXPECT_EQ(CREDIT_CARD_EXP_4_DIGIT_YEAR,
1377 form_structure->field(4)->heuristic_type()); 1334 form_structure->field(4)->heuristic_type());
1378 } 1335 }
1379 1336
1380 TEST(FormStructureTest, CVCCodeClash) { 1337 TEST(FormStructureTest, CVCCodeClash) {
1381 scoped_ptr<FormStructure> form_structure; 1338 scoped_ptr<FormStructure> form_structure;
1382 FormData form; 1339 FormData form;
1383 form.method = ASCIIToUTF16("post");
1384 1340
1385 FormFieldData field; 1341 FormFieldData field;
1386 field.form_control_type = "text"; 1342 field.form_control_type = "text";
1387 1343
1388 field.label = ASCIIToUTF16("Card number"); 1344 field.label = ASCIIToUTF16("Card number");
1389 field.name = ASCIIToUTF16("ccnumber"); 1345 field.name = ASCIIToUTF16("ccnumber");
1390 form.fields.push_back(field); 1346 form.fields.push_back(field);
1391 1347
1392 field.label = ASCIIToUTF16("First name"); 1348 field.label = ASCIIToUTF16("First name");
1393 field.name = ASCIIToUTF16("first_name"); 1349 field.name = ASCIIToUTF16("first_name");
(...skipping 10 matching lines...) Expand all
1404 field.label = base::string16(); 1360 field.label = base::string16();
1405 field.name = ASCIIToUTF16("ccexpiresyear"); 1361 field.name = ASCIIToUTF16("ccexpiresyear");
1406 form.fields.push_back(field); 1362 form.fields.push_back(field);
1407 1363
1408 field.label = ASCIIToUTF16("cvc number"); 1364 field.label = ASCIIToUTF16("cvc number");
1409 field.name = ASCIIToUTF16("csc"); 1365 field.name = ASCIIToUTF16("csc");
1410 form.fields.push_back(field); 1366 form.fields.push_back(field);
1411 1367
1412 form_structure.reset(new FormStructure(form)); 1368 form_structure.reset(new FormStructure(form));
1413 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); 1369 form_structure->DetermineHeuristicTypes(TestAutofillMetrics());
1414 EXPECT_TRUE(form_structure->IsAutofillable(true)); 1370 EXPECT_TRUE(form_structure->IsAutofillable());
1415 1371
1416 // Expect the correct number of fields. 1372 // Expect the correct number of fields.
1417 ASSERT_EQ(6U, form_structure->field_count()); 1373 ASSERT_EQ(6U, form_structure->field_count());
1418 ASSERT_EQ(5U, form_structure->autofill_count()); 1374 ASSERT_EQ(5U, form_structure->autofill_count());
1419 1375
1420 // Card Number. 1376 // Card Number.
1421 EXPECT_EQ(CREDIT_CARD_NUMBER, form_structure->field(0)->heuristic_type()); 1377 EXPECT_EQ(CREDIT_CARD_NUMBER, form_structure->field(0)->heuristic_type());
1422 // First name, taken as name on card. 1378 // First name, taken as name on card.
1423 EXPECT_EQ(CREDIT_CARD_NAME, form_structure->field(1)->heuristic_type()); 1379 EXPECT_EQ(CREDIT_CARD_NAME, form_structure->field(1)->heuristic_type());
1424 // Last name is not merged. 1380 // Last name is not merged.
1425 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(2)->heuristic_type()); 1381 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(2)->heuristic_type());
1426 // Expiration Date. 1382 // Expiration Date.
1427 EXPECT_EQ(CREDIT_CARD_EXP_MONTH, form_structure->field(3)->heuristic_type()); 1383 EXPECT_EQ(CREDIT_CARD_EXP_MONTH, form_structure->field(3)->heuristic_type());
1428 // Expiration Year. 1384 // Expiration Year.
1429 EXPECT_EQ(CREDIT_CARD_EXP_4_DIGIT_YEAR, 1385 EXPECT_EQ(CREDIT_CARD_EXP_4_DIGIT_YEAR,
1430 form_structure->field(4)->heuristic_type()); 1386 form_structure->field(4)->heuristic_type());
1431 // CVC code. 1387 // CVC code.
1432 EXPECT_EQ(CREDIT_CARD_VERIFICATION_CODE, 1388 EXPECT_EQ(CREDIT_CARD_VERIFICATION_CODE,
1433 form_structure->field(5)->heuristic_type()); 1389 form_structure->field(5)->heuristic_type());
1434 } 1390 }
1435 1391
1436 TEST(FormStructureTest, EncodeQueryRequest) { 1392 TEST(FormStructureTest, EncodeQueryRequest) {
1437 FormData form; 1393 FormData form;
1438 form.method = ASCIIToUTF16("post");
1439 1394
1440 FormFieldData field; 1395 FormFieldData field;
1441 field.form_control_type = "text"; 1396 field.form_control_type = "text";
1442 1397
1443 field.label = ASCIIToUTF16("Name on Card"); 1398 field.label = ASCIIToUTF16("Name on Card");
1444 field.name = ASCIIToUTF16("name_on_card"); 1399 field.name = ASCIIToUTF16("name_on_card");
1445 form.fields.push_back(field); 1400 form.fields.push_back(field);
1446 1401
1447 field.label = ASCIIToUTF16("Address"); 1402 field.label = ASCIIToUTF16("Address");
1448 field.name = ASCIIToUTF16("billing_address"); 1403 field.name = ASCIIToUTF16("billing_address");
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
1564 &encoded_signatures, 1519 &encoded_signatures,
1565 &encoded_xml)); 1520 &encoded_xml));
1566 EXPECT_EQ(0U, encoded_signatures.size()); 1521 EXPECT_EQ(0U, encoded_signatures.size());
1567 EXPECT_EQ("", encoded_xml); 1522 EXPECT_EQ("", encoded_xml);
1568 } 1523 }
1569 1524
1570 TEST(FormStructureTest, EncodeUploadRequest) { 1525 TEST(FormStructureTest, EncodeUploadRequest) {
1571 scoped_ptr<FormStructure> form_structure; 1526 scoped_ptr<FormStructure> form_structure;
1572 std::vector<ServerFieldTypeSet> possible_field_types; 1527 std::vector<ServerFieldTypeSet> possible_field_types;
1573 FormData form; 1528 FormData form;
1574 form.method = ASCIIToUTF16("post");
1575 form_structure.reset(new FormStructure(form)); 1529 form_structure.reset(new FormStructure(form));
1576 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); 1530 form_structure->DetermineHeuristicTypes(TestAutofillMetrics());
1577 1531
1578 FormFieldData field; 1532 FormFieldData field;
1579 field.form_control_type = "text"; 1533 field.form_control_type = "text";
1580 1534
1581 field.label = ASCIIToUTF16("First Name"); 1535 field.label = ASCIIToUTF16("First Name");
1582 field.name = ASCIIToUTF16("firstname"); 1536 field.name = ASCIIToUTF16("firstname");
1583 form.fields.push_back(field); 1537 form.fields.push_back(field);
1584 possible_field_types.push_back(ServerFieldTypeSet()); 1538 possible_field_types.push_back(ServerFieldTypeSet());
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
1722 for (size_t i = 0; i < form_structure->field_count(); ++i) 1676 for (size_t i = 0; i < form_structure->field_count(); ++i)
1723 form_structure->field(i)->set_possible_types(possible_field_types[i]); 1677 form_structure->field(i)->set_possible_types(possible_field_types[i]);
1724 EXPECT_FALSE(form_structure->EncodeUploadRequest(available_field_types, false, 1678 EXPECT_FALSE(form_structure->EncodeUploadRequest(available_field_types, false,
1725 &encoded_xml)); 1679 &encoded_xml));
1726 } 1680 }
1727 1681
1728 TEST(FormStructureTest, EncodeFieldAssignments) { 1682 TEST(FormStructureTest, EncodeFieldAssignments) {
1729 scoped_ptr<FormStructure> form_structure; 1683 scoped_ptr<FormStructure> form_structure;
1730 std::vector<ServerFieldTypeSet> possible_field_types; 1684 std::vector<ServerFieldTypeSet> possible_field_types;
1731 FormData form; 1685 FormData form;
1732 form.method = ASCIIToUTF16("post");
1733 form_structure.reset(new FormStructure(form)); 1686 form_structure.reset(new FormStructure(form));
1734 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); 1687 form_structure->DetermineHeuristicTypes(TestAutofillMetrics());
1735 1688
1736 FormFieldData field; 1689 FormFieldData field;
1737 field.form_control_type = "text"; 1690 field.form_control_type = "text";
1738 1691
1739 field.label = ASCIIToUTF16("First Name"); 1692 field.label = ASCIIToUTF16("First Name");
1740 field.name = ASCIIToUTF16("firstname"); 1693 field.name = ASCIIToUTF16("firstname");
1741 form.fields.push_back(field); 1694 form.fields.push_back(field);
1742 possible_field_types.push_back(ServerFieldTypeSet()); 1695 possible_field_types.push_back(ServerFieldTypeSet());
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
1848 "<fields fieldid=\"509334676\" fieldtype=\"37\" name=\"address\"/>" 1801 "<fields fieldid=\"509334676\" fieldtype=\"37\" name=\"address\"/>"
1849 "<fields fieldid=\"509334676\" fieldtype=\"38\" name=\"address\"/>" 1802 "<fields fieldid=\"509334676\" fieldtype=\"38\" name=\"address\"/>"
1850 "</fieldassignments>", 1803 "</fieldassignments>",
1851 encoded_xml); 1804 encoded_xml);
1852 } 1805 }
1853 1806
1854 // Check that we compute the "datapresent" string correctly for the given 1807 // Check that we compute the "datapresent" string correctly for the given
1855 // |available_types|. 1808 // |available_types|.
1856 TEST(FormStructureTest, CheckDataPresence) { 1809 TEST(FormStructureTest, CheckDataPresence) {
1857 FormData form; 1810 FormData form;
1858 form.method = ASCIIToUTF16("post");
1859 1811
1860 FormFieldData field; 1812 FormFieldData field;
1861 field.form_control_type = "text"; 1813 field.form_control_type = "text";
1862 1814
1863 field.label = ASCIIToUTF16("First Name"); 1815 field.label = ASCIIToUTF16("First Name");
1864 field.name = ASCIIToUTF16("first"); 1816 field.name = ASCIIToUTF16("first");
1865 form.fields.push_back(field); 1817 form.fields.push_back(field);
1866 1818
1867 field.label = ASCIIToUTF16("Last Name"); 1819 field.label = ASCIIToUTF16("Last Name");
1868 field.name = ASCIIToUTF16("last"); 1820 field.name = ASCIIToUTF16("last");
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
2102 available_field_types.insert(ADDRESS_HOME_LINE1); 2054 available_field_types.insert(ADDRESS_HOME_LINE1);
2103 available_field_types.insert(ADDRESS_HOME_LINE2); 2055 available_field_types.insert(ADDRESS_HOME_LINE2);
2104 available_field_types.insert(ADDRESS_HOME_CITY); 2056 available_field_types.insert(ADDRESS_HOME_CITY);
2105 available_field_types.insert(ADDRESS_HOME_STATE); 2057 available_field_types.insert(ADDRESS_HOME_STATE);
2106 available_field_types.insert(COMPANY_NAME); 2058 available_field_types.insert(COMPANY_NAME);
2107 2059
2108 // Check that multiple types for the field are processed correctly. 2060 // Check that multiple types for the field are processed correctly.
2109 scoped_ptr<FormStructure> form_structure; 2061 scoped_ptr<FormStructure> form_structure;
2110 std::vector<ServerFieldTypeSet> possible_field_types; 2062 std::vector<ServerFieldTypeSet> possible_field_types;
2111 FormData form; 2063 FormData form;
2112 form.method = ASCIIToUTF16("post");
2113 2064
2114 FormFieldData field; 2065 FormFieldData field;
2115 field.form_control_type = "text"; 2066 field.form_control_type = "text";
2116 2067
2117 field.label = ASCIIToUTF16("email"); 2068 field.label = ASCIIToUTF16("email");
2118 field.name = ASCIIToUTF16("email"); 2069 field.name = ASCIIToUTF16("email");
2119 form.fields.push_back(field); 2070 form.fields.push_back(field);
2120 possible_field_types.push_back(ServerFieldTypeSet()); 2071 possible_field_types.push_back(ServerFieldTypeSet());
2121 possible_field_types.back().insert(EMAIL_ADDRESS); 2072 possible_field_types.back().insert(EMAIL_ADDRESS);
2122 2073
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
2208 "<field signature=\"509334676\" autofilltype=\"30\"/>" 2159 "<field signature=\"509334676\" autofilltype=\"30\"/>"
2209 "<field signature=\"509334676\" autofilltype=\"60\"/>" 2160 "<field signature=\"509334676\" autofilltype=\"60\"/>"
2210 "</autofillupload>", 2161 "</autofillupload>",
2211 encoded_xml); 2162 encoded_xml);
2212 } 2163 }
2213 2164
2214 TEST(FormStructureTest, CheckFormSignature) { 2165 TEST(FormStructureTest, CheckFormSignature) {
2215 // Check that form signature is created correctly. 2166 // Check that form signature is created correctly.
2216 scoped_ptr<FormStructure> form_structure; 2167 scoped_ptr<FormStructure> form_structure;
2217 FormData form; 2168 FormData form;
2218 form.method = ASCIIToUTF16("post");
2219 2169
2220 FormFieldData field; 2170 FormFieldData field;
2221 field.form_control_type = "text"; 2171 field.form_control_type = "text";
2222 2172
2223 field.label = ASCIIToUTF16("email"); 2173 field.label = ASCIIToUTF16("email");
2224 field.name = ASCIIToUTF16("email"); 2174 field.name = ASCIIToUTF16("email");
2225 form.fields.push_back(field); 2175 form.fields.push_back(field);
2226 2176
2227 field.label = ASCIIToUTF16("First Name"); 2177 field.label = ASCIIToUTF16("First Name");
2228 field.name = ASCIIToUTF16("first"); 2178 field.name = ASCIIToUTF16("first");
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
2277 EXPECT_EQ(FormStructureTest::Hash64Bit( 2227 EXPECT_EQ(FormStructureTest::Hash64Bit(
2278 std::string("https://login.facebook.com&login_form&email&first&" 2228 std::string("https://login.facebook.com&login_form&email&first&"
2279 "random1234&random&1random&random")), 2229 "random1234&random&1random&random")),
2280 form_structure->FormSignature()); 2230 form_structure->FormSignature());
2281 2231
2282 } 2232 }
2283 2233
2284 TEST(FormStructureTest, ToFormData) { 2234 TEST(FormStructureTest, ToFormData) {
2285 FormData form; 2235 FormData form;
2286 form.name = ASCIIToUTF16("the-name"); 2236 form.name = ASCIIToUTF16("the-name");
2287 form.method = ASCIIToUTF16("POST");
2288 form.origin = GURL("http://cool.com"); 2237 form.origin = GURL("http://cool.com");
2289 form.action = form.origin.Resolve("/login"); 2238 form.action = form.origin.Resolve("/login");
2290 2239
2291 FormFieldData field; 2240 FormFieldData field;
2292 field.label = ASCIIToUTF16("username"); 2241 field.label = ASCIIToUTF16("username");
2293 field.name = ASCIIToUTF16("username"); 2242 field.name = ASCIIToUTF16("username");
2294 field.form_control_type = "text"; 2243 field.form_control_type = "text";
2295 form.fields.push_back(field); 2244 form.fields.push_back(field);
2296 2245
2297 field.label = ASCIIToUTF16("password"); 2246 field.label = ASCIIToUTF16("password");
(...skipping 10 matching lines...) Expand all
2308 2257
2309 // Currently |FormStructure(form_data)ToFormData().user_submitted| is always 2258 // Currently |FormStructure(form_data)ToFormData().user_submitted| is always
2310 // 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.
2311 form.user_submitted = true; 2260 form.user_submitted = true;
2312 EXPECT_NE(form, FormStructure(form).ToFormData()); 2261 EXPECT_NE(form, FormStructure(form).ToFormData());
2313 } 2262 }
2314 2263
2315 TEST(FormStructureTest, SkipFieldTest) { 2264 TEST(FormStructureTest, SkipFieldTest) {
2316 FormData form; 2265 FormData form;
2317 form.name = ASCIIToUTF16("the-name"); 2266 form.name = ASCIIToUTF16("the-name");
2318 form.method = ASCIIToUTF16("POST");
2319 form.origin = GURL("http://cool.com"); 2267 form.origin = GURL("http://cool.com");
2320 form.action = form.origin.Resolve("/login"); 2268 form.action = form.origin.Resolve("/login");
2321 2269
2322 FormFieldData field; 2270 FormFieldData field;
2323 field.label = ASCIIToUTF16("username"); 2271 field.label = ASCIIToUTF16("username");
2324 field.name = ASCIIToUTF16("username"); 2272 field.name = ASCIIToUTF16("username");
2325 field.form_control_type = "text"; 2273 field.form_control_type = "text";
2326 form.fields.push_back(field); 2274 form.fields.push_back(field);
2327 2275
2328 field.label = ASCIIToUTF16("select"); 2276 field.label = ASCIIToUTF16("select");
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
2393 // A freeform input (<input>) allows any value (overriding other <select>s). 2341 // A freeform input (<input>) allows any value (overriding other <select>s).
2394 FormFieldData freeform_field; 2342 FormFieldData freeform_field;
2395 freeform_field.autocomplete_attribute = "billing country"; 2343 freeform_field.autocomplete_attribute = "billing country";
2396 form_data.fields.push_back(freeform_field); 2344 form_data.fields.push_back(freeform_field);
2397 FormStructure form_structure2(form_data); 2345 FormStructure form_structure2(form_data);
2398 form_structure2.ParseFieldTypesFromAutocompleteAttributes(&unused, &unused); 2346 form_structure2.ParseFieldTypesFromAutocompleteAttributes(&unused, &unused);
2399 EXPECT_EQ(0U, form_structure2.PossibleValues(ADDRESS_BILLING_COUNTRY).size()); 2347 EXPECT_EQ(0U, form_structure2.PossibleValues(ADDRESS_BILLING_COUNTRY).size());
2400 } 2348 }
2401 2349
2402 } // namespace autofill 2350 } // namespace autofill
OLDNEW
« no previous file with comments | « components/autofill/core/browser/form_structure.cc ('k') | components/autofill/core/common/autofill_data_validation.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698