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/mock_sync_notifier_observer.h" | 6 #include "sync/notifier/mock_sync_notifier_observer.h" |
7 #include "sync/notifier/sync_notifier_registrar.h" | 7 #include "sync/notifier/sync_notifier_registrar.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
9 | 9 |
10 namespace syncer { | 10 namespace syncer { |
(...skipping 22 matching lines...) Expand all Loading... |
33 // Register a handler, register some IDs for that handler, and then unregister | 33 // Register a handler, register some IDs for that handler, and then unregister |
34 // the handler, dispatching invalidations in between. The handler should only | 34 // the handler, dispatching invalidations in between. The handler should only |
35 // see invalidations when its registered and its IDs are registered. | 35 // see invalidations when its registered and its IDs are registered. |
36 TEST_F(SyncNotifierRegistrarTest, Basic) { | 36 TEST_F(SyncNotifierRegistrarTest, Basic) { |
37 StrictMock<MockSyncNotifierObserver> handler; | 37 StrictMock<MockSyncNotifierObserver> handler; |
38 | 38 |
39 SyncNotifierRegistrar registrar; | 39 SyncNotifierRegistrar registrar; |
40 | 40 |
41 registrar.RegisterHandler(&handler); | 41 registrar.RegisterHandler(&handler); |
42 | 42 |
43 ObjectIdPayloadMap payloads; | 43 ObjectIdStateMap states; |
44 payloads[kObjectId1] = "1"; | 44 states[kObjectId1].payload = "1"; |
45 payloads[kObjectId2] = "2"; | 45 states[kObjectId2].payload = "2"; |
46 payloads[kObjectId3] = "3"; | 46 states[kObjectId3].payload = "3"; |
47 | 47 |
48 // Should be ignored since no IDs are registered to |handler|. | 48 // Should be ignored since no IDs are registered to |handler|. |
49 registrar.DispatchInvalidationsToHandlers(payloads, REMOTE_NOTIFICATION); | 49 registrar.DispatchInvalidationsToHandlers(states, REMOTE_NOTIFICATION); |
50 | 50 |
51 Mock::VerifyAndClearExpectations(&handler); | 51 Mock::VerifyAndClearExpectations(&handler); |
52 | 52 |
53 ObjectIdSet ids; | 53 ObjectIdSet ids; |
54 ids.insert(kObjectId1); | 54 ids.insert(kObjectId1); |
55 ids.insert(kObjectId2); | 55 ids.insert(kObjectId2); |
56 registrar.UpdateRegisteredIds(&handler, ids); | 56 registrar.UpdateRegisteredIds(&handler, ids); |
57 | 57 |
58 { | 58 { |
59 ObjectIdPayloadMap expected_payloads; | 59 ObjectIdStateMap expected_states; |
60 expected_payloads[kObjectId1] = "1"; | 60 expected_states[kObjectId1].payload = "1"; |
61 expected_payloads[kObjectId2] = "2"; | 61 expected_states[kObjectId2].payload = "2"; |
62 EXPECT_CALL(handler, OnIncomingNotification(expected_payloads, | 62 EXPECT_CALL(handler, OnIncomingNotification(expected_states, |
63 REMOTE_NOTIFICATION)); | 63 REMOTE_NOTIFICATION)); |
64 } | 64 } |
65 | 65 |
66 registrar.DispatchInvalidationsToHandlers(payloads, REMOTE_NOTIFICATION); | 66 registrar.DispatchInvalidationsToHandlers(states, REMOTE_NOTIFICATION); |
67 | 67 |
68 Mock::VerifyAndClearExpectations(&handler); | 68 Mock::VerifyAndClearExpectations(&handler); |
69 | 69 |
70 ids.erase(kObjectId1); | 70 ids.erase(kObjectId1); |
71 ids.insert(kObjectId3); | 71 ids.insert(kObjectId3); |
72 registrar.UpdateRegisteredIds(&handler, ids); | 72 registrar.UpdateRegisteredIds(&handler, ids); |
73 | 73 |
74 { | 74 { |
75 ObjectIdPayloadMap expected_payloads; | 75 ObjectIdStateMap expected_states; |
76 expected_payloads[kObjectId2] = "2"; | 76 expected_states[kObjectId2].payload = "2"; |
77 expected_payloads[kObjectId3] = "3"; | 77 expected_states[kObjectId3].payload = "3"; |
78 EXPECT_CALL(handler, OnIncomingNotification(expected_payloads, | 78 EXPECT_CALL(handler, OnIncomingNotification(expected_states, |
79 REMOTE_NOTIFICATION)); | 79 REMOTE_NOTIFICATION)); |
80 } | 80 } |
81 | 81 |
82 // Removed object IDs should not be notified, newly-added ones should. | 82 // Removed object IDs should not be notified, newly-added ones should. |
83 registrar.DispatchInvalidationsToHandlers(payloads, REMOTE_NOTIFICATION); | 83 registrar.DispatchInvalidationsToHandlers(states, REMOTE_NOTIFICATION); |
84 | 84 |
85 Mock::VerifyAndClearExpectations(&handler); | 85 Mock::VerifyAndClearExpectations(&handler); |
86 | 86 |
87 registrar.UnregisterHandler(&handler); | 87 registrar.UnregisterHandler(&handler); |
88 | 88 |
89 // Should be ignored since |handler| isn't registered anymore. | 89 // Should be ignored since |handler| isn't registered anymore. |
90 registrar.DispatchInvalidationsToHandlers(payloads, REMOTE_NOTIFICATION); | 90 registrar.DispatchInvalidationsToHandlers(states, REMOTE_NOTIFICATION); |
91 } | 91 } |
92 | 92 |
93 // Register handlers and some IDs for those handlers, register a handler with | 93 // Register handlers and some IDs for those handlers, register a handler with |
94 // no IDs, and register a handler with some IDs but unregister it. Then, | 94 // no IDs, and register a handler with some IDs but unregister it. Then, |
95 // dispatch some notifications and invalidations. Handlers that are registered | 95 // dispatch some notifications and invalidations. Handlers that are registered |
96 // should get notifications, and the ones that have registered IDs should | 96 // should get notifications, and the ones that have registered IDs should |
97 // receive invalidations for those IDs. | 97 // receive invalidations for those IDs. |
98 TEST_F(SyncNotifierRegistrarTest, MultipleHandlers) { | 98 TEST_F(SyncNotifierRegistrarTest, MultipleHandlers) { |
99 StrictMock<MockSyncNotifierObserver> handler1; | 99 StrictMock<MockSyncNotifierObserver> handler1; |
100 EXPECT_CALL(handler1, OnNotificationsEnabled()); | 100 EXPECT_CALL(handler1, OnNotificationsEnabled()); |
101 { | 101 { |
102 ObjectIdPayloadMap expected_payloads; | 102 ObjectIdStateMap expected_states; |
103 expected_payloads[kObjectId1] = "1"; | 103 expected_states[kObjectId1].payload = "1"; |
104 expected_payloads[kObjectId2] = "2"; | 104 expected_states[kObjectId2].payload = "2"; |
105 EXPECT_CALL(handler1, OnIncomingNotification(expected_payloads, | 105 EXPECT_CALL(handler1, OnIncomingNotification(expected_states, |
106 REMOTE_NOTIFICATION)); | 106 REMOTE_NOTIFICATION)); |
107 } | 107 } |
108 EXPECT_CALL(handler1, | 108 EXPECT_CALL(handler1, |
109 OnNotificationsDisabled(TRANSIENT_NOTIFICATION_ERROR)); | 109 OnNotificationsDisabled(TRANSIENT_NOTIFICATION_ERROR)); |
110 | 110 |
111 StrictMock<MockSyncNotifierObserver> handler2; | 111 StrictMock<MockSyncNotifierObserver> handler2; |
112 EXPECT_CALL(handler2, OnNotificationsEnabled()); | 112 EXPECT_CALL(handler2, OnNotificationsEnabled()); |
113 { | 113 { |
114 ObjectIdPayloadMap expected_payloads; | 114 ObjectIdStateMap expected_states; |
115 expected_payloads[kObjectId3] = "3"; | 115 expected_states[kObjectId3].payload = "3"; |
116 EXPECT_CALL(handler2, OnIncomingNotification(expected_payloads, | 116 EXPECT_CALL(handler2, OnIncomingNotification(expected_states, |
117 REMOTE_NOTIFICATION)); | 117 REMOTE_NOTIFICATION)); |
118 } | 118 } |
119 EXPECT_CALL(handler2, | 119 EXPECT_CALL(handler2, |
120 OnNotificationsDisabled(TRANSIENT_NOTIFICATION_ERROR)); | 120 OnNotificationsDisabled(TRANSIENT_NOTIFICATION_ERROR)); |
121 | 121 |
122 StrictMock<MockSyncNotifierObserver> handler3; | 122 StrictMock<MockSyncNotifierObserver> handler3; |
123 EXPECT_CALL(handler3, OnNotificationsEnabled()); | 123 EXPECT_CALL(handler3, OnNotificationsEnabled()); |
124 EXPECT_CALL(handler3, | 124 EXPECT_CALL(handler3, |
125 OnNotificationsDisabled(TRANSIENT_NOTIFICATION_ERROR)); | 125 OnNotificationsDisabled(TRANSIENT_NOTIFICATION_ERROR)); |
126 | 126 |
(...skipping 24 matching lines...) Expand all Loading... |
151 { | 151 { |
152 ObjectIdSet ids; | 152 ObjectIdSet ids; |
153 ids.insert(kObjectId4); | 153 ids.insert(kObjectId4); |
154 registrar.UpdateRegisteredIds(&handler4, ids); | 154 registrar.UpdateRegisteredIds(&handler4, ids); |
155 } | 155 } |
156 | 156 |
157 registrar.UnregisterHandler(&handler4); | 157 registrar.UnregisterHandler(&handler4); |
158 | 158 |
159 registrar.EmitOnNotificationsEnabled(); | 159 registrar.EmitOnNotificationsEnabled(); |
160 { | 160 { |
161 ObjectIdPayloadMap payloads; | 161 ObjectIdStateMap states; |
162 payloads[kObjectId1] = "1"; | 162 states[kObjectId1].payload = "1"; |
163 payloads[kObjectId2] = "2"; | 163 states[kObjectId2].payload = "2"; |
164 payloads[kObjectId3] = "3"; | 164 states[kObjectId3].payload = "3"; |
165 payloads[kObjectId4] = "4"; | 165 states[kObjectId4].payload = "4"; |
166 registrar.DispatchInvalidationsToHandlers(payloads, REMOTE_NOTIFICATION); | 166 registrar.DispatchInvalidationsToHandlers(states, REMOTE_NOTIFICATION); |
167 } | 167 } |
168 registrar.EmitOnNotificationsDisabled(TRANSIENT_NOTIFICATION_ERROR); | 168 registrar.EmitOnNotificationsDisabled(TRANSIENT_NOTIFICATION_ERROR); |
169 } | 169 } |
170 | 170 |
171 // Multiple registrations by different handlers on the same object ID should | 171 // Multiple registrations by different handlers on the same object ID should |
172 // cause a CHECK. | 172 // cause a CHECK. |
173 TEST_F(SyncNotifierRegistrarTest, MultipleRegistration) { | 173 TEST_F(SyncNotifierRegistrarTest, MultipleRegistration) { |
174 SyncNotifierRegistrar registrar; | 174 SyncNotifierRegistrar registrar; |
175 | 175 |
176 StrictMock<MockSyncNotifierObserver> handler1; | 176 StrictMock<MockSyncNotifierObserver> handler1; |
(...skipping 17 matching lines...) Expand all Loading... |
194 TEST_F(SyncNotifierRegistrarTest, EmptySetUnregisters) { | 194 TEST_F(SyncNotifierRegistrarTest, EmptySetUnregisters) { |
195 StrictMock<MockSyncNotifierObserver> handler1; | 195 StrictMock<MockSyncNotifierObserver> handler1; |
196 EXPECT_CALL(handler1, OnNotificationsEnabled()); | 196 EXPECT_CALL(handler1, OnNotificationsEnabled()); |
197 EXPECT_CALL(handler1, | 197 EXPECT_CALL(handler1, |
198 OnNotificationsDisabled(TRANSIENT_NOTIFICATION_ERROR)); | 198 OnNotificationsDisabled(TRANSIENT_NOTIFICATION_ERROR)); |
199 | 199 |
200 // Control observer. | 200 // Control observer. |
201 StrictMock<MockSyncNotifierObserver> handler2; | 201 StrictMock<MockSyncNotifierObserver> handler2; |
202 EXPECT_CALL(handler2, OnNotificationsEnabled()); | 202 EXPECT_CALL(handler2, OnNotificationsEnabled()); |
203 { | 203 { |
204 ObjectIdPayloadMap expected_payloads; | 204 ObjectIdStateMap expected_states; |
205 expected_payloads[kObjectId3] = "3"; | 205 expected_states[kObjectId3].payload = "3"; |
206 EXPECT_CALL(handler2, OnIncomingNotification(expected_payloads, | 206 EXPECT_CALL(handler2, OnIncomingNotification(expected_states, |
207 REMOTE_NOTIFICATION)); | 207 REMOTE_NOTIFICATION)); |
208 } | 208 } |
209 EXPECT_CALL(handler2, | 209 EXPECT_CALL(handler2, |
210 OnNotificationsDisabled(TRANSIENT_NOTIFICATION_ERROR)); | 210 OnNotificationsDisabled(TRANSIENT_NOTIFICATION_ERROR)); |
211 | 211 |
212 SyncNotifierRegistrar registrar; | 212 SyncNotifierRegistrar registrar; |
213 | 213 |
214 registrar.RegisterHandler(&handler1); | 214 registrar.RegisterHandler(&handler1); |
215 registrar.RegisterHandler(&handler2); | 215 registrar.RegisterHandler(&handler2); |
216 | 216 |
217 { | 217 { |
218 ObjectIdSet ids; | 218 ObjectIdSet ids; |
219 ids.insert(kObjectId1); | 219 ids.insert(kObjectId1); |
220 ids.insert(kObjectId2); | 220 ids.insert(kObjectId2); |
221 registrar.UpdateRegisteredIds(&handler1, ids); | 221 registrar.UpdateRegisteredIds(&handler1, ids); |
222 } | 222 } |
223 | 223 |
224 { | 224 { |
225 ObjectIdSet ids; | 225 ObjectIdSet ids; |
226 ids.insert(kObjectId3); | 226 ids.insert(kObjectId3); |
227 registrar.UpdateRegisteredIds(&handler2, ids); | 227 registrar.UpdateRegisteredIds(&handler2, ids); |
228 } | 228 } |
229 | 229 |
230 // Unregister the IDs for the first observer. It should not receive any | 230 // Unregister the IDs for the first observer. It should not receive any |
231 // further invalidations. | 231 // further invalidations. |
232 registrar.UpdateRegisteredIds(&handler1, ObjectIdSet()); | 232 registrar.UpdateRegisteredIds(&handler1, ObjectIdSet()); |
233 | 233 |
234 registrar.EmitOnNotificationsEnabled(); | 234 registrar.EmitOnNotificationsEnabled(); |
235 { | 235 { |
236 ObjectIdPayloadMap payloads; | 236 ObjectIdStateMap states; |
237 payloads[kObjectId1] = "1"; | 237 states[kObjectId1].payload = "1"; |
238 payloads[kObjectId2] = "2"; | 238 states[kObjectId2].payload = "2"; |
239 payloads[kObjectId3] = "3"; | 239 states[kObjectId3].payload = "3"; |
240 registrar.DispatchInvalidationsToHandlers(payloads, | 240 registrar.DispatchInvalidationsToHandlers(states, |
241 REMOTE_NOTIFICATION); | 241 REMOTE_NOTIFICATION); |
242 } | 242 } |
243 registrar.EmitOnNotificationsDisabled(TRANSIENT_NOTIFICATION_ERROR); | 243 registrar.EmitOnNotificationsDisabled(TRANSIENT_NOTIFICATION_ERROR); |
244 } | 244 } |
245 | 245 |
246 } // namespace | 246 } // namespace |
247 | 247 |
248 } // namespace syncer | 248 } // namespace syncer |
OLD | NEW |