| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/search_engines/template_url_prepopulate_data.h" | 5 #include "components/search_engines/template_url_prepopulate_data.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <utility> | 10 #include <utility> |
| 11 | 11 |
| 12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 13 #include "base/files/scoped_temp_dir.h" | 13 #include "base/files/scoped_temp_dir.h" |
| 14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
| 16 #include "components/google/core/browser/google_switches.h" | 16 #include "components/google/core/browser/google_switches.h" |
| 17 #include "components/pref_registry/testing_pref_service_syncable.h" | 17 #include "components/pref_registry/testing_pref_service_syncable.h" |
| 18 #include "components/search_engines/prepopulated_engines.h" | 18 #include "components/search_engines/prepopulated_engines.h" |
| 19 #include "components/search_engines/search_engines_pref_names.h" | 19 #include "components/search_engines/search_engines_pref_names.h" |
| 20 #include "components/search_engines/search_terms_data.h" | 20 #include "components/search_engines/search_terms_data.h" |
| 21 #include "components/search_engines/template_url.h" | 21 #include "components/search_engines/template_url.h" |
| 22 #include "components/search_engines/template_url_data_util.h" |
| 22 #include "components/search_engines/template_url_service.h" | 23 #include "components/search_engines/template_url_service.h" |
| 23 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
| 24 | 25 |
| 25 using base::ASCIIToUTF16; | 26 using base::ASCIIToUTF16; |
| 26 | 27 |
| 27 namespace { | 28 namespace { |
| 28 | 29 |
| 29 SearchEngineType GetEngineType(const std::string& url) { | 30 SearchEngineType GetEngineType(const std::string& url) { |
| 30 TemplateURLData data; | 31 TemplateURLData data; |
| 31 data.SetURL(url); | 32 data.SetURL(url); |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 EXPECT_EQ(ASCIIToUTF16("foo"), t_urls[0]->short_name()); | 147 EXPECT_EQ(ASCIIToUTF16("foo"), t_urls[0]->short_name()); |
| 147 EXPECT_EQ(ASCIIToUTF16("fook"), t_urls[0]->keyword()); | 148 EXPECT_EQ(ASCIIToUTF16("fook"), t_urls[0]->keyword()); |
| 148 EXPECT_EQ("foo.com", GetHostFromTemplateURLData(*t_urls[0])); | 149 EXPECT_EQ("foo.com", GetHostFromTemplateURLData(*t_urls[0])); |
| 149 EXPECT_EQ("foi.com", t_urls[0]->favicon_url.host()); | 150 EXPECT_EQ("foi.com", t_urls[0]->favicon_url.host()); |
| 150 EXPECT_EQ(1u, t_urls[0]->input_encodings.size()); | 151 EXPECT_EQ(1u, t_urls[0]->input_encodings.size()); |
| 151 EXPECT_EQ(1001, t_urls[0]->prepopulate_id); | 152 EXPECT_EQ(1001, t_urls[0]->prepopulate_id); |
| 152 EXPECT_TRUE(t_urls[0]->suggestions_url.empty()); | 153 EXPECT_TRUE(t_urls[0]->suggestions_url.empty()); |
| 153 EXPECT_TRUE(t_urls[0]->instant_url.empty()); | 154 EXPECT_TRUE(t_urls[0]->instant_url.empty()); |
| 154 EXPECT_EQ(0u, t_urls[0]->alternate_urls.size()); | 155 EXPECT_EQ(0u, t_urls[0]->alternate_urls.size()); |
| 155 EXPECT_TRUE(t_urls[0]->search_terms_replacement_key.empty()); | 156 EXPECT_TRUE(t_urls[0]->search_terms_replacement_key.empty()); |
| 157 EXPECT_TRUE(t_urls[0]->safe_for_autoreplace); |
| 158 EXPECT_TRUE(t_urls[0]->date_created.is_null()); |
| 159 EXPECT_TRUE(t_urls[0]->last_modified.is_null()); |
| 156 | 160 |
| 157 // Test the optional settings too. | 161 // Test the optional settings too. |
| 158 entry->SetString("suggest_url", "http://foo.com/suggest?q={searchTerms}"); | 162 entry->SetString("suggest_url", "http://foo.com/suggest?q={searchTerms}"); |
| 159 entry->SetString("instant_url", "http://foo.com/instant?q={searchTerms}"); | 163 entry->SetString("instant_url", "http://foo.com/instant?q={searchTerms}"); |
| 160 base::ListValue* alternate_urls = new base::ListValue; | 164 base::ListValue* alternate_urls = new base::ListValue; |
| 161 alternate_urls->AppendString("http://foo.com/alternate?q={searchTerms}"); | 165 alternate_urls->AppendString("http://foo.com/alternate?q={searchTerms}"); |
| 162 entry->Set("alternate_urls", alternate_urls); | 166 entry->Set("alternate_urls", alternate_urls); |
| 163 entry->SetString("search_terms_replacement_key", "espv"); | 167 entry->SetString("search_terms_replacement_key", "espv"); |
| 164 overrides = new base::ListValue; | 168 overrides = new base::ListValue; |
| 165 overrides->Append(entry->CreateDeepCopy()); | 169 overrides->Append(entry->CreateDeepCopy()); |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 | 269 |
| 266 // Ensure all the URLs have the required fields populated. | 270 // Ensure all the URLs have the required fields populated. |
| 267 ASSERT_FALSE(t_urls.empty()); | 271 ASSERT_FALSE(t_urls.empty()); |
| 268 for (size_t i = 0; i < t_urls.size(); ++i) { | 272 for (size_t i = 0; i < t_urls.size(); ++i) { |
| 269 ASSERT_FALSE(t_urls[i]->short_name().empty()); | 273 ASSERT_FALSE(t_urls[i]->short_name().empty()); |
| 270 ASSERT_FALSE(t_urls[i]->keyword().empty()); | 274 ASSERT_FALSE(t_urls[i]->keyword().empty()); |
| 271 ASSERT_FALSE(t_urls[i]->favicon_url.host().empty()); | 275 ASSERT_FALSE(t_urls[i]->favicon_url.host().empty()); |
| 272 ASSERT_FALSE(GetHostFromTemplateURLData(*t_urls[i]).empty()); | 276 ASSERT_FALSE(GetHostFromTemplateURLData(*t_urls[i]).empty()); |
| 273 ASSERT_FALSE(t_urls[i]->input_encodings.empty()); | 277 ASSERT_FALSE(t_urls[i]->input_encodings.empty()); |
| 274 EXPECT_GT(t_urls[i]->prepopulate_id, 0); | 278 EXPECT_GT(t_urls[i]->prepopulate_id, 0); |
| 279 EXPECT_TRUE(t_urls[0]->safe_for_autoreplace); |
| 280 EXPECT_TRUE(t_urls[0]->date_created.is_null()); |
| 281 EXPECT_TRUE(t_urls[0]->last_modified.is_null()); |
| 275 } | 282 } |
| 276 | 283 |
| 277 // Ensures the default URL is Google and has the optional fields filled. | 284 // Ensures the default URL is Google and has the optional fields filled. |
| 278 EXPECT_EQ(ASCIIToUTF16("Google"), t_urls[default_index]->short_name()); | 285 EXPECT_EQ(ASCIIToUTF16("Google"), t_urls[default_index]->short_name()); |
| 279 EXPECT_FALSE(t_urls[default_index]->suggestions_url.empty()); | 286 EXPECT_FALSE(t_urls[default_index]->suggestions_url.empty()); |
| 280 EXPECT_FALSE(t_urls[default_index]->instant_url.empty()); | 287 EXPECT_FALSE(t_urls[default_index]->instant_url.empty()); |
| 281 EXPECT_FALSE(t_urls[default_index]->image_url.empty()); | 288 EXPECT_FALSE(t_urls[default_index]->image_url.empty()); |
| 282 EXPECT_FALSE(t_urls[default_index]->new_tab_url.empty()); | 289 EXPECT_FALSE(t_urls[default_index]->new_tab_url.empty()); |
| 283 EXPECT_FALSE(t_urls[default_index]->contextual_search_url.empty()); | 290 EXPECT_FALSE(t_urls[default_index]->contextual_search_url.empty()); |
| 284 EXPECT_FALSE(t_urls[default_index]->image_url_post_params.empty()); | 291 EXPECT_FALSE(t_urls[default_index]->image_url_post_params.empty()); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 350 switches::kGoogleBaseURL, "http://www.foo.com/"); | 357 switches::kGoogleBaseURL, "http://www.foo.com/"); |
| 351 EXPECT_EQ(SEARCH_ENGINE_GOOGLE, GetEngineType(foo_url)); | 358 EXPECT_EQ(SEARCH_ENGINE_GOOGLE, GetEngineType(foo_url)); |
| 352 } | 359 } |
| 353 | 360 |
| 354 TEST_F(TemplateURLPrepopulateDataTest, GetEngineTypeForAllPrepopulatedEngines) { | 361 TEST_F(TemplateURLPrepopulateDataTest, GetEngineTypeForAllPrepopulatedEngines) { |
| 355 using PrepopulatedEngine = TemplateURLPrepopulateData::PrepopulatedEngine; | 362 using PrepopulatedEngine = TemplateURLPrepopulateData::PrepopulatedEngine; |
| 356 const std::vector<const PrepopulatedEngine*> all_engines = | 363 const std::vector<const PrepopulatedEngine*> all_engines = |
| 357 TemplateURLPrepopulateData::GetAllPrepopulatedEngines(); | 364 TemplateURLPrepopulateData::GetAllPrepopulatedEngines(); |
| 358 for (const PrepopulatedEngine* engine : all_engines) { | 365 for (const PrepopulatedEngine* engine : all_engines) { |
| 359 std::unique_ptr<TemplateURLData> data = | 366 std::unique_ptr<TemplateURLData> data = |
| 360 TemplateURLPrepopulateData::MakeTemplateURLDataFromPrepopulatedEngine( | 367 TemplateURLDataFromPrepopulatedEngine(*engine); |
| 361 *engine); | |
| 362 EXPECT_EQ(engine->type, | 368 EXPECT_EQ(engine->type, |
| 363 TemplateURL(*data).GetEngineType(SearchTermsData())); | 369 TemplateURL(*data).GetEngineType(SearchTermsData())); |
| 364 } | 370 } |
| 365 } | 371 } |
| OLD | NEW |