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

Unified Diff: mojo/edk/embedder/embedder_unittest.cc

Issue 2019973002: [mojo-edk] Bind a child token to child launches and port reservations. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 4 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mojo/edk/embedder/embedder.cc ('k') | mojo/edk/system/core.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
« no previous file with comments | « mojo/edk/embedder/embedder.cc ('k') | mojo/edk/system/core.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698