| Index: chrome/browser/search_engines/template_url_service_test_util.cc
|
| diff --git a/chrome/browser/search_engines/template_url_service_test_util.cc b/chrome/browser/search_engines/template_url_service_test_util.cc
|
| index b5e4a07b76bafb620702ae65d2b10e31274ea66a..b496712e1cd77f2d035788a835765c60dadda91b 100644
|
| --- a/chrome/browser/search_engines/template_url_service_test_util.cc
|
| +++ b/chrome/browser/search_engines/template_url_service_test_util.cc
|
| @@ -5,9 +5,8 @@
|
| #include "chrome/browser/search_engines/template_url_service_test_util.h"
|
|
|
| #include "base/bind.h"
|
| -#include "base/message_loop.h"
|
| #include "base/path_service.h"
|
| -#include "base/synchronization/waitable_event.h"
|
| +#include "base/run_loop.h"
|
| #include "base/threading/thread.h"
|
| #include "chrome/browser/chrome_notification_types.h"
|
| #include "chrome/browser/google/google_url_tracker.h"
|
| @@ -20,40 +19,12 @@
|
| #include "chrome/test/base/testing_pref_service_syncable.h"
|
| #include "chrome/test/base/testing_profile.h"
|
| #include "content/public/browser/notification_service.h"
|
| -#include "content/public/test/test_browser_thread.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
|
|
| -
|
| #if defined(OS_CHROMEOS)
|
| #include "chrome/browser/google/google_util_chromeos.h"
|
| #endif
|
|
|
| -using content::BrowserThread;
|
| -
|
| -namespace {
|
| -
|
| -// A callback used to coordinate when the database has finished processing
|
| -// requests. See note in BlockTillServiceProcessesRequests for details.
|
| -//
|
| -// Schedules a QuitClosure on the message loop it was created with.
|
| -void QuitCallback(base::MessageLoop* message_loop) {
|
| - message_loop->PostTask(FROM_HERE, base::MessageLoop::QuitClosure());
|
| -}
|
| -
|
| -// Blocks the caller until thread has finished servicing all pending
|
| -// requests.
|
| -static void WaitForThreadToProcessRequests(BrowserThread::ID identifier) {
|
| - // Schedule a task on the thread that is processed after all
|
| - // pending requests on the thread.
|
| - BrowserThread::PostTask(
|
| - identifier,
|
| - FROM_HERE,
|
| - base::Bind(&QuitCallback, base::MessageLoop::current()));
|
| - base::MessageLoop::current()->Run();
|
| -}
|
| -
|
| -} // namespace
|
| -
|
| // Trivial subclass of TemplateURLService that records the last invocation of
|
| // SetKeywordSearchTermsForURL.
|
| class TestingTemplateURLService : public TemplateURLService {
|
| @@ -86,9 +57,7 @@ class TestingTemplateURLService : public TemplateURLService {
|
| };
|
|
|
| TemplateURLServiceTestUtil::TemplateURLServiceTestUtil()
|
| - : ui_thread_(BrowserThread::UI, &message_loop_),
|
| - db_thread_(BrowserThread::DB),
|
| - io_thread_(BrowserThread::IO),
|
| + : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP),
|
| changed_count_(0) {
|
| }
|
|
|
| @@ -99,7 +68,6 @@ void TemplateURLServiceTestUtil::SetUp() {
|
| // Make unique temp directory.
|
| ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
|
| profile_.reset(new TestingProfile(temp_dir_.path()));
|
| - db_thread_.Start();
|
| profile_->CreateWebDataService();
|
|
|
| TemplateURLService* service = static_cast<TemplateURLService*>(
|
| @@ -113,39 +81,12 @@ void TemplateURLServiceTestUtil::SetUp() {
|
| }
|
|
|
| void TemplateURLServiceTestUtil::TearDown() {
|
| - if (profile_.get()) {
|
| - // Clear the request context so it will get deleted. This should be done
|
| - // before shutting down the I/O thread to avoid memory leaks.
|
| - profile_->ResetRequestContext();
|
| - profile_.reset();
|
| - }
|
| -
|
| - // Wait for the delete of the request context to happen.
|
| - if (io_thread_.IsRunning())
|
| - TemplateURLServiceTestUtil::BlockTillIOThreadProcessesRequests();
|
| -
|
| - // The I/O thread must be shutdown before the DB thread.
|
| - io_thread_.Stop();
|
| -
|
| - // Note that we must ensure the DB thread is stopped after WDS
|
| - // shutdown (so it can commit pending transactions) but before
|
| - // deleting the test profile directory, otherwise we may not be
|
| - // able to delete it due to an open transaction.
|
| - // Schedule another task on the DB thread to notify us that it's safe to
|
| - // carry on with the test.
|
| - base::WaitableEvent done(false, false);
|
| - BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
|
| - base::Bind(&base::WaitableEvent::Signal, base::Unretained(&done)));
|
| - done.Wait();
|
| - base::MessageLoop::current()->PostTask(FROM_HERE,
|
| - base::MessageLoop::QuitClosure());
|
| - base::MessageLoop::current()->Run();
|
| - db_thread_.Stop();
|
| + profile_.reset();
|
|
|
| UIThreadSearchTermsData::SetGoogleBaseURL(std::string());
|
|
|
| // Flush the message loop to make application verifiers happy.
|
| - message_loop_.RunUntilIdle();
|
| + base::RunLoop().RunUntilIdle();
|
| }
|
|
|
| void TemplateURLServiceTestUtil::OnTemplateURLServiceChanged() {
|
| @@ -160,18 +101,10 @@ void TemplateURLServiceTestUtil::ResetObserverCount() {
|
| changed_count_ = 0;
|
| }
|
|
|
| -void TemplateURLServiceTestUtil::BlockTillServiceProcessesRequests() {
|
| - WaitForThreadToProcessRequests(BrowserThread::DB);
|
| -}
|
| -
|
| -void TemplateURLServiceTestUtil::BlockTillIOThreadProcessesRequests() {
|
| - WaitForThreadToProcessRequests(BrowserThread::IO);
|
| -}
|
| -
|
| void TemplateURLServiceTestUtil::VerifyLoad() {
|
| ASSERT_FALSE(model()->loaded());
|
| model()->Load();
|
| - BlockTillServiceProcessesRequests();
|
| + base::RunLoop().RunUntilIdle();
|
| EXPECT_EQ(1, GetObserverCount());
|
| ResetObserverCount();
|
| }
|
| @@ -182,7 +115,7 @@ void TemplateURLServiceTestUtil::ChangeModelToLoadState() {
|
| // any changes made.
|
|
|
| model()->service_ = WebDataService::FromBrowserContext(profile_.get());
|
| - BlockTillServiceProcessesRequests();
|
| + base::RunLoop().RunUntilIdle();
|
| }
|
|
|
| void TemplateURLServiceTestUtil::ClearModel() {
|
| @@ -278,11 +211,3 @@ TemplateURLService* TemplateURLServiceTestUtil::model() const {
|
| TestingProfile* TemplateURLServiceTestUtil::profile() const {
|
| return profile_.get();
|
| }
|
| -
|
| -void TemplateURLServiceTestUtil::StartIOThread() {
|
| - io_thread_.StartIOThread();
|
| -}
|
| -
|
| -void TemplateURLServiceTestUtil::PumpLoop() {
|
| - message_loop_.RunUntilIdle();
|
| -}
|
|
|