OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "components/invalidation/invalidation_notifier.h" | |
6 | |
7 #include "base/memory/scoped_ptr.h" | |
8 #include "base/thread_task_runner_handle.h" | |
9 #include "components/invalidation/fake_invalidation_handler.h" | |
10 #include "components/invalidation/fake_invalidation_state_tracker.h" | |
11 #include "components/invalidation/invalidation_state_tracker.h" | |
12 #include "components/invalidation/invalidator_test_template.h" | |
13 #include "components/invalidation/push_client_channel.h" | |
14 #include "jingle/notifier/base/fake_base_task.h" | |
15 #include "jingle/notifier/base/notifier_options.h" | |
16 #include "jingle/notifier/listener/fake_push_client.h" | |
17 #include "net/url_request/url_request_test_util.h" | |
18 #include "testing/gtest/include/gtest/gtest.h" | |
19 | |
20 namespace syncer { | |
21 | |
22 namespace { | |
23 | |
24 class InvalidationNotifierTestDelegate { | |
25 public: | |
26 InvalidationNotifierTestDelegate() {} | |
27 | |
28 ~InvalidationNotifierTestDelegate() { | |
29 DestroyInvalidator(); | |
30 } | |
31 | |
32 void CreateInvalidator( | |
33 const std::string& invalidator_client_id, | |
34 const std::string& initial_state, | |
35 const base::WeakPtr<InvalidationStateTracker>& | |
36 invalidation_state_tracker) { | |
37 DCHECK(!invalidator_.get()); | |
38 scoped_ptr<notifier::PushClient> push_client( | |
39 new notifier::FakePushClient()); | |
40 scoped_ptr<SyncNetworkChannel> network_channel( | |
41 new PushClientChannel(push_client.Pass())); | |
42 invalidator_.reset(new InvalidationNotifier( | |
43 network_channel.Pass(), invalidator_client_id, | |
44 UnackedInvalidationsMap(), initial_state, invalidation_state_tracker, | |
45 base::ThreadTaskRunnerHandle::Get(), "fake_client_info")); | |
46 } | |
47 | |
48 Invalidator* GetInvalidator() { | |
49 return invalidator_.get(); | |
50 } | |
51 | |
52 void DestroyInvalidator() { | |
53 // Stopping the invalidation notifier stops its scheduler, which deletes | |
54 // any pending tasks without running them. Some tasks "run and delete" | |
55 // another task, so they must be run in order to avoid leaking the inner | |
56 // task. Stopping does not schedule any tasks, so it's both necessary and | |
57 // sufficient to drain the task queue before stopping the notifier. | |
58 message_loop_.RunUntilIdle(); | |
59 invalidator_.reset(); | |
60 } | |
61 | |
62 void WaitForInvalidator() { | |
63 message_loop_.RunUntilIdle(); | |
64 } | |
65 | |
66 void TriggerOnInvalidatorStateChange(InvalidatorState state) { | |
67 invalidator_->OnInvalidatorStateChange(state); | |
68 } | |
69 | |
70 void TriggerOnIncomingInvalidation( | |
71 const ObjectIdInvalidationMap& invalidation_map) { | |
72 invalidator_->OnInvalidate(invalidation_map); | |
73 } | |
74 | |
75 private: | |
76 base::MessageLoop message_loop_; | |
77 scoped_ptr<InvalidationNotifier> invalidator_; | |
78 }; | |
79 | |
80 INSTANTIATE_TYPED_TEST_CASE_P( | |
81 InvalidationNotifierTest, InvalidatorTest, | |
82 InvalidationNotifierTestDelegate); | |
83 | |
84 } // namespace | |
85 | |
86 } // namespace syncer | |
OLD | NEW |