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/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/template_url.h" | 9 #include "chrome/browser/search_engines/template_url.h" |
10 #include "chrome/browser/search_engines/template_url_prepopulate_data.h" | 10 #include "chrome/browser/search_engines/template_url_prepopulate_data.h" |
11 #include "chrome/browser/search_engines/template_url_service.h" | 11 #include "chrome/browser/search_engines/template_url_service.h" |
12 #include "chrome/common/chrome_switches.h" | 12 #include "chrome/common/chrome_switches.h" |
13 #include "chrome/common/pref_names.h" | 13 #include "chrome/common/pref_names.h" |
14 #include "chrome/test/base/testing_pref_service_syncable.h" | 14 #include "chrome/test/base/testing_pref_service_syncable.h" |
15 #include "chrome/test/base/testing_profile.h" | 15 #include "chrome/test/base/testing_profile.h" |
16 #include "components/google/core/browser/google_switches.h" | 16 #include "components/google/core/browser/google_switches.h" |
17 #include "components/search_engines/prepopulated_engines.h" | 17 #include "components/search_engines/prepopulated_engines.h" |
18 #include "components/search_engines/search_terms_data.h" | 18 #include "components/search_engines/search_terms_data.h" |
19 #include "grit/generated_resources.h" | 19 #include "grit/generated_resources.h" |
20 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
21 #include "ui/base/l10n/l10n_util.h" | 21 #include "ui/base/l10n/l10n_util.h" |
22 | 22 |
23 using base::ASCIIToUTF16; | 23 using base::ASCIIToUTF16; |
24 | 24 |
25 namespace { | 25 namespace { |
26 | 26 |
27 SearchEngineType GetEngineType(const std::string& url) { | 27 SearchEngineType GetEngineType(const std::string& url) { |
28 TemplateURLData data; | 28 TemplateURLData data; |
29 data.SetURL(url); | 29 data.SetURL(url); |
30 return TemplateURLPrepopulateData::GetEngineType(TemplateURL(NULL, data), | 30 return TemplateURLPrepopulateData::GetEngineType(TemplateURL(data), |
31 SearchTermsData()); | 31 SearchTermsData()); |
32 } | 32 } |
33 | 33 |
34 std::string GetHostFromTemplateURLData(const TemplateURLData& data) { | 34 std::string GetHostFromTemplateURLData(const TemplateURLData& data) { |
35 return TemplateURL(NULL, data).url_ref().GetHost(SearchTermsData()); | 35 return TemplateURL(data).url_ref().GetHost(SearchTermsData()); |
36 } | 36 } |
37 | 37 |
38 } // namespace | 38 } // namespace |
39 | 39 |
40 typedef testing::Test TemplateURLPrepopulateDataTest; | 40 typedef testing::Test TemplateURLPrepopulateDataTest; |
41 | 41 |
42 // Verifies the set of prepopulate data doesn't contain entries with duplicate | 42 // Verifies the set of prepopulate data doesn't contain entries with duplicate |
43 // ids. | 43 // ids. |
44 TEST(TemplateURLPrepopulateDataTest, UniqueIDs) { | 44 TEST(TemplateURLPrepopulateDataTest, UniqueIDs) { |
45 const int kCountryIds[] = { | 45 const int kCountryIds[] = { |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 // Ensures the default URL is Google and has the optional fields filled. | 237 // Ensures the default URL is Google and has the optional fields filled. |
238 EXPECT_EQ(ASCIIToUTF16("Google"), t_urls[default_index]->short_name); | 238 EXPECT_EQ(ASCIIToUTF16("Google"), t_urls[default_index]->short_name); |
239 EXPECT_FALSE(t_urls[default_index]->suggestions_url.empty()); | 239 EXPECT_FALSE(t_urls[default_index]->suggestions_url.empty()); |
240 EXPECT_FALSE(t_urls[default_index]->instant_url.empty()); | 240 EXPECT_FALSE(t_urls[default_index]->instant_url.empty()); |
241 EXPECT_FALSE(t_urls[default_index]->image_url.empty()); | 241 EXPECT_FALSE(t_urls[default_index]->image_url.empty()); |
242 EXPECT_FALSE(t_urls[default_index]->new_tab_url.empty()); | 242 EXPECT_FALSE(t_urls[default_index]->new_tab_url.empty()); |
243 EXPECT_FALSE(t_urls[default_index]->contextual_search_url.empty()); | 243 EXPECT_FALSE(t_urls[default_index]->contextual_search_url.empty()); |
244 EXPECT_FALSE(t_urls[default_index]->image_url_post_params.empty()); | 244 EXPECT_FALSE(t_urls[default_index]->image_url_post_params.empty()); |
245 EXPECT_EQ(SEARCH_ENGINE_GOOGLE, | 245 EXPECT_EQ(SEARCH_ENGINE_GOOGLE, |
246 TemplateURLPrepopulateData::GetEngineType( | 246 TemplateURLPrepopulateData::GetEngineType( |
247 TemplateURL(NULL, *t_urls[default_index]), | 247 TemplateURL(*t_urls[default_index]), |
248 SearchTermsData())); | 248 SearchTermsData())); |
249 } | 249 } |
250 | 250 |
251 // Verifies that built-in search providers are processed correctly. | 251 // Verifies that built-in search providers are processed correctly. |
252 TEST(TemplateURLPrepopulateDataTest, ProvidersFromPrepopulated) { | 252 TEST(TemplateURLPrepopulateDataTest, ProvidersFromPrepopulated) { |
253 TestingProfile profile; | 253 TestingProfile profile; |
254 // Use United States. | 254 // Use United States. |
255 profile.GetPrefs()->SetInteger(prefs::kCountryIDAtInstall, 'U'<<8|'S'); | 255 profile.GetPrefs()->SetInteger(prefs::kCountryIDAtInstall, 'U'<<8|'S'); |
256 size_t default_index; | 256 size_t default_index; |
257 ScopedVector<TemplateURLData> t_urls = | 257 ScopedVector<TemplateURLData> t_urls = |
(...skipping 19 matching lines...) Expand all Loading... |
277 EXPECT_FALSE(t_urls[default_index]->new_tab_url.empty()); | 277 EXPECT_FALSE(t_urls[default_index]->new_tab_url.empty()); |
278 EXPECT_FALSE(t_urls[default_index]->contextual_search_url.empty()); | 278 EXPECT_FALSE(t_urls[default_index]->contextual_search_url.empty()); |
279 EXPECT_FALSE(t_urls[default_index]->image_url_post_params.empty()); | 279 EXPECT_FALSE(t_urls[default_index]->image_url_post_params.empty()); |
280 // Expect at least 2 alternate_urls. | 280 // Expect at least 2 alternate_urls. |
281 // This caught a bug with static initialization of arrays, so leave this in. | 281 // This caught a bug with static initialization of arrays, so leave this in. |
282 EXPECT_GT(t_urls[default_index]->alternate_urls.size(), 1u); | 282 EXPECT_GT(t_urls[default_index]->alternate_urls.size(), 1u); |
283 for (size_t i = 0; i < t_urls[default_index]->alternate_urls.size(); ++i) | 283 for (size_t i = 0; i < t_urls[default_index]->alternate_urls.size(); ++i) |
284 EXPECT_FALSE(t_urls[default_index]->alternate_urls[i].empty()); | 284 EXPECT_FALSE(t_urls[default_index]->alternate_urls[i].empty()); |
285 EXPECT_EQ(SEARCH_ENGINE_GOOGLE, | 285 EXPECT_EQ(SEARCH_ENGINE_GOOGLE, |
286 TemplateURLPrepopulateData::GetEngineType( | 286 TemplateURLPrepopulateData::GetEngineType( |
287 TemplateURL(NULL, *t_urls[default_index]), | 287 TemplateURL(*t_urls[default_index]), |
288 SearchTermsData())); | 288 SearchTermsData())); |
289 EXPECT_FALSE(t_urls[default_index]->search_terms_replacement_key.empty()); | 289 EXPECT_FALSE(t_urls[default_index]->search_terms_replacement_key.empty()); |
290 } | 290 } |
291 | 291 |
292 TEST(TemplateURLPrepopulateDataTest, GetEngineTypeBasic) { | 292 TEST(TemplateURLPrepopulateDataTest, GetEngineTypeBasic) { |
293 EXPECT_EQ(SEARCH_ENGINE_OTHER, GetEngineType("http://example.com/")); | 293 EXPECT_EQ(SEARCH_ENGINE_OTHER, GetEngineType("http://example.com/")); |
294 EXPECT_EQ(SEARCH_ENGINE_ASK, GetEngineType("http://www.ask.com/")); | 294 EXPECT_EQ(SEARCH_ENGINE_ASK, GetEngineType("http://www.ask.com/")); |
295 EXPECT_EQ(SEARCH_ENGINE_OTHER, GetEngineType("http://search.atlas.cz/")); | 295 EXPECT_EQ(SEARCH_ENGINE_OTHER, GetEngineType("http://search.atlas.cz/")); |
296 EXPECT_EQ(SEARCH_ENGINE_GOOGLE, GetEngineType("http://www.google.com/")); | 296 EXPECT_EQ(SEARCH_ENGINE_GOOGLE, GetEngineType("http://www.google.com/")); |
297 } | 297 } |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
339 EXPECT_EQ(SEARCH_ENGINE_OTHER, GetEngineType("invalid:search:url")); | 339 EXPECT_EQ(SEARCH_ENGINE_OTHER, GetEngineType("invalid:search:url")); |
340 | 340 |
341 // URL that doesn't look Google-related, but matches a Google base URL | 341 // URL that doesn't look Google-related, but matches a Google base URL |
342 // specified on the command line. | 342 // specified on the command line. |
343 const std::string foo_url("http://www.foo.com/search?q={searchTerms}"); | 343 const std::string foo_url("http://www.foo.com/search?q={searchTerms}"); |
344 EXPECT_EQ(SEARCH_ENGINE_OTHER, GetEngineType(foo_url)); | 344 EXPECT_EQ(SEARCH_ENGINE_OTHER, GetEngineType(foo_url)); |
345 CommandLine::ForCurrentProcess()->AppendSwitchASCII(switches::kGoogleBaseURL, | 345 CommandLine::ForCurrentProcess()->AppendSwitchASCII(switches::kGoogleBaseURL, |
346 "http://www.foo.com/"); | 346 "http://www.foo.com/"); |
347 EXPECT_EQ(SEARCH_ENGINE_GOOGLE, GetEngineType(foo_url)); | 347 EXPECT_EQ(SEARCH_ENGINE_GOOGLE, GetEngineType(foo_url)); |
348 } | 348 } |
OLD | NEW |