| 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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 BackgroundTestState() {} | 80 BackgroundTestState() {} |
| 81 ~BackgroundTestState() {} | 81 ~BackgroundTestState() {} |
| 82 | 82 |
| 83 // Prepares the command line and other setup for connecting the test to mojo. | 83 // Prepares the command line and other setup for connecting the test to mojo. |
| 84 // Must be paired with a clal to ChildProcessLaunched(). | 84 // Must be paired with a clal to ChildProcessLaunched(). |
| 85 void Connect(base::CommandLine* command_line, | 85 void Connect(base::CommandLine* command_line, |
| 86 shell::Shell* shell, | 86 shell::Shell* shell, |
| 87 const std::string& instance, | 87 const std::string& instance, |
| 88 base::TestLauncher::LaunchOptions* test_launch_options) { | 88 base::TestLauncher::LaunchOptions* test_launch_options) { |
| 89 command_line->AppendSwitch(MojoTestConnector::kTestSwitch); | 89 command_line->AppendSwitch(MojoTestConnector::kTestSwitch); |
| 90 command_line->AppendSwitch(switches::kWaitForMojoShell); | |
| 91 command_line->AppendSwitch(switches::kChildProcess); | 90 command_line->AppendSwitch(switches::kChildProcess); |
| 92 mojo_ipc_channel_.reset(new mojo::edk::PlatformChannelPair); | 91 mojo_ipc_channel_.reset(new mojo::edk::PlatformChannelPair); |
| 93 mojo_ipc_channel_->PrepareToPassClientHandleToChildProcess( | 92 mojo_ipc_channel_->PrepareToPassClientHandleToChildProcess( |
| 94 command_line, &handle_passing_info_); | 93 command_line, &handle_passing_info_); |
| 95 #if defined(OS_WIN) | 94 #if defined(OS_WIN) |
| 96 test_launch_options->inherit_handles = true; | 95 test_launch_options->inherit_handles = true; |
| 97 test_launch_options->handles_to_inherit = &handle_passing_info_; | 96 test_launch_options->handles_to_inherit = &handle_passing_info_; |
| 98 #if defined(OFFICIAL_BUILD) | 97 #if defined(OFFICIAL_BUILD) |
| 99 CHECK(false) << "Launching mojo process with inherit_handles is insecure!"; | 98 CHECK(false) << "Launching mojo process with inherit_handles is insecure!"; |
| 100 #endif | 99 #endif |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 } | 210 } |
| 212 | 211 |
| 213 shell::BackgroundShell* background_shell_; | 212 shell::BackgroundShell* background_shell_; |
| 214 std::unique_ptr<BackgroundTestState> background_state_; | 213 std::unique_ptr<BackgroundTestState> background_state_; |
| 215 | 214 |
| 216 DISALLOW_COPY_AND_ASSIGN(MojoTestState); | 215 DISALLOW_COPY_AND_ASSIGN(MojoTestState); |
| 217 }; | 216 }; |
| 218 | 217 |
| 219 } // namespace | 218 } // namespace |
| 220 | 219 |
| 221 class MojoTestConnector::NativeRunnerDelegateImpl | |
| 222 : public shell::NativeRunnerDelegate { | |
| 223 public: | |
| 224 NativeRunnerDelegateImpl() {} | |
| 225 ~NativeRunnerDelegateImpl() override {} | |
| 226 | |
| 227 private: | |
| 228 // shell::NativeRunnerDelegate: | |
| 229 void AdjustCommandLineArgumentsForTarget( | |
| 230 const shell::Identity& target, | |
| 231 base::CommandLine* command_line) override { | |
| 232 if (target.name() == "exe:chrome") | |
| 233 command_line->AppendSwitch(switches::kWaitForMojoShell); | |
| 234 } | |
| 235 | |
| 236 DISALLOW_COPY_AND_ASSIGN(NativeRunnerDelegateImpl); | |
| 237 }; | |
| 238 | |
| 239 // static | 220 // static |
| 240 const char MojoTestConnector::kTestSwitch[] = "is_test"; | 221 const char MojoTestConnector::kTestSwitch[] = "is_test"; |
| 241 | 222 |
| 242 MojoTestConnector::MojoTestConnector() {} | 223 MojoTestConnector::MojoTestConnector() {} |
| 243 | 224 |
| 244 shell::mojom::ShellClientRequest MojoTestConnector::Init() { | 225 shell::mojom::ShellClientRequest MojoTestConnector::Init() { |
| 245 native_runner_delegate_.reset(new NativeRunnerDelegateImpl); | |
| 246 std::unique_ptr<shell::BackgroundShell::InitParams> init_params( | 226 std::unique_ptr<shell::BackgroundShell::InitParams> init_params( |
| 247 new shell::BackgroundShell::InitParams); | 227 new shell::BackgroundShell::InitParams); |
| 248 init_params->catalog_store = BuildTestCatalogStore(); | 228 init_params->catalog_store = BuildTestCatalogStore(); |
| 249 // When running in single_process mode chrome initializes the edk. | 229 // When running in single_process mode chrome initializes the edk. |
| 250 init_params->init_edk = !base::CommandLine::ForCurrentProcess()->HasSwitch( | 230 init_params->init_edk = !base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 251 content::kSingleProcessTestsFlag); | 231 content::kSingleProcessTestsFlag); |
| 252 init_params->native_runner_delegate = native_runner_delegate_.get(); | |
| 253 background_shell_.Init(std::move(init_params)); | 232 background_shell_.Init(std::move(init_params)); |
| 254 return background_shell_.CreateShellClientRequest(kTestRunnerName); | 233 return background_shell_.CreateShellClientRequest(kTestRunnerName); |
| 255 } | 234 } |
| 256 | 235 |
| 257 MojoTestConnector::~MojoTestConnector() {} | 236 MojoTestConnector::~MojoTestConnector() {} |
| 258 | 237 |
| 259 std::unique_ptr<content::TestState> MojoTestConnector::PrepareForTest( | 238 std::unique_ptr<content::TestState> MojoTestConnector::PrepareForTest( |
| 260 base::CommandLine* command_line, | 239 base::CommandLine* command_line, |
| 261 base::TestLauncher::LaunchOptions* test_launch_options) { | 240 base::TestLauncher::LaunchOptions* test_launch_options) { |
| 262 std::unique_ptr<MojoTestState> test_state( | 241 std::unique_ptr<MojoTestState> test_state( |
| 263 new MojoTestState(&background_shell_)); | 242 new MojoTestState(&background_shell_)); |
| 264 test_state->Init(command_line, test_launch_options); | 243 test_state->Init(command_line, test_launch_options); |
| 265 return std::move(test_state); | 244 return std::move(test_state); |
| 266 } | 245 } |
| OLD | NEW |