| 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 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 // Adds three local cards to the |personal_data_|. The three cards are | 203 // Adds three local cards to the |personal_data_|. The three cards are |
| 204 // different: two are from different companies and the third doesn't have a | 204 // different: two are from different companies and the third doesn't have a |
| 205 // number. All three have different owners and credit card number. This allows | 205 // number. All three have different owners and credit card number. This allows |
| 206 // to test the suggestions based on name as well as on credit card number. | 206 // to test the suggestions based on name as well as on credit card number. |
| 207 void SetupReferenceLocalCreditCards() { | 207 void SetupReferenceLocalCreditCards() { |
| 208 ASSERT_EQ(0U, personal_data_->GetCreditCards().size()); | 208 ASSERT_EQ(0U, personal_data_->GetCreditCards().size()); |
| 209 | 209 |
| 210 CreditCard credit_card0("287151C8-6AB1-487C-9095-28E80BE5DA15", | 210 CreditCard credit_card0("287151C8-6AB1-487C-9095-28E80BE5DA15", |
| 211 "https://www.example.com"); | 211 "https://www.example.com"); |
| 212 test::SetCreditCardInfo(&credit_card0, "Clyde Barrow", | 212 test::SetCreditCardInfo(&credit_card0, "Clyde Barrow", |
| 213 "347666888555" /* American Express */, "04", | 213 "347666888555" /* American Express */, "04", "2999", |
| 214 "2999"); | 214 "1"); |
| 215 credit_card0.set_use_count(3); | 215 credit_card0.set_use_count(3); |
| 216 credit_card0.set_use_date(AutofillClock::Now() - | 216 credit_card0.set_use_date(AutofillClock::Now() - |
| 217 base::TimeDelta::FromDays(1)); | 217 base::TimeDelta::FromDays(1)); |
| 218 personal_data_->AddCreditCard(credit_card0); | 218 personal_data_->AddCreditCard(credit_card0); |
| 219 | 219 |
| 220 CreditCard credit_card1("1141084B-72D7-4B73-90CF-3D6AC154673B", | 220 CreditCard credit_card1("1141084B-72D7-4B73-90CF-3D6AC154673B", |
| 221 "https://www.example.com"); | 221 "https://www.example.com"); |
| 222 credit_card1.set_use_count(300); | 222 credit_card1.set_use_count(300); |
| 223 credit_card1.set_use_date(AutofillClock::Now() - | 223 credit_card1.set_use_date(AutofillClock::Now() - |
| 224 base::TimeDelta::FromDays(10)); | 224 base::TimeDelta::FromDays(10)); |
| 225 test::SetCreditCardInfo(&credit_card1, "John Dillinger", | 225 test::SetCreditCardInfo(&credit_card1, "John Dillinger", |
| 226 "423456789012" /* Visa */, "01", "2999"); | 226 "423456789012" /* Visa */, "01", "2999", "1"); |
| 227 personal_data_->AddCreditCard(credit_card1); | 227 personal_data_->AddCreditCard(credit_card1); |
| 228 | 228 |
| 229 CreditCard credit_card2("002149C1-EE28-4213-A3B9-DA243FFF021B", | 229 CreditCard credit_card2("002149C1-EE28-4213-A3B9-DA243FFF021B", |
| 230 "https://www.example.com"); | 230 "https://www.example.com"); |
| 231 credit_card2.set_use_count(1); | 231 credit_card2.set_use_count(1); |
| 232 credit_card2.set_use_date(AutofillClock::Now() - | 232 credit_card2.set_use_date(AutofillClock::Now() - |
| 233 base::TimeDelta::FromDays(1)); | 233 base::TimeDelta::FromDays(1)); |
| 234 test::SetCreditCardInfo(&credit_card2, "Bonnie Parker", | 234 test::SetCreditCardInfo(&credit_card2, "Bonnie Parker", |
| 235 "518765432109" /* Mastercard */, "12", "2999"); | 235 "518765432109" /* Mastercard */, "12", "2999", "1"); |
| 236 personal_data_->AddCreditCard(credit_card2); | 236 personal_data_->AddCreditCard(credit_card2); |
| 237 | 237 |
| 238 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 238 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 239 .WillOnce(QuitMainMessageLoop()); | 239 .WillOnce(QuitMainMessageLoop()); |
| 240 base::RunLoop().Run(); | 240 base::RunLoop().Run(); |
| 241 | 241 |
| 242 ASSERT_EQ(3U, personal_data_->GetCreditCards().size()); | 242 ASSERT_EQ(3U, personal_data_->GetCreditCards().size()); |
| 243 } | 243 } |
| 244 | 244 |
| 245 // Helper methods that simply forward the call to the private member (to avoid | 245 // Helper methods that simply forward the call to the private member (to avoid |
| (...skipping 21 matching lines...) Expand all Loading... |
| 267 ASSERT_TRUE(imported_credit_card); | 267 ASSERT_TRUE(imported_credit_card); |
| 268 personal_data_->SaveImportedCreditCard(*imported_credit_card); | 268 personal_data_->SaveImportedCreditCard(*imported_credit_card); |
| 269 | 269 |
| 270 // Verify that the web database has been updated and the notification sent. | 270 // Verify that the web database has been updated and the notification sent. |
| 271 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 271 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 272 .WillOnce(QuitMainMessageLoop()); | 272 .WillOnce(QuitMainMessageLoop()); |
| 273 base::RunLoop().Run(); | 273 base::RunLoop().Run(); |
| 274 | 274 |
| 275 CreditCard expected(base::GenerateGUID(), "https://www.example.com"); | 275 CreditCard expected(base::GenerateGUID(), "https://www.example.com"); |
| 276 test::SetCreditCardInfo(&expected, exp_name, exp_cc_num, exp_cc_month, | 276 test::SetCreditCardInfo(&expected, exp_name, exp_cc_num, exp_cc_month, |
| 277 exp_cc_year); | 277 exp_cc_year, "1"); |
| 278 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); | 278 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); |
| 279 ASSERT_EQ(1U, results.size()); | 279 ASSERT_EQ(1U, results.size()); |
| 280 EXPECT_EQ(0, expected.Compare(*results[0])); | 280 EXPECT_EQ(0, expected.Compare(*results[0])); |
| 281 } | 281 } |
| 282 | 282 |
| 283 // The temporary directory should be deleted at the end to ensure that | 283 // The temporary directory should be deleted at the end to ensure that |
| 284 // files are not used anymore and deletion succeeds. | 284 // files are not used anymore and deletion succeeds. |
| 285 base::ScopedTempDir temp_dir_; | 285 base::ScopedTempDir temp_dir_; |
| 286 base::MessageLoopForUI message_loop_; | 286 base::MessageLoopForUI message_loop_; |
| 287 std::unique_ptr<PrefService> prefs_; | 287 std::unique_ptr<PrefService> prefs_; |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 489 // database. | 489 // database. |
| 490 ResetPersonalDataManager(USER_MODE_NORMAL); | 490 ResetPersonalDataManager(USER_MODE_NORMAL); |
| 491 | 491 |
| 492 // Verify that we've loaded the profiles from the web database. | 492 // Verify that we've loaded the profiles from the web database. |
| 493 ExpectSameElements(profiles, personal_data_->GetProfiles()); | 493 ExpectSameElements(profiles, personal_data_->GetProfiles()); |
| 494 } | 494 } |
| 495 | 495 |
| 496 TEST_F(PersonalDataManagerTest, AddUpdateRemoveCreditCards) { | 496 TEST_F(PersonalDataManagerTest, AddUpdateRemoveCreditCards) { |
| 497 EnableWalletCardImport(); | 497 EnableWalletCardImport(); |
| 498 CreditCard credit_card0(base::GenerateGUID(), "https://www.example.com"); | 498 CreditCard credit_card0(base::GenerateGUID(), "https://www.example.com"); |
| 499 test::SetCreditCardInfo(&credit_card0, | 499 test::SetCreditCardInfo(&credit_card0, "John Dillinger", |
| 500 "John Dillinger", "423456789012" /* Visa */, "01", "2999"); | 500 "423456789012" /* Visa */, "01", "2999", "1"); |
| 501 | 501 |
| 502 CreditCard credit_card1(base::GenerateGUID(), "https://www.example.com"); | 502 CreditCard credit_card1(base::GenerateGUID(), "https://www.example.com"); |
| 503 test::SetCreditCardInfo(&credit_card1, "Bonnie Parker", | 503 test::SetCreditCardInfo(&credit_card1, "Bonnie Parker", |
| 504 "518765432109" /* Mastercard */, "12", "2999"); | 504 "518765432109" /* Mastercard */, "12", "2999", "1"); |
| 505 | 505 |
| 506 CreditCard credit_card2(base::GenerateGUID(), "https://www.example.com"); | 506 CreditCard credit_card2(base::GenerateGUID(), "https://www.example.com"); |
| 507 test::SetCreditCardInfo(&credit_card2, "Clyde Barrow", | 507 test::SetCreditCardInfo(&credit_card2, "Clyde Barrow", |
| 508 "347666888555" /* American Express */, "04", "2999"); | 508 "347666888555" /* American Express */, "04", "2999", |
| 509 "1"); |
| 509 | 510 |
| 510 // Add two test credit cards to the database. | 511 // Add two test credit cards to the database. |
| 511 personal_data_->AddCreditCard(credit_card0); | 512 personal_data_->AddCreditCard(credit_card0); |
| 512 personal_data_->AddCreditCard(credit_card1); | 513 personal_data_->AddCreditCard(credit_card1); |
| 513 | 514 |
| 514 // Verify that the web database has been updated and the notification sent. | 515 // Verify that the web database has been updated and the notification sent. |
| 515 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 516 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 516 .WillOnce(QuitMainMessageLoop()); | 517 .WillOnce(QuitMainMessageLoop()); |
| 517 base::RunLoop().Run(); | 518 base::RunLoop().Run(); |
| 518 | 519 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 544 | 545 |
| 545 // Verify that we've loaded the credit cards from the web database. | 546 // Verify that we've loaded the credit cards from the web database. |
| 546 cards.clear(); | 547 cards.clear(); |
| 547 cards.push_back(&credit_card0); | 548 cards.push_back(&credit_card0); |
| 548 cards.push_back(&credit_card2); | 549 cards.push_back(&credit_card2); |
| 549 ExpectSameElements(cards, personal_data_->GetCreditCards()); | 550 ExpectSameElements(cards, personal_data_->GetCreditCards()); |
| 550 | 551 |
| 551 // Add a full server card. | 552 // Add a full server card. |
| 552 CreditCard credit_card3(base::GenerateGUID(), "https://www.example.com"); | 553 CreditCard credit_card3(base::GenerateGUID(), "https://www.example.com"); |
| 553 test::SetCreditCardInfo(&credit_card3, "Jane Doe", | 554 test::SetCreditCardInfo(&credit_card3, "Jane Doe", |
| 554 "4111111111111111" /* Visa */, "04", "2999"); | 555 "4111111111111111" /* Visa */, "04", "2999", "1"); |
| 555 credit_card3.set_record_type(CreditCard::FULL_SERVER_CARD); | 556 credit_card3.set_record_type(CreditCard::FULL_SERVER_CARD); |
| 556 credit_card3.set_server_id("server_id"); | 557 credit_card3.set_server_id("server_id"); |
| 557 | 558 |
| 558 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 559 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 559 .WillOnce(QuitMainMessageLoop()); | 560 .WillOnce(QuitMainMessageLoop()); |
| 560 | 561 |
| 561 personal_data_->AddFullServerCreditCard(credit_card3); | 562 personal_data_->AddFullServerCreditCard(credit_card3); |
| 562 base::RunLoop().Run(); | 563 base::RunLoop().Run(); |
| 563 | 564 |
| 564 cards.push_back(&credit_card3); | 565 cards.push_back(&credit_card3); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 584 | 585 |
| 585 // Test that a new credit card has its basic information set. | 586 // Test that a new credit card has its basic information set. |
| 586 TEST_F(PersonalDataManagerTest, AddCreditCard_BasicInformation) { | 587 TEST_F(PersonalDataManagerTest, AddCreditCard_BasicInformation) { |
| 587 // Create the test clock and set the time to a specific value. | 588 // Create the test clock and set the time to a specific value. |
| 588 TestAutofillClock test_clock; | 589 TestAutofillClock test_clock; |
| 589 test_clock.SetNow(kArbitraryTime); | 590 test_clock.SetNow(kArbitraryTime); |
| 590 | 591 |
| 591 // Add a credit card to the database. | 592 // Add a credit card to the database. |
| 592 CreditCard credit_card(base::GenerateGUID(), "https://www.example.com"); | 593 CreditCard credit_card(base::GenerateGUID(), "https://www.example.com"); |
| 593 test::SetCreditCardInfo(&credit_card, "John Dillinger", | 594 test::SetCreditCardInfo(&credit_card, "John Dillinger", |
| 594 "423456789012" /* Visa */, "01", "2999"); | 595 "423456789012" /* Visa */, "01", "2999", "1"); |
| 595 personal_data_->AddCreditCard(credit_card); | 596 personal_data_->AddCreditCard(credit_card); |
| 596 | 597 |
| 597 // Reload the database. | 598 // Reload the database. |
| 598 ResetPersonalDataManager(USER_MODE_NORMAL); | 599 ResetPersonalDataManager(USER_MODE_NORMAL); |
| 599 | 600 |
| 600 // Verify the addition. | 601 // Verify the addition. |
| 601 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); | 602 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); |
| 602 ASSERT_EQ(1U, results.size()); | 603 ASSERT_EQ(1U, results.size()); |
| 603 EXPECT_EQ(0, credit_card.Compare(*results[0])); | 604 EXPECT_EQ(0, credit_card.Compare(*results[0])); |
| 604 | 605 |
| 605 // Make sure the use count and use date were set. | 606 // Make sure the use count and use date were set. |
| 606 EXPECT_EQ(1U, results[0]->use_count()); | 607 EXPECT_EQ(1U, results[0]->use_count()); |
| 607 EXPECT_EQ(kArbitraryTime, results[0]->use_date()); | 608 EXPECT_EQ(kArbitraryTime, results[0]->use_date()); |
| 608 EXPECT_EQ(kArbitraryTime, results[0]->modification_date()); | 609 EXPECT_EQ(kArbitraryTime, results[0]->modification_date()); |
| 609 } | 610 } |
| 610 | 611 |
| 611 TEST_F(PersonalDataManagerTest, UpdateUnverifiedProfilesAndCreditCards) { | 612 TEST_F(PersonalDataManagerTest, UpdateUnverifiedProfilesAndCreditCards) { |
| 612 // Start with unverified data. | 613 // Start with unverified data. |
| 613 AutofillProfile profile(base::GenerateGUID(), "https://www.example.com/"); | 614 AutofillProfile profile(base::GenerateGUID(), "https://www.example.com/"); |
| 614 test::SetProfileInfo(&profile, | 615 test::SetProfileInfo(&profile, |
| 615 "Marion", "Mitchell", "Morrison", | 616 "Marion", "Mitchell", "Morrison", |
| 616 "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", "Hollywood", "CA", | 617 "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", "Hollywood", "CA", |
| 617 "91601", "US", "12345678910"); | 618 "91601", "US", "12345678910"); |
| 618 EXPECT_FALSE(profile.IsVerified()); | 619 EXPECT_FALSE(profile.IsVerified()); |
| 619 | 620 |
| 620 CreditCard credit_card(base::GenerateGUID(), "https://www.example.com/"); | 621 CreditCard credit_card(base::GenerateGUID(), "https://www.example.com/"); |
| 621 test::SetCreditCardInfo(&credit_card, | 622 test::SetCreditCardInfo(&credit_card, "John Dillinger", |
| 622 "John Dillinger", "423456789012" /* Visa */, "01", "2999"); | 623 "423456789012" /* Visa */, "01", "2999", "1"); |
| 623 EXPECT_FALSE(credit_card.IsVerified()); | 624 EXPECT_FALSE(credit_card.IsVerified()); |
| 624 | 625 |
| 625 // Add the data to the database. | 626 // Add the data to the database. |
| 626 personal_data_->AddProfile(profile); | 627 personal_data_->AddProfile(profile); |
| 627 personal_data_->AddCreditCard(credit_card); | 628 personal_data_->AddCreditCard(credit_card); |
| 628 | 629 |
| 629 // Verify that the web database has been updated and the notification sent. | 630 // Verify that the web database has been updated and the notification sent. |
| 630 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 631 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 631 .WillOnce(QuitMainMessageLoop()); | 632 .WillOnce(QuitMainMessageLoop()); |
| 632 base::RunLoop().Run(); | 633 base::RunLoop().Run(); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 694 EXPECT_FALSE(base::CommandLine::ForCurrentProcess()->HasSwitch( | 695 EXPECT_FALSE(base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 695 switches::kDisableOfferStoreUnmaskedWalletCards)); | 696 switches::kDisableOfferStoreUnmaskedWalletCards)); |
| 696 #else | 697 #else |
| 697 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 698 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 698 switches::kDisableOfferStoreUnmaskedWalletCards); | 699 switches::kDisableOfferStoreUnmaskedWalletCards); |
| 699 #endif | 700 #endif |
| 700 | 701 |
| 701 std::vector<CreditCard> server_cards; | 702 std::vector<CreditCard> server_cards; |
| 702 server_cards.push_back(CreditCard(CreditCard::FULL_SERVER_CARD, "c789")); | 703 server_cards.push_back(CreditCard(CreditCard::FULL_SERVER_CARD, "c789")); |
| 703 test::SetCreditCardInfo(&server_cards.back(), "Clyde Barrow", | 704 test::SetCreditCardInfo(&server_cards.back(), "Clyde Barrow", |
| 704 "347666888555" /* American Express */, "04", "2999"); | 705 "347666888555" /* American Express */, "04", "2999", |
| 706 "1"); |
| 705 test::SetServerCreditCards(autofill_table_, server_cards); | 707 test::SetServerCreditCards(autofill_table_, server_cards); |
| 706 personal_data_->Refresh(); | 708 personal_data_->Refresh(); |
| 707 | 709 |
| 708 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 710 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 709 .WillOnce(QuitMainMessageLoop()); | 711 .WillOnce(QuitMainMessageLoop()); |
| 710 base::RunLoop().Run(); | 712 base::RunLoop().Run(); |
| 711 | 713 |
| 712 ASSERT_EQ(1U, personal_data_->GetCreditCards().size()); | 714 ASSERT_EQ(1U, personal_data_->GetCreditCards().size()); |
| 713 EXPECT_EQ(CreditCard::MASKED_SERVER_CARD, | 715 EXPECT_EQ(CreditCard::MASKED_SERVER_CARD, |
| 714 personal_data_->GetCreditCards()[0]->record_type()); | 716 personal_data_->GetCreditCards()[0]->record_type()); |
| 715 } | 717 } |
| 716 | 718 |
| 717 // Makes sure that full cards are only added as masked card when full PAN | 719 // Makes sure that full cards are only added as masked card when full PAN |
| 718 // storage is disabled. | 720 // storage is disabled. |
| 719 TEST_F(PersonalDataManagerTest, AddFullCardAsMaskedCard) { | 721 TEST_F(PersonalDataManagerTest, AddFullCardAsMaskedCard) { |
| 720 // On Linux this should be disabled automatically. Elsewhere, only if the | 722 // On Linux this should be disabled automatically. Elsewhere, only if the |
| 721 // flag is passed. | 723 // flag is passed. |
| 722 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) | 724 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) |
| 723 EXPECT_FALSE(base::CommandLine::ForCurrentProcess()->HasSwitch( | 725 EXPECT_FALSE(base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 724 switches::kDisableOfferStoreUnmaskedWalletCards)); | 726 switches::kDisableOfferStoreUnmaskedWalletCards)); |
| 725 #else | 727 #else |
| 726 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 728 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 727 switches::kDisableOfferStoreUnmaskedWalletCards); | 729 switches::kDisableOfferStoreUnmaskedWalletCards); |
| 728 #endif | 730 #endif |
| 729 | 731 |
| 730 CreditCard server_card(CreditCard::FULL_SERVER_CARD, "c789"); | 732 CreditCard server_card(CreditCard::FULL_SERVER_CARD, "c789"); |
| 731 test::SetCreditCardInfo(&server_card, "Clyde Barrow", | 733 test::SetCreditCardInfo(&server_card, "Clyde Barrow", |
| 732 "347666888555" /* American Express */, "04", "2999"); | 734 "347666888555" /* American Express */, "04", "2999", |
| 735 "1"); |
| 733 | 736 |
| 734 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 737 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 735 .WillOnce(QuitMainMessageLoop()); | 738 .WillOnce(QuitMainMessageLoop()); |
| 736 | 739 |
| 737 personal_data_->AddFullServerCreditCard(server_card); | 740 personal_data_->AddFullServerCreditCard(server_card); |
| 738 | 741 |
| 739 base::RunLoop().Run(); | 742 base::RunLoop().Run(); |
| 740 | 743 |
| 741 ASSERT_EQ(1U, personal_data_->GetCreditCards().size()); | 744 ASSERT_EQ(1U, personal_data_->GetCreditCards().size()); |
| 742 EXPECT_EQ(CreditCard::MASKED_SERVER_CARD, | 745 EXPECT_EQ(CreditCard::MASKED_SERVER_CARD, |
| (...skipping 10 matching lines...) Expand all Loading... |
| 753 EXPECT_EQ(should_offer, OfferStoreUnmaskedCards()); | 756 EXPECT_EQ(should_offer, OfferStoreUnmaskedCards()); |
| 754 } | 757 } |
| 755 | 758 |
| 756 // Tests that UpdateServerCreditCard can be used to mask or unmask server cards. | 759 // Tests that UpdateServerCreditCard can be used to mask or unmask server cards. |
| 757 TEST_F(PersonalDataManagerTest, UpdateServerCreditCards) { | 760 TEST_F(PersonalDataManagerTest, UpdateServerCreditCards) { |
| 758 EnableWalletCardImport(); | 761 EnableWalletCardImport(); |
| 759 | 762 |
| 760 std::vector<CreditCard> server_cards; | 763 std::vector<CreditCard> server_cards; |
| 761 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "a123")); | 764 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "a123")); |
| 762 test::SetCreditCardInfo(&server_cards.back(), "John Dillinger", | 765 test::SetCreditCardInfo(&server_cards.back(), "John Dillinger", |
| 763 "9012" /* Visa */, "01", "2999"); | 766 "9012" /* Visa */, "01", "2999", "1"); |
| 764 server_cards.back().SetNetworkForMaskedCard(kVisaCard); | 767 server_cards.back().SetNetworkForMaskedCard(kVisaCard); |
| 765 | 768 |
| 766 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "b456")); | 769 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "b456")); |
| 767 test::SetCreditCardInfo(&server_cards.back(), "Bonnie Parker", | 770 test::SetCreditCardInfo(&server_cards.back(), "Bonnie Parker", |
| 768 "2109" /* Mastercard */, "12", "2999"); | 771 "2109" /* Mastercard */, "12", "2999", "1"); |
| 769 server_cards.back().SetNetworkForMaskedCard(kMasterCard); | 772 server_cards.back().SetNetworkForMaskedCard(kMasterCard); |
| 770 | 773 |
| 771 server_cards.push_back(CreditCard(CreditCard::FULL_SERVER_CARD, "c789")); | 774 server_cards.push_back(CreditCard(CreditCard::FULL_SERVER_CARD, "c789")); |
| 772 test::SetCreditCardInfo(&server_cards.back(), "Clyde Barrow", | 775 test::SetCreditCardInfo(&server_cards.back(), "Clyde Barrow", |
| 773 "347666888555" /* American Express */, "04", "2999"); | 776 "347666888555" /* American Express */, "04", "2999", |
| 777 "1"); |
| 774 | 778 |
| 775 test::SetServerCreditCards(autofill_table_, server_cards); | 779 test::SetServerCreditCards(autofill_table_, server_cards); |
| 776 personal_data_->Refresh(); | 780 personal_data_->Refresh(); |
| 777 | 781 |
| 778 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 782 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 779 .WillOnce(QuitMainMessageLoop()); | 783 .WillOnce(QuitMainMessageLoop()); |
| 780 base::RunLoop().Run(); | 784 base::RunLoop().Run(); |
| 781 | 785 |
| 782 ASSERT_EQ(3U, personal_data_->GetCreditCards().size()); | 786 ASSERT_EQ(3U, personal_data_->GetCreditCards().size()); |
| 783 | 787 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 830 "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", "Hollywood", "CA", | 834 "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", "Hollywood", "CA", |
| 831 "91601", "US", "12345678910"); | 835 "91601", "US", "12345678910"); |
| 832 | 836 |
| 833 AutofillProfile profile1(base::GenerateGUID(), "https://www.example.com"); | 837 AutofillProfile profile1(base::GenerateGUID(), "https://www.example.com"); |
| 834 test::SetProfileInfo(&profile1, | 838 test::SetProfileInfo(&profile1, |
| 835 "Josephine", "Alicia", "Saenz", | 839 "Josephine", "Alicia", "Saenz", |
| 836 "joewayne@me.xyz", "Fox", "903 Apple Ct.", NULL, "Orlando", "FL", "32801", | 840 "joewayne@me.xyz", "Fox", "903 Apple Ct.", NULL, "Orlando", "FL", "32801", |
| 837 "US", "19482937549"); | 841 "US", "19482937549"); |
| 838 | 842 |
| 839 CreditCard credit_card0(base::GenerateGUID(), "https://www.example.com"); | 843 CreditCard credit_card0(base::GenerateGUID(), "https://www.example.com"); |
| 840 test::SetCreditCardInfo(&credit_card0, | 844 test::SetCreditCardInfo(&credit_card0, "John Dillinger", |
| 841 "John Dillinger", "423456789012" /* Visa */, "01", "2999"); | 845 "423456789012" /* Visa */, "01", "2999", "1"); |
| 842 | 846 |
| 843 CreditCard credit_card1(base::GenerateGUID(), "https://www.example.com"); | 847 CreditCard credit_card1(base::GenerateGUID(), "https://www.example.com"); |
| 844 test::SetCreditCardInfo(&credit_card1, "Bonnie Parker", | 848 test::SetCreditCardInfo(&credit_card1, "Bonnie Parker", |
| 845 "518765432109" /* Mastercard */, "12", "2999"); | 849 "518765432109" /* Mastercard */, "12", "2999", "1"); |
| 846 | 850 |
| 847 // Add two test profiles to the database. | 851 // Add two test profiles to the database. |
| 848 personal_data_->AddProfile(profile0); | 852 personal_data_->AddProfile(profile0); |
| 849 personal_data_->AddProfile(profile1); | 853 personal_data_->AddProfile(profile1); |
| 850 | 854 |
| 851 // Verify that the web database has been updated and the notification sent. | 855 // Verify that the web database has been updated and the notification sent. |
| 852 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 856 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 853 .WillOnce(QuitMainMessageLoop()); | 857 .WillOnce(QuitMainMessageLoop()); |
| 854 base::RunLoop().Run(); | 858 base::RunLoop().Run(); |
| 855 | 859 |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 973 // database. | 977 // database. |
| 974 ResetPersonalDataManager(USER_MODE_NORMAL); | 978 ResetPersonalDataManager(USER_MODE_NORMAL); |
| 975 | 979 |
| 976 // Verify that we've loaded the profiles from the web database. | 980 // Verify that we've loaded the profiles from the web database. |
| 977 const std::vector<AutofillProfile*>& results2 = personal_data_->GetProfiles(); | 981 const std::vector<AutofillProfile*>& results2 = personal_data_->GetProfiles(); |
| 978 ASSERT_EQ(0U, results2.size()); | 982 ASSERT_EQ(0U, results2.size()); |
| 979 } | 983 } |
| 980 | 984 |
| 981 TEST_F(PersonalDataManagerTest, SetEmptyCreditCard) { | 985 TEST_F(PersonalDataManagerTest, SetEmptyCreditCard) { |
| 982 CreditCard credit_card0(base::GenerateGUID(), "https://www.example.com"); | 986 CreditCard credit_card0(base::GenerateGUID(), "https://www.example.com"); |
| 983 test::SetCreditCardInfo(&credit_card0, "", "", "", ""); | 987 test::SetCreditCardInfo(&credit_card0, "", "", "", "", ""); |
| 984 | 988 |
| 985 // Add the empty credit card to the database. | 989 // Add the empty credit card to the database. |
| 986 personal_data_->AddCreditCard(credit_card0); | 990 personal_data_->AddCreditCard(credit_card0); |
| 987 | 991 |
| 988 // Note: no refresh here. | 992 // Note: no refresh here. |
| 989 | 993 |
| 990 // Reset the PersonalDataManager. This tests that the personal data was saved | 994 // Reset the PersonalDataManager. This tests that the personal data was saved |
| 991 // to the web database, and that we can load the credit cards from the web | 995 // to the web database, and that we can load the credit cards from the web |
| 992 // database. | 996 // database. |
| 993 ResetPersonalDataManager(USER_MODE_NORMAL); | 997 ResetPersonalDataManager(USER_MODE_NORMAL); |
| (...skipping 1213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2207 ASSERT_TRUE(imported_credit_card); | 2211 ASSERT_TRUE(imported_credit_card); |
| 2208 personal_data_->SaveImportedCreditCard(*imported_credit_card); | 2212 personal_data_->SaveImportedCreditCard(*imported_credit_card); |
| 2209 | 2213 |
| 2210 // Verify that the web database has been updated and the notification sent. | 2214 // Verify that the web database has been updated and the notification sent. |
| 2211 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 2215 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 2212 .WillOnce(QuitMainMessageLoop()); | 2216 .WillOnce(QuitMainMessageLoop()); |
| 2213 base::RunLoop().Run(); | 2217 base::RunLoop().Run(); |
| 2214 | 2218 |
| 2215 CreditCard expected(base::GenerateGUID(), "https://www.example.com"); | 2219 CreditCard expected(base::GenerateGUID(), "https://www.example.com"); |
| 2216 test::SetCreditCardInfo(&expected, "Biggie Smalls", "4111111111111111", "01", | 2220 test::SetCreditCardInfo(&expected, "Biggie Smalls", "4111111111111111", "01", |
| 2217 "2999"); | 2221 "2999", "1"); |
| 2218 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); | 2222 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); |
| 2219 ASSERT_EQ(1U, results.size()); | 2223 ASSERT_EQ(1U, results.size()); |
| 2220 EXPECT_EQ(0, expected.Compare(*results[0])); | 2224 EXPECT_EQ(0, expected.Compare(*results[0])); |
| 2221 } | 2225 } |
| 2222 | 2226 |
| 2223 // Tests that an invalid credit card is not extracted. | 2227 // Tests that an invalid credit card is not extracted. |
| 2224 TEST_F(PersonalDataManagerTest, ImportCreditCard_Invalid) { | 2228 TEST_F(PersonalDataManagerTest, ImportCreditCard_Invalid) { |
| 2225 FormData form; | 2229 FormData form; |
| 2226 AddFullCreditCardForm(&form, "Jim Johansen", "1000000000000000", "02", | 2230 AddFullCreditCardForm(&form, "Jim Johansen", "1000000000000000", "02", |
| 2227 "2999"); | 2231 "2999"); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2268 personal_data_->SaveImportedCreditCard(*imported_credit_card); | 2272 personal_data_->SaveImportedCreditCard(*imported_credit_card); |
| 2269 | 2273 |
| 2270 // Verify that the web database has been updated and the notification sent. | 2274 // Verify that the web database has been updated and the notification sent. |
| 2271 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 2275 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 2272 .WillOnce(QuitMainMessageLoop()); | 2276 .WillOnce(QuitMainMessageLoop()); |
| 2273 base::RunLoop().Run(); | 2277 base::RunLoop().Run(); |
| 2274 | 2278 |
| 2275 // See that the invalid option text was converted to the right value. | 2279 // See that the invalid option text was converted to the right value. |
| 2276 CreditCard expected(base::GenerateGUID(), "https://www.example.com"); | 2280 CreditCard expected(base::GenerateGUID(), "https://www.example.com"); |
| 2277 test::SetCreditCardInfo(&expected, "Biggie Smalls", "4111111111111111", "02", | 2281 test::SetCreditCardInfo(&expected, "Biggie Smalls", "4111111111111111", "02", |
| 2278 "2999"); | 2282 "2999", "1"); |
| 2279 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); | 2283 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); |
| 2280 ASSERT_EQ(1U, results.size()); | 2284 ASSERT_EQ(1U, results.size()); |
| 2281 EXPECT_EQ(0, expected.Compare(*results[0])); | 2285 EXPECT_EQ(0, expected.Compare(*results[0])); |
| 2282 } | 2286 } |
| 2283 | 2287 |
| 2284 TEST_F(PersonalDataManagerTest, ImportCreditCard_TwoValidCards) { | 2288 TEST_F(PersonalDataManagerTest, ImportCreditCard_TwoValidCards) { |
| 2285 // Start with a single valid credit card form. | 2289 // Start with a single valid credit card form. |
| 2286 FormData form1; | 2290 FormData form1; |
| 2287 AddFullCreditCardForm(&form1, "Biggie Smalls", "4111-1111-1111-1111", "01", | 2291 AddFullCreditCardForm(&form1, "Biggie Smalls", "4111-1111-1111-1111", "01", |
| 2288 "2999"); | 2292 "2999"); |
| 2289 | 2293 |
| 2290 FormStructure form_structure1(form1); | 2294 FormStructure form_structure1(form1); |
| 2291 form_structure1.DetermineHeuristicTypes(nullptr /* ukm_service */); | 2295 form_structure1.DetermineHeuristicTypes(nullptr /* ukm_service */); |
| 2292 std::unique_ptr<CreditCard> imported_credit_card; | 2296 std::unique_ptr<CreditCard> imported_credit_card; |
| 2293 EXPECT_TRUE(ImportCreditCard(form_structure1, false, &imported_credit_card)); | 2297 EXPECT_TRUE(ImportCreditCard(form_structure1, false, &imported_credit_card)); |
| 2294 ASSERT_TRUE(imported_credit_card); | 2298 ASSERT_TRUE(imported_credit_card); |
| 2295 personal_data_->SaveImportedCreditCard(*imported_credit_card); | 2299 personal_data_->SaveImportedCreditCard(*imported_credit_card); |
| 2296 | 2300 |
| 2297 // Verify that the web database has been updated and the notification sent. | 2301 // Verify that the web database has been updated and the notification sent. |
| 2298 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 2302 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 2299 .WillOnce(QuitMainMessageLoop()); | 2303 .WillOnce(QuitMainMessageLoop()); |
| 2300 base::RunLoop().Run(); | 2304 base::RunLoop().Run(); |
| 2301 | 2305 |
| 2302 CreditCard expected(base::GenerateGUID(), "https://www.example.com"); | 2306 CreditCard expected(base::GenerateGUID(), "https://www.example.com"); |
| 2303 test::SetCreditCardInfo(&expected, "Biggie Smalls", "4111111111111111", "01", | 2307 test::SetCreditCardInfo(&expected, "Biggie Smalls", "4111111111111111", "01", |
| 2304 "2999"); | 2308 "2999", "1"); |
| 2305 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); | 2309 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); |
| 2306 ASSERT_EQ(1U, results.size()); | 2310 ASSERT_EQ(1U, results.size()); |
| 2307 EXPECT_EQ(0, expected.Compare(*results[0])); | 2311 EXPECT_EQ(0, expected.Compare(*results[0])); |
| 2308 | 2312 |
| 2309 // Add a second different valid credit card. | 2313 // Add a second different valid credit card. |
| 2310 FormData form2; | 2314 FormData form2; |
| 2311 AddFullCreditCardForm(&form2, "", "5500 0000 0000 0004", "02", "2999"); | 2315 AddFullCreditCardForm(&form2, "", "5500 0000 0000 0004", "02", "2999"); |
| 2312 | 2316 |
| 2313 FormStructure form_structure2(form2); | 2317 FormStructure form_structure2(form2); |
| 2314 form_structure2.DetermineHeuristicTypes(nullptr /* ukm_service */); | 2318 form_structure2.DetermineHeuristicTypes(nullptr /* ukm_service */); |
| 2315 std::unique_ptr<CreditCard> imported_credit_card2; | 2319 std::unique_ptr<CreditCard> imported_credit_card2; |
| 2316 EXPECT_TRUE(ImportCreditCard(form_structure2, false, &imported_credit_card2)); | 2320 EXPECT_TRUE(ImportCreditCard(form_structure2, false, &imported_credit_card2)); |
| 2317 ASSERT_TRUE(imported_credit_card2); | 2321 ASSERT_TRUE(imported_credit_card2); |
| 2318 personal_data_->SaveImportedCreditCard(*imported_credit_card2); | 2322 personal_data_->SaveImportedCreditCard(*imported_credit_card2); |
| 2319 | 2323 |
| 2320 // Verify that the web database has been updated and the notification sent. | 2324 // Verify that the web database has been updated and the notification sent. |
| 2321 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 2325 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 2322 .WillOnce(QuitMainMessageLoop()); | 2326 .WillOnce(QuitMainMessageLoop()); |
| 2323 base::RunLoop().Run(); | 2327 base::RunLoop().Run(); |
| 2324 | 2328 |
| 2325 CreditCard expected2(base::GenerateGUID(), "https://www.example.com"); | 2329 CreditCard expected2(base::GenerateGUID(), "https://www.example.com"); |
| 2326 test::SetCreditCardInfo(&expected2, "", "5500000000000004", "02", "2999"); | 2330 test::SetCreditCardInfo(&expected2, "", "5500000000000004", "02", "2999", |
| 2331 "1"); |
| 2327 std::vector<CreditCard*> cards; | 2332 std::vector<CreditCard*> cards; |
| 2328 cards.push_back(&expected); | 2333 cards.push_back(&expected); |
| 2329 cards.push_back(&expected2); | 2334 cards.push_back(&expected2); |
| 2330 ExpectSameElements(cards, personal_data_->GetCreditCards()); | 2335 ExpectSameElements(cards, personal_data_->GetCreditCards()); |
| 2331 } | 2336 } |
| 2332 | 2337 |
| 2333 // This form has the expiration year as one field with MM/YY. | 2338 // This form has the expiration year as one field with MM/YY. |
| 2334 TEST_F(PersonalDataManagerTest, ImportCreditCard_Month2DigitYearCombination) { | 2339 TEST_F(PersonalDataManagerTest, ImportCreditCard_Month2DigitYearCombination) { |
| 2335 FormData form; | 2340 FormData form; |
| 2336 FormFieldData field; | 2341 FormFieldData field; |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2407 } | 2412 } |
| 2408 | 2413 |
| 2409 // Tests that a credit card is extracted because it only matches a masked server | 2414 // Tests that a credit card is extracted because it only matches a masked server |
| 2410 // card. | 2415 // card. |
| 2411 TEST_F(PersonalDataManagerTest, | 2416 TEST_F(PersonalDataManagerTest, |
| 2412 ImportCreditCard_DuplicateServerCards_MaskedCard) { | 2417 ImportCreditCard_DuplicateServerCards_MaskedCard) { |
| 2413 // Add a masked server card. | 2418 // Add a masked server card. |
| 2414 std::vector<CreditCard> server_cards; | 2419 std::vector<CreditCard> server_cards; |
| 2415 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "a123")); | 2420 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "a123")); |
| 2416 test::SetCreditCardInfo(&server_cards.back(), "John Dillinger", | 2421 test::SetCreditCardInfo(&server_cards.back(), "John Dillinger", |
| 2417 "1111" /* Visa */, "01", "2999"); | 2422 "1111" /* Visa */, "01", "2999", "1"); |
| 2418 server_cards.back().SetNetworkForMaskedCard(kVisaCard); | 2423 server_cards.back().SetNetworkForMaskedCard(kVisaCard); |
| 2419 test::SetServerCreditCards(autofill_table_, server_cards); | 2424 test::SetServerCreditCards(autofill_table_, server_cards); |
| 2420 | 2425 |
| 2421 // Type the same data as the masked card into a form. | 2426 // Type the same data as the masked card into a form. |
| 2422 FormData form; | 2427 FormData form; |
| 2423 AddFullCreditCardForm(&form, "John Dillinger", "4111111111111111", "01", | 2428 AddFullCreditCardForm(&form, "John Dillinger", "4111111111111111", "01", |
| 2424 "2999"); | 2429 "2999"); |
| 2425 | 2430 |
| 2426 // The card should be offered to be saved locally because it only matches the | 2431 // The card should be offered to be saved locally because it only matches the |
| 2427 // masked server card. | 2432 // masked server card. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 2439 } | 2444 } |
| 2440 | 2445 |
| 2441 // Tests that a credit card is not extracted because it matches a full server | 2446 // Tests that a credit card is not extracted because it matches a full server |
| 2442 // card. | 2447 // card. |
| 2443 TEST_F(PersonalDataManagerTest, | 2448 TEST_F(PersonalDataManagerTest, |
| 2444 ImportCreditCard_DuplicateServerCards_FullCard) { | 2449 ImportCreditCard_DuplicateServerCards_FullCard) { |
| 2445 // Add a full server card. | 2450 // Add a full server card. |
| 2446 std::vector<CreditCard> server_cards; | 2451 std::vector<CreditCard> server_cards; |
| 2447 server_cards.push_back(CreditCard(CreditCard::FULL_SERVER_CARD, "c789")); | 2452 server_cards.push_back(CreditCard(CreditCard::FULL_SERVER_CARD, "c789")); |
| 2448 test::SetCreditCardInfo(&server_cards.back(), "Clyde Barrow", | 2453 test::SetCreditCardInfo(&server_cards.back(), "Clyde Barrow", |
| 2449 "347666888555" /* American Express */, "04", "2999"); | 2454 "347666888555" /* American Express */, "04", "2999", |
| 2455 "1"); |
| 2450 test::SetServerCreditCards(autofill_table_, server_cards); | 2456 test::SetServerCreditCards(autofill_table_, server_cards); |
| 2451 | 2457 |
| 2452 // Type the same data as the unmasked card into a form. | 2458 // Type the same data as the unmasked card into a form. |
| 2453 FormData form; | 2459 FormData form; |
| 2454 AddFullCreditCardForm(&form, "Clyde Barrow", "347666888555", "04", "2999"); | 2460 AddFullCreditCardForm(&form, "Clyde Barrow", "347666888555", "04", "2999"); |
| 2455 | 2461 |
| 2456 // The card should not be offered to be saved locally because it only matches | 2462 // The card should not be offered to be saved locally because it only matches |
| 2457 // the full server card. | 2463 // the full server card. |
| 2458 FormStructure form_structure(form); | 2464 FormStructure form_structure(form); |
| 2459 form_structure.DetermineHeuristicTypes(nullptr /* ukm_service */); | 2465 form_structure.DetermineHeuristicTypes(nullptr /* ukm_service */); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 2475 ASSERT_TRUE(imported_credit_card); | 2481 ASSERT_TRUE(imported_credit_card); |
| 2476 personal_data_->SaveImportedCreditCard(*imported_credit_card); | 2482 personal_data_->SaveImportedCreditCard(*imported_credit_card); |
| 2477 | 2483 |
| 2478 // Verify that the web database has been updated and the notification sent. | 2484 // Verify that the web database has been updated and the notification sent. |
| 2479 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 2485 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 2480 .WillOnce(QuitMainMessageLoop()); | 2486 .WillOnce(QuitMainMessageLoop()); |
| 2481 base::RunLoop().Run(); | 2487 base::RunLoop().Run(); |
| 2482 | 2488 |
| 2483 CreditCard expected(base::GenerateGUID(), "https://www.example.com"); | 2489 CreditCard expected(base::GenerateGUID(), "https://www.example.com"); |
| 2484 test::SetCreditCardInfo(&expected, "Biggie Smalls", "4111111111111111", "01", | 2490 test::SetCreditCardInfo(&expected, "Biggie Smalls", "4111111111111111", "01", |
| 2485 "2998"); | 2491 "2998", "1"); |
| 2486 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); | 2492 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); |
| 2487 ASSERT_EQ(1U, results.size()); | 2493 ASSERT_EQ(1U, results.size()); |
| 2488 EXPECT_EQ(0, expected.Compare(*results[0])); | 2494 EXPECT_EQ(0, expected.Compare(*results[0])); |
| 2489 | 2495 |
| 2490 // Add a second different valid credit card where the year is different but | 2496 // Add a second different valid credit card where the year is different but |
| 2491 // the credit card number matches. | 2497 // the credit card number matches. |
| 2492 FormData form2; | 2498 FormData form2; |
| 2493 AddFullCreditCardForm(&form2, "Biggie Smalls", "4111 1111 1111 1111", "01", | 2499 AddFullCreditCardForm(&form2, "Biggie Smalls", "4111 1111 1111 1111", "01", |
| 2494 /* different year */ "2999"); | 2500 /* different year */ "2999"); |
| 2495 | 2501 |
| 2496 FormStructure form_structure2(form2); | 2502 FormStructure form_structure2(form2); |
| 2497 form_structure2.DetermineHeuristicTypes(nullptr /* ukm_service */); | 2503 form_structure2.DetermineHeuristicTypes(nullptr /* ukm_service */); |
| 2498 std::unique_ptr<CreditCard> imported_credit_card2; | 2504 std::unique_ptr<CreditCard> imported_credit_card2; |
| 2499 EXPECT_TRUE(ImportCreditCard(form_structure2, false, &imported_credit_card2)); | 2505 EXPECT_TRUE(ImportCreditCard(form_structure2, false, &imported_credit_card2)); |
| 2500 EXPECT_FALSE(imported_credit_card2); | 2506 EXPECT_FALSE(imported_credit_card2); |
| 2501 | 2507 |
| 2502 // Verify that the web database has been updated and the notification sent. | 2508 // Verify that the web database has been updated and the notification sent. |
| 2503 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 2509 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 2504 .WillOnce(QuitMainMessageLoop()); | 2510 .WillOnce(QuitMainMessageLoop()); |
| 2505 base::RunLoop().Run(); | 2511 base::RunLoop().Run(); |
| 2506 | 2512 |
| 2507 // Expect that the newer information is saved. In this case the year is | 2513 // Expect that the newer information is saved. In this case the year is |
| 2508 // updated to "2999". | 2514 // updated to "2999". |
| 2509 CreditCard expected2(base::GenerateGUID(), "https://www.example.com"); | 2515 CreditCard expected2(base::GenerateGUID(), "https://www.example.com"); |
| 2510 test::SetCreditCardInfo(&expected2, "Biggie Smalls", "4111111111111111", "01", | 2516 test::SetCreditCardInfo(&expected2, "Biggie Smalls", "4111111111111111", "01", |
| 2511 "2999"); | 2517 "2999", "1"); |
| 2512 const std::vector<CreditCard*>& results2 = personal_data_->GetCreditCards(); | 2518 const std::vector<CreditCard*>& results2 = personal_data_->GetCreditCards(); |
| 2513 ASSERT_EQ(1U, results2.size()); | 2519 ASSERT_EQ(1U, results2.size()); |
| 2514 EXPECT_EQ(0, expected2.Compare(*results2[0])); | 2520 EXPECT_EQ(0, expected2.Compare(*results2[0])); |
| 2515 } | 2521 } |
| 2516 | 2522 |
| 2517 TEST_F(PersonalDataManagerTest, ImportCreditCard_ShouldReturnLocalCard) { | 2523 TEST_F(PersonalDataManagerTest, ImportCreditCard_ShouldReturnLocalCard) { |
| 2518 // Start with a single valid credit card form. | 2524 // Start with a single valid credit card form. |
| 2519 FormData form1; | 2525 FormData form1; |
| 2520 AddFullCreditCardForm(&form1, "Biggie Smalls", "4111-1111-1111-1111", "01", | 2526 AddFullCreditCardForm(&form1, "Biggie Smalls", "4111-1111-1111-1111", "01", |
| 2521 "2998"); | 2527 "2998"); |
| 2522 | 2528 |
| 2523 FormStructure form_structure1(form1); | 2529 FormStructure form_structure1(form1); |
| 2524 form_structure1.DetermineHeuristicTypes(nullptr /* ukm_service */); | 2530 form_structure1.DetermineHeuristicTypes(nullptr /* ukm_service */); |
| 2525 std::unique_ptr<CreditCard> imported_credit_card; | 2531 std::unique_ptr<CreditCard> imported_credit_card; |
| 2526 EXPECT_TRUE(ImportCreditCard(form_structure1, false, &imported_credit_card)); | 2532 EXPECT_TRUE(ImportCreditCard(form_structure1, false, &imported_credit_card)); |
| 2527 ASSERT_TRUE(imported_credit_card); | 2533 ASSERT_TRUE(imported_credit_card); |
| 2528 personal_data_->SaveImportedCreditCard(*imported_credit_card); | 2534 personal_data_->SaveImportedCreditCard(*imported_credit_card); |
| 2529 | 2535 |
| 2530 // Verify that the web database has been updated and the notification sent. | 2536 // Verify that the web database has been updated and the notification sent. |
| 2531 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 2537 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 2532 .WillOnce(QuitMainMessageLoop()); | 2538 .WillOnce(QuitMainMessageLoop()); |
| 2533 base::RunLoop().Run(); | 2539 base::RunLoop().Run(); |
| 2534 | 2540 |
| 2535 CreditCard expected(base::GenerateGUID(), "https://www.example.com"); | 2541 CreditCard expected(base::GenerateGUID(), "https://www.example.com"); |
| 2536 test::SetCreditCardInfo(&expected, "Biggie Smalls", "4111111111111111", "01", | 2542 test::SetCreditCardInfo(&expected, "Biggie Smalls", "4111111111111111", "01", |
| 2537 "2998"); | 2543 "2998", "1"); |
| 2538 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); | 2544 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); |
| 2539 ASSERT_EQ(1U, results.size()); | 2545 ASSERT_EQ(1U, results.size()); |
| 2540 EXPECT_EQ(0, expected.Compare(*results[0])); | 2546 EXPECT_EQ(0, expected.Compare(*results[0])); |
| 2541 | 2547 |
| 2542 // Add a second different valid credit card where the year is different but | 2548 // Add a second different valid credit card where the year is different but |
| 2543 // the credit card number matches. | 2549 // the credit card number matches. |
| 2544 FormData form2; | 2550 FormData form2; |
| 2545 AddFullCreditCardForm(&form2, "Biggie Smalls", "4111 1111 1111 1111", "01", | 2551 AddFullCreditCardForm(&form2, "Biggie Smalls", "4111 1111 1111 1111", "01", |
| 2546 /* different year */ "2999"); | 2552 /* different year */ "2999"); |
| 2547 | 2553 |
| 2548 FormStructure form_structure2(form2); | 2554 FormStructure form_structure2(form2); |
| 2549 form_structure2.DetermineHeuristicTypes(nullptr /* ukm_service */); | 2555 form_structure2.DetermineHeuristicTypes(nullptr /* ukm_service */); |
| 2550 std::unique_ptr<CreditCard> imported_credit_card2; | 2556 std::unique_ptr<CreditCard> imported_credit_card2; |
| 2551 EXPECT_TRUE(ImportCreditCard(form_structure2, | 2557 EXPECT_TRUE(ImportCreditCard(form_structure2, |
| 2552 /* should_return_local_card= */ true, | 2558 /* should_return_local_card= */ true, |
| 2553 &imported_credit_card2)); | 2559 &imported_credit_card2)); |
| 2554 // The local card is returned after an update. | 2560 // The local card is returned after an update. |
| 2555 EXPECT_TRUE(imported_credit_card2); | 2561 EXPECT_TRUE(imported_credit_card2); |
| 2556 | 2562 |
| 2557 // Verify that the web database has been updated and the notification sent. | 2563 // Verify that the web database has been updated and the notification sent. |
| 2558 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 2564 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 2559 .WillOnce(QuitMainMessageLoop()); | 2565 .WillOnce(QuitMainMessageLoop()); |
| 2560 base::RunLoop().Run(); | 2566 base::RunLoop().Run(); |
| 2561 | 2567 |
| 2562 // Expect that the newer information is saved. In this case the year is | 2568 // Expect that the newer information is saved. In this case the year is |
| 2563 // updated to "2999". | 2569 // updated to "2999". |
| 2564 CreditCard expected2(base::GenerateGUID(), "https://www.example.com"); | 2570 CreditCard expected2(base::GenerateGUID(), "https://www.example.com"); |
| 2565 test::SetCreditCardInfo(&expected2, "Biggie Smalls", "4111111111111111", "01", | 2571 test::SetCreditCardInfo(&expected2, "Biggie Smalls", "4111111111111111", "01", |
| 2566 "2999"); | 2572 "2999", "1"); |
| 2567 const std::vector<CreditCard*>& results2 = personal_data_->GetCreditCards(); | 2573 const std::vector<CreditCard*>& results2 = personal_data_->GetCreditCards(); |
| 2568 ASSERT_EQ(1U, results2.size()); | 2574 ASSERT_EQ(1U, results2.size()); |
| 2569 EXPECT_EQ(0, expected2.Compare(*results2[0])); | 2575 EXPECT_EQ(0, expected2.Compare(*results2[0])); |
| 2570 } | 2576 } |
| 2571 | 2577 |
| 2572 TEST_F(PersonalDataManagerTest, ImportCreditCard_EmptyCardWithConflict) { | 2578 TEST_F(PersonalDataManagerTest, ImportCreditCard_EmptyCardWithConflict) { |
| 2573 // Start with a single valid credit card form. | 2579 // Start with a single valid credit card form. |
| 2574 FormData form1; | 2580 FormData form1; |
| 2575 AddFullCreditCardForm(&form1, "Biggie Smalls", "4111-1111-1111-1111", "01", | 2581 AddFullCreditCardForm(&form1, "Biggie Smalls", "4111-1111-1111-1111", "01", |
| 2576 "2998"); | 2582 "2998"); |
| 2577 | 2583 |
| 2578 FormStructure form_structure1(form1); | 2584 FormStructure form_structure1(form1); |
| 2579 form_structure1.DetermineHeuristicTypes(nullptr /* ukm_service */); | 2585 form_structure1.DetermineHeuristicTypes(nullptr /* ukm_service */); |
| 2580 std::unique_ptr<CreditCard> imported_credit_card; | 2586 std::unique_ptr<CreditCard> imported_credit_card; |
| 2581 EXPECT_TRUE(ImportCreditCard(form_structure1, false, &imported_credit_card)); | 2587 EXPECT_TRUE(ImportCreditCard(form_structure1, false, &imported_credit_card)); |
| 2582 ASSERT_TRUE(imported_credit_card); | 2588 ASSERT_TRUE(imported_credit_card); |
| 2583 personal_data_->SaveImportedCreditCard(*imported_credit_card); | 2589 personal_data_->SaveImportedCreditCard(*imported_credit_card); |
| 2584 | 2590 |
| 2585 // Verify that the web database has been updated and the notification sent. | 2591 // Verify that the web database has been updated and the notification sent. |
| 2586 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 2592 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 2587 .WillOnce(QuitMainMessageLoop()); | 2593 .WillOnce(QuitMainMessageLoop()); |
| 2588 base::RunLoop().Run(); | 2594 base::RunLoop().Run(); |
| 2589 | 2595 |
| 2590 CreditCard expected(base::GenerateGUID(), "https://www.example.com"); | 2596 CreditCard expected(base::GenerateGUID(), "https://www.example.com"); |
| 2591 test::SetCreditCardInfo(&expected, "Biggie Smalls", "4111111111111111", "01", | 2597 test::SetCreditCardInfo(&expected, "Biggie Smalls", "4111111111111111", "01", |
| 2592 "2998"); | 2598 "2998", "1"); |
| 2593 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); | 2599 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); |
| 2594 ASSERT_EQ(1U, results.size()); | 2600 ASSERT_EQ(1U, results.size()); |
| 2595 EXPECT_EQ(0, expected.Compare(*results[0])); | 2601 EXPECT_EQ(0, expected.Compare(*results[0])); |
| 2596 | 2602 |
| 2597 // Add a second credit card with no number. | 2603 // Add a second credit card with no number. |
| 2598 FormData form2; | 2604 FormData form2; |
| 2599 AddFullCreditCardForm(&form2, "Biggie Smalls", /* no number */ nullptr, "01", | 2605 AddFullCreditCardForm(&form2, "Biggie Smalls", /* no number */ nullptr, "01", |
| 2600 "2999"); | 2606 "2999"); |
| 2601 | 2607 |
| 2602 FormStructure form_structure2(form2); | 2608 FormStructure form_structure2(form2); |
| 2603 form_structure2.DetermineHeuristicTypes(nullptr /* ukm_service */); | 2609 form_structure2.DetermineHeuristicTypes(nullptr /* ukm_service */); |
| 2604 std::unique_ptr<CreditCard> imported_credit_card2; | 2610 std::unique_ptr<CreditCard> imported_credit_card2; |
| 2605 EXPECT_FALSE( | 2611 EXPECT_FALSE( |
| 2606 ImportCreditCard(form_structure2, false, &imported_credit_card2)); | 2612 ImportCreditCard(form_structure2, false, &imported_credit_card2)); |
| 2607 EXPECT_FALSE(imported_credit_card2); | 2613 EXPECT_FALSE(imported_credit_card2); |
| 2608 | 2614 |
| 2609 // Since no refresh is expected, reload the data from the database to make | 2615 // Since no refresh is expected, reload the data from the database to make |
| 2610 // sure no changes were written out. | 2616 // sure no changes were written out. |
| 2611 ResetPersonalDataManager(USER_MODE_NORMAL); | 2617 ResetPersonalDataManager(USER_MODE_NORMAL); |
| 2612 | 2618 |
| 2613 // No change is expected. | 2619 // No change is expected. |
| 2614 CreditCard expected2(base::GenerateGUID(), "https://www.example.com"); | 2620 CreditCard expected2(base::GenerateGUID(), "https://www.example.com"); |
| 2615 test::SetCreditCardInfo(&expected2, "Biggie Smalls", "4111111111111111", "01", | 2621 test::SetCreditCardInfo(&expected2, "Biggie Smalls", "4111111111111111", "01", |
| 2616 "2998"); | 2622 "2998", "1"); |
| 2617 const std::vector<CreditCard*>& results2 = personal_data_->GetCreditCards(); | 2623 const std::vector<CreditCard*>& results2 = personal_data_->GetCreditCards(); |
| 2618 ASSERT_EQ(1U, results2.size()); | 2624 ASSERT_EQ(1U, results2.size()); |
| 2619 EXPECT_EQ(0, expected2.Compare(*results2[0])); | 2625 EXPECT_EQ(0, expected2.Compare(*results2[0])); |
| 2620 } | 2626 } |
| 2621 | 2627 |
| 2622 TEST_F(PersonalDataManagerTest, ImportCreditCard_MissingInfoInNew) { | 2628 TEST_F(PersonalDataManagerTest, ImportCreditCard_MissingInfoInNew) { |
| 2623 // Start with a single valid credit card form. | 2629 // Start with a single valid credit card form. |
| 2624 FormData form1; | 2630 FormData form1; |
| 2625 AddFullCreditCardForm(&form1, "Biggie Smalls", "4111-1111-1111-1111", "01", | 2631 AddFullCreditCardForm(&form1, "Biggie Smalls", "4111-1111-1111-1111", "01", |
| 2626 "2999"); | 2632 "2999"); |
| 2627 | 2633 |
| 2628 FormStructure form_structure1(form1); | 2634 FormStructure form_structure1(form1); |
| 2629 form_structure1.DetermineHeuristicTypes(nullptr /* ukm_service */); | 2635 form_structure1.DetermineHeuristicTypes(nullptr /* ukm_service */); |
| 2630 std::unique_ptr<CreditCard> imported_credit_card; | 2636 std::unique_ptr<CreditCard> imported_credit_card; |
| 2631 EXPECT_TRUE(ImportCreditCard(form_structure1, false, &imported_credit_card)); | 2637 EXPECT_TRUE(ImportCreditCard(form_structure1, false, &imported_credit_card)); |
| 2632 ASSERT_TRUE(imported_credit_card); | 2638 ASSERT_TRUE(imported_credit_card); |
| 2633 personal_data_->SaveImportedCreditCard(*imported_credit_card); | 2639 personal_data_->SaveImportedCreditCard(*imported_credit_card); |
| 2634 | 2640 |
| 2635 // Verify that the web database has been updated and the notification sent. | 2641 // Verify that the web database has been updated and the notification sent. |
| 2636 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 2642 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 2637 .WillOnce(QuitMainMessageLoop()); | 2643 .WillOnce(QuitMainMessageLoop()); |
| 2638 base::RunLoop().Run(); | 2644 base::RunLoop().Run(); |
| 2639 | 2645 |
| 2640 CreditCard expected(base::GenerateGUID(), "https://www.example.com"); | 2646 CreditCard expected(base::GenerateGUID(), "https://www.example.com"); |
| 2641 test::SetCreditCardInfo(&expected, | 2647 test::SetCreditCardInfo(&expected, "Biggie Smalls", "4111111111111111", "01", |
| 2642 "Biggie Smalls", "4111111111111111", "01", "2999"); | 2648 "2999", "1"); |
| 2643 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); | 2649 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); |
| 2644 ASSERT_EQ(1U, results.size()); | 2650 ASSERT_EQ(1U, results.size()); |
| 2645 EXPECT_EQ(0, expected.Compare(*results[0])); | 2651 EXPECT_EQ(0, expected.Compare(*results[0])); |
| 2646 | 2652 |
| 2647 // Add a second different valid credit card where the name is missing but | 2653 // Add a second different valid credit card where the name is missing but |
| 2648 // the credit card number matches. | 2654 // the credit card number matches. |
| 2649 FormData form2; | 2655 FormData form2; |
| 2650 AddFullCreditCardForm(&form2, /* missing name */ nullptr, | 2656 AddFullCreditCardForm(&form2, /* missing name */ nullptr, |
| 2651 "4111-1111-1111-1111", "01", "2999"); | 2657 "4111-1111-1111-1111", "01", "2999"); |
| 2652 | 2658 |
| 2653 FormStructure form_structure2(form2); | 2659 FormStructure form_structure2(form2); |
| 2654 form_structure2.DetermineHeuristicTypes(nullptr /* ukm_service */); | 2660 form_structure2.DetermineHeuristicTypes(nullptr /* ukm_service */); |
| 2655 std::unique_ptr<CreditCard> imported_credit_card2; | 2661 std::unique_ptr<CreditCard> imported_credit_card2; |
| 2656 EXPECT_TRUE(ImportCreditCard(form_structure2, false, &imported_credit_card2)); | 2662 EXPECT_TRUE(ImportCreditCard(form_structure2, false, &imported_credit_card2)); |
| 2657 EXPECT_FALSE(imported_credit_card2); | 2663 EXPECT_FALSE(imported_credit_card2); |
| 2658 | 2664 |
| 2659 // Since no refresh is expected, reload the data from the database to make | 2665 // Since no refresh is expected, reload the data from the database to make |
| 2660 // sure no changes were written out. | 2666 // sure no changes were written out. |
| 2661 ResetPersonalDataManager(USER_MODE_NORMAL); | 2667 ResetPersonalDataManager(USER_MODE_NORMAL); |
| 2662 | 2668 |
| 2663 // No change is expected. | 2669 // No change is expected. |
| 2664 CreditCard expected2(base::GenerateGUID(), "https://www.example.com"); | 2670 CreditCard expected2(base::GenerateGUID(), "https://www.example.com"); |
| 2665 test::SetCreditCardInfo(&expected2, | 2671 test::SetCreditCardInfo(&expected2, "Biggie Smalls", "4111111111111111", "01", |
| 2666 "Biggie Smalls", "4111111111111111", "01", "2999"); | 2672 "2999", "1"); |
| 2667 const std::vector<CreditCard*>& results2 = personal_data_->GetCreditCards(); | 2673 const std::vector<CreditCard*>& results2 = personal_data_->GetCreditCards(); |
| 2668 ASSERT_EQ(1U, results2.size()); | 2674 ASSERT_EQ(1U, results2.size()); |
| 2669 EXPECT_EQ(0, expected2.Compare(*results2[0])); | 2675 EXPECT_EQ(0, expected2.Compare(*results2[0])); |
| 2670 | 2676 |
| 2671 // Add a third credit card where the expiration date is missing. | 2677 // Add a third credit card where the expiration date is missing. |
| 2672 FormData form3; | 2678 FormData form3; |
| 2673 AddFullCreditCardForm(&form3, "Johnny McEnroe", "5555555555554444", | 2679 AddFullCreditCardForm(&form3, "Johnny McEnroe", "5555555555554444", |
| 2674 /* no month */ nullptr, | 2680 /* no month */ nullptr, |
| 2675 /* no year */ nullptr); | 2681 /* no year */ nullptr); |
| 2676 | 2682 |
| 2677 FormStructure form_structure3(form3); | 2683 FormStructure form_structure3(form3); |
| 2678 form_structure3.DetermineHeuristicTypes(nullptr /* ukm_service */); | 2684 form_structure3.DetermineHeuristicTypes(nullptr /* ukm_service */); |
| 2679 std::unique_ptr<CreditCard> imported_credit_card3; | 2685 std::unique_ptr<CreditCard> imported_credit_card3; |
| 2680 EXPECT_FALSE( | 2686 EXPECT_FALSE( |
| 2681 ImportCreditCard(form_structure3, false, &imported_credit_card3)); | 2687 ImportCreditCard(form_structure3, false, &imported_credit_card3)); |
| 2682 ASSERT_FALSE(imported_credit_card3); | 2688 ASSERT_FALSE(imported_credit_card3); |
| 2683 | 2689 |
| 2684 // Since no refresh is expected, reload the data from the database to make | 2690 // Since no refresh is expected, reload the data from the database to make |
| 2685 // sure no changes were written out. | 2691 // sure no changes were written out. |
| 2686 ResetPersonalDataManager(USER_MODE_NORMAL); | 2692 ResetPersonalDataManager(USER_MODE_NORMAL); |
| 2687 | 2693 |
| 2688 // No change is expected. | 2694 // No change is expected. |
| 2689 CreditCard expected3(base::GenerateGUID(), "https://www.example.com"); | 2695 CreditCard expected3(base::GenerateGUID(), "https://www.example.com"); |
| 2690 test::SetCreditCardInfo(&expected3, | 2696 test::SetCreditCardInfo(&expected3, "Biggie Smalls", "4111111111111111", "01", |
| 2691 "Biggie Smalls", "4111111111111111", "01", "2999"); | 2697 "2999", "1"); |
| 2692 const std::vector<CreditCard*>& results3 = personal_data_->GetCreditCards(); | 2698 const std::vector<CreditCard*>& results3 = personal_data_->GetCreditCards(); |
| 2693 ASSERT_EQ(1U, results3.size()); | 2699 ASSERT_EQ(1U, results3.size()); |
| 2694 EXPECT_EQ(0, expected3.Compare(*results3[0])); | 2700 EXPECT_EQ(0, expected3.Compare(*results3[0])); |
| 2695 } | 2701 } |
| 2696 | 2702 |
| 2697 TEST_F(PersonalDataManagerTest, ImportCreditCard_MissingInfoInOld) { | 2703 TEST_F(PersonalDataManagerTest, ImportCreditCard_MissingInfoInOld) { |
| 2698 // Start with a single valid credit card stored via the preferences. | 2704 // Start with a single valid credit card stored via the preferences. |
| 2699 // Note the empty name. | 2705 // Note the empty name. |
| 2700 CreditCard saved_credit_card(base::GenerateGUID(), "https://www.example.com"); | 2706 CreditCard saved_credit_card(base::GenerateGUID(), "https://www.example.com"); |
| 2701 test::SetCreditCardInfo(&saved_credit_card, "", "4111111111111111" /* Visa */, | 2707 test::SetCreditCardInfo(&saved_credit_card, "", "4111111111111111" /* Visa */, |
| 2702 "01", "2998"); | 2708 "01", "2998", "1"); |
| 2703 personal_data_->AddCreditCard(saved_credit_card); | 2709 personal_data_->AddCreditCard(saved_credit_card); |
| 2704 | 2710 |
| 2705 // Verify that the web database has been updated and the notification sent. | 2711 // Verify that the web database has been updated and the notification sent. |
| 2706 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 2712 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 2707 .WillOnce(QuitMainMessageLoop()); | 2713 .WillOnce(QuitMainMessageLoop()); |
| 2708 base::RunLoop().Run(); | 2714 base::RunLoop().Run(); |
| 2709 | 2715 |
| 2710 const std::vector<CreditCard*>& results1 = personal_data_->GetCreditCards(); | 2716 const std::vector<CreditCard*>& results1 = personal_data_->GetCreditCards(); |
| 2711 ASSERT_EQ(1U, results1.size()); | 2717 ASSERT_EQ(1U, results1.size()); |
| 2712 EXPECT_EQ(saved_credit_card, *results1[0]); | 2718 EXPECT_EQ(saved_credit_card, *results1[0]); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 2725 | 2731 |
| 2726 // Verify that the web database has been updated and the notification sent. | 2732 // Verify that the web database has been updated and the notification sent. |
| 2727 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 2733 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 2728 .WillOnce(QuitMainMessageLoop()); | 2734 .WillOnce(QuitMainMessageLoop()); |
| 2729 base::RunLoop().Run(); | 2735 base::RunLoop().Run(); |
| 2730 | 2736 |
| 2731 // Expect that the newer information is saved. In this case the year is | 2737 // Expect that the newer information is saved. In this case the year is |
| 2732 // added to the existing credit card. | 2738 // added to the existing credit card. |
| 2733 CreditCard expected2(base::GenerateGUID(), "https://www.example.com"); | 2739 CreditCard expected2(base::GenerateGUID(), "https://www.example.com"); |
| 2734 test::SetCreditCardInfo(&expected2, "Biggie Smalls", "4111111111111111", "01", | 2740 test::SetCreditCardInfo(&expected2, "Biggie Smalls", "4111111111111111", "01", |
| 2735 "2999"); | 2741 "2999", "1"); |
| 2736 const std::vector<CreditCard*>& results2 = personal_data_->GetCreditCards(); | 2742 const std::vector<CreditCard*>& results2 = personal_data_->GetCreditCards(); |
| 2737 ASSERT_EQ(1U, results2.size()); | 2743 ASSERT_EQ(1U, results2.size()); |
| 2738 EXPECT_EQ(0, expected2.Compare(*results2[0])); | 2744 EXPECT_EQ(0, expected2.Compare(*results2[0])); |
| 2739 } | 2745 } |
| 2740 | 2746 |
| 2741 // We allow the user to store a credit card number with separators via the UI. | 2747 // We allow the user to store a credit card number with separators via the UI. |
| 2742 // We should not try to re-aggregate the same card with the separators stripped. | 2748 // We should not try to re-aggregate the same card with the separators stripped. |
| 2743 TEST_F(PersonalDataManagerTest, ImportCreditCard_SameCardWithSeparators) { | 2749 TEST_F(PersonalDataManagerTest, ImportCreditCard_SameCardWithSeparators) { |
| 2744 // Start with a single valid credit card stored via the preferences. | 2750 // Start with a single valid credit card stored via the preferences. |
| 2745 // Note the separators in the credit card number. | 2751 // Note the separators in the credit card number. |
| 2746 CreditCard saved_credit_card(base::GenerateGUID(), "https://www.example.com"); | 2752 CreditCard saved_credit_card(base::GenerateGUID(), "https://www.example.com"); |
| 2747 test::SetCreditCardInfo(&saved_credit_card, | 2753 test::SetCreditCardInfo(&saved_credit_card, "Biggie Smalls", |
| 2748 "Biggie Smalls", "4111 1111 1111 1111" /* Visa */, "01", "2999"); | 2754 "4111 1111 1111 1111" /* Visa */, "01", "2999", "1"); |
| 2749 personal_data_->AddCreditCard(saved_credit_card); | 2755 personal_data_->AddCreditCard(saved_credit_card); |
| 2750 | 2756 |
| 2751 // Verify that the web database has been updated and the notification sent. | 2757 // Verify that the web database has been updated and the notification sent. |
| 2752 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 2758 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 2753 .WillOnce(QuitMainMessageLoop()); | 2759 .WillOnce(QuitMainMessageLoop()); |
| 2754 base::RunLoop().Run(); | 2760 base::RunLoop().Run(); |
| 2755 | 2761 |
| 2756 const std::vector<CreditCard*>& results1 = personal_data_->GetCreditCards(); | 2762 const std::vector<CreditCard*>& results1 = personal_data_->GetCreditCards(); |
| 2757 ASSERT_EQ(1U, results1.size()); | 2763 ASSERT_EQ(1U, results1.size()); |
| 2758 EXPECT_EQ(0, saved_credit_card.Compare(*results1[0])); | 2764 EXPECT_EQ(0, saved_credit_card.Compare(*results1[0])); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 2778 EXPECT_EQ(0, saved_credit_card.Compare(*results2[0])); | 2784 EXPECT_EQ(0, saved_credit_card.Compare(*results2[0])); |
| 2779 } | 2785 } |
| 2780 | 2786 |
| 2781 // Ensure that if a verified credit card already exists, aggregated credit cards | 2787 // Ensure that if a verified credit card already exists, aggregated credit cards |
| 2782 // cannot modify it in any way. | 2788 // cannot modify it in any way. |
| 2783 TEST_F(PersonalDataManagerTest, | 2789 TEST_F(PersonalDataManagerTest, |
| 2784 ImportCreditCard_ExistingVerifiedCardWithConflict) { | 2790 ImportCreditCard_ExistingVerifiedCardWithConflict) { |
| 2785 // Start with a verified credit card. | 2791 // Start with a verified credit card. |
| 2786 CreditCard credit_card(base::GenerateGUID(), kSettingsOrigin); | 2792 CreditCard credit_card(base::GenerateGUID(), kSettingsOrigin); |
| 2787 test::SetCreditCardInfo(&credit_card, "Biggie Smalls", | 2793 test::SetCreditCardInfo(&credit_card, "Biggie Smalls", |
| 2788 "4111 1111 1111 1111" /* Visa */, "01", "2998"); | 2794 "4111 1111 1111 1111" /* Visa */, "01", "2998", "1"); |
| 2789 EXPECT_TRUE(credit_card.IsVerified()); | 2795 EXPECT_TRUE(credit_card.IsVerified()); |
| 2790 | 2796 |
| 2791 // Add the credit card to the database. | 2797 // Add the credit card to the database. |
| 2792 personal_data_->AddCreditCard(credit_card); | 2798 personal_data_->AddCreditCard(credit_card); |
| 2793 | 2799 |
| 2794 // Verify that the web database has been updated and the notification sent. | 2800 // Verify that the web database has been updated and the notification sent. |
| 2795 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 2801 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 2796 .WillOnce(QuitMainMessageLoop()); | 2802 .WillOnce(QuitMainMessageLoop()); |
| 2797 base::RunLoop().Run(); | 2803 base::RunLoop().Run(); |
| 2798 | 2804 |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2868 "theprez@gmail.com", NULL, "21 Laussat St", NULL, | 2874 "theprez@gmail.com", NULL, "21 Laussat St", NULL, |
| 2869 "San Francisco", "California", "94102", NULL, NULL); | 2875 "San Francisco", "California", "94102", NULL, NULL); |
| 2870 const std::vector<AutofillProfile*>& results_addr = | 2876 const std::vector<AutofillProfile*>& results_addr = |
| 2871 personal_data_->GetProfiles(); | 2877 personal_data_->GetProfiles(); |
| 2872 ASSERT_EQ(1U, results_addr.size()); | 2878 ASSERT_EQ(1U, results_addr.size()); |
| 2873 EXPECT_EQ(0, expected_address.Compare(*results_addr[0])); | 2879 EXPECT_EQ(0, expected_address.Compare(*results_addr[0])); |
| 2874 | 2880 |
| 2875 // Test that the credit card has also been saved. | 2881 // Test that the credit card has also been saved. |
| 2876 CreditCard expected_card(base::GenerateGUID(), "https://www.example.com"); | 2882 CreditCard expected_card(base::GenerateGUID(), "https://www.example.com"); |
| 2877 test::SetCreditCardInfo(&expected_card, "Biggie Smalls", "4111111111111111", | 2883 test::SetCreditCardInfo(&expected_card, "Biggie Smalls", "4111111111111111", |
| 2878 "01", "2999"); | 2884 "01", "2999", "1"); |
| 2879 const std::vector<CreditCard*>& results_cards = | 2885 const std::vector<CreditCard*>& results_cards = |
| 2880 personal_data_->GetCreditCards(); | 2886 personal_data_->GetCreditCards(); |
| 2881 ASSERT_EQ(1U, results_cards.size()); | 2887 ASSERT_EQ(1U, results_cards.size()); |
| 2882 EXPECT_EQ(0, expected_card.Compare(*results_cards[0])); | 2888 EXPECT_EQ(0, expected_card.Compare(*results_cards[0])); |
| 2883 } | 2889 } |
| 2884 | 2890 |
| 2885 // Test that a form with two address sections and a credit card section does not | 2891 // Test that a form with two address sections and a credit card section does not |
| 2886 // import the address but does import the credit card. | 2892 // import the address but does import the credit card. |
| 2887 TEST_F(PersonalDataManagerTest, ImportFormData_TwoAddressesOneCreditCard) { | 2893 TEST_F(PersonalDataManagerTest, ImportFormData_TwoAddressesOneCreditCard) { |
| 2888 FormData form; | 2894 FormData form; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2939 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 2945 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 2940 .WillOnce(QuitMainMessageLoop()); | 2946 .WillOnce(QuitMainMessageLoop()); |
| 2941 base::RunLoop().Run(); | 2947 base::RunLoop().Run(); |
| 2942 | 2948 |
| 2943 // Test that both addresses have been saved. | 2949 // Test that both addresses have been saved. |
| 2944 EXPECT_EQ(2U, personal_data_->GetProfiles().size()); | 2950 EXPECT_EQ(2U, personal_data_->GetProfiles().size()); |
| 2945 | 2951 |
| 2946 // Test that the credit card has been saved. | 2952 // Test that the credit card has been saved. |
| 2947 CreditCard expected_card(base::GenerateGUID(), "https://www.example.com"); | 2953 CreditCard expected_card(base::GenerateGUID(), "https://www.example.com"); |
| 2948 test::SetCreditCardInfo(&expected_card, "Biggie Smalls", "4111111111111111", | 2954 test::SetCreditCardInfo(&expected_card, "Biggie Smalls", "4111111111111111", |
| 2949 "01", "2999"); | 2955 "01", "2999", "1"); |
| 2950 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); | 2956 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); |
| 2951 ASSERT_EQ(1U, results.size()); | 2957 ASSERT_EQ(1U, results.size()); |
| 2952 EXPECT_EQ(0, expected_card.Compare(*results[0])); | 2958 EXPECT_EQ(0, expected_card.Compare(*results[0])); |
| 2953 } | 2959 } |
| 2954 | 2960 |
| 2955 // Ensure that verified profiles can be saved via SaveImportedProfile, | 2961 // Ensure that verified profiles can be saved via SaveImportedProfile, |
| 2956 // overwriting existing unverified profiles. | 2962 // overwriting existing unverified profiles. |
| 2957 TEST_F(PersonalDataManagerTest, SaveImportedProfileWithVerifiedData) { | 2963 TEST_F(PersonalDataManagerTest, SaveImportedProfileWithVerifiedData) { |
| 2958 // Start with an unverified profile. | 2964 // Start with an unverified profile. |
| 2959 AutofillProfile profile(base::GenerateGUID(), "https://www.example.com"); | 2965 AutofillProfile profile(base::GenerateGUID(), "https://www.example.com"); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2994 expected.SetRawInfo(PHONE_HOME_WHOLE_NUMBER, | 3000 expected.SetRawInfo(PHONE_HOME_WHOLE_NUMBER, |
| 2995 base::ASCIIToUTF16("+1 234-567-8910")); | 3001 base::ASCIIToUTF16("+1 234-567-8910")); |
| 2996 EXPECT_EQ(0, expected.Compare(*results[0])) | 3002 EXPECT_EQ(0, expected.Compare(*results[0])) |
| 2997 << "result = {" << *results[0] << "} | expected = {" << expected << "}"; | 3003 << "result = {" << *results[0] << "} | expected = {" << expected << "}"; |
| 2998 } | 3004 } |
| 2999 | 3005 |
| 3000 // Ensure that verified credit cards can be saved via SaveImportedCreditCard. | 3006 // Ensure that verified credit cards can be saved via SaveImportedCreditCard. |
| 3001 TEST_F(PersonalDataManagerTest, SaveImportedCreditCardWithVerifiedData) { | 3007 TEST_F(PersonalDataManagerTest, SaveImportedCreditCardWithVerifiedData) { |
| 3002 // Start with a verified credit card. | 3008 // Start with a verified credit card. |
| 3003 CreditCard credit_card(base::GenerateGUID(), kSettingsOrigin); | 3009 CreditCard credit_card(base::GenerateGUID(), kSettingsOrigin); |
| 3004 test::SetCreditCardInfo(&credit_card, | 3010 test::SetCreditCardInfo(&credit_card, "Biggie Smalls", |
| 3005 "Biggie Smalls", "4111 1111 1111 1111" /* Visa */, "01", "2999"); | 3011 "4111 1111 1111 1111" /* Visa */, "01", "2999", "1"); |
| 3006 EXPECT_TRUE(credit_card.IsVerified()); | 3012 EXPECT_TRUE(credit_card.IsVerified()); |
| 3007 | 3013 |
| 3008 // Add the credit card to the database. | 3014 // Add the credit card to the database. |
| 3009 personal_data_->AddCreditCard(credit_card); | 3015 personal_data_->AddCreditCard(credit_card); |
| 3010 | 3016 |
| 3011 // Verify that the web database has been updated and the notification sent. | 3017 // Verify that the web database has been updated and the notification sent. |
| 3012 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 3018 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 3013 .WillOnce(QuitMainMessageLoop()); | 3019 .WillOnce(QuitMainMessageLoop()); |
| 3014 base::RunLoop().Run(); | 3020 base::RunLoop().Run(); |
| 3015 | 3021 |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3109 EXPECT_TRUE(non_empty_types.count(ADDRESS_HOME_ZIP)); | 3115 EXPECT_TRUE(non_empty_types.count(ADDRESS_HOME_ZIP)); |
| 3110 EXPECT_TRUE(non_empty_types.count(ADDRESS_HOME_COUNTRY)); | 3116 EXPECT_TRUE(non_empty_types.count(ADDRESS_HOME_COUNTRY)); |
| 3111 EXPECT_TRUE(non_empty_types.count(PHONE_HOME_NUMBER)); | 3117 EXPECT_TRUE(non_empty_types.count(PHONE_HOME_NUMBER)); |
| 3112 EXPECT_TRUE(non_empty_types.count(PHONE_HOME_CITY_CODE)); | 3118 EXPECT_TRUE(non_empty_types.count(PHONE_HOME_CITY_CODE)); |
| 3113 EXPECT_TRUE(non_empty_types.count(PHONE_HOME_COUNTRY_CODE)); | 3119 EXPECT_TRUE(non_empty_types.count(PHONE_HOME_COUNTRY_CODE)); |
| 3114 EXPECT_TRUE(non_empty_types.count(PHONE_HOME_CITY_AND_NUMBER)); | 3120 EXPECT_TRUE(non_empty_types.count(PHONE_HOME_CITY_AND_NUMBER)); |
| 3115 EXPECT_TRUE(non_empty_types.count(PHONE_HOME_WHOLE_NUMBER)); | 3121 EXPECT_TRUE(non_empty_types.count(PHONE_HOME_WHOLE_NUMBER)); |
| 3116 | 3122 |
| 3117 // Test with credit card information also stored. | 3123 // Test with credit card information also stored. |
| 3118 CreditCard credit_card(base::GenerateGUID(), "https://www.example.com"); | 3124 CreditCard credit_card(base::GenerateGUID(), "https://www.example.com"); |
| 3119 test::SetCreditCardInfo(&credit_card, | 3125 test::SetCreditCardInfo(&credit_card, "John Dillinger", |
| 3120 "John Dillinger", "423456789012" /* Visa */, | 3126 "423456789012" /* Visa */, "01", "2999", "1"); |
| 3121 "01", "2999"); | |
| 3122 personal_data_->AddCreditCard(credit_card); | 3127 personal_data_->AddCreditCard(credit_card); |
| 3123 | 3128 |
| 3124 // Verify that the web database has been updated and the notification sent. | 3129 // Verify that the web database has been updated and the notification sent. |
| 3125 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 3130 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 3126 .WillOnce(QuitMainMessageLoop()); | 3131 .WillOnce(QuitMainMessageLoop()); |
| 3127 base::RunLoop().Run(); | 3132 base::RunLoop().Run(); |
| 3128 | 3133 |
| 3129 personal_data_->GetNonEmptyTypes(&non_empty_types); | 3134 personal_data_->GetNonEmptyTypes(&non_empty_types); |
| 3130 EXPECT_EQ(29U, non_empty_types.size()); | 3135 EXPECT_EQ(29U, non_empty_types.size()); |
| 3131 EXPECT_TRUE(non_empty_types.count(NAME_FIRST)); | 3136 EXPECT_TRUE(non_empty_types.count(NAME_FIRST)); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3163 ASSERT_TRUE(personal_data_->GetProfiles().empty()); | 3168 ASSERT_TRUE(personal_data_->GetProfiles().empty()); |
| 3164 ASSERT_TRUE(personal_data_->GetCreditCards().empty()); | 3169 ASSERT_TRUE(personal_data_->GetCreditCards().empty()); |
| 3165 | 3170 |
| 3166 AutofillProfile steve_jobs(base::GenerateGUID(), "https://www.example.com"); | 3171 AutofillProfile steve_jobs(base::GenerateGUID(), "https://www.example.com"); |
| 3167 test::SetProfileInfo(&steve_jobs, "Steven", "Paul", "Jobs", "sjobs@apple.com", | 3172 test::SetProfileInfo(&steve_jobs, "Steven", "Paul", "Jobs", "sjobs@apple.com", |
| 3168 "Apple Computer, Inc.", "1 Infinite Loop", "", "Cupertino", "CA", "95014", | 3173 "Apple Computer, Inc.", "1 Infinite Loop", "", "Cupertino", "CA", "95014", |
| 3169 "US", "(800) 275-2273"); | 3174 "US", "(800) 275-2273"); |
| 3170 personal_data_->AddProfile(steve_jobs); | 3175 personal_data_->AddProfile(steve_jobs); |
| 3171 | 3176 |
| 3172 CreditCard bill_gates(base::GenerateGUID(), "https://www.example.com"); | 3177 CreditCard bill_gates(base::GenerateGUID(), "https://www.example.com"); |
| 3173 test::SetCreditCardInfo( | 3178 test::SetCreditCardInfo(&bill_gates, "William H. Gates", "5555555555554444", |
| 3174 &bill_gates, "William H. Gates", "5555555555554444", "1", "2020"); | 3179 "1", "2020", "1"); |
| 3175 personal_data_->AddCreditCard(bill_gates); | 3180 personal_data_->AddCreditCard(bill_gates); |
| 3176 | 3181 |
| 3177 // The personal data manager should be able to read existing profiles in an | 3182 // The personal data manager should be able to read existing profiles in an |
| 3178 // off-the-record context. | 3183 // off-the-record context. |
| 3179 ResetPersonalDataManager(USER_MODE_INCOGNITO); | 3184 ResetPersonalDataManager(USER_MODE_INCOGNITO); |
| 3180 ASSERT_EQ(1U, personal_data_->GetProfiles().size()); | 3185 ASSERT_EQ(1U, personal_data_->GetProfiles().size()); |
| 3181 ASSERT_EQ(1U, personal_data_->GetCreditCards().size()); | 3186 ASSERT_EQ(1U, personal_data_->GetCreditCards().size()); |
| 3182 | 3187 |
| 3183 // No adds, saves, or updates should take effect. | 3188 // No adds, saves, or updates should take effect. |
| 3184 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()).Times(0); | 3189 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()).Times(0); |
| 3185 | 3190 |
| 3186 // Add profiles or credit card shouldn't work. | 3191 // Add profiles or credit card shouldn't work. |
| 3187 personal_data_->AddProfile(test::GetFullProfile()); | 3192 personal_data_->AddProfile(test::GetFullProfile()); |
| 3188 | 3193 |
| 3189 CreditCard larry_page(base::GenerateGUID(), "https://www.example.com"); | 3194 CreditCard larry_page(base::GenerateGUID(), "https://www.example.com"); |
| 3190 test::SetCreditCardInfo( | 3195 test::SetCreditCardInfo(&larry_page, "Lawrence Page", "4111111111111111", |
| 3191 &larry_page, "Lawrence Page", "4111111111111111", "10", "2025"); | 3196 "10", "2025", "1"); |
| 3192 personal_data_->AddCreditCard(larry_page); | 3197 personal_data_->AddCreditCard(larry_page); |
| 3193 | 3198 |
| 3194 ResetPersonalDataManager(USER_MODE_INCOGNITO); | 3199 ResetPersonalDataManager(USER_MODE_INCOGNITO); |
| 3195 EXPECT_EQ(1U, personal_data_->GetProfiles().size()); | 3200 EXPECT_EQ(1U, personal_data_->GetProfiles().size()); |
| 3196 EXPECT_EQ(1U, personal_data_->GetCreditCards().size()); | 3201 EXPECT_EQ(1U, personal_data_->GetCreditCards().size()); |
| 3197 | 3202 |
| 3198 // Saving or creating profiles from imported profiles shouldn't work. | 3203 // Saving or creating profiles from imported profiles shouldn't work. |
| 3199 steve_jobs.SetRawInfo(NAME_FIRST, base::ASCIIToUTF16("Steve")); | 3204 steve_jobs.SetRawInfo(NAME_FIRST, base::ASCIIToUTF16("Steve")); |
| 3200 personal_data_->SaveImportedProfile(steve_jobs); | 3205 personal_data_->SaveImportedProfile(steve_jobs); |
| 3201 | 3206 |
| (...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3541 // Test that a masked server card is not suggested if more that six numbers have | 3546 // Test that a masked server card is not suggested if more that six numbers have |
| 3542 // been typed in the field. | 3547 // been typed in the field. |
| 3543 TEST_F(PersonalDataManagerTest, | 3548 TEST_F(PersonalDataManagerTest, |
| 3544 GetCreditCardSuggestions_MaskedCardWithMoreThan6Numbers) { | 3549 GetCreditCardSuggestions_MaskedCardWithMoreThan6Numbers) { |
| 3545 EnableWalletCardImport(); | 3550 EnableWalletCardImport(); |
| 3546 | 3551 |
| 3547 // Add a masked server card. | 3552 // Add a masked server card. |
| 3548 std::vector<CreditCard> server_cards; | 3553 std::vector<CreditCard> server_cards; |
| 3549 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "b459")); | 3554 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "b459")); |
| 3550 test::SetCreditCardInfo(&server_cards.back(), "Emmet Dalton", "2110", "12", | 3555 test::SetCreditCardInfo(&server_cards.back(), "Emmet Dalton", "2110", "12", |
| 3551 "2999"); | 3556 "2999", "1"); |
| 3552 server_cards.back().SetNetworkForMaskedCard(kVisaCard); | 3557 server_cards.back().SetNetworkForMaskedCard(kVisaCard); |
| 3553 | 3558 |
| 3554 test::SetServerCreditCards(autofill_table_, server_cards); | 3559 test::SetServerCreditCards(autofill_table_, server_cards); |
| 3555 personal_data_->Refresh(); | 3560 personal_data_->Refresh(); |
| 3556 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 3561 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 3557 .WillOnce(QuitMainMessageLoop()); | 3562 .WillOnce(QuitMainMessageLoop()); |
| 3558 base::RunLoop().Run(); | 3563 base::RunLoop().Run(); |
| 3559 | 3564 |
| 3560 std::vector<Suggestion> suggestions = | 3565 std::vector<Suggestion> suggestions = |
| 3561 personal_data_->GetCreditCardSuggestions(AutofillType(CREDIT_CARD_NUMBER), | 3566 personal_data_->GetCreditCardSuggestions(AutofillType(CREDIT_CARD_NUMBER), |
| (...skipping 30 matching lines...) Expand all Loading... |
| 3592 // Test that local and server cards are ordered as expected. | 3597 // Test that local and server cards are ordered as expected. |
| 3593 TEST_F(PersonalDataManagerTest, | 3598 TEST_F(PersonalDataManagerTest, |
| 3594 GetCreditCardSuggestions_LocalAndServerCardsRanking) { | 3599 GetCreditCardSuggestions_LocalAndServerCardsRanking) { |
| 3595 EnableWalletCardImport(); | 3600 EnableWalletCardImport(); |
| 3596 SetupReferenceLocalCreditCards(); | 3601 SetupReferenceLocalCreditCards(); |
| 3597 | 3602 |
| 3598 // Add some server cards. | 3603 // Add some server cards. |
| 3599 std::vector<CreditCard> server_cards; | 3604 std::vector<CreditCard> server_cards; |
| 3600 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "b459")); | 3605 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "b459")); |
| 3601 test::SetCreditCardInfo(&server_cards.back(), "Emmet Dalton", "2110", "12", | 3606 test::SetCreditCardInfo(&server_cards.back(), "Emmet Dalton", "2110", "12", |
| 3602 "2999"); | 3607 "2999", "1"); |
| 3603 server_cards.back().set_use_count(2); | 3608 server_cards.back().set_use_count(2); |
| 3604 server_cards.back().set_use_date(AutofillClock::Now() - | 3609 server_cards.back().set_use_date(AutofillClock::Now() - |
| 3605 base::TimeDelta::FromDays(1)); | 3610 base::TimeDelta::FromDays(1)); |
| 3606 server_cards.back().SetNetworkForMaskedCard(kVisaCard); | 3611 server_cards.back().SetNetworkForMaskedCard(kVisaCard); |
| 3607 | 3612 |
| 3608 server_cards.push_back(CreditCard(CreditCard::FULL_SERVER_CARD, "b460")); | 3613 server_cards.push_back(CreditCard(CreditCard::FULL_SERVER_CARD, "b460")); |
| 3609 test::SetCreditCardInfo(&server_cards.back(), "Jesse James", "2109", "12", | 3614 test::SetCreditCardInfo(&server_cards.back(), "Jesse James", "2109", "12", |
| 3610 "2999"); | 3615 "2999", "1"); |
| 3611 server_cards.back().set_use_count(6); | 3616 server_cards.back().set_use_count(6); |
| 3612 server_cards.back().set_use_date(AutofillClock::Now() - | 3617 server_cards.back().set_use_date(AutofillClock::Now() - |
| 3613 base::TimeDelta::FromDays(1)); | 3618 base::TimeDelta::FromDays(1)); |
| 3614 | 3619 |
| 3615 test::SetServerCreditCards(autofill_table_, server_cards); | 3620 test::SetServerCreditCards(autofill_table_, server_cards); |
| 3616 personal_data_->Refresh(); | 3621 personal_data_->Refresh(); |
| 3617 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 3622 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 3618 .WillOnce(QuitMainMessageLoop()); | 3623 .WillOnce(QuitMainMessageLoop()); |
| 3619 base::RunLoop().Run(); | 3624 base::RunLoop().Run(); |
| 3620 | 3625 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 3634 | 3639 |
| 3635 // Test that expired cards are ordered by frecency and are always suggested | 3640 // Test that expired cards are ordered by frecency and are always suggested |
| 3636 // after non expired cards even if they have a higher frecency score. | 3641 // after non expired cards even if they have a higher frecency score. |
| 3637 TEST_F(PersonalDataManagerTest, GetCreditCardSuggestions_ExpiredCards) { | 3642 TEST_F(PersonalDataManagerTest, GetCreditCardSuggestions_ExpiredCards) { |
| 3638 ASSERT_EQ(0U, personal_data_->GetCreditCards().size()); | 3643 ASSERT_EQ(0U, personal_data_->GetCreditCards().size()); |
| 3639 | 3644 |
| 3640 // Add a never used non expired credit card. | 3645 // Add a never used non expired credit card. |
| 3641 CreditCard credit_card0("002149C1-EE28-4213-A3B9-DA243FFF021B", | 3646 CreditCard credit_card0("002149C1-EE28-4213-A3B9-DA243FFF021B", |
| 3642 "https://www.example.com"); | 3647 "https://www.example.com"); |
| 3643 test::SetCreditCardInfo(&credit_card0, "Bonnie Parker", | 3648 test::SetCreditCardInfo(&credit_card0, "Bonnie Parker", |
| 3644 "518765432109" /* Mastercard */, "04", "2999"); | 3649 "518765432109" /* Mastercard */, "04", "2999", "1"); |
| 3645 personal_data_->AddCreditCard(credit_card0); | 3650 personal_data_->AddCreditCard(credit_card0); |
| 3646 | 3651 |
| 3647 // Add an expired card with a higher frecency score. | 3652 // Add an expired card with a higher frecency score. |
| 3648 CreditCard credit_card1("287151C8-6AB1-487C-9095-28E80BE5DA15", | 3653 CreditCard credit_card1("287151C8-6AB1-487C-9095-28E80BE5DA15", |
| 3649 "https://www.example.com"); | 3654 "https://www.example.com"); |
| 3650 test::SetCreditCardInfo(&credit_card1, "Clyde Barrow", | 3655 test::SetCreditCardInfo(&credit_card1, "Clyde Barrow", |
| 3651 "347666888555" /* American Express */, "04", "1999"); | 3656 "347666888555" /* American Express */, "04", "1999", |
| 3657 "1"); |
| 3652 credit_card1.set_use_count(300); | 3658 credit_card1.set_use_count(300); |
| 3653 credit_card1.set_use_date(AutofillClock::Now() - | 3659 credit_card1.set_use_date(AutofillClock::Now() - |
| 3654 base::TimeDelta::FromDays(10)); | 3660 base::TimeDelta::FromDays(10)); |
| 3655 personal_data_->AddCreditCard(credit_card1); | 3661 personal_data_->AddCreditCard(credit_card1); |
| 3656 | 3662 |
| 3657 // Add an expired card with a lower frecency score. | 3663 // Add an expired card with a lower frecency score. |
| 3658 CreditCard credit_card2("1141084B-72D7-4B73-90CF-3D6AC154673B", | 3664 CreditCard credit_card2("1141084B-72D7-4B73-90CF-3D6AC154673B", |
| 3659 "https://www.example.com"); | 3665 "https://www.example.com"); |
| 3660 credit_card2.set_use_count(3); | 3666 credit_card2.set_use_count(3); |
| 3661 credit_card2.set_use_date(AutofillClock::Now() - | 3667 credit_card2.set_use_date(AutofillClock::Now() - |
| 3662 base::TimeDelta::FromDays(1)); | 3668 base::TimeDelta::FromDays(1)); |
| 3663 test::SetCreditCardInfo(&credit_card2, "John Dillinger", | 3669 test::SetCreditCardInfo(&credit_card2, "John Dillinger", |
| 3664 "423456789012" /* Visa */, "01", "1998"); | 3670 "423456789012" /* Visa */, "01", "1998", "1"); |
| 3665 personal_data_->AddCreditCard(credit_card2); | 3671 personal_data_->AddCreditCard(credit_card2); |
| 3666 | 3672 |
| 3667 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 3673 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 3668 .WillOnce(QuitMainMessageLoop()); | 3674 .WillOnce(QuitMainMessageLoop()); |
| 3669 base::RunLoop().Run(); | 3675 base::RunLoop().Run(); |
| 3670 | 3676 |
| 3671 ASSERT_EQ(3U, personal_data_->GetCreditCards().size()); | 3677 ASSERT_EQ(3U, personal_data_->GetCreditCards().size()); |
| 3672 | 3678 |
| 3673 std::vector<Suggestion> suggestions = | 3679 std::vector<Suggestion> suggestions = |
| 3674 personal_data_->GetCreditCardSuggestions( | 3680 personal_data_->GetCreditCardSuggestions( |
| (...skipping 11 matching lines...) Expand all Loading... |
| 3686 | 3692 |
| 3687 // Test that a card that doesn't have a number is not shown in the suggestions | 3693 // Test that a card that doesn't have a number is not shown in the suggestions |
| 3688 // when querying credit cards by their number. | 3694 // when querying credit cards by their number. |
| 3689 TEST_F(PersonalDataManagerTest, GetCreditCardSuggestions_NumberMissing) { | 3695 TEST_F(PersonalDataManagerTest, GetCreditCardSuggestions_NumberMissing) { |
| 3690 // Create one normal credit card and one credit card with the number missing. | 3696 // Create one normal credit card and one credit card with the number missing. |
| 3691 ASSERT_EQ(0U, personal_data_->GetCreditCards().size()); | 3697 ASSERT_EQ(0U, personal_data_->GetCreditCards().size()); |
| 3692 | 3698 |
| 3693 CreditCard credit_card0("287151C8-6AB1-487C-9095-28E80BE5DA15", | 3699 CreditCard credit_card0("287151C8-6AB1-487C-9095-28E80BE5DA15", |
| 3694 "https://www.example.com"); | 3700 "https://www.example.com"); |
| 3695 test::SetCreditCardInfo(&credit_card0, "Clyde Barrow", | 3701 test::SetCreditCardInfo(&credit_card0, "Clyde Barrow", |
| 3696 "347666888555" /* American Express */, "04", "2999"); | 3702 "347666888555" /* American Express */, "04", "2999", |
| 3703 "1"); |
| 3697 credit_card0.set_use_count(3); | 3704 credit_card0.set_use_count(3); |
| 3698 credit_card0.set_use_date(AutofillClock::Now() - | 3705 credit_card0.set_use_date(AutofillClock::Now() - |
| 3699 base::TimeDelta::FromDays(1)); | 3706 base::TimeDelta::FromDays(1)); |
| 3700 personal_data_->AddCreditCard(credit_card0); | 3707 personal_data_->AddCreditCard(credit_card0); |
| 3701 | 3708 |
| 3702 CreditCard credit_card1("1141084B-72D7-4B73-90CF-3D6AC154673B", | 3709 CreditCard credit_card1("1141084B-72D7-4B73-90CF-3D6AC154673B", |
| 3703 "https://www.example.com"); | 3710 "https://www.example.com"); |
| 3704 credit_card1.set_use_count(300); | 3711 credit_card1.set_use_count(300); |
| 3705 credit_card1.set_use_date(AutofillClock::Now() - | 3712 credit_card1.set_use_date(AutofillClock::Now() - |
| 3706 base::TimeDelta::FromDays(10)); | 3713 base::TimeDelta::FromDays(10)); |
| 3707 test::SetCreditCardInfo(&credit_card1, "John Dillinger", "", "01", "2999"); | 3714 test::SetCreditCardInfo(&credit_card1, "John Dillinger", "", "01", "2999", |
| 3715 "1"); |
| 3708 personal_data_->AddCreditCard(credit_card1); | 3716 personal_data_->AddCreditCard(credit_card1); |
| 3709 | 3717 |
| 3710 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 3718 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 3711 .WillOnce(QuitMainMessageLoop()); | 3719 .WillOnce(QuitMainMessageLoop()); |
| 3712 base::RunLoop().Run(); | 3720 base::RunLoop().Run(); |
| 3713 | 3721 |
| 3714 ASSERT_EQ(2U, personal_data_->GetCreditCards().size()); | 3722 ASSERT_EQ(2U, personal_data_->GetCreditCards().size()); |
| 3715 | 3723 |
| 3716 // Sublabel is expiration date when filling card number. The second card | 3724 // Sublabel is expiration date when filling card number. The second card |
| 3717 // doesn't have a number so it should not be included in the suggestions. | 3725 // doesn't have a number so it should not be included in the suggestions. |
| (...skipping 14 matching lines...) Expand all Loading... |
| 3732 SetupReferenceLocalCreditCards(); | 3740 SetupReferenceLocalCreditCards(); |
| 3733 | 3741 |
| 3734 // Add some server cards. If there are local dupes, the locals should be | 3742 // Add some server cards. If there are local dupes, the locals should be |
| 3735 // hidden. | 3743 // hidden. |
| 3736 std::vector<CreditCard> server_cards; | 3744 std::vector<CreditCard> server_cards; |
| 3737 // This server card matches a local card, except the local card is missing the | 3745 // This server card matches a local card, except the local card is missing the |
| 3738 // number. This should count as a dupe and thus not be shown in the | 3746 // number. This should count as a dupe and thus not be shown in the |
| 3739 // suggestions since the locally saved card takes precedence. | 3747 // suggestions since the locally saved card takes precedence. |
| 3740 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "a123")); | 3748 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "a123")); |
| 3741 test::SetCreditCardInfo(&server_cards.back(), "John Dillinger", | 3749 test::SetCreditCardInfo(&server_cards.back(), "John Dillinger", |
| 3742 "9012" /* Visa */, "01", "2999"); | 3750 "9012" /* Visa */, "01", "2999", "1"); |
| 3743 server_cards.back().set_use_count(2); | 3751 server_cards.back().set_use_count(2); |
| 3744 server_cards.back().set_use_date(AutofillClock::Now() - | 3752 server_cards.back().set_use_date(AutofillClock::Now() - |
| 3745 base::TimeDelta::FromDays(15)); | 3753 base::TimeDelta::FromDays(15)); |
| 3746 server_cards.back().SetNetworkForMaskedCard(kVisaCard); | 3754 server_cards.back().SetNetworkForMaskedCard(kVisaCard); |
| 3747 | 3755 |
| 3748 // This server card is identical to a local card, but has a different | 3756 // This server card is identical to a local card, but has a different |
| 3749 // card type. Not a dupe and therefore both should appear in the suggestions. | 3757 // card type. Not a dupe and therefore both should appear in the suggestions. |
| 3750 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "b456")); | 3758 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "b456")); |
| 3751 test::SetCreditCardInfo(&server_cards.back(), "Bonnie Parker", "2109", "12", | 3759 test::SetCreditCardInfo(&server_cards.back(), "Bonnie Parker", "2109", "12", |
| 3752 "2999"); | 3760 "2999", "1"); |
| 3753 server_cards.back().set_use_count(3); | 3761 server_cards.back().set_use_count(3); |
| 3754 server_cards.back().set_use_date(AutofillClock::Now() - | 3762 server_cards.back().set_use_date(AutofillClock::Now() - |
| 3755 base::TimeDelta::FromDays(15)); | 3763 base::TimeDelta::FromDays(15)); |
| 3756 server_cards.back().SetNetworkForMaskedCard(kVisaCard); | 3764 server_cards.back().SetNetworkForMaskedCard(kVisaCard); |
| 3757 | 3765 |
| 3758 // This unmasked server card is an exact dupe of a local card. Therefore only | 3766 // This unmasked server card is an exact dupe of a local card. Therefore only |
| 3759 // this card should appear in the suggestions as full server cards have | 3767 // this card should appear in the suggestions as full server cards have |
| 3760 // precedence over local cards. | 3768 // precedence over local cards. |
| 3761 server_cards.push_back(CreditCard(CreditCard::FULL_SERVER_CARD, "c789")); | 3769 server_cards.push_back(CreditCard(CreditCard::FULL_SERVER_CARD, "c789")); |
| 3762 test::SetCreditCardInfo(&server_cards.back(), "Clyde Barrow", | 3770 test::SetCreditCardInfo(&server_cards.back(), "Clyde Barrow", |
| 3763 "347666888555" /* American Express */, "04", "2999"); | 3771 "347666888555" /* American Express */, "04", "2999", |
| 3772 "1"); |
| 3764 server_cards.back().set_use_count(1); | 3773 server_cards.back().set_use_count(1); |
| 3765 server_cards.back().set_use_date(AutofillClock::Now() - | 3774 server_cards.back().set_use_date(AutofillClock::Now() - |
| 3766 base::TimeDelta::FromDays(15)); | 3775 base::TimeDelta::FromDays(15)); |
| 3767 | 3776 |
| 3768 test::SetServerCreditCards(autofill_table_, server_cards); | 3777 test::SetServerCreditCards(autofill_table_, server_cards); |
| 3769 personal_data_->Refresh(); | 3778 personal_data_->Refresh(); |
| 3770 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 3779 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 3771 .WillOnce(QuitMainMessageLoop()); | 3780 .WillOnce(QuitMainMessageLoop()); |
| 3772 base::RunLoop().Run(); | 3781 base::RunLoop().Run(); |
| 3773 | 3782 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 3803 GetCreditCardSuggestions_ServerCardDuplicateOfMultipleLocalCards) { | 3812 GetCreditCardSuggestions_ServerCardDuplicateOfMultipleLocalCards) { |
| 3804 EnableWalletCardImport(); | 3813 EnableWalletCardImport(); |
| 3805 SetupReferenceLocalCreditCards(); | 3814 SetupReferenceLocalCreditCards(); |
| 3806 | 3815 |
| 3807 // Add a duplicate server card. | 3816 // Add a duplicate server card. |
| 3808 std::vector<CreditCard> server_cards; | 3817 std::vector<CreditCard> server_cards; |
| 3809 // This unmasked server card is an exact dupe of a local card. Therefore only | 3818 // This unmasked server card is an exact dupe of a local card. Therefore only |
| 3810 // the local card should appear in the suggestions. | 3819 // the local card should appear in the suggestions. |
| 3811 server_cards.push_back(CreditCard(CreditCard::FULL_SERVER_CARD, "c789")); | 3820 server_cards.push_back(CreditCard(CreditCard::FULL_SERVER_CARD, "c789")); |
| 3812 test::SetCreditCardInfo(&server_cards.back(), "Clyde Barrow", | 3821 test::SetCreditCardInfo(&server_cards.back(), "Clyde Barrow", |
| 3813 "347666888555" /* American Express */, "04", "2999"); | 3822 "347666888555" /* American Express */, "04", "2999", |
| 3823 "1"); |
| 3814 | 3824 |
| 3815 test::SetServerCreditCards(autofill_table_, server_cards); | 3825 test::SetServerCreditCards(autofill_table_, server_cards); |
| 3816 personal_data_->Refresh(); | 3826 personal_data_->Refresh(); |
| 3817 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 3827 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 3818 .WillOnce(QuitMainMessageLoop()); | 3828 .WillOnce(QuitMainMessageLoop()); |
| 3819 base::RunLoop().Run(); | 3829 base::RunLoop().Run(); |
| 3820 | 3830 |
| 3821 std::vector<Suggestion> suggestions = | 3831 std::vector<Suggestion> suggestions = |
| 3822 personal_data_->GetCreditCardSuggestions( | 3832 personal_data_->GetCreditCardSuggestions( |
| 3823 AutofillType(CREDIT_CARD_NAME_FULL), | 3833 AutofillType(CREDIT_CARD_NAME_FULL), |
| 3824 /* field_contents= */ base::string16()); | 3834 /* field_contents= */ base::string16()); |
| 3825 ASSERT_EQ(3U, suggestions.size()); | 3835 ASSERT_EQ(3U, suggestions.size()); |
| 3826 | 3836 |
| 3827 // Add a second dupe local card to make sure a full server card can be a dupe | 3837 // Add a second dupe local card to make sure a full server card can be a dupe |
| 3828 // of more than one local card. | 3838 // of more than one local card. |
| 3829 CreditCard credit_card3("4141084B-72D7-4B73-90CF-3D6AC154673B", | 3839 CreditCard credit_card3("4141084B-72D7-4B73-90CF-3D6AC154673B", |
| 3830 "https://www.example.com"); | 3840 "https://www.example.com"); |
| 3831 test::SetCreditCardInfo(&credit_card3, "Clyde Barrow", "", "04", ""); | 3841 test::SetCreditCardInfo(&credit_card3, "Clyde Barrow", "", "04", "", ""); |
| 3832 personal_data_->AddCreditCard(credit_card3); | 3842 personal_data_->AddCreditCard(credit_card3); |
| 3833 | 3843 |
| 3834 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 3844 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 3835 .WillOnce(QuitMainMessageLoop()); | 3845 .WillOnce(QuitMainMessageLoop()); |
| 3836 base::RunLoop().Run(); | 3846 base::RunLoop().Run(); |
| 3837 | 3847 |
| 3838 suggestions = personal_data_->GetCreditCardSuggestions( | 3848 suggestions = personal_data_->GetCreditCardSuggestions( |
| 3839 AutofillType(CREDIT_CARD_NAME_FULL), | 3849 AutofillType(CREDIT_CARD_NAME_FULL), |
| 3840 /* field_contents= */ base::string16()); | 3850 /* field_contents= */ base::string16()); |
| 3841 ASSERT_EQ(3U, suggestions.size()); | 3851 ASSERT_EQ(3U, suggestions.size()); |
| 3842 } | 3852 } |
| 3843 | 3853 |
| 3844 // Tests that only the full server card is kept when deduping with a local | 3854 // Tests that only the full server card is kept when deduping with a local |
| 3845 // duplicate of it. | 3855 // duplicate of it. |
| 3846 TEST_F(PersonalDataManagerTest, | 3856 TEST_F(PersonalDataManagerTest, |
| 3847 DedupeCreditCardToSuggest_FullServerShadowsLocal) { | 3857 DedupeCreditCardToSuggest_FullServerShadowsLocal) { |
| 3848 std::list<CreditCard*> credit_cards; | 3858 std::list<CreditCard*> credit_cards; |
| 3849 | 3859 |
| 3850 // Create 3 different local credit cards. | 3860 // Create 3 different local credit cards. |
| 3851 CreditCard local_card("287151C8-6AB1-487C-9095-28E80BE5DA15", | 3861 CreditCard local_card("287151C8-6AB1-487C-9095-28E80BE5DA15", |
| 3852 "https://www.example.com"); | 3862 "https://www.example.com"); |
| 3853 test::SetCreditCardInfo(&local_card, "Homer Simpson", | 3863 test::SetCreditCardInfo(&local_card, "Homer Simpson", |
| 3854 "423456789012" /* Visa */, "01", "2999"); | 3864 "423456789012" /* Visa */, "01", "2999", "1"); |
| 3855 local_card.set_use_count(3); | 3865 local_card.set_use_count(3); |
| 3856 local_card.set_use_date(AutofillClock::Now() - base::TimeDelta::FromDays(1)); | 3866 local_card.set_use_date(AutofillClock::Now() - base::TimeDelta::FromDays(1)); |
| 3857 credit_cards.push_back(&local_card); | 3867 credit_cards.push_back(&local_card); |
| 3858 | 3868 |
| 3859 // Create a full server card that is a duplicate of one of the local cards. | 3869 // Create a full server card that is a duplicate of one of the local cards. |
| 3860 CreditCard full_server_card(CreditCard::FULL_SERVER_CARD, "c789"); | 3870 CreditCard full_server_card(CreditCard::FULL_SERVER_CARD, "c789"); |
| 3861 test::SetCreditCardInfo(&full_server_card, "Homer Simpson", | 3871 test::SetCreditCardInfo(&full_server_card, "Homer Simpson", |
| 3862 "423456789012" /* Visa */, "01", "2999"); | 3872 "423456789012" /* Visa */, "01", "2999", "1"); |
| 3863 full_server_card.set_use_count(1); | 3873 full_server_card.set_use_count(1); |
| 3864 full_server_card.set_use_date(AutofillClock::Now() - | 3874 full_server_card.set_use_date(AutofillClock::Now() - |
| 3865 base::TimeDelta::FromDays(15)); | 3875 base::TimeDelta::FromDays(15)); |
| 3866 credit_cards.push_back(&full_server_card); | 3876 credit_cards.push_back(&full_server_card); |
| 3867 | 3877 |
| 3868 PersonalDataManager::DedupeCreditCardToSuggest(&credit_cards); | 3878 PersonalDataManager::DedupeCreditCardToSuggest(&credit_cards); |
| 3869 ASSERT_EQ(1U, credit_cards.size()); | 3879 ASSERT_EQ(1U, credit_cards.size()); |
| 3870 | 3880 |
| 3871 const CreditCard* deduped_card(credit_cards.front()); | 3881 const CreditCard* deduped_card(credit_cards.front()); |
| 3872 EXPECT_TRUE(*deduped_card == full_server_card); | 3882 EXPECT_TRUE(*deduped_card == full_server_card); |
| 3873 } | 3883 } |
| 3874 | 3884 |
| 3875 // Tests that only the local card is kept when deduping with a masked server | 3885 // Tests that only the local card is kept when deduping with a masked server |
| 3876 // duplicate of it. | 3886 // duplicate of it. |
| 3877 TEST_F(PersonalDataManagerTest, DedupeCreditCardToSuggest_LocalShadowsMasked) { | 3887 TEST_F(PersonalDataManagerTest, DedupeCreditCardToSuggest_LocalShadowsMasked) { |
| 3878 std::list<CreditCard*> credit_cards; | 3888 std::list<CreditCard*> credit_cards; |
| 3879 | 3889 |
| 3880 CreditCard local_card("1141084B-72D7-4B73-90CF-3D6AC154673B", | 3890 CreditCard local_card("1141084B-72D7-4B73-90CF-3D6AC154673B", |
| 3881 "https://www.example.com"); | 3891 "https://www.example.com"); |
| 3882 local_card.set_use_count(300); | 3892 local_card.set_use_count(300); |
| 3883 local_card.set_use_date(AutofillClock::Now() - base::TimeDelta::FromDays(10)); | 3893 local_card.set_use_date(AutofillClock::Now() - base::TimeDelta::FromDays(10)); |
| 3884 test::SetCreditCardInfo(&local_card, "Homer Simpson", | 3894 test::SetCreditCardInfo(&local_card, "Homer Simpson", |
| 3885 "423456789012" /* Visa */, "01", "2999"); | 3895 "423456789012" /* Visa */, "01", "2999", "1"); |
| 3886 credit_cards.push_back(&local_card); | 3896 credit_cards.push_back(&local_card); |
| 3887 | 3897 |
| 3888 // Create a masked server card that is a duplicate of a local card. | 3898 // Create a masked server card that is a duplicate of a local card. |
| 3889 CreditCard masked_card(CreditCard::MASKED_SERVER_CARD, "a123"); | 3899 CreditCard masked_card(CreditCard::MASKED_SERVER_CARD, "a123"); |
| 3890 test::SetCreditCardInfo(&masked_card, "Homer Simpson", "9012" /* Visa */, | 3900 test::SetCreditCardInfo(&masked_card, "Homer Simpson", "9012" /* Visa */, |
| 3891 "01", "2999"); | 3901 "01", "2999", "1"); |
| 3892 masked_card.set_use_count(2); | 3902 masked_card.set_use_count(2); |
| 3893 masked_card.set_use_date(AutofillClock::Now() - | 3903 masked_card.set_use_date(AutofillClock::Now() - |
| 3894 base::TimeDelta::FromDays(15)); | 3904 base::TimeDelta::FromDays(15)); |
| 3895 masked_card.SetNetworkForMaskedCard(kVisaCard); | 3905 masked_card.SetNetworkForMaskedCard(kVisaCard); |
| 3896 credit_cards.push_back(&masked_card); | 3906 credit_cards.push_back(&masked_card); |
| 3897 | 3907 |
| 3898 PersonalDataManager::DedupeCreditCardToSuggest(&credit_cards); | 3908 PersonalDataManager::DedupeCreditCardToSuggest(&credit_cards); |
| 3899 ASSERT_EQ(1U, credit_cards.size()); | 3909 ASSERT_EQ(1U, credit_cards.size()); |
| 3900 | 3910 |
| 3901 const CreditCard* deduped_card(credit_cards.front()); | 3911 const CreditCard* deduped_card(credit_cards.front()); |
| 3902 EXPECT_TRUE(*deduped_card == local_card); | 3912 EXPECT_TRUE(*deduped_card == local_card); |
| 3903 } | 3913 } |
| 3904 | 3914 |
| 3905 // Tests that identical full server and masked credit cards are not deduped. | 3915 // Tests that identical full server and masked credit cards are not deduped. |
| 3906 TEST_F(PersonalDataManagerTest, DedupeCreditCardToSuggest_FullServerAndMasked) { | 3916 TEST_F(PersonalDataManagerTest, DedupeCreditCardToSuggest_FullServerAndMasked) { |
| 3907 std::list<CreditCard*> credit_cards; | 3917 std::list<CreditCard*> credit_cards; |
| 3908 | 3918 |
| 3909 // Create a full server card that is a duplicate of one of the local cards. | 3919 // Create a full server card that is a duplicate of one of the local cards. |
| 3910 CreditCard full_server_card(CreditCard::FULL_SERVER_CARD, "c789"); | 3920 CreditCard full_server_card(CreditCard::FULL_SERVER_CARD, "c789"); |
| 3911 test::SetCreditCardInfo(&full_server_card, "Homer Simpson", | 3921 test::SetCreditCardInfo(&full_server_card, "Homer Simpson", |
| 3912 "423456789012" /* Visa */, "01", "2999"); | 3922 "423456789012" /* Visa */, "01", "2999", "1"); |
| 3913 full_server_card.set_use_count(1); | 3923 full_server_card.set_use_count(1); |
| 3914 full_server_card.set_use_date(AutofillClock::Now() - | 3924 full_server_card.set_use_date(AutofillClock::Now() - |
| 3915 base::TimeDelta::FromDays(15)); | 3925 base::TimeDelta::FromDays(15)); |
| 3916 credit_cards.push_back(&full_server_card); | 3926 credit_cards.push_back(&full_server_card); |
| 3917 | 3927 |
| 3918 // Create a masked server card that is a duplicate of a local card. | 3928 // Create a masked server card that is a duplicate of a local card. |
| 3919 CreditCard masked_card(CreditCard::MASKED_SERVER_CARD, "a123"); | 3929 CreditCard masked_card(CreditCard::MASKED_SERVER_CARD, "a123"); |
| 3920 test::SetCreditCardInfo(&masked_card, "Homer Simpson", "9012" /* Visa */, | 3930 test::SetCreditCardInfo(&masked_card, "Homer Simpson", "9012" /* Visa */, |
| 3921 "01", "2999"); | 3931 "01", "2999", "1"); |
| 3922 masked_card.set_use_count(2); | 3932 masked_card.set_use_count(2); |
| 3923 masked_card.set_use_date(AutofillClock::Now() - | 3933 masked_card.set_use_date(AutofillClock::Now() - |
| 3924 base::TimeDelta::FromDays(15)); | 3934 base::TimeDelta::FromDays(15)); |
| 3925 masked_card.SetNetworkForMaskedCard(kVisaCard); | 3935 masked_card.SetNetworkForMaskedCard(kVisaCard); |
| 3926 credit_cards.push_back(&masked_card); | 3936 credit_cards.push_back(&masked_card); |
| 3927 | 3937 |
| 3928 PersonalDataManager::DedupeCreditCardToSuggest(&credit_cards); | 3938 PersonalDataManager::DedupeCreditCardToSuggest(&credit_cards); |
| 3929 EXPECT_EQ(2U, credit_cards.size()); | 3939 EXPECT_EQ(2U, credit_cards.size()); |
| 3930 } | 3940 } |
| 3931 | 3941 |
| 3932 // Tests that slightly different local, full server, and masked credit cards are | 3942 // Tests that slightly different local, full server, and masked credit cards are |
| 3933 // not deduped. | 3943 // not deduped. |
| 3934 TEST_F(PersonalDataManagerTest, DedupeCreditCardToSuggest_DifferentCards) { | 3944 TEST_F(PersonalDataManagerTest, DedupeCreditCardToSuggest_DifferentCards) { |
| 3935 std::list<CreditCard*> credit_cards; | 3945 std::list<CreditCard*> credit_cards; |
| 3936 | 3946 |
| 3937 CreditCard credit_card2("002149C1-EE28-4213-A3B9-DA243FFF021B", | 3947 CreditCard credit_card2("002149C1-EE28-4213-A3B9-DA243FFF021B", |
| 3938 "https://www.example.com"); | 3948 "https://www.example.com"); |
| 3939 credit_card2.set_use_count(1); | 3949 credit_card2.set_use_count(1); |
| 3940 credit_card2.set_use_date(AutofillClock::Now() - | 3950 credit_card2.set_use_date(AutofillClock::Now() - |
| 3941 base::TimeDelta::FromDays(1)); | 3951 base::TimeDelta::FromDays(1)); |
| 3942 test::SetCreditCardInfo(&credit_card2, "Homer Simpson", | 3952 test::SetCreditCardInfo(&credit_card2, "Homer Simpson", |
| 3943 "518765432109" /* Mastercard */, "", ""); | 3953 "518765432109" /* Mastercard */, "", "", ""); |
| 3944 credit_cards.push_back(&credit_card2); | 3954 credit_cards.push_back(&credit_card2); |
| 3945 | 3955 |
| 3946 // Create a masked server card that is slightly different of the local card. | 3956 // Create a masked server card that is slightly different of the local card. |
| 3947 CreditCard credit_card4(CreditCard::MASKED_SERVER_CARD, "b456"); | 3957 CreditCard credit_card4(CreditCard::MASKED_SERVER_CARD, "b456"); |
| 3948 test::SetCreditCardInfo(&credit_card4, "Homer Simpson", "2109", "12", "2999"); | 3958 test::SetCreditCardInfo(&credit_card4, "Homer Simpson", "2109", "12", "2999", |
| 3959 "1"); |
| 3949 credit_card4.set_use_count(3); | 3960 credit_card4.set_use_count(3); |
| 3950 credit_card4.set_use_date(AutofillClock::Now() - | 3961 credit_card4.set_use_date(AutofillClock::Now() - |
| 3951 base::TimeDelta::FromDays(15)); | 3962 base::TimeDelta::FromDays(15)); |
| 3952 credit_card4.SetNetworkForMaskedCard(kVisaCard); | 3963 credit_card4.SetNetworkForMaskedCard(kVisaCard); |
| 3953 credit_cards.push_back(&credit_card4); | 3964 credit_cards.push_back(&credit_card4); |
| 3954 | 3965 |
| 3955 // Create a full server card that is slightly different of the two other | 3966 // Create a full server card that is slightly different of the two other |
| 3956 // cards. | 3967 // cards. |
| 3957 CreditCard credit_card5(CreditCard::FULL_SERVER_CARD, "c789"); | 3968 CreditCard credit_card5(CreditCard::FULL_SERVER_CARD, "c789"); |
| 3958 test::SetCreditCardInfo(&credit_card5, "Homer Simpson", | 3969 test::SetCreditCardInfo(&credit_card5, "Homer Simpson", |
| 3959 "347666888555" /* American Express */, "04", "2999"); | 3970 "347666888555" /* American Express */, "04", "2999", |
| 3971 "1"); |
| 3960 credit_card5.set_use_count(1); | 3972 credit_card5.set_use_count(1); |
| 3961 credit_card5.set_use_date(AutofillClock::Now() - | 3973 credit_card5.set_use_date(AutofillClock::Now() - |
| 3962 base::TimeDelta::FromDays(15)); | 3974 base::TimeDelta::FromDays(15)); |
| 3963 credit_cards.push_back(&credit_card5); | 3975 credit_cards.push_back(&credit_card5); |
| 3964 | 3976 |
| 3965 PersonalDataManager::DedupeCreditCardToSuggest(&credit_cards); | 3977 PersonalDataManager::DedupeCreditCardToSuggest(&credit_cards); |
| 3966 EXPECT_EQ(3U, credit_cards.size()); | 3978 EXPECT_EQ(3U, credit_cards.size()); |
| 3967 } | 3979 } |
| 3968 | 3980 |
| 3969 TEST_F(PersonalDataManagerTest, RecordUseOf) { | 3981 TEST_F(PersonalDataManagerTest, RecordUseOf) { |
| 3970 // Create the test clock and set the time to a specific value. | 3982 // Create the test clock and set the time to a specific value. |
| 3971 TestAutofillClock test_clock; | 3983 TestAutofillClock test_clock; |
| 3972 test_clock.SetNow(kArbitraryTime); | 3984 test_clock.SetNow(kArbitraryTime); |
| 3973 | 3985 |
| 3974 AutofillProfile profile(test::GetFullProfile()); | 3986 AutofillProfile profile(test::GetFullProfile()); |
| 3975 EXPECT_EQ(1U, profile.use_count()); | 3987 EXPECT_EQ(1U, profile.use_count()); |
| 3976 EXPECT_EQ(kArbitraryTime, profile.use_date()); | 3988 EXPECT_EQ(kArbitraryTime, profile.use_date()); |
| 3977 EXPECT_EQ(kArbitraryTime, profile.modification_date()); | 3989 EXPECT_EQ(kArbitraryTime, profile.modification_date()); |
| 3978 personal_data_->AddProfile(profile); | 3990 personal_data_->AddProfile(profile); |
| 3979 | 3991 |
| 3980 CreditCard credit_card(base::GenerateGUID(), "https://www.example.com"); | 3992 CreditCard credit_card(base::GenerateGUID(), "https://www.example.com"); |
| 3981 test::SetCreditCardInfo(&credit_card, "John Dillinger", | 3993 test::SetCreditCardInfo(&credit_card, "John Dillinger", |
| 3982 "423456789012" /* Visa */, "01", "2999"); | 3994 "423456789012" /* Visa */, "01", "2999", "1"); |
| 3983 EXPECT_EQ(1U, credit_card.use_count()); | 3995 EXPECT_EQ(1U, credit_card.use_count()); |
| 3984 EXPECT_EQ(kArbitraryTime, credit_card.use_date()); | 3996 EXPECT_EQ(kArbitraryTime, credit_card.use_date()); |
| 3985 EXPECT_EQ(kArbitraryTime, credit_card.modification_date()); | 3997 EXPECT_EQ(kArbitraryTime, credit_card.modification_date()); |
| 3986 personal_data_->AddCreditCard(credit_card); | 3998 personal_data_->AddCreditCard(credit_card); |
| 3987 | 3999 |
| 3988 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 4000 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 3989 .WillOnce(QuitMainMessageLoop()); | 4001 .WillOnce(QuitMainMessageLoop()); |
| 3990 base::RunLoop().Run(); | 4002 base::RunLoop().Run(); |
| 3991 | 4003 |
| 3992 // Set the current time to another value. | 4004 // Set the current time to another value. |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4028 EXPECT_EQ(kSomeLaterTime, added_card->use_date()); | 4040 EXPECT_EQ(kSomeLaterTime, added_card->use_date()); |
| 4029 EXPECT_EQ(kArbitraryTime, added_card->modification_date()); | 4041 EXPECT_EQ(kArbitraryTime, added_card->modification_date()); |
| 4030 } | 4042 } |
| 4031 | 4043 |
| 4032 TEST_F(PersonalDataManagerTest, UpdateServerCreditCardUsageStats) { | 4044 TEST_F(PersonalDataManagerTest, UpdateServerCreditCardUsageStats) { |
| 4033 EnableWalletCardImport(); | 4045 EnableWalletCardImport(); |
| 4034 | 4046 |
| 4035 std::vector<CreditCard> server_cards; | 4047 std::vector<CreditCard> server_cards; |
| 4036 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "a123")); | 4048 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "a123")); |
| 4037 test::SetCreditCardInfo(&server_cards.back(), "John Dillinger", | 4049 test::SetCreditCardInfo(&server_cards.back(), "John Dillinger", |
| 4038 "9012" /* Visa */, "01", "2999"); | 4050 "9012" /* Visa */, "01", "2999", "1"); |
| 4039 server_cards.back().SetNetworkForMaskedCard(kVisaCard); | 4051 server_cards.back().SetNetworkForMaskedCard(kVisaCard); |
| 4040 | 4052 |
| 4041 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "b456")); | 4053 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "b456")); |
| 4042 test::SetCreditCardInfo(&server_cards.back(), "Bonnie Parker", | 4054 test::SetCreditCardInfo(&server_cards.back(), "Bonnie Parker", |
| 4043 "4444" /* Mastercard */, "12", "2999"); | 4055 "4444" /* Mastercard */, "12", "2999", "1"); |
| 4044 server_cards.back().SetNetworkForMaskedCard(kMasterCard); | 4056 server_cards.back().SetNetworkForMaskedCard(kMasterCard); |
| 4045 | 4057 |
| 4046 server_cards.push_back(CreditCard(CreditCard::FULL_SERVER_CARD, "c789")); | 4058 server_cards.push_back(CreditCard(CreditCard::FULL_SERVER_CARD, "c789")); |
| 4047 test::SetCreditCardInfo(&server_cards.back(), "Clyde Barrow", | 4059 test::SetCreditCardInfo(&server_cards.back(), "Clyde Barrow", |
| 4048 "347666888555" /* American Express */, "04", "2999"); | 4060 "347666888555" /* American Express */, "04", "2999", |
| 4061 "1"); |
| 4049 | 4062 |
| 4050 // Create the test clock and set the time to a specific value. | 4063 // Create the test clock and set the time to a specific value. |
| 4051 TestAutofillClock test_clock; | 4064 TestAutofillClock test_clock; |
| 4052 test_clock.SetNow(kArbitraryTime); | 4065 test_clock.SetNow(kArbitraryTime); |
| 4053 | 4066 |
| 4054 test::SetServerCreditCards(autofill_table_, server_cards); | 4067 test::SetServerCreditCards(autofill_table_, server_cards); |
| 4055 personal_data_->Refresh(); | 4068 personal_data_->Refresh(); |
| 4056 | 4069 |
| 4057 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 4070 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 4058 .WillOnce(QuitMainMessageLoop()); | 4071 .WillOnce(QuitMainMessageLoop()); |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4150 ASSERT_EQ(3U, personal_data_->GetCreditCards().size()); | 4163 ASSERT_EQ(3U, personal_data_->GetCreditCards().size()); |
| 4151 EXPECT_EQ(3U, personal_data_->GetCreditCards()[1]->use_count()); | 4164 EXPECT_EQ(3U, personal_data_->GetCreditCards()[1]->use_count()); |
| 4152 EXPECT_EQ(kMuchLaterTime, personal_data_->GetCreditCards()[1]->use_date()); | 4165 EXPECT_EQ(kMuchLaterTime, personal_data_->GetCreditCards()[1]->use_date()); |
| 4153 } | 4166 } |
| 4154 | 4167 |
| 4155 TEST_F(PersonalDataManagerTest, ClearAllServerData) { | 4168 TEST_F(PersonalDataManagerTest, ClearAllServerData) { |
| 4156 // Add a server card. | 4169 // Add a server card. |
| 4157 std::vector<CreditCard> server_cards; | 4170 std::vector<CreditCard> server_cards; |
| 4158 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "a123")); | 4171 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "a123")); |
| 4159 test::SetCreditCardInfo(&server_cards.back(), "John Dillinger", | 4172 test::SetCreditCardInfo(&server_cards.back(), "John Dillinger", |
| 4160 "9012" /* Visa */, "01", "2999"); | 4173 "9012" /* Visa */, "01", "2999", "1"); |
| 4161 server_cards.back().SetNetworkForMaskedCard(kVisaCard); | 4174 server_cards.back().SetNetworkForMaskedCard(kVisaCard); |
| 4162 test::SetServerCreditCards(autofill_table_, server_cards); | 4175 test::SetServerCreditCards(autofill_table_, server_cards); |
| 4163 personal_data_->Refresh(); | 4176 personal_data_->Refresh(); |
| 4164 | 4177 |
| 4165 // Need to set the google services username | 4178 // Need to set the google services username |
| 4166 EnableWalletCardImport(); | 4179 EnableWalletCardImport(); |
| 4167 | 4180 |
| 4168 // The card and profile should be there. | 4181 // The card and profile should be there. |
| 4169 ResetPersonalDataManager(USER_MODE_NORMAL); | 4182 ResetPersonalDataManager(USER_MODE_NORMAL); |
| 4170 EXPECT_FALSE(personal_data_->GetCreditCards().empty()); | 4183 EXPECT_FALSE(personal_data_->GetCreditCards().empty()); |
| 4171 | 4184 |
| 4172 personal_data_->ClearAllServerData(); | 4185 personal_data_->ClearAllServerData(); |
| 4173 | 4186 |
| 4174 // Reload the database, everything should be gone. | 4187 // Reload the database, everything should be gone. |
| 4175 ResetPersonalDataManager(USER_MODE_NORMAL); | 4188 ResetPersonalDataManager(USER_MODE_NORMAL); |
| 4176 EXPECT_TRUE(personal_data_->GetCreditCards().empty()); | 4189 EXPECT_TRUE(personal_data_->GetCreditCards().empty()); |
| 4177 } | 4190 } |
| 4178 | 4191 |
| 4179 TEST_F(PersonalDataManagerTest, DontDuplicateServerCard) { | 4192 TEST_F(PersonalDataManagerTest, DontDuplicateServerCard) { |
| 4180 EnableWalletCardImport(); | 4193 EnableWalletCardImport(); |
| 4181 | 4194 |
| 4182 std::vector<CreditCard> server_cards; | 4195 std::vector<CreditCard> server_cards; |
| 4183 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "a123")); | 4196 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "a123")); |
| 4184 test::SetCreditCardInfo(&server_cards.back(), "John Dillinger", | 4197 test::SetCreditCardInfo(&server_cards.back(), "John Dillinger", |
| 4185 "1881" /* Visa */, "01", "2999"); | 4198 "1881" /* Visa */, "01", "2999", "1"); |
| 4186 server_cards.back().SetNetworkForMaskedCard(kVisaCard); | 4199 server_cards.back().SetNetworkForMaskedCard(kVisaCard); |
| 4187 | 4200 |
| 4188 server_cards.push_back(CreditCard(CreditCard::FULL_SERVER_CARD, "c789")); | 4201 server_cards.push_back(CreditCard(CreditCard::FULL_SERVER_CARD, "c789")); |
| 4189 test::SetCreditCardInfo(&server_cards.back(), "Clyde Barrow", | 4202 test::SetCreditCardInfo(&server_cards.back(), "Clyde Barrow", |
| 4190 "347666888555" /* American Express */, "04", "2999"); | 4203 "347666888555" /* American Express */, "04", "2999", |
| 4204 "1"); |
| 4191 | 4205 |
| 4192 test::SetServerCreditCards(autofill_table_, server_cards); | 4206 test::SetServerCreditCards(autofill_table_, server_cards); |
| 4193 personal_data_->Refresh(); | 4207 personal_data_->Refresh(); |
| 4194 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 4208 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 4195 .WillOnce(QuitMainMessageLoop()); | 4209 .WillOnce(QuitMainMessageLoop()); |
| 4196 base::RunLoop().Run(); | 4210 base::RunLoop().Run(); |
| 4197 | 4211 |
| 4198 // A valid credit card form. A user re-enters one of their masked cards. | 4212 // A valid credit card form. A user re-enters one of their masked cards. |
| 4199 // We shouldn't offer to save. It's possible this is actually a different card | 4213 // We shouldn't offer to save. It's possible this is actually a different card |
| 4200 // but it's very unlikely. And these circumstances will also arise if the user | 4214 // but it's very unlikely. And these circumstances will also arise if the user |
| (...skipping 820 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5021 "bart.simpson@abc.com", "Fox", "742 Evergreen Terrace.", | 5035 "bart.simpson@abc.com", "Fox", "742 Evergreen Terrace.", |
| 5022 "", "Springfield", "IL", "91601", "", ""); | 5036 "", "Springfield", "IL", "91601", "", ""); |
| 5023 profile6.set_use_count(10); | 5037 profile6.set_use_count(10); |
| 5024 profile6.set_use_date(AutofillClock::Now() - base::TimeDelta::FromDays(1)); | 5038 profile6.set_use_date(AutofillClock::Now() - base::TimeDelta::FromDays(1)); |
| 5025 | 5039 |
| 5026 // Add three credit cards. Give them a frecency score so that they are | 5040 // Add three credit cards. Give them a frecency score so that they are |
| 5027 // suggested in order (1, 2, 3). This will ensure a deterministic order for | 5041 // suggested in order (1, 2, 3). This will ensure a deterministic order for |
| 5028 // verifying results. | 5042 // verifying results. |
| 5029 CreditCard credit_card1(base::GenerateGUID(), "https://www.example.com"); | 5043 CreditCard credit_card1(base::GenerateGUID(), "https://www.example.com"); |
| 5030 test::SetCreditCardInfo(&credit_card1, "Clyde Barrow", | 5044 test::SetCreditCardInfo(&credit_card1, "Clyde Barrow", |
| 5031 "347666888555" /* American Express */, "04", "2999"); | 5045 "347666888555" /* American Express */, "04", "2999", |
| 5046 "1"); |
| 5032 credit_card1.set_use_count(10); | 5047 credit_card1.set_use_count(10); |
| 5033 | 5048 |
| 5034 CreditCard credit_card2(base::GenerateGUID(), "https://www.example.com"); | 5049 CreditCard credit_card2(base::GenerateGUID(), "https://www.example.com"); |
| 5035 test::SetCreditCardInfo(&credit_card2, "John Dillinger", | 5050 test::SetCreditCardInfo(&credit_card2, "John Dillinger", |
| 5036 "423456789012" /* Visa */, "01", "2999"); | 5051 "423456789012" /* Visa */, "01", "2999", "1"); |
| 5037 credit_card2.set_use_count(5); | 5052 credit_card2.set_use_count(5); |
| 5038 | 5053 |
| 5039 CreditCard credit_card3(base::GenerateGUID(), "https://www.example.com"); | 5054 CreditCard credit_card3(base::GenerateGUID(), "https://www.example.com"); |
| 5040 test::SetCreditCardInfo(&credit_card3, "Bonnie Parker", | 5055 test::SetCreditCardInfo(&credit_card3, "Bonnie Parker", |
| 5041 "518765432109" /* Mastercard */, "12", "2999"); | 5056 "518765432109" /* Mastercard */, "12", "2999", "1"); |
| 5042 credit_card3.set_use_count(1); | 5057 credit_card3.set_use_count(1); |
| 5043 | 5058 |
| 5044 // Associate the first card with profile1. | 5059 // Associate the first card with profile1. |
| 5045 credit_card1.set_billing_address_id(profile1.guid()); | 5060 credit_card1.set_billing_address_id(profile1.guid()); |
| 5046 // Associate the second card with profile4. | 5061 // Associate the second card with profile4. |
| 5047 credit_card2.set_billing_address_id(profile4.guid()); | 5062 credit_card2.set_billing_address_id(profile4.guid()); |
| 5048 // Associate the third card with profile6. | 5063 // Associate the third card with profile6. |
| 5049 credit_card3.set_billing_address_id(profile6.guid()); | 5064 credit_card3.set_billing_address_id(profile6.guid()); |
| 5050 | 5065 |
| 5051 personal_data_->AddProfile(profile1); | 5066 personal_data_->AddProfile(profile1); |
| (...skipping 760 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5812 GetServerProfiles.back().SetRawInfo(NAME_FULL, | 5827 GetServerProfiles.back().SetRawInfo(NAME_FULL, |
| 5813 base::ASCIIToUTF16("John Doe")); | 5828 base::ASCIIToUTF16("John Doe")); |
| 5814 GetServerProfiles.back().set_use_count(100); | 5829 GetServerProfiles.back().set_use_count(100); |
| 5815 autofill_table_->SetServerProfiles(GetServerProfiles); | 5830 autofill_table_->SetServerProfiles(GetServerProfiles); |
| 5816 | 5831 |
| 5817 // Add a server and a local card that have the server address as billing | 5832 // Add a server and a local card that have the server address as billing |
| 5818 // address. | 5833 // address. |
| 5819 CreditCard local_card("287151C8-6AB1-487C-9095-28E80BE5DA15", | 5834 CreditCard local_card("287151C8-6AB1-487C-9095-28E80BE5DA15", |
| 5820 "https://www.example.com"); | 5835 "https://www.example.com"); |
| 5821 test::SetCreditCardInfo(&local_card, "Clyde Barrow", | 5836 test::SetCreditCardInfo(&local_card, "Clyde Barrow", |
| 5822 "347666888555" /* American Express */, "04", "2999"); | 5837 "347666888555" /* American Express */, "04", "2999", |
| 5838 "1"); |
| 5823 local_card.set_billing_address_id(kServerAddressId); | 5839 local_card.set_billing_address_id(kServerAddressId); |
| 5824 personal_data_->AddCreditCard(local_card); | 5840 personal_data_->AddCreditCard(local_card); |
| 5825 | 5841 |
| 5826 std::vector<CreditCard> server_cards; | 5842 std::vector<CreditCard> server_cards; |
| 5827 server_cards.push_back( | 5843 server_cards.push_back( |
| 5828 CreditCard(CreditCard::MASKED_SERVER_CARD, "server_card1")); | 5844 CreditCard(CreditCard::MASKED_SERVER_CARD, "server_card1")); |
| 5829 test::SetCreditCardInfo(&server_cards.back(), "John Dillinger", | 5845 test::SetCreditCardInfo(&server_cards.back(), "John Dillinger", |
| 5830 "1111" /* Visa */, "01", "2999"); | 5846 "1111" /* Visa */, "01", "2999", "1"); |
| 5831 server_cards.back().SetNetworkForMaskedCard(kVisaCard); | 5847 server_cards.back().SetNetworkForMaskedCard(kVisaCard); |
| 5832 server_cards.back().set_billing_address_id(kServerAddressId); | 5848 server_cards.back().set_billing_address_id(kServerAddressId); |
| 5833 test::SetServerCreditCards(autofill_table_, server_cards); | 5849 test::SetServerCreditCards(autofill_table_, server_cards); |
| 5834 | 5850 |
| 5835 // Make sure everything is setup correctly. | 5851 // Make sure everything is setup correctly. |
| 5836 personal_data_->Refresh(); | 5852 personal_data_->Refresh(); |
| 5837 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 5853 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 5838 .WillOnce(QuitMainMessageLoop()); | 5854 .WillOnce(QuitMainMessageLoop()); |
| 5839 base::RunLoop().Run(); | 5855 base::RunLoop().Run(); |
| 5840 EXPECT_EQ(1U, personal_data_->web_profiles().size()); | 5856 EXPECT_EQ(1U, personal_data_->web_profiles().size()); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5920 GetServerProfiles.back().SetRawInfo(NAME_FULL, | 5936 GetServerProfiles.back().SetRawInfo(NAME_FULL, |
| 5921 base::ASCIIToUTF16("John Doe")); | 5937 base::ASCIIToUTF16("John Doe")); |
| 5922 GetServerProfiles.back().set_use_count(100); | 5938 GetServerProfiles.back().set_use_count(100); |
| 5923 autofill_table_->SetServerProfiles(GetServerProfiles); | 5939 autofill_table_->SetServerProfiles(GetServerProfiles); |
| 5924 | 5940 |
| 5925 // Add a server and a local card that have the server address as billing | 5941 // Add a server and a local card that have the server address as billing |
| 5926 // address. | 5942 // address. |
| 5927 CreditCard local_card("287151C8-6AB1-487C-9095-28E80BE5DA15", | 5943 CreditCard local_card("287151C8-6AB1-487C-9095-28E80BE5DA15", |
| 5928 "https://www.example.com"); | 5944 "https://www.example.com"); |
| 5929 test::SetCreditCardInfo(&local_card, "Clyde Barrow", | 5945 test::SetCreditCardInfo(&local_card, "Clyde Barrow", |
| 5930 "347666888555" /* American Express */, "04", "2999"); | 5946 "347666888555" /* American Express */, "04", "2999", |
| 5947 "1"); |
| 5931 local_card.set_billing_address_id(kServerAddressId); | 5948 local_card.set_billing_address_id(kServerAddressId); |
| 5932 personal_data_->AddCreditCard(local_card); | 5949 personal_data_->AddCreditCard(local_card); |
| 5933 | 5950 |
| 5934 std::vector<CreditCard> server_cards; | 5951 std::vector<CreditCard> server_cards; |
| 5935 server_cards.push_back( | 5952 server_cards.push_back( |
| 5936 CreditCard(CreditCard::MASKED_SERVER_CARD, "server_card1")); | 5953 CreditCard(CreditCard::MASKED_SERVER_CARD, "server_card1")); |
| 5937 test::SetCreditCardInfo(&server_cards.back(), "John Dillinger", | 5954 test::SetCreditCardInfo(&server_cards.back(), "John Dillinger", |
| 5938 "1111" /* Visa */, "01", "2999"); | 5955 "1111" /* Visa */, "01", "2999", "1"); |
| 5939 server_cards.back().SetNetworkForMaskedCard(kVisaCard); | 5956 server_cards.back().SetNetworkForMaskedCard(kVisaCard); |
| 5940 server_cards.back().set_billing_address_id(kServerAddressId); | 5957 server_cards.back().set_billing_address_id(kServerAddressId); |
| 5941 test::SetServerCreditCards(autofill_table_, server_cards); | 5958 test::SetServerCreditCards(autofill_table_, server_cards); |
| 5942 | 5959 |
| 5943 // Make sure everything is setup correctly. | 5960 // Make sure everything is setup correctly. |
| 5944 personal_data_->Refresh(); | 5961 personal_data_->Refresh(); |
| 5945 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 5962 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 5946 .WillOnce(QuitMainMessageLoop()); | 5963 .WillOnce(QuitMainMessageLoop()); |
| 5947 base::RunLoop().Run(); | 5964 base::RunLoop().Run(); |
| 5948 EXPECT_EQ(1U, personal_data_->web_profiles().size()); | 5965 EXPECT_EQ(1U, personal_data_->web_profiles().size()); |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6095 GetServerProfiles.back().SetRawInfo(NAME_FULL, | 6112 GetServerProfiles.back().SetRawInfo(NAME_FULL, |
| 6096 base::ASCIIToUTF16("John Doe")); | 6113 base::ASCIIToUTF16("John Doe")); |
| 6097 GetServerProfiles.back().set_use_count(200); | 6114 GetServerProfiles.back().set_use_count(200); |
| 6098 autofill_table_->SetServerProfiles(GetServerProfiles); | 6115 autofill_table_->SetServerProfiles(GetServerProfiles); |
| 6099 | 6116 |
| 6100 // Add a server and a local card that have the first and second Wallet address | 6117 // Add a server and a local card that have the first and second Wallet address |
| 6101 // as a billing address. | 6118 // as a billing address. |
| 6102 CreditCard local_card("287151C8-6AB1-487C-9095-28E80BE5DA15", | 6119 CreditCard local_card("287151C8-6AB1-487C-9095-28E80BE5DA15", |
| 6103 "https://www.example.com"); | 6120 "https://www.example.com"); |
| 6104 test::SetCreditCardInfo(&local_card, "Clyde Barrow", | 6121 test::SetCreditCardInfo(&local_card, "Clyde Barrow", |
| 6105 "347666888555" /* American Express */, "04", "2999"); | 6122 "347666888555" /* American Express */, "04", "2999", |
| 6123 "1"); |
| 6106 local_card.set_billing_address_id(kServerAddressId); | 6124 local_card.set_billing_address_id(kServerAddressId); |
| 6107 personal_data_->AddCreditCard(local_card); | 6125 personal_data_->AddCreditCard(local_card); |
| 6108 | 6126 |
| 6109 std::vector<CreditCard> server_cards; | 6127 std::vector<CreditCard> server_cards; |
| 6110 server_cards.push_back( | 6128 server_cards.push_back( |
| 6111 CreditCard(CreditCard::MASKED_SERVER_CARD, "server_card1")); | 6129 CreditCard(CreditCard::MASKED_SERVER_CARD, "server_card1")); |
| 6112 test::SetCreditCardInfo(&server_cards.back(), "John Dillinger", | 6130 test::SetCreditCardInfo(&server_cards.back(), "John Dillinger", |
| 6113 "1111" /* Visa */, "01", "2999"); | 6131 "1111" /* Visa */, "01", "2999", "1"); |
| 6114 server_cards.back().SetNetworkForMaskedCard(kVisaCard); | 6132 server_cards.back().SetNetworkForMaskedCard(kVisaCard); |
| 6115 server_cards.back().set_billing_address_id(kServerAddressId2); | 6133 server_cards.back().set_billing_address_id(kServerAddressId2); |
| 6116 test::SetServerCreditCards(autofill_table_, server_cards); | 6134 test::SetServerCreditCards(autofill_table_, server_cards); |
| 6117 | 6135 |
| 6118 // Make sure everything is setup correctly. | 6136 // Make sure everything is setup correctly. |
| 6119 personal_data_->Refresh(); | 6137 personal_data_->Refresh(); |
| 6120 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 6138 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 6121 .WillOnce(QuitMainMessageLoop()); | 6139 .WillOnce(QuitMainMessageLoop()); |
| 6122 base::RunLoop().Run(); | 6140 base::RunLoop().Run(); |
| 6123 EXPECT_EQ(1U, personal_data_->web_profiles().size()); | 6141 EXPECT_EQ(1U, personal_data_->web_profiles().size()); |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6200 GetServerProfiles.back().SetRawInfo(NAME_FULL, | 6218 GetServerProfiles.back().SetRawInfo(NAME_FULL, |
| 6201 base::ASCIIToUTF16("John Doe")); | 6219 base::ASCIIToUTF16("John Doe")); |
| 6202 GetServerProfiles.back().set_use_count(100); | 6220 GetServerProfiles.back().set_use_count(100); |
| 6203 autofill_table_->SetServerProfiles(GetServerProfiles); | 6221 autofill_table_->SetServerProfiles(GetServerProfiles); |
| 6204 | 6222 |
| 6205 // Add a server card that have the server address as billing address. | 6223 // Add a server card that have the server address as billing address. |
| 6206 std::vector<CreditCard> server_cards; | 6224 std::vector<CreditCard> server_cards; |
| 6207 server_cards.push_back( | 6225 server_cards.push_back( |
| 6208 CreditCard(CreditCard::MASKED_SERVER_CARD, "server_card1")); | 6226 CreditCard(CreditCard::MASKED_SERVER_CARD, "server_card1")); |
| 6209 test::SetCreditCardInfo(&server_cards.back(), "John Dillinger", | 6227 test::SetCreditCardInfo(&server_cards.back(), "John Dillinger", |
| 6210 "1111" /* Visa */, "01", "2999"); | 6228 "1111" /* Visa */, "01", "2999", "1"); |
| 6211 server_cards.back().SetNetworkForMaskedCard(kVisaCard); | 6229 server_cards.back().SetNetworkForMaskedCard(kVisaCard); |
| 6212 server_cards.back().set_billing_address_id(kServerAddressId); | 6230 server_cards.back().set_billing_address_id(kServerAddressId); |
| 6213 test::SetServerCreditCards(autofill_table_, server_cards); | 6231 test::SetServerCreditCards(autofill_table_, server_cards); |
| 6214 | 6232 |
| 6215 // Make sure everything is setup correctly. | 6233 // Make sure everything is setup correctly. |
| 6216 personal_data_->Refresh(); | 6234 personal_data_->Refresh(); |
| 6217 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 6235 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 6218 .WillOnce(QuitMainMessageLoop()); | 6236 .WillOnce(QuitMainMessageLoop()); |
| 6219 base::RunLoop().Run(); | 6237 base::RunLoop().Run(); |
| 6220 EXPECT_EQ(1U, personal_data_->GetServerProfiles().size()); | 6238 EXPECT_EQ(1U, personal_data_->GetServerProfiles().size()); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 6238 std::vector<AutofillProfile*> profiles = | 6256 std::vector<AutofillProfile*> profiles = |
| 6239 personal_data_->GetProfilesToSuggest(); | 6257 personal_data_->GetProfilesToSuggest(); |
| 6240 ASSERT_EQ(1U, profiles.size()); | 6258 ASSERT_EQ(1U, profiles.size()); |
| 6241 EXPECT_EQ(profiles[0]->guid(), | 6259 EXPECT_EQ(profiles[0]->guid(), |
| 6242 personal_data_->GetCreditCards()[0]->billing_address_id()); | 6260 personal_data_->GetCreditCards()[0]->billing_address_id()); |
| 6243 | 6261 |
| 6244 // Add a new server card that has the same billing address as the old one. | 6262 // Add a new server card that has the same billing address as the old one. |
| 6245 server_cards.push_back( | 6263 server_cards.push_back( |
| 6246 CreditCard(CreditCard::MASKED_SERVER_CARD, "server_card2")); | 6264 CreditCard(CreditCard::MASKED_SERVER_CARD, "server_card2")); |
| 6247 test::SetCreditCardInfo(&server_cards.back(), "John Dillinger", | 6265 test::SetCreditCardInfo(&server_cards.back(), "John Dillinger", |
| 6248 "1112" /* Visa */, "01", "2888"); | 6266 "1112" /* Visa */, "01", "2888", "1"); |
| 6249 server_cards.back().SetNetworkForMaskedCard(kVisaCard); | 6267 server_cards.back().SetNetworkForMaskedCard(kVisaCard); |
| 6250 server_cards.back().set_billing_address_id(kServerAddressId); | 6268 server_cards.back().set_billing_address_id(kServerAddressId); |
| 6251 test::SetServerCreditCards(autofill_table_, server_cards); | 6269 test::SetServerCreditCards(autofill_table_, server_cards); |
| 6252 | 6270 |
| 6253 // Make sure everything is setup correctly. | 6271 // Make sure everything is setup correctly. |
| 6254 personal_data_->Refresh(); | 6272 personal_data_->Refresh(); |
| 6255 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 6273 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 6256 .WillOnce(QuitMainMessageLoop()); | 6274 .WillOnce(QuitMainMessageLoop()); |
| 6257 base::RunLoop().Run(); | 6275 base::RunLoop().Run(); |
| 6258 EXPECT_EQ(1U, personal_data_->web_profiles().size()); | 6276 EXPECT_EQ(1U, personal_data_->web_profiles().size()); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 6283 // to the converted address. | 6301 // to the converted address. |
| 6284 EXPECT_EQ(profiles[0]->guid(), | 6302 EXPECT_EQ(profiles[0]->guid(), |
| 6285 personal_data_->GetCreditCards()[0]->billing_address_id()); | 6303 personal_data_->GetCreditCards()[0]->billing_address_id()); |
| 6286 // Make sure that the billing address id of the new server card still refers | 6304 // Make sure that the billing address id of the new server card still refers |
| 6287 // to the converted address. | 6305 // to the converted address. |
| 6288 EXPECT_EQ(profiles[0]->guid(), | 6306 EXPECT_EQ(profiles[0]->guid(), |
| 6289 personal_data_->GetCreditCards()[1]->billing_address_id()); | 6307 personal_data_->GetCreditCards()[1]->billing_address_id()); |
| 6290 } | 6308 } |
| 6291 | 6309 |
| 6292 } // namespace autofill | 6310 } // namespace autofill |
| OLD | NEW |