Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(226)

Unified Diff: chrome/browser/search_engines/template_url_service_test_util.cc

Issue 17127002: Correctly integrate StoragePartition into TestingProfile. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address comments. merge to ToT. Murder a DB thread and more TestBrowserThreads. Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 34894ab0a29a0a1a8db1f1caeb924ae446976c0b..896cb94b0af64164ef6b45a9f9bc847034ffaeb1 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/google/google_url_tracker.h"
#include "chrome/browser/search_engines/search_terms_data.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();
-}

Powered by Google App Engine
This is Rietveld 408576698