Chromium Code Reviews| Index: components/autofill/core/browser/personal_data_manager_unittest.cc |
| diff --git a/components/autofill/core/browser/personal_data_manager_unittest.cc b/components/autofill/core/browser/personal_data_manager_unittest.cc |
| index deee27ce5c10984b808879aa3a93d70ac65698e8..86b3e30e0b1947728fdb37b50e9e7e5666b2f054 100644 |
| --- a/components/autofill/core/browser/personal_data_manager_unittest.cc |
| +++ b/components/autofill/core/browser/personal_data_manager_unittest.cc |
| @@ -2138,6 +2138,146 @@ TEST_F(PersonalDataManagerTest, ImportCreditCard_TwoValidCards) { |
| ExpectSameElements(cards, personal_data_->GetCreditCards()); |
| } |
| +// This form has the expiration year as one field with MM/YY. |
| +TEST_F(PersonalDataManagerTest, ImportCreditCard_Month2DigitYearCombination) { |
|
sebsg
2016/07/08 10:01:45
There seems to be a some duplicate code between th
Mathieu
2016/07/08 14:27:05
reused code when possible. I think the struct abst
|
| + FormData form; |
| + FormFieldData field; |
| + test::CreateTestFormField("Name on card:", "name_on_card", "John MMYY", |
| + "text", &field); |
| + form.fields.push_back(field); |
| + test::CreateTestFormField("Card Number:", "card_number", "4111111111111111", |
| + "text", &field); |
| + form.fields.push_back(field); |
| + test::CreateTestFormField("Exp Date:", "exp_date", "05/45", "text", &field); |
| + field.autocomplete_attribute = "cc-exp"; |
| + field.max_length = 5; |
| + form.fields.push_back(field); |
| + |
| + FormStructure form_structure(form); |
| + form_structure.DetermineHeuristicTypes(); |
| + std::unique_ptr<CreditCard> imported_credit_card; |
| + EXPECT_TRUE(ImportCreditCard(form_structure, false, &imported_credit_card)); |
| + ASSERT_TRUE(imported_credit_card); |
| + personal_data_->SaveImportedCreditCard(*imported_credit_card); |
| + |
| + // Verify that the web database has been updated and the notification sent. |
| + EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| + .WillOnce(QuitMainMessageLoop()); |
| + base::MessageLoop::current()->Run(); |
| + |
| + CreditCard expected(base::GenerateGUID(), "https://www.example.com"); |
| + test::SetCreditCardInfo(&expected, "John MMYY", "4111111111111111", "05", |
| + "2045"); |
| + const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); |
| + ASSERT_EQ(1U, results.size()); |
| + EXPECT_EQ(0, expected.Compare(*results[0])); |
| +} |
| + |
| +// This form has the expiration year as one field with MM/YYYY. |
| +TEST_F(PersonalDataManagerTest, ImportCreditCard_Month4DigitYearCombination) { |
| + FormData form; |
| + FormFieldData field; |
| + test::CreateTestFormField("Name on card:", "name_on_card", "John MMYYYY", |
| + "text", &field); |
| + form.fields.push_back(field); |
| + test::CreateTestFormField("Card Number:", "card_number", "4111111111111111", |
| + "text", &field); |
| + form.fields.push_back(field); |
| + test::CreateTestFormField("Exp Date:", "exp_date", "05/2045", "text", &field); |
| + field.autocomplete_attribute = "cc-exp"; |
| + field.max_length = 7; |
| + form.fields.push_back(field); |
| + |
| + FormStructure form_structure(form); |
| + form_structure.DetermineHeuristicTypes(); |
| + std::unique_ptr<CreditCard> imported_credit_card; |
| + EXPECT_TRUE(ImportCreditCard(form_structure, false, &imported_credit_card)); |
| + ASSERT_TRUE(imported_credit_card); |
| + personal_data_->SaveImportedCreditCard(*imported_credit_card); |
| + |
| + // Verify that the web database has been updated and the notification sent. |
| + EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| + .WillOnce(QuitMainMessageLoop()); |
| + base::MessageLoop::current()->Run(); |
| + |
| + CreditCard expected(base::GenerateGUID(), "https://www.example.com"); |
| + test::SetCreditCardInfo(&expected, "John MMYYYY", "4111111111111111", "05", |
| + "2045"); |
| + const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); |
| + ASSERT_EQ(1U, results.size()); |
| + EXPECT_EQ(0, expected.Compare(*results[0])); |
| +} |
| + |
| +// This form has the expiration year as one field with M/YYYY. |
| +TEST_F(PersonalDataManagerTest, ImportCreditCard_1DigitMonth4DigitYear) { |
| + FormData form; |
| + FormFieldData field; |
| + test::CreateTestFormField("Name on card:", "name_on_card", "John MYYYY", |
| + "text", &field); |
| + form.fields.push_back(field); |
| + test::CreateTestFormField("Card Number:", "card_number", "4111111111111111", |
| + "text", &field); |
| + form.fields.push_back(field); |
| + test::CreateTestFormField("Exp Date:", "exp_date", "5/2045", "text", &field); |
| + field.autocomplete_attribute = "cc-exp"; |
| + form.fields.push_back(field); |
| + |
| + FormStructure form_structure(form); |
| + form_structure.DetermineHeuristicTypes(); |
| + std::unique_ptr<CreditCard> imported_credit_card; |
| + EXPECT_TRUE(ImportCreditCard(form_structure, false, &imported_credit_card)); |
| + ASSERT_TRUE(imported_credit_card); |
| + personal_data_->SaveImportedCreditCard(*imported_credit_card); |
| + |
| + // Verify that the web database has been updated and the notification sent. |
| + EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| + .WillOnce(QuitMainMessageLoop()); |
| + base::MessageLoop::current()->Run(); |
| + |
| + CreditCard expected(base::GenerateGUID(), "https://www.example.com"); |
| + test::SetCreditCardInfo(&expected, "John MYYYY", "4111111111111111", "05", |
| + "2045"); |
| + const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); |
| + ASSERT_EQ(1U, results.size()); |
| + EXPECT_EQ(0, expected.Compare(*results[0])); |
| +} |
| + |
| +// This form has the expiration year as a 2-digit field. |
| +TEST_F(PersonalDataManagerTest, ImportCreditCard_2DigitYear) { |
| + FormData form; |
| + FormFieldData field; |
| + test::CreateTestFormField("Name on card:", "name_on_card", "John Smith", |
| + "text", &field); |
| + form.fields.push_back(field); |
| + test::CreateTestFormField("Card Number:", "card_number", "4111111111111111", |
| + "text", &field); |
| + form.fields.push_back(field); |
| + test::CreateTestFormField("Exp Month:", "exp_month", "05", "text", &field); |
| + form.fields.push_back(field); |
| + test::CreateTestFormField("Exp Year:", "exp_year", "45", "text", &field); |
| + field.max_length = 2; |
| + form.fields.push_back(field); |
| + |
| + FormStructure form_structure(form); |
| + form_structure.DetermineHeuristicTypes(); |
| + std::unique_ptr<CreditCard> imported_credit_card; |
| + EXPECT_TRUE(ImportCreditCard(form_structure, false, &imported_credit_card)); |
| + ASSERT_TRUE(imported_credit_card); |
| + personal_data_->SaveImportedCreditCard(*imported_credit_card); |
| + |
| + // Verify that the web database has been updated and the notification sent. |
| + EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| + .WillOnce(QuitMainMessageLoop()); |
| + base::MessageLoop::current()->Run(); |
| + |
| + CreditCard expected(base::GenerateGUID(), "https://www.example.com"); |
| + test::SetCreditCardInfo(&expected, "John Smith", "4111111111111111", "05", |
| + "2045"); |
| + const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); |
| + ASSERT_EQ(1U, results.size()); |
| + EXPECT_EQ(0, expected.Compare(*results[0])); |
| +} |
| + |
| // Tests that a credit card is extracted because it only matches a masked server |
| // card. |
| TEST_F(PersonalDataManagerTest, |