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

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

Powered by Google App Engine
This is Rietveld 408576698