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

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: Work around brittle unit test 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
« no previous file with comments | « sync/notifier/p2p_notifier.cc ('k') | sync/notifier/sync_notifier.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
(...skipping 10 matching lines...) Expand all
21 using ::testing::StrictMock; 21 using ::testing::StrictMock;
22 22
23 class P2PNotifierTest : public testing::Test { 23 class P2PNotifierTest : public testing::Test {
24 protected: 24 protected:
25 P2PNotifierTest() 25 P2PNotifierTest()
26 : fake_push_client_(new notifier::FakePushClient()), 26 : fake_push_client_(new notifier::FakePushClient()),
27 p2p_notifier_( 27 p2p_notifier_(
28 scoped_ptr<notifier::PushClient>(fake_push_client_), 28 scoped_ptr<notifier::PushClient>(fake_push_client_),
29 NOTIFY_OTHERS), 29 NOTIFY_OTHERS),
30 next_sent_notification_to_reflect_(0) { 30 next_sent_notification_to_reflect_(0) {
31 p2p_notifier_.RegisterHandler(&mock_observer_);
31 } 32 }
32 33
33 virtual ~P2PNotifierTest() { 34 virtual ~P2PNotifierTest() {
34 p2p_notifier_.UpdateRegisteredIds(&mock_observer_, ObjectIdSet()); 35 p2p_notifier_.UnregisterHandler(&mock_observer_);
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_.UpdateRegisteredIds(&mock_observer_,
152 ModelTypeSetToObjectIdSet(enabled_types));
153
153 p2p_notifier_.SetUniqueId("sender"); 154 p2p_notifier_.SetUniqueId("sender");
154 155
155 const char kEmail[] = "foo@bar.com"; 156 const char kEmail[] = "foo@bar.com";
156 const char kToken[] = "token"; 157 const char kToken[] = "token";
157 p2p_notifier_.UpdateCredentials(kEmail, kToken); 158 p2p_notifier_.UpdateCredentials(kEmail, kToken);
158 { 159 {
159 notifier::Subscription expected_subscription; 160 notifier::Subscription expected_subscription;
160 expected_subscription.channel = kSyncP2PNotificationChannel; 161 expected_subscription.channel = kSyncP2PNotificationChannel;
161 expected_subscription.from = kEmail; 162 expected_subscription.from = kEmail;
162 EXPECT_TRUE(notifier::SubscriptionListsEqual( 163 EXPECT_TRUE(notifier::SubscriptionListsEqual(
(...skipping 13 matching lines...) Expand all
176 p2p_notifier_.SendNotification(changed_types); 177 p2p_notifier_.SendNotification(changed_types);
177 } 178 }
178 179
179 ReflectSentNotifications(); 180 ReflectSentNotifications();
180 } 181 }
181 182
182 // Set up the P2PNotifier and send out notifications with various 183 // Set up the P2PNotifier and send out notifications with various
183 // target settings. The notifications received by the observer should 184 // target settings. The notifications received by the observer should
184 // be consistent with the target settings. 185 // be consistent with the target settings.
185 TEST_F(P2PNotifierTest, SendNotificationData) { 186 TEST_F(P2PNotifierTest, SendNotificationData) {
186 ModelTypeSet enabled_types(BOOKMARKS, PREFERENCES, THEMES); 187 const ModelTypeSet enabled_types(BOOKMARKS, PREFERENCES, THEMES);
187 ModelTypeSet changed_types(THEMES, APPS); 188 const ModelTypeSet changed_types(THEMES, APPS);
188 ModelTypeSet expected_types(THEMES); 189 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 190
196 EXPECT_CALL(mock_observer_, OnNotificationsEnabled()); 191 EXPECT_CALL(mock_observer_, OnNotificationsEnabled());
197 EXPECT_CALL(mock_observer_, 192 EXPECT_CALL(mock_observer_,
198 OnIncomingNotification( 193 OnIncomingNotification(
199 ModelTypePayloadMapToObjectIdPayloadMap( 194 ModelTypePayloadMapToObjectIdPayloadMap(
200 MakePayloadMap(enabled_types)), 195 MakePayloadMap(enabled_types)),
201 REMOTE_NOTIFICATION)); 196 REMOTE_NOTIFICATION));
202 197
198 p2p_notifier_.UpdateRegisteredIds(&mock_observer_,
199 ModelTypeSetToObjectIdSet(enabled_types));
200
201 const ModelTypePayloadMap& expected_payload_map =
202 MakePayloadMap(expected_types);
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 206
206 ReflectSentNotifications(); 207 ReflectSentNotifications();
207 fake_push_client_->EnableNotifications(); 208 fake_push_client_->EnableNotifications();
208 209
209 ReflectSentNotifications(); 210 ReflectSentNotifications();
210 211
211 // Should be dropped. 212 // Should be dropped.
212 Mock::VerifyAndClearExpectations(&mock_observer_); 213 Mock::VerifyAndClearExpectations(&mock_observer_);
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 Mock::VerifyAndClearExpectations(&mock_observer_); 286 Mock::VerifyAndClearExpectations(&mock_observer_);
286 p2p_notifier_.SendNotificationDataForTest( 287 p2p_notifier_.SendNotificationDataForTest(
287 P2PNotificationData("sender2", NOTIFY_ALL, ModelTypeSet())); 288 P2PNotificationData("sender2", NOTIFY_ALL, ModelTypeSet()));
288 289
289 ReflectSentNotifications(); 290 ReflectSentNotifications();
290 } 291 }
291 292
292 } // namespace 293 } // namespace
293 294
294 } // namespace syncer 295 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/notifier/p2p_notifier.cc ('k') | sync/notifier/sync_notifier.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698