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