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

Side by Side Diff: chrome/browser/autofill/form_structure_unittest.cc

Issue 11000016: Move forms/ out of webkit/. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Response to review Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/memory/scoped_ptr.h" 5 #include "base/memory/scoped_ptr.h"
6 #include "base/string_util.h" 6 #include "base/string_util.h"
7 #include "base/utf_string_conversions.h" 7 #include "base/utf_string_conversions.h"
8 #include "chrome/browser/autofill/form_structure.h" 8 #include "chrome/browser/autofill/form_structure.h"
9 #include "chrome/common/form_data.h"
10 #include "chrome/common/form_field_data.h"
9 #include "googleurl/src/gurl.h" 11 #include "googleurl/src/gurl.h"
10 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputElement.h" 13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputElement.h"
12 #include "webkit/forms/form_data.h"
13 #include "webkit/forms/form_field.h"
14 14
15 using webkit::forms::FormData;
16 using webkit::forms::FormField;
17 using WebKit::WebInputElement; 15 using WebKit::WebInputElement;
18 16
19 namespace webkit { 17 namespace content {
20 namespace forms {
21 18
22 std::ostream& operator<<(std::ostream& os, const FormData& form) { 19 std::ostream& operator<<(std::ostream& os, const FormData& form) {
23 os << UTF16ToUTF8(form.name) 20 os << UTF16ToUTF8(form.name)
24 << " " 21 << " "
25 << UTF16ToUTF8(form.method) 22 << UTF16ToUTF8(form.method)
26 << " " 23 << " "
27 << form.origin.spec() 24 << form.origin.spec()
28 << " " 25 << " "
29 << form.action.spec() 26 << form.action.spec()
30 << " "; 27 << " ";
31 28
32 for (std::vector<webkit::forms::FormField>::const_iterator iter = 29 for (std::vector<FormFieldData>::const_iterator iter =
33 form.fields.begin(); 30 form.fields.begin();
34 iter != form.fields.end(); ++iter) { 31 iter != form.fields.end(); ++iter) {
35 os << *iter 32 os << *iter
36 << " "; 33 << " ";
37 } 34 }
38 35
39 return os; 36 return os;
40 } 37 }
41 38
42 } // namespace forms 39 } // namespace content
43 } // namespace webkit_glue
44 40
45 class FormStructureTest { 41 class FormStructureTest {
46 public: 42 public:
47 static std::string Hash64Bit(const std::string& str) { 43 static std::string Hash64Bit(const std::string& str) {
48 return FormStructure::Hash64Bit(str); 44 return FormStructure::Hash64Bit(str);
49 } 45 }
50 }; 46 };
51 47
52 TEST(FormStructureTest, FieldCount) { 48 TEST(FormStructureTest, FieldCount) {
53 FormData form; 49 FormData form;
54 form.method = ASCIIToUTF16("post"); 50 form.method = ASCIIToUTF16("post");
55 51
56 FormField field; 52 FormFieldData field;
57 field.label = ASCIIToUTF16("username"); 53 field.label = ASCIIToUTF16("username");
58 field.name = ASCIIToUTF16("username"); 54 field.name = ASCIIToUTF16("username");
59 field.form_control_type = ASCIIToUTF16("text"); 55 field.form_control_type = ASCIIToUTF16("text");
60 form.fields.push_back(field); 56 form.fields.push_back(field);
61 57
62 field.label = ASCIIToUTF16("password"); 58 field.label = ASCIIToUTF16("password");
63 field.name = ASCIIToUTF16("password"); 59 field.name = ASCIIToUTF16("password");
64 field.form_control_type = ASCIIToUTF16("password"); 60 field.form_control_type = ASCIIToUTF16("password");
65 form.fields.push_back(field); 61 form.fields.push_back(field);
66 62
67 field.label = string16(); 63 field.label = string16();
68 field.name = ASCIIToUTF16("Submit"); 64 field.name = ASCIIToUTF16("Submit");
69 field.form_control_type = ASCIIToUTF16("submit"); 65 field.form_control_type = ASCIIToUTF16("submit");
70 form.fields.push_back(field); 66 form.fields.push_back(field);
71 67
72 FormStructure form_structure(form); 68 FormStructure form_structure(form);
73 69
74 // All fields are counted. 70 // All fields are counted.
75 EXPECT_EQ(3U, form_structure.field_count()); 71 EXPECT_EQ(3U, form_structure.field_count());
76 } 72 }
77 73
78 TEST(FormStructureTest, AutofillCount) { 74 TEST(FormStructureTest, AutofillCount) {
79 FormData form; 75 FormData form;
80 form.method = ASCIIToUTF16("post"); 76 form.method = ASCIIToUTF16("post");
81 77
82 FormField field; 78 FormFieldData field;
83 field.label = ASCIIToUTF16("username"); 79 field.label = ASCIIToUTF16("username");
84 field.name = ASCIIToUTF16("username"); 80 field.name = ASCIIToUTF16("username");
85 field.form_control_type = ASCIIToUTF16("text"); 81 field.form_control_type = ASCIIToUTF16("text");
86 form.fields.push_back(field); 82 form.fields.push_back(field);
87 83
88 field.label = ASCIIToUTF16("password"); 84 field.label = ASCIIToUTF16("password");
89 field.name = ASCIIToUTF16("password"); 85 field.name = ASCIIToUTF16("password");
90 field.form_control_type = ASCIIToUTF16("password"); 86 field.form_control_type = ASCIIToUTF16("password");
91 form.fields.push_back(field); 87 form.fields.push_back(field);
92 88
(...skipping 23 matching lines...) Expand all
116 EXPECT_EQ(form.origin, form_structure.source_url()); 112 EXPECT_EQ(form.origin, form_structure.source_url());
117 } 113 }
118 114
119 TEST(FormStructureTest, IsAutofillable) { 115 TEST(FormStructureTest, IsAutofillable) {
120 scoped_ptr<FormStructure> form_structure; 116 scoped_ptr<FormStructure> form_structure;
121 FormData form; 117 FormData form;
122 118
123 // We need at least three text fields to be auto-fillable. 119 // We need at least three text fields to be auto-fillable.
124 form.method = ASCIIToUTF16("post"); 120 form.method = ASCIIToUTF16("post");
125 121
126 FormField field; 122 FormFieldData field;
127 field.label = ASCIIToUTF16("username"); 123 field.label = ASCIIToUTF16("username");
128 field.name = ASCIIToUTF16("username"); 124 field.name = ASCIIToUTF16("username");
129 field.form_control_type = ASCIIToUTF16("text"); 125 field.form_control_type = ASCIIToUTF16("text");
130 form.fields.push_back(field); 126 form.fields.push_back(field);
131 127
132 field.label = ASCIIToUTF16("password"); 128 field.label = ASCIIToUTF16("password");
133 field.name = ASCIIToUTF16("password"); 129 field.name = ASCIIToUTF16("password");
134 field.form_control_type = ASCIIToUTF16("password"); 130 field.form_control_type = ASCIIToUTF16("password");
135 form.fields.push_back(field); 131 form.fields.push_back(field);
136 132
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 EXPECT_TRUE(form_structure->IsAutofillable(true)); 186 EXPECT_TRUE(form_structure->IsAutofillable(true));
191 } 187 }
192 188
193 TEST(FormStructureTest, ShouldBeParsed) { 189 TEST(FormStructureTest, ShouldBeParsed) {
194 scoped_ptr<FormStructure> form_structure; 190 scoped_ptr<FormStructure> form_structure;
195 FormData form; 191 FormData form;
196 192
197 // We need at least three text fields to be parseable. 193 // We need at least three text fields to be parseable.
198 form.method = ASCIIToUTF16("post"); 194 form.method = ASCIIToUTF16("post");
199 195
200 FormField field; 196 FormFieldData field;
201 field.label = ASCIIToUTF16("username"); 197 field.label = ASCIIToUTF16("username");
202 field.name = ASCIIToUTF16("username"); 198 field.name = ASCIIToUTF16("username");
203 field.form_control_type = ASCIIToUTF16("text"); 199 field.form_control_type = ASCIIToUTF16("text");
204 form.fields.push_back(field); 200 form.fields.push_back(field);
205 201
206 form_structure.reset(new FormStructure(form)); 202 form_structure.reset(new FormStructure(form));
207 EXPECT_FALSE(form_structure->ShouldBeParsed(true)); 203 EXPECT_FALSE(form_structure->ShouldBeParsed(true));
208 204
209 // We now have three text fields, though only two are auto-fillable. 205 // We now have three text fields, though only two are auto-fillable.
210 field.label = ASCIIToUTF16("First Name"); 206 field.label = ASCIIToUTF16("First Name");
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 form.fields[0].form_control_type = ASCIIToUTF16("select-one"); 259 form.fields[0].form_control_type = ASCIIToUTF16("select-one");
264 form_structure.reset(new FormStructure(form)); 260 form_structure.reset(new FormStructure(form));
265 EXPECT_FALSE(form_structure->ShouldBeParsed(true)); 261 EXPECT_FALSE(form_structure->ShouldBeParsed(true));
266 } 262 }
267 263
268 TEST(FormStructureTest, HeuristicsContactInfo) { 264 TEST(FormStructureTest, HeuristicsContactInfo) {
269 scoped_ptr<FormStructure> form_structure; 265 scoped_ptr<FormStructure> form_structure;
270 FormData form; 266 FormData form;
271 form.method = ASCIIToUTF16("post"); 267 form.method = ASCIIToUTF16("post");
272 268
273 FormField field; 269 FormFieldData field;
274 field.form_control_type = ASCIIToUTF16("text"); 270 field.form_control_type = ASCIIToUTF16("text");
275 271
276 field.label = ASCIIToUTF16("First Name"); 272 field.label = ASCIIToUTF16("First Name");
277 field.name = ASCIIToUTF16("firstname"); 273 field.name = ASCIIToUTF16("firstname");
278 form.fields.push_back(field); 274 form.fields.push_back(field);
279 275
280 field.label = ASCIIToUTF16("Last Name"); 276 field.label = ASCIIToUTF16("Last Name");
281 field.name = ASCIIToUTF16("lastname"); 277 field.name = ASCIIToUTF16("lastname");
282 form.fields.push_back(field); 278 form.fields.push_back(field);
283 279
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 // Submit. 328 // Submit.
333 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(7)->heuristic_type()); 329 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(7)->heuristic_type());
334 } 330 }
335 331
336 // Verify that we can correctly process the |autocompletetype| attribute. 332 // Verify that we can correctly process the |autocompletetype| attribute.
337 TEST(FormStructureTest, HeuristicsAutocompletetype) { 333 TEST(FormStructureTest, HeuristicsAutocompletetype) {
338 scoped_ptr<FormStructure> form_structure; 334 scoped_ptr<FormStructure> form_structure;
339 FormData form; 335 FormData form;
340 form.method = ASCIIToUTF16("post"); 336 form.method = ASCIIToUTF16("post");
341 337
342 FormField field; 338 FormFieldData field;
343 field.form_control_type = ASCIIToUTF16("text"); 339 field.form_control_type = ASCIIToUTF16("text");
344 340
345 field.label = string16(); 341 field.label = string16();
346 field.name = ASCIIToUTF16("field1"); 342 field.name = ASCIIToUTF16("field1");
347 field.autocomplete_type = ASCIIToUTF16("given-name"); 343 field.autocomplete_type = ASCIIToUTF16("given-name");
348 form.fields.push_back(field); 344 form.fields.push_back(field);
349 345
350 field.label = string16(); 346 field.label = string16();
351 field.name = ASCIIToUTF16("field2"); 347 field.name = ASCIIToUTF16("field2");
352 field.autocomplete_type = ASCIIToUTF16("surname"); 348 field.autocomplete_type = ASCIIToUTF16("surname");
(...skipping 17 matching lines...) Expand all
370 EXPECT_EQ(EMAIL_ADDRESS, form_structure->field(2)->heuristic_type()); 366 EXPECT_EQ(EMAIL_ADDRESS, form_structure->field(2)->heuristic_type());
371 } 367 }
372 368
373 // Verify that we can correctly process the |autocompletetype| attribute for 369 // Verify that we can correctly process the |autocompletetype| attribute for
374 // phone number types (especially phone prefixes and suffixes). 370 // phone number types (especially phone prefixes and suffixes).
375 TEST(FormStructureTest, HeuristicsAutocompletetypePhones) { 371 TEST(FormStructureTest, HeuristicsAutocompletetypePhones) {
376 scoped_ptr<FormStructure> form_structure; 372 scoped_ptr<FormStructure> form_structure;
377 FormData form; 373 FormData form;
378 form.method = ASCIIToUTF16("post"); 374 form.method = ASCIIToUTF16("post");
379 375
380 FormField field; 376 FormFieldData field;
381 field.form_control_type = ASCIIToUTF16("text"); 377 field.form_control_type = ASCIIToUTF16("text");
382 378
383 field.label = string16(); 379 field.label = string16();
384 field.name = ASCIIToUTF16("field1"); 380 field.name = ASCIIToUTF16("field1");
385 field.autocomplete_type = ASCIIToUTF16("phone-local"); 381 field.autocomplete_type = ASCIIToUTF16("phone-local");
386 form.fields.push_back(field); 382 form.fields.push_back(field);
387 383
388 field.label = string16(); 384 field.label = string16();
389 field.name = ASCIIToUTF16("field2"); 385 field.name = ASCIIToUTF16("field2");
390 field.autocomplete_type = ASCIIToUTF16("phone-local-prefix"); 386 field.autocomplete_type = ASCIIToUTF16("phone-local-prefix");
(...skipping 23 matching lines...) Expand all
414 } 410 }
415 411
416 // If at least one field includes the |autocompletetype| attribute, we should 412 // If at least one field includes the |autocompletetype| attribute, we should
417 // not try to apply any other heuristics. 413 // not try to apply any other heuristics.
418 TEST(FormStructureTest, AutocompletetypeOverridesOtherHeuristics) { 414 TEST(FormStructureTest, AutocompletetypeOverridesOtherHeuristics) {
419 scoped_ptr<FormStructure> form_structure; 415 scoped_ptr<FormStructure> form_structure;
420 FormData form; 416 FormData form;
421 form.method = ASCIIToUTF16("post"); 417 form.method = ASCIIToUTF16("post");
422 418
423 // Start with a regular contact form. 419 // Start with a regular contact form.
424 FormField field; 420 FormFieldData field;
425 field.form_control_type = ASCIIToUTF16("text"); 421 field.form_control_type = ASCIIToUTF16("text");
426 422
427 field.label = ASCIIToUTF16("First Name"); 423 field.label = ASCIIToUTF16("First Name");
428 field.name = ASCIIToUTF16("firstname"); 424 field.name = ASCIIToUTF16("firstname");
429 form.fields.push_back(field); 425 form.fields.push_back(field);
430 426
431 field.label = ASCIIToUTF16("Last Name"); 427 field.label = ASCIIToUTF16("Last Name");
432 field.name = ASCIIToUTF16("lastname"); 428 field.name = ASCIIToUTF16("lastname");
433 form.fields.push_back(field); 429 form.fields.push_back(field);
434 430
(...skipping 28 matching lines...) Expand all
463 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(2)->heuristic_type()); 459 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(2)->heuristic_type());
464 } 460 }
465 461
466 // Verify that we can correctly process sections listed in the |autocomplete| 462 // Verify that we can correctly process sections listed in the |autocomplete|
467 // attribute. 463 // attribute.
468 TEST(FormStructureTest, HeuristicsAutocompletetypeWithSections) { 464 TEST(FormStructureTest, HeuristicsAutocompletetypeWithSections) {
469 scoped_ptr<FormStructure> form_structure; 465 scoped_ptr<FormStructure> form_structure;
470 FormData form; 466 FormData form;
471 form.method = ASCIIToUTF16("post"); 467 form.method = ASCIIToUTF16("post");
472 468
473 FormField field; 469 FormFieldData field;
474 field.form_control_type = ASCIIToUTF16("text"); 470 field.form_control_type = ASCIIToUTF16("text");
475 471
476 // We expect "shipping" and "billing" to be the most common sections. 472 // We expect "shipping" and "billing" to be the most common sections.
477 field.label = string16(); 473 field.label = string16();
478 field.name = ASCIIToUTF16("field1"); 474 field.name = ASCIIToUTF16("field1");
479 field.autocomplete_type = ASCIIToUTF16("section-shipping given-name"); 475 field.autocomplete_type = ASCIIToUTF16("section-shipping given-name");
480 form.fields.push_back(field); 476 form.fields.push_back(field);
481 477
482 // Some field will have no section specified. These fall into the default 478 // Some field will have no section specified. These fall into the default
483 // section, with an empty name. 479 // section, with an empty name.
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
535 EXPECT_EQ(ASCIIToUTF16("shipping-cc"), form_structure->field(5)->section()); 531 EXPECT_EQ(ASCIIToUTF16("shipping-cc"), form_structure->field(5)->section());
536 } 532 }
537 533
538 // Verify that we can correctly process fallback types listed in the 534 // Verify that we can correctly process fallback types listed in the
539 // |autocompletetype| attribute. 535 // |autocompletetype| attribute.
540 TEST(FormStructureTest, HeuristicsAutocompletetypeWithFallbacks) { 536 TEST(FormStructureTest, HeuristicsAutocompletetypeWithFallbacks) {
541 scoped_ptr<FormStructure> form_structure; 537 scoped_ptr<FormStructure> form_structure;
542 FormData form; 538 FormData form;
543 form.method = ASCIIToUTF16("post"); 539 form.method = ASCIIToUTF16("post");
544 540
545 FormField field; 541 FormFieldData field;
546 field.form_control_type = ASCIIToUTF16("text"); 542 field.form_control_type = ASCIIToUTF16("text");
547 543
548 // Skip over any sections and "x"-prefixed types. 544 // Skip over any sections and "x"-prefixed types.
549 field.label = string16(); 545 field.label = string16();
550 field.name = ASCIIToUTF16("field1"); 546 field.name = ASCIIToUTF16("field1");
551 field.autocomplete_type = 547 field.autocomplete_type =
552 ASCIIToUTF16("section-full-name x-given-name-initial given-name"); 548 ASCIIToUTF16("section-full-name x-given-name-initial given-name");
553 form.fields.push_back(field); 549 form.fields.push_back(field);
554 550
555 // Stop processing once we see a known type. 551 // Stop processing once we see a known type.
(...skipping 27 matching lines...) Expand all
583 form_structure->field(2)->heuristic_type()); 579 form_structure->field(2)->heuristic_type());
584 EXPECT_EQ(ASCIIToUTF16("shipping-default"), 580 EXPECT_EQ(ASCIIToUTF16("shipping-default"),
585 form_structure->field(2)->section()); 581 form_structure->field(2)->section());
586 } 582 }
587 583
588 TEST(FormStructureTest, HeuristicsSample8) { 584 TEST(FormStructureTest, HeuristicsSample8) {
589 scoped_ptr<FormStructure> form_structure; 585 scoped_ptr<FormStructure> form_structure;
590 FormData form; 586 FormData form;
591 form.method = ASCIIToUTF16("post"); 587 form.method = ASCIIToUTF16("post");
592 588
593 FormField field; 589 FormFieldData field;
594 field.form_control_type = ASCIIToUTF16("text"); 590 field.form_control_type = ASCIIToUTF16("text");
595 591
596 field.label = ASCIIToUTF16("Your First Name:"); 592 field.label = ASCIIToUTF16("Your First Name:");
597 field.name = ASCIIToUTF16("bill.first"); 593 field.name = ASCIIToUTF16("bill.first");
598 form.fields.push_back(field); 594 form.fields.push_back(field);
599 595
600 field.label = ASCIIToUTF16("Your Last Name:"); 596 field.label = ASCIIToUTF16("Your Last Name:");
601 field.name = ASCIIToUTF16("bill.last"); 597 field.name = ASCIIToUTF16("bill.last");
602 form.fields.push_back(field); 598 form.fields.push_back(field);
603 599
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
662 form_structure->field(8)->heuristic_type()); 658 form_structure->field(8)->heuristic_type());
663 // Submit. 659 // Submit.
664 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(9)->heuristic_type()); 660 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(9)->heuristic_type());
665 } 661 }
666 662
667 TEST(FormStructureTest, HeuristicsSample6) { 663 TEST(FormStructureTest, HeuristicsSample6) {
668 scoped_ptr<FormStructure> form_structure; 664 scoped_ptr<FormStructure> form_structure;
669 FormData form; 665 FormData form;
670 form.method = ASCIIToUTF16("post"); 666 form.method = ASCIIToUTF16("post");
671 667
672 FormField field; 668 FormFieldData field;
673 field.form_control_type = ASCIIToUTF16("text"); 669 field.form_control_type = ASCIIToUTF16("text");
674 670
675 field.label = ASCIIToUTF16("E-mail address"); 671 field.label = ASCIIToUTF16("E-mail address");
676 field.name = ASCIIToUTF16("email"); 672 field.name = ASCIIToUTF16("email");
677 form.fields.push_back(field); 673 form.fields.push_back(field);
678 674
679 field.label = ASCIIToUTF16("Full name"); 675 field.label = ASCIIToUTF16("Full name");
680 field.name = ASCIIToUTF16("name"); 676 field.name = ASCIIToUTF16("name");
681 form.fields.push_back(field); 677 form.fields.push_back(field);
682 678
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
718 EXPECT_EQ(ADDRESS_HOME_LINE1, form_structure->field(3)->heuristic_type()); 714 EXPECT_EQ(ADDRESS_HOME_LINE1, form_structure->field(3)->heuristic_type());
719 // City. 715 // City.
720 EXPECT_EQ(ADDRESS_HOME_CITY, form_structure->field(4)->heuristic_type()); 716 EXPECT_EQ(ADDRESS_HOME_CITY, form_structure->field(4)->heuristic_type());
721 // Zip. 717 // Zip.
722 EXPECT_EQ(ADDRESS_HOME_ZIP, form_structure->field(5)->heuristic_type()); 718 EXPECT_EQ(ADDRESS_HOME_ZIP, form_structure->field(5)->heuristic_type());
723 // Submit. 719 // Submit.
724 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(6)->heuristic_type()); 720 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(6)->heuristic_type());
725 } 721 }
726 722
727 // Tests a sequence of FormFields where only labels are supplied to heuristics 723 // Tests a sequence of FormFields where only labels are supplied to heuristics
728 // for matching. This works because FormField labels are matched in the case 724 // for matching. This works because FormFieldData labels are matched in the
729 // that input element ids (or |name| fields) are missing. 725 // case that input element ids (or |name| fields) are missing.
730 TEST(FormStructureTest, HeuristicsLabelsOnly) { 726 TEST(FormStructureTest, HeuristicsLabelsOnly) {
731 scoped_ptr<FormStructure> form_structure; 727 scoped_ptr<FormStructure> form_structure;
732 FormData form; 728 FormData form;
733 form.method = ASCIIToUTF16("post"); 729 form.method = ASCIIToUTF16("post");
734 730
735 FormField field; 731 FormFieldData field;
736 field.form_control_type = ASCIIToUTF16("text"); 732 field.form_control_type = ASCIIToUTF16("text");
737 733
738 field.label = ASCIIToUTF16("First Name"); 734 field.label = ASCIIToUTF16("First Name");
739 field.name = string16(); 735 field.name = string16();
740 form.fields.push_back(field); 736 form.fields.push_back(field);
741 737
742 field.label = ASCIIToUTF16("Last Name"); 738 field.label = ASCIIToUTF16("Last Name");
743 field.name = string16(); 739 field.name = string16();
744 form.fields.push_back(field); 740 form.fields.push_back(field);
745 741
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
791 EXPECT_EQ(ADDRESS_HOME_ZIP, form_structure->field(6)->heuristic_type()); 787 EXPECT_EQ(ADDRESS_HOME_ZIP, form_structure->field(6)->heuristic_type());
792 // Submit. 788 // Submit.
793 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(7)->heuristic_type()); 789 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(7)->heuristic_type());
794 } 790 }
795 791
796 TEST(FormStructureTest, HeuristicsCreditCardInfo) { 792 TEST(FormStructureTest, HeuristicsCreditCardInfo) {
797 scoped_ptr<FormStructure> form_structure; 793 scoped_ptr<FormStructure> form_structure;
798 FormData form; 794 FormData form;
799 form.method = ASCIIToUTF16("post"); 795 form.method = ASCIIToUTF16("post");
800 796
801 FormField field; 797 FormFieldData field;
802 field.form_control_type = ASCIIToUTF16("text"); 798 field.form_control_type = ASCIIToUTF16("text");
803 799
804 field.label = ASCIIToUTF16("Name on Card"); 800 field.label = ASCIIToUTF16("Name on Card");
805 field.name = ASCIIToUTF16("name_on_card"); 801 field.name = ASCIIToUTF16("name_on_card");
806 form.fields.push_back(field); 802 form.fields.push_back(field);
807 803
808 field.label = ASCIIToUTF16("Card Number"); 804 field.label = ASCIIToUTF16("Card Number");
809 field.name = ASCIIToUTF16("card_number"); 805 field.name = ASCIIToUTF16("card_number");
810 form.fields.push_back(field); 806 form.fields.push_back(field);
811 807
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
845 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(4)->heuristic_type()); 841 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(4)->heuristic_type());
846 // Submit. 842 // Submit.
847 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(5)->heuristic_type()); 843 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(5)->heuristic_type());
848 } 844 }
849 845
850 TEST(FormStructureTest, HeuristicsCreditCardInfoWithUnknownCardField) { 846 TEST(FormStructureTest, HeuristicsCreditCardInfoWithUnknownCardField) {
851 scoped_ptr<FormStructure> form_structure; 847 scoped_ptr<FormStructure> form_structure;
852 FormData form; 848 FormData form;
853 form.method = ASCIIToUTF16("post"); 849 form.method = ASCIIToUTF16("post");
854 850
855 FormField field; 851 FormFieldData field;
856 field.form_control_type = ASCIIToUTF16("text"); 852 field.form_control_type = ASCIIToUTF16("text");
857 853
858 field.label = ASCIIToUTF16("Name on Card"); 854 field.label = ASCIIToUTF16("Name on Card");
859 field.name = ASCIIToUTF16("name_on_card"); 855 field.name = ASCIIToUTF16("name_on_card");
860 form.fields.push_back(field); 856 form.fields.push_back(field);
861 857
862 // This is not a field we know how to process. But we should skip over it 858 // This is not a field we know how to process. But we should skip over it
863 // and process the other fields in the card block. 859 // and process the other fields in the card block.
864 field.label = ASCIIToUTF16("Card Type"); 860 field.label = ASCIIToUTF16("Card Type");
865 field.name = ASCIIToUTF16("card_type"); 861 field.name = ASCIIToUTF16("card_type");
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
907 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(5)->heuristic_type()); 903 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(5)->heuristic_type());
908 // Submit. 904 // Submit.
909 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(6)->heuristic_type()); 905 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(6)->heuristic_type());
910 } 906 }
911 907
912 TEST(FormStructureTest, ThreeAddressLines) { 908 TEST(FormStructureTest, ThreeAddressLines) {
913 scoped_ptr<FormStructure> form_structure; 909 scoped_ptr<FormStructure> form_structure;
914 FormData form; 910 FormData form;
915 form.method = ASCIIToUTF16("post"); 911 form.method = ASCIIToUTF16("post");
916 912
917 FormField field; 913 FormFieldData field;
918 field.form_control_type = ASCIIToUTF16("text"); 914 field.form_control_type = ASCIIToUTF16("text");
919 915
920 field.label = ASCIIToUTF16("Address Line1"); 916 field.label = ASCIIToUTF16("Address Line1");
921 field.name = ASCIIToUTF16("Address"); 917 field.name = ASCIIToUTF16("Address");
922 form.fields.push_back(field); 918 form.fields.push_back(field);
923 919
924 field.label = ASCIIToUTF16("Address Line2"); 920 field.label = ASCIIToUTF16("Address Line2");
925 field.name = ASCIIToUTF16("Address"); 921 field.name = ASCIIToUTF16("Address");
926 form.fields.push_back(field); 922 form.fields.push_back(field);
927 923
(...skipping 21 matching lines...) Expand all
949 EXPECT_EQ(ADDRESS_HOME_CITY, form_structure->field(3)->heuristic_type()); 945 EXPECT_EQ(ADDRESS_HOME_CITY, form_structure->field(3)->heuristic_type());
950 } 946 }
951 947
952 // This test verifies that "addressLine1" and "addressLine2" matches heuristics. 948 // This test verifies that "addressLine1" and "addressLine2" matches heuristics.
953 // This occured in https://www.gorillaclothing.com/. http://crbug.com/52126. 949 // This occured in https://www.gorillaclothing.com/. http://crbug.com/52126.
954 TEST(FormStructureTest, BillingAndShippingAddresses) { 950 TEST(FormStructureTest, BillingAndShippingAddresses) {
955 scoped_ptr<FormStructure> form_structure; 951 scoped_ptr<FormStructure> form_structure;
956 FormData form; 952 FormData form;
957 form.method = ASCIIToUTF16("post"); 953 form.method = ASCIIToUTF16("post");
958 954
959 FormField field; 955 FormFieldData field;
960 field.form_control_type = ASCIIToUTF16("text"); 956 field.form_control_type = ASCIIToUTF16("text");
961 957
962 field.label = ASCIIToUTF16("Address Line1"); 958 field.label = ASCIIToUTF16("Address Line1");
963 field.name = ASCIIToUTF16("shipping.address.addressLine1"); 959 field.name = ASCIIToUTF16("shipping.address.addressLine1");
964 form.fields.push_back(field); 960 form.fields.push_back(field);
965 961
966 field.label = ASCIIToUTF16("Address Line2"); 962 field.label = ASCIIToUTF16("Address Line2");
967 field.name = ASCIIToUTF16("shipping.address.addressLine2"); 963 field.name = ASCIIToUTF16("shipping.address.addressLine2");
968 form.fields.push_back(field); 964 form.fields.push_back(field);
969 965
(...skipping 25 matching lines...) Expand all
995 // This example comes from expedia.com where they use a "Suite" label to 991 // This example comes from expedia.com where they use a "Suite" label to
996 // indicate a suite or apartment number. We interpret this as address line 2. 992 // indicate a suite or apartment number. We interpret this as address line 2.
997 // And the following "Street address second line" we interpret as address line 993 // And the following "Street address second line" we interpret as address line
998 // 3 and discard. 994 // 3 and discard.
999 // See http://crbug.com/48197 for details. 995 // See http://crbug.com/48197 for details.
1000 TEST(FormStructureTest, ThreeAddressLinesExpedia) { 996 TEST(FormStructureTest, ThreeAddressLinesExpedia) {
1001 scoped_ptr<FormStructure> form_structure; 997 scoped_ptr<FormStructure> form_structure;
1002 FormData form; 998 FormData form;
1003 form.method = ASCIIToUTF16("post"); 999 form.method = ASCIIToUTF16("post");
1004 1000
1005 FormField field; 1001 FormFieldData field;
1006 field.form_control_type = ASCIIToUTF16("text"); 1002 field.form_control_type = ASCIIToUTF16("text");
1007 1003
1008 field.label = ASCIIToUTF16("Street:"); 1004 field.label = ASCIIToUTF16("Street:");
1009 field.name = ASCIIToUTF16("FOPIH_RgWebCC_0_IHAddress_ads1"); 1005 field.name = ASCIIToUTF16("FOPIH_RgWebCC_0_IHAddress_ads1");
1010 form.fields.push_back(field); 1006 form.fields.push_back(field);
1011 1007
1012 field.label = ASCIIToUTF16("Suite or Apt:"); 1008 field.label = ASCIIToUTF16("Suite or Apt:");
1013 field.name = ASCIIToUTF16("FOPIH_RgWebCC_0_IHAddress_adap"); 1009 field.name = ASCIIToUTF16("FOPIH_RgWebCC_0_IHAddress_adap");
1014 form.fields.push_back(field); 1010 form.fields.push_back(field);
1015 1011
(...skipping 22 matching lines...) Expand all
1038 } 1034 }
1039 1035
1040 // This example comes from ebay.com where the word "suite" appears in the label 1036 // This example comes from ebay.com where the word "suite" appears in the label
1041 // and the name "address2" clearly indicates that this is the address line 2. 1037 // and the name "address2" clearly indicates that this is the address line 2.
1042 // See http://crbug.com/48197 for details. 1038 // See http://crbug.com/48197 for details.
1043 TEST(FormStructureTest, TwoAddressLinesEbay) { 1039 TEST(FormStructureTest, TwoAddressLinesEbay) {
1044 scoped_ptr<FormStructure> form_structure; 1040 scoped_ptr<FormStructure> form_structure;
1045 FormData form; 1041 FormData form;
1046 form.method = ASCIIToUTF16("post"); 1042 form.method = ASCIIToUTF16("post");
1047 1043
1048 FormField field; 1044 FormFieldData field;
1049 field.form_control_type = ASCIIToUTF16("text"); 1045 field.form_control_type = ASCIIToUTF16("text");
1050 1046
1051 field.label = ASCIIToUTF16("Address Line1"); 1047 field.label = ASCIIToUTF16("Address Line1");
1052 field.name = ASCIIToUTF16("address1"); 1048 field.name = ASCIIToUTF16("address1");
1053 form.fields.push_back(field); 1049 form.fields.push_back(field);
1054 1050
1055 field.label = ASCIIToUTF16("Floor number, suite number, etc"); 1051 field.label = ASCIIToUTF16("Floor number, suite number, etc");
1056 field.name = ASCIIToUTF16("address2"); 1052 field.name = ASCIIToUTF16("address2");
1057 form.fields.push_back(field); 1053 form.fields.push_back(field);
1058 1054
(...skipping 13 matching lines...) Expand all
1072 EXPECT_EQ(ADDRESS_HOME_LINE2, form_structure->field(1)->heuristic_type()); 1068 EXPECT_EQ(ADDRESS_HOME_LINE2, form_structure->field(1)->heuristic_type());
1073 // City. 1069 // City.
1074 EXPECT_EQ(ADDRESS_HOME_CITY, form_structure->field(2)->heuristic_type()); 1070 EXPECT_EQ(ADDRESS_HOME_CITY, form_structure->field(2)->heuristic_type());
1075 } 1071 }
1076 1072
1077 TEST(FormStructureTest, HeuristicsStateWithProvince) { 1073 TEST(FormStructureTest, HeuristicsStateWithProvince) {
1078 scoped_ptr<FormStructure> form_structure; 1074 scoped_ptr<FormStructure> form_structure;
1079 FormData form; 1075 FormData form;
1080 form.method = ASCIIToUTF16("post"); 1076 form.method = ASCIIToUTF16("post");
1081 1077
1082 FormField field; 1078 FormFieldData field;
1083 field.form_control_type = ASCIIToUTF16("text"); 1079 field.form_control_type = ASCIIToUTF16("text");
1084 1080
1085 field.label = ASCIIToUTF16("Address Line1"); 1081 field.label = ASCIIToUTF16("Address Line1");
1086 field.name = ASCIIToUTF16("Address"); 1082 field.name = ASCIIToUTF16("Address");
1087 form.fields.push_back(field); 1083 form.fields.push_back(field);
1088 1084
1089 field.label = ASCIIToUTF16("Address Line2"); 1085 field.label = ASCIIToUTF16("Address Line2");
1090 field.name = ASCIIToUTF16("Address"); 1086 field.name = ASCIIToUTF16("Address");
1091 form.fields.push_back(field); 1087 form.fields.push_back(field);
1092 1088
(...skipping 14 matching lines...) Expand all
1107 // State. 1103 // State.
1108 EXPECT_EQ(ADDRESS_HOME_STATE, form_structure->field(2)->heuristic_type()); 1104 EXPECT_EQ(ADDRESS_HOME_STATE, form_structure->field(2)->heuristic_type());
1109 } 1105 }
1110 1106
1111 // This example comes from lego.com's checkout page. 1107 // This example comes from lego.com's checkout page.
1112 TEST(FormStructureTest, HeuristicsWithBilling) { 1108 TEST(FormStructureTest, HeuristicsWithBilling) {
1113 scoped_ptr<FormStructure> form_structure; 1109 scoped_ptr<FormStructure> form_structure;
1114 FormData form; 1110 FormData form;
1115 form.method = ASCIIToUTF16("post"); 1111 form.method = ASCIIToUTF16("post");
1116 1112
1117 FormField field; 1113 FormFieldData field;
1118 field.form_control_type = ASCIIToUTF16("text"); 1114 field.form_control_type = ASCIIToUTF16("text");
1119 1115
1120 field.label = ASCIIToUTF16("First Name*:"); 1116 field.label = ASCIIToUTF16("First Name*:");
1121 field.name = ASCIIToUTF16("editBillingAddress$firstNameBox"); 1117 field.name = ASCIIToUTF16("editBillingAddress$firstNameBox");
1122 form.fields.push_back(field); 1118 form.fields.push_back(field);
1123 1119
1124 field.label = ASCIIToUTF16("Last Name*:"); 1120 field.label = ASCIIToUTF16("Last Name*:");
1125 field.name = ASCIIToUTF16("editBillingAddress$lastNameBox"); 1121 field.name = ASCIIToUTF16("editBillingAddress$lastNameBox");
1126 form.fields.push_back(field); 1122 form.fields.push_back(field);
1127 1123
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
1180 EXPECT_EQ(PHONE_HOME_WHOLE_NUMBER, 1176 EXPECT_EQ(PHONE_HOME_WHOLE_NUMBER,
1181 form_structure->field(9)->heuristic_type()); 1177 form_structure->field(9)->heuristic_type());
1182 EXPECT_EQ(EMAIL_ADDRESS, form_structure->field(10)->heuristic_type()); 1178 EXPECT_EQ(EMAIL_ADDRESS, form_structure->field(10)->heuristic_type());
1183 } 1179 }
1184 1180
1185 TEST(FormStructureTest, ThreePartPhoneNumber) { 1181 TEST(FormStructureTest, ThreePartPhoneNumber) {
1186 scoped_ptr<FormStructure> form_structure; 1182 scoped_ptr<FormStructure> form_structure;
1187 FormData form; 1183 FormData form;
1188 form.method = ASCIIToUTF16("post"); 1184 form.method = ASCIIToUTF16("post");
1189 1185
1190 FormField field; 1186 FormFieldData field;
1191 field.form_control_type = ASCIIToUTF16("text"); 1187 field.form_control_type = ASCIIToUTF16("text");
1192 1188
1193 field.label = ASCIIToUTF16("Phone:"); 1189 field.label = ASCIIToUTF16("Phone:");
1194 field.name = ASCIIToUTF16("dayphone1"); 1190 field.name = ASCIIToUTF16("dayphone1");
1195 field.max_length = 0; 1191 field.max_length = 0;
1196 form.fields.push_back(field); 1192 form.fields.push_back(field);
1197 1193
1198 field.label = ASCIIToUTF16("-"); 1194 field.label = ASCIIToUTF16("-");
1199 field.name = ASCIIToUTF16("dayphone2"); 1195 field.name = ASCIIToUTF16("dayphone2");
1200 field.max_length = 3; // Size of prefix is 3. 1196 field.max_length = 3; // Size of prefix is 3.
(...skipping 27 matching lines...) Expand all
1228 form_structure->field(2)->heuristic_type()); 1224 form_structure->field(2)->heuristic_type());
1229 // Unknown. 1225 // Unknown.
1230 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(3)->heuristic_type()); 1226 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(3)->heuristic_type());
1231 } 1227 }
1232 1228
1233 TEST(FormStructureTest, HeuristicsInfernoCC) { 1229 TEST(FormStructureTest, HeuristicsInfernoCC) {
1234 scoped_ptr<FormStructure> form_structure; 1230 scoped_ptr<FormStructure> form_structure;
1235 FormData form; 1231 FormData form;
1236 form.method = ASCIIToUTF16("post"); 1232 form.method = ASCIIToUTF16("post");
1237 1233
1238 FormField field; 1234 FormFieldData field;
1239 field.form_control_type = ASCIIToUTF16("text"); 1235 field.form_control_type = ASCIIToUTF16("text");
1240 1236
1241 field.label = ASCIIToUTF16("Name on Card"); 1237 field.label = ASCIIToUTF16("Name on Card");
1242 field.name = ASCIIToUTF16("name_on_card"); 1238 field.name = ASCIIToUTF16("name_on_card");
1243 form.fields.push_back(field); 1239 form.fields.push_back(field);
1244 1240
1245 field.label = ASCIIToUTF16("Address"); 1241 field.label = ASCIIToUTF16("Address");
1246 field.name = ASCIIToUTF16("billing_address"); 1242 field.name = ASCIIToUTF16("billing_address");
1247 form.fields.push_back(field); 1243 form.fields.push_back(field);
1248 1244
(...skipping 28 matching lines...) Expand all
1277 // Expiration Year. 1273 // Expiration Year.
1278 EXPECT_EQ(CREDIT_CARD_EXP_4_DIGIT_YEAR, 1274 EXPECT_EQ(CREDIT_CARD_EXP_4_DIGIT_YEAR,
1279 form_structure->field(4)->heuristic_type()); 1275 form_structure->field(4)->heuristic_type());
1280 } 1276 }
1281 1277
1282 TEST(FormStructureTest, CVCCodeClash) { 1278 TEST(FormStructureTest, CVCCodeClash) {
1283 scoped_ptr<FormStructure> form_structure; 1279 scoped_ptr<FormStructure> form_structure;
1284 FormData form; 1280 FormData form;
1285 form.method = ASCIIToUTF16("post"); 1281 form.method = ASCIIToUTF16("post");
1286 1282
1287 FormField field; 1283 FormFieldData field;
1288 field.form_control_type = ASCIIToUTF16("text"); 1284 field.form_control_type = ASCIIToUTF16("text");
1289 1285
1290 field.label = ASCIIToUTF16("Card number"); 1286 field.label = ASCIIToUTF16("Card number");
1291 field.name = ASCIIToUTF16("ccnumber"); 1287 field.name = ASCIIToUTF16("ccnumber");
1292 form.fields.push_back(field); 1288 form.fields.push_back(field);
1293 1289
1294 field.label = ASCIIToUTF16("First name"); 1290 field.label = ASCIIToUTF16("First name");
1295 field.name = ASCIIToUTF16("first_name"); 1291 field.name = ASCIIToUTF16("first_name");
1296 form.fields.push_back(field); 1292 form.fields.push_back(field);
1297 1293
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1331 EXPECT_EQ(CREDIT_CARD_EXP_4_DIGIT_YEAR, 1327 EXPECT_EQ(CREDIT_CARD_EXP_4_DIGIT_YEAR,
1332 form_structure->field(4)->heuristic_type()); 1328 form_structure->field(4)->heuristic_type());
1333 // CVC code should not match. 1329 // CVC code should not match.
1334 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(5)->heuristic_type()); 1330 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(5)->heuristic_type());
1335 } 1331 }
1336 1332
1337 TEST(FormStructureTest, EncodeQueryRequest) { 1333 TEST(FormStructureTest, EncodeQueryRequest) {
1338 FormData form; 1334 FormData form;
1339 form.method = ASCIIToUTF16("post"); 1335 form.method = ASCIIToUTF16("post");
1340 1336
1341 FormField field; 1337 FormFieldData field;
1342 field.form_control_type = ASCIIToUTF16("text"); 1338 field.form_control_type = ASCIIToUTF16("text");
1343 1339
1344 field.label = ASCIIToUTF16("Name on Card"); 1340 field.label = ASCIIToUTF16("Name on Card");
1345 field.name = ASCIIToUTF16("name_on_card"); 1341 field.name = ASCIIToUTF16("name_on_card");
1346 form.fields.push_back(field); 1342 form.fields.push_back(field);
1347 1343
1348 field.label = ASCIIToUTF16("Address"); 1344 field.label = ASCIIToUTF16("Address");
1349 field.name = ASCIIToUTF16("billing_address"); 1345 field.name = ASCIIToUTF16("billing_address");
1350 form.fields.push_back(field); 1346 form.fields.push_back(field);
1351 1347
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
1446 } 1442 }
1447 1443
1448 TEST(FormStructureTest, EncodeUploadRequest) { 1444 TEST(FormStructureTest, EncodeUploadRequest) {
1449 scoped_ptr<FormStructure> form_structure; 1445 scoped_ptr<FormStructure> form_structure;
1450 std::vector<FieldTypeSet> possible_field_types; 1446 std::vector<FieldTypeSet> possible_field_types;
1451 FormData form; 1447 FormData form;
1452 form.method = ASCIIToUTF16("post"); 1448 form.method = ASCIIToUTF16("post");
1453 form_structure.reset(new FormStructure(form)); 1449 form_structure.reset(new FormStructure(form));
1454 form_structure->DetermineHeuristicTypes(); 1450 form_structure->DetermineHeuristicTypes();
1455 1451
1456 FormField field; 1452 FormFieldData field;
1457 field.form_control_type = ASCIIToUTF16("text"); 1453 field.form_control_type = ASCIIToUTF16("text");
1458 1454
1459 field.label = ASCIIToUTF16("First Name"); 1455 field.label = ASCIIToUTF16("First Name");
1460 field.name = ASCIIToUTF16("firstname"); 1456 field.name = ASCIIToUTF16("firstname");
1461 form.fields.push_back(field); 1457 form.fields.push_back(field);
1462 possible_field_types.push_back(FieldTypeSet()); 1458 possible_field_types.push_back(FieldTypeSet());
1463 possible_field_types.back().insert(NAME_FIRST); 1459 possible_field_types.back().insert(NAME_FIRST);
1464 1460
1465 field.label = ASCIIToUTF16("Last Name"); 1461 field.label = ASCIIToUTF16("Last Name");
1466 field.name = ASCIIToUTF16("lastname"); 1462 field.name = ASCIIToUTF16("lastname");
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
1592 EXPECT_FALSE(form_structure->EncodeUploadRequest(available_field_types, false, 1588 EXPECT_FALSE(form_structure->EncodeUploadRequest(available_field_types, false,
1593 &encoded_xml)); 1589 &encoded_xml));
1594 } 1590 }
1595 1591
1596 // Check that we compute the "datapresent" string correctly for the given 1592 // Check that we compute the "datapresent" string correctly for the given
1597 // |available_types|. 1593 // |available_types|.
1598 TEST(FormStructureTest, CheckDataPresence) { 1594 TEST(FormStructureTest, CheckDataPresence) {
1599 FormData form; 1595 FormData form;
1600 form.method = ASCIIToUTF16("post"); 1596 form.method = ASCIIToUTF16("post");
1601 1597
1602 FormField field; 1598 FormFieldData field;
1603 field.form_control_type = ASCIIToUTF16("text"); 1599 field.form_control_type = ASCIIToUTF16("text");
1604 1600
1605 field.label = ASCIIToUTF16("First Name"); 1601 field.label = ASCIIToUTF16("First Name");
1606 field.name = ASCIIToUTF16("first"); 1602 field.name = ASCIIToUTF16("first");
1607 form.fields.push_back(field); 1603 form.fields.push_back(field);
1608 1604
1609 field.label = ASCIIToUTF16("Last Name"); 1605 field.label = ASCIIToUTF16("Last Name");
1610 field.name = ASCIIToUTF16("last"); 1606 field.name = ASCIIToUTF16("last");
1611 form.fields.push_back(field); 1607 form.fields.push_back(field);
1612 1608
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
1846 available_field_types.insert(ADDRESS_HOME_CITY); 1842 available_field_types.insert(ADDRESS_HOME_CITY);
1847 available_field_types.insert(ADDRESS_HOME_STATE); 1843 available_field_types.insert(ADDRESS_HOME_STATE);
1848 available_field_types.insert(COMPANY_NAME); 1844 available_field_types.insert(COMPANY_NAME);
1849 1845
1850 // Check that multiple types for the field are processed correctly. 1846 // Check that multiple types for the field are processed correctly.
1851 scoped_ptr<FormStructure> form_structure; 1847 scoped_ptr<FormStructure> form_structure;
1852 std::vector<FieldTypeSet> possible_field_types; 1848 std::vector<FieldTypeSet> possible_field_types;
1853 FormData form; 1849 FormData form;
1854 form.method = ASCIIToUTF16("post"); 1850 form.method = ASCIIToUTF16("post");
1855 1851
1856 FormField field; 1852 FormFieldData field;
1857 field.form_control_type = ASCIIToUTF16("text"); 1853 field.form_control_type = ASCIIToUTF16("text");
1858 1854
1859 field.label = ASCIIToUTF16("email"); 1855 field.label = ASCIIToUTF16("email");
1860 field.name = ASCIIToUTF16("email"); 1856 field.name = ASCIIToUTF16("email");
1861 form.fields.push_back(field); 1857 form.fields.push_back(field);
1862 possible_field_types.push_back(FieldTypeSet()); 1858 possible_field_types.push_back(FieldTypeSet());
1863 possible_field_types.back().insert(EMAIL_ADDRESS); 1859 possible_field_types.back().insert(EMAIL_ADDRESS);
1864 1860
1865 field.label = ASCIIToUTF16("First Name"); 1861 field.label = ASCIIToUTF16("First Name");
1866 field.name = ASCIIToUTF16("first"); 1862 field.name = ASCIIToUTF16("first");
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
1952 "</autofillupload>", 1948 "</autofillupload>",
1953 encoded_xml); 1949 encoded_xml);
1954 } 1950 }
1955 1951
1956 TEST(FormStructureTest, CheckFormSignature) { 1952 TEST(FormStructureTest, CheckFormSignature) {
1957 // Check that form signature is created correctly. 1953 // Check that form signature is created correctly.
1958 scoped_ptr<FormStructure> form_structure; 1954 scoped_ptr<FormStructure> form_structure;
1959 FormData form; 1955 FormData form;
1960 form.method = ASCIIToUTF16("post"); 1956 form.method = ASCIIToUTF16("post");
1961 1957
1962 FormField field; 1958 FormFieldData field;
1963 field.form_control_type = ASCIIToUTF16("text"); 1959 field.form_control_type = ASCIIToUTF16("text");
1964 1960
1965 field.label = ASCIIToUTF16("email"); 1961 field.label = ASCIIToUTF16("email");
1966 field.name = ASCIIToUTF16("email"); 1962 field.name = ASCIIToUTF16("email");
1967 form.fields.push_back(field); 1963 form.fields.push_back(field);
1968 1964
1969 field.label = ASCIIToUTF16("First Name"); 1965 field.label = ASCIIToUTF16("First Name");
1970 field.name = ASCIIToUTF16("first"); 1966 field.name = ASCIIToUTF16("first");
1971 form.fields.push_back(field); 1967 form.fields.push_back(field);
1972 1968
(...skipping 14 matching lines...) Expand all
1987 EXPECT_EQ(FormStructureTest::Hash64Bit( 1983 EXPECT_EQ(FormStructureTest::Hash64Bit(
1988 std::string("https://login.facebook.com&&email&first")), 1984 std::string("https://login.facebook.com&&email&first")),
1989 form_structure->FormSignature()); 1985 form_structure->FormSignature());
1990 1986
1991 form.name = ASCIIToUTF16("login_form"); 1987 form.name = ASCIIToUTF16("login_form");
1992 form_structure.reset(new FormStructure(form)); 1988 form_structure.reset(new FormStructure(form));
1993 EXPECT_EQ(FormStructureTest::Hash64Bit( 1989 EXPECT_EQ(FormStructureTest::Hash64Bit(
1994 std::string("https://login.facebook.com&login_form&email&first")), 1990 std::string("https://login.facebook.com&login_form&email&first")),
1995 form_structure->FormSignature()); 1991 form_structure->FormSignature());
1996 } 1992 }
OLDNEW
« no previous file with comments | « chrome/browser/autofill/form_structure.cc ('k') | chrome/browser/autofill/name_field_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698