| 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 "sync/notifier/p2p_invalidator.h" | 5 #include "sync/notifier/p2p_invalidator.h" |
| 6 | 6 |
| 7 #include <cstddef> | 7 #include <cstddef> |
| 8 | 8 |
| 9 #include "jingle/notifier/listener/fake_push_client.h" | 9 #include "jingle/notifier/listener/fake_push_client.h" |
| 10 #include "sync/internal_api/public/base/model_type.h" | 10 #include "sync/internal_api/public/base/model_type.h" |
| 11 #include "sync/notifier/fake_invalidation_handler.h" | 11 #include "sync/notifier/fake_invalidation_handler.h" |
| 12 #include "sync/notifier/invalidator_test_template.h" | 12 #include "sync/notifier/invalidator_test_template.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 14 | 14 |
| 15 namespace syncer { | 15 namespace syncer { |
| 16 | 16 |
| 17 namespace { | 17 namespace { |
| 18 | 18 |
| 19 class P2PInvalidatorTestDelegate { | 19 class P2PInvalidatorTestDelegate { |
| 20 public: | 20 public: |
| 21 P2PInvalidatorTestDelegate() : fake_push_client_(NULL) {} | 21 P2PInvalidatorTestDelegate() : fake_push_client_(NULL) {} |
| 22 | 22 |
| 23 ~P2PInvalidatorTestDelegate() { | 23 ~P2PInvalidatorTestDelegate() { |
| 24 DestroyInvalidator(); | 24 DestroyInvalidator(); |
| 25 } | 25 } |
| 26 | 26 |
| 27 void CreateInvalidator( | 27 void CreateInvalidator( |
| 28 const std::string& invalidator_client_id, | 28 const std::string& invalidator_client_id, |
| 29 const std::string& initial_state, | 29 const std::string& initial_state, |
| 30 const base::WeakPtr<InvalidationStateTracker>& | 30 InvalidationStateTracker* invalidation_state_tracker) { |
| 31 invalidation_state_tracker) { | |
| 32 DCHECK(!fake_push_client_); | 31 DCHECK(!fake_push_client_); |
| 33 DCHECK(!invalidator_.get()); | 32 DCHECK(!invalidator_.get()); |
| 34 fake_push_client_ = new notifier::FakePushClient(); | 33 fake_push_client_ = new notifier::FakePushClient(); |
| 35 invalidator_.reset( | 34 invalidator_.reset( |
| 36 new P2PInvalidator( | 35 new P2PInvalidator( |
| 37 scoped_ptr<notifier::PushClient>(fake_push_client_), | 36 scoped_ptr<notifier::PushClient>(fake_push_client_), |
| 38 invalidator_client_id, | 37 invalidator_client_id, |
| 39 NOTIFY_OTHERS)); | 38 NOTIFY_OTHERS)); |
| 40 } | 39 } |
| 41 | 40 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 notifier::FakePushClient* fake_push_client_; | 78 notifier::FakePushClient* fake_push_client_; |
| 80 scoped_ptr<P2PInvalidator> invalidator_; | 79 scoped_ptr<P2PInvalidator> invalidator_; |
| 81 }; | 80 }; |
| 82 | 81 |
| 83 class P2PInvalidatorTest : public testing::Test { | 82 class P2PInvalidatorTest : public testing::Test { |
| 84 protected: | 83 protected: |
| 85 P2PInvalidatorTest() | 84 P2PInvalidatorTest() |
| 86 : next_sent_notification_to_reflect_(0) { | 85 : next_sent_notification_to_reflect_(0) { |
| 87 delegate_.CreateInvalidator("sender", | 86 delegate_.CreateInvalidator("sender", |
| 88 "fake_state", | 87 "fake_state", |
| 89 base::WeakPtr<InvalidationStateTracker>()); | 88 NULL); |
| 90 delegate_.GetInvalidator()->RegisterHandler(&fake_handler_); | 89 delegate_.GetInvalidator()->RegisterHandler(&fake_handler_); |
| 91 } | 90 } |
| 92 | 91 |
| 93 virtual ~P2PInvalidatorTest() { | 92 virtual ~P2PInvalidatorTest() { |
| 94 delegate_.GetInvalidator()->UnregisterHandler(&fake_handler_); | 93 delegate_.GetInvalidator()->UnregisterHandler(&fake_handler_); |
| 95 } | 94 } |
| 96 | 95 |
| 97 ObjectIdInvalidationMap MakeInvalidationMap(ModelTypeSet types) { | 96 ObjectIdInvalidationMap MakeInvalidationMap(ModelTypeSet types) { |
| 98 ObjectIdInvalidationMap invalidations; | 97 ObjectIdInvalidationMap invalidations; |
| 99 ObjectIdSet ids = ModelTypeSetToObjectIdSet(types); | 98 ObjectIdSet ids = ModelTypeSetToObjectIdSet(types); |
| (...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 346 EXPECT_EQ(5, fake_handler_.GetInvalidationCount()); | 345 EXPECT_EQ(5, fake_handler_.GetInvalidationCount()); |
| 347 } | 346 } |
| 348 | 347 |
| 349 INSTANTIATE_TYPED_TEST_CASE_P( | 348 INSTANTIATE_TYPED_TEST_CASE_P( |
| 350 P2PInvalidatorTest, InvalidatorTest, | 349 P2PInvalidatorTest, InvalidatorTest, |
| 351 P2PInvalidatorTestDelegate); | 350 P2PInvalidatorTestDelegate); |
| 352 | 351 |
| 353 } // namespace | 352 } // namespace |
| 354 | 353 |
| 355 } // namespace syncer | 354 } // namespace syncer |
| OLD | NEW |