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

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: 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 4d1812a3e88f58796042e7029f7c07fbefb2335c..701ac61dca5e7ee48c4e4eacfb08d7cdf70d8c1c 100644
--- a/components/autofill/core/browser/form_structure_unittest.cc
+++ b/components/autofill/core/browser/form_structure_unittest.cc
@@ -1646,7 +1646,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 at
+// the in the middle of the form.
Mathieu 2016/02/23 15:23:03 fix comment
sebsg 2016/02/24 18:49:44 Done.
+TEST_F(FormStructureTest, CreditCardNames) {
scoped_ptr<FormStructure> form_structure;
FormData form;
@@ -1683,14 +1685,72 @@ TEST_F(FormStructureTest, CVCCodeClash) {
// Expect the correct number of fields.
ASSERT_EQ(6U, form_structure->field_count());
- ASSERT_EQ(5U, form_structure->autofill_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 not merged.
- EXPECT_EQ(UNKNOWN_TYPE, 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 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.
+// keyword.
+TEST_F(FormStructureTest, CreditCardSplitNames_first) {
Mathieu 2016/02/12 20:53:30 more descriptive name?
sebsg 2016/02/24 18:49:44 Done.
+ 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());
+
+ // Card Number.
+ 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.
+ // 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());
// Expiration Date.
EXPECT_EQ(CREDIT_CARD_EXP_MONTH, form_structure->field(3)->heuristic_type());
// Expiration Year.

Powered by Google App Engine
This is Rietveld 408576698