OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "base/ref_counted.h" | 9 #include "base/ref_counted.h" |
10 #include "base/task.h" | 10 #include "base/task.h" |
| 11 #include "base/utf_string_conversions.h" |
11 #include "chrome/browser/browser_thread.h" | 12 #include "chrome/browser/browser_thread.h" |
12 #include "chrome/browser/search_engines/search_provider_install_data.h" | 13 #include "chrome/browser/search_engines/search_provider_install_data.h" |
13 #include "chrome/browser/search_engines/template_url.h" | 14 #include "chrome/browser/search_engines/template_url.h" |
14 #include "chrome/browser/search_engines/template_url_model.h" | 15 #include "chrome/browser/search_engines/template_url_model.h" |
15 #include "chrome/browser/search_engines/template_url_model_test_util.h" | 16 #include "chrome/browser/search_engines/template_url_model_test_util.h" |
16 #include "chrome/common/notification_service.h" | 17 #include "chrome/common/notification_service.h" |
17 #include "chrome/common/notification_source.h" | 18 #include "chrome/common/notification_source.h" |
18 #include "chrome/common/notification_type.h" | 19 #include "chrome/common/notification_type.h" |
19 #include "chrome/common/pref_names.h" | 20 #include "chrome/common/pref_names.h" |
20 #include "chrome/test/testing_pref_service.h" | 21 #include "chrome/test/testing_pref_service.h" |
21 #include "chrome/test/testing_profile.h" | 22 #include "chrome/test/testing_profile.h" |
22 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
23 | 24 |
24 // Create a TemplateURL. The caller owns the returned TemplateURL*. | 25 // Create a TemplateURL. The caller owns the returned TemplateURL*. |
25 static TemplateURL* CreateTemplateURL(const std::string& url, | 26 static TemplateURL* CreateTemplateURL(const std::string& url, |
26 const std::wstring& keyword) { | 27 const std::string& keyword) { |
27 TemplateURL* t_url = new TemplateURL(); | 28 TemplateURL* t_url = new TemplateURL(); |
28 t_url->SetURL(url, 0, 0); | 29 t_url->SetURL(url, 0, 0); |
29 t_url->set_keyword(keyword); | 30 t_url->set_keyword(UTF8ToUTF16(keyword)); |
30 t_url->set_short_name(keyword); | 31 t_url->set_short_name(UTF8ToUTF16(keyword)); |
31 return t_url; | 32 return t_url; |
32 } | 33 } |
33 | 34 |
34 // Test the SearchProviderInstallData::GetInstallState. | 35 // Test the SearchProviderInstallData::GetInstallState. |
35 class TestGetInstallState : | 36 class TestGetInstallState : |
36 public base::RefCountedThreadSafe<TestGetInstallState> { | 37 public base::RefCountedThreadSafe<TestGetInstallState> { |
37 public: | 38 public: |
38 explicit TestGetInstallState(SearchProviderInstallData* install_data) | 39 explicit TestGetInstallState(SearchProviderInstallData* install_data) |
39 : install_data_(install_data), | 40 : install_data_(install_data), |
40 main_loop_(NULL), | 41 main_loop_(NULL), |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 SearchProviderInstallData* install_data_; | 219 SearchProviderInstallData* install_data_; |
219 | 220 |
220 DISALLOW_COPY_AND_ASSIGN(SearchProviderInstallDataTest); | 221 DISALLOW_COPY_AND_ASSIGN(SearchProviderInstallDataTest); |
221 }; | 222 }; |
222 | 223 |
223 TEST_F(SearchProviderInstallDataTest, GetInstallState) { | 224 TEST_F(SearchProviderInstallDataTest, GetInstallState) { |
224 // Set up the database. | 225 // Set up the database. |
225 util_.ChangeModelToLoadState(); | 226 util_.ChangeModelToLoadState(); |
226 std::string host = "www.unittest.com"; | 227 std::string host = "www.unittest.com"; |
227 TemplateURL* t_url = CreateTemplateURL("http://" + host + "/path", | 228 TemplateURL* t_url = CreateTemplateURL("http://" + host + "/path", |
228 L"unittest"); | 229 "unittest"); |
229 util_.model()->Add(t_url); | 230 util_.model()->Add(t_url); |
230 | 231 |
231 // Wait for the changes to be saved. | 232 // Wait for the changes to be saved. |
232 TemplateURLModelTestUtil::BlockTillServiceProcessesRequests(); | 233 TemplateURLModelTestUtil::BlockTillServiceProcessesRequests(); |
233 | 234 |
234 // Verify the search providers install state (with no default set). | 235 // Verify the search providers install state (with no default set). |
235 scoped_refptr<TestGetInstallState> test_get_install_state( | 236 scoped_refptr<TestGetInstallState> test_get_install_state( |
236 new TestGetInstallState(install_data_)); | 237 new TestGetInstallState(install_data_)); |
237 test_get_install_state->set_search_provider_host(host); | 238 test_get_install_state->set_search_provider_host(host); |
238 EXPECT_TRUE(test_get_install_state->RunTests()); | 239 EXPECT_TRUE(test_get_install_state->RunTests()); |
239 | 240 |
240 // Set-up a default and try it all one more time. | 241 // Set-up a default and try it all one more time. |
241 std::string default_host = "www.mmm.com"; | 242 std::string default_host = "www.mmm.com"; |
242 TemplateURL* default_url = CreateTemplateURL("http://" + default_host + "/", | 243 TemplateURL* default_url = CreateTemplateURL("http://" + default_host + "/", |
243 L"mmm"); | 244 "mmm"); |
244 util_.model()->Add(default_url); | 245 util_.model()->Add(default_url); |
245 util_.model()->SetDefaultSearchProvider(default_url); | 246 util_.model()->SetDefaultSearchProvider(default_url); |
246 test_get_install_state->set_default_search_provider_host(default_host); | 247 test_get_install_state->set_default_search_provider_host(default_host); |
247 EXPECT_TRUE(test_get_install_state->RunTests()); | 248 EXPECT_TRUE(test_get_install_state->RunTests()); |
248 } | 249 } |
249 | 250 |
250 | 251 |
251 TEST_F(SearchProviderInstallDataTest, ManagedDefaultSearch) { | 252 TEST_F(SearchProviderInstallDataTest, ManagedDefaultSearch) { |
252 // Set up the database. | 253 // Set up the database. |
253 util_.ChangeModelToLoadState(); | 254 util_.ChangeModelToLoadState(); |
254 std::string host = "www.unittest.com"; | 255 std::string host = "www.unittest.com"; |
255 TemplateURL* t_url = CreateTemplateURL("http://" + host + "/path", | 256 TemplateURL* t_url = CreateTemplateURL("http://" + host + "/path", |
256 L"unittest"); | 257 "unittest"); |
257 util_.model()->Add(t_url); | 258 util_.model()->Add(t_url); |
258 | 259 |
259 // Set a managed preference that establishes a default search provider. | 260 // Set a managed preference that establishes a default search provider. |
260 std::string host2 = "www.managedtest.com"; | 261 std::string host2 = "www.managedtest.com"; |
261 std::string url2 = "http://" + host2 + "/p{searchTerms}"; | 262 std::string url2 = "http://" + host2 + "/p{searchTerms}"; |
262 SimulateDefaultSearchIsManaged(url2); | 263 SimulateDefaultSearchIsManaged(url2); |
263 EXPECT_TRUE(util_.model()->is_default_search_managed()); | 264 EXPECT_TRUE(util_.model()->is_default_search_managed()); |
264 | 265 |
265 // Wait for the changes to be saved. | 266 // Wait for the changes to be saved. |
266 util_.BlockTillServiceProcessesRequests(); | 267 util_.BlockTillServiceProcessesRequests(); |
(...skipping 13 matching lines...) Expand all Loading... |
280 new TestGetInstallState(install_data_)); | 281 new TestGetInstallState(install_data_)); |
281 | 282 |
282 // Set up the database. | 283 // Set up the database. |
283 util_.ChangeModelToLoadState(); | 284 util_.ChangeModelToLoadState(); |
284 std::string google_host = "w.com"; | 285 std::string google_host = "w.com"; |
285 util_.SetGoogleBaseURL("http://" + google_host + "/"); | 286 util_.SetGoogleBaseURL("http://" + google_host + "/"); |
286 // Wait for the I/O thread to process the update notification. | 287 // Wait for the I/O thread to process the update notification. |
287 TemplateURLModelTestUtil::BlockTillIOThreadProcessesRequests(); | 288 TemplateURLModelTestUtil::BlockTillIOThreadProcessesRequests(); |
288 | 289 |
289 TemplateURL* t_url = CreateTemplateURL("{google:baseURL}?q={searchTerms}", | 290 TemplateURL* t_url = CreateTemplateURL("{google:baseURL}?q={searchTerms}", |
290 L"t"); | 291 "t"); |
291 util_.model()->Add(t_url); | 292 util_.model()->Add(t_url); |
292 TemplateURL* default_url = CreateTemplateURL("http://d.com/", | 293 TemplateURL* default_url = CreateTemplateURL("http://d.com/", |
293 L"d"); | 294 "d"); |
294 util_.model()->Add(default_url); | 295 util_.model()->Add(default_url); |
295 util_.model()->SetDefaultSearchProvider(default_url); | 296 util_.model()->SetDefaultSearchProvider(default_url); |
296 | 297 |
297 // Wait for the changes to be saved. | 298 // Wait for the changes to be saved. |
298 TemplateURLModelTestUtil::BlockTillServiceProcessesRequests(); | 299 TemplateURLModelTestUtil::BlockTillServiceProcessesRequests(); |
299 | 300 |
300 // Verify the search providers install state (with no default set). | 301 // Verify the search providers install state (with no default set). |
301 test_get_install_state->set_search_provider_host(google_host); | 302 test_get_install_state->set_search_provider_host(google_host); |
302 EXPECT_TRUE(test_get_install_state->RunTests()); | 303 EXPECT_TRUE(test_get_install_state->RunTests()); |
303 | 304 |
304 // Change the Google base url. | 305 // Change the Google base url. |
305 google_host = "foo.com"; | 306 google_host = "foo.com"; |
306 util_.SetGoogleBaseURL("http://" + google_host + "/"); | 307 util_.SetGoogleBaseURL("http://" + google_host + "/"); |
307 // Wait for the I/O thread to process the update notification. | 308 // Wait for the I/O thread to process the update notification. |
308 TemplateURLModelTestUtil::BlockTillIOThreadProcessesRequests(); | 309 TemplateURLModelTestUtil::BlockTillIOThreadProcessesRequests(); |
309 | 310 |
310 // Verify that the change got picked up. | 311 // Verify that the change got picked up. |
311 test_get_install_state->set_search_provider_host(google_host); | 312 test_get_install_state->set_search_provider_host(google_host); |
312 EXPECT_TRUE(test_get_install_state->RunTests()); | 313 EXPECT_TRUE(test_get_install_state->RunTests()); |
313 } | 314 } |
OLD | NEW |