| 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/memory/ptr_util.h" |
| 15 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
| 17 #include "base/values.h" |
| 16 #include "components/google/core/browser/google_switches.h" | 18 #include "components/google/core/browser/google_switches.h" |
| 17 #include "components/search_engines/prepopulated_engines.h" | 19 #include "components/search_engines/prepopulated_engines.h" |
| 18 #include "components/search_engines/search_engines_pref_names.h" | 20 #include "components/search_engines/search_engines_pref_names.h" |
| 19 #include "components/search_engines/search_terms_data.h" | 21 #include "components/search_engines/search_terms_data.h" |
| 20 #include "components/search_engines/template_url.h" | 22 #include "components/search_engines/template_url.h" |
| 21 #include "components/search_engines/template_url_data_util.h" | 23 #include "components/search_engines/template_url_data_util.h" |
| 22 #include "components/search_engines/template_url_service.h" | 24 #include "components/search_engines/template_url_service.h" |
| 23 #include "components/sync_preferences/testing_pref_service_syncable.h" | 25 #include "components/sync_preferences/testing_pref_service_syncable.h" |
| 24 #include "testing/gtest/include/gtest/gtest.h" | 26 #include "testing/gtest/include/gtest/gtest.h" |
| 25 | 27 |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 EXPECT_TRUE(t_urls[0]->instant_url.empty()); | 154 EXPECT_TRUE(t_urls[0]->instant_url.empty()); |
| 153 EXPECT_EQ(0u, t_urls[0]->alternate_urls.size()); | 155 EXPECT_EQ(0u, t_urls[0]->alternate_urls.size()); |
| 154 EXPECT_TRUE(t_urls[0]->search_terms_replacement_key.empty()); | 156 EXPECT_TRUE(t_urls[0]->search_terms_replacement_key.empty()); |
| 155 EXPECT_TRUE(t_urls[0]->safe_for_autoreplace); | 157 EXPECT_TRUE(t_urls[0]->safe_for_autoreplace); |
| 156 EXPECT_TRUE(t_urls[0]->date_created.is_null()); | 158 EXPECT_TRUE(t_urls[0]->date_created.is_null()); |
| 157 EXPECT_TRUE(t_urls[0]->last_modified.is_null()); | 159 EXPECT_TRUE(t_urls[0]->last_modified.is_null()); |
| 158 | 160 |
| 159 // Test the optional settings too. | 161 // Test the optional settings too. |
| 160 entry->SetString("suggest_url", "http://foo.com/suggest?q={searchTerms}"); | 162 entry->SetString("suggest_url", "http://foo.com/suggest?q={searchTerms}"); |
| 161 entry->SetString("instant_url", "http://foo.com/instant?q={searchTerms}"); | 163 entry->SetString("instant_url", "http://foo.com/instant?q={searchTerms}"); |
| 162 base::ListValue* alternate_urls = new base::ListValue; | 164 auto alternate_urls = base::MakeUnique<base::ListValue>(); |
| 163 alternate_urls->AppendString("http://foo.com/alternate?q={searchTerms}"); | 165 alternate_urls->AppendString("http://foo.com/alternate?q={searchTerms}"); |
| 164 entry->Set("alternate_urls", alternate_urls); | 166 entry->Set("alternate_urls", std::move(alternate_urls)); |
| 165 entry->SetString("search_terms_replacement_key", "espv"); | 167 entry->SetString("search_terms_replacement_key", "espv"); |
| 166 overrides = base::MakeUnique<base::ListValue>(); | 168 overrides = base::MakeUnique<base::ListValue>(); |
| 167 overrides->Append(entry->CreateDeepCopy()); | 169 overrides->Append(entry->CreateDeepCopy()); |
| 168 prefs_.SetUserPref(prefs::kSearchProviderOverrides, std::move(overrides)); | 170 prefs_.SetUserPref(prefs::kSearchProviderOverrides, std::move(overrides)); |
| 169 | 171 |
| 170 t_urls = TemplateURLPrepopulateData::GetPrepopulatedEngines( | 172 t_urls = TemplateURLPrepopulateData::GetPrepopulatedEngines( |
| 171 &prefs_, &default_index); | 173 &prefs_, &default_index); |
| 172 ASSERT_EQ(1u, t_urls.size()); | 174 ASSERT_EQ(1u, t_urls.size()); |
| 173 EXPECT_EQ(ASCIIToUTF16("foo"), t_urls[0]->short_name()); | 175 EXPECT_EQ(ASCIIToUTF16("foo"), t_urls[0]->short_name()); |
| 174 EXPECT_EQ(ASCIIToUTF16("fook"), t_urls[0]->keyword()); | 176 EXPECT_EQ(ASCIIToUTF16("fook"), t_urls[0]->keyword()); |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 360 using PrepopulatedEngine = TemplateURLPrepopulateData::PrepopulatedEngine; | 362 using PrepopulatedEngine = TemplateURLPrepopulateData::PrepopulatedEngine; |
| 361 const std::vector<const PrepopulatedEngine*> all_engines = | 363 const std::vector<const PrepopulatedEngine*> all_engines = |
| 362 TemplateURLPrepopulateData::GetAllPrepopulatedEngines(); | 364 TemplateURLPrepopulateData::GetAllPrepopulatedEngines(); |
| 363 for (const PrepopulatedEngine* engine : all_engines) { | 365 for (const PrepopulatedEngine* engine : all_engines) { |
| 364 std::unique_ptr<TemplateURLData> data = | 366 std::unique_ptr<TemplateURLData> data = |
| 365 TemplateURLDataFromPrepopulatedEngine(*engine); | 367 TemplateURLDataFromPrepopulatedEngine(*engine); |
| 366 EXPECT_EQ(engine->type, | 368 EXPECT_EQ(engine->type, |
| 367 TemplateURL(*data).GetEngineType(SearchTermsData())); | 369 TemplateURL(*data).GetEngineType(SearchTermsData())); |
| 368 } | 370 } |
| 369 } | 371 } |
| OLD | NEW |