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

Side by Side Diff: sync/notifier/p2p_notifier_unittest.cc

Issue 10824161: [Sync] Avoid unregistering object IDs on shutdown (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments Created 8 years, 4 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/base/model_type.h" 10 #include "sync/internal_api/public/base/model_type.h"
11 #include "sync/internal_api/public/base/model_type_payload_map.h" 11 #include "sync/internal_api/public/base/model_type_payload_map.h"
12 #include "sync/notifier/mock_sync_notifier_observer.h" 12 #include "sync/notifier/mock_sync_notifier_observer.h"
13 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
14 14
15 namespace syncer { 15 namespace syncer {
16 16
17 namespace { 17 namespace {
18 18
19 using ::testing::_; 19 using ::testing::_;
20 using ::testing::Mock; 20 using ::testing::Mock;
21 using ::testing::StrictMock; 21 using ::testing::StrictMock;
22 22
23 const char kHandlerName[] = "MockObserver";
24
23 class P2PNotifierTest : public testing::Test { 25 class P2PNotifierTest : public testing::Test {
24 protected: 26 protected:
25 P2PNotifierTest() 27 P2PNotifierTest()
26 : fake_push_client_(new notifier::FakePushClient()), 28 : fake_push_client_(new notifier::FakePushClient()),
27 p2p_notifier_( 29 p2p_notifier_(
28 scoped_ptr<notifier::PushClient>(fake_push_client_), 30 scoped_ptr<notifier::PushClient>(fake_push_client_),
29 NOTIFY_OTHERS), 31 NOTIFY_OTHERS),
30 next_sent_notification_to_reflect_(0) { 32 next_sent_notification_to_reflect_(0) {}
31 }
32 33
33 virtual ~P2PNotifierTest() { 34 virtual ~P2PNotifierTest() {
34 p2p_notifier_.UpdateRegisteredIds(&mock_observer_, ObjectIdSet()); 35 p2p_notifier_.SetHandler(kHandlerName, NULL);
35 } 36 }
36 37
37 ModelTypePayloadMap MakePayloadMap(ModelTypeSet types) { 38 ModelTypePayloadMap MakePayloadMap(ModelTypeSet types) {
38 return ModelTypePayloadMapFromEnumSet(types, std::string()); 39 return ModelTypePayloadMapFromEnumSet(types, std::string());
39 } 40 }
40 41
41 // Simulate receiving all the notifications we sent out since last 42 // Simulate receiving all the notifications we sent out since last
42 // time this was called. 43 // time this was called.
43 void ReflectSentNotifications() { 44 void ReflectSentNotifications() {
44 const std::vector<notifier::Notification>& sent_notifications = 45 const std::vector<notifier::Notification>& sent_notifications =
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 P2PNotificationData notification_data_parsed; 134 P2PNotificationData notification_data_parsed;
134 EXPECT_TRUE(notification_data_parsed.ResetFromString(notification_data_str)); 135 EXPECT_TRUE(notification_data_parsed.ResetFromString(notification_data_str));
135 EXPECT_TRUE(notification_data.Equals(notification_data_parsed)); 136 EXPECT_TRUE(notification_data.Equals(notification_data_parsed));
136 } 137 }
137 138
138 // Set up the P2PNotifier, simulate a successful connection, and send 139 // Set up the P2PNotifier, simulate a successful connection, and send
139 // a notification with the default target (NOTIFY_OTHERS). The 140 // a notification with the default target (NOTIFY_OTHERS). The
140 // observer should receive only a notification from the call to 141 // observer should receive only a notification from the call to
141 // UpdateEnabledTypes(). 142 // UpdateEnabledTypes().
142 TEST_F(P2PNotifierTest, NotificationsBasic) { 143 TEST_F(P2PNotifierTest, NotificationsBasic) {
143 ModelTypeSet enabled_types(BOOKMARKS, PREFERENCES); 144 const ModelTypeSet enabled_types(BOOKMARKS, PREFERENCES);
144
145 p2p_notifier_.UpdateRegisteredIds(&mock_observer_,
146 ModelTypeSetToObjectIdSet(enabled_types));
147 145
148 EXPECT_CALL(mock_observer_, OnNotificationsEnabled()); 146 EXPECT_CALL(mock_observer_, OnNotificationsEnabled());
149 EXPECT_CALL(mock_observer_, OnIncomingNotification( 147 EXPECT_CALL(mock_observer_, OnIncomingNotification(
150 ModelTypePayloadMapToObjectIdPayloadMap(MakePayloadMap(enabled_types)), 148 ModelTypePayloadMapToObjectIdPayloadMap(MakePayloadMap(enabled_types)),
151 REMOTE_NOTIFICATION)); 149 REMOTE_NOTIFICATION));
152 150
151 p2p_notifier_.SetHandler(kHandlerName, &mock_observer_);
152 p2p_notifier_.UpdateRegisteredIds(kHandlerName,
153 ModelTypeSetToObjectIdSet(enabled_types));
154
153 p2p_notifier_.SetUniqueId("sender"); 155 p2p_notifier_.SetUniqueId("sender");
154 156
155 const char kEmail[] = "foo@bar.com"; 157 const char kEmail[] = "foo@bar.com";
156 const char kToken[] = "token"; 158 const char kToken[] = "token";
157 p2p_notifier_.UpdateCredentials(kEmail, kToken); 159 p2p_notifier_.UpdateCredentials(kEmail, kToken);
158 { 160 {
159 notifier::Subscription expected_subscription; 161 notifier::Subscription expected_subscription;
160 expected_subscription.channel = kSyncP2PNotificationChannel; 162 expected_subscription.channel = kSyncP2PNotificationChannel;
161 expected_subscription.from = kEmail; 163 expected_subscription.from = kEmail;
162 EXPECT_TRUE(notifier::SubscriptionListsEqual( 164 EXPECT_TRUE(notifier::SubscriptionListsEqual(
(...skipping 13 matching lines...) Expand all
176 p2p_notifier_.SendNotification(changed_types); 178 p2p_notifier_.SendNotification(changed_types);
177 } 179 }
178 180
179 ReflectSentNotifications(); 181 ReflectSentNotifications();
180 } 182 }
181 183
182 // Set up the P2PNotifier and send out notifications with various 184 // Set up the P2PNotifier and send out notifications with various
183 // target settings. The notifications received by the observer should 185 // target settings. The notifications received by the observer should
184 // be consistent with the target settings. 186 // be consistent with the target settings.
185 TEST_F(P2PNotifierTest, SendNotificationData) { 187 TEST_F(P2PNotifierTest, SendNotificationData) {
186 ModelTypeSet enabled_types(BOOKMARKS, PREFERENCES, THEMES); 188 const ModelTypeSet enabled_types(BOOKMARKS, PREFERENCES, THEMES);
187 ModelTypeSet changed_types(THEMES, APPS); 189 const ModelTypeSet changed_types(THEMES, APPS);
188 ModelTypeSet expected_types(THEMES); 190 const ModelTypeSet expected_types(THEMES);
189
190 p2p_notifier_.UpdateRegisteredIds(&mock_observer_,
191 ModelTypeSetToObjectIdSet(enabled_types));
192
193 const ModelTypePayloadMap& expected_payload_map =
194 MakePayloadMap(expected_types);
195 191
196 EXPECT_CALL(mock_observer_, OnNotificationsEnabled()); 192 EXPECT_CALL(mock_observer_, OnNotificationsEnabled());
197 EXPECT_CALL(mock_observer_, 193 EXPECT_CALL(mock_observer_,
198 OnIncomingNotification( 194 OnIncomingNotification(
199 ModelTypePayloadMapToObjectIdPayloadMap( 195 ModelTypePayloadMapToObjectIdPayloadMap(
200 MakePayloadMap(enabled_types)), 196 MakePayloadMap(enabled_types)),
201 REMOTE_NOTIFICATION)); 197 REMOTE_NOTIFICATION));
202 198
199 p2p_notifier_.SetHandler(kHandlerName, &mock_observer_);
200 p2p_notifier_.UpdateRegisteredIds(kHandlerName,
201 ModelTypeSetToObjectIdSet(enabled_types));
202
203 const ModelTypePayloadMap& expected_payload_map =
204 MakePayloadMap(expected_types);
205
203 p2p_notifier_.SetUniqueId("sender"); 206 p2p_notifier_.SetUniqueId("sender");
204 p2p_notifier_.UpdateCredentials("foo@bar.com", "fake_token"); 207 p2p_notifier_.UpdateCredentials("foo@bar.com", "fake_token");
205 208
206 ReflectSentNotifications(); 209 ReflectSentNotifications();
207 fake_push_client_->EnableNotifications(); 210 fake_push_client_->EnableNotifications();
208 211
209 ReflectSentNotifications(); 212 ReflectSentNotifications();
210 213
211 // Should be dropped. 214 // Should be dropped.
212 Mock::VerifyAndClearExpectations(&mock_observer_); 215 Mock::VerifyAndClearExpectations(&mock_observer_);
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 Mock::VerifyAndClearExpectations(&mock_observer_); 288 Mock::VerifyAndClearExpectations(&mock_observer_);
286 p2p_notifier_.SendNotificationDataForTest( 289 p2p_notifier_.SendNotificationDataForTest(
287 P2PNotificationData("sender2", NOTIFY_ALL, ModelTypeSet())); 290 P2PNotificationData("sender2", NOTIFY_ALL, ModelTypeSet()));
288 291
289 ReflectSentNotifications(); 292 ReflectSentNotifications();
290 } 293 }
291 294
292 } // namespace 295 } // namespace
293 296
294 } // namespace syncer 297 } // namespace syncer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698