Index: chrome/browser/search_engines/template_url_service_unittest.cc |
diff --git a/chrome/browser/search_engines/template_url_service_unittest.cc b/chrome/browser/search_engines/template_url_service_unittest.cc |
index ddc06380b068dc5a15b115a81b7277584f0d54a4..439eda928af13fc9546ad5b287b041128e2d751b 100644 |
--- a/chrome/browser/search_engines/template_url_service_unittest.cc |
+++ b/chrome/browser/search_engines/template_url_service_unittest.cc |
@@ -28,10 +28,12 @@ |
#include "chrome/test/base/testing_profile.h" |
#include "components/history/core/browser/history_service.h" |
#include "components/search_engines/keyword_web_data_service.h" |
+#include "components/search_engines/search_engines_pref_names.h" |
#include "components/search_engines/search_host_to_urls_map.h" |
#include "components/search_engines/search_terms_data.h" |
#include "components/search_engines/template_url.h" |
#include "components/search_engines/template_url_prepopulate_data.h" |
+#include "components/sync_preferences/testing_pref_service_syncable.h" |
#include "content/public/test/test_browser_thread_bundle.h" |
#include "testing/gtest/include/gtest/gtest.h" |
@@ -893,6 +895,46 @@ TEST_F(TemplateURLServiceTest, RepairSearchEnginesWithManagedDefault) { |
ExpectSimilar(expected_managed_default.get(), actual_managed_default); |
} |
+TEST_F(TemplateURLServiceTest, RepairPrepopulatedEnginesUpdatesSyncGuid) { |
+ test_util()->VerifyLoad(); |
+ |
+ // Expect no synced DSE guid until user selected something or sync come in. |
+ EXPECT_TRUE(test_util() |
+ ->profile() |
+ ->GetTestingPrefService() |
+ ->GetString(prefs::kSyncedDefaultSearchProviderGUID) |
+ .empty()); |
+ |
+ // Google engine must exist. |
+ TemplateURL* google = |
+ model()->GetTemplateURLForKeyword(ASCIIToUTF16("google.com")); |
+ ASSERT_TRUE(google); |
+ // Add third-party default search engine. |
+ TemplateURL* user_dse = AddKeywordWithDate( |
+ "user_dse", "user_dse.com", "http://www.user_dse.com/s?q={searchTerms}", |
+ std::string(), std::string(), std::string(), true, "UTF-8", Time(), |
+ Time(), Time()); |
+ model()->SetUserSelectedDefaultSearchProvider(user_dse); |
+ EXPECT_EQ(user_dse, model()->GetDefaultSearchProvider()); |
+ |
+ // Check that user DSE guid is stored in kSyncedDefaultSearchProviderGUID. |
+ EXPECT_EQ(user_dse->sync_guid(), |
+ test_util()->profile()->GetTestingPrefService()->GetString( |
+ prefs::kSyncedDefaultSearchProviderGUID)); |
+ |
+ model()->RepairPrepopulatedSearchEngines(); |
+ |
+ // Check that Google is default after repair. |
+ ASSERT_EQ(google, model()->GetDefaultSearchProvider()); |
+ // Check that google guid is stored in kSyncedDefaultSearchProviderGUID. |
+ const std::string dse_guid = |
+ test_util()->profile()->GetTestingPrefService()->GetString( |
+ prefs::kSyncedDefaultSearchProviderGUID); |
+ EXPECT_EQ(google->sync_guid(), dse_guid); |
+ EXPECT_EQ(google->keyword(), |
+ model()->GetTemplateURLForGUID(dse_guid)->keyword()); |
+} |
+ |
TEST_F(TemplateURLServiceTest, UpdateKeywordSearchTermsForURL) { |
struct TestData { |
const std::string url; |