| 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/bind.h" |
| 8 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 9 #include "base/message_loop.h" | 10 #include "base/message_loop.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/chrome_notification_types.h" |
| 17 #include "chrome/common/pref_names.h" | 17 #include "chrome/common/pref_names.h" |
| 18 #include "chrome/test/base/testing_pref_service.h" | 18 #include "chrome/test/base/testing_pref_service.h" |
| 19 #include "chrome/test/base/testing_profile.h" | 19 #include "chrome/test/base/testing_profile.h" |
| 20 #include "content/public/browser/notification_service.h" | 20 #include "content/public/browser/notification_service.h" |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 DISALLOW_COPY_AND_ASSIGN(TestGetInstallState); | 87 DISALLOW_COPY_AND_ASSIGN(TestGetInstallState); |
| 88 }; | 88 }; |
| 89 | 89 |
| 90 bool TestGetInstallState::RunTests() { | 90 bool TestGetInstallState::RunTests() { |
| 91 passed_ = true; | 91 passed_ = true; |
| 92 | 92 |
| 93 main_loop_ = MessageLoop::current(); | 93 main_loop_ = MessageLoop::current(); |
| 94 | 94 |
| 95 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)->PostTask( | 95 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)->PostTask( |
| 96 FROM_HERE, | 96 FROM_HERE, |
| 97 NewRunnableMethod(this, &TestGetInstallState::StartTestOnIOThread)); | 97 base::Bind(&TestGetInstallState::StartTestOnIOThread, this)); |
| 98 // Run the current message loop. When the test is finished on the I/O thread, | 98 // Run the current message loop. When the test is finished on the I/O thread, |
| 99 // it invokes Quit, which unblocks this. | 99 // it invokes Quit, which unblocks this. |
| 100 MessageLoop::current()->Run(); | 100 MessageLoop::current()->Run(); |
| 101 main_loop_ = NULL; | 101 main_loop_ = NULL; |
| 102 | 102 |
| 103 // Let the testing code know what the result is. | 103 // Let the testing code know what the result is. |
| 104 return passed_; | 104 return passed_; |
| 105 } | 105 } |
| 106 | 106 |
| 107 TestGetInstallState::~TestGetInstallState() { | 107 TestGetInstallState::~TestGetInstallState() { |
| 108 } | 108 } |
| 109 | 109 |
| 110 void TestGetInstallState::StartTestOnIOThread() { | 110 void TestGetInstallState::StartTestOnIOThread() { |
| 111 install_data_->CallWhenLoaded( | 111 install_data_->CallWhenLoaded( |
| 112 NewRunnableMethod(this, | 112 base::Bind(&TestGetInstallState::DoInstallStateTests, this)); |
| 113 &TestGetInstallState::DoInstallStateTests)); | |
| 114 } | 113 } |
| 115 | 114 |
| 116 void TestGetInstallState::DoInstallStateTests() { | 115 void TestGetInstallState::DoInstallStateTests() { |
| 117 // Installed but not default. | 116 // Installed but not default. |
| 118 VerifyInstallState(SearchProviderInstallData::INSTALLED_BUT_NOT_DEFAULT, | 117 VerifyInstallState(SearchProviderInstallData::INSTALLED_BUT_NOT_DEFAULT, |
| 119 "http://" + search_provider_host_ + "/"); | 118 "http://" + search_provider_host_ + "/"); |
| 120 VerifyInstallState(SearchProviderInstallData::INSTALLED_BUT_NOT_DEFAULT, | 119 VerifyInstallState(SearchProviderInstallData::INSTALLED_BUT_NOT_DEFAULT, |
| 121 "http://" + search_provider_host_ + ":80/"); | 120 "http://" + search_provider_host_ + ":80/"); |
| 122 | 121 |
| 123 // Not installed. | 122 // Not installed. |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 307 // Change the Google base url. | 306 // Change the Google base url. |
| 308 google_host = "foo.com"; | 307 google_host = "foo.com"; |
| 309 util_.SetGoogleBaseURL("http://" + google_host + "/"); | 308 util_.SetGoogleBaseURL("http://" + google_host + "/"); |
| 310 // Wait for the I/O thread to process the update notification. | 309 // Wait for the I/O thread to process the update notification. |
| 311 TemplateURLServiceTestUtil::BlockTillIOThreadProcessesRequests(); | 310 TemplateURLServiceTestUtil::BlockTillIOThreadProcessesRequests(); |
| 312 | 311 |
| 313 // Verify that the change got picked up. | 312 // Verify that the change got picked up. |
| 314 test_get_install_state->set_search_provider_host(google_host); | 313 test_get_install_state->set_search_provider_host(google_host); |
| 315 EXPECT_TRUE(test_get_install_state->RunTests()); | 314 EXPECT_TRUE(test_get_install_state->RunTests()); |
| 316 } | 315 } |
| OLD | NEW |