| 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 "google/cacheinvalidation/types.pb.h" | 5 #include "google/cacheinvalidation/types.pb.h" |
| 6 #include "sync/notifier/fake_sync_notifier_observer.h" | 6 #include "sync/notifier/fake_invalidation_handler.h" |
| 7 #include "sync/notifier/invalidator_registrar.h" |
| 7 #include "sync/notifier/object_id_state_map_test_util.h" | 8 #include "sync/notifier/object_id_state_map_test_util.h" |
| 8 #include "sync/notifier/sync_notifier_registrar.h" | |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 | 10 |
| 11 namespace syncer { | 11 namespace syncer { |
| 12 | 12 |
| 13 namespace { | 13 namespace { |
| 14 | 14 |
| 15 class SyncNotifierRegistrarTest : public testing::Test { | 15 class InvalidatorRegistrarTest : public testing::Test { |
| 16 protected: | 16 protected: |
| 17 SyncNotifierRegistrarTest() | 17 InvalidatorRegistrarTest() |
| 18 : kObjectId1(ipc::invalidation::ObjectSource::TEST, "a"), | 18 : kObjectId1(ipc::invalidation::ObjectSource::TEST, "a"), |
| 19 kObjectId2(ipc::invalidation::ObjectSource::TEST, "b"), | 19 kObjectId2(ipc::invalidation::ObjectSource::TEST, "b"), |
| 20 kObjectId3(ipc::invalidation::ObjectSource::TEST, "c"), | 20 kObjectId3(ipc::invalidation::ObjectSource::TEST, "c"), |
| 21 kObjectId4(ipc::invalidation::ObjectSource::TEST, "d") { | 21 kObjectId4(ipc::invalidation::ObjectSource::TEST, "d") { |
| 22 } | 22 } |
| 23 | 23 |
| 24 const invalidation::ObjectId kObjectId1; | 24 const invalidation::ObjectId kObjectId1; |
| 25 const invalidation::ObjectId kObjectId2; | 25 const invalidation::ObjectId kObjectId2; |
| 26 const invalidation::ObjectId kObjectId3; | 26 const invalidation::ObjectId kObjectId3; |
| 27 const invalidation::ObjectId kObjectId4; | 27 const invalidation::ObjectId kObjectId4; |
| 28 }; | 28 }; |
| 29 | 29 |
| 30 // Register a handler, register some IDs for that handler, and then unregister | 30 // Register a handler, register some IDs for that handler, and then unregister |
| 31 // the handler, dispatching invalidations in between. The handler should only | 31 // the handler, dispatching invalidations in between. The handler should only |
| 32 // see invalidations when its registered and its IDs are registered. | 32 // see invalidations when its registered and its IDs are registered. |
| 33 TEST_F(SyncNotifierRegistrarTest, Basic) { | 33 TEST_F(InvalidatorRegistrarTest, Basic) { |
| 34 FakeSyncNotifierObserver handler; | 34 FakeInvalidationHandler handler; |
| 35 | 35 |
| 36 SyncNotifierRegistrar registrar; | 36 InvalidatorRegistrar registrar; |
| 37 | 37 |
| 38 registrar.RegisterHandler(&handler); | 38 registrar.RegisterHandler(&handler); |
| 39 | 39 |
| 40 ObjectIdStateMap states; | 40 ObjectIdStateMap states; |
| 41 states[kObjectId1].payload = "1"; | 41 states[kObjectId1].payload = "1"; |
| 42 states[kObjectId2].payload = "2"; | 42 states[kObjectId2].payload = "2"; |
| 43 states[kObjectId3].payload = "3"; | 43 states[kObjectId3].payload = "3"; |
| 44 | 44 |
| 45 // Should be ignored since no IDs are registered to |handler|. | 45 // Should be ignored since no IDs are registered to |handler|. |
| 46 registrar.DispatchInvalidationsToHandlers(states, REMOTE_NOTIFICATION); | 46 registrar.DispatchInvalidationsToHandlers(states, REMOTE_NOTIFICATION); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 // Should be ignored since |handler| isn't registered anymore. | 82 // Should be ignored since |handler| isn't registered anymore. |
| 83 registrar.DispatchInvalidationsToHandlers(states, REMOTE_NOTIFICATION); | 83 registrar.DispatchInvalidationsToHandlers(states, REMOTE_NOTIFICATION); |
| 84 EXPECT_EQ(2, handler.GetNotificationCount()); | 84 EXPECT_EQ(2, handler.GetNotificationCount()); |
| 85 } | 85 } |
| 86 | 86 |
| 87 // Register handlers and some IDs for those handlers, register a handler with | 87 // Register handlers and some IDs for those handlers, register a handler with |
| 88 // no IDs, and register a handler with some IDs but unregister it. Then, | 88 // no IDs, and register a handler with some IDs but unregister it. Then, |
| 89 // dispatch some notifications and invalidations. Handlers that are registered | 89 // dispatch some notifications and invalidations. Handlers that are registered |
| 90 // should get notifications, and the ones that have registered IDs should | 90 // should get notifications, and the ones that have registered IDs should |
| 91 // receive invalidations for those IDs. | 91 // receive invalidations for those IDs. |
| 92 TEST_F(SyncNotifierRegistrarTest, MultipleHandlers) { | 92 TEST_F(InvalidatorRegistrarTest, MultipleHandlers) { |
| 93 FakeSyncNotifierObserver handler1; | 93 FakeInvalidationHandler handler1; |
| 94 FakeSyncNotifierObserver handler2; | 94 FakeInvalidationHandler handler2; |
| 95 FakeSyncNotifierObserver handler3; | 95 FakeInvalidationHandler handler3; |
| 96 FakeSyncNotifierObserver handler4; | 96 FakeInvalidationHandler handler4; |
| 97 | 97 |
| 98 SyncNotifierRegistrar registrar; | 98 InvalidatorRegistrar registrar; |
| 99 | 99 |
| 100 registrar.RegisterHandler(&handler1); | 100 registrar.RegisterHandler(&handler1); |
| 101 registrar.RegisterHandler(&handler2); | 101 registrar.RegisterHandler(&handler2); |
| 102 registrar.RegisterHandler(&handler3); | 102 registrar.RegisterHandler(&handler3); |
| 103 registrar.RegisterHandler(&handler4); | 103 registrar.RegisterHandler(&handler4); |
| 104 | 104 |
| 105 { | 105 { |
| 106 ObjectIdSet ids; | 106 ObjectIdSet ids; |
| 107 ids.insert(kObjectId1); | 107 ids.insert(kObjectId1); |
| 108 ids.insert(kObjectId2); | 108 ids.insert(kObjectId2); |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 EXPECT_EQ(TRANSIENT_NOTIFICATION_ERROR, | 172 EXPECT_EQ(TRANSIENT_NOTIFICATION_ERROR, |
| 173 handler2.GetNotificationsDisabledReason()); | 173 handler2.GetNotificationsDisabledReason()); |
| 174 EXPECT_EQ(TRANSIENT_NOTIFICATION_ERROR, | 174 EXPECT_EQ(TRANSIENT_NOTIFICATION_ERROR, |
| 175 handler3.GetNotificationsDisabledReason()); | 175 handler3.GetNotificationsDisabledReason()); |
| 176 EXPECT_EQ(TRANSIENT_NOTIFICATION_ERROR, | 176 EXPECT_EQ(TRANSIENT_NOTIFICATION_ERROR, |
| 177 handler4.GetNotificationsDisabledReason()); | 177 handler4.GetNotificationsDisabledReason()); |
| 178 } | 178 } |
| 179 | 179 |
| 180 // Multiple registrations by different handlers on the same object ID should | 180 // Multiple registrations by different handlers on the same object ID should |
| 181 // cause a CHECK. | 181 // cause a CHECK. |
| 182 TEST_F(SyncNotifierRegistrarTest, MultipleRegistration) { | 182 TEST_F(InvalidatorRegistrarTest, MultipleRegistration) { |
| 183 SyncNotifierRegistrar registrar; | 183 InvalidatorRegistrar registrar; |
| 184 | 184 |
| 185 FakeSyncNotifierObserver handler1; | 185 FakeInvalidationHandler handler1; |
| 186 registrar.RegisterHandler(&handler1); | 186 registrar.RegisterHandler(&handler1); |
| 187 | 187 |
| 188 FakeSyncNotifierObserver handler2; | 188 FakeInvalidationHandler handler2; |
| 189 registrar.RegisterHandler(&handler2); | 189 registrar.RegisterHandler(&handler2); |
| 190 | 190 |
| 191 ObjectIdSet ids; | 191 ObjectIdSet ids; |
| 192 ids.insert(kObjectId1); | 192 ids.insert(kObjectId1); |
| 193 ids.insert(kObjectId2); | 193 ids.insert(kObjectId2); |
| 194 registrar.UpdateRegisteredIds(&handler1, ids); | 194 registrar.UpdateRegisteredIds(&handler1, ids); |
| 195 | 195 |
| 196 registrar.DetachFromThreadForTest(); | 196 registrar.DetachFromThreadForTest(); |
| 197 // We expect a death via CHECK(). We can't match against the CHECK() message | 197 // We expect a death via CHECK(). We can't match against the CHECK() message |
| 198 // though since they are removed in official builds. | 198 // though since they are removed in official builds. |
| 199 EXPECT_DEATH({ registrar.UpdateRegisteredIds(&handler2, ids); }, ""); | 199 EXPECT_DEATH({ registrar.UpdateRegisteredIds(&handler2, ids); }, ""); |
| 200 } | 200 } |
| 201 | 201 |
| 202 // Make sure that passing an empty set to UpdateRegisteredIds clears the | 202 // Make sure that passing an empty set to UpdateRegisteredIds clears the |
| 203 // corresponding entries for the handler. | 203 // corresponding entries for the handler. |
| 204 TEST_F(SyncNotifierRegistrarTest, EmptySetUnregisters) { | 204 TEST_F(InvalidatorRegistrarTest, EmptySetUnregisters) { |
| 205 FakeSyncNotifierObserver handler1; | 205 FakeInvalidationHandler handler1; |
| 206 | 206 |
| 207 // Control observer. | 207 // Control observer. |
| 208 FakeSyncNotifierObserver handler2; | 208 FakeInvalidationHandler handler2; |
| 209 | 209 |
| 210 SyncNotifierRegistrar registrar; | 210 InvalidatorRegistrar registrar; |
| 211 | 211 |
| 212 registrar.RegisterHandler(&handler1); | 212 registrar.RegisterHandler(&handler1); |
| 213 registrar.RegisterHandler(&handler2); | 213 registrar.RegisterHandler(&handler2); |
| 214 | 214 |
| 215 { | 215 { |
| 216 ObjectIdSet ids; | 216 ObjectIdSet ids; |
| 217 ids.insert(kObjectId1); | 217 ids.insert(kObjectId1); |
| 218 ids.insert(kObjectId2); | 218 ids.insert(kObjectId2); |
| 219 registrar.UpdateRegisteredIds(&handler1, ids); | 219 registrar.UpdateRegisteredIds(&handler1, ids); |
| 220 } | 220 } |
| (...skipping 28 matching lines...) Expand all Loading... |
| 249 registrar.EmitOnNotificationsDisabled(TRANSIENT_NOTIFICATION_ERROR); | 249 registrar.EmitOnNotificationsDisabled(TRANSIENT_NOTIFICATION_ERROR); |
| 250 EXPECT_EQ(TRANSIENT_NOTIFICATION_ERROR, | 250 EXPECT_EQ(TRANSIENT_NOTIFICATION_ERROR, |
| 251 handler1.GetNotificationsDisabledReason()); | 251 handler1.GetNotificationsDisabledReason()); |
| 252 EXPECT_EQ(TRANSIENT_NOTIFICATION_ERROR, | 252 EXPECT_EQ(TRANSIENT_NOTIFICATION_ERROR, |
| 253 handler2.GetNotificationsDisabledReason()); | 253 handler2.GetNotificationsDisabledReason()); |
| 254 } | 254 } |
| 255 | 255 |
| 256 } // namespace | 256 } // namespace |
| 257 | 257 |
| 258 } // namespace syncer | 258 } // namespace syncer |
| OLD | NEW |