| 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" | 
| 11 #include "base/run_loop.h" | 11 #include "base/run_loop.h" | 
| 12 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" | 
| 13 #include "base/synchronization/waitable_event.h" | 13 #include "base/synchronization/waitable_event.h" | 
| 14 #include "base/threading/thread.h" | 14 #include "base/threading/thread.h" | 
| 15 #include "content/public/common/content_switches.h" | 15 #include "content/public/common/content_switches.h" | 
| 16 #include "content/public/test/test_launcher.h" | 16 #include "content/public/test/test_launcher.h" | 
| 17 #include "mojo/edk/embedder/embedder.h" | 17 #include "mojo/edk/embedder/embedder.h" | 
| 18 #include "mojo/edk/embedder/platform_channel_pair.h" | 18 #include "mojo/edk/embedder/platform_channel_pair.h" | 
| 19 #include "mojo/edk/embedder/process_delegate.h" | 19 #include "mojo/edk/embedder/process_delegate.h" | 
| 20 #include "mojo/public/cpp/bindings/interface_request.h" | 20 #include "mojo/public/cpp/bindings/interface_request.h" | 
| 21 #include "services/catalog/store.h" | 21 #include "services/catalog/store.h" | 
| 22 #include "services/service_manager/native_runner_delegate.h" |  | 
| 23 #include "services/service_manager/public/cpp/connector.h" | 22 #include "services/service_manager/public/cpp/connector.h" | 
| 24 #include "services/service_manager/public/cpp/service.h" | 23 #include "services/service_manager/public/cpp/service.h" | 
| 25 #include "services/service_manager/public/cpp/service_context.h" | 24 #include "services/service_manager/public/cpp/service_context.h" | 
| 26 #include "services/service_manager/runner/common/client_util.h" | 25 #include "services/service_manager/runner/common/client_util.h" | 
| 27 #include "services/service_manager/runner/common/switches.h" | 26 #include "services/service_manager/runner/common/switches.h" | 
|  | 27 #include "services/service_manager/runner/host/service_process_launcher.h" | 
| 28 #include "services/service_manager/service_manager.h" | 28 #include "services/service_manager/service_manager.h" | 
| 29 #include "services/service_manager/switches.h" | 29 #include "services/service_manager/switches.h" | 
| 30 | 30 | 
| 31 namespace { | 31 namespace { | 
| 32 | 32 | 
| 33 const char kTestRunnerName[] = "mash_browser_tests"; | 33 const char kTestRunnerName[] = "mash_browser_tests"; | 
| 34 const char kTestName[] = "content_browser"; | 34 const char kTestName[] = "content_browser"; | 
| 35 | 35 | 
| 36 // BackgroundTestState maintains all the state necessary to bind the test to | 36 // BackgroundTestState maintains all the state necessary to bind the test to | 
| 37 // mojo. This class is only used on the thread created by | 37 // mojo. This class is only used on the thread created by | 
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 193 #if defined(OS_WIN) | 193 #if defined(OS_WIN) | 
| 194   exe_path = exe_path.DirName().Append(FILE_PATH_LITERAL("browser_tests.exe")); | 194   exe_path = exe_path.DirName().Append(FILE_PATH_LITERAL("browser_tests.exe")); | 
| 195 #else | 195 #else | 
| 196   exe_path = exe_path.DirName().Append(FILE_PATH_LITERAL("browser_tests")); | 196   exe_path = exe_path.DirName().Append(FILE_PATH_LITERAL("browser_tests")); | 
| 197 #endif | 197 #endif | 
| 198   command_line->SetProgram(exe_path); | 198   command_line->SetProgram(exe_path); | 
| 199 } | 199 } | 
| 200 | 200 | 
| 201 }  // namespace | 201 }  // namespace | 
| 202 | 202 | 
| 203 // NativeRunnerDelegate that makes exe:mash_browser_tests to exe:browser_tests, | 203 // ServiceProcessLauncher::Delegate that makes exe:mash_browser_tests to | 
| 204 // and removes '--run-in-mash'. | 204 // exe:browser_tests and removes '--run-in-mash'. | 
| 205 class MojoTestConnector::NativeRunnerDelegateImpl | 205 class MojoTestConnector::ServiceProcessLauncherDelegateImpl | 
| 206     : public service_manager::NativeRunnerDelegate { | 206     : public service_manager::ServiceProcessLauncher::Delegate { | 
| 207  public: | 207  public: | 
| 208   NativeRunnerDelegateImpl() {} | 208   ServiceProcessLauncherDelegateImpl() {} | 
| 209   ~NativeRunnerDelegateImpl() override {} | 209   ~ServiceProcessLauncherDelegateImpl() override {} | 
| 210 | 210 | 
| 211  private: | 211  private: | 
| 212   // service_manager::NativeRunnerDelegate: | 212   // service_manager::ServiceProcessLauncherDelegate: | 
| 213   void AdjustCommandLineArgumentsForTarget( | 213   void AdjustCommandLineArgumentsForTarget( | 
| 214       const service_manager::Identity& target, | 214       const service_manager::Identity& target, | 
| 215       base::CommandLine* command_line) override { | 215       base::CommandLine* command_line) override { | 
| 216     if (target.name() != kTestName) { | 216     if (target.name() != kTestName) { | 
| 217       if (target.name() == kTestRunnerName) { | 217       if (target.name() == kTestRunnerName) { | 
| 218         RemoveMashFromBrowserTests(command_line); | 218         RemoveMashFromBrowserTests(command_line); | 
| 219         command_line->SetProgram( | 219         command_line->SetProgram( | 
| 220             base::CommandLine::ForCurrentProcess()->GetProgram()); | 220             base::CommandLine::ForCurrentProcess()->GetProgram()); | 
| 221       } | 221       } | 
| 222       command_line->AppendSwitch(MojoTestConnector::kMashApp); | 222       command_line->AppendSwitch(MojoTestConnector::kMashApp); | 
| 223       return; | 223       return; | 
| 224     } | 224     } | 
| 225 | 225 | 
| 226     base::CommandLine::StringVector argv(command_line->argv()); | 226     base::CommandLine::StringVector argv(command_line->argv()); | 
| 227     auto iter = | 227     auto iter = | 
| 228         std::find(argv.begin(), argv.end(), FILE_PATH_LITERAL("--run-in-mash")); | 228         std::find(argv.begin(), argv.end(), FILE_PATH_LITERAL("--run-in-mash")); | 
| 229     if (iter != argv.end()) | 229     if (iter != argv.end()) | 
| 230       argv.erase(iter); | 230       argv.erase(iter); | 
| 231     *command_line = base::CommandLine(argv); | 231     *command_line = base::CommandLine(argv); | 
| 232   } | 232   } | 
| 233 | 233 | 
| 234   DISALLOW_COPY_AND_ASSIGN(NativeRunnerDelegateImpl); | 234   DISALLOW_COPY_AND_ASSIGN(ServiceProcessLauncherDelegateImpl); | 
| 235 }; | 235 }; | 
| 236 | 236 | 
| 237 // static | 237 // static | 
| 238 const char MojoTestConnector::kTestSwitch[] = "is_test"; | 238 const char MojoTestConnector::kTestSwitch[] = "is_test"; | 
| 239 // static | 239 // static | 
| 240 const char MojoTestConnector::kMashApp[] = "mash-app"; | 240 const char MojoTestConnector::kMashApp[] = "mash-app"; | 
| 241 | 241 | 
| 242 MojoTestConnector::MojoTestConnector() {} | 242 MojoTestConnector::MojoTestConnector() {} | 
| 243 | 243 | 
| 244 service_manager::mojom::ServiceRequest MojoTestConnector::Init() { | 244 service_manager::mojom::ServiceRequest MojoTestConnector::Init() { | 
| 245   native_runner_delegate_ = base::MakeUnique<NativeRunnerDelegateImpl>(); | 245   service_process_launcher_delegate_ = | 
|  | 246       base::MakeUnique<ServiceProcessLauncherDelegateImpl>(); | 
| 246 | 247 | 
| 247   std::unique_ptr<service_manager::BackgroundServiceManager::InitParams> | 248   std::unique_ptr<service_manager::BackgroundServiceManager::InitParams> | 
| 248       init_params(new service_manager::BackgroundServiceManager::InitParams); | 249       init_params = base::MakeUnique< | 
|  | 250           service_manager::BackgroundServiceManager::InitParams>(); | 
| 249   // When running in single_process mode chrome initializes the edk. | 251   // When running in single_process mode chrome initializes the edk. | 
| 250   init_params->init_edk = !base::CommandLine::ForCurrentProcess()->HasSwitch( | 252   init_params->init_edk = !base::CommandLine::ForCurrentProcess()->HasSwitch( | 
| 251       content::kSingleProcessTestsFlag); | 253       content::kSingleProcessTestsFlag); | 
| 252   init_params->native_runner_delegate = native_runner_delegate_.get(); | 254   init_params->service_process_launcher_delegate = | 
|  | 255       service_process_launcher_delegate_.get(); | 
| 253   background_service_manager_.Init(std::move(init_params)); | 256   background_service_manager_.Init(std::move(init_params)); | 
| 254   return background_service_manager_.CreateServiceRequest(kTestRunnerName); | 257   return background_service_manager_.CreateServiceRequest(kTestRunnerName); | 
| 255 } | 258 } | 
| 256 | 259 | 
| 257 MojoTestConnector::~MojoTestConnector() {} | 260 MojoTestConnector::~MojoTestConnector() {} | 
| 258 | 261 | 
| 259 std::unique_ptr<content::TestState> MojoTestConnector::PrepareForTest( | 262 std::unique_ptr<content::TestState> MojoTestConnector::PrepareForTest( | 
| 260     base::CommandLine* command_line, | 263     base::CommandLine* command_line, | 
| 261     base::TestLauncher::LaunchOptions* test_launch_options) { | 264     base::TestLauncher::LaunchOptions* test_launch_options) { | 
| 262   std::unique_ptr<MojoTestState> test_state( | 265   std::unique_ptr<MojoTestState> test_state( | 
| 263       new MojoTestState(&background_service_manager_)); | 266       new MojoTestState(&background_service_manager_)); | 
| 264   test_state->Init(command_line, test_launch_options); | 267   test_state->Init(command_line, test_launch_options); | 
| 265   return std::move(test_state); | 268   return std::move(test_state); | 
| 266 } | 269 } | 
| OLD | NEW | 
|---|