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> |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 new base::FundamentalValue(1)); | 125 new base::FundamentalValue(1)); |
126 base::ListValue* overrides = new base::ListValue; | 126 base::ListValue* overrides = new base::ListValue; |
127 std::unique_ptr<base::DictionaryValue> entry(new base::DictionaryValue); | 127 std::unique_ptr<base::DictionaryValue> entry(new base::DictionaryValue); |
128 // Set only the minimal required settings for a search provider configuration. | 128 // Set only the minimal required settings for a search provider configuration. |
129 entry->SetString("name", "foo"); | 129 entry->SetString("name", "foo"); |
130 entry->SetString("keyword", "fook"); | 130 entry->SetString("keyword", "fook"); |
131 entry->SetString("search_url", "http://foo.com/s?q={searchTerms}"); | 131 entry->SetString("search_url", "http://foo.com/s?q={searchTerms}"); |
132 entry->SetString("favicon_url", "http://foi.com/favicon.ico"); | 132 entry->SetString("favicon_url", "http://foi.com/favicon.ico"); |
133 entry->SetString("encoding", "UTF-8"); | 133 entry->SetString("encoding", "UTF-8"); |
134 entry->SetInteger("id", 1001); | 134 entry->SetInteger("id", 1001); |
135 overrides->Append(entry->DeepCopy()); | 135 overrides->Append(entry->CreateDeepCopy()); |
136 prefs_.SetUserPref(prefs::kSearchProviderOverrides, overrides); | 136 prefs_.SetUserPref(prefs::kSearchProviderOverrides, overrides); |
137 | 137 |
138 int version = TemplateURLPrepopulateData::GetDataVersion(&prefs_); | 138 int version = TemplateURLPrepopulateData::GetDataVersion(&prefs_); |
139 EXPECT_EQ(1, version); | 139 EXPECT_EQ(1, version); |
140 | 140 |
141 size_t default_index; | 141 size_t default_index; |
142 ScopedVector<TemplateURLData> t_urls = | 142 ScopedVector<TemplateURLData> t_urls = |
143 TemplateURLPrepopulateData::GetPrepopulatedEngines(&prefs_, | 143 TemplateURLPrepopulateData::GetPrepopulatedEngines(&prefs_, |
144 &default_index); | 144 &default_index); |
145 | 145 |
(...skipping 10 matching lines...) Expand all Loading... |
156 EXPECT_TRUE(t_urls[0]->search_terms_replacement_key.empty()); | 156 EXPECT_TRUE(t_urls[0]->search_terms_replacement_key.empty()); |
157 | 157 |
158 // Test the optional settings too. | 158 // Test the optional settings too. |
159 entry->SetString("suggest_url", "http://foo.com/suggest?q={searchTerms}"); | 159 entry->SetString("suggest_url", "http://foo.com/suggest?q={searchTerms}"); |
160 entry->SetString("instant_url", "http://foo.com/instant?q={searchTerms}"); | 160 entry->SetString("instant_url", "http://foo.com/instant?q={searchTerms}"); |
161 base::ListValue* alternate_urls = new base::ListValue; | 161 base::ListValue* alternate_urls = new base::ListValue; |
162 alternate_urls->AppendString("http://foo.com/alternate?q={searchTerms}"); | 162 alternate_urls->AppendString("http://foo.com/alternate?q={searchTerms}"); |
163 entry->Set("alternate_urls", alternate_urls); | 163 entry->Set("alternate_urls", alternate_urls); |
164 entry->SetString("search_terms_replacement_key", "espv"); | 164 entry->SetString("search_terms_replacement_key", "espv"); |
165 overrides = new base::ListValue; | 165 overrides = new base::ListValue; |
166 overrides->Append(entry->DeepCopy()); | 166 overrides->Append(entry->CreateDeepCopy()); |
167 prefs_.SetUserPref(prefs::kSearchProviderOverrides, overrides); | 167 prefs_.SetUserPref(prefs::kSearchProviderOverrides, overrides); |
168 | 168 |
169 t_urls = TemplateURLPrepopulateData::GetPrepopulatedEngines( | 169 t_urls = TemplateURLPrepopulateData::GetPrepopulatedEngines( |
170 &prefs_, &default_index); | 170 &prefs_, &default_index); |
171 ASSERT_EQ(1u, t_urls.size()); | 171 ASSERT_EQ(1u, t_urls.size()); |
172 EXPECT_EQ(ASCIIToUTF16("foo"), t_urls[0]->short_name()); | 172 EXPECT_EQ(ASCIIToUTF16("foo"), t_urls[0]->short_name()); |
173 EXPECT_EQ(ASCIIToUTF16("fook"), t_urls[0]->keyword()); | 173 EXPECT_EQ(ASCIIToUTF16("fook"), t_urls[0]->keyword()); |
174 EXPECT_EQ("foo.com", GetHostFromTemplateURLData(*t_urls[0])); | 174 EXPECT_EQ("foo.com", GetHostFromTemplateURLData(*t_urls[0])); |
175 EXPECT_EQ("foi.com", t_urls[0]->favicon_url.host()); | 175 EXPECT_EQ("foi.com", t_urls[0]->favicon_url.host()); |
176 EXPECT_EQ(1u, t_urls[0]->input_encodings.size()); | 176 EXPECT_EQ(1u, t_urls[0]->input_encodings.size()); |
177 EXPECT_EQ(1001, t_urls[0]->prepopulate_id); | 177 EXPECT_EQ(1001, t_urls[0]->prepopulate_id); |
178 EXPECT_EQ("http://foo.com/suggest?q={searchTerms}", | 178 EXPECT_EQ("http://foo.com/suggest?q={searchTerms}", |
179 t_urls[0]->suggestions_url); | 179 t_urls[0]->suggestions_url); |
180 EXPECT_EQ("http://foo.com/instant?q={searchTerms}", | 180 EXPECT_EQ("http://foo.com/instant?q={searchTerms}", |
181 t_urls[0]->instant_url); | 181 t_urls[0]->instant_url); |
182 ASSERT_EQ(1u, t_urls[0]->alternate_urls.size()); | 182 ASSERT_EQ(1u, t_urls[0]->alternate_urls.size()); |
183 EXPECT_EQ("http://foo.com/alternate?q={searchTerms}", | 183 EXPECT_EQ("http://foo.com/alternate?q={searchTerms}", |
184 t_urls[0]->alternate_urls[0]); | 184 t_urls[0]->alternate_urls[0]); |
185 EXPECT_EQ("espv", t_urls[0]->search_terms_replacement_key); | 185 EXPECT_EQ("espv", t_urls[0]->search_terms_replacement_key); |
186 | 186 |
187 // Test that subsequent providers are loaded even if an intermediate | 187 // Test that subsequent providers are loaded even if an intermediate |
188 // provider has an incomplete configuration. | 188 // provider has an incomplete configuration. |
189 overrides = new base::ListValue; | 189 overrides = new base::ListValue; |
190 overrides->Append(entry->DeepCopy()); | 190 overrides->Append(entry->CreateDeepCopy()); |
191 entry->SetInteger("id", 1002); | 191 entry->SetInteger("id", 1002); |
192 entry->SetString("name", "bar"); | 192 entry->SetString("name", "bar"); |
193 entry->SetString("keyword", "bark"); | 193 entry->SetString("keyword", "bark"); |
194 entry->SetString("encoding", std::string()); | 194 entry->SetString("encoding", std::string()); |
195 overrides->Append(entry->DeepCopy()); | 195 overrides->Append(entry->CreateDeepCopy()); |
196 entry->SetInteger("id", 1003); | 196 entry->SetInteger("id", 1003); |
197 entry->SetString("name", "baz"); | 197 entry->SetString("name", "baz"); |
198 entry->SetString("keyword", "bazk"); | 198 entry->SetString("keyword", "bazk"); |
199 entry->SetString("encoding", "UTF-8"); | 199 entry->SetString("encoding", "UTF-8"); |
200 overrides->Append(entry->DeepCopy()); | 200 overrides->Append(entry->CreateDeepCopy()); |
201 prefs_.SetUserPref(prefs::kSearchProviderOverrides, overrides); | 201 prefs_.SetUserPref(prefs::kSearchProviderOverrides, overrides); |
202 | 202 |
203 t_urls = | 203 t_urls = |
204 TemplateURLPrepopulateData::GetPrepopulatedEngines(&prefs_, | 204 TemplateURLPrepopulateData::GetPrepopulatedEngines(&prefs_, |
205 &default_index); | 205 &default_index); |
206 EXPECT_EQ(2u, t_urls.size()); | 206 EXPECT_EQ(2u, t_urls.size()); |
207 } | 207 } |
208 | 208 |
209 TEST_F(TemplateURLPrepopulateDataTest, ClearProvidersFromPrefs) { | 209 TEST_F(TemplateURLPrepopulateDataTest, ClearProvidersFromPrefs) { |
210 prefs_.SetUserPref(prefs::kSearchProviderOverridesVersion, | 210 prefs_.SetUserPref(prefs::kSearchProviderOverridesVersion, |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
357 const std::vector<const PrepopulatedEngine*> all_engines = | 357 const std::vector<const PrepopulatedEngine*> all_engines = |
358 TemplateURLPrepopulateData::GetAllPrepopulatedEngines(); | 358 TemplateURLPrepopulateData::GetAllPrepopulatedEngines(); |
359 for (const PrepopulatedEngine* engine : all_engines) { | 359 for (const PrepopulatedEngine* engine : all_engines) { |
360 std::unique_ptr<TemplateURLData> data = | 360 std::unique_ptr<TemplateURLData> data = |
361 TemplateURLPrepopulateData::MakeTemplateURLDataFromPrepopulatedEngine( | 361 TemplateURLPrepopulateData::MakeTemplateURLDataFromPrepopulatedEngine( |
362 *engine); | 362 *engine); |
363 EXPECT_EQ(engine->type, | 363 EXPECT_EQ(engine->type, |
364 TemplateURL(*data).GetEngineType(SearchTermsData())); | 364 TemplateURL(*data).GetEngineType(SearchTermsData())); |
365 } | 365 } |
366 } | 366 } |
OLD | NEW |