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