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

Unified Diff: base/process/process_unittest.cc

Issue 2454073003: Allow backgrounding processes on Mac (Closed)
Patch Set: Remove unnecessary forward declare Created 4 years, 1 month 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
Index: base/process/process_unittest.cc
diff --git a/base/process/process_unittest.cc b/base/process/process_unittest.cc
index 853f1fe8fff4895d6a749333b6818651861c6312..e45210f716e0d2df2fe38803940ab411784f74a6 100644
--- a/base/process/process_unittest.cc
+++ b/base/process/process_unittest.cc
@@ -22,6 +22,16 @@ const int kExpectedStillRunningExitCode = 0x102;
const int kExpectedStillRunningExitCode = 0;
#endif
+#if defined(OS_MACOSX)
+// Fake port provider that returns the calling process's
+// task port, ignoring its argument.
+class FakePortProvider : public base::PortProvider {
+ mach_port_t TaskForPid(base::ProcessHandle process) const override {
+ return mach_task_self();
+ }
+};
+#endif
+
} // namespace
namespace base {
@@ -178,6 +188,19 @@ TEST_F(ProcessTest, SetProcessBackgrounded) {
EXPECT_TRUE(process.IsProcessBackgrounded());
EXPECT_TRUE(process.SetProcessBackgrounded(false));
EXPECT_FALSE(process.IsProcessBackgrounded());
+#elif defined(OS_MACOSX)
+ // On the Mac, backgrounding a process requires a port to that process.
+ // In the browser it's available through the MachBroker class, which is not
+ // part of base. Additionally, there is an indefinite amount of time between
+ // spawning a process and receiving its port. Because this test just checks
+ // the ability to background/foreground a process, we can use the current
+ // process's port instead.
+ FakePortProvider provider;
+ EXPECT_TRUE(process.SetProcessBackgrounded(&provider, true));
+ EXPECT_TRUE(process.IsProcessBackgrounded(&provider));
+ EXPECT_TRUE(process.SetProcessBackgrounded(&provider, false));
+ EXPECT_FALSE(process.IsProcessBackgrounded(&provider));
+
#else
if (process.CanBackgroundProcesses()) {
process.SetProcessBackgrounded(true);
@@ -198,6 +221,12 @@ TEST_F(ProcessTest, SetProcessBackgroundedSelf) {
EXPECT_TRUE(process.IsProcessBackgrounded());
EXPECT_TRUE(process.SetProcessBackgrounded(false));
EXPECT_FALSE(process.IsProcessBackgrounded());
+#elif defined(OS_MACOSX)
+ FakePortProvider provider;
+ EXPECT_TRUE(process.SetProcessBackgrounded(&provider, true));
+ EXPECT_TRUE(process.IsProcessBackgrounded(&provider));
+ EXPECT_TRUE(process.SetProcessBackgrounded(&provider, false));
+ EXPECT_FALSE(process.IsProcessBackgrounded(&provider));
#else
process.SetProcessBackgrounded(true);
process.SetProcessBackgrounded(false);

Powered by Google App Engine
This is Rietveld 408576698