| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 "base/location.h" | 5 #include "base/location.h" |
| 6 #include "base/message_loop.h" | 6 #include "base/message_loop.h" |
| 7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
| 8 #include "chrome/browser/autofill/autofill_profile.h" | 8 #include "chrome/browser/autofill/autofill_profile.h" |
| 9 #include "chrome/browser/webdata/autofill_change.h" | 9 #include "chrome/browser/webdata/autofill_change.h" |
| 10 #include "chrome/browser/webdata/autofill_profile_syncable_service.h" | 10 #include "chrome/browser/webdata/autofill_profile_syncable_service.h" |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 .WillOnce(Return(true)); | 163 .WillOnce(Return(true)); |
| 164 ON_CALL(*sync_processor_, ProcessSyncChanges(_, _)) | 164 ON_CALL(*sync_processor_, ProcessSyncChanges(_, _)) |
| 165 .WillByDefault(Return(syncer::SyncError())); | 165 .WillByDefault(Return(syncer::SyncError())); |
| 166 EXPECT_CALL(*sync_processor_, | 166 EXPECT_CALL(*sync_processor_, |
| 167 ProcessSyncChanges(_, CheckSyncChanges(expected_change_list))) | 167 ProcessSyncChanges(_, CheckSyncChanges(expected_change_list))) |
| 168 .Times(1) | 168 .Times(1) |
| 169 .WillOnce(Return(syncer::SyncError())); | 169 .WillOnce(Return(syncer::SyncError())); |
| 170 | 170 |
| 171 // Takes ownership of sync_processor_. | 171 // Takes ownership of sync_processor_. |
| 172 autofill_syncable_service_.MergeDataAndStartSyncing( | 172 autofill_syncable_service_.MergeDataAndStartSyncing( |
| 173 syncable::AUTOFILL_PROFILE, data_list, | 173 syncer::AUTOFILL_PROFILE, data_list, |
| 174 sync_processor_.PassAs<syncer::SyncChangeProcessor>(), | 174 sync_processor_.PassAs<syncer::SyncChangeProcessor>(), |
| 175 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); | 175 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); |
| 176 autofill_syncable_service_.StopSyncing(syncable::AUTOFILL_PROFILE); | 176 autofill_syncable_service_.StopSyncing(syncer::AUTOFILL_PROFILE); |
| 177 } | 177 } |
| 178 | 178 |
| 179 TEST_F(AutofillProfileSyncableServiceTest, GetAllSyncData) { | 179 TEST_F(AutofillProfileSyncableServiceTest, GetAllSyncData) { |
| 180 std::vector<AutofillProfile *> profiles_from_web_db; | 180 std::vector<AutofillProfile *> profiles_from_web_db; |
| 181 std::string guid_present1 = kGuid1; | 181 std::string guid_present1 = kGuid1; |
| 182 std::string guid_present2 = kGuid2; | 182 std::string guid_present2 = kGuid2; |
| 183 | 183 |
| 184 profiles_from_web_db.push_back(new AutofillProfile(guid_present1)); | 184 profiles_from_web_db.push_back(new AutofillProfile(guid_present1)); |
| 185 profiles_from_web_db.back()->SetInfo(NAME_FIRST, UTF8ToUTF16("John")); | 185 profiles_from_web_db.back()->SetInfo(NAME_FIRST, UTF8ToUTF16("John")); |
| 186 profiles_from_web_db.push_back(new AutofillProfile(guid_present2)); | 186 profiles_from_web_db.push_back(new AutofillProfile(guid_present2)); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 197 EXPECT_CALL(*sync_processor_, | 197 EXPECT_CALL(*sync_processor_, |
| 198 ProcessSyncChanges( | 198 ProcessSyncChanges( |
| 199 _, | 199 _, |
| 200 Property(&syncer::SyncChangeList::size, Eq(2U)))) | 200 Property(&syncer::SyncChangeList::size, Eq(2U)))) |
| 201 .Times(1) | 201 .Times(1) |
| 202 .WillOnce(Return(syncer::SyncError())); | 202 .WillOnce(Return(syncer::SyncError())); |
| 203 | 203 |
| 204 syncer::SyncDataList data_list; | 204 syncer::SyncDataList data_list; |
| 205 // Takes ownership of sync_processor_. | 205 // Takes ownership of sync_processor_. |
| 206 autofill_syncable_service_.MergeDataAndStartSyncing( | 206 autofill_syncable_service_.MergeDataAndStartSyncing( |
| 207 syncable::AUTOFILL_PROFILE, data_list, | 207 syncer::AUTOFILL_PROFILE, data_list, |
| 208 sync_processor_.PassAs<syncer::SyncChangeProcessor>(), | 208 sync_processor_.PassAs<syncer::SyncChangeProcessor>(), |
| 209 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); | 209 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); |
| 210 | 210 |
| 211 syncer::SyncDataList data = | 211 syncer::SyncDataList data = |
| 212 autofill_syncable_service_.GetAllSyncData(syncable::AUTOFILL_PROFILE); | 212 autofill_syncable_service_.GetAllSyncData(syncer::AUTOFILL_PROFILE); |
| 213 | 213 |
| 214 EXPECT_EQ(2U, data.size()); | 214 EXPECT_EQ(2U, data.size()); |
| 215 EXPECT_EQ(guid_present1, data.front().GetSpecifics() | 215 EXPECT_EQ(guid_present1, data.front().GetSpecifics() |
| 216 .autofill_profile().guid()); | 216 .autofill_profile().guid()); |
| 217 EXPECT_EQ(guid_present2, data.back().GetSpecifics() | 217 EXPECT_EQ(guid_present2, data.back().GetSpecifics() |
| 218 .autofill_profile().guid()); | 218 .autofill_profile().guid()); |
| 219 } | 219 } |
| 220 | 220 |
| 221 TEST_F(AutofillProfileSyncableServiceTest, ProcessSyncChanges) { | 221 TEST_F(AutofillProfileSyncableServiceTest, ProcessSyncChanges) { |
| 222 std::vector<AutofillProfile *> profiles_from_web_db; | 222 std::vector<AutofillProfile *> profiles_from_web_db; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 251 } | 251 } |
| 252 | 252 |
| 253 TEST_F(AutofillProfileSyncableServiceTest, ActOnChange) { | 253 TEST_F(AutofillProfileSyncableServiceTest, ActOnChange) { |
| 254 AutofillProfile profile(kGuid1); | 254 AutofillProfile profile(kGuid1); |
| 255 profile.SetInfo(NAME_FIRST, UTF8ToUTF16("Jane")); | 255 profile.SetInfo(NAME_FIRST, UTF8ToUTF16("Jane")); |
| 256 AutofillProfileChange change1(AutofillProfileChange::ADD, kGuid1, &profile); | 256 AutofillProfileChange change1(AutofillProfileChange::ADD, kGuid1, &profile); |
| 257 AutofillProfileChange change2(AutofillProfileChange::REMOVE, kGuid2, NULL); | 257 AutofillProfileChange change2(AutofillProfileChange::REMOVE, kGuid2, NULL); |
| 258 ON_CALL(*sync_processor_, ProcessSyncChanges(_, _)) | 258 ON_CALL(*sync_processor_, ProcessSyncChanges(_, _)) |
| 259 .WillByDefault( | 259 .WillByDefault( |
| 260 Return(syncer::SyncError(FROM_HERE, std::string("an error"), | 260 Return(syncer::SyncError(FROM_HERE, std::string("an error"), |
| 261 syncable::AUTOFILL_PROFILE))); | 261 syncer::AUTOFILL_PROFILE))); |
| 262 EXPECT_CALL(*sync_processor_, ProcessSyncChanges(_, _)).Times(2); | 262 EXPECT_CALL(*sync_processor_, ProcessSyncChanges(_, _)).Times(2); |
| 263 | 263 |
| 264 autofill_syncable_service_.set_sync_processor(sync_processor_.release()); | 264 autofill_syncable_service_.set_sync_processor(sync_processor_.release()); |
| 265 autofill_syncable_service_.ActOnChange(change1); | 265 autofill_syncable_service_.ActOnChange(change1); |
| 266 autofill_syncable_service_.ActOnChange(change2); | 266 autofill_syncable_service_.ActOnChange(change2); |
| 267 } | 267 } |
| 268 | 268 |
| 269 TEST_F(AutofillProfileSyncableServiceTest, UpdateField) { | 269 TEST_F(AutofillProfileSyncableServiceTest, UpdateField) { |
| 270 AutofillProfile profile(kGuid1); | 270 AutofillProfile profile(kGuid1); |
| 271 std::string company1 = "A Company"; | 271 std::string company1 = "A Company"; |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 406 profile1.GetMultiInfo(EMAIL_ADDRESS, &values); | 406 profile1.GetMultiInfo(EMAIL_ADDRESS, &values); |
| 407 ASSERT_EQ(values.size(), 3U); | 407 ASSERT_EQ(values.size(), 3U); |
| 408 EXPECT_EQ(values[0], UTF8ToUTF16("1@1.com")); | 408 EXPECT_EQ(values[0], UTF8ToUTF16("1@1.com")); |
| 409 EXPECT_EQ(values[1], UTF8ToUTF16("2@1.com")); | 409 EXPECT_EQ(values[1], UTF8ToUTF16("2@1.com")); |
| 410 EXPECT_EQ(values[2], UTF8ToUTF16("3@1.com")); | 410 EXPECT_EQ(values[2], UTF8ToUTF16("3@1.com")); |
| 411 | 411 |
| 412 profile1.GetMultiInfo(PHONE_HOME_WHOLE_NUMBER, &values); | 412 profile1.GetMultiInfo(PHONE_HOME_WHOLE_NUMBER, &values); |
| 413 ASSERT_EQ(values.size(), 1U); | 413 ASSERT_EQ(values.size(), 1U); |
| 414 EXPECT_EQ(values[0], UTF8ToUTF16("650234567")); | 414 EXPECT_EQ(values[0], UTF8ToUTF16("650234567")); |
| 415 } | 415 } |
| OLD | NEW |