Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(628)

Side by Side Diff: mojo/edk/test/multiprocess_test_helper.cc

Issue 1712143002: [mojo-edk] Add support for transferring mach ports. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: More stuff. Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <functional> 7 #include <functional>
8 #include <set> 8 #include <set>
9 #include <utility> 9 #include <utility>
10 10
11 #include "base/base_switches.h" 11 #include "base/base_switches.h"
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/command_line.h" 13 #include "base/command_line.h"
14 #include "base/files/file_path.h" 14 #include "base/files/file_path.h"
15 #include "base/logging.h" 15 #include "base/logging.h"
16 #include "base/memory/ref_counted.h" 16 #include "base/memory/ref_counted.h"
17 #include "base/process/kill.h" 17 #include "base/process/kill.h"
18 #include "base/process/process_handle.h" 18 #include "base/process/process_handle.h"
19 #include "base/run_loop.h" 19 #include "base/run_loop.h"
20 #include "base/strings/stringprintf.h" 20 #include "base/strings/stringprintf.h"
21 #include "base/task_runner.h" 21 #include "base/task_runner.h"
22 #include "base/thread_task_runner_handle.h" 22 #include "base/thread_task_runner_handle.h"
23 #include "build/build_config.h" 23 #include "build/build_config.h"
24 #include "mojo/edk/embedder/embedder.h" 24 #include "mojo/edk/embedder/embedder.h"
25 #include "mojo/edk/embedder/platform_channel_pair.h" 25 #include "mojo/edk/embedder/platform_channel_pair.h"
26 #include "testing/gtest/include/gtest/gtest.h" 26 #include "testing/gtest/include/gtest/gtest.h"
27 27
28 #if defined(OS_WIN) 28 #if defined(OS_WIN)
29 #include "base/win/windows_version.h" 29 #include "base/win/windows_version.h"
30 #elif defined(OS_MACOSX) && !defined(OS_IOS)
31 #include "base/mac/mach_port_broker.h"
30 #endif 32 #endif
31 33
32 namespace mojo { 34 namespace mojo {
33 namespace edk { 35 namespace edk {
34 namespace test { 36 namespace test {
35 37
36 namespace { 38 namespace {
37 39
38 const char kMojoPrimordialPipeToken[] = "mojo-primordial-pipe-token"; 40 const char kMojoPrimordialPipeToken[] = "mojo-primordial-pipe-token";
39 41
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 } 143 }
142 144
143 // static 145 // static
144 void MultiprocessTestHelper::ChildSetup() { 146 void MultiprocessTestHelper::ChildSetup() {
145 CHECK(base::CommandLine::InitializedForCurrentProcess()); 147 CHECK(base::CommandLine::InitializedForCurrentProcess());
146 148
147 primordial_pipe_token = base::CommandLine::ForCurrentProcess() 149 primordial_pipe_token = base::CommandLine::ForCurrentProcess()
148 ->GetSwitchValueASCII(kMojoPrimordialPipeToken); 150 ->GetSwitchValueASCII(kMojoPrimordialPipeToken);
149 CHECK(!primordial_pipe_token.empty()); 151 CHECK(!primordial_pipe_token.empty());
150 152
153 #if defined(OS_MACOSX) && !defined(OS_IOS)
154 CHECK(base::MachPortBroker::ChildSendTaskPortToParent("mojo_test"));
155 #endif
156
151 SetParentPipeHandle( 157 SetParentPipeHandle(
152 PlatformChannelPair::PassClientHandleFromParentProcess( 158 PlatformChannelPair::PassClientHandleFromParentProcess(
153 *base::CommandLine::ForCurrentProcess())); 159 *base::CommandLine::ForCurrentProcess()));
154 } 160 }
155 161
156 // static 162 // static
157 int MultiprocessTestHelper::RunClientMain( 163 int MultiprocessTestHelper::RunClientMain(
158 const base::Callback<int(MojoHandle)>& main) { 164 const base::Callback<int(MojoHandle)>& main) {
159 return RunClientFunction([main](MojoHandle handle){ 165 return RunClientFunction([main](MojoHandle handle){
160 return main.Run(handle); 166 return main.Run(handle);
161 }); 167 });
162 } 168 }
163 169
164 // static 170 // static
165 int MultiprocessTestHelper::RunClientTestMain( 171 int MultiprocessTestHelper::RunClientTestMain(
166 const base::Callback<void(MojoHandle)>& main) { 172 const base::Callback<void(MojoHandle)>& main) {
167 return RunClientFunction([main](MojoHandle handle) { 173 return RunClientFunction([main](MojoHandle handle) {
168 main.Run(handle); 174 main.Run(handle);
169 return (::testing::Test::HasFatalFailure() || 175 return (::testing::Test::HasFatalFailure() ||
170 ::testing::Test::HasNonfatalFailure()) ? 1 : 0; 176 ::testing::Test::HasNonfatalFailure()) ? 1 : 0;
171 }); 177 });
172 } 178 }
173 179
174 // static 180 // static
175 std::string MultiprocessTestHelper::primordial_pipe_token; 181 std::string MultiprocessTestHelper::primordial_pipe_token;
176 182
177 } // namespace test 183 } // namespace test
178 } // namespace edk 184 } // namespace edk
179 } // namespace mojo 185 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698