Skip to content

Commit

Permalink
Add methods to ProfileSyncServiceTestHarness to enable / disable sync…
Browse files Browse the repository at this point in the history
… for datatypes.

Some sync integration tests require functionality to enable or disable
sync for a given datatype.

BUG=55772,55650
TEST=sync_integration_tests

Review URL: http://codereview.chromium.org/3390007

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@59700 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
rsimha@chromium.org committed Sep 16, 2010
1 parent 1e72e6a commit bb41572
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 26 deletions.
59 changes: 56 additions & 3 deletions chrome/test/live_sync/profile_sync_service_test_harness.cc
Original file line number Diff line number Diff line change
Expand Up @@ -305,12 +305,12 @@ bool ProfileSyncServiceTestHarness::WaitForServiceInit() {
}

// Choose datatypes to be synced.
syncable::ModelTypeSet set;
syncable::ModelTypeSet synced_datatypes;
for (int i = syncable::FIRST_REAL_MODEL_TYPE;
i < syncable::MODEL_TYPE_COUNT; ++i) {
set.insert(syncable::ModelTypeFromInt(i));
synced_datatypes.insert(syncable::ModelTypeFromInt(i));
}
service()->OnUserChoseDatatypes(true, set);
service()->OnUserChoseDatatypes(true, synced_datatypes);

// Wait for initial sync cycle to complete.
EXPECT_EQ(wait_state_, WAITING_FOR_INITIAL_SYNC);
Expand Down Expand Up @@ -351,6 +351,59 @@ const SyncSessionSnapshot*
return NULL;
}

void ProfileSyncServiceTestHarness::EnableSyncForDatatype(
syncable::ModelType datatype) {
syncable::ModelTypeSet synced_datatypes;
EXPECT_FALSE(service() == NULL)
<< "EnableSyncForDatatype(): service() is null.";
service()->GetPreferredDataTypes(&synced_datatypes);
syncable::ModelTypeSet::iterator it = synced_datatypes.find(
syncable::ModelTypeFromInt(datatype));
if (it == synced_datatypes.end()) {
synced_datatypes.insert(syncable::ModelTypeFromInt(datatype));
service()->OnUserChoseDatatypes(false, synced_datatypes);
AwaitSyncCycleCompletion("Waiting for datatype configuration.");
LOG(INFO) << "EnableSyncForDatatype(): Enabled sync for datatype "
<< syncable::ModelTypeToString(datatype) << ".";
} else {
LOG(INFO) << "EnableSyncForDatatype(): Sync already enabled for datatype "
<< syncable::ModelTypeToString(datatype) << ".";
}
}

void ProfileSyncServiceTestHarness::DisableSyncForDatatype(
syncable::ModelType datatype) {
syncable::ModelTypeSet synced_datatypes;
EXPECT_FALSE(service() == NULL)
<< "DisableSyncForDatatype(): service() is null.";
service()->GetPreferredDataTypes(&synced_datatypes);
syncable::ModelTypeSet::iterator it = synced_datatypes.find(
syncable::ModelTypeFromInt(datatype));
if (it != synced_datatypes.end()) {
synced_datatypes.erase(it);
service()->OnUserChoseDatatypes(false, synced_datatypes);
AwaitSyncCycleCompletion("Waiting for datatype configuration.");
LOG(INFO) << "DisableSyncForDatatype(): Disabled sync for datatype "
<< syncable::ModelTypeToString(datatype) << ".";
} else {
LOG(INFO) << "DisableSyncForDatatype(): Sync already disabled for datatype "
<< syncable::ModelTypeToString(datatype) << ".";
}
}

void ProfileSyncServiceTestHarness::EnableSyncForAllDatatypes() {
syncable::ModelTypeSet synced_datatypes;
for (int i = syncable::FIRST_REAL_MODEL_TYPE;
i < syncable::MODEL_TYPE_COUNT; ++i) {
synced_datatypes.insert(syncable::ModelTypeFromInt(i));
}
EXPECT_FALSE(service() == NULL)
<< "EnableSyncForAllDatatypes(): service() is null.";
service()->OnUserChoseDatatypes(true, synced_datatypes);
AwaitSyncCycleCompletion("Waiting for datatype configuration.");
LOG(INFO) << "EnableSyncForAllDatatypes(): Enabled sync for all datatypes.";
}

