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

Unified Diff: components/autofill/core/browser/form_structure_unittest.cc

Issue 1694443004: [Autofill] Add credit card first and last name heuristics predictions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 4 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: components/autofill/core/browser/form_structure_unittest.cc
diff --git a/components/autofill/core/browser/form_structure_unittest.cc b/components/autofill/core/browser/form_structure_unittest.cc
index 4162781644bf8abb77321aecd8f94d85cf88bb62..fcf555a5a9d563762aee4a0bdd2e78cf650b5d16 100644
--- a/components/autofill/core/browser/form_structure_unittest.cc
+++ b/components/autofill/core/browser/form_structure_unittest.cc
@@ -1280,7 +1280,7 @@ TEST_F(FormStructureTest, HeuristicsCreditCardInfo) {
ASSERT_EQ(5U, form_structure->autofill_count());
// Credit card name.
- EXPECT_EQ(CREDIT_CARD_NAME, form_structure->field(0)->heuristic_type());
+ EXPECT_EQ(CREDIT_CARD_NAME_FULL, form_structure->field(0)->heuristic_type());
// Credit card number.
EXPECT_EQ(CREDIT_CARD_NUMBER, form_structure->field(1)->heuristic_type());
// Credit card expiration month.
@@ -1340,7 +1340,7 @@ TEST_F(FormStructureTest, HeuristicsCreditCardInfoWithUnknownCardField) {
ASSERT_EQ(5U, form_structure->autofill_count());
// Credit card name.
- EXPECT_EQ(CREDIT_CARD_NAME, form_structure->field(0)->heuristic_type());
+ EXPECT_EQ(CREDIT_CARD_NAME_FULL, form_structure->field(0)->heuristic_type());
// Credit card type. This is an unknown type but related to the credit card.
EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(1)->heuristic_type());
// Credit card number.
@@ -1703,7 +1703,7 @@ TEST_F(FormStructureTest, HeuristicsInfernoCC) {
EXPECT_EQ(5U, form_structure->autofill_count());
// Name on Card.
- EXPECT_EQ(CREDIT_CARD_NAME, form_structure->field(0)->heuristic_type());
+ EXPECT_EQ(CREDIT_CARD_NAME_FULL, form_structure->field(0)->heuristic_type());
// Address.
EXPECT_EQ(ADDRESS_HOME_LINE1, form_structure->field(1)->heuristic_type());
// Card Number.
@@ -1715,7 +1715,9 @@ TEST_F(FormStructureTest, HeuristicsInfernoCC) {
form_structure->field(4)->heuristic_type());
}
-TEST_F(FormStructureTest, CVCCodeClash) {
+// Tests that the heuristics detect split credit card names if they appear in
+// the middle of the form.
+TEST_F(FormStructureTest, HeuristicsInferCCNames_NamesNotFirst) {
scoped_ptr<FormStructure> form_structure;
FormData form;
@@ -1751,15 +1753,73 @@ TEST_F(FormStructureTest, CVCCodeClash) {
EXPECT_TRUE(form_structure->IsAutofillable());
// Expect the correct number of fields.
- EXPECT_EQ(6U, form_structure->field_count());
- EXPECT_EQ(6U, form_structure->autofill_count());
+ ASSERT_EQ(6U, form_structure->field_count());
+ ASSERT_EQ(6U, form_structure->autofill_count());
// Card Number.
EXPECT_EQ(CREDIT_CARD_NUMBER, form_structure->field(0)->heuristic_type());
- // First name, taken as name on card.
- EXPECT_EQ(CREDIT_CARD_NAME, form_structure->field(1)->heuristic_type());
- // Last name is picked up by the name parser.
- EXPECT_EQ(NAME_LAST, form_structure->field(2)->heuristic_type());
+ // First name.
+ EXPECT_EQ(CREDIT_CARD_NAME_FIRST, form_structure->field(1)->heuristic_type());
+ // Last name.
+ EXPECT_EQ(CREDIT_CARD_NAME_LAST, form_structure->field(2)->heuristic_type());
+ // Expiration Date.
+ EXPECT_EQ(CREDIT_CARD_EXP_MONTH, form_structure->field(3)->heuristic_type());
+ // Expiration Year.
+ EXPECT_EQ(CREDIT_CARD_EXP_4_DIGIT_YEAR,
+ form_structure->field(4)->heuristic_type());
+ // CVC code.
+ EXPECT_EQ(CREDIT_CARD_VERIFICATION_CODE,
+ form_structure->field(5)->heuristic_type());
+}
+
+// Tests that the heuristics detect split credit card names if they appear at
+// the beginning of the form. The first name has to contains some credit card
+// keyword.
+TEST_F(FormStructureTest, HeuristicsInferCCNames_NamesFirst) {
+ scoped_ptr<FormStructure> form_structure;
+ FormData form;
+
+ FormFieldData field;
+ field.form_control_type = "text";
+
+ field.label = ASCIIToUTF16("Cardholder Name");
+ field.name = ASCIIToUTF16("cc_first_name");
+ form.fields.push_back(field);
+
+ field.label = ASCIIToUTF16("Last name");
+ field.name = ASCIIToUTF16("last_name");
+ form.fields.push_back(field);
+
+ field.label = ASCIIToUTF16("Card number");
+ field.name = ASCIIToUTF16("ccnumber");
+ form.fields.push_back(field);
+
+ field.label = ASCIIToUTF16("Expiration date");
+ field.name = ASCIIToUTF16("ccexpiresmonth");
+ form.fields.push_back(field);
+
+ field.label = base::string16();
+ field.name = ASCIIToUTF16("ccexpiresyear");
+ form.fields.push_back(field);
+
+ field.label = ASCIIToUTF16("cvc number");
+ field.name = ASCIIToUTF16("csc");
+ form.fields.push_back(field);
+
+ form_structure.reset(new FormStructure(form));
+ form_structure->DetermineHeuristicTypes();
+ EXPECT_TRUE(form_structure->IsAutofillable());
+
+ // Expect the correct number of fields.
+ ASSERT_EQ(6U, form_structure->field_count());
+ ASSERT_EQ(6U, form_structure->autofill_count());
+
+ // First name.
+ EXPECT_EQ(CREDIT_CARD_NAME_FIRST, form_structure->field(0)->heuristic_type());
+ // Last name.
+ EXPECT_EQ(CREDIT_CARD_NAME_LAST, form_structure->field(1)->heuristic_type());
+ // Card Number.
+ EXPECT_EQ(CREDIT_CARD_NUMBER, form_structure->field(2)->heuristic_type());
// Expiration Date.
EXPECT_EQ(CREDIT_CARD_EXP_MONTH, form_structure->field(3)->heuristic_type());
// Expiration Year.
@@ -2753,7 +2813,7 @@ TEST_F(FormStructureTest, CheckDataPresence) {
// datapresent should be "0000000000001fc0" == trimmmed(0x0000000000001fc0) ==
// 0b0000000000000000000000000000000000000000000000000001111111000000
// The set bits are:
- // 51 == CREDIT_CARD_NAME
+ // 51 == CREDIT_CARD_NAME_FULL
// 52 == CREDIT_CARD_NUMBER
// 53 == CREDIT_CARD_EXP_MONTH
// 54 == CREDIT_CARD_EXP_2_DIGIT_YEAR
@@ -2761,7 +2821,7 @@ TEST_F(FormStructureTest, CheckDataPresence) {
// 56 == CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR
// 57 == CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR
available_field_types.clear();
- available_field_types.insert(CREDIT_CARD_NAME);
+ available_field_types.insert(CREDIT_CARD_NAME_FULL);
available_field_types.insert(CREDIT_CARD_NUMBER);
available_field_types.insert(CREDIT_CARD_EXP_MONTH);
available_field_types.insert(CREDIT_CARD_EXP_2_DIGIT_YEAR);
@@ -2801,7 +2861,7 @@ TEST_F(FormStructureTest, CheckDataPresence) {
// 34 == ADDRESS_HOME_STATE
// 35 == ADDRESS_HOME_ZIP
// 36 == ADDRESS_HOME_COUNTRY
- // 51 == CREDIT_CARD_NAME
+ // 51 == CREDIT_CARD_NAME_FULL
// 52 == CREDIT_CARD_NUMBER
// 53 == CREDIT_CARD_EXP_MONTH
// 54 == CREDIT_CARD_EXP_2_DIGIT_YEAR
@@ -2827,7 +2887,7 @@ TEST_F(FormStructureTest, CheckDataPresence) {
available_field_types.insert(ADDRESS_HOME_STATE);
available_field_types.insert(ADDRESS_HOME_ZIP);
available_field_types.insert(ADDRESS_HOME_COUNTRY);
- available_field_types.insert(CREDIT_CARD_NAME);
+ available_field_types.insert(CREDIT_CARD_NAME_FULL);
available_field_types.insert(CREDIT_CARD_NUMBER);
available_field_types.insert(CREDIT_CARD_EXP_MONTH);
available_field_types.insert(CREDIT_CARD_EXP_2_DIGIT_YEAR);
« no previous file with comments | « components/autofill/core/browser/form_structure.cc ('k') | components/autofill/core/browser/payments/payments_client.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698