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