Index: base/mac/mach_port_broker_unittest.cc |
diff --git a/base/mac/mach_port_broker_unittest.cc b/base/mac/mach_port_broker_unittest.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..c5b90c0557af41717fa7c915d04cf05a709095a6 |
--- /dev/null |
+++ b/base/mac/mach_port_broker_unittest.cc |
@@ -0,0 +1,57 @@ |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "base/mac/mach_port_broker.h" |
+ |
+#include "base/synchronization/lock.h" |
+#include "testing/gtest/include/gtest/gtest.h" |
+ |
+namespace base { |
+ |
+class MachPortBrokerTest : public testing::Test { |
+ public: |
+ MachPortBrokerTest() : broker_("foo") {} |
+ |
+ // Helper function to acquire/release locks and call |PlaceholderForPid()|. |
+ void AddPlaceholderForPid(base::ProcessHandle pid) { |
+ base::AutoLock lock(broker_.GetLock()); |
+ broker_.AddPlaceholderForPid(pid); |
+ } |
+ |
+ // Helper function to acquire/release locks and call |FinalizePid()|. |
+ void FinalizePid(base::ProcessHandle pid, |
+ mach_port_t task_port) { |
+ base::AutoLock lock(broker_.GetLock()); |
+ broker_.FinalizePid(pid, task_port); |
+ } |
+ |
+ protected: |
+ MachPortBroker broker_; |
+}; |
+ |
+TEST_F(MachPortBrokerTest, Locks) { |
+ // Acquire and release the locks. Nothing bad should happen. |
+ base::AutoLock lock(broker_.GetLock()); |
+} |
+ |
+TEST_F(MachPortBrokerTest, AddPlaceholderAndFinalize) { |
+ // Add a placeholder for PID 1. |
+ AddPlaceholderForPid(1); |
+ EXPECT_EQ(0u, broker_.TaskForPid(1)); |
+ |
+ // Finalize PID 1. |
+ FinalizePid(1, 100u); |
+ EXPECT_EQ(100u, broker_.TaskForPid(1)); |
+ |
+ // Should be no entry for PID 2. |
+ EXPECT_EQ(0u, broker_.TaskForPid(2)); |
+} |
+ |
+TEST_F(MachPortBrokerTest, FinalizeUnknownPid) { |
+ // Finalizing an entry for an unknown pid should not add it to the map. |
+ FinalizePid(1u, 100u); |
erikchen
2016/03/02 06:56:11
Sorry to impose, but could you add a multiprocess
Anand Mistry (off Chromium)
2016/03/03 01:57:39
Done.
|
+ EXPECT_EQ(0u, broker_.TaskForPid(1u)); |
+} |
+ |
+} // namespace base |