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()); |
156 | 157 |
Peter Kasting
2016/11/20 07:57:50
Nit: Why this blank line?
Alexander Yashkin
2016/11/20 20:24:05
Deleted.
| |
158 EXPECT_TRUE(t_urls[0]->show_in_default_list); | |
159 EXPECT_TRUE(t_urls[0]->safe_for_autoreplace); | |
160 EXPECT_TRUE(t_urls[0]->date_created.is_null()); | |
161 EXPECT_TRUE(t_urls[0]->last_modified.is_null()); | |
Peter Kasting
2016/11/20 07:57:50
Is it important to check these? If so, should we
Alexander Yashkin
2016/11/20 20:24:05
I saw that fields safe_for_autoreplace, date_creat
Peter Kasting
2016/11/21 02:17:07
Seems fine, but note that if you follow my suggest
| |
162 | |
157 // Test the optional settings too. | 163 // Test the optional settings too. |
158 entry->SetString("suggest_url", "http://foo.com/suggest?q={searchTerms}"); | 164 entry->SetString("suggest_url", "http://foo.com/suggest?q={searchTerms}"); |
159 entry->SetString("instant_url", "http://foo.com/instant?q={searchTerms}"); | 165 entry->SetString("instant_url", "http://foo.com/instant?q={searchTerms}"); |
160 base::ListValue* alternate_urls = new base::ListValue; | 166 base::ListValue* alternate_urls = new base::ListValue; |
161 alternate_urls->AppendString("http://foo.com/alternate?q={searchTerms}"); | 167 alternate_urls->AppendString("http://foo.com/alternate?q={searchTerms}"); |
162 entry->Set("alternate_urls", alternate_urls); | 168 entry->Set("alternate_urls", alternate_urls); |
163 entry->SetString("search_terms_replacement_key", "espv"); | 169 entry->SetString("search_terms_replacement_key", "espv"); |
164 overrides = new base::ListValue; | 170 overrides = new base::ListValue; |
165 overrides->Append(entry->CreateDeepCopy()); | 171 overrides->Append(entry->CreateDeepCopy()); |
166 prefs_.SetUserPref(prefs::kSearchProviderOverrides, overrides); | 172 prefs_.SetUserPref(prefs::kSearchProviderOverrides, overrides); |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
350 switches::kGoogleBaseURL, "http://www.foo.com/"); | 356 switches::kGoogleBaseURL, "http://www.foo.com/"); |
351 EXPECT_EQ(SEARCH_ENGINE_GOOGLE, GetEngineType(foo_url)); | 357 EXPECT_EQ(SEARCH_ENGINE_GOOGLE, GetEngineType(foo_url)); |
352 } | 358 } |
353 | 359 |
354 TEST_F(TemplateURLPrepopulateDataTest, GetEngineTypeForAllPrepopulatedEngines) { | 360 TEST_F(TemplateURLPrepopulateDataTest, GetEngineTypeForAllPrepopulatedEngines) { |
355 using PrepopulatedEngine = TemplateURLPrepopulateData::PrepopulatedEngine; | 361 using PrepopulatedEngine = TemplateURLPrepopulateData::PrepopulatedEngine; |
356 const std::vector<const PrepopulatedEngine*> all_engines = | 362 const std::vector<const PrepopulatedEngine*> all_engines = |
357 TemplateURLPrepopulateData::GetAllPrepopulatedEngines(); | 363 TemplateURLPrepopulateData::GetAllPrepopulatedEngines(); |
358 for (const PrepopulatedEngine* engine : all_engines) { | 364 for (const PrepopulatedEngine* engine : all_engines) { |
359 std::unique_ptr<TemplateURLData> data = | 365 std::unique_ptr<TemplateURLData> data = |
360 TemplateURLPrepopulateData::MakeTemplateURLDataFromPrepopulatedEngine( | 366 TemplateURLDataFromPrepopulatedEngine(*engine); |
361 *engine); | |
362 EXPECT_EQ(engine->type, | 367 EXPECT_EQ(engine->type, |
363 TemplateURL(*data).GetEngineType(SearchTermsData())); | 368 TemplateURL(*data).GetEngineType(SearchTermsData())); |
364 } | 369 } |
365 } | 370 } |
OLD | NEW |