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 "base/message_loop/message_loop.h" | 5 #include "base/message_loop/message_loop.h" |
6 #include "base/run_loop.h" | 6 #include "base/run_loop.h" |
7 #include "base/sequenced_task_runner.h" | 7 #include "base/sequenced_task_runner.h" |
8 #include "base/thread_task_runner_handle.h" | 8 #include "base/thread_task_runner_handle.h" |
9 #include "sync/engine/model_type_sync_proxy_impl.h" | 9 #include "sync/engine/model_type_sync_proxy_impl.h" |
10 #include "sync/internal_api/public/base/model_type.h" | 10 #include "sync/internal_api/public/base/model_type.h" |
11 #include "sync/internal_api/public/sync_context.h" | 11 #include "sync/internal_api/public/sync_context.h" |
12 #include "sync/internal_api/sync_context_proxy_impl.h" | 12 #include "sync/internal_api/sync_context_proxy_impl.h" |
13 #include "sync/sessions/model_type_registry.h" | 13 #include "sync/sessions/model_type_registry.h" |
| 14 #include "sync/test/engine/mock_nudge_handler.h" |
| 15 #include "sync/test/engine/test_directory_setter_upper.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
15 | 17 |
16 namespace syncer { | 18 namespace syncer { |
17 | 19 |
18 class SyncContextProxyImplTest : public ::testing::Test { | 20 class SyncContextProxyImplTest : public ::testing::Test { |
19 public: | 21 public: |
20 SyncContextProxyImplTest() | 22 SyncContextProxyImplTest() |
21 : sync_task_runner_(base::ThreadTaskRunnerHandle::Get()), | 23 : sync_task_runner_(base::ThreadTaskRunnerHandle::Get()), |
22 type_task_runner_(base::ThreadTaskRunnerHandle::Get()), | 24 type_task_runner_(base::ThreadTaskRunnerHandle::Get()) {} |
23 registry_(new ModelTypeRegistry()), | 25 |
24 context_proxy_(sync_task_runner_, registry_->AsWeakPtr()) {} | 26 virtual void SetUp() { |
| 27 dir_maker_.SetUp(); |
| 28 registry_.reset(new ModelTypeRegistry( |
| 29 workers_, dir_maker_.directory(), &nudge_handler_)); |
| 30 context_proxy_.reset( |
| 31 new SyncContextProxyImpl(sync_task_runner_, registry_->AsWeakPtr())); |
| 32 } |
| 33 |
| 34 virtual void TearDown() { |
| 35 context_proxy_.reset(); |
| 36 registry_.reset(); |
| 37 dir_maker_.TearDown(); |
| 38 } |
25 | 39 |
26 // The sync thread could be shut down at any time without warning. This | 40 // The sync thread could be shut down at any time without warning. This |
27 // function simulates such an event. | 41 // function simulates such an event. |
28 void DisableSync() { registry_.reset(); } | 42 void DisableSync() { registry_.reset(); } |
29 | 43 |
30 scoped_ptr<SyncContextProxy> GetProxy() { return context_proxy_.Clone(); } | 44 scoped_ptr<SyncContextProxy> GetProxy() { return context_proxy_->Clone(); } |
31 | 45 |
32 private: | 46 private: |
33 base::MessageLoop loop_; | 47 base::MessageLoop loop_; |
34 scoped_refptr<base::SequencedTaskRunner> sync_task_runner_; | 48 scoped_refptr<base::SequencedTaskRunner> sync_task_runner_; |
35 scoped_refptr<base::SequencedTaskRunner> type_task_runner_; | 49 scoped_refptr<base::SequencedTaskRunner> type_task_runner_; |
| 50 |
| 51 std::vector<scoped_refptr<ModelSafeWorker> > workers_; |
| 52 TestDirectorySetterUpper dir_maker_; |
| 53 MockNudgeHandler nudge_handler_; |
36 scoped_ptr<ModelTypeRegistry> registry_; | 54 scoped_ptr<ModelTypeRegistry> registry_; |
37 SyncContextProxyImpl context_proxy_; | 55 |
| 56 scoped_ptr<SyncContextProxyImpl> context_proxy_; |
38 }; | 57 }; |
39 | 58 |
40 // Try to connect a type to a SyncContext that has already shut down. | 59 // Try to connect a type to a SyncContext that has already shut down. |
41 TEST_F(SyncContextProxyImplTest, FailToConnect1) { | 60 TEST_F(SyncContextProxyImplTest, FailToConnect1) { |
42 ModelTypeSyncProxyImpl themes_sync_proxy(syncer::THEMES); | 61 ModelTypeSyncProxyImpl themes_sync_proxy(syncer::THEMES); |
43 DisableSync(); | 62 DisableSync(); |
44 themes_sync_proxy.Enable(GetProxy()); | 63 themes_sync_proxy.Enable(GetProxy()); |
45 | 64 |
46 base::RunLoop run_loop_; | 65 base::RunLoop run_loop_; |
47 run_loop_.RunUntilIdle(); | 66 run_loop_.RunUntilIdle(); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 themes_sync_proxy->Enable(GetProxy()); | 98 themes_sync_proxy->Enable(GetProxy()); |
80 | 99 |
81 base::RunLoop run_loop_; | 100 base::RunLoop run_loop_; |
82 run_loop_.RunUntilIdle(); | 101 run_loop_.RunUntilIdle(); |
83 | 102 |
84 EXPECT_TRUE(themes_sync_proxy->IsConnected()); | 103 EXPECT_TRUE(themes_sync_proxy->IsConnected()); |
85 DisableSync(); | 104 DisableSync(); |
86 } | 105 } |
87 | 106 |
88 } // namespace syncer | 107 } // namespace syncer |
OLD | NEW |