OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "components/sync_driver/backend_migrator.h" | 5 #include "components/sync/driver/backend_migrator.h" |
6 | 6 |
7 #include "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
9 #include "base/tracked_objects.h" | 9 #include "base/tracked_objects.h" |
10 #include "components/sync/base/model_type_test_util.h" | 10 #include "components/sync/base/model_type_test_util.h" |
11 #include "components/sync/core/test/test_user_share.h" | 11 #include "components/sync/core/test/test_user_share.h" |
12 #include "components/sync/core/write_transaction.h" | 12 #include "components/sync/core/write_transaction.h" |
| 13 #include "components/sync/driver/data_type_manager_mock.h" |
| 14 #include "components/sync/driver/fake_sync_service.h" |
13 #include "components/sync/protocol/sync.pb.h" | 15 #include "components/sync/protocol/sync.pb.h" |
14 #include "components/sync/syncable/directory.h" // TODO(tim): Remove. Bug 13113
0. | 16 #include "components/sync/syncable/directory.h" // TODO(tim): Remove. Bug 13113
0. |
15 #include "components/sync_driver/data_type_manager_mock.h" | |
16 #include "components/sync_driver/fake_sync_service.h" | |
17 #include "testing/gmock/include/gmock/gmock.h" | 17 #include "testing/gmock/include/gmock/gmock.h" |
18 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
19 | 19 |
20 using ::testing::_; | 20 using ::testing::_; |
21 using ::testing::Eq; | 21 using ::testing::Eq; |
22 using ::testing::Mock; | 22 using ::testing::Mock; |
23 using ::testing::NiceMock; | 23 using ::testing::NiceMock; |
24 using ::testing::Return; | 24 using ::testing::Return; |
25 using sync_driver::DataTypeManager; | 25 using sync_driver::DataTypeManager; |
26 using sync_driver::DataTypeManagerMock; | 26 using sync_driver::DataTypeManagerMock; |
27 | 27 |
28 namespace browser_sync { | 28 namespace browser_sync { |
29 | 29 |
30 using syncer::sessions::SyncSessionSnapshot; | 30 using syncer::sessions::SyncSessionSnapshot; |
31 | 31 |
32 class SyncBackendMigratorTest : public testing::Test { | 32 class SyncBackendMigratorTest : public testing::Test { |
33 public: | 33 public: |
34 SyncBackendMigratorTest() { } | 34 SyncBackendMigratorTest() {} |
35 virtual ~SyncBackendMigratorTest() { } | 35 virtual ~SyncBackendMigratorTest() {} |
36 | 36 |
37 virtual void SetUp() { | 37 virtual void SetUp() { |
38 test_user_share_.SetUp(); | 38 test_user_share_.SetUp(); |
39 Mock::VerifyAndClear(manager()); | 39 Mock::VerifyAndClear(manager()); |
40 preferred_types_.Put(syncer::BOOKMARKS); | 40 preferred_types_.Put(syncer::BOOKMARKS); |
41 preferred_types_.Put(syncer::PREFERENCES); | 41 preferred_types_.Put(syncer::PREFERENCES); |
42 preferred_types_.Put(syncer::AUTOFILL); | 42 preferred_types_.Put(syncer::AUTOFILL); |
43 | 43 |
44 migrator_.reset( | 44 migrator_.reset(new BackendMigrator("Profile0", |
45 new BackendMigrator( | 45 test_user_share_.user_share(), |
46 "Profile0", test_user_share_.user_share(), service(), manager(), | 46 service(), manager(), base::Closure())); |
47 base::Closure())); | |
48 SetUnsyncedTypes(syncer::ModelTypeSet()); | 47 SetUnsyncedTypes(syncer::ModelTypeSet()); |
49 } | 48 } |
50 | 49 |
51 virtual void TearDown() { | 50 virtual void TearDown() { |
52 migrator_.reset(); | 51 migrator_.reset(); |
53 test_user_share_.TearDown(); | 52 test_user_share_.TearDown(); |
54 } | 53 } |
55 | 54 |
56 // Marks all types in |unsynced_types| as unsynced and all other | 55 // Marks all types in |unsynced_types| as unsynced and all other |
57 // types as synced. | 56 // types as synced. |
58 void SetUnsyncedTypes(syncer::ModelTypeSet unsynced_types) { | 57 void SetUnsyncedTypes(syncer::ModelTypeSet unsynced_types) { |
59 syncer::WriteTransaction trans(FROM_HERE, | 58 syncer::WriteTransaction trans(FROM_HERE, test_user_share_.user_share()); |
60 test_user_share_.user_share()); | 59 for (int i = syncer::FIRST_REAL_MODEL_TYPE; i < syncer::MODEL_TYPE_COUNT; |
61 for (int i = syncer::FIRST_REAL_MODEL_TYPE; | 60 ++i) { |
62 i < syncer::MODEL_TYPE_COUNT; ++i) { | |
63 syncer::ModelType type = syncer::ModelTypeFromInt(i); | 61 syncer::ModelType type = syncer::ModelTypeFromInt(i); |
64 sync_pb::DataTypeProgressMarker progress_marker; | 62 sync_pb::DataTypeProgressMarker progress_marker; |
65 if (!unsynced_types.Has(type)) { | 63 if (!unsynced_types.Has(type)) { |
66 progress_marker.set_token("dummy"); | 64 progress_marker.set_token("dummy"); |
67 } | 65 } |
68 trans.GetDirectory()->SetDownloadProgress(type, progress_marker); | 66 trans.GetDirectory()->SetDownloadProgress(type, progress_marker); |
69 } | 67 } |
70 } | 68 } |
71 | 69 |
72 void SendConfigureDone(DataTypeManager::ConfigureStatus status, | 70 void SendConfigureDone(DataTypeManager::ConfigureStatus status, |
73 syncer::ModelTypeSet requested_types) { | 71 syncer::ModelTypeSet requested_types) { |
74 if (status == DataTypeManager::OK) { | 72 if (status == DataTypeManager::OK) { |
75 DataTypeManager::ConfigureResult result(status, requested_types); | 73 DataTypeManager::ConfigureResult result(status, requested_types); |
76 migrator_->OnConfigureDone(result); | 74 migrator_->OnConfigureDone(result); |
77 } else { | 75 } else { |
78 DataTypeManager::ConfigureResult result( | 76 DataTypeManager::ConfigureResult result(status, requested_types); |
79 status, | |
80 requested_types); | |
81 migrator_->OnConfigureDone(result); | 77 migrator_->OnConfigureDone(result); |
82 } | 78 } |
83 base::RunLoop run_loop; | 79 base::RunLoop run_loop; |
84 run_loop.RunUntilIdle(); | 80 run_loop.RunUntilIdle(); |
85 } | 81 } |
86 | 82 |
87 sync_driver::SyncService* service() { return &service_; } | 83 sync_driver::SyncService* service() { return &service_; } |
88 DataTypeManagerMock* manager() { return &manager_; } | 84 DataTypeManagerMock* manager() { return &manager_; } |
89 syncer::ModelTypeSet preferred_types() { return preferred_types_; } | 85 syncer::ModelTypeSet preferred_types() { return preferred_types_; } |
90 BackendMigrator* migrator() { return migrator_.get(); } | 86 BackendMigrator* migrator() { return migrator_.get(); } |
(...skipping 24 matching lines...) Expand all Loading... |
115 migrator()->AddMigrationObserver(&migration_observer); | 111 migrator()->AddMigrationObserver(&migration_observer); |
116 EXPECT_CALL(migration_observer, OnMigrationStateChange()).Times(4); | 112 EXPECT_CALL(migration_observer, OnMigrationStateChange()).Times(4); |
117 | 113 |
118 syncer::ModelTypeSet to_migrate, difference; | 114 syncer::ModelTypeSet to_migrate, difference; |
119 to_migrate.Put(syncer::PREFERENCES); | 115 to_migrate.Put(syncer::PREFERENCES); |
120 difference.Put(syncer::AUTOFILL); | 116 difference.Put(syncer::AUTOFILL); |
121 difference.Put(syncer::BOOKMARKS); | 117 difference.Put(syncer::BOOKMARKS); |
122 | 118 |
123 EXPECT_CALL(*manager(), state()) | 119 EXPECT_CALL(*manager(), state()) |
124 .WillOnce(Return(DataTypeManager::CONFIGURED)); | 120 .WillOnce(Return(DataTypeManager::CONFIGURED)); |
125 EXPECT_CALL( | 121 EXPECT_CALL(*manager(), |
126 *manager(), | 122 PurgeForMigration(_, syncer::CONFIGURE_REASON_MIGRATION)) |
127 PurgeForMigration(_, syncer::CONFIGURE_REASON_MIGRATION)).Times(1); | 123 .Times(1); |
128 EXPECT_CALL( | 124 EXPECT_CALL(*manager(), Configure(_, syncer::CONFIGURE_REASON_MIGRATION)) |
129 *manager(), | 125 .Times(1); |
130 Configure(_, syncer::CONFIGURE_REASON_MIGRATION)).Times(1); | |
131 | 126 |
132 migrator()->MigrateTypes(to_migrate); | 127 migrator()->MigrateTypes(to_migrate); |
133 EXPECT_EQ(BackendMigrator::DISABLING_TYPES, migrator()->state()); | 128 EXPECT_EQ(BackendMigrator::DISABLING_TYPES, migrator()->state()); |
134 | 129 |
135 SetUnsyncedTypes(to_migrate); | 130 SetUnsyncedTypes(to_migrate); |
136 SendConfigureDone(DataTypeManager::OK, difference); | 131 SendConfigureDone(DataTypeManager::OK, difference); |
137 EXPECT_EQ(BackendMigrator::REENABLING_TYPES, migrator()->state()); | 132 EXPECT_EQ(BackendMigrator::REENABLING_TYPES, migrator()->state()); |
138 | 133 |
139 SetUnsyncedTypes(syncer::ModelTypeSet()); | 134 SetUnsyncedTypes(syncer::ModelTypeSet()); |
140 SendConfigureDone(DataTypeManager::OK, preferred_types()); | 135 SendConfigureDone(DataTypeManager::OK, preferred_types()); |
141 EXPECT_EQ(BackendMigrator::IDLE, migrator()->state()); | 136 EXPECT_EQ(BackendMigrator::IDLE, migrator()->state()); |
142 | 137 |
143 migrator()->RemoveMigrationObserver(&migration_observer); | 138 migrator()->RemoveMigrationObserver(&migration_observer); |
144 } | 139 } |
145 | 140 |
146 // Test that in the normal case with Nigori a migration transitions through | 141 // Test that in the normal case with Nigori a migration transitions through |
147 // each state and wind up back in IDLE. | 142 // each state and wind up back in IDLE. |
148 TEST_F(SyncBackendMigratorTest, MigrateNigori) { | 143 TEST_F(SyncBackendMigratorTest, MigrateNigori) { |
149 syncer::ModelTypeSet to_migrate, difference; | 144 syncer::ModelTypeSet to_migrate, difference; |
150 to_migrate.Put(syncer::NIGORI); | 145 to_migrate.Put(syncer::NIGORI); |
151 difference.Put(syncer::AUTOFILL); | 146 difference.Put(syncer::AUTOFILL); |
152 difference.Put(syncer::BOOKMARKS); | 147 difference.Put(syncer::BOOKMARKS); |
153 | 148 |
154 EXPECT_CALL(*manager(), state()) | 149 EXPECT_CALL(*manager(), state()) |
155 .WillOnce(Return(DataTypeManager::CONFIGURED)); | 150 .WillOnce(Return(DataTypeManager::CONFIGURED)); |
156 | 151 |
157 EXPECT_CALL(*manager(), PurgeForMigration(_, | 152 EXPECT_CALL(*manager(), |
158 syncer::CONFIGURE_REASON_MIGRATION)); | 153 PurgeForMigration(_, syncer::CONFIGURE_REASON_MIGRATION)); |
159 | 154 |
160 migrator()->MigrateTypes(to_migrate); | 155 migrator()->MigrateTypes(to_migrate); |
161 EXPECT_EQ(BackendMigrator::DISABLING_TYPES, migrator()->state()); | 156 EXPECT_EQ(BackendMigrator::DISABLING_TYPES, migrator()->state()); |
162 | 157 |
163 SetUnsyncedTypes(to_migrate); | 158 SetUnsyncedTypes(to_migrate); |
164 SendConfigureDone(DataTypeManager::OK, difference); | 159 SendConfigureDone(DataTypeManager::OK, difference); |
165 EXPECT_EQ(BackendMigrator::REENABLING_TYPES, migrator()->state()); | 160 EXPECT_EQ(BackendMigrator::REENABLING_TYPES, migrator()->state()); |
166 | 161 |
167 SetUnsyncedTypes(syncer::ModelTypeSet()); | 162 SetUnsyncedTypes(syncer::ModelTypeSet()); |
168 SendConfigureDone(DataTypeManager::OK, preferred_types()); | 163 SendConfigureDone(DataTypeManager::OK, preferred_types()); |
169 EXPECT_EQ(BackendMigrator::IDLE, migrator()->state()); | 164 EXPECT_EQ(BackendMigrator::IDLE, migrator()->state()); |
170 } | 165 } |
171 | 166 |
172 | |
173 // Test that the migrator waits for the data type manager to be idle before | 167 // Test that the migrator waits for the data type manager to be idle before |
174 // starting a migration. | 168 // starting a migration. |
175 TEST_F(SyncBackendMigratorTest, WaitToStart) { | 169 TEST_F(SyncBackendMigratorTest, WaitToStart) { |
176 syncer::ModelTypeSet to_migrate; | 170 syncer::ModelTypeSet to_migrate; |
177 to_migrate.Put(syncer::PREFERENCES); | 171 to_migrate.Put(syncer::PREFERENCES); |
178 | 172 |
179 EXPECT_CALL(*manager(), state()) | 173 EXPECT_CALL(*manager(), state()) |
180 .WillOnce(Return(DataTypeManager::CONFIGURING)); | 174 .WillOnce(Return(DataTypeManager::CONFIGURING)); |
181 EXPECT_CALL(*manager(), Configure(_, _)).Times(0); | 175 EXPECT_CALL(*manager(), Configure(_, _)).Times(0); |
182 migrator()->MigrateTypes(to_migrate); | 176 migrator()->MigrateTypes(to_migrate); |
(...skipping 15 matching lines...) Expand all Loading... |
198 TEST_F(SyncBackendMigratorTest, RestartMigration) { | 192 TEST_F(SyncBackendMigratorTest, RestartMigration) { |
199 syncer::ModelTypeSet to_migrate1, to_migrate2, to_migrate_union, bookmarks; | 193 syncer::ModelTypeSet to_migrate1, to_migrate2, to_migrate_union, bookmarks; |
200 to_migrate1.Put(syncer::PREFERENCES); | 194 to_migrate1.Put(syncer::PREFERENCES); |
201 to_migrate2.Put(syncer::AUTOFILL); | 195 to_migrate2.Put(syncer::AUTOFILL); |
202 to_migrate_union.Put(syncer::PREFERENCES); | 196 to_migrate_union.Put(syncer::PREFERENCES); |
203 to_migrate_union.Put(syncer::AUTOFILL); | 197 to_migrate_union.Put(syncer::AUTOFILL); |
204 bookmarks.Put(syncer::BOOKMARKS); | 198 bookmarks.Put(syncer::BOOKMARKS); |
205 | 199 |
206 EXPECT_CALL(*manager(), state()) | 200 EXPECT_CALL(*manager(), state()) |
207 .WillOnce(Return(DataTypeManager::CONFIGURED)); | 201 .WillOnce(Return(DataTypeManager::CONFIGURED)); |
208 EXPECT_CALL( | 202 EXPECT_CALL(*manager(), |
209 *manager(), | 203 PurgeForMigration(_, syncer::CONFIGURE_REASON_MIGRATION)) |
210 PurgeForMigration(_, syncer::CONFIGURE_REASON_MIGRATION)).Times(2); | 204 .Times(2); |
211 migrator()->MigrateTypes(to_migrate1); | 205 migrator()->MigrateTypes(to_migrate1); |
212 | 206 |
213 EXPECT_EQ(BackendMigrator::DISABLING_TYPES, migrator()->state()); | 207 EXPECT_EQ(BackendMigrator::DISABLING_TYPES, migrator()->state()); |
214 migrator()->MigrateTypes(to_migrate2); | 208 migrator()->MigrateTypes(to_migrate2); |
215 | 209 |
216 const syncer::ModelTypeSet difference1 = | 210 const syncer::ModelTypeSet difference1 = |
217 Difference(preferred_types(), to_migrate1); | 211 Difference(preferred_types(), to_migrate1); |
218 | 212 |
219 Mock::VerifyAndClearExpectations(manager()); | 213 Mock::VerifyAndClearExpectations(manager()); |
220 EXPECT_CALL( | 214 EXPECT_CALL(*manager(), |
221 *manager(), | 215 PurgeForMigration(_, syncer::CONFIGURE_REASON_MIGRATION)) |
222 PurgeForMigration(_, syncer::CONFIGURE_REASON_MIGRATION)).Times(1); | 216 .Times(1); |
223 EXPECT_CALL(*manager(), Configure(_, syncer::CONFIGURE_REASON_MIGRATION)) | 217 EXPECT_CALL(*manager(), Configure(_, syncer::CONFIGURE_REASON_MIGRATION)) |
224 .Times(1); | 218 .Times(1); |
225 SetUnsyncedTypes(to_migrate1); | 219 SetUnsyncedTypes(to_migrate1); |
226 SendConfigureDone(DataTypeManager::OK, difference1); | 220 SendConfigureDone(DataTypeManager::OK, difference1); |
227 EXPECT_EQ(BackendMigrator::DISABLING_TYPES, migrator()->state()); | 221 EXPECT_EQ(BackendMigrator::DISABLING_TYPES, migrator()->state()); |
228 | 222 |
229 SetUnsyncedTypes(to_migrate_union); | 223 SetUnsyncedTypes(to_migrate_union); |
230 SendConfigureDone(DataTypeManager::OK, bookmarks); | 224 SendConfigureDone(DataTypeManager::OK, bookmarks); |
231 EXPECT_EQ(BackendMigrator::REENABLING_TYPES, migrator()->state()); | 225 EXPECT_EQ(BackendMigrator::REENABLING_TYPES, migrator()->state()); |
232 } | 226 } |
233 | 227 |
234 // Test that an external invocation of Configure(...) during a migration results | 228 // Test that an external invocation of Configure(...) during a migration results |
235 // in a migration reattempt. | 229 // in a migration reattempt. |
236 TEST_F(SyncBackendMigratorTest, InterruptedWhileDisablingTypes) { | 230 TEST_F(SyncBackendMigratorTest, InterruptedWhileDisablingTypes) { |
237 syncer::ModelTypeSet to_migrate; | 231 syncer::ModelTypeSet to_migrate; |
238 syncer::ModelTypeSet difference; | 232 syncer::ModelTypeSet difference; |
239 to_migrate.Put(syncer::PREFERENCES); | 233 to_migrate.Put(syncer::PREFERENCES); |
240 difference.Put(syncer::AUTOFILL); | 234 difference.Put(syncer::AUTOFILL); |
241 difference.Put(syncer::BOOKMARKS); | 235 difference.Put(syncer::BOOKMARKS); |
242 | 236 |
243 EXPECT_CALL(*manager(), state()) | 237 EXPECT_CALL(*manager(), state()) |
244 .WillOnce(Return(DataTypeManager::CONFIGURED)); | 238 .WillOnce(Return(DataTypeManager::CONFIGURED)); |
245 EXPECT_CALL(*manager(), PurgeForMigration(HasModelTypes(to_migrate), | 239 EXPECT_CALL(*manager(), |
246 syncer::CONFIGURE_REASON_MIGRATION)); | 240 PurgeForMigration(HasModelTypes(to_migrate), |
| 241 syncer::CONFIGURE_REASON_MIGRATION)); |
247 migrator()->MigrateTypes(to_migrate); | 242 migrator()->MigrateTypes(to_migrate); |
248 EXPECT_EQ(BackendMigrator::DISABLING_TYPES, migrator()->state()); | 243 EXPECT_EQ(BackendMigrator::DISABLING_TYPES, migrator()->state()); |
249 | 244 |
250 Mock::VerifyAndClearExpectations(manager()); | 245 Mock::VerifyAndClearExpectations(manager()); |
251 EXPECT_CALL(*manager(), PurgeForMigration(HasModelTypes(to_migrate), | 246 EXPECT_CALL(*manager(), |
252 syncer::CONFIGURE_REASON_MIGRATION)); | 247 PurgeForMigration(HasModelTypes(to_migrate), |
| 248 syncer::CONFIGURE_REASON_MIGRATION)); |
253 SetUnsyncedTypes(syncer::ModelTypeSet()); | 249 SetUnsyncedTypes(syncer::ModelTypeSet()); |
254 SendConfigureDone(DataTypeManager::OK, preferred_types()); | 250 SendConfigureDone(DataTypeManager::OK, preferred_types()); |
255 | 251 |
256 EXPECT_EQ(BackendMigrator::DISABLING_TYPES, migrator()->state()); | 252 EXPECT_EQ(BackendMigrator::DISABLING_TYPES, migrator()->state()); |
257 } | 253 } |
258 | 254 |
259 // Test that spurious OnConfigureDone events don't confuse the | 255 // Test that spurious OnConfigureDone events don't confuse the |
260 // migrator while it's waiting for disabled types to have been purged | 256 // migrator while it's waiting for disabled types to have been purged |
261 // from the sync db. | 257 // from the sync db. |
262 TEST_F(SyncBackendMigratorTest, WaitingForPurge) { | 258 TEST_F(SyncBackendMigratorTest, WaitingForPurge) { |
263 syncer::ModelTypeSet to_migrate, difference; | 259 syncer::ModelTypeSet to_migrate, difference; |
264 to_migrate.Put(syncer::PREFERENCES); | 260 to_migrate.Put(syncer::PREFERENCES); |
265 to_migrate.Put(syncer::AUTOFILL); | 261 to_migrate.Put(syncer::AUTOFILL); |
266 difference.Put(syncer::BOOKMARKS); | 262 difference.Put(syncer::BOOKMARKS); |
267 | 263 |
268 EXPECT_CALL(*manager(), state()) | 264 EXPECT_CALL(*manager(), state()) |
269 .WillOnce(Return(DataTypeManager::CONFIGURED)); | 265 .WillOnce(Return(DataTypeManager::CONFIGURED)); |
270 EXPECT_CALL( | 266 EXPECT_CALL(*manager(), |
271 *manager(), | 267 PurgeForMigration(_, syncer::CONFIGURE_REASON_MIGRATION)) |
272 PurgeForMigration(_, syncer::CONFIGURE_REASON_MIGRATION)).Times(1); | 268 .Times(1); |
273 EXPECT_CALL( | 269 EXPECT_CALL(*manager(), Configure(_, syncer::CONFIGURE_REASON_MIGRATION)) |
274 *manager(), | 270 .Times(1); |
275 Configure(_, syncer::CONFIGURE_REASON_MIGRATION)).Times(1); | |
276 | 271 |
277 migrator()->MigrateTypes(to_migrate); | 272 migrator()->MigrateTypes(to_migrate); |
278 EXPECT_EQ(BackendMigrator::DISABLING_TYPES, migrator()->state()); | 273 EXPECT_EQ(BackendMigrator::DISABLING_TYPES, migrator()->state()); |
279 | 274 |
280 SendConfigureDone(DataTypeManager::OK, difference); | 275 SendConfigureDone(DataTypeManager::OK, difference); |
281 EXPECT_EQ(BackendMigrator::DISABLING_TYPES, migrator()->state()); | 276 EXPECT_EQ(BackendMigrator::DISABLING_TYPES, migrator()->state()); |
282 | 277 |
283 syncer::ModelTypeSet prefs; | 278 syncer::ModelTypeSet prefs; |
284 prefs.Put(syncer::PREFERENCES); | 279 prefs.Put(syncer::PREFERENCES); |
285 SetUnsyncedTypes(prefs); | 280 SetUnsyncedTypes(prefs); |
286 SendConfigureDone(DataTypeManager::OK, difference); | 281 SendConfigureDone(DataTypeManager::OK, difference); |
287 EXPECT_EQ(BackendMigrator::DISABLING_TYPES, migrator()->state()); | 282 EXPECT_EQ(BackendMigrator::DISABLING_TYPES, migrator()->state()); |
288 | 283 |
289 SetUnsyncedTypes(to_migrate); | 284 SetUnsyncedTypes(to_migrate); |
290 SendConfigureDone(DataTypeManager::OK, difference); | 285 SendConfigureDone(DataTypeManager::OK, difference); |
291 EXPECT_EQ(BackendMigrator::REENABLING_TYPES, migrator()->state()); | 286 EXPECT_EQ(BackendMigrator::REENABLING_TYPES, migrator()->state()); |
292 } | 287 } |
293 | 288 |
294 TEST_F(SyncBackendMigratorTest, MigratedTypeDisabledByUserDuringMigration) { | 289 TEST_F(SyncBackendMigratorTest, MigratedTypeDisabledByUserDuringMigration) { |
295 syncer::ModelTypeSet to_migrate; | 290 syncer::ModelTypeSet to_migrate; |
296 to_migrate.Put(syncer::PREFERENCES); | 291 to_migrate.Put(syncer::PREFERENCES); |
297 | 292 |
298 EXPECT_CALL(*manager(), state()) | 293 EXPECT_CALL(*manager(), state()) |
299 .WillOnce(Return(DataTypeManager::CONFIGURED)); | 294 .WillOnce(Return(DataTypeManager::CONFIGURED)); |
300 EXPECT_CALL( | 295 EXPECT_CALL(*manager(), |
301 *manager(), | 296 PurgeForMigration(_, syncer::CONFIGURE_REASON_MIGRATION)) |
302 PurgeForMigration(_, syncer::CONFIGURE_REASON_MIGRATION)).Times(1); | 297 .Times(1); |
303 EXPECT_CALL( | 298 EXPECT_CALL(*manager(), Configure(_, syncer::CONFIGURE_REASON_MIGRATION)) |
304 *manager(), | 299 .Times(1); |
305 Configure(_, syncer::CONFIGURE_REASON_MIGRATION)).Times(1); | |
306 migrator()->MigrateTypes(to_migrate); | 300 migrator()->MigrateTypes(to_migrate); |
307 | 301 |
308 RemovePreferredType(syncer::PREFERENCES); | 302 RemovePreferredType(syncer::PREFERENCES); |
309 SetUnsyncedTypes(to_migrate); | 303 SetUnsyncedTypes(to_migrate); |
310 SendConfigureDone(DataTypeManager::OK, preferred_types()); | 304 SendConfigureDone(DataTypeManager::OK, preferred_types()); |
311 EXPECT_EQ(BackendMigrator::REENABLING_TYPES, migrator()->state()); | 305 EXPECT_EQ(BackendMigrator::REENABLING_TYPES, migrator()->state()); |
312 SetUnsyncedTypes(syncer::ModelTypeSet()); | 306 SetUnsyncedTypes(syncer::ModelTypeSet()); |
313 SendConfigureDone(DataTypeManager::OK, preferred_types()); | 307 SendConfigureDone(DataTypeManager::OK, preferred_types()); |
314 EXPECT_EQ(BackendMigrator::IDLE, migrator()->state()); | 308 EXPECT_EQ(BackendMigrator::IDLE, migrator()->state()); |
315 } | 309 } |
316 | 310 |
317 TEST_F(SyncBackendMigratorTest, ConfigureFailure) { | 311 TEST_F(SyncBackendMigratorTest, ConfigureFailure) { |
318 syncer::ModelTypeSet to_migrate; | 312 syncer::ModelTypeSet to_migrate; |
319 to_migrate.Put(syncer::PREFERENCES); | 313 to_migrate.Put(syncer::PREFERENCES); |
320 | 314 |
321 EXPECT_CALL(*manager(), state()) | 315 EXPECT_CALL(*manager(), state()) |
322 .WillOnce(Return(DataTypeManager::CONFIGURED)); | 316 .WillOnce(Return(DataTypeManager::CONFIGURED)); |
323 EXPECT_CALL( | 317 EXPECT_CALL(*manager(), |
324 *manager(), | 318 PurgeForMigration(_, syncer::CONFIGURE_REASON_MIGRATION)) |
325 PurgeForMigration(_, syncer::CONFIGURE_REASON_MIGRATION)).Times(1); | 319 .Times(1); |
326 migrator()->MigrateTypes(to_migrate); | 320 migrator()->MigrateTypes(to_migrate); |
327 SetUnsyncedTypes(syncer::ModelTypeSet()); | 321 SetUnsyncedTypes(syncer::ModelTypeSet()); |
328 SendConfigureDone(DataTypeManager::ABORTED, syncer::ModelTypeSet()); | 322 SendConfigureDone(DataTypeManager::ABORTED, syncer::ModelTypeSet()); |
329 EXPECT_EQ(BackendMigrator::IDLE, migrator()->state()); | 323 EXPECT_EQ(BackendMigrator::IDLE, migrator()->state()); |
330 } | 324 } |
331 | 325 |
332 }; // namespace browser_sync | 326 }; // namespace browser_sync |
OLD | NEW |