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

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

Powered by Google App Engine
This is Rietveld 408576698