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

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: Addressed Dominic's comments 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 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 // Use United States.
187 CommandLine::ForCurrentProcess()->AppendSwitchASCII(
188 switches::kCountry, "US");
Peter Kasting 2013/05/22 21:22:57 Why is this needed? It looks like the test ought
vasilii 2013/05/23 17:03:42 Done. I copied that from the next test.
189 TestingProfile profile;
190 TestingPrefServiceSyncable* prefs = profile.GetTestingPrefService();
191 prefs->SetUserPref(prefs::kSearchProviderOverridesVersion,
192 Value::CreateIntegerValue(1));
193 ListValue* overrides = new ListValue;
194 DictionaryValue* entry(new DictionaryValue);
195 // Set only the minimal required settings for a search provider configuration.
196 entry->SetString("name", "foo");
197 entry->SetString("keyword", "fook");
198 entry->SetString("search_url", "http://foo.com/s?q={searchTerms}");
199 entry->SetString("favicon_url", "http://foi.com/favicon.ico");
200 entry->SetString("encoding", "UTF-8");
201 entry->SetInteger("id", 1001);
202 overrides->Append(entry);
203 prefs->SetUserPref(prefs::kSearchProviderOverrides, overrides);
204
205 int version = TemplateURLPrepopulateData::GetDataVersion(prefs);
206 EXPECT_EQ(1, version);
207
208 // This call removes the above search engine.
209 TemplateURLPrepopulateData::ClearPrepopulatedEnginesInPrefs(&profile);
210
211 version = TemplateURLPrepopulateData::GetDataVersion(prefs);
212 EXPECT_EQ(TemplateURLPrepopulateData::kCurrentDataVersion, version);
213
214 ScopedVector<TemplateURL> t_urls;
215 size_t default_index;
216 TemplateURLPrepopulateData::GetPrepopulatedEngines(&profile, &t_urls.get(),
217 &default_index);
218 ASSERT_FALSE(t_urls.empty());
219 for (size_t i = 0; i < t_urls.size(); ++i) {
220 EXPECT_NE(ASCIIToUTF16("foo"), t_urls[i]->short_name());
221 EXPECT_NE(ASCIIToUTF16("fook"), t_urls[i]->keyword());
222 EXPECT_NE("foi.com", t_urls[i]->favicon_url().host());
223 EXPECT_NE("foo.com", t_urls[i]->url_ref().GetHost());
224 EXPECT_NE(1001, t_urls[i]->prepopulate_id());
225 }
226 // Ensures the default URL is Google and has the optional fields filled.
227 EXPECT_EQ(ASCIIToUTF16("Google"), t_urls[default_index]->short_name());
228 EXPECT_FALSE(t_urls[default_index]->suggestions_url().empty());
229 EXPECT_FALSE(t_urls[default_index]->instant_url().empty());
230 EXPECT_EQ(SEARCH_ENGINE_GOOGLE,
231 TemplateURLPrepopulateData::GetEngineType(t_urls[default_index]->url()));
232 }
233
184 // Verifies that built-in search providers are processed correctly. 234 // Verifies that built-in search providers are processed correctly.
185 TEST(TemplateURLPrepopulateDataTest, ProvidersFromPrepopulated) { 235 TEST(TemplateURLPrepopulateDataTest, ProvidersFromPrepopulated) {
186 // Use United States. 236 // Use United States.
187 CommandLine::ForCurrentProcess()->AppendSwitchASCII( 237 CommandLine::ForCurrentProcess()->AppendSwitchASCII(
188 switches::kCountry, "US"); 238 switches::kCountry, "US");
189 TestingProfile profile; 239 TestingProfile profile;
190 ScopedVector<TemplateURL> t_urls; 240 ScopedVector<TemplateURL> t_urls;
191 size_t default_index; 241 size_t default_index;
192 TemplateURLPrepopulateData::GetPrepopulatedEngines(&profile, &t_urls.get(), 242 TemplateURLPrepopulateData::GetPrepopulatedEngines(&profile, &t_urls.get(),
193 &default_index); 243 &default_index);
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 344
295 TEST(TemplateURLPrepopulateDataTest, GetLogoURLInvalid) { 345 TEST(TemplateURLPrepopulateDataTest, GetLogoURLInvalid) {
296 TemplateURLData data; 346 TemplateURLData data;
297 data.SetURL("http://invalid:search:url/"); 347 data.SetURL("http://invalid:search:url/");
298 TemplateURL turl(NULL, data); 348 TemplateURL turl(NULL, data);
299 GURL logo_url = TemplateURLPrepopulateData::GetLogoURL( 349 GURL logo_url = TemplateURLPrepopulateData::GetLogoURL(
300 turl, TemplateURLPrepopulateData::LOGO_100_PERCENT); 350 turl, TemplateURLPrepopulateData::LOGO_100_PERCENT);
301 351
302 EXPECT_TRUE(logo_url.is_empty()); 352 EXPECT_TRUE(logo_url.is_empty());
303 } 353 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698