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 <set> | 5 #include <set> |
6 #include <string> | 6 #include <string> |
7 #include <utility> | 7 #include <utility> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 866 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
877 ~FakeServerUpdater() { } | 877 ~FakeServerUpdater() { } |
878 | 878 |
879 AutofillEntry entry_; | 879 AutofillEntry entry_; |
880 TestProfileSyncService* service_; | 880 TestProfileSyncService* service_; |
881 scoped_ptr<WaitableEvent>* wait_for_start_; | 881 scoped_ptr<WaitableEvent>* wait_for_start_; |
882 scoped_ptr<WaitableEvent>* wait_for_syncapi_; | 882 scoped_ptr<WaitableEvent>* wait_for_syncapi_; |
883 WaitableEvent is_finished_; | 883 WaitableEvent is_finished_; |
884 syncer::syncable::Id parent_id_; | 884 syncer::syncable::Id parent_id_; |
885 }; | 885 }; |
886 | 886 |
887 namespace { | |
888 | |
889 // Checks if the field of type |field_type| in |profile1| includes all values | |
890 // of the field in |profile2|. | |
891 bool IncludesField(const AutofillProfile& profile1, | |
892 const AutofillProfile& profile2, | |
893 ServerFieldType field_type) { | |
894 std::vector<base::string16> values1; | |
895 profile1.GetRawMultiInfo(field_type, &values1); | |
896 std::vector<base::string16> values2; | |
897 profile2.GetRawMultiInfo(field_type, &values2); | |
898 | |
899 std::set<base::string16> values_set; | |
900 for (size_t i = 0; i < values1.size(); ++i) | |
901 values_set.insert(values1[i]); | |
902 for (size_t i = 0; i < values2.size(); ++i) | |
903 if (values_set.find(values2[i]) == values_set.end()) | |
904 return false; | |
905 return true; | |
906 } | |
907 | |
908 } // namespace | |
909 | |
910 // TODO(skrul): Test abort startup. | 887 // TODO(skrul): Test abort startup. |
911 // TODO(skrul): Test processing of cloud changes. | 888 // TODO(skrul): Test processing of cloud changes. |
912 // TODO(tim): Add autofill data type controller test, and a case to cover | 889 // TODO(tim): Add autofill data type controller test, and a case to cover |
913 // waiting for the PersonalDataManager. | 890 // waiting for the PersonalDataManager. |
914 TEST_F(ProfileSyncServiceAutofillTest, FailModelAssociation) { | 891 TEST_F(ProfileSyncServiceAutofillTest, FailModelAssociation) { |
915 // Don't create the root autofill node so startup fails. | 892 // Don't create the root autofill node so startup fails. |
916 StartSyncService(base::Closure(), true, syncer::AUTOFILL); | 893 StartSyncService(base::Closure(), true, syncer::AUTOFILL); |
917 EXPECT_TRUE(sync_service_->HasUnrecoverableError()); | 894 EXPECT_TRUE(sync_service_->HasUnrecoverableError()); |
918 } | 895 } |
919 | 896 |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1130 EXPECT_CALL(*personal_data_manager_, Refresh()); | 1107 EXPECT_CALL(*personal_data_manager_, Refresh()); |
1131 StartSyncService(add_autofill.callback(), false, syncer::AUTOFILL_PROFILE); | 1108 StartSyncService(add_autofill.callback(), false, syncer::AUTOFILL_PROFILE); |
1132 ASSERT_TRUE(add_autofill.success()); | 1109 ASSERT_TRUE(add_autofill.success()); |
1133 | 1110 |
1134 std::vector<AutofillProfile> new_sync_profiles; | 1111 std::vector<AutofillProfile> new_sync_profiles; |
1135 ASSERT_TRUE(GetAutofillProfilesFromSyncDBUnderProfileNode( | 1112 ASSERT_TRUE(GetAutofillProfilesFromSyncDBUnderProfileNode( |
1136 &new_sync_profiles)); | 1113 &new_sync_profiles)); |
1137 ASSERT_EQ(1U, new_sync_profiles.size()); | 1114 ASSERT_EQ(1U, new_sync_profiles.size()); |
1138 // Check that key fields are the same. | 1115 // Check that key fields are the same. |
1139 EXPECT_TRUE(new_sync_profiles[0].IsSubsetOf(sync_profile, "en-US")); | 1116 EXPECT_TRUE(new_sync_profiles[0].IsSubsetOf(sync_profile, "en-US")); |
1140 // Check that multivalued fields of the synced back data include original | |
1141 // data. | |
1142 EXPECT_TRUE( | |
1143 IncludesField(new_sync_profiles[0], sync_profile, autofill::NAME_FULL)); | |
1144 EXPECT_TRUE(IncludesField( | |
1145 new_sync_profiles[0], sync_profile, autofill::EMAIL_ADDRESS)); | |
1146 EXPECT_TRUE(IncludesField( | |
1147 new_sync_profiles[0], sync_profile, autofill::PHONE_HOME_WHOLE_NUMBER)); | |
1148 } | 1117 } |
1149 | 1118 |
1150 TEST_F(ProfileSyncServiceAutofillTest, MergeProfileWithDifferentGuid) { | 1119 TEST_F(ProfileSyncServiceAutofillTest, MergeProfileWithDifferentGuid) { |
1151 AutofillProfile sync_profile; | 1120 AutofillProfile sync_profile; |
1152 | 1121 |
1153 autofill::test::SetProfileInfoWithGuid(&sync_profile, | 1122 autofill::test::SetProfileInfoWithGuid(&sync_profile, |
1154 "23355099-1170-4B71-8ED4-144470CC9EBE", "Billing", | 1123 "23355099-1170-4B71-8ED4-144470CC9EBE", "Billing", |
1155 "Mitchell", "Morrison", | 1124 "Mitchell", "Morrison", |
1156 "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", "Hollywood", "CA", | 1125 "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", "Hollywood", "CA", |
1157 "91601", "US", "12345678910"); | 1126 "91601", "US", "12345678910"); |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1374 std::vector<AutofillEntry> sync_entries; | 1343 std::vector<AutofillEntry> sync_entries; |
1375 std::vector<AutofillProfile> sync_profiles; | 1344 std::vector<AutofillProfile> sync_profiles; |
1376 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&sync_entries, &sync_profiles)); | 1345 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&sync_entries, &sync_profiles)); |
1377 EXPECT_EQ(3U, sync_entries.size()); | 1346 EXPECT_EQ(3U, sync_entries.size()); |
1378 EXPECT_EQ(0U, sync_profiles.size()); | 1347 EXPECT_EQ(0U, sync_profiles.size()); |
1379 for (size_t i = 0; i < sync_entries.size(); i++) { | 1348 for (size_t i = 0; i < sync_entries.size(); i++) { |
1380 DVLOG(1) << "Entry " << i << ": " << sync_entries[i].key().name() | 1349 DVLOG(1) << "Entry " << i << ": " << sync_entries[i].key().name() |
1381 << ", " << sync_entries[i].key().value(); | 1350 << ", " << sync_entries[i].key().value(); |
1382 } | 1351 } |
1383 } | 1352 } |
OLD | NEW |