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

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

Issue 2026353002: [Autofill] Credit Card Assist Infobar (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: cleaning Created 4 years, 4 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> 9 #include <memory>
10 10
(...skipping 587 matching lines...) Expand 10 before | Expand all | Expand 10 after
598 ASSERT_EQ(3U, form_structure->autofill_count()); 598 ASSERT_EQ(3U, form_structure->autofill_count());
599 599
600 // Address 1. 600 // Address 1.
601 EXPECT_EQ(ADDRESS_HOME_LINE1, form_structure->field(0)->heuristic_type()); 601 EXPECT_EQ(ADDRESS_HOME_LINE1, form_structure->field(0)->heuristic_type());
602 // Address 2. 602 // Address 2.
603 EXPECT_EQ(ADDRESS_HOME_LINE2, form_structure->field(1)->heuristic_type()); 603 EXPECT_EQ(ADDRESS_HOME_LINE2, form_structure->field(1)->heuristic_type());
604 // Address 3 604 // Address 3
605 EXPECT_EQ(ADDRESS_HOME_LINE3, form_structure->field(2)->heuristic_type()); 605 EXPECT_EQ(ADDRESS_HOME_LINE3, form_structure->field(2)->heuristic_type());
606 } 606 }
607 607
608 TEST_F(FormStructureTest, IsCompleteCreditCardForm_Minimal) {
609 std::unique_ptr<FormStructure> form_structure;
610 FormData form;
611
612 FormFieldData field;
613 field.form_control_type = "text";
614
615 field.label = ASCIIToUTF16("Card Number");
616 field.name = ASCIIToUTF16("card_number");
617 form.fields.push_back(field);
618
619 field.label = ASCIIToUTF16("Expiration");
620 field.name = ASCIIToUTF16("cc_exp");
621 form.fields.push_back(field);
622
623 // Another field to reach the minimum 3.
624 field.label = ASCIIToUTF16("Zip");
625 field.name = ASCIIToUTF16("zip");
626 form.fields.push_back(field);
627
628 form_structure.reset(new FormStructure(form));
629 form_structure->DetermineHeuristicTypes();
630
631 EXPECT_TRUE(form_structure->IsCompleteCreditCardForm());
632 }
633
634 TEST_F(FormStructureTest, IsCompleteCreditCardForm_Full) {
635 std::unique_ptr<FormStructure> form_structure;
636 FormData form;
637
638 FormFieldData field;
639 field.form_control_type = "text";
640
641 field.label = ASCIIToUTF16("Name on Card");
642 field.name = ASCIIToUTF16("name_on_card");
643 form.fields.push_back(field);
644
645 field.label = ASCIIToUTF16("Card Number");
646 field.name = ASCIIToUTF16("card_number");
647 form.fields.push_back(field);
648
649 field.label = ASCIIToUTF16("Exp Month");
650 field.name = ASCIIToUTF16("ccmonth");
651 form.fields.push_back(field);
652
653 field.label = ASCIIToUTF16("Exp Year");
654 field.name = ASCIIToUTF16("ccyear");
655 form.fields.push_back(field);
656
657 field.label = ASCIIToUTF16("Verification");
658 field.name = ASCIIToUTF16("verification");
659 form.fields.push_back(field);
660
661 field.label = base::string16();
662 field.name = ASCIIToUTF16("Submit");
663 field.form_control_type = "submit";
664 form.fields.push_back(field);
665
666 form_structure.reset(new FormStructure(form));
667 form_structure->DetermineHeuristicTypes();
668
669 EXPECT_TRUE(form_structure->IsCompleteCreditCardForm());
670 }
671
672 // A form with only the credit card number is not considered sufficient.
673 TEST_F(FormStructureTest, IsCompleteCreditCardForm_OnlyCCNumber) {
674 std::unique_ptr<FormStructure> form_structure;
675 FormData form;
676
677 FormFieldData field;
678 field.form_control_type = "text";
679
680 field.label = ASCIIToUTF16("Card Number");
681 field.name = ASCIIToUTF16("card_number");
682 form.fields.push_back(field);
683
684 form_structure.reset(new FormStructure(form));
685 form_structure->DetermineHeuristicTypes();
686
687 EXPECT_FALSE(form_structure->IsCompleteCreditCardForm());
688 }
689
690 // A form with only the credit card number is not considered sufficient.
691 TEST_F(FormStructureTest, IsCompleteCreditCardForm_AddressForm) {
692 std::unique_ptr<FormStructure> form_structure;
693 FormData form;
694
695 FormFieldData field;
696 field.form_control_type = "text";
697
698 field.label = ASCIIToUTF16("First Name");
699 field.name = base::string16();
700 form.fields.push_back(field);
701
702 field.label = ASCIIToUTF16("Last Name");
703 field.name = base::string16();
704 form.fields.push_back(field);
705
706 field.label = ASCIIToUTF16("Email");
707 field.name = base::string16();
708 form.fields.push_back(field);
709
710 field.label = ASCIIToUTF16("Phone");
711 field.name = base::string16();
712 form.fields.push_back(field);
713
714 field.label = ASCIIToUTF16("Address");
715 field.name = base::string16();
716 form.fields.push_back(field);
717
718 field.label = ASCIIToUTF16("Address");
719 field.name = base::string16();
720 form.fields.push_back(field);
721
722 field.label = ASCIIToUTF16("Zip code");
723 field.name = base::string16();
724 form.fields.push_back(field);
725 form_structure.reset(new FormStructure(form));
726 form_structure->DetermineHeuristicTypes();
727
728 EXPECT_FALSE(form_structure->IsCompleteCreditCardForm());
729 }
730
608 // Verify that we can correctly process the 'autocomplete' attribute for phone 731 // Verify that we can correctly process the 'autocomplete' attribute for phone
609 // number types (especially phone prefixes and suffixes). 732 // number types (especially phone prefixes and suffixes).
610 TEST_F(FormStructureTest, HeuristicsAutocompleteAttributePhoneTypes) { 733 TEST_F(FormStructureTest, HeuristicsAutocompleteAttributePhoneTypes) {
611 std::unique_ptr<FormStructure> form_structure; 734 std::unique_ptr<FormStructure> form_structure;
612 FormData form; 735 FormData form;
613 736
614 FormFieldData field; 737 FormFieldData field;
615 field.form_control_type = "text"; 738 field.form_control_type = "text";
616 739
617 field.label = base::string16(); 740 field.label = base::string16();
(...skipping 3057 matching lines...) Expand 10 before | Expand all | Expand 10 after
3675 prefix = FormStructure::FindLongestCommonPrefix(strings); 3798 prefix = FormStructure::FindLongestCommonPrefix(strings);
3676 EXPECT_EQ(ASCIIToUTF16("1234567890123456"), prefix); 3799 EXPECT_EQ(ASCIIToUTF16("1234567890123456"), prefix);
3677 3800
3678 // Empty vector. 3801 // Empty vector.
3679 strings.clear(); 3802 strings.clear();
3680 prefix = FormStructure::FindLongestCommonPrefix(strings); 3803 prefix = FormStructure::FindLongestCommonPrefix(strings);
3681 EXPECT_EQ(ASCIIToUTF16(""), prefix); 3804 EXPECT_EQ(ASCIIToUTF16(""), prefix);
3682 } 3805 }
3683 3806
3684 } // namespace autofill 3807 } // namespace autofill
OLDNEW
« no previous file with comments | « components/autofill/core/browser/form_structure.cc ('k') | components/autofill/core/browser/test_autofill_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698