| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/test/base/mojo_test_connector.h" | 5 #include "chrome/test/base/mojo_test_connector.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 | 181 |
| 182 // static | 182 // static |
| 183 const char MojoTestConnector::kTestSwitch[] = "is_test"; | 183 const char MojoTestConnector::kTestSwitch[] = "is_test"; |
| 184 // static | 184 // static |
| 185 const char MojoTestConnector::kMashApp[] = "mash-app"; | 185 const char MojoTestConnector::kMashApp[] = "mash-app"; |
| 186 | 186 |
| 187 MojoTestConnector::MojoTestConnector( | 187 MojoTestConnector::MojoTestConnector( |
| 188 std::unique_ptr<base::Value> catalog_contents) | 188 std::unique_ptr<base::Value> catalog_contents) |
| 189 : service_process_launcher_delegate_( | 189 : service_process_launcher_delegate_( |
| 190 new ServiceProcessLauncherDelegateImpl), | 190 new ServiceProcessLauncherDelegateImpl), |
| 191 background_service_manager_(service_process_launcher_delegate_.get(), | 191 background_service_manager_(nullptr), |
| 192 std::move(catalog_contents)) {} | 192 catalog_contents_(std::move(catalog_contents)) {} |
| 193 | 193 |
| 194 service_manager::mojom::ServiceRequest MojoTestConnector::Init() { | 194 service_manager::mojom::ServiceRequest MojoTestConnector::Init() { |
| 195 // In single-process test mode, browser code will initialize the EDK and IPC. | 195 // In single-process test mode, browser code will initialize the EDK and IPC. |
| 196 // Otherwise we ensure it's initialized here. | 196 // Otherwise we ensure it's initialized here. |
| 197 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( | 197 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 198 content::kSingleProcessTestsFlag)) { | 198 content::kSingleProcessTestsFlag)) { |
| 199 mojo::edk::Init(); | 199 mojo::edk::Init(); |
| 200 ipc_thread_ = base::MakeUnique<base::Thread>("IPC thread"); | 200 ipc_thread_ = base::MakeUnique<base::Thread>("IPC thread"); |
| 201 ipc_thread_->StartWithOptions(base::Thread::Options( | 201 ipc_thread_->StartWithOptions(base::Thread::Options( |
| 202 base::MessageLoop::TYPE_IO, 0)); | 202 base::MessageLoop::TYPE_IO, 0)); |
| 203 ipc_support_ = base::MakeUnique<mojo::edk::ScopedIPCSupport>( | 203 ipc_support_ = base::MakeUnique<mojo::edk::ScopedIPCSupport>( |
| 204 ipc_thread_->task_runner(), | 204 ipc_thread_->task_runner(), |
| 205 mojo::edk::ScopedIPCSupport::ShutdownPolicy::FAST); | 205 mojo::edk::ScopedIPCSupport::ShutdownPolicy::FAST); |
| 206 } | 206 } |
| 207 | 207 |
| 208 service_manager::mojom::ServicePtr service; | 208 service_manager::mojom::ServicePtr service; |
| 209 service_manager::mojom::ServiceRequest request(&service); | 209 service_manager::mojom::ServiceRequest request(&service); |
| 210 background_service_manager_.RegisterService( | 210 |
| 211 // BackgroundServiceManager must be created after mojo::edk::Init() as it |
| 212 // attempts to create mojo pipes for the provided catalog on a separate |
| 213 // thread. |
| 214 background_service_manager_ = |
| 215 base::MakeUnique<service_manager::BackgroundServiceManager>( |
| 216 service_process_launcher_delegate_.get(), |
| 217 std::move(catalog_contents_)); |
| 218 background_service_manager_->RegisterService( |
| 211 service_manager::Identity(kTestRunnerName, | 219 service_manager::Identity(kTestRunnerName, |
| 212 service_manager::mojom::kRootUserID), | 220 service_manager::mojom::kRootUserID), |
| 213 std::move(service), nullptr); | 221 std::move(service), nullptr); |
| 214 return request; | 222 return request; |
| 215 } | 223 } |
| 216 | 224 |
| 217 MojoTestConnector::~MojoTestConnector() {} | 225 MojoTestConnector::~MojoTestConnector() {} |
| 218 | 226 |
| 219 std::unique_ptr<content::TestState> MojoTestConnector::PrepareForTest( | 227 std::unique_ptr<content::TestState> MojoTestConnector::PrepareForTest( |
| 220 base::CommandLine* command_line, | 228 base::CommandLine* command_line, |
| 221 base::TestLauncher::LaunchOptions* test_launch_options) { | 229 base::TestLauncher::LaunchOptions* test_launch_options) { |
| 222 auto test_state = | 230 auto test_state = |
| 223 base::MakeUnique<MojoTestState>(&background_service_manager_); | 231 base::MakeUnique<MojoTestState>(background_service_manager_.get()); |
| 224 test_state->Init(command_line, test_launch_options); | 232 test_state->Init(command_line, test_launch_options); |
| 225 return test_state; | 233 return test_state; |
| 226 } | 234 } |
| OLD | NEW |