| 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 <functional> | 7 #include <functional> |
| 8 #include <set> | 8 #include <set> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 namespace mojo { | 39 namespace mojo { |
| 40 namespace edk { | 40 namespace edk { |
| 41 namespace test { | 41 namespace test { |
| 42 | 42 |
| 43 namespace { | 43 namespace { |
| 44 | 44 |
| 45 const char kMojoPrimordialPipeToken[] = "mojo-primordial-pipe-token"; | 45 const char kMojoPrimordialPipeToken[] = "mojo-primordial-pipe-token"; |
| 46 const char kMojoNamedPipeName[] = "mojo-named-pipe-name"; | 46 const char kMojoNamedPipeName[] = "mojo-named-pipe-name"; |
| 47 | 47 |
| 48 template <typename Func> | 48 template <typename Func> |
| 49 int RunClientFunction(Func handler) { | 49 int RunClientFunction(Func handler, bool pass_pipe_ownership_to_main) { |
| 50 CHECK(MultiprocessTestHelper::primordial_pipe.is_valid()); | 50 CHECK(MultiprocessTestHelper::primordial_pipe.is_valid()); |
| 51 ScopedMessagePipeHandle pipe = | 51 ScopedMessagePipeHandle pipe = |
| 52 std::move(MultiprocessTestHelper::primordial_pipe); | 52 std::move(MultiprocessTestHelper::primordial_pipe); |
| 53 return handler(pipe.get().value()); | 53 MessagePipeHandle pipe_handle = |
| 54 pass_pipe_ownership_to_main ? pipe.release() : pipe.get(); |
| 55 return handler(pipe_handle.value()); |
| 54 } | 56 } |
| 55 | 57 |
| 56 } // namespace | 58 } // namespace |
| 57 | 59 |
| 58 MultiprocessTestHelper::MultiprocessTestHelper() {} | 60 MultiprocessTestHelper::MultiprocessTestHelper() {} |
| 59 | 61 |
| 60 MultiprocessTestHelper::~MultiprocessTestHelper() { | 62 MultiprocessTestHelper::~MultiprocessTestHelper() { |
| 61 CHECK(!test_child_.process.IsValid()); | 63 CHECK(!test_child_.process.IsValid()); |
| 62 } | 64 } |
| 63 | 65 |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 } else { | 227 } else { |
| 226 primordial_pipe = ConnectToPeerProcess( | 228 primordial_pipe = ConnectToPeerProcess( |
| 227 PlatformChannelPair::PassClientHandleFromParentProcess( | 229 PlatformChannelPair::PassClientHandleFromParentProcess( |
| 228 *base::CommandLine::ForCurrentProcess())); | 230 *base::CommandLine::ForCurrentProcess())); |
| 229 } | 231 } |
| 230 } | 232 } |
| 231 } | 233 } |
| 232 | 234 |
| 233 // static | 235 // static |
| 234 int MultiprocessTestHelper::RunClientMain( | 236 int MultiprocessTestHelper::RunClientMain( |
| 235 const base::Callback<int(MojoHandle)>& main) { | 237 const base::Callback<int(MojoHandle)>& main, |
| 236 return RunClientFunction([main](MojoHandle handle){ | 238 bool pass_pipe_ownership_to_main) { |
| 237 return main.Run(handle); | 239 return RunClientFunction( |
| 238 }); | 240 [main](MojoHandle handle) { return main.Run(handle); }, |
| 241 pass_pipe_ownership_to_main); |
| 239 } | 242 } |
| 240 | 243 |
| 241 // static | 244 // static |
| 242 int MultiprocessTestHelper::RunClientTestMain( | 245 int MultiprocessTestHelper::RunClientTestMain( |
| 243 const base::Callback<void(MojoHandle)>& main) { | 246 const base::Callback<void(MojoHandle)>& main) { |
| 244 return RunClientFunction([main](MojoHandle handle) { | 247 return RunClientFunction( |
| 245 main.Run(handle); | 248 [main](MojoHandle handle) { |
| 246 return (::testing::Test::HasFatalFailure() || | 249 main.Run(handle); |
| 247 ::testing::Test::HasNonfatalFailure()) ? 1 : 0; | 250 return (::testing::Test::HasFatalFailure() || |
| 248 }); | 251 ::testing::Test::HasNonfatalFailure()) |
| 252 ? 1 |
| 253 : 0; |
| 254 }, |
| 255 true /* close_pipe_on_exit */); |
| 249 } | 256 } |
| 250 | 257 |
| 251 // static | 258 // static |
| 252 mojo::ScopedMessagePipeHandle MultiprocessTestHelper::primordial_pipe; | 259 mojo::ScopedMessagePipeHandle MultiprocessTestHelper::primordial_pipe; |
| 253 | 260 |
| 254 } // namespace test | 261 } // namespace test |
| 255 } // namespace edk | 262 } // namespace edk |
| 256 } // namespace mojo | 263 } // namespace mojo |
| OLD | NEW |