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

Unified Diff: util/mach/mach_extensions_test.cc

Issue 1383283003: Add and use scoped-right-returning wrappers for Mach bootstrap routines (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: Self-review 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
« util/mach/mach_extensions.cc ('K') | « util/mach/mach_extensions.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_extensions_test.cc
diff --git a/util/mach/mach_extensions_test.cc b/util/mach/mach_extensions_test.cc
index 30013acb19f3ad8aab0a3df90e9a6d0b4084e37f..2b987b375fac6692be4dbd28c2448a2d40076aad 100644
--- a/util/mach/mach_extensions_test.cc
+++ b/util/mach/mach_extensions_test.cc
@@ -15,6 +15,7 @@
#include "util/mach/mach_extensions.h"
#include "base/mac/scoped_mach_port.h"
+#include "base/rand_util.h"
#include "gtest/gtest.h"
#include "test/mac/mach_errors.h"
#include "util/mac/mac_util.h"
@@ -131,6 +132,44 @@ TEST(MachExtensions, ExcMaskValid) {
EXPECT_TRUE(ExcMaskValid() & ~ExcMaskAll());
}
+TEST(MachExtensions, BootstrapCheckInAndLookUp) {
+ // This should always exist.
+ base::mac::ScopedMachSendRight
+ report_crash(BootstrapLookUp("com.apple.ReportCrash"));
+ EXPECT_NE(report_crash, kMachPortNull);
+
+ std::string service_name = "com.googlecode.crashpad.test.bootstrap_check_in.";
+ for (int index = 0; index < 16; ++index) {
+ service_name.append(1, base::RandInt('A', 'Z'));
+ }
+
+ {
+ // The new service hasn’t checked in yet, so this should fail.
+ base::mac::ScopedMachSendRight send(BootstrapLookUp(service_name));
+ EXPECT_EQ(kMachPortNull, send);
+
+ // Check it in.
+ base::mac::ScopedMachReceiveRight receive(BootstrapCheckIn(service_name));
+ EXPECT_NE(receive, kMachPortNull);
+
+ // Now it should be possible to look up the new service.
+ send = BootstrapLookUp(service_name);
+ EXPECT_NE(send, kMachPortNull);
+
+ // It shouldn’t be possible to check the service in while it’s active.
+ base::mac::ScopedMachReceiveRight receive_2(BootstrapCheckIn(service_name));
+ EXPECT_EQ(kMachPortNull, receive_2);
+ }
+
+ // The new service should be gone now.
+ base::mac::ScopedMachSendRight send(BootstrapLookUp(service_name));
+ EXPECT_EQ(kMachPortNull, send);
+
+ // It should be possible to check it in again.
+ base::mac::ScopedMachReceiveRight receive(BootstrapCheckIn(service_name));
+ EXPECT_NE(receive, kMachPortNull);
+}
+
TEST(MachExtensions, SystemCrashReporterHandler) {
base::mac::ScopedMachSendRight
system_crash_reporter_handler(SystemCrashReporterHandler());
« util/mach/mach_extensions.cc ('K') | « util/mach/mach_extensions.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698