Index: mojo/edk/embedder/embedder_unittest.cc |
diff --git a/mojo/edk/embedder/embedder_unittest.cc b/mojo/edk/embedder/embedder_unittest.cc |
index 0904799ac447cd8724bd59879a4acf8cf4565e75..127a74f09571b6cac49a3f34cc89300508be4882 100644 |
--- a/mojo/edk/embedder/embedder_unittest.cc |
+++ b/mojo/edk/embedder/embedder_unittest.cc |
@@ -17,6 +17,7 @@ |
#include "base/macros.h" |
#include "base/memory/shared_memory.h" |
#include "base/message_loop/message_loop.h" |
+#include "base/process/process_handle.h" |
#include "base/synchronization/waitable_event.h" |
#include "base/test/test_timeouts.h" |
#include "mojo/edk/embedder/platform_channel_pair.h" |
@@ -181,6 +182,58 @@ TEST_F(EmbedderTest, ChannelsHandlePassing) { |
ASSERT_EQ(MOJO_RESULT_OK, MojoClose(h1)); |
} |
+TEST_F(EmbedderTest, PipeSetup) { |
+ std::string child_token = GenerateRandomToken(); |
+ std::string pipe_token = GenerateRandomToken(); |
+ |
+ ScopedMessagePipeHandle parent_mp = |
+ CreateParentMessagePipe(pipe_token, child_token); |
+ ScopedMessagePipeHandle child_mp = |
+ CreateChildMessagePipe(pipe_token); |
+ |
+ const std::string kHello = "hello"; |
+ WriteMessage(parent_mp.get().value(), kHello); |
+ |
+ EXPECT_EQ(kHello, ReadMessage(child_mp.get().value())); |
+} |
+ |
+TEST_F(EmbedderTest, PipeSetup_LaunchDeath) { |
+ PlatformChannelPair pair; |
+ |
+ std::string child_token = GenerateRandomToken(); |
+ std::string pipe_token = GenerateRandomToken(); |
+ |
+ ScopedMessagePipeHandle parent_mp = |
+ CreateParentMessagePipe(pipe_token, child_token); |
+ ChildProcessLaunched(base::GetCurrentProcessHandle(), pair.PassServerHandle(), |
+ child_token); |
+ |
+ // Close the remote end, simulating child death before the child connects to |
+ // the reserved port. |
+ ignore_result(pair.PassClientHandle()); |
+ |
+ EXPECT_EQ(MOJO_RESULT_OK, MojoWait(parent_mp.get().value(), |
+ MOJO_HANDLE_SIGNAL_PEER_CLOSED, |
+ MOJO_DEADLINE_INDEFINITE, |
+ nullptr)); |
+} |
+ |
+TEST_F(EmbedderTest, PipeSetup_LaunchFailure) { |
+ PlatformChannelPair pair; |
+ |
+ std::string child_token = GenerateRandomToken(); |
+ std::string pipe_token = GenerateRandomToken(); |
+ |
+ ScopedMessagePipeHandle parent_mp = |
+ CreateParentMessagePipe(pipe_token, child_token); |
+ |
+ ChildProcessLaunchFailed(child_token); |
+ EXPECT_EQ(MOJO_RESULT_OK, MojoWait(parent_mp.get().value(), |
+ MOJO_HANDLE_SIGNAL_PEER_CLOSED, |
+ MOJO_DEADLINE_INDEFINITE, |
+ nullptr)); |
+} |
+ |
// The sequence of messages sent is: |
// server_mp client_mp mp0 mp1 mp2 mp3 |
// 1. "hello" |