| 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 "base/message_loop/message_loop.h" |
| 6 #include "base/message_loop/message_loop_proxy.h" |
| 7 #include "base/run_loop.h" |
| 8 #include "base/sequenced_task_runner.h" |
| 9 #include "sync/engine/model_type_sync_proxy_impl.h" |
| 10 #include "sync/internal_api/public/base/model_type.h" |
| 11 #include "sync/internal_api/sync_context.h" |
| 12 #include "sync/internal_api/sync_context_proxy_impl.h" |
| 13 #include "sync/sessions/model_type_registry.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" |
| 15 |
| 16 namespace syncer { |
| 17 |
| 18 class SyncContextProxyImplTest : public ::testing::Test { |
| 19 public: |
| 20 SyncContextProxyImplTest() |
| 21 : sync_task_runner_(base::MessageLoopProxy::current()), |
| 22 type_task_runner_(base::MessageLoopProxy::current()), |
| 23 context_(new SyncContext(®istry_)), |
| 24 context_proxy_(sync_task_runner_, context_->AsWeakPtr()) {} |
| 25 |
| 26 // The sync thread could be shut down at any time without warning. This |
| 27 // function simulates such an event. |
| 28 void DisableSync() { context_.reset(); } |
| 29 |
| 30 scoped_ptr<SyncContextProxy> GetProxy() { return context_proxy_.Clone(); } |
| 31 |
| 32 private: |
| 33 base::MessageLoop loop_; |
| 34 scoped_refptr<base::SequencedTaskRunner> sync_task_runner_; |
| 35 scoped_refptr<base::SequencedTaskRunner> type_task_runner_; |
| 36 ModelTypeRegistry registry_; |
| 37 scoped_ptr<SyncContext> context_; |
| 38 SyncContextProxyImpl context_proxy_; |
| 39 }; |
| 40 |
| 41 // Try to connect a type to a SyncContext that has already shut down. |
| 42 TEST_F(SyncContextProxyImplTest, FailToConnect1) { |
| 43 ModelTypeSyncProxyImpl themes_sync_proxy(syncer::THEMES); |
| 44 DisableSync(); |
| 45 themes_sync_proxy.Enable(GetProxy()); |
| 46 |
| 47 base::RunLoop run_loop_; |
| 48 run_loop_.RunUntilIdle(); |
| 49 EXPECT_FALSE(themes_sync_proxy.IsConnected()); |
| 50 } |
| 51 |
| 52 // Try to connect a type to a SyncContext as it shuts down. |
| 53 TEST_F(SyncContextProxyImplTest, FailToConnect2) { |
| 54 ModelTypeSyncProxyImpl themes_sync_proxy(syncer::THEMES); |
| 55 themes_sync_proxy.Enable(GetProxy()); |
| 56 DisableSync(); |
| 57 |
| 58 base::RunLoop run_loop_; |
| 59 run_loop_.RunUntilIdle(); |
| 60 EXPECT_FALSE(themes_sync_proxy.IsConnected()); |
| 61 } |
| 62 |
| 63 // Tests the case where the type's sync proxy shuts down first. |
| 64 TEST_F(SyncContextProxyImplTest, TypeDisconnectsFirst) { |
| 65 scoped_ptr<ModelTypeSyncProxyImpl> themes_sync_proxy( |
| 66 new ModelTypeSyncProxyImpl(syncer::THEMES)); |
| 67 themes_sync_proxy->Enable(GetProxy()); |
| 68 |
| 69 base::RunLoop run_loop_; |
| 70 run_loop_.RunUntilIdle(); |
| 71 |
| 72 EXPECT_TRUE(themes_sync_proxy->IsConnected()); |
| 73 themes_sync_proxy.reset(); |
| 74 } |
| 75 |
| 76 // Tests the case where the sync thread shuts down first. |
| 77 TEST_F(SyncContextProxyImplTest, SyncDisconnectsFirst) { |
| 78 scoped_ptr<ModelTypeSyncProxyImpl> themes_sync_proxy( |
| 79 new ModelTypeSyncProxyImpl(syncer::THEMES)); |
| 80 themes_sync_proxy->Enable(GetProxy()); |
| 81 |
| 82 base::RunLoop run_loop_; |
| 83 run_loop_.RunUntilIdle(); |
| 84 |
| 85 EXPECT_TRUE(themes_sync_proxy->IsConnected()); |
| 86 DisableSync(); |
| 87 } |
| 88 |
| 89 } // namespace syncer |
| OLD | NEW |