| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "mojo/edk/test/multiprocess_test_helper.h" | 5 #include "mojo/edk/test/multiprocess_test_helper.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/process/kill.h" | 9 #include "base/process/kill.h" |
| 10 #include "base/process/process_handle.h" | 10 #include "base/process/process_handle.h" |
| 11 #include "build/build_config.h" | 11 #include "build/build_config.h" |
| 12 #include "mojo/edk/embedder/platform_channel_pair.h" | 12 #include "mojo/edk/embedder/platform_channel_pair.h" |
| 13 | 13 |
| 14 namespace mojo { | 14 namespace mojo { |
| 15 namespace test { | 15 namespace test { |
| 16 | 16 |
| 17 MultiprocessTestHelper::MultiprocessTestHelper() { | 17 MultiprocessTestHelper::MultiprocessTestHelper() { |
| 18 platform_channel_pair_.reset(new embedder::PlatformChannelPair()); | 18 platform_channel_pair_.reset(new embedder::PlatformChannelPair()); |
| 19 server_platform_handle = platform_channel_pair_->PassServerHandle(); | 19 server_platform_handle = platform_channel_pair_->PassServerHandle(); |
| 20 } | 20 } |
| 21 | 21 |
| 22 MultiprocessTestHelper::~MultiprocessTestHelper() { | 22 MultiprocessTestHelper::~MultiprocessTestHelper() { |
| 23 CHECK(!test_child_.IsValid()); | 23 CHECK(!test_child_.IsValid()); |
| 24 server_platform_handle.reset(); | 24 server_platform_handle.reset(); |
| 25 platform_channel_pair_.reset(); | 25 platform_channel_pair_.reset(); |
| 26 } | 26 } |
| 27 | 27 |
| 28 void MultiprocessTestHelper::StartChild(const std::string& test_child_name) { | 28 void MultiprocessTestHelper::StartChild(const std::string& test_child_name) { |
| 29 StartChildWithExtraSwitch(test_child_name, std::string(), std::string()); | |
| 30 } | |
| 31 | |
| 32 void MultiprocessTestHelper::StartChildWithExtraSwitch( | |
| 33 const std::string& test_child_name, | |
| 34 const std::string& switch_string, | |
| 35 const std::string& switch_value) { | |
| 36 CHECK(platform_channel_pair_); | 29 CHECK(platform_channel_pair_); |
| 37 CHECK(!test_child_name.empty()); | 30 CHECK(!test_child_name.empty()); |
| 38 CHECK(!test_child_.IsValid()); | 31 CHECK(!test_child_.IsValid()); |
| 39 | 32 |
| 40 std::string test_child_main = test_child_name + "TestChildMain"; | 33 std::string test_child_main = test_child_name + "TestChildMain"; |
| 41 | 34 |
| 42 base::CommandLine command_line( | 35 base::CommandLine command_line( |
| 43 base::GetMultiProcessTestChildBaseCommandLine()); | 36 base::GetMultiProcessTestChildBaseCommandLine()); |
| 44 embedder::HandlePassingInformation handle_passing_info; | 37 embedder::HandlePassingInformation handle_passing_info; |
| 45 platform_channel_pair_->PrepareToPassClientHandleToChildProcess( | 38 platform_channel_pair_->PrepareToPassClientHandleToChildProcess( |
| 46 &command_line, &handle_passing_info); | 39 &command_line, &handle_passing_info); |
| 47 | 40 |
| 48 if (!switch_string.empty()) { | |
| 49 CHECK(!command_line.HasSwitch(switch_string)); | |
| 50 if (!switch_value.empty()) | |
| 51 command_line.AppendSwitchASCII(switch_string, switch_value); | |
| 52 else | |
| 53 command_line.AppendSwitch(switch_string); | |
| 54 } | |
| 55 | |
| 56 base::LaunchOptions options; | 41 base::LaunchOptions options; |
| 57 #if defined(OS_POSIX) | 42 #if defined(OS_POSIX) |
| 58 options.fds_to_remap = &handle_passing_info; | 43 options.fds_to_remap = &handle_passing_info; |
| 59 #elif defined(OS_WIN) | 44 #elif defined(OS_WIN) |
| 60 options.start_hidden = true; | 45 options.start_hidden = true; |
| 61 options.handles_to_inherit = &handle_passing_info; | 46 options.handles_to_inherit = &handle_passing_info; |
| 62 #else | 47 #else |
| 63 #error "Not supported yet." | 48 #error "Not supported yet." |
| 64 #endif | 49 #endif |
| 65 | 50 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 90 client_platform_handle = | 75 client_platform_handle = |
| 91 embedder::PlatformChannelPair::PassClientHandleFromParentProcess( | 76 embedder::PlatformChannelPair::PassClientHandleFromParentProcess( |
| 92 *base::CommandLine::ForCurrentProcess()); | 77 *base::CommandLine::ForCurrentProcess()); |
| 93 } | 78 } |
| 94 | 79 |
| 95 // static | 80 // static |
| 96 embedder::ScopedPlatformHandle MultiprocessTestHelper::client_platform_handle; | 81 embedder::ScopedPlatformHandle MultiprocessTestHelper::client_platform_handle; |
| 97 | 82 |
| 98 } // namespace test | 83 } // namespace test |
| 99 } // namespace mojo | 84 } // namespace mojo |
| OLD | NEW |