Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1672)

Unified Diff: chrome/browser/search_engines/template_url_prepopulate_data_unittest.cc

Issue 15572002: Implemented 'Reset Search engines' feature. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Android compilation error Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/search_engines/template_url_prepopulate_data_unittest.cc
diff --git a/chrome/browser/search_engines/template_url_prepopulate_data_unittest.cc b/chrome/browser/search_engines/template_url_prepopulate_data_unittest.cc
index aa4799202bf417072d53b75cd248a3b7e0887692..f6dc37f4c50b43f567295bf35fe474dbedc8de75 100644
--- a/chrome/browser/search_engines/template_url_prepopulate_data_unittest.cc
+++ b/chrome/browser/search_engines/template_url_prepopulate_data_unittest.cc
@@ -7,6 +7,7 @@
#include "base/files/scoped_temp_dir.h"
#include "base/memory/scoped_vector.h"
#include "base/utf_string_conversions.h"
+#include "chrome/browser/search_engines/prepopulated_engines.h"
#include "chrome/browser/search_engines/search_terms_data.h"
#include "chrome/browser/search_engines/template_url.h"
#include "chrome/browser/search_engines/template_url_prepopulate_data.h"
@@ -182,6 +183,55 @@ TEST(TemplateURLPrepopulateDataTest, ProvidersFromPrefs) {
EXPECT_EQ(2u, t_urls.size());
}
+TEST(TemplateURLPrepopulateDataTest, ClearProvidersFromPrefs) {
+ // Use United States.
+ CommandLine::ForCurrentProcess()->AppendSwitchASCII(
+ switches::kCountry, "US");
+ TestingProfile profile;
+ TestingPrefServiceSyncable* prefs = profile.GetTestingPrefService();
+ prefs->SetUserPref(prefs::kSearchProviderOverridesVersion,
+ Value::CreateIntegerValue(1));
+ ListValue* overrides = new ListValue;
+ scoped_ptr<DictionaryValue> entry(new DictionaryValue);
+ // Set only the minimal required settings for a search provider configuration.
+ entry->SetString("name", "foo");
+ entry->SetString("keyword", "fook");
+ entry->SetString("search_url", "http://foo.com/s?q={searchTerms}");
+ entry->SetString("favicon_url", "http://foi.com/favicon.ico");
+ entry->SetString("encoding", "UTF-8");
+ entry->SetInteger("id", 1001);
+ overrides->Append(entry->DeepCopy());
battre 2013/05/22 14:03:37 nit: Either entry.Pass() or allocate entry on the
vasilii 2013/05/22 18:54:08 Done.
+ prefs->SetUserPref(prefs::kSearchProviderOverrides, overrides);
+
+ int version = TemplateURLPrepopulateData::GetDataVersion(prefs);
+ EXPECT_EQ(1, version);
+
+ // This call removes the above search engine.
+ TemplateURLPrepopulateData::ClearPrepopulatedEnginesInPrefs(&profile);
+
+ version = TemplateURLPrepopulateData::GetDataVersion(prefs);
+ EXPECT_EQ(TemplateURLPrepopulateData::kCurrentDataVersion, version);
+
+ ScopedVector<TemplateURL> t_urls;
+ size_t default_index;
+ TemplateURLPrepopulateData::GetPrepopulatedEngines(&profile, &t_urls.get(),
+ &default_index);
+ ASSERT_FALSE(t_urls.empty());
+ for (size_t i = 0; i < t_urls.size(); ++i) {
+ EXPECT_NE(ASCIIToUTF16("foo"), t_urls[i]->short_name());
+ EXPECT_NE(ASCIIToUTF16("fook"), t_urls[i]->keyword());
+ EXPECT_NE("foi.com", t_urls[i]->favicon_url().host());
+ EXPECT_NE("foo.com", t_urls[i]->url_ref().GetHost());
+ EXPECT_NE(1001, t_urls[i]->prepopulate_id());
+ }
+ // Ensures the default URL is Google and has the optional fields filled.
+ EXPECT_EQ(ASCIIToUTF16("Google"), t_urls[default_index]->short_name());
+ EXPECT_FALSE(t_urls[default_index]->suggestions_url().empty());
+ EXPECT_FALSE(t_urls[default_index]->instant_url().empty());
+ EXPECT_EQ(SEARCH_ENGINE_GOOGLE,
+ TemplateURLPrepopulateData::GetEngineType(t_urls[default_index]->url()));
+}
+
// Verifies that built-in search providers are processed correctly.
TEST(TemplateURLPrepopulateDataTest, ProvidersFromPrepopulated) {
// Use United States.

Powered by Google App Engine
This is Rietveld 408576698