| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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 <stddef.h> | 5 #include <stddef.h> |
| 6 #include <stdint.h> | 6 #include <stdint.h> |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 using autofill::AutocompleteSyncableService; | 62 using autofill::AutocompleteSyncableService; |
| 63 using autofill::AutofillChange; | 63 using autofill::AutofillChange; |
| 64 using autofill::AutofillChangeList; | 64 using autofill::AutofillChangeList; |
| 65 using autofill::AutofillEntry; | 65 using autofill::AutofillEntry; |
| 66 using autofill::AutofillKey; | 66 using autofill::AutofillKey; |
| 67 using autofill::AutofillProfile; | 67 using autofill::AutofillProfile; |
| 68 using autofill::AutofillProfileChange; | 68 using autofill::AutofillProfileChange; |
| 69 using autofill::AutofillProfileSyncableService; | 69 using autofill::AutofillProfileSyncableService; |
| 70 using autofill::AutofillTable; | 70 using autofill::AutofillTable; |
| 71 using autofill::AutofillWebDataService; | 71 using autofill::AutofillWebDataService; |
| 72 using autofill::NAME_FULL; |
| 72 using autofill::PersonalDataManager; | 73 using autofill::PersonalDataManager; |
| 73 using autofill::ServerFieldType; | 74 using autofill::ServerFieldType; |
| 75 using base::ASCIIToUTF16; |
| 74 using base::Time; | 76 using base::Time; |
| 75 using base::TimeDelta; | 77 using base::TimeDelta; |
| 76 using base::WaitableEvent; | 78 using base::WaitableEvent; |
| 77 using browser_sync::AutofillDataTypeController; | 79 using browser_sync::AutofillDataTypeController; |
| 78 using browser_sync::AutofillProfileDataTypeController; | 80 using browser_sync::AutofillProfileDataTypeController; |
| 79 using syncer::AUTOFILL; | 81 using syncer::AUTOFILL; |
| 80 using syncer::AUTOFILL_PROFILE; | 82 using syncer::AUTOFILL_PROFILE; |
| 81 using syncer::BaseNode; | 83 using syncer::BaseNode; |
| 82 using syncer::syncable::CREATE; | 84 using syncer::syncable::CREATE; |
| 83 using syncer::syncable::GET_TYPE_ROOT; | 85 using syncer::syncable::GET_TYPE_ROOT; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 110 int time_shift0, | 112 int time_shift0, |
| 111 int time_shift1) { | 113 int time_shift1) { |
| 112 // Time deep in the past would cause Autocomplete sync to discard the | 114 // Time deep in the past would cause Autocomplete sync to discard the |
| 113 // entries. | 115 // entries. |
| 114 static Time base_time = Time::Now().LocalMidnight(); | 116 static Time base_time = Time::Now().LocalMidnight(); |
| 115 | 117 |
| 116 Time date_created = base_time + TimeDelta::FromSeconds(time_shift0); | 118 Time date_created = base_time + TimeDelta::FromSeconds(time_shift0); |
| 117 Time date_last_used = date_created; | 119 Time date_last_used = date_created; |
| 118 if (time_shift1 >= 0) | 120 if (time_shift1 >= 0) |
| 119 date_last_used = base_time + TimeDelta::FromSeconds(time_shift1); | 121 date_last_used = base_time + TimeDelta::FromSeconds(time_shift1); |
| 120 return AutofillEntry( | 122 return AutofillEntry(AutofillKey(ASCIIToUTF16(name), ASCIIToUTF16(value)), |
| 121 AutofillKey(base::ASCIIToUTF16(name), base::ASCIIToUTF16(value)), | 123 date_created, date_last_used); |
| 122 date_created, date_last_used); | |
| 123 } | 124 } |
| 124 | 125 |
| 125 AutofillEntry MakeAutofillEntry(const char* name, | 126 AutofillEntry MakeAutofillEntry(const char* name, |
| 126 const char* value, | 127 const char* value, |
| 127 int time_shift) { | 128 int time_shift) { |
| 128 return MakeAutofillEntry(name, value, time_shift, -1); | 129 return MakeAutofillEntry(name, value, time_shift, -1); |
| 129 } | 130 } |
| 130 | 131 |
| 131 } // namespace | 132 } // namespace |
| 132 | 133 |
| (...skipping 869 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1002 sync_profile.set_use_date(base::Time::FromTimeT(4321)); | 1003 sync_profile.set_use_date(base::Time::FromTimeT(4321)); |
| 1003 | 1004 |
| 1004 AutofillProfile* native_profile = new AutofillProfile; | 1005 AutofillProfile* native_profile = new AutofillProfile; |
| 1005 autofill::test::SetProfileInfoWithGuid( | 1006 autofill::test::SetProfileInfoWithGuid( |
| 1006 native_profile, "23355099-1170-4B71-8ED4-144470CC9EBF", "Billing", | 1007 native_profile, "23355099-1170-4B71-8ED4-144470CC9EBF", "Billing", |
| 1007 "Mitchell", "Morrison", "johnwayne@me.xyz", "", "123 Zoo St.", "unit 5", | 1008 "Mitchell", "Morrison", "johnwayne@me.xyz", "", "123 Zoo St.", "unit 5", |
| 1008 "Hollywood", "CA", "91601", "US", "12345678910"); | 1009 "Hollywood", "CA", "91601", "US", "12345678910"); |
| 1009 native_profile->set_use_date(base::Time::FromTimeT(1234)); | 1010 native_profile->set_use_date(base::Time::FromTimeT(1234)); |
| 1010 | 1011 |
| 1011 AutofillProfile expected_profile(sync_profile); | 1012 AutofillProfile expected_profile(sync_profile); |
| 1012 expected_profile.OverwriteWith(*native_profile, "en-US"); | 1013 expected_profile.SetRawInfo(NAME_FULL, |
| 1014 ASCIIToUTF16("Billing Mitchell Morrison")); |
| 1015 expected_profile.set_use_count(2); |
| 1013 | 1016 |
| 1014 std::vector<AutofillProfile*> native_profiles; | 1017 std::vector<AutofillProfile*> native_profiles; |
| 1015 native_profiles.push_back(native_profile); | 1018 native_profiles.push_back(native_profile); |
| 1016 EXPECT_CALL(autofill_table(), GetAutofillProfiles(_)) | 1019 EXPECT_CALL(autofill_table(), GetAutofillProfiles(_)) |
| 1017 .WillOnce(DoAll(SetArgumentPointee<0>(native_profiles), Return(true))); | 1020 .WillOnce(DoAll(SetArgumentPointee<0>(native_profiles), Return(true))); |
| 1018 EXPECT_CALL(autofill_table(), | 1021 EXPECT_CALL(autofill_table(), |
| 1019 AddAutofillProfile(MatchProfiles(expected_profile))) | 1022 AddAutofillProfile(MatchProfiles(expected_profile))) |
| 1020 .WillOnce(Return(true)); | 1023 .WillOnce(Return(true)); |
| 1021 EXPECT_CALL(autofill_table(), | 1024 EXPECT_CALL(autofill_table(), |
| 1022 RemoveAutofillProfile("23355099-1170-4B71-8ED4-144470CC9EBF")) | 1025 RemoveAutofillProfile("23355099-1170-4B71-8ED4-144470CC9EBF")) |
| 1023 .WillOnce(Return(true)); | 1026 .WillOnce(Return(true)); |
| 1024 std::vector<AutofillProfile> sync_profiles; | 1027 std::vector<AutofillProfile> sync_profiles; |
| 1025 sync_profiles.push_back(sync_profile); | 1028 sync_profiles.push_back(sync_profile); |
| 1026 AddAutofillHelper<AutofillProfile> add_autofill(this, sync_profiles); | 1029 AddAutofillHelper<AutofillProfile> add_autofill(this, sync_profiles); |
| 1027 | 1030 |
| 1028 EXPECT_CALL(personal_data_manager(), Refresh()); | 1031 EXPECT_CALL(personal_data_manager(), Refresh()); |
| 1029 // Adds all entries in |sync_profiles| to sync. | 1032 // Adds all entries in |sync_profiles| to sync. |
| 1030 StartSyncService(add_autofill.callback(), false, AUTOFILL_PROFILE); | 1033 StartSyncService(add_autofill.callback(), false, AUTOFILL_PROFILE); |
| 1031 ASSERT_TRUE(add_autofill.success()); | 1034 ASSERT_TRUE(add_autofill.success()); |
| 1032 | 1035 |
| 1033 std::vector<AutofillProfile> new_sync_profiles; | 1036 std::vector<AutofillProfile> new_sync_profiles; |
| 1034 ASSERT_TRUE( | 1037 ASSERT_TRUE( |
| 1035 GetAutofillProfilesFromSyncDBUnderProfileNode(&new_sync_profiles)); | 1038 GetAutofillProfilesFromSyncDBUnderProfileNode(&new_sync_profiles)); |
| 1036 ASSERT_EQ(1U, new_sync_profiles.size()); | 1039 ASSERT_EQ(1U, new_sync_profiles.size()); |
| 1037 // Check that key fields are the same. | 1040 // Check that key fields are the same. |
| 1038 EXPECT_TRUE(new_sync_profiles[0].IsSubsetOf(sync_profile, "en-US")); | 1041 EXPECT_TRUE(new_sync_profiles[0].IsSubsetOf(sync_profile, "en-US")); |
| 1039 // Make sure the additional information from the sync profile was kept. | 1042 // Make sure the additional information from the sync profile was kept. |
| 1040 EXPECT_EQ(base::ASCIIToUTF16("Fox"), | 1043 EXPECT_EQ(ASCIIToUTF16("Fox"), |
| 1041 new_sync_profiles[0].GetRawInfo(ServerFieldType::COMPANY_NAME)); | 1044 new_sync_profiles[0].GetRawInfo(ServerFieldType::COMPANY_NAME)); |
| 1042 // Check that the latest use date is saved. | 1045 // Check that the latest use date is saved. |
| 1043 EXPECT_EQ(base::Time::FromTimeT(4321), new_sync_profiles[0].use_date()); | 1046 EXPECT_EQ(base::Time::FromTimeT(4321), new_sync_profiles[0].use_date()); |
| 1044 // Check that the use counts were added (default value is 1). | 1047 // Check that the use counts were added (default value is 1). |
| 1045 EXPECT_EQ(2U, new_sync_profiles[0].use_count()); | 1048 EXPECT_EQ(2U, new_sync_profiles[0].use_count()); |
| 1046 } | 1049 } |
| 1047 | 1050 |
| 1048 // Tests that a sync with a new native profile that matches an older new sync | 1051 // Tests that a sync with a new native profile that matches an older new sync |
| 1049 // profile but with less information results in the native profile being deleted | 1052 // profile but with less information results in the native profile being deleted |
| 1050 // and replaced by the sync profile with merged usage stats. | 1053 // and replaced by the sync profile with merged usage stats. |
| 1051 TEST_F(ProfileSyncServiceAutofillTest, | 1054 TEST_F(ProfileSyncServiceAutofillTest, |
| 1052 HasNativeHasSyncMergeSimilarProfileCombine_SyncHasMoreInfoAndOlder) { | 1055 HasNativeHasSyncMergeSimilarProfileCombine_SyncHasMoreInfoAndOlder) { |
| 1053 // Create two almost identical profiles. The GUIDs are different and the | 1056 // Create two almost identical profiles. The GUIDs are different and the |
| 1054 // native profile has no value for company name. | 1057 // native profile has no value for company name. |
| 1055 AutofillProfile sync_profile; | 1058 AutofillProfile sync_profile; |
| 1056 autofill::test::SetProfileInfoWithGuid( | 1059 autofill::test::SetProfileInfoWithGuid( |
| 1057 &sync_profile, "23355099-1170-4B71-8ED4-144470CC9EBE", "Billing", | 1060 &sync_profile, "23355099-1170-4B71-8ED4-144470CC9EBE", "Billing", |
| 1058 "Mitchell", "Morrison", "johnwayne@me.xyz", "Fox", "123 Zoo St.", | 1061 "Mitchell", "Morrison", "johnwayne@me.xyz", "Fox", "123 Zoo St.", |
| 1059 "unit 5", "Hollywood", "CA", "91601", "US", "12345678910"); | 1062 "unit 5", "Hollywood", "CA", "91601", "US", "12345678910"); |
| 1060 sync_profile.set_use_date(base::Time::FromTimeT(1234)); | 1063 sync_profile.set_use_date(base::Time::FromTimeT(1234)); |
| 1061 | 1064 |
| 1062 AutofillProfile* native_profile = new AutofillProfile; | 1065 AutofillProfile* native_profile = new AutofillProfile; |
| 1063 autofill::test::SetProfileInfoWithGuid( | 1066 autofill::test::SetProfileInfoWithGuid( |
| 1064 native_profile, "23355099-1170-4B71-8ED4-144470CC9EBF", "Billing", | 1067 native_profile, "23355099-1170-4B71-8ED4-144470CC9EBF", "Billing", |
| 1065 "Mitchell", "Morrison", "johnwayne@me.xyz", "", "123 Zoo St.", "unit 5", | 1068 "Mitchell", "Morrison", "johnwayne@me.xyz", "", "123 Zoo St.", "unit 5", |
| 1066 "Hollywood", "CA", "91601", "US", "12345678910"); | 1069 "Hollywood", "CA", "91601", "US", "12345678910"); |
| 1067 native_profile->set_use_date(base::Time::FromTimeT(4321)); | 1070 native_profile->set_use_date(base::Time::FromTimeT(4321)); |
| 1068 | 1071 |
| 1069 AutofillProfile expected_profile(sync_profile); | 1072 AutofillProfile expected_profile(sync_profile); |
| 1070 expected_profile.OverwriteWith(*native_profile, "en-US"); | 1073 expected_profile.SetRawInfo(NAME_FULL, |
| 1074 ASCIIToUTF16("Billing Mitchell Morrison")); |
| 1075 expected_profile.set_use_count(2); |
| 1076 expected_profile.set_use_date(native_profile->use_date()); |
| 1071 | 1077 |
| 1072 std::vector<AutofillProfile*> native_profiles; | 1078 std::vector<AutofillProfile*> native_profiles; |
| 1073 native_profiles.push_back(native_profile); | 1079 native_profiles.push_back(native_profile); |
| 1074 EXPECT_CALL(autofill_table(), GetAutofillProfiles(_)) | 1080 EXPECT_CALL(autofill_table(), GetAutofillProfiles(_)) |
| 1075 .WillOnce(DoAll(SetArgumentPointee<0>(native_profiles), Return(true))); | 1081 .WillOnce(DoAll(SetArgumentPointee<0>(native_profiles), Return(true))); |
| 1076 EXPECT_CALL(autofill_table(), | 1082 EXPECT_CALL(autofill_table(), |
| 1077 AddAutofillProfile(MatchProfiles(expected_profile))) | 1083 AddAutofillProfile(MatchProfiles(expected_profile))) |
| 1078 .WillOnce(Return(true)); | 1084 .WillOnce(Return(true)); |
| 1079 EXPECT_CALL(autofill_table(), | 1085 EXPECT_CALL(autofill_table(), |
| 1080 RemoveAutofillProfile("23355099-1170-4B71-8ED4-144470CC9EBF")) | 1086 RemoveAutofillProfile("23355099-1170-4B71-8ED4-144470CC9EBF")) |
| 1081 .WillOnce(Return(true)); | 1087 .WillOnce(Return(true)); |
| 1082 std::vector<AutofillProfile> sync_profiles; | 1088 std::vector<AutofillProfile> sync_profiles; |
| 1083 sync_profiles.push_back(sync_profile); | 1089 sync_profiles.push_back(sync_profile); |
| 1084 AddAutofillHelper<AutofillProfile> add_autofill(this, sync_profiles); | 1090 AddAutofillHelper<AutofillProfile> add_autofill(this, sync_profiles); |
| 1085 | 1091 |
| 1086 EXPECT_CALL(personal_data_manager(), Refresh()); | 1092 EXPECT_CALL(personal_data_manager(), Refresh()); |
| 1087 // Adds all entries in |sync_profiles| to sync. | 1093 // Adds all entries in |sync_profiles| to sync. |
| 1088 StartSyncService(add_autofill.callback(), false, AUTOFILL_PROFILE); | 1094 StartSyncService(add_autofill.callback(), false, AUTOFILL_PROFILE); |
| 1089 ASSERT_TRUE(add_autofill.success()); | 1095 ASSERT_TRUE(add_autofill.success()); |
| 1090 | 1096 |
| 1091 std::vector<AutofillProfile> new_sync_profiles; | 1097 std::vector<AutofillProfile> new_sync_profiles; |
| 1092 ASSERT_TRUE( | 1098 ASSERT_TRUE( |
| 1093 GetAutofillProfilesFromSyncDBUnderProfileNode(&new_sync_profiles)); | 1099 GetAutofillProfilesFromSyncDBUnderProfileNode(&new_sync_profiles)); |
| 1094 ASSERT_EQ(1U, new_sync_profiles.size()); | 1100 ASSERT_EQ(1U, new_sync_profiles.size()); |
| 1095 // Check that key fields are the same. | 1101 // Check that key fields are the same. |
| 1096 EXPECT_TRUE(new_sync_profiles[0].IsSubsetOf(sync_profile, "en-US")); | 1102 EXPECT_TRUE(new_sync_profiles[0].IsSubsetOf(sync_profile, "en-US")); |
| 1097 // Make sure the additional information from the sync profile was kept. | 1103 // Make sure the additional information from the sync profile was kept. |
| 1098 EXPECT_EQ(base::ASCIIToUTF16("Fox"), | 1104 EXPECT_EQ(ASCIIToUTF16("Fox"), |
| 1099 new_sync_profiles[0].GetRawInfo(ServerFieldType::COMPANY_NAME)); | 1105 new_sync_profiles[0].GetRawInfo(ServerFieldType::COMPANY_NAME)); |
| 1100 // Check that the latest use date is saved. | 1106 // Check that the latest use date is saved. |
| 1101 EXPECT_EQ(base::Time::FromTimeT(4321), new_sync_profiles[0].use_date()); | 1107 EXPECT_EQ(base::Time::FromTimeT(4321), new_sync_profiles[0].use_date()); |
| 1102 // Check that the use counts were added (default value is 1). | 1108 // Check that the use counts were added (default value is 1). |
| 1103 EXPECT_EQ(2U, new_sync_profiles[0].use_count()); | 1109 EXPECT_EQ(2U, new_sync_profiles[0].use_count()); |
| 1104 } | 1110 } |
| 1105 | 1111 |
| 1106 // Tests that a sync with a new native profile that matches an a new sync | 1112 // Tests that a sync with a new native profile that matches an a new sync |
| 1107 // profile but with more information results in the native profile being deleted | 1113 // profile but with more information results in the native profile being deleted |
| 1108 // and replaced by the sync profile with the native profiles additional | 1114 // and replaced by the sync profile with the native profiles additional |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1119 "Hollywood", "CA", "91601", "US", "12345678910"); | 1125 "Hollywood", "CA", "91601", "US", "12345678910"); |
| 1120 sync_profile.set_use_date(base::Time::FromTimeT(4321)); | 1126 sync_profile.set_use_date(base::Time::FromTimeT(4321)); |
| 1121 | 1127 |
| 1122 AutofillProfile* native_profile = new AutofillProfile; | 1128 AutofillProfile* native_profile = new AutofillProfile; |
| 1123 autofill::test::SetProfileInfoWithGuid( | 1129 autofill::test::SetProfileInfoWithGuid( |
| 1124 native_profile, "23355099-1170-4B71-8ED4-144470CC9EBF", "Billing", | 1130 native_profile, "23355099-1170-4B71-8ED4-144470CC9EBF", "Billing", |
| 1125 "Mitchell", "Morrison", "johnwayne@me.xyz", "Fox", "123 Zoo St.", | 1131 "Mitchell", "Morrison", "johnwayne@me.xyz", "Fox", "123 Zoo St.", |
| 1126 "unit 5", "Hollywood", "CA", "91601", "US", "12345678910"); | 1132 "unit 5", "Hollywood", "CA", "91601", "US", "12345678910"); |
| 1127 native_profile->set_use_date(base::Time::FromTimeT(1234)); | 1133 native_profile->set_use_date(base::Time::FromTimeT(1234)); |
| 1128 | 1134 |
| 1129 AutofillProfile expected_profile(sync_profile); | 1135 AutofillProfile expected_profile(*native_profile); |
| 1130 expected_profile.OverwriteWith(*native_profile, "en-US"); | 1136 expected_profile.SetRawInfo(NAME_FULL, |
| 1137 ASCIIToUTF16("Billing Mitchell Morrison")); |
| 1138 expected_profile.set_use_date(sync_profile.use_date()); |
| 1139 expected_profile.set_use_count(2); |
| 1131 | 1140 |
| 1132 std::vector<AutofillProfile*> native_profiles; | 1141 std::vector<AutofillProfile*> native_profiles; |
| 1133 native_profiles.push_back(native_profile); | 1142 native_profiles.push_back(native_profile); |
| 1134 EXPECT_CALL(autofill_table(), GetAutofillProfiles(_)) | 1143 EXPECT_CALL(autofill_table(), GetAutofillProfiles(_)) |
| 1135 .WillOnce(DoAll(SetArgumentPointee<0>(native_profiles), Return(true))); | 1144 .WillOnce(DoAll(SetArgumentPointee<0>(native_profiles), Return(true))); |
| 1136 EXPECT_CALL(autofill_table(), | 1145 EXPECT_CALL(autofill_table(), |
| 1137 AddAutofillProfile(MatchProfiles(expected_profile))) | 1146 AddAutofillProfile(MatchProfiles(expected_profile))) |
| 1138 .WillOnce(Return(true)); | 1147 .WillOnce(Return(true)); |
| 1139 EXPECT_CALL(autofill_table(), | 1148 EXPECT_CALL(autofill_table(), |
| 1140 RemoveAutofillProfile("23355099-1170-4B71-8ED4-144470CC9EBF")) | 1149 RemoveAutofillProfile("23355099-1170-4B71-8ED4-144470CC9EBF")) |
| 1141 .WillOnce(Return(true)); | 1150 .WillOnce(Return(true)); |
| 1142 std::vector<AutofillProfile> sync_profiles; | 1151 std::vector<AutofillProfile> sync_profiles; |
| 1143 sync_profiles.push_back(sync_profile); | 1152 sync_profiles.push_back(sync_profile); |
| 1144 AddAutofillHelper<AutofillProfile> add_autofill(this, sync_profiles); | 1153 AddAutofillHelper<AutofillProfile> add_autofill(this, sync_profiles); |
| 1145 | 1154 |
| 1146 EXPECT_CALL(personal_data_manager(), Refresh()); | 1155 EXPECT_CALL(personal_data_manager(), Refresh()); |
| 1147 // Adds all entries in |sync_profiles| to sync. | 1156 // Adds all entries in |sync_profiles| to sync. |
| 1148 StartSyncService(add_autofill.callback(), false, AUTOFILL_PROFILE); | 1157 StartSyncService(add_autofill.callback(), false, AUTOFILL_PROFILE); |
| 1149 ASSERT_TRUE(add_autofill.success()); | 1158 ASSERT_TRUE(add_autofill.success()); |
| 1150 | 1159 |
| 1151 std::vector<AutofillProfile> new_sync_profiles; | 1160 std::vector<AutofillProfile> new_sync_profiles; |
| 1152 ASSERT_TRUE( | 1161 ASSERT_TRUE( |
| 1153 GetAutofillProfilesFromSyncDBUnderProfileNode(&new_sync_profiles)); | 1162 GetAutofillProfilesFromSyncDBUnderProfileNode(&new_sync_profiles)); |
| 1154 ASSERT_EQ(1U, new_sync_profiles.size()); | 1163 ASSERT_EQ(1U, new_sync_profiles.size()); |
| 1155 // Check that key fields are the same. | 1164 // Check that key fields are the same. |
| 1156 EXPECT_TRUE(new_sync_profiles[0].IsSubsetOf(expected_profile, "en-US")); | 1165 EXPECT_TRUE(new_sync_profiles[0].IsSubsetOf(expected_profile, "en-US")); |
| 1157 // Make sure the addtional information of the native profile was saved into | 1166 // Make sure the addtional information of the native profile was saved into |
| 1158 // the sync profile. | 1167 // the sync profile. |
| 1159 EXPECT_EQ(base::ASCIIToUTF16("Fox"), | 1168 EXPECT_EQ(ASCIIToUTF16("Fox"), |
| 1160 new_sync_profiles[0].GetRawInfo(ServerFieldType::COMPANY_NAME)); | 1169 new_sync_profiles[0].GetRawInfo(ServerFieldType::COMPANY_NAME)); |
| 1161 // Check that the latest use date is saved. | 1170 // Check that the latest use date is saved. |
| 1162 EXPECT_EQ(base::Time::FromTimeT(4321), new_sync_profiles[0].use_date()); | 1171 EXPECT_EQ(base::Time::FromTimeT(4321), new_sync_profiles[0].use_date()); |
| 1163 // Check that the use counts were added (default value is 1). | 1172 // Check that the use counts were added (default value is 1). |
| 1164 EXPECT_EQ(2U, new_sync_profiles[0].use_count()); | 1173 EXPECT_EQ(2U, new_sync_profiles[0].use_count()); |
| 1165 } | 1174 } |
| 1166 | 1175 |
| 1167 // Tests that a sync with a new native profile that differ only by name a new | 1176 // Tests that a sync with a new native profile that differ only by name a new |
| 1168 // sync profile results in keeping both profiles. | 1177 // sync profile results in keeping both profiles. |
| 1169 TEST_F(ProfileSyncServiceAutofillTest, HasNativeHasSync_DifferentPrimaryInfo) { | 1178 TEST_F(ProfileSyncServiceAutofillTest, HasNativeHasSync_DifferentPrimaryInfo) { |
| 1170 AutofillProfile sync_profile; | 1179 AutofillProfile sync_profile; |
| 1171 autofill::test::SetProfileInfoWithGuid( | 1180 autofill::test::SetProfileInfoWithGuid( |
| 1172 &sync_profile, "23355099-1170-4B71-8ED4-144470CC9EBE", "Billing", | 1181 &sync_profile, "23355099-1170-4B71-8ED4-144470CC9EBE", "Billing", |
| 1173 "Mitchell", "Morrison", "johnwayne@me.xyz", "Fox", "123 Zoo St.", | 1182 "Mitchell", "Morrison", "johnwayne@me.xyz", "Fox", "123 Zoo St.", |
| 1174 "unit 5", "Hollywood", "CA", "91601", "US", "12345678910"); | 1183 "unit 5", "Hollywood", "CA", "91601", "US", "12345678910"); |
| 1175 sync_profile.set_use_date(base::Time::FromTimeT(4321)); | 1184 sync_profile.set_use_date(base::Time::FromTimeT(4321)); |
| 1176 | 1185 |
| 1177 AutofillProfile* native_profile = new AutofillProfile; | 1186 AutofillProfile* native_profile = new AutofillProfile; |
| 1178 autofill::test::SetProfileInfoWithGuid( | 1187 autofill::test::SetProfileInfoWithGuid( |
| 1179 native_profile, "23355099-1170-4B71-8ED4-144470CC9EBF", "Billing", "John", | 1188 native_profile, "23355099-1170-4B71-8ED4-144470CC9EBF", "Billing", "John", |
| 1180 "Smith", "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", "Hollywood", | 1189 "Smith", "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", "Hollywood", |
| 1181 "CA", "91601", "US", "12345678910"); | 1190 "CA", "91601", "US", "12345678910"); |
| 1182 native_profile->set_use_date(base::Time::FromTimeT(1234)); | 1191 native_profile->set_use_date(base::Time::FromTimeT(1234)); |
| 1183 | 1192 |
| 1184 AutofillProfile expected_profile(sync_profile); | |
| 1185 expected_profile.OverwriteWith(*native_profile, "en-US"); | |
| 1186 | |
| 1187 std::vector<AutofillProfile*> native_profiles; | 1193 std::vector<AutofillProfile*> native_profiles; |
| 1188 native_profiles.push_back(native_profile); | 1194 native_profiles.push_back(native_profile); |
| 1189 EXPECT_CALL(autofill_table(), GetAutofillProfiles(_)) | 1195 EXPECT_CALL(autofill_table(), GetAutofillProfiles(_)) |
| 1190 .WillOnce(DoAll(SetArgumentPointee<0>(native_profiles), Return(true))); | 1196 .WillOnce(DoAll(SetArgumentPointee<0>(native_profiles), Return(true))); |
| 1191 EXPECT_CALL(autofill_table(), AddAutofillProfile(MatchProfiles(sync_profile))) | 1197 EXPECT_CALL(autofill_table(), AddAutofillProfile(MatchProfiles(sync_profile))) |
| 1192 .WillOnce(Return(true)); | 1198 .WillOnce(Return(true)); |
| 1193 std::vector<AutofillProfile> sync_profiles; | 1199 std::vector<AutofillProfile> sync_profiles; |
| 1194 sync_profiles.push_back(sync_profile); | 1200 sync_profiles.push_back(sync_profile); |
| 1195 AddAutofillHelper<AutofillProfile> add_autofill(this, sync_profiles); | 1201 AddAutofillHelper<AutofillProfile> add_autofill(this, sync_profiles); |
| 1196 | 1202 |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1455 std::vector<AutofillEntry> sync_entries; | 1461 std::vector<AutofillEntry> sync_entries; |
| 1456 std::vector<AutofillProfile> sync_profiles; | 1462 std::vector<AutofillProfile> sync_profiles; |
| 1457 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&sync_entries, &sync_profiles)); | 1463 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&sync_entries, &sync_profiles)); |
| 1458 EXPECT_EQ(3U, sync_entries.size()); | 1464 EXPECT_EQ(3U, sync_entries.size()); |
| 1459 EXPECT_EQ(0U, sync_profiles.size()); | 1465 EXPECT_EQ(0U, sync_profiles.size()); |
| 1460 for (size_t i = 0; i < sync_entries.size(); i++) { | 1466 for (size_t i = 0; i < sync_entries.size(); i++) { |
| 1461 DVLOG(1) << "Entry " << i << ": " << sync_entries[i].key().name() | 1467 DVLOG(1) << "Entry " << i << ": " << sync_entries[i].key().name() |
| 1462 << ", " << sync_entries[i].key().value(); | 1468 << ", " << sync_entries[i].key().value(); |
| 1463 } | 1469 } |
| 1464 } | 1470 } |
| OLD | NEW |