| 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 // |
| 11 // class MyInvalidatorTestDelegate { | 11 // class MyInvalidatorTestDelegate { |
| 12 // public: | 12 // public: |
| 13 // MyInvalidatorTestDelegate() ... | 13 // MyInvalidatorTestDelegate() ... |
| 14 // | 14 // |
| 15 // ~MyInvalidatorTestDelegate() { | 15 // ~MyInvalidatorTestDelegate() { |
| 16 // // DestroyInvalidator() may not be explicitly called by tests. | 16 // // DestroyInvalidator() may not be explicitly called by tests. |
| 17 // DestroyInvalidator(); | 17 // DestroyInvalidator(); |
| 18 // } | 18 // } |
| 19 // | 19 // |
| 20 // // Create the Invalidator implementation with the given parameters. | 20 // // Create the Invalidator implementation with the given parameters. |
| 21 // void CreateInvalidator( | 21 // void CreateInvalidator( |
| 22 // const std::string& initial_state, | 22 // const std::string& initial_state, |
| 23 // const base::WeakPtr<InvalidationStateTracker>& | 23 // InvalidationStateTracker* invalidation_state_tracker) { |
| 24 // invalidation_state_tracker) { | |
| 25 // ... | 24 // ... |
| 26 // } | 25 // } |
| 27 // | 26 // |
| 28 // // Should return the Invalidator implementation. Only called after | 27 // // Should return the Invalidator implementation. Only called after |
| 29 // // CreateInvalidator and before DestroyInvalidator. | 28 // // CreateInvalidator and before DestroyInvalidator. |
| 30 // MyInvalidator* GetInvalidator() { | 29 // MyInvalidator* GetInvalidator() { |
| 31 // ... | 30 // ... |
| 32 // } | 31 // } |
| 33 // | 32 // |
| 34 // // Destroy the Invalidator implementation. | 33 // // Destroy the Invalidator implementation. |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 class InvalidatorTest : public testing::Test { | 92 class InvalidatorTest : public testing::Test { |
| 94 protected: | 93 protected: |
| 95 InvalidatorTest() | 94 InvalidatorTest() |
| 96 : id1(ipc::invalidation::ObjectSource::TEST, "a"), | 95 : id1(ipc::invalidation::ObjectSource::TEST, "a"), |
| 97 id2(ipc::invalidation::ObjectSource::TEST, "b"), | 96 id2(ipc::invalidation::ObjectSource::TEST, "b"), |
| 98 id3(ipc::invalidation::ObjectSource::TEST, "c"), | 97 id3(ipc::invalidation::ObjectSource::TEST, "c"), |
| 99 id4(ipc::invalidation::ObjectSource::TEST, "d") { | 98 id4(ipc::invalidation::ObjectSource::TEST, "d") { |
| 100 } | 99 } |
| 101 | 100 |
| 102 Invalidator* CreateAndInitializeInvalidator() { | 101 Invalidator* CreateAndInitializeInvalidator() { |
| 103 this->delegate_.CreateInvalidator("fake_invalidator_client_id", | 102 delegate_.CreateInvalidator("fake_invalidator_client_id", |
| 104 "fake_initial_state", | 103 "fake_initial_state", |
| 105 this->fake_tracker_.AsWeakPtr()); | 104 &fake_tracker_); |
| 106 Invalidator* const invalidator = this->delegate_.GetInvalidator(); | 105 Invalidator* const invalidator = delegate_.GetInvalidator(); |
| 107 | 106 |
| 108 this->delegate_.WaitForInvalidator(); | 107 delegate_.WaitForInvalidator(); |
| 109 invalidator->UpdateCredentials("foo@bar.com", "fake_token"); | 108 invalidator->UpdateCredentials("foo@bar.com", "fake_token"); |
| 110 this->delegate_.WaitForInvalidator(); | 109 delegate_.WaitForInvalidator(); |
| 111 | 110 |
| 112 return invalidator; | 111 return invalidator; |
| 113 } | 112 } |
| 114 | 113 |
| 115 FakeInvalidationStateTracker fake_tracker_; | 114 FakeInvalidationStateTracker fake_tracker_; |
| 116 InvalidatorTestDelegate delegate_; | 115 InvalidatorTestDelegate delegate_; |
| 117 | 116 |
| 118 const invalidation::ObjectId id1; | 117 const invalidation::ObjectId id1; |
| 119 const invalidation::ObjectId id2; | 118 const invalidation::ObjectId id2; |
| 120 const invalidation::ObjectId id3; | 119 const invalidation::ObjectId id3; |
| (...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 368 invalidator->UnregisterHandler(&handler); | 367 invalidator->UnregisterHandler(&handler); |
| 369 } | 368 } |
| 370 | 369 |
| 371 REGISTER_TYPED_TEST_CASE_P(InvalidatorTest, | 370 REGISTER_TYPED_TEST_CASE_P(InvalidatorTest, |
| 372 Basic, MultipleHandlers, EmptySetUnregisters, | 371 Basic, MultipleHandlers, EmptySetUnregisters, |
| 373 GetInvalidatorStateAlwaysCurrent); | 372 GetInvalidatorStateAlwaysCurrent); |
| 374 | 373 |
| 375 } // namespace syncer | 374 } // namespace syncer |
| 376 | 375 |
| 377 #endif // SYNC_NOTIFIER_INVALIDATOR_TEST_TEMPLATE_H_ | 376 #endif // SYNC_NOTIFIER_INVALIDATOR_TEST_TEMPLATE_H_ |
| OLD | NEW |