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

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

Issue 287103002: Introduce ability to register callback with GoogleURLTracker (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Response to review 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 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 protected: 128 protected:
129 TemplateURL* AddNewTemplateURL(const std::string& url, 129 TemplateURL* AddNewTemplateURL(const std::string& url,
130 const base::string16& keyword); 130 const base::string16& keyword);
131 131
132 // Sets the Google base URL to |base_url| and runs the IO thread for
133 // |SearchProviderInstallData| to process the update.
134 void SetGoogleBaseURLAndProcessOnIOThread(GURL base_url);
135
132 TemplateURLServiceTestUtil util_; 136 TemplateURLServiceTestUtil util_;
133 137
134 // Provides the search provider install state on the I/O thread. It must be 138 // Provides the search provider install state on the I/O thread. It must be
135 // deleted on the I/O thread, which is why it isn't a scoped_ptr. 139 // deleted on the I/O thread, which is why it isn't a scoped_ptr.
136 SearchProviderInstallData* install_data_; 140 SearchProviderInstallData* install_data_;
137 141
138 // A mock RenderProcessHost that the SearchProviderInstallData will scope its 142 // A mock RenderProcessHost that the SearchProviderInstallData will scope its
139 // lifetime to. 143 // lifetime to.
140 scoped_ptr<content::MockRenderProcessHost> process_; 144 scoped_ptr<content::MockRenderProcessHost> process_;
141 145
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 const base::string16& keyword) { 179 const base::string16& keyword) {
176 TemplateURLData data; 180 TemplateURLData data;
177 data.short_name = keyword; 181 data.short_name = keyword;
178 data.SetKeyword(keyword); 182 data.SetKeyword(keyword);
179 data.SetURL(url); 183 data.SetURL(url);
180 TemplateURL* t_url = new TemplateURL(util_.profile(), data); 184 TemplateURL* t_url = new TemplateURL(util_.profile(), data);
181 util_.model()->Add(t_url); 185 util_.model()->Add(t_url);
182 return t_url; 186 return t_url;
183 } 187 }
184 188
189 void SearchProviderInstallDataTest::SetGoogleBaseURLAndProcessOnIOThread(
190 GURL base_url) {
191 util_.SetGoogleBaseURL(base_url);
192 BrowserThread::PostTask(
193 BrowserThread::IO,
194 FROM_HERE,
195 base::Bind(&SearchProviderInstallData::OnGoogleURLChange,
196 base::Unretained(install_data_),
197 base_url.spec()));
198
199 // Wait for the I/O thread to process the update notification.
200 base::RunLoop().RunUntilIdle();
201 }
202
185 // Actual tests --------------------------------------------------------------- 203 // Actual tests ---------------------------------------------------------------
186 204
187 TEST_F(SearchProviderInstallDataTest, GetInstallState) { 205 TEST_F(SearchProviderInstallDataTest, GetInstallState) {
188 // Set up the database. 206 // Set up the database.
189 util_.ChangeModelToLoadState(); 207 util_.ChangeModelToLoadState();
190 std::string host = "www.unittest.com"; 208 std::string host = "www.unittest.com";
191 AddNewTemplateURL("http://" + host + "/path", base::ASCIIToUTF16("unittest")); 209 AddNewTemplateURL("http://" + host + "/path", base::ASCIIToUTF16("unittest"));
192 210
193 // Wait for the changes to be saved. 211 // Wait for the changes to be saved.
194 base::RunLoop().RunUntilIdle(); 212 base::RunLoop().RunUntilIdle();
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 TestGetInstallState test_get_install_state(install_data_); 253 TestGetInstallState test_get_install_state(install_data_);
236 test_get_install_state.RunTests(host, host2); 254 test_get_install_state.RunTests(host, host2);
237 } 255 }
238 256
239 TEST_F(SearchProviderInstallDataTest, GoogleBaseUrlChange) { 257 TEST_F(SearchProviderInstallDataTest, GoogleBaseUrlChange) {
240 TestGetInstallState test_get_install_state(install_data_); 258 TestGetInstallState test_get_install_state(install_data_);
241 259
242 // Set up the database. 260 // Set up the database.
243 util_.ChangeModelToLoadState(); 261 util_.ChangeModelToLoadState();
244 std::string google_host = "w.com"; 262 std::string google_host = "w.com";
245 util_.SetGoogleBaseURL(GURL("http://" + google_host + "/")); 263 SetGoogleBaseURLAndProcessOnIOThread(GURL("http://" + google_host + "/"));
246 // Wait for the I/O thread to process the update notification.
247 base::RunLoop().RunUntilIdle();
248 264
249 AddNewTemplateURL("{google:baseURL}?q={searchTerms}", 265 AddNewTemplateURL("{google:baseURL}?q={searchTerms}",
250 base::ASCIIToUTF16("t")); 266 base::ASCIIToUTF16("t"));
251 TemplateURL* default_url = 267 TemplateURL* default_url =
252 AddNewTemplateURL("http://d.com/", base::ASCIIToUTF16("d")); 268 AddNewTemplateURL("http://d.com/", base::ASCIIToUTF16("d"));
253 util_.model()->SetUserSelectedDefaultSearchProvider(default_url); 269 util_.model()->SetUserSelectedDefaultSearchProvider(default_url);
254 270
255 // Wait for the changes to be saved. 271 // Wait for the changes to be saved.
256 base::RunLoop().RunUntilIdle(); 272 base::RunLoop().RunUntilIdle();
257 273
258 // Verify the search providers install state (with no default set). 274 // Verify the search providers install state (with no default set).
259 test_get_install_state.RunTests(google_host, std::string()); 275 test_get_install_state.RunTests(google_host, std::string());
260 276
261 // Change the Google base url. 277 // Change the Google base url.
262 google_host = "foo.com"; 278 google_host = "foo.com";
263 util_.SetGoogleBaseURL(GURL("http://" + google_host + "/")); 279 SetGoogleBaseURLAndProcessOnIOThread(GURL("http://" + google_host + "/"));
264 // Wait for the I/O thread to process the update notification.
265 base::RunLoop().RunUntilIdle();
266 280
267 // Verify that the change got picked up. 281 // Verify that the change got picked up.
268 test_get_install_state.RunTests(google_host, std::string()); 282 test_get_install_state.RunTests(google_host, std::string());
269 } 283 }
OLDNEW
« no previous file with comments | « chrome/browser/search_engines/search_provider_install_data.cc ('k') | chrome/browser/search_engines/template_url_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698