Commit 3295f031 authored by stevet@chromium.org's avatar stevet@chromium.org

Ensure that MergeDataAndStartSyncing considers already synced entries when setting the synced DSP.

Add a regression test to verify this.

BUG=142872
TEST=Ensure that bug 142872 is no longer reproducible.

Review URL: https://chromiumcodereview.appspot.com/10831338

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@152156 0039d316-1c4b-4281-b951-d872f2087c98
parent 762f8d91
...@@ -1165,6 +1165,15 @@ syncer::SyncError TemplateURLService::MergeDataAndStartSyncing( ...@@ -1165,6 +1165,15 @@ syncer::SyncError TemplateURLService::MergeDataAndStartSyncing(
} }
} }
// If there is a pending synced default search provider that was processed
// above, set it now.
TemplateURL* pending_default = GetPendingSyncedDefaultSearchProvider();
if (pending_default) {
AutoReset<DefaultSearchChangeOrigin> change_origin(
&dsp_change_origin_, DSP_CHANGE_SYNC_ADD);
SetDefaultSearchProvider(pending_default);
}
// The remaining SyncData in local_data_map should be everything that needs to // The remaining SyncData in local_data_map should be everything that needs to
// be pushed as ADDs to sync. // be pushed as ADDs to sync.
for (SyncDataMap::const_iterator iter = local_data_map.begin(); for (SyncDataMap::const_iterator iter = local_data_map.begin();
...@@ -2425,9 +2434,6 @@ void TemplateURLService::MergeInSyncTemplateURL( ...@@ -2425,9 +2434,6 @@ void TemplateURLService::MergeInSyncTemplateURL(
TemplateURLData data(sync_turl->data()); TemplateURLData data(sync_turl->data());
data.id = kInvalidTemplateURLID; data.id = kInvalidTemplateURLID;
Add(new TemplateURL(profile_, data)); Add(new TemplateURL(profile_, data));
// Possibly set the newly added |turl| as the default search provider.
SetDefaultSearchProviderIfNewlySynced(guid);
} }
} }
......
...@@ -1570,6 +1570,40 @@ TEST_F(TemplateURLServiceSyncTest, SyncedDefaultAlreadySetOnStartup) { ...@@ -1570,6 +1570,40 @@ TEST_F(TemplateURLServiceSyncTest, SyncedDefaultAlreadySetOnStartup) {
ASSERT_EQ(default_search, model()->GetDefaultSearchProvider()); ASSERT_EQ(default_search, model()->GetDefaultSearchProvider());
} }
TEST_F(TemplateURLServiceSyncTest, NewDefaultIsAlreadySynced) {
// Ensure that if the synced DSP pref changed to another synced entry (as
// opposed to coming in as a new entry), it gets reset correctly.
// Start by setting kSyncedDefaultSearchProviderGUID to the entry that should
// end up as the default. Note that this must be done before the initial
// entries are added as otherwise this call will set the DSP immediately.
profile_a()->GetTestingPrefService()->SetString(
prefs::kSyncedDefaultSearchProviderGUID, "key2");
syncer::SyncDataList initial_data = CreateInitialSyncData();
// Ensure that our candidate default supports replacement.
scoped_ptr<TemplateURL> turl(CreateTestTemplateURL(ASCIIToUTF16("key2"),
"http://key2.com/{searchTerms}", "key2", 90));
initial_data[1] = TemplateURLService::CreateSyncDataFromTemplateURL(*turl);
for (syncer::SyncDataList::const_iterator iter = initial_data.begin();
iter != initial_data.end(); ++iter) {
TemplateURL* converted = Deserialize(*iter);
model()->Add(converted);
}
// Set the initial default to something other than the desired default.
model()->SetDefaultSearchProvider(model()->GetTemplateURLForGUID("key1"));
// Merge in the same data (i.e. already synced entries).
model()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, initial_data,
PassProcessor(), CreateAndPassSyncErrorFactory());
EXPECT_EQ(3U, model()->GetAllSyncData(syncer::SEARCH_ENGINES).size());
TemplateURL* current_default = model()->GetDefaultSearchProvider();
ASSERT_TRUE(current_default);
EXPECT_EQ("key2", current_default->sync_guid());
EXPECT_EQ(ASCIIToUTF16("key2"), current_default->keyword());
}
TEST_F(TemplateURLServiceSyncTest, SyncWithManagedDefaultSearch) { TEST_F(TemplateURLServiceSyncTest, SyncWithManagedDefaultSearch) {
// First start off with a few entries and make sure we can set an unmanaged // First start off with a few entries and make sure we can set an unmanaged
// default search provider. // default search provider.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment