| 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/live_sync_test.h" | 11 #include "chrome/test/live_sync/live_sync_test.h" |
| 12 #include "chrome/test/live_sync/bookmarks_helper.h" | 12 #include "chrome/test/live_sync/bookmarks_helper.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; |
| 16 using bookmarks_helper::IndexedURL; |
| 17 using bookmarks_helper::IndexedURLTitle; |
| 18 |
| 19 using preferences_helper::BooleanPrefMatches; |
| 20 using preferences_helper::ChangeBooleanPref; |
| 21 |
| 15 class MigrationErrorsTest : public LiveSyncTest { | 22 class MigrationErrorsTest : public LiveSyncTest { |
| 16 public: | 23 public: |
| 17 MigrationErrorsTest() : LiveSyncTest(TWO_CLIENT) {} | 24 MigrationErrorsTest() : LiveSyncTest(TWO_CLIENT) {} |
| 18 virtual ~MigrationErrorsTest() {} | 25 virtual ~MigrationErrorsTest() {} |
| 19 | 26 |
| 20 private: | 27 private: |
| 21 DISALLOW_COPY_AND_ASSIGN(MigrationErrorsTest); | 28 DISALLOW_COPY_AND_ASSIGN(MigrationErrorsTest); |
| 22 }; | 29 }; |
| 23 | 30 |
| 24 // Easiest possible test of migration errors: triggers a server migration on | 31 // Easiest possible test of migration errors: triggers a server migration on |
| 25 // one datatype, then modifies some other datatype. | 32 // one datatype, then modifies some other datatype. |
| 26 IN_PROC_BROWSER_TEST_F(MigrationErrorsTest, MigratePrefsThenModifyBookmark) { | 33 IN_PROC_BROWSER_TEST_F(MigrationErrorsTest, MigratePrefsThenModifyBookmark) { |
| 27 if (!ServerSupportsErrorTriggering()) { | 34 if (!ServerSupportsErrorTriggering()) { |
| 28 LOG(WARNING) << "Test skipped in this server environment."; | 35 LOG(WARNING) << "Test skipped in this server environment."; |
| 29 return; | 36 return; |
| 30 } | 37 } |
| 31 | 38 |
| 32 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | 39 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; |
| 33 | 40 |
| 34 // Phase 1: Before migrating anything, create & sync a preference. | 41 // Phase 1: Before migrating anything, create & sync a preference. |
| 35 ASSERT_TRUE(PreferencesHelper::BooleanPrefMatches(prefs::kShowHomeButton)); | 42 ASSERT_TRUE(BooleanPrefMatches(prefs::kShowHomeButton)); |
| 36 PreferencesHelper::ChangeBooleanPref(0, prefs::kShowHomeButton); | 43 ChangeBooleanPref(0, prefs::kShowHomeButton); |
| 37 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); | 44 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); |
| 38 ASSERT_TRUE(PreferencesHelper::BooleanPrefMatches(prefs::kShowHomeButton)); | 45 ASSERT_TRUE(BooleanPrefMatches(prefs::kShowHomeButton)); |
| 39 | 46 |
| 40 // Phase 2: Trigger a preference migration on the server. | 47 // Phase 2: Trigger a preference migration on the server. |
| 41 syncable::ModelTypeSet migrate_types; | 48 syncable::ModelTypeSet migrate_types; |
| 42 migrate_types.insert(syncable::PREFERENCES); | 49 migrate_types.insert(syncable::PREFERENCES); |
| 43 TriggerMigrationDoneError(migrate_types); | 50 TriggerMigrationDoneError(migrate_types); |
| 44 | 51 |
| 45 // Phase 3: Modify a bookmark and wait for it to sync. | 52 // Phase 3: Modify a bookmark and wait for it to sync. |
| 46 ASSERT_TRUE(BookmarksHelper::AddURL(0, BookmarksHelper::IndexedURLTitle(0), | 53 ASSERT_TRUE(AddURL(0, IndexedURLTitle(0), GURL(IndexedURL(0))) != NULL); |
| 47 GURL(BookmarksHelper::IndexedURL(0))) != NULL); | |
| 48 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); | 54 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); |
| 49 | 55 |
| 50 // Phase 4: Verify that preferences can still be synchronized. | 56 // Phase 4: Verify that preferences can still be synchronized. |
| 51 ASSERT_TRUE(PreferencesHelper::BooleanPrefMatches(prefs::kShowHomeButton)); | 57 ASSERT_TRUE(BooleanPrefMatches(prefs::kShowHomeButton)); |
| 52 PreferencesHelper::ChangeBooleanPref(0, prefs::kShowHomeButton); | 58 ChangeBooleanPref(0, prefs::kShowHomeButton); |
| 53 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); | 59 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); |
| 54 ASSERT_TRUE(PreferencesHelper::BooleanPrefMatches(prefs::kShowHomeButton)); | 60 ASSERT_TRUE(BooleanPrefMatches(prefs::kShowHomeButton)); |
| 55 } | 61 } |
| 56 | 62 |
| 57 // Triggers a server migration on two datatypes, then makes a local | 63 // Triggers a server migration on two datatypes, then makes a local |
| 58 // modification to one of them. | 64 // modification to one of them. |
| 59 IN_PROC_BROWSER_TEST_F(MigrationErrorsTest, | 65 IN_PROC_BROWSER_TEST_F(MigrationErrorsTest, |
| 60 MigratePrefsAndBookmarksThenModifyBookmark) { | 66 MigratePrefsAndBookmarksThenModifyBookmark) { |
| 61 if (!ServerSupportsErrorTriggering()) { | 67 if (!ServerSupportsErrorTriggering()) { |
| 62 LOG(WARNING) << "Test skipped in this server environment."; | 68 LOG(WARNING) << "Test skipped in this server environment."; |
| 63 return; | 69 return; |
| 64 } | 70 } |
| 65 | 71 |
| 66 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | 72 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; |
| 67 | 73 |
| 68 // Phase 1: Before migrating anything, create & sync a preference. | 74 // Phase 1: Before migrating anything, create & sync a preference. |
| 69 ASSERT_TRUE(PreferencesHelper::BooleanPrefMatches(prefs::kShowHomeButton)); | 75 ASSERT_TRUE(BooleanPrefMatches(prefs::kShowHomeButton)); |
| 70 PreferencesHelper::ChangeBooleanPref(0, prefs::kShowHomeButton); | 76 ChangeBooleanPref(0, prefs::kShowHomeButton); |
| 71 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); | 77 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); |
| 72 ASSERT_TRUE(PreferencesHelper::BooleanPrefMatches(prefs::kShowHomeButton)); | 78 ASSERT_TRUE(BooleanPrefMatches(prefs::kShowHomeButton)); |
| 73 | 79 |
| 74 // Phase 2: Trigger a migration on the server. | 80 // Phase 2: Trigger a migration on the server. |
| 75 syncable::ModelTypeSet migrate_types; | 81 syncable::ModelTypeSet migrate_types; |
| 76 migrate_types.insert(syncable::PREFERENCES); | 82 migrate_types.insert(syncable::PREFERENCES); |
| 77 migrate_types.insert(syncable::BOOKMARKS); | 83 migrate_types.insert(syncable::BOOKMARKS); |
| 78 TriggerMigrationDoneError(migrate_types); | 84 TriggerMigrationDoneError(migrate_types); |
| 79 | 85 |
| 80 // Phase 3: Modify a bookmark and wait for it to sync. | 86 // Phase 3: Modify a bookmark and wait for it to sync. |
| 81 ASSERT_TRUE(BookmarksHelper::AddURL(0, BookmarksHelper::IndexedURLTitle(0), | 87 ASSERT_TRUE(AddURL(0, IndexedURLTitle(0), GURL(IndexedURL(0))) != NULL); |
| 82 GURL(BookmarksHelper::IndexedURL(0))) != NULL); | |
| 83 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); | 88 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); |
| 84 | 89 |
| 85 // Phase 4: Verify that preferences can still be synchronized. | 90 // Phase 4: Verify that preferences can still be synchronized. |
| 86 ASSERT_TRUE(PreferencesHelper::BooleanPrefMatches(prefs::kShowHomeButton)); | 91 ASSERT_TRUE(BooleanPrefMatches(prefs::kShowHomeButton)); |
| 87 PreferencesHelper::ChangeBooleanPref(0, prefs::kShowHomeButton); | 92 ChangeBooleanPref(0, prefs::kShowHomeButton); |
| 88 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); | 93 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); |
| 89 ASSERT_TRUE(PreferencesHelper::BooleanPrefMatches(prefs::kShowHomeButton)); | 94 ASSERT_TRUE(BooleanPrefMatches(prefs::kShowHomeButton)); |
| 90 } | 95 } |
| 91 | 96 |
| 92 // Migrate every datatype in sequence; the catch being that the server | 97 // Migrate every datatype in sequence; the catch being that the server |
| 93 // will only tell the client about the migrations one at a time. | 98 // will only tell the client about the migrations one at a time. |
| 94 IN_PROC_BROWSER_TEST_F(MigrationErrorsTest, MigrationHellWithoutNigori) { | 99 IN_PROC_BROWSER_TEST_F(MigrationErrorsTest, MigrationHellWithoutNigori) { |
| 95 if (!ServerSupportsErrorTriggering()) { | 100 if (!ServerSupportsErrorTriggering()) { |
| 96 LOG(WARNING) << "Test skipped in this server environment."; | 101 LOG(WARNING) << "Test skipped in this server environment."; |
| 97 return; | 102 return; |
| 98 } | 103 } |
| 99 | 104 |
| 100 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | 105 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; |
| 101 | 106 |
| 102 // Phase 1: Before migrating anything, create & sync a preference. | 107 // Phase 1: Before migrating anything, create & sync a preference. |
| 103 ASSERT_TRUE(PreferencesHelper::BooleanPrefMatches(prefs::kShowHomeButton)); | 108 ASSERT_TRUE(BooleanPrefMatches(prefs::kShowHomeButton)); |
| 104 PreferencesHelper::ChangeBooleanPref(0, prefs::kShowHomeButton); | 109 ChangeBooleanPref(0, prefs::kShowHomeButton); |
| 105 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); | 110 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); |
| 106 ASSERT_TRUE(PreferencesHelper::BooleanPrefMatches(prefs::kShowHomeButton)); | 111 ASSERT_TRUE(BooleanPrefMatches(prefs::kShowHomeButton)); |
| 107 | 112 |
| 108 // Phase 2: Queue up a horrendous number of migrations on the server. | 113 // Phase 2: Queue up a horrendous number of migrations on the server. |
| 109 // Let the first nudge be a datatype that's neither prefs nor bookmarks. | 114 // Let the first nudge be a datatype that's neither prefs nor bookmarks. |
| 110 syncable::ModelTypeSet migrate_themes; | 115 syncable::ModelTypeSet migrate_themes; |
| 111 migrate_themes.insert(syncable::THEMES); | 116 migrate_themes.insert(syncable::THEMES); |
| 112 TriggerMigrationDoneError(migrate_themes); | 117 TriggerMigrationDoneError(migrate_themes); |
| 113 for (int i = syncable::FIRST_REAL_MODEL_TYPE; i < syncable::MODEL_TYPE_COUNT; | 118 for (int i = syncable::FIRST_REAL_MODEL_TYPE; i < syncable::MODEL_TYPE_COUNT; |
| 114 ++i) { | 119 ++i) { |
| 115 if (i == syncable::NIGORI) { | 120 if (i == syncable::NIGORI) { |
| 116 continue; | 121 continue; |
| 117 } | 122 } |
| 118 syncable::ModelTypeSet migrate_types; | 123 syncable::ModelTypeSet migrate_types; |
| 119 migrate_types.insert(syncable::ModelTypeFromInt(i)); | 124 migrate_types.insert(syncable::ModelTypeFromInt(i)); |
| 120 TriggerMigrationDoneError(migrate_types); | 125 TriggerMigrationDoneError(migrate_types); |
| 121 } | 126 } |
| 122 | 127 |
| 123 // Phase 3: Modify a bookmark and wait for it to sync. | 128 // Phase 3: Modify a bookmark and wait for it to sync. |
| 124 ASSERT_TRUE(BookmarksHelper::AddURL(0, BookmarksHelper::IndexedURLTitle(0), | 129 ASSERT_TRUE(AddURL(0, IndexedURLTitle(0), GURL(IndexedURL(0))) != NULL); |
| 125 GURL(BookmarksHelper::IndexedURL(0))) != NULL); | |
| 126 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); | 130 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); |
| 127 | 131 |
| 128 // Phase 4: Verify that preferences can still be synchronized. | 132 // Phase 4: Verify that preferences can still be synchronized. |
| 129 ASSERT_TRUE(PreferencesHelper::BooleanPrefMatches(prefs::kShowHomeButton)); | 133 ASSERT_TRUE(BooleanPrefMatches(prefs::kShowHomeButton)); |
| 130 PreferencesHelper::ChangeBooleanPref(0, prefs::kShowHomeButton); | 134 ChangeBooleanPref(0, prefs::kShowHomeButton); |
| 131 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); | 135 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); |
| 132 ASSERT_TRUE(PreferencesHelper::BooleanPrefMatches(prefs::kShowHomeButton)); | 136 ASSERT_TRUE(BooleanPrefMatches(prefs::kShowHomeButton)); |
| 133 } | 137 } |
| 134 | 138 |
| 135 IN_PROC_BROWSER_TEST_F(MigrationErrorsTest, MigrationHellWithNigori) { | 139 IN_PROC_BROWSER_TEST_F(MigrationErrorsTest, MigrationHellWithNigori) { |
| 136 if (!ServerSupportsErrorTriggering()) { | 140 if (!ServerSupportsErrorTriggering()) { |
| 137 LOG(WARNING) << "Test skipped in this server environment."; | 141 LOG(WARNING) << "Test skipped in this server environment."; |
| 138 return; | 142 return; |
| 139 } | 143 } |
| 140 | 144 |
| 141 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | 145 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; |
| 142 | 146 |
| 143 // Phase 1: Before migrating anything, create & sync a preference. | 147 // Phase 1: Before migrating anything, create & sync a preference. |
| 144 ASSERT_TRUE(PreferencesHelper::BooleanPrefMatches(prefs::kShowHomeButton)); | 148 ASSERT_TRUE(BooleanPrefMatches(prefs::kShowHomeButton)); |
| 145 PreferencesHelper::ChangeBooleanPref(0, prefs::kShowHomeButton); | 149 ChangeBooleanPref(0, prefs::kShowHomeButton); |
| 146 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); | 150 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); |
| 147 ASSERT_TRUE(PreferencesHelper::BooleanPrefMatches(prefs::kShowHomeButton)); | 151 ASSERT_TRUE(BooleanPrefMatches(prefs::kShowHomeButton)); |
| 148 | 152 |
| 149 // Phase 2: Queue up a horrendous number of migrations on the server. | 153 // Phase 2: Queue up a horrendous number of migrations on the server. |
| 150 // Let the first nudge be a datatype that's neither prefs nor bookmarks. | 154 // Let the first nudge be a datatype that's neither prefs nor bookmarks. |
| 151 syncable::ModelTypeSet migrate_themes; | 155 syncable::ModelTypeSet migrate_themes; |
| 152 migrate_themes.insert(syncable::THEMES); | 156 migrate_themes.insert(syncable::THEMES); |
| 153 TriggerMigrationDoneError(migrate_themes); | 157 TriggerMigrationDoneError(migrate_themes); |
| 154 for (int i = syncable::FIRST_REAL_MODEL_TYPE; i < syncable::MODEL_TYPE_COUNT; | 158 for (int i = syncable::FIRST_REAL_MODEL_TYPE; i < syncable::MODEL_TYPE_COUNT; |
| 155 ++i) { | 159 ++i) { |
| 156 // TODO(lipalani): If all types are disabled syncer freaks out. Fix it. | 160 // TODO(lipalani): If all types are disabled syncer freaks out. Fix it. |
| 157 if (i == syncable::BOOKMARKS) { | 161 if (i == syncable::BOOKMARKS) { |
| 158 continue; | 162 continue; |
| 159 } | 163 } |
| 160 syncable::ModelTypeSet migrate_types; | 164 syncable::ModelTypeSet migrate_types; |
| 161 migrate_types.insert(syncable::ModelTypeFromInt(i)); | 165 migrate_types.insert(syncable::ModelTypeFromInt(i)); |
| 162 TriggerMigrationDoneError(migrate_types); | 166 TriggerMigrationDoneError(migrate_types); |
| 163 } | 167 } |
| 164 | 168 |
| 165 // Phase 3: Modify a bookmark and wait for it to sync. | 169 // Phase 3: Modify a bookmark and wait for it to sync. |
| 166 ASSERT_TRUE(BookmarksHelper::AddURL(0, BookmarksHelper::IndexedURLTitle(0), | 170 ASSERT_TRUE(AddURL(0, IndexedURLTitle(0), GURL(IndexedURL(0))) != NULL); |
| 167 GURL(BookmarksHelper::IndexedURL(0))) != NULL); | |
| 168 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); | 171 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); |
| 169 | 172 |
| 170 // Phase 4: Verify that preferences can still be synchronized. | 173 // Phase 4: Verify that preferences can still be synchronized. |
| 171 ASSERT_TRUE(PreferencesHelper::BooleanPrefMatches(prefs::kShowHomeButton)); | 174 ASSERT_TRUE(BooleanPrefMatches(prefs::kShowHomeButton)); |
| 172 PreferencesHelper::ChangeBooleanPref(0, prefs::kShowHomeButton); | 175 ChangeBooleanPref(0, prefs::kShowHomeButton); |
| 173 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); | 176 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); |
| 174 ASSERT_TRUE(PreferencesHelper::BooleanPrefMatches(prefs::kShowHomeButton)); | 177 ASSERT_TRUE(BooleanPrefMatches(prefs::kShowHomeButton)); |
| 175 } | 178 } |
| OLD | NEW |