| 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" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 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/runner/common/switches.h" | 27 #include "services/service_manager/runner/common/switches.h" |
| 28 #include "services/service_manager/runner/host/child_process.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/host/child_process_base.h" |
| 30 #include "services/service_manager/runner/init.h" | 30 #include "services/service_manager/runner/init.h" |
| 31 | 31 |
| 32 namespace { | 32 namespace { |
| 33 | 33 |
| 34 void ConnectToDefaultApps(shell::Connector* connector) { | 34 void ConnectToDefaultApps(service_manager::Connector* connector) { |
| 35 connector->Connect("service:mash_session"); | 35 connector->Connect("service:mash_session"); |
| 36 } | 36 } |
| 37 | 37 |
| 38 class MashTestSuite : public ChromeTestSuite { | 38 class MashTestSuite : public ChromeTestSuite { |
| 39 public: | 39 public: |
| 40 MashTestSuite(int argc, char** argv) : ChromeTestSuite(argc, argv) {} | 40 MashTestSuite(int argc, char** argv) : ChromeTestSuite(argc, argv) {} |
| 41 | 41 |
| 42 void SetMojoTestConnector(std::unique_ptr<MojoTestConnector> connector) { | 42 void SetMojoTestConnector(std::unique_ptr<MojoTestConnector> connector) { |
| 43 mojo_test_connector_ = std::move(connector); | 43 mojo_test_connector_ = std::move(connector); |
| 44 } | 44 } |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 const int result = test_suite_->Run(); | 81 const int result = test_suite_->Run(); |
| 82 test_suite_.reset(); | 82 test_suite_.reset(); |
| 83 return result; | 83 return result; |
| 84 } | 84 } |
| 85 std::unique_ptr<content::TestState> PreRunTest( | 85 std::unique_ptr<content::TestState> PreRunTest( |
| 86 base::CommandLine* command_line, | 86 base::CommandLine* command_line, |
| 87 base::TestLauncher::LaunchOptions* test_launch_options) override { | 87 base::TestLauncher::LaunchOptions* test_launch_options) override { |
| 88 if (!mojo_test_connector_) { | 88 if (!mojo_test_connector_) { |
| 89 mojo_test_connector_ = base::MakeUnique<MojoTestConnector>(); | 89 mojo_test_connector_ = base::MakeUnique<MojoTestConnector>(); |
| 90 service_ = base::MakeUnique<mash::MashPackagedService>(); | 90 service_ = base::MakeUnique<mash::MashPackagedService>(); |
| 91 service_->set_context(base::MakeUnique<shell::ServiceContext>( | 91 service_->set_context(base::MakeUnique<service_manager::ServiceContext>( |
| 92 service_.get(), mojo_test_connector_->Init())); | 92 service_.get(), mojo_test_connector_->Init())); |
| 93 } | 93 } |
| 94 std::unique_ptr<content::TestState> test_state = | 94 std::unique_ptr<content::TestState> test_state = |
| 95 mojo_test_connector_->PrepareForTest(command_line, test_launch_options); | 95 mojo_test_connector_->PrepareForTest(command_line, test_launch_options); |
| 96 // Start default apps after chrome, as they may try to connect to chrome on | 96 // Start default apps after chrome, as they may try to connect to chrome on |
| 97 // startup. Attempt to connect once per test in case a previous test crashed | 97 // startup. Attempt to connect once per test in case a previous test crashed |
| 98 // mash_session. | 98 // mash_session. |
| 99 ConnectToDefaultApps(service_->connector()); | 99 ConnectToDefaultApps(service_->connector()); |
| 100 return test_state; | 100 return test_state; |
| 101 } | 101 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 117 CreateServiceManagerConnection(MashTestLauncherDelegate* delegate) { | 117 CreateServiceManagerConnection(MashTestLauncherDelegate* delegate) { |
| 118 std::unique_ptr<content::ServiceManagerConnection> connection( | 118 std::unique_ptr<content::ServiceManagerConnection> connection( |
| 119 content::ServiceManagerConnection::Create( | 119 content::ServiceManagerConnection::Create( |
| 120 delegate->GetMojoTestConnectorForSingleProcess()->Init(), | 120 delegate->GetMojoTestConnectorForSingleProcess()->Init(), |
| 121 base::ThreadTaskRunnerHandle::Get())); | 121 base::ThreadTaskRunnerHandle::Get())); |
| 122 connection->Start(); | 122 connection->Start(); |
| 123 ConnectToDefaultApps(connection->GetConnector()); | 123 ConnectToDefaultApps(connection->GetConnector()); |
| 124 return connection; | 124 return connection; |
| 125 } | 125 } |
| 126 | 126 |
| 127 void StartChildApp(shell::mojom::ServiceRequest service_request) { | 127 void StartChildApp(service_manager::mojom::ServiceRequest service_request) { |
| 128 base::MessageLoop message_loop(base::MessageLoop::TYPE_DEFAULT); | 128 base::MessageLoop message_loop(base::MessageLoop::TYPE_DEFAULT); |
| 129 base::RunLoop run_loop; | 129 base::RunLoop run_loop; |
| 130 mash::MashPackagedService service; | 130 mash::MashPackagedService service; |
| 131 std::unique_ptr<shell::ServiceContext> context = | 131 std::unique_ptr<service_manager::ServiceContext> context = |
| 132 base::MakeUnique<shell::ServiceContext>(&service, | 132 base::MakeUnique<service_manager::ServiceContext>( |
| 133 std::move(service_request)); | 133 &service, std::move(service_request)); |
| 134 context->SetConnectionLostClosure(run_loop.QuitClosure()); | 134 context->SetConnectionLostClosure(run_loop.QuitClosure()); |
| 135 service.set_context(std::move(context)); | 135 service.set_context(std::move(context)); |
| 136 run_loop.Run(); | 136 run_loop.Run(); |
| 137 } | 137 } |
| 138 | 138 |
| 139 } // namespace | 139 } // namespace |
| 140 | 140 |
| 141 bool RunMashBrowserTests(int argc, char** argv, int* exit_code) { | 141 bool RunMashBrowserTests(int argc, char** argv, int* exit_code) { |
| 142 base::CommandLine::Init(argc, argv); | 142 base::CommandLine::Init(argc, argv); |
| 143 const base::CommandLine& command_line = | 143 const base::CommandLine& command_line = |
| 144 *base::CommandLine::ForCurrentProcess(); | 144 *base::CommandLine::ForCurrentProcess(); |
| 145 if (!command_line.HasSwitch("run-in-mash")) | 145 if (!command_line.HasSwitch("run-in-mash")) |
| 146 return false; | 146 return false; |
| 147 | 147 |
| 148 if (command_line.HasSwitch(MojoTestConnector::kMashApp)) { | 148 if (command_line.HasSwitch(MojoTestConnector::kMashApp)) { |
| 149 #if defined(OS_LINUX) | 149 #if defined(OS_LINUX) |
| 150 base::AtExitManager exit_manager; | 150 base::AtExitManager exit_manager; |
| 151 #endif | 151 #endif |
| 152 base::i18n::InitializeICU(); | 152 base::i18n::InitializeICU(); |
| 153 shell::ChildProcessMainWithCallback(base::Bind(&StartChildApp)); | 153 service_manager::ChildProcessMainWithCallback(base::Bind(&StartChildApp)); |
| 154 *exit_code = 0; | 154 *exit_code = 0; |
| 155 return true; | 155 return true; |
| 156 } | 156 } |
| 157 | 157 |
| 158 if (command_line.HasSwitch(switches::kChildProcess) && | 158 if (command_line.HasSwitch(switches::kChildProcess) && |
| 159 !command_line.HasSwitch(MojoTestConnector::kTestSwitch)) { | 159 !command_line.HasSwitch(MojoTestConnector::kTestSwitch)) { |
| 160 base::AtExitManager at_exit; | 160 base::AtExitManager at_exit; |
| 161 shell::InitializeLogging(); | 161 service_manager::InitializeLogging(); |
| 162 shell::WaitForDebuggerIfNecessary(); | 162 service_manager::WaitForDebuggerIfNecessary(); |
| 163 #if !defined(OFFICIAL_BUILD) && defined(OS_WIN) | 163 #if !defined(OFFICIAL_BUILD) && defined(OS_WIN) |
| 164 base::RouteStdioToConsole(false); | 164 base::RouteStdioToConsole(false); |
| 165 #endif | 165 #endif |
| 166 *exit_code = shell::ChildProcessMain(); | 166 *exit_code = service_manager::ChildProcessMain(); |
| 167 return true; | 167 return true; |
| 168 } | 168 } |
| 169 | 169 |
| 170 int default_jobs = std::max(1, base::SysInfo::NumberOfProcessors() / 2); | 170 int default_jobs = std::max(1, base::SysInfo::NumberOfProcessors() / 2); |
| 171 MashTestLauncherDelegate delegate; | 171 MashTestLauncherDelegate delegate; |
| 172 // --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 |
| 173 // 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 |
| 174 // ServiceManagerConnection | 174 // ServiceManagerConnection |
| 175 // as though we were embedded. | 175 // as though we were embedded. |
| 176 content::ServiceManagerConnection::Factory shell_connection_factory; | 176 content::ServiceManagerConnection::Factory service_manager_connection_factory; |
| 177 if (command_line.HasSwitch(content::kSingleProcessTestsFlag) && | 177 if (command_line.HasSwitch(content::kSingleProcessTestsFlag) && |
| 178 !command_line.HasSwitch(switches::kPrimordialPipeToken)) { | 178 !command_line.HasSwitch(switches::kPrimordialPipeToken)) { |
| 179 shell_connection_factory = | 179 service_manager_connection_factory = |
| 180 base::Bind(&CreateServiceManagerConnection, &delegate); | 180 base::Bind(&CreateServiceManagerConnection, &delegate); |
| 181 content::ServiceManagerConnection::SetFactoryForTest( | 181 content::ServiceManagerConnection::SetFactoryForTest( |
| 182 &shell_connection_factory); | 182 &service_manager_connection_factory); |
| 183 } | 183 } |
| 184 *exit_code = LaunchChromeTests(default_jobs, &delegate, argc, argv); | 184 *exit_code = LaunchChromeTests(default_jobs, &delegate, argc, argv); |
| 185 return true; | 185 return true; |
| 186 } | 186 } |
| OLD | NEW |