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

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

Issue 1859453002: components/autofill: scoped_ptr -> unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Comments addressed Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/autofill/core/browser/form_structure.h" 5 #include "components/autofill/core/browser/form_structure.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <memory>
10
9 #include "base/command_line.h" 11 #include "base/command_line.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/metrics/field_trial.h" 12 #include "base/metrics/field_trial.h"
12 #include "base/strings/string_number_conversions.h" 13 #include "base/strings/string_number_conversions.h"
13 #include "base/strings/string_util.h" 14 #include "base/strings/string_util.h"
14 #include "base/strings/utf_string_conversions.h" 15 #include "base/strings/utf_string_conversions.h"
15 #include "components/autofill/core/browser/autofill_test_utils.h" 16 #include "components/autofill/core/browser/autofill_test_utils.h"
16 #include "components/autofill/core/common/autofill_switches.h" 17 #include "components/autofill/core/common/autofill_switches.h"
17 #include "components/autofill/core/common/form_data.h" 18 #include "components/autofill/core/common/form_data.h"
18 #include "components/autofill/core/common/form_field_data.h" 19 #include "components/autofill/core/common/form_field_data.h"
19 #include "components/variations/entropy_provider.h" 20 #include "components/variations/entropy_provider.h"
20 #include "testing/gtest/include/gtest/gtest.h" 21 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 private: 66 private:
66 void EnableAutofillMetadataFieldTrial() { 67 void EnableAutofillMetadataFieldTrial() {
67 field_trial_list_.reset(); 68 field_trial_list_.reset();
68 field_trial_list_.reset( 69 field_trial_list_.reset(
69 new base::FieldTrialList(new metrics::SHA1EntropyProvider("foo"))); 70 new base::FieldTrialList(new metrics::SHA1EntropyProvider("foo")));
70 field_trial_ = base::FieldTrialList::CreateFieldTrial( 71 field_trial_ = base::FieldTrialList::CreateFieldTrial(
71 "AutofillFieldMetadata", "Enabled"); 72 "AutofillFieldMetadata", "Enabled");
72 field_trial_->group(); 73 field_trial_->group();
73 } 74 }
74 75
75 scoped_ptr<base::FieldTrialList> field_trial_list_; 76 std::unique_ptr<base::FieldTrialList> field_trial_list_;
76 scoped_refptr<base::FieldTrial> field_trial_; 77 scoped_refptr<base::FieldTrial> field_trial_;
77 }; 78 };
78 79
79 TEST_F(FormStructureTest, FieldCount) { 80 TEST_F(FormStructureTest, FieldCount) {
80 scoped_ptr<FormStructure> form_structure; 81 std::unique_ptr<FormStructure> form_structure;
81 FormData form; 82 FormData form;
82 83
83 FormFieldData field; 84 FormFieldData field;
84 field.label = ASCIIToUTF16("username"); 85 field.label = ASCIIToUTF16("username");
85 field.name = ASCIIToUTF16("username"); 86 field.name = ASCIIToUTF16("username");
86 field.form_control_type = "text"; 87 field.form_control_type = "text";
87 form.fields.push_back(field); 88 form.fields.push_back(field);
88 89
89 field.label = ASCIIToUTF16("password"); 90 field.label = ASCIIToUTF16("password");
90 field.name = ASCIIToUTF16("password"); 91 field.name = ASCIIToUTF16("password");
(...skipping 11 matching lines...) Expand all
102 field.should_autocomplete = false; 103 field.should_autocomplete = false;
103 form.fields.push_back(field); 104 form.fields.push_back(field);
104 105
105 // The render process sends all fields to browser including fields with 106 // The render process sends all fields to browser including fields with
106 // autocomplete=off 107 // autocomplete=off
107 form_structure.reset(new FormStructure(form)); 108 form_structure.reset(new FormStructure(form));
108 EXPECT_EQ(4U, form_structure->field_count()); 109 EXPECT_EQ(4U, form_structure->field_count());
109 } 110 }
110 111
111 TEST_F(FormStructureTest, AutofillCount) { 112 TEST_F(FormStructureTest, AutofillCount) {
112 scoped_ptr<FormStructure> form_structure; 113 std::unique_ptr<FormStructure> form_structure;
113 FormData form; 114 FormData form;
114 115
115 FormFieldData field; 116 FormFieldData field;
116 field.label = ASCIIToUTF16("username"); 117 field.label = ASCIIToUTF16("username");
117 field.name = ASCIIToUTF16("username"); 118 field.name = ASCIIToUTF16("username");
118 field.form_control_type = "text"; 119 field.form_control_type = "text";
119 form.fields.push_back(field); 120 form.fields.push_back(field);
120 121
121 field.label = ASCIIToUTF16("password"); 122 field.label = ASCIIToUTF16("password");
122 field.name = ASCIIToUTF16("password"); 123 field.name = ASCIIToUTF16("password");
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 164
164 TEST_F(FormStructureTest, SourceURL) { 165 TEST_F(FormStructureTest, SourceURL) {
165 FormData form; 166 FormData form;
166 form.origin = GURL("http://www.foo.com/"); 167 form.origin = GURL("http://www.foo.com/");
167 FormStructure form_structure(form); 168 FormStructure form_structure(form);
168 169
169 EXPECT_EQ(form.origin, form_structure.source_url()); 170 EXPECT_EQ(form.origin, form_structure.source_url());
170 } 171 }
171 172
172 TEST_F(FormStructureTest, IsAutofillable) { 173 TEST_F(FormStructureTest, IsAutofillable) {
173 scoped_ptr<FormStructure> form_structure; 174 std::unique_ptr<FormStructure> form_structure;
174 FormData form; 175 FormData form;
175 176
176 // We need at least three text fields to be auto-fillable. 177 // We need at least three text fields to be auto-fillable.
177 FormFieldData field; 178 FormFieldData field;
178 179
179 field.label = ASCIIToUTF16("username"); 180 field.label = ASCIIToUTF16("username");
180 field.name = ASCIIToUTF16("username"); 181 field.name = ASCIIToUTF16("username");
181 field.form_control_type = "text"; 182 field.form_control_type = "text";
182 form.fields.push_back(field); 183 form.fields.push_back(field);
183 184
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 EXPECT_FALSE(form_structure->IsAutofillable()); 228 EXPECT_FALSE(form_structure->IsAutofillable());
228 229
229 // But search can be in the URL. 230 // But search can be in the URL.
230 form.action = GURL("http://search.com/?q=hello"); 231 form.action = GURL("http://search.com/?q=hello");
231 form_structure.reset(new FormStructure(form)); 232 form_structure.reset(new FormStructure(form));
232 form_structure->DetermineHeuristicTypes(); 233 form_structure->DetermineHeuristicTypes();
233 EXPECT_TRUE(form_structure->IsAutofillable()); 234 EXPECT_TRUE(form_structure->IsAutofillable());
234 } 235 }
235 236
236 TEST_F(FormStructureTest, ShouldBeParsed) { 237 TEST_F(FormStructureTest, ShouldBeParsed) {
237 scoped_ptr<FormStructure> form_structure; 238 std::unique_ptr<FormStructure> form_structure;
238 FormData form; 239 FormData form;
239 240
240 // We need at least three text fields to be parseable. 241 // We need at least three text fields to be parseable.
241 FormFieldData field; 242 FormFieldData field;
242 field.label = ASCIIToUTF16("username"); 243 field.label = ASCIIToUTF16("username");
243 field.name = ASCIIToUTF16("username"); 244 field.name = ASCIIToUTF16("username");
244 field.form_control_type = "text"; 245 field.form_control_type = "text";
245 form.fields.push_back(field); 246 form.fields.push_back(field);
246 247
247 FormFieldData checkable_field; 248 FormFieldData checkable_field;
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 field.name = ASCIIToUTF16("new_pw"); 329 field.name = ASCIIToUTF16("new_pw");
329 field.form_control_type = "password"; 330 field.form_control_type = "password";
330 form.fields.push_back(field); 331 form.fields.push_back(field);
331 form_structure.reset(new FormStructure(form)); 332 form_structure.reset(new FormStructure(form));
332 EXPECT_TRUE(form_structure->ShouldBeParsed()); 333 EXPECT_TRUE(form_structure->ShouldBeParsed());
333 } 334 }
334 335
335 // Tests that ShouldBeParsed returns true for a form containing less than three 336 // Tests that ShouldBeParsed returns true for a form containing less than three
336 // fields if at least one has an autocomplete attribute. 337 // fields if at least one has an autocomplete attribute.
337 TEST_F(FormStructureTest, ShouldBeParsed_TwoFields_HasAutocomplete) { 338 TEST_F(FormStructureTest, ShouldBeParsed_TwoFields_HasAutocomplete) {
338 scoped_ptr<FormStructure> form_structure; 339 std::unique_ptr<FormStructure> form_structure;
339 FormData form; 340 FormData form;
340 FormFieldData field; 341 FormFieldData field;
341 342
342 field.label = ASCIIToUTF16("Name"); 343 field.label = ASCIIToUTF16("Name");
343 field.name = ASCIIToUTF16("name"); 344 field.name = ASCIIToUTF16("name");
344 field.form_control_type = "name"; 345 field.form_control_type = "name";
345 field.autocomplete_attribute = "name"; 346 field.autocomplete_attribute = "name";
346 form.fields.push_back(field); 347 form.fields.push_back(field);
347 348
348 field.label = ASCIIToUTF16("Address"); 349 field.label = ASCIIToUTF16("Address");
349 field.name = ASCIIToUTF16("Address"); 350 field.name = ASCIIToUTF16("Address");
350 field.form_control_type = "select-one"; 351 field.form_control_type = "select-one";
351 field.autocomplete_attribute = ""; 352 field.autocomplete_attribute = "";
352 form.fields.push_back(field); 353 form.fields.push_back(field);
353 354
354 form_structure.reset(new FormStructure(form)); 355 form_structure.reset(new FormStructure(form));
355 form_structure->ParseFieldTypesFromAutocompleteAttributes(); 356 form_structure->ParseFieldTypesFromAutocompleteAttributes();
356 EXPECT_TRUE(form_structure->ShouldBeParsed()); 357 EXPECT_TRUE(form_structure->ShouldBeParsed());
357 } 358 }
358 359
359 TEST_F(FormStructureTest, HeuristicsContactInfo) { 360 TEST_F(FormStructureTest, HeuristicsContactInfo) {
360 scoped_ptr<FormStructure> form_structure; 361 std::unique_ptr<FormStructure> form_structure;
361 FormData form; 362 FormData form;
362 363
363 FormFieldData field; 364 FormFieldData field;
364 field.form_control_type = "text"; 365 field.form_control_type = "text";
365 366
366 field.label = ASCIIToUTF16("First Name"); 367 field.label = ASCIIToUTF16("First Name");
367 field.name = ASCIIToUTF16("firstname"); 368 field.name = ASCIIToUTF16("firstname");
368 form.fields.push_back(field); 369 form.fields.push_back(field);
369 370
370 field.label = ASCIIToUTF16("Last Name"); 371 field.label = ASCIIToUTF16("Last Name");
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 // City. 425 // City.
425 EXPECT_EQ(ADDRESS_HOME_CITY, form_structure->field(6)->heuristic_type()); 426 EXPECT_EQ(ADDRESS_HOME_CITY, form_structure->field(6)->heuristic_type());
426 // Zip. 427 // Zip.
427 EXPECT_EQ(ADDRESS_HOME_ZIP, form_structure->field(7)->heuristic_type()); 428 EXPECT_EQ(ADDRESS_HOME_ZIP, form_structure->field(7)->heuristic_type());
428 // Submit. 429 // Submit.
429 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(8)->heuristic_type()); 430 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(8)->heuristic_type());
430 } 431 }
431 432
432 // Verify that we can correctly process the |autocomplete| attribute. 433 // Verify that we can correctly process the |autocomplete| attribute.
433 TEST_F(FormStructureTest, HeuristicsAutocompleteAttribute) { 434 TEST_F(FormStructureTest, HeuristicsAutocompleteAttribute) {
434 scoped_ptr<FormStructure> form_structure; 435 std::unique_ptr<FormStructure> form_structure;
435 FormData form; 436 FormData form;
436 437
437 FormFieldData field; 438 FormFieldData field;
438 field.form_control_type = "text"; 439 field.form_control_type = "text";
439 440
440 field.label = base::string16(); 441 field.label = base::string16();
441 field.name = ASCIIToUTF16("field1"); 442 field.name = ASCIIToUTF16("field1");
442 field.autocomplete_attribute = "given-name"; 443 field.autocomplete_attribute = "given-name";
443 form.fields.push_back(field); 444 form.fields.push_back(field);
444 445
(...skipping 18 matching lines...) Expand all
463 EXPECT_EQ(HTML_TYPE_GIVEN_NAME, form_structure->field(0)->html_type()); 464 EXPECT_EQ(HTML_TYPE_GIVEN_NAME, form_structure->field(0)->html_type());
464 EXPECT_EQ(HTML_TYPE_FAMILY_NAME, form_structure->field(1)->html_type()); 465 EXPECT_EQ(HTML_TYPE_FAMILY_NAME, form_structure->field(1)->html_type());
465 EXPECT_EQ(HTML_TYPE_EMAIL, form_structure->field(2)->html_type()); 466 EXPECT_EQ(HTML_TYPE_EMAIL, form_structure->field(2)->html_type());
466 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(0)->heuristic_type()); 467 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(0)->heuristic_type());
467 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(1)->heuristic_type()); 468 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(1)->heuristic_type());
468 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(2)->heuristic_type()); 469 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(2)->heuristic_type());
469 } 470 }
470 471
471 // Verify that the heuristics are not run for non checkout formless forms. 472 // Verify that the heuristics are not run for non checkout formless forms.
472 TEST_F(FormStructureTest, Heuristics_FormlessNonCheckoutForm) { 473 TEST_F(FormStructureTest, Heuristics_FormlessNonCheckoutForm) {
473 scoped_ptr<FormStructure> form_structure; 474 std::unique_ptr<FormStructure> form_structure;
474 FormData form; 475 FormData form;
475 476
476 FormFieldData field; 477 FormFieldData field;
477 field.form_control_type = "text"; 478 field.form_control_type = "text";
478 479
479 field.label = ASCIIToUTF16("First Name:"); 480 field.label = ASCIIToUTF16("First Name:");
480 field.name = ASCIIToUTF16("firstname"); 481 field.name = ASCIIToUTF16("firstname");
481 field.autocomplete_attribute = "given-name"; 482 field.autocomplete_attribute = "given-name";
482 form.fields.push_back(field); 483 form.fields.push_back(field);
483 484
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
541 542
542 field.label = ASCIIToUTF16("Phone"); 543 field.label = ASCIIToUTF16("Phone");
543 field.name = ASCIIToUTF16("ctl01$ctl00$ShippingAddressCreditPhone$phone"); 544 field.name = ASCIIToUTF16("ctl01$ctl00$ShippingAddressCreditPhone$phone");
544 form.fields.push_back(field); 545 form.fields.push_back(field);
545 546
546 field.label = base::string16(); 547 field.label = base::string16();
547 field.name = ASCIIToUTF16("ctl01$ctl00$ShippingAddressCreditPhone$submit"); 548 field.name = ASCIIToUTF16("ctl01$ctl00$ShippingAddressCreditPhone$submit");
548 field.form_control_type = "submit"; 549 field.form_control_type = "submit";
549 form.fields.push_back(field); 550 form.fields.push_back(field);
550 551
551 scoped_ptr<FormStructure> form_structure(new FormStructure(form)); 552 std::unique_ptr<FormStructure> form_structure(new FormStructure(form));
552 form_structure->DetermineHeuristicTypes(); 553 form_structure->DetermineHeuristicTypes();
553 EXPECT_TRUE(form_structure->IsAutofillable()); 554 EXPECT_TRUE(form_structure->IsAutofillable());
554 555
555 // Expect the correct number of fields. 556 // Expect the correct number of fields.
556 ASSERT_EQ(5U, form_structure->field_count()); 557 ASSERT_EQ(5U, form_structure->field_count());
557 ASSERT_EQ(4U, form_structure->autofill_count()); 558 ASSERT_EQ(4U, form_structure->autofill_count());
558 559
559 // First name. 560 // First name.
560 EXPECT_EQ(NAME_FIRST, form_structure->field(0)->heuristic_type()); 561 EXPECT_EQ(NAME_FIRST, form_structure->field(0)->heuristic_type());
561 // Last name. 562 // Last name.
(...skipping 19 matching lines...) Expand all
581 form.fields.push_back(field); 582 form.fields.push_back(field);
582 583
583 field.label = ASCIIToUTF16("Address 2"); 584 field.label = ASCIIToUTF16("Address 2");
584 field.name = ASCIIToUTF16("address2"); 585 field.name = ASCIIToUTF16("address2");
585 form.fields.push_back(field); 586 form.fields.push_back(field);
586 587
587 field.label = ASCIIToUTF16("Address 3"); 588 field.label = ASCIIToUTF16("Address 3");
588 field.name = ASCIIToUTF16("address3"); 589 field.name = ASCIIToUTF16("address3");
589 form.fields.push_back(field); 590 form.fields.push_back(field);
590 591
591 scoped_ptr<FormStructure> form_structure(new FormStructure(form)); 592 std::unique_ptr<FormStructure> form_structure(new FormStructure(form));
592 form_structure->DetermineHeuristicTypes(); 593 form_structure->DetermineHeuristicTypes();
593 EXPECT_TRUE(form_structure->IsAutofillable()); 594 EXPECT_TRUE(form_structure->IsAutofillable());
594 595
595 // Expect the correct number of fields. 596 // Expect the correct number of fields.
596 ASSERT_EQ(3U, form_structure->field_count()); 597 ASSERT_EQ(3U, form_structure->field_count());
597 ASSERT_EQ(3U, form_structure->autofill_count()); 598 ASSERT_EQ(3U, form_structure->autofill_count());
598 599
599 // Address 1. 600 // Address 1.
600 EXPECT_EQ(ADDRESS_HOME_LINE1, form_structure->field(0)->heuristic_type()); 601 EXPECT_EQ(ADDRESS_HOME_LINE1, form_structure->field(0)->heuristic_type());
601 // Address 2. 602 // Address 2.
602 EXPECT_EQ(ADDRESS_HOME_LINE2, form_structure->field(1)->heuristic_type()); 603 EXPECT_EQ(ADDRESS_HOME_LINE2, form_structure->field(1)->heuristic_type());
603 // Address 3 604 // Address 3
604 EXPECT_EQ(ADDRESS_HOME_LINE3, form_structure->field(2)->heuristic_type()); 605 EXPECT_EQ(ADDRESS_HOME_LINE3, form_structure->field(2)->heuristic_type());
605 } 606 }
606 607
607 // Verify that we can correctly process the 'autocomplete' attribute for phone 608 // Verify that we can correctly process the 'autocomplete' attribute for phone
608 // number types (especially phone prefixes and suffixes). 609 // number types (especially phone prefixes and suffixes).
609 TEST_F(FormStructureTest, HeuristicsAutocompleteAttributePhoneTypes) { 610 TEST_F(FormStructureTest, HeuristicsAutocompleteAttributePhoneTypes) {
610 scoped_ptr<FormStructure> form_structure; 611 std::unique_ptr<FormStructure> form_structure;
611 FormData form; 612 FormData form;
612 613
613 FormFieldData field; 614 FormFieldData field;
614 field.form_control_type = "text"; 615 field.form_control_type = "text";
615 616
616 field.label = base::string16(); 617 field.label = base::string16();
617 field.name = ASCIIToUTF16("field1"); 618 field.name = ASCIIToUTF16("field1");
618 field.autocomplete_attribute = "tel-local"; 619 field.autocomplete_attribute = "tel-local";
619 form.fields.push_back(field); 620 form.fields.push_back(field);
620 621
(...skipping 22 matching lines...) Expand all
643 form_structure->field(1)->phone_part()); 644 form_structure->field(1)->phone_part());
644 EXPECT_EQ(HTML_TYPE_TEL_LOCAL_SUFFIX, form_structure->field(2)->html_type()); 645 EXPECT_EQ(HTML_TYPE_TEL_LOCAL_SUFFIX, form_structure->field(2)->html_type());
645 EXPECT_EQ(AutofillField::PHONE_SUFFIX, 646 EXPECT_EQ(AutofillField::PHONE_SUFFIX,
646 form_structure->field(2)->phone_part()); 647 form_structure->field(2)->phone_part());
647 } 648 }
648 649
649 // The heuristics and server predictions should run if there are more than two 650 // The heuristics and server predictions should run if there are more than two
650 // fillable fields. 651 // fillable fields.
651 TEST_F(FormStructureTest, 652 TEST_F(FormStructureTest,
652 HeuristicsAndServerPredictions_BigForm_NoAutocompleteAttribute) { 653 HeuristicsAndServerPredictions_BigForm_NoAutocompleteAttribute) {
653 scoped_ptr<FormStructure> form_structure; 654 std::unique_ptr<FormStructure> form_structure;
654 FormData form; 655 FormData form;
655 656
656 FormFieldData field; 657 FormFieldData field;
657 field.form_control_type = "text"; 658 field.form_control_type = "text";
658 659
659 field.label = ASCIIToUTF16("First Name"); 660 field.label = ASCIIToUTF16("First Name");
660 field.name = ASCIIToUTF16("firstname"); 661 field.name = ASCIIToUTF16("firstname");
661 form.fields.push_back(field); 662 form.fields.push_back(field);
662 663
663 field.label = ASCIIToUTF16("Last Name"); 664 field.label = ASCIIToUTF16("Last Name");
(...skipping 14 matching lines...) Expand all
678 679
679 EXPECT_EQ(NAME_FIRST, form_structure->field(0)->heuristic_type()); 680 EXPECT_EQ(NAME_FIRST, form_structure->field(0)->heuristic_type());
680 EXPECT_EQ(NAME_LAST, form_structure->field(1)->heuristic_type()); 681 EXPECT_EQ(NAME_LAST, form_structure->field(1)->heuristic_type());
681 EXPECT_EQ(EMAIL_ADDRESS, form_structure->field(2)->heuristic_type()); 682 EXPECT_EQ(EMAIL_ADDRESS, form_structure->field(2)->heuristic_type());
682 } 683 }
683 684
684 // The heuristics and server predictions should run even if a valid autocomplete 685 // The heuristics and server predictions should run even if a valid autocomplete
685 // attribute is present in the form (if it has more that two fillable fields). 686 // attribute is present in the form (if it has more that two fillable fields).
686 TEST_F(FormStructureTest, 687 TEST_F(FormStructureTest,
687 HeuristicsAndServerPredictions_ValidAutocompleteAttribute) { 688 HeuristicsAndServerPredictions_ValidAutocompleteAttribute) {
688 scoped_ptr<FormStructure> form_structure; 689 std::unique_ptr<FormStructure> form_structure;
689 FormData form; 690 FormData form;
690 691
691 FormFieldData field; 692 FormFieldData field;
692 field.form_control_type = "text"; 693 field.form_control_type = "text";
693 694
694 // Set a valid autocomplete attribute to the first field. 695 // Set a valid autocomplete attribute to the first field.
695 field.label = ASCIIToUTF16("First Name"); 696 field.label = ASCIIToUTF16("First Name");
696 field.name = ASCIIToUTF16("firstname"); 697 field.name = ASCIIToUTF16("firstname");
697 field.autocomplete_attribute = "given-name"; 698 field.autocomplete_attribute = "given-name";
698 form.fields.push_back(field); 699 form.fields.push_back(field);
(...skipping 18 matching lines...) Expand all
717 EXPECT_EQ(NAME_FIRST, form_structure->field(0)->heuristic_type()); 718 EXPECT_EQ(NAME_FIRST, form_structure->field(0)->heuristic_type());
718 EXPECT_EQ(NAME_LAST, form_structure->field(1)->heuristic_type()); 719 EXPECT_EQ(NAME_LAST, form_structure->field(1)->heuristic_type());
719 EXPECT_EQ(EMAIL_ADDRESS, form_structure->field(2)->heuristic_type()); 720 EXPECT_EQ(EMAIL_ADDRESS, form_structure->field(2)->heuristic_type());
720 } 721 }
721 722
722 // The heuristics and server predictions should run even if an unrecognized 723 // The heuristics and server predictions should run even if an unrecognized
723 // autocomplete attribute is present in the form (if it has more than two 724 // autocomplete attribute is present in the form (if it has more than two
724 // fillable fields). 725 // fillable fields).
725 TEST_F(FormStructureTest, 726 TEST_F(FormStructureTest,
726 HeuristicsAndServerPredictions_UnrecognizedAutocompleteAttribute) { 727 HeuristicsAndServerPredictions_UnrecognizedAutocompleteAttribute) {
727 scoped_ptr<FormStructure> form_structure; 728 std::unique_ptr<FormStructure> form_structure;
728 FormData form; 729 FormData form;
729 730
730 FormFieldData field; 731 FormFieldData field;
731 field.form_control_type = "text"; 732 field.form_control_type = "text";
732 733
733 // Set an unrecognized autocomplete attribute to the first field. 734 // Set an unrecognized autocomplete attribute to the first field.
734 field.label = ASCIIToUTF16("First Name"); 735 field.label = ASCIIToUTF16("First Name");
735 field.name = ASCIIToUTF16("firstname"); 736 field.name = ASCIIToUTF16("firstname");
736 field.autocomplete_attribute = "unrecognized"; 737 field.autocomplete_attribute = "unrecognized";
737 form.fields.push_back(field); 738 form.fields.push_back(field);
(...skipping 22 matching lines...) Expand all
760 EXPECT_EQ(NAME_FIRST, form_structure->field(0)->heuristic_type()); 761 EXPECT_EQ(NAME_FIRST, form_structure->field(0)->heuristic_type());
761 EXPECT_EQ(NAME_MIDDLE, form_structure->field(1)->heuristic_type()); 762 EXPECT_EQ(NAME_MIDDLE, form_structure->field(1)->heuristic_type());
762 EXPECT_EQ(NAME_LAST, form_structure->field(2)->heuristic_type()); 763 EXPECT_EQ(NAME_LAST, form_structure->field(2)->heuristic_type());
763 EXPECT_EQ(EMAIL_ADDRESS, form_structure->field(3)->heuristic_type()); 764 EXPECT_EQ(EMAIL_ADDRESS, form_structure->field(3)->heuristic_type());
764 } 765 }
765 766
766 // Tests the heuristics and server predictions are not run for forms with less 767 // Tests the heuristics and server predictions are not run for forms with less
767 // than 3 fields. 768 // than 3 fields.
768 TEST_F(FormStructureTest, 769 TEST_F(FormStructureTest,
769 HeuristicsAndServerPredictions_SmallForm_NoAutocompleteAttribute) { 770 HeuristicsAndServerPredictions_SmallForm_NoAutocompleteAttribute) {
770 scoped_ptr<FormStructure> form_structure; 771 std::unique_ptr<FormStructure> form_structure;
771 FormData form; 772 FormData form;
772 773
773 FormFieldData field; 774 FormFieldData field;
774 field.form_control_type = "text"; 775 field.form_control_type = "text";
775 776
776 field.label = ASCIIToUTF16("First Name"); 777 field.label = ASCIIToUTF16("First Name");
777 field.name = ASCIIToUTF16("firstname"); 778 field.name = ASCIIToUTF16("firstname");
778 form.fields.push_back(field); 779 form.fields.push_back(field);
779 780
780 field.label = ASCIIToUTF16("Last Name"); 781 field.label = ASCIIToUTF16("Last Name");
(...skipping 11 matching lines...) Expand all
792 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(0)->heuristic_type()); 793 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(0)->heuristic_type());
793 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(1)->heuristic_type()); 794 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(1)->heuristic_type());
794 EXPECT_EQ(NO_SERVER_DATA, form_structure->field(0)->server_type()); 795 EXPECT_EQ(NO_SERVER_DATA, form_structure->field(0)->server_type());
795 EXPECT_EQ(NO_SERVER_DATA, form_structure->field(1)->server_type()); 796 EXPECT_EQ(NO_SERVER_DATA, form_structure->field(1)->server_type());
796 } 797 }
797 798
798 // Tests the heuristics and server predictions are not run for forms with less 799 // Tests the heuristics and server predictions are not run for forms with less
799 // than 3 fields, even if an autocomplete attribute is specified. 800 // than 3 fields, even if an autocomplete attribute is specified.
800 TEST_F(FormStructureTest, 801 TEST_F(FormStructureTest,
801 HeuristicsAndServerPredictions_SmallForm_ValidAutocompleteAttribute) { 802 HeuristicsAndServerPredictions_SmallForm_ValidAutocompleteAttribute) {
802 scoped_ptr<FormStructure> form_structure; 803 std::unique_ptr<FormStructure> form_structure;
803 FormData form; 804 FormData form;
804 805
805 FormFieldData field; 806 FormFieldData field;
806 field.form_control_type = "text"; 807 field.form_control_type = "text";
807 808
808 // Set a valid autocompelete attribute to the first field. 809 // Set a valid autocompelete attribute to the first field.
809 field.label = ASCIIToUTF16("First Name"); 810 field.label = ASCIIToUTF16("First Name");
810 field.name = ASCIIToUTF16("firstname"); 811 field.name = ASCIIToUTF16("firstname");
811 field.autocomplete_attribute = "given-name"; 812 field.autocomplete_attribute = "given-name";
812 form.fields.push_back(field); 813 form.fields.push_back(field);
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
1031 // Normally, the two separate address fields would cause us to detect two 1032 // Normally, the two separate address fields would cause us to detect two
1032 // separate sections; but because there is an author-specified section in this 1033 // separate sections; but because there is an author-specified section in this
1033 // form, we do not apply these usual heuristics. 1034 // form, we do not apply these usual heuristics.
1034 EXPECT_EQ(ASCIIToUTF16("one"), form_structure.field(0)->name); 1035 EXPECT_EQ(ASCIIToUTF16("one"), form_structure.field(0)->name);
1035 EXPECT_EQ(ASCIIToUTF16("two"), form_structure.field(3)->name); 1036 EXPECT_EQ(ASCIIToUTF16("two"), form_structure.field(3)->name);
1036 EXPECT_EQ(form_structure.field(0)->section(), 1037 EXPECT_EQ(form_structure.field(0)->section(),
1037 form_structure.field(3)->section()); 1038 form_structure.field(3)->section());
1038 } 1039 }
1039 1040
1040 TEST_F(FormStructureTest, HeuristicsSample8) { 1041 TEST_F(FormStructureTest, HeuristicsSample8) {
1041 scoped_ptr<FormStructure> form_structure; 1042 std::unique_ptr<FormStructure> form_structure;
1042 FormData form; 1043 FormData form;
1043 1044
1044 FormFieldData field; 1045 FormFieldData field;
1045 field.form_control_type = "text"; 1046 field.form_control_type = "text";
1046 1047
1047 field.label = ASCIIToUTF16("Your First Name:"); 1048 field.label = ASCIIToUTF16("Your First Name:");
1048 field.name = ASCIIToUTF16("bill.first"); 1049 field.name = ASCIIToUTF16("bill.first");
1049 form.fields.push_back(field); 1050 form.fields.push_back(field);
1050 1051
1051 field.label = ASCIIToUTF16("Your Last Name:"); 1052 field.label = ASCIIToUTF16("Your Last Name:");
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
1108 // Country. 1109 // Country.
1109 EXPECT_EQ(ADDRESS_HOME_COUNTRY, form_structure->field(7)->heuristic_type()); 1110 EXPECT_EQ(ADDRESS_HOME_COUNTRY, form_structure->field(7)->heuristic_type());
1110 // Phone. 1111 // Phone.
1111 EXPECT_EQ(PHONE_HOME_WHOLE_NUMBER, 1112 EXPECT_EQ(PHONE_HOME_WHOLE_NUMBER,
1112 form_structure->field(8)->heuristic_type()); 1113 form_structure->field(8)->heuristic_type());
1113 // Submit. 1114 // Submit.
1114 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(9)->heuristic_type()); 1115 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(9)->heuristic_type());
1115 } 1116 }
1116 1117
1117 TEST_F(FormStructureTest, HeuristicsSample6) { 1118 TEST_F(FormStructureTest, HeuristicsSample6) {
1118 scoped_ptr<FormStructure> form_structure; 1119 std::unique_ptr<FormStructure> form_structure;
1119 FormData form; 1120 FormData form;
1120 1121
1121 FormFieldData field; 1122 FormFieldData field;
1122 field.form_control_type = "text"; 1123 field.form_control_type = "text";
1123 1124
1124 field.label = ASCIIToUTF16("E-mail address"); 1125 field.label = ASCIIToUTF16("E-mail address");
1125 field.name = ASCIIToUTF16("email"); 1126 field.name = ASCIIToUTF16("email");
1126 form.fields.push_back(field); 1127 form.fields.push_back(field);
1127 1128
1128 field.label = ASCIIToUTF16("Full name"); 1129 field.label = ASCIIToUTF16("Full name");
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1170 // Zip. 1171 // Zip.
1171 EXPECT_EQ(ADDRESS_HOME_ZIP, form_structure->field(5)->heuristic_type()); 1172 EXPECT_EQ(ADDRESS_HOME_ZIP, form_structure->field(5)->heuristic_type());
1172 // Submit. 1173 // Submit.
1173 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(6)->heuristic_type()); 1174 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(6)->heuristic_type());
1174 } 1175 }
1175 1176
1176 // Tests a sequence of FormFields where only labels are supplied to heuristics 1177 // Tests a sequence of FormFields where only labels are supplied to heuristics
1177 // for matching. This works because FormFieldData labels are matched in the 1178 // for matching. This works because FormFieldData labels are matched in the
1178 // case that input element ids (or |name| fields) are missing. 1179 // case that input element ids (or |name| fields) are missing.
1179 TEST_F(FormStructureTest, HeuristicsLabelsOnly) { 1180 TEST_F(FormStructureTest, HeuristicsLabelsOnly) {
1180 scoped_ptr<FormStructure> form_structure; 1181 std::unique_ptr<FormStructure> form_structure;
1181 FormData form; 1182 FormData form;
1182 1183
1183 FormFieldData field; 1184 FormFieldData field;
1184 field.form_control_type = "text"; 1185 field.form_control_type = "text";
1185 1186
1186 field.label = ASCIIToUTF16("First Name"); 1187 field.label = ASCIIToUTF16("First Name");
1187 field.name = base::string16(); 1188 field.name = base::string16();
1188 form.fields.push_back(field); 1189 form.fields.push_back(field);
1189 1190
1190 field.label = ASCIIToUTF16("Last Name"); 1191 field.label = ASCIIToUTF16("Last Name");
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1235 EXPECT_EQ(ADDRESS_HOME_LINE1, form_structure->field(4)->heuristic_type()); 1236 EXPECT_EQ(ADDRESS_HOME_LINE1, form_structure->field(4)->heuristic_type());
1236 // Address Line 2. 1237 // Address Line 2.
1237 EXPECT_EQ(ADDRESS_HOME_LINE2, form_structure->field(5)->heuristic_type()); 1238 EXPECT_EQ(ADDRESS_HOME_LINE2, form_structure->field(5)->heuristic_type());
1238 // Zip. 1239 // Zip.
1239 EXPECT_EQ(ADDRESS_HOME_ZIP, form_structure->field(6)->heuristic_type()); 1240 EXPECT_EQ(ADDRESS_HOME_ZIP, form_structure->field(6)->heuristic_type());
1240 // Submit. 1241 // Submit.
1241 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(7)->heuristic_type()); 1242 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(7)->heuristic_type());
1242 } 1243 }
1243 1244
1244 TEST_F(FormStructureTest, HeuristicsCreditCardInfo) { 1245 TEST_F(FormStructureTest, HeuristicsCreditCardInfo) {
1245 scoped_ptr<FormStructure> form_structure; 1246 std::unique_ptr<FormStructure> form_structure;
1246 FormData form; 1247 FormData form;
1247 1248
1248 FormFieldData field; 1249 FormFieldData field;
1249 field.form_control_type = "text"; 1250 field.form_control_type = "text";
1250 1251
1251 field.label = ASCIIToUTF16("Name on Card"); 1252 field.label = ASCIIToUTF16("Name on Card");
1252 field.name = ASCIIToUTF16("name_on_card"); 1253 field.name = ASCIIToUTF16("name_on_card");
1253 form.fields.push_back(field); 1254 form.fields.push_back(field);
1254 1255
1255 field.label = ASCIIToUTF16("Card Number"); 1256 field.label = ASCIIToUTF16("Card Number");
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1289 EXPECT_EQ(CREDIT_CARD_EXP_4_DIGIT_YEAR, 1290 EXPECT_EQ(CREDIT_CARD_EXP_4_DIGIT_YEAR,
1290 form_structure->field(3)->heuristic_type()); 1291 form_structure->field(3)->heuristic_type());
1291 // CVV. 1292 // CVV.
1292 EXPECT_EQ(CREDIT_CARD_VERIFICATION_CODE, 1293 EXPECT_EQ(CREDIT_CARD_VERIFICATION_CODE,
1293 form_structure->field(4)->heuristic_type()); 1294 form_structure->field(4)->heuristic_type());
1294 // Submit. 1295 // Submit.
1295 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(5)->heuristic_type()); 1296 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(5)->heuristic_type());
1296 } 1297 }
1297 1298
1298 TEST_F(FormStructureTest, HeuristicsCreditCardInfoWithUnknownCardField) { 1299 TEST_F(FormStructureTest, HeuristicsCreditCardInfoWithUnknownCardField) {
1299 scoped_ptr<FormStructure> form_structure; 1300 std::unique_ptr<FormStructure> form_structure;
1300 FormData form; 1301 FormData form;
1301 1302
1302 FormFieldData field; 1303 FormFieldData field;
1303 field.form_control_type = "text"; 1304 field.form_control_type = "text";
1304 1305
1305 field.label = ASCIIToUTF16("Name on Card"); 1306 field.label = ASCIIToUTF16("Name on Card");
1306 field.name = ASCIIToUTF16("name_on_card"); 1307 field.name = ASCIIToUTF16("name_on_card");
1307 form.fields.push_back(field); 1308 form.fields.push_back(field);
1308 1309
1309 // This is not a field we know how to process. But we should skip over it 1310 // This is not a field we know how to process. But we should skip over it
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1351 EXPECT_EQ(CREDIT_CARD_EXP_4_DIGIT_YEAR, 1352 EXPECT_EQ(CREDIT_CARD_EXP_4_DIGIT_YEAR,
1352 form_structure->field(4)->heuristic_type()); 1353 form_structure->field(4)->heuristic_type());
1353 // CVV. 1354 // CVV.
1354 EXPECT_EQ(CREDIT_CARD_VERIFICATION_CODE, 1355 EXPECT_EQ(CREDIT_CARD_VERIFICATION_CODE,
1355 form_structure->field(5)->heuristic_type()); 1356 form_structure->field(5)->heuristic_type());
1356 // Submit. 1357 // Submit.
1357 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(6)->heuristic_type()); 1358 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(6)->heuristic_type());
1358 } 1359 }
1359 1360
1360 TEST_F(FormStructureTest, ThreeAddressLines) { 1361 TEST_F(FormStructureTest, ThreeAddressLines) {
1361 scoped_ptr<FormStructure> form_structure; 1362 std::unique_ptr<FormStructure> form_structure;
1362 FormData form; 1363 FormData form;
1363 1364
1364 FormFieldData field; 1365 FormFieldData field;
1365 field.form_control_type = "text"; 1366 field.form_control_type = "text";
1366 1367
1367 field.label = ASCIIToUTF16("Address Line1"); 1368 field.label = ASCIIToUTF16("Address Line1");
1368 field.name = ASCIIToUTF16("Address"); 1369 field.name = ASCIIToUTF16("Address");
1369 form.fields.push_back(field); 1370 form.fields.push_back(field);
1370 1371
1371 field.label = ASCIIToUTF16("Address Line2"); 1372 field.label = ASCIIToUTF16("Address Line2");
(...skipping 19 matching lines...) Expand all
1391 // Address Line 2. 1392 // Address Line 2.
1392 EXPECT_EQ(ADDRESS_HOME_LINE2, form_structure->field(1)->heuristic_type()); 1393 EXPECT_EQ(ADDRESS_HOME_LINE2, form_structure->field(1)->heuristic_type());
1393 // Address Line 3. 1394 // Address Line 3.
1394 EXPECT_EQ(ADDRESS_HOME_LINE3, form_structure->field(2)->heuristic_type()); 1395 EXPECT_EQ(ADDRESS_HOME_LINE3, form_structure->field(2)->heuristic_type());
1395 // City. 1396 // City.
1396 EXPECT_EQ(ADDRESS_HOME_CITY, form_structure->field(3)->heuristic_type()); 1397 EXPECT_EQ(ADDRESS_HOME_CITY, form_structure->field(3)->heuristic_type());
1397 } 1398 }
1398 1399
1399 // Numbered address lines after line two are ignored. 1400 // Numbered address lines after line two are ignored.
1400 TEST_F(FormStructureTest, SurplusAddressLinesIgnored) { 1401 TEST_F(FormStructureTest, SurplusAddressLinesIgnored) {
1401 scoped_ptr<FormStructure> form_structure; 1402 std::unique_ptr<FormStructure> form_structure;
1402 FormData form; 1403 FormData form;
1403 1404
1404 FormFieldData field; 1405 FormFieldData field;
1405 field.form_control_type = "text"; 1406 field.form_control_type = "text";
1406 1407
1407 field.label = ASCIIToUTF16("Address Line1"); 1408 field.label = ASCIIToUTF16("Address Line1");
1408 field.name = ASCIIToUTF16("shipping.address.addressLine1"); 1409 field.name = ASCIIToUTF16("shipping.address.addressLine1");
1409 form.fields.push_back(field); 1410 form.fields.push_back(field);
1410 1411
1411 field.label = ASCIIToUTF16("Address Line2"); 1412 field.label = ASCIIToUTF16("Address Line2");
(...skipping 22 matching lines...) Expand all
1434 // Address Line 4 (ignored). 1435 // Address Line 4 (ignored).
1435 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(3)->heuristic_type()); 1436 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(3)->heuristic_type());
1436 } 1437 }
1437 1438
1438 // This example comes from expedia.com where they used to use a "Suite" label 1439 // This example comes from expedia.com where they used to use a "Suite" label
1439 // to indicate a suite or apartment number (the form has changed since this 1440 // to indicate a suite or apartment number (the form has changed since this
1440 // test was written). We interpret this as address line 2. And the following 1441 // test was written). We interpret this as address line 2. And the following
1441 // "Street address second line" we interpret as address line 3. 1442 // "Street address second line" we interpret as address line 3.
1442 // See http://crbug.com/48197 for details. 1443 // See http://crbug.com/48197 for details.
1443 TEST_F(FormStructureTest, ThreeAddressLinesExpedia) { 1444 TEST_F(FormStructureTest, ThreeAddressLinesExpedia) {
1444 scoped_ptr<FormStructure> form_structure; 1445 std::unique_ptr<FormStructure> form_structure;
1445 FormData form; 1446 FormData form;
1446 1447
1447 FormFieldData field; 1448 FormFieldData field;
1448 field.form_control_type = "text"; 1449 field.form_control_type = "text";
1449 1450
1450 field.label = ASCIIToUTF16("Street:"); 1451 field.label = ASCIIToUTF16("Street:");
1451 field.name = ASCIIToUTF16("FOPIH_RgWebCC_0_IHAddress_ads1"); 1452 field.name = ASCIIToUTF16("FOPIH_RgWebCC_0_IHAddress_ads1");
1452 form.fields.push_back(field); 1453 form.fields.push_back(field);
1453 1454
1454 field.label = ASCIIToUTF16("Suite or Apt:"); 1455 field.label = ASCIIToUTF16("Suite or Apt:");
(...skipping 21 matching lines...) Expand all
1476 // Address Line 3. 1477 // Address Line 3.
1477 EXPECT_EQ(ADDRESS_HOME_LINE3, form_structure->field(2)->heuristic_type()); 1478 EXPECT_EQ(ADDRESS_HOME_LINE3, form_structure->field(2)->heuristic_type());
1478 // City. 1479 // City.
1479 EXPECT_EQ(ADDRESS_HOME_CITY, form_structure->field(3)->heuristic_type()); 1480 EXPECT_EQ(ADDRESS_HOME_CITY, form_structure->field(3)->heuristic_type());
1480 } 1481 }
1481 1482
1482 // This example comes from ebay.com where the word "suite" appears in the label 1483 // This example comes from ebay.com where the word "suite" appears in the label
1483 // and the name "address2" clearly indicates that this is the address line 2. 1484 // and the name "address2" clearly indicates that this is the address line 2.
1484 // See http://crbug.com/48197 for details. 1485 // See http://crbug.com/48197 for details.
1485 TEST_F(FormStructureTest, TwoAddressLinesEbay) { 1486 TEST_F(FormStructureTest, TwoAddressLinesEbay) {
1486 scoped_ptr<FormStructure> form_structure; 1487 std::unique_ptr<FormStructure> form_structure;
1487 FormData form; 1488 FormData form;
1488 1489
1489 FormFieldData field; 1490 FormFieldData field;
1490 field.form_control_type = "text"; 1491 field.form_control_type = "text";
1491 1492
1492 field.label = ASCIIToUTF16("Address Line1"); 1493 field.label = ASCIIToUTF16("Address Line1");
1493 field.name = ASCIIToUTF16("address1"); 1494 field.name = ASCIIToUTF16("address1");
1494 form.fields.push_back(field); 1495 form.fields.push_back(field);
1495 1496
1496 field.label = ASCIIToUTF16("Floor number, suite number, etc"); 1497 field.label = ASCIIToUTF16("Floor number, suite number, etc");
(...skipping 12 matching lines...) Expand all
1509 1510
1510 // Address Line 1. 1511 // Address Line 1.
1511 EXPECT_EQ(ADDRESS_HOME_LINE1, form_structure->field(0)->heuristic_type()); 1512 EXPECT_EQ(ADDRESS_HOME_LINE1, form_structure->field(0)->heuristic_type());
1512 // Address Line 2. 1513 // Address Line 2.
1513 EXPECT_EQ(ADDRESS_HOME_LINE2, form_structure->field(1)->heuristic_type()); 1514 EXPECT_EQ(ADDRESS_HOME_LINE2, form_structure->field(1)->heuristic_type());
1514 // City. 1515 // City.
1515 EXPECT_EQ(ADDRESS_HOME_CITY, form_structure->field(2)->heuristic_type()); 1516 EXPECT_EQ(ADDRESS_HOME_CITY, form_structure->field(2)->heuristic_type());
1516 } 1517 }
1517 1518
1518 TEST_F(FormStructureTest, HeuristicsStateWithProvince) { 1519 TEST_F(FormStructureTest, HeuristicsStateWithProvince) {
1519 scoped_ptr<FormStructure> form_structure; 1520 std::unique_ptr<FormStructure> form_structure;
1520 FormData form; 1521 FormData form;
1521 1522
1522 FormFieldData field; 1523 FormFieldData field;
1523 field.form_control_type = "text"; 1524 field.form_control_type = "text";
1524 1525
1525 field.label = ASCIIToUTF16("Address Line1"); 1526 field.label = ASCIIToUTF16("Address Line1");
1526 field.name = ASCIIToUTF16("Address"); 1527 field.name = ASCIIToUTF16("Address");
1527 form.fields.push_back(field); 1528 form.fields.push_back(field);
1528 1529
1529 field.label = ASCIIToUTF16("Address Line2"); 1530 field.label = ASCIIToUTF16("Address Line2");
(...skipping 13 matching lines...) Expand all
1543 // Address Line 1. 1544 // Address Line 1.
1544 EXPECT_EQ(ADDRESS_HOME_LINE1, form_structure->field(0)->heuristic_type()); 1545 EXPECT_EQ(ADDRESS_HOME_LINE1, form_structure->field(0)->heuristic_type());
1545 // Address Line 2. 1546 // Address Line 2.
1546 EXPECT_EQ(ADDRESS_HOME_LINE2, form_structure->field(1)->heuristic_type()); 1547 EXPECT_EQ(ADDRESS_HOME_LINE2, form_structure->field(1)->heuristic_type());
1547 // State. 1548 // State.
1548 EXPECT_EQ(ADDRESS_HOME_STATE, form_structure->field(2)->heuristic_type()); 1549 EXPECT_EQ(ADDRESS_HOME_STATE, form_structure->field(2)->heuristic_type());
1549 } 1550 }
1550 1551
1551 // This example comes from lego.com's checkout page. 1552 // This example comes from lego.com's checkout page.
1552 TEST_F(FormStructureTest, HeuristicsWithBilling) { 1553 TEST_F(FormStructureTest, HeuristicsWithBilling) {
1553 scoped_ptr<FormStructure> form_structure; 1554 std::unique_ptr<FormStructure> form_structure;
1554 FormData form; 1555 FormData form;
1555 1556
1556 FormFieldData field; 1557 FormFieldData field;
1557 field.form_control_type = "text"; 1558 field.form_control_type = "text";
1558 1559
1559 field.label = ASCIIToUTF16("First Name*:"); 1560 field.label = ASCIIToUTF16("First Name*:");
1560 field.name = ASCIIToUTF16("editBillingAddress$firstNameBox"); 1561 field.name = ASCIIToUTF16("editBillingAddress$firstNameBox");
1561 form.fields.push_back(field); 1562 form.fields.push_back(field);
1562 1563
1563 field.label = ASCIIToUTF16("Last Name*:"); 1564 field.label = ASCIIToUTF16("Last Name*:");
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
1614 EXPECT_EQ(ADDRESS_HOME_CITY, form_structure->field(5)->heuristic_type()); 1615 EXPECT_EQ(ADDRESS_HOME_CITY, form_structure->field(5)->heuristic_type());
1615 EXPECT_EQ(ADDRESS_HOME_STATE, form_structure->field(6)->heuristic_type()); 1616 EXPECT_EQ(ADDRESS_HOME_STATE, form_structure->field(6)->heuristic_type());
1616 EXPECT_EQ(ADDRESS_HOME_COUNTRY, form_structure->field(7)->heuristic_type()); 1617 EXPECT_EQ(ADDRESS_HOME_COUNTRY, form_structure->field(7)->heuristic_type());
1617 EXPECT_EQ(ADDRESS_HOME_ZIP, form_structure->field(8)->heuristic_type()); 1618 EXPECT_EQ(ADDRESS_HOME_ZIP, form_structure->field(8)->heuristic_type());
1618 EXPECT_EQ(PHONE_HOME_WHOLE_NUMBER, 1619 EXPECT_EQ(PHONE_HOME_WHOLE_NUMBER,
1619 form_structure->field(9)->heuristic_type()); 1620 form_structure->field(9)->heuristic_type());
1620 EXPECT_EQ(EMAIL_ADDRESS, form_structure->field(10)->heuristic_type()); 1621 EXPECT_EQ(EMAIL_ADDRESS, form_structure->field(10)->heuristic_type());
1621 } 1622 }
1622 1623
1623 TEST_F(FormStructureTest, ThreePartPhoneNumber) { 1624 TEST_F(FormStructureTest, ThreePartPhoneNumber) {
1624 scoped_ptr<FormStructure> form_structure; 1625 std::unique_ptr<FormStructure> form_structure;
1625 FormData form; 1626 FormData form;
1626 1627
1627 FormFieldData field; 1628 FormFieldData field;
1628 field.form_control_type = "text"; 1629 field.form_control_type = "text";
1629 1630
1630 field.label = ASCIIToUTF16("Phone:"); 1631 field.label = ASCIIToUTF16("Phone:");
1631 field.name = ASCIIToUTF16("dayphone1"); 1632 field.name = ASCIIToUTF16("dayphone1");
1632 field.max_length = 0; 1633 field.max_length = 0;
1633 form.fields.push_back(field); 1634 form.fields.push_back(field);
1634 1635
(...skipping 26 matching lines...) Expand all
1661 EXPECT_EQ(PHONE_HOME_NUMBER, 1662 EXPECT_EQ(PHONE_HOME_NUMBER,
1662 form_structure->field(1)->heuristic_type()); 1663 form_structure->field(1)->heuristic_type());
1663 // Phone number suffix. 1664 // Phone number suffix.
1664 EXPECT_EQ(PHONE_HOME_NUMBER, 1665 EXPECT_EQ(PHONE_HOME_NUMBER,
1665 form_structure->field(2)->heuristic_type()); 1666 form_structure->field(2)->heuristic_type());
1666 // Phone extension. 1667 // Phone extension.
1667 EXPECT_EQ(PHONE_HOME_EXTENSION, form_structure->field(3)->heuristic_type()); 1668 EXPECT_EQ(PHONE_HOME_EXTENSION, form_structure->field(3)->heuristic_type());
1668 } 1669 }
1669 1670
1670 TEST_F(FormStructureTest, HeuristicsInfernoCC) { 1671 TEST_F(FormStructureTest, HeuristicsInfernoCC) {
1671 scoped_ptr<FormStructure> form_structure; 1672 std::unique_ptr<FormStructure> form_structure;
1672 FormData form; 1673 FormData form;
1673 1674
1674 FormFieldData field; 1675 FormFieldData field;
1675 field.form_control_type = "text"; 1676 field.form_control_type = "text";
1676 1677
1677 field.label = ASCIIToUTF16("Name on Card"); 1678 field.label = ASCIIToUTF16("Name on Card");
1678 field.name = ASCIIToUTF16("name_on_card"); 1679 field.name = ASCIIToUTF16("name_on_card");
1679 form.fields.push_back(field); 1680 form.fields.push_back(field);
1680 1681
1681 field.label = ASCIIToUTF16("Address"); 1682 field.label = ASCIIToUTF16("Address");
(...skipping 29 matching lines...) Expand all
1711 // Expiration Date. 1712 // Expiration Date.
1712 EXPECT_EQ(CREDIT_CARD_EXP_MONTH, form_structure->field(3)->heuristic_type()); 1713 EXPECT_EQ(CREDIT_CARD_EXP_MONTH, form_structure->field(3)->heuristic_type());
1713 // Expiration Year. 1714 // Expiration Year.
1714 EXPECT_EQ(CREDIT_CARD_EXP_4_DIGIT_YEAR, 1715 EXPECT_EQ(CREDIT_CARD_EXP_4_DIGIT_YEAR,
1715 form_structure->field(4)->heuristic_type()); 1716 form_structure->field(4)->heuristic_type());
1716 } 1717 }
1717 1718
1718 // Tests that the heuristics detect split credit card names if they appear in 1719 // Tests that the heuristics detect split credit card names if they appear in
1719 // the middle of the form. 1720 // the middle of the form.
1720 TEST_F(FormStructureTest, HeuristicsInferCCNames_NamesNotFirst) { 1721 TEST_F(FormStructureTest, HeuristicsInferCCNames_NamesNotFirst) {
1721 scoped_ptr<FormStructure> form_structure; 1722 std::unique_ptr<FormStructure> form_structure;
1722 FormData form; 1723 FormData form;
1723 1724
1724 FormFieldData field; 1725 FormFieldData field;
1725 field.form_control_type = "text"; 1726 field.form_control_type = "text";
1726 1727
1727 field.label = ASCIIToUTF16("Card number"); 1728 field.label = ASCIIToUTF16("Card number");
1728 field.name = ASCIIToUTF16("ccnumber"); 1729 field.name = ASCIIToUTF16("ccnumber");
1729 form.fields.push_back(field); 1730 form.fields.push_back(field);
1730 1731
1731 field.label = ASCIIToUTF16("First name"); 1732 field.label = ASCIIToUTF16("First name");
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1769 form_structure->field(4)->heuristic_type()); 1770 form_structure->field(4)->heuristic_type());
1770 // CVC code. 1771 // CVC code.
1771 EXPECT_EQ(CREDIT_CARD_VERIFICATION_CODE, 1772 EXPECT_EQ(CREDIT_CARD_VERIFICATION_CODE,
1772 form_structure->field(5)->heuristic_type()); 1773 form_structure->field(5)->heuristic_type());
1773 } 1774 }
1774 1775
1775 // Tests that the heuristics detect split credit card names if they appear at 1776 // Tests that the heuristics detect split credit card names if they appear at
1776 // the beginning of the form. The first name has to contains some credit card 1777 // the beginning of the form. The first name has to contains some credit card
1777 // keyword. 1778 // keyword.
1778 TEST_F(FormStructureTest, HeuristicsInferCCNames_NamesFirst) { 1779 TEST_F(FormStructureTest, HeuristicsInferCCNames_NamesFirst) {
1779 scoped_ptr<FormStructure> form_structure; 1780 std::unique_ptr<FormStructure> form_structure;
1780 FormData form; 1781 FormData form;
1781 1782
1782 FormFieldData field; 1783 FormFieldData field;
1783 field.form_control_type = "text"; 1784 field.form_control_type = "text";
1784 1785
1785 field.label = ASCIIToUTF16("Cardholder Name"); 1786 field.label = ASCIIToUTF16("Cardholder Name");
1786 field.name = ASCIIToUTF16("cc_first_name"); 1787 field.name = ASCIIToUTF16("cc_first_name");
1787 form.fields.push_back(field); 1788 form.fields.push_back(field);
1788 1789
1789 field.label = ASCIIToUTF16("Last name"); 1790 field.label = ASCIIToUTF16("Last name");
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
1975 1976
1976 // Check that we fail if there are only bad form(s). 1977 // Check that we fail if there are only bad form(s).
1977 ScopedVector<FormStructure> bad_forms; 1978 ScopedVector<FormStructure> bad_forms;
1978 bad_forms.push_back(new FormStructure(malformed_form)); 1979 bad_forms.push_back(new FormStructure(malformed_form));
1979 AutofillQueryContents encoded_query5; 1980 AutofillQueryContents encoded_query5;
1980 EXPECT_FALSE(FormStructure::EncodeQueryRequest( 1981 EXPECT_FALSE(FormStructure::EncodeQueryRequest(
1981 bad_forms.get(), &encoded_signatures, &encoded_query5)); 1982 bad_forms.get(), &encoded_signatures, &encoded_query5));
1982 } 1983 }
1983 1984
1984 TEST_F(FormStructureTest, EncodeUploadRequest) { 1985 TEST_F(FormStructureTest, EncodeUploadRequest) {
1985 scoped_ptr<FormStructure> form_structure; 1986 std::unique_ptr<FormStructure> form_structure;
1986 std::vector<ServerFieldTypeSet> possible_field_types; 1987 std::vector<ServerFieldTypeSet> possible_field_types;
1987 FormData form; 1988 FormData form;
1988 form_structure.reset(new FormStructure(form)); 1989 form_structure.reset(new FormStructure(form));
1989 form_structure->DetermineHeuristicTypes(); 1990 form_structure->DetermineHeuristicTypes();
1990 1991
1991 FormFieldData field; 1992 FormFieldData field;
1992 field.form_control_type = "text"; 1993 field.form_control_type = "text";
1993 1994
1994 field.label = ASCIIToUTF16("First Name"); 1995 field.label = ASCIIToUTF16("First Name");
1995 field.name = ASCIIToUTF16("firstname"); 1996 field.name = ASCIIToUTF16("firstname");
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
2151 for (size_t i = 0; i < form_structure->field_count(); ++i) 2152 for (size_t i = 0; i < form_structure->field_count(); ++i)
2152 form_structure->field(i)->set_possible_types(possible_field_types[i]); 2153 form_structure->field(i)->set_possible_types(possible_field_types[i]);
2153 2154
2154 AutofillUploadContents encoded_upload4; 2155 AutofillUploadContents encoded_upload4;
2155 EXPECT_FALSE(form_structure->EncodeUploadRequest( 2156 EXPECT_FALSE(form_structure->EncodeUploadRequest(
2156 available_field_types, false, std::string(), true, &encoded_upload4)); 2157 available_field_types, false, std::string(), true, &encoded_upload4));
2157 } 2158 }
2158 2159
2159 TEST_F(FormStructureTest, 2160 TEST_F(FormStructureTest,
2160 EncodeUploadRequestWithAdditionalPasswordFormSignature) { 2161 EncodeUploadRequestWithAdditionalPasswordFormSignature) {
2161 scoped_ptr<FormStructure> form_structure; 2162 std::unique_ptr<FormStructure> form_structure;
2162 std::vector<ServerFieldTypeSet> possible_field_types; 2163 std::vector<ServerFieldTypeSet> possible_field_types;
2163 FormData form; 2164 FormData form;
2164 form_structure.reset(new FormStructure(form)); 2165 form_structure.reset(new FormStructure(form));
2165 form_structure->DetermineHeuristicTypes(); 2166 form_structure->DetermineHeuristicTypes();
2166 2167
2167 FormFieldData field; 2168 FormFieldData field;
2168 field.label = ASCIIToUTF16("First Name"); 2169 field.label = ASCIIToUTF16("First Name");
2169 field.name = ASCIIToUTF16("firstname"); 2170 field.name = ASCIIToUTF16("firstname");
2170 field.autocomplete_attribute = "given-name"; 2171 field.autocomplete_attribute = "given-name";
2171 form.fields.push_back(field); 2172 form.fields.push_back(field);
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
2250 AutofillUploadContents encoded_upload; 2251 AutofillUploadContents encoded_upload;
2251 EXPECT_TRUE(form_structure->EncodeUploadRequest(available_field_types, true, 2252 EXPECT_TRUE(form_structure->EncodeUploadRequest(available_field_types, true,
2252 "42", true, &encoded_upload)); 2253 "42", true, &encoded_upload));
2253 2254
2254 std::string encoded_upload_string; 2255 std::string encoded_upload_string;
2255 encoded_upload.SerializeToString(&encoded_upload_string); 2256 encoded_upload.SerializeToString(&encoded_upload_string);
2256 EXPECT_EQ(expected_upload_string, encoded_upload_string); 2257 EXPECT_EQ(expected_upload_string, encoded_upload_string);
2257 } 2258 }
2258 2259
2259 TEST_F(FormStructureTest, EncodeUploadRequest_WithAutocomplete) { 2260 TEST_F(FormStructureTest, EncodeUploadRequest_WithAutocomplete) {
2260 scoped_ptr<FormStructure> form_structure; 2261 std::unique_ptr<FormStructure> form_structure;
2261 std::vector<ServerFieldTypeSet> possible_field_types; 2262 std::vector<ServerFieldTypeSet> possible_field_types;
2262 FormData form; 2263 FormData form;
2263 form_structure.reset(new FormStructure(form)); 2264 form_structure.reset(new FormStructure(form));
2264 form_structure->DetermineHeuristicTypes(); 2265 form_structure->DetermineHeuristicTypes();
2265 2266
2266 FormFieldData field; 2267 FormFieldData field;
2267 field.form_control_type = "text"; 2268 field.form_control_type = "text";
2268 2269
2269 field.label = ASCIIToUTF16("First Name"); 2270 field.label = ASCIIToUTF16("First Name");
2270 field.name = ASCIIToUTF16("firstname"); 2271 field.name = ASCIIToUTF16("firstname");
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
2321 AutofillUploadContents encoded_upload; 2322 AutofillUploadContents encoded_upload;
2322 EXPECT_TRUE(form_structure->EncodeUploadRequest( 2323 EXPECT_TRUE(form_structure->EncodeUploadRequest(
2323 available_field_types, true, std::string(), true, &encoded_upload)); 2324 available_field_types, true, std::string(), true, &encoded_upload));
2324 2325
2325 std::string encoded_upload_string; 2326 std::string encoded_upload_string;
2326 encoded_upload.SerializeToString(&encoded_upload_string); 2327 encoded_upload.SerializeToString(&encoded_upload_string);
2327 EXPECT_EQ(expected_upload_string, encoded_upload_string); 2328 EXPECT_EQ(expected_upload_string, encoded_upload_string);
2328 } 2329 }
2329 2330
2330 TEST_F(FormStructureTest, EncodeUploadRequest_ObservedSubmissionFalse) { 2331 TEST_F(FormStructureTest, EncodeUploadRequest_ObservedSubmissionFalse) {
2331 scoped_ptr<FormStructure> form_structure; 2332 std::unique_ptr<FormStructure> form_structure;
2332 std::vector<ServerFieldTypeSet> possible_field_types; 2333 std::vector<ServerFieldTypeSet> possible_field_types;
2333 FormData form; 2334 FormData form;
2334 form_structure.reset(new FormStructure(form)); 2335 form_structure.reset(new FormStructure(form));
2335 form_structure->DetermineHeuristicTypes(); 2336 form_structure->DetermineHeuristicTypes();
2336 2337
2337 FormFieldData field; 2338 FormFieldData field;
2338 field.form_control_type = "text"; 2339 field.form_control_type = "text";
2339 2340
2340 field.label = ASCIIToUTF16("First Name"); 2341 field.label = ASCIIToUTF16("First Name");
2341 field.name = ASCIIToUTF16("firstname"); 2342 field.name = ASCIIToUTF16("firstname");
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
2390 EXPECT_TRUE(form_structure->EncodeUploadRequest( 2391 EXPECT_TRUE(form_structure->EncodeUploadRequest(
2391 available_field_types, true, std::string(), 2392 available_field_types, true, std::string(),
2392 /* observed_submission= */ false, &encoded_upload)); 2393 /* observed_submission= */ false, &encoded_upload));
2393 2394
2394 std::string encoded_upload_string; 2395 std::string encoded_upload_string;
2395 encoded_upload.SerializeToString(&encoded_upload_string); 2396 encoded_upload.SerializeToString(&encoded_upload_string);
2396 EXPECT_EQ(expected_upload_string, encoded_upload_string); 2397 EXPECT_EQ(expected_upload_string, encoded_upload_string);
2397 } 2398 }
2398 2399
2399 TEST_F(FormStructureTest, EncodeUploadRequest_WithLabels) { 2400 TEST_F(FormStructureTest, EncodeUploadRequest_WithLabels) {
2400 scoped_ptr<FormStructure> form_structure; 2401 std::unique_ptr<FormStructure> form_structure;
2401 std::vector<ServerFieldTypeSet> possible_field_types; 2402 std::vector<ServerFieldTypeSet> possible_field_types;
2402 FormData form; 2403 FormData form;
2403 form_structure.reset(new FormStructure(form)); 2404 form_structure.reset(new FormStructure(form));
2404 form_structure->DetermineHeuristicTypes(); 2405 form_structure->DetermineHeuristicTypes();
2405 2406
2406 FormFieldData field; 2407 FormFieldData field;
2407 field.form_control_type = "text"; 2408 field.form_control_type = "text";
2408 2409
2409 // No label for the first field. 2410 // No label for the first field.
2410 form.fields.push_back(field); 2411 form.fields.push_back(field);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
2455 EXPECT_TRUE(form_structure->EncodeUploadRequest( 2456 EXPECT_TRUE(form_structure->EncodeUploadRequest(
2456 available_field_types, true, std::string(), true, &encoded_upload)); 2457 available_field_types, true, std::string(), true, &encoded_upload));
2457 2458
2458 std::string encoded_upload_string; 2459 std::string encoded_upload_string;
2459 encoded_upload.SerializeToString(&encoded_upload_string); 2460 encoded_upload.SerializeToString(&encoded_upload_string);
2460 EXPECT_EQ(expected_upload_string, encoded_upload_string); 2461 EXPECT_EQ(expected_upload_string, encoded_upload_string);
2461 } 2462 }
2462 2463
2463 // Test that the form name is sent in the upload request. 2464 // Test that the form name is sent in the upload request.
2464 TEST_F(FormStructureTest, EncodeUploadRequest_WithFormName) { 2465 TEST_F(FormStructureTest, EncodeUploadRequest_WithFormName) {
2465 scoped_ptr<FormStructure> form_structure; 2466 std::unique_ptr<FormStructure> form_structure;
2466 std::vector<ServerFieldTypeSet> possible_field_types; 2467 std::vector<ServerFieldTypeSet> possible_field_types;
2467 FormData form; 2468 FormData form;
2468 // Setting the form name which we expect to see in the upload. 2469 // Setting the form name which we expect to see in the upload.
2469 form.name = ASCIIToUTF16("myform"); 2470 form.name = ASCIIToUTF16("myform");
2470 form_structure.reset(new FormStructure(form)); 2471 form_structure.reset(new FormStructure(form));
2471 form_structure->DetermineHeuristicTypes(); 2472 form_structure->DetermineHeuristicTypes();
2472 2473
2473 FormFieldData field; 2474 FormFieldData field;
2474 field.form_control_type = "text"; 2475 field.form_control_type = "text";
2475 2476
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
2519 AutofillUploadContents encoded_upload; 2520 AutofillUploadContents encoded_upload;
2520 EXPECT_TRUE(form_structure->EncodeUploadRequest( 2521 EXPECT_TRUE(form_structure->EncodeUploadRequest(
2521 available_field_types, true, std::string(), true, &encoded_upload)); 2522 available_field_types, true, std::string(), true, &encoded_upload));
2522 2523
2523 std::string encoded_upload_string; 2524 std::string encoded_upload_string;
2524 encoded_upload.SerializeToString(&encoded_upload_string); 2525 encoded_upload.SerializeToString(&encoded_upload_string);
2525 EXPECT_EQ(expected_upload_string, encoded_upload_string); 2526 EXPECT_EQ(expected_upload_string, encoded_upload_string);
2526 } 2527 }
2527 2528
2528 TEST_F(FormStructureTest, EncodeUploadRequestPartialMetadata) { 2529 TEST_F(FormStructureTest, EncodeUploadRequestPartialMetadata) {
2529 scoped_ptr<FormStructure> form_structure; 2530 std::unique_ptr<FormStructure> form_structure;
2530 std::vector<ServerFieldTypeSet> possible_field_types; 2531 std::vector<ServerFieldTypeSet> possible_field_types;
2531 FormData form; 2532 FormData form;
2532 form_structure.reset(new FormStructure(form)); 2533 form_structure.reset(new FormStructure(form));
2533 form_structure->DetermineHeuristicTypes(); 2534 form_structure->DetermineHeuristicTypes();
2534 2535
2535 FormFieldData field; 2536 FormFieldData field;
2536 field.form_control_type = "text"; 2537 field.form_control_type = "text";
2537 2538
2538 // Some fields don't have "name" or "autocomplete" attributes, and some have 2539 // Some fields don't have "name" or "autocomplete" attributes, and some have
2539 // neither. 2540 // neither.
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
2592 2593
2593 std::string encoded_upload_string; 2594 std::string encoded_upload_string;
2594 encoded_upload.SerializeToString(&encoded_upload_string); 2595 encoded_upload.SerializeToString(&encoded_upload_string);
2595 EXPECT_EQ(expected_upload_string, encoded_upload_string); 2596 EXPECT_EQ(expected_upload_string, encoded_upload_string);
2596 } 2597 }
2597 2598
2598 // Sending field metadata to the server is disabled. 2599 // Sending field metadata to the server is disabled.
2599 TEST_F(FormStructureTest, EncodeUploadRequest_DisabledMetadataTrial) { 2600 TEST_F(FormStructureTest, EncodeUploadRequest_DisabledMetadataTrial) {
2600 DisableAutofillMetadataFieldTrial(); 2601 DisableAutofillMetadataFieldTrial();
2601 2602
2602 scoped_ptr<FormStructure> form_structure; 2603 std::unique_ptr<FormStructure> form_structure;
2603 std::vector<ServerFieldTypeSet> possible_field_types; 2604 std::vector<ServerFieldTypeSet> possible_field_types;
2604 FormData form; 2605 FormData form;
2605 form_structure.reset(new FormStructure(form)); 2606 form_structure.reset(new FormStructure(form));
2606 form_structure->DetermineHeuristicTypes(); 2607 form_structure->DetermineHeuristicTypes();
2607 2608
2608 FormFieldData field; 2609 FormFieldData field;
2609 field.form_control_type = "text"; 2610 field.form_control_type = "text";
2610 2611
2611 field.label = ASCIIToUTF16("First Name"); 2612 field.label = ASCIIToUTF16("First Name");
2612 field.name = ASCIIToUTF16("firstname"); 2613 field.name = ASCIIToUTF16("firstname");
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after
2925 available_field_types.insert(NAME_FIRST); 2926 available_field_types.insert(NAME_FIRST);
2926 available_field_types.insert(NAME_LAST); 2927 available_field_types.insert(NAME_LAST);
2927 available_field_types.insert(EMAIL_ADDRESS); 2928 available_field_types.insert(EMAIL_ADDRESS);
2928 available_field_types.insert(ADDRESS_HOME_LINE1); 2929 available_field_types.insert(ADDRESS_HOME_LINE1);
2929 available_field_types.insert(ADDRESS_HOME_LINE2); 2930 available_field_types.insert(ADDRESS_HOME_LINE2);
2930 available_field_types.insert(ADDRESS_HOME_CITY); 2931 available_field_types.insert(ADDRESS_HOME_CITY);
2931 available_field_types.insert(ADDRESS_HOME_STATE); 2932 available_field_types.insert(ADDRESS_HOME_STATE);
2932 available_field_types.insert(COMPANY_NAME); 2933 available_field_types.insert(COMPANY_NAME);
2933 2934
2934 // Check that multiple types for the field are processed correctly. 2935 // Check that multiple types for the field are processed correctly.
2935 scoped_ptr<FormStructure> form_structure; 2936 std::unique_ptr<FormStructure> form_structure;
2936 std::vector<ServerFieldTypeSet> possible_field_types; 2937 std::vector<ServerFieldTypeSet> possible_field_types;
2937 FormData form; 2938 FormData form;
2938 2939
2939 FormFieldData field; 2940 FormFieldData field;
2940 field.form_control_type = "text"; 2941 field.form_control_type = "text";
2941 2942
2942 field.label = ASCIIToUTF16("email"); 2943 field.label = ASCIIToUTF16("email");
2943 field.name = ASCIIToUTF16("email"); 2944 field.name = ASCIIToUTF16("email");
2944 form.fields.push_back(field); 2945 form.fields.push_back(field);
2945 possible_field_types.push_back(ServerFieldTypeSet()); 2946 possible_field_types.push_back(ServerFieldTypeSet());
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
3051 AutofillUploadContents encoded_upload4; 3052 AutofillUploadContents encoded_upload4;
3052 EXPECT_TRUE(form_structure->EncodeUploadRequest( 3053 EXPECT_TRUE(form_structure->EncodeUploadRequest(
3053 available_field_types, false, std::string(), true, &encoded_upload4)); 3054 available_field_types, false, std::string(), true, &encoded_upload4));
3054 3055
3055 encoded_upload4.SerializeToString(&encoded_upload_string); 3056 encoded_upload4.SerializeToString(&encoded_upload_string);
3056 EXPECT_EQ(expected_upload_string, encoded_upload_string); 3057 EXPECT_EQ(expected_upload_string, encoded_upload_string);
3057 } 3058 }
3058 3059
3059 TEST_F(FormStructureTest, CheckFormSignature) { 3060 TEST_F(FormStructureTest, CheckFormSignature) {
3060 // Check that form signature is created correctly. 3061 // Check that form signature is created correctly.
3061 scoped_ptr<FormStructure> form_structure; 3062 std::unique_ptr<FormStructure> form_structure;
3062 FormData form; 3063 FormData form;
3063 3064
3064 FormFieldData field; 3065 FormFieldData field;
3065 field.form_control_type = "text"; 3066 field.form_control_type = "text";
3066 3067
3067 field.label = ASCIIToUTF16("email"); 3068 field.label = ASCIIToUTF16("email");
3068 field.name = ASCIIToUTF16("email"); 3069 field.name = ASCIIToUTF16("email");
3069 form.fields.push_back(field); 3070 form.fields.push_back(field);
3070 3071
3071 field.label = ASCIIToUTF16("First Name"); 3072 field.label = ASCIIToUTF16("First Name");
(...skipping 509 matching lines...) Expand 10 before | Expand all | Expand 10 after
3581 prefix = FormStructure::FindLongestCommonPrefix(strings); 3582 prefix = FormStructure::FindLongestCommonPrefix(strings);
3582 EXPECT_EQ(ASCIIToUTF16("1234567890123456"), prefix); 3583 EXPECT_EQ(ASCIIToUTF16("1234567890123456"), prefix);
3583 3584
3584 // Empty vector. 3585 // Empty vector.
3585 strings.clear(); 3586 strings.clear();
3586 prefix = FormStructure::FindLongestCommonPrefix(strings); 3587 prefix = FormStructure::FindLongestCommonPrefix(strings);
3587 EXPECT_EQ(ASCIIToUTF16(""), prefix); 3588 EXPECT_EQ(ASCIIToUTF16(""), prefix);
3588 } 3589 }
3589 3590
3590 } // namespace autofill 3591 } // namespace autofill
OLDNEW
« no previous file with comments | « components/autofill/core/browser/form_structure.cc ('k') | components/autofill/core/browser/legal_message_line.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698