summaryrefslogtreecommitdiffstats
path: root/chrome/browser/search_engines/template_url_prepopulate_data_unittest.cc
diff options
context:
space:
mode:
authorpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-14 21:36:02 +0000
committerpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-14 21:36:02 +0000
commit623de74f174b29368b6e0c87527c84955212dddd (patch)
tree389eb3b7e11b1d84e3bbcc30defc6c5219e1327e /chrome/browser/search_engines/template_url_prepopulate_data_unittest.cc
parent004b37467a9957faa835512904381b158501ab9d (diff)
downloadchromium_src-623de74f174b29368b6e0c87527c84955212dddd.zip
chromium_src-623de74f174b29368b6e0c87527c84955212dddd.tar.gz
chromium_src-623de74f174b29368b6e0c87527c84955212dddd.tar.bz2
Clean up TemplateURL prepopulate data:
* Replace a pair of overlapping functions in the API with two distinct accessors for relevant pieces of information about prepopulated URLs. One key side effect here is that we no longer return TemplateURL*s from these, which will make the upcoming refactoring changes slightly cleaner. * Make the implementation of these a bit more robust w.r.t. determining if a provided URL corresponds to Google. This will also be important later as we'll want to be able to match a hand-coded "google.co.uk" entry against an auto-generated "google.de" entry (or similar). * Remove a bunch of string conversions, as well as a lot of passing of raw C-style string pointers. * Remove using statements. * Remove two obscure engines which have the same hostname as another, different engine. These cause problems when we ask for the name or type of an engine because the answer we get back is basically indeterminate. I don't think either of these is very important (they lived at slots 4 and 5 in their respective countries) so just gut them. BUG=none TEST=none Review URL: https://chromiumcodereview.appspot.com/9705021 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@126746 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/search_engines/template_url_prepopulate_data_unittest.cc')
-rw-r--r--chrome/browser/search_engines/template_url_prepopulate_data_unittest.cc113
1 files changed, 42 insertions, 71 deletions
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 7a6d2d7..672f0d1 100644
--- a/chrome/browser/search_engines/template_url_prepopulate_data_unittest.cc
+++ b/chrome/browser/search_engines/template_url_prepopulate_data_unittest.cc
@@ -6,7 +6,6 @@
#include "base/memory/scoped_vector.h"
#include "base/scoped_temp_dir.h"
#include "base/utf_string_conversions.h"
-#include "chrome/browser/search_engines/search_engine_type.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_service.h"
@@ -14,7 +13,9 @@
#include "chrome/common/pref_names.h"
#include "chrome/test/base/testing_pref_service.h"
#include "chrome/test/base/testing_profile.h"
+#include "grit/generated_resources.h"
#include "testing/gtest/include/gtest/gtest.h"
+#include "ui/base/l10n/l10n_util.h"
typedef testing::Test TemplateURLPrepopulateDataTest;
@@ -71,14 +72,14 @@ const int kCountryIds[] = {
// Verifies the set of prepopulate data doesn't contain entries with duplicate
// ids.
-TEST_F(TemplateURLPrepopulateDataTest, UniqueIDs) {
+TEST(TemplateURLPrepopulateDataTest, UniqueIDs) {
TestingProfile profile;
for (size_t i = 0; i < arraysize(kCountryIds); ++i) {
profile.GetPrefs()->SetInteger(prefs::kCountryIDAtInstall, kCountryIds[i]);
ScopedVector<TemplateURL> urls;
size_t default_index;
- TemplateURLPrepopulateData::GetPrepopulatedEngines(
- profile.GetPrefs(), &(urls.get()), &default_index);
+ TemplateURLPrepopulateData::GetPrepopulatedEngines(profile.GetPrefs(),
+ &urls.get(), &default_index);
std::set<int> unique_ids;
for (size_t turl_i = 0; turl_i < urls.size(); ++turl_i) {
ASSERT_TRUE(unique_ids.find(urls[turl_i]->prepopulate_id()) ==
@@ -90,11 +91,11 @@ TEST_F(TemplateURLPrepopulateDataTest, UniqueIDs) {
// Verifies that default search providers from the preferences file
// override the built-in ones.
-TEST_F(TemplateURLPrepopulateDataTest, ProvidersFromPrefs) {
- TestingPrefService prefs;
- TemplateURLPrepopulateData::RegisterUserPrefs(&prefs);
- prefs.SetUserPref(prefs::kSearchProviderOverridesVersion,
- Value::CreateIntegerValue(1));
+TEST(TemplateURLPrepopulateDataTest, ProvidersFromPrefs) {
+ TestingProfile profile;
+ TestingPrefService* prefs = profile.GetTestingPrefService();
+ prefs->SetUserPref(prefs::kSearchProviderOverridesVersion,
+ Value::CreateIntegerValue(1));
ListValue* overrides = new ListValue;
DictionaryValue* entry = new DictionaryValue;
entry->SetString("name", "foo");
@@ -107,15 +108,15 @@ TEST_F(TemplateURLPrepopulateDataTest, ProvidersFromPrefs) {
entry->SetInteger("search_engine_type", 1);
entry->SetInteger("id", 1001);
overrides->Append(entry);
- prefs.SetUserPref(prefs::kSearchProviderOverrides, overrides);
+ prefs->SetUserPref(prefs::kSearchProviderOverrides, overrides);
- int version = TemplateURLPrepopulateData::GetDataVersion(&prefs);
+ int version = TemplateURLPrepopulateData::GetDataVersion(prefs);
EXPECT_EQ(1, version);
ScopedVector<TemplateURL> t_urls;
size_t default_index;
- TemplateURLPrepopulateData::GetPrepopulatedEngines(
- &prefs, &(t_urls.get()), &default_index);
+ TemplateURLPrepopulateData::GetPrepopulatedEngines(prefs, &t_urls.get(),
+ &default_index);
ASSERT_EQ(1u, t_urls.size());
EXPECT_EQ(ASCIIToUTF16("foo"), t_urls[0]->short_name());
@@ -124,53 +125,31 @@ TEST_F(TemplateURLPrepopulateDataTest, ProvidersFromPrefs) {
EXPECT_EQ("foi.com", t_urls[0]->GetFaviconURL().host());
EXPECT_EQ(1u, t_urls[0]->input_encodings().size());
EXPECT_EQ(1001, t_urls[0]->prepopulate_id());
- EXPECT_EQ(SEARCH_ENGINE_GOOGLE, t_urls[0]->search_engine_type());
}
-TEST_F(TemplateURLPrepopulateDataTest, SearchEngineFromOrigin) {
- UIThreadSearchTermsData search_terms_data;
- std::set<GURL> unique_engines;
-
- { // Scoping for the profile.
- TestingProfile profile;
- for (size_t i = 0; i < arraysize(kCountryIds); ++i) {
- profile.GetPrefs()->SetInteger(prefs::kCountryIDAtInstall,
- kCountryIds[i]);
- ScopedVector<TemplateURL> urls;
- size_t default_index;
- TemplateURLPrepopulateData::GetPrepopulatedEngines(
- profile.GetPrefs(), &(urls.get()), &default_index);
- for (size_t turl_i = 0; turl_i < urls.size(); ++turl_i) {
- GURL engine_url(urls[turl_i]->url()->url());
- if (!engine_url.is_valid()) {
- engine_url = TemplateURLService::GenerateSearchURLUsingTermsData(
- urls[turl_i], search_terms_data);
- }
- GURL origin = engine_url.GetOrigin();
- unique_engines.insert(origin);
- }
- }
- }
-
- TestingProfile profile;
- for (std::set<GURL>::iterator it = unique_engines.begin();
- it != unique_engines.end(); ++it) {
- scoped_ptr<TemplateURL> found_url(
- TemplateURLPrepopulateData::GetEngineForOrigin(profile.GetPrefs(),
- *it));
- EXPECT_EQ(
- TemplateURLService::GenerateSearchURLUsingTermsData(
- found_url.get(), search_terms_data).GetOrigin(),
- it->GetOrigin());
- }
+TEST(TemplateURLPrepopulateDataTest, GetEngineName) {
+ EXPECT_EQ(ASCIIToUTF16("Atlas"),
+ TemplateURLPrepopulateData::GetEngineName("http://search.atlas.cz/"));
+ EXPECT_EQ(ASCIIToUTF16("Google"),
+ TemplateURLPrepopulateData::GetEngineName("http://www.google.com/"));
+ EXPECT_EQ(ASCIIToUTF16("example.com"),
+ TemplateURLPrepopulateData::GetEngineName("http://example.com/"));
+ EXPECT_EQ(l10n_util::GetStringUTF16(IDS_UNKNOWN_SEARCH_ENGINE_NAME),
+ TemplateURLPrepopulateData::GetEngineName("!@#"));
+}
- GURL not_a_search_engine("http://example.com/");
- EXPECT_EQ(NULL, TemplateURLPrepopulateData::GetEngineForOrigin(
- profile.GetPrefs(),
- not_a_search_engine));
+TEST(TemplateURLPrepopulateDataTest, GetEngineTypeBasic) {
+ EXPECT_EQ(SEARCH_ENGINE_OTHER,
+ TemplateURLPrepopulateData::GetEngineType("http://example.com/"));
+ EXPECT_EQ(SEARCH_ENGINE_ASK,
+ TemplateURLPrepopulateData::GetEngineType("http://www.ask.com/"));
+ EXPECT_EQ(SEARCH_ENGINE_OTHER,
+ TemplateURLPrepopulateData::GetEngineType("http://search.atlas.cz/"));
+ EXPECT_EQ(SEARCH_ENGINE_GOOGLE,
+ TemplateURLPrepopulateData::GetEngineType("http://www.google.com/"));
}
-TEST_F(TemplateURLPrepopulateDataTest, FindPrepopulatedEngine) {
+TEST_F(TemplateURLPrepopulateDataTest, GetEngineTypeAdvanced) {
// Google URLs in different forms.
const char* kGoogleURLs[] = {
// Original with google:baseURL:
@@ -189,13 +168,9 @@ TEST_F(TemplateURLPrepopulateDataTest, FindPrepopulatedEngine) {
"{google:instantFieldTrialGroupParameter}"
"sourceid=chrome&ie={inputEncoding}&q={searchTerms}"
};
- scoped_ptr<TemplateURL> t_url;
for (size_t i = 0; i < arraysize(kGoogleURLs); ++i) {
- t_url.reset(
- TemplateURLPrepopulateData::FindPrepopulatedEngine(kGoogleURLs[i]));
- ASSERT_TRUE(t_url.get());
- // Google's prepopulated ID is 1.
- EXPECT_EQ(1, t_url->prepopulate_id());
+ EXPECT_EQ(SEARCH_ENGINE_GOOGLE,
+ TemplateURLPrepopulateData::GetEngineType(kGoogleURLs[i]));
}
// Non-Google URLs.
const char* kYahooURLs[] = {
@@ -204,17 +179,13 @@ TEST_F(TemplateURLPrepopulateDataTest, FindPrepopulatedEngine) {
"http://search.yahoo.com/search?p={searchTerms}"
};
for (size_t i = 0; i < arraysize(kYahooURLs); ++i) {
- t_url.reset(
- TemplateURLPrepopulateData::FindPrepopulatedEngine(kYahooURLs[i]));
- ASSERT_TRUE(t_url.get());
- // Yahoo!'s prepopulated ID is 2.
- EXPECT_EQ(2, t_url->prepopulate_id());
+ EXPECT_EQ(SEARCH_ENGINE_YAHOO,
+ TemplateURLPrepopulateData::GetEngineType(kYahooURLs[i]));
}
// Search URL for which no prepopulated search provider exists.
std::string kExampleSearchURL = "http://example.net/search?q={searchTerms}";
- EXPECT_FALSE(TemplateURLPrepopulateData::FindPrepopulatedEngine(
- kExampleSearchURL));
- // Invalid search URL.
- EXPECT_FALSE(TemplateURLPrepopulateData::FindPrepopulatedEngine(
- "invalid:search:url"));
+ EXPECT_EQ(SEARCH_ENGINE_OTHER,
+ TemplateURLPrepopulateData::GetEngineType(kExampleSearchURL));
+ EXPECT_EQ(SEARCH_ENGINE_OTHER,
+ TemplateURLPrepopulateData::GetEngineType("invalid:search:url"));
}