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

Unified Diff: chrome/browser/webdata/autofill_profile_syncable_service_unittest.cc

Issue 8065016: [Sync] Refactor non-frontend DTC to handle new API properly. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Try harder trybot (rebase). Created 9 years, 2 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/webdata/autofill_profile_syncable_service_unittest.cc
diff --git a/chrome/browser/webdata/autofill_profile_syncable_service_unittest.cc b/chrome/browser/webdata/autofill_profile_syncable_service_unittest.cc
index 90cddb0db517309470ed1032848b5d4bf1b0d391..838df14f96f10cc898bff5ebff075d4b309897d0 100644
--- a/chrome/browser/webdata/autofill_profile_syncable_service_unittest.cc
+++ b/chrome/browser/webdata/autofill_profile_syncable_service_unittest.cc
@@ -34,21 +34,6 @@ class MockAutofillProfileSyncableService
MOCK_METHOD1(LoadAutofillData, bool(std::vector<AutofillProfile*>*));
MOCK_METHOD1(SaveChangesToWebData,
bool(const AutofillProfileSyncableService::DataBundle&));
-
- // Helper for tests that do not need to setup service completely through the
- // MergeDataAndStartSyncing().
- class AutoSetSyncProcessor {
- public:
- AutoSetSyncProcessor(MockAutofillProfileSyncableService* service,
- SyncChangeProcessor* sync_processor)
- : service_(service) {
- service->set_sync_processor(sync_processor);
- }
- ~AutoSetSyncProcessor() {
- service_->set_sync_processor(NULL);
- }
- MockAutofillProfileSyncableService* service_;
- };
};
ACTION_P(CopyData, data) {
@@ -114,11 +99,23 @@ class AutofillProfileSyncableServiceTest : public testing::Test {
AutofillProfileSyncableServiceTest()
: db_thread_(BrowserThread::DB, &message_loop_) {}
+ virtual void SetUp() OVERRIDE {
+ sync_processor_.reset(new MockSyncChangeProcessor);
+ }
+
+ virtual void TearDown() OVERRIDE {
+ // Each test passes ownership of the sync processor to the SyncableService.
+ // We don't release it immediately so we can verify the mock calls, so
+ // release it at teardown. Any test that doesn't call
+ // MergeDataAndStartSyncing or set_sync_processor must ensure the
+ // sync_processor_ gets properly reset.
+ ignore_result(sync_processor_.release());
+ }
protected:
MessageLoop message_loop_;
BrowserThread db_thread_;
MockAutofillProfileSyncableService autofill_syncable_service_;
- MockSyncChangeProcessor sync_processor_;
+ scoped_ptr<MockSyncChangeProcessor> sync_processor_;
};
TEST_F(AutofillProfileSyncableServiceTest, MergeDataAndStartSyncing) {
@@ -163,15 +160,16 @@ TEST_F(AutofillProfileSyncableServiceTest, MergeDataAndStartSyncing) {
SaveChangesToWebData(DataBundleCheck(expected_bundle)))
.Times(1)
.WillOnce(Return(true));
- ON_CALL(sync_processor_, ProcessSyncChanges(_, _))
+ ON_CALL(*sync_processor_, ProcessSyncChanges(_, _))
.WillByDefault(Return(SyncError()));
- EXPECT_CALL(sync_processor_,
+ EXPECT_CALL(*sync_processor_,
ProcessSyncChanges(_, CheckSyncChanges(expected_change_list)))
.Times(1)
.WillOnce(Return(SyncError()));
+ // Takes ownership of sync_processor_.
autofill_syncable_service_.MergeDataAndStartSyncing(
- syncable::AUTOFILL_PROFILE, data_list, &sync_processor_);
+ syncable::AUTOFILL_PROFILE, data_list, sync_processor_.get());
autofill_syncable_service_.StopSyncing(syncable::AUTOFILL_PROFILE);
}
@@ -191,16 +189,17 @@ TEST_F(AutofillProfileSyncableServiceTest, GetAllSyncData) {
EXPECT_CALL(autofill_syncable_service_, SaveChangesToWebData(_))
.Times(1)
.WillOnce(Return(true));
- ON_CALL(sync_processor_, ProcessSyncChanges(_, _))
+ ON_CALL(*sync_processor_, ProcessSyncChanges(_, _))
.WillByDefault(Return(SyncError()));
- EXPECT_CALL(sync_processor_,
+ EXPECT_CALL(*sync_processor_,
ProcessSyncChanges(_, Property(&SyncChangeList::size, Eq(2U))))
.Times(1)
.WillOnce(Return(SyncError()));
SyncDataList data_list;
+ // Takes ownership of sync_processor_.
autofill_syncable_service_.MergeDataAndStartSyncing(
- syncable::AUTOFILL_PROFILE, data_list, &sync_processor_);
+ syncable::AUTOFILL_PROFILE, data_list, sync_processor_.get());
SyncDataList data =
autofill_syncable_service_.GetAllSyncData(syncable::AUTOFILL_PROFILE);
@@ -237,8 +236,7 @@ TEST_F(AutofillProfileSyncableServiceTest, ProcessSyncChanges) {
.Times(1)
.WillOnce(Return(true));
- MockAutofillProfileSyncableService::AutoSetSyncProcessor temp(
- &autofill_syncable_service_, &sync_processor_);
+ autofill_syncable_service_.set_sync_processor(sync_processor_.get());
SyncError error = autofill_syncable_service_.ProcessSyncChanges(
FROM_HERE, change_list);
@@ -253,12 +251,11 @@ TEST_F(AutofillProfileSyncableServiceTest, ActOnChange) {
profile.SetInfo(NAME_FIRST, UTF8ToUTF16("Jane"));
AutofillProfileChange change1(AutofillProfileChange::ADD, guid1, &profile);
AutofillProfileChange change2(AutofillProfileChange::REMOVE, guid2, NULL);
- ON_CALL(sync_processor_, ProcessSyncChanges(_, _))
+ ON_CALL(*sync_processor_, ProcessSyncChanges(_, _))
.WillByDefault(Return(SyncError(FROM_HERE, std::string("an error"),
syncable::AUTOFILL_PROFILE)));
- MockAutofillProfileSyncableService::AutoSetSyncProcessor temp(
- &autofill_syncable_service_, &sync_processor_);
+ autofill_syncable_service_.set_sync_processor(sync_processor_.get());
autofill_syncable_service_.ActOnChange(change1);
autofill_syncable_service_.ActOnChange(change2);
}

Powered by Google App Engine
This is Rietveld 408576698