Index: components/autofill/core/browser/personal_data_manager_unittest.cc |
diff --git a/components/autofill/core/browser/personal_data_manager_unittest.cc b/components/autofill/core/browser/personal_data_manager_unittest.cc |
index dab6be0898e0c60056921f2b8882e63f12a8bf37..b90fbb739f552f743769e0312535ce72cd7079d9 100644 |
--- a/components/autofill/core/browser/personal_data_manager_unittest.cc |
+++ b/components/autofill/core/browser/personal_data_manager_unittest.cc |
@@ -54,15 +54,15 @@ |
#include "testing/gmock/include/gmock/gmock.h" |
#include "testing/gtest/include/gtest/gtest.h" |
-using base::ASCIIToUTF16; |
-using base::UTF8ToUTF16; |
- |
namespace autofill { |
namespace { |
+using ::base::ASCIIToUTF16; |
+using ::base::UTF8ToUTF16; |
+ |
enum UserMode { USER_MODE_NORMAL, USER_MODE_INCOGNITO }; |
-const std::string kUTF8MidlineEllipsis = |
+const char kUTF8MidlineEllipsis[] = |
" " |
"\xE2\x80\xA2\xE2\x80\x86" |
"\xE2\x80\xA2\xE2\x80\x86" |
@@ -764,12 +764,12 @@ TEST_F(PersonalDataManagerTest, UpdateServerCreditCards) { |
server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "a123")); |
test::SetCreditCardInfo(&server_cards.back(), "John Dillinger", |
"9012" /* Visa */, "01", "2999"); |
- server_cards.back().SetTypeForMaskedCard(kVisaCard); |
+ server_cards.back().SetNetworkForMaskedCard(kVisaCard); |
server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "b456")); |
test::SetCreditCardInfo(&server_cards.back(), "Bonnie Parker", |
"2109" /* Mastercard */, "12", "2999"); |
- server_cards.back().SetTypeForMaskedCard(kMasterCard); |
+ server_cards.back().SetNetworkForMaskedCard(kMasterCard); |
server_cards.push_back(CreditCard(CreditCard::FULL_SERVER_CARD, "c789")); |
test::SetCreditCardInfo(&server_cards.back(), "Clyde Barrow", |
@@ -2417,7 +2417,7 @@ TEST_F(PersonalDataManagerTest, |
server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "a123")); |
test::SetCreditCardInfo(&server_cards.back(), "John Dillinger", |
"1111" /* Visa */, "01", "2999"); |
- server_cards.back().SetTypeForMaskedCard(kVisaCard); |
+ server_cards.back().SetNetworkForMaskedCard(kVisaCard); |
test::SetServerCreditCards(autofill_table_, server_cards); |
// Type the same data as the masked card into a form. |
@@ -3546,7 +3546,7 @@ TEST_F(PersonalDataManagerTest, |
server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "b459")); |
test::SetCreditCardInfo(&server_cards.back(), "Emmet Dalton", "2110", "12", |
"2999"); |
- server_cards.back().SetTypeForMaskedCard(kVisaCard); |
+ server_cards.back().SetNetworkForMaskedCard(kVisaCard); |
test::SetServerCreditCards(autofill_table_, server_cards); |
personal_data_->Refresh(); |
@@ -3600,7 +3600,7 @@ TEST_F(PersonalDataManagerTest, |
server_cards.back().set_use_count(2); |
server_cards.back().set_use_date(AutofillClock::Now() - |
base::TimeDelta::FromDays(1)); |
- server_cards.back().SetTypeForMaskedCard(kVisaCard); |
+ server_cards.back().SetNetworkForMaskedCard(kVisaCard); |
server_cards.push_back(CreditCard(CreditCard::FULL_SERVER_CARD, "b460")); |
test::SetCreditCardInfo(&server_cards.back(), "Jesse James", "2109", "12", |
@@ -3717,7 +3717,7 @@ TEST_F(PersonalDataManagerTest, GetCreditCardSuggestions_NumberMissing) { |
AutofillType(CREDIT_CARD_NUMBER), |
/* field_contents= */ base::string16()); |
ASSERT_EQ(1U, suggestions.size()); |
- EXPECT_EQ(UTF8ToUTF16("Amex" + kUTF8MidlineEllipsis + "8555"), |
+ EXPECT_EQ(UTF8ToUTF16(std::string("Amex") + kUTF8MidlineEllipsis + "8555"), |
suggestions[0].value); |
EXPECT_EQ(ASCIIToUTF16("04/99"), suggestions[0].label); |
} |
@@ -3739,7 +3739,7 @@ TEST_F(PersonalDataManagerTest, GetCreditCardSuggestions_ServerDuplicates) { |
server_cards.back().set_use_count(2); |
server_cards.back().set_use_date(AutofillClock::Now() - |
base::TimeDelta::FromDays(15)); |
- server_cards.back().SetTypeForMaskedCard(kVisaCard); |
+ server_cards.back().SetNetworkForMaskedCard(kVisaCard); |
// This server card is identical to a local card, but has a different |
// card type. Not a dupe and therefore both should appear in the suggestions. |
@@ -3749,7 +3749,7 @@ TEST_F(PersonalDataManagerTest, GetCreditCardSuggestions_ServerDuplicates) { |
server_cards.back().set_use_count(3); |
server_cards.back().set_use_date(AutofillClock::Now() - |
base::TimeDelta::FromDays(15)); |
- server_cards.back().SetTypeForMaskedCard(kVisaCard); |
+ server_cards.back().SetNetworkForMaskedCard(kVisaCard); |
// This unmasked server card is an exact dupe of a local card. Therefore only |
// this card should appear in the suggestions as full server cards have |
@@ -3780,13 +3780,14 @@ TEST_F(PersonalDataManagerTest, GetCreditCardSuggestions_ServerDuplicates) { |
suggestions = personal_data_->GetCreditCardSuggestions( |
AutofillType(CREDIT_CARD_NUMBER), /* field_contents= */ base::string16()); |
ASSERT_EQ(4U, suggestions.size()); |
- EXPECT_EQ(UTF8ToUTF16("Visa" + kUTF8MidlineEllipsis + "9012"), |
+ EXPECT_EQ(UTF8ToUTF16(std::string("Visa") + kUTF8MidlineEllipsis + "9012"), |
suggestions[0].value); |
- EXPECT_EQ(UTF8ToUTF16("Amex" + kUTF8MidlineEllipsis + "8555"), |
+ EXPECT_EQ(UTF8ToUTF16(std::string("Amex") + kUTF8MidlineEllipsis + "8555"), |
suggestions[1].value); |
- EXPECT_EQ(UTF8ToUTF16("MasterCard" + kUTF8MidlineEllipsis + "2109"), |
- suggestions[2].value); |
- EXPECT_EQ(UTF8ToUTF16("Visa" + kUTF8MidlineEllipsis + "2109"), |
+ EXPECT_EQ( |
+ UTF8ToUTF16(std::string("MasterCard") + kUTF8MidlineEllipsis + "2109"), |
+ suggestions[2].value); |
+ EXPECT_EQ(UTF8ToUTF16(std::string("Visa") + kUTF8MidlineEllipsis + "2109"), |
suggestions[3].value); |
} |
@@ -3884,7 +3885,7 @@ TEST_F(PersonalDataManagerTest, DedupeCreditCardToSuggest_LocalShadowsMasked) { |
masked_card.set_use_count(2); |
masked_card.set_use_date(AutofillClock::Now() - |
base::TimeDelta::FromDays(15)); |
- masked_card.SetTypeForMaskedCard(kVisaCard); |
+ masked_card.SetNetworkForMaskedCard(kVisaCard); |
credit_cards.push_back(&masked_card); |
PersonalDataManager::DedupeCreditCardToSuggest(&credit_cards); |
@@ -3914,7 +3915,7 @@ TEST_F(PersonalDataManagerTest, DedupeCreditCardToSuggest_FullServerAndMasked) { |
masked_card.set_use_count(2); |
masked_card.set_use_date(AutofillClock::Now() - |
base::TimeDelta::FromDays(15)); |
- masked_card.SetTypeForMaskedCard(kVisaCard); |
+ masked_card.SetNetworkForMaskedCard(kVisaCard); |
credit_cards.push_back(&masked_card); |
PersonalDataManager::DedupeCreditCardToSuggest(&credit_cards); |
@@ -3941,7 +3942,7 @@ TEST_F(PersonalDataManagerTest, DedupeCreditCardToSuggest_DifferentCards) { |
credit_card4.set_use_count(3); |
credit_card4.set_use_date(AutofillClock::Now() - |
base::TimeDelta::FromDays(15)); |
- credit_card4.SetTypeForMaskedCard(kVisaCard); |
+ credit_card4.SetNetworkForMaskedCard(kVisaCard); |
credit_cards.push_back(&credit_card4); |
// Create a full server card that is slightly different of the two other |
@@ -4028,12 +4029,12 @@ TEST_F(PersonalDataManagerTest, UpdateServerCreditCardUsageStats) { |
server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "a123")); |
test::SetCreditCardInfo(&server_cards.back(), "John Dillinger", |
"9012" /* Visa */, "01", "2999"); |
- server_cards.back().SetTypeForMaskedCard(kVisaCard); |
+ server_cards.back().SetNetworkForMaskedCard(kVisaCard); |
server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "b456")); |
test::SetCreditCardInfo(&server_cards.back(), "Bonnie Parker", |
"4444" /* Mastercard */, "12", "2999"); |
- server_cards.back().SetTypeForMaskedCard(kMasterCard); |
+ server_cards.back().SetNetworkForMaskedCard(kMasterCard); |
server_cards.push_back(CreditCard(CreditCard::FULL_SERVER_CARD, "c789")); |
test::SetCreditCardInfo(&server_cards.back(), "Clyde Barrow", |
@@ -4150,7 +4151,7 @@ TEST_F(PersonalDataManagerTest, ClearAllServerData) { |
server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "a123")); |
test::SetCreditCardInfo(&server_cards.back(), "John Dillinger", |
"9012" /* Visa */, "01", "2999"); |
- server_cards.back().SetTypeForMaskedCard(kVisaCard); |
+ server_cards.back().SetNetworkForMaskedCard(kVisaCard); |
test::SetServerCreditCards(autofill_table_, server_cards); |
personal_data_->Refresh(); |
@@ -4175,7 +4176,7 @@ TEST_F(PersonalDataManagerTest, DontDuplicateServerCard) { |
server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "a123")); |
test::SetCreditCardInfo(&server_cards.back(), "John Dillinger", |
"1881" /* Visa */, "01", "2999"); |
- server_cards.back().SetTypeForMaskedCard(kVisaCard); |
+ server_cards.back().SetNetworkForMaskedCard(kVisaCard); |
server_cards.push_back(CreditCard(CreditCard::FULL_SERVER_CARD, "c789")); |
test::SetCreditCardInfo(&server_cards.back(), "Clyde Barrow", |
@@ -4239,456 +4240,448 @@ TEST_F(PersonalDataManagerTest, DontDuplicateServerCard) { |
typedef struct { |
autofill::ServerFieldType field_type; |
std::string field_value; |
- } ProfileField; |
- |
- typedef std::vector<ProfileField> ProfileFields; |
- |
- typedef struct { |
- // Each test starts with a default pre-existing profile and applies these |
- // changes to it. |
- ProfileFields changes_to_original; |
- // Each test saves a second profile. Applies these changes to the default |
- // values before saving. |
- ProfileFields changes_to_new; |
- // For tests with profile merging, makes sure that these fields' values are |
- // the ones we expect (depending on the test). |
- ProfileFields changed_field_values; |
- } SaveImportedProfileTestCase; |
- |
- class SaveImportedProfileTest |
- : public PersonalDataManagerTestBase, |
- public testing::TestWithParam<SaveImportedProfileTestCase> { |
- public: |
- SaveImportedProfileTest() {} |
- ~SaveImportedProfileTest() override {} |
- |
- void SetUp() override { |
- OSCryptMocker::SetUpWithSingleton(); |
- prefs_ = test::PrefServiceForTesting(); |
- ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
- base::FilePath path = temp_dir_.GetPath().AppendASCII("TestWebDB"); |
- web_database_ = |
- new WebDatabaseService(path, base::ThreadTaskRunnerHandle::Get(), |
- base::ThreadTaskRunnerHandle::Get()); |
- |
- // Setup account tracker. |
- signin_client_.reset(new TestSigninClient(prefs_.get())); |
- account_tracker_.reset(new AccountTrackerService()); |
- account_tracker_->Initialize(signin_client_.get()); |
- signin_manager_.reset(new FakeSigninManagerBase(signin_client_.get(), |
- account_tracker_.get())); |
- signin_manager_->Initialize(prefs_.get()); |
- |
- // Hacky: hold onto a pointer but pass ownership. |
- autofill_table_ = new AutofillTable; |
- web_database_->AddTable( |
- std::unique_ptr<WebDatabaseTable>(autofill_table_)); |
- web_database_->LoadDatabase(); |
- autofill_database_service_ = new AutofillWebDataService( |
- web_database_, base::ThreadTaskRunnerHandle::Get(), |
- base::ThreadTaskRunnerHandle::Get(), |
- WebDataServiceBase::ProfileErrorCallback()); |
- autofill_database_service_->Init(); |
- |
- test::DisableSystemServices(prefs_.get()); |
- ResetPersonalDataManager(USER_MODE_NORMAL); |
- |
- // Reset the deduping pref to its default value. |
- personal_data_->pref_service_->SetInteger( |
- prefs::kAutofillLastVersionDeduped, 0); |
- personal_data_->pref_service_->SetBoolean( |
- prefs::kAutofillProfileUseDatesFixed, false); |
- } |
+} ProfileField; |
- void TearDown() override { |
- // Order of destruction is important as AutofillManager relies on |
- // PersonalDataManager to be around when it gets destroyed. |
- signin_manager_->Shutdown(); |
- signin_manager_.reset(); |
+typedef std::vector<ProfileField> ProfileFields; |
- account_tracker_->Shutdown(); |
- account_tracker_.reset(); |
- signin_client_.reset(); |
+typedef struct { |
+ // Each test starts with a default pre-existing profile and applies these |
+ // changes to it. |
+ ProfileFields changes_to_original; |
+ // Each test saves a second profile. Applies these changes to the default |
+ // values before saving. |
+ ProfileFields changes_to_new; |
+ // For tests with profile merging, makes sure that these fields' values are |
+ // the ones we expect (depending on the test). |
+ ProfileFields changed_field_values; |
+} SaveImportedProfileTestCase; |
+ |
+class SaveImportedProfileTest |
+ : public PersonalDataManagerTestBase, |
+ public testing::TestWithParam<SaveImportedProfileTestCase> { |
+ public: |
+ SaveImportedProfileTest() {} |
+ ~SaveImportedProfileTest() override {} |
- test::DisableSystemServices(prefs_.get()); |
- OSCryptMocker::TearDown(); |
- } |
- }; |
- |
- TEST_P(SaveImportedProfileTest, SaveImportedProfile) { |
- // Create the test clock. |
- TestAutofillClock test_clock; |
- auto test_case = GetParam(); |
- // Set the time to a specific value. |
- test_clock.SetNow(kArbitraryTime); |
- |
- SetupReferenceProfile(); |
- const std::vector<AutofillProfile*>& initial_profiles = |
- personal_data_->GetProfiles(); |
- |
- // Apply changes to the original profile (if applicable). |
- for (ProfileField change : test_case.changes_to_original) { |
- initial_profiles.front()->SetRawInfo( |
- change.field_type, base::UTF8ToUTF16(change.field_value)); |
- } |
+ void SetUp() override { |
+ OSCryptMocker::SetUpWithSingleton(); |
+ prefs_ = test::PrefServiceForTesting(); |
+ ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
+ base::FilePath path = temp_dir_.GetPath().AppendASCII("TestWebDB"); |
+ web_database_ = |
+ new WebDatabaseService(path, base::ThreadTaskRunnerHandle::Get(), |
+ base::ThreadTaskRunnerHandle::Get()); |
- // Set the time to a bigger value. |
- test_clock.SetNow(kSomeLaterTime); |
+ // Setup account tracker. |
+ signin_client_.reset(new TestSigninClient(prefs_.get())); |
+ account_tracker_.reset(new AccountTrackerService()); |
+ account_tracker_->Initialize(signin_client_.get()); |
+ signin_manager_.reset(new FakeSigninManagerBase(signin_client_.get(), |
+ account_tracker_.get())); |
+ signin_manager_->Initialize(prefs_.get()); |
- AutofillProfile profile2(base::GenerateGUID(), "https://www.example.com"); |
- test::SetProfileInfo(&profile2, "Marion", "Mitchell", "Morrison", |
- "johnwayne@me.xyz", "Fox", "123 Zoo St", "unit 5", |
- "Hollywood", "CA", "91601", "US", "12345678910"); |
+ // Hacky: hold onto a pointer but pass ownership. |
+ autofill_table_ = new AutofillTable; |
+ web_database_->AddTable(std::unique_ptr<WebDatabaseTable>(autofill_table_)); |
+ web_database_->LoadDatabase(); |
+ autofill_database_service_ = new AutofillWebDataService( |
+ web_database_, base::ThreadTaskRunnerHandle::Get(), |
+ base::ThreadTaskRunnerHandle::Get(), |
+ WebDataServiceBase::ProfileErrorCallback()); |
+ autofill_database_service_->Init(); |
- // Apply changes to the second profile (if applicable). |
- for (ProfileField change : test_case.changes_to_new) { |
- profile2.SetRawInfo(change.field_type, |
- base::UTF8ToUTF16(change.field_value)); |
- } |
+ test::DisableSystemServices(prefs_.get()); |
+ ResetPersonalDataManager(USER_MODE_NORMAL); |
- personal_data_->SaveImportedProfile(profile2); |
- |
- const std::vector<AutofillProfile*>& saved_profiles = |
- personal_data_->GetProfiles(); |
- |
- // If there are no merge changes to verify, make sure that two profiles were |
- // saved. |
- if (test_case.changed_field_values.empty()) { |
- EXPECT_EQ(2U, saved_profiles.size()); |
- } else { |
- EXPECT_EQ(1U, saved_profiles.size()); |
- |
- // Make sure the new information was merged correctly. |
- for (ProfileField changed_field : test_case.changed_field_values) { |
- EXPECT_EQ(base::UTF8ToUTF16(changed_field.field_value), |
- saved_profiles.front()->GetRawInfo(changed_field.field_type)); |
- } |
- // Verify that the merged profile's use count, use date and modification |
- // date were properly updated. |
- EXPECT_EQ(1U, saved_profiles.front()->use_count()); |
- EXPECT_EQ(kSomeLaterTime, saved_profiles.front()->use_date()); |
- EXPECT_EQ(kSomeLaterTime, saved_profiles.front()->modification_date()); |
- } |
+ // Reset the deduping pref to its default value. |
+ personal_data_->pref_service_->SetInteger( |
+ prefs::kAutofillLastVersionDeduped, 0); |
+ personal_data_->pref_service_->SetBoolean( |
+ prefs::kAutofillProfileUseDatesFixed, false); |
+ } |
- // Erase the profiles for the next test. |
- ResetProfiles(); |
+ void TearDown() override { |
+ // Order of destruction is important as AutofillManager relies on |
+ // PersonalDataManager to be around when it gets destroyed. |
+ signin_manager_->Shutdown(); |
+ signin_manager_.reset(); |
+ |
+ account_tracker_->Shutdown(); |
+ account_tracker_.reset(); |
+ signin_client_.reset(); |
+ |
+ test::DisableSystemServices(prefs_.get()); |
+ OSCryptMocker::TearDown(); |
+ } |
+}; |
+ |
+TEST_P(SaveImportedProfileTest, SaveImportedProfile) { |
+ // Create the test clock. |
+ TestAutofillClock test_clock; |
+ auto test_case = GetParam(); |
+ // Set the time to a specific value. |
+ test_clock.SetNow(kArbitraryTime); |
+ |
+ SetupReferenceProfile(); |
+ const std::vector<AutofillProfile*>& initial_profiles = |
+ personal_data_->GetProfiles(); |
+ |
+ // Apply changes to the original profile (if applicable). |
+ for (ProfileField change : test_case.changes_to_original) { |
+ initial_profiles.front()->SetRawInfo(change.field_type, |
+ base::UTF8ToUTF16(change.field_value)); |
+ } |
+ |
+ // Set the time to a bigger value. |
+ test_clock.SetNow(kSomeLaterTime); |
+ |
+ AutofillProfile profile2(base::GenerateGUID(), "https://www.example.com"); |
+ test::SetProfileInfo(&profile2, "Marion", "Mitchell", "Morrison", |
+ "johnwayne@me.xyz", "Fox", "123 Zoo St", "unit 5", |
+ "Hollywood", "CA", "91601", "US", "12345678910"); |
+ |
+ // Apply changes to the second profile (if applicable). |
+ for (ProfileField change : test_case.changes_to_new) { |
+ profile2.SetRawInfo(change.field_type, |
+ base::UTF8ToUTF16(change.field_value)); |
} |
- INSTANTIATE_TEST_CASE_P( |
- PersonalDataManagerTest, |
- SaveImportedProfileTest, |
- testing::Values( |
- // Test that saving an identical profile except for the name results |
- // in two profiles being saved. |
- SaveImportedProfileTestCase{ProfileFields(), |
- {{NAME_FIRST, "Marionette"}}}, |
- |
- // Test that saving an identical profile except with the middle name |
- // initial instead of the full middle name results in the profiles |
- // getting merged and the full middle name being kept. |
- SaveImportedProfileTestCase{ |
- ProfileFields(), |
- {{NAME_MIDDLE, "M"}}, |
- {{NAME_MIDDLE, "Mitchell"}, |
- {NAME_FULL, "Marion Mitchell Morrison"}}}, |
- |
- // Test that saving an identical profile except with the full middle |
- // name instead of the middle name initial results in the profiles |
- // getting merged and the full middle name replacing the initial. |
- SaveImportedProfileTestCase{{{NAME_MIDDLE, "M"}}, |
- {{NAME_MIDDLE, "Mitchell"}}, |
- {{NAME_MIDDLE, "Mitchell"}}}, |
- |
- // Test that saving an identical profile except with no middle name |
- // results in the profiles getting merged and the full middle name |
- // being kept. |
- SaveImportedProfileTestCase{ProfileFields(), |
- {{NAME_MIDDLE, ""}}, |
- {{NAME_MIDDLE, "Mitchell"}}}, |
- |
- // Test that saving an identical profile except with a middle name |
- // initial results in the profiles getting merged and the middle name |
- // initial being saved. |
- SaveImportedProfileTestCase{{{NAME_MIDDLE, ""}}, |
- {{NAME_MIDDLE, "M"}}, |
- {{NAME_MIDDLE, "M"}}}, |
- |
- // Test that saving an identical profile except with a middle name |
- // results in the profiles getting merged and the full middle name |
- // being saved. |
- SaveImportedProfileTestCase{{{NAME_MIDDLE, ""}}, |
- {{NAME_MIDDLE, "Mitchell"}}, |
- {{NAME_MIDDLE, "Mitchell"}}}, |
- |
- // Test that saving a identical profile except with the full name set |
- // instead of the name parts results in the two profiles being merged |
- // and all the name parts kept and the full name being added. |
- SaveImportedProfileTestCase{ |
- { |
- {NAME_FIRST, "Marion"}, |
- {NAME_MIDDLE, "Mitchell"}, |
- {NAME_LAST, "Morrison"}, |
- {NAME_FULL, ""}, |
- }, |
- { |
- {NAME_FIRST, ""}, |
- {NAME_MIDDLE, ""}, |
- {NAME_LAST, ""}, |
- {NAME_FULL, "Marion Mitchell Morrison"}, |
- }, |
- { |
- {NAME_FIRST, "Marion"}, |
- {NAME_MIDDLE, "Mitchell"}, |
- {NAME_LAST, "Morrison"}, |
- {NAME_FULL, "Marion Mitchell Morrison"}, |
- }, |
- }, |
- |
- // Test that saving a identical profile except with the name parts set |
- // instead of the full name results in the two profiles being merged |
- // and the full name being kept and all the name parts being added. |
- SaveImportedProfileTestCase{ |
- { |
- {NAME_FIRST, ""}, |
- {NAME_MIDDLE, ""}, |
- {NAME_LAST, ""}, |
- {NAME_FULL, "Marion Mitchell Morrison"}, |
- }, |
- { |
- {NAME_FIRST, "Marion"}, |
- {NAME_MIDDLE, "Mitchell"}, |
- {NAME_LAST, "Morrison"}, |
- {NAME_FULL, ""}, |
- }, |
- { |
- {NAME_FIRST, "Marion"}, |
- {NAME_MIDDLE, "Mitchell"}, |
- {NAME_LAST, "Morrison"}, |
- {NAME_FULL, "Marion Mitchell Morrison"}, |
- }, |
- }, |
- |
- // Test that saving a profile that has only a full name set does not |
- // get merged with a profile with only the name parts set if the names |
- // are different. |
- SaveImportedProfileTestCase{ |
- { |
- {NAME_FIRST, "Marion"}, |
- {NAME_MIDDLE, "Mitchell"}, |
- {NAME_LAST, "Morrison"}, |
- {NAME_FULL, ""}, |
- }, |
- { |
- {NAME_FIRST, ""}, |
- {NAME_MIDDLE, ""}, |
- {NAME_LAST, ""}, |
- {NAME_FULL, "John Thompson Smith"}, |
- }, |
- }, |
- |
- // Test that saving a profile that has only the name parts set does |
- // not get merged with a profile with only the full name set if the |
- // names are different. |
- SaveImportedProfileTestCase{ |
- { |
- {NAME_FIRST, ""}, |
- {NAME_MIDDLE, ""}, |
- {NAME_LAST, ""}, |
- {NAME_FULL, "John Thompson Smith"}, |
- }, |
- { |
- {NAME_FIRST, "Marion"}, |
- {NAME_MIDDLE, "Mitchell"}, |
- {NAME_LAST, "Morrison"}, |
- {NAME_FULL, ""}, |
- }, |
- }, |
- |
- // Test that saving an identical profile except for the first address |
- // line results in two profiles being saved. |
- SaveImportedProfileTestCase{ |
- ProfileFields(), |
- {{ADDRESS_HOME_LINE1, "123 Aquarium St."}}}, |
- |
- // Test that saving an identical profile except for the second address |
- // line results in two profiles being saved. |
- SaveImportedProfileTestCase{ProfileFields(), |
- {{ADDRESS_HOME_LINE2, "unit 7"}}}, |
- |
- // Tests that saving an identical profile that has a new piece of |
- // information (company name) results in a merge and that the original |
- // empty value gets overwritten by the new information. |
- SaveImportedProfileTestCase{{{COMPANY_NAME, ""}}, |
- ProfileFields(), |
- {{COMPANY_NAME, "Fox"}}}, |
- |
- // Tests that saving an identical profile except a loss of information |
- // results in a merge but the original value is not overwritten (no |
- // information loss). |
- SaveImportedProfileTestCase{ProfileFields(), |
- {{COMPANY_NAME, ""}}, |
- {{COMPANY_NAME, "Fox"}}}, |
- |
- // Tests that saving an identical profile except a slightly different |
- // postal code results in a merge with the new value kept. |
- SaveImportedProfileTestCase{{{ADDRESS_HOME_ZIP, "R2C 0A1"}}, |
- {{ADDRESS_HOME_ZIP, "R2C0A1"}}, |
- {{ADDRESS_HOME_ZIP, "R2C0A1"}}}, |
- SaveImportedProfileTestCase{{{ADDRESS_HOME_ZIP, "R2C0A1"}}, |
- {{ADDRESS_HOME_ZIP, "R2C 0A1"}}, |
- {{ADDRESS_HOME_ZIP, "R2C 0A1"}}}, |
- SaveImportedProfileTestCase{{{ADDRESS_HOME_ZIP, "r2c 0a1"}}, |
- {{ADDRESS_HOME_ZIP, "R2C0A1"}}, |
- {{ADDRESS_HOME_ZIP, "R2C0A1"}}}, |
- |
- // Tests that saving an identical profile plus a new piece of |
- // information on the address line 2 results in a merge and that the |
- // original empty value gets overwritten by the new information. |
- SaveImportedProfileTestCase{{{ADDRESS_HOME_LINE2, ""}}, |
- ProfileFields(), |
- {{ADDRESS_HOME_LINE2, "unit 5"}}}, |
- |
- // Tests that saving an identical profile except a loss of information |
- // on the address line 2 results in a merge but that the original |
- // value gets not overwritten (no information loss). |
- SaveImportedProfileTestCase{ProfileFields(), |
- {{ADDRESS_HOME_LINE2, ""}}, |
- {{ADDRESS_HOME_LINE2, "unit 5"}}}, |
- |
- // Tests that saving an identical except with more punctuation in the |
- // fist address line, while the second is empty, results in a merge |
- // and that the original address gets overwritten. |
- SaveImportedProfileTestCase{ |
- {{ADDRESS_HOME_LINE2, ""}}, |
- {{ADDRESS_HOME_LINE2, ""}, {ADDRESS_HOME_LINE1, "123, Zoo St."}}, |
- {{ADDRESS_HOME_LINE1, "123, Zoo St."}}}, |
- |
- // Tests that saving an identical profile except with less punctuation |
- // in the fist address line, while the second is empty, results in a |
- // merge and that the longer address is retained. |
- SaveImportedProfileTestCase{ |
- {{ADDRESS_HOME_LINE2, ""}, {ADDRESS_HOME_LINE1, "123, Zoo St."}}, |
- {{ADDRESS_HOME_LINE2, ""}}, |
- {{ADDRESS_HOME_LINE1, "123 Zoo St"}}}, |
- |
- // Tests that saving an identical profile except additional |
- // punctuation in the two address lines results in a merge and that |
- // the newer address is retained. |
- SaveImportedProfileTestCase{ProfileFields(), |
- {{ADDRESS_HOME_LINE1, "123, Zoo St."}, |
- {ADDRESS_HOME_LINE2, "unit. 5"}}, |
- {{ADDRESS_HOME_LINE1, "123, Zoo St."}, |
- {ADDRESS_HOME_LINE2, "unit. 5"}}}, |
- |
- // Tests that saving an identical profile except less punctuation in |
- // the two address lines results in a merge and that the newer address |
- // is retained. |
- SaveImportedProfileTestCase{{{ADDRESS_HOME_LINE1, "123, Zoo St."}, |
- {ADDRESS_HOME_LINE2, "unit. 5"}}, |
- ProfileFields(), |
- {{ADDRESS_HOME_LINE1, "123 Zoo St"}, |
- {ADDRESS_HOME_LINE2, "unit 5"}}}, |
- |
- // Tests that saving an identical profile with accented characters in |
- // the two address lines results in a merge and that the newer address |
- // is retained. |
- SaveImportedProfileTestCase{ProfileFields(), |
- {{ADDRESS_HOME_LINE1, "123 Zôö St"}, |
- {ADDRESS_HOME_LINE2, "üñìt 5"}}, |
- {{ADDRESS_HOME_LINE1, "123 Zôö St"}, |
- {ADDRESS_HOME_LINE2, "üñìt 5"}}}, |
- |
- // Tests that saving an identical profile without accented characters |
- // in the two address lines results in a merge and that the newer |
- // address is retained. |
- SaveImportedProfileTestCase{{{ADDRESS_HOME_LINE1, "123 Zôö St"}, |
- {ADDRESS_HOME_LINE2, "üñìt 5"}}, |
- ProfileFields(), |
- {{ADDRESS_HOME_LINE1, "123 Zoo St"}, |
- {ADDRESS_HOME_LINE2, "unit 5"}}}, |
- |
- // Tests that saving an identical profile except that the address line |
- // 1 is in the address line 2 results in a merge and that the |
- // multi-lne address is retained. |
- SaveImportedProfileTestCase{ |
- ProfileFields(), |
- {{ADDRESS_HOME_LINE1, "123 Zoo St, unit 5"}, |
- {ADDRESS_HOME_LINE2, ""}}, |
- {{ADDRESS_HOME_LINE1, "123 Zoo St"}, |
- {ADDRESS_HOME_LINE2, "unit 5"}}}, |
- |
- // Tests that saving an identical profile except that the address line |
- // 2 contains part of the old address line 1 results in a merge and |
- // that the original address lines of the reference profile get |
- // overwritten. |
- SaveImportedProfileTestCase{ |
- {{ADDRESS_HOME_LINE1, "123 Zoo St, unit 5"}, |
- {ADDRESS_HOME_LINE2, ""}}, |
- ProfileFields(), |
- {{ADDRESS_HOME_LINE1, "123 Zoo St"}, |
- {ADDRESS_HOME_LINE2, "unit 5"}}}, |
- |
- // Tests that saving an identical profile except that the state is the |
- // abbreviation instead of the full form results in a merge and that |
- // the original state gets overwritten. |
- SaveImportedProfileTestCase{{{ADDRESS_HOME_STATE, "California"}}, |
- ProfileFields(), |
- {{ADDRESS_HOME_STATE, "CA"}}}, |
- |
- // Tests that saving an identical profile except that the state is the |
- // full form instead of the abbreviation results in a merge and that |
- // the abbreviated state is retained. |
- SaveImportedProfileTestCase{ProfileFields(), |
- {{ADDRESS_HOME_STATE, "California"}}, |
- {{ADDRESS_HOME_STATE, "CA"}}}, |
- |
- // Tests that saving and identical profile except that the company |
- // name has different punctuation and case results in a merge and that |
- // the syntax of the new profile replaces the old one. |
- SaveImportedProfileTestCase{{{COMPANY_NAME, "Stark inc"}}, |
- {{COMPANY_NAME, "Stark Inc."}}, |
- {{COMPANY_NAME, "Stark Inc."}}})); |
- |
- // Tests that MergeProfile tries to merge the imported profile into the |
- // existing profile in decreasing order of frecency. |
- TEST_F(PersonalDataManagerTest, MergeProfile_Frecency) { |
- // Create two very similar profiles except with different company names. |
- std::unique_ptr<AutofillProfile> profile1 = |
- base::MakeUnique<AutofillProfile>(base::GenerateGUID(), |
- "https://www.example.com"); |
- test::SetProfileInfo(profile1.get(), "Homer", "Jay", "Simpson", |
- "homer.simpson@abc.com", "SNP", |
- "742 Evergreen Terrace", "", "Springfield", "IL", |
- "91601", "US", "12345678910"); |
- AutofillProfile* profile2 = |
- new AutofillProfile(base::GenerateGUID(), "https://www.example.com"); |
- test::SetProfileInfo(profile2, "Homer", "Jay", "Simpson", |
- "homer.simpson@abc.com", "Fox", |
- "742 Evergreen Terrace", "", "Springfield", "IL", |
- "91601", "US", "12345678910"); |
- |
- // Give the "Fox" profile a bigger frecency score. |
- profile2->set_use_count(15); |
- |
- // Create the |existing_profiles| vector. |
- std::vector<std::unique_ptr<AutofillProfile>> existing_profiles; |
- existing_profiles.push_back(std::move(profile1)); |
- existing_profiles.push_back(base::WrapUnique(profile2)); |
- |
- // Create a new imported profile with no company name. |
- AutofillProfile imported_profile(base::GenerateGUID(), |
- "https://www.example.com"); |
- test::SetProfileInfo(&imported_profile, "Homer", "Jay", "Simpson", |
- "homer.simpson@abc.com", "", "742 Evergreen Terrace", |
- "", "Springfield", "IL", "91601", "US", "12345678910"); |
- |
- // Merge the imported profile into the existing profiles. |
- std::vector<AutofillProfile> profiles; |
- std::string guid = personal_data_->MergeProfile( |
- imported_profile, &existing_profiles, "US-EN", &profiles); |
- |
- // The new profile should be merged into the "fox" profile. |
- EXPECT_EQ(profile2->guid(), guid); |
+ personal_data_->SaveImportedProfile(profile2); |
+ |
+ const std::vector<AutofillProfile*>& saved_profiles = |
+ personal_data_->GetProfiles(); |
+ |
+ // If there are no merge changes to verify, make sure that two profiles were |
+ // saved. |
+ if (test_case.changed_field_values.empty()) { |
+ EXPECT_EQ(2U, saved_profiles.size()); |
+ } else { |
+ EXPECT_EQ(1U, saved_profiles.size()); |
+ |
+ // Make sure the new information was merged correctly. |
+ for (ProfileField changed_field : test_case.changed_field_values) { |
+ EXPECT_EQ(base::UTF8ToUTF16(changed_field.field_value), |
+ saved_profiles.front()->GetRawInfo(changed_field.field_type)); |
+ } |
+ // Verify that the merged profile's use count, use date and modification |
+ // date were properly updated. |
+ EXPECT_EQ(1U, saved_profiles.front()->use_count()); |
+ EXPECT_EQ(kSomeLaterTime, saved_profiles.front()->use_date()); |
+ EXPECT_EQ(kSomeLaterTime, saved_profiles.front()->modification_date()); |
+ } |
+ |
+ // Erase the profiles for the next test. |
+ ResetProfiles(); |
+} |
+ |
+INSTANTIATE_TEST_CASE_P( |
+ PersonalDataManagerTest, |
+ SaveImportedProfileTest, |
+ testing::Values( |
+ // Test that saving an identical profile except for the name results |
+ // in two profiles being saved. |
+ SaveImportedProfileTestCase{ProfileFields(), |
+ {{NAME_FIRST, "Marionette"}}}, |
+ |
+ // Test that saving an identical profile except with the middle name |
+ // initial instead of the full middle name results in the profiles |
+ // getting merged and the full middle name being kept. |
+ SaveImportedProfileTestCase{ProfileFields(), |
+ {{NAME_MIDDLE, "M"}}, |
+ {{NAME_MIDDLE, "Mitchell"}, |
+ {NAME_FULL, "Marion Mitchell Morrison"}}}, |
+ |
+ // Test that saving an identical profile except with the full middle |
+ // name instead of the middle name initial results in the profiles |
+ // getting merged and the full middle name replacing the initial. |
+ SaveImportedProfileTestCase{{{NAME_MIDDLE, "M"}}, |
+ {{NAME_MIDDLE, "Mitchell"}}, |
+ {{NAME_MIDDLE, "Mitchell"}}}, |
+ |
+ // Test that saving an identical profile except with no middle name |
+ // results in the profiles getting merged and the full middle name |
+ // being kept. |
+ SaveImportedProfileTestCase{ProfileFields(), |
+ {{NAME_MIDDLE, ""}}, |
+ {{NAME_MIDDLE, "Mitchell"}}}, |
+ |
+ // Test that saving an identical profile except with a middle name |
+ // initial results in the profiles getting merged and the middle name |
+ // initial being saved. |
+ SaveImportedProfileTestCase{{{NAME_MIDDLE, ""}}, |
+ {{NAME_MIDDLE, "M"}}, |
+ {{NAME_MIDDLE, "M"}}}, |
+ |
+ // Test that saving an identical profile except with a middle name |
+ // results in the profiles getting merged and the full middle name |
+ // being saved. |
+ SaveImportedProfileTestCase{{{NAME_MIDDLE, ""}}, |
+ {{NAME_MIDDLE, "Mitchell"}}, |
+ {{NAME_MIDDLE, "Mitchell"}}}, |
+ |
+ // Test that saving a identical profile except with the full name set |
+ // instead of the name parts results in the two profiles being merged |
+ // and all the name parts kept and the full name being added. |
+ SaveImportedProfileTestCase{ |
+ { |
+ {NAME_FIRST, "Marion"}, |
+ {NAME_MIDDLE, "Mitchell"}, |
+ {NAME_LAST, "Morrison"}, |
+ {NAME_FULL, ""}, |
+ }, |
+ { |
+ {NAME_FIRST, ""}, |
+ {NAME_MIDDLE, ""}, |
+ {NAME_LAST, ""}, |
+ {NAME_FULL, "Marion Mitchell Morrison"}, |
+ }, |
+ { |
+ {NAME_FIRST, "Marion"}, |
+ {NAME_MIDDLE, "Mitchell"}, |
+ {NAME_LAST, "Morrison"}, |
+ {NAME_FULL, "Marion Mitchell Morrison"}, |
+ }, |
+ }, |
+ |
+ // Test that saving a identical profile except with the name parts set |
+ // instead of the full name results in the two profiles being merged |
+ // and the full name being kept and all the name parts being added. |
+ SaveImportedProfileTestCase{ |
+ { |
+ {NAME_FIRST, ""}, |
+ {NAME_MIDDLE, ""}, |
+ {NAME_LAST, ""}, |
+ {NAME_FULL, "Marion Mitchell Morrison"}, |
+ }, |
+ { |
+ {NAME_FIRST, "Marion"}, |
+ {NAME_MIDDLE, "Mitchell"}, |
+ {NAME_LAST, "Morrison"}, |
+ {NAME_FULL, ""}, |
+ }, |
+ { |
+ {NAME_FIRST, "Marion"}, |
+ {NAME_MIDDLE, "Mitchell"}, |
+ {NAME_LAST, "Morrison"}, |
+ {NAME_FULL, "Marion Mitchell Morrison"}, |
+ }, |
+ }, |
+ |
+ // Test that saving a profile that has only a full name set does not |
+ // get merged with a profile with only the name parts set if the names |
+ // are different. |
+ SaveImportedProfileTestCase{ |
+ { |
+ {NAME_FIRST, "Marion"}, |
+ {NAME_MIDDLE, "Mitchell"}, |
+ {NAME_LAST, "Morrison"}, |
+ {NAME_FULL, ""}, |
+ }, |
+ { |
+ {NAME_FIRST, ""}, |
+ {NAME_MIDDLE, ""}, |
+ {NAME_LAST, ""}, |
+ {NAME_FULL, "John Thompson Smith"}, |
+ }, |
+ }, |
+ |
+ // Test that saving a profile that has only the name parts set does |
+ // not get merged with a profile with only the full name set if the |
+ // names are different. |
+ SaveImportedProfileTestCase{ |
+ { |
+ {NAME_FIRST, ""}, |
+ {NAME_MIDDLE, ""}, |
+ {NAME_LAST, ""}, |
+ {NAME_FULL, "John Thompson Smith"}, |
+ }, |
+ { |
+ {NAME_FIRST, "Marion"}, |
+ {NAME_MIDDLE, "Mitchell"}, |
+ {NAME_LAST, "Morrison"}, |
+ {NAME_FULL, ""}, |
+ }, |
+ }, |
+ |
+ // Test that saving an identical profile except for the first address |
+ // line results in two profiles being saved. |
+ SaveImportedProfileTestCase{ProfileFields(), |
+ {{ADDRESS_HOME_LINE1, "123 Aquarium St."}}}, |
+ |
+ // Test that saving an identical profile except for the second address |
+ // line results in two profiles being saved. |
+ SaveImportedProfileTestCase{ProfileFields(), |
+ {{ADDRESS_HOME_LINE2, "unit 7"}}}, |
+ |
+ // Tests that saving an identical profile that has a new piece of |
+ // information (company name) results in a merge and that the original |
+ // empty value gets overwritten by the new information. |
+ SaveImportedProfileTestCase{{{COMPANY_NAME, ""}}, |
+ ProfileFields(), |
+ {{COMPANY_NAME, "Fox"}}}, |
+ |
+ // Tests that saving an identical profile except a loss of information |
+ // results in a merge but the original value is not overwritten (no |
+ // information loss). |
+ SaveImportedProfileTestCase{ProfileFields(), |
+ {{COMPANY_NAME, ""}}, |
+ {{COMPANY_NAME, "Fox"}}}, |
+ |
+ // Tests that saving an identical profile except a slightly different |
+ // postal code results in a merge with the new value kept. |
+ SaveImportedProfileTestCase{{{ADDRESS_HOME_ZIP, "R2C 0A1"}}, |
+ {{ADDRESS_HOME_ZIP, "R2C0A1"}}, |
+ {{ADDRESS_HOME_ZIP, "R2C0A1"}}}, |
+ SaveImportedProfileTestCase{{{ADDRESS_HOME_ZIP, "R2C0A1"}}, |
+ {{ADDRESS_HOME_ZIP, "R2C 0A1"}}, |
+ {{ADDRESS_HOME_ZIP, "R2C 0A1"}}}, |
+ SaveImportedProfileTestCase{{{ADDRESS_HOME_ZIP, "r2c 0a1"}}, |
+ {{ADDRESS_HOME_ZIP, "R2C0A1"}}, |
+ {{ADDRESS_HOME_ZIP, "R2C0A1"}}}, |
+ |
+ // Tests that saving an identical profile plus a new piece of |
+ // information on the address line 2 results in a merge and that the |
+ // original empty value gets overwritten by the new information. |
+ SaveImportedProfileTestCase{{{ADDRESS_HOME_LINE2, ""}}, |
+ ProfileFields(), |
+ {{ADDRESS_HOME_LINE2, "unit 5"}}}, |
+ |
+ // Tests that saving an identical profile except a loss of information |
+ // on the address line 2 results in a merge but that the original |
+ // value gets not overwritten (no information loss). |
+ SaveImportedProfileTestCase{ProfileFields(), |
+ {{ADDRESS_HOME_LINE2, ""}}, |
+ {{ADDRESS_HOME_LINE2, "unit 5"}}}, |
+ |
+ // Tests that saving an identical except with more punctuation in the |
+ // fist address line, while the second is empty, results in a merge |
+ // and that the original address gets overwritten. |
+ SaveImportedProfileTestCase{ |
+ {{ADDRESS_HOME_LINE2, ""}}, |
+ {{ADDRESS_HOME_LINE2, ""}, {ADDRESS_HOME_LINE1, "123, Zoo St."}}, |
+ {{ADDRESS_HOME_LINE1, "123, Zoo St."}}}, |
+ |
+ // Tests that saving an identical profile except with less punctuation |
+ // in the fist address line, while the second is empty, results in a |
+ // merge and that the longer address is retained. |
+ SaveImportedProfileTestCase{ |
+ {{ADDRESS_HOME_LINE2, ""}, {ADDRESS_HOME_LINE1, "123, Zoo St."}}, |
+ {{ADDRESS_HOME_LINE2, ""}}, |
+ {{ADDRESS_HOME_LINE1, "123 Zoo St"}}}, |
+ |
+ // Tests that saving an identical profile except additional |
+ // punctuation in the two address lines results in a merge and that |
+ // the newer address is retained. |
+ SaveImportedProfileTestCase{ProfileFields(), |
+ {{ADDRESS_HOME_LINE1, "123, Zoo St."}, |
+ {ADDRESS_HOME_LINE2, "unit. 5"}}, |
+ {{ADDRESS_HOME_LINE1, "123, Zoo St."}, |
+ {ADDRESS_HOME_LINE2, "unit. 5"}}}, |
+ |
+ // Tests that saving an identical profile except less punctuation in |
+ // the two address lines results in a merge and that the newer address |
+ // is retained. |
+ SaveImportedProfileTestCase{{{ADDRESS_HOME_LINE1, "123, Zoo St."}, |
+ {ADDRESS_HOME_LINE2, "unit. 5"}}, |
+ ProfileFields(), |
+ {{ADDRESS_HOME_LINE1, "123 Zoo St"}, |
+ {ADDRESS_HOME_LINE2, "unit 5"}}}, |
+ |
+ // Tests that saving an identical profile with accented characters in |
+ // the two address lines results in a merge and that the newer address |
+ // is retained. |
+ SaveImportedProfileTestCase{ProfileFields(), |
+ {{ADDRESS_HOME_LINE1, "123 Zôö St"}, |
+ {ADDRESS_HOME_LINE2, "üñìt 5"}}, |
+ {{ADDRESS_HOME_LINE1, "123 Zôö St"}, |
+ {ADDRESS_HOME_LINE2, "üñìt 5"}}}, |
+ |
+ // Tests that saving an identical profile without accented characters |
+ // in the two address lines results in a merge and that the newer |
+ // address is retained. |
+ SaveImportedProfileTestCase{{{ADDRESS_HOME_LINE1, "123 Zôö St"}, |
+ {ADDRESS_HOME_LINE2, "üñìt 5"}}, |
+ ProfileFields(), |
+ {{ADDRESS_HOME_LINE1, "123 Zoo St"}, |
+ {ADDRESS_HOME_LINE2, "unit 5"}}}, |
+ |
+ // Tests that saving an identical profile except that the address line |
+ // 1 is in the address line 2 results in a merge and that the |
+ // multi-lne address is retained. |
+ SaveImportedProfileTestCase{ProfileFields(), |
+ {{ADDRESS_HOME_LINE1, "123 Zoo St, unit 5"}, |
+ {ADDRESS_HOME_LINE2, ""}}, |
+ {{ADDRESS_HOME_LINE1, "123 Zoo St"}, |
+ {ADDRESS_HOME_LINE2, "unit 5"}}}, |
+ |
+ // Tests that saving an identical profile except that the address line |
+ // 2 contains part of the old address line 1 results in a merge and |
+ // that the original address lines of the reference profile get |
+ // overwritten. |
+ SaveImportedProfileTestCase{{{ADDRESS_HOME_LINE1, "123 Zoo St, unit 5"}, |
+ {ADDRESS_HOME_LINE2, ""}}, |
+ ProfileFields(), |
+ {{ADDRESS_HOME_LINE1, "123 Zoo St"}, |
+ {ADDRESS_HOME_LINE2, "unit 5"}}}, |
+ |
+ // Tests that saving an identical profile except that the state is the |
+ // abbreviation instead of the full form results in a merge and that |
+ // the original state gets overwritten. |
+ SaveImportedProfileTestCase{{{ADDRESS_HOME_STATE, "California"}}, |
+ ProfileFields(), |
+ {{ADDRESS_HOME_STATE, "CA"}}}, |
+ |
+ // Tests that saving an identical profile except that the state is the |
+ // full form instead of the abbreviation results in a merge and that |
+ // the abbreviated state is retained. |
+ SaveImportedProfileTestCase{ProfileFields(), |
+ {{ADDRESS_HOME_STATE, "California"}}, |
+ {{ADDRESS_HOME_STATE, "CA"}}}, |
+ |
+ // Tests that saving and identical profile except that the company |
+ // name has different punctuation and case results in a merge and that |
+ // the syntax of the new profile replaces the old one. |
+ SaveImportedProfileTestCase{{{COMPANY_NAME, "Stark inc"}}, |
+ {{COMPANY_NAME, "Stark Inc."}}, |
+ {{COMPANY_NAME, "Stark Inc."}}})); |
+ |
+// Tests that MergeProfile tries to merge the imported profile into the |
+// existing profile in decreasing order of frecency. |
+TEST_F(PersonalDataManagerTest, MergeProfile_Frecency) { |
+ // Create two very similar profiles except with different company names. |
+ std::unique_ptr<AutofillProfile> profile1 = base::MakeUnique<AutofillProfile>( |
+ base::GenerateGUID(), "https://www.example.com"); |
+ test::SetProfileInfo(profile1.get(), "Homer", "Jay", "Simpson", |
+ "homer.simpson@abc.com", "SNP", "742 Evergreen Terrace", |
+ "", "Springfield", "IL", "91601", "US", "12345678910"); |
+ AutofillProfile* profile2 = |
+ new AutofillProfile(base::GenerateGUID(), "https://www.example.com"); |
+ test::SetProfileInfo(profile2, "Homer", "Jay", "Simpson", |
+ "homer.simpson@abc.com", "Fox", "742 Evergreen Terrace", |
+ "", "Springfield", "IL", "91601", "US", "12345678910"); |
+ |
+ // Give the "Fox" profile a bigger frecency score. |
+ profile2->set_use_count(15); |
+ |
+ // Create the |existing_profiles| vector. |
+ std::vector<std::unique_ptr<AutofillProfile>> existing_profiles; |
+ existing_profiles.push_back(std::move(profile1)); |
+ existing_profiles.push_back(base::WrapUnique(profile2)); |
+ |
+ // Create a new imported profile with no company name. |
+ AutofillProfile imported_profile(base::GenerateGUID(), |
+ "https://www.example.com"); |
+ test::SetProfileInfo(&imported_profile, "Homer", "Jay", "Simpson", |
+ "homer.simpson@abc.com", "", "742 Evergreen Terrace", "", |
+ "Springfield", "IL", "91601", "US", "12345678910"); |
+ |
+ // Merge the imported profile into the existing profiles. |
+ std::vector<AutofillProfile> profiles; |
+ std::string guid = personal_data_->MergeProfile( |
+ imported_profile, &existing_profiles, "US-EN", &profiles); |
+ |
+ // The new profile should be merged into the "fox" profile. |
+ EXPECT_EQ(profile2->guid(), guid); |
} |
// Tests that MergeProfile produces a merged profile with the expected usage |
@@ -5713,7 +5706,6 @@ TEST_F(PersonalDataManagerTest, ApplyDedupingRoutine_NopIfOneProfile) { |
EXPECT_FALSE(personal_data_->ApplyDedupingRoutine()); |
} |
- |
// Tests that ApplyDedupingRoutine is not run a second time on the same major |
// version. |
TEST_F(PersonalDataManagerTest, ApplyDedupingRoutine_OncePerVersion) { |
@@ -5826,7 +5818,7 @@ TEST_F(PersonalDataManagerTest, |
CreditCard(CreditCard::MASKED_SERVER_CARD, "server_card1")); |
test::SetCreditCardInfo(&server_cards.back(), "John Dillinger", |
"1111" /* Visa */, "01", "2999"); |
- server_cards.back().SetTypeForMaskedCard(kVisaCard); |
+ server_cards.back().SetNetworkForMaskedCard(kVisaCard); |
server_cards.back().set_billing_address_id(kServerAddressId); |
test::SetServerCreditCards(autofill_table_, server_cards); |
@@ -5933,7 +5925,7 @@ TEST_F(PersonalDataManagerTest, |
CreditCard(CreditCard::MASKED_SERVER_CARD, "server_card1")); |
test::SetCreditCardInfo(&server_cards.back(), "John Dillinger", |
"1111" /* Visa */, "01", "2999"); |
- server_cards.back().SetTypeForMaskedCard(kVisaCard); |
+ server_cards.back().SetNetworkForMaskedCard(kVisaCard); |
server_cards.back().set_billing_address_id(kServerAddressId); |
test::SetServerCreditCards(autofill_table_, server_cards); |
@@ -6105,7 +6097,7 @@ TEST_F( |
CreditCard(CreditCard::MASKED_SERVER_CARD, "server_card1")); |
test::SetCreditCardInfo(&server_cards.back(), "John Dillinger", |
"1111" /* Visa */, "01", "2999"); |
- server_cards.back().SetTypeForMaskedCard(kVisaCard); |
+ server_cards.back().SetNetworkForMaskedCard(kVisaCard); |
server_cards.back().set_billing_address_id(kServerAddressId2); |
test::SetServerCreditCards(autofill_table_, server_cards); |
@@ -6171,7 +6163,7 @@ TEST_F( |
// address was already converted in the past. |
TEST_F( |
PersonalDataManagerTest, |
- ConvertWalletAddressesAndUpdateWalletCards_NewCard_AddressAlreadyConverted) { |
+ ConvertWalletAddressesAndUpdateWalletCards_NewCrd_AddressAlreadyConverted) { |
/////////////////////////////////////////////////////////////////////// |
// Setup. |
/////////////////////////////////////////////////////////////////////// |
@@ -6200,7 +6192,7 @@ TEST_F( |
CreditCard(CreditCard::MASKED_SERVER_CARD, "server_card1")); |
test::SetCreditCardInfo(&server_cards.back(), "John Dillinger", |
"1111" /* Visa */, "01", "2999"); |
- server_cards.back().SetTypeForMaskedCard(kVisaCard); |
+ server_cards.back().SetNetworkForMaskedCard(kVisaCard); |
server_cards.back().set_billing_address_id(kServerAddressId); |
test::SetServerCreditCards(autofill_table_, server_cards); |
@@ -6238,7 +6230,7 @@ TEST_F( |
CreditCard(CreditCard::MASKED_SERVER_CARD, "server_card2")); |
test::SetCreditCardInfo(&server_cards.back(), "John Dillinger", |
"1112" /* Visa */, "01", "2888"); |
- server_cards.back().SetTypeForMaskedCard(kVisaCard); |
+ server_cards.back().SetNetworkForMaskedCard(kVisaCard); |
server_cards.back().set_billing_address_id(kServerAddressId); |
test::SetServerCreditCards(autofill_table_, server_cards); |