Commit d332658f authored by Scott Violet's avatar Scott Violet Committed by Commit Bot

views: fix leaks in views_mus_unittests

views_mus_unittests was calling mojo::core::Init() multiple times, which
leaks. The fix is to move the Init() call to the TestSuite as well as
setting up the ipc thread.

BUG=888533
TEST=test only changes

Change-Id: I852ca0ab4736aa7a4a18d3c650fa6122b320eb9d
Reviewed-on: https://chromium-review.googlesource.com/1249810Reviewed-by: default avatarKen Rockot <rockot@chromium.org>
Commit-Queue: Scott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#594847}
parent 18f09917
...@@ -14,7 +14,6 @@ ...@@ -14,7 +14,6 @@
#include "base/run_loop.h" #include "base/run_loop.h"
#include "base/synchronization/waitable_event.h" #include "base/synchronization/waitable_event.h"
#include "base/threading/simple_thread.h" #include "base/threading/simple_thread.h"
#include "base/threading/thread.h"
#include "mojo/core/embedder/embedder.h" #include "mojo/core/embedder/embedder.h"
#include "mojo/core/embedder/scoped_ipc_support.h" #include "mojo/core/embedder/scoped_ipc_support.h"
#include "services/catalog/catalog.h" #include "services/catalog/catalog.h"
...@@ -68,24 +67,18 @@ class DefaultService : public service_manager::Service { ...@@ -68,24 +67,18 @@ class DefaultService : public service_manager::Service {
class ServiceManagerConnection { class ServiceManagerConnection {
public: public:
ServiceManagerConnection() ServiceManagerConnection()
: thread_("Persistent service_manager connections"), : thread_("Persistent service_manager connections") {
ipc_thread_("IPC thread") {
catalog::Catalog::LoadDefaultCatalogManifest( catalog::Catalog::LoadDefaultCatalogManifest(
base::FilePath(kCatalogFilename)); base::FilePath(kCatalogFilename));
mojo::core::Init();
ipc_thread_.StartWithOptions(
base::Thread::Options(base::MessageLoop::TYPE_IO, 0));
ipc_support_ = std::make_unique<mojo::core::ScopedIPCSupport>(
ipc_thread_.task_runner(),
mojo::core::ScopedIPCSupport::ShutdownPolicy::CLEAN);
base::WaitableEvent wait(base::WaitableEvent::ResetPolicy::AUTOMATIC, base::WaitableEvent wait(base::WaitableEvent::ResetPolicy::AUTOMATIC,
base::WaitableEvent::InitialState::NOT_SIGNALED); base::WaitableEvent::InitialState::NOT_SIGNALED);
base::Thread::Options options; base::Thread::Options options;
thread_.StartWithOptions(options); thread_.StartWithOptions(options);
thread_.task_runner()->PostTask( thread_.task_runner()->PostTask(
FROM_HERE, base::BindOnce(&ServiceManagerConnection::SetUpConnections, FROM_HERE,
base::Unretained(this), &wait)); base::BindOnce(
&ServiceManagerConnection::SetUpConnectionsOnBackgroundThread,
base::Unretained(this), &wait));
wait.Wait(); wait.Wait();
} }
...@@ -94,8 +87,9 @@ class ServiceManagerConnection { ...@@ -94,8 +87,9 @@ class ServiceManagerConnection {
base::WaitableEvent::InitialState::NOT_SIGNALED); base::WaitableEvent::InitialState::NOT_SIGNALED);
thread_.task_runner()->PostTask( thread_.task_runner()->PostTask(
FROM_HERE, FROM_HERE,
base::BindOnce(&ServiceManagerConnection::TearDownConnections, base::BindOnce(
base::Unretained(this), &wait)); &ServiceManagerConnection::TearDownConnectionsOnBackgroundThread,
base::Unretained(this), &wait));
wait.Wait(); wait.Wait();
} }
...@@ -124,7 +118,7 @@ class ServiceManagerConnection { ...@@ -124,7 +118,7 @@ class ServiceManagerConnection {
wait->Signal(); wait->Signal();
} }
void SetUpConnections(base::WaitableEvent* wait) { void SetUpConnectionsOnBackgroundThread(base::WaitableEvent* wait) {
background_service_manager_ = background_service_manager_ =
std::make_unique<service_manager::BackgroundServiceManager>(nullptr, std::make_unique<service_manager::BackgroundServiceManager>(nullptr,
nullptr); nullptr);
...@@ -140,8 +134,9 @@ class ServiceManagerConnection { ...@@ -140,8 +134,9 @@ class ServiceManagerConnection {
wait->Signal(); wait->Signal();
} }
void TearDownConnections(base::WaitableEvent* wait) { void TearDownConnectionsOnBackgroundThread(base::WaitableEvent* wait) {
context_.reset(); context_.reset();
background_service_manager_.reset();
wait->Signal(); wait->Signal();
} }
...@@ -155,8 +150,6 @@ class ServiceManagerConnection { ...@@ -155,8 +150,6 @@ class ServiceManagerConnection {
} }
base::Thread thread_; base::Thread thread_;
base::Thread ipc_thread_;
std::unique_ptr<mojo::core::ScopedIPCSupport> ipc_support_;
std::unique_ptr<service_manager::BackgroundServiceManager> std::unique_ptr<service_manager::BackgroundServiceManager>
background_service_manager_; background_service_manager_;
std::unique_ptr<service_manager::ServiceContext> context_; std::unique_ptr<service_manager::ServiceContext> context_;
...@@ -226,7 +219,7 @@ std::unique_ptr<PlatformTestHelper> CreatePlatformTestHelper() { ...@@ -226,7 +219,7 @@ std::unique_ptr<PlatformTestHelper> CreatePlatformTestHelper() {
} // namespace } // namespace
ViewsMusTestSuite::ViewsMusTestSuite(int argc, char** argv) ViewsMusTestSuite::ViewsMusTestSuite(int argc, char** argv)
: ViewsTestSuite(argc, argv) {} : ViewsTestSuite(argc, argv), ipc_thread_("IPC thread") {}
ViewsMusTestSuite::~ViewsMusTestSuite() {} ViewsMusTestSuite::~ViewsMusTestSuite() {}
...@@ -248,6 +241,13 @@ void ViewsMusTestSuite::Initialize() { ...@@ -248,6 +241,13 @@ void ViewsMusTestSuite::Initialize() {
switches::kEnableFeatures, features::kMash.name); switches::kEnableFeatures, features::kMash.name);
PlatformTestHelper::set_factory(base::Bind(&CreatePlatformTestHelper)); PlatformTestHelper::set_factory(base::Bind(&CreatePlatformTestHelper));
mojo::core::Init();
ipc_thread_.StartWithOptions(
base::Thread::Options(base::MessageLoop::TYPE_IO, 0));
ipc_support_ = std::make_unique<mojo::core::ScopedIPCSupport>(
ipc_thread_.task_runner(),
mojo::core::ScopedIPCSupport::ShutdownPolicy::CLEAN);
} }
void ViewsMusTestSuite::InitializeEnv() { void ViewsMusTestSuite::InitializeEnv() {
......
...@@ -9,8 +9,15 @@ ...@@ -9,8 +9,15 @@
#include "base/macros.h" #include "base/macros.h"
#include "base/test/scoped_feature_list.h" #include "base/test/scoped_feature_list.h"
#include "base/threading/thread.h"
#include "ui/views/views_test_suite.h" #include "ui/views/views_test_suite.h"
namespace mojo {
namespace core {
class ScopedIPCSupport;
}
} // namespace mojo
namespace views { namespace views {
class ViewsMusTestSuite : public ViewsTestSuite { class ViewsMusTestSuite : public ViewsTestSuite {
...@@ -24,6 +31,9 @@ class ViewsMusTestSuite : public ViewsTestSuite { ...@@ -24,6 +31,9 @@ class ViewsMusTestSuite : public ViewsTestSuite {
void InitializeEnv() override; void InitializeEnv() override;
void DestroyEnv() override; void DestroyEnv() override;
base::Thread ipc_thread_;
std::unique_ptr<mojo::core::ScopedIPCSupport> ipc_support_;
base::test::ScopedFeatureList feature_list_; base::test::ScopedFeatureList feature_list_;
std::unique_ptr<aura::Env> env_; std::unique_ptr<aura::Env> env_;
......
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