| 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 "chrome/browser/sync/notifier/non_blocking_invalidation_notifier.h" | 5 #include "chrome/browser/sync/notifier/non_blocking_invalidation_notifier.h" |
| 6 | 6 |
| 7 #include "base/memory/ref_counted.h" | 7 #include "base/memory/ref_counted.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/threading/thread.h" | 10 #include "base/threading/thread.h" |
| 11 #include "chrome/browser/sync/notifier/invalidation_version_tracker.h" | 11 #include "chrome/browser/sync/notifier/invalidation_version_tracker.h" |
| 12 #include "chrome/browser/sync/notifier/mock_sync_notifier_observer.h" | 12 #include "chrome/browser/sync/notifier/mock_sync_notifier_observer.h" |
| 13 #include "chrome/browser/sync/syncable/model_type.h" | 13 #include "chrome/browser/sync/syncable/model_type.h" |
| 14 #include "chrome/browser/sync/syncable/model_type_payload_map.h" | 14 #include "chrome/browser/sync/syncable/model_type_payload_map.h" |
| 15 #include "chrome/browser/sync/util/weak_handle.h" | 15 #include "chrome/browser/sync/util/weak_handle.h" |
| 16 #include "content/test/test_browser_thread.h" | |
| 17 #include "jingle/notifier/base/fake_base_task.h" | 16 #include "jingle/notifier/base/fake_base_task.h" |
| 18 #include "net/url_request/url_request_test_util.h" | 17 #include "net/url_request/url_request_test_util.h" |
| 19 #include "testing/gmock/include/gmock/gmock.h" | 18 #include "testing/gmock/include/gmock/gmock.h" |
| 20 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| 21 | 20 |
| 22 namespace sync_notifier { | 21 namespace sync_notifier { |
| 23 | 22 |
| 24 namespace { | 23 namespace { |
| 25 | 24 |
| 26 using ::testing::InSequence; | 25 using ::testing::InSequence; |
| 27 using ::testing::StrictMock; | 26 using ::testing::StrictMock; |
| 28 using content::BrowserThread; | |
| 29 | 27 |
| 30 class NonBlockingInvalidationNotifierTest : public testing::Test { | 28 class NonBlockingInvalidationNotifierTest : public testing::Test { |
| 31 public: | 29 public: |
| 32 NonBlockingInvalidationNotifierTest() | 30 NonBlockingInvalidationNotifierTest() : io_thread_("Test IO thread") {} |
| 33 : io_thread_(BrowserThread::IO) {} | |
| 34 | 31 |
| 35 protected: | 32 protected: |
| 36 virtual void SetUp() { | 33 virtual void SetUp() { |
| 37 base::Thread::Options options; | 34 base::Thread::Options options; |
| 38 options.message_loop_type = MessageLoop::TYPE_IO; | 35 options.message_loop_type = MessageLoop::TYPE_IO; |
| 39 io_thread_.StartIOThread(); | 36 io_thread_.StartWithOptions(options); |
| 40 request_context_getter_ = | 37 request_context_getter_ = |
| 41 new TestURLRequestContextGetter( | 38 new TestURLRequestContextGetter(io_thread_.message_loop_proxy()); |
| 42 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)); | |
| 43 notifier::NotifierOptions notifier_options; | 39 notifier::NotifierOptions notifier_options; |
| 44 notifier_options.request_context_getter = request_context_getter_; | 40 notifier_options.request_context_getter = request_context_getter_; |
| 45 invalidation_notifier_.reset( | 41 invalidation_notifier_.reset( |
| 46 new NonBlockingInvalidationNotifier( | 42 new NonBlockingInvalidationNotifier( |
| 47 notifier_options, | 43 notifier_options, |
| 48 InvalidationVersionMap(), | 44 InvalidationVersionMap(), |
| 49 browser_sync::MakeWeakHandle( | 45 browser_sync::MakeWeakHandle( |
| 50 base::WeakPtr<sync_notifier::InvalidationVersionTracker>()), | 46 base::WeakPtr<sync_notifier::InvalidationVersionTracker>()), |
| 51 "fake_client_info")); | 47 "fake_client_info")); |
| 52 invalidation_notifier_->AddObserver(&mock_observer_); | 48 invalidation_notifier_->AddObserver(&mock_observer_); |
| 53 } | 49 } |
| 54 | 50 |
| 55 virtual void TearDown() { | 51 virtual void TearDown() { |
| 56 invalidation_notifier_->RemoveObserver(&mock_observer_); | 52 invalidation_notifier_->RemoveObserver(&mock_observer_); |
| 57 invalidation_notifier_.reset(); | 53 invalidation_notifier_.reset(); |
| 58 request_context_getter_ = NULL; | 54 request_context_getter_ = NULL; |
| 59 io_thread_.Stop(); | 55 io_thread_.Stop(); |
| 60 ui_loop_.RunAllPending(); | 56 ui_loop_.RunAllPending(); |
| 61 } | 57 } |
| 62 | 58 |
| 63 MessageLoop ui_loop_; | 59 MessageLoop ui_loop_; |
| 64 content::TestBrowserThread io_thread_; | 60 base::Thread io_thread_; |
| 65 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; | 61 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; |
| 66 scoped_ptr<NonBlockingInvalidationNotifier> invalidation_notifier_; | 62 scoped_ptr<NonBlockingInvalidationNotifier> invalidation_notifier_; |
| 67 StrictMock<MockSyncNotifierObserver> mock_observer_; | 63 StrictMock<MockSyncNotifierObserver> mock_observer_; |
| 68 notifier::FakeBaseTask fake_base_task_; | 64 notifier::FakeBaseTask fake_base_task_; |
| 69 }; | 65 }; |
| 70 | 66 |
| 71 TEST_F(NonBlockingInvalidationNotifierTest, Basic) { | 67 TEST_F(NonBlockingInvalidationNotifierTest, Basic) { |
| 72 InSequence dummy; | 68 InSequence dummy; |
| 73 | 69 |
| 74 syncable::ModelTypePayloadMap type_payloads; | 70 syncable::ModelTypePayloadMap type_payloads; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 92 invalidation_notifier_->OnIncomingNotification(type_payloads, | 88 invalidation_notifier_->OnIncomingNotification(type_payloads, |
| 93 REMOTE_NOTIFICATION); | 89 REMOTE_NOTIFICATION); |
| 94 invalidation_notifier_->OnNotificationStateChange(false); | 90 invalidation_notifier_->OnNotificationStateChange(false); |
| 95 | 91 |
| 96 ui_loop_.RunAllPending(); | 92 ui_loop_.RunAllPending(); |
| 97 } | 93 } |
| 98 | 94 |
| 99 } // namespace | 95 } // namespace |
| 100 | 96 |
| 101 } // namespace sync_notifier | 97 } // namespace sync_notifier |
| OLD | NEW |