Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/prefs/scoped_user_pref_update.h" | 5 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
| 6 #include "chrome/browser/profiles/profile.h" | 6 #include "chrome/browser/profiles/profile.h" |
| 7 #include "chrome/browser/sync/profile_sync_service_harness.h" | 7 #include "chrome/browser/sync/profile_sync_service_harness.h" |
| 8 #include "chrome/browser/translate/translate_prefs.h" | 8 #include "chrome/browser/translate/translate_prefs.h" |
| 9 #include "chrome/common/pref_names.h" | 9 #include "chrome/common/pref_names.h" |
| 10 #include "chrome/test/base/ui_test_utils.h" | 10 #include "chrome/test/base/ui_test_utils.h" |
| 11 #include "chrome/test/live_sync/bookmarks_helper.h" | 11 #include "chrome/test/live_sync/bookmarks_helper.h" |
| 12 #include "chrome/test/live_sync/live_sync_test.h" | 12 #include "chrome/test/live_sync/live_sync_test.h" |
| 13 #include "chrome/test/live_sync/preferences_helper.h" | 13 #include "chrome/test/live_sync/preferences_helper.h" |
| 14 | 14 |
| 15 using bookmarks_helper::AddURL; | 15 using bookmarks_helper::AddURL; |
| 16 using bookmarks_helper::IndexedURL; | 16 using bookmarks_helper::IndexedURL; |
| 17 using bookmarks_helper::IndexedURLTitle; | 17 using bookmarks_helper::IndexedURLTitle; |
| 18 | 18 |
| 19 using preferences_helper::BooleanPrefMatches; | 19 using preferences_helper::BooleanPrefMatches; |
| 20 using preferences_helper::ChangeBooleanPref; | 20 using preferences_helper::ChangeBooleanPref; |
| 21 | 21 |
| 22 // Tests to make sure that the migration cycle works properly, | 22 namespace { |
|
Raghu Simha
2011/09/01 03:53:06
Now that you're adding all these tests, does it do
akalin
2011/09/01 04:03:24
Yeah, I agree. Should be a different CL, though.
| |
| 23 // i.e. doesn't stall. | 23 |
| 24 | 24 // Utility functions to make a model type set out of a small number of |
| 25 class MigrationCycleTest : public LiveSyncTest { | 25 // model types. |
| 26 | |
| 27 syncable::ModelTypeSet MakeSet(syncable::ModelType type) { | |
| 28 syncable::ModelTypeSet model_types; | |
| 29 model_types.insert(type); | |
| 30 return model_types; | |
| 31 } | |
| 32 | |
| 33 syncable::ModelTypeSet MakeSet(syncable::ModelType type1, | |
| 34 syncable::ModelType type2) { | |
| 35 syncable::ModelTypeSet model_types; | |
| 36 model_types.insert(type1); | |
| 37 model_types.insert(type2); | |
| 38 return model_types; | |
| 39 } | |
| 40 | |
| 41 // An ordered list of model types sets to migrate. Used by | |
| 42 // RunMigrationTest(). | |
| 43 typedef std::deque<syncable::ModelTypeSet> MigrationList; | |
| 44 | |
| 45 // Utility functions to make a MigrationList out of a small number of | |
| 46 // model types / model type sets. | |
| 47 | |
| 48 MigrationList MakeList(const syncable::ModelTypeSet& model_types) { | |
| 49 return MigrationList(1, model_types); | |
| 50 } | |
| 51 | |
| 52 MigrationList MakeList(const syncable::ModelTypeSet& model_types1, | |
| 53 const syncable::ModelTypeSet& model_types2) { | |
| 54 MigrationList migration_list; | |
| 55 migration_list.push_back(model_types1); | |
| 56 migration_list.push_back(model_types2); | |
| 57 return migration_list; | |
| 58 } | |
| 59 | |
| 60 MigrationList MakeList(syncable::ModelType type) { | |
| 61 return MakeList(MakeSet(type)); | |
| 62 } | |
| 63 | |
| 64 MigrationList MakeList(syncable::ModelType type1, | |
| 65 syncable::ModelType type2) { | |
| 66 return MakeList(MakeSet(type1), MakeSet(type2)); | |
| 67 } | |
| 68 | |
| 69 class MigrationTest : public LiveSyncTest { | |
| 26 public: | 70 public: |
| 27 MigrationCycleTest() : LiveSyncTest(SINGLE_CLIENT) {} | 71 explicit MigrationTest(TestType test_type) : LiveSyncTest(test_type) {} |
| 28 virtual ~MigrationCycleTest() {} | 72 virtual ~MigrationTest() {} |
| 73 | |
| 74 // TODO(akalin): Add a poll-based trigger method. | |
| 75 enum TriggerMethod { MODIFY_PREF, MODIFY_BOOKMARK, TRIGGER_NOTIFICATION }; | |
| 76 | |
| 77 syncable::ModelTypeSet GetPreferredDataTypes() { | |
| 78 syncable::ModelTypeSet preferred_data_types; | |
| 79 GetClient(0)->service()->GetPreferredDataTypes(&preferred_data_types); | |
| 80 // Make sure all clients have the same preferred data types. | |
| 81 for (int i = 1; i < num_clients(); ++i) { | |
| 82 syncable::ModelTypeSet other_preferred_data_types; | |
| 83 GetClient(i)->service()->GetPreferredDataTypes( | |
| 84 &other_preferred_data_types); | |
| 85 EXPECT_EQ(preferred_data_types, other_preferred_data_types); | |
| 86 } | |
| 87 return preferred_data_types; | |
| 88 } | |
| 89 | |
| 90 // Returns a MigrationList with every enabled data type in its own | |
| 91 // set. | |
| 92 MigrationList GetPreferredDataTypesList() { | |
| 93 MigrationList migration_list; | |
| 94 const syncable::ModelTypeSet& preferred_data_types = | |
| 95 GetPreferredDataTypes(); | |
| 96 for (syncable::ModelTypeSet::const_iterator it = | |
| 97 preferred_data_types.begin(); | |
| 98 it != preferred_data_types.end(); ++it) { | |
| 99 migration_list.push_back(MakeSet(*it)); | |
| 100 } | |
| 101 return migration_list; | |
| 102 } | |
| 103 | |
| 104 // Trigger a migration for the given types with the given method. | |
| 105 void TriggerMigration(const syncable::ModelTypeSet& model_types, | |
| 106 TriggerMethod trigger_method) { | |
| 107 switch (trigger_method) { | |
| 108 case MODIFY_PREF: | |
| 109 // Unlike MODIFY_BOOKMARK, MODIFY_PREF doesn't cause a | |
| 110 // notification to happen (since model association on a | |
| 111 // boolean pref clobbers the local value), so it doesn't work | |
| 112 // for anything but single-client tests. | |
| 113 ASSERT_EQ(1, num_clients()); | |
| 114 ASSERT_TRUE(BooleanPrefMatches(prefs::kShowHomeButton)); | |
| 115 ChangeBooleanPref(0, prefs::kShowHomeButton); | |
| 116 break; | |
| 117 case MODIFY_BOOKMARK: | |
| 118 ASSERT_TRUE(AddURL(0, IndexedURLTitle(0), GURL(IndexedURL(0)))); | |
| 119 break; | |
| 120 case TRIGGER_NOTIFICATION: | |
| 121 TriggerNotification(model_types); | |
| 122 break; | |
| 123 default: | |
| 124 ADD_FAILURE(); | |
| 125 } | |
| 126 } | |
| 127 | |
| 128 // Block until all clients have completed migration for the given | |
| 129 // types. | |
| 130 void AwaitMigration(const syncable::ModelTypeSet& migrate_types) { | |
| 131 for (int i = 0; i < num_clients(); ++i) { | |
| 132 ASSERT_TRUE(GetClient(i)->AwaitMigration(migrate_types)); | |
| 133 } | |
| 134 } | |
| 135 | |
| 136 bool ShouldRunMigrationTest() const { | |
| 137 if (!ServerSupportsNotificationControl() || | |
| 138 !ServerSupportsErrorTriggering()) { | |
| 139 LOG(WARNING) << "Test skipped in this server environment."; | |
| 140 return false; | |
| 141 } | |
| 142 return true; | |
| 143 } | |
| 144 | |
| 145 // Makes sure migration works with the given migration list and | |
| 146 // trigger method. | |
| 147 void RunMigrationTest(const MigrationList& migration_list, | |
| 148 TriggerMethod trigger_method) { | |
| 149 ASSERT_TRUE(ShouldRunMigrationTest()); | |
| 150 | |
| 151 // If we have only one client, turn off notifications to avoid the | |
| 152 // possibility of spurious sync cycles. | |
| 153 bool do_test_without_notifications = | |
| 154 (trigger_method != TRIGGER_NOTIFICATION && num_clients() == 1); | |
| 155 | |
| 156 if (do_test_without_notifications) { | |
| 157 DisableNotifications(); | |
| 158 } | |
| 159 | |
| 160 // Phase 1: Trigger the migrations on the server. | |
| 161 for (MigrationList::const_iterator it = migration_list.begin(); | |
| 162 it != migration_list.end(); ++it) { | |
| 163 TriggerMigrationDoneError(*it); | |
| 164 } | |
| 165 | |
| 166 // Phase 2: Trigger each migration individually and wait for it to | |
| 167 // complete. (Multiple migrations may be handled by each | |
| 168 // migration cycle, but there's no guarantee of that, so we have | |
| 169 // to trigger each migration individually.) | |
| 170 for (MigrationList::const_iterator it = migration_list.begin(); | |
| 171 it != migration_list.end(); ++it) { | |
| 172 TriggerMigration(*it, trigger_method); | |
| 173 AwaitMigration(*it); | |
| 174 } | |
| 175 | |
| 176 // Phase 3: Wait for all clients to catch up. | |
| 177 AwaitQuiescence(); | |
| 178 | |
| 179 // Re-enable notifications if we disabled it. | |
| 180 if (do_test_without_notifications) { | |
| 181 EnableNotifications(); | |
| 182 } | |
| 183 } | |
| 29 | 184 |
| 30 private: | 185 private: |
| 31 DISALLOW_COPY_AND_ASSIGN(MigrationCycleTest); | 186 DISALLOW_COPY_AND_ASSIGN(MigrationTest); |
| 32 }; | 187 }; |
| 33 | 188 |
| 34 IN_PROC_BROWSER_TEST_F(MigrationCycleTest, PrefsOnly) { | 189 class MigrationSingleClientTest : public MigrationTest { |
| 35 if (!ServerSupportsNotificationControl() || | |
| 36 !ServerSupportsErrorTriggering()) { | |
| 37 LOG(WARNING) << "Test skipped in this server environment."; | |
| 38 return; | |
| 39 } | |
| 40 | |
| 41 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | |
| 42 | |
| 43 DisableNotifications(); | |
| 44 | |
| 45 // Phase 1: Trigger a preference migration on the server. | |
| 46 syncable::ModelTypeSet migrate_types; | |
| 47 migrate_types.insert(syncable::PREFERENCES); | |
| 48 TriggerMigrationDoneError(migrate_types); | |
| 49 | |
| 50 // Phase 2: Modify a pref (to trigger migration) and wait for a sync | |
| 51 // cycle. | |
| 52 // TODO(akalin): Shouldn't need to wait for full sync cycle; see | |
| 53 // 93167. | |
| 54 ASSERT_TRUE(BooleanPrefMatches(prefs::kShowHomeButton)); | |
| 55 ChangeBooleanPref(0, prefs::kShowHomeButton); | |
| 56 ASSERT_TRUE(GetClient(0)->AwaitSyncCycleCompletion("Migration")); | |
| 57 } | |
| 58 | |
| 59 // TODO(akalin): Fails (times out) due to http://crbug.com/92928. | |
| 60 IN_PROC_BROWSER_TEST_F(MigrationCycleTest, | |
| 61 DISABLED_PrefsOnlyTriggerNotification) { | |
| 62 if (!ServerSupportsNotificationControl() || | |
| 63 !ServerSupportsErrorTriggering()) { | |
| 64 LOG(WARNING) << "Test skipped in this server environment."; | |
| 65 return; | |
| 66 } | |
| 67 | |
| 68 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | |
| 69 | |
| 70 // Phase 1: Trigger a preference migration on the server. | |
| 71 syncable::ModelTypeSet migrate_types; | |
| 72 migrate_types.insert(syncable::PREFERENCES); | |
| 73 TriggerMigrationDoneError(migrate_types); | |
| 74 | |
| 75 // Phase 2: Synthesize a notification (to trigger migration) and | |
| 76 // wait for a sync cycle. | |
| 77 // TODO(akalin): Shouldn't need to wait for full sync cycle; see | |
| 78 // 93167. | |
| 79 TriggerNotification(migrate_types); | |
| 80 ASSERT_TRUE(GetClient(0)->AwaitNextSyncCycleCompletion("Migration")); | |
| 81 } | |
| 82 | |
| 83 // TODO(akalin): Fails (times out) due to http://crbug.com/92928. | |
| 84 IN_PROC_BROWSER_TEST_F(MigrationCycleTest, DISABLED_PrefsNigori) { | |
| 85 if (!ServerSupportsNotificationControl() || | |
| 86 !ServerSupportsErrorTriggering()) { | |
| 87 LOG(WARNING) << "Test skipped in this server environment."; | |
| 88 return; | |
| 89 } | |
| 90 | |
| 91 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | |
| 92 | |
| 93 DisableNotifications(); | |
| 94 | |
| 95 // Phase 1: Trigger a preference and nigori migration on the server. | |
| 96 { | |
| 97 syncable::ModelTypeSet migrate_types; | |
| 98 migrate_types.insert(syncable::PREFERENCES); | |
| 99 TriggerMigrationDoneError(migrate_types); | |
| 100 } | |
| 101 { | |
| 102 syncable::ModelTypeSet migrate_types; | |
| 103 migrate_types.insert(syncable::NIGORI); | |
| 104 TriggerMigrationDoneError(migrate_types); | |
| 105 } | |
| 106 | |
| 107 // Phase 2: Modify a pref (to trigger migration) and wait for a sync | |
| 108 // cycle. | |
| 109 // TODO(akalin): Shouldn't need to wait for full sync cycle; see | |
| 110 // 93167. | |
| 111 ASSERT_TRUE(BooleanPrefMatches(prefs::kShowHomeButton)); | |
| 112 ChangeBooleanPref(0, prefs::kShowHomeButton); | |
| 113 ASSERT_TRUE(GetClient(0)->AwaitSyncCycleCompletion("Migration")); | |
| 114 } | |
| 115 | |
| 116 // TODO(akalin): Fails (times out) due to http://crbug.com/92928. | |
| 117 IN_PROC_BROWSER_TEST_F(MigrationCycleTest, DISABLED_BookmarksPrefs) { | |
| 118 if (!ServerSupportsNotificationControl() || | |
| 119 !ServerSupportsErrorTriggering()) { | |
| 120 LOG(WARNING) << "Test skipped in this server environment."; | |
| 121 return; | |
| 122 } | |
| 123 | |
| 124 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | |
| 125 | |
| 126 DisableNotifications(); | |
| 127 | |
| 128 // Phase 1: Trigger a bookmark and preference migration on the | |
| 129 // server. | |
| 130 { | |
| 131 syncable::ModelTypeSet migrate_types; | |
| 132 migrate_types.insert(syncable::BOOKMARKS); | |
| 133 TriggerMigrationDoneError(migrate_types); | |
| 134 } | |
| 135 { | |
| 136 syncable::ModelTypeSet migrate_types; | |
| 137 migrate_types.insert(syncable::PREFERENCES); | |
| 138 TriggerMigrationDoneError(migrate_types); | |
| 139 } | |
| 140 | |
| 141 // Phase 2: Modify a bookmark (to trigger migration) and wait for a | |
| 142 // sync cycle. | |
| 143 // TODO(akalin): Shouldn't need to wait for full sync cycle; see | |
| 144 // 93167. | |
| 145 ASSERT_TRUE(AddURL(0, IndexedURLTitle(0), GURL(IndexedURL(0))) != NULL); | |
| 146 ASSERT_TRUE(GetClient(0)->AwaitSyncCycleCompletion("Migration")); | |
| 147 } | |
| 148 | |
| 149 // TODO(akalin): Add tests where the migration trigger is a poll. | |
| 150 | |
| 151 class MigrationErrorsTest : public LiveSyncTest { | |
| 152 public: | 190 public: |
| 153 MigrationErrorsTest() : LiveSyncTest(TWO_CLIENT) {} | 191 MigrationSingleClientTest() : MigrationTest(SINGLE_CLIENT) {} |
| 154 virtual ~MigrationErrorsTest() {} | 192 virtual ~MigrationSingleClientTest() {} |
| 193 | |
| 194 void RunSingleClientMigrationTest(const MigrationList& migration_list, | |
| 195 TriggerMethod trigger_method) { | |
| 196 if (!ShouldRunMigrationTest()) { | |
| 197 return; | |
| 198 } | |
| 199 ASSERT_TRUE(SetupSync()); | |
| 200 RunMigrationTest(migration_list, trigger_method); | |
| 201 } | |
| 155 | 202 |
| 156 private: | 203 private: |
| 157 DISALLOW_COPY_AND_ASSIGN(MigrationErrorsTest); | 204 DISALLOW_COPY_AND_ASSIGN(MigrationSingleClientTest); |
| 158 }; | 205 }; |
| 159 | 206 |
| 160 // Easiest possible test of migration errors: triggers a server migration on | 207 // The simplest possible migration tests -- a single data type. |
| 161 // one datatype, then modifies some other datatype. | 208 |
| 162 // TODO(akalin): Fails (times out) due to http://crbug.com/92928. | 209 IN_PROC_BROWSER_TEST_F(MigrationSingleClientTest, PrefsOnlyModifyPref) { |
| 163 IN_PROC_BROWSER_TEST_F(MigrationErrorsTest, | 210 RunSingleClientMigrationTest(MakeList(syncable::PREFERENCES), MODIFY_PREF); |
| 164 DISABLED_MigratePrefsThenModifyBookmark) { | 211 } |
| 165 if (!ServerSupportsErrorTriggering()) { | 212 |
| 166 LOG(WARNING) << "Test skipped in this server environment."; | 213 IN_PROC_BROWSER_TEST_F(MigrationSingleClientTest, PrefsOnlyModifyBookmark) { |
| 167 return; | 214 RunSingleClientMigrationTest(MakeList(syncable::PREFERENCES), |
| 168 } | 215 MODIFY_BOOKMARK); |
| 169 | 216 } |
| 170 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | 217 |
| 171 | 218 IN_PROC_BROWSER_TEST_F(MigrationSingleClientTest, |
| 172 // Phase 1: Before migrating anything, create & sync a preference. | 219 PrefsOnlyTriggerNotification) { |
| 173 ASSERT_TRUE(BooleanPrefMatches(prefs::kShowHomeButton)); | 220 RunSingleClientMigrationTest(MakeList(syncable::PREFERENCES), |
| 174 ChangeBooleanPref(0, prefs::kShowHomeButton); | 221 TRIGGER_NOTIFICATION); |
| 175 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); | 222 } |
| 176 ASSERT_TRUE(BooleanPrefMatches(prefs::kShowHomeButton)); | 223 |
| 177 | 224 // Nigori is handled specially, so we test that separately. |
| 178 // Phase 2: Trigger a preference migration on the server. | 225 |
| 179 syncable::ModelTypeSet migrate_types; | 226 IN_PROC_BROWSER_TEST_F(MigrationSingleClientTest, NigoriOnly) { |
| 180 migrate_types.insert(syncable::PREFERENCES); | 227 RunSingleClientMigrationTest(MakeList(syncable::PREFERENCES), |
| 181 TriggerMigrationDoneError(migrate_types); | 228 TRIGGER_NOTIFICATION); |
| 182 | 229 } |
| 183 // Phase 3: Modify a bookmark and wait for it to sync. | 230 |
| 184 ASSERT_TRUE(AddURL(0, IndexedURLTitle(0), GURL(IndexedURL(0))) != NULL); | 231 // A little more complicated -- two data types. |
| 185 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); | 232 |
| 186 | 233 IN_PROC_BROWSER_TEST_F(MigrationSingleClientTest, |
| 187 // Phase 4: Verify that preferences can still be synchronized. | 234 BookmarksPrefsIndividually) { |
| 188 ASSERT_TRUE(BooleanPrefMatches(prefs::kShowHomeButton)); | 235 RunSingleClientMigrationTest( |
| 189 ChangeBooleanPref(0, prefs::kShowHomeButton); | 236 MakeList(syncable::BOOKMARKS, syncable::PREFERENCES), |
| 190 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); | 237 MODIFY_PREF); |
| 191 ASSERT_TRUE(BooleanPrefMatches(prefs::kShowHomeButton)); | 238 } |
| 239 | |
| 240 IN_PROC_BROWSER_TEST_F(MigrationSingleClientTest, BookmarksPrefsBoth) { | |
| 241 RunSingleClientMigrationTest( | |
| 242 MakeList(MakeSet(syncable::BOOKMARKS, syncable::PREFERENCES)), | |
| 243 MODIFY_BOOKMARK); | |
| 244 } | |
| 245 | |
| 246 // Two data types with one being nigori. | |
| 247 | |
| 248 IN_PROC_BROWSER_TEST_F(MigrationSingleClientTest, PrefsNigoriIndividiaully) { | |
| 249 RunSingleClientMigrationTest( | |
| 250 MakeList(syncable::PREFERENCES, syncable::NIGORI), | |
| 251 TRIGGER_NOTIFICATION); | |
| 252 } | |
| 253 | |
| 254 IN_PROC_BROWSER_TEST_F(MigrationSingleClientTest, PrefsNigoriBoth) { | |
| 255 RunSingleClientMigrationTest( | |
| 256 MakeList(MakeSet(syncable::PREFERENCES, syncable::NIGORI)), | |
| 257 MODIFY_PREF); | |
| 258 } | |
| 259 | |
| 260 // The whole shebang -- all data types. | |
| 261 | |
| 262 IN_PROC_BROWSER_TEST_F(MigrationSingleClientTest, AllTypesIndividually) { | |
| 263 ASSERT_TRUE(SetupClients()); | |
| 264 RunSingleClientMigrationTest(GetPreferredDataTypesList(), MODIFY_BOOKMARK); | |
| 265 } | |
| 266 | |
| 267 IN_PROC_BROWSER_TEST_F(MigrationSingleClientTest, | |
| 268 AllTypesIndividuallyTriggerNotification) { | |
| 269 ASSERT_TRUE(SetupClients()); | |
| 270 RunSingleClientMigrationTest(GetPreferredDataTypesList(), | |
| 271 TRIGGER_NOTIFICATION); | |
| 272 } | |
| 273 | |
| 274 IN_PROC_BROWSER_TEST_F(MigrationSingleClientTest, AllTypesAtOnce) { | |
| 275 ASSERT_TRUE(SetupClients()); | |
| 276 RunSingleClientMigrationTest(MakeList(GetPreferredDataTypes()), | |
| 277 MODIFY_PREF); | |
| 278 } | |
| 279 | |
| 280 IN_PROC_BROWSER_TEST_F(MigrationSingleClientTest, | |
| 281 AllTypesAtOnceTriggerNotification) { | |
| 282 ASSERT_TRUE(SetupClients()); | |
| 283 RunSingleClientMigrationTest(MakeList(GetPreferredDataTypes()), | |
| 284 TRIGGER_NOTIFICATION); | |
| 285 } | |
| 286 | |
| 287 // All data types plus nigori. | |
| 288 | |
| 289 IN_PROC_BROWSER_TEST_F(MigrationSingleClientTest, | |
| 290 AllTypesWithNigoriIndividually) { | |
| 291 ASSERT_TRUE(SetupClients()); | |
| 292 MigrationList migration_list = GetPreferredDataTypesList(); | |
| 293 migration_list.push_front(MakeSet(syncable::NIGORI)); | |
| 294 RunSingleClientMigrationTest(migration_list, MODIFY_BOOKMARK); | |
| 295 } | |
| 296 | |
| 297 IN_PROC_BROWSER_TEST_F(MigrationSingleClientTest, AllTypesWithNigoriAtOnce) { | |
| 298 ASSERT_TRUE(SetupClients()); | |
| 299 syncable::ModelTypeSet all_types = GetPreferredDataTypes(); | |
| 300 all_types.insert(syncable::NIGORI); | |
| 301 RunSingleClientMigrationTest(MakeList(all_types), MODIFY_PREF); | |
| 302 } | |
| 303 | |
| 304 class MigrationTwoClientTest : public MigrationTest { | |
| 305 public: | |
| 306 MigrationTwoClientTest() : MigrationTest(TWO_CLIENT) {} | |
| 307 virtual ~MigrationTwoClientTest() {} | |
| 308 | |
| 309 // Helper function that verifies that preferences sync still works. | |
| 310 void VerifyPrefSync() { | |
| 311 ASSERT_TRUE(BooleanPrefMatches(prefs::kShowHomeButton)); | |
| 312 ChangeBooleanPref(0, prefs::kShowHomeButton); | |
| 313 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); | |
| 314 ASSERT_TRUE(BooleanPrefMatches(prefs::kShowHomeButton)); | |
| 315 } | |
| 316 | |
| 317 void RunTwoClientMigrationTest(const MigrationList& migration_list, | |
| 318 TriggerMethod trigger_method) { | |
| 319 if (!ShouldRunMigrationTest()) { | |
| 320 return; | |
| 321 } | |
| 322 ASSERT_TRUE(SetupSync()); | |
| 323 | |
| 324 // Make sure pref sync works before running the migration test. | |
| 325 VerifyPrefSync(); | |
| 326 | |
| 327 RunMigrationTest(migration_list, trigger_method); | |
| 328 | |
| 329 // Make sure pref sync still works after running the migration | |
| 330 // test. | |
| 331 VerifyPrefSync(); | |
| 332 } | |
| 333 | |
| 334 private: | |
| 335 DISALLOW_COPY_AND_ASSIGN(MigrationTwoClientTest); | |
| 336 }; | |
| 337 | |
| 338 // Easiest possible test of migration errors: triggers a server | |
| 339 // migration on one datatype, then modifies some other datatype. | |
| 340 IN_PROC_BROWSER_TEST_F(MigrationTwoClientTest, | |
| 341 MigratePrefsThenModifyBookmark) { | |
| 342 RunTwoClientMigrationTest(MakeList(syncable::PREFERENCES), | |
| 343 MODIFY_BOOKMARK); | |
| 192 } | 344 } |
| 193 | 345 |
| 194 // Triggers a server migration on two datatypes, then makes a local | 346 // Triggers a server migration on two datatypes, then makes a local |
| 195 // modification to one of them. | 347 // modification to one of them. |
| 196 // TODO(akalin): Fails (times out) due to http://crbug.com/92928. | 348 IN_PROC_BROWSER_TEST_F(MigrationTwoClientTest, |
| 197 IN_PROC_BROWSER_TEST_F(MigrationErrorsTest, | 349 MigratePrefsAndBookmarksThenModifyBookmark) { |
| 198 DISABLED_MigratePrefsAndBookmarksThenModifyBookmark) { | 350 RunTwoClientMigrationTest( |
| 199 if (!ServerSupportsErrorTriggering()) { | 351 MakeList(syncable::PREFERENCES, syncable::BOOKMARKS), |
| 200 LOG(WARNING) << "Test skipped in this server environment."; | 352 MODIFY_BOOKMARK); |
| 201 return; | |
| 202 } | |
| 203 | |
| 204 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | |
| 205 | |
| 206 // Phase 1: Before migrating anything, create & sync a preference. | |
| 207 ASSERT_TRUE(BooleanPrefMatches(prefs::kShowHomeButton)); | |
| 208 ChangeBooleanPref(0, prefs::kShowHomeButton); | |
| 209 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); | |
| 210 ASSERT_TRUE(BooleanPrefMatches(prefs::kShowHomeButton)); | |
| 211 | |
| 212 // Phase 2: Trigger a migration on the server. | |
| 213 syncable::ModelTypeSet migrate_types; | |
| 214 migrate_types.insert(syncable::PREFERENCES); | |
| 215 migrate_types.insert(syncable::BOOKMARKS); | |
| 216 TriggerMigrationDoneError(migrate_types); | |
| 217 | |
| 218 // Phase 3: Modify a bookmark and wait for it to sync. | |
| 219 ASSERT_TRUE(AddURL(0, IndexedURLTitle(0), GURL(IndexedURL(0))) != NULL); | |
| 220 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); | |
| 221 | |
| 222 // Phase 4: Verify that preferences can still be synchronized. | |
| 223 ASSERT_TRUE(BooleanPrefMatches(prefs::kShowHomeButton)); | |
| 224 ChangeBooleanPref(0, prefs::kShowHomeButton); | |
| 225 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); | |
| 226 ASSERT_TRUE(BooleanPrefMatches(prefs::kShowHomeButton)); | |
| 227 } | 353 } |
| 228 | 354 |
| 229 // Migrate every datatype in sequence; the catch being that the server | 355 // Migrate every datatype in sequence; the catch being that the server |
| 230 // will only tell the client about the migrations one at a time. | 356 // will only tell the client about the migrations one at a time. |
| 231 // TODO(akalin): Fails (times out) due to http://crbug.com/92928. | 357 IN_PROC_BROWSER_TEST_F(MigrationTwoClientTest, MigrationHellWithoutNigori) { |
| 232 IN_PROC_BROWSER_TEST_F(MigrationErrorsTest, | 358 ASSERT_TRUE(SetupClients()); |
| 233 DISABLED_MigrationHellWithoutNigori) { | 359 MigrationList migration_list = GetPreferredDataTypesList(); |
| 234 if (!ServerSupportsErrorTriggering()) { | 360 // Let the first nudge be a datatype that's neither prefs nor |
| 235 LOG(WARNING) << "Test skipped in this server environment."; | 361 // bookmarks. |
| 236 return; | 362 migration_list.push_front(MakeSet(syncable::THEMES)); |
| 237 } | 363 RunTwoClientMigrationTest(migration_list, MODIFY_BOOKMARK); |
| 238 | 364 } |
| 239 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | 365 |
| 240 | 366 IN_PROC_BROWSER_TEST_F(MigrationTwoClientTest, MigrationHellWithNigori) { |
| 241 // Phase 1: Before migrating anything, create & sync a preference. | 367 ASSERT_TRUE(SetupClients()); |
| 242 ASSERT_TRUE(BooleanPrefMatches(prefs::kShowHomeButton)); | 368 MigrationList migration_list = GetPreferredDataTypesList(); |
| 243 ChangeBooleanPref(0, prefs::kShowHomeButton); | 369 // Let the first nudge be a datatype that's neither prefs nor |
| 244 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); | 370 // bookmarks. |
| 245 ASSERT_TRUE(BooleanPrefMatches(prefs::kShowHomeButton)); | 371 migration_list.push_front(MakeSet(syncable::THEMES)); |
| 246 | 372 // Pop off one so that we don't migrate all data types; the syncer |
| 247 // Phase 2: Queue up a horrendous number of migrations on the server. | 373 // freaks out if we do that (see http://crbug.com/94882). |
| 248 // Let the first nudge be a datatype that's neither prefs nor bookmarks. | 374 ASSERT_GE(migration_list.size(), 2u); |
| 249 syncable::ModelTypeSet migrate_themes; | 375 ASSERT_NE(migration_list.back(), MakeSet(syncable::NIGORI)); |
| 250 migrate_themes.insert(syncable::THEMES); | 376 migration_list.back() = MakeSet(syncable::NIGORI); |
| 251 TriggerMigrationDoneError(migrate_themes); | 377 RunTwoClientMigrationTest(migration_list, MODIFY_BOOKMARK); |
| 252 for (int i = syncable::FIRST_REAL_MODEL_TYPE; i < syncable::MODEL_TYPE_COUNT; | 378 } |
| 253 ++i) { | 379 |
| 254 if (i == syncable::NIGORI) { | 380 class MigrationReconfigureTest : public MigrationTwoClientTest { |
| 255 continue; | |
| 256 } | |
| 257 syncable::ModelTypeSet migrate_types; | |
| 258 migrate_types.insert(syncable::ModelTypeFromInt(i)); | |
| 259 TriggerMigrationDoneError(migrate_types); | |
| 260 } | |
| 261 | |
| 262 // Phase 3: Modify a bookmark and wait for it to sync. | |
| 263 ASSERT_TRUE(AddURL(0, IndexedURLTitle(0), GURL(IndexedURL(0))) != NULL); | |
| 264 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); | |
| 265 | |
| 266 // Phase 4: Verify that preferences can still be synchronized. | |
| 267 ASSERT_TRUE(BooleanPrefMatches(prefs::kShowHomeButton)); | |
| 268 ChangeBooleanPref(0, prefs::kShowHomeButton); | |
| 269 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); | |
| 270 ASSERT_TRUE(BooleanPrefMatches(prefs::kShowHomeButton)); | |
| 271 } | |
| 272 | |
| 273 // TODO(akalin): Fails (times out) due to http://crbug.com/92928. | |
| 274 IN_PROC_BROWSER_TEST_F(MigrationErrorsTest, | |
| 275 DISABLED_MigrationHellWithNigori) { | |
| 276 if (!ServerSupportsErrorTriggering()) { | |
| 277 LOG(WARNING) << "Test skipped in this server environment."; | |
| 278 return; | |
| 279 } | |
| 280 | |
| 281 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | |
| 282 | |
| 283 // Phase 1: Before migrating anything, create & sync a preference. | |
| 284 ASSERT_TRUE(BooleanPrefMatches(prefs::kShowHomeButton)); | |
| 285 ChangeBooleanPref(0, prefs::kShowHomeButton); | |
| 286 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); | |
| 287 ASSERT_TRUE(BooleanPrefMatches(prefs::kShowHomeButton)); | |
| 288 | |
| 289 // Phase 2: Queue up a horrendous number of migrations on the server. | |
| 290 // Let the first nudge be a datatype that's neither prefs nor bookmarks. | |
| 291 syncable::ModelTypeSet migrate_themes; | |
| 292 migrate_themes.insert(syncable::THEMES); | |
| 293 TriggerMigrationDoneError(migrate_themes); | |
| 294 for (int i = syncable::FIRST_REAL_MODEL_TYPE; i < syncable::MODEL_TYPE_COUNT; | |
| 295 ++i) { | |
| 296 // TODO(lipalani): If all types are disabled syncer freaks out. Fix it. | |
| 297 if (i == syncable::BOOKMARKS) { | |
| 298 continue; | |
| 299 } | |
| 300 syncable::ModelTypeSet migrate_types; | |
| 301 migrate_types.insert(syncable::ModelTypeFromInt(i)); | |
| 302 TriggerMigrationDoneError(migrate_types); | |
| 303 } | |
| 304 | |
| 305 // Phase 3: Modify a bookmark and wait for it to sync. | |
| 306 ASSERT_TRUE(AddURL(0, IndexedURLTitle(0), GURL(IndexedURL(0))) != NULL); | |
| 307 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); | |
| 308 | |
| 309 // Phase 4: Verify that preferences can still be synchronized. | |
| 310 ASSERT_TRUE(BooleanPrefMatches(prefs::kShowHomeButton)); | |
| 311 ChangeBooleanPref(0, prefs::kShowHomeButton); | |
| 312 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); | |
| 313 ASSERT_TRUE(BooleanPrefMatches(prefs::kShowHomeButton)); | |
| 314 } | |
| 315 | |
| 316 class MigrationReconfigureTest : public LiveSyncTest { | |
| 317 public: | 381 public: |
| 318 MigrationReconfigureTest() : LiveSyncTest(TWO_CLIENT) {} | 382 MigrationReconfigureTest() {} |
| 319 | 383 |
| 320 virtual void SetUpCommandLine(CommandLine* cl) OVERRIDE { | 384 virtual void SetUpCommandLine(CommandLine* cl) OVERRIDE { |
| 321 AddTestSwitches(cl); | 385 AddTestSwitches(cl); |
| 322 // Do not add optional datatypes. | 386 // Do not add optional datatypes. |
| 323 } | 387 } |
| 324 | 388 |
| 325 virtual ~MigrationReconfigureTest() {} | 389 virtual ~MigrationReconfigureTest() {} |
| 326 | 390 |
| 327 private: | 391 private: |
| 328 DISALLOW_COPY_AND_ASSIGN(MigrationReconfigureTest); | 392 DISALLOW_COPY_AND_ASSIGN(MigrationReconfigureTest); |
| 329 }; | 393 }; |
| 330 | 394 |
| 331 IN_PROC_BROWSER_TEST_F(MigrationReconfigureTest, SetSyncTabs) { | 395 IN_PROC_BROWSER_TEST_F(MigrationReconfigureTest, SetSyncTabs) { |
| 332 if (!ServerSupportsErrorTriggering()) { | 396 if (!ServerSupportsErrorTriggering()) { |
| 333 LOG(WARNING) << "Test skipped in this server environment."; | 397 LOG(WARNING) << "Test skipped in this server environment."; |
| 334 return; | 398 return; |
| 335 } | 399 } |
| 336 | 400 |
| 337 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | 401 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; |
| 338 ASSERT_FALSE(GetClient(0)->IsTypeRegistered(syncable::SESSIONS)); | 402 ASSERT_FALSE(GetClient(0)->IsTypeRegistered(syncable::SESSIONS)); |
| 339 ASSERT_FALSE(GetClient(0)->IsTypePreferred(syncable::SESSIONS)); | 403 ASSERT_FALSE(GetClient(0)->IsTypePreferred(syncable::SESSIONS)); |
| 340 | 404 |
| 341 // Phase 1: Before migrating anything, create & sync a preference. | 405 // Phase 1: Before migrating anything, create & sync a preference. |
| 342 ASSERT_TRUE(BooleanPrefMatches(prefs::kShowHomeButton)); | 406 VerifyPrefSync(); |
| 343 ChangeBooleanPref(0, prefs::kShowHomeButton); | |
| 344 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); | |
| 345 ASSERT_TRUE(BooleanPrefMatches(prefs::kShowHomeButton)); | |
| 346 | 407 |
| 347 // Phase 2: Trigger setting the sync_tabs field. | 408 // Phase 2: Trigger setting the sync_tabs field. |
| 348 TriggerSetSyncTabs(); | 409 TriggerSetSyncTabs(); |
| 349 | 410 |
| 350 // Phase 3: Modify a bookmark and wait for it to sync. | 411 // Phase 3: Modify a bookmark and wait for it to sync. |
| 351 ASSERT_TRUE(AddURL(0, IndexedURLTitle(0), GURL(IndexedURL(0))) != NULL); | 412 ASSERT_TRUE(AddURL(0, IndexedURLTitle(0), GURL(IndexedURL(0))) != NULL); |
| 352 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); | 413 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); |
| 353 | 414 |
| 354 // Phase 4: Verify that preferences can still be synchronized. | 415 // Phase 4: Verify that preferences can still be synchronized. |
| 355 ASSERT_TRUE(BooleanPrefMatches(prefs::kShowHomeButton)); | 416 VerifyPrefSync(); |
| 356 ChangeBooleanPref(0, prefs::kShowHomeButton); | |
| 357 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); | |
| 358 ASSERT_TRUE(BooleanPrefMatches(prefs::kShowHomeButton)); | |
| 359 | 417 |
| 360 // Phase 5: Verify that sessions are registered and enabled. | 418 // Phase 5: Verify that sessions are registered and enabled. |
| 361 ASSERT_TRUE(GetClient(0)->IsTypeRegistered(syncable::SESSIONS)); | 419 ASSERT_TRUE(GetClient(0)->IsTypeRegistered(syncable::SESSIONS)); |
| 362 ASSERT_TRUE(GetClient(0)->IsTypePreferred(syncable::SESSIONS)); | 420 ASSERT_TRUE(GetClient(0)->IsTypePreferred(syncable::SESSIONS)); |
| 363 } | 421 } |
| 364 | 422 |
| 365 // TODO(akalin): Fails (times out) due to http://crbug.com/92928. | 423 IN_PROC_BROWSER_TEST_F(MigrationReconfigureTest, SetSyncTabsAndMigrate) { |
| 366 IN_PROC_BROWSER_TEST_F(MigrationReconfigureTest, | |
| 367 DISABLED_SetSyncTabsAndMigrate) { | |
| 368 if (!ServerSupportsErrorTriggering()) { | 424 if (!ServerSupportsErrorTriggering()) { |
| 369 LOG(WARNING) << "Test skipped in this server environment."; | 425 LOG(WARNING) << "Test skipped in this server environment."; |
| 370 return; | 426 return; |
| 371 } | 427 } |
| 372 | 428 |
| 373 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | 429 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; |
| 374 ASSERT_FALSE(GetClient(0)->IsTypeRegistered(syncable::SESSIONS)); | 430 ASSERT_FALSE(GetClient(0)->IsTypeRegistered(syncable::SESSIONS)); |
| 375 ASSERT_FALSE(GetClient(0)->IsTypePreferred(syncable::SESSIONS)); | 431 ASSERT_FALSE(GetClient(0)->IsTypePreferred(syncable::SESSIONS)); |
| 376 | 432 |
| 377 // Phase 1: Before migrating anything, create & sync a preference. | 433 // Phase 1: Before migrating anything, create & sync a preference. |
| 378 ASSERT_TRUE(BooleanPrefMatches(prefs::kShowHomeButton)); | 434 VerifyPrefSync(); |
| 379 ChangeBooleanPref(0, prefs::kShowHomeButton); | |
| 380 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); | |
| 381 ASSERT_TRUE(BooleanPrefMatches(prefs::kShowHomeButton)); | |
| 382 | 435 |
| 383 // Phase 2: Trigger setting the sync_tabs field. | 436 // Phase 2: Trigger setting the sync_tabs field. |
| 384 TriggerSetSyncTabs(); | 437 TriggerSetSyncTabs(); |
| 385 | 438 |
| 386 // Phase 3: Trigger a preference migration on the server. | 439 // Phase 3: Trigger a preference migration on the server. |
| 387 syncable::ModelTypeSet migrate_types; | 440 RunMigrationTest(MakeList(syncable::PREFERENCES), MODIFY_BOOKMARK); |
| 388 migrate_types.insert(syncable::PREFERENCES); | |
| 389 TriggerMigrationDoneError(migrate_types); | |
| 390 | |
| 391 // Phase 4: Modify a bookmark and wait for it to sync. | |
| 392 ASSERT_TRUE(AddURL(0, IndexedURLTitle(0), GURL(IndexedURL(0))) != NULL); | |
| 393 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); | |
| 394 | 441 |
| 395 // Phase 5: Verify that preferences can still be synchronized. | 442 // Phase 5: Verify that preferences can still be synchronized. |
| 396 ASSERT_TRUE(BooleanPrefMatches(prefs::kShowHomeButton)); | 443 VerifyPrefSync(); |
| 397 ChangeBooleanPref(0, prefs::kShowHomeButton); | |
| 398 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); | |
| 399 ASSERT_TRUE(BooleanPrefMatches(prefs::kShowHomeButton)); | |
| 400 | 444 |
| 401 // Phase 6: Verify that sessions are registered and enabled. | 445 // Phase 6: Verify that sessions are registered and enabled. |
| 402 ASSERT_TRUE(GetClient(0)->IsTypeRegistered(syncable::SESSIONS)); | 446 ASSERT_TRUE(GetClient(0)->IsTypeRegistered(syncable::SESSIONS)); |
| 403 ASSERT_TRUE(GetClient(0)->IsTypePreferred(syncable::SESSIONS)); | 447 ASSERT_TRUE(GetClient(0)->IsTypePreferred(syncable::SESSIONS)); |
| 404 } | 448 } |
| 449 | |
| 450 } // namespace | |
| OLD | NEW |