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 1011 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1022 AutofillProfile* native_profile = new AutofillProfile; | 1022 AutofillProfile* native_profile = new AutofillProfile; |
1023 autofill::test::SetProfileInfoWithGuid( | 1023 autofill::test::SetProfileInfoWithGuid( |
1024 native_profile, "23355099-1170-4B71-8ED4-144470CC9EBF", "Billing", | 1024 native_profile, "23355099-1170-4B71-8ED4-144470CC9EBF", "Billing", |
1025 "Mitchell", "Morrison", "johnwayne@me.xyz", "", "123 Zoo St.", "unit 5", | 1025 "Mitchell", "Morrison", "johnwayne@me.xyz", "", "123 Zoo St.", "unit 5", |
1026 "Hollywood", "CA", "91601", "US", "12345678910"); | 1026 "Hollywood", "CA", "91601", "US", "12345678910"); |
1027 native_profile->set_use_date(base::Time::FromTimeT(1234)); | 1027 native_profile->set_use_date(base::Time::FromTimeT(1234)); |
1028 | 1028 |
1029 AutofillProfile expected_profile(sync_profile); | 1029 AutofillProfile expected_profile(sync_profile); |
1030 expected_profile.SetRawInfo(NAME_FULL, | 1030 expected_profile.SetRawInfo(NAME_FULL, |
1031 ASCIIToUTF16("Billing Mitchell Morrison")); | 1031 ASCIIToUTF16("Billing Mitchell Morrison")); |
1032 expected_profile.set_use_count(2); | 1032 expected_profile.set_use_count(1); |
1033 | 1033 |
1034 std::vector<AutofillProfile*> native_profiles; | 1034 std::vector<AutofillProfile*> native_profiles; |
1035 native_profiles.push_back(native_profile); | 1035 native_profiles.push_back(native_profile); |
1036 EXPECT_CALL(autofill_table(), GetAutofillProfiles(_)) | 1036 EXPECT_CALL(autofill_table(), GetAutofillProfiles(_)) |
1037 .WillOnce(DoAll(SetArgumentPointee<0>(native_profiles), Return(true))); | 1037 .WillOnce(DoAll(SetArgumentPointee<0>(native_profiles), Return(true))); |
1038 EXPECT_CALL(autofill_table(), | 1038 EXPECT_CALL(autofill_table(), |
1039 AddAutofillProfile(MatchProfiles(expected_profile))) | 1039 AddAutofillProfile(MatchProfiles(expected_profile))) |
1040 .WillOnce(Return(true)); | 1040 .WillOnce(Return(true)); |
1041 EXPECT_CALL(autofill_table(), | 1041 EXPECT_CALL(autofill_table(), |
1042 RemoveAutofillProfile("23355099-1170-4B71-8ED4-144470CC9EBF")) | 1042 RemoveAutofillProfile("23355099-1170-4B71-8ED4-144470CC9EBF")) |
(...skipping 12 matching lines...) Expand all Loading... |
1055 GetAutofillProfilesFromSyncDBUnderProfileNode(&new_sync_profiles)); | 1055 GetAutofillProfilesFromSyncDBUnderProfileNode(&new_sync_profiles)); |
1056 ASSERT_EQ(1U, new_sync_profiles.size()); | 1056 ASSERT_EQ(1U, new_sync_profiles.size()); |
1057 // Check that key fields are the same. | 1057 // Check that key fields are the same. |
1058 EXPECT_TRUE(new_sync_profiles[0].IsSubsetOf(sync_profile, "en-US")); | 1058 EXPECT_TRUE(new_sync_profiles[0].IsSubsetOf(sync_profile, "en-US")); |
1059 // Make sure the additional information from the sync profile was kept. | 1059 // Make sure the additional information from the sync profile was kept. |
1060 EXPECT_EQ(ASCIIToUTF16("Fox"), | 1060 EXPECT_EQ(ASCIIToUTF16("Fox"), |
1061 new_sync_profiles[0].GetRawInfo(ServerFieldType::COMPANY_NAME)); | 1061 new_sync_profiles[0].GetRawInfo(ServerFieldType::COMPANY_NAME)); |
1062 // Check that the latest use date is saved. | 1062 // Check that the latest use date is saved. |
1063 EXPECT_EQ(base::Time::FromTimeT(4321), new_sync_profiles[0].use_date()); | 1063 EXPECT_EQ(base::Time::FromTimeT(4321), new_sync_profiles[0].use_date()); |
1064 // Check that the use counts were added (default value is 1). | 1064 // Check that the use counts were added (default value is 1). |
1065 EXPECT_EQ(2U, new_sync_profiles[0].use_count()); | 1065 EXPECT_EQ(1U, new_sync_profiles[0].use_count()); |
1066 } | 1066 } |
1067 | 1067 |
1068 // Tests that a sync with a new native profile that matches an older new sync | 1068 // Tests that a sync with a new native profile that matches an older new sync |
1069 // profile but with less information results in the native profile being deleted | 1069 // profile but with less information results in the native profile being deleted |
1070 // and replaced by the sync profile with merged usage stats. | 1070 // and replaced by the sync profile with merged usage stats. |
1071 TEST_F(ProfileSyncServiceAutofillTest, | 1071 TEST_F(ProfileSyncServiceAutofillTest, |
1072 HasNativeHasSyncMergeSimilarProfileCombine_SyncHasMoreInfoAndOlder) { | 1072 HasNativeHasSyncMergeSimilarProfileCombine_SyncHasMoreInfoAndOlder) { |
1073 // Create two almost identical profiles. The GUIDs are different and the | 1073 // Create two almost identical profiles. The GUIDs are different and the |
1074 // native profile has no value for company name. | 1074 // native profile has no value for company name. |
1075 AutofillProfile sync_profile; | 1075 AutofillProfile sync_profile; |
1076 autofill::test::SetProfileInfoWithGuid( | 1076 autofill::test::SetProfileInfoWithGuid( |
1077 &sync_profile, "23355099-1170-4B71-8ED4-144470CC9EBE", "Billing", | 1077 &sync_profile, "23355099-1170-4B71-8ED4-144470CC9EBE", "Billing", |
1078 "Mitchell", "Morrison", "johnwayne@me.xyz", "Fox", "123 Zoo St.", | 1078 "Mitchell", "Morrison", "johnwayne@me.xyz", "Fox", "123 Zoo St.", |
1079 "unit 5", "Hollywood", "CA", "91601", "US", "12345678910"); | 1079 "unit 5", "Hollywood", "CA", "91601", "US", "12345678910"); |
1080 sync_profile.set_use_date(base::Time::FromTimeT(1234)); | 1080 sync_profile.set_use_date(base::Time::FromTimeT(1234)); |
1081 | 1081 |
1082 AutofillProfile* native_profile = new AutofillProfile; | 1082 AutofillProfile* native_profile = new AutofillProfile; |
1083 autofill::test::SetProfileInfoWithGuid( | 1083 autofill::test::SetProfileInfoWithGuid( |
1084 native_profile, "23355099-1170-4B71-8ED4-144470CC9EBF", "Billing", | 1084 native_profile, "23355099-1170-4B71-8ED4-144470CC9EBF", "Billing", |
1085 "Mitchell", "Morrison", "johnwayne@me.xyz", "", "123 Zoo St.", "unit 5", | 1085 "Mitchell", "Morrison", "johnwayne@me.xyz", "", "123 Zoo St.", "unit 5", |
1086 "Hollywood", "CA", "91601", "US", "12345678910"); | 1086 "Hollywood", "CA", "91601", "US", "12345678910"); |
1087 native_profile->set_use_date(base::Time::FromTimeT(4321)); | 1087 native_profile->set_use_date(base::Time::FromTimeT(4321)); |
1088 | 1088 |
1089 AutofillProfile expected_profile(sync_profile); | 1089 AutofillProfile expected_profile(sync_profile); |
1090 expected_profile.SetRawInfo(NAME_FULL, | 1090 expected_profile.SetRawInfo(NAME_FULL, |
1091 ASCIIToUTF16("Billing Mitchell Morrison")); | 1091 ASCIIToUTF16("Billing Mitchell Morrison")); |
1092 expected_profile.set_use_count(2); | 1092 expected_profile.set_use_count(1); |
1093 expected_profile.set_use_date(native_profile->use_date()); | 1093 expected_profile.set_use_date(native_profile->use_date()); |
1094 | 1094 |
1095 std::vector<AutofillProfile*> native_profiles; | 1095 std::vector<AutofillProfile*> native_profiles; |
1096 native_profiles.push_back(native_profile); | 1096 native_profiles.push_back(native_profile); |
1097 EXPECT_CALL(autofill_table(), GetAutofillProfiles(_)) | 1097 EXPECT_CALL(autofill_table(), GetAutofillProfiles(_)) |
1098 .WillOnce(DoAll(SetArgumentPointee<0>(native_profiles), Return(true))); | 1098 .WillOnce(DoAll(SetArgumentPointee<0>(native_profiles), Return(true))); |
1099 EXPECT_CALL(autofill_table(), | 1099 EXPECT_CALL(autofill_table(), |
1100 AddAutofillProfile(MatchProfiles(expected_profile))) | 1100 AddAutofillProfile(MatchProfiles(expected_profile))) |
1101 .WillOnce(Return(true)); | 1101 .WillOnce(Return(true)); |
1102 EXPECT_CALL(autofill_table(), | 1102 EXPECT_CALL(autofill_table(), |
(...skipping 13 matching lines...) Expand all Loading... |
1116 GetAutofillProfilesFromSyncDBUnderProfileNode(&new_sync_profiles)); | 1116 GetAutofillProfilesFromSyncDBUnderProfileNode(&new_sync_profiles)); |
1117 ASSERT_EQ(1U, new_sync_profiles.size()); | 1117 ASSERT_EQ(1U, new_sync_profiles.size()); |
1118 // Check that key fields are the same. | 1118 // Check that key fields are the same. |
1119 EXPECT_TRUE(new_sync_profiles[0].IsSubsetOf(sync_profile, "en-US")); | 1119 EXPECT_TRUE(new_sync_profiles[0].IsSubsetOf(sync_profile, "en-US")); |
1120 // Make sure the additional information from the sync profile was kept. | 1120 // Make sure the additional information from the sync profile was kept. |
1121 EXPECT_EQ(ASCIIToUTF16("Fox"), | 1121 EXPECT_EQ(ASCIIToUTF16("Fox"), |
1122 new_sync_profiles[0].GetRawInfo(ServerFieldType::COMPANY_NAME)); | 1122 new_sync_profiles[0].GetRawInfo(ServerFieldType::COMPANY_NAME)); |
1123 // Check that the latest use date is saved. | 1123 // Check that the latest use date is saved. |
1124 EXPECT_EQ(base::Time::FromTimeT(4321), new_sync_profiles[0].use_date()); | 1124 EXPECT_EQ(base::Time::FromTimeT(4321), new_sync_profiles[0].use_date()); |
1125 // Check that the use counts were added (default value is 1). | 1125 // Check that the use counts were added (default value is 1). |
1126 EXPECT_EQ(2U, new_sync_profiles[0].use_count()); | 1126 EXPECT_EQ(1U, new_sync_profiles[0].use_count()); |
1127 } | 1127 } |
1128 | 1128 |
1129 // Tests that a sync with a new native profile that matches an a new sync | 1129 // Tests that a sync with a new native profile that matches an a new sync |
1130 // profile but with more information results in the native profile being deleted | 1130 // profile but with more information results in the native profile being deleted |
1131 // and replaced by the sync profile with the native profiles additional | 1131 // and replaced by the sync profile with the native profiles additional |
1132 // information merged in. The merge should happen even if the sync profile is | 1132 // information merged in. The merge should happen even if the sync profile is |
1133 // more recent. | 1133 // more recent. |
1134 TEST_F(ProfileSyncServiceAutofillTest, | 1134 TEST_F(ProfileSyncServiceAutofillTest, |
1135 HasNativeHasSyncMergeSimilarProfileCombine_NativeHasMoreInfo) { | 1135 HasNativeHasSyncMergeSimilarProfileCombine_NativeHasMoreInfo) { |
1136 // Create two almost identical profiles. The GUIDs are different and the | 1136 // Create two almost identical profiles. The GUIDs are different and the |
1137 // sync profile has no value for company name. | 1137 // sync profile has no value for company name. |
1138 AutofillProfile sync_profile; | 1138 AutofillProfile sync_profile; |
1139 autofill::test::SetProfileInfoWithGuid( | 1139 autofill::test::SetProfileInfoWithGuid( |
1140 &sync_profile, "23355099-1170-4B71-8ED4-144470CC9EBE", "Billing", | 1140 &sync_profile, "23355099-1170-4B71-8ED4-144470CC9EBE", "Billing", |
1141 "Mitchell", "Morrison", "johnwayne@me.xyz", "", "123 Zoo St.", "unit 5", | 1141 "Mitchell", "Morrison", "johnwayne@me.xyz", "", "123 Zoo St.", "unit 5", |
1142 "Hollywood", "CA", "91601", "US", "12345678910"); | 1142 "Hollywood", "CA", "91601", "US", "12345678910"); |
1143 sync_profile.set_use_date(base::Time::FromTimeT(4321)); | 1143 sync_profile.set_use_date(base::Time::FromTimeT(4321)); |
1144 | 1144 |
1145 AutofillProfile* native_profile = new AutofillProfile; | 1145 AutofillProfile* native_profile = new AutofillProfile; |
1146 autofill::test::SetProfileInfoWithGuid( | 1146 autofill::test::SetProfileInfoWithGuid( |
1147 native_profile, "23355099-1170-4B71-8ED4-144470CC9EBF", "Billing", | 1147 native_profile, "23355099-1170-4B71-8ED4-144470CC9EBF", "Billing", |
1148 "Mitchell", "Morrison", "johnwayne@me.xyz", "Fox", "123 Zoo St.", | 1148 "Mitchell", "Morrison", "johnwayne@me.xyz", "Fox", "123 Zoo St.", |
1149 "unit 5", "Hollywood", "CA", "91601", "US", "12345678910"); | 1149 "unit 5", "Hollywood", "CA", "91601", "US", "12345678910"); |
1150 native_profile->set_use_date(base::Time::FromTimeT(1234)); | 1150 native_profile->set_use_date(base::Time::FromTimeT(1234)); |
1151 | 1151 |
1152 AutofillProfile expected_profile(*native_profile); | 1152 AutofillProfile expected_profile(*native_profile); |
1153 expected_profile.SetRawInfo(NAME_FULL, | 1153 expected_profile.SetRawInfo(NAME_FULL, |
1154 ASCIIToUTF16("Billing Mitchell Morrison")); | 1154 ASCIIToUTF16("Billing Mitchell Morrison")); |
1155 expected_profile.set_use_date(sync_profile.use_date()); | 1155 expected_profile.set_use_date(sync_profile.use_date()); |
1156 expected_profile.set_use_count(2); | 1156 expected_profile.set_use_count(1); |
1157 | 1157 |
1158 std::vector<AutofillProfile*> native_profiles; | 1158 std::vector<AutofillProfile*> native_profiles; |
1159 native_profiles.push_back(native_profile); | 1159 native_profiles.push_back(native_profile); |
1160 EXPECT_CALL(autofill_table(), GetAutofillProfiles(_)) | 1160 EXPECT_CALL(autofill_table(), GetAutofillProfiles(_)) |
1161 .WillOnce(DoAll(SetArgumentPointee<0>(native_profiles), Return(true))); | 1161 .WillOnce(DoAll(SetArgumentPointee<0>(native_profiles), Return(true))); |
1162 EXPECT_CALL(autofill_table(), | 1162 EXPECT_CALL(autofill_table(), |
1163 AddAutofillProfile(MatchProfiles(expected_profile))) | 1163 AddAutofillProfile(MatchProfiles(expected_profile))) |
1164 .WillOnce(Return(true)); | 1164 .WillOnce(Return(true)); |
1165 EXPECT_CALL(autofill_table(), | 1165 EXPECT_CALL(autofill_table(), |
1166 RemoveAutofillProfile("23355099-1170-4B71-8ED4-144470CC9EBF")) | 1166 RemoveAutofillProfile("23355099-1170-4B71-8ED4-144470CC9EBF")) |
(...skipping 13 matching lines...) Expand all Loading... |
1180 ASSERT_EQ(1U, new_sync_profiles.size()); | 1180 ASSERT_EQ(1U, new_sync_profiles.size()); |
1181 // Check that key fields are the same. | 1181 // Check that key fields are the same. |
1182 EXPECT_TRUE(new_sync_profiles[0].IsSubsetOf(expected_profile, "en-US")); | 1182 EXPECT_TRUE(new_sync_profiles[0].IsSubsetOf(expected_profile, "en-US")); |
1183 // Make sure the addtional information of the native profile was saved into | 1183 // Make sure the addtional information of the native profile was saved into |
1184 // the sync profile. | 1184 // the sync profile. |
1185 EXPECT_EQ(ASCIIToUTF16("Fox"), | 1185 EXPECT_EQ(ASCIIToUTF16("Fox"), |
1186 new_sync_profiles[0].GetRawInfo(ServerFieldType::COMPANY_NAME)); | 1186 new_sync_profiles[0].GetRawInfo(ServerFieldType::COMPANY_NAME)); |
1187 // Check that the latest use date is saved. | 1187 // Check that the latest use date is saved. |
1188 EXPECT_EQ(base::Time::FromTimeT(4321), new_sync_profiles[0].use_date()); | 1188 EXPECT_EQ(base::Time::FromTimeT(4321), new_sync_profiles[0].use_date()); |
1189 // Check that the use counts were added (default value is 1). | 1189 // Check that the use counts were added (default value is 1). |
1190 EXPECT_EQ(2U, new_sync_profiles[0].use_count()); | 1190 EXPECT_EQ(1U, new_sync_profiles[0].use_count()); |
1191 } | 1191 } |
1192 | 1192 |
1193 // Tests that a sync with a new native profile that differ only by name a new | 1193 // Tests that a sync with a new native profile that differ only by name a new |
1194 // sync profile results in keeping both profiles. | 1194 // sync profile results in keeping both profiles. |
1195 TEST_F(ProfileSyncServiceAutofillTest, HasNativeHasSync_DifferentPrimaryInfo) { | 1195 TEST_F(ProfileSyncServiceAutofillTest, HasNativeHasSync_DifferentPrimaryInfo) { |
1196 AutofillProfile sync_profile; | 1196 AutofillProfile sync_profile; |
1197 autofill::test::SetProfileInfoWithGuid( | 1197 autofill::test::SetProfileInfoWithGuid( |
1198 &sync_profile, "23355099-1170-4B71-8ED4-144470CC9EBE", "Billing", | 1198 &sync_profile, "23355099-1170-4B71-8ED4-144470CC9EBE", "Billing", |
1199 "Mitchell", "Morrison", "johnwayne@me.xyz", "Fox", "123 Zoo St.", | 1199 "Mitchell", "Morrison", "johnwayne@me.xyz", "Fox", "123 Zoo St.", |
1200 "unit 5", "Hollywood", "CA", "91601", "US", "12345678910"); | 1200 "unit 5", "Hollywood", "CA", "91601", "US", "12345678910"); |
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1478 std::vector<AutofillEntry> sync_entries; | 1478 std::vector<AutofillEntry> sync_entries; |
1479 std::vector<AutofillProfile> sync_profiles; | 1479 std::vector<AutofillProfile> sync_profiles; |
1480 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&sync_entries, &sync_profiles)); | 1480 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&sync_entries, &sync_profiles)); |
1481 EXPECT_EQ(3U, sync_entries.size()); | 1481 EXPECT_EQ(3U, sync_entries.size()); |
1482 EXPECT_EQ(0U, sync_profiles.size()); | 1482 EXPECT_EQ(0U, sync_profiles.size()); |
1483 for (size_t i = 0; i < sync_entries.size(); i++) { | 1483 for (size_t i = 0; i < sync_entries.size(); i++) { |
1484 DVLOG(1) << "Entry " << i << ": " << sync_entries[i].key().name() | 1484 DVLOG(1) << "Entry " << i << ": " << sync_entries[i].key().name() |
1485 << ", " << sync_entries[i].key().value(); | 1485 << ", " << sync_entries[i].key().value(); |
1486 } | 1486 } |
1487 } | 1487 } |
OLD | NEW |