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