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

Unified Diff: util/mach/mach_message_test.cc

Issue 1408473002: ChildPortHandshake: allow receive rights to be received (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: Address review feedback Created 5 years, 2 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 | « util/mach/mach_message_server_test.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: util/mach/mach_message_test.cc
diff --git a/util/mach/mach_message_test.cc b/util/mach/mach_message_test.cc
index 5e79b212d715768a75138096b68204e9db977e06..d77f0dd38fa51b4e62e8df1169cb2930aa7ed62b 100644
--- a/util/mach/mach_message_test.cc
+++ b/util/mach/mach_message_test.cc
@@ -16,6 +16,7 @@
#include <unistd.h>
+#include "base/basictypes.h"
#include "base/mac/scoped_mach_port.h"
#include "gtest/gtest.h"
#include "test/mac/mach_errors.h"
@@ -148,6 +149,55 @@ TEST(MachMessage, AuditPIDFromMachMessageTrailer) {
EXPECT_EQ(getpid(), AuditPIDFromMachMessageTrailer(&receive.trailer));
}
+TEST(MachMessage, MachMessageDestroyReceivedPort) {
+ mach_port_t port = NewMachPort(MACH_PORT_RIGHT_RECEIVE);
+ ASSERT_NE(kMachPortNull, port);
+ EXPECT_TRUE(MachMessageDestroyReceivedPort(port, MACH_MSG_TYPE_PORT_RECEIVE));
+
+ base::mac::ScopedMachReceiveRight receive(
+ NewMachPort(MACH_PORT_RIGHT_RECEIVE));
+ mach_msg_type_name_t right_type;
+ kern_return_t kr = mach_port_extract_right(mach_task_self(),
+ receive.get(),
+ MACH_MSG_TYPE_MAKE_SEND,
+ &port,
+ &right_type);
+ ASSERT_EQ(KERN_SUCCESS, kr)
+ << MachErrorMessage(kr, "mach_port_extract_right");
+ ASSERT_EQ(receive, port);
+ ASSERT_EQ(implicit_cast<mach_msg_type_name_t>(MACH_MSG_TYPE_PORT_SEND),
+ right_type);
+ EXPECT_TRUE(MachMessageDestroyReceivedPort(port, MACH_MSG_TYPE_PORT_SEND));
+
+ kr = mach_port_extract_right(mach_task_self(),
+ receive.get(),
+ MACH_MSG_TYPE_MAKE_SEND_ONCE,
+ &port,
+ &right_type);
+ ASSERT_EQ(KERN_SUCCESS, kr)
+ << MachErrorMessage(kr, "mach_port_extract_right");
+ ASSERT_NE(kMachPortNull, port);
+ EXPECT_NE(receive, port);
+ ASSERT_EQ(implicit_cast<mach_msg_type_name_t>(MACH_MSG_TYPE_PORT_SEND_ONCE),
+ right_type);
+ EXPECT_TRUE(
+ MachMessageDestroyReceivedPort(port, MACH_MSG_TYPE_PORT_SEND_ONCE));
+
+ kr = mach_port_extract_right(mach_task_self(),
+ receive.get(),
+ MACH_MSG_TYPE_MAKE_SEND,
+ &port,
+ &right_type);
+ ASSERT_EQ(KERN_SUCCESS, kr)
+ << MachErrorMessage(kr, "mach_port_extract_right");
+ ASSERT_EQ(receive, port);
+ ASSERT_EQ(implicit_cast<mach_msg_type_name_t>(MACH_MSG_TYPE_PORT_SEND),
+ right_type);
+ EXPECT_TRUE(MachMessageDestroyReceivedPort(port, MACH_MSG_TYPE_PORT_RECEIVE));
+ ignore_result(receive.release());
+ EXPECT_TRUE(MachMessageDestroyReceivedPort(port, MACH_MSG_TYPE_PORT_SEND));
+}
+
} // namespace
} // namespace test
} // namespace crashpad
« no previous file with comments | « util/mach/mach_message_server_test.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698