Chromium Code Reviews| Index: components/browser_sync/browser/profile_sync_service_autofill_unittest.cc |
| diff --git a/components/browser_sync/browser/profile_sync_service_autofill_unittest.cc b/components/browser_sync/browser/profile_sync_service_autofill_unittest.cc |
| index 7539925b8bba4201847b15fd60250b75364ff074..b01fcb2d12431b5b531193497327b71e660d4e7c 100644 |
| --- a/components/browser_sync/browser/profile_sync_service_autofill_unittest.cc |
| +++ b/components/browser_sync/browser/profile_sync_service_autofill_unittest.cc |
| @@ -26,6 +26,7 @@ |
| #include "base/time/time.h" |
| #include "components/autofill/core/browser/autofill_test_utils.h" |
| #include "components/autofill/core/browser/country_names.h" |
| +#include "components/autofill/core/browser/field_types.h" |
| #include "components/autofill/core/browser/personal_data_manager.h" |
| #include "components/autofill/core/browser/webdata/autocomplete_syncable_service.h" |
| #include "components/autofill/core/browser/webdata/autofill_change.h" |
| @@ -68,6 +69,7 @@ using autofill::AutofillProfileSyncableService; |
| using autofill::AutofillTable; |
| using autofill::AutofillWebDataService; |
| using autofill::PersonalDataManager; |
| +using autofill::ServerFieldType; |
| using base::Time; |
| using base::TimeDelta; |
| using base::WaitableEvent; |
| @@ -978,20 +980,26 @@ TEST_F(ProfileSyncServiceAutofillTest, HasNativeHasSyncMergeProfile) { |
| EXPECT_EQ(0, sync_profile.Compare(new_sync_profiles[0])); |
| } |
| -TEST_F(ProfileSyncServiceAutofillTest, HasNativeHasSyncMergeProfileCombine) { |
| +// Tests that adding a new profile that matches an existing sync profile gets |
| +// deleted and that the sync profile gets merged down as a local profile. |
|
Nicolas Zea
2016/04/22 20:15:22
I find it tough to follow this comment. Are you sa
sebsg
2016/04/25 15:35:40
Is it more clear now?
|
| +TEST_F( |
| + ProfileSyncServiceAutofillTest, |
| + HasNativeHasSyncMergeSimilarProfileCombine_SyncHasMoreInfoAndMoreRecent) { |
| + // Create two almost identical profiles. The GUIDs are different and the |
| + // native profile has no value for company name. |
| AutofillProfile sync_profile; |
| - autofill::test::SetProfileInfoWithGuid(&sync_profile, |
| - "23355099-1170-4B71-8ED4-144470CC9EBE", "Billing", |
| - "Mitchell", "Morrison", |
| - "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", "Hollywood", "CA", |
| - "91601", "US", "12345678910"); |
| + autofill::test::SetProfileInfoWithGuid( |
| + &sync_profile, "23355099-1170-4B71-8ED4-144470CC9EBE", "Billing", |
| + "Mitchell", "Morrison", "johnwayne@me.xyz", "Fox", "123 Zoo St.", |
| + "unit 5", "Hollywood", "CA", "91601", "US", "12345678910"); |
| + sync_profile.set_use_date(base::Time::FromTimeT(4321)); |
| AutofillProfile* native_profile = new AutofillProfile; |
| - // Same address, but different names, phones and e-mails. |
| - autofill::test::SetProfileInfoWithGuid(native_profile, |
| - "23355099-1170-4B71-8ED4-144470CC9EBF", "Billing", "Alicia", "Saenz", |
| - "joewayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", "Hollywood", "CA", |
| - "91601", "US", "19482937549"); |
| + autofill::test::SetProfileInfoWithGuid( |
| + native_profile, "23355099-1170-4B71-8ED4-144470CC9EBF", "Billing", |
| + "Mitchell", "Morrison", "johnwayne@me.xyz", "", "123 Zoo St.", "unit 5", |
| + "Hollywood", "CA", "91601", "US", "12345678910"); |
| + native_profile->set_use_date(base::Time::FromTimeT(1234)); |
| AutofillProfile expected_profile(sync_profile); |
| expected_profile.OverwriteWith(*native_profile, "en-US"); |
| @@ -1011,17 +1019,187 @@ TEST_F(ProfileSyncServiceAutofillTest, HasNativeHasSyncMergeProfileCombine) { |
| AddAutofillHelper<AutofillProfile> add_autofill(this, sync_profiles); |
| EXPECT_CALL(personal_data_manager(), Refresh()); |
| + // Adds all entries in |sync_profiles| to sync. |
| StartSyncService(add_autofill.callback(), false, AUTOFILL_PROFILE); |
| ASSERT_TRUE(add_autofill.success()); |
| std::vector<AutofillProfile> new_sync_profiles; |
| - ASSERT_TRUE(GetAutofillProfilesFromSyncDBUnderProfileNode( |
| - &new_sync_profiles)); |
| + ASSERT_TRUE( |
| + GetAutofillProfilesFromSyncDBUnderProfileNode(&new_sync_profiles)); |
| + ASSERT_EQ(1U, new_sync_profiles.size()); |
| + // Check that key fields are the same. |
| + EXPECT_TRUE(new_sync_profiles[0].IsSubsetOf(sync_profile, "en-US")); |
| + // Make sure the new information was merged down. |
|
Nicolas Zea
2016/04/22 20:15:22
Same as above. "merged down" -> "merged into the n
sebsg
2016/04/25 15:35:40
Done.
|
| + EXPECT_EQ(base::ASCIIToUTF16("Fox"), |
| + new_sync_profiles[0].GetRawInfo(ServerFieldType::COMPANY_NAME)); |
| + // Check that the latest use date is saved. |
| + EXPECT_EQ(base::Time::FromTimeT(4321), new_sync_profiles[0].use_date()); |
| + // Check that the use counts were added (default value is 1). |
| + EXPECT_EQ(2U, new_sync_profiles[0].use_count()); |
| +} |
| + |
| +// Tests that adding a new profile that matches an existing sync profile gets |
| +// deleted and that the sync profile gets merged down as a local profile even |
| +// if the local profile is more recent. |
| +TEST_F(ProfileSyncServiceAutofillTest, |
| + HasNativeHasSyncMergeSimilarProfileCombine_SyncHasMoreInfoAndOlder) { |
| + // Create two almost identical profiles. The GUIDs are different and the |
| + // native profile has no value for company name. |
| + AutofillProfile sync_profile; |
| + autofill::test::SetProfileInfoWithGuid( |
| + &sync_profile, "23355099-1170-4B71-8ED4-144470CC9EBE", "Billing", |
| + "Mitchell", "Morrison", "johnwayne@me.xyz", "Fox", "123 Zoo St.", |
| + "unit 5", "Hollywood", "CA", "91601", "US", "12345678910"); |
| + sync_profile.set_use_date(base::Time::FromTimeT(1234)); |
| + |
| + AutofillProfile* native_profile = new AutofillProfile; |
| + autofill::test::SetProfileInfoWithGuid( |
| + native_profile, "23355099-1170-4B71-8ED4-144470CC9EBF", "Billing", |
| + "Mitchell", "Morrison", "johnwayne@me.xyz", "", "123 Zoo St.", "unit 5", |
| + "Hollywood", "CA", "91601", "US", "12345678910"); |
| + native_profile->set_use_date(base::Time::FromTimeT(4321)); |
| + |
| + AutofillProfile expected_profile(sync_profile); |
| + expected_profile.OverwriteWith(*native_profile, "en-US"); |
| + |
| + std::vector<AutofillProfile*> native_profiles; |
| + native_profiles.push_back(native_profile); |
| + EXPECT_CALL(autofill_table(), GetAutofillProfiles(_)) |
| + .WillOnce(DoAll(SetArgumentPointee<0>(native_profiles), Return(true))); |
| + EXPECT_CALL(autofill_table(), |
| + AddAutofillProfile(MatchProfiles(expected_profile))) |
| + .WillOnce(Return(true)); |
| + EXPECT_CALL(autofill_table(), |
| + RemoveAutofillProfile("23355099-1170-4B71-8ED4-144470CC9EBF")) |
| + .WillOnce(Return(true)); |
| + std::vector<AutofillProfile> sync_profiles; |
| + sync_profiles.push_back(sync_profile); |
| + AddAutofillHelper<AutofillProfile> add_autofill(this, sync_profiles); |
| + |
| + EXPECT_CALL(personal_data_manager(), Refresh()); |
| + // Adds all entries in |sync_profiles| to sync. |
| + StartSyncService(add_autofill.callback(), false, AUTOFILL_PROFILE); |
| + ASSERT_TRUE(add_autofill.success()); |
| + |
| + std::vector<AutofillProfile> new_sync_profiles; |
| + ASSERT_TRUE( |
| + GetAutofillProfilesFromSyncDBUnderProfileNode(&new_sync_profiles)); |
| ASSERT_EQ(1U, new_sync_profiles.size()); |
| // Check that key fields are the same. |
| EXPECT_TRUE(new_sync_profiles[0].IsSubsetOf(sync_profile, "en-US")); |
| + // Make sure the new information was merged down. |
| + EXPECT_EQ(base::ASCIIToUTF16("Fox"), |
| + new_sync_profiles[0].GetRawInfo(ServerFieldType::COMPANY_NAME)); |
| + // Check that the latest use date is saved. |
| + EXPECT_EQ(base::Time::FromTimeT(4321), new_sync_profiles[0].use_date()); |
| + // Check that the use counts were added (default value is 1). |
| + EXPECT_EQ(2U, new_sync_profiles[0].use_count()); |
| +} |
| + |
| +// Tests that adding a new profile that matches an existing sync profile but |
| +// with more information gets merged to the sync profile and merged down to the |
| +// native profile. The merge should happen even if the sync profile is more |
| +// recent. |
| +TEST_F(ProfileSyncServiceAutofillTest, |
| + HasNativeHasSyncMergeSimilarProfileCombine_NativeHasMoreInfo) { |
| + // Create two almost identical profiles. The GUIDs are different and the |
| + // sync profile has no value for company name. |
| + AutofillProfile sync_profile; |
| + autofill::test::SetProfileInfoWithGuid( |
| + &sync_profile, "23355099-1170-4B71-8ED4-144470CC9EBE", "Billing", |
| + "Mitchell", "Morrison", "johnwayne@me.xyz", "", "123 Zoo St.", "unit 5", |
| + "Hollywood", "CA", "91601", "US", "12345678910"); |
| + sync_profile.set_use_date(base::Time::FromTimeT(4321)); |
| + |
| + AutofillProfile* native_profile = new AutofillProfile; |
| + autofill::test::SetProfileInfoWithGuid( |
| + native_profile, "23355099-1170-4B71-8ED4-144470CC9EBF", "Billing", |
| + "Mitchell", "Morrison", "johnwayne@me.xyz", "Fox", "123 Zoo St.", |
| + "unit 5", "Hollywood", "CA", "91601", "US", "12345678910"); |
| + native_profile->set_use_date(base::Time::FromTimeT(1234)); |
| + |
| + AutofillProfile expected_profile(sync_profile); |
| + expected_profile.OverwriteWith(*native_profile, "en-US"); |
| + |
| + std::vector<AutofillProfile*> native_profiles; |
| + native_profiles.push_back(native_profile); |
| + EXPECT_CALL(autofill_table(), GetAutofillProfiles(_)) |
| + .WillOnce(DoAll(SetArgumentPointee<0>(native_profiles), Return(true))); |
| + EXPECT_CALL(autofill_table(), |
| + AddAutofillProfile(MatchProfiles(expected_profile))) |
| + .WillOnce(Return(true)); |
| + EXPECT_CALL(autofill_table(), |
| + RemoveAutofillProfile("23355099-1170-4B71-8ED4-144470CC9EBF")) |
| + .WillOnce(Return(true)); |
| + std::vector<AutofillProfile> sync_profiles; |
| + sync_profiles.push_back(sync_profile); |
| + AddAutofillHelper<AutofillProfile> add_autofill(this, sync_profiles); |
| + |
| + EXPECT_CALL(personal_data_manager(), Refresh()); |
| + // Adds all entries in |sync_profiles| to sync. |
| + StartSyncService(add_autofill.callback(), false, AUTOFILL_PROFILE); |
| + ASSERT_TRUE(add_autofill.success()); |
| + |
| + std::vector<AutofillProfile> new_sync_profiles; |
| + ASSERT_TRUE( |
| + GetAutofillProfilesFromSyncDBUnderProfileNode(&new_sync_profiles)); |
| + ASSERT_EQ(1U, new_sync_profiles.size()); |
| + // Check that key fields are the same. |
| + EXPECT_TRUE(new_sync_profiles[0].IsSubsetOf(expected_profile, "en-US")); |
| + // Make sure the new information was conserved. |
| + EXPECT_EQ(base::ASCIIToUTF16("Fox"), |
| + new_sync_profiles[0].GetRawInfo(ServerFieldType::COMPANY_NAME)); |
| + // Check that the latest use date is saved. |
| + EXPECT_EQ(base::Time::FromTimeT(4321), new_sync_profiles[0].use_date()); |
| + // Check that the use counts were added (default value is 1). |
| + EXPECT_EQ(2U, new_sync_profiles[0].use_count()); |
| +} |
| + |
| +// Tests that adding a new profile that differ only by name to the new sync |
| +// profile results in keeping the two profiles. |
| +TEST_F(ProfileSyncServiceAutofillTest, HasNativeHasSync_DifferentPrimaryInfo) { |
| + AutofillProfile sync_profile; |
| + autofill::test::SetProfileInfoWithGuid( |
| + &sync_profile, "23355099-1170-4B71-8ED4-144470CC9EBE", "Billing", |
| + "Mitchell", "Morrison", "johnwayne@me.xyz", "Fox", "123 Zoo St.", |
| + "unit 5", "Hollywood", "CA", "91601", "US", "12345678910"); |
| + sync_profile.set_use_date(base::Time::FromTimeT(4321)); |
| + |
| + AutofillProfile* native_profile = new AutofillProfile; |
| + autofill::test::SetProfileInfoWithGuid( |
| + native_profile, "23355099-1170-4B71-8ED4-144470CC9EBF", "Billing", "John", |
| + "Smith", "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", "Hollywood", |
| + "CA", "91601", "US", "12345678910"); |
| + native_profile->set_use_date(base::Time::FromTimeT(1234)); |
| + |
| + AutofillProfile expected_profile(sync_profile); |
| + expected_profile.OverwriteWith(*native_profile, "en-US"); |
| + |
| + std::vector<AutofillProfile*> native_profiles; |
| + native_profiles.push_back(native_profile); |
| + EXPECT_CALL(autofill_table(), GetAutofillProfiles(_)) |
| + .WillOnce(DoAll(SetArgumentPointee<0>(native_profiles), Return(true))); |
| + EXPECT_CALL(autofill_table(), AddAutofillProfile(MatchProfiles(sync_profile))) |
| + .WillOnce(Return(true)); |
| + std::vector<AutofillProfile> sync_profiles; |
| + sync_profiles.push_back(sync_profile); |
| + AddAutofillHelper<AutofillProfile> add_autofill(this, sync_profiles); |
| + |
| + EXPECT_CALL(personal_data_manager(), Refresh()); |
| + // Adds all entries in |sync_profiles| to sync. |
| + StartSyncService(add_autofill.callback(), false, AUTOFILL_PROFILE); |
| + ASSERT_TRUE(add_autofill.success()); |
| + |
| + std::vector<AutofillProfile> new_sync_profiles; |
| + ASSERT_TRUE( |
| + GetAutofillProfilesFromSyncDBUnderProfileNode(&new_sync_profiles)); |
| + // The two profiles should be kept. |
| + ASSERT_EQ(2U, new_sync_profiles.size()); |
| } |
| +// Tests that adding a local profile that is the same as a sync profile except |
| +// with different GUIDs results in the local profile being deleted and the sync |
| +// profile being merged down with updated usage stats. |
| TEST_F(ProfileSyncServiceAutofillTest, MergeProfileWithDifferentGuid) { |
| AutofillProfile sync_profile; |
| @@ -1030,6 +1208,8 @@ TEST_F(ProfileSyncServiceAutofillTest, MergeProfileWithDifferentGuid) { |
| "Mitchell", "Morrison", |
| "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", "Hollywood", "CA", |
| "91601", "US", "12345678910"); |
| + sync_profile.set_use_count(20); |
| + sync_profile.set_use_date(base::Time::FromTimeT(1234)); |
| std::string native_guid = "EDC609ED-7EEE-4F27-B00C-423242A9C44B"; |
| AutofillProfile* native_profile = new AutofillProfile; |
| @@ -1038,6 +1218,8 @@ TEST_F(ProfileSyncServiceAutofillTest, MergeProfileWithDifferentGuid) { |
| "Mitchell", "Morrison", |
| "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", "Hollywood", "CA", |
| "91601", "US", "12345678910"); |
| + native_profile->set_use_count(5); |
| + native_profile->set_use_date(base::Time::FromTimeT(4321)); |
| std::vector<AutofillProfile*> native_profiles; |
| native_profiles.push_back(native_profile); |
| @@ -1058,9 +1240,15 @@ TEST_F(ProfileSyncServiceAutofillTest, MergeProfileWithDifferentGuid) { |
| std::vector<AutofillProfile> new_sync_profiles; |
| ASSERT_TRUE(GetAutofillProfilesFromSyncDBUnderProfileNode( |
| &new_sync_profiles)); |
| + // Check that the profiles were merged. |
| ASSERT_EQ(1U, new_sync_profiles.size()); |
| EXPECT_EQ(0, sync_profile.Compare(new_sync_profiles[0])); |
| + // Check that the sync guid was kept. |
| EXPECT_EQ(sync_profile.guid(), new_sync_profiles[0].guid()); |
| + // Check that the sync profile use count was kept. |
| + EXPECT_EQ(20U, new_sync_profiles[0].use_count()); |
| + // Check that the sync profile use date was kept. |
| + EXPECT_EQ(base::Time::FromTimeT(1234), new_sync_profiles[0].use_date()); |
| } |
| TEST_F(ProfileSyncServiceAutofillTest, ProcessUserChangeAddEntry) { |