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

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

Issue 11377049: Moving prepopulated search engines to a JSON file. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Rebased to fix conflict. Created 8 years, 1 month 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/file_util.h" 6 #include "base/file_util.h"
6 #include "base/files/scoped_temp_dir.h" 7 #include "base/files/scoped_temp_dir.h"
7 #include "base/memory/scoped_vector.h" 8 #include "base/memory/scoped_vector.h"
8 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.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"
14 #include "chrome/common/chrome_switches.h"
13 #include "chrome/common/pref_names.h" 15 #include "chrome/common/pref_names.h"
14 #include "chrome/test/base/testing_pref_service.h" 16 #include "chrome/test/base/testing_pref_service.h"
15 #include "chrome/test/base/testing_profile.h" 17 #include "chrome/test/base/testing_profile.h"
16 #include "grit/generated_resources.h" 18 #include "grit/generated_resources.h"
17 #include "testing/gtest/include/gtest/gtest.h" 19 #include "testing/gtest/include/gtest/gtest.h"
18 #include "ui/base/l10n/l10n_util.h" 20 #include "ui/base/l10n/l10n_util.h"
19 21
20 typedef testing::Test TemplateURLPrepopulateDataTest; 22 typedef testing::Test TemplateURLPrepopulateDataTest;
21 23
22 const int kCountryIds[] = { 24 const int kCountryIds[] = {
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 entry->SetString("encoding", "UTF-8"); 172 entry->SetString("encoding", "UTF-8");
171 overrides->Append(entry->DeepCopy()); 173 overrides->Append(entry->DeepCopy());
172 prefs->SetUserPref(prefs::kSearchProviderOverrides, overrides); 174 prefs->SetUserPref(prefs::kSearchProviderOverrides, overrides);
173 175
174 t_urls.clear(); 176 t_urls.clear();
175 TemplateURLPrepopulateData::GetPrepopulatedEngines(&profile, &t_urls.get(), 177 TemplateURLPrepopulateData::GetPrepopulatedEngines(&profile, &t_urls.get(),
176 &default_index); 178 &default_index);
177 EXPECT_EQ(2u, t_urls.size()); 179 EXPECT_EQ(2u, t_urls.size());
178 } 180 }
179 181
182 // Verifies that built-in search providers are processed correctly.
183 TEST(TemplateURLPrepopulateDataTest, ProvidersFromPrepopulated) {
184 // Use United States.
185 CommandLine::ForCurrentProcess()->AppendSwitchASCII(
186 switches::kCountry, "US");
187 TestingProfile profile;
188 ScopedVector<TemplateURL> t_urls;
189 size_t default_index;
190 TemplateURLPrepopulateData::GetPrepopulatedEngines(&profile, &t_urls.get(),
191 &default_index);
192
193 // Ensure all the URLs have the required fields populated.
194 ASSERT_FALSE(t_urls.empty());
195 for (size_t i = 0; i < t_urls.size(); ++i) {
196 ASSERT_FALSE(t_urls[i]->short_name().empty());
197 ASSERT_FALSE(t_urls[i]->keyword().empty());
198 ASSERT_FALSE(t_urls[i]->favicon_url().host().empty());
199 ASSERT_FALSE(t_urls[i]->url_ref().GetHost().empty());
200 ASSERT_FALSE(t_urls[i]->input_encodings().empty());
201 EXPECT_GT(t_urls[i]->prepopulate_id(), 0);
202 }
203
204 // Ensures the default URL is Google and has the optional fields filled.
205 EXPECT_EQ(ASCIIToUTF16("Google"), t_urls[default_index]->short_name());
206 EXPECT_FALSE(t_urls[default_index]->suggestions_url().empty());
207 EXPECT_FALSE(t_urls[default_index]->instant_url().empty());
208 // Expect at least 2 alternate_urls.
209 // This caught a bug with static initialization of arrays, so leave this in.
210 EXPECT_GT(t_urls[default_index]->alternate_urls().size(), 1u);
211 for (size_t i = 0; i < t_urls[default_index]->alternate_urls().size(); ++i)
212 EXPECT_FALSE(t_urls[default_index]->alternate_urls()[i].empty());
213 EXPECT_EQ(SEARCH_ENGINE_GOOGLE,
214 TemplateURLPrepopulateData::GetEngineType(t_urls[default_index]->url()));
215 }
216
180 TEST(TemplateURLPrepopulateDataTest, GetEngineTypeBasic) { 217 TEST(TemplateURLPrepopulateDataTest, GetEngineTypeBasic) {
181 EXPECT_EQ(SEARCH_ENGINE_OTHER, 218 EXPECT_EQ(SEARCH_ENGINE_OTHER,
182 TemplateURLPrepopulateData::GetEngineType("http://example.com/")); 219 TemplateURLPrepopulateData::GetEngineType("http://example.com/"));
183 EXPECT_EQ(SEARCH_ENGINE_ASK, 220 EXPECT_EQ(SEARCH_ENGINE_ASK,
184 TemplateURLPrepopulateData::GetEngineType("http://www.ask.com/")); 221 TemplateURLPrepopulateData::GetEngineType("http://www.ask.com/"));
185 EXPECT_EQ(SEARCH_ENGINE_OTHER, 222 EXPECT_EQ(SEARCH_ENGINE_OTHER,
186 TemplateURLPrepopulateData::GetEngineType("http://search.atlas.cz/")); 223 TemplateURLPrepopulateData::GetEngineType("http://search.atlas.cz/"));
187 EXPECT_EQ(SEARCH_ENGINE_GOOGLE, 224 EXPECT_EQ(SEARCH_ENGINE_GOOGLE,
188 TemplateURLPrepopulateData::GetEngineType("http://www.google.com/")); 225 TemplateURLPrepopulateData::GetEngineType("http://www.google.com/"));
189 } 226 }
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 291
255 TEST(TemplateURLPrepopulateDataTest, GetLogoURLInvalid) { 292 TEST(TemplateURLPrepopulateDataTest, GetLogoURLInvalid) {
256 TemplateURLData data; 293 TemplateURLData data;
257 data.SetURL("http://invalid:search:url/"); 294 data.SetURL("http://invalid:search:url/");
258 TemplateURL turl(NULL, data); 295 TemplateURL turl(NULL, data);
259 GURL logo_url = TemplateURLPrepopulateData::GetLogoURL( 296 GURL logo_url = TemplateURLPrepopulateData::GetLogoURL(
260 turl, TemplateURLPrepopulateData::LOGO_100_PERCENT); 297 turl, TemplateURLPrepopulateData::LOGO_100_PERCENT);
261 298
262 EXPECT_TRUE(logo_url.is_empty()); 299 EXPECT_TRUE(logo_url.is_empty());
263 } 300 }
OLDNEW
« no previous file with comments | « chrome/browser/search_engines/template_url_prepopulate_data.cc ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698