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

Unified Diff: chrome/test/base/mojo_test_connector.cc

Issue 2858103002: Have mash_browser_tests recreate BackgroundServiceManager per test (Closed)
Patch Set: Disable broken tests Created 3 years, 7 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/test/base/mojo_test_connector.cc
diff --git a/chrome/test/base/mojo_test_connector.cc b/chrome/test/base/mojo_test_connector.cc
index fc2d968bdd26139e32fb7585fda040f4e77b62ed..e7837f78bebdaca2a614e6633b9bdf14c75c24b4 100644
--- a/chrome/test/base/mojo_test_connector.cc
+++ b/chrome/test/base/mojo_test_connector.cc
@@ -18,6 +18,7 @@
#include "content/public/common/content_switches.h"
#include "content/public/common/service_names.mojom.h"
#include "content/public/test/test_launcher.h"
+#include "mash/session/public/interfaces/constants.mojom.h"
#include "mojo/edk/embedder/embedder.h"
#include "mojo/edk/embedder/outgoing_broker_client_invitation.h"
#include "mojo/edk/embedder/platform_channel_pair.h"
@@ -43,13 +44,12 @@ const char kMusTestRunnerName[] = "mus_browser_tests";
// service manager.
class MojoTestState : public content::TestState {
public:
- explicit MojoTestState(
- service_manager::BackgroundServiceManager* background_service_manager,
- base::CommandLine* command_line,
- base::TestLauncher::LaunchOptions* test_launch_options,
- const std::string& mus_config_switch,
- base::OnceClosure on_process_launched)
- : background_service_manager_(background_service_manager),
+ MojoTestState(MojoTestConnector* connector,
+ base::CommandLine* command_line,
+ base::TestLauncher::LaunchOptions* test_launch_options,
+ const std::string& mus_config_switch,
+ base::OnceClosure on_process_launched)
+ : connector_(connector),
platform_channel_(base::MakeUnique<mojo::edk::PlatformChannelPair>()),
main_task_runner_(base::ThreadTaskRunnerHandle::Get()),
on_process_launched_(std::move(on_process_launched)),
@@ -98,7 +98,10 @@ class MojoTestState : public content::TestState {
// after ChildProcessLaunched as previous test runs will tear down existing
// connections.
void SetupService(base::ProcessId pid) {
- background_service_manager_->RegisterService(
+ connector_->InitBackgroundServiceManager();
+ service_manager::BackgroundServiceManager* background_service_manager =
+ connector_->background_service_manager();
+ background_service_manager->RegisterService(
service_manager::Identity(content::mojom::kPackagedServicesServiceName,
service_manager::mojom::kRootUserID),
std::move(service_),
@@ -112,7 +115,7 @@ class MojoTestState : public content::TestState {
}
mojo::edk::OutgoingBrokerClientInvitation broker_client_invitation_;
- service_manager::BackgroundServiceManager* const background_service_manager_;
+ MojoTestConnector* connector_;
// The ServicePtr must be created before child process launch so that the pipe
// can be set on the command line. It is held until SetupService is called at
@@ -200,7 +203,7 @@ MojoTestConnector::MojoTestConnector(
background_service_manager_(nullptr),
catalog_contents_(std::move(catalog_contents)) {}
-service_manager::mojom::ServiceRequest MojoTestConnector::Init() {
+void MojoTestConnector::Init() {
// In single-process test mode, browser code will initialize the EDK and IPC.
// Otherwise we ensure it's initialized here.
if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
@@ -213,7 +216,10 @@ service_manager::mojom::ServiceRequest MojoTestConnector::Init() {
ipc_thread_->task_runner(),
mojo::edk::ScopedIPCSupport::ShutdownPolicy::FAST);
}
+}
+service_manager::mojom::ServiceRequest
+MojoTestConnector::InitBackgroundServiceManager() {
service_manager::mojom::ServicePtr service;
service_manager::mojom::ServiceRequest request(&service);
@@ -223,7 +229,7 @@ service_manager::mojom::ServiceRequest MojoTestConnector::Init() {
background_service_manager_ =
base::MakeUnique<service_manager::BackgroundServiceManager>(
service_process_launcher_delegate_.get(),
- std::move(catalog_contents_));
+ catalog_contents_->CreateDeepCopy());
background_service_manager_->RegisterService(
service_manager::Identity(config_ == MojoTestConnector::Config::MASH
? kMashTestRunnerName
@@ -240,7 +246,7 @@ std::unique_ptr<content::TestState> MojoTestConnector::PrepareForTest(
base::TestLauncher::LaunchOptions* test_launch_options,
base::OnceClosure on_process_launched) {
return base::MakeUnique<MojoTestState>(
- background_service_manager_.get(), command_line, test_launch_options,
+ this, command_line, test_launch_options,
config_ == MojoTestConnector::Config::MASH ? switches::kMash
: switches::kMus,
std::move(on_process_launched));

Powered by Google App Engine
This is Rietveld 408576698