summaryrefslogtreecommitdiffstats
path: root/sync
diff options
context:
space:
mode:
authorakalin@chromium.org <akalin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-08-24 18:00:19 +0000
committerakalin@chromium.org <akalin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-08-24 18:00:19 +0000
commit07cdcae841e6b6cf3eeb634ea09928afc895f2ed (patch)
treeb0a2151337b60ab455182f014ac1dcb837296c2c /sync
parent9d5730b2fd88a6e7710c250b5b0d875d193d8325 (diff)
downloadchromium_src-07cdcae841e6b6cf3eeb634ea09928afc895f2ed.zip
chromium_src-07cdcae841e6b6cf3eeb634ea09928afc895f2ed.tar.gz
chromium_src-07cdcae841e6b6cf3eeb634ea09928afc895f2ed.tar.bz2
[Sync] Use fakes for SyncNotifier{,Observer} instead of mocks
An upcoming CL will require more complex functionality, so fakes are better suited. BUG=141678 Review URL: https://chromiumcodereview.appspot.com/10868061 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@153243 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'sync')
-rw-r--r--sync/internal_api/sync_manager_impl_unittest.cc73
-rw-r--r--sync/notifier/fake_sync_notifier.cc74
-rw-r--r--sync/notifier/fake_sync_notifier.h51
-rw-r--r--sync/notifier/fake_sync_notifier_observer.cc52
-rw-r--r--sync/notifier/fake_sync_notifier_observer.h42
-rw-r--r--sync/notifier/invalidation_notifier_unittest.cc40
-rw-r--r--sync/notifier/mock_sync_notifier_observer.cc12
-rw-r--r--sync/notifier/mock_sync_notifier_observer.h28
-rw-r--r--sync/notifier/non_blocking_invalidation_notifier_unittest.cc40
-rw-r--r--sync/notifier/p2p_notifier_unittest.cc107
-rw-r--r--sync/notifier/sync_notifier_factory_unittest.cc23
-rw-r--r--sync/notifier/sync_notifier_registrar.cc19
-rw-r--r--sync/notifier/sync_notifier_registrar.h3
-rw-r--r--sync/notifier/sync_notifier_registrar_unittest.cc153
-rw-r--r--sync/sync.gyp6
15 files changed, 450 insertions, 273 deletions
diff --git a/sync/internal_api/sync_manager_impl_unittest.cc b/sync/internal_api/sync_manager_impl_unittest.cc
index dc3ea15..613150c 100644
--- a/sync/internal_api/sync_manager_impl_unittest.cc
+++ b/sync/internal_api/sync_manager_impl_unittest.cc
@@ -44,6 +44,8 @@
#include "sync/js/js_event_handler.h"
#include "sync/js/js_reply_handler.h"
#include "sync/js/js_test_util.h"
+#include "sync/notifier/fake_sync_notifier.h"
+#include "sync/notifier/fake_sync_notifier_observer.h"
#include "sync/notifier/sync_notifier.h"
#include "sync/notifier/sync_notifier_observer.h"
#include "sync/protocol/bookmark_specifics.pb.h"
@@ -73,12 +75,8 @@
using base::ExpectDictStringValue;
using testing::_;
-using testing::AnyNumber;
-using testing::AtLeast;
using testing::DoAll;
using testing::InSequence;
-using testing::Invoke;
-using testing::NiceMock;
using testing::Return;
using testing::SaveArg;
using testing::StrictMock;
@@ -712,19 +710,6 @@ class SyncEncryptionHandlerObserverMock
MOCK_METHOD1(OnCryptographerStateChanged, void(Cryptographer*)); // NOLINT
};
-class SyncNotifierMock : public SyncNotifier {
- public:
- MOCK_METHOD1(RegisterHandler, void(SyncNotifierObserver*));
- MOCK_METHOD2(UpdateRegisteredIds,
- void(SyncNotifierObserver*, const ObjectIdSet&));
- MOCK_METHOD1(UnregisterHandler, void(SyncNotifierObserver*));
- 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(SendNotification, void(ModelTypeSet));
-};
-
} // namespace
class SyncManagerTest : public testing::Test,
@@ -742,14 +727,14 @@ class SyncManagerTest : public testing::Test,
};
SyncManagerTest()
- : sync_notifier_mock_(NULL),
+ : fake_notifier_(NULL),
sync_manager_("Test sync manager") {
switches_.encryption_method =
InternalComponentsFactory::ENCRYPTION_KEYSTORE;
}
virtual ~SyncManagerTest() {
- EXPECT_FALSE(sync_notifier_mock_);
+ EXPECT_FALSE(fake_notifier_);
}
// Test implementation.
@@ -760,15 +745,7 @@ class SyncManagerTest : public testing::Test,
credentials.email = "foo@bar.com";
credentials.sync_token = "sometoken";
- sync_notifier_mock_ = new StrictMock<SyncNotifierMock>();
- 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_, RegisterHandler(_));
-
- // Called by ShutdownOnSyncThread().
- EXPECT_CALL(*sync_notifier_mock_, UnregisterHandler(_));
+ fake_notifier_ = new FakeSyncNotifier();
sync_manager_.AddObserver(&manager_observer_);
EXPECT_CALL(manager_observer_, OnInitializationComplete(_, _, _)).
@@ -780,7 +757,7 @@ class SyncManagerTest : public testing::Test,
ModelSafeRoutingInfo routing_info;
GetModelSafeRoutingInfo(&routing_info);
- // Takes ownership of |sync_notifier_mock_|.
+ // Takes ownership of |fake_notifier_|.
sync_manager_.Init(temp_dir_.path(),
WeakHandle<JsEventHandler>(),
"bogus", 0, false,
@@ -789,7 +766,7 @@ class SyncManagerTest : public testing::Test,
new TestHttpPostProviderFactory()),
workers, &extensions_activity_monitor_, this,
credentials,
- scoped_ptr<SyncNotifier>(sync_notifier_mock_),
+ scoped_ptr<SyncNotifier>(fake_notifier_),
"", "", // bootstrap tokens
scoped_ptr<InternalComponentsFactory>(GetFactory()),
&encryptor_,
@@ -806,14 +783,17 @@ class SyncManagerTest : public testing::Test,
sync_manager_.GetUserShare(), i->first);
}
PumpLoop();
+
+ EXPECT_TRUE(fake_notifier_->IsHandlerRegistered(&sync_manager_));
}
void TearDown() {
sync_manager_.RemoveObserver(&manager_observer_);
- // |sync_notifier_mock_| is strict, which ensures we don't do anything but
- // unregister |sync_manager_| as a handler on shutdown.
sync_manager_.ShutdownOnSyncThread();
- sync_notifier_mock_ = NULL;
+ // We can't assert that |sync_manager_| isn't registered with
+ // |fake_notifier_| anymore because |fake_notifier_| is now
+ // destroyed.
+ fake_notifier_ = NULL;
PumpLoop();
}
@@ -981,7 +961,7 @@ class SyncManagerTest : public testing::Test,
protected:
FakeEncryptor encryptor_;
TestUnrecoverableErrorHandler handler_;
- StrictMock<SyncNotifierMock>* sync_notifier_mock_;
+ FakeSyncNotifier* fake_notifier_;
SyncManagerImpl sync_manager_;
WeakHandle<JsBackend> js_backend_;
StrictMock<SyncManagerObserverMock> manager_observer_;
@@ -993,26 +973,23 @@ TEST_F(SyncManagerTest, UpdateEnabledTypes) {
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(ModelTypeSetToObjectIdSet(enabled_types),
+ fake_notifier_->GetRegisteredIds(&sync_manager_));
}
TEST_F(SyncManagerTest, RegisterInvalidationHandler) {
- EXPECT_CALL(*sync_notifier_mock_, RegisterHandler(NULL));
- sync_manager_.RegisterInvalidationHandler(NULL);
-}
+ FakeSyncNotifierObserver fake_observer;
+ sync_manager_.RegisterInvalidationHandler(&fake_observer);
+ EXPECT_TRUE(fake_notifier_->IsHandlerRegistered(&fake_observer));
-TEST_F(SyncManagerTest, UpdateRegisteredInvalidationIds) {
- EXPECT_CALL(*sync_notifier_mock_, UpdateRegisteredIds(NULL, ObjectIdSet()));
- sync_manager_.UpdateRegisteredInvalidationIds(NULL, ObjectIdSet());
-}
+ const ObjectIdSet& ids =
+ ModelTypeSetToObjectIdSet(ModelTypeSet(BOOKMARKS, PREFERENCES));
+ sync_manager_.UpdateRegisteredInvalidationIds(&fake_observer, ids);
+ EXPECT_EQ(ids, fake_notifier_->GetRegisteredIds(&fake_observer));
-TEST_F(SyncManagerTest, UnregisterInvalidationHandler) {
- EXPECT_CALL(*sync_notifier_mock_, UnregisterHandler(NULL));
- sync_manager_.UnregisterInvalidationHandler(NULL);
+ sync_manager_.UnregisterInvalidationHandler(&fake_observer);
+ EXPECT_FALSE(fake_notifier_->IsHandlerRegistered(&fake_observer));
}
TEST_F(SyncManagerTest, ProcessJsMessage) {
diff --git a/sync/notifier/fake_sync_notifier.cc b/sync/notifier/fake_sync_notifier.cc
new file mode 100644
index 0000000..0ef5ef9
--- /dev/null
+++ b/sync/notifier/fake_sync_notifier.cc
@@ -0,0 +1,74 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "sync/notifier/fake_sync_notifier.h"
+
+namespace syncer {
+
+FakeSyncNotifier::FakeSyncNotifier() {}
+
+FakeSyncNotifier::~FakeSyncNotifier() {}
+
+bool FakeSyncNotifier::IsHandlerRegistered(
+ SyncNotifierObserver* handler) const {
+ return registrar_.IsHandlerRegisteredForTest(handler);
+}
+
+ObjectIdSet FakeSyncNotifier::GetRegisteredIds(
+ SyncNotifierObserver* handler) const {
+ return registrar_.GetRegisteredIdsForTest(handler);
+}
+
+void FakeSyncNotifier::RegisterHandler(SyncNotifierObserver* handler) {
+ registrar_.RegisterHandler(handler);
+}
+
+const std::string& FakeSyncNotifier::GetUniqueId() const {
+ return unique_id_;
+}
+
+const std::string& FakeSyncNotifier::GetStateDeprecated() const {
+ return state_;
+}
+
+const std::string& FakeSyncNotifier::GetCredentialsEmail() const {
+ return email_;
+}
+
+const std::string& FakeSyncNotifier::GetCredentialsToken() const {
+ return token_;
+}
+
+ModelTypeSet FakeSyncNotifier::GetLastChangedTypes() const {
+ return last_changed_types_;
+}
+
+void FakeSyncNotifier::UpdateRegisteredIds(SyncNotifierObserver* handler,
+ const ObjectIdSet& ids) {
+ registrar_.UpdateRegisteredIds(handler, ids);
+}
+
+void FakeSyncNotifier::UnregisterHandler(SyncNotifierObserver* handler) {
+ registrar_.UnregisterHandler(handler);
+}
+
+void FakeSyncNotifier::SetUniqueId(const std::string& unique_id) {
+ unique_id_ = unique_id;
+}
+
+void FakeSyncNotifier::SetStateDeprecated(const std::string& state) {
+ state_ = state;
+}
+
+void FakeSyncNotifier::UpdateCredentials(
+ const std::string& email, const std::string& token) {
+ email_ = email;
+ token_ = token;
+}
+
+void FakeSyncNotifier::SendNotification(ModelTypeSet changed_types) {
+ last_changed_types_ = changed_types;
+}
+
+} // namespace syncer
diff --git a/sync/notifier/fake_sync_notifier.h b/sync/notifier/fake_sync_notifier.h
new file mode 100644
index 0000000..74cfdf1
--- /dev/null
+++ b/sync/notifier/fake_sync_notifier.h
@@ -0,0 +1,51 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef SYNC_NOTIFIER_FAKE_SYNC_NOTIFIER_H_
+#define SYNC_NOTIFIER_FAKE_SYNC_NOTIFIER_H_
+
+#include <string>
+
+#include "base/compiler_specific.h"
+#include "sync/notifier/invalidation_util.h"
+#include "sync/notifier/sync_notifier.h"
+#include "sync/notifier/sync_notifier_registrar.h"
+
+namespace syncer {
+
+class FakeSyncNotifier : public SyncNotifier {
+ public:
+ FakeSyncNotifier();
+ virtual ~FakeSyncNotifier();
+
+ bool IsHandlerRegistered(SyncNotifierObserver* handler) const;
+ ObjectIdSet GetRegisteredIds(SyncNotifierObserver* handler) const;
+ const std::string& GetUniqueId() const;
+ const std::string& GetStateDeprecated() const;
+ const std::string& GetCredentialsEmail() const;
+ const std::string& GetCredentialsToken() const;
+ ModelTypeSet GetLastChangedTypes() const;
+
+ virtual void RegisterHandler(SyncNotifierObserver* handler) OVERRIDE;
+ virtual void UpdateRegisteredIds(SyncNotifierObserver* handler,
+ const ObjectIdSet& ids) OVERRIDE;
+ virtual void UnregisterHandler(SyncNotifierObserver* handler) OVERRIDE;
+ virtual void SetUniqueId(const std::string& unique_id) OVERRIDE;
+ virtual void SetStateDeprecated(const std::string& state) OVERRIDE;
+ virtual void UpdateCredentials(
+ const std::string& email, const std::string& token) OVERRIDE;
+ virtual void SendNotification(ModelTypeSet changed_types) OVERRIDE;
+
+ private:
+ SyncNotifierRegistrar registrar_;
+ std::string unique_id_;
+ std::string state_;
+ std::string email_;
+ std::string token_;
+ ModelTypeSet last_changed_types_;
+};
+
+} // namespace syncer
+
+#endif // SYNC_NOTIFIER_FAKE_SYNC_NOTIFIER_H_
diff --git a/sync/notifier/fake_sync_notifier_observer.cc b/sync/notifier/fake_sync_notifier_observer.cc
new file mode 100644
index 0000000..b95f9a9
--- /dev/null
+++ b/sync/notifier/fake_sync_notifier_observer.cc
@@ -0,0 +1,52 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "sync/notifier/fake_sync_notifier_observer.h"
+
+namespace syncer {
+
+FakeSyncNotifierObserver::FakeSyncNotifierObserver()
+ : reason_(TRANSIENT_NOTIFICATION_ERROR),
+ last_source_(LOCAL_NOTIFICATION),
+ notification_count_(0) {}
+
+FakeSyncNotifierObserver::~FakeSyncNotifierObserver() {}
+
+NotificationsDisabledReason
+FakeSyncNotifierObserver::GetNotificationsDisabledReason() const {
+ return reason_;
+}
+
+const ObjectIdStateMap&
+FakeSyncNotifierObserver::GetLastNotificationIdStateMap() const {
+ return last_id_state_map_;
+}
+
+IncomingNotificationSource
+FakeSyncNotifierObserver::GetLastNotificationSource() const {
+ return last_source_;
+}
+
+int FakeSyncNotifierObserver::GetNotificationCount() const {
+ return notification_count_;
+}
+
+void FakeSyncNotifierObserver::OnNotificationsEnabled() {
+ reason_ = NO_NOTIFICATION_ERROR;
+}
+
+void FakeSyncNotifierObserver::OnNotificationsDisabled(
+ NotificationsDisabledReason reason) {
+ reason_ = reason;
+}
+
+void FakeSyncNotifierObserver::OnIncomingNotification(
+ const ObjectIdStateMap& id_state_map,
+ IncomingNotificationSource source) {
+ last_id_state_map_ = id_state_map;
+ last_source_ = source;
+ ++notification_count_;
+}
+
+} // namespace syncer
diff --git a/sync/notifier/fake_sync_notifier_observer.h b/sync/notifier/fake_sync_notifier_observer.h
new file mode 100644
index 0000000..e1195d9
--- /dev/null
+++ b/sync/notifier/fake_sync_notifier_observer.h
@@ -0,0 +1,42 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef SYNC_NOTIFIER_FAKE_SYNC_NOTIFIER_OBSERVER_H_
+#define SYNC_NOTIFIER_FAKE_SYNC_NOTIFIER_OBSERVER_H_
+
+#include <string>
+
+#include "base/compiler_specific.h"
+#include "sync/notifier/sync_notifier_observer.h"
+
+namespace syncer {
+
+class FakeSyncNotifierObserver : public SyncNotifierObserver {
+ public:
+ FakeSyncNotifierObserver();
+ virtual ~FakeSyncNotifierObserver();
+
+ NotificationsDisabledReason GetNotificationsDisabledReason() const;
+ const ObjectIdStateMap& GetLastNotificationIdStateMap() const;
+ IncomingNotificationSource GetLastNotificationSource() const;
+ int GetNotificationCount() const;
+
+ // SyncNotifierObserver implementation.
+ virtual void OnNotificationsEnabled() OVERRIDE;
+ virtual void OnNotificationsDisabled(
+ NotificationsDisabledReason reason) OVERRIDE;
+ virtual void OnIncomingNotification(
+ const ObjectIdStateMap& id_state_map,
+ IncomingNotificationSource source) OVERRIDE;
+
+ private:
+ NotificationsDisabledReason reason_;
+ ObjectIdStateMap last_id_state_map_;
+ IncomingNotificationSource last_source_;
+ int notification_count_;
+};
+
+} // namespace syncer
+
+#endif // SYNC_NOTIFIER_FAKE_SYNC_NOTIFIER_OBSERVER_H_
diff --git a/sync/notifier/invalidation_notifier_unittest.cc b/sync/notifier/invalidation_notifier_unittest.cc
index bdf88eb..6ced3ef 100644
--- a/sync/notifier/invalidation_notifier_unittest.cc
+++ b/sync/notifier/invalidation_notifier_unittest.cc
@@ -14,8 +14,8 @@
#include "sync/internal_api/public/base/model_type_state_map.h"
#include "sync/internal_api/public/util/weak_handle.h"
#include "sync/notifier/fake_invalidation_state_tracker.h"
+#include "sync/notifier/fake_sync_notifier_observer.h"
#include "sync/notifier/invalidation_state_tracker.h"
-#include "sync/notifier/mock_sync_notifier_observer.h"
#include "sync/notifier/object_id_state_map_test_util.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -35,7 +35,7 @@ class InvalidationNotifierTest : public testing::Test {
}
// Constructs an InvalidationNotifier, places it in |invalidation_notifier_|,
- // and registers |mock_observer_| as a handler. This remains in place until
+ // and registers |fake_observer_| as a handler. This remains in place until
// either TearDown (automatic) or ResetNotifier (manual) is called.
void CreateNotifier(
const std::string& initial_invalidation_state) {
@@ -50,11 +50,11 @@ class InvalidationNotifierTest : public testing::Test {
initial_invalidation_state,
MakeWeakHandle(fake_tracker_.AsWeakPtr()),
"fake_client_info"));
- invalidation_notifier_->RegisterHandler(&mock_observer_);
+ invalidation_notifier_->RegisterHandler(&fake_observer_);
}
void ResetNotifier() {
- invalidation_notifier_->UnregisterHandler(&mock_observer_);
+ invalidation_notifier_->UnregisterHandler(&fake_observer_);
// Stopping the invalidation notifier stops its scheduler, which deletes any
// pending tasks without running them. Some tasks "run and delete" another
// task, so they must be run in order to avoid leaking the inner task.
@@ -76,28 +76,19 @@ class InvalidationNotifierTest : public testing::Test {
protected:
scoped_ptr<InvalidationNotifier> invalidation_notifier_;
FakeInvalidationStateTracker fake_tracker_;
- StrictMock<MockSyncNotifierObserver> mock_observer_;
+ FakeSyncNotifierObserver fake_observer_;
};
TEST_F(InvalidationNotifierTest, Basic) {
- InSequence dummy;
-
CreateNotifier("fake_state");
const ModelTypeSet models(PREFERENCES, BOOKMARKS, AUTOFILL);
- const ModelTypeStateMap& type_state_map =
- ModelTypeSetToStateMap(models, "payload");
- EXPECT_CALL(mock_observer_, OnNotificationsEnabled());
- EXPECT_CALL(mock_observer_, OnIncomingNotification(
- ModelTypeStateMapToObjectIdStateMap(type_state_map),
- REMOTE_NOTIFICATION));
- EXPECT_CALL(mock_observer_,
- OnNotificationsDisabled(TRANSIENT_NOTIFICATION_ERROR));
- EXPECT_CALL(mock_observer_,
- OnNotificationsDisabled(NOTIFICATION_CREDENTIALS_REJECTED));
+ const ObjectIdStateMap& id_state_map =
+ ModelTypeStateMapToObjectIdStateMap(
+ ModelTypeSetToStateMap(models, "payload"));
invalidation_notifier_->UpdateRegisteredIds(
- &mock_observer_, ModelTypeSetToObjectIdSet(models));
+ &fake_observer_, ModelTypeSetToObjectIdSet(models));
// TODO(tim): This call should be a no-op, Remove once bug 124140 and
// associated issues are fixed.
@@ -109,14 +100,23 @@ TEST_F(InvalidationNotifierTest, Basic) {
invalidation_notifier_->UpdateCredentials("foo@bar.com", "fake_token");
invalidation_notifier_->OnNotificationsEnabled();
+ EXPECT_EQ(NO_NOTIFICATION_ERROR,
+ fake_observer_.GetNotificationsDisabledReason());
- invalidation_notifier_->OnInvalidate(
- ModelTypeStateMapToObjectIdStateMap(type_state_map));
+ invalidation_notifier_->OnInvalidate(id_state_map);
+ EXPECT_THAT(id_state_map,
+ Eq(fake_observer_.GetLastNotificationIdStateMap()));
+ EXPECT_EQ(REMOTE_NOTIFICATION, fake_observer_.GetLastNotificationSource());
invalidation_notifier_->OnNotificationsDisabled(
TRANSIENT_NOTIFICATION_ERROR);
+ EXPECT_EQ(TRANSIENT_NOTIFICATION_ERROR,
+ fake_observer_.GetNotificationsDisabledReason());
+
invalidation_notifier_->OnNotificationsDisabled(
NOTIFICATION_CREDENTIALS_REJECTED);
+ EXPECT_EQ(NOTIFICATION_CREDENTIALS_REJECTED,
+ fake_observer_.GetNotificationsDisabledReason());
}
TEST_F(InvalidationNotifierTest, MigrateState) {
diff --git a/sync/notifier/mock_sync_notifier_observer.cc b/sync/notifier/mock_sync_notifier_observer.cc
deleted file mode 100644
index d8db8f2..0000000
--- a/sync/notifier/mock_sync_notifier_observer.cc
+++ /dev/null
@@ -1,12 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "sync/notifier/mock_sync_notifier_observer.h"
-
-namespace syncer {
-
-MockSyncNotifierObserver::MockSyncNotifierObserver() {}
-MockSyncNotifierObserver::~MockSyncNotifierObserver() {}
-
-} // namespace syncer
diff --git a/sync/notifier/mock_sync_notifier_observer.h b/sync/notifier/mock_sync_notifier_observer.h
deleted file mode 100644
index 6a50ad4..0000000
--- a/sync/notifier/mock_sync_notifier_observer.h
+++ /dev/null
@@ -1,28 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef SYNC_NOTIFIER_MOCK_SYNC_NOTIFIER_OBSERVER_H_
-#define SYNC_NOTIFIER_MOCK_SYNC_NOTIFIER_OBSERVER_H_
-
-#include <string>
-
-#include "sync/notifier/sync_notifier_observer.h"
-#include "testing/gmock/include/gmock/gmock.h"
-
-namespace syncer {
-
-class MockSyncNotifierObserver : public SyncNotifierObserver {
- public:
- MockSyncNotifierObserver();
- virtual ~MockSyncNotifierObserver();
-
- MOCK_METHOD0(OnNotificationsEnabled, void());
- MOCK_METHOD1(OnNotificationsDisabled, void(NotificationsDisabledReason));
- MOCK_METHOD2(OnIncomingNotification,
- void(const ObjectIdStateMap&, IncomingNotificationSource));
-};
-
-} // namespace syncer
-
-#endif // SYNC_NOTIFIER_MOCK_SYNC_NOTIFIER_OBSERVER_H_
diff --git a/sync/notifier/non_blocking_invalidation_notifier_unittest.cc b/sync/notifier/non_blocking_invalidation_notifier_unittest.cc
index 1121b4b..a749b64 100644
--- a/sync/notifier/non_blocking_invalidation_notifier_unittest.cc
+++ b/sync/notifier/non_blocking_invalidation_notifier_unittest.cc
@@ -14,8 +14,8 @@
#include "sync/internal_api/public/base/model_type.h"
#include "sync/internal_api/public/base/model_type_state_map.h"
#include "sync/internal_api/public/util/weak_handle.h"
+#include "sync/notifier/fake_sync_notifier_observer.h"
#include "sync/notifier/invalidation_state_tracker.h"
-#include "sync/notifier/mock_sync_notifier_observer.h"
#include "sync/notifier/object_id_state_map_test_util.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -47,11 +47,11 @@ class NonBlockingInvalidationNotifierTest : public testing::Test {
std::string(), // initial_invalidation_state
MakeWeakHandle(base::WeakPtr<InvalidationStateTracker>()),
"fake_client_info"));
- invalidation_notifier_->RegisterHandler(&mock_observer_);
+ invalidation_notifier_->RegisterHandler(&fake_observer_);
}
virtual void TearDown() {
- invalidation_notifier_->UnregisterHandler(&mock_observer_);
+ invalidation_notifier_->UnregisterHandler(&fake_observer_);
invalidation_notifier_.reset();
request_context_getter_ = NULL;
io_thread_.Stop();
@@ -62,42 +62,44 @@ class NonBlockingInvalidationNotifierTest : public testing::Test {
base::Thread io_thread_;
scoped_refptr<net::URLRequestContextGetter> request_context_getter_;
scoped_ptr<NonBlockingInvalidationNotifier> invalidation_notifier_;
- StrictMock<MockSyncNotifierObserver> mock_observer_;
+ FakeSyncNotifierObserver fake_observer_;
notifier::FakeBaseTask fake_base_task_;
};
// TODO(akalin): Add real unit tests (http://crbug.com/140410).
TEST_F(NonBlockingInvalidationNotifierTest, Basic) {
- InSequence dummy;
-
const ModelTypeSet models(PREFERENCES, BOOKMARKS, AUTOFILL);
- const ModelTypeStateMap& type_state_map =
- ModelTypeSetToStateMap(models, "payload");
- EXPECT_CALL(mock_observer_, OnNotificationsEnabled());
- EXPECT_CALL(mock_observer_, OnIncomingNotification(
- ModelTypeStateMapToObjectIdStateMap(type_state_map),
- REMOTE_NOTIFICATION));
- EXPECT_CALL(mock_observer_,
- OnNotificationsDisabled(TRANSIENT_NOTIFICATION_ERROR));
- EXPECT_CALL(mock_observer_,
- OnNotificationsDisabled(NOTIFICATION_CREDENTIALS_REJECTED));
+ const ObjectIdStateMap& id_state_map =
+ ModelTypeStateMapToObjectIdStateMap(
+ ModelTypeSetToStateMap(models, "payload"));
invalidation_notifier_->UpdateRegisteredIds(
- &mock_observer_, ModelTypeSetToObjectIdSet(models));
+ &fake_observer_, ModelTypeSetToObjectIdSet(models));
invalidation_notifier_->SetStateDeprecated("fake_state");
invalidation_notifier_->SetUniqueId("fake_id");
invalidation_notifier_->UpdateCredentials("foo@bar.com", "fake_token");
invalidation_notifier_->OnNotificationsEnabled();
+ EXPECT_EQ(NO_NOTIFICATION_ERROR,
+ fake_observer_.GetNotificationsDisabledReason());
+
invalidation_notifier_->OnIncomingNotification(
- ModelTypeStateMapToObjectIdStateMap(type_state_map),
- REMOTE_NOTIFICATION);
+ id_state_map, REMOTE_NOTIFICATION);
+ EXPECT_THAT(id_state_map,
+ Eq(fake_observer_.GetLastNotificationIdStateMap()));
+ EXPECT_EQ(REMOTE_NOTIFICATION, fake_observer_.GetLastNotificationSource());
+
invalidation_notifier_->OnNotificationsDisabled(
TRANSIENT_NOTIFICATION_ERROR);
+ EXPECT_EQ(TRANSIENT_NOTIFICATION_ERROR,
+ fake_observer_.GetNotificationsDisabledReason());
+
invalidation_notifier_->OnNotificationsDisabled(
NOTIFICATION_CREDENTIALS_REJECTED);
+ EXPECT_EQ(NOTIFICATION_CREDENTIALS_REJECTED,
+ fake_observer_.GetNotificationsDisabledReason());
ui_loop_.RunAllPending();
}
diff --git a/sync/notifier/p2p_notifier_unittest.cc b/sync/notifier/p2p_notifier_unittest.cc
index 9ad6f8a..6a62038b 100644
--- a/sync/notifier/p2p_notifier_unittest.cc
+++ b/sync/notifier/p2p_notifier_unittest.cc
@@ -9,7 +9,7 @@
#include "jingle/notifier/listener/fake_push_client.h"
#include "sync/internal_api/public/base/model_type.h"
#include "sync/internal_api/public/base/model_type_state_map.h"
-#include "sync/notifier/mock_sync_notifier_observer.h"
+#include "sync/notifier/fake_sync_notifier_observer.h"
#include "sync/notifier/object_id_state_map_test_util.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -17,10 +17,6 @@ namespace syncer {
namespace {
-using ::testing::_;
-using ::testing::Mock;
-using ::testing::StrictMock;
-
class P2PNotifierTest : public testing::Test {
protected:
P2PNotifierTest()
@@ -29,11 +25,11 @@ class P2PNotifierTest : public testing::Test {
scoped_ptr<notifier::PushClient>(fake_push_client_),
NOTIFY_OTHERS),
next_sent_notification_to_reflect_(0) {
- p2p_notifier_.RegisterHandler(&mock_observer_);
+ p2p_notifier_.RegisterHandler(&fake_observer_);
}
virtual ~P2PNotifierTest() {
- p2p_notifier_.UnregisterHandler(&mock_observer_);
+ p2p_notifier_.UnregisterHandler(&fake_observer_);
}
ModelTypeStateMap MakeStateMap(ModelTypeSet types) {
@@ -55,7 +51,7 @@ class P2PNotifierTest : public testing::Test {
// Owned by |p2p_notifier_|.
notifier::FakePushClient* fake_push_client_;
P2PNotifier p2p_notifier_;
- StrictMock<MockSyncNotifierObserver> mock_observer_;
+ FakeSyncNotifierObserver fake_observer_;
private:
size_t next_sent_notification_to_reflect_;
@@ -144,13 +140,7 @@ TEST_F(P2PNotifierTest, P2PNotificationDataNonDefault) {
TEST_F(P2PNotifierTest, NotificationsBasic) {
const ModelTypeSet enabled_types(BOOKMARKS, PREFERENCES);
- EXPECT_CALL(mock_observer_, OnNotificationsEnabled());
- EXPECT_CALL(mock_observer_, OnIncomingNotification(
- ModelTypeStateMapToObjectIdStateMap(MakeStateMap(
- enabled_types)),
- REMOTE_NOTIFICATION));
-
- p2p_notifier_.UpdateRegisteredIds(&mock_observer_,
+ p2p_notifier_.UpdateRegisteredIds(&fake_observer_,
ModelTypeSetToObjectIdSet(enabled_types));
p2p_notifier_.SetUniqueId("sender");
@@ -171,15 +161,25 @@ TEST_F(P2PNotifierTest, NotificationsBasic) {
ReflectSentNotifications();
fake_push_client_->EnableNotifications();
+ EXPECT_EQ(NO_NOTIFICATION_ERROR,
+ fake_observer_.GetNotificationsDisabledReason());
+
+ ReflectSentNotifications();
+ EXPECT_EQ(1, fake_observer_.GetNotificationCount());
+ EXPECT_THAT(
+ ModelTypeStateMapToObjectIdStateMap(MakeStateMap(enabled_types)),
+ Eq(fake_observer_.GetLastNotificationIdStateMap()));
+ EXPECT_EQ(REMOTE_NOTIFICATION, fake_observer_.GetLastNotificationSource());
// Sent with target NOTIFY_OTHERS so should not be propagated to
- // |mock_observer_|.
+ // |fake_observer_|.
{
ModelTypeSet changed_types(THEMES, APPS);
p2p_notifier_.SendNotification(changed_types);
}
ReflectSentNotifications();
+ EXPECT_EQ(1, fake_observer_.GetNotificationCount());
}
// Set up the P2PNotifier and send out notifications with various
@@ -190,106 +190,97 @@ TEST_F(P2PNotifierTest, SendNotificationData) {
const ModelTypeSet changed_types(THEMES, APPS);
const ModelTypeSet expected_types(THEMES);
- EXPECT_CALL(mock_observer_, OnNotificationsEnabled());
- EXPECT_CALL(mock_observer_,
- OnIncomingNotification(
- ModelTypeStateMapToObjectIdStateMap(
- MakeStateMap(enabled_types)),
- REMOTE_NOTIFICATION));
-
- p2p_notifier_.UpdateRegisteredIds(&mock_observer_,
+ p2p_notifier_.UpdateRegisteredIds(&fake_observer_,
ModelTypeSetToObjectIdSet(enabled_types));
- const ModelTypeStateMap& expected_state_map =
- MakeStateMap(expected_types);
-
p2p_notifier_.SetUniqueId("sender");
p2p_notifier_.UpdateCredentials("foo@bar.com", "fake_token");
ReflectSentNotifications();
fake_push_client_->EnableNotifications();
+ EXPECT_EQ(NO_NOTIFICATION_ERROR,
+ fake_observer_.GetNotificationsDisabledReason());
ReflectSentNotifications();
+ EXPECT_EQ(1, fake_observer_.GetNotificationCount());
+ EXPECT_THAT(
+ ModelTypeStateMapToObjectIdStateMap(MakeStateMap(enabled_types)),
+ Eq(fake_observer_.GetLastNotificationIdStateMap()));
+ EXPECT_EQ(REMOTE_NOTIFICATION, fake_observer_.GetLastNotificationSource());
// Should be dropped.
- Mock::VerifyAndClearExpectations(&mock_observer_);
p2p_notifier_.SendNotificationDataForTest(P2PNotificationData());
-
ReflectSentNotifications();
+ EXPECT_EQ(1, fake_observer_.GetNotificationCount());
+
+ const ObjectIdStateMap& expected_ids =
+ ModelTypeStateMapToObjectIdStateMap(MakeStateMap(expected_types));
// Should be propagated.
- Mock::VerifyAndClearExpectations(&mock_observer_);
- EXPECT_CALL(mock_observer_, OnIncomingNotification(
- ModelTypeStateMapToObjectIdStateMap(expected_state_map),
- REMOTE_NOTIFICATION));
p2p_notifier_.SendNotificationDataForTest(
P2PNotificationData("sender", NOTIFY_SELF, changed_types));
-
ReflectSentNotifications();
+ EXPECT_EQ(2, fake_observer_.GetNotificationCount());
+ EXPECT_THAT(
+ expected_ids,
+ Eq(fake_observer_.GetLastNotificationIdStateMap()));
// Should be dropped.
- Mock::VerifyAndClearExpectations(&mock_observer_);
p2p_notifier_.SendNotificationDataForTest(
P2PNotificationData("sender2", NOTIFY_SELF, changed_types));
-
ReflectSentNotifications();
+ EXPECT_EQ(2, fake_observer_.GetNotificationCount());
// Should be dropped.
- Mock::VerifyAndClearExpectations(&mock_observer_);
p2p_notifier_.SendNotificationDataForTest(
P2PNotificationData("sender", NOTIFY_SELF, ModelTypeSet()));
-
ReflectSentNotifications();
+ EXPECT_EQ(2, fake_observer_.GetNotificationCount());
// Should be dropped.
p2p_notifier_.SendNotificationDataForTest(
P2PNotificationData("sender", NOTIFY_OTHERS, changed_types));
-
ReflectSentNotifications();
+ EXPECT_EQ(2, fake_observer_.GetNotificationCount());
// Should be propagated.
- Mock::VerifyAndClearExpectations(&mock_observer_);
- EXPECT_CALL(mock_observer_, OnIncomingNotification(
- ModelTypeStateMapToObjectIdStateMap(expected_state_map),
- REMOTE_NOTIFICATION));
p2p_notifier_.SendNotificationDataForTest(
P2PNotificationData("sender2", NOTIFY_OTHERS, changed_types));
-
ReflectSentNotifications();
+ EXPECT_EQ(3, fake_observer_.GetNotificationCount());
+ EXPECT_THAT(
+ expected_ids,
+ Eq(fake_observer_.GetLastNotificationIdStateMap()));
// Should be dropped.
- Mock::VerifyAndClearExpectations(&mock_observer_);
p2p_notifier_.SendNotificationDataForTest(
P2PNotificationData("sender2", NOTIFY_OTHERS, ModelTypeSet()));
-
ReflectSentNotifications();
+ EXPECT_EQ(3, fake_observer_.GetNotificationCount());
// Should be propagated.
- Mock::VerifyAndClearExpectations(&mock_observer_);
- EXPECT_CALL(mock_observer_, OnIncomingNotification(
- ModelTypeStateMapToObjectIdStateMap(expected_state_map),
- REMOTE_NOTIFICATION));
p2p_notifier_.SendNotificationDataForTest(
P2PNotificationData("sender", NOTIFY_ALL, changed_types));
-
ReflectSentNotifications();
+ EXPECT_EQ(4, fake_observer_.GetNotificationCount());
+ EXPECT_THAT(
+ expected_ids,
+ Eq(fake_observer_.GetLastNotificationIdStateMap()));
// Should be propagated.
- Mock::VerifyAndClearExpectations(&mock_observer_);
- EXPECT_CALL(mock_observer_, OnIncomingNotification(
- ModelTypeStateMapToObjectIdStateMap(expected_state_map),
- REMOTE_NOTIFICATION));
p2p_notifier_.SendNotificationDataForTest(
P2PNotificationData("sender2", NOTIFY_ALL, changed_types));
-
ReflectSentNotifications();
+ EXPECT_EQ(5, fake_observer_.GetNotificationCount());
+ EXPECT_THAT(
+ expected_ids,
+ Eq(fake_observer_.GetLastNotificationIdStateMap()));
// Should be dropped.
- Mock::VerifyAndClearExpectations(&mock_observer_);
p2p_notifier_.SendNotificationDataForTest(
P2PNotificationData("sender2", NOTIFY_ALL, ModelTypeSet()));
-
ReflectSentNotifications();
+ EXPECT_EQ(5, fake_observer_.GetNotificationCount());
}
} // namespace
diff --git a/sync/notifier/sync_notifier_factory_unittest.cc b/sync/notifier/sync_notifier_factory_unittest.cc
index 64c802f..6e2bc58 100644
--- a/sync/notifier/sync_notifier_factory_unittest.cc
+++ b/sync/notifier/sync_notifier_factory_unittest.cc
@@ -15,19 +15,14 @@
#include "jingle/notifier/base/notifier_options.h"
#include "net/url_request/url_request_test_util.h"
#include "sync/internal_api/public/base/model_type.h"
+#include "sync/notifier/fake_sync_notifier_observer.h"
#include "sync/notifier/invalidation_state_tracker.h"
-#include "sync/notifier/mock_sync_notifier_observer.h"
#include "sync/notifier/sync_notifier.h"
-#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace syncer {
namespace {
-using ::testing::Mock;
-using ::testing::NiceMock;
-using ::testing::StrictMock;
-
class SyncNotifierFactoryTest : public testing::Test {
protected:
@@ -37,12 +32,12 @@ class SyncNotifierFactoryTest : public testing::Test {
}
virtual void TearDown() OVERRIDE {
- Mock::VerifyAndClearExpectations(&mock_observer_);
message_loop_.RunAllPending();
+ EXPECT_EQ(0, fake_observer_.GetNotificationCount());
}
MessageLoop message_loop_;
- StrictMock<MockSyncNotifierObserver> mock_observer_;
+ FakeSyncNotifierObserver fake_observer_;
notifier::NotifierOptions notifier_options_;
scoped_ptr<SyncNotifierFactory> factory_;
};
@@ -60,9 +55,9 @@ TEST_F(SyncNotifierFactoryTest, Basic) {
#else
ASSERT_TRUE(notifier.get());
ObjectIdSet ids = ModelTypeSetToObjectIdSet(ModelTypeSet(syncer::BOOKMARKS));
- notifier->RegisterHandler(&mock_observer_);
- notifier->UpdateRegisteredIds(&mock_observer_, ids);
- notifier->UnregisterHandler(&mock_observer_);
+ notifier->RegisterHandler(&fake_observer_);
+ notifier->UpdateRegisteredIds(&fake_observer_, ids);
+ notifier->UnregisterHandler(&fake_observer_);
#endif
}
@@ -79,9 +74,9 @@ TEST_F(SyncNotifierFactoryTest, Basic_P2P) {
#else
ASSERT_TRUE(notifier.get());
ObjectIdSet ids = ModelTypeSetToObjectIdSet(ModelTypeSet(syncer::BOOKMARKS));
- notifier->RegisterHandler(&mock_observer_);
- notifier->UpdateRegisteredIds(&mock_observer_, ids);
- notifier->UnregisterHandler(&mock_observer_);
+ notifier->RegisterHandler(&fake_observer_);
+ notifier->UpdateRegisteredIds(&fake_observer_, ids);
+ notifier->UnregisterHandler(&fake_observer_);
#endif
}
diff --git a/sync/notifier/sync_notifier_registrar.cc b/sync/notifier/sync_notifier_registrar.cc
index 77c394c..a6960f5 100644
--- a/sync/notifier/sync_notifier_registrar.cc
+++ b/sync/notifier/sync_notifier_registrar.cc
@@ -114,6 +114,25 @@ void SyncNotifierRegistrar::EmitOnNotificationsDisabled(
OnNotificationsDisabled(reason));
}
+bool SyncNotifierRegistrar::IsHandlerRegisteredForTest(
+ SyncNotifierObserver* handler) const {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ return handlers_.HasObserver(handler);
+}
+
+ObjectIdSet SyncNotifierRegistrar::GetRegisteredIdsForTest(
+ SyncNotifierObserver* handler) const {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ ObjectIdSet registered_ids;
+ for (IdHandlerMap::const_iterator it = id_to_handler_map_.begin();
+ it != id_to_handler_map_.end(); ++it) {
+ if (it->second == handler) {
+ registered_ids.insert(it->first);
+ }
+ }
+ return registered_ids;
+}
+
void SyncNotifierRegistrar::DetachFromThreadForTest() {
DCHECK(thread_checker_.CalledOnValidThread());
thread_checker_.DetachFromThread();
diff --git a/sync/notifier/sync_notifier_registrar.h b/sync/notifier/sync_notifier_registrar.h
index 4ebdc14..38a81c4 100644
--- a/sync/notifier/sync_notifier_registrar.h
+++ b/sync/notifier/sync_notifier_registrar.h
@@ -60,6 +60,9 @@ class SyncNotifierRegistrar {
void EmitOnNotificationsEnabled();
void EmitOnNotificationsDisabled(NotificationsDisabledReason reason);
+ bool IsHandlerRegisteredForTest(SyncNotifierObserver* handler) const;
+ ObjectIdSet GetRegisteredIdsForTest(SyncNotifierObserver* handler) const;
+
// Needed for death tests.
void DetachFromThreadForTest();
diff --git a/sync/notifier/sync_notifier_registrar_unittest.cc b/sync/notifier/sync_notifier_registrar_unittest.cc
index f78ebc9..a9e57c5 100644
--- a/sync/notifier/sync_notifier_registrar_unittest.cc
+++ b/sync/notifier/sync_notifier_registrar_unittest.cc
@@ -3,7 +3,7 @@
// found in the LICENSE file.
#include "google/cacheinvalidation/types.pb.h"
-#include "sync/notifier/mock_sync_notifier_observer.h"
+#include "sync/notifier/fake_sync_notifier_observer.h"
#include "sync/notifier/object_id_state_map_test_util.h"
#include "sync/notifier/sync_notifier_registrar.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -12,10 +12,6 @@ namespace syncer {
namespace {
-using testing::InSequence;
-using testing::Mock;
-using testing::StrictMock;
-
class SyncNotifierRegistrarTest : public testing::Test {
protected:
SyncNotifierRegistrarTest()
@@ -35,7 +31,7 @@ class SyncNotifierRegistrarTest : public testing::Test {
// the handler, dispatching invalidations in between. The handler should only
// see invalidations when its registered and its IDs are registered.
TEST_F(SyncNotifierRegistrarTest, Basic) {
- StrictMock<MockSyncNotifierObserver> handler;
+ FakeSyncNotifierObserver handler;
SyncNotifierRegistrar registrar;
@@ -48,47 +44,44 @@ TEST_F(SyncNotifierRegistrarTest, Basic) {
// Should be ignored since no IDs are registered to |handler|.
registrar.DispatchInvalidationsToHandlers(states, REMOTE_NOTIFICATION);
-
- Mock::VerifyAndClearExpectations(&handler);
+ EXPECT_EQ(0, handler.GetNotificationCount());
ObjectIdSet ids;
ids.insert(kObjectId1);
ids.insert(kObjectId2);
registrar.UpdateRegisteredIds(&handler, ids);
- {
- ObjectIdStateMap expected_states;
- expected_states[kObjectId1].payload = "1";
- expected_states[kObjectId2].payload = "2";
- EXPECT_CALL(handler, OnIncomingNotification(
- expected_states, REMOTE_NOTIFICATION));
- }
+ ObjectIdStateMap expected_states;
+ expected_states[kObjectId1].payload = "1";
+ expected_states[kObjectId2].payload = "2";
registrar.DispatchInvalidationsToHandlers(states, REMOTE_NOTIFICATION);
-
- Mock::VerifyAndClearExpectations(&handler);
+ EXPECT_EQ(1, handler.GetNotificationCount());
+ EXPECT_THAT(
+ expected_states,
+ Eq(handler.GetLastNotificationIdStateMap()));
+ EXPECT_EQ(REMOTE_NOTIFICATION, handler.GetLastNotificationSource());
ids.erase(kObjectId1);
ids.insert(kObjectId3);
registrar.UpdateRegisteredIds(&handler, ids);
- {
- ObjectIdStateMap expected_states;
- expected_states[kObjectId2].payload = "2";
- expected_states[kObjectId3].payload = "3";
- EXPECT_CALL(handler, OnIncomingNotification(
- expected_states, REMOTE_NOTIFICATION));
- }
+ expected_states.erase(kObjectId1);
+ expected_states[kObjectId3].payload = "3";
// Removed object IDs should not be notified, newly-added ones should.
registrar.DispatchInvalidationsToHandlers(states, REMOTE_NOTIFICATION);
-
- Mock::VerifyAndClearExpectations(&handler);
+ EXPECT_EQ(2, handler.GetNotificationCount());
+ EXPECT_THAT(
+ expected_states,
+ Eq(handler.GetLastNotificationIdStateMap()));
+ EXPECT_EQ(REMOTE_NOTIFICATION, handler.GetLastNotificationSource());
registrar.UnregisterHandler(&handler);
// Should be ignored since |handler| isn't registered anymore.
registrar.DispatchInvalidationsToHandlers(states, REMOTE_NOTIFICATION);
+ EXPECT_EQ(2, handler.GetNotificationCount());
}
// Register handlers and some IDs for those handlers, register a handler with
@@ -97,35 +90,10 @@ TEST_F(SyncNotifierRegistrarTest, Basic) {
// should get notifications, and the ones that have registered IDs should
// receive invalidations for those IDs.
TEST_F(SyncNotifierRegistrarTest, MultipleHandlers) {
- StrictMock<MockSyncNotifierObserver> handler1;
- EXPECT_CALL(handler1, OnNotificationsEnabled());
- {
- ObjectIdStateMap expected_states;
- expected_states[kObjectId1].payload = "1";
- expected_states[kObjectId2].payload = "2";
- EXPECT_CALL(handler1, OnIncomingNotification(
- expected_states, REMOTE_NOTIFICATION));
- }
- EXPECT_CALL(handler1,
- OnNotificationsDisabled(TRANSIENT_NOTIFICATION_ERROR));
-
- StrictMock<MockSyncNotifierObserver> handler2;
- EXPECT_CALL(handler2, OnNotificationsEnabled());
- {
- ObjectIdStateMap expected_states;
- expected_states[kObjectId3].payload = "3";
- EXPECT_CALL(handler2, OnIncomingNotification(
- expected_states, REMOTE_NOTIFICATION));
- }
- EXPECT_CALL(handler2,
- OnNotificationsDisabled(TRANSIENT_NOTIFICATION_ERROR));
-
- StrictMock<MockSyncNotifierObserver> handler3;
- EXPECT_CALL(handler3, OnNotificationsEnabled());
- EXPECT_CALL(handler3,
- OnNotificationsDisabled(TRANSIENT_NOTIFICATION_ERROR));
-
- StrictMock<MockSyncNotifierObserver> handler4;
+ FakeSyncNotifierObserver handler1;
+ FakeSyncNotifierObserver handler2;
+ FakeSyncNotifierObserver handler3;
+ FakeSyncNotifierObserver handler4;
SyncNotifierRegistrar registrar;
@@ -158,6 +126,15 @@ TEST_F(SyncNotifierRegistrarTest, MultipleHandlers) {
registrar.UnregisterHandler(&handler4);
registrar.EmitOnNotificationsEnabled();
+ EXPECT_EQ(NO_NOTIFICATION_ERROR,
+ handler1.GetNotificationsDisabledReason());
+ EXPECT_EQ(NO_NOTIFICATION_ERROR,
+ handler2.GetNotificationsDisabledReason());
+ EXPECT_EQ(NO_NOTIFICATION_ERROR,
+ handler3.GetNotificationsDisabledReason());
+ EXPECT_EQ(TRANSIENT_NOTIFICATION_ERROR,
+ handler4.GetNotificationsDisabledReason());
+
{
ObjectIdStateMap states;
states[kObjectId1].payload = "1";
@@ -165,8 +142,39 @@ TEST_F(SyncNotifierRegistrarTest, MultipleHandlers) {
states[kObjectId3].payload = "3";
states[kObjectId4].payload = "4";
registrar.DispatchInvalidationsToHandlers(states, REMOTE_NOTIFICATION);
+
+ ObjectIdStateMap expected_states;
+ expected_states[kObjectId1].payload = "1";
+ expected_states[kObjectId2].payload = "2";
+
+ EXPECT_EQ(1, handler1.GetNotificationCount());
+ EXPECT_THAT(
+ expected_states,
+ Eq(handler1.GetLastNotificationIdStateMap()));
+ EXPECT_EQ(REMOTE_NOTIFICATION, handler1.GetLastNotificationSource());
+
+ expected_states.clear();
+ expected_states[kObjectId3].payload = "3";
+
+ EXPECT_EQ(1, handler2.GetNotificationCount());
+ EXPECT_THAT(
+ expected_states,
+ Eq(handler2.GetLastNotificationIdStateMap()));
+ EXPECT_EQ(REMOTE_NOTIFICATION, handler2.GetLastNotificationSource());
+
+ EXPECT_EQ(0, handler3.GetNotificationCount());
+ EXPECT_EQ(0, handler4.GetNotificationCount());
}
+
registrar.EmitOnNotificationsDisabled(TRANSIENT_NOTIFICATION_ERROR);
+ EXPECT_EQ(TRANSIENT_NOTIFICATION_ERROR,
+ handler1.GetNotificationsDisabledReason());
+ EXPECT_EQ(TRANSIENT_NOTIFICATION_ERROR,
+ handler2.GetNotificationsDisabledReason());
+ EXPECT_EQ(TRANSIENT_NOTIFICATION_ERROR,
+ handler3.GetNotificationsDisabledReason());
+ EXPECT_EQ(TRANSIENT_NOTIFICATION_ERROR,
+ handler4.GetNotificationsDisabledReason());
}
// Multiple registrations by different handlers on the same object ID should
@@ -174,10 +182,10 @@ TEST_F(SyncNotifierRegistrarTest, MultipleHandlers) {
TEST_F(SyncNotifierRegistrarTest, MultipleRegistration) {
SyncNotifierRegistrar registrar;
- StrictMock<MockSyncNotifierObserver> handler1;
+ FakeSyncNotifierObserver handler1;
registrar.RegisterHandler(&handler1);
- MockSyncNotifierObserver handler2;
+ FakeSyncNotifierObserver handler2;
registrar.RegisterHandler(&handler2);
ObjectIdSet ids;
@@ -194,22 +202,10 @@ TEST_F(SyncNotifierRegistrarTest, MultipleRegistration) {
// Make sure that passing an empty set to UpdateRegisteredIds clears the
// corresponding entries for the handler.
TEST_F(SyncNotifierRegistrarTest, EmptySetUnregisters) {
- StrictMock<MockSyncNotifierObserver> handler1;
- EXPECT_CALL(handler1, OnNotificationsEnabled());
- EXPECT_CALL(handler1,
- OnNotificationsDisabled(TRANSIENT_NOTIFICATION_ERROR));
+ FakeSyncNotifierObserver handler1;
// Control observer.
- StrictMock<MockSyncNotifierObserver> handler2;
- EXPECT_CALL(handler2, OnNotificationsEnabled());
- {
- ObjectIdStateMap expected_states;
- expected_states[kObjectId3].payload = "3";
- EXPECT_CALL(handler2, OnIncomingNotification(
- expected_states, REMOTE_NOTIFICATION));
- }
- EXPECT_CALL(handler2,
- OnNotificationsDisabled(TRANSIENT_NOTIFICATION_ERROR));
+ FakeSyncNotifierObserver handler2;
SyncNotifierRegistrar registrar;
@@ -234,14 +230,27 @@ TEST_F(SyncNotifierRegistrarTest, EmptySetUnregisters) {
registrar.UpdateRegisteredIds(&handler1, ObjectIdSet());
registrar.EmitOnNotificationsEnabled();
+ EXPECT_EQ(NO_NOTIFICATION_ERROR,
+ handler1.GetNotificationsDisabledReason());
+ EXPECT_EQ(NO_NOTIFICATION_ERROR,
+ handler2.GetNotificationsDisabledReason());
+
{
ObjectIdStateMap states;
states[kObjectId1].payload = "1";
states[kObjectId2].payload = "2";
states[kObjectId3].payload = "3";
- registrar.DispatchInvalidationsToHandlers(states, REMOTE_NOTIFICATION);
+ registrar.DispatchInvalidationsToHandlers(states,
+ REMOTE_NOTIFICATION);
+ EXPECT_EQ(0, handler1.GetNotificationCount());
+ EXPECT_EQ(1, handler2.GetNotificationCount());
}
+
registrar.EmitOnNotificationsDisabled(TRANSIENT_NOTIFICATION_ERROR);
+ EXPECT_EQ(TRANSIENT_NOTIFICATION_ERROR,
+ handler1.GetNotificationsDisabledReason());
+ EXPECT_EQ(TRANSIENT_NOTIFICATION_ERROR,
+ handler2.GetNotificationsDisabledReason());
}
} // namespace
diff --git a/sync/sync.gyp b/sync/sync.gyp
index 415a3be..397d057 100644
--- a/sync/sync.gyp
+++ b/sync/sync.gyp
@@ -480,8 +480,10 @@
'sources': [
'notifier/fake_invalidation_state_tracker.cc',
'notifier/fake_invalidation_state_tracker.h',
- 'notifier/mock_sync_notifier_observer.cc',
- 'notifier/mock_sync_notifier_observer.h',
+ 'notifier/fake_sync_notifier.cc',
+ 'notifier/fake_sync_notifier.h',
+ 'notifier/fake_sync_notifier_observer.cc',
+ 'notifier/fake_sync_notifier_observer.h',
'notifier/object_id_state_map_test_util.cc',
'notifier/object_id_state_map_test_util.h',
],