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_, OnNotificationsEnabled()); |
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_->EnableNotifications(); |
173 | 173 |
174 // Sent with target NOTIFY_OTHERS so should not be propagated to | 174 // Sent with target NOTIFY_OTHERS so should not be propagated to |
175 // |mock_observer_|. | 175 // |mock_observer_|. |
176 { | 176 { |
177 syncable::ModelTypeSet changed_types( | 177 syncable::ModelTypeSet changed_types( |
178 syncable::THEMES, syncable::APPS); | 178 syncable::THEMES, syncable::APPS); |
179 p2p_notifier_.SendNotification(changed_types); | 179 p2p_notifier_.SendNotification(changed_types); |
180 } | 180 } |
181 | 181 |
182 ReflectSentNotifications(); | 182 ReflectSentNotifications(); |
183 } | 183 } |
184 | 184 |
185 // Set up the P2PNotifier and send out notifications with various | 185 // Set up the P2PNotifier and send out notifications with various |
186 // target settings. The notifications received by the observer should | 186 // target settings. The notifications received by the observer should |
187 // be consistent with the target settings. | 187 // be consistent with the target settings. |
188 TEST_F(P2PNotifierTest, SendNotificationData) { | 188 TEST_F(P2PNotifierTest, SendNotificationData) { |
189 syncable::ModelTypeSet enabled_types( | 189 syncable::ModelTypeSet enabled_types( |
190 syncable::BOOKMARKS, syncable::PREFERENCES); | 190 syncable::BOOKMARKS, syncable::PREFERENCES); |
191 | 191 |
192 syncable::ModelTypeSet changed_types( | 192 syncable::ModelTypeSet changed_types( |
193 syncable::THEMES, syncable::APPS); | 193 syncable::THEMES, syncable::APPS); |
194 | 194 |
195 const syncable::ModelTypePayloadMap& changed_payload_map = | 195 const syncable::ModelTypePayloadMap& changed_payload_map = |
196 MakePayloadMap(changed_types); | 196 MakePayloadMap(changed_types); |
197 | 197 |
198 EXPECT_CALL(mock_observer_, OnNotificationStateChange(true)); | 198 EXPECT_CALL(mock_observer_, OnNotificationsEnabled()); |
199 EXPECT_CALL(mock_observer_, | 199 EXPECT_CALL(mock_observer_, |
200 OnIncomingNotification(MakePayloadMap(enabled_types), | 200 OnIncomingNotification(MakePayloadMap(enabled_types), |
201 REMOTE_NOTIFICATION)); | 201 REMOTE_NOTIFICATION)); |
202 | 202 |
203 p2p_notifier_.SetUniqueId("sender"); | 203 p2p_notifier_.SetUniqueId("sender"); |
204 p2p_notifier_.UpdateCredentials("foo@bar.com", "fake_token"); | 204 p2p_notifier_.UpdateCredentials("foo@bar.com", "fake_token"); |
205 p2p_notifier_.UpdateEnabledTypes(enabled_types); | 205 p2p_notifier_.UpdateEnabledTypes(enabled_types); |
206 | 206 |
207 ReflectSentNotifications(); | 207 ReflectSentNotifications(); |
208 fake_push_client_->SimulateNotificationStateChange(true); | 208 fake_push_client_->EnableNotifications(); |
209 | 209 |
210 ReflectSentNotifications(); | 210 ReflectSentNotifications(); |
211 | 211 |
212 // Should be dropped. | 212 // Should be dropped. |
213 Mock::VerifyAndClearExpectations(&mock_observer_); | 213 Mock::VerifyAndClearExpectations(&mock_observer_); |
214 p2p_notifier_.SendNotificationDataForTest(P2PNotificationData()); | 214 p2p_notifier_.SendNotificationDataForTest(P2PNotificationData()); |
215 | 215 |
216 ReflectSentNotifications(); | 216 ReflectSentNotifications(); |
217 | 217 |
218 // Should be propagated. | 218 // Should be propagated. |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
282 Mock::VerifyAndClearExpectations(&mock_observer_); | 282 Mock::VerifyAndClearExpectations(&mock_observer_); |
283 p2p_notifier_.SendNotificationDataForTest( | 283 p2p_notifier_.SendNotificationDataForTest( |
284 P2PNotificationData("sender2", NOTIFY_ALL, syncable::ModelTypeSet())); | 284 P2PNotificationData("sender2", NOTIFY_ALL, syncable::ModelTypeSet())); |
285 | 285 |
286 ReflectSentNotifications(); | 286 ReflectSentNotifications(); |
287 } | 287 } |
288 | 288 |
289 } // namespace | 289 } // namespace |
290 | 290 |
291 } // namespace sync_notifier | 291 } // namespace sync_notifier |
OLD | NEW |