Index: chrome/browser/sync/glue/sync_backend_registrar_unittest.cc |
diff --git a/chrome/browser/sync/glue/sync_backend_registrar_unittest.cc b/chrome/browser/sync/glue/sync_backend_registrar_unittest.cc |
index 4f9da663be406618213f9311724b53184f1c1190..e920e3aa0b4bded0e3c96013c88cf2cd9801f5cb 100644 |
--- a/chrome/browser/sync/glue/sync_backend_registrar_unittest.cc |
+++ b/chrome/browser/sync/glue/sync_backend_registrar_unittest.cc |
@@ -4,6 +4,7 @@ |
#include "chrome/browser/sync/glue/sync_backend_registrar.h" |
+#include "base/tracked.h" |
#include "chrome/browser/sync/glue/change_processor_mock.h" |
#include "chrome/browser/sync/glue/ui_model_worker.h" |
#include "chrome/browser/sync/syncable/model_type.h" |
@@ -17,6 +18,7 @@ namespace browser_sync { |
namespace { |
+using ::testing::_; |
using ::testing::InSequence; |
using ::testing::Return; |
using ::testing::StrictMock; |
@@ -53,15 +55,12 @@ class SyncBackendRegistrarTest : public testing::Test { |
EXPECT_EQ(expected_routing_info, routing_info); |
} |
- void ExpectHasProcessorsForTypes(SyncBackendRegistrar* registrar, |
+ void ExpectHasProcessorsForTypes(const SyncBackendRegistrar& registrar, |
const ModelTypeSet& types) { |
for (int i = FIRST_REAL_MODEL_TYPE; i < MODEL_TYPE_COUNT; ++i) { |
ModelType model_type = ModelTypeFromInt(i); |
- if (types.count(model_type) > 0) { |
- EXPECT_TRUE(registrar->GetProcessor(model_type)); |
- } else { |
- EXPECT_FALSE(registrar->GetProcessor(model_type)); |
- } |
+ EXPECT_EQ(types.count(model_type) > 0, |
+ registrar.IsTypeActivatedForTest(model_type)); |
} |
} |
@@ -82,7 +81,7 @@ TEST_F(SyncBackendRegistrarTest, ConstructorEmpty) { |
EXPECT_EQ(4u, workers.size()); |
} |
ExpectRoutingInfo(®istrar, ModelSafeRoutingInfo()); |
- ExpectHasProcessorsForTypes(®istrar, ModelTypeSet()); |
+ ExpectHasProcessorsForTypes(registrar, ModelTypeSet()); |
registrar.OnSyncerShutdownComplete(); |
registrar.StopOnUIThread(); |
} |
@@ -107,7 +106,7 @@ TEST_F(SyncBackendRegistrarTest, ConstructorNonEmpty) { |
// Passwords dropped because of no password store. |
ExpectRoutingInfo(®istrar, expected_routing_info); |
} |
- ExpectHasProcessorsForTypes(®istrar, ModelTypeSet()); |
+ ExpectHasProcessorsForTypes(registrar, ModelTypeSet()); |
registrar.OnSyncerShutdownComplete(); |
registrar.StopOnUIThread(); |
} |
@@ -129,7 +128,7 @@ TEST_F(SyncBackendRegistrarTest, ConfigureDataTypes) { |
expected_routing_info[AUTOFILL] = GROUP_PASSIVE; |
ExpectRoutingInfo(®istrar, expected_routing_info); |
} |
- ExpectHasProcessorsForTypes(®istrar, ModelTypeSet()); |
+ ExpectHasProcessorsForTypes(registrar, ModelTypeSet()); |
// Add and remove. |
ModelTypeSet types2; |
@@ -142,25 +141,39 @@ TEST_F(SyncBackendRegistrarTest, ConfigureDataTypes) { |
expected_routing_info[THEMES] = GROUP_PASSIVE; |
ExpectRoutingInfo(®istrar, expected_routing_info); |
} |
- ExpectHasProcessorsForTypes(®istrar, ModelTypeSet()); |
+ ExpectHasProcessorsForTypes(registrar, ModelTypeSet()); |
// Remove. |
EXPECT_TRUE(registrar.ConfigureDataTypes(ModelTypeSet(), types2).empty()); |
ExpectRoutingInfo(®istrar, ModelSafeRoutingInfo()); |
- ExpectHasProcessorsForTypes(®istrar, ModelTypeSet()); |
+ ExpectHasProcessorsForTypes(registrar, ModelTypeSet()); |
registrar.OnSyncerShutdownComplete(); |
registrar.StopOnUIThread(); |
} |
+void TriggerChanges(SyncBackendRegistrar* registrar, ModelType type) { |
+ registrar->OnChangesApplied(type, NULL, |
+ sync_api::ImmutableChangeRecordList()); |
+ registrar->OnChangesComplete(type); |
+} |
+ |
TEST_F(SyncBackendRegistrarTest, ActivateDeactivateUIDataType) { |
InSequence in_sequence; |
TestingProfile profile; |
SyncBackendRegistrar registrar(ModelTypeSet(), "test", &profile, &loop_); |
+ |
+ // Should do nothing. |
+ TriggerChanges(®istrar, BOOKMARKS); |
+ |
StrictMock<ChangeProcessorMock> change_processor_mock; |
EXPECT_CALL(change_processor_mock, StartImpl(&profile)); |
EXPECT_CALL(change_processor_mock, IsRunning()) |
.WillRepeatedly(Return(true)); |
+ EXPECT_CALL(change_processor_mock, ApplyChangesFromSyncModel(NULL, _)); |
+ EXPECT_CALL(change_processor_mock, IsRunning()) |
+ .WillRepeatedly(Return(true)); |
+ EXPECT_CALL(change_processor_mock, CommitChangesFromSyncModel()); |
EXPECT_CALL(change_processor_mock, StopImpl()); |
EXPECT_CALL(change_processor_mock, IsRunning()) |
.WillRepeatedly(Return(false)); |
@@ -176,11 +189,16 @@ TEST_F(SyncBackendRegistrarTest, ActivateDeactivateUIDataType) { |
expected_routing_info[BOOKMARKS] = GROUP_UI; |
ExpectRoutingInfo(®istrar, expected_routing_info); |
} |
- ExpectHasProcessorsForTypes(®istrar, types); |
+ ExpectHasProcessorsForTypes(registrar, types); |
+ |
+ TriggerChanges(®istrar, BOOKMARKS); |
registrar.DeactivateDataType(BOOKMARKS); |
ExpectRoutingInfo(®istrar, ModelSafeRoutingInfo()); |
- ExpectHasProcessorsForTypes(®istrar, ModelTypeSet()); |
+ ExpectHasProcessorsForTypes(registrar, ModelTypeSet()); |
+ |
+ // Should do nothing. |
+ TriggerChanges(®istrar, BOOKMARKS); |
registrar.OnSyncerShutdownComplete(); |
registrar.StopOnUIThread(); |
@@ -191,10 +209,18 @@ TEST_F(SyncBackendRegistrarTest, ActivateDeactivateNonUIDataType) { |
InSequence in_sequence; |
TestingProfile profile; |
SyncBackendRegistrar registrar(ModelTypeSet(), "test", &profile, &loop_); |
+ |
+ // Should do nothing. |
+ TriggerChanges(®istrar, AUTOFILL); |
+ |
StrictMock<ChangeProcessorMock> change_processor_mock; |
EXPECT_CALL(change_processor_mock, StartImpl(&profile)); |
EXPECT_CALL(change_processor_mock, IsRunning()) |
.WillRepeatedly(Return(true)); |
+ EXPECT_CALL(change_processor_mock, ApplyChangesFromSyncModel(NULL, _)); |
+ EXPECT_CALL(change_processor_mock, IsRunning()) |
+ .WillRepeatedly(Return(true)); |
+ EXPECT_CALL(change_processor_mock, CommitChangesFromSyncModel()); |
EXPECT_CALL(change_processor_mock, StopImpl()); |
EXPECT_CALL(change_processor_mock, IsRunning()) |
.WillRepeatedly(Return(false)); |
@@ -210,19 +236,21 @@ TEST_F(SyncBackendRegistrarTest, ActivateDeactivateNonUIDataType) { |
expected_routing_info[AUTOFILL] = GROUP_DB; |
ExpectRoutingInfo(®istrar, expected_routing_info); |
} |
- ExpectHasProcessorsForTypes(®istrar, types); |
+ ExpectHasProcessorsForTypes(registrar, types); |
+ |
+ TriggerChanges(®istrar, AUTOFILL); |
registrar.DeactivateDataType(AUTOFILL); |
ExpectRoutingInfo(®istrar, ModelSafeRoutingInfo()); |
- ExpectHasProcessorsForTypes(®istrar, ModelTypeSet()); |
+ ExpectHasProcessorsForTypes(registrar, ModelTypeSet()); |
+ |
+ // Should do nothing. |
+ TriggerChanges(®istrar, AUTOFILL); |
registrar.OnSyncerShutdownComplete(); |
registrar.StopOnUIThread(); |
} |
-// TODO(akalin): Add tests for non-UI non-passive data types (see |
-// http://crbug.com/93456). |
- |
} // namespace |
} // namespace browser_sync |