Chromium Code Reviews| Index: chrome/browser/sync/glue/autofill_profile_syncable_service_unittest.cc |
| =================================================================== |
| --- chrome/browser/sync/glue/autofill_profile_syncable_service_unittest.cc (revision 0) |
| +++ chrome/browser/sync/glue/autofill_profile_syncable_service_unittest.cc (revision 0) |
| @@ -0,0 +1,181 @@ |
| +// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "base/tracked.h" |
| +#include "base/utf_string_conversions.h" |
| +#include "chrome/browser/sync/glue/autofill_profile_syncable_service.h" |
| +#include "chrome/browser/sync/internal_api/read_node_mock.h" |
| +#include "chrome/browser/sync/internal_api/syncapi_mock.h" |
| +#include "chrome/browser/sync/syncable/syncable.h" |
| +#include "chrome/browser/sync/syncable/syncable_mock.h" |
| +#include "testing/gmock/include/gmock/gmock.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| + |
| +using ::testing::_; |
| +using ::testing::DoAll; |
| +using ::testing::Eq; |
| +using ::testing::Return; |
| +using ::testing::Property; |
| +class AutofillProfile; |
| + |
| +namespace browser_sync { |
| + |
| +class MockAutofillProfileSyncableService |
| + : public browser_sync::AutofillProfileSyncableService { |
|
dhollowa
2011/09/01 23:20:29
nit: indent 4 spaces
|
| + public: |
| + MockAutofillProfileSyncableService() { |
| + } |
| + virtual ~MockAutofillProfileSyncableService() {} |
| + |
| + MOCK_CONST_METHOD1(LoadAutofillData, |
| + bool(std::vector<AutofillProfile*>*)); |
| + MOCK_METHOD1(SaveChangesToWebData, |
| + bool(const AutofillProfileSyncableService::DataBundle&)); |
| + |
| + // Helper for tests that do not need to setup service completely throught the |
|
dhollowa
2011/09/01 23:20:29
s/throught/through/
|
| + // MergeDataAndStartSyncing(). |
| + class AutoSetSyncProcessor { |
| + public: |
| + AutoSetSyncProcessor(MockAutofillProfileSyncableService *service, |
|
dhollowa
2011/09/01 20:17:49
nit: s/ */* /
GeorgeY
2011/09/02 04:34:12
Done.
|
| + SyncChangeProcessor* sync_processor) |
| + : service_(service) { |
| + service->set_sync_processor(sync_processor); |
| + } |
| + ~AutoSetSyncProcessor() { |
| + service_->set_sync_processor(NULL); |
| + } |
| + MockAutofillProfileSyncableService *service_; |
|
dhollowa
2011/09/01 20:17:49
nit: s/ */* /
GeorgeY
2011/09/02 04:34:12
Done.
|
| + }; |
| +}; |
| + |
| +ACTION_P(CopyData, data) { |
| + arg0->resize(data->size()); |
| + std::copy(data->begin(), data->end(), arg0->begin()); |
| +} |
| + |
| +MATCHER_P3(DataBundleCheck, n_delete, n_update, n_new, "") { |
| + return (arg.profiles_to_delete.size() == n_delete) && |
| + (arg.updated_profiles.size() == n_update) && |
| + (arg.new_profiles.size() == n_new); |
| +} |
| + |
| +class MockSyncChangeProcessor : public SyncChangeProcessor { |
| + public: |
| + MockSyncChangeProcessor() {} |
| + virtual ~MockSyncChangeProcessor() {} |
| + |
| + MOCK_METHOD2(ProcessSyncChanges, |
| + SyncError(const tracked_objects::Location&, |
| + const SyncChangeList&)); |
| +}; |
| + |
| +class AutofillProfileSyncableServiceTest : public testing::Test { |
| + public: |
| + AutofillProfileSyncableServiceTest() |
| + : db_thread_(BrowserThread::DB, &message_loop_) {} |
| + |
| + protected: |
| + MessageLoop message_loop_; |
| + BrowserThread db_thread_; |
| + MockAutofillProfileSyncableService autofill_syncable_service_; |
| + MockSyncChangeProcessor sync_processor_; |
| +}; |
| + |
| +TEST_F(AutofillProfileSyncableServiceTest, MergeDataAndStartSyncing) { |
| + std::vector<AutofillProfile *> profiles_from_web_db; |
| + std::string guid_present = "EDC609ED-7EEE-4F27-B00C-423242A9C44B"; |
| + std::string guid_synced1 = "EDC609ED-7EEE-4F27-B00C-423242A9C44C"; |
| + std::string guid_synced2 = "EDC609ED-7EEE-4F27-B00C-423242A9C44D"; |
| + |
| + profiles_from_web_db.push_back(new AutofillProfile(guid_present)); |
| + profiles_from_web_db.back()->SetInfo(NAME_FIRST, UTF8ToUTF16("John")); |
| + |
| + SyncDataList data_list; |
| + AutofillProfile profile1(guid_synced1); |
| + profile1.SetInfo(NAME_FIRST, UTF8ToUTF16("Jane")); |
| + data_list.push_back(autofill_syncable_service_.CreateData(profile1)); |
| + AutofillProfile profile2(guid_synced2); |
| + profile2.SetInfo(NAME_FIRST, UTF8ToUTF16("Harry")); |
| + data_list.push_back(autofill_syncable_service_.CreateData(profile2)); |
| + |
| + EXPECT_CALL(autofill_syncable_service_, LoadAutofillData(_)) |
| + .Times(1) |
| + .WillOnce(DoAll(CopyData(&profiles_from_web_db), Return(true))); |
|
lipalani1
2011/09/01 05:06:02
Dont you want to verify the data that is being sen
GeorgeY
2011/09/02 04:34:12
CopyData(&profiles_from_web_db) puts data into the
|
| + EXPECT_CALL(autofill_syncable_service_, SaveChangesToWebData(_)) |
| + .Times(1) |
| + .WillOnce(Return(true)); |
| + ON_CALL(sync_processor_, ProcessSyncChanges(_, _)) |
| + .WillByDefault(Return(SyncError())); |
| + EXPECT_CALL(sync_processor_, |
| + ProcessSyncChanges(_, Property(&SyncChangeList::size, Eq(1U)))) |
| + .Times(1) |
| + .WillOnce(Return(SyncError())); |
| + |
| + autofill_syncable_service_.MergeDataAndStartSyncing( |
| + syncable::AUTOFILL_PROFILE, data_list, &sync_processor_); |
| + autofill_syncable_service_.StopSyncing(syncable::AUTOFILL_PROFILE); |
| +} |
| + |
| +TEST_F(AutofillProfileSyncableServiceTest, GetAllSyncData) { |
| + std::vector<AutofillProfile *> profiles_from_web_db; |
| + std::string guid_present1 = "EDC609ED-7EEE-4F27-B00C-423242A9C44B"; |
| + std::string guid_present2 = "EDC609ED-7EEE-4F27-B00C-423242A9C44C"; |
| + |
| + profiles_from_web_db.push_back(new AutofillProfile(guid_present1)); |
| + profiles_from_web_db.back()->SetInfo(NAME_FIRST, UTF8ToUTF16("John")); |
| + profiles_from_web_db.push_back(new AutofillProfile(guid_present2)); |
| + profiles_from_web_db.back()->SetInfo(NAME_FIRST, UTF8ToUTF16("Jane")); |
| + |
| + EXPECT_CALL(autofill_syncable_service_, LoadAutofillData(_)) |
| + .Times(1) |
| + .WillOnce(DoAll(CopyData(&profiles_from_web_db), Return(true))); |
| + |
| + MockAutofillProfileSyncableService::AutoSetSyncProcessor temp( |
| + &autofill_syncable_service_, &sync_processor_); |
| + |
| + SyncDataList data = |
| + autofill_syncable_service_.GetAllSyncData(syncable::AUTOFILL_PROFILE); |
| + |
| + EXPECT_EQ(2U, data.size()); |
| + EXPECT_EQ(guid_present1, data.front().GetSpecifics() |
| + .GetExtension(sync_pb::autofill_profile).guid()); |
| + EXPECT_EQ(guid_present2, data.back().GetSpecifics() |
| + .GetExtension(sync_pb::autofill_profile).guid()); |
| +} |
| + |
| +TEST_F(AutofillProfileSyncableServiceTest, ProcessSyncChanges) { |
| + std::vector<AutofillProfile *> profiles_from_web_db; |
| + std::string guid_present = "EDC609ED-7EEE-4F27-B00C-423242A9C44B"; |
| + std::string guid_synced = "EDC609ED-7EEE-4F27-B00C-423242A9C44C"; |
| + |
| + profiles_from_web_db.push_back(new AutofillProfile(guid_present)); |
| + profiles_from_web_db.back()->SetInfo(NAME_FIRST, UTF8ToUTF16("John")); |
| + |
| + SyncChangeList change_list; |
| + AutofillProfile profile(guid_synced); |
| + profile.SetInfo(NAME_FIRST, UTF8ToUTF16("Jane")); |
| + change_list.push_back( |
| + autofill_syncable_service_.CreateChange(SyncChange::ACTION_ADD, profile)); |
| + change_list.push_back( |
| + autofill_syncable_service_.CreateDeleteChange(guid_present)); |
| + |
| + EXPECT_CALL(autofill_syncable_service_, LoadAutofillData(_)) |
| + .Times(1) |
| + .WillOnce(DoAll(CopyData(&profiles_from_web_db), Return(true))); |
| + EXPECT_CALL(autofill_syncable_service_, SaveChangesToWebData( |
| + DataBundleCheck(1U, 0U, 1U))) |
| + .Times(1) |
| + .WillOnce(Return(true)); |
| + |
| + MockAutofillProfileSyncableService::AutoSetSyncProcessor temp( |
| + &autofill_syncable_service_, &sync_processor_); |
| + SyncError error = autofill_syncable_service_.ProcessSyncChanges( |
| + FROM_HERE, change_list); |
| + |
| + EXPECT_FALSE(error.IsSet()); |
| +} |
| + |
| +} // namespace browser_sync |
| + |
|
dhollowa
2011/09/01 20:17:49
nit: remove extra blank line.
GeorgeY
2011/09/02 04:34:12
Done. Either this, or Lint complains :)
|
| + |
| Property changes on: chrome\browser\sync\glue\autofill_profile_syncable_service_unittest.cc |
| ___________________________________________________________________ |
| Added: svn:eol-style |
| + LF |