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

Unified Diff: components/sync/engine_impl/sync_manager_impl_unittest.cc

Issue 2644373003: Revert of [Sync] Make directory types registration explicit in ModelTypeRegistry (Closed)
Patch Set: Created 3 years, 11 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
« no previous file with comments | « components/sync/engine_impl/sync_manager_impl.cc ('k') | components/sync/engine_impl/sync_scheduler.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/sync/engine_impl/sync_manager_impl_unittest.cc
diff --git a/components/sync/engine_impl/sync_manager_impl_unittest.cc b/components/sync/engine_impl/sync_manager_impl_unittest.cc
index 8bf15f9331318d149417a52d46eb6e2c63760300..afaab93d635294de0a75e045dc895f9113103a5f 100644
--- a/components/sync/engine_impl/sync_manager_impl_unittest.cc
+++ b/components/sync/engine_impl/sync_manager_impl_unittest.cc
@@ -1017,6 +1017,8 @@
EXPECT_FALSE(js_backend_.IsInitialized());
std::vector<scoped_refptr<ModelSafeWorker>> workers;
+ ModelSafeRoutingInfo routing_info;
+ GetModelSafeRoutingInfo(&routing_info);
// This works only because all routing info types are GROUP_PASSIVE.
// If we had types in other groups, we would need additional workers
@@ -1050,10 +1052,10 @@
EXPECT_EQ(EngineComponentsFactory::STORAGE_ON_DISK, storage_used_);
if (initialization_succeeded_) {
- ModelTypeSet enabled_types = GetEnabledTypes();
- for (auto it = enabled_types.First(); it.Good(); it.Inc()) {
- type_roots_[it.Get()] =
- MakeTypeRoot(sync_manager_.GetUserShare(), it.Get());
+ for (ModelSafeRoutingInfo::iterator i = routing_info.begin();
+ i != routing_info.end(); ++i) {
+ type_roots_[i->first] =
+ MakeTypeRoot(sync_manager_.GetUserShare(), i->first);
}
}
@@ -1069,20 +1071,23 @@
PumpLoop();
}
+ void GetModelSafeRoutingInfo(ModelSafeRoutingInfo* out) {
+ (*out)[NIGORI] = GROUP_PASSIVE;
+ (*out)[DEVICE_INFO] = GROUP_PASSIVE;
+ (*out)[EXPERIMENTS] = GROUP_PASSIVE;
+ (*out)[BOOKMARKS] = GROUP_PASSIVE;
+ (*out)[THEMES] = GROUP_PASSIVE;
+ (*out)[SESSIONS] = GROUP_PASSIVE;
+ (*out)[PASSWORDS] = GROUP_PASSIVE;
+ (*out)[PREFERENCES] = GROUP_PASSIVE;
+ (*out)[PRIORITY_PREFERENCES] = GROUP_PASSIVE;
+ (*out)[ARTICLES] = GROUP_PASSIVE;
+ }
+
ModelTypeSet GetEnabledTypes() {
- ModelTypeSet enabled_types;
- enabled_types.Put(NIGORI);
- enabled_types.Put(DEVICE_INFO);
- enabled_types.Put(EXPERIMENTS);
- enabled_types.Put(BOOKMARKS);
- enabled_types.Put(THEMES);
- enabled_types.Put(SESSIONS);
- enabled_types.Put(PASSWORDS);
- enabled_types.Put(PREFERENCES);
- enabled_types.Put(PRIORITY_PREFERENCES);
- enabled_types.Put(ARTICLES);
-
- return enabled_types;
+ ModelSafeRoutingInfo routing_info;
+ GetModelSafeRoutingInfo(&routing_info);
+ return GetRoutingInfoTypes(routing_info);
}
void OnChangesApplied(ModelType model_type,
@@ -2658,15 +2663,18 @@
// Verify transaction version of a model type is incremented when node of
// that type is updated.
TEST_F(SyncManagerTest, IncrementTransactionVersion) {
+ ModelSafeRoutingInfo routing_info;
+ GetModelSafeRoutingInfo(&routing_info);
+
{
ReadTransaction read_trans(FROM_HERE, sync_manager_.GetUserShare());
- ModelTypeSet enabled_types = GetEnabledTypes();
- for (auto it = enabled_types.First(); it.Good(); it.Inc()) {
+ for (ModelSafeRoutingInfo::iterator i = routing_info.begin();
+ i != routing_info.end(); ++i) {
// Transaction version is incremented when SyncManagerTest::SetUp()
// creates a node of each type.
EXPECT_EQ(1,
sync_manager_.GetUserShare()->directory->GetTransactionVersion(
- it.Get()));
+ i->first));
}
}
@@ -2680,11 +2688,11 @@
{
ReadTransaction read_trans(FROM_HERE, sync_manager_.GetUserShare());
- ModelTypeSet enabled_types = GetEnabledTypes();
- for (auto it = enabled_types.First(); it.Good(); it.Inc()) {
- EXPECT_EQ(it.Get() == BOOKMARKS ? 2 : 1,
+ for (ModelSafeRoutingInfo::iterator i = routing_info.begin();
+ i != routing_info.end(); ++i) {
+ EXPECT_EQ(i->first == BOOKMARKS ? 2 : 1,
sync_manager_.GetUserShare()->directory->GetTransactionVersion(
- it.Get()));
+ i->first));
}
}
}
@@ -2775,19 +2783,33 @@
};
// Test that the configuration params are properly created and sent to
-// ScheduleConfigure. No callback should be invoked.
+// ScheduleConfigure. No callback should be invoked. Any disabled datatypes
+// should be purged.
TEST_F(SyncManagerTestWithMockScheduler, BasicConfiguration) {
ConfigureReason reason = CONFIGURE_REASON_RECONFIGURATION;
ModelTypeSet types_to_download(BOOKMARKS, PREFERENCES);
+ ModelSafeRoutingInfo new_routing_info;
+ GetModelSafeRoutingInfo(&new_routing_info);
+ ModelTypeSet enabled_types = GetRoutingInfoTypes(new_routing_info);
+ ModelTypeSet disabled_types = Difference(ModelTypeSet::All(), enabled_types);
ConfigurationParams params;
EXPECT_CALL(*scheduler(), Start(SyncScheduler::CONFIGURATION_MODE, _));
EXPECT_CALL(*scheduler(), ScheduleConfiguration(_))
.WillOnce(SaveArg<0>(&params));
+ // Set data for all types.
+ ModelTypeSet protocol_types = ProtocolTypes();
+ for (ModelTypeSet::Iterator iter = protocol_types.First(); iter.Good();
+ iter.Inc()) {
+ SetProgressMarkerForType(iter.Get(), true);
+ }
+
+ sync_manager_.PurgeDisabledTypes(disabled_types, ModelTypeSet(),
+ ModelTypeSet());
CallbackCounter ready_task_counter, retry_task_counter;
sync_manager_.ConfigureSyncer(
- reason, types_to_download,
+ reason, types_to_download, new_routing_info,
base::Bind(&CallbackCounter::Callback,
base::Unretained(&ready_task_counter)),
base::Bind(&CallbackCounter::Callback,
@@ -2796,27 +2818,67 @@
EXPECT_EQ(0, retry_task_counter.times_called());
EXPECT_EQ(sync_pb::GetUpdatesCallerInfo::RECONFIGURATION, params.source);
EXPECT_EQ(types_to_download, params.types_to_download);
-}
-
-// Test that PurgeDisabledTypes only purges recently disabled types leaving
-// others intact.
-TEST_F(SyncManagerTestWithMockScheduler, PurgeDisabledTypes) {
- ModelTypeSet enabled_types = GetEnabledTypes();
- ModelTypeSet disabled_types = Difference(ModelTypeSet::All(), enabled_types);
- // Set data for all types.
- ModelTypeSet protocol_types = ProtocolTypes();
- for (ModelTypeSet::Iterator iter = protocol_types.First(); iter.Good();
- iter.Inc()) {
- SetProgressMarkerForType(iter.Get(), true);
- }
-
- sync_manager_.PurgeDisabledTypes(disabled_types, ModelTypeSet(),
- ModelTypeSet());
+ EXPECT_EQ(new_routing_info, params.routing_info);
+
// Verify all the disabled types were purged.
EXPECT_EQ(enabled_types,
sync_manager_.GetUserShare()->directory->InitialSyncEndedTypes());
EXPECT_EQ(disabled_types, sync_manager_.GetTypesWithEmptyProgressMarkerToken(
ModelTypeSet::All()));
+}
+
+// Test that on a reconfiguration (configuration where the session context
+// already has routing info), only those recently disabled types are purged.
+TEST_F(SyncManagerTestWithMockScheduler, ReConfiguration) {
+ ConfigureReason reason = CONFIGURE_REASON_RECONFIGURATION;
+ ModelTypeSet types_to_download(BOOKMARKS, PREFERENCES);
+ ModelTypeSet disabled_types = ModelTypeSet(THEMES, SESSIONS);
+ ModelSafeRoutingInfo old_routing_info;
+ ModelSafeRoutingInfo new_routing_info;
+ GetModelSafeRoutingInfo(&old_routing_info);
+ new_routing_info = old_routing_info;
+ new_routing_info.erase(THEMES);
+ new_routing_info.erase(SESSIONS);
+ ModelTypeSet enabled_types = GetRoutingInfoTypes(new_routing_info);
+
+ ConfigurationParams params;
+ EXPECT_CALL(*scheduler(), Start(SyncScheduler::CONFIGURATION_MODE, _));
+ EXPECT_CALL(*scheduler(), ScheduleConfiguration(_))
+ .WillOnce(SaveArg<0>(&params));
+
+ // Set data for all types except those recently disabled (so we can verify
+ // only those recently disabled are purged) .
+ ModelTypeSet protocol_types = ProtocolTypes();
+ for (ModelTypeSet::Iterator iter = protocol_types.First(); iter.Good();
+ iter.Inc()) {
+ if (!disabled_types.Has(iter.Get())) {
+ SetProgressMarkerForType(iter.Get(), true);
+ } else {
+ SetProgressMarkerForType(iter.Get(), false);
+ }
+ }
+
+ // Set the context to have the old routing info.
+ cycle_context()->SetRoutingInfo(old_routing_info);
+
+ CallbackCounter ready_task_counter, retry_task_counter;
+ sync_manager_.PurgeDisabledTypes(ModelTypeSet(), ModelTypeSet(),
+ ModelTypeSet());
+ sync_manager_.ConfigureSyncer(
+ reason, types_to_download, new_routing_info,
+ base::Bind(&CallbackCounter::Callback,
+ base::Unretained(&ready_task_counter)),
+ base::Bind(&CallbackCounter::Callback,
+ base::Unretained(&retry_task_counter)));
+ EXPECT_EQ(0, ready_task_counter.times_called());
+ EXPECT_EQ(0, retry_task_counter.times_called());
+ EXPECT_EQ(sync_pb::GetUpdatesCallerInfo::RECONFIGURATION, params.source);
+ EXPECT_EQ(types_to_download, params.types_to_download);
+ EXPECT_EQ(new_routing_info, params.routing_info);
+
+ // Verify only the recently disabled types were purged.
+ EXPECT_EQ(disabled_types, sync_manager_.GetTypesWithEmptyProgressMarkerToken(
+ ProtocolTypes()));
}
// Test that SyncManager::ClearServerData invokes the scheduler.
@@ -2832,7 +2894,9 @@
// Test that PurgePartiallySyncedTypes purges only those types that have not
// fully completed their initial download and apply.
TEST_F(SyncManagerTest, PurgePartiallySyncedTypes) {
- ModelTypeSet enabled_types = GetEnabledTypes();
+ ModelSafeRoutingInfo routing_info;
+ GetModelSafeRoutingInfo(&routing_info);
+ ModelTypeSet enabled_types = GetRoutingInfoTypes(routing_info);
UserShare* share = sync_manager_.GetUserShare();
@@ -2907,7 +2971,9 @@
// Test CleanupDisabledTypes properly purges all disabled types as specified
// by the previous and current enabled params.
TEST_F(SyncManagerTest, PurgeDisabledTypes) {
- ModelTypeSet enabled_types = GetEnabledTypes();
+ ModelSafeRoutingInfo routing_info;
+ GetModelSafeRoutingInfo(&routing_info);
+ ModelTypeSet enabled_types = GetRoutingInfoTypes(routing_info);
ModelTypeSet disabled_types = Difference(ModelTypeSet::All(), enabled_types);
// The harness should have initialized the enabled_types for us.
@@ -2948,8 +3014,10 @@
// Test PurgeDisabledTypes properly unapplies types by deleting their local data
// and preserving their server data and progress marker.
TEST_F(SyncManagerTest, PurgeUnappliedTypes) {
+ ModelSafeRoutingInfo routing_info;
+ GetModelSafeRoutingInfo(&routing_info);
ModelTypeSet unapplied_types = ModelTypeSet(BOOKMARKS, PREFERENCES);
- ModelTypeSet enabled_types = GetEnabledTypes();
+ ModelTypeSet enabled_types = GetRoutingInfoTypes(routing_info);
ModelTypeSet disabled_types = Difference(ModelTypeSet::All(), enabled_types);
// The harness should have initialized the enabled_types for us.
« no previous file with comments | « components/sync/engine_impl/sync_manager_impl.cc ('k') | components/sync/engine_impl/sync_scheduler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698