[email protected] | b486b46 | 2012-02-11 00:11:42 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | dc55625 | 2011-04-20 01:59:35 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "chrome/browser/sync/backend_migrator.h" |
| 6 | |
[email protected] | 1a425fc | 2011-09-01 23:11:59 | [diff] [blame] | 7 | #include "base/message_loop.h" |
| 8 | #include "base/tracked_objects.h" |
[email protected] | dc55625 | 2011-04-20 01:59:35 | [diff] [blame] | 9 | #include "chrome/browser/sync/glue/data_type_manager_mock.h" |
| 10 | #include "chrome/browser/sync/profile_sync_service_mock.h" |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 11 | #include "chrome/common/chrome_notification_types.h" |
[email protected] | 3f8556a | 2012-06-07 17:50:19 | [diff] [blame^] | 12 | #include "sync/internal_api/public/syncable/model_type_test_util.h" |
[email protected] | 91835ca | 2012-04-21 09:59:42 | [diff] [blame] | 13 | #include "sync/internal_api/test_user_share.h" |
| 14 | #include "sync/internal_api/write_transaction.h" |
[email protected] | 1bcf30e | 2012-03-10 01:06:41 | [diff] [blame] | 15 | #include "sync/protocol/sync.pb.h" |
[email protected] | dc55625 | 2011-04-20 01:59:35 | [diff] [blame] | 16 | #include "testing/gmock/include/gmock/gmock.h" |
| 17 | #include "testing/gtest/include/gtest/gtest.h" |
| 18 | |
| 19 | using ::testing::_; |
| 20 | using ::testing::Eq; |
| 21 | using ::testing::Mock; |
| 22 | using ::testing::NiceMock; |
| 23 | using ::testing::Return; |
[email protected] | dc55625 | 2011-04-20 01:59:35 | [diff] [blame] | 24 | |
| 25 | namespace browser_sync { |
| 26 | |
| 27 | using sessions::ErrorCounters; |
| 28 | using sessions::SyncerStatus; |
| 29 | using sessions::SyncSessionSnapshot; |
| 30 | |
[email protected] | b486b46 | 2012-02-11 00:11:42 | [diff] [blame] | 31 | class SyncBackendMigratorTest : public testing::Test { |
[email protected] | dc55625 | 2011-04-20 01:59:35 | [diff] [blame] | 32 | public: |
[email protected] | b486b46 | 2012-02-11 00:11:42 | [diff] [blame] | 33 | SyncBackendMigratorTest() { } |
| 34 | virtual ~SyncBackendMigratorTest() { } |
[email protected] | dc55625 | 2011-04-20 01:59:35 | [diff] [blame] | 35 | |
| 36 | virtual void SetUp() { |
[email protected] | 1a425fc | 2011-09-01 23:11:59 | [diff] [blame] | 37 | test_user_share_.SetUp(); |
[email protected] | dc55625 | 2011-04-20 01:59:35 | [diff] [blame] | 38 | Mock::VerifyAndClear(manager()); |
| 39 | Mock::VerifyAndClear(&service_); |
[email protected] | 71229fa8 | 2011-12-10 01:00:54 | [diff] [blame] | 40 | preferred_types_.Put(syncable::BOOKMARKS); |
| 41 | preferred_types_.Put(syncable::PREFERENCES); |
| 42 | preferred_types_.Put(syncable::AUTOFILL); |
[email protected] | dc55625 | 2011-04-20 01:59:35 | [diff] [blame] | 43 | |
[email protected] | 71229fa8 | 2011-12-10 01:00:54 | [diff] [blame] | 44 | ON_CALL(service_, GetPreferredDataTypes()). |
| 45 | WillByDefault(Return(preferred_types_)); |
[email protected] | 1a425fc | 2011-09-01 23:11:59 | [diff] [blame] | 46 | |
| 47 | migrator_.reset( |
| 48 | new BackendMigrator( |
[email protected] | 32d7c33 | 2012-04-23 19:44:09 | [diff] [blame] | 49 | "Profile0", test_user_share_.user_share(), service(), manager(), |
| 50 | base::Closure())); |
[email protected] | 400f521a | 2011-12-13 01:50:23 | [diff] [blame] | 51 | SetUnsyncedTypes(syncable::ModelTypeSet()); |
[email protected] | dc55625 | 2011-04-20 01:59:35 | [diff] [blame] | 52 | } |
| 53 | |
[email protected] | 1a425fc | 2011-09-01 23:11:59 | [diff] [blame] | 54 | virtual void TearDown() { |
| 55 | migrator_.reset(); |
| 56 | test_user_share_.TearDown(); |
[email protected] | dc55625 | 2011-04-20 01:59:35 | [diff] [blame] | 57 | } |
| 58 | |
[email protected] | 1a425fc | 2011-09-01 23:11:59 | [diff] [blame] | 59 | // Marks all types in |unsynced_types| as unsynced and all other |
| 60 | // types as synced. |
[email protected] | 400f521a | 2011-12-13 01:50:23 | [diff] [blame] | 61 | void SetUnsyncedTypes(syncable::ModelTypeSet unsynced_types) { |
[email protected] | 1a425fc | 2011-09-01 23:11:59 | [diff] [blame] | 62 | sync_api::WriteTransaction trans(FROM_HERE, |
| 63 | test_user_share_.user_share()); |
| 64 | for (int i = syncable::FIRST_REAL_MODEL_TYPE; |
| 65 | i < syncable::MODEL_TYPE_COUNT; ++i) { |
| 66 | syncable::ModelType type = syncable::ModelTypeFromInt(i); |
| 67 | sync_pb::DataTypeProgressMarker progress_marker; |
[email protected] | 71229fa8 | 2011-12-10 01:00:54 | [diff] [blame] | 68 | if (!unsynced_types.Has(type)) { |
[email protected] | 1a425fc | 2011-09-01 23:11:59 | [diff] [blame] | 69 | progress_marker.set_token("dummy"); |
| 70 | } |
[email protected] | 30aebeb9 | 2012-02-28 05:27:15 | [diff] [blame] | 71 | trans.GetDirectory()->SetDownloadProgress(type, progress_marker); |
[email protected] | dc55625 | 2011-04-20 01:59:35 | [diff] [blame] | 72 | } |
[email protected] | dc55625 | 2011-04-20 01:59:35 | [diff] [blame] | 73 | } |
| 74 | |
[email protected] | de7d78c7 | 2011-07-26 23:41:50 | [diff] [blame] | 75 | void SendConfigureDone(DataTypeManager::ConfigureStatus status, |
[email protected] | 400f521a | 2011-12-13 01:50:23 | [diff] [blame] | 76 | syncable::ModelTypeSet requested_types) { |
[email protected] | de7d78c7 | 2011-07-26 23:41:50 | [diff] [blame] | 77 | if (status == DataTypeManager::OK) { |
[email protected] | 1a425fc | 2011-09-01 23:11:59 | [diff] [blame] | 78 | DataTypeManager::ConfigureResult result(status, requested_types); |
[email protected] | 32d7c33 | 2012-04-23 19:44:09 | [diff] [blame] | 79 | migrator_->OnConfigureDone(result); |
[email protected] | de7d78c7 | 2011-07-26 23:41:50 | [diff] [blame] | 80 | } else { |
[email protected] | 631b193f | 2011-10-06 08:07:46 | [diff] [blame] | 81 | std::list<SyncError> errors; |
| 82 | DataTypeManager::ConfigureResult result( |
| 83 | status, |
| 84 | requested_types, |
[email protected] | 46220c2 | 2012-05-23 23:26:50 | [diff] [blame] | 85 | errors, |
| 86 | syncable::ModelTypeSet()); |
[email protected] | 32d7c33 | 2012-04-23 19:44:09 | [diff] [blame] | 87 | migrator_->OnConfigureDone(result); |
[email protected] | de7d78c7 | 2011-07-26 23:41:50 | [diff] [blame] | 88 | } |
[email protected] | 1a425fc | 2011-09-01 23:11:59 | [diff] [blame] | 89 | message_loop_.RunAllPending(); |
[email protected] | dc55625 | 2011-04-20 01:59:35 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | ProfileSyncService* service() { return &service_; } |
| 93 | DataTypeManagerMock* manager() { return &manager_; } |
[email protected] | 400f521a | 2011-12-13 01:50:23 | [diff] [blame] | 94 | syncable::ModelTypeSet preferred_types() { return preferred_types_; } |
[email protected] | 1a425fc | 2011-09-01 23:11:59 | [diff] [blame] | 95 | BackendMigrator* migrator() { return migrator_.get(); } |
[email protected] | dc55625 | 2011-04-20 01:59:35 | [diff] [blame] | 96 | void RemovePreferredType(syncable::ModelType type) { |
[email protected] | 71229fa8 | 2011-12-10 01:00:54 | [diff] [blame] | 97 | preferred_types_.Remove(type); |
[email protected] | dc55625 | 2011-04-20 01:59:35 | [diff] [blame] | 98 | Mock::VerifyAndClear(&service_); |
[email protected] | 71229fa8 | 2011-12-10 01:00:54 | [diff] [blame] | 99 | ON_CALL(service_, GetPreferredDataTypes()). |
| 100 | WillByDefault(Return(preferred_types_)); |
[email protected] | dc55625 | 2011-04-20 01:59:35 | [diff] [blame] | 101 | } |
[email protected] | 1a425fc | 2011-09-01 23:11:59 | [diff] [blame] | 102 | |
[email protected] | dc55625 | 2011-04-20 01:59:35 | [diff] [blame] | 103 | private: |
| 104 | scoped_ptr<SyncSessionSnapshot> snap_; |
[email protected] | 1a425fc | 2011-09-01 23:11:59 | [diff] [blame] | 105 | MessageLoop message_loop_; |
[email protected] | 400f521a | 2011-12-13 01:50:23 | [diff] [blame] | 106 | syncable::ModelTypeSet preferred_types_; |
[email protected] | dc55625 | 2011-04-20 01:59:35 | [diff] [blame] | 107 | NiceMock<ProfileSyncServiceMock> service_; |
| 108 | NiceMock<DataTypeManagerMock> manager_; |
[email protected] | 1a425fc | 2011-09-01 23:11:59 | [diff] [blame] | 109 | TestUserShare test_user_share_; |
| 110 | scoped_ptr<BackendMigrator> migrator_; |
| 111 | }; |
| 112 | |
| 113 | class MockMigrationObserver : public MigrationObserver { |
| 114 | public: |
| 115 | virtual ~MockMigrationObserver() {} |
| 116 | |
| 117 | MOCK_METHOD0(OnMigrationStateChange, void()); |
[email protected] | dc55625 | 2011-04-20 01:59:35 | [diff] [blame] | 118 | }; |
| 119 | |
| 120 | // Test that in the normal case a migration does transition through each state |
| 121 | // and wind up back in IDLE. |
[email protected] | b486b46 | 2012-02-11 00:11:42 | [diff] [blame] | 122 | TEST_F(SyncBackendMigratorTest, Sanity) { |
[email protected] | 1a425fc | 2011-09-01 23:11:59 | [diff] [blame] | 123 | MockMigrationObserver migration_observer; |
| 124 | migrator()->AddMigrationObserver(&migration_observer); |
| 125 | EXPECT_CALL(migration_observer, OnMigrationStateChange()).Times(4); |
| 126 | |
[email protected] | 400f521a | 2011-12-13 01:50:23 | [diff] [blame] | 127 | syncable::ModelTypeSet to_migrate, difference; |
[email protected] | 71229fa8 | 2011-12-10 01:00:54 | [diff] [blame] | 128 | to_migrate.Put(syncable::PREFERENCES); |
| 129 | difference.Put(syncable::AUTOFILL); |
| 130 | difference.Put(syncable::BOOKMARKS); |
[email protected] | dc55625 | 2011-04-20 01:59:35 | [diff] [blame] | 131 | |
| 132 | EXPECT_CALL(*manager(), state()) |
| 133 | .WillOnce(Return(DataTypeManager::CONFIGURED)); |
[email protected] | 1a425fc | 2011-09-01 23:11:59 | [diff] [blame] | 134 | EXPECT_CALL(*manager(), Configure(_, sync_api::CONFIGURE_REASON_MIGRATION)) |
| 135 | .Times(2); |
[email protected] | dc55625 | 2011-04-20 01:59:35 | [diff] [blame] | 136 | |
[email protected] | 1a425fc | 2011-09-01 23:11:59 | [diff] [blame] | 137 | migrator()->MigrateTypes(to_migrate); |
| 138 | EXPECT_EQ(BackendMigrator::DISABLING_TYPES, migrator()->state()); |
[email protected] | dc55625 | 2011-04-20 01:59:35 | [diff] [blame] | 139 | |
[email protected] | 1a425fc | 2011-09-01 23:11:59 | [diff] [blame] | 140 | SetUnsyncedTypes(to_migrate); |
[email protected] | dc55625 | 2011-04-20 01:59:35 | [diff] [blame] | 141 | SendConfigureDone(DataTypeManager::OK, difference); |
[email protected] | 1a425fc | 2011-09-01 23:11:59 | [diff] [blame] | 142 | EXPECT_EQ(BackendMigrator::REENABLING_TYPES, migrator()->state()); |
[email protected] | dc55625 | 2011-04-20 01:59:35 | [diff] [blame] | 143 | |
[email protected] | 400f521a | 2011-12-13 01:50:23 | [diff] [blame] | 144 | SetUnsyncedTypes(syncable::ModelTypeSet()); |
[email protected] | dc55625 | 2011-04-20 01:59:35 | [diff] [blame] | 145 | SendConfigureDone(DataTypeManager::OK, preferred_types()); |
[email protected] | 1a425fc | 2011-09-01 23:11:59 | [diff] [blame] | 146 | EXPECT_EQ(BackendMigrator::IDLE, migrator()->state()); |
| 147 | |
| 148 | migrator()->RemoveMigrationObserver(&migration_observer); |
[email protected] | dc55625 | 2011-04-20 01:59:35 | [diff] [blame] | 149 | } |
| 150 | |
[email protected] | 8e8aea77 | 2011-06-02 18:43:57 | [diff] [blame] | 151 | // Test that in the normal case with Nigori a migration transitions through |
| 152 | // each state and wind up back in IDLE. |
[email protected] | b486b46 | 2012-02-11 00:11:42 | [diff] [blame] | 153 | TEST_F(SyncBackendMigratorTest, MigrateNigori) { |
[email protected] | 400f521a | 2011-12-13 01:50:23 | [diff] [blame] | 154 | syncable::ModelTypeSet to_migrate, difference; |
[email protected] | 71229fa8 | 2011-12-10 01:00:54 | [diff] [blame] | 155 | to_migrate.Put(syncable::NIGORI); |
| 156 | difference.Put(syncable::AUTOFILL); |
| 157 | difference.Put(syncable::BOOKMARKS); |
[email protected] | 8e8aea77 | 2011-06-02 18:43:57 | [diff] [blame] | 158 | |
| 159 | EXPECT_CALL(*manager(), state()) |
| 160 | .WillOnce(Return(DataTypeManager::CONFIGURED)); |
| 161 | |
| 162 | EXPECT_CALL(*manager(), ConfigureWithoutNigori(_, |
| 163 | sync_api::CONFIGURE_REASON_MIGRATION)); |
| 164 | |
[email protected] | 1a425fc | 2011-09-01 23:11:59 | [diff] [blame] | 165 | migrator()->MigrateTypes(to_migrate); |
| 166 | EXPECT_EQ(BackendMigrator::DISABLING_TYPES, migrator()->state()); |
[email protected] | 8e8aea77 | 2011-06-02 18:43:57 | [diff] [blame] | 167 | |
[email protected] | 1a425fc | 2011-09-01 23:11:59 | [diff] [blame] | 168 | SetUnsyncedTypes(to_migrate); |
[email protected] | 8e8aea77 | 2011-06-02 18:43:57 | [diff] [blame] | 169 | SendConfigureDone(DataTypeManager::OK, difference); |
[email protected] | 1a425fc | 2011-09-01 23:11:59 | [diff] [blame] | 170 | EXPECT_EQ(BackendMigrator::REENABLING_TYPES, migrator()->state()); |
[email protected] | 8e8aea77 | 2011-06-02 18:43:57 | [diff] [blame] | 171 | |
[email protected] | 400f521a | 2011-12-13 01:50:23 | [diff] [blame] | 172 | SetUnsyncedTypes(syncable::ModelTypeSet()); |
[email protected] | 8e8aea77 | 2011-06-02 18:43:57 | [diff] [blame] | 173 | SendConfigureDone(DataTypeManager::OK, preferred_types()); |
[email protected] | 1a425fc | 2011-09-01 23:11:59 | [diff] [blame] | 174 | EXPECT_EQ(BackendMigrator::IDLE, migrator()->state()); |
[email protected] | 8e8aea77 | 2011-06-02 18:43:57 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | |
[email protected] | dc55625 | 2011-04-20 01:59:35 | [diff] [blame] | 178 | // Test that the migrator waits for the data type manager to be idle before |
| 179 | // starting a migration. |
[email protected] | b486b46 | 2012-02-11 00:11:42 | [diff] [blame] | 180 | TEST_F(SyncBackendMigratorTest, WaitToStart) { |
[email protected] | 400f521a | 2011-12-13 01:50:23 | [diff] [blame] | 181 | syncable::ModelTypeSet to_migrate; |
[email protected] | 71229fa8 | 2011-12-10 01:00:54 | [diff] [blame] | 182 | to_migrate.Put(syncable::PREFERENCES); |
[email protected] | dc55625 | 2011-04-20 01:59:35 | [diff] [blame] | 183 | |
| 184 | EXPECT_CALL(*manager(), state()) |
| 185 | .WillOnce(Return(DataTypeManager::CONFIGURING)); |
[email protected] | b2a3c14 | 2011-05-05 03:29:55 | [diff] [blame] | 186 | EXPECT_CALL(*manager(), Configure(_, _)).Times(0); |
[email protected] | 1a425fc | 2011-09-01 23:11:59 | [diff] [blame] | 187 | migrator()->MigrateTypes(to_migrate); |
| 188 | EXPECT_EQ(BackendMigrator::WAITING_TO_START, migrator()->state()); |
[email protected] | dc55625 | 2011-04-20 01:59:35 | [diff] [blame] | 189 | |
| 190 | Mock::VerifyAndClearExpectations(manager()); |
| 191 | EXPECT_CALL(*manager(), state()) |
| 192 | .WillOnce(Return(DataTypeManager::CONFIGURED)); |
[email protected] | b2a3c14 | 2011-05-05 03:29:55 | [diff] [blame] | 193 | EXPECT_CALL(*manager(), Configure(_, sync_api::CONFIGURE_REASON_MIGRATION)); |
[email protected] | 400f521a | 2011-12-13 01:50:23 | [diff] [blame] | 194 | SetUnsyncedTypes(syncable::ModelTypeSet()); |
| 195 | SendConfigureDone(DataTypeManager::OK, syncable::ModelTypeSet()); |
[email protected] | dc55625 | 2011-04-20 01:59:35 | [diff] [blame] | 196 | |
[email protected] | 1a425fc | 2011-09-01 23:11:59 | [diff] [blame] | 197 | EXPECT_EQ(BackendMigrator::DISABLING_TYPES, migrator()->state()); |
[email protected] | dc55625 | 2011-04-20 01:59:35 | [diff] [blame] | 198 | } |
| 199 | |
| 200 | // Test that the migrator can cope with a migration request while a migration |
| 201 | // is in progress. |
[email protected] | b486b46 | 2012-02-11 00:11:42 | [diff] [blame] | 202 | TEST_F(SyncBackendMigratorTest, RestartMigration) { |
[email protected] | 400f521a | 2011-12-13 01:50:23 | [diff] [blame] | 203 | syncable::ModelTypeSet to_migrate1, to_migrate2, to_migrate_union, bookmarks; |
[email protected] | 71229fa8 | 2011-12-10 01:00:54 | [diff] [blame] | 204 | to_migrate1.Put(syncable::PREFERENCES); |
| 205 | to_migrate2.Put(syncable::AUTOFILL); |
| 206 | to_migrate_union.Put(syncable::PREFERENCES); |
| 207 | to_migrate_union.Put(syncable::AUTOFILL); |
| 208 | bookmarks.Put(syncable::BOOKMARKS); |
[email protected] | dc55625 | 2011-04-20 01:59:35 | [diff] [blame] | 209 | |
| 210 | EXPECT_CALL(*manager(), state()) |
| 211 | .WillOnce(Return(DataTypeManager::CONFIGURED)); |
[email protected] | b2a3c14 | 2011-05-05 03:29:55 | [diff] [blame] | 212 | EXPECT_CALL(*manager(), Configure(_, sync_api::CONFIGURE_REASON_MIGRATION)) |
[email protected] | 1a425fc | 2011-09-01 23:11:59 | [diff] [blame] | 213 | .Times(2); |
| 214 | migrator()->MigrateTypes(to_migrate1); |
[email protected] | dc55625 | 2011-04-20 01:59:35 | [diff] [blame] | 215 | |
[email protected] | 1a425fc | 2011-09-01 23:11:59 | [diff] [blame] | 216 | EXPECT_EQ(BackendMigrator::DISABLING_TYPES, migrator()->state()); |
| 217 | migrator()->MigrateTypes(to_migrate2); |
[email protected] | dc55625 | 2011-04-20 01:59:35 | [diff] [blame] | 218 | |
[email protected] | 400f521a | 2011-12-13 01:50:23 | [diff] [blame] | 219 | const syncable::ModelTypeSet difference1 = |
[email protected] | 71229fa8 | 2011-12-10 01:00:54 | [diff] [blame] | 220 | Difference(preferred_types(), to_migrate1); |
[email protected] | dc55625 | 2011-04-20 01:59:35 | [diff] [blame] | 221 | |
| 222 | Mock::VerifyAndClearExpectations(manager()); |
[email protected] | 1a425fc | 2011-09-01 23:11:59 | [diff] [blame] | 223 | EXPECT_CALL(*manager(), Configure(_, sync_api::CONFIGURE_REASON_MIGRATION)) |
| 224 | .Times(2); |
| 225 | SetUnsyncedTypes(to_migrate1); |
[email protected] | dc55625 | 2011-04-20 01:59:35 | [diff] [blame] | 226 | SendConfigureDone(DataTypeManager::OK, difference1); |
[email protected] | 1a425fc | 2011-09-01 23:11:59 | [diff] [blame] | 227 | EXPECT_EQ(BackendMigrator::DISABLING_TYPES, migrator()->state()); |
[email protected] | dc55625 | 2011-04-20 01:59:35 | [diff] [blame] | 228 | |
[email protected] | 1a425fc | 2011-09-01 23:11:59 | [diff] [blame] | 229 | SetUnsyncedTypes(to_migrate_union); |
[email protected] | dc55625 | 2011-04-20 01:59:35 | [diff] [blame] | 230 | SendConfigureDone(DataTypeManager::OK, bookmarks); |
[email protected] | 1a425fc | 2011-09-01 23:11:59 | [diff] [blame] | 231 | EXPECT_EQ(BackendMigrator::REENABLING_TYPES, migrator()->state()); |
[email protected] | dc55625 | 2011-04-20 01:59:35 | [diff] [blame] | 232 | } |
| 233 | |
| 234 | // Test that an external invocation of Configure(...) during a migration results |
| 235 | // in a migration reattempt. |
[email protected] | b486b46 | 2012-02-11 00:11:42 | [diff] [blame] | 236 | TEST_F(SyncBackendMigratorTest, InterruptedWhileDisablingTypes) { |
[email protected] | 400f521a | 2011-12-13 01:50:23 | [diff] [blame] | 237 | syncable::ModelTypeSet to_migrate; |
| 238 | syncable::ModelTypeSet difference; |
[email protected] | 71229fa8 | 2011-12-10 01:00:54 | [diff] [blame] | 239 | to_migrate.Put(syncable::PREFERENCES); |
| 240 | difference.Put(syncable::AUTOFILL); |
| 241 | difference.Put(syncable::BOOKMARKS); |
[email protected] | dc55625 | 2011-04-20 01:59:35 | [diff] [blame] | 242 | |
| 243 | EXPECT_CALL(*manager(), state()) |
| 244 | .WillOnce(Return(DataTypeManager::CONFIGURED)); |
[email protected] | 71229fa8 | 2011-12-10 01:00:54 | [diff] [blame] | 245 | EXPECT_CALL(*manager(), Configure(HasModelTypes(difference), |
[email protected] | b2a3c14 | 2011-05-05 03:29:55 | [diff] [blame] | 246 | sync_api::CONFIGURE_REASON_MIGRATION)); |
[email protected] | 1a425fc | 2011-09-01 23:11:59 | [diff] [blame] | 247 | migrator()->MigrateTypes(to_migrate); |
| 248 | EXPECT_EQ(BackendMigrator::DISABLING_TYPES, migrator()->state()); |
[email protected] | dc55625 | 2011-04-20 01:59:35 | [diff] [blame] | 249 | |
| 250 | Mock::VerifyAndClearExpectations(manager()); |
[email protected] | 71229fa8 | 2011-12-10 01:00:54 | [diff] [blame] | 251 | EXPECT_CALL(*manager(), Configure(HasModelTypes(difference), |
[email protected] | b2a3c14 | 2011-05-05 03:29:55 | [diff] [blame] | 252 | sync_api::CONFIGURE_REASON_MIGRATION)); |
[email protected] | 400f521a | 2011-12-13 01:50:23 | [diff] [blame] | 253 | SetUnsyncedTypes(syncable::ModelTypeSet()); |
[email protected] | dc55625 | 2011-04-20 01:59:35 | [diff] [blame] | 254 | SendConfigureDone(DataTypeManager::OK, preferred_types()); |
| 255 | |
[email protected] | 1a425fc | 2011-09-01 23:11:59 | [diff] [blame] | 256 | EXPECT_EQ(BackendMigrator::DISABLING_TYPES, migrator()->state()); |
[email protected] | dc55625 | 2011-04-20 01:59:35 | [diff] [blame] | 257 | } |
| 258 | |
[email protected] | 1a425fc | 2011-09-01 23:11:59 | [diff] [blame] | 259 | // Test that spurious OnConfigureDone events don't confuse the |
| 260 | // migrator while it's waiting for disabled types to have been purged |
| 261 | // from the sync db. |
[email protected] | b486b46 | 2012-02-11 00:11:42 | [diff] [blame] | 262 | TEST_F(SyncBackendMigratorTest, WaitingForPurge) { |
[email protected] | 400f521a | 2011-12-13 01:50:23 | [diff] [blame] | 263 | syncable::ModelTypeSet to_migrate, difference; |
[email protected] | 71229fa8 | 2011-12-10 01:00:54 | [diff] [blame] | 264 | to_migrate.Put(syncable::PREFERENCES); |
| 265 | to_migrate.Put(syncable::AUTOFILL); |
| 266 | difference.Put(syncable::BOOKMARKS); |
[email protected] | dc55625 | 2011-04-20 01:59:35 | [diff] [blame] | 267 | |
| 268 | EXPECT_CALL(*manager(), state()) |
| 269 | .WillOnce(Return(DataTypeManager::CONFIGURED)); |
[email protected] | 1a425fc | 2011-09-01 23:11:59 | [diff] [blame] | 270 | EXPECT_CALL(*manager(), Configure(_, sync_api::CONFIGURE_REASON_MIGRATION)) |
| 271 | .Times(2); |
[email protected] | dc55625 | 2011-04-20 01:59:35 | [diff] [blame] | 272 | |
[email protected] | 1a425fc | 2011-09-01 23:11:59 | [diff] [blame] | 273 | migrator()->MigrateTypes(to_migrate); |
| 274 | EXPECT_EQ(BackendMigrator::DISABLING_TYPES, migrator()->state()); |
| 275 | |
| 276 | SendConfigureDone(DataTypeManager::OK, difference); |
| 277 | EXPECT_EQ(BackendMigrator::DISABLING_TYPES, migrator()->state()); |
[email protected] | dc55625 | 2011-04-20 01:59:35 | [diff] [blame] | 278 | |
[email protected] | 400f521a | 2011-12-13 01:50:23 | [diff] [blame] | 279 | syncable::ModelTypeSet prefs; |
[email protected] | 71229fa8 | 2011-12-10 01:00:54 | [diff] [blame] | 280 | prefs.Put(syncable::PREFERENCES); |
[email protected] | 1a425fc | 2011-09-01 23:11:59 | [diff] [blame] | 281 | SetUnsyncedTypes(prefs); |
| 282 | SendConfigureDone(DataTypeManager::OK, difference); |
| 283 | EXPECT_EQ(BackendMigrator::DISABLING_TYPES, migrator()->state()); |
[email protected] | dc55625 | 2011-04-20 01:59:35 | [diff] [blame] | 284 | |
[email protected] | 1a425fc | 2011-09-01 23:11:59 | [diff] [blame] | 285 | SetUnsyncedTypes(to_migrate); |
| 286 | SendConfigureDone(DataTypeManager::OK, difference); |
| 287 | EXPECT_EQ(BackendMigrator::REENABLING_TYPES, migrator()->state()); |
[email protected] | dc55625 | 2011-04-20 01:59:35 | [diff] [blame] | 288 | } |
| 289 | |
[email protected] | b486b46 | 2012-02-11 00:11:42 | [diff] [blame] | 290 | TEST_F(SyncBackendMigratorTest, MigratedTypeDisabledByUserDuringMigration) { |
[email protected] | 400f521a | 2011-12-13 01:50:23 | [diff] [blame] | 291 | syncable::ModelTypeSet to_migrate; |
[email protected] | 71229fa8 | 2011-12-10 01:00:54 | [diff] [blame] | 292 | to_migrate.Put(syncable::PREFERENCES); |
[email protected] | dc55625 | 2011-04-20 01:59:35 | [diff] [blame] | 293 | |
| 294 | EXPECT_CALL(*manager(), state()) |
| 295 | .WillOnce(Return(DataTypeManager::CONFIGURED)); |
[email protected] | 1a425fc | 2011-09-01 23:11:59 | [diff] [blame] | 296 | EXPECT_CALL(*manager(), Configure(_, sync_api::CONFIGURE_REASON_MIGRATION)) |
| 297 | .Times(2); |
| 298 | migrator()->MigrateTypes(to_migrate); |
[email protected] | dc55625 | 2011-04-20 01:59:35 | [diff] [blame] | 299 | |
| 300 | RemovePreferredType(syncable::PREFERENCES); |
[email protected] | 1a425fc | 2011-09-01 23:11:59 | [diff] [blame] | 301 | SetUnsyncedTypes(to_migrate); |
[email protected] | dc55625 | 2011-04-20 01:59:35 | [diff] [blame] | 302 | SendConfigureDone(DataTypeManager::OK, preferred_types()); |
[email protected] | 1a425fc | 2011-09-01 23:11:59 | [diff] [blame] | 303 | EXPECT_EQ(BackendMigrator::REENABLING_TYPES, migrator()->state()); |
[email protected] | 400f521a | 2011-12-13 01:50:23 | [diff] [blame] | 304 | SetUnsyncedTypes(syncable::ModelTypeSet()); |
[email protected] | dc55625 | 2011-04-20 01:59:35 | [diff] [blame] | 305 | SendConfigureDone(DataTypeManager::OK, preferred_types()); |
[email protected] | 1a425fc | 2011-09-01 23:11:59 | [diff] [blame] | 306 | EXPECT_EQ(BackendMigrator::IDLE, migrator()->state()); |
[email protected] | dc55625 | 2011-04-20 01:59:35 | [diff] [blame] | 307 | } |
| 308 | |
[email protected] | b486b46 | 2012-02-11 00:11:42 | [diff] [blame] | 309 | TEST_F(SyncBackendMigratorTest, ConfigureFailure) { |
[email protected] | 400f521a | 2011-12-13 01:50:23 | [diff] [blame] | 310 | syncable::ModelTypeSet to_migrate; |
[email protected] | 71229fa8 | 2011-12-10 01:00:54 | [diff] [blame] | 311 | to_migrate.Put(syncable::PREFERENCES); |
[email protected] | dc55625 | 2011-04-20 01:59:35 | [diff] [blame] | 312 | |
| 313 | EXPECT_CALL(*manager(), state()) |
| 314 | .WillOnce(Return(DataTypeManager::CONFIGURED)); |
[email protected] | b2a3c14 | 2011-05-05 03:29:55 | [diff] [blame] | 315 | EXPECT_CALL(*manager(), Configure(_, sync_api::CONFIGURE_REASON_MIGRATION)) |
| 316 | .Times(1); |
[email protected] | 1a425fc | 2011-09-01 23:11:59 | [diff] [blame] | 317 | migrator()->MigrateTypes(to_migrate); |
[email protected] | 400f521a | 2011-12-13 01:50:23 | [diff] [blame] | 318 | SetUnsyncedTypes(syncable::ModelTypeSet()); |
| 319 | SendConfigureDone(DataTypeManager::ABORTED, syncable::ModelTypeSet()); |
[email protected] | 1a425fc | 2011-09-01 23:11:59 | [diff] [blame] | 320 | EXPECT_EQ(BackendMigrator::IDLE, migrator()->state()); |
[email protected] | dc55625 | 2011-04-20 01:59:35 | [diff] [blame] | 321 | } |
| 322 | |
| 323 | }; // namespace browser_sync |