| 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/non_blocking_invalidator.h" | 5 #include "components/invalidation/non_blocking_invalidator.h" |
| 6 | 6 |
| 7 #include "base/bind_helpers.h" | 7 #include "base/bind_helpers.h" |
| 8 #include "base/location.h" |
| 8 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 9 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/message_loop/message_loop.h" | |
| 11 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
| 12 #include "base/threading/thread.h" | 12 #include "base/threading/thread.h" |
| 13 #include "components/invalidation/fake_invalidation_handler.h" | 13 #include "components/invalidation/fake_invalidation_handler.h" |
| 14 #include "components/invalidation/invalidation_state_tracker.h" | 14 #include "components/invalidation/invalidation_state_tracker.h" |
| 15 #include "components/invalidation/invalidator_test_template.h" | 15 #include "components/invalidation/invalidator_test_template.h" |
| 16 #include "google/cacheinvalidation/types.pb.h" | 16 #include "google/cacheinvalidation/types.pb.h" |
| 17 #include "jingle/notifier/base/fake_base_task.h" | 17 #include "jingle/notifier/base/fake_base_task.h" |
| 18 #include "net/url_request/url_request_test_util.h" | 18 #include "net/url_request/url_request_test_util.h" |
| 19 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| 20 | 20 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 31 void CreateInvalidator( | 31 void CreateInvalidator( |
| 32 const std::string& invalidator_client_id, | 32 const std::string& invalidator_client_id, |
| 33 const std::string& initial_state, | 33 const std::string& initial_state, |
| 34 const base::WeakPtr<InvalidationStateTracker>& | 34 const base::WeakPtr<InvalidationStateTracker>& |
| 35 invalidation_state_tracker) { | 35 invalidation_state_tracker) { |
| 36 DCHECK(!invalidator_.get()); | 36 DCHECK(!invalidator_.get()); |
| 37 base::Thread::Options options; | 37 base::Thread::Options options; |
| 38 options.message_loop_type = base::MessageLoop::TYPE_IO; | 38 options.message_loop_type = base::MessageLoop::TYPE_IO; |
| 39 io_thread_.StartWithOptions(options); | 39 io_thread_.StartWithOptions(options); |
| 40 request_context_getter_ = | 40 request_context_getter_ = |
| 41 new net::TestURLRequestContextGetter(io_thread_.message_loop_proxy()); | 41 new net::TestURLRequestContextGetter(io_thread_.task_runner()); |
| 42 notifier::NotifierOptions notifier_options; | 42 notifier::NotifierOptions notifier_options; |
| 43 notifier_options.request_context_getter = request_context_getter_; | 43 notifier_options.request_context_getter = request_context_getter_; |
| 44 NetworkChannelCreator network_channel_creator = | 44 NetworkChannelCreator network_channel_creator = |
| 45 NonBlockingInvalidator::MakePushClientChannelCreator(notifier_options); | 45 NonBlockingInvalidator::MakePushClientChannelCreator(notifier_options); |
| 46 invalidator_.reset( | 46 invalidator_.reset( |
| 47 new NonBlockingInvalidator( | 47 new NonBlockingInvalidator( |
| 48 network_channel_creator, | 48 network_channel_creator, |
| 49 invalidator_client_id, | 49 invalidator_client_id, |
| 50 UnackedInvalidationsMap(), | 50 UnackedInvalidationsMap(), |
| 51 initial_state, | 51 initial_state, |
| 52 invalidation_state_tracker.get(), | 52 invalidation_state_tracker.get(), |
| 53 "fake_client_info", | 53 "fake_client_info", |
| 54 request_context_getter_)); | 54 request_context_getter_)); |
| 55 } | 55 } |
| 56 | 56 |
| 57 Invalidator* GetInvalidator() { | 57 Invalidator* GetInvalidator() { |
| 58 return invalidator_.get(); | 58 return invalidator_.get(); |
| 59 } | 59 } |
| 60 | 60 |
| 61 void DestroyInvalidator() { | 61 void DestroyInvalidator() { |
| 62 invalidator_.reset(); | 62 invalidator_.reset(); |
| 63 request_context_getter_ = NULL; | 63 request_context_getter_ = NULL; |
| 64 io_thread_.Stop(); | 64 io_thread_.Stop(); |
| 65 message_loop_.RunUntilIdle(); | 65 message_loop_.RunUntilIdle(); |
| 66 } | 66 } |
| 67 | 67 |
| 68 void WaitForInvalidator() { | 68 void WaitForInvalidator() { |
| 69 base::RunLoop run_loop; | 69 base::RunLoop run_loop; |
| 70 ASSERT_TRUE( | 70 ASSERT_TRUE(io_thread_.task_runner()->PostTaskAndReply( |
| 71 io_thread_.message_loop_proxy()->PostTaskAndReply( | 71 FROM_HERE, base::Bind(&base::DoNothing), run_loop.QuitClosure())); |
| 72 FROM_HERE, | |
| 73 base::Bind(&base::DoNothing), | |
| 74 run_loop.QuitClosure())); | |
| 75 run_loop.Run(); | 72 run_loop.Run(); |
| 76 } | 73 } |
| 77 | 74 |
| 78 void TriggerOnInvalidatorStateChange(InvalidatorState state) { | 75 void TriggerOnInvalidatorStateChange(InvalidatorState state) { |
| 79 invalidator_->OnInvalidatorStateChange(state); | 76 invalidator_->OnInvalidatorStateChange(state); |
| 80 } | 77 } |
| 81 | 78 |
| 82 void TriggerOnIncomingInvalidation( | 79 void TriggerOnIncomingInvalidation( |
| 83 const ObjectIdInvalidationMap& invalidation_map) { | 80 const ObjectIdInvalidationMap& invalidation_map) { |
| 84 invalidator_->OnIncomingInvalidation(invalidation_map); | 81 invalidator_->OnIncomingInvalidation(invalidation_map); |
| 85 } | 82 } |
| 86 | 83 |
| 87 private: | 84 private: |
| 88 base::MessageLoop message_loop_; | 85 base::MessageLoop message_loop_; |
| 89 base::Thread io_thread_; | 86 base::Thread io_thread_; |
| 90 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; | 87 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; |
| 91 scoped_ptr<NonBlockingInvalidator> invalidator_; | 88 scoped_ptr<NonBlockingInvalidator> invalidator_; |
| 92 }; | 89 }; |
| 93 | 90 |
| 94 INSTANTIATE_TYPED_TEST_CASE_P( | 91 INSTANTIATE_TYPED_TEST_CASE_P( |
| 95 NonBlockingInvalidatorTest, InvalidatorTest, | 92 NonBlockingInvalidatorTest, InvalidatorTest, |
| 96 NonBlockingInvalidatorTestDelegate); | 93 NonBlockingInvalidatorTestDelegate); |
| 97 | 94 |
| 98 } // namespace syncer | 95 } // namespace syncer |
| OLD | NEW |