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

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

Issue 2058233002: Rewrite simple uses of base::ListValue::Append() taking a raw pointer var. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: less comments more ownership Created 4 years, 6 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"
6
5 #include <stddef.h> 7 #include <stddef.h>
6 8
9 #include <memory>
10 #include <utility>
11
7 #include "base/command_line.h" 12 #include "base/command_line.h"
8 #include "base/files/scoped_temp_dir.h" 13 #include "base/files/scoped_temp_dir.h"
9 #include "base/macros.h" 14 #include "base/macros.h"
10 #include "base/memory/scoped_vector.h" 15 #include "base/memory/scoped_vector.h"
11 #include "base/strings/utf_string_conversions.h" 16 #include "base/strings/utf_string_conversions.h"
12 #include "components/google/core/browser/google_switches.h" 17 #include "components/google/core/browser/google_switches.h"
13 #include "components/pref_registry/testing_pref_service_syncable.h" 18 #include "components/pref_registry/testing_pref_service_syncable.h"
14 #include "components/search_engines/prepopulated_engines.h" 19 #include "components/search_engines/prepopulated_engines.h"
15 #include "components/search_engines/search_engines_pref_names.h" 20 #include "components/search_engines/search_engines_pref_names.h"
16 #include "components/search_engines/search_terms_data.h" 21 #include "components/search_engines/search_terms_data.h"
17 #include "components/search_engines/template_url.h" 22 #include "components/search_engines/template_url.h"
18 #include "components/search_engines/template_url_prepopulate_data.h"
19 #include "components/search_engines/template_url_service.h" 23 #include "components/search_engines/template_url_service.h"
20 #include "testing/gtest/include/gtest/gtest.h" 24 #include "testing/gtest/include/gtest/gtest.h"
21 25
22 using base::ASCIIToUTF16; 26 using base::ASCIIToUTF16;
23 27
24 namespace { 28 namespace {
25 29
26 SearchEngineType GetEngineType(const std::string& url) { 30 SearchEngineType GetEngineType(const std::string& url) {
27 TemplateURLData data; 31 TemplateURLData data;
28 data.SetURL(url); 32 data.SetURL(url);
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 t_urls = 204 t_urls =
201 TemplateURLPrepopulateData::GetPrepopulatedEngines(&prefs_, 205 TemplateURLPrepopulateData::GetPrepopulatedEngines(&prefs_,
202 &default_index); 206 &default_index);
203 EXPECT_EQ(2u, t_urls.size()); 207 EXPECT_EQ(2u, t_urls.size());
204 } 208 }
205 209
206 TEST_F(TemplateURLPrepopulateDataTest, ClearProvidersFromPrefs) { 210 TEST_F(TemplateURLPrepopulateDataTest, ClearProvidersFromPrefs) {
207 prefs_.SetUserPref(prefs::kSearchProviderOverridesVersion, 211 prefs_.SetUserPref(prefs::kSearchProviderOverridesVersion,
208 new base::FundamentalValue(1)); 212 new base::FundamentalValue(1));
209 base::ListValue* overrides = new base::ListValue; 213 base::ListValue* overrides = new base::ListValue;
210 base::DictionaryValue* entry(new base::DictionaryValue); 214 std::unique_ptr<base::DictionaryValue> entry(new base::DictionaryValue);
211 // Set only the minimal required settings for a search provider configuration. 215 // Set only the minimal required settings for a search provider configuration.
212 entry->SetString("name", "foo"); 216 entry->SetString("name", "foo");
213 entry->SetString("keyword", "fook"); 217 entry->SetString("keyword", "fook");
214 entry->SetString("search_url", "http://foo.com/s?q={searchTerms}"); 218 entry->SetString("search_url", "http://foo.com/s?q={searchTerms}");
215 entry->SetString("favicon_url", "http://foi.com/favicon.ico"); 219 entry->SetString("favicon_url", "http://foi.com/favicon.ico");
216 entry->SetString("encoding", "UTF-8"); 220 entry->SetString("encoding", "UTF-8");
217 entry->SetInteger("id", 1001); 221 entry->SetInteger("id", 1001);
218 overrides->Append(entry); 222 overrides->Append(std::move(entry));
219 prefs_.SetUserPref(prefs::kSearchProviderOverrides, overrides); 223 prefs_.SetUserPref(prefs::kSearchProviderOverrides, overrides);
220 224
221 int version = TemplateURLPrepopulateData::GetDataVersion(&prefs_); 225 int version = TemplateURLPrepopulateData::GetDataVersion(&prefs_);
222 EXPECT_EQ(1, version); 226 EXPECT_EQ(1, version);
223 227
224 // This call removes the above search engine. 228 // This call removes the above search engine.
225 TemplateURLPrepopulateData::ClearPrepopulatedEnginesInPrefs(&prefs_); 229 TemplateURLPrepopulateData::ClearPrepopulatedEnginesInPrefs(&prefs_);
226 230
227 version = TemplateURLPrepopulateData::GetDataVersion(&prefs_); 231 version = TemplateURLPrepopulateData::GetDataVersion(&prefs_);
228 EXPECT_EQ(TemplateURLPrepopulateData::kCurrentDataVersion, version); 232 EXPECT_EQ(TemplateURLPrepopulateData::kCurrentDataVersion, version);
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 EXPECT_EQ(SEARCH_ENGINE_OTHER, GetEngineType("invalid:search:url")); 347 EXPECT_EQ(SEARCH_ENGINE_OTHER, GetEngineType("invalid:search:url"));
344 348
345 // URL that doesn't look Google-related, but matches a Google base URL 349 // URL that doesn't look Google-related, but matches a Google base URL
346 // specified on the command line. 350 // specified on the command line.
347 const std::string foo_url("http://www.foo.com/search?q={searchTerms}"); 351 const std::string foo_url("http://www.foo.com/search?q={searchTerms}");
348 EXPECT_EQ(SEARCH_ENGINE_OTHER, GetEngineType(foo_url)); 352 EXPECT_EQ(SEARCH_ENGINE_OTHER, GetEngineType(foo_url));
349 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( 353 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
350 switches::kGoogleBaseURL, "http://www.foo.com/"); 354 switches::kGoogleBaseURL, "http://www.foo.com/");
351 EXPECT_EQ(SEARCH_ENGINE_GOOGLE, GetEngineType(foo_url)); 355 EXPECT_EQ(SEARCH_ENGINE_GOOGLE, GetEngineType(foo_url));
352 } 356 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698