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" |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 StatusChangeChecker, |
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 : harness_(harness) { |
75 harness_(harness) { | |
76 DCHECK(harness_); | 75 DCHECK(harness_); |
77 browser_sync::BackendMigrator* migrator = | 76 browser_sync::BackendMigrator* migrator = |
78 harness_->service()->GetBackendMigratorForTest(); | 77 harness_->service()->GetBackendMigratorForTest(); |
79 // PSS must have a migrator after sync is setup and initial data type | 78 // PSS must have a migrator after sync is setup and initial data type |
80 // configuration is complete. | 79 // configuration is complete. |
81 DCHECK(migrator); | 80 DCHECK(migrator); |
82 migrator->AddMigrationObserver(this); | 81 migrator->AddMigrationObserver(this); |
83 } | 82 } |
84 | 83 |
85 virtual ~MigrationChecker() {} | 84 virtual ~MigrationChecker() {} |
86 | 85 |
87 // Returns true when sync reports that there is no pending migration, and | 86 // Returns true when sync reports that there is no pending migration, and |
88 // migration is complete for all data types in |expected_types_|. | 87 // migration is complete for all data types in |expected_types_|. |
89 virtual bool IsExitConditionSatisfied() OVERRIDE { | 88 virtual bool IsExitConditionSatisfied() OVERRIDE { |
90 DCHECK(!expected_types_.Empty()); | 89 DCHECK(!expected_types_.Empty()); |
91 bool all_expected_types_migrated = migrated_types_.HasAll(expected_types_); | 90 bool all_expected_types_migrated = migrated_types_.HasAll(expected_types_); |
92 DVLOG(1) << harness_->profile_debug_name() << ": Migrated types " | 91 DVLOG(1) << harness_->profile_debug_name() << ": Migrated types " |
93 << syncer::ModelTypeSetToString(migrated_types_) | 92 << syncer::ModelTypeSetToString(migrated_types_) |
94 << (all_expected_types_migrated ? " contains " : | 93 << (all_expected_types_migrated ? " contains " : |
95 " does not contain ") | 94 " does not contain ") |
96 << syncer::ModelTypeSetToString(expected_types_); | 95 << syncer::ModelTypeSetToString(expected_types_); |
97 return all_expected_types_migrated && | 96 return all_expected_types_migrated && |
98 !HasPendingBackendMigration(); | 97 !HasPendingBackendMigration(); |
99 } | 98 } |
100 | 99 |
| 100 virtual std::string GetDebugMessage() const OVERRIDE { |
| 101 return "Waiting to migrate (" + ModelTypeSetToString(expected_types_) + ")"; |
| 102 } |
| 103 |
101 bool HasPendingBackendMigration() const { | 104 bool HasPendingBackendMigration() const { |
102 browser_sync::BackendMigrator* migrator = | 105 browser_sync::BackendMigrator* migrator = |
103 harness_->service()->GetBackendMigratorForTest(); | 106 harness_->service()->GetBackendMigratorForTest(); |
104 return migrator && migrator->state() != browser_sync::BackendMigrator::IDLE; | 107 return migrator && migrator->state() != browser_sync::BackendMigrator::IDLE; |
105 } | 108 } |
106 | 109 |
107 void set_expected_types(syncer::ModelTypeSet expected_types) { | 110 void set_expected_types(syncer::ModelTypeSet expected_types) { |
108 expected_types_ = expected_types; | 111 expected_types_ = expected_types; |
109 } | 112 } |
110 | 113 |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 } | 230 } |
228 } | 231 } |
229 | 232 |
230 // Block until all clients have completed migration for the given | 233 // Block until all clients have completed migration for the given |
231 // types. | 234 // types. |
232 void AwaitMigration(syncer::ModelTypeSet migrate_types) { | 235 void AwaitMigration(syncer::ModelTypeSet migrate_types) { |
233 for (int i = 0; i < num_clients(); ++i) { | 236 for (int i = 0; i < num_clients(); ++i) { |
234 MigrationChecker* checker = migration_checkers_[i]; | 237 MigrationChecker* checker = migration_checkers_[i]; |
235 checker->set_expected_types(migrate_types); | 238 checker->set_expected_types(migrate_types); |
236 if (!checker->IsExitConditionSatisfied()) | 239 if (!checker->IsExitConditionSatisfied()) |
237 ASSERT_TRUE(GetClient(i)->AwaitStatusChange(checker, "AwaitMigration")); | 240 ASSERT_TRUE(GetClient(i)->AwaitStatusChange(checker)); |
238 } | 241 } |
239 } | 242 } |
240 | 243 |
241 bool ShouldRunMigrationTest() const { | 244 bool ShouldRunMigrationTest() const { |
242 if (!ServerSupportsNotificationControl() || | 245 if (!ServerSupportsNotificationControl() || |
243 !ServerSupportsErrorTriggering()) { | 246 !ServerSupportsErrorTriggering()) { |
244 LOG(WARNING) << "Test skipped in this server environment."; | 247 LOG(WARNING) << "Test skipped in this server environment."; |
245 return false; | 248 return false; |
246 } | 249 } |
247 return true; | 250 return true; |
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
516 // Do not add optional datatypes. | 519 // Do not add optional datatypes. |
517 } | 520 } |
518 | 521 |
519 virtual ~MigrationReconfigureTest() {} | 522 virtual ~MigrationReconfigureTest() {} |
520 | 523 |
521 private: | 524 private: |
522 DISALLOW_COPY_AND_ASSIGN(MigrationReconfigureTest); | 525 DISALLOW_COPY_AND_ASSIGN(MigrationReconfigureTest); |
523 }; | 526 }; |
524 | 527 |
525 } // namespace | 528 } // namespace |
OLD | NEW |