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

Unified Diff: base/process/process_unittest.cc

Issue 2480203002: ui: Cleanup class/struct forward declarations (Closed)
Patch Set: Sync CL to position 430550 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
« no previous file with comments | « base/process/process_posix.cc ('k') | base/task_scheduler/scheduler_worker_pool_impl.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/process/process_unittest.cc
diff --git a/base/process/process_unittest.cc b/base/process/process_unittest.cc
index 853f1fe8fff4895d6a749333b6818651861c6312..90bb95a0fe9b04964cedb716629bb42e3058741f 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 {
@@ -171,6 +181,8 @@ TEST_F(ProcessTest, WaitForExitWithTimeout) {
// Note: a platform may not be willing or able to lower the priority of
// a process. The calls to SetProcessBackground should be noops then.
TEST_F(ProcessTest, SetProcessBackgrounded) {
+ if (!Process::CanBackgroundProcesses())
+ return;
Process process(SpawnChild("SimpleChildProcess"));
int old_priority = process.GetPriority();
#if defined(OS_WIN)
@@ -178,11 +190,22 @@ 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);
- process.SetProcessBackgrounded(false);
- }
+ process.SetProcessBackgrounded(true);
+ process.SetProcessBackgrounded(false);
#endif
int new_priority = process.GetPriority();
EXPECT_EQ(old_priority, new_priority);
@@ -191,6 +214,8 @@ TEST_F(ProcessTest, SetProcessBackgrounded) {
// Same as SetProcessBackgrounded but to this very process. It uses
// a different code path at least for Windows.
TEST_F(ProcessTest, SetProcessBackgroundedSelf) {
+ if (!Process::CanBackgroundProcesses())
+ return;
Process process = Process::Current();
int old_priority = process.GetPriority();
#if defined(OS_WIN)
@@ -198,6 +223,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);
« no previous file with comments | « base/process/process_posix.cc ('k') | base/task_scheduler/scheduler_worker_pool_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698