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

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

Issue 2043713004: Mojo: Add NotifyBadMessage API (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: no bindings 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/system/message_for_transit.h ('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 946322c9b97de509f7286f9fc8812c3aaad9db56..6e2c6f1866ff8fa26cc21f2711dd73dca5a5f40c 100644
--- a/mojo/edk/system/multiprocess_message_pipe_unittest.cc
+++ b/mojo/edk/system/multiprocess_message_pipe_unittest.cc
@@ -11,6 +11,7 @@
#include <utility>
#include <vector>
+#include "base/bind.h"
#include "base/containers/hash_tables.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
@@ -1280,6 +1281,71 @@ TEST_F(MultiprocessMessagePipeTest, BootstrapMessagePipeAsync) {
END_CHILD()
}
+DEFINE_TEST_CLIENT_TEST_WITH_PIPE(BadMessageClient, MultiprocessMessagePipeTest,
+ parent) {
+ MojoHandle pipe;
+ EXPECT_EQ("hi", ReadMessageWithHandles(parent, &pipe, 1));
+ WriteMessage(pipe, "derp");
+ EXPECT_EQ("bye", ReadMessage(parent));
+}
+
+void OnProcessError(std::string* out_error, const std::string& error) {
+ *out_error = error;
+}
+
+TEST_F(MultiprocessMessagePipeTest, NotifyBadMessage) {
+ const std::string kFirstErrorMessage = "everything is terrible!";
+ const std::string kSecondErrorMessage = "not the bits you're looking for";
+
+ std::string first_process_error;
+ std::string second_process_error;
+
+ set_process_error_callback(base::Bind(&OnProcessError, &first_process_error));
+ RUN_CHILD_ON_PIPE(BadMessageClient, child1)
+ set_process_error_callback(base::Bind(&OnProcessError,
+ &second_process_error));
+ RUN_CHILD_ON_PIPE(BadMessageClient, child2)
+ MojoHandle a, b, c, d;
+ CreateMessagePipe(&a, &b);
+ CreateMessagePipe(&c, &d);
+ WriteMessageWithHandles(child1, "hi", &b, 1);
+ WriteMessageWithHandles(child2, "hi", &d, 1);
+
+ // Read a message from the pipe we sent to child1 and flag it as bad.
+ ASSERT_EQ(MOJO_RESULT_OK, MojoWait(a, MOJO_HANDLE_SIGNAL_READABLE,
+ MOJO_DEADLINE_INDEFINITE, nullptr));
+ uint32_t num_bytes = 0;
+ MojoMessageHandle message;
+ ASSERT_EQ(MOJO_RESULT_OK,
+ MojoReadMessageNew(a, &message, &num_bytes, nullptr, 0,
+ MOJO_READ_MESSAGE_FLAG_NONE));
+ EXPECT_EQ(MOJO_RESULT_OK,
+ MojoNotifyBadMessage(message, kFirstErrorMessage.data(),
+ kFirstErrorMessage.size()));
+ EXPECT_EQ(MOJO_RESULT_OK, MojoFreeMessage(message));
+
+ // Read a message from the pipe we sent to child2 and flag it as bad.
+ ASSERT_EQ(MOJO_RESULT_OK, MojoWait(c, MOJO_HANDLE_SIGNAL_READABLE,
+ MOJO_DEADLINE_INDEFINITE, nullptr));
+ ASSERT_EQ(MOJO_RESULT_OK,
+ MojoReadMessageNew(c, &message, &num_bytes, nullptr, 0,
+ MOJO_READ_MESSAGE_FLAG_NONE));
+ EXPECT_EQ(MOJO_RESULT_OK,
+ MojoNotifyBadMessage(message, kSecondErrorMessage.data(),
+ kSecondErrorMessage.size()));
+ EXPECT_EQ(MOJO_RESULT_OK, MojoFreeMessage(message));
+
+ WriteMessage(child2, "bye");
+ END_CHILD();
+
+ WriteMessage(child1, "bye");
+ END_CHILD()
+
+ // The error messages should match the processes which triggered them.
+ EXPECT_NE(std::string::npos, first_process_error.find(kFirstErrorMessage));
+ EXPECT_NE(std::string::npos, second_process_error.find(kSecondErrorMessage));
+}
+
} // namespace
} // namespace edk
} // namespace mojo
« no previous file with comments | « mojo/edk/system/message_for_transit.h ('k') | mojo/edk/system/node_channel.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698