| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/compiler_specific.h" | 5 #include "base/compiler_specific.h" |
| 6 #include "base/memory/scoped_vector.h" | 6 #include "base/memory/scoped_vector.h" |
| 7 #include "base/prefs/scoped_user_pref_update.h" | 7 #include "base/prefs/scoped_user_pref_update.h" |
| 8 #include "chrome/browser/profiles/profile.h" | 8 #include "chrome/browser/profiles/profile.h" |
| 9 #include "chrome/browser/sync/backend_migrator.h" | 9 #include "chrome/browser/sync/backend_migrator.h" |
| 10 #include "chrome/browser/sync/test/integration/bookmarks_helper.h" | 10 #include "chrome/browser/sync/test/integration/bookmarks_helper.h" |
| 11 #include "chrome/browser/sync/test/integration/preferences_helper.h" | 11 #include "chrome/browser/sync/test/integration/preferences_helper.h" |
| 12 #include "chrome/browser/sync/test/integration/profile_sync_service_harness.h" | 12 #include "chrome/browser/sync/test/integration/profile_sync_service_harness.h" |
| 13 #include "chrome/browser/sync/test/integration/status_change_checker.h" | 13 #include "chrome/browser/sync/test/integration/single_client_status_change_check
er.h" |
| 14 #include "chrome/browser/sync/test/integration/sync_test.h" | 14 #include "chrome/browser/sync/test/integration/sync_test.h" |
| 15 #include "chrome/browser/translate/translate_prefs.h" | 15 #include "chrome/browser/translate/translate_prefs.h" |
| 16 #include "chrome/common/pref_names.h" | 16 #include "chrome/common/pref_names.h" |
| 17 #include "chrome/test/base/ui_test_utils.h" | 17 #include "chrome/test/base/ui_test_utils.h" |
| 18 | 18 |
| 19 using bookmarks_helper::AddURL; | 19 using bookmarks_helper::AddURL; |
| 20 using bookmarks_helper::IndexedURL; | 20 using bookmarks_helper::IndexedURL; |
| 21 using bookmarks_helper::IndexedURLTitle; | 21 using bookmarks_helper::IndexedURLTitle; |
| 22 | 22 |
| 23 using preferences_helper::BooleanPrefMatches; | 23 using preferences_helper::BooleanPrefMatches; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 return MakeList(MakeSet(type)); | 60 return MakeList(MakeSet(type)); |
| 61 } | 61 } |
| 62 | 62 |
| 63 MigrationList MakeList(syncer::ModelType type1, | 63 MigrationList MakeList(syncer::ModelType type1, |
| 64 syncer::ModelType type2) { | 64 syncer::ModelType type2) { |
| 65 return MakeList(MakeSet(type1), MakeSet(type2)); | 65 return MakeList(MakeSet(type1), MakeSet(type2)); |
| 66 } | 66 } |
| 67 | 67 |
| 68 // Helper class that checks if the sync backend has successfully completed | 68 // Helper class that checks if the sync backend has successfully completed |
| 69 // migration for a set of data types. | 69 // migration for a set of data types. |
| 70 class MigrationChecker : public StatusChangeChecker, | 70 class MigrationChecker : public SingleClientStatusChangeChecker, |
| 71 public browser_sync::MigrationObserver { | 71 public browser_sync::MigrationObserver { |
| 72 public: | 72 public: |
| 73 explicit MigrationChecker(ProfileSyncServiceHarness* harness) | 73 explicit MigrationChecker(ProfileSyncServiceHarness* harness) |
| 74 : StatusChangeChecker("MigrationChecker"), | 74 : SingleClientStatusChangeChecker(harness->service()), |
| 75 harness_(harness) { | 75 harness_(harness) { |
| 76 DCHECK(harness_); | 76 DCHECK(harness_); |
| 77 browser_sync::BackendMigrator* migrator = | 77 browser_sync::BackendMigrator* migrator = |
| 78 harness_->service()->GetBackendMigratorForTest(); | 78 harness_->service()->GetBackendMigratorForTest(); |
| 79 // PSS must have a migrator after sync is setup and initial data type | 79 // PSS must have a migrator after sync is setup and initial data type |
| 80 // configuration is complete. | 80 // configuration is complete. |
| 81 DCHECK(migrator); | 81 DCHECK(migrator); |
| 82 migrator->AddMigrationObserver(this); | 82 migrator->AddMigrationObserver(this); |
| 83 } | 83 } |
| 84 | 84 |
| 85 virtual ~MigrationChecker() {} | 85 virtual ~MigrationChecker() {} |
| 86 | 86 |
| 87 // Returns true when sync reports that there is no pending migration, and | 87 // Returns true when sync reports that there is no pending migration, and |
| 88 // migration is complete for all data types in |expected_types_|. | 88 // migration is complete for all data types in |expected_types_|. |
| 89 virtual bool IsExitConditionSatisfied() OVERRIDE { | 89 virtual bool IsExitConditionSatisfied() OVERRIDE { |
| 90 DCHECK(!expected_types_.Empty()); | 90 DCHECK(!expected_types_.Empty()); |
| 91 bool all_expected_types_migrated = migrated_types_.HasAll(expected_types_); | 91 bool all_expected_types_migrated = migrated_types_.HasAll(expected_types_); |
| 92 DVLOG(1) << harness_->profile_debug_name() << ": Migrated types " | 92 DVLOG(1) << harness_->profile_debug_name() << ": Migrated types " |
| 93 << syncer::ModelTypeSetToString(migrated_types_) | 93 << syncer::ModelTypeSetToString(migrated_types_) |
| 94 << (all_expected_types_migrated ? " contains " : | 94 << (all_expected_types_migrated ? " contains " : |
| 95 " does not contain ") | 95 " does not contain ") |
| 96 << syncer::ModelTypeSetToString(expected_types_); | 96 << syncer::ModelTypeSetToString(expected_types_); |
| 97 return all_expected_types_migrated && | 97 return all_expected_types_migrated && |
| 98 !HasPendingBackendMigration(); | 98 !HasPendingBackendMigration(); |
| 99 } | 99 } |
| 100 | 100 |
| 101 virtual std::string GetDebugMessage() const OVERRIDE { |
| 102 return "Waiting to migrate (" + ModelTypeSetToString(expected_types_) + ")"; |
| 103 } |
| 104 |
| 101 bool HasPendingBackendMigration() const { | 105 bool HasPendingBackendMigration() const { |
| 102 browser_sync::BackendMigrator* migrator = | 106 browser_sync::BackendMigrator* migrator = |
| 103 harness_->service()->GetBackendMigratorForTest(); | 107 harness_->service()->GetBackendMigratorForTest(); |
| 104 return migrator && migrator->state() != browser_sync::BackendMigrator::IDLE; | 108 return migrator && migrator->state() != browser_sync::BackendMigrator::IDLE; |
| 105 } | 109 } |
| 106 | 110 |
| 107 void set_expected_types(syncer::ModelTypeSet expected_types) { | 111 void set_expected_types(syncer::ModelTypeSet expected_types) { |
| 108 expected_types_ = expected_types; | 112 expected_types_ = expected_types; |
| 109 } | 113 } |
| 110 | 114 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 124 << syncer::ModelTypeSetToString(pending_types_); | 128 << syncer::ModelTypeSetToString(pending_types_); |
| 125 } else { | 129 } else { |
| 126 // Migration just finished for a bunch of data types. Merge them into | 130 // Migration just finished for a bunch of data types. Merge them into |
| 127 // |migrated_types_|. | 131 // |migrated_types_|. |
| 128 migrated_types_.PutAll(pending_types_); | 132 migrated_types_.PutAll(pending_types_); |
| 129 pending_types_.Clear(); | 133 pending_types_.Clear(); |
| 130 DVLOG(1) << harness_->profile_debug_name() << ": new migrated types " | 134 DVLOG(1) << harness_->profile_debug_name() << ": new migrated types " |
| 131 << syncer::ModelTypeSetToString(migrated_types_); | 135 << syncer::ModelTypeSetToString(migrated_types_); |
| 132 } | 136 } |
| 133 | 137 |
| 138 #if 0 |
| 134 // Nudge ProfileSyncServiceHarness to inspect the exit condition provided by | 139 // Nudge ProfileSyncServiceHarness to inspect the exit condition provided by |
| 135 // AwaitMigration. | 140 // AwaitMigration. |
| 136 harness_->OnStateChanged(); | 141 if (IsWaiting() && IsExitConditionSatisfied()) { |
| 142 StopWaitingAndSucceed(); |
| 143 } |
| 144 #endif |
| 137 } | 145 } |
| 138 | 146 |
| 139 private: | 147 private: |
| 140 // The sync client for which migration is being verified. | 148 // The sync client for which migration is being verified. |
| 141 ProfileSyncServiceHarness* harness_; | 149 ProfileSyncServiceHarness* harness_; |
| 142 | 150 |
| 143 // The set of data types that are expected to eventually undergo migration. | 151 // The set of data types that are expected to eventually undergo migration. |
| 144 syncer::ModelTypeSet expected_types_; | 152 syncer::ModelTypeSet expected_types_; |
| 145 | 153 |
| 146 // The set of data types currently undergoing migration. | 154 // The set of data types currently undergoing migration. |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 } | 235 } |
| 228 } | 236 } |
| 229 | 237 |
| 230 // Block until all clients have completed migration for the given | 238 // Block until all clients have completed migration for the given |
| 231 // types. | 239 // types. |
| 232 void AwaitMigration(syncer::ModelTypeSet migrate_types) { | 240 void AwaitMigration(syncer::ModelTypeSet migrate_types) { |
| 233 for (int i = 0; i < num_clients(); ++i) { | 241 for (int i = 0; i < num_clients(); ++i) { |
| 234 MigrationChecker* checker = migration_checkers_[i]; | 242 MigrationChecker* checker = migration_checkers_[i]; |
| 235 checker->set_expected_types(migrate_types); | 243 checker->set_expected_types(migrate_types); |
| 236 if (!checker->IsExitConditionSatisfied()) | 244 if (!checker->IsExitConditionSatisfied()) |
| 237 ASSERT_TRUE(GetClient(i)->AwaitStatusChange(checker, "AwaitMigration")); | 245 ASSERT_TRUE(GetClient(i)->AwaitStatusChange(checker)); |
| 238 } | 246 } |
| 239 } | 247 } |
| 240 | 248 |
| 241 bool ShouldRunMigrationTest() const { | 249 bool ShouldRunMigrationTest() const { |
| 242 if (!ServerSupportsNotificationControl() || | 250 if (!ServerSupportsNotificationControl() || |
| 243 !ServerSupportsErrorTriggering()) { | 251 !ServerSupportsErrorTriggering()) { |
| 244 LOG(WARNING) << "Test skipped in this server environment."; | 252 LOG(WARNING) << "Test skipped in this server environment."; |
| 245 return false; | 253 return false; |
| 246 } | 254 } |
| 247 return true; | 255 return true; |
| (...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 516 // Do not add optional datatypes. | 524 // Do not add optional datatypes. |
| 517 } | 525 } |
| 518 | 526 |
| 519 virtual ~MigrationReconfigureTest() {} | 527 virtual ~MigrationReconfigureTest() {} |
| 520 | 528 |
| 521 private: | 529 private: |
| 522 DISALLOW_COPY_AND_ASSIGN(MigrationReconfigureTest); | 530 DISALLOW_COPY_AND_ASSIGN(MigrationReconfigureTest); |
| 523 }; | 531 }; |
| 524 | 532 |
| 525 } // namespace | 533 } // namespace |
| OLD | NEW |