OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #ifndef CHROME_BROWSER_SYNC_TEST_ENGINE_SYNCER_COMMAND_TEST_H_ | 5 #ifndef CHROME_BROWSER_SYNC_TEST_ENGINE_SYNCER_COMMAND_TEST_H_ |
6 #define CHROME_BROWSER_SYNC_TEST_ENGINE_SYNCER_COMMAND_TEST_H_ | 6 #define CHROME_BROWSER_SYNC_TEST_ENGINE_SYNCER_COMMAND_TEST_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <string> | 10 #include <string> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
14 #include "chrome/browser/sync/engine/model_safe_worker.h" | 14 #include "chrome/browser/sync/engine/model_safe_worker.h" |
15 #include "chrome/browser/sync/sessions/debug_info_getter.h" | |
16 #include "chrome/browser/sync/sessions/sync_session.h" | 15 #include "chrome/browser/sync/sessions/sync_session.h" |
17 #include "chrome/browser/sync/sessions/sync_session_context.h" | 16 #include "chrome/browser/sync/sessions/sync_session_context.h" |
18 #include "chrome/browser/sync/test/engine/mock_connection_manager.h" | 17 #include "chrome/browser/sync/test/engine/mock_connection_manager.h" |
19 #include "chrome/browser/sync/test/engine/test_directory_setter_upper.h" | 18 #include "chrome/browser/sync/test/engine/test_directory_setter_upper.h" |
20 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
21 #include "testing/gmock/include/gmock/gmock.h" | |
22 | |
23 using ::testing::NiceMock; | |
24 | 20 |
25 namespace browser_sync { | 21 namespace browser_sync { |
26 | 22 |
27 class MockDebugInfoGetter : public browser_sync::sessions::DebugInfoGetter { | |
28 public: | |
29 MockDebugInfoGetter(); | |
30 virtual ~MockDebugInfoGetter(); | |
31 MOCK_METHOD1(GetAndClearDebugInfo, void(sync_pb::DebugInfo* debug_info)); | |
32 }; | |
33 | |
34 // A test fixture that simplifies writing unit tests for individual | 23 // A test fixture that simplifies writing unit tests for individual |
35 // SyncerCommands, providing convenient access to a test directory | 24 // SyncerCommands, providing convenient access to a test directory |
36 // and a syncer session. | 25 // and a syncer session. |
37 template<typename T> | 26 template<typename T> |
38 class SyncerCommandTestWithParam : public testing::TestWithParam<T>, | 27 class SyncerCommandTestWithParam : public testing::TestWithParam<T>, |
39 public sessions::SyncSession::Delegate, | 28 public sessions::SyncSession::Delegate, |
40 public ModelSafeWorkerRegistrar { | 29 public ModelSafeWorkerRegistrar { |
41 public: | 30 public: |
42 enum UseMockDirectory { | 31 enum UseMockDirectory { |
43 USE_MOCK_DIRECTORY | 32 USE_MOCK_DIRECTORY |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 return session_.get(); | 110 return session_.get(); |
122 } | 111 } |
123 | 112 |
124 void ClearSession() { | 113 void ClearSession() { |
125 session_.reset(); | 114 session_.reset(); |
126 } | 115 } |
127 | 116 |
128 void ResetContext() { | 117 void ResetContext() { |
129 context_.reset(new sessions::SyncSessionContext( | 118 context_.reset(new sessions::SyncSessionContext( |
130 mock_server_.get(), syncdb_->manager(), registrar(), | 119 mock_server_.get(), syncdb_->manager(), registrar(), |
131 std::vector<SyncEngineEventListener*>(), &mock_debug_info_getter_)); | 120 std::vector<SyncEngineEventListener*>())); |
132 context_->set_account_name(syncdb_->name()); | 121 context_->set_account_name(syncdb_->name()); |
133 ClearSession(); | 122 ClearSession(); |
134 } | 123 } |
135 | 124 |
136 // Install a MockServerConnection. Resets the context. By default, | 125 // Install a MockServerConnection. Resets the context. By default, |
137 // the context does not have a MockServerConnection attached. | 126 // the context does not have a MockServerConnection attached. |
138 void ConfigureMockServerConnection() { | 127 void ConfigureMockServerConnection() { |
139 mock_server_.reset( | 128 mock_server_.reset( |
140 new MockConnectionManager(syncdb_->manager(), syncdb_->name())); | 129 new MockConnectionManager(syncdb_->manager(), syncdb_->name())); |
141 ResetContext(); | 130 ResetContext(); |
142 } | 131 } |
143 | 132 |
144 std::vector<scoped_refptr<ModelSafeWorker> >* workers() { | 133 std::vector<scoped_refptr<ModelSafeWorker> >* workers() { |
145 return &workers_; | 134 return &workers_; |
146 } | 135 } |
147 | 136 |
148 const ModelSafeRoutingInfo& routing_info() { return routing_info_; } | 137 const ModelSafeRoutingInfo& routing_info() { return routing_info_; } |
149 ModelSafeRoutingInfo* mutable_routing_info() { return &routing_info_; } | 138 ModelSafeRoutingInfo* mutable_routing_info() { return &routing_info_; } |
150 | 139 |
151 MockConnectionManager* mock_server() { | 140 MockConnectionManager* mock_server() { |
152 return mock_server_.get(); | 141 return mock_server_.get(); |
153 } | 142 } |
154 | 143 |
155 MockDebugInfoGetter* mock_debug_info_getter() { | |
156 return &mock_debug_info_getter_; | |
157 } | |
158 | |
159 private: | 144 private: |
160 scoped_ptr<TestDirectorySetterUpper> syncdb_; | 145 scoped_ptr<TestDirectorySetterUpper> syncdb_; |
161 scoped_ptr<sessions::SyncSessionContext> context_; | 146 scoped_ptr<sessions::SyncSessionContext> context_; |
162 scoped_ptr<MockConnectionManager> mock_server_; | 147 scoped_ptr<MockConnectionManager> mock_server_; |
163 scoped_ptr<sessions::SyncSession> session_; | 148 scoped_ptr<sessions::SyncSession> session_; |
164 std::vector<scoped_refptr<ModelSafeWorker> > workers_; | 149 std::vector<scoped_refptr<ModelSafeWorker> > workers_; |
165 ModelSafeRoutingInfo routing_info_; | 150 ModelSafeRoutingInfo routing_info_; |
166 NiceMock<MockDebugInfoGetter> mock_debug_info_getter_; | |
167 DISALLOW_COPY_AND_ASSIGN(SyncerCommandTestWithParam); | 151 DISALLOW_COPY_AND_ASSIGN(SyncerCommandTestWithParam); |
168 }; | 152 }; |
169 | 153 |
170 class SyncerCommandTest : public SyncerCommandTestWithParam<void*> {}; | 154 class SyncerCommandTest : public SyncerCommandTestWithParam<void*> {}; |
171 | 155 |
172 class MockDirectorySyncerCommandTest | 156 class MockDirectorySyncerCommandTest |
173 : public SyncerCommandTestWithParam<void*> { | 157 : public SyncerCommandTestWithParam<void*> { |
174 public: | 158 public: |
175 MockDirectorySyncerCommandTest() | 159 MockDirectorySyncerCommandTest() |
176 : SyncerCommandTestWithParam<void*>( | 160 : SyncerCommandTestWithParam<void*>( |
177 SyncerCommandTestWithParam<void*>::USE_MOCK_DIRECTORY) {} | 161 SyncerCommandTestWithParam<void*>::USE_MOCK_DIRECTORY) {} |
178 MockDirectorySetterUpper::MockDirectory* mock_directory() { | 162 MockDirectorySetterUpper::MockDirectory* mock_directory() { |
179 return static_cast<MockDirectorySetterUpper*>(syncdb())->directory(); | 163 return static_cast<MockDirectorySetterUpper*>(syncdb())->directory(); |
180 } | 164 } |
181 }; | 165 }; |
182 | 166 |
183 } // namespace browser_sync | 167 } // namespace browser_sync |
184 | 168 |
185 #endif // CHROME_BROWSER_SYNC_TEST_ENGINE_SYNCER_COMMAND_TEST_H_ | 169 #endif // CHROME_BROWSER_SYNC_TEST_ENGINE_SYNCER_COMMAND_TEST_H_ |
OLD | NEW |