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

Side by Side Diff: base/process/process_unittest.cc

Issue 1142913004: Revert of Add support for backgrounding processes on the Mac (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 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 unified diff | Download patch
« no previous file with comments | « base/process/process_posix.cc ('k') | content/browser/child_process_launcher.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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)
15 #include <mach/mach.h>
16 #endif // OS_MACOSX
17
18 namespace { 14 namespace {
19 15
20 #if defined(OS_WIN) 16 #if defined(OS_WIN)
21 const int kExpectedStillRunningExitCode = 0x102; 17 const int kExpectedStillRunningExitCode = 0x102;
22 #else 18 #else
23 const int kExpectedStillRunningExitCode = 0; 19 const int kExpectedStillRunningExitCode = 0;
24 #endif 20 #endif
25 21
26 } // namespace 22 } // namespace
27 23
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 process.Terminate(kDummyExitCode, false); 163 process.Terminate(kDummyExitCode, false);
168 } 164 }
169 165
170 // Ensure that the priority of a process is restored correctly after 166 // Ensure that the priority of a process is restored correctly after
171 // backgrounding and restoring. 167 // backgrounding and restoring.
172 // Note: a platform may not be willing or able to lower the priority of 168 // Note: a platform may not be willing or able to lower the priority of
173 // a process. The calls to SetProcessBackground should be noops then. 169 // a process. The calls to SetProcessBackground should be noops then.
174 TEST_F(ProcessTest, SetProcessBackgrounded) { 170 TEST_F(ProcessTest, SetProcessBackgrounded) {
175 Process process(SpawnChild("SimpleChildProcess")); 171 Process process(SpawnChild("SimpleChildProcess"));
176 int old_priority = process.GetPriority(); 172 int old_priority = process.GetPriority();
177 #if defined(OS_MACOSX) 173 #if defined(OS_WIN)
178 // On the Mac, backgrounding a process requires a port to that process.
179 // 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
181 // 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
183 // process's port instead.
184 mach_port_t process_port = mach_task_self();
185 EXPECT_TRUE(process.SetProcessBackgrounded(process_port, true));
186 EXPECT_TRUE(process.IsProcessBackgrounded(process_port));
187 EXPECT_TRUE(process.SetProcessBackgrounded(process_port, false));
188 EXPECT_FALSE(process.IsProcessBackgrounded(process_port));
189 #elif defined(OS_WIN)
190 EXPECT_TRUE(process.SetProcessBackgrounded(true)); 174 EXPECT_TRUE(process.SetProcessBackgrounded(true));
191 EXPECT_TRUE(process.IsProcessBackgrounded()); 175 EXPECT_TRUE(process.IsProcessBackgrounded());
192 EXPECT_TRUE(process.SetProcessBackgrounded(false)); 176 EXPECT_TRUE(process.SetProcessBackgrounded(false));
193 EXPECT_FALSE(process.IsProcessBackgrounded()); 177 EXPECT_FALSE(process.IsProcessBackgrounded());
194 #else 178 #else
195 process.SetProcessBackgrounded(true); 179 process.SetProcessBackgrounded(true);
196 process.SetProcessBackgrounded(false); 180 process.SetProcessBackgrounded(false);
197 #endif 181 #endif
198 int new_priority = process.GetPriority(); 182 int new_priority = process.GetPriority();
199 EXPECT_EQ(old_priority, new_priority); 183 EXPECT_EQ(old_priority, new_priority);
200 } 184 }
201 185
202 // Same as SetProcessBackgrounded but to this very process. It uses 186 // Same as SetProcessBackgrounded but to this very process. It uses
203 // a different code path at least for Windows. 187 // a different code path at least for Windows.
204 TEST_F(ProcessTest, SetProcessBackgroundedSelf) { 188 TEST_F(ProcessTest, SetProcessBackgroundedSelf) {
205 Process process = Process::Current(); 189 Process process = Process::Current();
206 int old_priority = process.GetPriority(); 190 int old_priority = process.GetPriority();
207 #if defined(OS_MACOSX) 191 #if defined(OS_WIN)
208 mach_port_t process_port = mach_task_self();
209 EXPECT_TRUE(process.SetProcessBackgrounded(process_port, true));
210 EXPECT_TRUE(process.IsProcessBackgrounded(process_port));
211 EXPECT_TRUE(process.SetProcessBackgrounded(process_port, false));
212 EXPECT_FALSE(process.IsProcessBackgrounded(process_port));
213 #elif defined(OS_WIN)
214 EXPECT_TRUE(process.SetProcessBackgrounded(true)); 192 EXPECT_TRUE(process.SetProcessBackgrounded(true));
215 EXPECT_TRUE(process.IsProcessBackgrounded()); 193 EXPECT_TRUE(process.IsProcessBackgrounded());
216 EXPECT_TRUE(process.SetProcessBackgrounded(false)); 194 EXPECT_TRUE(process.SetProcessBackgrounded(false));
217 EXPECT_FALSE(process.IsProcessBackgrounded()); 195 EXPECT_FALSE(process.IsProcessBackgrounded());
218 #else 196 #else
219 process.SetProcessBackgrounded(true); 197 process.SetProcessBackgrounded(true);
220 process.SetProcessBackgrounded(false); 198 process.SetProcessBackgrounded(false);
221 #endif 199 #endif
222 int new_priority = process.GetPriority(); 200 int new_priority = process.GetPriority();
223 EXPECT_EQ(old_priority, new_priority); 201 EXPECT_EQ(old_priority, new_priority);
224 } 202 }
225 203
226 } // namespace base 204 } // namespace base
OLDNEW
« no previous file with comments | « base/process/process_posix.cc ('k') | content/browser/child_process_launcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698