| 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/personal_data_manager.h" | 5 #include "components/autofill/core/browser/personal_data_manager.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <list> | 10 #include <list> |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 // different: two are from different companies and the third doesn't have a | 253 // different: two are from different companies and the third doesn't have a |
| 254 // number. All three have different owners and credit card number. This allows | 254 // number. All three have different owners and credit card number. This allows |
| 255 // to test the suggestions based on name as well as on credit card number. | 255 // to test the suggestions based on name as well as on credit card number. |
| 256 void SetupReferenceLocalCreditCards() { | 256 void SetupReferenceLocalCreditCards() { |
| 257 ASSERT_EQ(0U, personal_data_->GetCreditCards().size()); | 257 ASSERT_EQ(0U, personal_data_->GetCreditCards().size()); |
| 258 | 258 |
| 259 CreditCard credit_card0("287151C8-6AB1-487C-9095-28E80BE5DA15", | 259 CreditCard credit_card0("287151C8-6AB1-487C-9095-28E80BE5DA15", |
| 260 "https://www.example.com"); | 260 "https://www.example.com"); |
| 261 test::SetCreditCardInfo(&credit_card0, "Clyde Barrow", | 261 test::SetCreditCardInfo(&credit_card0, "Clyde Barrow", |
| 262 "347666888555" /* American Express */, "04", | 262 "347666888555" /* American Express */, "04", |
| 263 "3999"); | 263 "2999"); |
| 264 credit_card0.set_use_count(3); | 264 credit_card0.set_use_count(3); |
| 265 credit_card0.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(1)); | 265 credit_card0.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(1)); |
| 266 personal_data_->AddCreditCard(credit_card0); | 266 personal_data_->AddCreditCard(credit_card0); |
| 267 | 267 |
| 268 CreditCard credit_card1("1141084B-72D7-4B73-90CF-3D6AC154673B", | 268 CreditCard credit_card1("1141084B-72D7-4B73-90CF-3D6AC154673B", |
| 269 "https://www.example.com"); | 269 "https://www.example.com"); |
| 270 credit_card1.set_use_count(300); | 270 credit_card1.set_use_count(300); |
| 271 credit_card1.set_use_date(base::Time::Now() - | 271 credit_card1.set_use_date(base::Time::Now() - |
| 272 base::TimeDelta::FromDays(10)); | 272 base::TimeDelta::FromDays(10)); |
| 273 test::SetCreditCardInfo(&credit_card1, "John Dillinger", | 273 test::SetCreditCardInfo(&credit_card1, "John Dillinger", |
| 274 "423456789012" /* Visa */, "01", "2999"); | 274 "423456789012" /* Visa */, "01", "2999"); |
| 275 personal_data_->AddCreditCard(credit_card1); | 275 personal_data_->AddCreditCard(credit_card1); |
| 276 | 276 |
| 277 CreditCard credit_card2("002149C1-EE28-4213-A3B9-DA243FFF021B", | 277 CreditCard credit_card2("002149C1-EE28-4213-A3B9-DA243FFF021B", |
| 278 "https://www.example.com"); | 278 "https://www.example.com"); |
| 279 credit_card2.set_use_count(1); | 279 credit_card2.set_use_count(1); |
| 280 credit_card2.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(1)); | 280 credit_card2.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(1)); |
| 281 test::SetCreditCardInfo(&credit_card2, "Bonnie Parker", | 281 test::SetCreditCardInfo(&credit_card2, "Bonnie Parker", |
| 282 "518765432109" /* Mastercard */, "12", "3999"); | 282 "518765432109" /* Mastercard */, "12", "2999"); |
| 283 personal_data_->AddCreditCard(credit_card2); | 283 personal_data_->AddCreditCard(credit_card2); |
| 284 | 284 |
| 285 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 285 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 286 .WillOnce(QuitMainMessageLoop()); | 286 .WillOnce(QuitMainMessageLoop()); |
| 287 base::RunLoop().Run(); | 287 base::RunLoop().Run(); |
| 288 | 288 |
| 289 ASSERT_EQ(3U, personal_data_->GetCreditCards().size()); | 289 ASSERT_EQ(3U, personal_data_->GetCreditCards().size()); |
| 290 } | 290 } |
| 291 | 291 |
| 292 // Helper methods that simply forward the call to the private member (to avoid | 292 // Helper methods that simply forward the call to the private member (to avoid |
| (...skipping 23 matching lines...) Expand all Loading... |
| 316 std::map<std::string, std::string> params; | 316 std::map<std::string, std::string> params; |
| 317 params[kFrecencyFieldTrialLimitParam] = limit_param; | 317 params[kFrecencyFieldTrialLimitParam] = limit_param; |
| 318 variations::AssociateVariationParams(kFrecencyFieldTrialName, "LimitToN", | 318 variations::AssociateVariationParams(kFrecencyFieldTrialName, "LimitToN", |
| 319 params); | 319 params); |
| 320 | 320 |
| 321 field_trial_ = base::FieldTrialList::CreateFieldTrial( | 321 field_trial_ = base::FieldTrialList::CreateFieldTrial( |
| 322 kFrecencyFieldTrialName, "LimitToN"); | 322 kFrecencyFieldTrialName, "LimitToN"); |
| 323 field_trial_->group(); | 323 field_trial_->group(); |
| 324 } | 324 } |
| 325 | 325 |
| 326 void SubmitFormAndExpectImportedCardWithData(const FormData& form, |
| 327 const char* exp_name, |
| 328 const char* exp_cc_num, |
| 329 const char* exp_cc_month, |
| 330 const char* exp_cc_year) { |
| 331 FormStructure form_structure(form); |
| 332 form_structure.DetermineHeuristicTypes(); |
| 333 std::unique_ptr<CreditCard> imported_credit_card; |
| 334 EXPECT_TRUE(ImportCreditCard(form_structure, false, &imported_credit_card)); |
| 335 ASSERT_TRUE(imported_credit_card); |
| 336 personal_data_->SaveImportedCreditCard(*imported_credit_card); |
| 337 |
| 338 // Verify that the web database has been updated and the notification sent. |
| 339 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 340 .WillOnce(QuitMainMessageLoop()); |
| 341 base::MessageLoop::current()->Run(); |
| 342 |
| 343 CreditCard expected(base::GenerateGUID(), "https://www.example.com"); |
| 344 test::SetCreditCardInfo(&expected, exp_name, exp_cc_num, exp_cc_month, |
| 345 exp_cc_year); |
| 346 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); |
| 347 ASSERT_EQ(1U, results.size()); |
| 348 EXPECT_EQ(0, expected.Compare(*results[0])); |
| 349 } |
| 350 |
| 326 // The temporary directory should be deleted at the end to ensure that | 351 // The temporary directory should be deleted at the end to ensure that |
| 327 // files are not used anymore and deletion succeeds. | 352 // files are not used anymore and deletion succeeds. |
| 328 base::ScopedTempDir temp_dir_; | 353 base::ScopedTempDir temp_dir_; |
| 329 base::MessageLoopForUI message_loop_; | 354 base::MessageLoopForUI message_loop_; |
| 330 std::unique_ptr<PrefService> prefs_; | 355 std::unique_ptr<PrefService> prefs_; |
| 331 std::unique_ptr<AccountTrackerService> account_tracker_; | 356 std::unique_ptr<AccountTrackerService> account_tracker_; |
| 332 std::unique_ptr<FakeSigninManagerBase> signin_manager_; | 357 std::unique_ptr<FakeSigninManagerBase> signin_manager_; |
| 333 std::unique_ptr<TestSigninClient> signin_client_; | 358 std::unique_ptr<TestSigninClient> signin_client_; |
| 334 scoped_refptr<AutofillWebDataService> autofill_database_service_; | 359 scoped_refptr<AutofillWebDataService> autofill_database_service_; |
| 335 scoped_refptr<WebDatabaseService> web_database_; | 360 scoped_refptr<WebDatabaseService> web_database_; |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 522 // Verify that we've loaded the profiles from the web database. | 547 // Verify that we've loaded the profiles from the web database. |
| 523 ExpectSameElements(profiles, personal_data_->GetProfiles()); | 548 ExpectSameElements(profiles, personal_data_->GetProfiles()); |
| 524 } | 549 } |
| 525 | 550 |
| 526 TEST_F(PersonalDataManagerTest, AddUpdateRemoveCreditCards) { | 551 TEST_F(PersonalDataManagerTest, AddUpdateRemoveCreditCards) { |
| 527 CreditCard credit_card0(base::GenerateGUID(), "https://www.example.com"); | 552 CreditCard credit_card0(base::GenerateGUID(), "https://www.example.com"); |
| 528 test::SetCreditCardInfo(&credit_card0, | 553 test::SetCreditCardInfo(&credit_card0, |
| 529 "John Dillinger", "423456789012" /* Visa */, "01", "2999"); | 554 "John Dillinger", "423456789012" /* Visa */, "01", "2999"); |
| 530 | 555 |
| 531 CreditCard credit_card1(base::GenerateGUID(), "https://www.example.com"); | 556 CreditCard credit_card1(base::GenerateGUID(), "https://www.example.com"); |
| 532 test::SetCreditCardInfo(&credit_card1, | 557 test::SetCreditCardInfo(&credit_card1, "Bonnie Parker", |
| 533 "Bonnie Parker", "518765432109" /* Mastercard */, "12", "3999"); | 558 "518765432109" /* Mastercard */, "12", "2999"); |
| 534 | 559 |
| 535 CreditCard credit_card2(base::GenerateGUID(), "https://www.example.com"); | 560 CreditCard credit_card2(base::GenerateGUID(), "https://www.example.com"); |
| 536 test::SetCreditCardInfo(&credit_card2, | 561 test::SetCreditCardInfo(&credit_card2, "Clyde Barrow", |
| 537 "Clyde Barrow", "347666888555" /* American Express */, "04", "3999"); | 562 "347666888555" /* American Express */, "04", "2999"); |
| 538 | 563 |
| 539 // Add two test credit cards to the database. | 564 // Add two test credit cards to the database. |
| 540 personal_data_->AddCreditCard(credit_card0); | 565 personal_data_->AddCreditCard(credit_card0); |
| 541 personal_data_->AddCreditCard(credit_card1); | 566 personal_data_->AddCreditCard(credit_card1); |
| 542 | 567 |
| 543 // Verify that the web database has been updated and the notification sent. | 568 // Verify that the web database has been updated and the notification sent. |
| 544 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 569 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 545 .WillOnce(QuitMainMessageLoop()); | 570 .WillOnce(QuitMainMessageLoop()); |
| 546 base::RunLoop().Run(); | 571 base::RunLoop().Run(); |
| 547 | 572 |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 686 EXPECT_FALSE(base::CommandLine::ForCurrentProcess()->HasSwitch( | 711 EXPECT_FALSE(base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 687 switches::kDisableOfferStoreUnmaskedWalletCards)); | 712 switches::kDisableOfferStoreUnmaskedWalletCards)); |
| 688 #else | 713 #else |
| 689 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 714 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 690 switches::kDisableOfferStoreUnmaskedWalletCards); | 715 switches::kDisableOfferStoreUnmaskedWalletCards); |
| 691 #endif | 716 #endif |
| 692 | 717 |
| 693 std::vector<CreditCard> server_cards; | 718 std::vector<CreditCard> server_cards; |
| 694 server_cards.push_back(CreditCard(CreditCard::FULL_SERVER_CARD, "c789")); | 719 server_cards.push_back(CreditCard(CreditCard::FULL_SERVER_CARD, "c789")); |
| 695 test::SetCreditCardInfo(&server_cards.back(), "Clyde Barrow", | 720 test::SetCreditCardInfo(&server_cards.back(), "Clyde Barrow", |
| 696 "347666888555" /* American Express */, "04", "3999"); | 721 "347666888555" /* American Express */, "04", "2999"); |
| 697 test::SetServerCreditCards(autofill_table_, server_cards); | 722 test::SetServerCreditCards(autofill_table_, server_cards); |
| 698 personal_data_->Refresh(); | 723 personal_data_->Refresh(); |
| 699 | 724 |
| 700 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 725 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 701 .WillOnce(QuitMainMessageLoop()); | 726 .WillOnce(QuitMainMessageLoop()); |
| 702 base::RunLoop().Run(); | 727 base::RunLoop().Run(); |
| 703 | 728 |
| 704 ASSERT_EQ(1U, personal_data_->GetCreditCards().size()); | 729 ASSERT_EQ(1U, personal_data_->GetCreditCards().size()); |
| 705 EXPECT_EQ(CreditCard::MASKED_SERVER_CARD, | 730 EXPECT_EQ(CreditCard::MASKED_SERVER_CARD, |
| 706 personal_data_->GetCreditCards()[0]->record_type()); | 731 personal_data_->GetCreditCards()[0]->record_type()); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 721 EnableWalletCardImport(); | 746 EnableWalletCardImport(); |
| 722 | 747 |
| 723 std::vector<CreditCard> server_cards; | 748 std::vector<CreditCard> server_cards; |
| 724 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "a123")); | 749 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "a123")); |
| 725 test::SetCreditCardInfo(&server_cards.back(), "John Dillinger", | 750 test::SetCreditCardInfo(&server_cards.back(), "John Dillinger", |
| 726 "9012" /* Visa */, "01", "2999"); | 751 "9012" /* Visa */, "01", "2999"); |
| 727 server_cards.back().SetTypeForMaskedCard(kVisaCard); | 752 server_cards.back().SetTypeForMaskedCard(kVisaCard); |
| 728 | 753 |
| 729 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "b456")); | 754 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "b456")); |
| 730 test::SetCreditCardInfo(&server_cards.back(), "Bonnie Parker", | 755 test::SetCreditCardInfo(&server_cards.back(), "Bonnie Parker", |
| 731 "2109" /* Mastercard */, "12", "3999"); | 756 "2109" /* Mastercard */, "12", "2999"); |
| 732 server_cards.back().SetTypeForMaskedCard(kMasterCard); | 757 server_cards.back().SetTypeForMaskedCard(kMasterCard); |
| 733 | 758 |
| 734 server_cards.push_back(CreditCard(CreditCard::FULL_SERVER_CARD, "c789")); | 759 server_cards.push_back(CreditCard(CreditCard::FULL_SERVER_CARD, "c789")); |
| 735 test::SetCreditCardInfo(&server_cards.back(), "Clyde Barrow", | 760 test::SetCreditCardInfo(&server_cards.back(), "Clyde Barrow", |
| 736 "347666888555" /* American Express */, "04", "3999"); | 761 "347666888555" /* American Express */, "04", "2999"); |
| 737 | 762 |
| 738 test::SetServerCreditCards(autofill_table_, server_cards); | 763 test::SetServerCreditCards(autofill_table_, server_cards); |
| 739 personal_data_->Refresh(); | 764 personal_data_->Refresh(); |
| 740 | 765 |
| 741 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 766 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 742 .WillOnce(QuitMainMessageLoop()); | 767 .WillOnce(QuitMainMessageLoop()); |
| 743 base::RunLoop().Run(); | 768 base::RunLoop().Run(); |
| 744 | 769 |
| 745 ASSERT_EQ(3U, personal_data_->GetCreditCards().size()); | 770 ASSERT_EQ(3U, personal_data_->GetCreditCards().size()); |
| 746 | 771 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 797 test::SetProfileInfo(&profile1, | 822 test::SetProfileInfo(&profile1, |
| 798 "Josephine", "Alicia", "Saenz", | 823 "Josephine", "Alicia", "Saenz", |
| 799 "joewayne@me.xyz", "Fox", "903 Apple Ct.", NULL, "Orlando", "FL", "32801", | 824 "joewayne@me.xyz", "Fox", "903 Apple Ct.", NULL, "Orlando", "FL", "32801", |
| 800 "US", "19482937549"); | 825 "US", "19482937549"); |
| 801 | 826 |
| 802 CreditCard credit_card0(base::GenerateGUID(), "https://www.example.com"); | 827 CreditCard credit_card0(base::GenerateGUID(), "https://www.example.com"); |
| 803 test::SetCreditCardInfo(&credit_card0, | 828 test::SetCreditCardInfo(&credit_card0, |
| 804 "John Dillinger", "423456789012" /* Visa */, "01", "2999"); | 829 "John Dillinger", "423456789012" /* Visa */, "01", "2999"); |
| 805 | 830 |
| 806 CreditCard credit_card1(base::GenerateGUID(), "https://www.example.com"); | 831 CreditCard credit_card1(base::GenerateGUID(), "https://www.example.com"); |
| 807 test::SetCreditCardInfo(&credit_card1, | 832 test::SetCreditCardInfo(&credit_card1, "Bonnie Parker", |
| 808 "Bonnie Parker", "518765432109" /* Mastercard */, "12", "3999"); | 833 "518765432109" /* Mastercard */, "12", "2999"); |
| 809 | 834 |
| 810 // Add two test profiles to the database. | 835 // Add two test profiles to the database. |
| 811 personal_data_->AddProfile(profile0); | 836 personal_data_->AddProfile(profile0); |
| 812 personal_data_->AddProfile(profile1); | 837 personal_data_->AddProfile(profile1); |
| 813 | 838 |
| 814 // Verify that the web database has been updated and the notification sent. | 839 // Verify that the web database has been updated and the notification sent. |
| 815 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 840 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 816 .WillOnce(QuitMainMessageLoop()); | 841 .WillOnce(QuitMainMessageLoop()); |
| 817 base::RunLoop().Run(); | 842 base::RunLoop().Run(); |
| 818 | 843 |
| (...skipping 1230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2049 "2999"); | 2074 "2999"); |
| 2050 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); | 2075 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); |
| 2051 ASSERT_EQ(1U, results.size()); | 2076 ASSERT_EQ(1U, results.size()); |
| 2052 EXPECT_EQ(0, expected.Compare(*results[0])); | 2077 EXPECT_EQ(0, expected.Compare(*results[0])); |
| 2053 } | 2078 } |
| 2054 | 2079 |
| 2055 // Tests that an invalid credit card is not extracted. | 2080 // Tests that an invalid credit card is not extracted. |
| 2056 TEST_F(PersonalDataManagerTest, ImportCreditCard_Invalid) { | 2081 TEST_F(PersonalDataManagerTest, ImportCreditCard_Invalid) { |
| 2057 FormData form; | 2082 FormData form; |
| 2058 AddFullCreditCardForm(&form, "Jim Johansen", "1000000000000000", "02", | 2083 AddFullCreditCardForm(&form, "Jim Johansen", "1000000000000000", "02", |
| 2059 "3999"); | 2084 "2999"); |
| 2060 | 2085 |
| 2061 FormStructure form_structure(form); | 2086 FormStructure form_structure(form); |
| 2062 form_structure.DetermineHeuristicTypes(); | 2087 form_structure.DetermineHeuristicTypes(); |
| 2063 std::unique_ptr<CreditCard> imported_credit_card; | 2088 std::unique_ptr<CreditCard> imported_credit_card; |
| 2064 EXPECT_FALSE(ImportCreditCard(form_structure, false, &imported_credit_card)); | 2089 EXPECT_FALSE(ImportCreditCard(form_structure, false, &imported_credit_card)); |
| 2065 ASSERT_FALSE(imported_credit_card); | 2090 ASSERT_FALSE(imported_credit_card); |
| 2066 | 2091 |
| 2067 // Since no refresh is expected, reload the data from the database to make | 2092 // Since no refresh is expected, reload the data from the database to make |
| 2068 // sure no changes were written out. | 2093 // sure no changes were written out. |
| 2069 ResetPersonalDataManager(USER_MODE_NORMAL); | 2094 ResetPersonalDataManager(USER_MODE_NORMAL); |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2133 | 2158 |
| 2134 CreditCard expected(base::GenerateGUID(), "https://www.example.com"); | 2159 CreditCard expected(base::GenerateGUID(), "https://www.example.com"); |
| 2135 test::SetCreditCardInfo(&expected, "Biggie Smalls", "4111111111111111", "01", | 2160 test::SetCreditCardInfo(&expected, "Biggie Smalls", "4111111111111111", "01", |
| 2136 "2999"); | 2161 "2999"); |
| 2137 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); | 2162 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); |
| 2138 ASSERT_EQ(1U, results.size()); | 2163 ASSERT_EQ(1U, results.size()); |
| 2139 EXPECT_EQ(0, expected.Compare(*results[0])); | 2164 EXPECT_EQ(0, expected.Compare(*results[0])); |
| 2140 | 2165 |
| 2141 // Add a second different valid credit card. | 2166 // Add a second different valid credit card. |
| 2142 FormData form2; | 2167 FormData form2; |
| 2143 AddFullCreditCardForm(&form2, "", "5500 0000 0000 0004", "02", "3999"); | 2168 AddFullCreditCardForm(&form2, "", "5500 0000 0000 0004", "02", "2999"); |
| 2144 | 2169 |
| 2145 FormStructure form_structure2(form2); | 2170 FormStructure form_structure2(form2); |
| 2146 form_structure2.DetermineHeuristicTypes(); | 2171 form_structure2.DetermineHeuristicTypes(); |
| 2147 std::unique_ptr<CreditCard> imported_credit_card2; | 2172 std::unique_ptr<CreditCard> imported_credit_card2; |
| 2148 EXPECT_TRUE(ImportCreditCard(form_structure2, false, &imported_credit_card2)); | 2173 EXPECT_TRUE(ImportCreditCard(form_structure2, false, &imported_credit_card2)); |
| 2149 ASSERT_TRUE(imported_credit_card2); | 2174 ASSERT_TRUE(imported_credit_card2); |
| 2150 personal_data_->SaveImportedCreditCard(*imported_credit_card2); | 2175 personal_data_->SaveImportedCreditCard(*imported_credit_card2); |
| 2151 | 2176 |
| 2152 // Verify that the web database has been updated and the notification sent. | 2177 // Verify that the web database has been updated and the notification sent. |
| 2153 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 2178 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 2154 .WillOnce(QuitMainMessageLoop()); | 2179 .WillOnce(QuitMainMessageLoop()); |
| 2155 base::RunLoop().Run(); | 2180 base::RunLoop().Run(); |
| 2156 | 2181 |
| 2157 CreditCard expected2(base::GenerateGUID(), "https://www.example.com"); | 2182 CreditCard expected2(base::GenerateGUID(), "https://www.example.com"); |
| 2158 test::SetCreditCardInfo(&expected2, "", "5500000000000004", "02", "3999"); | 2183 test::SetCreditCardInfo(&expected2, "", "5500000000000004", "02", "2999"); |
| 2159 std::vector<CreditCard*> cards; | 2184 std::vector<CreditCard*> cards; |
| 2160 cards.push_back(&expected); | 2185 cards.push_back(&expected); |
| 2161 cards.push_back(&expected2); | 2186 cards.push_back(&expected2); |
| 2162 ExpectSameElements(cards, personal_data_->GetCreditCards()); | 2187 ExpectSameElements(cards, personal_data_->GetCreditCards()); |
| 2163 } | 2188 } |
| 2164 | 2189 |
| 2190 // This form has the expiration year as one field with MM/YY. |
| 2191 TEST_F(PersonalDataManagerTest, ImportCreditCard_Month2DigitYearCombination) { |
| 2192 FormData form; |
| 2193 FormFieldData field; |
| 2194 test::CreateTestFormField("Name on card:", "name_on_card", "John MMYY", |
| 2195 "text", &field); |
| 2196 form.fields.push_back(field); |
| 2197 test::CreateTestFormField("Card Number:", "card_number", "4111111111111111", |
| 2198 "text", &field); |
| 2199 form.fields.push_back(field); |
| 2200 test::CreateTestFormField("Exp Date:", "exp_date", "05/45", "text", &field); |
| 2201 field.autocomplete_attribute = "cc-exp"; |
| 2202 field.max_length = 5; |
| 2203 form.fields.push_back(field); |
| 2204 |
| 2205 SubmitFormAndExpectImportedCardWithData(form, "John MMYY", "4111111111111111", |
| 2206 "05", "2045"); |
| 2207 } |
| 2208 |
| 2209 // This form has the expiration year as one field with MM/YYYY. |
| 2210 TEST_F(PersonalDataManagerTest, ImportCreditCard_Month4DigitYearCombination) { |
| 2211 FormData form; |
| 2212 FormFieldData field; |
| 2213 test::CreateTestFormField("Name on card:", "name_on_card", "John MMYYYY", |
| 2214 "text", &field); |
| 2215 form.fields.push_back(field); |
| 2216 test::CreateTestFormField("Card Number:", "card_number", "4111111111111111", |
| 2217 "text", &field); |
| 2218 form.fields.push_back(field); |
| 2219 test::CreateTestFormField("Exp Date:", "exp_date", "05/2045", "text", &field); |
| 2220 field.autocomplete_attribute = "cc-exp"; |
| 2221 field.max_length = 7; |
| 2222 form.fields.push_back(field); |
| 2223 |
| 2224 SubmitFormAndExpectImportedCardWithData(form, "John MMYYYY", |
| 2225 "4111111111111111", "05", "2045"); |
| 2226 } |
| 2227 |
| 2228 // This form has the expiration year as one field with M/YYYY. |
| 2229 TEST_F(PersonalDataManagerTest, ImportCreditCard_1DigitMonth4DigitYear) { |
| 2230 FormData form; |
| 2231 FormFieldData field; |
| 2232 test::CreateTestFormField("Name on card:", "name_on_card", "John MYYYY", |
| 2233 "text", &field); |
| 2234 form.fields.push_back(field); |
| 2235 test::CreateTestFormField("Card Number:", "card_number", "4111111111111111", |
| 2236 "text", &field); |
| 2237 form.fields.push_back(field); |
| 2238 test::CreateTestFormField("Exp Date:", "exp_date", "5/2045", "text", &field); |
| 2239 field.autocomplete_attribute = "cc-exp"; |
| 2240 form.fields.push_back(field); |
| 2241 |
| 2242 SubmitFormAndExpectImportedCardWithData(form, "John MYYYY", |
| 2243 "4111111111111111", "05", "2045"); |
| 2244 } |
| 2245 |
| 2246 // This form has the expiration year as a 2-digit field. |
| 2247 TEST_F(PersonalDataManagerTest, ImportCreditCard_2DigitYear) { |
| 2248 FormData form; |
| 2249 FormFieldData field; |
| 2250 test::CreateTestFormField("Name on card:", "name_on_card", "John Smith", |
| 2251 "text", &field); |
| 2252 form.fields.push_back(field); |
| 2253 test::CreateTestFormField("Card Number:", "card_number", "4111111111111111", |
| 2254 "text", &field); |
| 2255 form.fields.push_back(field); |
| 2256 test::CreateTestFormField("Exp Month:", "exp_month", "05", "text", &field); |
| 2257 form.fields.push_back(field); |
| 2258 test::CreateTestFormField("Exp Year:", "exp_year", "45", "text", &field); |
| 2259 field.max_length = 2; |
| 2260 form.fields.push_back(field); |
| 2261 |
| 2262 SubmitFormAndExpectImportedCardWithData(form, "John Smith", |
| 2263 "4111111111111111", "05", "2045"); |
| 2264 } |
| 2265 |
| 2165 // Tests that a credit card is extracted because it only matches a masked server | 2266 // Tests that a credit card is extracted because it only matches a masked server |
| 2166 // card. | 2267 // card. |
| 2167 TEST_F(PersonalDataManagerTest, | 2268 TEST_F(PersonalDataManagerTest, |
| 2168 ImportCreditCard_DuplicateServerCards_MaskedCard) { | 2269 ImportCreditCard_DuplicateServerCards_MaskedCard) { |
| 2169 // Add a masked server card. | 2270 // Add a masked server card. |
| 2170 std::vector<CreditCard> server_cards; | 2271 std::vector<CreditCard> server_cards; |
| 2171 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "a123")); | 2272 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "a123")); |
| 2172 test::SetCreditCardInfo(&server_cards.back(), "John Dillinger", | 2273 test::SetCreditCardInfo(&server_cards.back(), "John Dillinger", |
| 2173 "1111" /* Visa */, "01", "2999"); | 2274 "1111" /* Visa */, "01", "2999"); |
| 2174 server_cards.back().SetTypeForMaskedCard(kVisaCard); | 2275 server_cards.back().SetTypeForMaskedCard(kVisaCard); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 2195 } | 2296 } |
| 2196 | 2297 |
| 2197 // Tests that a credit card is not extracted because it matches a full server | 2298 // Tests that a credit card is not extracted because it matches a full server |
| 2198 // card. | 2299 // card. |
| 2199 TEST_F(PersonalDataManagerTest, | 2300 TEST_F(PersonalDataManagerTest, |
| 2200 ImportCreditCard_DuplicateServerCards_FullCard) { | 2301 ImportCreditCard_DuplicateServerCards_FullCard) { |
| 2201 // Add a full server card. | 2302 // Add a full server card. |
| 2202 std::vector<CreditCard> server_cards; | 2303 std::vector<CreditCard> server_cards; |
| 2203 server_cards.push_back(CreditCard(CreditCard::FULL_SERVER_CARD, "c789")); | 2304 server_cards.push_back(CreditCard(CreditCard::FULL_SERVER_CARD, "c789")); |
| 2204 test::SetCreditCardInfo(&server_cards.back(), "Clyde Barrow", | 2305 test::SetCreditCardInfo(&server_cards.back(), "Clyde Barrow", |
| 2205 "347666888555" /* American Express */, "04", "3999"); | 2306 "347666888555" /* American Express */, "04", "2999"); |
| 2206 test::SetServerCreditCards(autofill_table_, server_cards); | 2307 test::SetServerCreditCards(autofill_table_, server_cards); |
| 2207 | 2308 |
| 2208 // Type the same data as the unmasked card into a form. | 2309 // Type the same data as the unmasked card into a form. |
| 2209 FormData form; | 2310 FormData form; |
| 2210 AddFullCreditCardForm(&form, "Clyde Barrow", "347666888555", "04", "3999"); | 2311 AddFullCreditCardForm(&form, "Clyde Barrow", "347666888555", "04", "2999"); |
| 2211 | 2312 |
| 2212 // The card should not be offered to be saved locally because it only matches | 2313 // The card should not be offered to be saved locally because it only matches |
| 2213 // the full server card. | 2314 // the full server card. |
| 2214 FormStructure form_structure(form); | 2315 FormStructure form_structure(form); |
| 2215 form_structure.DetermineHeuristicTypes(); | 2316 form_structure.DetermineHeuristicTypes(); |
| 2216 std::unique_ptr<CreditCard> imported_credit_card; | 2317 std::unique_ptr<CreditCard> imported_credit_card; |
| 2217 EXPECT_FALSE(ImportCreditCard(form_structure, false, &imported_credit_card)); | 2318 EXPECT_FALSE(ImportCreditCard(form_structure, false, &imported_credit_card)); |
| 2218 ASSERT_FALSE(imported_credit_card); | 2319 ASSERT_FALSE(imported_credit_card); |
| 2219 } | 2320 } |
| 2220 | 2321 |
| 2221 TEST_F(PersonalDataManagerTest, ImportCreditCard_SameCreditCardWithConflict) { | 2322 TEST_F(PersonalDataManagerTest, ImportCreditCard_SameCreditCardWithConflict) { |
| 2222 // Start with a single valid credit card form. | 2323 // Start with a single valid credit card form. |
| 2223 FormData form1; | 2324 FormData form1; |
| 2224 AddFullCreditCardForm(&form1, "Biggie Smalls", "4111-1111-1111-1111", "01", | 2325 AddFullCreditCardForm(&form1, "Biggie Smalls", "4111-1111-1111-1111", "01", |
| 2225 "2999"); | 2326 "2998"); |
| 2226 | 2327 |
| 2227 FormStructure form_structure1(form1); | 2328 FormStructure form_structure1(form1); |
| 2228 form_structure1.DetermineHeuristicTypes(); | 2329 form_structure1.DetermineHeuristicTypes(); |
| 2229 std::unique_ptr<CreditCard> imported_credit_card; | 2330 std::unique_ptr<CreditCard> imported_credit_card; |
| 2230 EXPECT_TRUE(ImportCreditCard(form_structure1, false, &imported_credit_card)); | 2331 EXPECT_TRUE(ImportCreditCard(form_structure1, false, &imported_credit_card)); |
| 2231 ASSERT_TRUE(imported_credit_card); | 2332 ASSERT_TRUE(imported_credit_card); |
| 2232 personal_data_->SaveImportedCreditCard(*imported_credit_card); | 2333 personal_data_->SaveImportedCreditCard(*imported_credit_card); |
| 2233 | 2334 |
| 2234 // Verify that the web database has been updated and the notification sent. | 2335 // Verify that the web database has been updated and the notification sent. |
| 2235 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 2336 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 2236 .WillOnce(QuitMainMessageLoop()); | 2337 .WillOnce(QuitMainMessageLoop()); |
| 2237 base::RunLoop().Run(); | 2338 base::RunLoop().Run(); |
| 2238 | 2339 |
| 2239 CreditCard expected(base::GenerateGUID(), "https://www.example.com"); | 2340 CreditCard expected(base::GenerateGUID(), "https://www.example.com"); |
| 2240 test::SetCreditCardInfo(&expected, | 2341 test::SetCreditCardInfo(&expected, "Biggie Smalls", "4111111111111111", "01", |
| 2241 "Biggie Smalls", "4111111111111111", "01", "2999"); | 2342 "2998"); |
| 2242 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); | 2343 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); |
| 2243 ASSERT_EQ(1U, results.size()); | 2344 ASSERT_EQ(1U, results.size()); |
| 2244 EXPECT_EQ(0, expected.Compare(*results[0])); | 2345 EXPECT_EQ(0, expected.Compare(*results[0])); |
| 2245 | 2346 |
| 2246 // Add a second different valid credit card where the year is different but | 2347 // Add a second different valid credit card where the year is different but |
| 2247 // the credit card number matches. | 2348 // the credit card number matches. |
| 2248 FormData form2; | 2349 FormData form2; |
| 2249 AddFullCreditCardForm(&form2, "Biggie Smalls", "4111 1111 1111 1111", "01", | 2350 AddFullCreditCardForm(&form2, "Biggie Smalls", "4111 1111 1111 1111", "01", |
| 2250 /* different year */ "3999"); | 2351 /* different year */ "2999"); |
| 2251 | 2352 |
| 2252 FormStructure form_structure2(form2); | 2353 FormStructure form_structure2(form2); |
| 2253 form_structure2.DetermineHeuristicTypes(); | 2354 form_structure2.DetermineHeuristicTypes(); |
| 2254 std::unique_ptr<CreditCard> imported_credit_card2; | 2355 std::unique_ptr<CreditCard> imported_credit_card2; |
| 2255 EXPECT_TRUE(ImportCreditCard(form_structure2, false, &imported_credit_card2)); | 2356 EXPECT_TRUE(ImportCreditCard(form_structure2, false, &imported_credit_card2)); |
| 2256 EXPECT_FALSE(imported_credit_card2); | 2357 EXPECT_FALSE(imported_credit_card2); |
| 2257 | 2358 |
| 2258 // Verify that the web database has been updated and the notification sent. | 2359 // Verify that the web database has been updated and the notification sent. |
| 2259 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 2360 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 2260 .WillOnce(QuitMainMessageLoop()); | 2361 .WillOnce(QuitMainMessageLoop()); |
| 2261 base::RunLoop().Run(); | 2362 base::RunLoop().Run(); |
| 2262 | 2363 |
| 2263 // Expect that the newer information is saved. In this case the year is | 2364 // Expect that the newer information is saved. In this case the year is |
| 2264 // updated to "3999". | 2365 // updated to "2999". |
| 2265 CreditCard expected2(base::GenerateGUID(), "https://www.example.com"); | 2366 CreditCard expected2(base::GenerateGUID(), "https://www.example.com"); |
| 2266 test::SetCreditCardInfo(&expected2, "Biggie Smalls", "4111111111111111", "01", | 2367 test::SetCreditCardInfo(&expected2, "Biggie Smalls", "4111111111111111", "01", |
| 2267 "3999"); | 2368 "2999"); |
| 2268 const std::vector<CreditCard*>& results2 = personal_data_->GetCreditCards(); | 2369 const std::vector<CreditCard*>& results2 = personal_data_->GetCreditCards(); |
| 2269 ASSERT_EQ(1U, results2.size()); | 2370 ASSERT_EQ(1U, results2.size()); |
| 2270 EXPECT_EQ(0, expected2.Compare(*results2[0])); | 2371 EXPECT_EQ(0, expected2.Compare(*results2[0])); |
| 2271 } | 2372 } |
| 2272 | 2373 |
| 2273 TEST_F(PersonalDataManagerTest, ImportCreditCard_ShouldReturnLocalCard) { | 2374 TEST_F(PersonalDataManagerTest, ImportCreditCard_ShouldReturnLocalCard) { |
| 2274 // Start with a single valid credit card form. | 2375 // Start with a single valid credit card form. |
| 2275 FormData form1; | 2376 FormData form1; |
| 2276 AddFullCreditCardForm(&form1, "Biggie Smalls", "4111-1111-1111-1111", "01", | 2377 AddFullCreditCardForm(&form1, "Biggie Smalls", "4111-1111-1111-1111", "01", |
| 2277 "2999"); | 2378 "2998"); |
| 2278 | 2379 |
| 2279 FormStructure form_structure1(form1); | 2380 FormStructure form_structure1(form1); |
| 2280 form_structure1.DetermineHeuristicTypes(); | 2381 form_structure1.DetermineHeuristicTypes(); |
| 2281 std::unique_ptr<CreditCard> imported_credit_card; | 2382 std::unique_ptr<CreditCard> imported_credit_card; |
| 2282 EXPECT_TRUE(ImportCreditCard(form_structure1, false, &imported_credit_card)); | 2383 EXPECT_TRUE(ImportCreditCard(form_structure1, false, &imported_credit_card)); |
| 2283 ASSERT_TRUE(imported_credit_card); | 2384 ASSERT_TRUE(imported_credit_card); |
| 2284 personal_data_->SaveImportedCreditCard(*imported_credit_card); | 2385 personal_data_->SaveImportedCreditCard(*imported_credit_card); |
| 2285 | 2386 |
| 2286 // Verify that the web database has been updated and the notification sent. | 2387 // Verify that the web database has been updated and the notification sent. |
| 2287 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 2388 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 2288 .WillOnce(QuitMainMessageLoop()); | 2389 .WillOnce(QuitMainMessageLoop()); |
| 2289 base::RunLoop().Run(); | 2390 base::RunLoop().Run(); |
| 2290 | 2391 |
| 2291 CreditCard expected(base::GenerateGUID(), "https://www.example.com"); | 2392 CreditCard expected(base::GenerateGUID(), "https://www.example.com"); |
| 2292 test::SetCreditCardInfo(&expected, | 2393 test::SetCreditCardInfo(&expected, "Biggie Smalls", "4111111111111111", "01", |
| 2293 "Biggie Smalls", "4111111111111111", "01", "2999"); | 2394 "2998"); |
| 2294 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); | 2395 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); |
| 2295 ASSERT_EQ(1U, results.size()); | 2396 ASSERT_EQ(1U, results.size()); |
| 2296 EXPECT_EQ(0, expected.Compare(*results[0])); | 2397 EXPECT_EQ(0, expected.Compare(*results[0])); |
| 2297 | 2398 |
| 2298 // Add a second different valid credit card where the year is different but | 2399 // Add a second different valid credit card where the year is different but |
| 2299 // the credit card number matches. | 2400 // the credit card number matches. |
| 2300 FormData form2; | 2401 FormData form2; |
| 2301 AddFullCreditCardForm(&form2, "Biggie Smalls", "4111 1111 1111 1111", "01", | 2402 AddFullCreditCardForm(&form2, "Biggie Smalls", "4111 1111 1111 1111", "01", |
| 2302 /* different year */ "3999"); | 2403 /* different year */ "2999"); |
| 2303 | 2404 |
| 2304 FormStructure form_structure2(form2); | 2405 FormStructure form_structure2(form2); |
| 2305 form_structure2.DetermineHeuristicTypes(); | 2406 form_structure2.DetermineHeuristicTypes(); |
| 2306 std::unique_ptr<CreditCard> imported_credit_card2; | 2407 std::unique_ptr<CreditCard> imported_credit_card2; |
| 2307 EXPECT_TRUE(ImportCreditCard(form_structure2, | 2408 EXPECT_TRUE(ImportCreditCard(form_structure2, |
| 2308 /* should_return_local_card= */ true, | 2409 /* should_return_local_card= */ true, |
| 2309 &imported_credit_card2)); | 2410 &imported_credit_card2)); |
| 2310 // The local card is returned after an update. | 2411 // The local card is returned after an update. |
| 2311 EXPECT_TRUE(imported_credit_card2); | 2412 EXPECT_TRUE(imported_credit_card2); |
| 2312 | 2413 |
| 2313 // Verify that the web database has been updated and the notification sent. | 2414 // Verify that the web database has been updated and the notification sent. |
| 2314 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 2415 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 2315 .WillOnce(QuitMainMessageLoop()); | 2416 .WillOnce(QuitMainMessageLoop()); |
| 2316 base::RunLoop().Run(); | 2417 base::RunLoop().Run(); |
| 2317 | 2418 |
| 2318 // Expect that the newer information is saved. In this case the year is | 2419 // Expect that the newer information is saved. In this case the year is |
| 2319 // updated to "3999". | 2420 // updated to "2999". |
| 2320 CreditCard expected2(base::GenerateGUID(), "https://www.example.com"); | 2421 CreditCard expected2(base::GenerateGUID(), "https://www.example.com"); |
| 2321 test::SetCreditCardInfo(&expected2, | 2422 test::SetCreditCardInfo(&expected2, "Biggie Smalls", "4111111111111111", "01", |
| 2322 "Biggie Smalls", "4111111111111111", "01", "3999"); | 2423 "2999"); |
| 2323 const std::vector<CreditCard*>& results2 = personal_data_->GetCreditCards(); | 2424 const std::vector<CreditCard*>& results2 = personal_data_->GetCreditCards(); |
| 2324 ASSERT_EQ(1U, results2.size()); | 2425 ASSERT_EQ(1U, results2.size()); |
| 2325 EXPECT_EQ(0, expected2.Compare(*results2[0])); | 2426 EXPECT_EQ(0, expected2.Compare(*results2[0])); |
| 2326 } | 2427 } |
| 2327 | 2428 |
| 2328 TEST_F(PersonalDataManagerTest, ImportCreditCard_EmptyCardWithConflict) { | 2429 TEST_F(PersonalDataManagerTest, ImportCreditCard_EmptyCardWithConflict) { |
| 2329 // Start with a single valid credit card form. | 2430 // Start with a single valid credit card form. |
| 2330 FormData form1; | 2431 FormData form1; |
| 2331 AddFullCreditCardForm(&form1, "Biggie Smalls", "4111-1111-1111-1111", "01", | 2432 AddFullCreditCardForm(&form1, "Biggie Smalls", "4111-1111-1111-1111", "01", |
| 2332 "2999"); | 2433 "2998"); |
| 2333 | 2434 |
| 2334 FormStructure form_structure1(form1); | 2435 FormStructure form_structure1(form1); |
| 2335 form_structure1.DetermineHeuristicTypes(); | 2436 form_structure1.DetermineHeuristicTypes(); |
| 2336 std::unique_ptr<CreditCard> imported_credit_card; | 2437 std::unique_ptr<CreditCard> imported_credit_card; |
| 2337 EXPECT_TRUE(ImportCreditCard(form_structure1, false, &imported_credit_card)); | 2438 EXPECT_TRUE(ImportCreditCard(form_structure1, false, &imported_credit_card)); |
| 2338 ASSERT_TRUE(imported_credit_card); | 2439 ASSERT_TRUE(imported_credit_card); |
| 2339 personal_data_->SaveImportedCreditCard(*imported_credit_card); | 2440 personal_data_->SaveImportedCreditCard(*imported_credit_card); |
| 2340 | 2441 |
| 2341 // Verify that the web database has been updated and the notification sent. | 2442 // Verify that the web database has been updated and the notification sent. |
| 2342 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 2443 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 2343 .WillOnce(QuitMainMessageLoop()); | 2444 .WillOnce(QuitMainMessageLoop()); |
| 2344 base::RunLoop().Run(); | 2445 base::RunLoop().Run(); |
| 2345 | 2446 |
| 2346 CreditCard expected(base::GenerateGUID(), "https://www.example.com"); | 2447 CreditCard expected(base::GenerateGUID(), "https://www.example.com"); |
| 2347 test::SetCreditCardInfo(&expected, | 2448 test::SetCreditCardInfo(&expected, "Biggie Smalls", "4111111111111111", "01", |
| 2348 "Biggie Smalls", "4111111111111111", "01", "2999"); | 2449 "2998"); |
| 2349 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); | 2450 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); |
| 2350 ASSERT_EQ(1U, results.size()); | 2451 ASSERT_EQ(1U, results.size()); |
| 2351 EXPECT_EQ(0, expected.Compare(*results[0])); | 2452 EXPECT_EQ(0, expected.Compare(*results[0])); |
| 2352 | 2453 |
| 2353 // Add a second credit card with no number. | 2454 // Add a second credit card with no number. |
| 2354 FormData form2; | 2455 FormData form2; |
| 2355 AddFullCreditCardForm(&form2, "Biggie Smalls", /* no number */ nullptr, "01", | 2456 AddFullCreditCardForm(&form2, "Biggie Smalls", /* no number */ nullptr, "01", |
| 2356 "3999"); | 2457 "2999"); |
| 2357 | 2458 |
| 2358 FormStructure form_structure2(form2); | 2459 FormStructure form_structure2(form2); |
| 2359 form_structure2.DetermineHeuristicTypes(); | 2460 form_structure2.DetermineHeuristicTypes(); |
| 2360 std::unique_ptr<CreditCard> imported_credit_card2; | 2461 std::unique_ptr<CreditCard> imported_credit_card2; |
| 2361 EXPECT_FALSE( | 2462 EXPECT_FALSE( |
| 2362 ImportCreditCard(form_structure2, false, &imported_credit_card2)); | 2463 ImportCreditCard(form_structure2, false, &imported_credit_card2)); |
| 2363 EXPECT_FALSE(imported_credit_card2); | 2464 EXPECT_FALSE(imported_credit_card2); |
| 2364 | 2465 |
| 2365 // Since no refresh is expected, reload the data from the database to make | 2466 // Since no refresh is expected, reload the data from the database to make |
| 2366 // sure no changes were written out. | 2467 // sure no changes were written out. |
| 2367 ResetPersonalDataManager(USER_MODE_NORMAL); | 2468 ResetPersonalDataManager(USER_MODE_NORMAL); |
| 2368 | 2469 |
| 2369 // No change is expected. | 2470 // No change is expected. |
| 2370 CreditCard expected2(base::GenerateGUID(), "https://www.example.com"); | 2471 CreditCard expected2(base::GenerateGUID(), "https://www.example.com"); |
| 2371 test::SetCreditCardInfo(&expected2, | 2472 test::SetCreditCardInfo(&expected2, "Biggie Smalls", "4111111111111111", "01", |
| 2372 "Biggie Smalls", "4111111111111111", "01", "2999"); | 2473 "2998"); |
| 2373 const std::vector<CreditCard*>& results2 = personal_data_->GetCreditCards(); | 2474 const std::vector<CreditCard*>& results2 = personal_data_->GetCreditCards(); |
| 2374 ASSERT_EQ(1U, results2.size()); | 2475 ASSERT_EQ(1U, results2.size()); |
| 2375 EXPECT_EQ(0, expected2.Compare(*results2[0])); | 2476 EXPECT_EQ(0, expected2.Compare(*results2[0])); |
| 2376 } | 2477 } |
| 2377 | 2478 |
| 2378 TEST_F(PersonalDataManagerTest, ImportCreditCard_MissingInfoInNew) { | 2479 TEST_F(PersonalDataManagerTest, ImportCreditCard_MissingInfoInNew) { |
| 2379 // Start with a single valid credit card form. | 2480 // Start with a single valid credit card form. |
| 2380 FormData form1; | 2481 FormData form1; |
| 2381 AddFullCreditCardForm(&form1, "Biggie Smalls", "4111-1111-1111-1111", "01", | 2482 AddFullCreditCardForm(&form1, "Biggie Smalls", "4111-1111-1111-1111", "01", |
| 2382 "2999"); | 2483 "2999"); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2447 "Biggie Smalls", "4111111111111111", "01", "2999"); | 2548 "Biggie Smalls", "4111111111111111", "01", "2999"); |
| 2448 const std::vector<CreditCard*>& results3 = personal_data_->GetCreditCards(); | 2549 const std::vector<CreditCard*>& results3 = personal_data_->GetCreditCards(); |
| 2449 ASSERT_EQ(1U, results3.size()); | 2550 ASSERT_EQ(1U, results3.size()); |
| 2450 EXPECT_EQ(0, expected3.Compare(*results3[0])); | 2551 EXPECT_EQ(0, expected3.Compare(*results3[0])); |
| 2451 } | 2552 } |
| 2452 | 2553 |
| 2453 TEST_F(PersonalDataManagerTest, ImportCreditCard_MissingInfoInOld) { | 2554 TEST_F(PersonalDataManagerTest, ImportCreditCard_MissingInfoInOld) { |
| 2454 // Start with a single valid credit card stored via the preferences. | 2555 // Start with a single valid credit card stored via the preferences. |
| 2455 // Note the empty name. | 2556 // Note the empty name. |
| 2456 CreditCard saved_credit_card(base::GenerateGUID(), "https://www.example.com"); | 2557 CreditCard saved_credit_card(base::GenerateGUID(), "https://www.example.com"); |
| 2457 test::SetCreditCardInfo(&saved_credit_card, | 2558 test::SetCreditCardInfo(&saved_credit_card, "", "4111111111111111" /* Visa */, |
| 2458 "", "4111111111111111" /* Visa */, "01", "2999"); | 2559 "01", "2998"); |
| 2459 personal_data_->AddCreditCard(saved_credit_card); | 2560 personal_data_->AddCreditCard(saved_credit_card); |
| 2460 | 2561 |
| 2461 // Verify that the web database has been updated and the notification sent. | 2562 // Verify that the web database has been updated and the notification sent. |
| 2462 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 2563 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 2463 .WillOnce(QuitMainMessageLoop()); | 2564 .WillOnce(QuitMainMessageLoop()); |
| 2464 base::RunLoop().Run(); | 2565 base::RunLoop().Run(); |
| 2465 | 2566 |
| 2466 const std::vector<CreditCard*>& results1 = personal_data_->GetCreditCards(); | 2567 const std::vector<CreditCard*>& results1 = personal_data_->GetCreditCards(); |
| 2467 ASSERT_EQ(1U, results1.size()); | 2568 ASSERT_EQ(1U, results1.size()); |
| 2468 EXPECT_EQ(saved_credit_card, *results1[0]); | 2569 EXPECT_EQ(saved_credit_card, *results1[0]); |
| 2469 | 2570 |
| 2470 // Add a second different valid credit card where the year is different but | 2571 // Add a second different valid credit card where the year is different but |
| 2471 // the credit card number matches. | 2572 // the credit card number matches. |
| 2472 FormData form; | 2573 FormData form; |
| 2473 AddFullCreditCardForm(&form, "Biggie Smalls", "4111-1111-1111-1111", "01", | 2574 AddFullCreditCardForm(&form, "Biggie Smalls", "4111-1111-1111-1111", "01", |
| 2474 /* different year */ "3999"); | 2575 /* different year */ "2999"); |
| 2475 | 2576 |
| 2476 FormStructure form_structure(form); | 2577 FormStructure form_structure(form); |
| 2477 form_structure.DetermineHeuristicTypes(); | 2578 form_structure.DetermineHeuristicTypes(); |
| 2478 std::unique_ptr<CreditCard> imported_credit_card; | 2579 std::unique_ptr<CreditCard> imported_credit_card; |
| 2479 EXPECT_TRUE(ImportCreditCard(form_structure, false, &imported_credit_card)); | 2580 EXPECT_TRUE(ImportCreditCard(form_structure, false, &imported_credit_card)); |
| 2480 EXPECT_FALSE(imported_credit_card); | 2581 EXPECT_FALSE(imported_credit_card); |
| 2481 | 2582 |
| 2482 // Verify that the web database has been updated and the notification sent. | 2583 // Verify that the web database has been updated and the notification sent. |
| 2483 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 2584 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 2484 .WillOnce(QuitMainMessageLoop()); | 2585 .WillOnce(QuitMainMessageLoop()); |
| 2485 base::RunLoop().Run(); | 2586 base::RunLoop().Run(); |
| 2486 | 2587 |
| 2487 // Expect that the newer information is saved. In this case the year is | 2588 // Expect that the newer information is saved. In this case the year is |
| 2488 // added to the existing credit card. | 2589 // added to the existing credit card. |
| 2489 CreditCard expected2(base::GenerateGUID(), "https://www.example.com"); | 2590 CreditCard expected2(base::GenerateGUID(), "https://www.example.com"); |
| 2490 test::SetCreditCardInfo(&expected2, | 2591 test::SetCreditCardInfo(&expected2, "Biggie Smalls", "4111111111111111", "01", |
| 2491 "Biggie Smalls", "4111111111111111", "01", "3999"); | 2592 "2999"); |
| 2492 const std::vector<CreditCard*>& results2 = personal_data_->GetCreditCards(); | 2593 const std::vector<CreditCard*>& results2 = personal_data_->GetCreditCards(); |
| 2493 ASSERT_EQ(1U, results2.size()); | 2594 ASSERT_EQ(1U, results2.size()); |
| 2494 EXPECT_EQ(0, expected2.Compare(*results2[0])); | 2595 EXPECT_EQ(0, expected2.Compare(*results2[0])); |
| 2495 } | 2596 } |
| 2496 | 2597 |
| 2497 // We allow the user to store a credit card number with separators via the UI. | 2598 // We allow the user to store a credit card number with separators via the UI. |
| 2498 // We should not try to re-aggregate the same card with the separators stripped. | 2599 // We should not try to re-aggregate the same card with the separators stripped. |
| 2499 TEST_F(PersonalDataManagerTest, ImportCreditCard_SameCardWithSeparators) { | 2600 TEST_F(PersonalDataManagerTest, ImportCreditCard_SameCardWithSeparators) { |
| 2500 // Start with a single valid credit card stored via the preferences. | 2601 // Start with a single valid credit card stored via the preferences. |
| 2501 // Note the separators in the credit card number. | 2602 // Note the separators in the credit card number. |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2534 EXPECT_EQ(0, saved_credit_card.Compare(*results2[0])); | 2635 EXPECT_EQ(0, saved_credit_card.Compare(*results2[0])); |
| 2535 } | 2636 } |
| 2536 | 2637 |
| 2537 // Ensure that if a verified credit card already exists, aggregated credit cards | 2638 // Ensure that if a verified credit card already exists, aggregated credit cards |
| 2538 // cannot modify it in any way. | 2639 // cannot modify it in any way. |
| 2539 TEST_F(PersonalDataManagerTest, | 2640 TEST_F(PersonalDataManagerTest, |
| 2540 ImportCreditCard_ExistingVerifiedCardWithConflict) { | 2641 ImportCreditCard_ExistingVerifiedCardWithConflict) { |
| 2541 // Start with a verified credit card. | 2642 // Start with a verified credit card. |
| 2542 CreditCard credit_card(base::GenerateGUID(), kSettingsOrigin); | 2643 CreditCard credit_card(base::GenerateGUID(), kSettingsOrigin); |
| 2543 test::SetCreditCardInfo(&credit_card, "Biggie Smalls", | 2644 test::SetCreditCardInfo(&credit_card, "Biggie Smalls", |
| 2544 "4111 1111 1111 1111" /* Visa */, "01", "2999"); | 2645 "4111 1111 1111 1111" /* Visa */, "01", "2998"); |
| 2545 EXPECT_TRUE(credit_card.IsVerified()); | 2646 EXPECT_TRUE(credit_card.IsVerified()); |
| 2546 | 2647 |
| 2547 // Add the credit card to the database. | 2648 // Add the credit card to the database. |
| 2548 personal_data_->AddCreditCard(credit_card); | 2649 personal_data_->AddCreditCard(credit_card); |
| 2549 | 2650 |
| 2550 // Verify that the web database has been updated and the notification sent. | 2651 // Verify that the web database has been updated and the notification sent. |
| 2551 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 2652 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 2552 .WillOnce(QuitMainMessageLoop()); | 2653 .WillOnce(QuitMainMessageLoop()); |
| 2553 base::RunLoop().Run(); | 2654 base::RunLoop().Run(); |
| 2554 | 2655 |
| 2555 // Simulate a form submission with conflicting expiration year. | 2656 // Simulate a form submission with conflicting expiration year. |
| 2556 FormData form; | 2657 FormData form; |
| 2557 AddFullCreditCardForm(&form, "Biggie Smalls", "4111 1111 1111 1111", "01", | 2658 AddFullCreditCardForm(&form, "Biggie Smalls", "4111 1111 1111 1111", "01", |
| 2558 /* different year */ "3999"); | 2659 /* different year */ "2999"); |
| 2559 | 2660 |
| 2560 FormStructure form_structure(form); | 2661 FormStructure form_structure(form); |
| 2561 form_structure.DetermineHeuristicTypes(); | 2662 form_structure.DetermineHeuristicTypes(); |
| 2562 std::unique_ptr<CreditCard> imported_credit_card; | 2663 std::unique_ptr<CreditCard> imported_credit_card; |
| 2563 EXPECT_TRUE(ImportCreditCard(form_structure, false, &imported_credit_card)); | 2664 EXPECT_TRUE(ImportCreditCard(form_structure, false, &imported_credit_card)); |
| 2564 ASSERT_FALSE(imported_credit_card); | 2665 ASSERT_FALSE(imported_credit_card); |
| 2565 | 2666 |
| 2566 // Since no refresh is expected, reload the data from the database to make | 2667 // Since no refresh is expected, reload the data from the database to make |
| 2567 // sure no changes were written out. | 2668 // sure no changes were written out. |
| 2568 ResetPersonalDataManager(USER_MODE_NORMAL); | 2669 ResetPersonalDataManager(USER_MODE_NORMAL); |
| (...skipping 721 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3290 // Test that a masked server card is not suggested if more that six numbers have | 3391 // Test that a masked server card is not suggested if more that six numbers have |
| 3291 // been typed in the field. | 3392 // been typed in the field. |
| 3292 TEST_F(PersonalDataManagerTest, | 3393 TEST_F(PersonalDataManagerTest, |
| 3293 GetCreditCardSuggestions_MaskedCardWithMoreThan6Numbers) { | 3394 GetCreditCardSuggestions_MaskedCardWithMoreThan6Numbers) { |
| 3294 EnableWalletCardImport(); | 3395 EnableWalletCardImport(); |
| 3295 | 3396 |
| 3296 // Add a masked server card. | 3397 // Add a masked server card. |
| 3297 std::vector<CreditCard> server_cards; | 3398 std::vector<CreditCard> server_cards; |
| 3298 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "b459")); | 3399 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "b459")); |
| 3299 test::SetCreditCardInfo(&server_cards.back(), "Emmet Dalton", "2110", "12", | 3400 test::SetCreditCardInfo(&server_cards.back(), "Emmet Dalton", "2110", "12", |
| 3300 "3999"); | 3401 "2999"); |
| 3301 server_cards.back().SetTypeForMaskedCard(kVisaCard); | 3402 server_cards.back().SetTypeForMaskedCard(kVisaCard); |
| 3302 | 3403 |
| 3303 test::SetServerCreditCards(autofill_table_, server_cards); | 3404 test::SetServerCreditCards(autofill_table_, server_cards); |
| 3304 personal_data_->Refresh(); | 3405 personal_data_->Refresh(); |
| 3305 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 3406 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 3306 .WillOnce(QuitMainMessageLoop()); | 3407 .WillOnce(QuitMainMessageLoop()); |
| 3307 base::RunLoop().Run(); | 3408 base::RunLoop().Run(); |
| 3308 | 3409 |
| 3309 std::vector<Suggestion> suggestions = | 3410 std::vector<Suggestion> suggestions = |
| 3310 personal_data_->GetCreditCardSuggestions(AutofillType(CREDIT_CARD_NUMBER), | 3411 personal_data_->GetCreditCardSuggestions(AutofillType(CREDIT_CARD_NUMBER), |
| (...skipping 30 matching lines...) Expand all Loading... |
| 3341 // Test that local and server cards are ordered as expected. | 3442 // Test that local and server cards are ordered as expected. |
| 3342 TEST_F(PersonalDataManagerTest, | 3443 TEST_F(PersonalDataManagerTest, |
| 3343 GetCreditCardSuggestions_LocalAndServerCardsRanking) { | 3444 GetCreditCardSuggestions_LocalAndServerCardsRanking) { |
| 3344 EnableWalletCardImport(); | 3445 EnableWalletCardImport(); |
| 3345 SetupReferenceLocalCreditCards(); | 3446 SetupReferenceLocalCreditCards(); |
| 3346 | 3447 |
| 3347 // Add some server cards. | 3448 // Add some server cards. |
| 3348 std::vector<CreditCard> server_cards; | 3449 std::vector<CreditCard> server_cards; |
| 3349 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "b459")); | 3450 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "b459")); |
| 3350 test::SetCreditCardInfo(&server_cards.back(), "Emmet Dalton", "2110", "12", | 3451 test::SetCreditCardInfo(&server_cards.back(), "Emmet Dalton", "2110", "12", |
| 3351 "3999"); | 3452 "2999"); |
| 3352 server_cards.back().set_use_count(2); | 3453 server_cards.back().set_use_count(2); |
| 3353 server_cards.back().set_use_date(base::Time::Now() - | 3454 server_cards.back().set_use_date(base::Time::Now() - |
| 3354 base::TimeDelta::FromDays(1)); | 3455 base::TimeDelta::FromDays(1)); |
| 3355 server_cards.back().SetTypeForMaskedCard(kVisaCard); | 3456 server_cards.back().SetTypeForMaskedCard(kVisaCard); |
| 3356 | 3457 |
| 3357 server_cards.push_back(CreditCard(CreditCard::FULL_SERVER_CARD, "b460")); | 3458 server_cards.push_back(CreditCard(CreditCard::FULL_SERVER_CARD, "b460")); |
| 3358 test::SetCreditCardInfo(&server_cards.back(), "Jesse James", "2109", "12", | 3459 test::SetCreditCardInfo(&server_cards.back(), "Jesse James", "2109", "12", |
| 3359 "3999"); | 3460 "2999"); |
| 3360 server_cards.back().set_use_count(6); | 3461 server_cards.back().set_use_count(6); |
| 3361 server_cards.back().set_use_date(base::Time::Now() - | 3462 server_cards.back().set_use_date(base::Time::Now() - |
| 3362 base::TimeDelta::FromDays(1)); | 3463 base::TimeDelta::FromDays(1)); |
| 3363 | 3464 |
| 3364 test::SetServerCreditCards(autofill_table_, server_cards); | 3465 test::SetServerCreditCards(autofill_table_, server_cards); |
| 3365 personal_data_->Refresh(); | 3466 personal_data_->Refresh(); |
| 3366 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 3467 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 3367 .WillOnce(QuitMainMessageLoop()); | 3468 .WillOnce(QuitMainMessageLoop()); |
| 3368 base::RunLoop().Run(); | 3469 base::RunLoop().Run(); |
| 3369 | 3470 |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3433 | 3534 |
| 3434 // Test that a card that doesn't have a number is not shown in the suggestions | 3535 // Test that a card that doesn't have a number is not shown in the suggestions |
| 3435 // when querying credit cards by their number. | 3536 // when querying credit cards by their number. |
| 3436 TEST_F(PersonalDataManagerTest, GetCreditCardSuggestions_NumberMissing) { | 3537 TEST_F(PersonalDataManagerTest, GetCreditCardSuggestions_NumberMissing) { |
| 3437 // Create one normal credit card and one credit card with the number missing. | 3538 // Create one normal credit card and one credit card with the number missing. |
| 3438 ASSERT_EQ(0U, personal_data_->GetCreditCards().size()); | 3539 ASSERT_EQ(0U, personal_data_->GetCreditCards().size()); |
| 3439 | 3540 |
| 3440 CreditCard credit_card0("287151C8-6AB1-487C-9095-28E80BE5DA15", | 3541 CreditCard credit_card0("287151C8-6AB1-487C-9095-28E80BE5DA15", |
| 3441 "https://www.example.com"); | 3542 "https://www.example.com"); |
| 3442 test::SetCreditCardInfo(&credit_card0, "Clyde Barrow", | 3543 test::SetCreditCardInfo(&credit_card0, "Clyde Barrow", |
| 3443 "347666888555" /* American Express */, "04", "3999"); | 3544 "347666888555" /* American Express */, "04", "2999"); |
| 3444 credit_card0.set_use_count(3); | 3545 credit_card0.set_use_count(3); |
| 3445 credit_card0.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(1)); | 3546 credit_card0.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(1)); |
| 3446 personal_data_->AddCreditCard(credit_card0); | 3547 personal_data_->AddCreditCard(credit_card0); |
| 3447 | 3548 |
| 3448 CreditCard credit_card1("1141084B-72D7-4B73-90CF-3D6AC154673B", | 3549 CreditCard credit_card1("1141084B-72D7-4B73-90CF-3D6AC154673B", |
| 3449 "https://www.example.com"); | 3550 "https://www.example.com"); |
| 3450 credit_card1.set_use_count(300); | 3551 credit_card1.set_use_count(300); |
| 3451 credit_card1.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(10)); | 3552 credit_card1.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(10)); |
| 3452 test::SetCreditCardInfo(&credit_card1, "John Dillinger", "", "01", "2999"); | 3553 test::SetCreditCardInfo(&credit_card1, "John Dillinger", "", "01", "2999"); |
| 3453 personal_data_->AddCreditCard(credit_card1); | 3554 personal_data_->AddCreditCard(credit_card1); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3487 "9012" /* Visa */, "01", "2999"); | 3588 "9012" /* Visa */, "01", "2999"); |
| 3488 server_cards.back().set_use_count(2); | 3589 server_cards.back().set_use_count(2); |
| 3489 server_cards.back().set_use_date(base::Time::Now() - | 3590 server_cards.back().set_use_date(base::Time::Now() - |
| 3490 base::TimeDelta::FromDays(15)); | 3591 base::TimeDelta::FromDays(15)); |
| 3491 server_cards.back().SetTypeForMaskedCard(kVisaCard); | 3592 server_cards.back().SetTypeForMaskedCard(kVisaCard); |
| 3492 | 3593 |
| 3493 // This server card is identical to a local card, but has a different | 3594 // This server card is identical to a local card, but has a different |
| 3494 // card type. Not a dupe and therefore both should appear in the suggestions. | 3595 // card type. Not a dupe and therefore both should appear in the suggestions. |
| 3495 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "b456")); | 3596 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "b456")); |
| 3496 test::SetCreditCardInfo(&server_cards.back(), "Bonnie Parker", "2109", "12", | 3597 test::SetCreditCardInfo(&server_cards.back(), "Bonnie Parker", "2109", "12", |
| 3497 "3999"); | 3598 "2999"); |
| 3498 server_cards.back().set_use_count(3); | 3599 server_cards.back().set_use_count(3); |
| 3499 server_cards.back().set_use_date(base::Time::Now() - | 3600 server_cards.back().set_use_date(base::Time::Now() - |
| 3500 base::TimeDelta::FromDays(15)); | 3601 base::TimeDelta::FromDays(15)); |
| 3501 server_cards.back().SetTypeForMaskedCard(kVisaCard); | 3602 server_cards.back().SetTypeForMaskedCard(kVisaCard); |
| 3502 | 3603 |
| 3503 // This unmasked server card is an exact dupe of a local card. Therefore only | 3604 // This unmasked server card is an exact dupe of a local card. Therefore only |
| 3504 // this card should appear in the suggestions as full server cards have | 3605 // this card should appear in the suggestions as full server cards have |
| 3505 // precedence over local cards. | 3606 // precedence over local cards. |
| 3506 server_cards.push_back(CreditCard(CreditCard::FULL_SERVER_CARD, "c789")); | 3607 server_cards.push_back(CreditCard(CreditCard::FULL_SERVER_CARD, "c789")); |
| 3507 test::SetCreditCardInfo(&server_cards.back(), "Clyde Barrow", | 3608 test::SetCreditCardInfo(&server_cards.back(), "Clyde Barrow", |
| 3508 "347666888555" /* American Express */, "04", "3999"); | 3609 "347666888555" /* American Express */, "04", "2999"); |
| 3509 server_cards.back().set_use_count(1); | 3610 server_cards.back().set_use_count(1); |
| 3510 server_cards.back().set_use_date(base::Time::Now() - | 3611 server_cards.back().set_use_date(base::Time::Now() - |
| 3511 base::TimeDelta::FromDays(15)); | 3612 base::TimeDelta::FromDays(15)); |
| 3512 | 3613 |
| 3513 test::SetServerCreditCards(autofill_table_, server_cards); | 3614 test::SetServerCreditCards(autofill_table_, server_cards); |
| 3514 personal_data_->Refresh(); | 3615 personal_data_->Refresh(); |
| 3515 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 3616 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 3516 .WillOnce(QuitMainMessageLoop()); | 3617 .WillOnce(QuitMainMessageLoop()); |
| 3517 base::RunLoop().Run(); | 3618 base::RunLoop().Run(); |
| 3518 | 3619 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 3548 GetCreditCardSuggestions_ServerCardDuplicateOfMultipleLocalCards) { | 3649 GetCreditCardSuggestions_ServerCardDuplicateOfMultipleLocalCards) { |
| 3549 EnableWalletCardImport(); | 3650 EnableWalletCardImport(); |
| 3550 SetupReferenceLocalCreditCards(); | 3651 SetupReferenceLocalCreditCards(); |
| 3551 | 3652 |
| 3552 // Add a duplicate server card. | 3653 // Add a duplicate server card. |
| 3553 std::vector<CreditCard> server_cards; | 3654 std::vector<CreditCard> server_cards; |
| 3554 // This unmasked server card is an exact dupe of a local card. Therefore only | 3655 // This unmasked server card is an exact dupe of a local card. Therefore only |
| 3555 // the local card should appear in the suggestions. | 3656 // the local card should appear in the suggestions. |
| 3556 server_cards.push_back(CreditCard(CreditCard::FULL_SERVER_CARD, "c789")); | 3657 server_cards.push_back(CreditCard(CreditCard::FULL_SERVER_CARD, "c789")); |
| 3557 test::SetCreditCardInfo(&server_cards.back(), "Clyde Barrow", | 3658 test::SetCreditCardInfo(&server_cards.back(), "Clyde Barrow", |
| 3558 "347666888555" /* American Express */, "04", "3999"); | 3659 "347666888555" /* American Express */, "04", "2999"); |
| 3559 | 3660 |
| 3560 test::SetServerCreditCards(autofill_table_, server_cards); | 3661 test::SetServerCreditCards(autofill_table_, server_cards); |
| 3561 personal_data_->Refresh(); | 3662 personal_data_->Refresh(); |
| 3562 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 3663 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 3563 .WillOnce(QuitMainMessageLoop()); | 3664 .WillOnce(QuitMainMessageLoop()); |
| 3564 base::RunLoop().Run(); | 3665 base::RunLoop().Run(); |
| 3565 | 3666 |
| 3566 std::vector<Suggestion> suggestions = | 3667 std::vector<Suggestion> suggestions = |
| 3567 personal_data_->GetCreditCardSuggestions( | 3668 personal_data_->GetCreditCardSuggestions( |
| 3568 AutofillType(CREDIT_CARD_NAME_FULL), | 3669 AutofillType(CREDIT_CARD_NAME_FULL), |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3680 CreditCard credit_card2("002149C1-EE28-4213-A3B9-DA243FFF021B", | 3781 CreditCard credit_card2("002149C1-EE28-4213-A3B9-DA243FFF021B", |
| 3681 "https://www.example.com"); | 3782 "https://www.example.com"); |
| 3682 credit_card2.set_use_count(1); | 3783 credit_card2.set_use_count(1); |
| 3683 credit_card2.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(1)); | 3784 credit_card2.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(1)); |
| 3684 test::SetCreditCardInfo(&credit_card2, "Homer Simpson", | 3785 test::SetCreditCardInfo(&credit_card2, "Homer Simpson", |
| 3685 "518765432109" /* Mastercard */, "", ""); | 3786 "518765432109" /* Mastercard */, "", ""); |
| 3686 credit_cards.push_back(&credit_card2); | 3787 credit_cards.push_back(&credit_card2); |
| 3687 | 3788 |
| 3688 // Create a masked server card that is slightly different of the local card. | 3789 // Create a masked server card that is slightly different of the local card. |
| 3689 CreditCard credit_card4(CreditCard::MASKED_SERVER_CARD, "b456"); | 3790 CreditCard credit_card4(CreditCard::MASKED_SERVER_CARD, "b456"); |
| 3690 test::SetCreditCardInfo(&credit_card4, "Homer Simpson", "2109", "12", "3999"); | 3791 test::SetCreditCardInfo(&credit_card4, "Homer Simpson", "2109", "12", "2999"); |
| 3691 credit_card4.set_use_count(3); | 3792 credit_card4.set_use_count(3); |
| 3692 credit_card4.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(15)); | 3793 credit_card4.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(15)); |
| 3693 credit_card4.SetTypeForMaskedCard(kVisaCard); | 3794 credit_card4.SetTypeForMaskedCard(kVisaCard); |
| 3694 credit_cards.push_back(&credit_card4); | 3795 credit_cards.push_back(&credit_card4); |
| 3695 | 3796 |
| 3696 // Create a full server card that is slightly different of the two other | 3797 // Create a full server card that is slightly different of the two other |
| 3697 // cards. | 3798 // cards. |
| 3698 CreditCard credit_card5(CreditCard::FULL_SERVER_CARD, "c789"); | 3799 CreditCard credit_card5(CreditCard::FULL_SERVER_CARD, "c789"); |
| 3699 test::SetCreditCardInfo(&credit_card5, "Homer Simpson", | 3800 test::SetCreditCardInfo(&credit_card5, "Homer Simpson", |
| 3700 "347666888555" /* American Express */, "04", "3999"); | 3801 "347666888555" /* American Express */, "04", "2999"); |
| 3701 credit_card5.set_use_count(1); | 3802 credit_card5.set_use_count(1); |
| 3702 credit_card5.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(15)); | 3803 credit_card5.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(15)); |
| 3703 credit_cards.push_back(&credit_card5); | 3804 credit_cards.push_back(&credit_card5); |
| 3704 | 3805 |
| 3705 PersonalDataManager::DedupeCreditCardToSuggest(&credit_cards); | 3806 PersonalDataManager::DedupeCreditCardToSuggest(&credit_cards); |
| 3706 EXPECT_EQ(3U, credit_cards.size()); | 3807 EXPECT_EQ(3U, credit_cards.size()); |
| 3707 } | 3808 } |
| 3708 | 3809 |
| 3709 TEST_F(PersonalDataManagerTest, RecordUseOf) { | 3810 TEST_F(PersonalDataManagerTest, RecordUseOf) { |
| 3710 base::Time creation_time = base::Time::FromTimeT(12345); | 3811 base::Time creation_time = base::Time::FromTimeT(12345); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3772 EnableWalletCardImport(); | 3873 EnableWalletCardImport(); |
| 3773 | 3874 |
| 3774 std::vector<CreditCard> server_cards; | 3875 std::vector<CreditCard> server_cards; |
| 3775 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "a123")); | 3876 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "a123")); |
| 3776 test::SetCreditCardInfo(&server_cards.back(), "John Dillinger", | 3877 test::SetCreditCardInfo(&server_cards.back(), "John Dillinger", |
| 3777 "9012" /* Visa */, "01", "2999"); | 3878 "9012" /* Visa */, "01", "2999"); |
| 3778 server_cards.back().SetTypeForMaskedCard(kVisaCard); | 3879 server_cards.back().SetTypeForMaskedCard(kVisaCard); |
| 3779 | 3880 |
| 3780 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "b456")); | 3881 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "b456")); |
| 3781 test::SetCreditCardInfo(&server_cards.back(), "Bonnie Parker", | 3882 test::SetCreditCardInfo(&server_cards.back(), "Bonnie Parker", |
| 3782 "4444" /* Mastercard */, "12", "3999"); | 3883 "4444" /* Mastercard */, "12", "2999"); |
| 3783 server_cards.back().SetTypeForMaskedCard(kMasterCard); | 3884 server_cards.back().SetTypeForMaskedCard(kMasterCard); |
| 3784 | 3885 |
| 3785 server_cards.push_back(CreditCard(CreditCard::FULL_SERVER_CARD, "c789")); | 3886 server_cards.push_back(CreditCard(CreditCard::FULL_SERVER_CARD, "c789")); |
| 3786 test::SetCreditCardInfo(&server_cards.back(), "Clyde Barrow", | 3887 test::SetCreditCardInfo(&server_cards.back(), "Clyde Barrow", |
| 3787 "347666888555" /* American Express */, "04", "3999"); | 3888 "347666888555" /* American Express */, "04", "2999"); |
| 3788 | 3889 |
| 3789 test::SetServerCreditCards(autofill_table_, server_cards); | 3890 test::SetServerCreditCards(autofill_table_, server_cards); |
| 3790 personal_data_->Refresh(); | 3891 personal_data_->Refresh(); |
| 3791 | 3892 |
| 3792 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 3893 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 3793 .WillOnce(QuitMainMessageLoop()); | 3894 .WillOnce(QuitMainMessageLoop()); |
| 3794 base::RunLoop().Run(); | 3895 base::RunLoop().Run(); |
| 3795 | 3896 |
| 3796 ASSERT_EQ(3U, personal_data_->GetCreditCards().size()); | 3897 ASSERT_EQ(3U, personal_data_->GetCreditCards().size()); |
| 3797 | 3898 |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3914 EXPECT_TRUE(personal_data_->GetCreditCards().empty()); | 4015 EXPECT_TRUE(personal_data_->GetCreditCards().empty()); |
| 3915 EXPECT_TRUE(personal_data_->GetProfiles().empty()); | 4016 EXPECT_TRUE(personal_data_->GetProfiles().empty()); |
| 3916 } | 4017 } |
| 3917 | 4018 |
| 3918 TEST_F(PersonalDataManagerTest, DontDuplicateServerCard) { | 4019 TEST_F(PersonalDataManagerTest, DontDuplicateServerCard) { |
| 3919 EnableWalletCardImport(); | 4020 EnableWalletCardImport(); |
| 3920 | 4021 |
| 3921 std::vector<CreditCard> server_cards; | 4022 std::vector<CreditCard> server_cards; |
| 3922 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "a123")); | 4023 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "a123")); |
| 3923 test::SetCreditCardInfo(&server_cards.back(), "John Dillinger", | 4024 test::SetCreditCardInfo(&server_cards.back(), "John Dillinger", |
| 3924 "1881" /* Visa */, "01", "4999"); | 4025 "1881" /* Visa */, "01", "2999"); |
| 3925 server_cards.back().SetTypeForMaskedCard(kVisaCard); | 4026 server_cards.back().SetTypeForMaskedCard(kVisaCard); |
| 3926 | 4027 |
| 3927 server_cards.push_back(CreditCard(CreditCard::FULL_SERVER_CARD, "c789")); | 4028 server_cards.push_back(CreditCard(CreditCard::FULL_SERVER_CARD, "c789")); |
| 3928 test::SetCreditCardInfo(&server_cards.back(), "Clyde Barrow", | 4029 test::SetCreditCardInfo(&server_cards.back(), "Clyde Barrow", |
| 3929 "347666888555" /* American Express */, "04", "3999"); | 4030 "347666888555" /* American Express */, "04", "2999"); |
| 3930 | 4031 |
| 3931 test::SetServerCreditCards(autofill_table_, server_cards); | 4032 test::SetServerCreditCards(autofill_table_, server_cards); |
| 3932 personal_data_->Refresh(); | 4033 personal_data_->Refresh(); |
| 3933 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 4034 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 3934 .WillOnce(QuitMainMessageLoop()); | 4035 .WillOnce(QuitMainMessageLoop()); |
| 3935 base::RunLoop().Run(); | 4036 base::RunLoop().Run(); |
| 3936 | 4037 |
| 3937 // A valid credit card form. A user re-enters one of their masked cards. | 4038 // A valid credit card form. A user re-enters one of their masked cards. |
| 3938 // We shouldn't offer to save. It's possible this is actually a different card | 4039 // We shouldn't offer to save. It's possible this is actually a different card |
| 3939 // but it's very unlikely. And these circumstances will also arise if the user | 4040 // but it's very unlikely. And these circumstances will also arise if the user |
| 3940 // has the same card available locally and synced from payments. | 4041 // has the same card available locally and synced from payments. |
| 3941 FormData form1; | 4042 FormData form1; |
| 3942 FormFieldData field; | 4043 FormFieldData field; |
| 3943 test::CreateTestFormField("Name on card:", "name_on_card", "John Dillinger", | 4044 test::CreateTestFormField("Name on card:", "name_on_card", "John Dillinger", |
| 3944 "text", &field); | 4045 "text", &field); |
| 3945 form1.fields.push_back(field); | 4046 form1.fields.push_back(field); |
| 3946 test::CreateTestFormField("Card Number:", "card_number", "4012888888881881", | 4047 test::CreateTestFormField("Card Number:", "card_number", "4012888888881881", |
| 3947 "text", &field); | 4048 "text", &field); |
| 3948 form1.fields.push_back(field); | 4049 form1.fields.push_back(field); |
| 3949 test::CreateTestFormField("Exp Month:", "exp_month", "01", "text", &field); | 4050 test::CreateTestFormField("Exp Month:", "exp_month", "01", "text", &field); |
| 3950 form1.fields.push_back(field); | 4051 form1.fields.push_back(field); |
| 3951 test::CreateTestFormField("Exp Year:", "exp_year", "4999", "text", &field); | 4052 test::CreateTestFormField("Exp Year:", "exp_year", "2999", "text", &field); |
| 3952 form1.fields.push_back(field); | 4053 form1.fields.push_back(field); |
| 3953 | 4054 |
| 3954 FormStructure form_structure1(form1); | 4055 FormStructure form_structure1(form1); |
| 3955 form_structure1.DetermineHeuristicTypes(); | 4056 form_structure1.DetermineHeuristicTypes(); |
| 3956 std::unique_ptr<CreditCard> imported_credit_card; | 4057 std::unique_ptr<CreditCard> imported_credit_card; |
| 3957 EXPECT_FALSE(personal_data_->ImportFormData(form_structure1, false, | 4058 EXPECT_FALSE(personal_data_->ImportFormData(form_structure1, false, |
| 3958 &imported_credit_card)); | 4059 &imported_credit_card)); |
| 3959 EXPECT_FALSE(imported_credit_card); | 4060 EXPECT_FALSE(imported_credit_card); |
| 3960 | 4061 |
| 3961 // A user re-types (or fills with) an unmasked card. Don't offer to save | 4062 // A user re-types (or fills with) an unmasked card. Don't offer to save |
| 3962 // here, either. Since it's unmasked, we know for certain that it's the same | 4063 // here, either. Since it's unmasked, we know for certain that it's the same |
| 3963 // card. | 4064 // card. |
| 3964 FormData form2; | 4065 FormData form2; |
| 3965 test::CreateTestFormField("Name on card:", "name_on_card", "Clyde Barrow", | 4066 test::CreateTestFormField("Name on card:", "name_on_card", "Clyde Barrow", |
| 3966 "text", &field); | 4067 "text", &field); |
| 3967 form2.fields.push_back(field); | 4068 form2.fields.push_back(field); |
| 3968 test::CreateTestFormField("Card Number:", "card_number", "347666888555", | 4069 test::CreateTestFormField("Card Number:", "card_number", "347666888555", |
| 3969 "text", &field); | 4070 "text", &field); |
| 3970 form2.fields.push_back(field); | 4071 form2.fields.push_back(field); |
| 3971 test::CreateTestFormField("Exp Month:", "exp_month", "04", "text", &field); | 4072 test::CreateTestFormField("Exp Month:", "exp_month", "04", "text", &field); |
| 3972 form2.fields.push_back(field); | 4073 form2.fields.push_back(field); |
| 3973 test::CreateTestFormField("Exp Year:", "exp_year", "3999", "text", &field); | 4074 test::CreateTestFormField("Exp Year:", "exp_year", "2999", "text", &field); |
| 3974 form2.fields.push_back(field); | 4075 form2.fields.push_back(field); |
| 3975 | 4076 |
| 3976 FormStructure form_structure2(form2); | 4077 FormStructure form_structure2(form2); |
| 3977 form_structure2.DetermineHeuristicTypes(); | 4078 form_structure2.DetermineHeuristicTypes(); |
| 3978 std::unique_ptr<CreditCard> imported_credit_card2; | 4079 std::unique_ptr<CreditCard> imported_credit_card2; |
| 3979 EXPECT_FALSE(personal_data_->ImportFormData(form_structure2, false, | 4080 EXPECT_FALSE(personal_data_->ImportFormData(form_structure2, false, |
| 3980 &imported_credit_card2)); | 4081 &imported_credit_card2)); |
| 3981 EXPECT_FALSE(imported_credit_card2); | 4082 EXPECT_FALSE(imported_credit_card2); |
| 3982 } | 4083 } |
| 3983 | 4084 |
| (...skipping 1131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5115 EnableAutofillProfileCleanup(); | 5216 EnableAutofillProfileCleanup(); |
| 5116 | 5217 |
| 5117 // The deduping routine should not be run. | 5218 // The deduping routine should not be run. |
| 5118 EXPECT_FALSE(personal_data_->ApplyDedupingRoutine()); | 5219 EXPECT_FALSE(personal_data_->ApplyDedupingRoutine()); |
| 5119 | 5220 |
| 5120 // The two duplicate profiles should still be present. | 5221 // The two duplicate profiles should still be present. |
| 5121 EXPECT_EQ(2U, personal_data_->GetProfiles().size()); | 5222 EXPECT_EQ(2U, personal_data_->GetProfiles().size()); |
| 5122 } | 5223 } |
| 5123 | 5224 |
| 5124 } // namespace autofill | 5225 } // namespace autofill |
| OLD | NEW |