| OLD | NEW |
| 1 // Copyright (c) 2011 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/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/task.h" | 10 #include "base/task.h" |
| 11 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
| 12 #include "chrome/browser/search_engines/search_provider_install_data.h" | 12 #include "chrome/browser/search_engines/search_provider_install_data.h" |
| 13 #include "chrome/browser/search_engines/template_url.h" | 13 #include "chrome/browser/search_engines/template_url.h" |
| 14 #include "chrome/browser/search_engines/template_url_service.h" | 14 #include "chrome/browser/search_engines/template_url_service.h" |
| 15 #include "chrome/browser/search_engines/template_url_service_test_util.h" | 15 #include "chrome/browser/search_engines/template_url_service_test_util.h" |
| 16 #include "chrome/common/chrome_notification_types.h" |
| 16 #include "chrome/common/pref_names.h" | 17 #include "chrome/common/pref_names.h" |
| 17 #include "chrome/test/testing_pref_service.h" | 18 #include "chrome/test/testing_pref_service.h" |
| 18 #include "chrome/test/testing_profile.h" | 19 #include "chrome/test/testing_profile.h" |
| 19 #include "content/browser/browser_thread.h" | 20 #include "content/browser/browser_thread.h" |
| 20 #include "content/common/notification_service.h" | 21 #include "content/common/notification_service.h" |
| 21 #include "content/common/notification_source.h" | 22 #include "content/common/notification_source.h" |
| 22 #include "content/common/notification_type.h" | |
| 23 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
| 24 | 24 |
| 25 // Create a TemplateURL. The caller owns the returned TemplateURL*. | 25 // Create a TemplateURL. The caller owns the returned TemplateURL*. |
| 26 static TemplateURL* CreateTemplateURL(const std::string& url, | 26 static TemplateURL* CreateTemplateURL(const std::string& url, |
| 27 const std::string& keyword) { | 27 const std::string& keyword) { |
| 28 TemplateURL* t_url = new TemplateURL(); | 28 TemplateURL* t_url = new TemplateURL(); |
| 29 t_url->SetURL(url, 0, 0); | 29 t_url->SetURL(url, 0, 0); |
| 30 t_url->set_keyword(UTF8ToUTF16(keyword)); | 30 t_url->set_keyword(UTF8ToUTF16(keyword)); |
| 31 t_url->set_short_name(UTF8ToUTF16(keyword)); | 31 t_url->set_short_name(UTF8ToUTF16(keyword)); |
| 32 return t_url; | 32 return t_url; |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 public: | 160 public: |
| 161 SearchProviderInstallDataTest() | 161 SearchProviderInstallDataTest() |
| 162 : install_data_(NULL) {} | 162 : install_data_(NULL) {} |
| 163 | 163 |
| 164 virtual void SetUp() { | 164 virtual void SetUp() { |
| 165 testing::Test::SetUp(); | 165 testing::Test::SetUp(); |
| 166 util_.SetUp(); | 166 util_.SetUp(); |
| 167 util_.StartIOThread(); | 167 util_.StartIOThread(); |
| 168 install_data_ = new SearchProviderInstallData( | 168 install_data_ = new SearchProviderInstallData( |
| 169 util_.GetWebDataService(), | 169 util_.GetWebDataService(), |
| 170 NotificationType::RENDERER_PROCESS_TERMINATED, | 170 content::NOTIFICATION_RENDERER_PROCESS_TERMINATED, |
| 171 Source<SearchProviderInstallDataTest>(this)); | 171 Source<SearchProviderInstallDataTest>(this)); |
| 172 } | 172 } |
| 173 | 173 |
| 174 virtual void TearDown() { | 174 virtual void TearDown() { |
| 175 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)->PostTask( | 175 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)->PostTask( |
| 176 FROM_HERE, | 176 FROM_HERE, |
| 177 new DeleteTask<SearchProviderInstallData>(install_data_)); | 177 new DeleteTask<SearchProviderInstallData>(install_data_)); |
| 178 install_data_ = NULL; | 178 install_data_ = NULL; |
| 179 | 179 |
| 180 // Make sure that the install data class on the UI thread gets cleaned up. | 180 // Make sure that the install data class on the UI thread gets cleaned up. |
| 181 // It doesn't matter that this happens after install_data_ is deleted. | 181 // It doesn't matter that this happens after install_data_ is deleted. |
| 182 NotificationService::current()->Notify( | 182 NotificationService::current()->Notify( |
| 183 NotificationType::RENDERER_PROCESS_TERMINATED, | 183 content::NOTIFICATION_RENDERER_PROCESS_TERMINATED, |
| 184 Source<SearchProviderInstallDataTest>(this), | 184 Source<SearchProviderInstallDataTest>(this), |
| 185 NotificationService::NoDetails()); | 185 NotificationService::NoDetails()); |
| 186 | 186 |
| 187 util_.TearDown(); | 187 util_.TearDown(); |
| 188 testing::Test::TearDown(); | 188 testing::Test::TearDown(); |
| 189 } | 189 } |
| 190 | 190 |
| 191 void SimulateDefaultSearchIsManaged(const std::string& url) { | 191 void SimulateDefaultSearchIsManaged(const std::string& url) { |
| 192 ASSERT_FALSE(url.empty()); | 192 ASSERT_FALSE(url.empty()); |
| 193 TestingPrefService* service = util_.profile()->GetTestingPrefService(); | 193 TestingPrefService* service = util_.profile()->GetTestingPrefService(); |
| 194 service->SetManagedPref( | 194 service->SetManagedPref( |
| 195 prefs::kDefaultSearchProviderEnabled, | 195 prefs::kDefaultSearchProviderEnabled, |
| 196 Value::CreateBooleanValue(true)); | 196 Value::CreateBooleanValue(true)); |
| 197 service->SetManagedPref( | 197 service->SetManagedPref( |
| 198 prefs::kDefaultSearchProviderSearchURL, | 198 prefs::kDefaultSearchProviderSearchURL, |
| 199 Value::CreateStringValue(url)); | 199 Value::CreateStringValue(url)); |
| 200 service->SetManagedPref( | 200 service->SetManagedPref( |
| 201 prefs::kDefaultSearchProviderName, | 201 prefs::kDefaultSearchProviderName, |
| 202 Value::CreateStringValue("managed")); | 202 Value::CreateStringValue("managed")); |
| 203 // Clear the IDs that are not specified via policy. | 203 // Clear the IDs that are not specified via policy. |
| 204 service->SetManagedPref( | 204 service->SetManagedPref( |
| 205 prefs::kDefaultSearchProviderID, new StringValue("")); | 205 prefs::kDefaultSearchProviderID, new StringValue("")); |
| 206 service->SetManagedPref( | 206 service->SetManagedPref( |
| 207 prefs::kDefaultSearchProviderPrepopulateID, new StringValue("")); | 207 prefs::kDefaultSearchProviderPrepopulateID, new StringValue("")); |
| 208 util_.model()->Observe( | 208 util_.model()->Observe( |
| 209 NotificationType::PREF_CHANGED, | 209 chrome::NOTIFICATION_PREF_CHANGED, |
| 210 Source<PrefService>(util_.profile()->GetTestingPrefService()), | 210 Source<PrefService>(util_.profile()->GetTestingPrefService()), |
| 211 Details<std::string>(NULL)); | 211 Details<std::string>(NULL)); |
| 212 } | 212 } |
| 213 | 213 |
| 214 protected: | 214 protected: |
| 215 TemplateURLServiceTestUtil util_; | 215 TemplateURLServiceTestUtil util_; |
| 216 | 216 |
| 217 // Provides the search provider install state on the I/O thread. It must be | 217 // Provides the search provider install state on the I/O thread. It must be |
| 218 // deleted on the I/O thread, which is why it isn't a scoped_ptr. | 218 // deleted on the I/O thread, which is why it isn't a scoped_ptr. |
| 219 SearchProviderInstallData* install_data_; | 219 SearchProviderInstallData* install_data_; |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 305 // Change the Google base url. | 305 // Change the Google base url. |
| 306 google_host = "foo.com"; | 306 google_host = "foo.com"; |
| 307 util_.SetGoogleBaseURL("http://" + google_host + "/"); | 307 util_.SetGoogleBaseURL("http://" + google_host + "/"); |
| 308 // Wait for the I/O thread to process the update notification. | 308 // Wait for the I/O thread to process the update notification. |
| 309 TemplateURLServiceTestUtil::BlockTillIOThreadProcessesRequests(); | 309 TemplateURLServiceTestUtil::BlockTillIOThreadProcessesRequests(); |
| 310 | 310 |
| 311 // Verify that the change got picked up. | 311 // Verify that the change got picked up. |
| 312 test_get_install_state->set_search_provider_host(google_host); | 312 test_get_install_state->set_search_provider_host(google_host); |
| 313 EXPECT_TRUE(test_get_install_state->RunTests()); | 313 EXPECT_TRUE(test_get_install_state->RunTests()); |
| 314 } | 314 } |
| OLD | NEW |