| 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 756fe072922acf569ea66d5a2913db7cc2a2d3d9..068e46a396537c3784f55831731d3c0a8f88563a 100644
|
| --- a/chrome/browser/search_engines/template_url_service_test_util.cc
|
| +++ b/chrome/browser/search_engines/template_url_service_test_util.cc
|
| @@ -5,7 +5,6 @@
|
| #include "chrome/browser/search_engines/template_url_service_test_util.h"
|
|
|
| #include "base/bind.h"
|
| -#include "base/files/scoped_temp_dir.h"
|
| #include "base/message_loop.h"
|
| #include "base/path_service.h"
|
| #include "base/synchronization/waitable_event.h"
|
| @@ -15,6 +14,7 @@
|
| #include "chrome/browser/search_engines/template_url_service.h"
|
| #include "chrome/browser/search_engines/template_url_service_factory.h"
|
| #include "chrome/browser/webdata/web_data_service_factory.h"
|
| +#include "chrome/common/chrome_constants.h"
|
| #include "chrome/common/chrome_notification_types.h"
|
| #include "chrome/common/pref_names.h"
|
| #include "chrome/test/automation/value_conversion_util.h"
|
| @@ -53,35 +53,6 @@ static void WaitForThreadToProcessRequests(BrowserThread::ID identifier) {
|
|
|
| } // namespace
|
|
|
| -// Subclass the TestingProfile so that it can return a WebDataService.
|
| -class TemplateURLServiceTestingProfile : public TestingProfile {
|
| - public:
|
| - TemplateURLServiceTestingProfile()
|
| - : TestingProfile(),
|
| - db_thread_(BrowserThread::DB),
|
| - io_thread_(BrowserThread::IO) {
|
| - }
|
| -
|
| - void SetUp();
|
| - void TearDown();
|
| -
|
| - // Starts the I/O thread. This isn't done automatically because not every test
|
| - // needs this.
|
| - void StartIOThread() {
|
| - io_thread_.StartIOThread();
|
| - }
|
| -
|
| - static scoped_refptr<RefcountedProfileKeyedService>
|
| - GetWebDataServiceForTemplateURLServiceTestingProfile(Profile* profile);
|
| -
|
| - private:
|
| - scoped_refptr<WebDataService> service_;
|
| - base::ScopedTempDir temp_dir_;
|
| - content::TestBrowserThread db_thread_;
|
| - content::TestBrowserThread io_thread_;
|
| -};
|
| -
|
| -
|
| // Trivial subclass of TemplateURLService that records the last invocation of
|
| // SetKeywordSearchTermsForURL.
|
| class TestingTemplateURLService : public TemplateURLService {
|
| @@ -113,57 +84,10 @@ class TestingTemplateURLService : public TemplateURLService {
|
| DISALLOW_COPY_AND_ASSIGN(TestingTemplateURLService);
|
| };
|
|
|
| -void TemplateURLServiceTestingProfile::SetUp() {
|
| - db_thread_.Start();
|
| -
|
| - // Make unique temp directory.
|
| - ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
|
| -
|
| - base::FilePath path = temp_dir_.path().AppendASCII("TestDataService.db");
|
| - service_ = new WebDataService;
|
| - service_->Init(path);
|
| -}
|
| -
|
| -void TemplateURLServiceTestingProfile::TearDown() {
|
| - // Clear the request context so it will get deleted. This should be done
|
| - // before shutting down the I/O thread to avoid memory leaks.
|
| - ResetRequestContext();
|
| -
|
| - // 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();
|
| -
|
| - // Clean up the test directory.
|
| - if (service_.get()) {
|
| - service_->ShutdownOnUIThread();
|
| - service_ = NULL;
|
| - }
|
| - // 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();
|
| - db_thread_.Stop();
|
| -}
|
| -
|
| -scoped_refptr<RefcountedProfileKeyedService>
|
| -TemplateURLServiceTestingProfile::
|
| - GetWebDataServiceForTemplateURLServiceTestingProfile(Profile* profile) {
|
| - TemplateURLServiceTestingProfile* test_profile =
|
| - reinterpret_cast<TemplateURLServiceTestingProfile*>(profile);
|
| - return test_profile->service_;
|
| -}
|
| -
|
| TemplateURLServiceTestUtil::TemplateURLServiceTestUtil()
|
| : ui_thread_(BrowserThread::UI, &message_loop_),
|
| + db_thread_(BrowserThread::DB),
|
| + io_thread_(BrowserThread::IO),
|
| changed_count_(0) {
|
| }
|
|
|
| @@ -171,12 +95,13 @@ TemplateURLServiceTestUtil::~TemplateURLServiceTestUtil() {
|
| }
|
|
|
| void TemplateURLServiceTestUtil::SetUp() {
|
| - profile_.reset(new TemplateURLServiceTestingProfile());
|
| - WebDataServiceFactory::GetInstance()->SetTestingFactory(
|
| - profile_.get(), TemplateURLServiceTestingProfile::
|
| - GetWebDataServiceForTemplateURLServiceTestingProfile);
|
| + ASSERT_TRUE(db_thread_.Start());
|
| + // Make unique temp directory.
|
| + ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
|
| +
|
| + profile_.reset(new TestingProfile(temp_dir_.path()));
|
| + profile_->CreateWebDataService();
|
|
|
| - profile_->SetUp();
|
| TemplateURLService* service = static_cast<TemplateURLService*>(
|
| TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse(
|
| profile_.get(), TestingTemplateURLService::Build));
|
| @@ -188,10 +113,25 @@ void TemplateURLServiceTestUtil::SetUp() {
|
| }
|
|
|
| void TemplateURLServiceTestUtil::TearDown() {
|
| + // 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();
|
| +
|
| + // 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();
|
| +
|
| if (profile_.get()) {
|
| - profile_->TearDown();
|
| profile_.reset();
|
| }
|
| + base::WaitableEvent done(false, false);
|
| + BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
|
| + base::Bind(&base::WaitableEvent::Signal, base::Unretained(&done)));
|
| + done.Wait();
|
| + db_thread_.Stop();
|
| UIThreadSearchTermsData::SetGoogleBaseURL(std::string());
|
|
|
| // Flush the message loop to make application verifiers happy.
|
| @@ -230,9 +170,8 @@ void TemplateURLServiceTestUtil::ChangeModelToLoadState() {
|
| model()->ChangeToLoadedState();
|
| // Initialize the web data service so that the database gets updated with
|
| // any changes made.
|
| -
|
| - model()->service_ = WebDataServiceFactory::GetForProfile(
|
| - profile_.get(), Profile::EXPLICIT_ACCESS);
|
| + model()->service_ = WebDataService::FromBrowserContext(profile_.get());
|
| + BlockTillServiceProcessesRequests();
|
| }
|
|
|
| void TemplateURLServiceTestUtil::ClearModel() {
|
| @@ -330,7 +269,7 @@ TestingProfile* TemplateURLServiceTestUtil::profile() const {
|
| }
|
|
|
| void TemplateURLServiceTestUtil::StartIOThread() {
|
| - profile_->StartIOThread();
|
| + io_thread_.StartIOThread();
|
| }
|
|
|
| void TemplateURLServiceTestUtil::PumpLoop() {
|
|
|