Commit cf5df561 authored by Greg Thompson's avatar Greg Thompson Committed by Commit Bot

Plug resource leaks in ShortcutsBackendTest.

Explicitly shut down the ShortcutsBackend and HistoryService in TearDown
before cleaning up the ScopedTempDir.

BUG=546640

Change-Id: I961dc49376116550e63a9c353d3d15a436731e93
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1943130
Auto-Submit: Greg Thompson <grt@chromium.org>
Reviewed-by: default avatarKevin Bailey <krb@chromium.org>
Commit-Queue: Greg Thompson <grt@chromium.org>
Cr-Commit-Position: refs/heads/master@{#720359}
parent 0285b089
......@@ -60,8 +60,8 @@ class ShortcutsBackendTest : public testing::Test,
TemplateURLService* GetTemplateURLService();
private:
base::test::TaskEnvironment task_environment_;
base::ScopedTempDir profile_dir_;
base::test::TaskEnvironment task_environment_;
std::unique_ptr<TemplateURLService> template_url_service_;
std::unique_ptr<history::HistoryService> history_service_;
......@@ -107,10 +107,10 @@ void ShortcutsBackendTest::SetSearchProvider() {
}
void ShortcutsBackendTest::SetUp() {
ASSERT_TRUE(profile_dir_.CreateUniqueTempDir());
template_url_service_.reset(new TemplateURLService(nullptr, 0));
if (profile_dir_.CreateUniqueTempDir())
history_service_ =
history::CreateHistoryService(profile_dir_.GetPath(), true);
history_service_ =
history::CreateHistoryService(profile_dir_.GetPath(), true);
ASSERT_TRUE(history_service_);
base::FilePath shortcuts_database_path =
......@@ -124,7 +124,18 @@ void ShortcutsBackendTest::SetUp() {
void ShortcutsBackendTest::TearDown() {
backend_->RemoveObserver(this);
backend_->ShutdownOnUIThread();
backend_.reset();
// Explicitly shut down the history service and wait for its backend to be
// destroyed to prevent resource leaks.
base::RunLoop run_loop;
history_service_->SetOnBackendDestroyTask(run_loop.QuitClosure());
history_service_->Shutdown();
run_loop.Run();
task_environment_.RunUntilIdle();
EXPECT_TRUE(profile_dir_.Delete());
}
void ShortcutsBackendTest::OnShortcutsLoaded() {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment