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/bind.h" | 5 #include "base/bind.h" |
6 #include "base/message_loop/message_loop.h" | 6 #include "base/message_loop/message_loop.h" |
7 #include "base/run_loop.h" | 7 #include "base/run_loop.h" |
8 #include "base/sequenced_task_runner.h" | 8 #include "base/sequenced_task_runner.h" |
9 #include "base/thread_task_runner_handle.h" | 9 #include "base/thread_task_runner_handle.h" |
10 #include "sync/engine/model_type_processor_impl.h" | |
11 #include "sync/internal_api/public/activation_context.h" | 10 #include "sync/internal_api/public/activation_context.h" |
12 #include "sync/internal_api/public/base/model_type.h" | 11 #include "sync/internal_api/public/base/model_type.h" |
| 12 #include "sync/internal_api/public/shared_model_type_processor.h" |
13 #include "sync/internal_api/public/sync_context.h" | 13 #include "sync/internal_api/public/sync_context.h" |
14 #include "sync/internal_api/sync_context_proxy_impl.h" | 14 #include "sync/internal_api/sync_context_proxy_impl.h" |
15 #include "sync/sessions/model_type_registry.h" | 15 #include "sync/sessions/model_type_registry.h" |
16 #include "sync/test/engine/mock_nudge_handler.h" | 16 #include "sync/test/engine/mock_nudge_handler.h" |
17 #include "sync/test/engine/test_directory_setter_upper.h" | 17 #include "sync/test/engine/test_directory_setter_upper.h" |
18 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
19 | 19 |
20 namespace syncer_v2 { | 20 namespace syncer_v2 { |
21 | 21 |
22 class SyncContextProxyImplTest : public ::testing::Test { | 22 class SyncContextProxyImplTest : public ::testing::Test { |
(...skipping 13 matching lines...) Expand all Loading... |
36 void TearDown() override { | 36 void TearDown() override { |
37 context_proxy_.reset(); | 37 context_proxy_.reset(); |
38 registry_.reset(); | 38 registry_.reset(); |
39 dir_maker_.TearDown(); | 39 dir_maker_.TearDown(); |
40 } | 40 } |
41 | 41 |
42 // The sync thread could be shut down at any time without warning. This | 42 // The sync thread could be shut down at any time without warning. This |
43 // function simulates such an event. | 43 // function simulates such an event. |
44 void DisableSync() { registry_.reset(); } | 44 void DisableSync() { registry_.reset(); } |
45 | 45 |
46 void Start(ModelTypeProcessorImpl* processor) { | 46 void Start(SharedModelTypeProcessor* processor) { |
47 processor->Start(base::Bind(&SyncContextProxyImplTest::StartDone, | 47 processor->Start(base::Bind(&SyncContextProxyImplTest::StartDone, |
48 base::Unretained(this))); | 48 base::Unretained(this))); |
49 } | 49 } |
50 | 50 |
51 void StartDone( | 51 void StartDone( |
52 /*syncer::SyncError,*/ scoped_ptr<ActivationContext> context) { | 52 /*syncer::SyncError,*/ scoped_ptr<ActivationContext> context) { |
53 context_proxy_->ConnectTypeToSync(syncer::THEMES, context.Pass()); | 53 context_proxy_->ConnectTypeToSync(syncer::THEMES, context.Pass()); |
54 } | 54 } |
55 | 55 |
56 private: | 56 private: |
57 base::MessageLoop loop_; | 57 base::MessageLoop loop_; |
58 scoped_refptr<base::SequencedTaskRunner> sync_task_runner_; | 58 scoped_refptr<base::SequencedTaskRunner> sync_task_runner_; |
59 scoped_refptr<base::SequencedTaskRunner> type_task_runner_; | 59 scoped_refptr<base::SequencedTaskRunner> type_task_runner_; |
60 | 60 |
61 std::vector<scoped_refptr<syncer::ModelSafeWorker>> workers_; | 61 std::vector<scoped_refptr<syncer::ModelSafeWorker>> workers_; |
62 syncer::TestDirectorySetterUpper dir_maker_; | 62 syncer::TestDirectorySetterUpper dir_maker_; |
63 syncer::MockNudgeHandler nudge_handler_; | 63 syncer::MockNudgeHandler nudge_handler_; |
64 scoped_ptr<syncer::ModelTypeRegistry> registry_; | 64 scoped_ptr<syncer::ModelTypeRegistry> registry_; |
65 | 65 |
66 scoped_ptr<SyncContextProxyImpl> context_proxy_; | 66 scoped_ptr<SyncContextProxyImpl> context_proxy_; |
67 }; | 67 }; |
68 | 68 |
69 // Try to connect a type to a SyncContext that has already shut down. | 69 // Try to connect a type to a SyncContext that has already shut down. |
70 TEST_F(SyncContextProxyImplTest, FailToConnect1) { | 70 TEST_F(SyncContextProxyImplTest, FailToConnect1) { |
71 ModelTypeProcessorImpl processor(syncer::THEMES, | 71 SharedModelTypeProcessor processor(syncer::THEMES, |
72 base::WeakPtr<ModelTypeStore>()); | 72 base::WeakPtr<ModelTypeStore>()); |
73 DisableSync(); | 73 DisableSync(); |
74 Start(&processor); | 74 Start(&processor); |
75 | 75 |
76 base::RunLoop run_loop_; | 76 base::RunLoop run_loop_; |
77 run_loop_.RunUntilIdle(); | 77 run_loop_.RunUntilIdle(); |
78 EXPECT_FALSE(processor.IsConnected()); | 78 EXPECT_FALSE(processor.IsConnected()); |
79 } | 79 } |
80 | 80 |
81 // Try to connect a type to a SyncContext as it shuts down. | 81 // Try to connect a type to a SyncContext as it shuts down. |
82 TEST_F(SyncContextProxyImplTest, FailToConnect2) { | 82 TEST_F(SyncContextProxyImplTest, FailToConnect2) { |
83 ModelTypeProcessorImpl processor(syncer::THEMES, | 83 SharedModelTypeProcessor processor(syncer::THEMES, |
84 base::WeakPtr<ModelTypeStore>()); | 84 base::WeakPtr<ModelTypeStore>()); |
85 Start(&processor); | 85 Start(&processor); |
86 DisableSync(); | 86 DisableSync(); |
87 | 87 |
88 base::RunLoop run_loop_; | 88 base::RunLoop run_loop_; |
89 run_loop_.RunUntilIdle(); | 89 run_loop_.RunUntilIdle(); |
90 EXPECT_FALSE(processor.IsConnected()); | 90 EXPECT_FALSE(processor.IsConnected()); |
91 } | 91 } |
92 | 92 |
93 // Tests the case where the type's sync proxy shuts down first. | 93 // Tests the case where the type's sync proxy shuts down first. |
94 TEST_F(SyncContextProxyImplTest, TypeDisconnectsFirst) { | 94 TEST_F(SyncContextProxyImplTest, TypeDisconnectsFirst) { |
95 scoped_ptr<ModelTypeProcessorImpl> processor(new ModelTypeProcessorImpl( | 95 scoped_ptr<SharedModelTypeProcessor> processor(new SharedModelTypeProcessor( |
96 syncer::THEMES, base::WeakPtr<ModelTypeStore>())); | 96 syncer::THEMES, base::WeakPtr<ModelTypeStore>())); |
97 Start(processor.get()); | 97 Start(processor.get()); |
98 | 98 |
99 base::RunLoop run_loop_; | 99 base::RunLoop run_loop_; |
100 run_loop_.RunUntilIdle(); | 100 run_loop_.RunUntilIdle(); |
101 | 101 |
102 EXPECT_TRUE(processor->IsConnected()); | 102 EXPECT_TRUE(processor->IsConnected()); |
103 processor.reset(); | 103 processor.reset(); |
104 } | 104 } |
105 | 105 |
106 // Tests the case where the sync thread shuts down first. | 106 // Tests the case where the sync thread shuts down first. |
107 TEST_F(SyncContextProxyImplTest, SyncDisconnectsFirst) { | 107 TEST_F(SyncContextProxyImplTest, SyncDisconnectsFirst) { |
108 scoped_ptr<ModelTypeProcessorImpl> processor(new ModelTypeProcessorImpl( | 108 scoped_ptr<SharedModelTypeProcessor> processor(new SharedModelTypeProcessor( |
109 syncer::THEMES, base::WeakPtr<ModelTypeStore>())); | 109 syncer::THEMES, base::WeakPtr<ModelTypeStore>())); |
110 Start(processor.get()); | 110 Start(processor.get()); |
111 | 111 |
112 base::RunLoop run_loop_; | 112 base::RunLoop run_loop_; |
113 run_loop_.RunUntilIdle(); | 113 run_loop_.RunUntilIdle(); |
114 | 114 |
115 EXPECT_TRUE(processor->IsConnected()); | 115 EXPECT_TRUE(processor->IsConnected()); |
116 DisableSync(); | 116 DisableSync(); |
117 } | 117 } |
118 | 118 |
119 } // namespace syncer | 119 } // namespace syncer |
OLD | NEW |