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

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

Issue 1135163002: Omnibox - Strip Extra Whitespace from Custom Search Engine Names (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix more tests that don't set short_name Created 5 years, 7 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 "base/files/scoped_temp_dir.h" 5 #include "base/files/scoped_temp_dir.h"
6 #include "base/memory/scoped_ptr.h" 6 #include "base/memory/scoped_ptr.h"
7 #include "base/strings/string_split.h" 7 #include "base/strings/string_split.h"
8 #include "base/strings/string_util.h" 8 #include "base/strings/string_util.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "base/time/time.h" 10 #include "base/time/time.h"
(...skipping 12 matching lines...) Expand all
23 const char kDefaultSearchProviderData[] = 23 const char kDefaultSearchProviderData[] =
24 "default_search_provider_data.template_url_data"; 24 "default_search_provider_data.template_url_data";
25 25
26 // Checks that the two TemplateURLs are similar. Does not check the id, the 26 // Checks that the two TemplateURLs are similar. Does not check the id, the
27 // date_created or the last_modified time. Neither pointer should be NULL. 27 // date_created or the last_modified time. Neither pointer should be NULL.
28 void ExpectSimilar(const TemplateURLData* expected, 28 void ExpectSimilar(const TemplateURLData* expected,
29 const TemplateURLData* actual) { 29 const TemplateURLData* actual) {
30 ASSERT_TRUE(expected != NULL); 30 ASSERT_TRUE(expected != NULL);
31 ASSERT_TRUE(actual != NULL); 31 ASSERT_TRUE(actual != NULL);
32 32
33 EXPECT_EQ(expected->short_name, actual->short_name); 33 EXPECT_EQ(expected->short_name(), actual->short_name());
34 EXPECT_EQ(expected->keyword(), actual->keyword()); 34 EXPECT_EQ(expected->keyword(), actual->keyword());
35 EXPECT_EQ(expected->url(), actual->url()); 35 EXPECT_EQ(expected->url(), actual->url());
36 EXPECT_EQ(expected->suggestions_url, actual->suggestions_url); 36 EXPECT_EQ(expected->suggestions_url, actual->suggestions_url);
37 EXPECT_EQ(expected->favicon_url, actual->favicon_url); 37 EXPECT_EQ(expected->favicon_url, actual->favicon_url);
38 EXPECT_EQ(expected->alternate_urls, actual->alternate_urls); 38 EXPECT_EQ(expected->alternate_urls, actual->alternate_urls);
39 EXPECT_EQ(expected->show_in_default_list, actual->show_in_default_list); 39 EXPECT_EQ(expected->show_in_default_list, actual->show_in_default_list);
40 EXPECT_EQ(expected->safe_for_autoreplace, actual->safe_for_autoreplace); 40 EXPECT_EQ(expected->safe_for_autoreplace, actual->safe_for_autoreplace);
41 EXPECT_EQ(expected->input_encodings, actual->input_encodings); 41 EXPECT_EQ(expected->input_encodings, actual->input_encodings);
42 EXPECT_EQ(expected->search_terms_replacement_key, 42 EXPECT_EQ(expected->search_terms_replacement_key,
43 actual->search_terms_replacement_key); 43 actual->search_terms_replacement_key);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 } 79 }
80 80
81 void SetPolicy(user_prefs::TestingPrefServiceSyncable* prefs, 81 void SetPolicy(user_prefs::TestingPrefServiceSyncable* prefs,
82 bool enabled, 82 bool enabled,
83 TemplateURLData* data) { 83 TemplateURLData* data) {
84 if (enabled) { 84 if (enabled) {
85 EXPECT_FALSE(data->keyword().empty()); 85 EXPECT_FALSE(data->keyword().empty());
86 EXPECT_FALSE(data->url().empty()); 86 EXPECT_FALSE(data->url().empty());
87 } 87 }
88 scoped_ptr<base::DictionaryValue> entry(new base::DictionaryValue); 88 scoped_ptr<base::DictionaryValue> entry(new base::DictionaryValue);
89 entry->SetString(DefaultSearchManager::kShortName, data->short_name); 89 entry->SetString(DefaultSearchManager::kShortName, data->short_name());
90 entry->SetString(DefaultSearchManager::kKeyword, data->keyword()); 90 entry->SetString(DefaultSearchManager::kKeyword, data->keyword());
91 entry->SetString(DefaultSearchManager::kURL, data->url()); 91 entry->SetString(DefaultSearchManager::kURL, data->url());
92 entry->SetString(DefaultSearchManager::kFaviconURL, data->favicon_url.spec()); 92 entry->SetString(DefaultSearchManager::kFaviconURL, data->favicon_url.spec());
93 entry->SetString(DefaultSearchManager::kSuggestionsURL, 93 entry->SetString(DefaultSearchManager::kSuggestionsURL,
94 data->suggestions_url); 94 data->suggestions_url);
95 entry->SetBoolean(DefaultSearchManager::kSafeForAutoReplace, 95 entry->SetBoolean(DefaultSearchManager::kSafeForAutoReplace,
96 data->safe_for_autoreplace); 96 data->safe_for_autoreplace);
97 scoped_ptr<base::ListValue> alternate_urls(new base::ListValue); 97 scoped_ptr<base::ListValue> alternate_urls(new base::ListValue);
98 for (std::vector<std::string>::const_iterator it = 98 for (std::vector<std::string>::const_iterator it =
99 data->alternate_urls.begin(); 99 data->alternate_urls.begin();
(...skipping 13 matching lines...) Expand all
113 entry->Set(DefaultSearchManager::kInputEncodings, encodings.release()); 113 entry->Set(DefaultSearchManager::kInputEncodings, encodings.release());
114 114
115 entry->SetString(DefaultSearchManager::kSearchTermsReplacementKey, 115 entry->SetString(DefaultSearchManager::kSearchTermsReplacementKey,
116 data->search_terms_replacement_key); 116 data->search_terms_replacement_key);
117 entry->SetBoolean(DefaultSearchManager::kDisabledByPolicy, !enabled); 117 entry->SetBoolean(DefaultSearchManager::kDisabledByPolicy, !enabled);
118 prefs->SetManagedPref(kDefaultSearchProviderData, entry.release()); 118 prefs->SetManagedPref(kDefaultSearchProviderData, entry.release());
119 } 119 }
120 120
121 scoped_ptr<TemplateURLData> GenerateDummyTemplateURLData(std::string type) { 121 scoped_ptr<TemplateURLData> GenerateDummyTemplateURLData(std::string type) {
122 scoped_ptr<TemplateURLData> data(new TemplateURLData()); 122 scoped_ptr<TemplateURLData> data(new TemplateURLData());
123 data->short_name = base::UTF8ToUTF16(std::string(type).append("name")); 123 data->SetShortName(base::UTF8ToUTF16(std::string(type).append("name")));
124 data->SetKeyword(base::UTF8ToUTF16(std::string(type).append("key"))); 124 data->SetKeyword(base::UTF8ToUTF16(std::string(type).append("key")));
125 data->SetURL(std::string("http://").append(type).append("foo/{searchTerms}")); 125 data->SetURL(std::string("http://").append(type).append("foo/{searchTerms}"));
126 data->suggestions_url = std::string("http://").append(type).append("sugg"); 126 data->suggestions_url = std::string("http://").append(type).append("sugg");
127 data->alternate_urls.push_back( 127 data->alternate_urls.push_back(
128 std::string("http://").append(type).append("foo/alt")); 128 std::string("http://").append(type).append("foo/alt"));
129 data->favicon_url = GURL("http://icon1"); 129 data->favicon_url = GURL("http://icon1");
130 data->safe_for_autoreplace = true; 130 data->safe_for_autoreplace = true;
131 data->show_in_default_list = true; 131 data->show_in_default_list = true;
132 base::SplitString("UTF-8;UTF-16", ';', &data->input_encodings); 132 base::SplitString("UTF-8;UTF-16", ';', &data->input_encodings);
133 data->date_created = base::Time(); 133 data->date_created = base::Time();
(...skipping 21 matching lines...) Expand all
155 scoped_ptr<user_prefs::TestingPrefServiceSyncable> pref_service_; 155 scoped_ptr<user_prefs::TestingPrefServiceSyncable> pref_service_;
156 156
157 DISALLOW_COPY_AND_ASSIGN(DefaultSearchManagerTest); 157 DISALLOW_COPY_AND_ASSIGN(DefaultSearchManagerTest);
158 }; 158 };
159 159
160 // Test that a TemplateURLData object is properly written and read from Prefs. 160 // Test that a TemplateURLData object is properly written and read from Prefs.
161 TEST_F(DefaultSearchManagerTest, ReadAndWritePref) { 161 TEST_F(DefaultSearchManagerTest, ReadAndWritePref) {
162 DefaultSearchManager manager(pref_service(), 162 DefaultSearchManager manager(pref_service(),
163 DefaultSearchManager::ObserverCallback()); 163 DefaultSearchManager::ObserverCallback());
164 TemplateURLData data; 164 TemplateURLData data;
165 data.short_name = base::UTF8ToUTF16("name1"); 165 data.SetShortName(base::UTF8ToUTF16("name1"));
166 data.SetKeyword(base::UTF8ToUTF16("key1")); 166 data.SetKeyword(base::UTF8ToUTF16("key1"));
167 data.SetURL("http://foo1/{searchTerms}"); 167 data.SetURL("http://foo1/{searchTerms}");
168 data.suggestions_url = "http://sugg1"; 168 data.suggestions_url = "http://sugg1";
169 data.alternate_urls.push_back("http://foo1/alt"); 169 data.alternate_urls.push_back("http://foo1/alt");
170 data.favicon_url = GURL("http://icon1"); 170 data.favicon_url = GURL("http://icon1");
171 data.safe_for_autoreplace = true; 171 data.safe_for_autoreplace = true;
172 data.show_in_default_list = true; 172 data.show_in_default_list = true;
173 base::SplitString("UTF-8;UTF-16", ';', &data.input_encodings); 173 base::SplitString("UTF-8;UTF-16", ';', &data.input_encodings);
174 data.date_created = base::Time(); 174 data.date_created = base::Time();
175 data.last_modified = base::Time(); 175 data.last_modified = base::Time();
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 235
236 // Update the overrides: 236 // Update the overrides:
237 SetOverrides(pref_service(), true); 237 SetOverrides(pref_service(), true);
238 prepopulated_urls = TemplateURLPrepopulateData::GetPrepopulatedEngines( 238 prepopulated_urls = TemplateURLPrepopulateData::GetPrepopulatedEngines(
239 pref_service(), &default_search_index); 239 pref_service(), &default_search_index);
240 240
241 // Make sure DefaultSearchManager updated: 241 // Make sure DefaultSearchManager updated:
242 ExpectSimilar(prepopulated_urls[default_search_index], 242 ExpectSimilar(prepopulated_urls[default_search_index],
243 manager.GetDefaultSearchEngine(&source)); 243 manager.GetDefaultSearchEngine(&source));
244 EXPECT_EQ(DefaultSearchManager::FROM_FALLBACK, source); 244 EXPECT_EQ(DefaultSearchManager::FROM_FALLBACK, source);
245 EXPECT_NE(manager.GetDefaultSearchEngine(NULL)->short_name, 245 EXPECT_NE(manager.GetDefaultSearchEngine(NULL)->short_name(),
246 first_default.short_name); 246 first_default.short_name());
247 EXPECT_NE(manager.GetDefaultSearchEngine(NULL)->keyword(), 247 EXPECT_NE(manager.GetDefaultSearchEngine(NULL)->keyword(),
248 first_default.keyword()); 248 first_default.keyword());
249 } 249 }
250 250
251 // Test DefaultSearchManager handles policy-enforced DSEs correctly. 251 // Test DefaultSearchManager handles policy-enforced DSEs correctly.
252 TEST_F(DefaultSearchManagerTest, DefaultSearchSetByPolicy) { 252 TEST_F(DefaultSearchManagerTest, DefaultSearchSetByPolicy) {
253 DefaultSearchManager manager(pref_service(), 253 DefaultSearchManager manager(pref_service(),
254 DefaultSearchManager::ObserverCallback()); 254 DefaultSearchManager::ObserverCallback());
255 scoped_ptr<TemplateURLData> data = GenerateDummyTemplateURLData("user"); 255 scoped_ptr<TemplateURLData> data = GenerateDummyTemplateURLData("user");
256 manager.SetUserSelectedDefaultSearchEngine(*data.get()); 256 manager.SetUserSelectedDefaultSearchEngine(*data.get());
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 315
316 ExpectSimilar(extension_data_3.get(), 316 ExpectSimilar(extension_data_3.get(),
317 manager.GetDefaultSearchEngine(&source)); 317 manager.GetDefaultSearchEngine(&source));
318 EXPECT_EQ(DefaultSearchManager::FROM_EXTENSION, source); 318 EXPECT_EQ(DefaultSearchManager::FROM_EXTENSION, source);
319 319
320 manager.ClearExtensionControlledDefaultSearchEngine(); 320 manager.ClearExtensionControlledDefaultSearchEngine();
321 321
322 ExpectSimilar(data.get(), manager.GetDefaultSearchEngine(&source)); 322 ExpectSimilar(data.get(), manager.GetDefaultSearchEngine(&source));
323 EXPECT_EQ(DefaultSearchManager::FROM_USER, source); 323 EXPECT_EQ(DefaultSearchManager::FROM_USER, source);
324 } 324 }
OLDNEW
« no previous file with comments | « components/search_engines/default_search_manager.cc ('k') | components/search_engines/keyword_table.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698