| 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 479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 490 // Reset the PersonalDataManager. This tests that the personal data was saved | 490 // Reset the PersonalDataManager. This tests that the personal data was saved |
| 491 // to the web database, and that we can load the profiles from the web | 491 // to the web database, and that we can load the profiles from the web |
| 492 // database. | 492 // database. |
| 493 ResetPersonalDataManager(USER_MODE_NORMAL); | 493 ResetPersonalDataManager(USER_MODE_NORMAL); |
| 494 | 494 |
| 495 // Verify that we've loaded the profiles from the web database. | 495 // Verify that we've loaded the profiles from the web database. |
| 496 ExpectSameElements(profiles, personal_data_->GetProfiles()); | 496 ExpectSameElements(profiles, personal_data_->GetProfiles()); |
| 497 } | 497 } |
| 498 | 498 |
| 499 TEST_F(PersonalDataManagerTest, AddUpdateRemoveCreditCards) { | 499 TEST_F(PersonalDataManagerTest, AddUpdateRemoveCreditCards) { |
| 500 EnableWalletCardImport(); |
| 500 CreditCard credit_card0(base::GenerateGUID(), "https://www.example.com"); | 501 CreditCard credit_card0(base::GenerateGUID(), "https://www.example.com"); |
| 501 test::SetCreditCardInfo(&credit_card0, | 502 test::SetCreditCardInfo(&credit_card0, |
| 502 "John Dillinger", "423456789012" /* Visa */, "01", "2999"); | 503 "John Dillinger", "423456789012" /* Visa */, "01", "2999"); |
| 503 | 504 |
| 504 CreditCard credit_card1(base::GenerateGUID(), "https://www.example.com"); | 505 CreditCard credit_card1(base::GenerateGUID(), "https://www.example.com"); |
| 505 test::SetCreditCardInfo(&credit_card1, "Bonnie Parker", | 506 test::SetCreditCardInfo(&credit_card1, "Bonnie Parker", |
| 506 "518765432109" /* Mastercard */, "12", "2999"); | 507 "518765432109" /* Mastercard */, "12", "2999"); |
| 507 | 508 |
| 508 CreditCard credit_card2(base::GenerateGUID(), "https://www.example.com"); | 509 CreditCard credit_card2(base::GenerateGUID(), "https://www.example.com"); |
| 509 test::SetCreditCardInfo(&credit_card2, "Clyde Barrow", | 510 test::SetCreditCardInfo(&credit_card2, "Clyde Barrow", |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 542 // Reset the PersonalDataManager. This tests that the personal data was saved | 543 // Reset the PersonalDataManager. This tests that the personal data was saved |
| 543 // to the web database, and that we can load the credit cards from the web | 544 // to the web database, and that we can load the credit cards from the web |
| 544 // database. | 545 // database. |
| 545 ResetPersonalDataManager(USER_MODE_NORMAL); | 546 ResetPersonalDataManager(USER_MODE_NORMAL); |
| 546 | 547 |
| 547 // Verify that we've loaded the credit cards from the web database. | 548 // Verify that we've loaded the credit cards from the web database. |
| 548 cards.clear(); | 549 cards.clear(); |
| 549 cards.push_back(&credit_card0); | 550 cards.push_back(&credit_card0); |
| 550 cards.push_back(&credit_card2); | 551 cards.push_back(&credit_card2); |
| 551 ExpectSameElements(cards, personal_data_->GetCreditCards()); | 552 ExpectSameElements(cards, personal_data_->GetCreditCards()); |
| 553 |
| 554 // Add a full server card. |
| 555 CreditCard credit_card3(base::GenerateGUID(), "https://www.example.com"); |
| 556 test::SetCreditCardInfo(&credit_card3, "Jane Doe", |
| 557 "4111111111111111" /* Visa */, "04", "2999"); |
| 558 credit_card3.set_record_type(CreditCard::FULL_SERVER_CARD); |
| 559 credit_card3.set_server_id("server_id"); |
| 560 |
| 561 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 562 .WillOnce(QuitMainMessageLoop()); |
| 563 |
| 564 personal_data_->AddServerCreditCard(credit_card3); |
| 565 base::RunLoop().Run(); |
| 566 |
| 567 cards.push_back(&credit_card3); |
| 568 ExpectSameElements(cards, personal_data_->GetCreditCards()); |
| 569 |
| 570 // Must not add a duplicate server card with same GUID. |
| 571 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()).Times(0); |
| 572 |
| 573 personal_data_->AddServerCreditCard(credit_card3); |
| 574 |
| 575 ExpectSameElements(cards, personal_data_->GetCreditCards()); |
| 576 |
| 577 // Must not add a duplicate card with same contents as another server card. |
| 578 CreditCard duplicate_server_card(credit_card3); |
| 579 duplicate_server_card.set_guid(base::GenerateGUID()); |
| 580 |
| 581 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()).Times(0); |
| 582 |
| 583 personal_data_->AddServerCreditCard(duplicate_server_card); |
| 584 |
| 585 ExpectSameElements(cards, personal_data_->GetCreditCards()); |
| 552 } | 586 } |
| 553 | 587 |
| 554 // Test that a new credit card has its basic information set. | 588 // Test that a new credit card has its basic information set. |
| 555 TEST_F(PersonalDataManagerTest, AddCreditCard_BasicInformation) { | 589 TEST_F(PersonalDataManagerTest, AddCreditCard_BasicInformation) { |
| 556 // Create the test clock and set the time to a specific value. | 590 // Create the test clock and set the time to a specific value. |
| 557 TestAutofillClock test_clock; | 591 TestAutofillClock test_clock; |
| 558 test_clock.SetNow(kArbitraryTime); | 592 test_clock.SetNow(kArbitraryTime); |
| 559 | 593 |
| 560 // Add a credit to the database. | 594 // Add a credit card to the database. |
| 561 CreditCard credit_card(base::GenerateGUID(), "https://www.example.com"); | 595 CreditCard credit_card(base::GenerateGUID(), "https://www.example.com"); |
| 562 test::SetCreditCardInfo(&credit_card, "John Dillinger", | 596 test::SetCreditCardInfo(&credit_card, "John Dillinger", |
| 563 "423456789012" /* Visa */, "01", "2999"); | 597 "423456789012" /* Visa */, "01", "2999"); |
| 564 personal_data_->AddCreditCard(credit_card); | 598 personal_data_->AddCreditCard(credit_card); |
| 565 | 599 |
| 566 // Reload the database. | 600 // Reload the database. |
| 567 ResetPersonalDataManager(USER_MODE_NORMAL); | 601 ResetPersonalDataManager(USER_MODE_NORMAL); |
| 568 | 602 |
| 569 // Verify the addition. | 603 // Verify the addition. |
| 570 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); | 604 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 676 | 710 |
| 677 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 711 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 678 .WillOnce(QuitMainMessageLoop()); | 712 .WillOnce(QuitMainMessageLoop()); |
| 679 base::RunLoop().Run(); | 713 base::RunLoop().Run(); |
| 680 | 714 |
| 681 ASSERT_EQ(1U, personal_data_->GetCreditCards().size()); | 715 ASSERT_EQ(1U, personal_data_->GetCreditCards().size()); |
| 682 EXPECT_EQ(CreditCard::MASKED_SERVER_CARD, | 716 EXPECT_EQ(CreditCard::MASKED_SERVER_CARD, |
| 683 personal_data_->GetCreditCards()[0]->record_type()); | 717 personal_data_->GetCreditCards()[0]->record_type()); |
| 684 } | 718 } |
| 685 | 719 |
| 720 // Makes sure that full cards are only added as masked card when full PAN |
| 721 // storage is disabled. |
| 722 TEST_F(PersonalDataManagerTest, AddFullCardAsMaskedCard) { |
| 723 // On Linux this should be disabled automatically. Elsewhere, only if the |
| 724 // flag is passed. |
| 725 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) |
| 726 EXPECT_FALSE(base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 727 switches::kDisableOfferStoreUnmaskedWalletCards)); |
| 728 #else |
| 729 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 730 switches::kDisableOfferStoreUnmaskedWalletCards); |
| 731 #endif |
| 732 |
| 733 CreditCard server_card(CreditCard::FULL_SERVER_CARD, "c789"); |
| 734 test::SetCreditCardInfo(&server_card, "Clyde Barrow", |
| 735 "347666888555" /* American Express */, "04", "2999"); |
| 736 |
| 737 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 738 .WillOnce(QuitMainMessageLoop()); |
| 739 |
| 740 personal_data_->AddServerCreditCard(server_card); |
| 741 |
| 742 base::RunLoop().Run(); |
| 743 |
| 744 ASSERT_EQ(1U, personal_data_->GetCreditCards().size()); |
| 745 EXPECT_EQ(CreditCard::MASKED_SERVER_CARD, |
| 746 personal_data_->GetCreditCards()[0]->record_type()); |
| 747 } |
| 748 |
| 686 TEST_F(PersonalDataManagerTest, OfferStoreUnmaskedCards) { | 749 TEST_F(PersonalDataManagerTest, OfferStoreUnmaskedCards) { |
| 687 #if defined(OS_CHROMEOS) || defined(OS_WIN) || defined(OS_MACOSX) || \ | 750 #if defined(OS_CHROMEOS) || defined(OS_WIN) || defined(OS_MACOSX) || \ |
| 688 defined(OS_IOS) || defined(OS_ANDROID) | 751 defined(OS_IOS) || defined(OS_ANDROID) |
| 689 bool should_offer = true; | 752 bool should_offer = true; |
| 690 #elif defined(OS_LINUX) | 753 #elif defined(OS_LINUX) |
| 691 bool should_offer = false; | 754 bool should_offer = false; |
| 692 #endif | 755 #endif |
| 693 EXPECT_EQ(should_offer, OfferStoreUnmaskedCards()); | 756 EXPECT_EQ(should_offer, OfferStoreUnmaskedCards()); |
| 694 } | 757 } |
| 695 | 758 |
| (...skipping 5516 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6212 // to the converted address. | 6275 // to the converted address. |
| 6213 EXPECT_EQ(profiles[0]->guid(), | 6276 EXPECT_EQ(profiles[0]->guid(), |
| 6214 personal_data_->GetCreditCards()[0]->billing_address_id()); | 6277 personal_data_->GetCreditCards()[0]->billing_address_id()); |
| 6215 // Make sure that the billing address id of the new server card still refers | 6278 // Make sure that the billing address id of the new server card still refers |
| 6216 // to the converted address. | 6279 // to the converted address. |
| 6217 EXPECT_EQ(profiles[0]->guid(), | 6280 EXPECT_EQ(profiles[0]->guid(), |
| 6218 personal_data_->GetCreditCards()[1]->billing_address_id()); | 6281 personal_data_->GetCreditCards()[1]->billing_address_id()); |
| 6219 } | 6282 } |
| 6220 | 6283 |
| 6221 } // namespace autofill | 6284 } // namespace autofill |
| OLD | NEW |