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_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" |
11 #include "sync/internal_api/public/base/model_type_invalidation_map.h" | |
12 #include "sync/notifier/fake_invalidation_handler.h" | 11 #include "sync/notifier/fake_invalidation_handler.h" |
13 #include "sync/notifier/invalidator_test_template.h" | 12 #include "sync/notifier/invalidator_test_template.h" |
14 #include "sync/notifier/object_id_invalidation_map_test_util.h" | 13 #include "sync/notifier/object_id_invalidation_map_test_util.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
16 | 15 |
17 namespace syncer { | 16 namespace syncer { |
18 | 17 |
19 namespace { | 18 namespace { |
20 | 19 |
21 class P2PInvalidatorTestDelegate { | 20 class P2PInvalidatorTestDelegate { |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 delegate_.CreateInvalidator("sender", | 88 delegate_.CreateInvalidator("sender", |
90 "fake_state", | 89 "fake_state", |
91 base::WeakPtr<InvalidationStateTracker>()); | 90 base::WeakPtr<InvalidationStateTracker>()); |
92 delegate_.GetInvalidator()->RegisterHandler(&fake_handler_); | 91 delegate_.GetInvalidator()->RegisterHandler(&fake_handler_); |
93 } | 92 } |
94 | 93 |
95 virtual ~P2PInvalidatorTest() { | 94 virtual ~P2PInvalidatorTest() { |
96 delegate_.GetInvalidator()->UnregisterHandler(&fake_handler_); | 95 delegate_.GetInvalidator()->UnregisterHandler(&fake_handler_); |
97 } | 96 } |
98 | 97 |
99 ModelTypeInvalidationMap MakeInvalidationMap(ModelTypeSet types) { | 98 ObjectIdInvalidationMap MakeInvalidationMap(ModelTypeSet types) { |
100 return ModelTypeSetToInvalidationMap(types, std::string()); | 99 ObjectIdInvalidationMap invalidations; |
| 100 ObjectIdSet ids = ModelTypeSetToObjectIdSet(types); |
| 101 return ObjectIdSetToInvalidationMap(ids, |
| 102 Invalidation::kUnknownVersion, |
| 103 std::string()); |
101 } | 104 } |
102 | 105 |
103 // Simulate receiving all the notifications we sent out since last | 106 // Simulate receiving all the notifications we sent out since last |
104 // time this was called. | 107 // time this was called. |
105 void ReflectSentNotifications() { | 108 void ReflectSentNotifications() { |
106 const std::vector<notifier::Notification>& sent_notifications = | 109 const std::vector<notifier::Notification>& sent_notifications = |
107 delegate_.GetPushClient()->sent_notifications(); | 110 delegate_.GetPushClient()->sent_notifications(); |
108 for(size_t i = next_sent_notification_to_reflect_; | 111 for(size_t i = next_sent_notification_to_reflect_; |
109 i < sent_notifications.size(); ++i) { | 112 i < sent_notifications.size(); ++i) { |
110 delegate_.GetInvalidator()->OnIncomingNotification(sent_notifications[i]); | 113 delegate_.GetInvalidator()->OnIncomingNotification(sent_notifications[i]); |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 EXPECT_EQ(kEmail, push_client->email()); | 236 EXPECT_EQ(kEmail, push_client->email()); |
234 EXPECT_EQ(kToken, push_client->token()); | 237 EXPECT_EQ(kToken, push_client->token()); |
235 | 238 |
236 ReflectSentNotifications(); | 239 ReflectSentNotifications(); |
237 push_client->EnableNotifications(); | 240 push_client->EnableNotifications(); |
238 EXPECT_EQ(INVALIDATIONS_ENABLED, fake_handler_.GetInvalidatorState()); | 241 EXPECT_EQ(INVALIDATIONS_ENABLED, fake_handler_.GetInvalidatorState()); |
239 | 242 |
240 ReflectSentNotifications(); | 243 ReflectSentNotifications(); |
241 EXPECT_EQ(1, fake_handler_.GetInvalidationCount()); | 244 EXPECT_EQ(1, fake_handler_.GetInvalidationCount()); |
242 EXPECT_THAT( | 245 EXPECT_THAT( |
243 ModelTypeInvalidationMapToObjectIdInvalidationMap( | 246 MakeInvalidationMap(enabled_types), |
244 MakeInvalidationMap(enabled_types)), | |
245 Eq(fake_handler_.GetLastInvalidationMap())); | 247 Eq(fake_handler_.GetLastInvalidationMap())); |
246 | 248 |
247 // Sent with target NOTIFY_OTHERS so should not be propagated to | 249 // Sent with target NOTIFY_OTHERS so should not be propagated to |
248 // |fake_handler_|. | 250 // |fake_handler_|. |
249 { | 251 { |
250 const ObjectIdInvalidationMap& invalidation_map = | 252 const ObjectIdInvalidationMap& invalidation_map = |
251 ObjectIdSetToInvalidationMap( | 253 ObjectIdSetToInvalidationMap( |
252 ModelTypeSetToObjectIdSet(ModelTypeSet(THEMES, APPS)), | 254 ModelTypeSetToObjectIdSet(ModelTypeSet(THEMES, APPS)), |
253 Invalidation::kUnknownVersion, | 255 Invalidation::kUnknownVersion, |
254 std::string()); | 256 std::string()); |
(...skipping 24 matching lines...) Expand all Loading... |
279 ModelTypeSetToObjectIdSet(enabled_types)); | 281 ModelTypeSetToObjectIdSet(enabled_types)); |
280 | 282 |
281 invalidator->UpdateCredentials("foo@bar.com", "fake_token"); | 283 invalidator->UpdateCredentials("foo@bar.com", "fake_token"); |
282 | 284 |
283 ReflectSentNotifications(); | 285 ReflectSentNotifications(); |
284 push_client->EnableNotifications(); | 286 push_client->EnableNotifications(); |
285 EXPECT_EQ(INVALIDATIONS_ENABLED, fake_handler_.GetInvalidatorState()); | 287 EXPECT_EQ(INVALIDATIONS_ENABLED, fake_handler_.GetInvalidatorState()); |
286 | 288 |
287 ReflectSentNotifications(); | 289 ReflectSentNotifications(); |
288 EXPECT_EQ(1, fake_handler_.GetInvalidationCount()); | 290 EXPECT_EQ(1, fake_handler_.GetInvalidationCount()); |
289 EXPECT_THAT( | 291 EXPECT_THAT(MakeInvalidationMap(enabled_types), |
290 ModelTypeInvalidationMapToObjectIdInvalidationMap( | 292 Eq(fake_handler_.GetLastInvalidationMap())); |
291 MakeInvalidationMap(enabled_types)), | |
292 Eq(fake_handler_.GetLastInvalidationMap())); | |
293 | 293 |
294 // Should be dropped. | 294 // Should be dropped. |
295 invalidator->SendNotificationDataForTest(P2PNotificationData()); | 295 invalidator->SendNotificationDataForTest(P2PNotificationData()); |
296 ReflectSentNotifications(); | 296 ReflectSentNotifications(); |
297 EXPECT_EQ(1, fake_handler_.GetInvalidationCount()); | 297 EXPECT_EQ(1, fake_handler_.GetInvalidationCount()); |
298 | 298 |
299 const ObjectIdInvalidationMap& expected_ids = | 299 const ObjectIdInvalidationMap& expected_ids = |
300 ModelTypeInvalidationMapToObjectIdInvalidationMap( | 300 MakeInvalidationMap(expected_types); |
301 MakeInvalidationMap(expected_types)); | |
302 | 301 |
303 // Should be propagated. | 302 // Should be propagated. |
304 invalidator->SendNotificationDataForTest( | 303 invalidator->SendNotificationDataForTest( |
305 P2PNotificationData("sender", NOTIFY_SELF, invalidation_map)); | 304 P2PNotificationData("sender", NOTIFY_SELF, invalidation_map)); |
306 ReflectSentNotifications(); | 305 ReflectSentNotifications(); |
307 EXPECT_EQ(2, fake_handler_.GetInvalidationCount()); | 306 EXPECT_EQ(2, fake_handler_.GetInvalidationCount()); |
308 EXPECT_THAT(expected_ids, Eq(fake_handler_.GetLastInvalidationMap())); | 307 EXPECT_THAT(expected_ids, Eq(fake_handler_.GetLastInvalidationMap())); |
309 | 308 |
310 // Should be dropped. | 309 // Should be dropped. |
311 invalidator->SendNotificationDataForTest( | 310 invalidator->SendNotificationDataForTest( |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
359 EXPECT_EQ(5, fake_handler_.GetInvalidationCount()); | 358 EXPECT_EQ(5, fake_handler_.GetInvalidationCount()); |
360 } | 359 } |
361 | 360 |
362 INSTANTIATE_TYPED_TEST_CASE_P( | 361 INSTANTIATE_TYPED_TEST_CASE_P( |
363 P2PInvalidatorTest, InvalidatorTest, | 362 P2PInvalidatorTest, InvalidatorTest, |
364 P2PInvalidatorTestDelegate); | 363 P2PInvalidatorTestDelegate); |
365 | 364 |
366 } // namespace | 365 } // namespace |
367 | 366 |
368 } // namespace syncer | 367 } // namespace syncer |
OLD | NEW |