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 // This class defines tests that implementations of Invalidator should pass in | 5 // This class defines tests that implementations of Invalidator should pass in |
6 // order to be conformant. Here's how you use it to test your implementation. | 6 // order to be conformant. Here's how you use it to test your implementation. |
7 // | 7 // |
8 // Say your class is called MyInvalidator. Then you need to define a class | 8 // Say your class is called MyInvalidator. Then you need to define a class |
9 // called MyInvalidatorTestDelegate in my_sync_notifier_unittest.cc like this: | 9 // called MyInvalidatorTestDelegate in my_sync_notifier_unittest.cc like this: |
10 // | 10 // |
(...skipping 28 matching lines...) Expand all Loading... |
39 // // Called after a call to SetStateDeprecated(), SetUniqueId(), or | 39 // // Called after a call to SetStateDeprecated(), SetUniqueId(), or |
40 // // UpdateCredentials() on the Invalidator implementation. Should block | 40 // // UpdateCredentials() on the Invalidator implementation. Should block |
41 // // until the effects of the call are visible on the current thread. | 41 // // until the effects of the call are visible on the current thread. |
42 // void WaitForInvalidator() { | 42 // void WaitForInvalidator() { |
43 // ... | 43 // ... |
44 // } | 44 // } |
45 // | 45 // |
46 // // The Trigger* functions below should block until the effects of | 46 // // The Trigger* functions below should block until the effects of |
47 // // the call are visible on the current thread. | 47 // // the call are visible on the current thread. |
48 // | 48 // |
49 // // Should cause OnNotificationsEnabled() to be called on all | 49 // // Should cause OnInvalidatorStateChange() to be called on all |
50 // // observers of the Invalidator implementation. | 50 // // observers of the Invalidator implementation with the given |
51 // void TriggerOnNotificationsEnabled() { | 51 // // parameters. |
| 52 // void TriggerOnInvalidatorStateChange(InvalidatorState state) { |
52 // ... | 53 // ... |
53 // } | 54 // } |
54 // | 55 // |
55 // // Should cause OnIncomingNotification() to be called on all | 56 // // Should cause OnIncomingInvalidation() to be called on all |
56 // // observers of the Invalidator implementation with the given | 57 // // observers of the Invalidator implementation with the given |
57 // // parameters. | 58 // // parameters. |
58 // void TriggerOnIncomingNotification(const ObjectIdStateMap& id_state_map, | 59 // void TriggerOnIncomingInvalidation(const ObjectIdStateMap& id_state_map, |
59 // IncomingNotificationSource source) { | 60 // IncomingInvalidationSource source) { |
60 // ... | 61 // ... |
61 // } | 62 // } |
62 // | 63 // |
63 // // Should cause OnNotificationsDisabled() to be called on all | |
64 // // observers of the Invalidator implementation with the given | |
65 // // parameters. | |
66 // void TriggerOnNotificationsDisabled( | |
67 // NotificationsDisabledReason reason) { | |
68 // ... | |
69 // } | |
70 // | |
71 // // Returns whether or not the notifier handles storing the old | 64 // // Returns whether or not the notifier handles storing the old |
72 // // (deprecated) notifier state. | 65 // // (deprecated) notifier state. |
73 // static bool InvalidatorHandlesDeprecatedState() { | 66 // static bool InvalidatorHandlesDeprecatedState() { |
74 // return false; | 67 // return false; |
75 // } | 68 // } |
76 // }; | 69 // }; |
77 // | 70 // |
78 // The InvalidatorTest test harness will have a member variable of | 71 // The InvalidatorTest test harness will have a member variable of |
79 // this delegate type and will call its functions in the various | 72 // this delegate type and will call its functions in the various |
80 // tests. | 73 // tests. |
81 // | 74 // |
82 // Then you simply #include this file as well as gtest.h and add the | 75 // Then you simply #include this file as well as gtest.h and add the |
83 // following statement to my_sync_notifier_unittest.cc: | 76 // following statement to my_sync_notifier_unittest.cc: |
84 // | 77 // |
85 // INSTANTIATE_TYPED_TEST_CASE_P( | 78 // INSTANTIATE_TYPED_TEST_CASE_P( |
86 // MyInvalidator, InvalidatorTest, MyInvalidatorTestDelegate); | 79 // MyInvalidator, InvalidatorTest, MyInvalidatorTestDelegate); |
87 // | 80 // |
88 // Easy! | 81 // Easy! |
89 | 82 |
90 #ifndef SYNC_NOTIFIER_INVALIDATOR_TEST_TEMPLATE_H_ | 83 #ifndef SYNC_NOTIFIER_INVALIDATOR_TEST_TEMPLATE_H_ |
91 #define SYNC_NOTIFIER_INVALIDATOR_TEST_TEMPLATE_H_ | 84 #define SYNC_NOTIFIER_INVALIDATOR_TEST_TEMPLATE_H_ |
92 | 85 |
| 86 #include "base/basictypes.h" |
| 87 #include "base/compiler_specific.h" |
93 #include "google/cacheinvalidation/include/types.h" | 88 #include "google/cacheinvalidation/include/types.h" |
94 #include "google/cacheinvalidation/types.pb.h" | 89 #include "google/cacheinvalidation/types.pb.h" |
95 #include "sync/notifier/fake_invalidation_handler.h" | 90 #include "sync/notifier/fake_invalidation_handler.h" |
96 #include "sync/notifier/fake_invalidation_state_tracker.h" | 91 #include "sync/notifier/fake_invalidation_state_tracker.h" |
97 #include "sync/notifier/invalidator.h" | 92 #include "sync/notifier/invalidator.h" |
98 #include "sync/notifier/object_id_state_map.h" | 93 #include "sync/notifier/object_id_state_map.h" |
99 #include "sync/notifier/object_id_state_map_test_util.h" | 94 #include "sync/notifier/object_id_state_map_test_util.h" |
100 #include "testing/gtest/include/gtest/gtest.h" | 95 #include "testing/gtest/include/gtest/gtest.h" |
101 | 96 |
102 namespace syncer { | 97 namespace syncer { |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 FakeInvalidationHandler handler; | 147 FakeInvalidationHandler handler; |
153 | 148 |
154 invalidator->RegisterHandler(&handler); | 149 invalidator->RegisterHandler(&handler); |
155 | 150 |
156 ObjectIdStateMap states; | 151 ObjectIdStateMap states; |
157 states[this->id1].payload = "1"; | 152 states[this->id1].payload = "1"; |
158 states[this->id2].payload = "2"; | 153 states[this->id2].payload = "2"; |
159 states[this->id3].payload = "3"; | 154 states[this->id3].payload = "3"; |
160 | 155 |
161 // Should be ignored since no IDs are registered to |handler|. | 156 // Should be ignored since no IDs are registered to |handler|. |
162 this->delegate_.TriggerOnIncomingNotification(states, REMOTE_NOTIFICATION); | 157 this->delegate_.TriggerOnIncomingInvalidation(states, REMOTE_INVALIDATION); |
163 EXPECT_EQ(0, handler.GetNotificationCount()); | 158 EXPECT_EQ(0, handler.GetInvalidationCount()); |
164 | 159 |
165 ObjectIdSet ids; | 160 ObjectIdSet ids; |
166 ids.insert(this->id1); | 161 ids.insert(this->id1); |
167 ids.insert(this->id2); | 162 ids.insert(this->id2); |
168 invalidator->UpdateRegisteredIds(&handler, ids); | 163 invalidator->UpdateRegisteredIds(&handler, ids); |
169 | 164 |
170 this->delegate_.TriggerOnNotificationsEnabled(); | 165 this->delegate_.TriggerOnInvalidatorStateChange(INVALIDATIONS_ENABLED); |
171 EXPECT_EQ(NO_NOTIFICATION_ERROR, | 166 EXPECT_EQ(INVALIDATIONS_ENABLED, handler.GetInvalidatorState()); |
172 handler.GetNotificationsDisabledReason()); | |
173 | 167 |
174 ObjectIdStateMap expected_states; | 168 ObjectIdStateMap expected_states; |
175 expected_states[this->id1].payload = "1"; | 169 expected_states[this->id1].payload = "1"; |
176 expected_states[this->id2].payload = "2"; | 170 expected_states[this->id2].payload = "2"; |
177 | 171 |
178 this->delegate_.TriggerOnIncomingNotification(states, REMOTE_NOTIFICATION); | 172 this->delegate_.TriggerOnIncomingInvalidation(states, REMOTE_INVALIDATION); |
179 EXPECT_EQ(1, handler.GetNotificationCount()); | 173 EXPECT_EQ(1, handler.GetInvalidationCount()); |
180 EXPECT_THAT( | 174 EXPECT_THAT( |
181 expected_states, | 175 expected_states, |
182 Eq(handler.GetLastNotificationIdStateMap())); | 176 Eq(handler.GetLastInvalidationIdStateMap())); |
183 EXPECT_EQ(REMOTE_NOTIFICATION, handler.GetLastNotificationSource()); | 177 EXPECT_EQ(REMOTE_INVALIDATION, handler.GetLastInvalidationSource()); |
184 | 178 |
185 ids.erase(this->id1); | 179 ids.erase(this->id1); |
186 ids.insert(this->id3); | 180 ids.insert(this->id3); |
187 invalidator->UpdateRegisteredIds(&handler, ids); | 181 invalidator->UpdateRegisteredIds(&handler, ids); |
188 | 182 |
189 expected_states.erase(this->id1); | 183 expected_states.erase(this->id1); |
190 expected_states[this->id3].payload = "3"; | 184 expected_states[this->id3].payload = "3"; |
191 | 185 |
192 // Removed object IDs should not be notified, newly-added ones should. | 186 // Removed object IDs should not be notified, newly-added ones should. |
193 this->delegate_.TriggerOnIncomingNotification(states, REMOTE_NOTIFICATION); | 187 this->delegate_.TriggerOnIncomingInvalidation(states, REMOTE_INVALIDATION); |
194 EXPECT_EQ(2, handler.GetNotificationCount()); | 188 EXPECT_EQ(2, handler.GetInvalidationCount()); |
195 EXPECT_THAT( | 189 EXPECT_THAT( |
196 expected_states, | 190 expected_states, |
197 Eq(handler.GetLastNotificationIdStateMap())); | 191 Eq(handler.GetLastInvalidationIdStateMap())); |
198 EXPECT_EQ(REMOTE_NOTIFICATION, handler.GetLastNotificationSource()); | 192 EXPECT_EQ(REMOTE_INVALIDATION, handler.GetLastInvalidationSource()); |
199 | 193 |
200 this->delegate_.TriggerOnNotificationsDisabled(TRANSIENT_NOTIFICATION_ERROR); | 194 this->delegate_.TriggerOnInvalidatorStateChange(TRANSIENT_INVALIDATION_ERROR); |
201 EXPECT_EQ(TRANSIENT_NOTIFICATION_ERROR, | 195 EXPECT_EQ(TRANSIENT_INVALIDATION_ERROR, |
202 handler.GetNotificationsDisabledReason()); | 196 handler.GetInvalidatorState()); |
203 | 197 |
204 this->delegate_.TriggerOnNotificationsDisabled( | 198 this->delegate_.TriggerOnInvalidatorStateChange( |
205 NOTIFICATION_CREDENTIALS_REJECTED); | 199 INVALIDATION_CREDENTIALS_REJECTED); |
206 EXPECT_EQ(NOTIFICATION_CREDENTIALS_REJECTED, | 200 EXPECT_EQ(INVALIDATION_CREDENTIALS_REJECTED, |
207 handler.GetNotificationsDisabledReason()); | 201 handler.GetInvalidatorState()); |
208 | 202 |
209 invalidator->UnregisterHandler(&handler); | 203 invalidator->UnregisterHandler(&handler); |
210 | 204 |
211 // Should be ignored since |handler| isn't registered anymore. | 205 // Should be ignored since |handler| isn't registered anymore. |
212 this->delegate_.TriggerOnIncomingNotification(states, REMOTE_NOTIFICATION); | 206 this->delegate_.TriggerOnIncomingInvalidation(states, REMOTE_INVALIDATION); |
213 EXPECT_EQ(2, handler.GetNotificationCount()); | 207 EXPECT_EQ(2, handler.GetInvalidationCount()); |
214 } | 208 } |
215 | 209 |
216 // Register handlers and some IDs for those handlers, register a handler with | 210 // Register handlers and some IDs for those handlers, register a handler with |
217 // no IDs, and register a handler with some IDs but unregister it. Then, | 211 // no IDs, and register a handler with some IDs but unregister it. Then, |
218 // dispatch some notifications and invalidations. Handlers that are registered | 212 // dispatch some invalidations and invalidations. Handlers that are registered |
219 // should get notifications, and the ones that have registered IDs should | 213 // should get invalidations, and the ones that have registered IDs should |
220 // receive invalidations for those IDs. | 214 // receive invalidations for those IDs. |
221 TYPED_TEST_P(InvalidatorTest, MultipleHandlers) { | 215 TYPED_TEST_P(InvalidatorTest, MultipleHandlers) { |
222 Invalidator* const invalidator = this->CreateAndInitializeInvalidator(); | 216 Invalidator* const invalidator = this->CreateAndInitializeInvalidator(); |
223 | 217 |
224 FakeInvalidationHandler handler1; | 218 FakeInvalidationHandler handler1; |
225 FakeInvalidationHandler handler2; | 219 FakeInvalidationHandler handler2; |
226 FakeInvalidationHandler handler3; | 220 FakeInvalidationHandler handler3; |
227 FakeInvalidationHandler handler4; | 221 FakeInvalidationHandler handler4; |
228 | 222 |
229 invalidator->RegisterHandler(&handler1); | 223 invalidator->RegisterHandler(&handler1); |
(...skipping 17 matching lines...) Expand all Loading... |
247 // Don't register any IDs for handler3. | 241 // Don't register any IDs for handler3. |
248 | 242 |
249 { | 243 { |
250 ObjectIdSet ids; | 244 ObjectIdSet ids; |
251 ids.insert(this->id4); | 245 ids.insert(this->id4); |
252 invalidator->UpdateRegisteredIds(&handler4, ids); | 246 invalidator->UpdateRegisteredIds(&handler4, ids); |
253 } | 247 } |
254 | 248 |
255 invalidator->UnregisterHandler(&handler4); | 249 invalidator->UnregisterHandler(&handler4); |
256 | 250 |
257 this->delegate_.TriggerOnNotificationsEnabled(); | 251 this->delegate_.TriggerOnInvalidatorStateChange(INVALIDATIONS_ENABLED); |
258 EXPECT_EQ(NO_NOTIFICATION_ERROR, | 252 EXPECT_EQ(INVALIDATIONS_ENABLED, handler1.GetInvalidatorState()); |
259 handler1.GetNotificationsDisabledReason()); | 253 EXPECT_EQ(INVALIDATIONS_ENABLED, handler2.GetInvalidatorState()); |
260 EXPECT_EQ(NO_NOTIFICATION_ERROR, | 254 EXPECT_EQ(INVALIDATIONS_ENABLED, handler3.GetInvalidatorState()); |
261 handler2.GetNotificationsDisabledReason()); | 255 EXPECT_EQ(TRANSIENT_INVALIDATION_ERROR, handler4.GetInvalidatorState()); |
262 EXPECT_EQ(NO_NOTIFICATION_ERROR, | |
263 handler3.GetNotificationsDisabledReason()); | |
264 EXPECT_EQ(TRANSIENT_NOTIFICATION_ERROR, | |
265 handler4.GetNotificationsDisabledReason()); | |
266 | 256 |
267 { | 257 { |
268 ObjectIdStateMap states; | 258 ObjectIdStateMap states; |
269 states[this->id1].payload = "1"; | 259 states[this->id1].payload = "1"; |
270 states[this->id2].payload = "2"; | 260 states[this->id2].payload = "2"; |
271 states[this->id3].payload = "3"; | 261 states[this->id3].payload = "3"; |
272 states[this->id4].payload = "4"; | 262 states[this->id4].payload = "4"; |
273 this->delegate_.TriggerOnIncomingNotification(states, REMOTE_NOTIFICATION); | 263 this->delegate_.TriggerOnIncomingInvalidation(states, REMOTE_INVALIDATION); |
274 | 264 |
275 ObjectIdStateMap expected_states; | 265 ObjectIdStateMap expected_states; |
276 expected_states[this->id1].payload = "1"; | 266 expected_states[this->id1].payload = "1"; |
277 expected_states[this->id2].payload = "2"; | 267 expected_states[this->id2].payload = "2"; |
278 | 268 |
279 EXPECT_EQ(1, handler1.GetNotificationCount()); | 269 EXPECT_EQ(1, handler1.GetInvalidationCount()); |
280 EXPECT_THAT( | 270 EXPECT_THAT( |
281 expected_states, | 271 expected_states, |
282 Eq(handler1.GetLastNotificationIdStateMap())); | 272 Eq(handler1.GetLastInvalidationIdStateMap())); |
283 EXPECT_EQ(REMOTE_NOTIFICATION, handler1.GetLastNotificationSource()); | 273 EXPECT_EQ(REMOTE_INVALIDATION, handler1.GetLastInvalidationSource()); |
284 | 274 |
285 expected_states.clear(); | 275 expected_states.clear(); |
286 expected_states[this->id3].payload = "3"; | 276 expected_states[this->id3].payload = "3"; |
287 | 277 |
288 EXPECT_EQ(1, handler2.GetNotificationCount()); | 278 EXPECT_EQ(1, handler2.GetInvalidationCount()); |
289 EXPECT_THAT( | 279 EXPECT_THAT( |
290 expected_states, | 280 expected_states, |
291 Eq(handler2.GetLastNotificationIdStateMap())); | 281 Eq(handler2.GetLastInvalidationIdStateMap())); |
292 EXPECT_EQ(REMOTE_NOTIFICATION, handler2.GetLastNotificationSource()); | 282 EXPECT_EQ(REMOTE_INVALIDATION, handler2.GetLastInvalidationSource()); |
293 | 283 |
294 EXPECT_EQ(0, handler3.GetNotificationCount()); | 284 EXPECT_EQ(0, handler3.GetInvalidationCount()); |
295 EXPECT_EQ(0, handler4.GetNotificationCount()); | 285 EXPECT_EQ(0, handler4.GetInvalidationCount()); |
296 } | 286 } |
297 | 287 |
298 this->delegate_.TriggerOnNotificationsDisabled(TRANSIENT_NOTIFICATION_ERROR); | 288 this->delegate_.TriggerOnInvalidatorStateChange(TRANSIENT_INVALIDATION_ERROR); |
299 EXPECT_EQ(TRANSIENT_NOTIFICATION_ERROR, | 289 EXPECT_EQ(TRANSIENT_INVALIDATION_ERROR, handler1.GetInvalidatorState()); |
300 handler1.GetNotificationsDisabledReason()); | 290 EXPECT_EQ(TRANSIENT_INVALIDATION_ERROR, handler2.GetInvalidatorState()); |
301 EXPECT_EQ(TRANSIENT_NOTIFICATION_ERROR, | 291 EXPECT_EQ(TRANSIENT_INVALIDATION_ERROR, handler3.GetInvalidatorState()); |
302 handler2.GetNotificationsDisabledReason()); | 292 EXPECT_EQ(TRANSIENT_INVALIDATION_ERROR, handler4.GetInvalidatorState()); |
303 EXPECT_EQ(TRANSIENT_NOTIFICATION_ERROR, | |
304 handler3.GetNotificationsDisabledReason()); | |
305 EXPECT_EQ(TRANSIENT_NOTIFICATION_ERROR, | |
306 handler4.GetNotificationsDisabledReason()); | |
307 } | 293 } |
308 | 294 |
309 // Make sure that passing an empty set to UpdateRegisteredIds clears the | 295 // Make sure that passing an empty set to UpdateRegisteredIds clears the |
310 // corresponding entries for the handler. | 296 // corresponding entries for the handler. |
311 TYPED_TEST_P(InvalidatorTest, EmptySetUnregisters) { | 297 TYPED_TEST_P(InvalidatorTest, EmptySetUnregisters) { |
312 Invalidator* const invalidator = this->CreateAndInitializeInvalidator(); | 298 Invalidator* const invalidator = this->CreateAndInitializeInvalidator(); |
313 | 299 |
314 FakeInvalidationHandler handler1; | 300 FakeInvalidationHandler handler1; |
315 | 301 |
316 // Control observer. | 302 // Control observer. |
(...skipping 12 matching lines...) Expand all Loading... |
329 { | 315 { |
330 ObjectIdSet ids; | 316 ObjectIdSet ids; |
331 ids.insert(this->id3); | 317 ids.insert(this->id3); |
332 invalidator->UpdateRegisteredIds(&handler2, ids); | 318 invalidator->UpdateRegisteredIds(&handler2, ids); |
333 } | 319 } |
334 | 320 |
335 // Unregister the IDs for the first observer. It should not receive any | 321 // Unregister the IDs for the first observer. It should not receive any |
336 // further invalidations. | 322 // further invalidations. |
337 invalidator->UpdateRegisteredIds(&handler1, ObjectIdSet()); | 323 invalidator->UpdateRegisteredIds(&handler1, ObjectIdSet()); |
338 | 324 |
339 this->delegate_.TriggerOnNotificationsEnabled(); | 325 this->delegate_.TriggerOnInvalidatorStateChange(INVALIDATIONS_ENABLED); |
340 EXPECT_EQ(NO_NOTIFICATION_ERROR, | 326 EXPECT_EQ(INVALIDATIONS_ENABLED, handler1.GetInvalidatorState()); |
341 handler1.GetNotificationsDisabledReason()); | 327 EXPECT_EQ(INVALIDATIONS_ENABLED, handler2.GetInvalidatorState()); |
342 EXPECT_EQ(NO_NOTIFICATION_ERROR, | |
343 handler2.GetNotificationsDisabledReason()); | |
344 | 328 |
345 { | 329 { |
346 ObjectIdStateMap states; | 330 ObjectIdStateMap states; |
347 states[this->id1].payload = "1"; | 331 states[this->id1].payload = "1"; |
348 states[this->id2].payload = "2"; | 332 states[this->id2].payload = "2"; |
349 states[this->id3].payload = "3"; | 333 states[this->id3].payload = "3"; |
350 this->delegate_.TriggerOnIncomingNotification(states, REMOTE_NOTIFICATION); | 334 this->delegate_.TriggerOnIncomingInvalidation(states, REMOTE_INVALIDATION); |
351 EXPECT_EQ(0, handler1.GetNotificationCount()); | 335 EXPECT_EQ(0, handler1.GetInvalidationCount()); |
352 EXPECT_EQ(1, handler2.GetNotificationCount()); | 336 EXPECT_EQ(1, handler2.GetInvalidationCount()); |
353 } | 337 } |
354 | 338 |
355 this->delegate_.TriggerOnNotificationsDisabled(TRANSIENT_NOTIFICATION_ERROR); | 339 this->delegate_.TriggerOnInvalidatorStateChange(TRANSIENT_INVALIDATION_ERROR); |
356 EXPECT_EQ(TRANSIENT_NOTIFICATION_ERROR, | 340 EXPECT_EQ(TRANSIENT_INVALIDATION_ERROR, handler1.GetInvalidatorState()); |
357 handler1.GetNotificationsDisabledReason()); | 341 EXPECT_EQ(TRANSIENT_INVALIDATION_ERROR, handler2.GetInvalidatorState()); |
358 EXPECT_EQ(TRANSIENT_NOTIFICATION_ERROR, | 342 } |
359 handler2.GetNotificationsDisabledReason()); | 343 |
| 344 namespace internal { |
| 345 |
| 346 // A FakeInvalidationHandler that is "bound" to a specific |
| 347 // Invalidator. This is for cross-referencing state information with |
| 348 // the bound Invalidator. |
| 349 class BoundFakeInvalidationHandler : public FakeInvalidationHandler { |
| 350 public: |
| 351 explicit BoundFakeInvalidationHandler(const Invalidator& invalidator); |
| 352 virtual ~BoundFakeInvalidationHandler(); |
| 353 |
| 354 // Returns the last return value of GetInvalidatorState() on the |
| 355 // bound invalidator from the last time the invalidator state |
| 356 // changed. |
| 357 InvalidatorState GetLastRetrievedState() const; |
| 358 |
| 359 // InvalidationHandler implementation. |
| 360 virtual void OnInvalidatorStateChange(InvalidatorState state) OVERRIDE; |
| 361 |
| 362 private: |
| 363 const Invalidator& invalidator_; |
| 364 InvalidatorState last_retrieved_state_; |
| 365 |
| 366 DISALLOW_COPY_AND_ASSIGN(BoundFakeInvalidationHandler); |
| 367 }; |
| 368 |
| 369 } // namespace internal |
| 370 |
| 371 TYPED_TEST_P(InvalidatorTest, GetInvalidatorStateAlwaysCurrent) { |
| 372 Invalidator* const invalidator = this->CreateAndInitializeInvalidator(); |
| 373 |
| 374 internal::BoundFakeInvalidationHandler handler(*invalidator); |
| 375 invalidator->RegisterHandler(&handler); |
| 376 |
| 377 this->delegate_.TriggerOnInvalidatorStateChange(INVALIDATIONS_ENABLED); |
| 378 EXPECT_EQ(INVALIDATIONS_ENABLED, handler.GetInvalidatorState()); |
| 379 EXPECT_EQ(INVALIDATIONS_ENABLED, handler.GetLastRetrievedState()); |
| 380 |
| 381 this->delegate_.TriggerOnInvalidatorStateChange(TRANSIENT_INVALIDATION_ERROR); |
| 382 EXPECT_EQ(TRANSIENT_INVALIDATION_ERROR, handler.GetInvalidatorState()); |
| 383 EXPECT_EQ(TRANSIENT_INVALIDATION_ERROR, handler.GetLastRetrievedState()); |
360 } | 384 } |
361 | 385 |
362 // Initialize the invalidator with an empty initial state. Call the deprecated | 386 // Initialize the invalidator with an empty initial state. Call the deprecated |
363 // state setter function a number of times, destroying and re-creating the | 387 // state setter function a number of times, destroying and re-creating the |
364 // invalidator in between. Only the first one should take effect (i.e., state | 388 // invalidator in between. Only the first one should take effect (i.e., state |
365 // migration should only happen once). | 389 // migration should only happen once). |
366 TYPED_TEST_P(InvalidatorTest, MigrateState) { | 390 TYPED_TEST_P(InvalidatorTest, MigrateState) { |
367 if (!this->delegate_.InvalidatorHandlesDeprecatedState()) { | 391 if (!this->delegate_.InvalidatorHandlesDeprecatedState()) { |
368 DLOG(INFO) << "This Invalidator doesn't handle deprecated state; " | 392 DLOG(INFO) << "This Invalidator doesn't handle deprecated state; " |
369 << "skipping"; | 393 << "skipping"; |
370 return; | 394 return; |
371 } | 395 } |
372 | 396 |
373 this->delegate_.CreateInvalidator(std::string(), | 397 this->delegate_.CreateInvalidator(std::string(), |
374 this->fake_tracker_.AsWeakPtr()); | 398 this->fake_tracker_.AsWeakPtr()); |
375 Invalidator* invalidator = this->delegate_.GetInvalidator(); | 399 Invalidator* invalidator = this->delegate_.GetInvalidator(); |
376 | 400 |
377 invalidator->SetStateDeprecated("fake_state"); | 401 invalidator->SetStateDeprecated("fake_state"); |
378 this->delegate_.WaitForInvalidator(); | 402 this->delegate_.WaitForInvalidator(); |
379 EXPECT_EQ("fake_state", this->fake_tracker_.GetInvalidationState()); | 403 EXPECT_EQ("fake_state", this->fake_tracker_.GetInvalidationState()); |
380 | 404 |
381 // Should do nothing. | 405 // Should do nothing. |
382 invalidator->SetStateDeprecated("spurious_fake_state"); | 406 invalidator->SetStateDeprecated("spurious_fake_state"); |
383 this->delegate_.WaitForInvalidator(); | 407 this->delegate_.WaitForInvalidator(); |
384 EXPECT_EQ("fake_state", this->fake_tracker_.GetInvalidationState()); | 408 EXPECT_EQ("fake_state", this->fake_tracker_.GetInvalidationState()); |
385 | 409 |
386 // Pretend that Chrome has shut down. | 410 // Pretend that Chrome has shut down. |
387 this->delegate_.DestroyInvalidator(); | 411 this->delegate_.DestroyInvalidator(); |
388 this->delegate_.CreateInvalidator("fake_state", | 412 this->delegate_.CreateInvalidator("fake_state", |
389 this->fake_tracker_.AsWeakPtr()); | 413 this->fake_tracker_.AsWeakPtr()); |
390 invalidator = this->delegate_.GetInvalidator(); | 414 invalidator = this->delegate_.GetInvalidator(); |
391 | 415 |
392 // Should do nothing. | 416 // Should do nothing. |
393 invalidator->SetStateDeprecated("more_spurious_fake_state"); | 417 invalidator->SetStateDeprecated("more_spurious_fake_state"); |
394 this->delegate_.WaitForInvalidator(); | 418 this->delegate_.WaitForInvalidator(); |
395 EXPECT_EQ("fake_state", this->fake_tracker_.GetInvalidationState()); | 419 EXPECT_EQ("fake_state", this->fake_tracker_.GetInvalidationState()); |
396 } | 420 } |
397 | 421 |
398 REGISTER_TYPED_TEST_CASE_P(InvalidatorTest, | 422 REGISTER_TYPED_TEST_CASE_P(InvalidatorTest, |
399 Basic, MultipleHandlers, EmptySetUnregisters, | 423 Basic, MultipleHandlers, EmptySetUnregisters, |
400 MigrateState); | 424 GetInvalidatorStateAlwaysCurrent, MigrateState); |
401 | 425 |
402 } // namespace syncer | 426 } // namespace syncer |
403 | 427 |
404 #endif // SYNC_NOTIFIER_INVALIDATOR_TEST_TEMPLATE_H_ | 428 #endif // SYNC_NOTIFIER_INVALIDATOR_TEST_TEMPLATE_H_ |
OLD | NEW |