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

Unified Diff: mojo/edk/system/multiprocess_message_pipe_unittest.cc

Issue 2735113003: Changing SpawnChild to return a struct.
Patch Set: Created 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mojo/edk/system/message_pipe_dispatcher.cc ('k') | mojo/edk/system/node_channel.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/edk/system/multiprocess_message_pipe_unittest.cc
diff --git a/mojo/edk/system/multiprocess_message_pipe_unittest.cc b/mojo/edk/system/multiprocess_message_pipe_unittest.cc
index 498980c9d0e99db6fca826a10c11e6a63077a76c..ad4eeb49887a88a13fe2c761d807b529501eb852 100644
--- a/mojo/edk/system/multiprocess_message_pipe_unittest.cc
+++ b/mojo/edk/system/multiprocess_message_pipe_unittest.cc
@@ -31,9 +31,13 @@
#include "mojo/public/c/system/buffer.h"
#include "mojo/public/c/system/functions.h"
#include "mojo/public/c/system/types.h"
+#include "mojo/public/cpp/system/platform_handle.h"
#include "mojo/public/cpp/system/watcher.h"
#include "testing/gtest/include/gtest/gtest.h"
+#if defined(OS_ANDROID)
+#include "base/test/android/jni_test_util.h"
+#endif
namespace mojo {
namespace edk {
@@ -107,11 +111,13 @@ DEFINE_TEST_CLIENT_WITH_PIPE(EchoEcho, MultiprocessMessagePipeTest, h) {
std::string read_buffer(1000, '\0');
uint32_t read_buffer_size = static_cast<uint32_t>(read_buffer.size());
- CHECK_EQ(MojoReadMessage(h, &read_buffer[0],
- &read_buffer_size, nullptr,
- 0, MOJO_READ_MESSAGE_FLAG_NONE),
+ MojoHandle handles[10];
+ uint32_t num_handles = 10;
+ CHECK_EQ(MojoReadMessage(h, &read_buffer[0], &read_buffer_size, handles,
+ &num_handles, MOJO_READ_MESSAGE_FLAG_NONE),
MOJO_RESULT_OK);
read_buffer.resize(read_buffer_size);
+
VLOG(2) << "Child got: " << read_buffer;
if (read_buffer == quitquitquit) {
@@ -120,10 +126,11 @@ DEFINE_TEST_CLIENT_WITH_PIPE(EchoEcho, MultiprocessMessagePipeTest, h) {
}
std::string write_buffer = read_buffer + read_buffer;
- CHECK_EQ(MojoWriteMessage(h, write_buffer.data(),
- static_cast<uint32_t>(write_buffer.size()),
- nullptr, 0u, MOJO_WRITE_MESSAGE_FLAG_NONE),
- MOJO_RESULT_OK);
+ CHECK_EQ(
+ MojoWriteMessage(h, write_buffer.data(),
+ static_cast<uint32_t>(write_buffer.size()), handles,
+ num_handles, MOJO_WRITE_MESSAGE_FLAG_NONE),
+ MOJO_RESULT_OK);
}
return rv;
@@ -1328,6 +1335,68 @@ void OnProcessError(std::string* out_error, const std::string& error) {
*out_error = error;
}
+#if defined(OS_ANDROID)
+TEST_F(MultiprocessMessagePipeTest, BasicParcelable) {
+ RUN_CHILD_ON_PIPE(EchoEcho, h)
+ MojoHandle handles[2];
+ base::android::ScopedJavaLocalRef<jobject> parcelable1 =
+ base::android::test::CreateJavaPoint(11, 22);
+ base::android::ScopedJavaLocalRef<jobject> parcelable2 =
+ base::android::test::CreateJavaPoint(88, 99);
+ ScopedHandle parcelable1_handle = WrapParcelable(parcelable1);
+ handles[0] = parcelable1_handle.release().value();
+ ScopedHandle parcelable2_handle = WrapParcelable(parcelable2);
+ handles[1] = parcelable2_handle.release().value();
+
+ std::string hello("hello");
+ WriteMessageWithHandles(h, hello, handles, 2u);
+
+ HandleSignalsState hss;
+ ASSERT_EQ(MOJO_RESULT_OK, MojoWait(h, MOJO_HANDLE_SIGNAL_READABLE,
+ MOJO_DEADLINE_INDEFINITE, &hss));
+ // The child may or may not have closed its end of the message pipe and died
+ // (and we may or may not know it yet), so our end may or may not appear as
+ // writable.
+ EXPECT_TRUE((hss.satisfied_signals & MOJO_HANDLE_SIGNAL_READABLE));
+ EXPECT_TRUE((hss.satisfiable_signals & MOJO_HANDLE_SIGNAL_READABLE));
+
+ std::string read_buffer(1000, '\0');
+ uint32_t read_buffer_size = static_cast<uint32_t>(read_buffer.size());
+ MojoHandle received_handles[10];
+ uint32_t num_received_handles = 10;
+ CHECK_EQ(
+ MojoReadMessage(h, &read_buffer[0], &read_buffer_size, received_handles,
+ &num_received_handles, MOJO_READ_MESSAGE_FLAG_NONE),
+ MOJO_RESULT_OK);
+ read_buffer.resize(read_buffer_size);
+ VLOG(2) << "Parent got: " << read_buffer;
+ ASSERT_EQ(hello + hello, read_buffer);
+
+ ASSERT_EQ(2U, num_received_handles);
+ base::android::ScopedJavaLocalRef<jobject> received_parcelable1;
+ ASSERT_EQ(MOJO_RESULT_OK,
+ UnwrapParcelable(MakeScopedHandle(Handle(received_handles[0])),
+ &received_parcelable1));
+ EXPECT_TRUE(base::android::test::AreJavaObjectsEqual(
+ parcelable1.obj(), received_parcelable1.obj()));
+
+ base::android::ScopedJavaLocalRef<jobject> received_parcelable2;
+ ASSERT_EQ(MOJO_RESULT_OK,
+ UnwrapParcelable(MakeScopedHandle(Handle(received_handles[1])),
+ &received_parcelable2));
+ EXPECT_TRUE(base::android::test::AreJavaObjectsEqual(
+ parcelable2.obj(), received_parcelable2.obj()));
+
+ std::string quitquitquit("quitquitquit");
+ CHECK_EQ(MojoWriteMessage(h, quitquitquit.data(),
+ static_cast<uint32_t>(quitquitquit.size()), nullptr,
+ 0u, MOJO_WRITE_MESSAGE_FLAG_NONE),
+ MOJO_RESULT_OK);
+ END_CHILD_AND_EXPECT_EXIT_CODE(1 % 100);
+}
+
+#endif // defined(OS_ANDROID)
+
TEST_F(MultiprocessMessagePipeTest, NotifyBadMessage) {
const std::string kFirstErrorMessage = "everything is terrible!";
const std::string kSecondErrorMessage = "not the bits you're looking for";
« no previous file with comments | « mojo/edk/system/message_pipe_dispatcher.cc ('k') | mojo/edk/system/node_channel.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698