| 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/run_loop.h" | 10 #include "base/run_loop.h" |
| 11 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
| 12 #include "base/synchronization/waitable_event.h" | 12 #include "base/synchronization/waitable_event.h" |
| 13 #include "base/threading/thread.h" | 13 #include "base/threading/thread.h" |
| 14 #include "content/public/common/content_switches.h" | 14 #include "content/public/common/content_switches.h" |
| 15 #include "content/public/test/test_launcher.h" | 15 #include "content/public/test/test_launcher.h" |
| 16 #include "mojo/edk/embedder/embedder.h" | 16 #include "mojo/edk/embedder/embedder.h" |
| 17 #include "mojo/edk/embedder/platform_channel_pair.h" | 17 #include "mojo/edk/embedder/platform_channel_pair.h" |
| 18 #include "mojo/edk/embedder/process_delegate.h" | 18 #include "mojo/edk/embedder/process_delegate.h" |
| 19 #include "mojo/public/cpp/bindings/interface_request.h" | 19 #include "mojo/public/cpp/bindings/interface_request.h" |
| 20 #include "mojo/services/catalog/store.h" | 20 #include "mojo/services/catalog/store.h" |
| 21 #include "mojo/shell/background/tests/test_catalog_store.h" | 21 #include "mojo/shell/background/tests/test_catalog_store.h" |
| 22 #include "mojo/shell/native_runner_delegate.h" |
| 22 #include "mojo/shell/public/cpp/connector.h" | 23 #include "mojo/shell/public/cpp/connector.h" |
| 23 #include "mojo/shell/public/cpp/shell_client.h" | 24 #include "mojo/shell/public/cpp/shell_client.h" |
| 24 #include "mojo/shell/public/cpp/shell_connection.h" | 25 #include "mojo/shell/public/cpp/shell_connection.h" |
| 25 #include "mojo/shell/runner/common/client_util.h" | 26 #include "mojo/shell/runner/common/client_util.h" |
| 26 #include "mojo/shell/runner/common/switches.h" | 27 #include "mojo/shell/runner/common/switches.h" |
| 27 #include "mojo/shell/shell.h" | 28 #include "mojo/shell/shell.h" |
| 28 #include "mojo/shell/switches.h" | 29 #include "mojo/shell/switches.h" |
| 29 | 30 |
| 30 using mojo::shell::mojom::ShellClient; | 31 using mojo::shell::mojom::ShellClient; |
| 31 using mojo::shell::mojom::ShellClientPtr; | 32 using mojo::shell::mojom::ShellClientPtr; |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 } | 210 } |
| 210 | 211 |
| 211 mojo::shell::BackgroundShell* background_shell_; | 212 mojo::shell::BackgroundShell* background_shell_; |
| 212 scoped_ptr<BackgroundTestState> background_state_; | 213 scoped_ptr<BackgroundTestState> background_state_; |
| 213 | 214 |
| 214 DISALLOW_COPY_AND_ASSIGN(MojoTestState); | 215 DISALLOW_COPY_AND_ASSIGN(MojoTestState); |
| 215 }; | 216 }; |
| 216 | 217 |
| 217 } // namespace | 218 } // namespace |
| 218 | 219 |
| 220 class MojoTestConnector::NativeRunnerDelegateImpl |
| 221 : public mojo::shell::NativeRunnerDelegate { |
| 222 public: |
| 223 NativeRunnerDelegateImpl() {} |
| 224 ~NativeRunnerDelegateImpl() override {} |
| 225 |
| 226 private: |
| 227 // mojo::shell::NativeRunnerDelegate: |
| 228 void AdjustCommandLineArgumentsForTarget( |
| 229 const mojo::Identity& target, |
| 230 base::CommandLine* command_line) override { |
| 231 if (target.name() == "exe:chrome") |
| 232 command_line->AppendSwitch(switches::kWaitForMojoShell); |
| 233 } |
| 234 |
| 235 DISALLOW_COPY_AND_ASSIGN(NativeRunnerDelegateImpl); |
| 236 }; |
| 237 |
| 219 // static | 238 // static |
| 220 const char MojoTestConnector::kTestSwitch[] = "is_test"; | 239 const char MojoTestConnector::kTestSwitch[] = "is_test"; |
| 221 | 240 |
| 222 MojoTestConnector::MojoTestConnector() {} | 241 MojoTestConnector::MojoTestConnector() {} |
| 223 | 242 |
| 224 mojo::shell::mojom::ShellClientRequest MojoTestConnector::Init() { | 243 mojo::shell::mojom::ShellClientRequest MojoTestConnector::Init() { |
| 244 native_runner_delegate_.reset(new NativeRunnerDelegateImpl); |
| 225 scoped_ptr<mojo::shell::BackgroundShell::InitParams> init_params( | 245 scoped_ptr<mojo::shell::BackgroundShell::InitParams> init_params( |
| 226 new mojo::shell::BackgroundShell::InitParams); | 246 new mojo::shell::BackgroundShell::InitParams); |
| 227 init_params->catalog_store = BuildTestCatalogStore(); | 247 init_params->catalog_store = BuildTestCatalogStore(); |
| 228 // When running in single_process mode chrome initializes the edk. | 248 // When running in single_process mode chrome initializes the edk. |
| 229 init_params->init_edk = !base::CommandLine::ForCurrentProcess()->HasSwitch( | 249 init_params->init_edk = !base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 230 content::kSingleProcessTestsFlag); | 250 content::kSingleProcessTestsFlag); |
| 251 init_params->native_runner_delegate = native_runner_delegate_.get(); |
| 231 background_shell_.Init(std::move(init_params)); | 252 background_shell_.Init(std::move(init_params)); |
| 232 return background_shell_.CreateShellClientRequest(kTestRunnerName); | 253 return background_shell_.CreateShellClientRequest(kTestRunnerName); |
| 233 } | 254 } |
| 234 | 255 |
| 235 MojoTestConnector::~MojoTestConnector() {} | 256 MojoTestConnector::~MojoTestConnector() {} |
| 236 | 257 |
| 237 scoped_ptr<content::TestState> MojoTestConnector::PrepareForTest( | 258 scoped_ptr<content::TestState> MojoTestConnector::PrepareForTest( |
| 238 base::CommandLine* command_line, | 259 base::CommandLine* command_line, |
| 239 base::TestLauncher::LaunchOptions* test_launch_options) { | 260 base::TestLauncher::LaunchOptions* test_launch_options) { |
| 240 scoped_ptr<MojoTestState> test_state(new MojoTestState(&background_shell_)); | 261 scoped_ptr<MojoTestState> test_state(new MojoTestState(&background_shell_)); |
| 241 test_state->Init(command_line, test_launch_options); | 262 test_state->Init(command_line, test_launch_options); |
| 242 return std::move(test_state); | 263 return std::move(test_state); |
| 243 } | 264 } |
| OLD | NEW |