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