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

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

Issue 2641523004: [Sync] Make directory types registration explicit in ModelTypeRegistry (Closed)
Patch Set: Address comments 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 afaab93d635294de0a75e045dc895f9113103a5f..8bf15f9331318d149417a52d46eb6e2c63760300 100644
--- a/components/sync/engine_impl/sync_manager_impl_unittest.cc
+++ b/components/sync/engine_impl/sync_manager_impl_unittest.cc
@@ -1017,8 +1017,6 @@ class SyncManagerTest : public testing::Test,
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
@@ -1052,10 +1050,10 @@ class SyncManagerTest : public testing::Test,
EXPECT_EQ(EngineComponentsFactory::STORAGE_ON_DISK, storage_used_);
if (initialization_succeeded_) {
- for (ModelSafeRoutingInfo::iterator i = routing_info.begin();
- i != routing_info.end(); ++i) {
- type_roots_[i->first] =
- MakeTypeRoot(sync_manager_.GetUserShare(), i->first);
+ ModelTypeSet enabled_types = GetEnabledTypes();
+ for (auto it = enabled_types.First(); it.Good(); it.Inc()) {
+ type_roots_[it.Get()] =
+ MakeTypeRoot(sync_manager_.GetUserShare(), it.Get());
}
}
@@ -1071,23 +1069,20 @@ class SyncManagerTest : public testing::Test,
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() {
- ModelSafeRoutingInfo routing_info;
- GetModelSafeRoutingInfo(&routing_info);
- return GetRoutingInfoTypes(routing_info);
+ 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;
}
void OnChangesApplied(ModelType model_type,
@@ -2663,18 +2658,15 @@ TEST_F(SyncManagerTest, SetPreviouslyEncryptedSpecifics) {
// 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());
- for (ModelSafeRoutingInfo::iterator i = routing_info.begin();
- i != routing_info.end(); ++i) {
+ ModelTypeSet enabled_types = GetEnabledTypes();
+ for (auto it = enabled_types.First(); it.Good(); it.Inc()) {
// Transaction version is incremented when SyncManagerTest::SetUp()
// creates a node of each type.
EXPECT_EQ(1,
sync_manager_.GetUserShare()->directory->GetTransactionVersion(
- i->first));
+ it.Get()));
}
}
@@ -2688,11 +2680,11 @@ TEST_F(SyncManagerTest, IncrementTransactionVersion) {
{
ReadTransaction read_trans(FROM_HERE, sync_manager_.GetUserShare());
- for (ModelSafeRoutingInfo::iterator i = routing_info.begin();
- i != routing_info.end(); ++i) {
- EXPECT_EQ(i->first == BOOKMARKS ? 2 : 1,
+ ModelTypeSet enabled_types = GetEnabledTypes();
+ for (auto it = enabled_types.First(); it.Good(); it.Inc()) {
+ EXPECT_EQ(it.Get() == BOOKMARKS ? 2 : 1,
sync_manager_.GetUserShare()->directory->GetTransactionVersion(
- i->first));
+ it.Get()));
}
}
}
@@ -2783,33 +2775,19 @@ class SyncManagerTestWithMockScheduler : public SyncManagerTest {
};
// Test that the configuration params are properly created and sent to
-// ScheduleConfigure. No callback should be invoked. Any disabled datatypes
-// should be purged.
+// ScheduleConfigure. No callback should be invoked.
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, new_routing_info,
+ reason, types_to_download,
base::Bind(&CallbackCounter::Callback,
base::Unretained(&ready_task_counter)),
base::Bind(&CallbackCounter::Callback,
@@ -2818,67 +2796,27 @@ TEST_F(SyncManagerTestWithMockScheduler, BasicConfiguration) {
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 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) .
+// 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()) {
- if (!disabled_types.Has(iter.Get())) {
- SetProgressMarkerForType(iter.Get(), true);
- } else {
- SetProgressMarkerForType(iter.Get(), false);
- }
+ SetProgressMarkerForType(iter.Get(), true);
}
- // 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(),
+ sync_manager_.PurgeDisabledTypes(disabled_types, 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.
+ // Verify all the disabled types were purged.
+ EXPECT_EQ(enabled_types,
+ sync_manager_.GetUserShare()->directory->InitialSyncEndedTypes());
EXPECT_EQ(disabled_types, sync_manager_.GetTypesWithEmptyProgressMarkerToken(
- ProtocolTypes()));
+ ModelTypeSet::All()));
}
// Test that SyncManager::ClearServerData invokes the scheduler.
@@ -2894,9 +2832,7 @@ TEST_F(SyncManagerTestWithMockScheduler, ClearServerData) {
// Test that PurgePartiallySyncedTypes purges only those types that have not
// fully completed their initial download and apply.
TEST_F(SyncManagerTest, PurgePartiallySyncedTypes) {
- ModelSafeRoutingInfo routing_info;
- GetModelSafeRoutingInfo(&routing_info);
- ModelTypeSet enabled_types = GetRoutingInfoTypes(routing_info);
+ ModelTypeSet enabled_types = GetEnabledTypes();
UserShare* share = sync_manager_.GetUserShare();
@@ -2971,9 +2907,7 @@ TEST_F(SyncManagerTest, PurgePartiallySyncedTypes) {
// Test CleanupDisabledTypes properly purges all disabled types as specified
// by the previous and current enabled params.
TEST_F(SyncManagerTest, PurgeDisabledTypes) {
- ModelSafeRoutingInfo routing_info;
- GetModelSafeRoutingInfo(&routing_info);
- ModelTypeSet enabled_types = GetRoutingInfoTypes(routing_info);
+ ModelTypeSet enabled_types = GetEnabledTypes();
ModelTypeSet disabled_types = Difference(ModelTypeSet::All(), enabled_types);
// The harness should have initialized the enabled_types for us.
@@ -3014,10 +2948,8 @@ TEST_F(SyncManagerTest, PurgeDisabledTypes) {
// 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 = GetRoutingInfoTypes(routing_info);
+ ModelTypeSet enabled_types = GetEnabledTypes();
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