OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/invalidation/invalidation_notifier.h" | 5 #include "components/invalidation/invalidation_notifier.h" |
6 | 6 |
7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "components/invalidation/fake_invalidation_handler.h" | 9 #include "components/invalidation/fake_invalidation_handler.h" |
10 #include "components/invalidation/fake_invalidation_state_tracker.h" | 10 #include "components/invalidation/fake_invalidation_state_tracker.h" |
11 #include "components/invalidation/invalidation_state_tracker.h" | 11 #include "components/invalidation/invalidation_state_tracker.h" |
12 #include "components/invalidation/invalidator_test_template.h" | 12 #include "components/invalidation/invalidator_test_template.h" |
13 #include "components/invalidation/push_client_channel.h" | 13 #include "components/invalidation/push_client_channel.h" |
14 #include "jingle/notifier/base/fake_base_task.h" | 14 #include "jingle/notifier/base/fake_base_task.h" |
15 #include "jingle/notifier/base/notifier_options.h" | 15 #include "jingle/notifier/base/notifier_options.h" |
16 #include "jingle/notifier/listener/fake_push_client.h" | 16 #include "jingle/notifier/listener/fake_push_client.h" |
17 #include "net/url_request/url_request_test_util.h" | 17 #include "net/url_request/url_request_test_util.h" |
18 #include "sync/internal_api/public/util/weak_handle.h" | |
19 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
20 | 19 |
21 namespace syncer { | 20 namespace syncer { |
22 | 21 |
23 namespace { | 22 namespace { |
24 | 23 |
25 class InvalidationNotifierTestDelegate { | 24 class InvalidationNotifierTestDelegate { |
26 public: | 25 public: |
27 InvalidationNotifierTestDelegate() {} | 26 InvalidationNotifierTestDelegate() {} |
28 | 27 |
29 ~InvalidationNotifierTestDelegate() { | 28 ~InvalidationNotifierTestDelegate() { |
30 DestroyInvalidator(); | 29 DestroyInvalidator(); |
31 } | 30 } |
32 | 31 |
33 void CreateInvalidator( | 32 void CreateInvalidator( |
34 const std::string& invalidator_client_id, | 33 const std::string& invalidator_client_id, |
35 const std::string& initial_state, | 34 const std::string& initial_state, |
36 const base::WeakPtr<InvalidationStateTracker>& | 35 const base::WeakPtr<InvalidationStateTracker>& |
37 invalidation_state_tracker) { | 36 invalidation_state_tracker) { |
38 DCHECK(!invalidator_.get()); | 37 DCHECK(!invalidator_.get()); |
39 scoped_ptr<notifier::PushClient> push_client( | 38 scoped_ptr<notifier::PushClient> push_client( |
40 new notifier::FakePushClient()); | 39 new notifier::FakePushClient()); |
41 scoped_ptr<SyncNetworkChannel> network_channel( | 40 scoped_ptr<SyncNetworkChannel> network_channel( |
42 new PushClientChannel(push_client.Pass())); | 41 new PushClientChannel(push_client.Pass())); |
43 invalidator_.reset( | 42 invalidator_.reset( |
44 new InvalidationNotifier( | 43 new InvalidationNotifier(network_channel.Pass(), |
45 network_channel.Pass(), | 44 invalidator_client_id, |
46 invalidator_client_id, | 45 UnackedInvalidationsMap(), |
47 UnackedInvalidationsMap(), | 46 initial_state, |
48 initial_state, | 47 invalidation_state_tracker, |
49 MakeWeakHandle(invalidation_state_tracker), | 48 base::MessageLoopProxy::current(), |
50 "fake_client_info")); | 49 "fake_client_info")); |
51 } | 50 } |
52 | 51 |
53 Invalidator* GetInvalidator() { | 52 Invalidator* GetInvalidator() { |
54 return invalidator_.get(); | 53 return invalidator_.get(); |
55 } | 54 } |
56 | 55 |
57 void DestroyInvalidator() { | 56 void DestroyInvalidator() { |
58 // Stopping the invalidation notifier stops its scheduler, which deletes | 57 // Stopping the invalidation notifier stops its scheduler, which deletes |
59 // any pending tasks without running them. Some tasks "run and delete" | 58 // any pending tasks without running them. Some tasks "run and delete" |
60 // another task, so they must be run in order to avoid leaking the inner | 59 // another task, so they must be run in order to avoid leaking the inner |
(...skipping 21 matching lines...) Expand all Loading... |
82 scoped_ptr<InvalidationNotifier> invalidator_; | 81 scoped_ptr<InvalidationNotifier> invalidator_; |
83 }; | 82 }; |
84 | 83 |
85 INSTANTIATE_TYPED_TEST_CASE_P( | 84 INSTANTIATE_TYPED_TEST_CASE_P( |
86 InvalidationNotifierTest, InvalidatorTest, | 85 InvalidationNotifierTest, InvalidatorTest, |
87 InvalidationNotifierTestDelegate); | 86 InvalidationNotifierTestDelegate); |
88 | 87 |
89 } // namespace | 88 } // namespace |
90 | 89 |
91 } // namespace syncer | 90 } // namespace syncer |
OLD | NEW |