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

Side by Side Diff: sync/notifier/invalidator_test_template.h

Issue 11046008: [Invalidations] Require there to be no registered handlers on Invalidator destruction (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Sync to HEAD Created 8 years, 2 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/invalidator_registrar_unittest.cc ('k') | no next file » | 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 // 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 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 276
277 EXPECT_EQ(0, handler3.GetInvalidationCount()); 277 EXPECT_EQ(0, handler3.GetInvalidationCount());
278 EXPECT_EQ(0, handler4.GetInvalidationCount()); 278 EXPECT_EQ(0, handler4.GetInvalidationCount());
279 } 279 }
280 280
281 this->delegate_.TriggerOnInvalidatorStateChange(TRANSIENT_INVALIDATION_ERROR); 281 this->delegate_.TriggerOnInvalidatorStateChange(TRANSIENT_INVALIDATION_ERROR);
282 EXPECT_EQ(TRANSIENT_INVALIDATION_ERROR, handler1.GetInvalidatorState()); 282 EXPECT_EQ(TRANSIENT_INVALIDATION_ERROR, handler1.GetInvalidatorState());
283 EXPECT_EQ(TRANSIENT_INVALIDATION_ERROR, handler2.GetInvalidatorState()); 283 EXPECT_EQ(TRANSIENT_INVALIDATION_ERROR, handler2.GetInvalidatorState());
284 EXPECT_EQ(TRANSIENT_INVALIDATION_ERROR, handler3.GetInvalidatorState()); 284 EXPECT_EQ(TRANSIENT_INVALIDATION_ERROR, handler3.GetInvalidatorState());
285 EXPECT_EQ(TRANSIENT_INVALIDATION_ERROR, handler4.GetInvalidatorState()); 285 EXPECT_EQ(TRANSIENT_INVALIDATION_ERROR, handler4.GetInvalidatorState());
286
287 invalidator->UnregisterHandler(&handler3);
288 invalidator->UnregisterHandler(&handler2);
289 invalidator->UnregisterHandler(&handler1);
286 } 290 }
287 291
288 // Make sure that passing an empty set to UpdateRegisteredIds clears the 292 // Make sure that passing an empty set to UpdateRegisteredIds clears the
289 // corresponding entries for the handler. 293 // corresponding entries for the handler.
290 TYPED_TEST_P(InvalidatorTest, EmptySetUnregisters) { 294 TYPED_TEST_P(InvalidatorTest, EmptySetUnregisters) {
291 Invalidator* const invalidator = this->CreateAndInitializeInvalidator(); 295 Invalidator* const invalidator = this->CreateAndInitializeInvalidator();
292 296
293 FakeInvalidationHandler handler1; 297 FakeInvalidationHandler handler1;
294 298
295 // Control observer. 299 // Control observer.
(...skipping 29 matching lines...) Expand all
325 states[this->id2].payload = "2"; 329 states[this->id2].payload = "2";
326 states[this->id3].payload = "3"; 330 states[this->id3].payload = "3";
327 this->delegate_.TriggerOnIncomingInvalidation(states, REMOTE_INVALIDATION); 331 this->delegate_.TriggerOnIncomingInvalidation(states, REMOTE_INVALIDATION);
328 EXPECT_EQ(0, handler1.GetInvalidationCount()); 332 EXPECT_EQ(0, handler1.GetInvalidationCount());
329 EXPECT_EQ(1, handler2.GetInvalidationCount()); 333 EXPECT_EQ(1, handler2.GetInvalidationCount());
330 } 334 }
331 335
332 this->delegate_.TriggerOnInvalidatorStateChange(TRANSIENT_INVALIDATION_ERROR); 336 this->delegate_.TriggerOnInvalidatorStateChange(TRANSIENT_INVALIDATION_ERROR);
333 EXPECT_EQ(TRANSIENT_INVALIDATION_ERROR, handler1.GetInvalidatorState()); 337 EXPECT_EQ(TRANSIENT_INVALIDATION_ERROR, handler1.GetInvalidatorState());
334 EXPECT_EQ(TRANSIENT_INVALIDATION_ERROR, handler2.GetInvalidatorState()); 338 EXPECT_EQ(TRANSIENT_INVALIDATION_ERROR, handler2.GetInvalidatorState());
339
340 invalidator->UnregisterHandler(&handler2);
341 invalidator->UnregisterHandler(&handler1);
335 } 342 }
336 343
337 namespace internal { 344 namespace internal {
338 345
339 // A FakeInvalidationHandler that is "bound" to a specific 346 // A FakeInvalidationHandler that is "bound" to a specific
340 // Invalidator. This is for cross-referencing state information with 347 // Invalidator. This is for cross-referencing state information with
341 // the bound Invalidator. 348 // the bound Invalidator.
342 class BoundFakeInvalidationHandler : public FakeInvalidationHandler { 349 class BoundFakeInvalidationHandler : public FakeInvalidationHandler {
343 public: 350 public:
344 explicit BoundFakeInvalidationHandler(const Invalidator& invalidator); 351 explicit BoundFakeInvalidationHandler(const Invalidator& invalidator);
(...skipping 22 matching lines...) Expand all
367 internal::BoundFakeInvalidationHandler handler(*invalidator); 374 internal::BoundFakeInvalidationHandler handler(*invalidator);
368 invalidator->RegisterHandler(&handler); 375 invalidator->RegisterHandler(&handler);
369 376
370 this->delegate_.TriggerOnInvalidatorStateChange(INVALIDATIONS_ENABLED); 377 this->delegate_.TriggerOnInvalidatorStateChange(INVALIDATIONS_ENABLED);
371 EXPECT_EQ(INVALIDATIONS_ENABLED, handler.GetInvalidatorState()); 378 EXPECT_EQ(INVALIDATIONS_ENABLED, handler.GetInvalidatorState());
372 EXPECT_EQ(INVALIDATIONS_ENABLED, handler.GetLastRetrievedState()); 379 EXPECT_EQ(INVALIDATIONS_ENABLED, handler.GetLastRetrievedState());
373 380
374 this->delegate_.TriggerOnInvalidatorStateChange(TRANSIENT_INVALIDATION_ERROR); 381 this->delegate_.TriggerOnInvalidatorStateChange(TRANSIENT_INVALIDATION_ERROR);
375 EXPECT_EQ(TRANSIENT_INVALIDATION_ERROR, handler.GetInvalidatorState()); 382 EXPECT_EQ(TRANSIENT_INVALIDATION_ERROR, handler.GetInvalidatorState());
376 EXPECT_EQ(TRANSIENT_INVALIDATION_ERROR, handler.GetLastRetrievedState()); 383 EXPECT_EQ(TRANSIENT_INVALIDATION_ERROR, handler.GetLastRetrievedState());
384
385 invalidator->UnregisterHandler(&handler);
377 } 386 }
378 387
379 // Initialize the invalidator with no bootstrap data. Call the deprecated 388 // Initialize the invalidator with no bootstrap data. Call the deprecated
380 // state setter function a number of times, destroying and re-creating the 389 // state setter function a number of times, destroying and re-creating the
381 // invalidator in between. Only the first one should take effect (i.e., 390 // invalidator in between. Only the first one should take effect (i.e.,
382 // migration of bootstrap data should only happen once) 391 // migration of bootstrap data should only happen once)
383 TYPED_TEST_P(InvalidatorTest, MigrateState) { 392 TYPED_TEST_P(InvalidatorTest, MigrateState) {
384 if (!this->delegate_.InvalidatorHandlesDeprecatedState()) { 393 if (!this->delegate_.InvalidatorHandlesDeprecatedState()) {
385 DLOG(INFO) << "This Invalidator doesn't handle deprecated state; " 394 DLOG(INFO) << "This Invalidator doesn't handle deprecated state; "
386 << "skipping"; 395 << "skipping";
(...skipping 25 matching lines...) Expand all
412 EXPECT_EQ("fake_state", this->fake_tracker_.GetBootstrapData()); 421 EXPECT_EQ("fake_state", this->fake_tracker_.GetBootstrapData());
413 } 422 }
414 423
415 REGISTER_TYPED_TEST_CASE_P(InvalidatorTest, 424 REGISTER_TYPED_TEST_CASE_P(InvalidatorTest,
416 Basic, MultipleHandlers, EmptySetUnregisters, 425 Basic, MultipleHandlers, EmptySetUnregisters,
417 GetInvalidatorStateAlwaysCurrent, MigrateState); 426 GetInvalidatorStateAlwaysCurrent, MigrateState);
418 427
419 } // namespace syncer 428 } // namespace syncer
420 429
421 #endif // SYNC_NOTIFIER_INVALIDATOR_TEST_TEMPLATE_H_ 430 #endif // SYNC_NOTIFIER_INVALIDATOR_TEST_TEMPLATE_H_
OLDNEW
« no previous file with comments | « sync/notifier/invalidator_registrar_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698