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

Side by Side Diff: chrome/browser/search_engines/template_url_prepopulate_data_unittest.cc

Issue 11170007: Make some of the search engine configuration data from master_preferences optional. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 2 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/file_util.h" 5 #include "base/file_util.h"
6 #include "base/memory/scoped_vector.h" 6 #include "base/memory/scoped_vector.h"
7 #include "base/scoped_temp_dir.h" 7 #include "base/scoped_temp_dir.h"
8 #include "base/utf_string_conversions.h" 8 #include "base/utf_string_conversions.h"
9 #include "chrome/browser/search_engines/search_terms_data.h" 9 #include "chrome/browser/search_engines/search_terms_data.h"
10 #include "chrome/browser/search_engines/template_url.h" 10 #include "chrome/browser/search_engines/template_url.h"
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 } 90 }
91 91
92 // Verifies that default search providers from the preferences file 92 // Verifies that default search providers from the preferences file
93 // override the built-in ones. 93 // override the built-in ones.
94 TEST(TemplateURLPrepopulateDataTest, ProvidersFromPrefs) { 94 TEST(TemplateURLPrepopulateDataTest, ProvidersFromPrefs) {
95 TestingProfile profile; 95 TestingProfile profile;
96 TestingPrefService* prefs = profile.GetTestingPrefService(); 96 TestingPrefService* prefs = profile.GetTestingPrefService();
97 prefs->SetUserPref(prefs::kSearchProviderOverridesVersion, 97 prefs->SetUserPref(prefs::kSearchProviderOverridesVersion,
98 Value::CreateIntegerValue(1)); 98 Value::CreateIntegerValue(1));
99 ListValue* overrides = new ListValue; 99 ListValue* overrides = new ListValue;
100 DictionaryValue* entry = new DictionaryValue; 100 scoped_ptr<DictionaryValue> entry(new DictionaryValue);
101 // Set only the minimal required settings for a search provider configuration.
101 entry->SetString("name", "foo"); 102 entry->SetString("name", "foo");
102 entry->SetString("keyword", "fook"); 103 entry->SetString("keyword", "fook");
103 entry->SetString("search_url", "http://foo.com/s?q={searchTerms}"); 104 entry->SetString("search_url", "http://foo.com/s?q={searchTerms}");
104 entry->SetString("favicon_url", "http://foi.com/favicon.ico"); 105 entry->SetString("favicon_url", "http://foi.com/favicon.ico");
105 entry->SetString("suggest_url", "");
106 entry->SetString("instant_url", "");
107 entry->Set("alternate_urls", new ListValue());
108 entry->SetString("encoding", "UTF-8"); 106 entry->SetString("encoding", "UTF-8");
109 entry->SetInteger("id", 1001); 107 entry->SetInteger("id", 1001);
110 overrides->Append(entry); 108 overrides->Append(entry->DeepCopy());
111 prefs->SetUserPref(prefs::kSearchProviderOverrides, overrides); 109 prefs->SetUserPref(prefs::kSearchProviderOverrides, overrides);
112 110
113 int version = TemplateURLPrepopulateData::GetDataVersion(prefs); 111 int version = TemplateURLPrepopulateData::GetDataVersion(prefs);
114 EXPECT_EQ(1, version); 112 EXPECT_EQ(1, version);
115 113
116 ScopedVector<TemplateURL> t_urls; 114 ScopedVector<TemplateURL> t_urls;
117 size_t default_index; 115 size_t default_index;
118 TemplateURLPrepopulateData::GetPrepopulatedEngines(&profile, &t_urls.get(), 116 TemplateURLPrepopulateData::GetPrepopulatedEngines(&profile, &t_urls.get(),
119 &default_index); 117 &default_index);
120 118
121 ASSERT_EQ(1u, t_urls.size()); 119 ASSERT_EQ(1u, t_urls.size());
122 EXPECT_EQ(ASCIIToUTF16("foo"), t_urls[0]->short_name()); 120 EXPECT_EQ(ASCIIToUTF16("foo"), t_urls[0]->short_name());
123 EXPECT_EQ(ASCIIToUTF16("fook"), t_urls[0]->keyword()); 121 EXPECT_EQ(ASCIIToUTF16("fook"), t_urls[0]->keyword());
124 EXPECT_EQ("foo.com", t_urls[0]->url_ref().GetHost()); 122 EXPECT_EQ("foo.com", t_urls[0]->url_ref().GetHost());
125 EXPECT_EQ("foi.com", t_urls[0]->favicon_url().host()); 123 EXPECT_EQ("foi.com", t_urls[0]->favicon_url().host());
126 EXPECT_EQ(1u, t_urls[0]->input_encodings().size()); 124 EXPECT_EQ(1u, t_urls[0]->input_encodings().size());
127 EXPECT_EQ(1001, t_urls[0]->prepopulate_id()); 125 EXPECT_EQ(1001, t_urls[0]->prepopulate_id());
126 EXPECT_TRUE(t_urls[0]->suggestions_url().empty());
127 EXPECT_TRUE(t_urls[0]->instant_url().empty());
128 EXPECT_EQ(0u, t_urls[0]->alternate_urls().size());
129
130 // Test the optional settings too.
131 entry->SetString("suggest_url", "http://foo.com/suggest?q={searchTerms}");
132 entry->SetString("instant_url", "http://foo.com/instant?q={searchTerms}");
133 ListValue* alternate_urls = new ListValue;
134 alternate_urls->AppendString("http://foo.com/alternate?q={searchTerms}");
135 entry->Set("alternate_urls", alternate_urls);
136 overrides = new ListValue;
137 overrides->Append(entry->DeepCopy());
138 prefs->SetUserPref(prefs::kSearchProviderOverrides, overrides);
139
140 t_urls.clear();
141 TemplateURLPrepopulateData::GetPrepopulatedEngines(&profile, &t_urls.get(),
142 &default_index);
143 ASSERT_EQ(1u, t_urls.size());
144 EXPECT_EQ(ASCIIToUTF16("foo"), t_urls[0]->short_name());
145 EXPECT_EQ(ASCIIToUTF16("fook"), t_urls[0]->keyword());
146 EXPECT_EQ("foo.com", t_urls[0]->url_ref().GetHost());
147 EXPECT_EQ("foi.com", t_urls[0]->favicon_url().host());
148 EXPECT_EQ(1u, t_urls[0]->input_encodings().size());
149 EXPECT_EQ(1001, t_urls[0]->prepopulate_id());
150 EXPECT_EQ("http://foo.com/suggest?q={searchTerms}",
151 t_urls[0]->suggestions_url());
152 EXPECT_EQ("http://foo.com/instant?q={searchTerms}",
153 t_urls[0]->instant_url());
154 ASSERT_EQ(1u, t_urls[0]->alternate_urls().size());
155 EXPECT_EQ("http://foo.com/alternate?q={searchTerms}",
156 t_urls[0]->alternate_urls()[0]);
157
158 // Test that subsequent providers are loaded even if an intermediate
159 // provider has an incomplete configuration.
160 overrides = new ListValue;
161 overrides->Append(entry->DeepCopy());
162 entry->SetInteger("id", 1002);
163 entry->SetString("name", "bar");
164 entry->SetString("keyword", "bark");
165 entry->SetString("encoding", "");
166 overrides->Append(entry->DeepCopy());
167 entry->SetInteger("id", 1003);
168 entry->SetString("name", "baz");
169 entry->SetString("keyword", "bazk");
170 entry->SetString("encoding", "UTF-8");
171 overrides->Append(entry->DeepCopy());
172 prefs->SetUserPref(prefs::kSearchProviderOverrides, overrides);
173
174 t_urls.clear();
175 TemplateURLPrepopulateData::GetPrepopulatedEngines(&profile, &t_urls.get(),
176 &default_index);
177 EXPECT_EQ(2u, t_urls.size());
128 } 178 }
129 179
130 TEST(TemplateURLPrepopulateDataTest, GetEngineTypeBasic) { 180 TEST(TemplateURLPrepopulateDataTest, GetEngineTypeBasic) {
131 EXPECT_EQ(SEARCH_ENGINE_OTHER, 181 EXPECT_EQ(SEARCH_ENGINE_OTHER,
132 TemplateURLPrepopulateData::GetEngineType("http://example.com/")); 182 TemplateURLPrepopulateData::GetEngineType("http://example.com/"));
133 EXPECT_EQ(SEARCH_ENGINE_ASK, 183 EXPECT_EQ(SEARCH_ENGINE_ASK,
134 TemplateURLPrepopulateData::GetEngineType("http://www.ask.com/")); 184 TemplateURLPrepopulateData::GetEngineType("http://www.ask.com/"));
135 EXPECT_EQ(SEARCH_ENGINE_OTHER, 185 EXPECT_EQ(SEARCH_ENGINE_OTHER,
136 TemplateURLPrepopulateData::GetEngineType("http://search.atlas.cz/")); 186 TemplateURLPrepopulateData::GetEngineType("http://search.atlas.cz/"));
137 EXPECT_EQ(SEARCH_ENGINE_GOOGLE, 187 EXPECT_EQ(SEARCH_ENGINE_GOOGLE,
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 254
205 TEST(TemplateURLPrepopulateDataTest, GetLogoURLInvalid) { 255 TEST(TemplateURLPrepopulateDataTest, GetLogoURLInvalid) {
206 TemplateURLData data; 256 TemplateURLData data;
207 data.SetURL("http://invalid:search:url/"); 257 data.SetURL("http://invalid:search:url/");
208 TemplateURL turl(NULL, data); 258 TemplateURL turl(NULL, data);
209 GURL logo_url = TemplateURLPrepopulateData::GetLogoURL( 259 GURL logo_url = TemplateURLPrepopulateData::GetLogoURL(
210 turl, TemplateURLPrepopulateData::LOGO_100_PERCENT); 260 turl, TemplateURLPrepopulateData::LOGO_100_PERCENT);
211 261
212 EXPECT_TRUE(logo_url.is_empty()); 262 EXPECT_TRUE(logo_url.is_empty());
213 } 263 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698