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

Unified Diff: content/browser/mach_broker_mac_unittest.cc

Issue 1755973002: Move non-content specific parts of content::MachBroker into base::MachPortBroker. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove libbsm from content build rules. Created 4 years, 10 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 | « content/browser/mach_broker_mac.mm ('k') | content/content_browser.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/mach_broker_mac_unittest.cc
diff --git a/content/browser/mach_broker_mac_unittest.cc b/content/browser/mach_broker_mac_unittest.cc
index 9ba50c3109022be8757370123d8e38c2ba819fde..21a4c4d58f2ad401aa4b58b7aaca2b7eb34b9bc2 100644
--- a/content/browser/mach_broker_mac_unittest.cc
+++ b/content/browser/mach_broker_mac_unittest.cc
@@ -4,8 +4,13 @@
#include "content/browser/mach_broker_mac.h"
+#include "base/command_line.h"
#include "base/synchronization/lock.h"
+#include "base/test/multiprocess_test.h"
+#include "base/test/test_timeouts.h"
+#include "content/public/test/test_browser_thread_bundle.h"
#include "testing/gtest/include/gtest/gtest.h"
+#include "testing/multiprocess_func_list.h"
namespace content {
@@ -25,59 +30,58 @@ class MachBrokerTest : public testing::Test {
return broker_.child_process_id_map_.count(child_process_id);
}
- // Helper function to acquire/release locks and call |FinalizePid()|.
- void FinalizePid(base::ProcessHandle pid,
- mach_port_t task_port) {
+ base::Process LaunchTestChild(const std::string& function,
+ int child_process_id) {
base::AutoLock lock(broker_.GetLock());
- broker_.FinalizePid(pid, task_port);
+ base::Process test_child_process = base::SpawnMultiProcessTestChild(
+ function, base::GetMultiProcessTestChildBaseCommandLine(),
+ base::LaunchOptions());
+ broker_.AddPlaceholderForPid(test_child_process.Handle(), child_process_id);
+ return test_child_process;
+ }
+
+ void WaitForChildExit(base::Process& process) {
+ int rv = -1;
+ ASSERT_TRUE(process.WaitForExitWithTimeout(
+ TestTimeouts::action_timeout(), &rv));
+ EXPECT_EQ(0, rv);
}
protected:
MachBroker broker_;
+ TestBrowserThreadBundle thread_bundle_;
};
+MULTIPROCESS_TEST_MAIN(MachBrokerTestChild) {
+ CHECK(MachBroker::ChildSendTaskPortToParent());
+ return 0;
+}
+
TEST_F(MachBrokerTest, Locks) {
// Acquire and release the locks. Nothing bad should happen.
base::AutoLock lock(broker_.GetLock());
}
-TEST_F(MachBrokerTest, AddPlaceholderAndFinalize) {
- // Add a placeholder for PID 1.
- AddPlaceholderForPid(1, 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(MachBrokerTest, InvalidateChildProcessId) {
- // Add a placeholder for PID 1 and child process id 50.
- AddPlaceholderForPid(1, 50);
- FinalizePid(1, 100u);
-
- EXPECT_EQ(100u, broker_.TaskForPid(1));
- InvalidateChildProcessId(50);
- EXPECT_EQ(0u, broker_.TaskForPid(1));
-}
+TEST_F(MachBrokerTest, AddChildProcess) {
+ {
+ base::AutoLock lock(broker_.GetLock());
+ broker_.EnsureRunning();
+ }
+ base::Process child_process = LaunchTestChild("MachBrokerTestChild", 7);
+ WaitForChildExit(child_process);
-TEST_F(MachBrokerTest, ValidateChildProcessIdMap) {
- // Add a placeholder for PID 1 and child process id 50.
- AddPlaceholderForPid(1, 50);
- FinalizePid(1, 100u);
+ EXPECT_NE(static_cast<mach_port_t>(MACH_PORT_NULL),
+ broker_.TaskForPid(child_process.Handle()));
+ EXPECT_EQ(1, GetChildProcessCount(7));
- EXPECT_EQ(1, GetChildProcessCount(50));
- InvalidateChildProcessId(50);
- EXPECT_EQ(0, GetChildProcessCount(50));
-}
+ // Should be no entry for any other PID.
+ EXPECT_EQ(static_cast<mach_port_t>(MACH_PORT_NULL),
+ broker_.TaskForPid(child_process.Handle() + 1));
-TEST_F(MachBrokerTest, FinalizeUnknownPid) {
- // Finalizing an entry for an unknown pid should not add it to the map.
- FinalizePid(1u, 100u);
- EXPECT_EQ(0u, broker_.TaskForPid(1u));
+ InvalidateChildProcessId(7);
+ EXPECT_EQ(static_cast<mach_port_t>(MACH_PORT_NULL),
+ broker_.TaskForPid(child_process.Handle()));
+ EXPECT_EQ(0, GetChildProcessCount(7));
}
} // namespace content
« no previous file with comments | « content/browser/mach_broker_mac.mm ('k') | content/content_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698