Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(224)

Side by Side Diff: components/browser_sync/profile_sync_service_autofill_unittest.cc

Issue 2403773002: Remove stl_util's STLDeleteContainerPointers from autofill. (Closed)
Patch Set: rebase Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 MOCK_METHOD1(GetAllAutofillEntries, 145 MOCK_METHOD1(GetAllAutofillEntries,
146 bool(std::vector<AutofillEntry>* entries)); // NOLINT 146 bool(std::vector<AutofillEntry>* entries)); // NOLINT
147 MOCK_METHOD4(GetAutofillTimestamps, 147 MOCK_METHOD4(GetAutofillTimestamps,
148 bool(const base::string16& name, // NOLINT 148 bool(const base::string16& name, // NOLINT
149 const base::string16& value, 149 const base::string16& value,
150 Time* date_created, 150 Time* date_created,
151 Time* date_last_used)); 151 Time* date_last_used));
152 MOCK_METHOD1(UpdateAutofillEntries, 152 MOCK_METHOD1(UpdateAutofillEntries,
153 bool(const std::vector<AutofillEntry>&)); // NOLINT 153 bool(const std::vector<AutofillEntry>&)); // NOLINT
154 MOCK_METHOD1(GetAutofillProfiles, 154 MOCK_METHOD1(GetAutofillProfiles,
155 bool(std::vector<AutofillProfile*>*)); // NOLINT 155 bool(std::vector<std::unique_ptr<AutofillProfile>>*)); // NOLINT
156 MOCK_METHOD1(UpdateAutofillProfile, bool(const AutofillProfile&)); // NOLINT 156 MOCK_METHOD1(UpdateAutofillProfile, bool(const AutofillProfile&)); // NOLINT
157 MOCK_METHOD1(AddAutofillProfile, bool(const AutofillProfile&)); // NOLINT 157 MOCK_METHOD1(AddAutofillProfile, bool(const AutofillProfile&)); // NOLINT
158 MOCK_METHOD1(RemoveAutofillProfile, bool(const std::string&)); // NOLINT 158 MOCK_METHOD1(RemoveAutofillProfile, bool(const std::string&)); // NOLINT
159 }; 159 };
160 160
161 MATCHER_P(MatchProfiles, profile, "") { 161 MATCHER_P(MatchProfiles, profile, "") {
162 return (profile.Compare(arg) == 0); 162 return (profile.Compare(arg) == 0);
163 } 163 }
164 164
165 ACTION_P(LoadAutofillProfiles, datafunc) {
166 std::vector<std::unique_ptr<AutofillProfile>> profiles =
167 std::move(datafunc());
168 arg0->swap(profiles);
169 }
170
165 class WebDatabaseFake : public WebDatabase { 171 class WebDatabaseFake : public WebDatabase {
166 public: 172 public:
167 explicit WebDatabaseFake(AutofillTable* autofill_table) { 173 explicit WebDatabaseFake(AutofillTable* autofill_table) {
168 AddTable(autofill_table); 174 AddTable(autofill_table);
169 } 175 }
170 }; 176 };
171 177
172 class MockAutofillBackend : public autofill::AutofillWebDataBackend { 178 class MockAutofillBackend : public autofill::AutofillWebDataBackend {
173 public: 179 public:
174 MockAutofillBackend( 180 MockAutofillBackend(
(...skipping 666 matching lines...) Expand 10 before | Expand all | Expand 10 after
841 ASSERT_TRUE(create_root.success()); 847 ASSERT_TRUE(create_root.success());
842 std::vector<AutofillEntry> sync_entries; 848 std::vector<AutofillEntry> sync_entries;
843 std::vector<AutofillProfile> sync_profiles; 849 std::vector<AutofillProfile> sync_profiles;
844 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&sync_entries, &sync_profiles)); 850 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&sync_entries, &sync_profiles));
845 ASSERT_EQ(1U, entries.size()); 851 ASSERT_EQ(1U, entries.size());
846 EXPECT_TRUE(entries[0] == sync_entries[0]); 852 EXPECT_TRUE(entries[0] == sync_entries[0]);
847 EXPECT_EQ(0U, sync_profiles.size()); 853 EXPECT_EQ(0U, sync_profiles.size());
848 } 854 }
849 855
850 TEST_F(ProfileSyncServiceAutofillTest, HasProfileEmptySync) { 856 TEST_F(ProfileSyncServiceAutofillTest, HasProfileEmptySync) {
851 std::vector<AutofillProfile*> profiles; 857 std::vector<std::unique_ptr<AutofillProfile>> profiles;
852 std::vector<AutofillProfile> expected_profiles; 858 std::vector<AutofillProfile> expected_profiles;
853 // Owned by GetAutofillProfiles caller. 859 std::unique_ptr<AutofillProfile> profile0 =
854 AutofillProfile* profile0 = new AutofillProfile; 860 base::MakeUnique<AutofillProfile>();
855 autofill::test::SetProfileInfoWithGuid( 861 autofill::test::SetProfileInfoWithGuid(
856 profile0, "54B3F9AA-335E-4F71-A27D-719C41564230", "Billing", "Mitchell", 862 profile0.get(), "54B3F9AA-335E-4F71-A27D-719C41564230", "Billing",
857 "Morrison", "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", 863 "Mitchell", "Morrison", "johnwayne@me.xyz", "Fox", "123 Zoo St.",
858 "Hollywood", "CA", "91601", "US", "12345678910"); 864 "unit 5", "Hollywood", "CA", "91601", "US", "12345678910");
859 profiles.push_back(profile0);
860 expected_profiles.push_back(*profile0); 865 expected_profiles.push_back(*profile0);
866 profiles.push_back(std::move(profile0));
867 auto profile_returner = [&profiles]() { return std::move(profiles); };
861 EXPECT_CALL(autofill_table(), GetAutofillProfiles(_)) 868 EXPECT_CALL(autofill_table(), GetAutofillProfiles(_))
862 .WillOnce(DoAll(SetArgumentPointee<0>(profiles), Return(true))); 869 .WillOnce(DoAll(LoadAutofillProfiles(profile_returner), Return(true)));
863 EXPECT_CALL(personal_data_manager(), Refresh()); 870 EXPECT_CALL(personal_data_manager(), Refresh());
864 SetIdleChangeProcessorExpectations(); 871 SetIdleChangeProcessorExpectations();
865 CreateRootHelper create_root(this, AUTOFILL_PROFILE); 872 CreateRootHelper create_root(this, AUTOFILL_PROFILE);
866 StartSyncService(create_root.callback(), false, AUTOFILL_PROFILE); 873 StartSyncService(create_root.callback(), false, AUTOFILL_PROFILE);
867 ASSERT_TRUE(create_root.success()); 874 ASSERT_TRUE(create_root.success());
868 std::vector<AutofillProfile> sync_profiles; 875 std::vector<AutofillProfile> sync_profiles;
869 ASSERT_TRUE(GetAutofillProfilesFromSyncDBUnderProfileNode(&sync_profiles)); 876 ASSERT_TRUE(GetAutofillProfilesFromSyncDBUnderProfileNode(&sync_profiles));
870 EXPECT_EQ(1U, sync_profiles.size()); 877 EXPECT_EQ(1U, sync_profiles.size());
871 EXPECT_EQ(0, expected_profiles[0].Compare(sync_profiles[0])); 878 EXPECT_EQ(0, expected_profiles[0].Compare(sync_profiles[0]));
872 } 879 }
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
956 EXPECT_TRUE(merged_entry == new_sync_entries[0]); 963 EXPECT_TRUE(merged_entry == new_sync_entries[0]);
957 } 964 }
958 965
959 TEST_F(ProfileSyncServiceAutofillTest, HasNativeHasSyncMergeProfile) { 966 TEST_F(ProfileSyncServiceAutofillTest, HasNativeHasSyncMergeProfile) {
960 AutofillProfile sync_profile; 967 AutofillProfile sync_profile;
961 autofill::test::SetProfileInfoWithGuid( 968 autofill::test::SetProfileInfoWithGuid(
962 &sync_profile, "23355099-1170-4B71-8ED4-144470CC9EBE", "Billing", 969 &sync_profile, "23355099-1170-4B71-8ED4-144470CC9EBE", "Billing",
963 "Mitchell", "Morrison", "johnwayne@me.xyz", "Fox", "123 Zoo St.", 970 "Mitchell", "Morrison", "johnwayne@me.xyz", "Fox", "123 Zoo St.",
964 "unit 5", "Hollywood", "CA", "91601", "US", "12345678910"); 971 "unit 5", "Hollywood", "CA", "91601", "US", "12345678910");
965 972
966 AutofillProfile* native_profile = new AutofillProfile; 973 std::unique_ptr<AutofillProfile> native_profile =
974 base::MakeUnique<AutofillProfile>();
967 autofill::test::SetProfileInfoWithGuid( 975 autofill::test::SetProfileInfoWithGuid(
968 native_profile, "23355099-1170-4B71-8ED4-144470CC9EBE", "Billing", 976 native_profile.get(), "23355099-1170-4B71-8ED4-144470CC9EBE", "Billing",
969 "Alicia", "Saenz", "joewayne@me.xyz", "Fox", "1212 Center.", "Bld. 5", 977 "Alicia", "Saenz", "joewayne@me.xyz", "Fox", "1212 Center.", "Bld. 5",
970 "Orlando", "FL", "32801", "US", "19482937549"); 978 "Orlando", "FL", "32801", "US", "19482937549");
971 979
972 std::vector<AutofillProfile*> native_profiles; 980 std::vector<std::unique_ptr<AutofillProfile>> native_profiles;
973 native_profiles.push_back(native_profile); 981 native_profiles.push_back(std::move(native_profile));
982 auto profile_returner = [&native_profiles]() {
983 return std::move(native_profiles);
984 };
974 EXPECT_CALL(autofill_table(), GetAutofillProfiles(_)) 985 EXPECT_CALL(autofill_table(), GetAutofillProfiles(_))
975 .WillOnce(DoAll(SetArgumentPointee<0>(native_profiles), Return(true))); 986 .WillOnce(DoAll(LoadAutofillProfiles(profile_returner), Return(true)));
976 987
977 std::vector<AutofillProfile> sync_profiles; 988 std::vector<AutofillProfile> sync_profiles;
978 sync_profiles.push_back(sync_profile); 989 sync_profiles.push_back(sync_profile);
979 AddAutofillHelper<AutofillProfile> add_autofill(this, sync_profiles); 990 AddAutofillHelper<AutofillProfile> add_autofill(this, sync_profiles);
980 991
981 EXPECT_CALL(autofill_table(), 992 EXPECT_CALL(autofill_table(),
982 UpdateAutofillProfile(MatchProfiles(sync_profile))) 993 UpdateAutofillProfile(MatchProfiles(sync_profile)))
983 .WillOnce(Return(true)); 994 .WillOnce(Return(true));
984 EXPECT_CALL(personal_data_manager(), Refresh()); 995 EXPECT_CALL(personal_data_manager(), Refresh());
985 StartSyncService(add_autofill.callback(), false, AUTOFILL_PROFILE); 996 StartSyncService(add_autofill.callback(), false, AUTOFILL_PROFILE);
(...skipping 14 matching lines...) Expand all
1000 HasNativeHasSyncMergeSimilarProfileCombine_SyncHasMoreInfoAndMoreRecent) { 1011 HasNativeHasSyncMergeSimilarProfileCombine_SyncHasMoreInfoAndMoreRecent) {
1001 // Create two almost identical profiles. The GUIDs are different and the 1012 // Create two almost identical profiles. The GUIDs are different and the
1002 // native profile has no value for company name. 1013 // native profile has no value for company name.
1003 AutofillProfile sync_profile; 1014 AutofillProfile sync_profile;
1004 autofill::test::SetProfileInfoWithGuid( 1015 autofill::test::SetProfileInfoWithGuid(
1005 &sync_profile, "23355099-1170-4B71-8ED4-144470CC9EBE", "Billing", 1016 &sync_profile, "23355099-1170-4B71-8ED4-144470CC9EBE", "Billing",
1006 "Mitchell", "Morrison", "johnwayne@me.xyz", "Fox", "123 Zoo St.", 1017 "Mitchell", "Morrison", "johnwayne@me.xyz", "Fox", "123 Zoo St.",
1007 "unit 5", "Hollywood", "CA", "91601", "US", "12345678910"); 1018 "unit 5", "Hollywood", "CA", "91601", "US", "12345678910");
1008 sync_profile.set_use_date(base::Time::FromTimeT(4321)); 1019 sync_profile.set_use_date(base::Time::FromTimeT(4321));
1009 1020
1010 AutofillProfile* native_profile = new AutofillProfile; 1021 std::unique_ptr<AutofillProfile> native_profile =
1022 base::MakeUnique<AutofillProfile>();
1011 autofill::test::SetProfileInfoWithGuid( 1023 autofill::test::SetProfileInfoWithGuid(
1012 native_profile, "23355099-1170-4B71-8ED4-144470CC9EBF", "Billing", 1024 native_profile.get(), "23355099-1170-4B71-8ED4-144470CC9EBF", "Billing",
1013 "Mitchell", "Morrison", "johnwayne@me.xyz", "", "123 Zoo St.", "unit 5", 1025 "Mitchell", "Morrison", "johnwayne@me.xyz", "", "123 Zoo St.", "unit 5",
1014 "Hollywood", "CA", "91601", "US", "12345678910"); 1026 "Hollywood", "CA", "91601", "US", "12345678910");
1015 native_profile->set_use_date(base::Time::FromTimeT(1234)); 1027 native_profile->set_use_date(base::Time::FromTimeT(1234));
1016 1028
1017 AutofillProfile expected_profile(sync_profile); 1029 AutofillProfile expected_profile(sync_profile);
1018 expected_profile.SetRawInfo(NAME_FULL, 1030 expected_profile.SetRawInfo(NAME_FULL,
1019 ASCIIToUTF16("Billing Mitchell Morrison")); 1031 ASCIIToUTF16("Billing Mitchell Morrison"));
1020 expected_profile.set_use_count(1); 1032 expected_profile.set_use_count(1);
1021 1033
1022 std::vector<AutofillProfile*> native_profiles; 1034 std::vector<std::unique_ptr<AutofillProfile>> native_profiles;
1023 native_profiles.push_back(native_profile); 1035 native_profiles.push_back(std::move(native_profile));
1036 auto profile_returner = [&native_profiles]() {
1037 return std::move(native_profiles);
1038 };
1024 EXPECT_CALL(autofill_table(), GetAutofillProfiles(_)) 1039 EXPECT_CALL(autofill_table(), GetAutofillProfiles(_))
1025 .WillOnce(DoAll(SetArgumentPointee<0>(native_profiles), Return(true))); 1040 .WillOnce(DoAll(LoadAutofillProfiles(profile_returner), Return(true)));
1026 EXPECT_CALL(autofill_table(), 1041 EXPECT_CALL(autofill_table(),
1027 AddAutofillProfile(MatchProfiles(expected_profile))) 1042 AddAutofillProfile(MatchProfiles(expected_profile)))
1028 .WillOnce(Return(true)); 1043 .WillOnce(Return(true));
1029 EXPECT_CALL(autofill_table(), 1044 EXPECT_CALL(autofill_table(),
1030 RemoveAutofillProfile("23355099-1170-4B71-8ED4-144470CC9EBF")) 1045 RemoveAutofillProfile("23355099-1170-4B71-8ED4-144470CC9EBF"))
1031 .WillOnce(Return(true)); 1046 .WillOnce(Return(true));
1032 std::vector<AutofillProfile> sync_profiles; 1047 std::vector<AutofillProfile> sync_profiles;
1033 sync_profiles.push_back(sync_profile); 1048 sync_profiles.push_back(sync_profile);
1034 AddAutofillHelper<AutofillProfile> add_autofill(this, sync_profiles); 1049 AddAutofillHelper<AutofillProfile> add_autofill(this, sync_profiles);
1035 1050
(...skipping 24 matching lines...) Expand all
1060 HasNativeHasSyncMergeSimilarProfileCombine_SyncHasMoreInfoAndOlder) { 1075 HasNativeHasSyncMergeSimilarProfileCombine_SyncHasMoreInfoAndOlder) {
1061 // Create two almost identical profiles. The GUIDs are different and the 1076 // Create two almost identical profiles. The GUIDs are different and the
1062 // native profile has no value for company name. 1077 // native profile has no value for company name.
1063 AutofillProfile sync_profile; 1078 AutofillProfile sync_profile;
1064 autofill::test::SetProfileInfoWithGuid( 1079 autofill::test::SetProfileInfoWithGuid(
1065 &sync_profile, "23355099-1170-4B71-8ED4-144470CC9EBE", "Billing", 1080 &sync_profile, "23355099-1170-4B71-8ED4-144470CC9EBE", "Billing",
1066 "Mitchell", "Morrison", "johnwayne@me.xyz", "Fox", "123 Zoo St.", 1081 "Mitchell", "Morrison", "johnwayne@me.xyz", "Fox", "123 Zoo St.",
1067 "unit 5", "Hollywood", "CA", "91601", "US", "12345678910"); 1082 "unit 5", "Hollywood", "CA", "91601", "US", "12345678910");
1068 sync_profile.set_use_date(base::Time::FromTimeT(1234)); 1083 sync_profile.set_use_date(base::Time::FromTimeT(1234));
1069 1084
1070 AutofillProfile* native_profile = new AutofillProfile; 1085 std::unique_ptr<AutofillProfile> native_profile =
1086 base::MakeUnique<AutofillProfile>();
1071 autofill::test::SetProfileInfoWithGuid( 1087 autofill::test::SetProfileInfoWithGuid(
1072 native_profile, "23355099-1170-4B71-8ED4-144470CC9EBF", "Billing", 1088 native_profile.get(), "23355099-1170-4B71-8ED4-144470CC9EBF", "Billing",
1073 "Mitchell", "Morrison", "johnwayne@me.xyz", "", "123 Zoo St.", "unit 5", 1089 "Mitchell", "Morrison", "johnwayne@me.xyz", "", "123 Zoo St.", "unit 5",
1074 "Hollywood", "CA", "91601", "US", "12345678910"); 1090 "Hollywood", "CA", "91601", "US", "12345678910");
1075 native_profile->set_use_date(base::Time::FromTimeT(4321)); 1091 native_profile->set_use_date(base::Time::FromTimeT(4321));
1076 1092
1077 AutofillProfile expected_profile(sync_profile); 1093 AutofillProfile expected_profile(sync_profile);
1078 expected_profile.SetRawInfo(NAME_FULL, 1094 expected_profile.SetRawInfo(NAME_FULL,
1079 ASCIIToUTF16("Billing Mitchell Morrison")); 1095 ASCIIToUTF16("Billing Mitchell Morrison"));
1080 expected_profile.set_use_count(1); 1096 expected_profile.set_use_count(1);
1081 expected_profile.set_use_date(native_profile->use_date()); 1097 expected_profile.set_use_date(native_profile->use_date());
1082 1098
1083 std::vector<AutofillProfile*> native_profiles; 1099 std::vector<std::unique_ptr<AutofillProfile>> native_profiles;
1084 native_profiles.push_back(native_profile); 1100 native_profiles.push_back(std::move(native_profile));
1101 auto profile_returner = [&native_profiles]() {
1102 return std::move(native_profiles);
1103 };
1085 EXPECT_CALL(autofill_table(), GetAutofillProfiles(_)) 1104 EXPECT_CALL(autofill_table(), GetAutofillProfiles(_))
1086 .WillOnce(DoAll(SetArgumentPointee<0>(native_profiles), Return(true))); 1105 .WillOnce(DoAll(LoadAutofillProfiles(profile_returner), Return(true)));
1087 EXPECT_CALL(autofill_table(), 1106 EXPECT_CALL(autofill_table(),
1088 AddAutofillProfile(MatchProfiles(expected_profile))) 1107 AddAutofillProfile(MatchProfiles(expected_profile)))
1089 .WillOnce(Return(true)); 1108 .WillOnce(Return(true));
1090 EXPECT_CALL(autofill_table(), 1109 EXPECT_CALL(autofill_table(),
1091 RemoveAutofillProfile("23355099-1170-4B71-8ED4-144470CC9EBF")) 1110 RemoveAutofillProfile("23355099-1170-4B71-8ED4-144470CC9EBF"))
1092 .WillOnce(Return(true)); 1111 .WillOnce(Return(true));
1093 std::vector<AutofillProfile> sync_profiles; 1112 std::vector<AutofillProfile> sync_profiles;
1094 sync_profiles.push_back(sync_profile); 1113 sync_profiles.push_back(sync_profile);
1095 AddAutofillHelper<AutofillProfile> add_autofill(this, sync_profiles); 1114 AddAutofillHelper<AutofillProfile> add_autofill(this, sync_profiles);
1096 1115
(...skipping 26 matching lines...) Expand all
1123 HasNativeHasSyncMergeSimilarProfileCombine_NativeHasMoreInfo) { 1142 HasNativeHasSyncMergeSimilarProfileCombine_NativeHasMoreInfo) {
1124 // Create two almost identical profiles. The GUIDs are different and the 1143 // Create two almost identical profiles. The GUIDs are different and the
1125 // sync profile has no value for company name. 1144 // sync profile has no value for company name.
1126 AutofillProfile sync_profile; 1145 AutofillProfile sync_profile;
1127 autofill::test::SetProfileInfoWithGuid( 1146 autofill::test::SetProfileInfoWithGuid(
1128 &sync_profile, "23355099-1170-4B71-8ED4-144470CC9EBE", "Billing", 1147 &sync_profile, "23355099-1170-4B71-8ED4-144470CC9EBE", "Billing",
1129 "Mitchell", "Morrison", "johnwayne@me.xyz", "", "123 Zoo St.", "unit 5", 1148 "Mitchell", "Morrison", "johnwayne@me.xyz", "", "123 Zoo St.", "unit 5",
1130 "Hollywood", "CA", "91601", "US", "12345678910"); 1149 "Hollywood", "CA", "91601", "US", "12345678910");
1131 sync_profile.set_use_date(base::Time::FromTimeT(4321)); 1150 sync_profile.set_use_date(base::Time::FromTimeT(4321));
1132 1151
1133 AutofillProfile* native_profile = new AutofillProfile; 1152 std::unique_ptr<AutofillProfile> native_profile =
1153 base::MakeUnique<AutofillProfile>();
1134 autofill::test::SetProfileInfoWithGuid( 1154 autofill::test::SetProfileInfoWithGuid(
1135 native_profile, "23355099-1170-4B71-8ED4-144470CC9EBF", "Billing", 1155 native_profile.get(), "23355099-1170-4B71-8ED4-144470CC9EBF", "Billing",
1136 "Mitchell", "Morrison", "johnwayne@me.xyz", "Fox", "123 Zoo St.", 1156 "Mitchell", "Morrison", "johnwayne@me.xyz", "Fox", "123 Zoo St.",
1137 "unit 5", "Hollywood", "CA", "91601", "US", "12345678910"); 1157 "unit 5", "Hollywood", "CA", "91601", "US", "12345678910");
1138 native_profile->set_use_date(base::Time::FromTimeT(1234)); 1158 native_profile->set_use_date(base::Time::FromTimeT(1234));
1139 1159
1140 AutofillProfile expected_profile(*native_profile); 1160 AutofillProfile expected_profile(*native_profile);
1141 expected_profile.SetRawInfo(NAME_FULL, 1161 expected_profile.SetRawInfo(NAME_FULL,
1142 ASCIIToUTF16("Billing Mitchell Morrison")); 1162 ASCIIToUTF16("Billing Mitchell Morrison"));
1143 expected_profile.set_use_date(sync_profile.use_date()); 1163 expected_profile.set_use_date(sync_profile.use_date());
1144 expected_profile.set_use_count(1); 1164 expected_profile.set_use_count(1);
1145 1165
1146 std::vector<AutofillProfile*> native_profiles; 1166 std::vector<std::unique_ptr<AutofillProfile>> native_profiles;
1147 native_profiles.push_back(native_profile); 1167 native_profiles.push_back(std::move(native_profile));
1168 auto profile_returner = [&native_profiles]() {
1169 return std::move(native_profiles);
1170 };
1148 EXPECT_CALL(autofill_table(), GetAutofillProfiles(_)) 1171 EXPECT_CALL(autofill_table(), GetAutofillProfiles(_))
1149 .WillOnce(DoAll(SetArgumentPointee<0>(native_profiles), Return(true))); 1172 .WillOnce(DoAll(LoadAutofillProfiles(profile_returner), Return(true)));
1150 EXPECT_CALL(autofill_table(), 1173 EXPECT_CALL(autofill_table(),
1151 AddAutofillProfile(MatchProfiles(expected_profile))) 1174 AddAutofillProfile(MatchProfiles(expected_profile)))
1152 .WillOnce(Return(true)); 1175 .WillOnce(Return(true));
1153 EXPECT_CALL(autofill_table(), 1176 EXPECT_CALL(autofill_table(),
1154 RemoveAutofillProfile("23355099-1170-4B71-8ED4-144470CC9EBF")) 1177 RemoveAutofillProfile("23355099-1170-4B71-8ED4-144470CC9EBF"))
1155 .WillOnce(Return(true)); 1178 .WillOnce(Return(true));
1156 std::vector<AutofillProfile> sync_profiles; 1179 std::vector<AutofillProfile> sync_profiles;
1157 sync_profiles.push_back(sync_profile); 1180 sync_profiles.push_back(sync_profile);
1158 AddAutofillHelper<AutofillProfile> add_autofill(this, sync_profiles); 1181 AddAutofillHelper<AutofillProfile> add_autofill(this, sync_profiles);
1159 1182
1160 EXPECT_CALL(personal_data_manager(), Refresh()); 1183 EXPECT_CALL(personal_data_manager(), Refresh());
1161 // Adds all entries in |sync_profiles| to sync. 1184 // Adds all entries in |sync_profiles| to sync.
1162 StartSyncService(add_autofill.callback(), false, AUTOFILL_PROFILE); 1185 StartSyncService(add_autofill.callback(), false, AUTOFILL_PROFILE);
1163 ASSERT_TRUE(add_autofill.success()); 1186 ASSERT_TRUE(add_autofill.success());
1164 1187
1165 std::vector<AutofillProfile> new_sync_profiles; 1188 std::vector<AutofillProfile> new_sync_profiles;
1166 ASSERT_TRUE( 1189 ASSERT_TRUE(
1167 GetAutofillProfilesFromSyncDBUnderProfileNode(&new_sync_profiles)); 1190 GetAutofillProfilesFromSyncDBUnderProfileNode(&new_sync_profiles));
1168 ASSERT_EQ(1U, new_sync_profiles.size()); 1191 ASSERT_EQ(1U, new_sync_profiles.size());
1169 // Check that key fields are the same. 1192 // Check that key fields are the same.
1170 EXPECT_TRUE(new_sync_profiles[0].IsSubsetOf(expected_profile, "en-US")); 1193 EXPECT_TRUE(new_sync_profiles[0].IsSubsetOf(expected_profile, "en-US"));
1171 // Make sure the addtional information of the native profile was saved into 1194 // Make sure the additional information of the native profile was saved into
1172 // the sync profile. 1195 // the sync profile.
1173 EXPECT_EQ(ASCIIToUTF16("Fox"), 1196 EXPECT_EQ(ASCIIToUTF16("Fox"),
1174 new_sync_profiles[0].GetRawInfo(ServerFieldType::COMPANY_NAME)); 1197 new_sync_profiles[0].GetRawInfo(ServerFieldType::COMPANY_NAME));
1175 // Check that the latest use date is saved. 1198 // Check that the latest use date is saved.
1176 EXPECT_EQ(base::Time::FromTimeT(4321), new_sync_profiles[0].use_date()); 1199 EXPECT_EQ(base::Time::FromTimeT(4321), new_sync_profiles[0].use_date());
1177 // Check that the use counts were added (default value is 1). 1200 // Check that the use counts were added (default value is 1).
1178 EXPECT_EQ(1U, new_sync_profiles[0].use_count()); 1201 EXPECT_EQ(1U, new_sync_profiles[0].use_count());
1179 } 1202 }
1180 1203
1181 // Tests that a sync with a new native profile that differ only by name a new 1204 // Tests that a sync with a new native profile that differ only by name a new
1182 // sync profile results in keeping both profiles. 1205 // sync profile results in keeping both profiles.
1183 TEST_F(ProfileSyncServiceAutofillTest, HasNativeHasSync_DifferentPrimaryInfo) { 1206 TEST_F(ProfileSyncServiceAutofillTest, HasNativeHasSync_DifferentPrimaryInfo) {
1184 AutofillProfile sync_profile; 1207 AutofillProfile sync_profile;
1185 autofill::test::SetProfileInfoWithGuid( 1208 autofill::test::SetProfileInfoWithGuid(
1186 &sync_profile, "23355099-1170-4B71-8ED4-144470CC9EBE", "Billing", 1209 &sync_profile, "23355099-1170-4B71-8ED4-144470CC9EBE", "Billing",
1187 "Mitchell", "Morrison", "johnwayne@me.xyz", "Fox", "123 Zoo St.", 1210 "Mitchell", "Morrison", "johnwayne@me.xyz", "Fox", "123 Zoo St.",
1188 "unit 5", "Hollywood", "CA", "91601", "US", "12345678910"); 1211 "unit 5", "Hollywood", "CA", "91601", "US", "12345678910");
1189 sync_profile.set_use_date(base::Time::FromTimeT(4321)); 1212 sync_profile.set_use_date(base::Time::FromTimeT(4321));
1190 1213
1191 AutofillProfile* native_profile = new AutofillProfile; 1214 std::unique_ptr<AutofillProfile> native_profile =
1215 base::MakeUnique<AutofillProfile>();
1192 autofill::test::SetProfileInfoWithGuid( 1216 autofill::test::SetProfileInfoWithGuid(
1193 native_profile, "23355099-1170-4B71-8ED4-144470CC9EBF", "Billing", "John", 1217 native_profile.get(), "23355099-1170-4B71-8ED4-144470CC9EBF", "Billing",
1194 "Smith", "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", "Hollywood", 1218 "John", "Smith", "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5",
1195 "CA", "91601", "US", "12345678910"); 1219 "Hollywood", "CA", "91601", "US", "12345678910");
1196 native_profile->set_use_date(base::Time::FromTimeT(1234)); 1220 native_profile->set_use_date(base::Time::FromTimeT(1234));
1197 1221
1198 std::vector<AutofillProfile*> native_profiles; 1222 std::vector<std::unique_ptr<AutofillProfile>> native_profiles;
1199 native_profiles.push_back(native_profile); 1223 native_profiles.push_back(std::move(native_profile));
1224 auto profile_returner = [&native_profiles]() {
1225 return std::move(native_profiles);
1226 };
1200 EXPECT_CALL(autofill_table(), GetAutofillProfiles(_)) 1227 EXPECT_CALL(autofill_table(), GetAutofillProfiles(_))
1201 .WillOnce(DoAll(SetArgumentPointee<0>(native_profiles), Return(true))); 1228 .WillOnce(DoAll(LoadAutofillProfiles(profile_returner), Return(true)));
1202 EXPECT_CALL(autofill_table(), AddAutofillProfile(MatchProfiles(sync_profile))) 1229 EXPECT_CALL(autofill_table(), AddAutofillProfile(MatchProfiles(sync_profile)))
1203 .WillOnce(Return(true)); 1230 .WillOnce(Return(true));
1204 std::vector<AutofillProfile> sync_profiles; 1231 std::vector<AutofillProfile> sync_profiles;
1205 sync_profiles.push_back(sync_profile); 1232 sync_profiles.push_back(sync_profile);
1206 AddAutofillHelper<AutofillProfile> add_autofill(this, sync_profiles); 1233 AddAutofillHelper<AutofillProfile> add_autofill(this, sync_profiles);
1207 1234
1208 EXPECT_CALL(personal_data_manager(), Refresh()); 1235 EXPECT_CALL(personal_data_manager(), Refresh());
1209 // Adds all entries in |sync_profiles| to sync. 1236 // Adds all entries in |sync_profiles| to sync.
1210 StartSyncService(add_autofill.callback(), false, AUTOFILL_PROFILE); 1237 StartSyncService(add_autofill.callback(), false, AUTOFILL_PROFILE);
1211 ASSERT_TRUE(add_autofill.success()); 1238 ASSERT_TRUE(add_autofill.success());
(...skipping 12 matching lines...) Expand all
1224 AutofillProfile sync_profile; 1251 AutofillProfile sync_profile;
1225 1252
1226 autofill::test::SetProfileInfoWithGuid( 1253 autofill::test::SetProfileInfoWithGuid(
1227 &sync_profile, "23355099-1170-4B71-8ED4-144470CC9EBE", "Billing", 1254 &sync_profile, "23355099-1170-4B71-8ED4-144470CC9EBE", "Billing",
1228 "Mitchell", "Morrison", "johnwayne@me.xyz", "Fox", "123 Zoo St.", 1255 "Mitchell", "Morrison", "johnwayne@me.xyz", "Fox", "123 Zoo St.",
1229 "unit 5", "Hollywood", "CA", "91601", "US", "12345678910"); 1256 "unit 5", "Hollywood", "CA", "91601", "US", "12345678910");
1230 sync_profile.set_use_count(20); 1257 sync_profile.set_use_count(20);
1231 sync_profile.set_use_date(base::Time::FromTimeT(1234)); 1258 sync_profile.set_use_date(base::Time::FromTimeT(1234));
1232 1259
1233 std::string native_guid = "EDC609ED-7EEE-4F27-B00C-423242A9C44B"; 1260 std::string native_guid = "EDC609ED-7EEE-4F27-B00C-423242A9C44B";
1234 AutofillProfile* native_profile = new AutofillProfile; 1261 std::unique_ptr<AutofillProfile> native_profile =
1262 base::MakeUnique<AutofillProfile>();
1235 autofill::test::SetProfileInfoWithGuid( 1263 autofill::test::SetProfileInfoWithGuid(
1236 native_profile, native_guid.c_str(), "Billing", "Mitchell", "Morrison", 1264 native_profile.get(), native_guid.c_str(), "Billing", "Mitchell",
1237 "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", "Hollywood", "CA", 1265 "Morrison", "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5",
1238 "91601", "US", "12345678910"); 1266 "Hollywood", "CA", "91601", "US", "12345678910");
1239 native_profile->set_use_count(5); 1267 native_profile->set_use_count(5);
1240 native_profile->set_use_date(base::Time::FromTimeT(4321)); 1268 native_profile->set_use_date(base::Time::FromTimeT(4321));
1241 1269
1242 std::vector<AutofillProfile*> native_profiles; 1270 std::vector<std::unique_ptr<AutofillProfile>> native_profiles;
1243 native_profiles.push_back(native_profile); 1271 native_profiles.push_back(std::move(native_profile));
1272 auto profile_returner = [&native_profiles]() {
1273 return std::move(native_profiles);
1274 };
1244 EXPECT_CALL(autofill_table(), GetAutofillProfiles(_)) 1275 EXPECT_CALL(autofill_table(), GetAutofillProfiles(_))
1245 .WillOnce(DoAll(SetArgumentPointee<0>(native_profiles), Return(true))); 1276 .WillOnce(DoAll(LoadAutofillProfiles(profile_returner), Return(true)));
1246 1277
1247 std::vector<AutofillProfile> sync_profiles; 1278 std::vector<AutofillProfile> sync_profiles;
1248 sync_profiles.push_back(sync_profile); 1279 sync_profiles.push_back(sync_profile);
1249 AddAutofillHelper<AutofillProfile> add_autofill(this, sync_profiles); 1280 AddAutofillHelper<AutofillProfile> add_autofill(this, sync_profiles);
1250 1281
1251 EXPECT_CALL(autofill_table(), AddAutofillProfile(_)).WillOnce(Return(true)); 1282 EXPECT_CALL(autofill_table(), AddAutofillProfile(_)).WillOnce(Return(true));
1252 EXPECT_CALL(autofill_table(), RemoveAutofillProfile(native_guid)) 1283 EXPECT_CALL(autofill_table(), RemoveAutofillProfile(native_guid))
1253 .WillOnce(Return(true)); 1284 .WillOnce(Return(true));
1254 EXPECT_CALL(personal_data_manager(), Refresh()); 1285 EXPECT_CALL(personal_data_manager(), Refresh());
1255 StartSyncService(add_autofill.callback(), false, AUTOFILL_PROFILE); 1286 StartSyncService(add_autofill.callback(), false, AUTOFILL_PROFILE);
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
1378 GetAutofillEntriesFromSyncDB(&new_sync_entries, &new_sync_profiles)); 1409 GetAutofillEntriesFromSyncDB(&new_sync_entries, &new_sync_profiles));
1379 ASSERT_EQ(0U, new_sync_entries.size()); 1410 ASSERT_EQ(0U, new_sync_entries.size());
1380 } 1411 }
1381 1412
1382 TEST_F(ProfileSyncServiceAutofillTest, ProcessUserChangeRemoveProfile) { 1413 TEST_F(ProfileSyncServiceAutofillTest, ProcessUserChangeRemoveProfile) {
1383 AutofillProfile sync_profile; 1414 AutofillProfile sync_profile;
1384 autofill::test::SetProfileInfoWithGuid( 1415 autofill::test::SetProfileInfoWithGuid(
1385 &sync_profile, "3BA5FA1B-1EC4-4BB3-9B57-EC92BE3C1A09", "Josephine", 1416 &sync_profile, "3BA5FA1B-1EC4-4BB3-9B57-EC92BE3C1A09", "Josephine",
1386 "Alicia", "Saenz", "joewayne@me.xyz", "Fox", "1212 Center.", "Bld. 5", 1417 "Alicia", "Saenz", "joewayne@me.xyz", "Fox", "1212 Center.", "Bld. 5",
1387 "Orlando", "FL", "32801", "US", "19482937549"); 1418 "Orlando", "FL", "32801", "US", "19482937549");
1388 AutofillProfile* native_profile = new AutofillProfile; 1419 std::unique_ptr<AutofillProfile> native_profile =
1420 base::MakeUnique<AutofillProfile>();
1389 autofill::test::SetProfileInfoWithGuid( 1421 autofill::test::SetProfileInfoWithGuid(
1390 native_profile, "3BA5FA1B-1EC4-4BB3-9B57-EC92BE3C1A09", "Josephine", 1422 native_profile.get(), "3BA5FA1B-1EC4-4BB3-9B57-EC92BE3C1A09", "Josephine",
1391 "Alicia", "Saenz", "joewayne@me.xyz", "Fox", "1212 Center.", "Bld. 5", 1423 "Alicia", "Saenz", "joewayne@me.xyz", "Fox", "1212 Center.", "Bld. 5",
1392 "Orlando", "FL", "32801", "US", "19482937549"); 1424 "Orlando", "FL", "32801", "US", "19482937549");
1393 1425
1394 std::vector<AutofillProfile*> native_profiles; 1426 std::vector<std::unique_ptr<AutofillProfile>> native_profiles;
1395 native_profiles.push_back(native_profile); 1427 native_profiles.push_back(std::move(native_profile));
1428 auto profile_returner = [&native_profiles]() {
1429 return std::move(native_profiles);
1430 };
1396 EXPECT_CALL(autofill_table(), GetAutofillProfiles(_)) 1431 EXPECT_CALL(autofill_table(), GetAutofillProfiles(_))
1397 .WillOnce(DoAll(SetArgumentPointee<0>(native_profiles), Return(true))); 1432 .WillOnce(DoAll(LoadAutofillProfiles(profile_returner), Return(true)));
1398 1433
1399 std::vector<AutofillProfile> sync_profiles; 1434 std::vector<AutofillProfile> sync_profiles;
1400 sync_profiles.push_back(sync_profile); 1435 sync_profiles.push_back(sync_profile);
1401 AddAutofillHelper<AutofillProfile> add_autofill(this, sync_profiles); 1436 AddAutofillHelper<AutofillProfile> add_autofill(this, sync_profiles);
1402 EXPECT_CALL(personal_data_manager(), Refresh()); 1437 EXPECT_CALL(personal_data_manager(), Refresh());
1403 StartSyncService(add_autofill.callback(), false, AUTOFILL_PROFILE); 1438 StartSyncService(add_autofill.callback(), false, AUTOFILL_PROFILE);
1404 ASSERT_TRUE(add_autofill.success()); 1439 ASSERT_TRUE(add_autofill.success());
1405 1440
1406 AutofillProfileChange change(AutofillProfileChange::REMOVE, 1441 AutofillProfileChange change(AutofillProfileChange::REMOVE,
1407 sync_profile.guid(), NULL); 1442 sync_profile.guid(), NULL);
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
1465 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&sync_entries, &sync_profiles)); 1500 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&sync_entries, &sync_profiles));
1466 EXPECT_EQ(3U, sync_entries.size()); 1501 EXPECT_EQ(3U, sync_entries.size());
1467 EXPECT_EQ(0U, sync_profiles.size()); 1502 EXPECT_EQ(0U, sync_profiles.size());
1468 for (size_t i = 0; i < sync_entries.size(); i++) { 1503 for (size_t i = 0; i < sync_entries.size(); i++) {
1469 DVLOG(1) << "Entry " << i << ": " << sync_entries[i].key().name() << ", " 1504 DVLOG(1) << "Entry " << i << ": " << sync_entries[i].key().name() << ", "
1470 << sync_entries[i].key().value(); 1505 << sync_entries[i].key().value();
1471 } 1506 }
1472 } 1507 }
1473 1508
1474 } // namespace browser_sync 1509 } // namespace browser_sync
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698