| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "sync/notifier/p2p_notifier.h" | 5 #include "sync/notifier/p2p_notifier.h" |
| 6 | 6 |
| 7 #include <cstddef> | 7 #include <cstddef> |
| 8 | 8 |
| 9 #include "jingle/notifier/listener/fake_push_client.h" | 9 #include "jingle/notifier/listener/fake_push_client.h" |
| 10 #include "sync/internal_api/public/syncable/model_type.h" | 10 #include "sync/internal_api/public/syncable/model_type.h" |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 } | 138 } |
| 139 | 139 |
| 140 // Set up the P2PNotifier, simulate a successful connection, and send | 140 // Set up the P2PNotifier, simulate a successful connection, and send |
| 141 // a notification with the default target (NOTIFY_OTHERS). The | 141 // a notification with the default target (NOTIFY_OTHERS). The |
| 142 // observer should receive only a notification from the call to | 142 // observer should receive only a notification from the call to |
| 143 // UpdateEnabledTypes(). | 143 // UpdateEnabledTypes(). |
| 144 TEST_F(P2PNotifierTest, NotificationsBasic) { | 144 TEST_F(P2PNotifierTest, NotificationsBasic) { |
| 145 syncable::ModelTypeSet enabled_types( | 145 syncable::ModelTypeSet enabled_types( |
| 146 syncable::BOOKMARKS, syncable::PREFERENCES); | 146 syncable::BOOKMARKS, syncable::PREFERENCES); |
| 147 | 147 |
| 148 EXPECT_CALL(mock_observer_, OnNotificationStateChange(true)); | 148 EXPECT_CALL(mock_observer_, OnSyncNotifierStateChange(NOTIFICATIONS_ON)); |
| 149 EXPECT_CALL(mock_observer_, | 149 EXPECT_CALL(mock_observer_, |
| 150 OnIncomingNotification(MakePayloadMap(enabled_types), | 150 OnIncomingNotification(MakePayloadMap(enabled_types), |
| 151 REMOTE_NOTIFICATION)); | 151 REMOTE_NOTIFICATION)); |
| 152 | 152 |
| 153 p2p_notifier_.SetUniqueId("sender"); | 153 p2p_notifier_.SetUniqueId("sender"); |
| 154 | 154 |
| 155 const char kEmail[] = "foo@bar.com"; | 155 const char kEmail[] = "foo@bar.com"; |
| 156 const char kToken[] = "token"; | 156 const char kToken[] = "token"; |
| 157 p2p_notifier_.UpdateCredentials(kEmail, kToken); | 157 p2p_notifier_.UpdateCredentials(kEmail, kToken); |
| 158 { | 158 { |
| 159 notifier::Subscription expected_subscription; | 159 notifier::Subscription expected_subscription; |
| 160 expected_subscription.channel = kSyncP2PNotificationChannel; | 160 expected_subscription.channel = kSyncP2PNotificationChannel; |
| 161 expected_subscription.from = kEmail; | 161 expected_subscription.from = kEmail; |
| 162 EXPECT_TRUE(notifier::SubscriptionListsEqual( | 162 EXPECT_TRUE(notifier::SubscriptionListsEqual( |
| 163 fake_push_client_->subscriptions(), | 163 fake_push_client_->subscriptions(), |
| 164 notifier::SubscriptionList(1, expected_subscription))); | 164 notifier::SubscriptionList(1, expected_subscription))); |
| 165 } | 165 } |
| 166 EXPECT_EQ(kEmail, fake_push_client_->email()); | 166 EXPECT_EQ(kEmail, fake_push_client_->email()); |
| 167 EXPECT_EQ(kToken, fake_push_client_->token()); | 167 EXPECT_EQ(kToken, fake_push_client_->token()); |
| 168 | 168 |
| 169 p2p_notifier_.UpdateEnabledTypes(enabled_types); | 169 p2p_notifier_.UpdateEnabledTypes(enabled_types); |
| 170 | 170 |
| 171 ReflectSentNotifications(); | 171 ReflectSentNotifications(); |
| 172 fake_push_client_->SimulateNotificationStateChange(true); | 172 fake_push_client_->SimulatePushClientStateChange( |
| 173 notifier::NOTIFICATIONS_ON); |
| 173 | 174 |
| 174 // Sent with target NOTIFY_OTHERS so should not be propagated to | 175 // Sent with target NOTIFY_OTHERS so should not be propagated to |
| 175 // |mock_observer_|. | 176 // |mock_observer_|. |
| 176 { | 177 { |
| 177 syncable::ModelTypeSet changed_types( | 178 syncable::ModelTypeSet changed_types( |
| 178 syncable::THEMES, syncable::APPS); | 179 syncable::THEMES, syncable::APPS); |
| 179 p2p_notifier_.SendNotification(changed_types); | 180 p2p_notifier_.SendNotification(changed_types); |
| 180 } | 181 } |
| 181 | 182 |
| 182 ReflectSentNotifications(); | 183 ReflectSentNotifications(); |
| 183 } | 184 } |
| 184 | 185 |
| 185 // Set up the P2PNotifier and send out notifications with various | 186 // Set up the P2PNotifier and send out notifications with various |
| 186 // target settings. The notifications received by the observer should | 187 // target settings. The notifications received by the observer should |
| 187 // be consistent with the target settings. | 188 // be consistent with the target settings. |
| 188 TEST_F(P2PNotifierTest, SendNotificationData) { | 189 TEST_F(P2PNotifierTest, SendNotificationData) { |
| 189 syncable::ModelTypeSet enabled_types( | 190 syncable::ModelTypeSet enabled_types( |
| 190 syncable::BOOKMARKS, syncable::PREFERENCES); | 191 syncable::BOOKMARKS, syncable::PREFERENCES); |
| 191 | 192 |
| 192 syncable::ModelTypeSet changed_types( | 193 syncable::ModelTypeSet changed_types( |
| 193 syncable::THEMES, syncable::APPS); | 194 syncable::THEMES, syncable::APPS); |
| 194 | 195 |
| 195 const syncable::ModelTypePayloadMap& changed_payload_map = | 196 const syncable::ModelTypePayloadMap& changed_payload_map = |
| 196 MakePayloadMap(changed_types); | 197 MakePayloadMap(changed_types); |
| 197 | 198 |
| 198 EXPECT_CALL(mock_observer_, OnNotificationStateChange(true)); | 199 EXPECT_CALL(mock_observer_, OnSyncNotifierStateChange(NOTIFICATIONS_ON)); |
| 199 EXPECT_CALL(mock_observer_, | 200 EXPECT_CALL(mock_observer_, |
| 200 OnIncomingNotification(MakePayloadMap(enabled_types), | 201 OnIncomingNotification(MakePayloadMap(enabled_types), |
| 201 REMOTE_NOTIFICATION)); | 202 REMOTE_NOTIFICATION)); |
| 202 | 203 |
| 203 p2p_notifier_.SetUniqueId("sender"); | 204 p2p_notifier_.SetUniqueId("sender"); |
| 204 p2p_notifier_.UpdateCredentials("foo@bar.com", "fake_token"); | 205 p2p_notifier_.UpdateCredentials("foo@bar.com", "fake_token"); |
| 205 p2p_notifier_.UpdateEnabledTypes(enabled_types); | 206 p2p_notifier_.UpdateEnabledTypes(enabled_types); |
| 206 | 207 |
| 207 ReflectSentNotifications(); | 208 ReflectSentNotifications(); |
| 208 fake_push_client_->SimulateNotificationStateChange(true); | 209 fake_push_client_->SimulatePushClientStateChange( |
| 210 notifier::NOTIFICATIONS_ON); |
| 209 | 211 |
| 210 ReflectSentNotifications(); | 212 ReflectSentNotifications(); |
| 211 | 213 |
| 212 // Should be dropped. | 214 // Should be dropped. |
| 213 Mock::VerifyAndClearExpectations(&mock_observer_); | 215 Mock::VerifyAndClearExpectations(&mock_observer_); |
| 214 p2p_notifier_.SendNotificationDataForTest(P2PNotificationData()); | 216 p2p_notifier_.SendNotificationDataForTest(P2PNotificationData()); |
| 215 | 217 |
| 216 ReflectSentNotifications(); | 218 ReflectSentNotifications(); |
| 217 | 219 |
| 218 // Should be propagated. | 220 // Should be propagated. |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 Mock::VerifyAndClearExpectations(&mock_observer_); | 284 Mock::VerifyAndClearExpectations(&mock_observer_); |
| 283 p2p_notifier_.SendNotificationDataForTest( | 285 p2p_notifier_.SendNotificationDataForTest( |
| 284 P2PNotificationData("sender2", NOTIFY_ALL, syncable::ModelTypeSet())); | 286 P2PNotificationData("sender2", NOTIFY_ALL, syncable::ModelTypeSet())); |
| 285 | 287 |
| 286 ReflectSentNotifications(); | 288 ReflectSentNotifications(); |
| 287 } | 289 } |
| 288 | 290 |
| 289 } // namespace | 291 } // namespace |
| 290 | 292 |
| 291 } // namespace sync_notifier | 293 } // namespace sync_notifier |
| OLD | NEW |