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

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

Issue 12114012: Remove syncer::IncomingInvalidationSource (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove comment Created 7 years, 10 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_invalidator.cc ('k') | sync/tools/sync_listen_notifications.cc » ('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_invalidator.h" 5 #include "sync/notifier/p2p_invalidator.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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 58
59 void TriggerOnInvalidatorStateChange(InvalidatorState state) { 59 void TriggerOnInvalidatorStateChange(InvalidatorState state) {
60 if (state == INVALIDATIONS_ENABLED) { 60 if (state == INVALIDATIONS_ENABLED) {
61 fake_push_client_->EnableNotifications(); 61 fake_push_client_->EnableNotifications();
62 } else { 62 } else {
63 fake_push_client_->DisableNotifications(ToNotifierReasonForTest(state)); 63 fake_push_client_->DisableNotifications(ToNotifierReasonForTest(state));
64 } 64 }
65 } 65 }
66 66
67 void TriggerOnIncomingInvalidation( 67 void TriggerOnIncomingInvalidation(
68 const ObjectIdInvalidationMap& invalidation_map, 68 const ObjectIdInvalidationMap& invalidation_map) {
69 IncomingInvalidationSource source) {
70 const P2PNotificationData notification_data( 69 const P2PNotificationData notification_data(
71 "", NOTIFY_ALL, invalidation_map, source); 70 "", NOTIFY_ALL, invalidation_map);
72 notifier::Notification notification; 71 notifier::Notification notification;
73 notification.channel = kSyncP2PNotificationChannel; 72 notification.channel = kSyncP2PNotificationChannel;
74 notification.data = notification_data.ToString(); 73 notification.data = notification_data.ToString();
75 fake_push_client_->SimulateIncomingNotification(notification); 74 fake_push_client_->SimulateIncomingNotification(notification);
76 } 75 }
77 76
78 private: 77 private:
79 // Owned by |invalidator_|. 78 // Owned by |invalidator_|.
80 notifier::FakePushClient* fake_push_client_; 79 notifier::FakePushClient* fake_push_client_;
81 scoped_ptr<P2PInvalidator> invalidator_; 80 scoped_ptr<P2PInvalidator> invalidator_;
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 EXPECT_FALSE(target_str.empty()); 125 EXPECT_FALSE(target_str.empty());
127 EXPECT_EQ(target, P2PNotificationTargetFromString(target_str)); 126 EXPECT_EQ(target, P2PNotificationTargetFromString(target_str));
128 } 127 }
129 EXPECT_EQ(NOTIFY_SELF, P2PNotificationTargetFromString("unknown")); 128 EXPECT_EQ(NOTIFY_SELF, P2PNotificationTargetFromString("unknown"));
130 } 129 }
131 130
132 // Make sure notification targeting works correctly. 131 // Make sure notification targeting works correctly.
133 TEST_F(P2PInvalidatorTest, P2PNotificationDataIsTargeted) { 132 TEST_F(P2PInvalidatorTest, P2PNotificationDataIsTargeted) {
134 { 133 {
135 const P2PNotificationData notification_data( 134 const P2PNotificationData notification_data(
136 "sender", NOTIFY_SELF, ObjectIdInvalidationMap(), REMOTE_INVALIDATION); 135 "sender", NOTIFY_SELF, ObjectIdInvalidationMap());
137 EXPECT_TRUE(notification_data.IsTargeted("sender")); 136 EXPECT_TRUE(notification_data.IsTargeted("sender"));
138 EXPECT_FALSE(notification_data.IsTargeted("other1")); 137 EXPECT_FALSE(notification_data.IsTargeted("other1"));
139 EXPECT_FALSE(notification_data.IsTargeted("other2")); 138 EXPECT_FALSE(notification_data.IsTargeted("other2"));
140 } 139 }
141 { 140 {
142 const P2PNotificationData notification_data( 141 const P2PNotificationData notification_data(
143 "sender", NOTIFY_OTHERS, ObjectIdInvalidationMap(), 142 "sender", NOTIFY_OTHERS, ObjectIdInvalidationMap());
144 REMOTE_INVALIDATION);
145 EXPECT_FALSE(notification_data.IsTargeted("sender")); 143 EXPECT_FALSE(notification_data.IsTargeted("sender"));
146 EXPECT_TRUE(notification_data.IsTargeted("other1")); 144 EXPECT_TRUE(notification_data.IsTargeted("other1"));
147 EXPECT_TRUE(notification_data.IsTargeted("other2")); 145 EXPECT_TRUE(notification_data.IsTargeted("other2"));
148 } 146 }
149 { 147 {
150 const P2PNotificationData notification_data( 148 const P2PNotificationData notification_data(
151 "sender", NOTIFY_ALL, ObjectIdInvalidationMap(), REMOTE_INVALIDATION); 149 "sender", NOTIFY_ALL, ObjectIdInvalidationMap());
152 EXPECT_TRUE(notification_data.IsTargeted("sender")); 150 EXPECT_TRUE(notification_data.IsTargeted("sender"));
153 EXPECT_TRUE(notification_data.IsTargeted("other1")); 151 EXPECT_TRUE(notification_data.IsTargeted("other1"));
154 EXPECT_TRUE(notification_data.IsTargeted("other2")); 152 EXPECT_TRUE(notification_data.IsTargeted("other2"));
155 } 153 }
156 } 154 }
157 155
158 // Make sure the P2PNotificationData <-> string conversions work for a 156 // Make sure the P2PNotificationData <-> string conversions work for a
159 // default-constructed P2PNotificationData. 157 // default-constructed P2PNotificationData.
160 TEST_F(P2PInvalidatorTest, P2PNotificationDataDefault) { 158 TEST_F(P2PInvalidatorTest, P2PNotificationDataDefault) {
161 const P2PNotificationData notification_data; 159 const P2PNotificationData notification_data;
162 EXPECT_TRUE(notification_data.IsTargeted("")); 160 EXPECT_TRUE(notification_data.IsTargeted(""));
163 EXPECT_FALSE(notification_data.IsTargeted("other1")); 161 EXPECT_FALSE(notification_data.IsTargeted("other1"));
164 EXPECT_FALSE(notification_data.IsTargeted("other2")); 162 EXPECT_FALSE(notification_data.IsTargeted("other2"));
165 EXPECT_TRUE(notification_data.GetIdInvalidationMap().empty()); 163 EXPECT_TRUE(notification_data.GetIdInvalidationMap().empty());
166 const std::string& notification_data_str = notification_data.ToString(); 164 const std::string& notification_data_str = notification_data.ToString();
167 EXPECT_EQ( 165 EXPECT_EQ(
168 "{\"idInvalidationMap\":[],\"notificationType\":\"notifySelf\"," 166 "{\"idInvalidationMap\":[],\"notificationType\":\"notifySelf\","
169 "\"senderId\":\"\",\"source\":0}", notification_data_str); 167 "\"senderId\":\"\"}", notification_data_str);
170 168
171 P2PNotificationData notification_data_parsed; 169 P2PNotificationData notification_data_parsed;
172 EXPECT_TRUE(notification_data_parsed.ResetFromString(notification_data_str)); 170 EXPECT_TRUE(notification_data_parsed.ResetFromString(notification_data_str));
173 EXPECT_TRUE(notification_data.Equals(notification_data_parsed)); 171 EXPECT_TRUE(notification_data.Equals(notification_data_parsed));
174 } 172 }
175 173
176 // Make sure the P2PNotificationData <-> string conversions work for a 174 // Make sure the P2PNotificationData <-> string conversions work for a
177 // non-default-constructed P2PNotificationData. 175 // non-default-constructed P2PNotificationData.
178 TEST_F(P2PInvalidatorTest, P2PNotificationDataNonDefault) { 176 TEST_F(P2PInvalidatorTest, P2PNotificationDataNonDefault) {
179 const ObjectIdInvalidationMap& invalidation_map = 177 const ObjectIdInvalidationMap& invalidation_map =
180 ObjectIdSetToInvalidationMap( 178 ObjectIdSetToInvalidationMap(
181 ModelTypeSetToObjectIdSet(ModelTypeSet(BOOKMARKS, THEMES)), ""); 179 ModelTypeSetToObjectIdSet(ModelTypeSet(BOOKMARKS, THEMES)), "");
182 const P2PNotificationData notification_data( 180 const P2PNotificationData notification_data(
183 "sender", NOTIFY_ALL, invalidation_map, LOCAL_INVALIDATION); 181 "sender", NOTIFY_ALL, invalidation_map);
184 EXPECT_TRUE(notification_data.IsTargeted("sender")); 182 EXPECT_TRUE(notification_data.IsTargeted("sender"));
185 EXPECT_TRUE(notification_data.IsTargeted("other1")); 183 EXPECT_TRUE(notification_data.IsTargeted("other1"));
186 EXPECT_TRUE(notification_data.IsTargeted("other2")); 184 EXPECT_TRUE(notification_data.IsTargeted("other2"));
187 EXPECT_THAT(invalidation_map, 185 EXPECT_THAT(invalidation_map,
188 Eq(notification_data.GetIdInvalidationMap())); 186 Eq(notification_data.GetIdInvalidationMap()));
189 const std::string& notification_data_str = notification_data.ToString(); 187 const std::string& notification_data_str = notification_data.ToString();
190 EXPECT_EQ( 188 EXPECT_EQ(
191 "{\"idInvalidationMap\":[" 189 "{\"idInvalidationMap\":["
192 "{\"objectId\":{\"name\":\"BOOKMARK\",\"source\":1004}," 190 "{\"objectId\":{\"name\":\"BOOKMARK\",\"source\":1004},"
193 "\"state\":{\"ackHandle\":{\"state\":\"\",\"timestamp\":\"0\"}," 191 "\"state\":{\"ackHandle\":{\"state\":\"\",\"timestamp\":\"0\"},"
194 "\"payload\":\"\"}}," 192 "\"payload\":\"\"}},"
195 "{\"objectId\":{\"name\":\"THEME\",\"source\":1004}," 193 "{\"objectId\":{\"name\":\"THEME\",\"source\":1004},"
196 "\"state\":{\"ackHandle\":{\"state\":\"\",\"timestamp\":\"0\"}," 194 "\"state\":{\"ackHandle\":{\"state\":\"\",\"timestamp\":\"0\"},"
197 "\"payload\":\"\"}}" 195 "\"payload\":\"\"}}"
198 "],\"notificationType\":\"notifyAll\"," 196 "],\"notificationType\":\"notifyAll\","
199 "\"senderId\":\"sender\",\"source\":1}", notification_data_str); 197 "\"senderId\":\"sender\"}", notification_data_str);
200 198
201 P2PNotificationData notification_data_parsed; 199 P2PNotificationData notification_data_parsed;
202 EXPECT_TRUE(notification_data_parsed.ResetFromString(notification_data_str)); 200 EXPECT_TRUE(notification_data_parsed.ResetFromString(notification_data_str));
203 EXPECT_TRUE(notification_data.Equals(notification_data_parsed)); 201 EXPECT_TRUE(notification_data.Equals(notification_data_parsed));
204 } 202 }
205 203
206 // Set up the P2PInvalidator, simulate a successful connection, and send 204 // Set up the P2PInvalidator, simulate a successful connection, and send
207 // a notification with the default target (NOTIFY_OTHERS). The 205 // a notification with the default target (NOTIFY_OTHERS). The
208 // observer should receive only a notification from the call to 206 // observer should receive only a notification from the call to
209 // UpdateEnabledTypes(). 207 // UpdateEnabledTypes().
(...skipping 25 matching lines...) Expand all
235 ReflectSentNotifications(); 233 ReflectSentNotifications();
236 push_client->EnableNotifications(); 234 push_client->EnableNotifications();
237 EXPECT_EQ(INVALIDATIONS_ENABLED, fake_handler_.GetInvalidatorState()); 235 EXPECT_EQ(INVALIDATIONS_ENABLED, fake_handler_.GetInvalidatorState());
238 236
239 ReflectSentNotifications(); 237 ReflectSentNotifications();
240 EXPECT_EQ(1, fake_handler_.GetInvalidationCount()); 238 EXPECT_EQ(1, fake_handler_.GetInvalidationCount());
241 EXPECT_THAT( 239 EXPECT_THAT(
242 ModelTypeInvalidationMapToObjectIdInvalidationMap( 240 ModelTypeInvalidationMapToObjectIdInvalidationMap(
243 MakeInvalidationMap(enabled_types)), 241 MakeInvalidationMap(enabled_types)),
244 Eq(fake_handler_.GetLastInvalidationMap())); 242 Eq(fake_handler_.GetLastInvalidationMap()));
245 EXPECT_EQ(REMOTE_INVALIDATION, fake_handler_.GetLastInvalidationSource());
246 243
247 // Sent with target NOTIFY_OTHERS so should not be propagated to 244 // Sent with target NOTIFY_OTHERS so should not be propagated to
248 // |fake_handler_|. 245 // |fake_handler_|.
249 { 246 {
250 const ObjectIdInvalidationMap& invalidation_map = 247 const ObjectIdInvalidationMap& invalidation_map =
251 ObjectIdSetToInvalidationMap( 248 ObjectIdSetToInvalidationMap(
252 ModelTypeSetToObjectIdSet(ModelTypeSet(THEMES, APPS)), ""); 249 ModelTypeSetToObjectIdSet(ModelTypeSet(THEMES, APPS)), "");
253 invalidator->SendInvalidation(invalidation_map); 250 invalidator->SendInvalidation(invalidation_map);
254 } 251 }
255 252
(...skipping 25 matching lines...) Expand all
281 ReflectSentNotifications(); 278 ReflectSentNotifications();
282 push_client->EnableNotifications(); 279 push_client->EnableNotifications();
283 EXPECT_EQ(INVALIDATIONS_ENABLED, fake_handler_.GetInvalidatorState()); 280 EXPECT_EQ(INVALIDATIONS_ENABLED, fake_handler_.GetInvalidatorState());
284 281
285 ReflectSentNotifications(); 282 ReflectSentNotifications();
286 EXPECT_EQ(1, fake_handler_.GetInvalidationCount()); 283 EXPECT_EQ(1, fake_handler_.GetInvalidationCount());
287 EXPECT_THAT( 284 EXPECT_THAT(
288 ModelTypeInvalidationMapToObjectIdInvalidationMap( 285 ModelTypeInvalidationMapToObjectIdInvalidationMap(
289 MakeInvalidationMap(enabled_types)), 286 MakeInvalidationMap(enabled_types)),
290 Eq(fake_handler_.GetLastInvalidationMap())); 287 Eq(fake_handler_.GetLastInvalidationMap()));
291 EXPECT_EQ(REMOTE_INVALIDATION, fake_handler_.GetLastInvalidationSource());
292 288
293 // Should be dropped. 289 // Should be dropped.
294 invalidator->SendNotificationDataForTest(P2PNotificationData()); 290 invalidator->SendNotificationDataForTest(P2PNotificationData());
295 ReflectSentNotifications(); 291 ReflectSentNotifications();
296 EXPECT_EQ(1, fake_handler_.GetInvalidationCount()); 292 EXPECT_EQ(1, fake_handler_.GetInvalidationCount());
297 293
298 const ObjectIdInvalidationMap& expected_ids = 294 const ObjectIdInvalidationMap& expected_ids =
299 ModelTypeInvalidationMapToObjectIdInvalidationMap( 295 ModelTypeInvalidationMapToObjectIdInvalidationMap(
300 MakeInvalidationMap(expected_types)); 296 MakeInvalidationMap(expected_types));
301 297
302 // Should be propagated. 298 // Should be propagated.
303 invalidator->SendNotificationDataForTest( 299 invalidator->SendNotificationDataForTest(
304 P2PNotificationData("sender", NOTIFY_SELF, 300 P2PNotificationData("sender", NOTIFY_SELF, invalidation_map));
305 invalidation_map, REMOTE_INVALIDATION));
306 ReflectSentNotifications(); 301 ReflectSentNotifications();
307 EXPECT_EQ(2, fake_handler_.GetInvalidationCount()); 302 EXPECT_EQ(2, fake_handler_.GetInvalidationCount());
308 EXPECT_THAT(expected_ids, Eq(fake_handler_.GetLastInvalidationMap())); 303 EXPECT_THAT(expected_ids, Eq(fake_handler_.GetLastInvalidationMap()));
309 304
310 // Should be dropped. 305 // Should be dropped.
311 invalidator->SendNotificationDataForTest( 306 invalidator->SendNotificationDataForTest(
312 P2PNotificationData("sender2", NOTIFY_SELF, 307 P2PNotificationData("sender2", NOTIFY_SELF, invalidation_map));
313 invalidation_map, REMOTE_INVALIDATION));
314 ReflectSentNotifications(); 308 ReflectSentNotifications();
315 EXPECT_EQ(2, fake_handler_.GetInvalidationCount()); 309 EXPECT_EQ(2, fake_handler_.GetInvalidationCount());
316 310
317 // Should be dropped. 311 // Should be dropped.
318 invalidator->SendNotificationDataForTest( 312 invalidator->SendNotificationDataForTest(
319 P2PNotificationData("sender", NOTIFY_SELF, 313 P2PNotificationData("sender", NOTIFY_SELF, ObjectIdInvalidationMap()));
320 ObjectIdInvalidationMap(), REMOTE_INVALIDATION));
321 ReflectSentNotifications(); 314 ReflectSentNotifications();
322 EXPECT_EQ(2, fake_handler_.GetInvalidationCount()); 315 EXPECT_EQ(2, fake_handler_.GetInvalidationCount());
323 316
324 // Should be dropped. 317 // Should be dropped.
325 invalidator->SendNotificationDataForTest( 318 invalidator->SendNotificationDataForTest(
326 P2PNotificationData("sender", NOTIFY_OTHERS, 319 P2PNotificationData("sender", NOTIFY_OTHERS, invalidation_map));
327 invalidation_map, REMOTE_INVALIDATION));
328 ReflectSentNotifications(); 320 ReflectSentNotifications();
329 EXPECT_EQ(2, fake_handler_.GetInvalidationCount()); 321 EXPECT_EQ(2, fake_handler_.GetInvalidationCount());
330 322
331 // Should be propagated. 323 // Should be propagated.
332 invalidator->SendNotificationDataForTest( 324 invalidator->SendNotificationDataForTest(
333 P2PNotificationData("sender2", NOTIFY_OTHERS, 325 P2PNotificationData("sender2", NOTIFY_OTHERS, invalidation_map));
334 invalidation_map, REMOTE_INVALIDATION));
335 ReflectSentNotifications(); 326 ReflectSentNotifications();
336 EXPECT_EQ(3, fake_handler_.GetInvalidationCount()); 327 EXPECT_EQ(3, fake_handler_.GetInvalidationCount());
337 EXPECT_THAT(expected_ids, Eq(fake_handler_.GetLastInvalidationMap())); 328 EXPECT_THAT(expected_ids, Eq(fake_handler_.GetLastInvalidationMap()));
338 329
339 // Should be dropped. 330 // Should be dropped.
340 invalidator->SendNotificationDataForTest( 331 invalidator->SendNotificationDataForTest(
341 P2PNotificationData("sender2", NOTIFY_OTHERS, 332 P2PNotificationData("sender2", NOTIFY_OTHERS, ObjectIdInvalidationMap()));
342 ObjectIdInvalidationMap(), REMOTE_INVALIDATION));
343 ReflectSentNotifications(); 333 ReflectSentNotifications();
344 EXPECT_EQ(3, fake_handler_.GetInvalidationCount()); 334 EXPECT_EQ(3, fake_handler_.GetInvalidationCount());
345 335
346 // Should be propagated. 336 // Should be propagated.
347 invalidator->SendNotificationDataForTest( 337 invalidator->SendNotificationDataForTest(
348 P2PNotificationData("sender", NOTIFY_ALL, 338 P2PNotificationData("sender", NOTIFY_ALL, invalidation_map));
349 invalidation_map, REMOTE_INVALIDATION));
350 ReflectSentNotifications(); 339 ReflectSentNotifications();
351 EXPECT_EQ(4, fake_handler_.GetInvalidationCount()); 340 EXPECT_EQ(4, fake_handler_.GetInvalidationCount());
352 EXPECT_THAT(expected_ids, Eq(fake_handler_.GetLastInvalidationMap())); 341 EXPECT_THAT(expected_ids, Eq(fake_handler_.GetLastInvalidationMap()));
353 342
354 // Should be propagated. 343 // Should be propagated.
355 invalidator->SendNotificationDataForTest( 344 invalidator->SendNotificationDataForTest(
356 P2PNotificationData("sender2", NOTIFY_ALL, 345 P2PNotificationData("sender2", NOTIFY_ALL, invalidation_map));
357 invalidation_map, REMOTE_INVALIDATION));
358 ReflectSentNotifications(); 346 ReflectSentNotifications();
359 EXPECT_EQ(5, fake_handler_.GetInvalidationCount()); 347 EXPECT_EQ(5, fake_handler_.GetInvalidationCount());
360 EXPECT_THAT(expected_ids, Eq(fake_handler_.GetLastInvalidationMap())); 348 EXPECT_THAT(expected_ids, Eq(fake_handler_.GetLastInvalidationMap()));
361 349
362 // Should be dropped. 350 // Should be dropped.
363 invalidator->SendNotificationDataForTest( 351 invalidator->SendNotificationDataForTest(
364 P2PNotificationData("sender2", NOTIFY_ALL, 352 P2PNotificationData("sender2", NOTIFY_ALL, ObjectIdInvalidationMap()));
365 ObjectIdInvalidationMap(), REMOTE_INVALIDATION));
366 ReflectSentNotifications(); 353 ReflectSentNotifications();
367 EXPECT_EQ(5, fake_handler_.GetInvalidationCount()); 354 EXPECT_EQ(5, fake_handler_.GetInvalidationCount());
368 } 355 }
369 356
370 INSTANTIATE_TYPED_TEST_CASE_P( 357 INSTANTIATE_TYPED_TEST_CASE_P(
371 P2PInvalidatorTest, InvalidatorTest, 358 P2PInvalidatorTest, InvalidatorTest,
372 P2PInvalidatorTestDelegate); 359 P2PInvalidatorTestDelegate);
373 360
374 } // namespace 361 } // namespace
375 362
376 } // namespace syncer 363 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/notifier/p2p_invalidator.cc ('k') | sync/tools/sync_listen_notifications.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698