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 "base/command_line.h" | 5 #include "base/command_line.h" |
6 #include "base/files/scoped_temp_dir.h" | 6 #include "base/files/scoped_temp_dir.h" |
7 #include "base/memory/scoped_vector.h" | 7 #include "base/memory/scoped_vector.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "components/google/core/browser/google_switches.h" | 9 #include "components/google/core/browser/google_switches.h" |
10 #include "components/pref_registry/testing_pref_service_syncable.h" | 10 #include "components/pref_registry/testing_pref_service_syncable.h" |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 unique_ids.end()); | 109 unique_ids.end()); |
110 unique_ids.insert(urls[turl_i]->prepopulate_id); | 110 unique_ids.insert(urls[turl_i]->prepopulate_id); |
111 } | 111 } |
112 } | 112 } |
113 } | 113 } |
114 | 114 |
115 // Verifies that default search providers from the preferences file | 115 // Verifies that default search providers from the preferences file |
116 // override the built-in ones. | 116 // override the built-in ones. |
117 TEST_F(TemplateURLPrepopulateDataTest, ProvidersFromPrefs) { | 117 TEST_F(TemplateURLPrepopulateDataTest, ProvidersFromPrefs) { |
118 prefs_.SetUserPref(prefs::kSearchProviderOverridesVersion, | 118 prefs_.SetUserPref(prefs::kSearchProviderOverridesVersion, |
119 base::Value::CreateIntegerValue(1)); | 119 new base::FundamentalValue(1)); |
120 base::ListValue* overrides = new base::ListValue; | 120 base::ListValue* overrides = new base::ListValue; |
121 scoped_ptr<base::DictionaryValue> entry(new base::DictionaryValue); | 121 scoped_ptr<base::DictionaryValue> entry(new base::DictionaryValue); |
122 // Set only the minimal required settings for a search provider configuration. | 122 // Set only the minimal required settings for a search provider configuration. |
123 entry->SetString("name", "foo"); | 123 entry->SetString("name", "foo"); |
124 entry->SetString("keyword", "fook"); | 124 entry->SetString("keyword", "fook"); |
125 entry->SetString("search_url", "http://foo.com/s?q={searchTerms}"); | 125 entry->SetString("search_url", "http://foo.com/s?q={searchTerms}"); |
126 entry->SetString("favicon_url", "http://foi.com/favicon.ico"); | 126 entry->SetString("favicon_url", "http://foi.com/favicon.ico"); |
127 entry->SetString("encoding", "UTF-8"); | 127 entry->SetString("encoding", "UTF-8"); |
128 entry->SetInteger("id", 1001); | 128 entry->SetInteger("id", 1001); |
129 overrides->Append(entry->DeepCopy()); | 129 overrides->Append(entry->DeepCopy()); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 prefs_.SetUserPref(prefs::kSearchProviderOverrides, overrides); | 195 prefs_.SetUserPref(prefs::kSearchProviderOverrides, overrides); |
196 | 196 |
197 t_urls = | 197 t_urls = |
198 TemplateURLPrepopulateData::GetPrepopulatedEngines(&prefs_, | 198 TemplateURLPrepopulateData::GetPrepopulatedEngines(&prefs_, |
199 &default_index); | 199 &default_index); |
200 EXPECT_EQ(2u, t_urls.size()); | 200 EXPECT_EQ(2u, t_urls.size()); |
201 } | 201 } |
202 | 202 |
203 TEST_F(TemplateURLPrepopulateDataTest, ClearProvidersFromPrefs) { | 203 TEST_F(TemplateURLPrepopulateDataTest, ClearProvidersFromPrefs) { |
204 prefs_.SetUserPref(prefs::kSearchProviderOverridesVersion, | 204 prefs_.SetUserPref(prefs::kSearchProviderOverridesVersion, |
205 base::Value::CreateIntegerValue(1)); | 205 new base::FundamentalValue(1)); |
206 base::ListValue* overrides = new base::ListValue; | 206 base::ListValue* overrides = new base::ListValue; |
207 base::DictionaryValue* entry(new base::DictionaryValue); | 207 base::DictionaryValue* entry(new base::DictionaryValue); |
208 // Set only the minimal required settings for a search provider configuration. | 208 // Set only the minimal required settings for a search provider configuration. |
209 entry->SetString("name", "foo"); | 209 entry->SetString("name", "foo"); |
210 entry->SetString("keyword", "fook"); | 210 entry->SetString("keyword", "fook"); |
211 entry->SetString("search_url", "http://foo.com/s?q={searchTerms}"); | 211 entry->SetString("search_url", "http://foo.com/s?q={searchTerms}"); |
212 entry->SetString("favicon_url", "http://foi.com/favicon.ico"); | 212 entry->SetString("favicon_url", "http://foi.com/favicon.ico"); |
213 entry->SetString("encoding", "UTF-8"); | 213 entry->SetString("encoding", "UTF-8"); |
214 entry->SetInteger("id", 1001); | 214 entry->SetInteger("id", 1001); |
215 overrides->Append(entry); | 215 overrides->Append(entry); |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
340 EXPECT_EQ(SEARCH_ENGINE_OTHER, GetEngineType("invalid:search:url")); | 340 EXPECT_EQ(SEARCH_ENGINE_OTHER, GetEngineType("invalid:search:url")); |
341 | 341 |
342 // URL that doesn't look Google-related, but matches a Google base URL | 342 // URL that doesn't look Google-related, but matches a Google base URL |
343 // specified on the command line. | 343 // specified on the command line. |
344 const std::string foo_url("http://www.foo.com/search?q={searchTerms}"); | 344 const std::string foo_url("http://www.foo.com/search?q={searchTerms}"); |
345 EXPECT_EQ(SEARCH_ENGINE_OTHER, GetEngineType(foo_url)); | 345 EXPECT_EQ(SEARCH_ENGINE_OTHER, GetEngineType(foo_url)); |
346 CommandLine::ForCurrentProcess()->AppendSwitchASCII(switches::kGoogleBaseURL, | 346 CommandLine::ForCurrentProcess()->AppendSwitchASCII(switches::kGoogleBaseURL, |
347 "http://www.foo.com/"); | 347 "http://www.foo.com/"); |
348 EXPECT_EQ(SEARCH_ENGINE_GOOGLE, GetEngineType(foo_url)); | 348 EXPECT_EQ(SEARCH_ENGINE_GOOGLE, GetEngineType(foo_url)); |
349 } | 349 } |
OLD | NEW |