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

Side by Side Diff: chrome/browser/search_engines/template_url_prepopulate_data_unittest.cc

Issue 12546016: Remove the Extensions URLRequestContext (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix silly compile error Created 7 years, 4 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 | Annotate | Revision Log
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/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "chrome/browser/search_engines/prepopulated_engines.h" 9 #include "chrome/browser/search_engines/prepopulated_engines.h"
10 #include "chrome/browser/search_engines/search_terms_data.h" 10 #include "chrome/browser/search_engines/search_terms_data.h"
11 #include "chrome/browser/search_engines/template_url.h" 11 #include "chrome/browser/search_engines/template_url.h"
12 #include "chrome/browser/search_engines/template_url_prepopulate_data.h" 12 #include "chrome/browser/search_engines/template_url_prepopulate_data.h"
13 #include "chrome/browser/search_engines/template_url_service.h" 13 #include "chrome/browser/search_engines/template_url_service.h"
14 #include "chrome/common/chrome_switches.h" 14 #include "chrome/common/chrome_switches.h"
15 #include "chrome/common/pref_names.h" 15 #include "chrome/common/pref_names.h"
16 #include "chrome/test/base/testing_pref_service_syncable.h" 16 #include "chrome/test/base/testing_pref_service_syncable.h"
17 #include "chrome/test/base/testing_profile.h" 17 #include "chrome/test/base/testing_profile.h"
18 #include "content/public/test/test_browser_thread_bundle.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"
20 #include "ui/base/l10n/l10n_util.h" 21 #include "ui/base/l10n/l10n_util.h"
21 22
22 typedef testing::Test TemplateURLPrepopulateDataTest; 23 typedef testing::Test TemplateURLPrepopulateDataTest;
23 24
24 const int kCountryIds[] = { 25 const int kCountryIds[] = {
25 'A'<<8|'D', 'A'<<8|'E', 'A'<<8|'F', 'A'<<8|'G', 'A'<<8|'I', 26 'A'<<8|'D', 'A'<<8|'E', 'A'<<8|'F', 'A'<<8|'G', 'A'<<8|'I',
26 'A'<<8|'L', 'A'<<8|'M', 'A'<<8|'N', 'A'<<8|'O', 'A'<<8|'Q', 27 'A'<<8|'L', 'A'<<8|'M', 'A'<<8|'N', 'A'<<8|'O', 'A'<<8|'Q',
27 'A'<<8|'R', 'A'<<8|'S', 'A'<<8|'T', 'A'<<8|'U', 'A'<<8|'W', 28 'A'<<8|'R', 'A'<<8|'S', 'A'<<8|'T', 'A'<<8|'U', 'A'<<8|'W',
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 'T'<<8|'L', 'T'<<8|'M', 'T'<<8|'N', 'T'<<8|'O', 'T'<<8|'R', 69 'T'<<8|'L', 'T'<<8|'M', 'T'<<8|'N', 'T'<<8|'O', 'T'<<8|'R',
69 'T'<<8|'T', 'T'<<8|'V', 'T'<<8|'W', 'T'<<8|'Z', 'U'<<8|'A', 70 'T'<<8|'T', 'T'<<8|'V', 'T'<<8|'W', 'T'<<8|'Z', 'U'<<8|'A',
70 'U'<<8|'G', 'U'<<8|'M', 'U'<<8|'S', 'U'<<8|'Y', 'U'<<8|'Z', 71 'U'<<8|'G', 'U'<<8|'M', 'U'<<8|'S', 'U'<<8|'Y', 'U'<<8|'Z',
71 'V'<<8|'A', 'V'<<8|'C', 'V'<<8|'E', 'V'<<8|'G', 'V'<<8|'I', 72 'V'<<8|'A', 'V'<<8|'C', 'V'<<8|'E', 'V'<<8|'G', 'V'<<8|'I',
72 'V'<<8|'N', 'V'<<8|'U', 'W'<<8|'F', 'W'<<8|'S', 'Y'<<8|'E', 73 'V'<<8|'N', 'V'<<8|'U', 'W'<<8|'F', 'W'<<8|'S', 'Y'<<8|'E',
73 'Y'<<8|'T', 'Z'<<8|'A', 'Z'<<8|'M', 'Z'<<8|'W', -1 }; 74 'Y'<<8|'T', 'Z'<<8|'A', 'Z'<<8|'M', 'Z'<<8|'W', -1 };
74 75
75 // Verifies the set of prepopulate data doesn't contain entries with duplicate 76 // Verifies the set of prepopulate data doesn't contain entries with duplicate
76 // ids. 77 // ids.
77 TEST(TemplateURLPrepopulateDataTest, UniqueIDs) { 78 TEST(TemplateURLPrepopulateDataTest, UniqueIDs) {
79 content::TestBrowserThreadBundle thread_bundle;
78 TestingProfile profile; 80 TestingProfile profile;
79 for (size_t i = 0; i < arraysize(kCountryIds); ++i) { 81 for (size_t i = 0; i < arraysize(kCountryIds); ++i) {
80 profile.GetPrefs()->SetInteger(prefs::kCountryIDAtInstall, kCountryIds[i]); 82 profile.GetPrefs()->SetInteger(prefs::kCountryIDAtInstall, kCountryIds[i]);
81 ScopedVector<TemplateURL> urls; 83 ScopedVector<TemplateURL> urls;
82 size_t default_index; 84 size_t default_index;
83 TemplateURLPrepopulateData::GetPrepopulatedEngines(&profile, &urls.get(), 85 TemplateURLPrepopulateData::GetPrepopulatedEngines(&profile, &urls.get(),
84 &default_index); 86 &default_index);
85 std::set<int> unique_ids; 87 std::set<int> unique_ids;
86 for (size_t turl_i = 0; turl_i < urls.size(); ++turl_i) { 88 for (size_t turl_i = 0; turl_i < urls.size(); ++turl_i) {
87 ASSERT_TRUE(unique_ids.find(urls[turl_i]->prepopulate_id()) == 89 ASSERT_TRUE(unique_ids.find(urls[turl_i]->prepopulate_id()) ==
88 unique_ids.end()); 90 unique_ids.end());
89 unique_ids.insert(urls[turl_i]->prepopulate_id()); 91 unique_ids.insert(urls[turl_i]->prepopulate_id());
90 } 92 }
91 } 93 }
92 } 94 }
93 95
94 // Verifies that default search providers from the preferences file 96 // Verifies that default search providers from the preferences file
95 // override the built-in ones. 97 // override the built-in ones.
96 TEST(TemplateURLPrepopulateDataTest, ProvidersFromPrefs) { 98 TEST(TemplateURLPrepopulateDataTest, ProvidersFromPrefs) {
99 content::TestBrowserThreadBundle thread_bundle;
97 TestingProfile profile; 100 TestingProfile profile;
98 TestingPrefServiceSyncable* prefs = profile.GetTestingPrefService(); 101 TestingPrefServiceSyncable* prefs = profile.GetTestingPrefService();
99 prefs->SetUserPref(prefs::kSearchProviderOverridesVersion, 102 prefs->SetUserPref(prefs::kSearchProviderOverridesVersion,
100 Value::CreateIntegerValue(1)); 103 Value::CreateIntegerValue(1));
101 ListValue* overrides = new ListValue; 104 ListValue* overrides = new ListValue;
102 scoped_ptr<DictionaryValue> entry(new DictionaryValue); 105 scoped_ptr<DictionaryValue> entry(new DictionaryValue);
103 // Set only the minimal required settings for a search provider configuration. 106 // Set only the minimal required settings for a search provider configuration.
104 entry->SetString("name", "foo"); 107 entry->SetString("name", "foo");
105 entry->SetString("keyword", "fook"); 108 entry->SetString("keyword", "fook");
106 entry->SetString("search_url", "http://foo.com/s?q={searchTerms}"); 109 entry->SetString("search_url", "http://foo.com/s?q={searchTerms}");
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 overrides->Append(entry->DeepCopy()); 179 overrides->Append(entry->DeepCopy());
177 prefs->SetUserPref(prefs::kSearchProviderOverrides, overrides); 180 prefs->SetUserPref(prefs::kSearchProviderOverrides, overrides);
178 181
179 t_urls.clear(); 182 t_urls.clear();
180 TemplateURLPrepopulateData::GetPrepopulatedEngines(&profile, &t_urls.get(), 183 TemplateURLPrepopulateData::GetPrepopulatedEngines(&profile, &t_urls.get(),
181 &default_index); 184 &default_index);
182 EXPECT_EQ(2u, t_urls.size()); 185 EXPECT_EQ(2u, t_urls.size());
183 } 186 }
184 187
185 TEST(TemplateURLPrepopulateDataTest, ClearProvidersFromPrefs) { 188 TEST(TemplateURLPrepopulateDataTest, ClearProvidersFromPrefs) {
189 content::TestBrowserThreadBundle thread_bundle;
186 TestingProfile profile; 190 TestingProfile profile;
187 TestingPrefServiceSyncable* prefs = profile.GetTestingPrefService(); 191 TestingPrefServiceSyncable* prefs = profile.GetTestingPrefService();
188 prefs->SetUserPref(prefs::kSearchProviderOverridesVersion, 192 prefs->SetUserPref(prefs::kSearchProviderOverridesVersion,
189 Value::CreateIntegerValue(1)); 193 Value::CreateIntegerValue(1));
190 ListValue* overrides = new ListValue; 194 ListValue* overrides = new ListValue;
191 DictionaryValue* entry(new DictionaryValue); 195 DictionaryValue* entry(new DictionaryValue);
192 // Set only the minimal required settings for a search provider configuration. 196 // Set only the minimal required settings for a search provider configuration.
193 entry->SetString("name", "foo"); 197 entry->SetString("name", "foo");
194 entry->SetString("keyword", "fook"); 198 entry->SetString("keyword", "fook");
195 entry->SetString("search_url", "http://foo.com/s?q={searchTerms}"); 199 entry->SetString("search_url", "http://foo.com/s?q={searchTerms}");
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 EXPECT_EQ( 233 EXPECT_EQ(
230 SEARCH_ENGINE_GOOGLE, 234 SEARCH_ENGINE_GOOGLE,
231 TemplateURLPrepopulateData::GetEngineType(t_urls[default_index]->url())); 235 TemplateURLPrepopulateData::GetEngineType(t_urls[default_index]->url()));
232 } 236 }
233 237
234 // Verifies that built-in search providers are processed correctly. 238 // Verifies that built-in search providers are processed correctly.
235 TEST(TemplateURLPrepopulateDataTest, ProvidersFromPrepopulated) { 239 TEST(TemplateURLPrepopulateDataTest, ProvidersFromPrepopulated) {
236 // Use United States. 240 // Use United States.
237 CommandLine::ForCurrentProcess()->AppendSwitchASCII( 241 CommandLine::ForCurrentProcess()->AppendSwitchASCII(
238 switches::kCountry, "US"); 242 switches::kCountry, "US");
243 content::TestBrowserThreadBundle thread_bundle;
239 TestingProfile profile; 244 TestingProfile profile;
240 ScopedVector<TemplateURL> t_urls; 245 ScopedVector<TemplateURL> t_urls;
241 size_t default_index; 246 size_t default_index;
242 TemplateURLPrepopulateData::GetPrepopulatedEngines(&profile, &t_urls.get(), 247 TemplateURLPrepopulateData::GetPrepopulatedEngines(&profile, &t_urls.get(),
243 &default_index); 248 &default_index);
244 249
245 // Ensure all the URLs have the required fields populated. 250 // Ensure all the URLs have the required fields populated.
246 ASSERT_FALSE(t_urls.empty()); 251 ASSERT_FALSE(t_urls.empty());
247 for (size_t i = 0; i < t_urls.size(); ++i) { 252 for (size_t i = 0; i < t_urls.size(); ++i) {
248 ASSERT_FALSE(t_urls[i]->short_name().empty()); 253 ASSERT_FALSE(t_urls[i]->short_name().empty());
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 371
367 TEST(TemplateURLPrepopulateDataTest, GetLogoURLInvalid) { 372 TEST(TemplateURLPrepopulateDataTest, GetLogoURLInvalid) {
368 TemplateURLData data; 373 TemplateURLData data;
369 data.SetURL("http://invalid:search:url/"); 374 data.SetURL("http://invalid:search:url/");
370 TemplateURL turl(NULL, data); 375 TemplateURL turl(NULL, data);
371 GURL logo_url = TemplateURLPrepopulateData::GetLogoURL( 376 GURL logo_url = TemplateURLPrepopulateData::GetLogoURL(
372 turl, TemplateURLPrepopulateData::LOGO_100_PERCENT); 377 turl, TemplateURLPrepopulateData::LOGO_100_PERCENT);
373 378
374 EXPECT_TRUE(logo_url.is_empty()); 379 EXPECT_TRUE(logo_url.is_empty());
375 } 380 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698