-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());
-}
-