Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "base/file_util.h" | 6 #include "base/file_util.h" |
| 7 #include "base/files/scoped_temp_dir.h" | 7 #include "base/files/scoped_temp_dir.h" |
| 8 #include "base/memory/scoped_vector.h" | 8 #include "base/memory/scoped_vector.h" |
| 9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "chrome/browser/search_engines/prepopulated_engines.h" | |
| 10 #include "chrome/browser/search_engines/search_terms_data.h" | 11 #include "chrome/browser/search_engines/search_terms_data.h" |
| 11 #include "chrome/browser/search_engines/template_url.h" | 12 #include "chrome/browser/search_engines/template_url.h" |
| 12 #include "chrome/browser/search_engines/template_url_prepopulate_data.h" | 13 #include "chrome/browser/search_engines/template_url_prepopulate_data.h" |
| 13 #include "chrome/browser/search_engines/template_url_service.h" | 14 #include "chrome/browser/search_engines/template_url_service.h" |
| 14 #include "chrome/common/chrome_switches.h" | 15 #include "chrome/common/chrome_switches.h" |
| 15 #include "chrome/common/pref_names.h" | 16 #include "chrome/common/pref_names.h" |
| 16 #include "chrome/test/base/testing_pref_service_syncable.h" | 17 #include "chrome/test/base/testing_pref_service_syncable.h" |
| 17 #include "chrome/test/base/testing_profile.h" | 18 #include "chrome/test/base/testing_profile.h" |
| 18 #include "grit/generated_resources.h" | 19 #include "grit/generated_resources.h" |
| 19 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 175 entry->SetString("encoding", "UTF-8"); | 176 entry->SetString("encoding", "UTF-8"); |
| 176 overrides->Append(entry->DeepCopy()); | 177 overrides->Append(entry->DeepCopy()); |
| 177 prefs->SetUserPref(prefs::kSearchProviderOverrides, overrides); | 178 prefs->SetUserPref(prefs::kSearchProviderOverrides, overrides); |
| 178 | 179 |
| 179 t_urls.clear(); | 180 t_urls.clear(); |
| 180 TemplateURLPrepopulateData::GetPrepopulatedEngines(&profile, &t_urls.get(), | 181 TemplateURLPrepopulateData::GetPrepopulatedEngines(&profile, &t_urls.get(), |
| 181 &default_index); | 182 &default_index); |
| 182 EXPECT_EQ(2u, t_urls.size()); | 183 EXPECT_EQ(2u, t_urls.size()); |
| 183 } | 184 } |
| 184 | 185 |
| 186 TEST(TemplateURLPrepopulateDataTest, ClearProvidersFromPrefs) { | |
| 187 // Use United States. | |
| 188 CommandLine::ForCurrentProcess()->AppendSwitchASCII( | |
| 189 switches::kCountry, "US"); | |
| 190 TestingProfile profile; | |
| 191 TestingPrefServiceSyncable* prefs = profile.GetTestingPrefService(); | |
| 192 prefs->SetUserPref(prefs::kSearchProviderOverridesVersion, | |
| 193 Value::CreateIntegerValue(1)); | |
| 194 ListValue* overrides = new ListValue; | |
| 195 scoped_ptr<DictionaryValue> entry(new DictionaryValue); | |
| 196 // Set only the minimal required settings for a search provider configuration. | |
| 197 entry->SetString("name", "foo"); | |
| 198 entry->SetString("keyword", "fook"); | |
| 199 entry->SetString("search_url", "http://foo.com/s?q={searchTerms}"); | |
| 200 entry->SetString("favicon_url", "http://foi.com/favicon.ico"); | |
| 201 entry->SetString("encoding", "UTF-8"); | |
| 202 entry->SetInteger("id", 1001); | |
| 203 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.
| |
| 204 prefs->SetUserPref(prefs::kSearchProviderOverrides, overrides); | |
| 205 | |
| 206 int version = TemplateURLPrepopulateData::GetDataVersion(prefs); | |
| 207 EXPECT_EQ(1, version); | |
| 208 | |
| 209 // This call removes the above search engine. | |
| 210 TemplateURLPrepopulateData::ClearPrepopulatedEnginesInPrefs(&profile); | |
| 211 | |
| 212 version = TemplateURLPrepopulateData::GetDataVersion(prefs); | |
| 213 EXPECT_EQ(TemplateURLPrepopulateData::kCurrentDataVersion, version); | |
| 214 | |
| 215 ScopedVector<TemplateURL> t_urls; | |
| 216 size_t default_index; | |
| 217 TemplateURLPrepopulateData::GetPrepopulatedEngines(&profile, &t_urls.get(), | |
| 218 &default_index); | |
| 219 ASSERT_FALSE(t_urls.empty()); | |
| 220 for (size_t i = 0; i < t_urls.size(); ++i) { | |
| 221 EXPECT_NE(ASCIIToUTF16("foo"), t_urls[i]->short_name()); | |
| 222 EXPECT_NE(ASCIIToUTF16("fook"), t_urls[i]->keyword()); | |
| 223 EXPECT_NE("foi.com", t_urls[i]->favicon_url().host()); | |
| 224 EXPECT_NE("foo.com", t_urls[i]->url_ref().GetHost()); | |
| 225 EXPECT_NE(1001, t_urls[i]->prepopulate_id()); | |
| 226 } | |
| 227 // Ensures the default URL is Google and has the optional fields filled. | |
| 228 EXPECT_EQ(ASCIIToUTF16("Google"), t_urls[default_index]->short_name()); | |
| 229 EXPECT_FALSE(t_urls[default_index]->suggestions_url().empty()); | |
| 230 EXPECT_FALSE(t_urls[default_index]->instant_url().empty()); | |
| 231 EXPECT_EQ(SEARCH_ENGINE_GOOGLE, | |
| 232 TemplateURLPrepopulateData::GetEngineType(t_urls[default_index]->url())); | |
| 233 } | |
| 234 | |
| 185 // Verifies that built-in search providers are processed correctly. | 235 // Verifies that built-in search providers are processed correctly. |
| 186 TEST(TemplateURLPrepopulateDataTest, ProvidersFromPrepopulated) { | 236 TEST(TemplateURLPrepopulateDataTest, ProvidersFromPrepopulated) { |
| 187 // Use United States. | 237 // Use United States. |
| 188 CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 238 CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| 189 switches::kCountry, "US"); | 239 switches::kCountry, "US"); |
| 190 TestingProfile profile; | 240 TestingProfile profile; |
| 191 ScopedVector<TemplateURL> t_urls; | 241 ScopedVector<TemplateURL> t_urls; |
| 192 size_t default_index; | 242 size_t default_index; |
| 193 TemplateURLPrepopulateData::GetPrepopulatedEngines(&profile, &t_urls.get(), | 243 TemplateURLPrepopulateData::GetPrepopulatedEngines(&profile, &t_urls.get(), |
| 194 &default_index); | 244 &default_index); |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 295 | 345 |
| 296 TEST(TemplateURLPrepopulateDataTest, GetLogoURLInvalid) { | 346 TEST(TemplateURLPrepopulateDataTest, GetLogoURLInvalid) { |
| 297 TemplateURLData data; | 347 TemplateURLData data; |
| 298 data.SetURL("http://invalid:search:url/"); | 348 data.SetURL("http://invalid:search:url/"); |
| 299 TemplateURL turl(NULL, data); | 349 TemplateURL turl(NULL, data); |
| 300 GURL logo_url = TemplateURLPrepopulateData::GetLogoURL( | 350 GURL logo_url = TemplateURLPrepopulateData::GetLogoURL( |
| 301 turl, TemplateURLPrepopulateData::LOGO_100_PERCENT); | 351 turl, TemplateURLPrepopulateData::LOGO_100_PERCENT); |
| 302 | 352 |
| 303 EXPECT_TRUE(logo_url.is_empty()); | 353 EXPECT_TRUE(logo_url.is_empty()); |
| 304 } | 354 } |
| OLD | NEW |