int64 ProfileSyncServiceTestHarness::GetUpdatedTimestamp() {
const SyncSessionSnapshot* snap = GetLastSessionSnapshot();
EXPECT_FALSE(snap == NULL) << "GetUpdatedTimestamp(): Sync snapshot is NULL.";
Expand Down
9 changes: 9 additions & 0 deletions chrome/test/live_sync/profile_sync_service_test_harness.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,15 @@ class ProfileSyncServiceTestHarness : public ProfileSyncServiceObserver {
// See ProfileSyncService::ShouldPushChanges().
bool ServiceIsPushingChanges() { return service_->ShouldPushChanges(); }

// Enables sync for a particular sync datatype.
void EnableSyncForDatatype(syncable::ModelType datatype);

// Disables sync for a particular sync datatype.
void DisableSyncForDatatype(syncable::ModelType datatype);

// Enables sync for all sync datatypes.
void EnableSyncForAllDatatypes();

private:
friend class StateChangeTimeoutEvent;

Expand Down
42 changes: 19 additions & 23 deletions chrome/test/live_sync/two_client_live_preferences_sync_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,36 +64,30 @@ IN_PROC_BROWSER_TEST_F(TwoClientLivePreferencesSyncTest,
EXPECT_EQ(GetPrefs(0)->GetBoolean(prefs::kSyncThemes),
GetPrefs(1)->GetBoolean(prefs::kSyncThemes));

GetPrefs(0)->SetBoolean(prefs::kKeepEverythingSynced, 0);
GetPrefs(0)->SetBoolean(prefs::kSyncThemes, 0);
GetPrefs(1)->SetBoolean(prefs::kKeepEverythingSynced, 1);
EXPECT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
GetClient(0)->DisableSyncForDatatype(syncable::THEMES);

EXPECT_NE(GetPrefs(0)->GetBoolean(prefs::kKeepEverythingSynced),
GetPrefs(1)->GetBoolean(prefs::kKeepEverythingSynced));
}

// TODO(rsimha): Remove FAILS_ prefix after http://crbug.com/55650 is fixed.
IN_PROC_BROWSER_TEST_F(TwoClientLivePreferencesSyncTest,
FAILS_kSyncPreferences) {
IN_PROC_BROWSER_TEST_F(TwoClientLivePreferencesSyncTest, kSyncPreferences) {
ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
EXPECT_EQ(GetPrefs(0)->GetBoolean(prefs::kSyncPreferences),
GetPrefs(1)->GetBoolean(prefs::kSyncPreferences));
EXPECT_EQ(GetPrefs(0)->GetBoolean(prefs::kPasswordManagerEnabled),
GetPrefs(1)->GetBoolean(prefs::kPasswordManagerEnabled));

GetPrefs(0)->SetBoolean(prefs::kKeepEverythingSynced, 0);
GetPrefs(0)->SetBoolean(prefs::kSyncPreferences, 0);
GetClient(0)->DisableSyncForDatatype(syncable::PREFERENCES);

GetPrefs(0)->SetBoolean(prefs::kPasswordManagerEnabled, 1);
GetPrefs(1)->SetBoolean(prefs::kPasswordManagerEnabled, 0);
EXPECT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
ASSERT_TRUE(ProfileSyncServiceTestHarness::AwaitQuiescence(clients()));

EXPECT_NE(GetPrefs(0)->GetBoolean(prefs::kPasswordManagerEnabled),
GetPrefs(1)->GetBoolean(prefs::kPasswordManagerEnabled));
}

IN_PROC_BROWSER_TEST_F(TwoClientLivePreferencesSyncTest,
SignInDialog) {
IN_PROC_BROWSER_TEST_F(TwoClientLivePreferencesSyncTest, SignInDialog) {
ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
EXPECT_EQ(GetPrefs(0)->GetBoolean(prefs::kSyncPreferences),
GetPrefs(1)->GetBoolean(prefs::kSyncPreferences));
Expand All @@ -108,19 +102,21 @@ IN_PROC_BROWSER_TEST_F(TwoClientLivePreferencesSyncTest,
EXPECT_EQ(GetPrefs(0)->GetBoolean(prefs::kKeepEverythingSynced),
GetPrefs(1)->GetBoolean(prefs::kKeepEverythingSynced));

GetPrefs(0)->SetBoolean(prefs::kKeepEverythingSynced, 0);
GetPrefs(1)->SetBoolean(prefs::kKeepEverythingSynced, 1);
GetPrefs(0)->SetBoolean(prefs::kSyncAutofill, 0);
GetPrefs(1)->SetBoolean(prefs::kSyncAutofill, 1);
GetPrefs(0)->SetBoolean(prefs::kSyncBookmarks, 0);
GetPrefs(1)->SetBoolean(prefs::kSyncBookmarks, 1);
GetPrefs(0)->SetBoolean(prefs::kSyncExtensions, 0);
GetPrefs(1)->SetBoolean(prefs::kSyncExtensions, 1);
GetPrefs(0)->SetBoolean(prefs::kSyncThemes, 0);
GetPrefs(1)->SetBoolean(prefs::kSyncThemes, 1);
GetClient(0)->DisableSyncForDatatype(syncable::PREFERENCES);
GetClient(1)->EnableSyncForDatatype(syncable::PREFERENCES);
GetClient(0)->DisableSyncForDatatype(syncable::AUTOFILL);
GetClient(1)->EnableSyncForDatatype(syncable::AUTOFILL);
GetClient(0)->DisableSyncForDatatype(syncable::BOOKMARKS);
GetClient(1)->EnableSyncForDatatype(syncable::BOOKMARKS);
GetClient(0)->DisableSyncForDatatype(syncable::EXTENSIONS);
GetClient(1)->EnableSyncForDatatype(syncable::EXTENSIONS);
GetClient(0)->DisableSyncForDatatype(syncable::THEMES);
GetClient(1)->EnableSyncForDatatype(syncable::THEMES);

EXPECT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
ASSERT_TRUE(ProfileSyncServiceTestHarness::AwaitQuiescence(clients()));

EXPECT_NE(GetPrefs(0)->GetBoolean(prefs::kSyncPreferences),
GetPrefs(1)->GetBoolean(prefs::kSyncPreferences));
EXPECT_NE(GetPrefs(0)->GetBoolean(prefs::kSyncAutofill),
GetPrefs(1)->GetBoolean(prefs::kSyncAutofill));
EXPECT_NE(GetPrefs(0)->GetBoolean(prefs::kSyncBookmarks),
Expand Down

0 comments on commit bb41572

Please sign in to comment.