| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/process/process.h" | 5 #include "base/process/process.h" |
| 6 | 6 |
| 7 #include "base/process/kill.h" | 7 #include "base/process/kill.h" |
| 8 #include "base/test/multiprocess_test.h" | 8 #include "base/test/multiprocess_test.h" |
| 9 #include "base/test/test_timeouts.h" | 9 #include "base/test/test_timeouts.h" |
| 10 #include "base/threading/platform_thread.h" | 10 #include "base/threading/platform_thread.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 #include "testing/multiprocess_func_list.h" | 12 #include "testing/multiprocess_func_list.h" |
| 13 | 13 |
| 14 #if defined(OS_MACOSX) | 14 #if defined(OS_MACOSX) |
| 15 #include <mach/mach.h> | 15 #include <mach/mach.h> |
| 16 #endif // OS_MACOSX | 16 #endif // OS_MACOSX |
| 17 | 17 |
| 18 namespace { | 18 namespace { |
| 19 | 19 |
| 20 #if defined(OS_WIN) | |
| 21 const int kExpectedStillRunningExitCode = 0x102; | |
| 22 #else | |
| 23 const int kExpectedStillRunningExitCode = 0; | 20 const int kExpectedStillRunningExitCode = 0; |
| 24 #endif | |
| 25 | 21 |
| 26 } // namespace | 22 } // namespace |
| 27 | 23 |
| 28 namespace base { | 24 namespace base { |
| 29 | 25 |
| 30 class ProcessTest : public MultiProcessTest { | 26 class ProcessTest : public MultiProcessTest { |
| 31 }; | 27 }; |
| 32 | 28 |
| 33 TEST_F(ProcessTest, Create) { | 29 TEST_F(ProcessTest, Create) { |
| 34 Process process(SpawnChild("SimpleChildProcess")); | 30 Process process(SpawnChild("SimpleChildProcess")); |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 // In the browser it's available through the MachBroker class, which is not | 175 // In the browser it's available through the MachBroker class, which is not |
| 180 // part of base. Additionally, there is an indefinite amount of time between | 176 // part of base. Additionally, there is an indefinite amount of time between |
| 181 // spawning a process and receiving its port. Because this test just checks | 177 // spawning a process and receiving its port. Because this test just checks |
| 182 // the ability to background/foreground a process, we can use the current | 178 // the ability to background/foreground a process, we can use the current |
| 183 // process's port instead. | 179 // process's port instead. |
| 184 mach_port_t process_port = mach_task_self(); | 180 mach_port_t process_port = mach_task_self(); |
| 185 EXPECT_TRUE(process.SetProcessBackgrounded(process_port, true)); | 181 EXPECT_TRUE(process.SetProcessBackgrounded(process_port, true)); |
| 186 EXPECT_TRUE(process.IsProcessBackgrounded(process_port)); | 182 EXPECT_TRUE(process.IsProcessBackgrounded(process_port)); |
| 187 EXPECT_TRUE(process.SetProcessBackgrounded(process_port, false)); | 183 EXPECT_TRUE(process.SetProcessBackgrounded(process_port, false)); |
| 188 EXPECT_FALSE(process.IsProcessBackgrounded(process_port)); | 184 EXPECT_FALSE(process.IsProcessBackgrounded(process_port)); |
| 189 #elif defined(OS_WIN) | |
| 190 EXPECT_TRUE(process.SetProcessBackgrounded(true)); | |
| 191 EXPECT_TRUE(process.IsProcessBackgrounded()); | |
| 192 EXPECT_TRUE(process.SetProcessBackgrounded(false)); | |
| 193 EXPECT_FALSE(process.IsProcessBackgrounded()); | |
| 194 #else | 185 #else |
| 195 process.SetProcessBackgrounded(true); | 186 process.SetProcessBackgrounded(true); |
| 196 process.SetProcessBackgrounded(false); | 187 process.SetProcessBackgrounded(false); |
| 197 #endif | 188 #endif |
| 198 int new_priority = process.GetPriority(); | 189 int new_priority = process.GetPriority(); |
| 199 EXPECT_EQ(old_priority, new_priority); | 190 EXPECT_EQ(old_priority, new_priority); |
| 200 } | 191 } |
| 201 | 192 |
| 202 // Same as SetProcessBackgrounded but to this very process. It uses | 193 // Same as SetProcessBackgrounded but to this very process. It uses |
| 203 // a different code path at least for Windows. | 194 // a different code path at least for Windows. |
| 204 TEST_F(ProcessTest, SetProcessBackgroundedSelf) { | 195 TEST_F(ProcessTest, SetProcessBackgroundedSelf) { |
| 205 Process process = Process::Current(); | 196 Process process = Process::Current(); |
| 206 int old_priority = process.GetPriority(); | 197 int old_priority = process.GetPriority(); |
| 207 #if defined(OS_MACOSX) | 198 #if defined(OS_MACOSX) |
| 208 mach_port_t process_port = mach_task_self(); | 199 mach_port_t process_port = mach_task_self(); |
| 209 EXPECT_TRUE(process.SetProcessBackgrounded(process_port, true)); | 200 EXPECT_TRUE(process.SetProcessBackgrounded(process_port, true)); |
| 210 EXPECT_TRUE(process.IsProcessBackgrounded(process_port)); | 201 EXPECT_TRUE(process.IsProcessBackgrounded(process_port)); |
| 211 EXPECT_TRUE(process.SetProcessBackgrounded(process_port, false)); | 202 EXPECT_TRUE(process.SetProcessBackgrounded(process_port, false)); |
| 212 EXPECT_FALSE(process.IsProcessBackgrounded(process_port)); | 203 EXPECT_FALSE(process.IsProcessBackgrounded(process_port)); |
| 213 #elif defined(OS_WIN) | |
| 214 EXPECT_TRUE(process.SetProcessBackgrounded(true)); | |
| 215 EXPECT_TRUE(process.IsProcessBackgrounded()); | |
| 216 EXPECT_TRUE(process.SetProcessBackgrounded(false)); | |
| 217 EXPECT_FALSE(process.IsProcessBackgrounded()); | |
| 218 #else | 204 #else |
| 219 process.SetProcessBackgrounded(true); | 205 process.SetProcessBackgrounded(true); |
| 220 process.SetProcessBackgrounded(false); | 206 process.SetProcessBackgrounded(false); |
| 221 #endif | 207 #endif |
| 222 int new_priority = process.GetPriority(); | 208 int new_priority = process.GetPriority(); |
| 223 EXPECT_EQ(old_priority, new_priority); | 209 EXPECT_EQ(old_priority, new_priority); |
| 224 } | 210 } |
| 225 | 211 |
| 226 } // namespace base | 212 } // namespace base |
| OLD | NEW |