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

Unified Diff: sync/internal_api/syncapi_unittest.cc

Issue 10702074: Refactor sync-specific parts out of SyncNotifier/SyncNotifierObserver (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: FOR_THE_HORDE Created 8 years, 5 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: sync/internal_api/syncapi_unittest.cc
diff --git a/sync/internal_api/syncapi_unittest.cc b/sync/internal_api/syncapi_unittest.cc
index f5eb675e17e30bf054dab6918b9fadbfac026a06..9c49f2d1582081d41b1e4c23d7aeeb78c4355122 100644
--- a/sync/internal_api/syncapi_unittest.cc
+++ b/sync/internal_api/syncapi_unittest.cc
@@ -695,14 +695,12 @@ class SyncManagerObserverMock : public SyncManager::Observer {
class SyncNotifierMock : public SyncNotifier {
public:
- MOCK_METHOD1(AddObserver, void(SyncNotifierObserver*));
- MOCK_METHOD1(RemoveObserver, void(SyncNotifierObserver*));
+ MOCK_METHOD2(UpdateRegisteredIds, void(SyncNotifierObserver*,
+ const ObjectIdSet&));
MOCK_METHOD1(SetUniqueId, void(const std::string&));
MOCK_METHOD1(SetStateDeprecated, void(const std::string&));
MOCK_METHOD2(UpdateCredentials,
void(const std::string&, const std::string&));
- MOCK_METHOD1(UpdateEnabledTypes,
- void(ModelTypeSet));
MOCK_METHOD1(SendNotification, void(ModelTypeSet));
};
@@ -724,9 +722,7 @@ class SyncManagerTest : public testing::Test,
SyncManagerTest()
: sync_notifier_mock_(NULL),
- sync_manager_("Test sync manager"),
- sync_notifier_observer_(NULL),
- update_enabled_types_call_count_(0) {}
+ sync_manager_("Test sync manager") {}
akalin 2012/07/21 01:09:47 init sync_notifier_mock_ to NULL
dcheng 2012/07/21 14:06:53 Err... it is on line 724? =) (I didn't add it, I j
virtual ~SyncManagerTest() {
EXPECT_FALSE(sync_notifier_mock_);
@@ -741,23 +737,15 @@ class SyncManagerTest : public testing::Test,
credentials.sync_token = "sometoken";
sync_notifier_mock_ = new StrictMock<SyncNotifierMock>();
- EXPECT_CALL(*sync_notifier_mock_, AddObserver(_)).
- WillOnce(Invoke(this, &SyncManagerTest::SyncNotifierAddObserver));
EXPECT_CALL(*sync_notifier_mock_, SetUniqueId(_));
EXPECT_CALL(*sync_notifier_mock_, SetStateDeprecated(""));
EXPECT_CALL(*sync_notifier_mock_,
UpdateCredentials(credentials.email, credentials.sync_token));
- EXPECT_CALL(*sync_notifier_mock_, UpdateEnabledTypes(_)).
- WillRepeatedly(
- Invoke(this, &SyncManagerTest::SyncNotifierUpdateEnabledTypes));
- EXPECT_CALL(*sync_notifier_mock_, RemoveObserver(_)).
- WillOnce(Invoke(this, &SyncManagerTest::SyncNotifierRemoveObserver));
sync_manager_.AddObserver(&observer_);
EXPECT_CALL(observer_, OnInitializationComplete(_, _)).
WillOnce(SaveArg<0>(&js_backend_));
- EXPECT_FALSE(sync_notifier_observer_);
EXPECT_FALSE(js_backend_.IsInitialized());
std::vector<ModelSafeWorker*> workers;
@@ -781,11 +769,8 @@ class SyncManagerTest : public testing::Test,
&handler_,
NULL);
- EXPECT_TRUE(sync_notifier_observer_);
EXPECT_TRUE(js_backend_.IsInitialized());
- EXPECT_EQ(0, update_enabled_types_call_count_);
-
for (ModelSafeRoutingInfo::iterator i = routing_info.begin();
i != routing_info.end(); ++i) {
type_roots_[i->first] = MakeServerNodeForType(
@@ -796,9 +781,10 @@ class SyncManagerTest : public testing::Test,
void TearDown() {
sync_manager_.RemoveObserver(&observer_);
+ EXPECT_CALL(*sync_notifier_mock_,
+ UpdateRegisteredIds(_, ObjectIdSet()));
sync_manager_.ShutdownOnSyncThread();
sync_notifier_mock_ = NULL;
- EXPECT_FALSE(sync_notifier_observer_);
PumpLoop();
}
@@ -859,26 +845,6 @@ class SyncManagerTest : public testing::Test,
return type_roots_[type];
}
- void SyncNotifierAddObserver(
- SyncNotifierObserver* sync_notifier_observer) {
- EXPECT_EQ(NULL, sync_notifier_observer_);
- sync_notifier_observer_ = sync_notifier_observer;
- }
-
- void SyncNotifierRemoveObserver(
- SyncNotifierObserver* sync_notifier_observer) {
- EXPECT_EQ(sync_notifier_observer_, sync_notifier_observer);
- sync_notifier_observer_ = NULL;
- }
-
- void SyncNotifierUpdateEnabledTypes(ModelTypeSet types) {
- ModelSafeRoutingInfo routes;
- GetModelSafeRoutingInfo(&routes);
- const ModelTypeSet expected_types = GetRoutingInfoTypes(routes);
- EXPECT_TRUE(types.Equals(expected_types));
- ++update_enabled_types_call_count_;
- }
-
void PumpLoop() {
message_loop_.RunAllPending();
}
@@ -927,27 +893,24 @@ class SyncManagerTest : public testing::Test,
// Sync Id's for the roots of the enabled datatypes.
std::map<ModelType, int64> type_roots_;
FakeExtensionsActivityMonitor extensions_activity_monitor_;
- StrictMock<SyncNotifierMock>* sync_notifier_mock_;
protected:
FakeEncryptor encryptor_;
TestUnrecoverableErrorHandler handler_;
+ StrictMock<SyncNotifierMock>* sync_notifier_mock_;
SyncManagerImpl sync_manager_;
WeakHandle<JsBackend> js_backend_;
StrictMock<SyncManagerObserverMock> observer_;
- SyncNotifierObserver* sync_notifier_observer_;
- int update_enabled_types_call_count_;
};
TEST_F(SyncManagerTest, UpdateEnabledTypes) {
- EXPECT_EQ(0, update_enabled_types_call_count_);
-
ModelSafeRoutingInfo routes;
GetModelSafeRoutingInfo(&routes);
const ModelTypeSet enabled_types = GetRoutingInfoTypes(routes);
+ EXPECT_CALL(*sync_notifier_mock_,
+ UpdateRegisteredIds(_, ModelTypeSetToObjectIdSet(enabled_types)));
sync_manager_.UpdateEnabledTypes(enabled_types);
- EXPECT_EQ(1, update_enabled_types_call_count_);
}
TEST_F(SyncManagerTest, ProcessJsMessage) {

Powered by Google App Engine
This is Rietveld 408576698