This source file includes following definitions.
- MakeSet
- MakeSet
- MakeList
- MakeList
- MakeList
- MakeList
- harness_
- IsExitConditionSatisfied
- GetDebugMessage
- HasPendingBackendMigration
- set_expected_types
- migrated_types
- OnMigrationStateChange
- SetupSync
- GetPreferredDataTypes
- GetPreferredDataTypesList
- TriggerMigration
- AwaitMigration
- ShouldRunMigrationTest
- RunMigrationTest
- RunSingleClientMigrationTest
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- VerifyPrefSync
- RunTwoClientMigrationTest
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- SetUpCommandLine
#include "base/compiler_specific.h"
#include "base/memory/scoped_vector.h"
#include "base/prefs/scoped_user_pref_update.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/sync/backend_migrator.h"
#include "chrome/browser/sync/profile_sync_service.h"
#include "chrome/browser/sync/test/integration/bookmarks_helper.h"
#include "chrome/browser/sync/test/integration/preferences_helper.h"
#include "chrome/browser/sync/test/integration/profile_sync_service_harness.h"
#include "chrome/browser/sync/test/integration/single_client_status_change_checker.h"
#include "chrome/browser/sync/test/integration/sync_test.h"
#include "chrome/common/pref_names.h"
#include "chrome/test/base/ui_test_utils.h"
#include "components/translate/core/browser/translate_prefs.h"
using bookmarks_helper::AddURL;
using bookmarks_helper::IndexedURL;
using bookmarks_helper::IndexedURLTitle;
using preferences_helper::BooleanPrefMatches;
using preferences_helper::ChangeBooleanPref;
namespace {
syncer::ModelTypeSet MakeSet(syncer::ModelType type) {
return syncer::ModelTypeSet(type);
}
syncer::ModelTypeSet MakeSet(syncer::ModelType type1,
syncer::ModelType type2) {
return syncer::ModelTypeSet(type1, type2);
}
typedef std::deque<syncer::ModelTypeSet> MigrationList;
MigrationList MakeList(syncer::ModelTypeSet model_types) {
return MigrationList(1, model_types);
}
MigrationList MakeList(syncer::ModelTypeSet model_types1,
syncer::ModelTypeSet model_types2) {
MigrationList migration_list;
migration_list.push_back(model_types1);
migration_list.push_back(model_types2);
return migration_list;
}
MigrationList MakeList(syncer::ModelType type) {
return MakeList(MakeSet(type));
}
MigrationList MakeList(syncer::ModelType type1,
syncer::ModelType type2) {
return MakeList(MakeSet(type1), MakeSet(type2));
}
class MigrationChecker : public SingleClientStatusChangeChecker,
public browser_sync::MigrationObserver {
public:
explicit MigrationChecker(ProfileSyncServiceHarness* harness)
: SingleClientStatusChangeChecker(harness->service()),
harness_(harness) {
DCHECK(harness_);
browser_sync::BackendMigrator* migrator =
harness_->service()->GetBackendMigratorForTest();
DCHECK(migrator);
migrator->AddMigrationObserver(this);
}
virtual ~MigrationChecker() {}
virtual bool IsExitConditionSatisfied() OVERRIDE {
DCHECK(!expected_types_.Empty());
bool all_expected_types_migrated = migrated_types_.HasAll(expected_types_);
DVLOG(1) << harness_->profile_debug_name() << ": Migrated types "
<< syncer::ModelTypeSetToString(migrated_types_)
<< (all_expected_types_migrated ? " contains " :
" does not contain ")
<< syncer::ModelTypeSetToString(expected_types_);
return all_expected_types_migrated &&
!HasPendingBackendMigration();
}
virtual std::string GetDebugMessage() const OVERRIDE {
return "Waiting to migrate (" + ModelTypeSetToString(expected_types_) + ")";
}
bool HasPendingBackendMigration() const {
browser_sync::BackendMigrator* migrator =
harness_->service()->GetBackendMigratorForTest();
return migrator && migrator->state() != browser_sync::BackendMigrator::IDLE;
}
void set_expected_types(syncer::ModelTypeSet expected_types) {
expected_types_ = expected_types;
}
syncer::ModelTypeSet migrated_types() const {
return migrated_types_;
}
virtual void OnMigrationStateChange() OVERRIDE {
if (HasPendingBackendMigration()) {
pending_types_.PutAll(
harness_->service()->GetBackendMigratorForTest()->
GetPendingMigrationTypesForTest());
DVLOG(1) << harness_->profile_debug_name()
<< ": new pending migration types "
<< syncer::ModelTypeSetToString(pending_types_);
} else {
migrated_types_.PutAll(pending_types_);
pending_types_.Clear();
DVLOG(1) << harness_->profile_debug_name() << ": new migrated types "
<< syncer::ModelTypeSetToString(migrated_types_);
}
if (!expected_types_.Empty())
OnStateChanged();
}
private:
ProfileSyncServiceHarness* harness_;
syncer::ModelTypeSet expected_types_;
syncer::ModelTypeSet pending_types_;
syncer::ModelTypeSet migrated_types_;
DISALLOW_COPY_AND_ASSIGN(MigrationChecker);
};
class MigrationTest : public SyncTest {
public:
explicit MigrationTest(TestType test_type) : SyncTest(test_type) {}
virtual ~MigrationTest() {}
enum TriggerMethod { MODIFY_PREF, MODIFY_BOOKMARK, TRIGGER_NOTIFICATION };
virtual bool SetupSync() OVERRIDE {
if (!SyncTest::SetupSync())
return false;
for (int i = 0; i < num_clients(); ++i) {
MigrationChecker* checker = new MigrationChecker(GetClient(i));
migration_checkers_.push_back(checker);
}
return true;
}
syncer::ModelTypeSet GetPreferredDataTypes() {
DCHECK(GetSyncService((0)));
syncer::ModelTypeSet preferred_data_types =
GetSyncService((0))->GetPreferredDataTypes();
preferred_data_types.RemoveAll(syncer::ProxyTypes());
for (int i = 1; i < num_clients(); ++i) {
const syncer::ModelTypeSet other_preferred_data_types =
GetSyncService((i))->GetPreferredDataTypes();
EXPECT_TRUE(preferred_data_types.Equals(other_preferred_data_types));
}
return preferred_data_types;
}
MigrationList GetPreferredDataTypesList() {
MigrationList migration_list;
const syncer::ModelTypeSet preferred_data_types =
GetPreferredDataTypes();
for (syncer::ModelTypeSet::Iterator it =
preferred_data_types.First(); it.Good(); it.Inc()) {
migration_list.push_back(MakeSet(it.Get()));
}
return migration_list;
}
void TriggerMigration(syncer::ModelTypeSet model_types,
TriggerMethod trigger_method) {
switch (trigger_method) {
case MODIFY_PREF:
ASSERT_EQ(1, num_clients());
ASSERT_TRUE(BooleanPrefMatches(prefs::kShowHomeButton));
ChangeBooleanPref(0, prefs::kShowHomeButton);
break;
case MODIFY_BOOKMARK:
ASSERT_TRUE(AddURL(0, IndexedURLTitle(0), GURL(IndexedURL(0))));
break;
case TRIGGER_NOTIFICATION:
TriggerNotification(model_types);
break;
default:
ADD_FAILURE();
}
}
void AwaitMigration(syncer::ModelTypeSet migrate_types) {
for (int i = 0; i < num_clients(); ++i) {
MigrationChecker* checker = migration_checkers_[i];
checker->set_expected_types(migrate_types);
checker->Wait();
ASSERT_FALSE(checker->TimedOut());
}
}
bool ShouldRunMigrationTest() const {
if (!ServerSupportsNotificationControl() ||
!ServerSupportsErrorTriggering()) {
LOG(WARNING) << "Test skipped in this server environment.";
return false;
}
return true;
}
void RunMigrationTest(const MigrationList& migration_list,
TriggerMethod trigger_method) {
ASSERT_TRUE(ShouldRunMigrationTest());
bool do_test_without_notifications =
(trigger_method != TRIGGER_NOTIFICATION && num_clients() == 1);
if (do_test_without_notifications) {
DisableNotifications();
}
for (int i = 0; i < num_clients(); ++i) {
ASSERT_TRUE(migration_checkers_[i]->migrated_types().Empty());
}
for (MigrationList::const_iterator it = migration_list.begin();
it != migration_list.end(); ++it) {
TriggerMigrationDoneError(*it);
}
for (MigrationList::const_iterator it = migration_list.begin();
it != migration_list.end(); ++it) {
TriggerMigration(*it, trigger_method);
AwaitMigration(*it);
}
if (!do_test_without_notifications) {
AwaitQuiescence();
}
}
private:
ScopedVector<MigrationChecker> migration_checkers_;
DISALLOW_COPY_AND_ASSIGN(MigrationTest);
};
class MigrationSingleClientTest : public MigrationTest {
public:
MigrationSingleClientTest() : MigrationTest(SINGLE_CLIENT) {}
virtual ~MigrationSingleClientTest() {}
void RunSingleClientMigrationTest(const MigrationList& migration_list,
TriggerMethod trigger_method) {
if (!ShouldRunMigrationTest()) {
return;
}
ASSERT_TRUE(SetupSync());
RunMigrationTest(migration_list, trigger_method);
}
private:
DISALLOW_COPY_AND_ASSIGN(MigrationSingleClientTest);
};
IN_PROC_BROWSER_TEST_F(MigrationSingleClientTest, PrefsOnlyModifyPref) {
RunSingleClientMigrationTest(MakeList(syncer::PREFERENCES), MODIFY_PREF);
}
IN_PROC_BROWSER_TEST_F(MigrationSingleClientTest, PrefsOnlyModifyBookmark) {
RunSingleClientMigrationTest(MakeList(syncer::PREFERENCES),
MODIFY_BOOKMARK);
}
IN_PROC_BROWSER_TEST_F(MigrationSingleClientTest,
PrefsOnlyTriggerNotification) {
RunSingleClientMigrationTest(MakeList(syncer::PREFERENCES),
TRIGGER_NOTIFICATION);
}
IN_PROC_BROWSER_TEST_F(MigrationSingleClientTest, NigoriOnly) {
RunSingleClientMigrationTest(MakeList(syncer::PREFERENCES),
TRIGGER_NOTIFICATION);
}
IN_PROC_BROWSER_TEST_F(MigrationSingleClientTest,
BookmarksPrefsIndividually) {
RunSingleClientMigrationTest(
MakeList(syncer::BOOKMARKS, syncer::PREFERENCES),
MODIFY_PREF);
}
IN_PROC_BROWSER_TEST_F(MigrationSingleClientTest, BookmarksPrefsBoth) {
RunSingleClientMigrationTest(
MakeList(MakeSet(syncer::BOOKMARKS, syncer::PREFERENCES)),
MODIFY_BOOKMARK);
}
IN_PROC_BROWSER_TEST_F(MigrationSingleClientTest,
DISABLED_PrefsNigoriIndividiaully) {
RunSingleClientMigrationTest(
MakeList(syncer::PREFERENCES, syncer::NIGORI),
TRIGGER_NOTIFICATION);
}
IN_PROC_BROWSER_TEST_F(MigrationSingleClientTest, PrefsNigoriBoth) {
RunSingleClientMigrationTest(
MakeList(MakeSet(syncer::PREFERENCES, syncer::NIGORI)),
MODIFY_PREF);
}
IN_PROC_BROWSER_TEST_F(MigrationSingleClientTest, AllTypesIndividually) {
ASSERT_TRUE(SetupClients());
RunSingleClientMigrationTest(GetPreferredDataTypesList(), MODIFY_BOOKMARK);
}
IN_PROC_BROWSER_TEST_F(MigrationSingleClientTest,
AllTypesIndividuallyTriggerNotification) {
ASSERT_TRUE(SetupClients());
RunSingleClientMigrationTest(GetPreferredDataTypesList(),
TRIGGER_NOTIFICATION);
}
IN_PROC_BROWSER_TEST_F(MigrationSingleClientTest, AllTypesAtOnce) {
ASSERT_TRUE(SetupClients());
RunSingleClientMigrationTest(MakeList(GetPreferredDataTypes()),
MODIFY_PREF);
}
IN_PROC_BROWSER_TEST_F(MigrationSingleClientTest,
AllTypesAtOnceTriggerNotification) {
ASSERT_TRUE(SetupClients());
RunSingleClientMigrationTest(MakeList(GetPreferredDataTypes()),
TRIGGER_NOTIFICATION);
}
IN_PROC_BROWSER_TEST_F(MigrationSingleClientTest,
DISABLED_AllTypesWithNigoriIndividually) {
ASSERT_TRUE(SetupClients());
MigrationList migration_list = GetPreferredDataTypesList();
migration_list.push_front(MakeSet(syncer::NIGORI));
RunSingleClientMigrationTest(migration_list, MODIFY_BOOKMARK);
}
IN_PROC_BROWSER_TEST_F(MigrationSingleClientTest,
AllTypesWithNigoriAtOnce) {
ASSERT_TRUE(SetupClients());
syncer::ModelTypeSet all_types = GetPreferredDataTypes();
all_types.Put(syncer::NIGORI);
RunSingleClientMigrationTest(MakeList(all_types), MODIFY_PREF);
}
class MigrationTwoClientTest : public MigrationTest {
public:
MigrationTwoClientTest() : MigrationTest(TWO_CLIENT) {}
virtual ~MigrationTwoClientTest() {}
void VerifyPrefSync() {
ASSERT_TRUE(BooleanPrefMatches(prefs::kShowHomeButton));
ChangeBooleanPref(0, prefs::kShowHomeButton);
ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
ASSERT_TRUE(BooleanPrefMatches(prefs::kShowHomeButton));
}
void RunTwoClientMigrationTest(const MigrationList& migration_list,
TriggerMethod trigger_method) {
if (!ShouldRunMigrationTest()) {
return;
}
ASSERT_TRUE(SetupSync());
VerifyPrefSync();
RunMigrationTest(migration_list, trigger_method);
VerifyPrefSync();
}
private:
DISALLOW_COPY_AND_ASSIGN(MigrationTwoClientTest);
};
IN_PROC_BROWSER_TEST_F(MigrationTwoClientTest, MigratePrefsThenModifyBookmark) {
RunTwoClientMigrationTest(MakeList(syncer::PREFERENCES),
MODIFY_BOOKMARK);
}
IN_PROC_BROWSER_TEST_F(MigrationTwoClientTest,
MigratePrefsAndBookmarksThenModifyBookmark) {
RunTwoClientMigrationTest(
MakeList(syncer::PREFERENCES, syncer::BOOKMARKS),
MODIFY_BOOKMARK);
}
IN_PROC_BROWSER_TEST_F(MigrationTwoClientTest,
DISABLED_MigrationHellWithoutNigori) {
ASSERT_TRUE(SetupClients());
MigrationList migration_list = GetPreferredDataTypesList();
migration_list.push_front(MakeSet(syncer::THEMES));
RunTwoClientMigrationTest(migration_list, MODIFY_BOOKMARK);
}
IN_PROC_BROWSER_TEST_F(MigrationTwoClientTest,
DISABLED_MigrationHellWithNigori) {
ASSERT_TRUE(SetupClients());
MigrationList migration_list = GetPreferredDataTypesList();
migration_list.push_front(MakeSet(syncer::THEMES));
ASSERT_GE(migration_list.size(), 2u);
ASSERT_FALSE(migration_list.back().Equals(MakeSet(syncer::NIGORI)));
migration_list.back() = MakeSet(syncer::NIGORI);
RunTwoClientMigrationTest(migration_list, MODIFY_BOOKMARK);
}
class MigrationReconfigureTest : public MigrationTwoClientTest {
public:
MigrationReconfigureTest() {}
virtual void SetUpCommandLine(base::CommandLine* cl) OVERRIDE {
AddTestSwitches(cl);
}
virtual ~MigrationReconfigureTest() {}
private:
DISALLOW_COPY_AND_ASSIGN(MigrationReconfigureTest);
};
}