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