| 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 <algorithm> | 5 #include <algorithm> |
| 6 | 6 |
| 7 #include "base/at_exit.h" | 7 #include "base/at_exit.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/debug/debugger.h" | 9 #include "base/debug/debugger.h" |
| 10 #include "base/i18n/icu_util.h" | 10 #include "base/i18n/icu_util.h" |
| 11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
| 12 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
| 13 #include "base/process/launch.h" | 13 #include "base/process/launch.h" |
| 14 #include "base/run_loop.h" | 14 #include "base/run_loop.h" |
| 15 #include "base/sys_info.h" | 15 #include "base/sys_info.h" |
| 16 #include "base/threading/thread_task_runner_handle.h" | 16 #include "base/threading/thread_task_runner_handle.h" |
| 17 #include "chrome/test/base/chrome_test_launcher.h" | 17 #include "chrome/test/base/chrome_test_launcher.h" |
| 18 #include "chrome/test/base/chrome_test_suite.h" | 18 #include "chrome/test/base/chrome_test_suite.h" |
| 19 #include "chrome/test/base/mojo_test_connector.h" | 19 #include "chrome/test/base/mojo_test_connector.h" |
| 20 #include "content/public/common/service_manager_connection.h" | 20 #include "content/public/common/service_manager_connection.h" |
| 21 #include "content/public/test/test_launcher.h" | 21 #include "content/public/test/test_launcher.h" |
| 22 #include "mash/package/mash_packaged_service.h" | 22 #include "mash/package/mash_packaged_service.h" |
| 23 #include "services/service_manager/public/cpp/connector.h" | 23 #include "services/service_manager/public/cpp/connector.h" |
| 24 #include "services/service_manager/public/cpp/service.h" | 24 #include "services/service_manager/public/cpp/service.h" |
| 25 #include "services/service_manager/public/cpp/service_context.h" | 25 #include "services/service_manager/public/cpp/service_context.h" |
| 26 #include "services/service_manager/public/cpp/service_runner.h" | 26 #include "services/service_manager/public/cpp/service_runner.h" |
| 27 #include "services/service_manager/public/cpp/standalone_service/standalone_serv
ice.h" | |
| 28 #include "services/service_manager/runner/common/switches.h" | 27 #include "services/service_manager/runner/common/switches.h" |
| 28 #include "services/service_manager/runner/host/child_process.h" |
| 29 #include "services/service_manager/runner/host/child_process_base.h" |
| 29 #include "services/service_manager/runner/init.h" | 30 #include "services/service_manager/runner/init.h" |
| 30 | 31 |
| 31 namespace { | 32 namespace { |
| 32 | 33 |
| 33 void ConnectToDefaultApps(service_manager::Connector* connector) { | 34 void ConnectToDefaultApps(service_manager::Connector* connector) { |
| 34 connector->Connect("mash_session"); | 35 connector->Connect("mash_session"); |
| 35 } | 36 } |
| 36 | 37 |
| 37 class MashTestSuite : public ChromeTestSuite { | 38 class MashTestSuite : public ChromeTestSuite { |
| 38 public: | 39 public: |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 const base::CommandLine& command_line = | 143 const base::CommandLine& command_line = |
| 143 *base::CommandLine::ForCurrentProcess(); | 144 *base::CommandLine::ForCurrentProcess(); |
| 144 if (!command_line.HasSwitch("run-in-mash")) | 145 if (!command_line.HasSwitch("run-in-mash")) |
| 145 return false; | 146 return false; |
| 146 | 147 |
| 147 if (command_line.HasSwitch(MojoTestConnector::kMashApp)) { | 148 if (command_line.HasSwitch(MojoTestConnector::kMashApp)) { |
| 148 #if defined(OS_LINUX) | 149 #if defined(OS_LINUX) |
| 149 base::AtExitManager exit_manager; | 150 base::AtExitManager exit_manager; |
| 150 #endif | 151 #endif |
| 151 base::i18n::InitializeICU(); | 152 base::i18n::InitializeICU(); |
| 152 service_manager::RunStandaloneService(base::Bind(&StartChildApp)); | 153 service_manager::ChildProcessMainWithCallback(base::Bind(&StartChildApp)); |
| 153 *exit_code = 0; | 154 *exit_code = 0; |
| 154 return true; | 155 return true; |
| 155 } | 156 } |
| 156 | 157 |
| 158 if (command_line.HasSwitch(switches::kChildProcess) && |
| 159 !command_line.HasSwitch(MojoTestConnector::kTestSwitch)) { |
| 160 base::AtExitManager at_exit; |
| 161 service_manager::InitializeLogging(); |
| 162 service_manager::WaitForDebuggerIfNecessary(); |
| 163 #if !defined(OFFICIAL_BUILD) && defined(OS_WIN) |
| 164 base::RouteStdioToConsole(false); |
| 165 #endif |
| 166 *exit_code = service_manager::ChildProcessMain(); |
| 167 return true; |
| 168 } |
| 169 |
| 157 int default_jobs = std::max(1, base::SysInfo::NumberOfProcessors() / 2); | 170 int default_jobs = std::max(1, base::SysInfo::NumberOfProcessors() / 2); |
| 158 MashTestLauncherDelegate delegate; | 171 MashTestLauncherDelegate delegate; |
| 159 // --single_process and no primoridal pipe token indicate we were run directly | 172 // --single_process and no primoridal pipe token indicate we were run directly |
| 160 // from the command line. In this case we have to start up | 173 // from the command line. In this case we have to start up |
| 161 // ServiceManagerConnection | 174 // ServiceManagerConnection |
| 162 // as though we were embedded. | 175 // as though we were embedded. |
| 163 content::ServiceManagerConnection::Factory service_manager_connection_factory; | 176 content::ServiceManagerConnection::Factory service_manager_connection_factory; |
| 164 if (command_line.HasSwitch(content::kSingleProcessTestsFlag) && | 177 if (command_line.HasSwitch(content::kSingleProcessTestsFlag) && |
| 165 !command_line.HasSwitch(switches::kPrimordialPipeToken)) { | 178 !command_line.HasSwitch(switches::kPrimordialPipeToken)) { |
| 166 service_manager_connection_factory = | 179 service_manager_connection_factory = |
| 167 base::Bind(&CreateServiceManagerConnection, &delegate); | 180 base::Bind(&CreateServiceManagerConnection, &delegate); |
| 168 content::ServiceManagerConnection::SetFactoryForTest( | 181 content::ServiceManagerConnection::SetFactoryForTest( |
| 169 &service_manager_connection_factory); | 182 &service_manager_connection_factory); |
| 170 } | 183 } |
| 171 *exit_code = LaunchChromeTests(default_jobs, &delegate, argc, argv); | 184 *exit_code = LaunchChromeTests(default_jobs, &delegate, argc, argv); |
| 172 return true; | 185 return true; |
| 173 } | 186 } |
| OLD | NEW |