OLD | NEW |
---|---|
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/memory/scoped_vector.h" | 7 #include "base/memory/scoped_vector.h" |
7 #include "base/scoped_temp_dir.h" | 8 #include "base/scoped_temp_dir.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_service.h" | 12 #include "chrome/browser/search_engines/template_url_service.h" |
12 #include "chrome/browser/search_engines/template_url_prepopulate_data.h" | 13 #include "chrome/browser/search_engines/template_url_prepopulate_data.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 Loading... | |
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, "NO"); | |
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_GT(t_urls.size(), 0u); | |
Peter Kasting
2012/11/14 18:09:48
Nit: Or ASSERT_FALSE(t_urls.empty()), and similar
| |
195 for (size_t i = 0; i < t_urls.size(); ++i) { | |
196 EXPECT_GT(t_urls[i]->short_name().size(), 0u); | |
197 EXPECT_GT(t_urls[i]->keyword().size(), 0u); | |
198 EXPECT_GT(t_urls[i]->favicon_url().host().size(), 0u); | |
199 EXPECT_GT(t_urls[i]->url_ref().GetHost().size(), 0u); | |
200 EXPECT_GT(t_urls[i]->input_encodings().size(), 0u); | |
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_GT(t_urls[default_index]->suggestions_url().size(), 0u); | |
207 EXPECT_GT(t_urls[default_index]->instant_url().size(), 0u); | |
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_GT(t_urls[default_index]->alternate_urls()[i].size(), 0u); | |
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 Loading... | |
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 } |
OLD | NEW |