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

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

Issue 1891903002: [Autofill] Set basic information when adding a new profiles and credit cards. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Further changes to the sync logic Created 4 years, 8 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 <set> 8 #include <set>
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/bind.h" 13 #include "base/bind.h"
14 #include "base/bind_helpers.h" 14 #include "base/bind_helpers.h"
15 #include "base/callback.h" 15 #include "base/callback.h"
16 #include "base/location.h" 16 #include "base/location.h"
17 #include "base/macros.h" 17 #include "base/macros.h"
18 #include "base/memory/ref_counted.h" 18 #include "base/memory/ref_counted.h"
19 #include "base/memory/scoped_ptr.h" 19 #include "base/memory/scoped_ptr.h"
20 #include "base/run_loop.h" 20 #include "base/run_loop.h"
21 #include "base/strings/string16.h" 21 #include "base/strings/string16.h"
22 #include "base/strings/utf_string_conversions.h" 22 #include "base/strings/utf_string_conversions.h"
23 #include "base/synchronization/waitable_event.h" 23 #include "base/synchronization/waitable_event.h"
24 #include "base/thread_task_runner_handle.h" 24 #include "base/thread_task_runner_handle.h"
25 #include "base/threading/thread.h" 25 #include "base/threading/thread.h"
26 #include "base/time/time.h" 26 #include "base/time/time.h"
27 #include "components/autofill/core/browser/autofill_test_utils.h" 27 #include "components/autofill/core/browser/autofill_test_utils.h"
28 #include "components/autofill/core/browser/country_names.h" 28 #include "components/autofill/core/browser/country_names.h"
29 #include "components/autofill/core/browser/field_types.h"
29 #include "components/autofill/core/browser/personal_data_manager.h" 30 #include "components/autofill/core/browser/personal_data_manager.h"
30 #include "components/autofill/core/browser/webdata/autocomplete_syncable_service .h" 31 #include "components/autofill/core/browser/webdata/autocomplete_syncable_service .h"
31 #include "components/autofill/core/browser/webdata/autofill_change.h" 32 #include "components/autofill/core/browser/webdata/autofill_change.h"
32 #include "components/autofill/core/browser/webdata/autofill_data_type_controller .h" 33 #include "components/autofill/core/browser/webdata/autofill_data_type_controller .h"
33 #include "components/autofill/core/browser/webdata/autofill_entry.h" 34 #include "components/autofill/core/browser/webdata/autofill_entry.h"
34 #include "components/autofill/core/browser/webdata/autofill_profile_data_type_co ntroller.h" 35 #include "components/autofill/core/browser/webdata/autofill_profile_data_type_co ntroller.h"
35 #include "components/autofill/core/browser/webdata/autofill_profile_syncable_ser vice.h" 36 #include "components/autofill/core/browser/webdata/autofill_profile_syncable_ser vice.h"
36 #include "components/autofill/core/browser/webdata/autofill_table.h" 37 #include "components/autofill/core/browser/webdata/autofill_table.h"
37 #include "components/autofill/core/browser/webdata/autofill_webdata_service.h" 38 #include "components/autofill/core/browser/webdata/autofill_webdata_service.h"
38 #include "components/autofill/core/common/autofill_pref_names.h" 39 #include "components/autofill/core/common/autofill_pref_names.h"
(...skipping 22 matching lines...) Expand all
61 using autofill::AutofillChange; 62 using autofill::AutofillChange;
62 using autofill::AutofillChangeList; 63 using autofill::AutofillChangeList;
63 using autofill::AutofillEntry; 64 using autofill::AutofillEntry;
64 using autofill::AutofillKey; 65 using autofill::AutofillKey;
65 using autofill::AutofillProfile; 66 using autofill::AutofillProfile;
66 using autofill::AutofillProfileChange; 67 using autofill::AutofillProfileChange;
67 using autofill::AutofillProfileSyncableService; 68 using autofill::AutofillProfileSyncableService;
68 using autofill::AutofillTable; 69 using autofill::AutofillTable;
69 using autofill::AutofillWebDataService; 70 using autofill::AutofillWebDataService;
70 using autofill::PersonalDataManager; 71 using autofill::PersonalDataManager;
72 using autofill::ServerFieldType;
71 using base::Time; 73 using base::Time;
72 using base::TimeDelta; 74 using base::TimeDelta;
73 using base::WaitableEvent; 75 using base::WaitableEvent;
74 using browser_sync::AutofillDataTypeController; 76 using browser_sync::AutofillDataTypeController;
75 using browser_sync::AutofillProfileDataTypeController; 77 using browser_sync::AutofillProfileDataTypeController;
76 using syncer::AUTOFILL; 78 using syncer::AUTOFILL;
77 using syncer::AUTOFILL_PROFILE; 79 using syncer::AUTOFILL_PROFILE;
78 using syncer::BaseNode; 80 using syncer::BaseNode;
79 using syncer::syncable::CREATE; 81 using syncer::syncable::CREATE;
80 using syncer::syncable::GET_TYPE_ROOT; 82 using syncer::syncable::GET_TYPE_ROOT;
(...skipping 890 matching lines...) Expand 10 before | Expand all | Expand 10 after
971 StartSyncService(add_autofill.callback(), false, AUTOFILL_PROFILE); 973 StartSyncService(add_autofill.callback(), false, AUTOFILL_PROFILE);
972 ASSERT_TRUE(add_autofill.success()); 974 ASSERT_TRUE(add_autofill.success());
973 975
974 std::vector<AutofillProfile> new_sync_profiles; 976 std::vector<AutofillProfile> new_sync_profiles;
975 ASSERT_TRUE(GetAutofillProfilesFromSyncDBUnderProfileNode( 977 ASSERT_TRUE(GetAutofillProfilesFromSyncDBUnderProfileNode(
976 &new_sync_profiles)); 978 &new_sync_profiles));
977 ASSERT_EQ(1U, new_sync_profiles.size()); 979 ASSERT_EQ(1U, new_sync_profiles.size());
978 EXPECT_EQ(0, sync_profile.Compare(new_sync_profiles[0])); 980 EXPECT_EQ(0, sync_profile.Compare(new_sync_profiles[0]));
979 } 981 }
980 982
981 TEST_F(ProfileSyncServiceAutofillTest, HasNativeHasSyncMergeProfileCombine) { 983 // Tests that adding a new profile that matches an existing sync profile gets
984 // 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?
985 TEST_F(
986 ProfileSyncServiceAutofillTest,
987 HasNativeHasSyncMergeSimilarProfileCombine_SyncHasMoreInfoAndMoreRecent) {
988 // Create two almost identical profiles. The GUIDs are different and the
989 // native profile has no value for company name.
982 AutofillProfile sync_profile; 990 AutofillProfile sync_profile;
983 autofill::test::SetProfileInfoWithGuid(&sync_profile, 991 autofill::test::SetProfileInfoWithGuid(
984 "23355099-1170-4B71-8ED4-144470CC9EBE", "Billing", 992 &sync_profile, "23355099-1170-4B71-8ED4-144470CC9EBE", "Billing",
985 "Mitchell", "Morrison", 993 "Mitchell", "Morrison", "johnwayne@me.xyz", "Fox", "123 Zoo St.",
986 "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", "Hollywood", "CA", 994 "unit 5", "Hollywood", "CA", "91601", "US", "12345678910");
987 "91601", "US", "12345678910"); 995 sync_profile.set_use_date(base::Time::FromTimeT(4321));
988 996
989 AutofillProfile* native_profile = new AutofillProfile; 997 AutofillProfile* native_profile = new AutofillProfile;
990 // Same address, but different names, phones and e-mails. 998 autofill::test::SetProfileInfoWithGuid(
991 autofill::test::SetProfileInfoWithGuid(native_profile, 999 native_profile, "23355099-1170-4B71-8ED4-144470CC9EBF", "Billing",
992 "23355099-1170-4B71-8ED4-144470CC9EBF", "Billing", "Alicia", "Saenz", 1000 "Mitchell", "Morrison", "johnwayne@me.xyz", "", "123 Zoo St.", "unit 5",
993 "joewayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", "Hollywood", "CA", 1001 "Hollywood", "CA", "91601", "US", "12345678910");
994 "91601", "US", "19482937549"); 1002 native_profile->set_use_date(base::Time::FromTimeT(1234));
995 1003
996 AutofillProfile expected_profile(sync_profile); 1004 AutofillProfile expected_profile(sync_profile);
997 expected_profile.OverwriteWith(*native_profile, "en-US"); 1005 expected_profile.OverwriteWith(*native_profile, "en-US");
998 1006
999 std::vector<AutofillProfile*> native_profiles; 1007 std::vector<AutofillProfile*> native_profiles;
1000 native_profiles.push_back(native_profile); 1008 native_profiles.push_back(native_profile);
1001 EXPECT_CALL(autofill_table(), GetAutofillProfiles(_)) 1009 EXPECT_CALL(autofill_table(), GetAutofillProfiles(_))
1002 .WillOnce(DoAll(SetArgumentPointee<0>(native_profiles), Return(true))); 1010 .WillOnce(DoAll(SetArgumentPointee<0>(native_profiles), Return(true)));
1003 EXPECT_CALL(autofill_table(), 1011 EXPECT_CALL(autofill_table(),
1004 AddAutofillProfile(MatchProfiles(expected_profile))) 1012 AddAutofillProfile(MatchProfiles(expected_profile)))
1005 .WillOnce(Return(true)); 1013 .WillOnce(Return(true));
1006 EXPECT_CALL(autofill_table(), 1014 EXPECT_CALL(autofill_table(),
1007 RemoveAutofillProfile("23355099-1170-4B71-8ED4-144470CC9EBF")) 1015 RemoveAutofillProfile("23355099-1170-4B71-8ED4-144470CC9EBF"))
1008 .WillOnce(Return(true)); 1016 .WillOnce(Return(true));
1009 std::vector<AutofillProfile> sync_profiles; 1017 std::vector<AutofillProfile> sync_profiles;
1010 sync_profiles.push_back(sync_profile); 1018 sync_profiles.push_back(sync_profile);
1011 AddAutofillHelper<AutofillProfile> add_autofill(this, sync_profiles); 1019 AddAutofillHelper<AutofillProfile> add_autofill(this, sync_profiles);
1012 1020
1013 EXPECT_CALL(personal_data_manager(), Refresh()); 1021 EXPECT_CALL(personal_data_manager(), Refresh());
1022 // Adds all entries in |sync_profiles| to sync.
1014 StartSyncService(add_autofill.callback(), false, AUTOFILL_PROFILE); 1023 StartSyncService(add_autofill.callback(), false, AUTOFILL_PROFILE);
1015 ASSERT_TRUE(add_autofill.success()); 1024 ASSERT_TRUE(add_autofill.success());
1016 1025
1017 std::vector<AutofillProfile> new_sync_profiles; 1026 std::vector<AutofillProfile> new_sync_profiles;
1018 ASSERT_TRUE(GetAutofillProfilesFromSyncDBUnderProfileNode( 1027 ASSERT_TRUE(
1019 &new_sync_profiles)); 1028 GetAutofillProfilesFromSyncDBUnderProfileNode(&new_sync_profiles));
1020 ASSERT_EQ(1U, new_sync_profiles.size()); 1029 ASSERT_EQ(1U, new_sync_profiles.size());
1021 // Check that key fields are the same. 1030 // Check that key fields are the same.
1022 EXPECT_TRUE(new_sync_profiles[0].IsSubsetOf(sync_profile, "en-US")); 1031 EXPECT_TRUE(new_sync_profiles[0].IsSubsetOf(sync_profile, "en-US"));
1032 // 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.
1033 EXPECT_EQ(base::ASCIIToUTF16("Fox"),
1034 new_sync_profiles[0].GetRawInfo(ServerFieldType::COMPANY_NAME));
1035 // Check that the latest use date is saved.
1036 EXPECT_EQ(base::Time::FromTimeT(4321), new_sync_profiles[0].use_date());
1037 // Check that the use counts were added (default value is 1).
1038 EXPECT_EQ(2U, new_sync_profiles[0].use_count());
1023 } 1039 }
1024 1040
1041 // Tests that adding a new profile that matches an existing sync profile gets
1042 // deleted and that the sync profile gets merged down as a local profile even
1043 // if the local profile is more recent.
1044 TEST_F(ProfileSyncServiceAutofillTest,
1045 HasNativeHasSyncMergeSimilarProfileCombine_SyncHasMoreInfoAndOlder) {
1046 // Create two almost identical profiles. The GUIDs are different and the
1047 // native profile has no value for company name.
1048 AutofillProfile sync_profile;
1049 autofill::test::SetProfileInfoWithGuid(
1050 &sync_profile, "23355099-1170-4B71-8ED4-144470CC9EBE", "Billing",
1051 "Mitchell", "Morrison", "johnwayne@me.xyz", "Fox", "123 Zoo St.",
1052 "unit 5", "Hollywood", "CA", "91601", "US", "12345678910");
1053 sync_profile.set_use_date(base::Time::FromTimeT(1234));
1054
1055 AutofillProfile* native_profile = new AutofillProfile;
1056 autofill::test::SetProfileInfoWithGuid(
1057 native_profile, "23355099-1170-4B71-8ED4-144470CC9EBF", "Billing",
1058 "Mitchell", "Morrison", "johnwayne@me.xyz", "", "123 Zoo St.", "unit 5",
1059 "Hollywood", "CA", "91601", "US", "12345678910");
1060 native_profile->set_use_date(base::Time::FromTimeT(4321));
1061
1062 AutofillProfile expected_profile(sync_profile);
1063 expected_profile.OverwriteWith(*native_profile, "en-US");
1064
1065 std::vector<AutofillProfile*> native_profiles;
1066 native_profiles.push_back(native_profile);
1067 EXPECT_CALL(autofill_table(), GetAutofillProfiles(_))
1068 .WillOnce(DoAll(SetArgumentPointee<0>(native_profiles), Return(true)));
1069 EXPECT_CALL(autofill_table(),
1070 AddAutofillProfile(MatchProfiles(expected_profile)))
1071 .WillOnce(Return(true));
1072 EXPECT_CALL(autofill_table(),
1073 RemoveAutofillProfile("23355099-1170-4B71-8ED4-144470CC9EBF"))
1074 .WillOnce(Return(true));
1075 std::vector<AutofillProfile> sync_profiles;
1076 sync_profiles.push_back(sync_profile);
1077 AddAutofillHelper<AutofillProfile> add_autofill(this, sync_profiles);
1078
1079 EXPECT_CALL(personal_data_manager(), Refresh());
1080 // Adds all entries in |sync_profiles| to sync.
1081 StartSyncService(add_autofill.callback(), false, AUTOFILL_PROFILE);
1082 ASSERT_TRUE(add_autofill.success());
1083
1084 std::vector<AutofillProfile> new_sync_profiles;
1085 ASSERT_TRUE(
1086 GetAutofillProfilesFromSyncDBUnderProfileNode(&new_sync_profiles));
1087 ASSERT_EQ(1U, new_sync_profiles.size());
1088 // Check that key fields are the same.
1089 EXPECT_TRUE(new_sync_profiles[0].IsSubsetOf(sync_profile, "en-US"));
1090 // Make sure the new information was merged down.
1091 EXPECT_EQ(base::ASCIIToUTF16("Fox"),
1092 new_sync_profiles[0].GetRawInfo(ServerFieldType::COMPANY_NAME));
1093 // Check that the latest use date is saved.
1094 EXPECT_EQ(base::Time::FromTimeT(4321), new_sync_profiles[0].use_date());
1095 // Check that the use counts were added (default value is 1).
1096 EXPECT_EQ(2U, new_sync_profiles[0].use_count());
1097 }
1098
1099 // Tests that adding a new profile that matches an existing sync profile but
1100 // with more information gets merged to the sync profile and merged down to the
1101 // native profile. The merge should happen even if the sync profile is more
1102 // recent.
1103 TEST_F(ProfileSyncServiceAutofillTest,
1104 HasNativeHasSyncMergeSimilarProfileCombine_NativeHasMoreInfo) {
1105 // Create two almost identical profiles. The GUIDs are different and the
1106 // sync profile has no value for company name.
1107 AutofillProfile sync_profile;
1108 autofill::test::SetProfileInfoWithGuid(
1109 &sync_profile, "23355099-1170-4B71-8ED4-144470CC9EBE", "Billing",
1110 "Mitchell", "Morrison", "johnwayne@me.xyz", "", "123 Zoo St.", "unit 5",
1111 "Hollywood", "CA", "91601", "US", "12345678910");
1112 sync_profile.set_use_date(base::Time::FromTimeT(4321));
1113
1114 AutofillProfile* native_profile = new AutofillProfile;
1115 autofill::test::SetProfileInfoWithGuid(
1116 native_profile, "23355099-1170-4B71-8ED4-144470CC9EBF", "Billing",
1117 "Mitchell", "Morrison", "johnwayne@me.xyz", "Fox", "123 Zoo St.",
1118 "unit 5", "Hollywood", "CA", "91601", "US", "12345678910");
1119 native_profile->set_use_date(base::Time::FromTimeT(1234));
1120
1121 AutofillProfile expected_profile(sync_profile);
1122 expected_profile.OverwriteWith(*native_profile, "en-US");
1123
1124 std::vector<AutofillProfile*> native_profiles;
1125 native_profiles.push_back(native_profile);
1126 EXPECT_CALL(autofill_table(), GetAutofillProfiles(_))
1127 .WillOnce(DoAll(SetArgumentPointee<0>(native_profiles), Return(true)));
1128 EXPECT_CALL(autofill_table(),
1129 AddAutofillProfile(MatchProfiles(expected_profile)))
1130 .WillOnce(Return(true));
1131 EXPECT_CALL(autofill_table(),
1132 RemoveAutofillProfile("23355099-1170-4B71-8ED4-144470CC9EBF"))
1133 .WillOnce(Return(true));
1134 std::vector<AutofillProfile> sync_profiles;
1135 sync_profiles.push_back(sync_profile);
1136 AddAutofillHelper<AutofillProfile> add_autofill(this, sync_profiles);
1137
1138 EXPECT_CALL(personal_data_manager(), Refresh());
1139 // Adds all entries in |sync_profiles| to sync.
1140 StartSyncService(add_autofill.callback(), false, AUTOFILL_PROFILE);
1141 ASSERT_TRUE(add_autofill.success());
1142
1143 std::vector<AutofillProfile> new_sync_profiles;
1144 ASSERT_TRUE(
1145 GetAutofillProfilesFromSyncDBUnderProfileNode(&new_sync_profiles));
1146 ASSERT_EQ(1U, new_sync_profiles.size());
1147 // Check that key fields are the same.
1148 EXPECT_TRUE(new_sync_profiles[0].IsSubsetOf(expected_profile, "en-US"));
1149 // Make sure the new information was conserved.
1150 EXPECT_EQ(base::ASCIIToUTF16("Fox"),
1151 new_sync_profiles[0].GetRawInfo(ServerFieldType::COMPANY_NAME));
1152 // Check that the latest use date is saved.
1153 EXPECT_EQ(base::Time::FromTimeT(4321), new_sync_profiles[0].use_date());
1154 // Check that the use counts were added (default value is 1).
1155 EXPECT_EQ(2U, new_sync_profiles[0].use_count());
1156 }
1157
1158 // Tests that adding a new profile that differ only by name to the new sync
1159 // profile results in keeping the two profiles.
1160 TEST_F(ProfileSyncServiceAutofillTest, HasNativeHasSync_DifferentPrimaryInfo) {
1161 AutofillProfile sync_profile;
1162 autofill::test::SetProfileInfoWithGuid(
1163 &sync_profile, "23355099-1170-4B71-8ED4-144470CC9EBE", "Billing",
1164 "Mitchell", "Morrison", "johnwayne@me.xyz", "Fox", "123 Zoo St.",
1165 "unit 5", "Hollywood", "CA", "91601", "US", "12345678910");
1166 sync_profile.set_use_date(base::Time::FromTimeT(4321));
1167
1168 AutofillProfile* native_profile = new AutofillProfile;
1169 autofill::test::SetProfileInfoWithGuid(
1170 native_profile, "23355099-1170-4B71-8ED4-144470CC9EBF", "Billing", "John",
1171 "Smith", "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", "Hollywood",
1172 "CA", "91601", "US", "12345678910");
1173 native_profile->set_use_date(base::Time::FromTimeT(1234));
1174
1175 AutofillProfile expected_profile(sync_profile);
1176 expected_profile.OverwriteWith(*native_profile, "en-US");
1177
1178 std::vector<AutofillProfile*> native_profiles;
1179 native_profiles.push_back(native_profile);
1180 EXPECT_CALL(autofill_table(), GetAutofillProfiles(_))
1181 .WillOnce(DoAll(SetArgumentPointee<0>(native_profiles), Return(true)));
1182 EXPECT_CALL(autofill_table(), AddAutofillProfile(MatchProfiles(sync_profile)))
1183 .WillOnce(Return(true));
1184 std::vector<AutofillProfile> sync_profiles;
1185 sync_profiles.push_back(sync_profile);
1186 AddAutofillHelper<AutofillProfile> add_autofill(this, sync_profiles);
1187
1188 EXPECT_CALL(personal_data_manager(), Refresh());
1189 // Adds all entries in |sync_profiles| to sync.
1190 StartSyncService(add_autofill.callback(), false, AUTOFILL_PROFILE);
1191 ASSERT_TRUE(add_autofill.success());
1192
1193 std::vector<AutofillProfile> new_sync_profiles;
1194 ASSERT_TRUE(
1195 GetAutofillProfilesFromSyncDBUnderProfileNode(&new_sync_profiles));
1196 // The two profiles should be kept.
1197 ASSERT_EQ(2U, new_sync_profiles.size());
1198 }
1199
1200 // Tests that adding a local profile that is the same as a sync profile except
1201 // with different GUIDs results in the local profile being deleted and the sync
1202 // profile being merged down with updated usage stats.
1025 TEST_F(ProfileSyncServiceAutofillTest, MergeProfileWithDifferentGuid) { 1203 TEST_F(ProfileSyncServiceAutofillTest, MergeProfileWithDifferentGuid) {
1026 AutofillProfile sync_profile; 1204 AutofillProfile sync_profile;
1027 1205
1028 autofill::test::SetProfileInfoWithGuid(&sync_profile, 1206 autofill::test::SetProfileInfoWithGuid(&sync_profile,
1029 "23355099-1170-4B71-8ED4-144470CC9EBE", "Billing", 1207 "23355099-1170-4B71-8ED4-144470CC9EBE", "Billing",
1030 "Mitchell", "Morrison", 1208 "Mitchell", "Morrison",
1031 "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", "Hollywood", "CA", 1209 "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", "Hollywood", "CA",
1032 "91601", "US", "12345678910"); 1210 "91601", "US", "12345678910");
1211 sync_profile.set_use_count(20);
1212 sync_profile.set_use_date(base::Time::FromTimeT(1234));
1033 1213
1034 std::string native_guid = "EDC609ED-7EEE-4F27-B00C-423242A9C44B"; 1214 std::string native_guid = "EDC609ED-7EEE-4F27-B00C-423242A9C44B";
1035 AutofillProfile* native_profile = new AutofillProfile; 1215 AutofillProfile* native_profile = new AutofillProfile;
1036 autofill::test::SetProfileInfoWithGuid(native_profile, 1216 autofill::test::SetProfileInfoWithGuid(native_profile,
1037 native_guid.c_str(), "Billing", 1217 native_guid.c_str(), "Billing",
1038 "Mitchell", "Morrison", 1218 "Mitchell", "Morrison",
1039 "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", "Hollywood", "CA", 1219 "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", "Hollywood", "CA",
1040 "91601", "US", "12345678910"); 1220 "91601", "US", "12345678910");
1221 native_profile->set_use_count(5);
1222 native_profile->set_use_date(base::Time::FromTimeT(4321));
1041 1223
1042 std::vector<AutofillProfile*> native_profiles; 1224 std::vector<AutofillProfile*> native_profiles;
1043 native_profiles.push_back(native_profile); 1225 native_profiles.push_back(native_profile);
1044 EXPECT_CALL(autofill_table(), GetAutofillProfiles(_)) 1226 EXPECT_CALL(autofill_table(), GetAutofillProfiles(_))
1045 .WillOnce(DoAll(SetArgumentPointee<0>(native_profiles), Return(true))); 1227 .WillOnce(DoAll(SetArgumentPointee<0>(native_profiles), Return(true)));
1046 1228
1047 std::vector<AutofillProfile> sync_profiles; 1229 std::vector<AutofillProfile> sync_profiles;
1048 sync_profiles.push_back(sync_profile); 1230 sync_profiles.push_back(sync_profile);
1049 AddAutofillHelper<AutofillProfile> add_autofill(this, sync_profiles); 1231 AddAutofillHelper<AutofillProfile> add_autofill(this, sync_profiles);
1050 1232
1051 EXPECT_CALL(autofill_table(), AddAutofillProfile(_)).WillOnce(Return(true)); 1233 EXPECT_CALL(autofill_table(), AddAutofillProfile(_)).WillOnce(Return(true));
1052 EXPECT_CALL(autofill_table(), RemoveAutofillProfile(native_guid)) 1234 EXPECT_CALL(autofill_table(), RemoveAutofillProfile(native_guid))
1053 .WillOnce(Return(true)); 1235 .WillOnce(Return(true));
1054 EXPECT_CALL(personal_data_manager(), Refresh()); 1236 EXPECT_CALL(personal_data_manager(), Refresh());
1055 StartSyncService(add_autofill.callback(), false, AUTOFILL_PROFILE); 1237 StartSyncService(add_autofill.callback(), false, AUTOFILL_PROFILE);
1056 ASSERT_TRUE(add_autofill.success()); 1238 ASSERT_TRUE(add_autofill.success());
1057 1239
1058 std::vector<AutofillProfile> new_sync_profiles; 1240 std::vector<AutofillProfile> new_sync_profiles;
1059 ASSERT_TRUE(GetAutofillProfilesFromSyncDBUnderProfileNode( 1241 ASSERT_TRUE(GetAutofillProfilesFromSyncDBUnderProfileNode(
1060 &new_sync_profiles)); 1242 &new_sync_profiles));
1243 // Check that the profiles were merged.
1061 ASSERT_EQ(1U, new_sync_profiles.size()); 1244 ASSERT_EQ(1U, new_sync_profiles.size());
1062 EXPECT_EQ(0, sync_profile.Compare(new_sync_profiles[0])); 1245 EXPECT_EQ(0, sync_profile.Compare(new_sync_profiles[0]));
1246 // Check that the sync guid was kept.
1063 EXPECT_EQ(sync_profile.guid(), new_sync_profiles[0].guid()); 1247 EXPECT_EQ(sync_profile.guid(), new_sync_profiles[0].guid());
1248 // Check that the sync profile use count was kept.
1249 EXPECT_EQ(20U, new_sync_profiles[0].use_count());
1250 // Check that the sync profile use date was kept.
1251 EXPECT_EQ(base::Time::FromTimeT(1234), new_sync_profiles[0].use_date());
1064 } 1252 }
1065 1253
1066 TEST_F(ProfileSyncServiceAutofillTest, ProcessUserChangeAddEntry) { 1254 TEST_F(ProfileSyncServiceAutofillTest, ProcessUserChangeAddEntry) {
1067 EXPECT_CALL(autofill_table(), GetAllAutofillEntries(_)) 1255 EXPECT_CALL(autofill_table(), GetAllAutofillEntries(_))
1068 .WillOnce(Return(true)); 1256 .WillOnce(Return(true));
1069 EXPECT_CALL(personal_data_manager(), Refresh()); 1257 EXPECT_CALL(personal_data_manager(), Refresh());
1070 SetIdleChangeProcessorExpectations(); 1258 SetIdleChangeProcessorExpectations();
1071 CreateRootHelper create_root(this, AUTOFILL); 1259 CreateRootHelper create_root(this, AUTOFILL);
1072 StartSyncService(create_root.callback(), false, AUTOFILL); 1260 StartSyncService(create_root.callback(), false, AUTOFILL);
1073 ASSERT_TRUE(create_root.success()); 1261 ASSERT_TRUE(create_root.success());
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
1255 std::vector<AutofillEntry> sync_entries; 1443 std::vector<AutofillEntry> sync_entries;
1256 std::vector<AutofillProfile> sync_profiles; 1444 std::vector<AutofillProfile> sync_profiles;
1257 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&sync_entries, &sync_profiles)); 1445 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&sync_entries, &sync_profiles));
1258 EXPECT_EQ(3U, sync_entries.size()); 1446 EXPECT_EQ(3U, sync_entries.size());
1259 EXPECT_EQ(0U, sync_profiles.size()); 1447 EXPECT_EQ(0U, sync_profiles.size());
1260 for (size_t i = 0; i < sync_entries.size(); i++) { 1448 for (size_t i = 0; i < sync_entries.size(); i++) {
1261 DVLOG(1) << "Entry " << i << ": " << sync_entries[i].key().name() 1449 DVLOG(1) << "Entry " << i << ": " << sync_entries[i].key().name()
1262 << ", " << sync_entries[i].key().value(); 1450 << ", " << sync_entries[i].key().value();
1263 } 1451 }
1264 } 1452 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698