Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(52)

Side by Side Diff: components/search_engines/template_url_prepopulate_data_unittest.cc

Issue 2307663002: Remove ScopedVector from search_engines. (Closed)
Patch Set: devlin Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/scoped_vector.h"
16 #include "base/strings/utf_string_conversions.h" 15 #include "base/strings/utf_string_conversions.h"
17 #include "components/google/core/browser/google_switches.h" 16 #include "components/google/core/browser/google_switches.h"
18 #include "components/pref_registry/testing_pref_service_syncable.h" 17 #include "components/pref_registry/testing_pref_service_syncable.h"
19 #include "components/search_engines/prepopulated_engines.h" 18 #include "components/search_engines/prepopulated_engines.h"
20 #include "components/search_engines/search_engines_pref_names.h" 19 #include "components/search_engines/search_engines_pref_names.h"
21 #include "components/search_engines/search_terms_data.h" 20 #include "components/search_engines/search_terms_data.h"
22 #include "components/search_engines/template_url.h" 21 #include "components/search_engines/template_url.h"
23 #include "components/search_engines/template_url_service.h" 22 #include "components/search_engines/template_url_service.h"
24 #include "testing/gtest/include/gtest/gtest.h" 23 #include "testing/gtest/include/gtest/gtest.h"
25 24
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 'T'<<8|'L', 'T'<<8|'M', 'T'<<8|'N', 'T'<<8|'O', 'T'<<8|'R', 98 'T'<<8|'L', 'T'<<8|'M', 'T'<<8|'N', 'T'<<8|'O', 'T'<<8|'R',
100 'T'<<8|'T', 'T'<<8|'V', 'T'<<8|'W', 'T'<<8|'Z', 'U'<<8|'A', 99 'T'<<8|'T', 'T'<<8|'V', 'T'<<8|'W', 'T'<<8|'Z', 'U'<<8|'A',
101 'U'<<8|'G', 'U'<<8|'M', 'U'<<8|'S', 'U'<<8|'Y', 'U'<<8|'Z', 100 'U'<<8|'G', 'U'<<8|'M', 'U'<<8|'S', 'U'<<8|'Y', 'U'<<8|'Z',
102 'V'<<8|'A', 'V'<<8|'C', 'V'<<8|'E', 'V'<<8|'G', 'V'<<8|'I', 101 'V'<<8|'A', 'V'<<8|'C', 'V'<<8|'E', 'V'<<8|'G', 'V'<<8|'I',
103 'V'<<8|'N', 'V'<<8|'U', 'W'<<8|'F', 'W'<<8|'S', 'Y'<<8|'E', 102 'V'<<8|'N', 'V'<<8|'U', 'W'<<8|'F', 'W'<<8|'S', 'Y'<<8|'E',
104 'Y'<<8|'T', 'Z'<<8|'A', 'Z'<<8|'M', 'Z'<<8|'W', -1 }; 103 'Y'<<8|'T', 'Z'<<8|'A', 'Z'<<8|'M', 'Z'<<8|'W', -1 };
105 104
106 for (size_t i = 0; i < arraysize(kCountryIds); ++i) { 105 for (size_t i = 0; i < arraysize(kCountryIds); ++i) {
107 prefs_.SetInteger(prefs::kCountryIDAtInstall, kCountryIds[i]); 106 prefs_.SetInteger(prefs::kCountryIDAtInstall, kCountryIds[i]);
108 size_t default_index; 107 size_t default_index;
109 ScopedVector<TemplateURLData> urls = 108 std::vector<std::unique_ptr<TemplateURLData>> urls =
110 TemplateURLPrepopulateData::GetPrepopulatedEngines(&prefs_, 109 TemplateURLPrepopulateData::GetPrepopulatedEngines(&prefs_,
111 &default_index); 110 &default_index);
112 std::set<int> unique_ids; 111 std::set<int> unique_ids;
113 for (size_t turl_i = 0; turl_i < urls.size(); ++turl_i) { 112 for (size_t turl_i = 0; turl_i < urls.size(); ++turl_i) {
114 ASSERT_TRUE(unique_ids.find(urls[turl_i]->prepopulate_id) == 113 ASSERT_TRUE(unique_ids.find(urls[turl_i]->prepopulate_id) ==
115 unique_ids.end()); 114 unique_ids.end());
116 unique_ids.insert(urls[turl_i]->prepopulate_id); 115 unique_ids.insert(urls[turl_i]->prepopulate_id);
117 } 116 }
118 } 117 }
119 } 118 }
(...skipping 12 matching lines...) Expand all
132 entry->SetString("favicon_url", "http://foi.com/favicon.ico"); 131 entry->SetString("favicon_url", "http://foi.com/favicon.ico");
133 entry->SetString("encoding", "UTF-8"); 132 entry->SetString("encoding", "UTF-8");
134 entry->SetInteger("id", 1001); 133 entry->SetInteger("id", 1001);
135 overrides->Append(entry->CreateDeepCopy()); 134 overrides->Append(entry->CreateDeepCopy());
136 prefs_.SetUserPref(prefs::kSearchProviderOverrides, overrides); 135 prefs_.SetUserPref(prefs::kSearchProviderOverrides, overrides);
137 136
138 int version = TemplateURLPrepopulateData::GetDataVersion(&prefs_); 137 int version = TemplateURLPrepopulateData::GetDataVersion(&prefs_);
139 EXPECT_EQ(1, version); 138 EXPECT_EQ(1, version);
140 139
141 size_t default_index; 140 size_t default_index;
142 ScopedVector<TemplateURLData> t_urls = 141 std::vector<std::unique_ptr<TemplateURLData>> t_urls =
143 TemplateURLPrepopulateData::GetPrepopulatedEngines(&prefs_, 142 TemplateURLPrepopulateData::GetPrepopulatedEngines(&prefs_,
144 &default_index); 143 &default_index);
145 144
146 ASSERT_EQ(1u, t_urls.size()); 145 ASSERT_EQ(1u, t_urls.size());
147 EXPECT_EQ(ASCIIToUTF16("foo"), t_urls[0]->short_name()); 146 EXPECT_EQ(ASCIIToUTF16("foo"), t_urls[0]->short_name());
148 EXPECT_EQ(ASCIIToUTF16("fook"), t_urls[0]->keyword()); 147 EXPECT_EQ(ASCIIToUTF16("fook"), t_urls[0]->keyword());
149 EXPECT_EQ("foo.com", GetHostFromTemplateURLData(*t_urls[0])); 148 EXPECT_EQ("foo.com", GetHostFromTemplateURLData(*t_urls[0]));
150 EXPECT_EQ("foi.com", t_urls[0]->favicon_url.host()); 149 EXPECT_EQ("foi.com", t_urls[0]->favicon_url.host());
151 EXPECT_EQ(1u, t_urls[0]->input_encodings.size()); 150 EXPECT_EQ(1u, t_urls[0]->input_encodings.size());
152 EXPECT_EQ(1001, t_urls[0]->prepopulate_id); 151 EXPECT_EQ(1001, t_urls[0]->prepopulate_id);
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 int version = TemplateURLPrepopulateData::GetDataVersion(&prefs_); 223 int version = TemplateURLPrepopulateData::GetDataVersion(&prefs_);
225 EXPECT_EQ(1, version); 224 EXPECT_EQ(1, version);
226 225
227 // This call removes the above search engine. 226 // This call removes the above search engine.
228 TemplateURLPrepopulateData::ClearPrepopulatedEnginesInPrefs(&prefs_); 227 TemplateURLPrepopulateData::ClearPrepopulatedEnginesInPrefs(&prefs_);
229 228
230 version = TemplateURLPrepopulateData::GetDataVersion(&prefs_); 229 version = TemplateURLPrepopulateData::GetDataVersion(&prefs_);
231 EXPECT_EQ(TemplateURLPrepopulateData::kCurrentDataVersion, version); 230 EXPECT_EQ(TemplateURLPrepopulateData::kCurrentDataVersion, version);
232 231
233 size_t default_index; 232 size_t default_index;
234 ScopedVector<TemplateURLData> t_urls = 233 std::vector<std::unique_ptr<TemplateURLData>> t_urls =
235 TemplateURLPrepopulateData::GetPrepopulatedEngines(&prefs_, 234 TemplateURLPrepopulateData::GetPrepopulatedEngines(&prefs_,
236 &default_index); 235 &default_index);
237 ASSERT_FALSE(t_urls.empty()); 236 ASSERT_FALSE(t_urls.empty());
238 for (size_t i = 0; i < t_urls.size(); ++i) { 237 for (size_t i = 0; i < t_urls.size(); ++i) {
239 EXPECT_NE(ASCIIToUTF16("foo"), t_urls[i]->short_name()); 238 EXPECT_NE(ASCIIToUTF16("foo"), t_urls[i]->short_name());
240 EXPECT_NE(ASCIIToUTF16("fook"), t_urls[i]->keyword()); 239 EXPECT_NE(ASCIIToUTF16("fook"), t_urls[i]->keyword());
241 EXPECT_NE("foi.com", t_urls[i]->favicon_url.host()); 240 EXPECT_NE("foi.com", t_urls[i]->favicon_url.host());
242 EXPECT_NE("foo.com", GetHostFromTemplateURLData(*t_urls[i])); 241 EXPECT_NE("foo.com", GetHostFromTemplateURLData(*t_urls[i]));
243 EXPECT_NE(1001, t_urls[i]->prepopulate_id); 242 EXPECT_NE(1001, t_urls[i]->prepopulate_id);
244 } 243 }
245 // Ensures the default URL is Google and has the optional fields filled. 244 // Ensures the default URL is Google and has the optional fields filled.
246 EXPECT_EQ(ASCIIToUTF16("Google"), t_urls[default_index]->short_name()); 245 EXPECT_EQ(ASCIIToUTF16("Google"), t_urls[default_index]->short_name());
247 EXPECT_FALSE(t_urls[default_index]->suggestions_url.empty()); 246 EXPECT_FALSE(t_urls[default_index]->suggestions_url.empty());
248 EXPECT_FALSE(t_urls[default_index]->instant_url.empty()); 247 EXPECT_FALSE(t_urls[default_index]->instant_url.empty());
249 EXPECT_FALSE(t_urls[default_index]->image_url.empty()); 248 EXPECT_FALSE(t_urls[default_index]->image_url.empty());
250 EXPECT_FALSE(t_urls[default_index]->new_tab_url.empty()); 249 EXPECT_FALSE(t_urls[default_index]->new_tab_url.empty());
251 EXPECT_FALSE(t_urls[default_index]->contextual_search_url.empty()); 250 EXPECT_FALSE(t_urls[default_index]->contextual_search_url.empty());
252 EXPECT_FALSE(t_urls[default_index]->image_url_post_params.empty()); 251 EXPECT_FALSE(t_urls[default_index]->image_url_post_params.empty());
253 EXPECT_EQ(SEARCH_ENGINE_GOOGLE, 252 EXPECT_EQ(SEARCH_ENGINE_GOOGLE,
254 TemplateURL(*t_urls[default_index]).GetEngineType( 253 TemplateURL(*t_urls[default_index]).GetEngineType(
255 SearchTermsData())); 254 SearchTermsData()));
256 } 255 }
257 256
258 // Verifies that built-in search providers are processed correctly. 257 // Verifies that built-in search providers are processed correctly.
259 TEST_F(TemplateURLPrepopulateDataTest, ProvidersFromPrepopulated) { 258 TEST_F(TemplateURLPrepopulateDataTest, ProvidersFromPrepopulated) {
260 // Use United States. 259 // Use United States.
261 prefs_.SetInteger(prefs::kCountryIDAtInstall, 'U'<<8|'S'); 260 prefs_.SetInteger(prefs::kCountryIDAtInstall, 'U'<<8|'S');
262 size_t default_index; 261 size_t default_index;
263 ScopedVector<TemplateURLData> t_urls = 262 std::vector<std::unique_ptr<TemplateURLData>> t_urls =
264 TemplateURLPrepopulateData::GetPrepopulatedEngines(&prefs_, 263 TemplateURLPrepopulateData::GetPrepopulatedEngines(&prefs_,
265 &default_index); 264 &default_index);
266 265
267 // Ensure all the URLs have the required fields populated. 266 // Ensure all the URLs have the required fields populated.
268 ASSERT_FALSE(t_urls.empty()); 267 ASSERT_FALSE(t_urls.empty());
269 for (size_t i = 0; i < t_urls.size(); ++i) { 268 for (size_t i = 0; i < t_urls.size(); ++i) {
270 ASSERT_FALSE(t_urls[i]->short_name().empty()); 269 ASSERT_FALSE(t_urls[i]->short_name().empty());
271 ASSERT_FALSE(t_urls[i]->keyword().empty()); 270 ASSERT_FALSE(t_urls[i]->keyword().empty());
272 ASSERT_FALSE(t_urls[i]->favicon_url.host().empty()); 271 ASSERT_FALSE(t_urls[i]->favicon_url.host().empty());
273 ASSERT_FALSE(GetHostFromTemplateURLData(*t_urls[i]).empty()); 272 ASSERT_FALSE(GetHostFromTemplateURLData(*t_urls[i]).empty());
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 const std::vector<const PrepopulatedEngine*> all_engines = 356 const std::vector<const PrepopulatedEngine*> all_engines =
358 TemplateURLPrepopulateData::GetAllPrepopulatedEngines(); 357 TemplateURLPrepopulateData::GetAllPrepopulatedEngines();
359 for (const PrepopulatedEngine* engine : all_engines) { 358 for (const PrepopulatedEngine* engine : all_engines) {
360 std::unique_ptr<TemplateURLData> data = 359 std::unique_ptr<TemplateURLData> data =
361 TemplateURLPrepopulateData::MakeTemplateURLDataFromPrepopulatedEngine( 360 TemplateURLPrepopulateData::MakeTemplateURLDataFromPrepopulatedEngine(
362 *engine); 361 *engine);
363 EXPECT_EQ(engine->type, 362 EXPECT_EQ(engine->type,
364 TemplateURL(*data).GetEngineType(SearchTermsData())); 363 TemplateURL(*data).GetEngineType(SearchTermsData()));
365 } 364 }
366 } 365 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698