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

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

Issue 11293291: Revert 167793 - Moving prepopulated search engines to a JSON file. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: 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 | 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"
6 #include "base/file_util.h" 5 #include "base/file_util.h"
7 #include "base/memory/scoped_vector.h" 6 #include "base/memory/scoped_vector.h"
8 #include "base/scoped_temp_dir.h" 7 #include "base/scoped_temp_dir.h"
9 #include "base/utf_string_conversions.h" 8 #include "base/utf_string_conversions.h"
10 #include "chrome/browser/search_engines/search_terms_data.h" 9 #include "chrome/browser/search_engines/search_terms_data.h"
11 #include "chrome/browser/search_engines/template_url.h" 10 #include "chrome/browser/search_engines/template_url.h"
12 #include "chrome/browser/search_engines/template_url_service.h" 11 #include "chrome/browser/search_engines/template_url_service.h"
13 #include "chrome/browser/search_engines/template_url_prepopulate_data.h" 12 #include "chrome/browser/search_engines/template_url_prepopulate_data.h"
14 #include "chrome/common/chrome_switches.h"
15 #include "chrome/common/pref_names.h" 13 #include "chrome/common/pref_names.h"
16 #include "chrome/test/base/testing_pref_service.h" 14 #include "chrome/test/base/testing_pref_service.h"
17 #include "chrome/test/base/testing_profile.h" 15 #include "chrome/test/base/testing_profile.h"
18 #include "grit/generated_resources.h" 16 #include "grit/generated_resources.h"
19 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
20 #include "ui/base/l10n/l10n_util.h" 18 #include "ui/base/l10n/l10n_util.h"
21 19
22 typedef testing::Test TemplateURLPrepopulateDataTest; 20 typedef testing::Test TemplateURLPrepopulateDataTest;
23 21
24 const int kCountryIds[] = { 22 const int kCountryIds[] = {
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 entry->SetString("encoding", "UTF-8"); 170 entry->SetString("encoding", "UTF-8");
173 overrides->Append(entry->DeepCopy()); 171 overrides->Append(entry->DeepCopy());
174 prefs->SetUserPref(prefs::kSearchProviderOverrides, overrides); 172 prefs->SetUserPref(prefs::kSearchProviderOverrides, overrides);
175 173
176 t_urls.clear(); 174 t_urls.clear();
177 TemplateURLPrepopulateData::GetPrepopulatedEngines(&profile, &t_urls.get(), 175 TemplateURLPrepopulateData::GetPrepopulatedEngines(&profile, &t_urls.get(),
178 &default_index); 176 &default_index);
179 EXPECT_EQ(2u, t_urls.size()); 177 EXPECT_EQ(2u, t_urls.size());
180 } 178 }
181 179
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
217 TEST(TemplateURLPrepopulateDataTest, GetEngineTypeBasic) { 180 TEST(TemplateURLPrepopulateDataTest, GetEngineTypeBasic) {
218 EXPECT_EQ(SEARCH_ENGINE_OTHER, 181 EXPECT_EQ(SEARCH_ENGINE_OTHER,
219 TemplateURLPrepopulateData::GetEngineType("http://example.com/")); 182 TemplateURLPrepopulateData::GetEngineType("http://example.com/"));
220 EXPECT_EQ(SEARCH_ENGINE_ASK, 183 EXPECT_EQ(SEARCH_ENGINE_ASK,
221 TemplateURLPrepopulateData::GetEngineType("http://www.ask.com/")); 184 TemplateURLPrepopulateData::GetEngineType("http://www.ask.com/"));
222 EXPECT_EQ(SEARCH_ENGINE_OTHER, 185 EXPECT_EQ(SEARCH_ENGINE_OTHER,
223 TemplateURLPrepopulateData::GetEngineType("http://search.atlas.cz/")); 186 TemplateURLPrepopulateData::GetEngineType("http://search.atlas.cz/"));
224 EXPECT_EQ(SEARCH_ENGINE_GOOGLE, 187 EXPECT_EQ(SEARCH_ENGINE_GOOGLE,
225 TemplateURLPrepopulateData::GetEngineType("http://www.google.com/")); 188 TemplateURLPrepopulateData::GetEngineType("http://www.google.com/"));
226 } 189 }
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 254
292 TEST(TemplateURLPrepopulateDataTest, GetLogoURLInvalid) { 255 TEST(TemplateURLPrepopulateDataTest, GetLogoURLInvalid) {
293 TemplateURLData data; 256 TemplateURLData data;
294 data.SetURL("http://invalid:search:url/"); 257 data.SetURL("http://invalid:search:url/");
295 TemplateURL turl(NULL, data); 258 TemplateURL turl(NULL, data);
296 GURL logo_url = TemplateURLPrepopulateData::GetLogoURL( 259 GURL logo_url = TemplateURLPrepopulateData::GetLogoURL(
297 turl, TemplateURLPrepopulateData::LOGO_100_PERCENT); 260 turl, TemplateURLPrepopulateData::LOGO_100_PERCENT);
298 261
299 EXPECT_TRUE(logo_url.is_empty()); 262 EXPECT_TRUE(logo_url.is_empty());
300 } 263 }
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