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/test/test_timeouts.h" | 9 #include "base/test/test_timeouts.h" |
10 #include "mojo/edk/embedder/platform_channel_pair.h" | 10 #include "mojo/edk/embedder/platform_channel_pair.h" |
11 | 11 |
12 namespace mojo { | 12 namespace mojo { |
13 namespace test { | 13 namespace test { |
14 | 14 |
| 15 const char kPlatformChannelHandleInfoSwitch[] = "platform-channel-handle-info"; |
| 16 |
15 MultiprocessTestHelper::MultiprocessTestHelper() | 17 MultiprocessTestHelper::MultiprocessTestHelper() |
16 : platform_channel_pair_(new embedder::PlatformChannelPair()) { | 18 : platform_channel_pair_(new embedder::PlatformChannelPair()) { |
17 server_platform_handle = platform_channel_pair_->PassServerHandle(); | 19 server_platform_handle = platform_channel_pair_->PassServerHandle(); |
18 } | 20 } |
19 | 21 |
20 MultiprocessTestHelper::~MultiprocessTestHelper() { | 22 MultiprocessTestHelper::~MultiprocessTestHelper() { |
21 CHECK(!test_child_.IsValid()); | 23 CHECK(!test_child_.IsValid()); |
22 server_platform_handle.reset(); | 24 server_platform_handle.reset(); |
23 platform_channel_pair_.reset(); | 25 platform_channel_pair_.reset(); |
24 } | 26 } |
25 | 27 |
26 void MultiprocessTestHelper::StartChild(const std::string& test_child_name) { | 28 void MultiprocessTestHelper::StartChild(const std::string& test_child_name) { |
27 StartChildWithExtraSwitch(test_child_name, std::string(), std::string()); | 29 StartChildWithExtraSwitch(test_child_name, std::string(), std::string()); |
28 } | 30 } |
29 | 31 |
30 void MultiprocessTestHelper::StartChildWithExtraSwitch( | 32 void MultiprocessTestHelper::StartChildWithExtraSwitch( |
31 const std::string& test_child_name, | 33 const std::string& test_child_name, |
32 const std::string& switch_string, | 34 const std::string& switch_string, |
33 const std::string& switch_value) { | 35 const std::string& switch_value) { |
34 CHECK(platform_channel_pair_); | 36 CHECK(platform_channel_pair_); |
35 CHECK(!test_child_name.empty()); | 37 CHECK(!test_child_name.empty()); |
36 CHECK(!test_child_.IsValid()); | 38 CHECK(!test_child_.IsValid()); |
37 | 39 |
38 std::string test_child_main = test_child_name + "TestChildMain"; | 40 std::string test_child_main = test_child_name + "TestChildMain"; |
39 | 41 |
| 42 std::string string_for_child; |
| 43 embedder::HandlePassingInformation handle_passing_info; |
| 44 platform_channel_pair_->PrepareToPassClientHandleToChildProcess( |
| 45 &string_for_child, &handle_passing_info); |
| 46 |
40 base::CommandLine command_line( | 47 base::CommandLine command_line( |
41 base::GetMultiProcessTestChildBaseCommandLine()); | 48 base::GetMultiProcessTestChildBaseCommandLine()); |
42 embedder::HandlePassingInformation handle_passing_info; | 49 command_line.AppendSwitchASCII(kPlatformChannelHandleInfoSwitch, |
43 platform_channel_pair_->PrepareToPassClientHandleToChildProcess( | 50 string_for_child); |
44 &command_line, &handle_passing_info); | |
45 | 51 |
46 if (!switch_string.empty()) { | 52 if (!switch_string.empty()) { |
47 CHECK(!command_line.HasSwitch(switch_string)); | 53 CHECK(!command_line.HasSwitch(switch_string)); |
48 if (!switch_value.empty()) | 54 if (!switch_value.empty()) |
49 command_line.AppendSwitchASCII(switch_string, switch_value); | 55 command_line.AppendSwitchASCII(switch_string, switch_value); |
50 else | 56 else |
51 command_line.AppendSwitch(switch_string); | 57 command_line.AppendSwitch(switch_string); |
52 } | 58 } |
53 | 59 |
54 base::LaunchOptions options; | 60 base::LaunchOptions options; |
(...skipping 16 matching lines...) Expand all Loading... |
71 return rv; | 77 return rv; |
72 } | 78 } |
73 | 79 |
74 bool MultiprocessTestHelper::WaitForChildTestShutdown() { | 80 bool MultiprocessTestHelper::WaitForChildTestShutdown() { |
75 return WaitForChildShutdown() == 0; | 81 return WaitForChildShutdown() == 0; |
76 } | 82 } |
77 | 83 |
78 // static | 84 // static |
79 void MultiprocessTestHelper::ChildSetup() { | 85 void MultiprocessTestHelper::ChildSetup() { |
80 CHECK(base::CommandLine::InitializedForCurrentProcess()); | 86 CHECK(base::CommandLine::InitializedForCurrentProcess()); |
| 87 const base::CommandLine& command_line = |
| 88 *base::CommandLine::ForCurrentProcess(); |
81 client_platform_handle = | 89 client_platform_handle = |
82 embedder::PlatformChannelPair::PassClientHandleFromParentProcess( | 90 embedder::PlatformChannelPair::PassClientHandleFromParentProcess( |
83 *base::CommandLine::ForCurrentProcess()); | 91 command_line.GetSwitchValueASCII(kPlatformChannelHandleInfoSwitch)); |
| 92 CHECK(client_platform_handle.is_valid()); |
84 } | 93 } |
85 | 94 |
86 // static | 95 // static |
87 embedder::ScopedPlatformHandle MultiprocessTestHelper::client_platform_handle; | 96 embedder::ScopedPlatformHandle MultiprocessTestHelper::client_platform_handle; |
88 | 97 |
89 } // namespace test | 98 } // namespace test |
90 } // namespace mojo | 99 } // namespace mojo |
OLD | NEW |