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

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

Issue 265393007: Test fixes and clean up in preparation for moving DSE to Prefs. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Eriks test fixes Created 6 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 | 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 <string> 5 #include <string>
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/memory/ref_counted.h" 9 #include "base/memory/ref_counted.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 118
119 // Provides basic test set-up/tear-down functionality needed by all tests 119 // Provides basic test set-up/tear-down functionality needed by all tests
120 // that use TemplateURLServiceTestUtil. 120 // that use TemplateURLServiceTestUtil.
121 class SearchProviderInstallDataTest : public testing::Test { 121 class SearchProviderInstallDataTest : public testing::Test {
122 public: 122 public:
123 SearchProviderInstallDataTest(); 123 SearchProviderInstallDataTest();
124 124
125 virtual void SetUp() OVERRIDE; 125 virtual void SetUp() OVERRIDE;
126 virtual void TearDown() OVERRIDE; 126 virtual void TearDown() OVERRIDE;
127 127
128 void SimulateDefaultSearchIsManaged(const std::string& url);
129
130 protected: 128 protected:
131 TemplateURL* AddNewTemplateURL(const std::string& url, 129 TemplateURL* AddNewTemplateURL(const std::string& url,
132 const base::string16& keyword); 130 const base::string16& keyword);
133 131
134 TemplateURLServiceTestUtil util_; 132 TemplateURLServiceTestUtil util_;
135 133
136 // Provides the search provider install state on the I/O thread. It must be 134 // Provides the search provider install state on the I/O thread. It must be
137 // deleted on the I/O thread, which is why it isn't a scoped_ptr. 135 // deleted on the I/O thread, which is why it isn't a scoped_ptr.
138 SearchProviderInstallData* install_data_; 136 SearchProviderInstallData* install_data_;
139 137
(...skipping 25 matching lines...) Expand all
165 install_data_ = NULL; 163 install_data_ = NULL;
166 164
167 // Make sure that the install data class on the UI thread gets cleaned up. 165 // Make sure that the install data class on the UI thread gets cleaned up.
168 // It doesn't matter that this happens after install_data_ is deleted. 166 // It doesn't matter that this happens after install_data_ is deleted.
169 process_.reset(); 167 process_.reset();
170 168
171 util_.TearDown(); 169 util_.TearDown();
172 testing::Test::TearDown(); 170 testing::Test::TearDown();
173 } 171 }
174 172
175 void SearchProviderInstallDataTest::SimulateDefaultSearchIsManaged(
176 const std::string& url) {
177 ASSERT_FALSE(url.empty());
178 TestingPrefServiceSyncable* service =
179 util_.profile()->GetTestingPrefService();
180 service->SetManagedPref(prefs::kDefaultSearchProviderEnabled,
181 base::Value::CreateBooleanValue(true));
182 service->SetManagedPref(prefs::kDefaultSearchProviderSearchURL,
183 base::Value::CreateStringValue(url));
184 service->SetManagedPref(prefs::kDefaultSearchProviderName,
185 base::Value::CreateStringValue("managed"));
186 service->SetManagedPref(prefs::kDefaultSearchProviderKeyword,
187 new base::StringValue("managed"));
188 // Clear the IDs that are not specified via policy.
189 service->SetManagedPref(prefs::kDefaultSearchProviderID,
190 new base::StringValue(std::string()));
191 service->SetManagedPref(prefs::kDefaultSearchProviderPrepopulateID,
192 new base::StringValue(std::string()));
193 util_.model()->Observe(chrome::NOTIFICATION_DEFAULT_SEARCH_POLICY_CHANGED,
194 content::NotificationService::AllSources(),
195 content::NotificationService::NoDetails());
196 }
197
198 TemplateURL* SearchProviderInstallDataTest::AddNewTemplateURL( 173 TemplateURL* SearchProviderInstallDataTest::AddNewTemplateURL(
199 const std::string& url, 174 const std::string& url,
200 const base::string16& keyword) { 175 const base::string16& keyword) {
201 TemplateURLData data; 176 TemplateURLData data;
202 data.short_name = keyword; 177 data.short_name = keyword;
203 data.SetKeyword(keyword); 178 data.SetKeyword(keyword);
204 data.SetURL(url); 179 data.SetURL(url);
205 TemplateURL* t_url = new TemplateURL(util_.profile(), data); 180 TemplateURL* t_url = new TemplateURL(util_.profile(), data);
206 util_.model()->Add(t_url); 181 util_.model()->Add(t_url);
207 return t_url; 182 return t_url;
(...skipping 24 matching lines...) Expand all
232 } 207 }
233 208
234 TEST_F(SearchProviderInstallDataTest, ManagedDefaultSearch) { 209 TEST_F(SearchProviderInstallDataTest, ManagedDefaultSearch) {
235 // Set up the database. 210 // Set up the database.
236 util_.ChangeModelToLoadState(); 211 util_.ChangeModelToLoadState();
237 std::string host = "www.unittest.com"; 212 std::string host = "www.unittest.com";
238 AddNewTemplateURL("http://" + host + "/path", base::ASCIIToUTF16("unittest")); 213 AddNewTemplateURL("http://" + host + "/path", base::ASCIIToUTF16("unittest"));
239 214
240 // Set a managed preference that establishes a default search provider. 215 // Set a managed preference that establishes a default search provider.
241 std::string host2 = "www.managedtest.com"; 216 std::string host2 = "www.managedtest.com";
242 std::string url2 = "http://" + host2 + "/p{searchTerms}"; 217 util_.SetManagedDefaultSearchPreferences(
243 SimulateDefaultSearchIsManaged(url2); 218 true,
219 "managed",
220 "managed",
221 "http://" + host2 + "/p{searchTerms}",
222 std::string(),
223 std::string(),
224 std::string(),
225 std::string(),
226 std::string());
227
244 EXPECT_TRUE(util_.model()->is_default_search_managed()); 228 EXPECT_TRUE(util_.model()->is_default_search_managed());
245 229
246 // Wait for the changes to be saved. 230 // Wait for the changes to be saved.
247 base::RunLoop().RunUntilIdle(); 231 base::RunLoop().RunUntilIdle();
248 232
249 // Verify the search providers install state. The default search should be 233 // Verify the search providers install state. The default search should be
250 // the managed one we previously set. 234 // the managed one we previously set.
251 TestGetInstallState test_get_install_state(install_data_); 235 TestGetInstallState test_get_install_state(install_data_);
252 test_get_install_state.RunTests(host, host2); 236 test_get_install_state.RunTests(host, host2);
253 } 237 }
(...skipping 22 matching lines...) Expand all
276 260
277 // Change the Google base url. 261 // Change the Google base url.
278 google_host = "foo.com"; 262 google_host = "foo.com";
279 util_.SetGoogleBaseURL(GURL("http://" + google_host + "/")); 263 util_.SetGoogleBaseURL(GURL("http://" + google_host + "/"));
280 // Wait for the I/O thread to process the update notification. 264 // Wait for the I/O thread to process the update notification.
281 base::RunLoop().RunUntilIdle(); 265 base::RunLoop().RunUntilIdle();
282 266
283 // Verify that the change got picked up. 267 // Verify that the change got picked up.
284 test_get_install_state.RunTests(google_host, std::string()); 268 test_get_install_state.RunTests(google_host, std::string());
285 } 269 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698