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

Unified Diff: chrome/browser/extensions/settings/settings_sync_unittest.cc

Issue 9749012: [Sync] Have SyncableService's take ownership of their SyncChangeProcessor. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Comment Created 8 years, 9 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/extensions/settings/settings_sync_unittest.cc
diff --git a/chrome/browser/extensions/settings/settings_sync_unittest.cc b/chrome/browser/extensions/settings/settings_sync_unittest.cc
index 87945e99c6166c3c3fd8ac6be729a6f510db9910..b803931a51f95dc76cfac4bd3e2a7a25334d910d 100644
--- a/chrome/browser/extensions/settings/settings_sync_unittest.cc
+++ b/chrome/browser/extensions/settings/settings_sync_unittest.cc
@@ -142,6 +142,26 @@ class MockSyncChangeProcessor : public SyncChangeProcessor {
bool fail_all_requests_;
};
+class SyncChangeProcessorDelegate : public SyncChangeProcessor {
asargent_no_longer_on_chrome 2012/03/22 22:54:11 same thing here about duplicate code
Nicolas Zea 2012/03/22 23:05:29 See previous comment.
+ public:
+ explicit SyncChangeProcessorDelegate(SyncChangeProcessor* recipient)
+ : recipient_(recipient) {
+ DCHECK(recipient_);
+ }
+ virtual ~SyncChangeProcessorDelegate() {}
+
+ // SyncChangeProcessor implementation.
+ virtual SyncError ProcessSyncChanges(
+ const tracked_objects::Location& from_here,
+ const SyncChangeList& change_list) OVERRIDE {
+ return recipient_->ProcessSyncChanges(from_here, change_list);
+ }
+
+ private:
+ // The recipient of all sync changes.
+ SyncChangeProcessor* recipient_;
+};
+
// SettingsStorageFactory which always returns TestingSettingsStorage objects,
// and allows individually created objects to be returned.
class TestingSettingsStorageFactory : public SettingsStorageFactory {
@@ -182,7 +202,10 @@ class ExtensionSettingsSyncTest : public testing::Test {
ExtensionSettingsSyncTest()
: ui_thread_(BrowserThread::UI, MessageLoop::current()),
file_thread_(BrowserThread::FILE, MessageLoop::current()),
- storage_factory_(new util::ScopedSettingsStorageFactory()) {}
+ storage_factory_(new util::ScopedSettingsStorageFactory()),
+ sync_processor_(new MockSyncChangeProcessor),
+ sync_processor_delegate_(new SyncChangeProcessorDelegate(
+ sync_processor_.get())) {}
virtual void SetUp() OVERRIDE {
ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
@@ -233,10 +256,11 @@ class ExtensionSettingsSyncTest : public testing::Test {
content::TestBrowserThread file_thread_;
ScopedTempDir temp_dir_;
- MockSyncChangeProcessor sync_;
scoped_ptr<util::MockProfile> profile_;
scoped_ptr<SettingsFrontend> frontend_;
scoped_refptr<util::ScopedSettingsStorageFactory> storage_factory_;
+ scoped_ptr<MockSyncChangeProcessor> sync_processor_;
+ scoped_ptr<SyncChangeProcessorDelegate> sync_processor_delegate_;
};
// Get a semblance of coverage for both EXTENSION_SETTINGS and APP_SETTINGS
@@ -253,14 +277,16 @@ TEST_F(ExtensionSettingsSyncTest, NoDataDoesNotInvokeSync) {
EXPECT_EQ(0u, GetAllSyncData(model_type).size());
GetSyncableService(model_type)->MergeDataAndStartSyncing(
- model_type, SyncDataList(), &sync_);
+ model_type,
+ SyncDataList(),
+ sync_processor_delegate_.PassAs<SyncChangeProcessor>());
AddExtensionAndGetStorage("s2", type);
EXPECT_EQ(0u, GetAllSyncData(model_type).size());
GetSyncableService(model_type)->StopSyncing(model_type);
- EXPECT_EQ(0u, sync_.changes().size());
+ EXPECT_EQ(0u, sync_processor_->changes().size());
EXPECT_EQ(0u, GetAllSyncData(model_type).size());
}
@@ -293,19 +319,20 @@ TEST_F(ExtensionSettingsSyncTest, InSyncDataDoesNotInvokeSync) {
"s2", "bar", value2, model_type));
GetSyncableService(model_type)->MergeDataAndStartSyncing(
- model_type, sync_data, &sync_);
+ model_type, sync_data,
+ sync_processor_delegate_.PassAs<SyncChangeProcessor>());
// Already in sync, so no changes.
- EXPECT_EQ(0u, sync_.changes().size());
+ EXPECT_EQ(0u, sync_processor_->changes().size());
// Regression test: not-changing the synced value shouldn't result in a sync
// change, and changing the synced value should result in an update.
storage1->Set(DEFAULTS, "foo", value1);
- EXPECT_EQ(0u, sync_.changes().size());
+ EXPECT_EQ(0u, sync_processor_->changes().size());
storage1->Set(DEFAULTS, "foo", value2);
- EXPECT_EQ(1u, sync_.changes().size());
- SettingSyncData change = sync_.GetOnlyChange("s1", "foo");
+ EXPECT_EQ(1u, sync_processor_->changes().size());
+ SettingSyncData change = sync_processor_->GetOnlyChange("s1", "foo");
EXPECT_EQ(SyncChange::ACTION_UPDATE, change.change_type());
EXPECT_TRUE(value2.Equals(&change.value()));
@@ -327,14 +354,16 @@ TEST_F(ExtensionSettingsSyncTest, LocalDataWithNoSyncDataIsPushedToSync) {
storage2->Set(DEFAULTS, "bar", value2);
GetSyncableService(model_type)->MergeDataAndStartSyncing(
- model_type, SyncDataList(), &sync_);
+ model_type,
+ SyncDataList(),
+ sync_processor_delegate_.PassAs<SyncChangeProcessor>());
// All settings should have been pushed to sync.
- EXPECT_EQ(2u, sync_.changes().size());
- SettingSyncData change = sync_.GetOnlyChange("s1", "foo");
+ EXPECT_EQ(2u, sync_processor_->changes().size());
+ SettingSyncData change = sync_processor_->GetOnlyChange("s1", "foo");
EXPECT_EQ(SyncChange::ACTION_ADD, change.change_type());
EXPECT_TRUE(value1.Equals(&change.value()));
- change = sync_.GetOnlyChange("s2", "bar");
+ change = sync_processor_->GetOnlyChange("s2", "bar");
EXPECT_EQ(SyncChange::ACTION_ADD, change.change_type());
EXPECT_TRUE(value2.Equals(&change.value()));
@@ -363,14 +392,15 @@ TEST_F(ExtensionSettingsSyncTest, AnySyncDataOverwritesLocalData) {
sync_data.push_back(settings_sync_util::CreateData(
"s2", "bar", value2, model_type));
GetSyncableService(model_type)->MergeDataAndStartSyncing(
- model_type, sync_data, &sync_);
+ model_type, sync_data,
+ sync_processor_delegate_.PassAs<SyncChangeProcessor>());
expected1.Set("foo", value1.DeepCopy());
expected2.Set("bar", value2.DeepCopy());
SettingsStorage* storage2 = AddExtensionAndGetStorage("s2", type);
// All changes should be local, so no sync changes.
- EXPECT_EQ(0u, sync_.changes().size());
+ EXPECT_EQ(0u, sync_processor_->changes().size());
// Sync settings should have been pushed to local settings.
EXPECT_PRED_FORMAT2(SettingsEq, expected1, storage1->Get());
@@ -403,7 +433,8 @@ TEST_F(ExtensionSettingsSyncTest, ProcessSyncChanges) {
"s2", "bar", value2, model_type));
GetSyncableService(model_type)->MergeDataAndStartSyncing(
- model_type, sync_data, &sync_);
+ model_type, sync_data,
+ sync_processor_delegate_.PassAs<SyncChangeProcessor>());
expected2.Set("bar", value2.DeepCopy());
// Make sync add some settings.
@@ -475,7 +506,8 @@ TEST_F(ExtensionSettingsSyncTest, PushToSync) {
"s4", "bar", value2, model_type));
GetSyncableService(model_type)->MergeDataAndStartSyncing(
- model_type, sync_data, &sync_);
+ model_type, sync_data,
+ sync_processor_delegate_.PassAs<SyncChangeProcessor>());
// Add something locally.
storage1->Set(DEFAULTS, "bar", value2);
@@ -483,45 +515,45 @@ TEST_F(ExtensionSettingsSyncTest, PushToSync) {
storage3->Set(DEFAULTS, "foo", value1);
storage4->Set(DEFAULTS, "foo", value1);
- SettingSyncData change = sync_.GetOnlyChange("s1", "bar");
+ SettingSyncData change = sync_processor_->GetOnlyChange("s1", "bar");
EXPECT_EQ(SyncChange::ACTION_ADD, change.change_type());
EXPECT_TRUE(value2.Equals(&change.value()));
- sync_.GetOnlyChange("s2", "bar");
+ sync_processor_->GetOnlyChange("s2", "bar");
EXPECT_EQ(SyncChange::ACTION_ADD, change.change_type());
EXPECT_TRUE(value2.Equals(&change.value()));
- change = sync_.GetOnlyChange("s3", "foo");
+ change = sync_processor_->GetOnlyChange("s3", "foo");
EXPECT_EQ(SyncChange::ACTION_ADD, change.change_type());
EXPECT_TRUE(value1.Equals(&change.value()));
- change = sync_.GetOnlyChange("s4", "foo");
+ change = sync_processor_->GetOnlyChange("s4", "foo");
EXPECT_EQ(SyncChange::ACTION_ADD, change.change_type());
EXPECT_TRUE(value1.Equals(&change.value()));
// Change something locally, storage1/3 the new setting and storage2/4 the
// initial setting, for all combinations of local vs sync intialisation and
// new vs initial.
- sync_.ClearChanges();
+ sync_processor_->ClearChanges();
storage1->Set(DEFAULTS, "bar", value1);
storage2->Set(DEFAULTS, "foo", value2);
storage3->Set(DEFAULTS, "bar", value1);
storage4->Set(DEFAULTS, "foo", value2);
- change = sync_.GetOnlyChange("s1", "bar");
+ change = sync_processor_->GetOnlyChange("s1", "bar");
EXPECT_EQ(SyncChange::ACTION_UPDATE, change.change_type());
EXPECT_TRUE(value1.Equals(&change.value()));
- change = sync_.GetOnlyChange("s2", "foo");
+ change = sync_processor_->GetOnlyChange("s2", "foo");
EXPECT_EQ(SyncChange::ACTION_UPDATE, change.change_type());
EXPECT_TRUE(value2.Equals(&change.value()));
- change = sync_.GetOnlyChange("s3", "bar");
+ change = sync_processor_->GetOnlyChange("s3", "bar");
EXPECT_EQ(SyncChange::ACTION_UPDATE, change.change_type());
EXPECT_TRUE(value1.Equals(&change.value()));
- change = sync_.GetOnlyChange("s4", "foo");
+ change = sync_processor_->GetOnlyChange("s4", "foo");
EXPECT_EQ(SyncChange::ACTION_UPDATE, change.change_type());
EXPECT_TRUE(value2.Equals(&change.value()));
// Remove something locally, storage1/3 the new setting and storage2/4 the
// initial setting, for all combinations of local vs sync intialisation and
// new vs initial.
- sync_.ClearChanges();
+ sync_processor_->ClearChanges();
storage1->Remove("foo");
storage2->Remove("bar");
storage3->Remove("foo");
@@ -529,25 +561,25 @@ TEST_F(ExtensionSettingsSyncTest, PushToSync) {
EXPECT_EQ(
SyncChange::ACTION_DELETE,
- sync_.GetOnlyChange("s1", "foo").change_type());
+ sync_processor_->GetOnlyChange("s1", "foo").change_type());
EXPECT_EQ(
SyncChange::ACTION_DELETE,
- sync_.GetOnlyChange("s2", "bar").change_type());
+ sync_processor_->GetOnlyChange("s2", "bar").change_type());
EXPECT_EQ(
SyncChange::ACTION_DELETE,
- sync_.GetOnlyChange("s3", "foo").change_type());
+ sync_processor_->GetOnlyChange("s3", "foo").change_type());
EXPECT_EQ(
SyncChange::ACTION_DELETE,
- sync_.GetOnlyChange("s4", "bar").change_type());
+ sync_processor_->GetOnlyChange("s4", "bar").change_type());
// Remove some nonexistent settings.
- sync_.ClearChanges();
+ sync_processor_->ClearChanges();
storage1->Remove("foo");
storage2->Remove("bar");
storage3->Remove("foo");
storage4->Remove("bar");
- EXPECT_EQ(0u, sync_.changes().size());
+ EXPECT_EQ(0u, sync_processor_->changes().size());
// Clear the rest of the settings. Add the removed ones back first so that
// more than one setting is cleared.
@@ -556,7 +588,7 @@ TEST_F(ExtensionSettingsSyncTest, PushToSync) {
storage3->Set(DEFAULTS, "foo", value1);
storage4->Set(DEFAULTS, "bar", value2);
- sync_.ClearChanges();
+ sync_processor_->ClearChanges();
storage1->Clear();
storage2->Clear();
storage3->Clear();
@@ -564,28 +596,28 @@ TEST_F(ExtensionSettingsSyncTest, PushToSync) {
EXPECT_EQ(
SyncChange::ACTION_DELETE,
- sync_.GetOnlyChange("s1", "foo").change_type());
+ sync_processor_->GetOnlyChange("s1", "foo").change_type());
EXPECT_EQ(
SyncChange::ACTION_DELETE,
- sync_.GetOnlyChange("s1", "bar").change_type());
+ sync_processor_->GetOnlyChange("s1", "bar").change_type());
EXPECT_EQ(
SyncChange::ACTION_DELETE,
- sync_.GetOnlyChange("s2", "foo").change_type());
+ sync_processor_->GetOnlyChange("s2", "foo").change_type());
EXPECT_EQ(
SyncChange::ACTION_DELETE,
- sync_.GetOnlyChange("s2", "bar").change_type());
+ sync_processor_->GetOnlyChange("s2", "bar").change_type());
EXPECT_EQ(
SyncChange::ACTION_DELETE,
- sync_.GetOnlyChange("s3", "foo").change_type());
+ sync_processor_->GetOnlyChange("s3", "foo").change_type());
EXPECT_EQ(
SyncChange::ACTION_DELETE,
- sync_.GetOnlyChange("s3", "bar").change_type());
+ sync_processor_->GetOnlyChange("s3", "bar").change_type());
EXPECT_EQ(
SyncChange::ACTION_DELETE,
- sync_.GetOnlyChange("s4", "foo").change_type());
+ sync_processor_->GetOnlyChange("s4", "foo").change_type());
EXPECT_EQ(
SyncChange::ACTION_DELETE,
- sync_.GetOnlyChange("s4", "bar").change_type());
+ sync_processor_->GetOnlyChange("s4", "bar").change_type());
GetSyncableService(model_type)->StopSyncing(model_type);
}
@@ -621,21 +653,27 @@ TEST_F(ExtensionSettingsSyncTest, ExtensionAndAppSettingsSyncSeparately) {
sync_data.push_back(settings_sync_util::CreateData(
"s1", "foo", value1, syncable::EXTENSION_SETTINGS));
- GetSyncableService(syncable::EXTENSION_SETTINGS)->
- MergeDataAndStartSyncing(syncable::EXTENSION_SETTINGS, sync_data, &sync_);
+ GetSyncableService(syncable::EXTENSION_SETTINGS)->MergeDataAndStartSyncing(
+ syncable::EXTENSION_SETTINGS,
+ sync_data,
+ sync_processor_delegate_.PassAs<SyncChangeProcessor>());
GetSyncableService(syncable::EXTENSION_SETTINGS)->
StopSyncing(syncable::EXTENSION_SETTINGS);
- EXPECT_EQ(0u, sync_.changes().size());
+ EXPECT_EQ(0u, sync_processor_->changes().size());
sync_data.clear();
sync_data.push_back(settings_sync_util::CreateData(
"s2", "bar", value2, syncable::APP_SETTINGS));
- GetSyncableService(syncable::APP_SETTINGS)->
- MergeDataAndStartSyncing(syncable::APP_SETTINGS, sync_data, &sync_);
+ scoped_ptr<SyncChangeProcessorDelegate> app_settings_delegate_(
+ new SyncChangeProcessorDelegate(sync_processor_.get()));
+ GetSyncableService(syncable::APP_SETTINGS)->MergeDataAndStartSyncing(
+ syncable::APP_SETTINGS,
+ sync_data,
+ app_settings_delegate_.PassAs<SyncChangeProcessor>());
GetSyncableService(syncable::APP_SETTINGS)->
StopSyncing(syncable::APP_SETTINGS);
- EXPECT_EQ(0u, sync_.changes().size());
+ EXPECT_EQ(0u, sync_processor_->changes().size());
}
TEST_F(ExtensionSettingsSyncTest, FailingStartSyncingDisablesSync) {
@@ -664,7 +702,9 @@ TEST_F(ExtensionSettingsSyncTest, FailingStartSyncingDisablesSync) {
sync_data.push_back(settings_sync_util::CreateData(
"bad", "foo", fooValue, model_type));
GetSyncableService(model_type)->MergeDataAndStartSyncing(
- model_type, sync_data, &sync_);
+ model_type,
+ sync_data,
+ sync_processor_delegate_.PassAs<SyncChangeProcessor>());
}
testing_factory->GetExisting("bad")->SetFailAllRequests(false);
@@ -679,14 +719,14 @@ TEST_F(ExtensionSettingsSyncTest, FailingStartSyncingDisablesSync) {
}
// Changes made to good should be sent to sync, changes from bad shouldn't.
- sync_.ClearChanges();
+ sync_processor_->ClearChanges();
good->Set(DEFAULTS, "bar", barValue);
bad->Set(DEFAULTS, "bar", barValue);
EXPECT_EQ(
SyncChange::ACTION_ADD,
- sync_.GetOnlyChange("good", "bar").change_type());
- EXPECT_EQ(1u, sync_.changes().size());
+ sync_processor_->GetOnlyChange("good", "bar").change_type());
+ EXPECT_EQ(1u, sync_processor_->changes().size());
{
DictionaryValue dict;
@@ -727,14 +767,14 @@ TEST_F(ExtensionSettingsSyncTest, FailingStartSyncingDisablesSync) {
// Changes made to bad still shouldn't go to sync, even though it didn't fail
// last time.
- sync_.ClearChanges();
+ sync_processor_->ClearChanges();
good->Set(DEFAULTS, "bar", fooValue);
bad->Set(DEFAULTS, "bar", fooValue);
EXPECT_EQ(
SyncChange::ACTION_UPDATE,
- sync_.GetOnlyChange("good", "bar").change_type());
- EXPECT_EQ(1u, sync_.changes().size());
+ sync_processor_->GetOnlyChange("good", "bar").change_type());
+ EXPECT_EQ(1u, sync_processor_->changes().size());
{
DictionaryValue dict;
@@ -774,36 +814,40 @@ TEST_F(ExtensionSettingsSyncTest, FailingStartSyncingDisablesSync) {
}
// Restarting sync should make bad start syncing again.
- sync_.ClearChanges();
+ sync_processor_->ClearChanges();
GetSyncableService(model_type)->StopSyncing(model_type);
+ sync_processor_delegate_.reset(new SyncChangeProcessorDelegate(
+ sync_processor_.get()));
GetSyncableService(model_type)->MergeDataAndStartSyncing(
- model_type, SyncDataList(), &sync_);
+ model_type,
+ SyncDataList(),
+ sync_processor_delegate_.PassAs<SyncChangeProcessor>());
// Local settings will have been pushed to sync, since it's empty (in this
// test; presumably it wouldn't be live, since we've been getting changes).
EXPECT_EQ(
SyncChange::ACTION_ADD,
- sync_.GetOnlyChange("good", "foo").change_type());
+ sync_processor_->GetOnlyChange("good", "foo").change_type());
EXPECT_EQ(
SyncChange::ACTION_ADD,
- sync_.GetOnlyChange("good", "bar").change_type());
+ sync_processor_->GetOnlyChange("good", "bar").change_type());
EXPECT_EQ(
SyncChange::ACTION_ADD,
- sync_.GetOnlyChange("bad", "bar").change_type());
- EXPECT_EQ(3u, sync_.changes().size());
+ sync_processor_->GetOnlyChange("bad", "bar").change_type());
+ EXPECT_EQ(3u, sync_processor_->changes().size());
// Live local changes now get pushed, too.
- sync_.ClearChanges();
+ sync_processor_->ClearChanges();
good->Set(DEFAULTS, "bar", barValue);
bad->Set(DEFAULTS, "bar", barValue);
EXPECT_EQ(
SyncChange::ACTION_UPDATE,
- sync_.GetOnlyChange("good", "bar").change_type());
+ sync_processor_->GetOnlyChange("good", "bar").change_type());
EXPECT_EQ(
SyncChange::ACTION_UPDATE,
- sync_.GetOnlyChange("bad", "bar").change_type());
- EXPECT_EQ(2u, sync_.changes().size());
+ sync_processor_->GetOnlyChange("bad", "bar").change_type());
+ EXPECT_EQ(2u, sync_processor_->changes().size());
// And ProcessSyncChanges work, too.
{
@@ -852,10 +896,12 @@ TEST_F(ExtensionSettingsSyncTest, FailingProcessChangesDisablesSync) {
sync_data.push_back(settings_sync_util::CreateData(
"bad", "foo", fooValue, model_type));
GetSyncableService(model_type)->MergeDataAndStartSyncing(
- model_type, sync_data, &sync_);
+ model_type,
+ sync_data,
+ sync_processor_delegate_.PassAs<SyncChangeProcessor>());
}
- EXPECT_EQ(0u, sync_.changes().size());
+ EXPECT_EQ(0u, sync_processor_->changes().size());
{
DictionaryValue dict;
@@ -893,14 +939,14 @@ TEST_F(ExtensionSettingsSyncTest, FailingProcessChangesDisablesSync) {
}
// No more changes sent to sync for bad.
- sync_.ClearChanges();
+ sync_processor_->ClearChanges();
good->Set(DEFAULTS, "foo", barValue);
bad->Set(DEFAULTS, "foo", barValue);
EXPECT_EQ(
SyncChange::ACTION_UPDATE,
- sync_.GetOnlyChange("good", "foo").change_type());
- EXPECT_EQ(1u, sync_.changes().size());
+ sync_processor_->GetOnlyChange("good", "foo").change_type());
+ EXPECT_EQ(1u, sync_processor_->changes().size());
// No more changes received from sync should go to bad.
{
@@ -955,27 +1001,29 @@ TEST_F(ExtensionSettingsSyncTest, FailingGetAllSyncDataDoesntStopSync) {
// Sync shouldn't be disabled for good (nor bad -- but this is unimportant).
GetSyncableService(model_type)->MergeDataAndStartSyncing(
- model_type, SyncDataList(), &sync_);
+ model_type,
+ SyncDataList(),
+ sync_processor_delegate_.PassAs<SyncChangeProcessor>());
EXPECT_EQ(
SyncChange::ACTION_ADD,
- sync_.GetOnlyChange("good", "foo").change_type());
+ sync_processor_->GetOnlyChange("good", "foo").change_type());
EXPECT_EQ(
SyncChange::ACTION_ADD,
- sync_.GetOnlyChange("bad", "foo").change_type());
- EXPECT_EQ(2u, sync_.changes().size());
+ sync_processor_->GetOnlyChange("bad", "foo").change_type());
+ EXPECT_EQ(2u, sync_processor_->changes().size());
- sync_.ClearChanges();
+ sync_processor_->ClearChanges();
good->Set(DEFAULTS, "bar", barValue);
bad->Set(DEFAULTS, "bar", barValue);
EXPECT_EQ(
SyncChange::ACTION_ADD,
- sync_.GetOnlyChange("good", "bar").change_type());
+ sync_processor_->GetOnlyChange("good", "bar").change_type());
EXPECT_EQ(
SyncChange::ACTION_ADD,
- sync_.GetOnlyChange("bad", "bar").change_type());
- EXPECT_EQ(2u, sync_.changes().size());
+ sync_processor_->GetOnlyChange("bad", "bar").change_type());
+ EXPECT_EQ(2u, sync_processor_->changes().size());
}
TEST_F(ExtensionSettingsSyncTest, FailureToReadChangesToPushDisablesSync) {
@@ -999,23 +1047,25 @@ TEST_F(ExtensionSettingsSyncTest, FailureToReadChangesToPushDisablesSync) {
// get them so won't.
testing_factory->GetExisting("bad")->SetFailAllRequests(true);
GetSyncableService(model_type)->MergeDataAndStartSyncing(
- model_type, SyncDataList(), &sync_);
+ model_type,
+ SyncDataList(),
+ sync_processor_delegate_.PassAs<SyncChangeProcessor>());
testing_factory->GetExisting("bad")->SetFailAllRequests(false);
EXPECT_EQ(
SyncChange::ACTION_ADD,
- sync_.GetOnlyChange("good", "foo").change_type());
- EXPECT_EQ(1u, sync_.changes().size());
+ sync_processor_->GetOnlyChange("good", "foo").change_type());
+ EXPECT_EQ(1u, sync_processor_->changes().size());
// bad should now be disabled for sync.
- sync_.ClearChanges();
+ sync_processor_->ClearChanges();
good->Set(DEFAULTS, "bar", barValue);
bad->Set(DEFAULTS, "bar", barValue);
EXPECT_EQ(
SyncChange::ACTION_ADD,
- sync_.GetOnlyChange("good", "bar").change_type());
- EXPECT_EQ(1u, sync_.changes().size());
+ sync_processor_->GetOnlyChange("good", "bar").change_type());
+ EXPECT_EQ(1u, sync_processor_->changes().size());
{
SyncChangeList change_list;
@@ -1043,36 +1093,40 @@ TEST_F(ExtensionSettingsSyncTest, FailureToReadChangesToPushDisablesSync) {
// Re-enabling sync without failing should cause the local changes from bad
// to be pushed to sync successfully, as should future changes to bad.
- sync_.ClearChanges();
+ sync_processor_->ClearChanges();
GetSyncableService(model_type)->StopSyncing(model_type);
+ sync_processor_delegate_.reset(new SyncChangeProcessorDelegate(
+ sync_processor_.get()));
GetSyncableService(model_type)->MergeDataAndStartSyncing(
- model_type, SyncDataList(), &sync_);
+ model_type,
+ SyncDataList(),
+ sync_processor_delegate_.PassAs<SyncChangeProcessor>());
EXPECT_EQ(
SyncChange::ACTION_ADD,
- sync_.GetOnlyChange("good", "foo").change_type());
+ sync_processor_->GetOnlyChange("good", "foo").change_type());
EXPECT_EQ(
SyncChange::ACTION_ADD,
- sync_.GetOnlyChange("good", "bar").change_type());
+ sync_processor_->GetOnlyChange("good", "bar").change_type());
EXPECT_EQ(
SyncChange::ACTION_ADD,
- sync_.GetOnlyChange("bad", "foo").change_type());
+ sync_processor_->GetOnlyChange("bad", "foo").change_type());
EXPECT_EQ(
SyncChange::ACTION_ADD,
- sync_.GetOnlyChange("bad", "bar").change_type());
- EXPECT_EQ(4u, sync_.changes().size());
+ sync_processor_->GetOnlyChange("bad", "bar").change_type());
+ EXPECT_EQ(4u, sync_processor_->changes().size());
- sync_.ClearChanges();
+ sync_processor_->ClearChanges();
good->Set(DEFAULTS, "bar", fooValue);
bad->Set(DEFAULTS, "bar", fooValue);
EXPECT_EQ(
SyncChange::ACTION_UPDATE,
- sync_.GetOnlyChange("good", "bar").change_type());
+ sync_processor_->GetOnlyChange("good", "bar").change_type());
EXPECT_EQ(
SyncChange::ACTION_UPDATE,
- sync_.GetOnlyChange("good", "bar").change_type());
- EXPECT_EQ(2u, sync_.changes().size());
+ sync_processor_->GetOnlyChange("good", "bar").change_type());
+ EXPECT_EQ(2u, sync_processor_->changes().size());
}
TEST_F(ExtensionSettingsSyncTest, FailureToPushLocalStateDisablesSync) {
@@ -1092,20 +1146,22 @@ TEST_F(ExtensionSettingsSyncTest, FailureToPushLocalStateDisablesSync) {
// Only set bad; setting good will cause it to fail below.
bad->Set(DEFAULTS, "foo", fooValue);
- sync_.SetFailAllRequests(true);
+ sync_processor_->SetFailAllRequests(true);
GetSyncableService(model_type)->MergeDataAndStartSyncing(
- model_type, SyncDataList(), &sync_);
- sync_.SetFailAllRequests(false);
+ model_type,
+ SyncDataList(),
+ sync_processor_delegate_.PassAs<SyncChangeProcessor>());
+ sync_processor_->SetFailAllRequests(false);
// Changes from good will be send to sync, changes from bad won't.
- sync_.ClearChanges();
+ sync_processor_->ClearChanges();
good->Set(DEFAULTS, "foo", barValue);
bad->Set(DEFAULTS, "foo", barValue);
EXPECT_EQ(
SyncChange::ACTION_ADD,
- sync_.GetOnlyChange("good", "foo").change_type());
- EXPECT_EQ(1u, sync_.changes().size());
+ sync_processor_->GetOnlyChange("good", "foo").change_type());
+ EXPECT_EQ(1u, sync_processor_->changes().size());
// Changes from sync will be sent to good, not to bad.
{
@@ -1130,33 +1186,37 @@ TEST_F(ExtensionSettingsSyncTest, FailureToPushLocalStateDisablesSync) {
}
// Restarting sync makes everything work again.
- sync_.ClearChanges();
+ sync_processor_->ClearChanges();
GetSyncableService(model_type)->StopSyncing(model_type);
+ sync_processor_delegate_.reset(new SyncChangeProcessorDelegate(
+ sync_processor_.get()));
GetSyncableService(model_type)->MergeDataAndStartSyncing(
- model_type, SyncDataList(), &sync_);
+ model_type,
+ SyncDataList(),
+ sync_processor_delegate_.PassAs<SyncChangeProcessor>());
EXPECT_EQ(
SyncChange::ACTION_ADD,
- sync_.GetOnlyChange("good", "foo").change_type());
+ sync_processor_->GetOnlyChange("good", "foo").change_type());
EXPECT_EQ(
SyncChange::ACTION_ADD,
- sync_.GetOnlyChange("good", "bar").change_type());
+ sync_processor_->GetOnlyChange("good", "bar").change_type());
EXPECT_EQ(
SyncChange::ACTION_ADD,
- sync_.GetOnlyChange("bad", "foo").change_type());
- EXPECT_EQ(3u, sync_.changes().size());
+ sync_processor_->GetOnlyChange("bad", "foo").change_type());
+ EXPECT_EQ(3u, sync_processor_->changes().size());
- sync_.ClearChanges();
+ sync_processor_->ClearChanges();
good->Set(DEFAULTS, "foo", fooValue);
bad->Set(DEFAULTS, "foo", fooValue);
EXPECT_EQ(
SyncChange::ACTION_UPDATE,
- sync_.GetOnlyChange("good", "foo").change_type());
+ sync_processor_->GetOnlyChange("good", "foo").change_type());
EXPECT_EQ(
SyncChange::ACTION_UPDATE,
- sync_.GetOnlyChange("good", "foo").change_type());
- EXPECT_EQ(2u, sync_.changes().size());
+ sync_processor_->GetOnlyChange("good", "foo").change_type());
+ EXPECT_EQ(2u, sync_processor_->changes().size());
}
TEST_F(ExtensionSettingsSyncTest, FailureToPushLocalChangeDisablesSync) {
@@ -1174,28 +1234,30 @@ TEST_F(ExtensionSettingsSyncTest, FailureToPushLocalChangeDisablesSync) {
SettingsStorage* bad = AddExtensionAndGetStorage("bad", type);
GetSyncableService(model_type)->MergeDataAndStartSyncing(
- model_type, SyncDataList(), &sync_);
+ model_type,
+ SyncDataList(),
+ sync_processor_delegate_.PassAs<SyncChangeProcessor>());
// bad will fail to send changes.
good->Set(DEFAULTS, "foo", fooValue);
- sync_.SetFailAllRequests(true);
+ sync_processor_->SetFailAllRequests(true);
bad->Set(DEFAULTS, "foo", fooValue);
- sync_.SetFailAllRequests(false);
+ sync_processor_->SetFailAllRequests(false);
EXPECT_EQ(
SyncChange::ACTION_ADD,
- sync_.GetOnlyChange("good", "foo").change_type());
- EXPECT_EQ(1u, sync_.changes().size());
+ sync_processor_->GetOnlyChange("good", "foo").change_type());
+ EXPECT_EQ(1u, sync_processor_->changes().size());
// No further changes should be sent from bad.
- sync_.ClearChanges();
+ sync_processor_->ClearChanges();
good->Set(DEFAULTS, "foo", barValue);
bad->Set(DEFAULTS, "foo", barValue);
EXPECT_EQ(
SyncChange::ACTION_UPDATE,
- sync_.GetOnlyChange("good", "foo").change_type());
- EXPECT_EQ(1u, sync_.changes().size());
+ sync_processor_->GetOnlyChange("good", "foo").change_type());
+ EXPECT_EQ(1u, sync_processor_->changes().size());
// Changes from sync will be sent to good, not to bad.
{
@@ -1220,37 +1282,41 @@ TEST_F(ExtensionSettingsSyncTest, FailureToPushLocalChangeDisablesSync) {
}
// Restarting sync makes everything work again.
- sync_.ClearChanges();
+ sync_processor_->ClearChanges();
GetSyncableService(model_type)->StopSyncing(model_type);
+ sync_processor_delegate_.reset(new SyncChangeProcessorDelegate(
+ sync_processor_.get()));
GetSyncableService(model_type)->MergeDataAndStartSyncing(
- model_type, SyncDataList(), &sync_);
+ model_type,
+ SyncDataList(),
+ sync_processor_delegate_.PassAs<SyncChangeProcessor>());
EXPECT_EQ(
SyncChange::ACTION_ADD,
- sync_.GetOnlyChange("good", "foo").change_type());
+ sync_processor_->GetOnlyChange("good", "foo").change_type());
EXPECT_EQ(
SyncChange::ACTION_ADD,
- sync_.GetOnlyChange("good", "bar").change_type());
+ sync_processor_->GetOnlyChange("good", "bar").change_type());
EXPECT_EQ(
SyncChange::ACTION_ADD,
- sync_.GetOnlyChange("bad", "foo").change_type());
- EXPECT_EQ(3u, sync_.changes().size());
+ sync_processor_->GetOnlyChange("bad", "foo").change_type());
+ EXPECT_EQ(3u, sync_processor_->changes().size());
- sync_.ClearChanges();
+ sync_processor_->ClearChanges();
good->Set(DEFAULTS, "foo", fooValue);
bad->Set(DEFAULTS, "foo", fooValue);
EXPECT_EQ(
SyncChange::ACTION_UPDATE,
- sync_.GetOnlyChange("good", "foo").change_type());
+ sync_processor_->GetOnlyChange("good", "foo").change_type());
EXPECT_EQ(
SyncChange::ACTION_UPDATE,
- sync_.GetOnlyChange("good", "foo").change_type());
- EXPECT_EQ(2u, sync_.changes().size());
+ sync_processor_->GetOnlyChange("good", "foo").change_type());
+ EXPECT_EQ(2u, sync_processor_->changes().size());
}
TEST_F(ExtensionSettingsSyncTest,
- LargeOutgoingChangeRejectedButIncomingAccepted) {
+ LargeOutgoingChangeRejectedButIncomingAccepted) {
syncable::ModelType model_type = syncable::APP_SETTINGS;
Extension::Type type = Extension::TYPE_PACKAGED_APP;
@@ -1262,12 +1328,14 @@ TEST_F(ExtensionSettingsSyncTest,
StringValue large_value(string_5k);
GetSyncableService(model_type)->MergeDataAndStartSyncing(
- model_type, SyncDataList(), &sync_);
+ model_type,
+ SyncDataList(),
+ sync_processor_delegate_.PassAs<SyncChangeProcessor>());
// Large local change rejected and doesn't get sent out.
SettingsStorage* storage1 = AddExtensionAndGetStorage("s1", type);
EXPECT_TRUE(storage1->Set(DEFAULTS, "large_value", large_value).HasError());
- EXPECT_EQ(0u, sync_.changes().size());
+ EXPECT_EQ(0u, sync_processor_->changes().size());
// Large incoming change should still get accepted.
SettingsStorage* storage2 = AddExtensionAndGetStorage("s2", type);

Powered by Google App Engine
This is Rietveld 408576698