| 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 "base/memory/ref_counted.h" | |
| 15 #include "base/message_loop.h" | 14 #include "base/message_loop.h" |
| 16 #include "chrome/browser/sync/engine/model_changing_syncer_command.h" | |
| 17 #include "chrome/browser/sync/engine/model_safe_worker.h" | 15 #include "chrome/browser/sync/engine/model_safe_worker.h" |
| 18 #include "chrome/browser/sync/sessions/debug_info_getter.h" | 16 #include "chrome/browser/sync/sessions/debug_info_getter.h" |
| 19 #include "chrome/browser/sync/sessions/sync_session.h" | 17 #include "chrome/browser/sync/sessions/sync_session.h" |
| 20 #include "chrome/browser/sync/sessions/sync_session_context.h" | 18 #include "chrome/browser/sync/sessions/sync_session_context.h" |
| 21 #include "chrome/browser/sync/test/engine/mock_connection_manager.h" | 19 #include "chrome/browser/sync/test/engine/mock_connection_manager.h" |
| 22 #include "chrome/browser/sync/test/engine/fake_model_worker.h" | |
| 23 #include "chrome/browser/sync/test/engine/test_directory_setter_upper.h" | 20 #include "chrome/browser/sync/test/engine/test_directory_setter_upper.h" |
| 24 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
| 25 #include "testing/gmock/include/gmock/gmock.h" | 22 #include "testing/gmock/include/gmock/gmock.h" |
| 26 | 23 |
| 27 using ::testing::NiceMock; | 24 using ::testing::NiceMock; |
| 28 | 25 |
| 29 namespace browser_sync { | 26 namespace browser_sync { |
| 30 | 27 |
| 31 class MockDebugInfoGetter : public browser_sync::sessions::DebugInfoGetter { | 28 class MockDebugInfoGetter : public browser_sync::sessions::DebugInfoGetter { |
| 32 public: | 29 public: |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 protected: | 86 protected: |
| 90 SyncerCommandTestWithParam() : syncdb_(new TestDirectorySetterUpper()) {} | 87 SyncerCommandTestWithParam() : syncdb_(new TestDirectorySetterUpper()) {} |
| 91 | 88 |
| 92 explicit SyncerCommandTestWithParam(UseMockDirectory use_mock) | 89 explicit SyncerCommandTestWithParam(UseMockDirectory use_mock) |
| 93 : syncdb_(new MockDirectorySetterUpper()) {} | 90 : syncdb_(new MockDirectorySetterUpper()) {} |
| 94 | 91 |
| 95 virtual ~SyncerCommandTestWithParam() {} | 92 virtual ~SyncerCommandTestWithParam() {} |
| 96 virtual void SetUp() { | 93 virtual void SetUp() { |
| 97 syncdb_->SetUp(); | 94 syncdb_->SetUp(); |
| 98 ResetContext(); | 95 ResetContext(); |
| 99 // The session always expects there to be a passive worker. | |
| 100 workers()->push_back( | |
| 101 make_scoped_refptr(new FakeModelWorker(GROUP_PASSIVE))); | |
| 102 } | 96 } |
| 103 virtual void TearDown() { | 97 virtual void TearDown() { |
| 104 syncdb_->TearDown(); | 98 syncdb_->TearDown(); |
| 105 } | 99 } |
| 106 | 100 |
| 107 TestDirectorySetterUpper* syncdb() { return syncdb_.get(); } | 101 TestDirectorySetterUpper* syncdb() { return syncdb_.get(); } |
| 108 sessions::SyncSessionContext* context() const { return context_.get(); } | 102 sessions::SyncSessionContext* context() const { return context_.get(); } |
| 109 sessions::SyncSession::Delegate* delegate() { return this; } | 103 sessions::SyncSession::Delegate* delegate() { return this; } |
| 110 ModelSafeWorkerRegistrar* registrar() { return this; } | 104 ModelSafeWorkerRegistrar* registrar() { return this; } |
| 111 | 105 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 ModelSafeRoutingInfo* mutable_routing_info() { return &routing_info_; } | 150 ModelSafeRoutingInfo* mutable_routing_info() { return &routing_info_; } |
| 157 | 151 |
| 158 MockConnectionManager* mock_server() { | 152 MockConnectionManager* mock_server() { |
| 159 return mock_server_.get(); | 153 return mock_server_.get(); |
| 160 } | 154 } |
| 161 | 155 |
| 162 MockDebugInfoGetter* mock_debug_info_getter() { | 156 MockDebugInfoGetter* mock_debug_info_getter() { |
| 163 return &mock_debug_info_getter_; | 157 return &mock_debug_info_getter_; |
| 164 } | 158 } |
| 165 | 159 |
| 166 // Helper functions to check command.GetGroupsToChange(). | |
| 167 | |
| 168 void ExpectNoGroupsToChange(const ModelChangingSyncerCommand& command) { | |
| 169 EXPECT_TRUE(command.GetGroupsToChangeForTest(*session()).empty()); | |
| 170 } | |
| 171 | |
| 172 void ExpectGroupToChange( | |
| 173 const ModelChangingSyncerCommand& command, ModelSafeGroup group) { | |
| 174 std::set<ModelSafeGroup> expected_groups_to_change; | |
| 175 expected_groups_to_change.insert(group); | |
| 176 EXPECT_EQ(expected_groups_to_change, | |
| 177 command.GetGroupsToChangeForTest(*session())); | |
| 178 } | |
| 179 | |
| 180 void ExpectGroupsToChange( | |
| 181 const ModelChangingSyncerCommand& command, | |
| 182 ModelSafeGroup group1, ModelSafeGroup group2) { | |
| 183 std::set<ModelSafeGroup> expected_groups_to_change; | |
| 184 expected_groups_to_change.insert(group1); | |
| 185 expected_groups_to_change.insert(group2); | |
| 186 EXPECT_EQ(expected_groups_to_change, | |
| 187 command.GetGroupsToChangeForTest(*session())); | |
| 188 } | |
| 189 | |
| 190 void ExpectGroupsToChange( | |
| 191 const ModelChangingSyncerCommand& command, | |
| 192 ModelSafeGroup group1, ModelSafeGroup group2, ModelSafeGroup group3) { | |
| 193 std::set<ModelSafeGroup> expected_groups_to_change; | |
| 194 expected_groups_to_change.insert(group1); | |
| 195 expected_groups_to_change.insert(group2); | |
| 196 expected_groups_to_change.insert(group3); | |
| 197 EXPECT_EQ(expected_groups_to_change, | |
| 198 command.GetGroupsToChangeForTest(*session())); | |
| 199 } | |
| 200 | |
| 201 private: | 160 private: |
| 202 MessageLoop message_loop_; | 161 MessageLoop message_loop_; |
| 203 scoped_ptr<TestDirectorySetterUpper> syncdb_; | 162 scoped_ptr<TestDirectorySetterUpper> syncdb_; |
| 204 scoped_ptr<sessions::SyncSessionContext> context_; | 163 scoped_ptr<sessions::SyncSessionContext> context_; |
| 205 scoped_ptr<MockConnectionManager> mock_server_; | 164 scoped_ptr<MockConnectionManager> mock_server_; |
| 206 scoped_ptr<sessions::SyncSession> session_; | 165 scoped_ptr<sessions::SyncSession> session_; |
| 207 std::vector<scoped_refptr<ModelSafeWorker> > workers_; | 166 std::vector<scoped_refptr<ModelSafeWorker> > workers_; |
| 208 ModelSafeRoutingInfo routing_info_; | 167 ModelSafeRoutingInfo routing_info_; |
| 209 NiceMock<MockDebugInfoGetter> mock_debug_info_getter_; | 168 NiceMock<MockDebugInfoGetter> mock_debug_info_getter_; |
| 210 DISALLOW_COPY_AND_ASSIGN(SyncerCommandTestWithParam); | 169 DISALLOW_COPY_AND_ASSIGN(SyncerCommandTestWithParam); |
| 211 }; | 170 }; |
| 212 | 171 |
| 213 class SyncerCommandTest : public SyncerCommandTestWithParam<void*> {}; | 172 class SyncerCommandTest : public SyncerCommandTestWithParam<void*> {}; |
| 214 | 173 |
| 215 class MockDirectorySyncerCommandTest | 174 class MockDirectorySyncerCommandTest |
| 216 : public SyncerCommandTestWithParam<void*> { | 175 : public SyncerCommandTestWithParam<void*> { |
| 217 public: | 176 public: |
| 218 MockDirectorySyncerCommandTest() | 177 MockDirectorySyncerCommandTest() |
| 219 : SyncerCommandTestWithParam<void*>( | 178 : SyncerCommandTestWithParam<void*>( |
| 220 SyncerCommandTestWithParam<void*>::USE_MOCK_DIRECTORY) {} | 179 SyncerCommandTestWithParam<void*>::USE_MOCK_DIRECTORY) {} |
| 221 MockDirectorySetterUpper::MockDirectory* mock_directory() { | 180 MockDirectorySetterUpper::MockDirectory* mock_directory() { |
| 222 return static_cast<MockDirectorySetterUpper*>(syncdb())->directory(); | 181 return static_cast<MockDirectorySetterUpper*>(syncdb())->directory(); |
| 223 } | 182 } |
| 224 }; | 183 }; |
| 225 | 184 |
| 226 } // namespace browser_sync | 185 } // namespace browser_sync |
| 227 | 186 |
| 228 #endif // CHROME_BROWSER_SYNC_TEST_ENGINE_SYNCER_COMMAND_TEST_H_ | 187 #endif // CHROME_BROWSER_SYNC_TEST_ENGINE_SYNCER_COMMAND_TEST_H_ |
| OLD | NEW |