| 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 5602 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5613 EXPECT_FALSE(personal_data_->ApplyDedupingRoutine()); | 5613 EXPECT_FALSE(personal_data_->ApplyDedupingRoutine()); |
| 5614 | 5614 |
| 5615 // The two duplicate profiles should still be present. | 5615 // The two duplicate profiles should still be present. |
| 5616 EXPECT_EQ(2U, personal_data_->GetProfiles().size()); | 5616 EXPECT_EQ(2U, personal_data_->GetProfiles().size()); |
| 5617 } | 5617 } |
| 5618 | 5618 |
| 5619 // Tests that a new local profile is created if no existing one is a duplicate | 5619 // Tests that a new local profile is created if no existing one is a duplicate |
| 5620 // of the server address. Also tests that the billing address relationship was | 5620 // of the server address. Also tests that the billing address relationship was |
| 5621 // transferred to the converted address. | 5621 // transferred to the converted address. |
| 5622 TEST_F(PersonalDataManagerTest, | 5622 TEST_F(PersonalDataManagerTest, |
| 5623 ConvertWalletAddressesToLocalProfiles_NewProfile) { | 5623 ConvertWalletAddressesAndUpdateWalletCards_NewProfile) { |
| 5624 /////////////////////////////////////////////////////////////////////// | 5624 /////////////////////////////////////////////////////////////////////// |
| 5625 // Setup. | 5625 // Setup. |
| 5626 /////////////////////////////////////////////////////////////////////// | 5626 /////////////////////////////////////////////////////////////////////// |
| 5627 EnableWalletCardImport(); | 5627 EnableWalletCardImport(); |
| 5628 base::HistogramTester histogram_tester; | 5628 base::HistogramTester histogram_tester; |
| 5629 const std::string kServerAddressId("server_address1"); | 5629 const std::string kServerAddressId("server_address1"); |
| 5630 | 5630 |
| 5631 // Add two different profiles, a local and a server one. Set the use stats so | 5631 // Add two different profiles, a local and a server one. Set the use stats so |
| 5632 // the server profile has a higher frecency, to have a predictable ordering to | 5632 // the server profile has a higher frecency, to have a predictable ordering to |
| 5633 // validate results. | 5633 // validate results. |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5675 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 5675 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 5676 .WillOnce(QuitMainMessageLoop()); | 5676 .WillOnce(QuitMainMessageLoop()); |
| 5677 base::RunLoop().Run(); | 5677 base::RunLoop().Run(); |
| 5678 EXPECT_EQ(1U, personal_data_->web_profiles().size()); | 5678 EXPECT_EQ(1U, personal_data_->web_profiles().size()); |
| 5679 EXPECT_EQ(1U, personal_data_->GetServerProfiles().size()); | 5679 EXPECT_EQ(1U, personal_data_->GetServerProfiles().size()); |
| 5680 EXPECT_EQ(2U, personal_data_->GetCreditCards().size()); | 5680 EXPECT_EQ(2U, personal_data_->GetCreditCards().size()); |
| 5681 | 5681 |
| 5682 /////////////////////////////////////////////////////////////////////// | 5682 /////////////////////////////////////////////////////////////////////// |
| 5683 // Tested method. | 5683 // Tested method. |
| 5684 /////////////////////////////////////////////////////////////////////// | 5684 /////////////////////////////////////////////////////////////////////// |
| 5685 personal_data_->ConvertWalletAddressesToLocalProfiles(); | 5685 personal_data_->ConvertWalletAddressesAndUpdateWalletCards(); |
| 5686 | 5686 |
| 5687 /////////////////////////////////////////////////////////////////////// | 5687 /////////////////////////////////////////////////////////////////////// |
| 5688 // Validation. | 5688 // Validation. |
| 5689 /////////////////////////////////////////////////////////////////////// | 5689 /////////////////////////////////////////////////////////////////////// |
| 5690 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 5690 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 5691 .WillOnce(QuitMainMessageLoop()); | 5691 .WillOnce(QuitMainMessageLoop()); |
| 5692 base::RunLoop().Run(); | 5692 base::RunLoop().Run(); |
| 5693 | 5693 |
| 5694 // The Wallet address should have been added as a new local profile. | 5694 // The Wallet address should have been added as a new local profile. |
| 5695 EXPECT_EQ(2U, personal_data_->web_profiles().size()); | 5695 EXPECT_EQ(2U, personal_data_->web_profiles().size()); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 5720 // Make sure that the added address has the email address of the currently | 5720 // Make sure that the added address has the email address of the currently |
| 5721 // signed-in user. | 5721 // signed-in user. |
| 5722 EXPECT_EQ(UTF8ToUTF16("syncuser@example.com"), | 5722 EXPECT_EQ(UTF8ToUTF16("syncuser@example.com"), |
| 5723 profiles[0]->GetRawInfo(EMAIL_ADDRESS)); | 5723 profiles[0]->GetRawInfo(EMAIL_ADDRESS)); |
| 5724 } | 5724 } |
| 5725 | 5725 |
| 5726 // Tests that the converted wallet address is merged into an existing local | 5726 // Tests that the converted wallet address is merged into an existing local |
| 5727 // profile if they are considered equivalent. Also tests that the billing | 5727 // profile if they are considered equivalent. Also tests that the billing |
| 5728 // address relationship was transferred to the converted address. | 5728 // address relationship was transferred to the converted address. |
| 5729 TEST_F(PersonalDataManagerTest, | 5729 TEST_F(PersonalDataManagerTest, |
| 5730 ConvertWalletAddressesToLocalProfiles_MergedProfile) { | 5730 ConvertWalletAddressesAndUpdateWalletCards_MergedProfile) { |
| 5731 /////////////////////////////////////////////////////////////////////// | 5731 /////////////////////////////////////////////////////////////////////// |
| 5732 // Setup. | 5732 // Setup. |
| 5733 /////////////////////////////////////////////////////////////////////// | 5733 /////////////////////////////////////////////////////////////////////// |
| 5734 EnableWalletCardImport(); | 5734 EnableWalletCardImport(); |
| 5735 base::HistogramTester histogram_tester; | 5735 base::HistogramTester histogram_tester; |
| 5736 const std::string kServerAddressId("server_address1"); | 5736 const std::string kServerAddressId("server_address1"); |
| 5737 | 5737 |
| 5738 // Add two similar profile, a local and a server one. Set the use stats so | 5738 // Add two similar profile, a local and a server one. Set the use stats so |
| 5739 // the server card has a higher frecency, to have a predicatble ordering to | 5739 // the server card has a higher frecency, to have a predicatble ordering to |
| 5740 // validate results. | 5740 // validate results. |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5782 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 5782 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 5783 .WillOnce(QuitMainMessageLoop()); | 5783 .WillOnce(QuitMainMessageLoop()); |
| 5784 base::RunLoop().Run(); | 5784 base::RunLoop().Run(); |
| 5785 EXPECT_EQ(1U, personal_data_->web_profiles().size()); | 5785 EXPECT_EQ(1U, personal_data_->web_profiles().size()); |
| 5786 EXPECT_EQ(1U, personal_data_->GetServerProfiles().size()); | 5786 EXPECT_EQ(1U, personal_data_->GetServerProfiles().size()); |
| 5787 EXPECT_EQ(2U, personal_data_->GetCreditCards().size()); | 5787 EXPECT_EQ(2U, personal_data_->GetCreditCards().size()); |
| 5788 | 5788 |
| 5789 /////////////////////////////////////////////////////////////////////// | 5789 /////////////////////////////////////////////////////////////////////// |
| 5790 // Tested method. | 5790 // Tested method. |
| 5791 /////////////////////////////////////////////////////////////////////// | 5791 /////////////////////////////////////////////////////////////////////// |
| 5792 personal_data_->ConvertWalletAddressesToLocalProfiles(); | 5792 personal_data_->ConvertWalletAddressesAndUpdateWalletCards(); |
| 5793 | 5793 |
| 5794 /////////////////////////////////////////////////////////////////////// | 5794 /////////////////////////////////////////////////////////////////////// |
| 5795 // Validation. | 5795 // Validation. |
| 5796 /////////////////////////////////////////////////////////////////////// | 5796 /////////////////////////////////////////////////////////////////////// |
| 5797 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 5797 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 5798 .WillOnce(QuitMainMessageLoop()); | 5798 .WillOnce(QuitMainMessageLoop()); |
| 5799 base::RunLoop().Run(); | 5799 base::RunLoop().Run(); |
| 5800 | 5800 |
| 5801 // The Wallet address should have been merged with the existing local profile. | 5801 // The Wallet address should have been merged with the existing local profile. |
| 5802 EXPECT_EQ(1U, personal_data_->web_profiles().size()); | 5802 EXPECT_EQ(1U, personal_data_->web_profiles().size()); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 5825 // converted profile. | 5825 // converted profile. |
| 5826 EXPECT_EQ(profiles[0]->guid(), | 5826 EXPECT_EQ(profiles[0]->guid(), |
| 5827 personal_data_->GetCreditCards()[0]->billing_address_id()); | 5827 personal_data_->GetCreditCards()[0]->billing_address_id()); |
| 5828 EXPECT_EQ(profiles[0]->guid(), | 5828 EXPECT_EQ(profiles[0]->guid(), |
| 5829 personal_data_->GetCreditCards()[1]->billing_address_id()); | 5829 personal_data_->GetCreditCards()[1]->billing_address_id()); |
| 5830 } | 5830 } |
| 5831 | 5831 |
| 5832 // Tests that a Wallet address that has already converted does not get converted | 5832 // Tests that a Wallet address that has already converted does not get converted |
| 5833 // a second time. | 5833 // a second time. |
| 5834 TEST_F(PersonalDataManagerTest, | 5834 TEST_F(PersonalDataManagerTest, |
| 5835 ConvertWalletAddressesToLocalProfiles_AlreadyConverted) { | 5835 ConvertWalletAddressesAndUpdateWalletCards_AlreadyConverted) { |
| 5836 /////////////////////////////////////////////////////////////////////// | 5836 /////////////////////////////////////////////////////////////////////// |
| 5837 // Setup. | 5837 // Setup. |
| 5838 /////////////////////////////////////////////////////////////////////// | 5838 /////////////////////////////////////////////////////////////////////// |
| 5839 EnableWalletCardImport(); | 5839 EnableWalletCardImport(); |
| 5840 base::HistogramTester histogram_tester; | 5840 base::HistogramTester histogram_tester; |
| 5841 const std::string kServerAddressId("server_address1"); | 5841 const std::string kServerAddressId("server_address1"); |
| 5842 | 5842 |
| 5843 // Add a server profile that has already been converted. | 5843 // Add a server profile that has already been converted. |
| 5844 std::vector<AutofillProfile> GetServerProfiles; | 5844 std::vector<AutofillProfile> GetServerProfiles; |
| 5845 GetServerProfiles.push_back( | 5845 GetServerProfiles.push_back( |
| (...skipping 10 matching lines...) Expand all Loading... |
| 5856 personal_data_->Refresh(); | 5856 personal_data_->Refresh(); |
| 5857 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 5857 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 5858 .WillOnce(QuitMainMessageLoop()); | 5858 .WillOnce(QuitMainMessageLoop()); |
| 5859 base::RunLoop().Run(); | 5859 base::RunLoop().Run(); |
| 5860 EXPECT_EQ(0U, personal_data_->web_profiles().size()); | 5860 EXPECT_EQ(0U, personal_data_->web_profiles().size()); |
| 5861 EXPECT_EQ(1U, personal_data_->GetServerProfiles().size()); | 5861 EXPECT_EQ(1U, personal_data_->GetServerProfiles().size()); |
| 5862 | 5862 |
| 5863 /////////////////////////////////////////////////////////////////////// | 5863 /////////////////////////////////////////////////////////////////////// |
| 5864 // Tested method. | 5864 // Tested method. |
| 5865 /////////////////////////////////////////////////////////////////////// | 5865 /////////////////////////////////////////////////////////////////////// |
| 5866 personal_data_->ConvertWalletAddressesToLocalProfiles(); | 5866 personal_data_->ConvertWalletAddressesAndUpdateWalletCards(); |
| 5867 | 5867 |
| 5868 /////////////////////////////////////////////////////////////////////// | 5868 /////////////////////////////////////////////////////////////////////// |
| 5869 // Validation. | 5869 // Validation. |
| 5870 /////////////////////////////////////////////////////////////////////// | 5870 /////////////////////////////////////////////////////////////////////// |
| 5871 // Since there should be no change in data, OnPersonalDataChanged should not | 5871 // Since there should be no change in data, OnPersonalDataChanged should not |
| 5872 // have been called. | 5872 // have been called. |
| 5873 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()).Times(0); | 5873 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()).Times(0); |
| 5874 | 5874 |
| 5875 personal_data_->Refresh(); | 5875 personal_data_->Refresh(); |
| 5876 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 5876 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 5877 .WillOnce(QuitMainMessageLoop()); | 5877 .WillOnce(QuitMainMessageLoop()); |
| 5878 base::RunLoop().Run(); | 5878 base::RunLoop().Run(); |
| 5879 | 5879 |
| 5880 // There should be no local profiles added. | 5880 // There should be no local profiles added. |
| 5881 EXPECT_EQ(0U, personal_data_->web_profiles().size()); | 5881 EXPECT_EQ(0U, personal_data_->web_profiles().size()); |
| 5882 EXPECT_EQ(1U, personal_data_->GetServerProfiles().size()); | 5882 EXPECT_EQ(1U, personal_data_->GetServerProfiles().size()); |
| 5883 } | 5883 } |
| 5884 | 5884 |
| 5885 // Tests that when the user has multiple similar Wallet addresses, they get | 5885 // Tests that when the user has multiple similar Wallet addresses, they get |
| 5886 // merged into a single local profile, and that the billing address relationship | 5886 // merged into a single local profile, and that the billing address relationship |
| 5887 // is merged too. | 5887 // is merged too. |
| 5888 TEST_F(PersonalDataManagerTest, | 5888 TEST_F( |
| 5889 ConvertWalletAddressesToLocalProfiles_MultipleSimilarWalletAddresses) { | 5889 PersonalDataManagerTest, |
| 5890 ConvertWalletAddressesAndUpdateWalletCards_MultipleSimilarWalletAddresses) { |
| 5890 /////////////////////////////////////////////////////////////////////// | 5891 /////////////////////////////////////////////////////////////////////// |
| 5891 // Setup. | 5892 // Setup. |
| 5892 /////////////////////////////////////////////////////////////////////// | 5893 /////////////////////////////////////////////////////////////////////// |
| 5893 EnableWalletCardImport(); | 5894 EnableWalletCardImport(); |
| 5894 base::HistogramTester histogram_tester; | 5895 base::HistogramTester histogram_tester; |
| 5895 const std::string kServerAddressId("server_address1"); | 5896 const std::string kServerAddressId("server_address1"); |
| 5896 const std::string kServerAddressId2("server_address2"); | 5897 const std::string kServerAddressId2("server_address2"); |
| 5897 | 5898 |
| 5898 // Add a unique local profile and two similar server profiles. Set the use | 5899 // Add a unique local profile and two similar server profiles. Set the use |
| 5899 // stats to have a predicatble ordering to validate results. | 5900 // stats to have a predicatble ordering to validate results. |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5953 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 5954 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 5954 .WillOnce(QuitMainMessageLoop()); | 5955 .WillOnce(QuitMainMessageLoop()); |
| 5955 base::RunLoop().Run(); | 5956 base::RunLoop().Run(); |
| 5956 EXPECT_EQ(1U, personal_data_->web_profiles().size()); | 5957 EXPECT_EQ(1U, personal_data_->web_profiles().size()); |
| 5957 EXPECT_EQ(2U, personal_data_->GetServerProfiles().size()); | 5958 EXPECT_EQ(2U, personal_data_->GetServerProfiles().size()); |
| 5958 EXPECT_EQ(2U, personal_data_->GetCreditCards().size()); | 5959 EXPECT_EQ(2U, personal_data_->GetCreditCards().size()); |
| 5959 | 5960 |
| 5960 /////////////////////////////////////////////////////////////////////// | 5961 /////////////////////////////////////////////////////////////////////// |
| 5961 // Tested method. | 5962 // Tested method. |
| 5962 /////////////////////////////////////////////////////////////////////// | 5963 /////////////////////////////////////////////////////////////////////// |
| 5963 personal_data_->ConvertWalletAddressesToLocalProfiles(); | 5964 personal_data_->ConvertWalletAddressesAndUpdateWalletCards(); |
| 5964 | 5965 |
| 5965 /////////////////////////////////////////////////////////////////////// | 5966 /////////////////////////////////////////////////////////////////////// |
| 5966 // Validation. | 5967 // Validation. |
| 5967 /////////////////////////////////////////////////////////////////////// | 5968 /////////////////////////////////////////////////////////////////////// |
| 5968 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 5969 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 5969 .WillOnce(QuitMainMessageLoop()); | 5970 .WillOnce(QuitMainMessageLoop()); |
| 5970 base::RunLoop().Run(); | 5971 base::RunLoop().Run(); |
| 5971 | 5972 |
| 5972 // The first Wallet address should have been added as a new local profile and | 5973 // The first Wallet address should have been added as a new local profile and |
| 5973 // the second one should have merged with the first. | 5974 // the second one should have merged with the first. |
| (...skipping 25 matching lines...) Expand all Loading... |
| 5999 EXPECT_EQ(UTF8ToUTF16("32801"), profiles[0]->GetRawInfo(ADDRESS_HOME_ZIP)); | 6000 EXPECT_EQ(UTF8ToUTF16("32801"), profiles[0]->GetRawInfo(ADDRESS_HOME_ZIP)); |
| 6000 | 6001 |
| 6001 // Make sure that the billing address id of the two cards now point to the | 6002 // Make sure that the billing address id of the two cards now point to the |
| 6002 // converted profile. | 6003 // converted profile. |
| 6003 EXPECT_EQ(profiles[0]->guid(), | 6004 EXPECT_EQ(profiles[0]->guid(), |
| 6004 personal_data_->GetCreditCards()[0]->billing_address_id()); | 6005 personal_data_->GetCreditCards()[0]->billing_address_id()); |
| 6005 EXPECT_EQ(profiles[0]->guid(), | 6006 EXPECT_EQ(profiles[0]->guid(), |
| 6006 personal_data_->GetCreditCards()[1]->billing_address_id()); | 6007 personal_data_->GetCreditCards()[1]->billing_address_id()); |
| 6007 } | 6008 } |
| 6008 | 6009 |
| 6010 // Tests a new server card's billing address is updated propely even if the |
| 6011 // address was already converted in the past. |
| 6012 TEST_F( |
| 6013 PersonalDataManagerTest, |
| 6014 ConvertWalletAddressesAndUpdateWalletCards_NewCard_AddressAlreadyConverted)
{ |
| 6015 /////////////////////////////////////////////////////////////////////// |
| 6016 // Setup. |
| 6017 /////////////////////////////////////////////////////////////////////// |
| 6018 // Go through the conversion process for a server address and card. Then add |
| 6019 // a new server card that refers to the already converted server address as |
| 6020 // its billing address. |
| 6021 EnableWalletCardImport(); |
| 6022 base::HistogramTester histogram_tester; |
| 6023 const std::string kServerAddressId("server_address1"); |
| 6024 |
| 6025 // Add a server profile. |
| 6026 std::vector<AutofillProfile> GetServerProfiles; |
| 6027 GetServerProfiles.push_back( |
| 6028 AutofillProfile(AutofillProfile::SERVER_PROFILE, kServerAddressId)); |
| 6029 test::SetProfileInfo(&GetServerProfiles.back(), "John", "", "Doe", "", "Fox", |
| 6030 "1212 Center", "Bld. 5", "Orlando", "FL", "", "US", ""); |
| 6031 // Wallet only provides a full name, so the above first and last names |
| 6032 // will be ignored when the profile is written to the DB. |
| 6033 GetServerProfiles.back().SetRawInfo(NAME_FULL, ASCIIToUTF16("John Doe")); |
| 6034 GetServerProfiles.back().set_use_count(100); |
| 6035 autofill_table_->SetServerProfiles(GetServerProfiles); |
| 6036 |
| 6037 // Add a server card that have the server address as billing address. |
| 6038 std::vector<CreditCard> server_cards; |
| 6039 server_cards.push_back( |
| 6040 CreditCard(CreditCard::MASKED_SERVER_CARD, "server_card1")); |
| 6041 test::SetCreditCardInfo(&server_cards.back(), "John Dillinger", |
| 6042 "1111" /* Visa */, "01", "2999"); |
| 6043 server_cards.back().SetTypeForMaskedCard(kVisaCard); |
| 6044 server_cards.back().set_billing_address_id(kServerAddressId); |
| 6045 test::SetServerCreditCards(autofill_table_, server_cards); |
| 6046 |
| 6047 // Make sure everything is setup correctly. |
| 6048 personal_data_->Refresh(); |
| 6049 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 6050 .WillOnce(QuitMainMessageLoop()); |
| 6051 base::RunLoop().Run(); |
| 6052 EXPECT_EQ(1U, personal_data_->GetServerProfiles().size()); |
| 6053 EXPECT_EQ(1U, personal_data_->GetCreditCards().size()); |
| 6054 |
| 6055 // Run the conversion. |
| 6056 personal_data_->ConvertWalletAddressesAndUpdateWalletCards(); |
| 6057 |
| 6058 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 6059 .WillOnce(QuitMainMessageLoop()); |
| 6060 base::RunLoop().Run(); |
| 6061 |
| 6062 // The Wallet address should have been converted to a new local profile. |
| 6063 EXPECT_EQ(1U, personal_data_->web_profiles().size()); |
| 6064 |
| 6065 // The conversion should be recorded in the Wallet address. |
| 6066 EXPECT_TRUE(personal_data_->GetServerProfiles().back()->has_converted()); |
| 6067 |
| 6068 // Make sure that the billing address id of the card now point to the |
| 6069 // converted profile. |
| 6070 std::vector<AutofillProfile*> profiles = |
| 6071 personal_data_->GetProfilesToSuggest(); |
| 6072 ASSERT_EQ(1U, profiles.size()); |
| 6073 EXPECT_EQ(profiles[0]->guid(), |
| 6074 personal_data_->GetCreditCards()[0]->billing_address_id()); |
| 6075 |
| 6076 // Add a new server card that has the same billing address as the old one. |
| 6077 server_cards.push_back( |
| 6078 CreditCard(CreditCard::MASKED_SERVER_CARD, "server_card2")); |
| 6079 test::SetCreditCardInfo(&server_cards.back(), "John Dillinger", |
| 6080 "1112" /* Visa */, "01", "2888"); |
| 6081 server_cards.back().SetTypeForMaskedCard(kVisaCard); |
| 6082 server_cards.back().set_billing_address_id(kServerAddressId); |
| 6083 test::SetServerCreditCards(autofill_table_, server_cards); |
| 6084 |
| 6085 // Make sure everything is setup correctly. |
| 6086 personal_data_->Refresh(); |
| 6087 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 6088 .WillOnce(QuitMainMessageLoop()); |
| 6089 base::RunLoop().Run(); |
| 6090 EXPECT_EQ(1U, personal_data_->web_profiles().size()); |
| 6091 EXPECT_EQ(2U, personal_data_->GetCreditCards().size()); |
| 6092 |
| 6093 /////////////////////////////////////////////////////////////////////// |
| 6094 // Tested method. |
| 6095 /////////////////////////////////////////////////////////////////////// |
| 6096 personal_data_->ConvertWalletAddressesAndUpdateWalletCards(); |
| 6097 |
| 6098 /////////////////////////////////////////////////////////////////////// |
| 6099 // Validation. |
| 6100 /////////////////////////////////////////////////////////////////////// |
| 6101 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 6102 .WillOnce(QuitMainMessageLoop()); |
| 6103 base::RunLoop().Run(); |
| 6104 |
| 6105 // The conversion should still be recorded in the Wallet address. |
| 6106 EXPECT_TRUE(personal_data_->GetServerProfiles().back()->has_converted()); |
| 6107 |
| 6108 // Get the profiles, sorted by frecency to have a deterministic order. |
| 6109 profiles = personal_data_->GetProfilesToSuggest(); |
| 6110 |
| 6111 // Make sure that there is still only one profile. |
| 6112 ASSERT_EQ(1U, profiles.size()); |
| 6113 |
| 6114 // Make sure that the billing address id of the first server card still refers |
| 6115 // to the converted address. |
| 6116 EXPECT_EQ(profiles[0]->guid(), |
| 6117 personal_data_->GetCreditCards()[0]->billing_address_id()); |
| 6118 // Make sure that the billing address id of the new server card still refers |
| 6119 // to the converted address. |
| 6120 EXPECT_EQ(profiles[0]->guid(), |
| 6121 personal_data_->GetCreditCards()[1]->billing_address_id()); |
| 6122 } |
| 6123 |
| 6009 } // namespace autofill | 6124 } // namespace autofill |
| OLD | NEW |