summaryrefslogtreecommitdiffstats
path: root/sync/notifier/p2p_notifier_unittest.cc
diff options
context:
space:
mode:
authordcheng@chromium.org <dcheng@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-07-21 19:40:33 +0000
committerdcheng@chromium.org <dcheng@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-07-21 19:40:33 +0000
commit877197584abc8883cbccc3bd83240a9be6c2e16e (patch)
tree36da6824a41c80c87f1b95dc1c8cf1f4a9e4571c /sync/notifier/p2p_notifier_unittest.cc
parent8e2dd2741c41e5090aee5f8bc31349ff6d9c0fed (diff)
downloadchromium_src-877197584abc8883cbccc3bd83240a9be6c2e16e.zip
chromium_src-877197584abc8883cbccc3bd83240a9be6c2e16e.tar.gz
chromium_src-877197584abc8883cbccc3bd83240a9be6c2e16e.tar.bz2
Refactor sync-specific parts out of SyncNotifier/SyncNotifierObserver
Sort of. SendNotification() is still there. Perhaps we want to split the interfaces completely. BUG=124149 TEST=tests should still pass, no observable behavior change Review URL: https://chromiumcodereview.appspot.com/10702074 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@147801 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'sync/notifier/p2p_notifier_unittest.cc')
-rw-r--r--sync/notifier/p2p_notifier_unittest.cc54
1 files changed, 32 insertions, 22 deletions
diff --git a/sync/notifier/p2p_notifier_unittest.cc b/sync/notifier/p2p_notifier_unittest.cc
index e6e406a..2f7b2c9 100644
--- a/sync/notifier/p2p_notifier_unittest.cc
+++ b/sync/notifier/p2p_notifier_unittest.cc
@@ -8,6 +8,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_payload_map.h"
#include "sync/notifier/mock_sync_notifier_observer.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -27,15 +28,14 @@ class P2PNotifierTest : public testing::Test {
scoped_ptr<notifier::PushClient>(fake_push_client_),
NOTIFY_OTHERS),
next_sent_notification_to_reflect_(0) {
- p2p_notifier_.AddObserver(&mock_observer_);
}
virtual ~P2PNotifierTest() {
- p2p_notifier_.RemoveObserver(&mock_observer_);
+ p2p_notifier_.UpdateRegisteredIds(&mock_observer_, ObjectIdSet());
}
ModelTypePayloadMap MakePayloadMap(ModelTypeSet types) {
- return ModelTypePayloadMapFromEnumSet(types, "");
+ return ModelTypePayloadMapFromEnumSet(types, std::string());
}
// Simulate receiving all the notifications we sent out since last
@@ -142,10 +142,13 @@ TEST_F(P2PNotifierTest, P2PNotificationDataNonDefault) {
TEST_F(P2PNotifierTest, NotificationsBasic) {
ModelTypeSet enabled_types(BOOKMARKS, PREFERENCES);
+ p2p_notifier_.UpdateRegisteredIds(&mock_observer_,
+ ModelTypeSetToObjectIdSet(enabled_types));
+
EXPECT_CALL(mock_observer_, OnNotificationsEnabled());
- EXPECT_CALL(mock_observer_,
- OnIncomingNotification(MakePayloadMap(enabled_types),
- REMOTE_NOTIFICATION));
+ EXPECT_CALL(mock_observer_, OnIncomingNotification(
+ ModelTypePayloadMapToObjectIdPayloadMap(MakePayloadMap(enabled_types)),
+ REMOTE_NOTIFICATION));
p2p_notifier_.SetUniqueId("sender");
@@ -163,8 +166,6 @@ TEST_F(P2PNotifierTest, NotificationsBasic) {
EXPECT_EQ(kEmail, fake_push_client_->email());
EXPECT_EQ(kToken, fake_push_client_->token());
- p2p_notifier_.UpdateEnabledTypes(enabled_types);
-
ReflectSentNotifications();
fake_push_client_->EnableNotifications();
@@ -184,19 +185,24 @@ TEST_F(P2PNotifierTest, NotificationsBasic) {
TEST_F(P2PNotifierTest, SendNotificationData) {
ModelTypeSet enabled_types(BOOKMARKS, PREFERENCES);
- ModelTypeSet changed_types(THEMES, APPS);
+ p2p_notifier_.UpdateRegisteredIds(&mock_observer_,
+ ModelTypeSetToObjectIdSet(enabled_types));
+
+ ModelTypeSet changed_types(BOOKMARKS, APPS);
+ ModelTypeSet expected_changed_types(BOOKMARKS);
- const ModelTypePayloadMap& changed_payload_map =
- MakePayloadMap(changed_types);
+ const ModelTypePayloadMap& expected_changed_payload_map =
+ MakePayloadMap(expected_changed_types);
EXPECT_CALL(mock_observer_, OnNotificationsEnabled());
EXPECT_CALL(mock_observer_,
- OnIncomingNotification(MakePayloadMap(enabled_types),
- REMOTE_NOTIFICATION));
+ OnIncomingNotification(
+ ModelTypePayloadMapToObjectIdPayloadMap(
+ MakePayloadMap(enabled_types)),
+ REMOTE_NOTIFICATION));
p2p_notifier_.SetUniqueId("sender");
p2p_notifier_.UpdateCredentials("foo@bar.com", "fake_token");
- p2p_notifier_.UpdateEnabledTypes(enabled_types);
ReflectSentNotifications();
fake_push_client_->EnableNotifications();
@@ -211,8 +217,9 @@ TEST_F(P2PNotifierTest, SendNotificationData) {
// Should be propagated.
Mock::VerifyAndClearExpectations(&mock_observer_);
- EXPECT_CALL(mock_observer_, OnIncomingNotification(changed_payload_map,
- REMOTE_NOTIFICATION));
+ EXPECT_CALL(mock_observer_, OnIncomingNotification(
+ ModelTypePayloadMapToObjectIdPayloadMap(expected_changed_payload_map),
+ REMOTE_NOTIFICATION));
p2p_notifier_.SendNotificationDataForTest(
P2PNotificationData("sender", NOTIFY_SELF, changed_types));
@@ -240,8 +247,9 @@ TEST_F(P2PNotifierTest, SendNotificationData) {
// Should be propagated.
Mock::VerifyAndClearExpectations(&mock_observer_);
- EXPECT_CALL(mock_observer_, OnIncomingNotification(changed_payload_map,
- REMOTE_NOTIFICATION));
+ EXPECT_CALL(mock_observer_, OnIncomingNotification(
+ ModelTypePayloadMapToObjectIdPayloadMap(expected_changed_payload_map),
+ REMOTE_NOTIFICATION));
p2p_notifier_.SendNotificationDataForTest(
P2PNotificationData("sender2", NOTIFY_OTHERS, changed_types));
@@ -256,8 +264,9 @@ TEST_F(P2PNotifierTest, SendNotificationData) {
// Should be propagated.
Mock::VerifyAndClearExpectations(&mock_observer_);
- EXPECT_CALL(mock_observer_, OnIncomingNotification(changed_payload_map,
- REMOTE_NOTIFICATION));
+ EXPECT_CALL(mock_observer_, OnIncomingNotification(
+ ModelTypePayloadMapToObjectIdPayloadMap(expected_changed_payload_map),
+ REMOTE_NOTIFICATION));
p2p_notifier_.SendNotificationDataForTest(
P2PNotificationData("sender", NOTIFY_ALL, changed_types));
@@ -265,8 +274,9 @@ TEST_F(P2PNotifierTest, SendNotificationData) {
// Should be propagated.
Mock::VerifyAndClearExpectations(&mock_observer_);
- EXPECT_CALL(mock_observer_, OnIncomingNotification(changed_payload_map,
- REMOTE_NOTIFICATION));
+ EXPECT_CALL(mock_observer_, OnIncomingNotification(
+ ModelTypePayloadMapToObjectIdPayloadMap(expected_changed_payload_map),
+ REMOTE_NOTIFICATION));
p2p_notifier_.SendNotificationDataForTest(
P2PNotificationData("sender2", NOTIFY_ALL, changed_types));