Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 1628 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1639 EXPECT_EQ(ADDRESS_HOME_LINE1, form_structure->field(1)->heuristic_type()); | 1639 EXPECT_EQ(ADDRESS_HOME_LINE1, form_structure->field(1)->heuristic_type()); |
| 1640 // Card Number. | 1640 // Card Number. |
| 1641 EXPECT_EQ(CREDIT_CARD_NUMBER, form_structure->field(2)->heuristic_type()); | 1641 EXPECT_EQ(CREDIT_CARD_NUMBER, form_structure->field(2)->heuristic_type()); |
| 1642 // Expiration Date. | 1642 // Expiration Date. |
| 1643 EXPECT_EQ(CREDIT_CARD_EXP_MONTH, form_structure->field(3)->heuristic_type()); | 1643 EXPECT_EQ(CREDIT_CARD_EXP_MONTH, form_structure->field(3)->heuristic_type()); |
| 1644 // Expiration Year. | 1644 // Expiration Year. |
| 1645 EXPECT_EQ(CREDIT_CARD_EXP_4_DIGIT_YEAR, | 1645 EXPECT_EQ(CREDIT_CARD_EXP_4_DIGIT_YEAR, |
| 1646 form_structure->field(4)->heuristic_type()); | 1646 form_structure->field(4)->heuristic_type()); |
| 1647 } | 1647 } |
| 1648 | 1648 |
| 1649 TEST_F(FormStructureTest, CVCCodeClash) { | 1649 // Tests that the heuristics detect split credit card names if they appear at |
| 1650 // the in the middle of the form. | |
|
Mathieu
2016/02/23 15:23:03
fix comment
sebsg
2016/02/24 18:49:44
Done.
| |
| 1651 TEST_F(FormStructureTest, CreditCardNames) { | |
| 1650 scoped_ptr<FormStructure> form_structure; | 1652 scoped_ptr<FormStructure> form_structure; |
| 1651 FormData form; | 1653 FormData form; |
| 1652 | 1654 |
| 1653 FormFieldData field; | 1655 FormFieldData field; |
| 1654 field.form_control_type = "text"; | 1656 field.form_control_type = "text"; |
| 1655 | 1657 |
| 1656 field.label = ASCIIToUTF16("Card number"); | 1658 field.label = ASCIIToUTF16("Card number"); |
| 1657 field.name = ASCIIToUTF16("ccnumber"); | 1659 field.name = ASCIIToUTF16("ccnumber"); |
| 1658 form.fields.push_back(field); | 1660 form.fields.push_back(field); |
| 1659 | 1661 |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 1676 field.label = ASCIIToUTF16("cvc number"); | 1678 field.label = ASCIIToUTF16("cvc number"); |
| 1677 field.name = ASCIIToUTF16("csc"); | 1679 field.name = ASCIIToUTF16("csc"); |
| 1678 form.fields.push_back(field); | 1680 form.fields.push_back(field); |
| 1679 | 1681 |
| 1680 form_structure.reset(new FormStructure(form)); | 1682 form_structure.reset(new FormStructure(form)); |
| 1681 form_structure->DetermineHeuristicTypes(); | 1683 form_structure->DetermineHeuristicTypes(); |
| 1682 EXPECT_TRUE(form_structure->IsAutofillable()); | 1684 EXPECT_TRUE(form_structure->IsAutofillable()); |
| 1683 | 1685 |
| 1684 // Expect the correct number of fields. | 1686 // Expect the correct number of fields. |
| 1685 ASSERT_EQ(6U, form_structure->field_count()); | 1687 ASSERT_EQ(6U, form_structure->field_count()); |
| 1686 ASSERT_EQ(5U, form_structure->autofill_count()); | 1688 ASSERT_EQ(6U, form_structure->autofill_count()); |
| 1687 | 1689 |
| 1688 // Card Number. | 1690 // Card Number. |
| 1689 EXPECT_EQ(CREDIT_CARD_NUMBER, form_structure->field(0)->heuristic_type()); | 1691 EXPECT_EQ(CREDIT_CARD_NUMBER, form_structure->field(0)->heuristic_type()); |
| 1690 // First name, taken as name on card. | 1692 // First name. |
| 1691 EXPECT_EQ(CREDIT_CARD_NAME, form_structure->field(1)->heuristic_type()); | 1693 EXPECT_EQ(CREDIT_CARD_NAME_FIRST, form_structure->field(1)->heuristic_type()); |
| 1692 // Last name is not merged. | 1694 // Last name. |
| 1693 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(2)->heuristic_type()); | 1695 EXPECT_EQ(CREDIT_CARD_NAME_LAST, form_structure->field(2)->heuristic_type()); |
| 1694 // Expiration Date. | 1696 // Expiration Date. |
| 1695 EXPECT_EQ(CREDIT_CARD_EXP_MONTH, form_structure->field(3)->heuristic_type()); | 1697 EXPECT_EQ(CREDIT_CARD_EXP_MONTH, form_structure->field(3)->heuristic_type()); |
| 1696 // Expiration Year. | 1698 // Expiration Year. |
| 1699 EXPECT_EQ(CREDIT_CARD_EXP_4_DIGIT_YEAR, | |
| 1700 form_structure->field(4)->heuristic_type()); | |
| 1701 // CVC code. | |
| 1702 EXPECT_EQ(CREDIT_CARD_VERIFICATION_CODE, | |
| 1703 form_structure->field(5)->heuristic_type()); | |
| 1704 } | |
| 1705 | |
| 1706 // Tests that the heuristics detect split credit card names if they appear at | |
| 1707 // the beginning of the form. The fist name has to contains some credit card | |
|
Mathieu
2016/02/12 20:53:30
nit:first
sebsg
2016/02/24 18:49:44
Done.
| |
| 1708 // keyword. | |
| 1709 TEST_F(FormStructureTest, CreditCardSplitNames_first) { | |
|
Mathieu
2016/02/12 20:53:30
more descriptive name?
sebsg
2016/02/24 18:49:44
Done.
| |
| 1710 scoped_ptr<FormStructure> form_structure; | |
| 1711 FormData form; | |
| 1712 | |
| 1713 FormFieldData field; | |
| 1714 field.form_control_type = "text"; | |
| 1715 | |
| 1716 field.label = ASCIIToUTF16("Cardholder Name"); | |
| 1717 field.name = ASCIIToUTF16("cc_first_name"); | |
| 1718 form.fields.push_back(field); | |
| 1719 | |
| 1720 field.label = ASCIIToUTF16("Last name"); | |
| 1721 field.name = ASCIIToUTF16("last_name"); | |
| 1722 form.fields.push_back(field); | |
| 1723 | |
| 1724 field.label = ASCIIToUTF16("Card number"); | |
| 1725 field.name = ASCIIToUTF16("ccnumber"); | |
| 1726 form.fields.push_back(field); | |
| 1727 | |
| 1728 field.label = ASCIIToUTF16("Expiration date"); | |
| 1729 field.name = ASCIIToUTF16("ccexpiresmonth"); | |
| 1730 form.fields.push_back(field); | |
| 1731 | |
| 1732 field.label = base::string16(); | |
| 1733 field.name = ASCIIToUTF16("ccexpiresyear"); | |
| 1734 form.fields.push_back(field); | |
| 1735 | |
| 1736 field.label = ASCIIToUTF16("cvc number"); | |
| 1737 field.name = ASCIIToUTF16("csc"); | |
| 1738 form.fields.push_back(field); | |
| 1739 | |
| 1740 form_structure.reset(new FormStructure(form)); | |
| 1741 form_structure->DetermineHeuristicTypes(); | |
| 1742 EXPECT_TRUE(form_structure->IsAutofillable()); | |
| 1743 | |
| 1744 // Expect the correct number of fields. | |
| 1745 ASSERT_EQ(6U, form_structure->field_count()); | |
| 1746 ASSERT_EQ(6U, form_structure->autofill_count()); | |
| 1747 | |
| 1748 // Card Number. | |
| 1749 EXPECT_EQ(CREDIT_CARD_NUMBER, form_structure->field(2)->heuristic_type()); | |
|
Mathieu
2016/02/12 20:53:30
nit: can they be in order?
sebsg
2016/02/24 18:49:44
Done.
| |
| 1750 // First name. | |
| 1751 EXPECT_EQ(CREDIT_CARD_NAME_FIRST, form_structure->field(0)->heuristic_type()); | |
| 1752 // Last name. | |
| 1753 EXPECT_EQ(CREDIT_CARD_NAME_LAST, form_structure->field(1)->heuristic_type()); | |
| 1754 // Expiration Date. | |
| 1755 EXPECT_EQ(CREDIT_CARD_EXP_MONTH, form_structure->field(3)->heuristic_type()); | |
| 1756 // Expiration Year. | |
| 1697 EXPECT_EQ(CREDIT_CARD_EXP_4_DIGIT_YEAR, | 1757 EXPECT_EQ(CREDIT_CARD_EXP_4_DIGIT_YEAR, |
| 1698 form_structure->field(4)->heuristic_type()); | 1758 form_structure->field(4)->heuristic_type()); |
| 1699 // CVC code. | 1759 // CVC code. |
| 1700 EXPECT_EQ(CREDIT_CARD_VERIFICATION_CODE, | 1760 EXPECT_EQ(CREDIT_CARD_VERIFICATION_CODE, |
| 1701 form_structure->field(5)->heuristic_type()); | 1761 form_structure->field(5)->heuristic_type()); |
| 1702 } | 1762 } |
| 1703 | 1763 |
| 1704 TEST_F(FormStructureTest, EncodeQueryRequest) { | 1764 TEST_F(FormStructureTest, EncodeQueryRequest) { |
| 1705 FormData form; | 1765 FormData form; |
| 1706 | 1766 |
| (...skipping 1734 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3441 prefix = FormStructure::FindLongestCommonPrefix(strings); | 3501 prefix = FormStructure::FindLongestCommonPrefix(strings); |
| 3442 EXPECT_EQ(ASCIIToUTF16("123456789"), prefix.as_string()); | 3502 EXPECT_EQ(ASCIIToUTF16("123456789"), prefix.as_string()); |
| 3443 | 3503 |
| 3444 // Empty vector. | 3504 // Empty vector. |
| 3445 strings.clear(); | 3505 strings.clear(); |
| 3446 prefix = FormStructure::FindLongestCommonPrefix(strings); | 3506 prefix = FormStructure::FindLongestCommonPrefix(strings); |
| 3447 EXPECT_EQ(ASCIIToUTF16(""), prefix.as_string()); | 3507 EXPECT_EQ(ASCIIToUTF16(""), prefix.as_string()); |
| 3448 } | 3508 } |
| 3449 | 3509 |
| 3450 } // namespace autofill | 3510 } // namespace autofill |
| OLD | NEW |