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

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

Issue 651253002: Enforce handle ownership in base::Process (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add empty line Created 6 years, 2 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_unittest.cc ('k') | base/process/process_win.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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #define _CRT_SECURE_NO_WARNINGS 5 #define _CRT_SECURE_NO_WARNINGS
6 6
7 #include <limits> 7 #include <limits>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/debug/alias.h" 10 #include "base/debug/alias.h"
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 #elif defined(OS_POSIX) 304 #elif defined(OS_POSIX)
305 int signaled = WIFSIGNALED(exit_code); 305 int signaled = WIFSIGNALED(exit_code);
306 EXPECT_NE(0, signaled); 306 EXPECT_NE(0, signaled);
307 int signal = WTERMSIG(exit_code); 307 int signal = WTERMSIG(exit_code);
308 EXPECT_EQ(SIGKILL, signal); 308 EXPECT_EQ(SIGKILL, signal);
309 #endif 309 #endif
310 base::CloseProcessHandle(handle); 310 base::CloseProcessHandle(handle);
311 remove(signal_file.c_str()); 311 remove(signal_file.c_str());
312 } 312 }
313 313
314 // Ensure that the priority of a process is restored correctly after
315 // backgrounding and restoring.
316 // Note: a platform may not be willing or able to lower the priority of
317 // a process. The calls to SetProcessBackground should be noops then.
318 TEST_F(ProcessUtilTest, SetProcessBackgrounded) {
319 base::ProcessHandle handle = SpawnChild("SimpleChildProcess");
320 base::Process process(handle);
321 int old_priority = process.GetPriority();
322 #if defined(OS_WIN)
323 EXPECT_TRUE(process.SetProcessBackgrounded(true));
324 EXPECT_TRUE(process.IsProcessBackgrounded());
325 EXPECT_TRUE(process.SetProcessBackgrounded(false));
326 EXPECT_FALSE(process.IsProcessBackgrounded());
327 #else
328 process.SetProcessBackgrounded(true);
329 process.SetProcessBackgrounded(false);
330 #endif
331 int new_priority = process.GetPriority();
332 EXPECT_EQ(old_priority, new_priority);
333 }
334
335 // Same as SetProcessBackgrounded but to this very process. It uses
336 // a different code path at least for Windows.
337 TEST_F(ProcessUtilTest, SetProcessBackgroundedSelf) {
338 base::Process process(base::Process::Current().handle());
339 int old_priority = process.GetPriority();
340 #if defined(OS_WIN)
341 EXPECT_TRUE(process.SetProcessBackgrounded(true));
342 EXPECT_TRUE(process.IsProcessBackgrounded());
343 EXPECT_TRUE(process.SetProcessBackgrounded(false));
344 EXPECT_FALSE(process.IsProcessBackgrounded());
345 #else
346 process.SetProcessBackgrounded(true);
347 process.SetProcessBackgrounded(false);
348 #endif
349 int new_priority = process.GetPriority();
350 EXPECT_EQ(old_priority, new_priority);
351 }
352
353 #if defined(OS_WIN) 314 #if defined(OS_WIN)
354 // TODO(estade): if possible, port this test. 315 // TODO(estade): if possible, port this test.
355 TEST_F(ProcessUtilTest, GetAppOutput) { 316 TEST_F(ProcessUtilTest, GetAppOutput) {
356 // Let's create a decently long message. 317 // Let's create a decently long message.
357 std::string message; 318 std::string message;
358 for (int i = 0; i < 1025; i++) { // 1025 so it does not end on a kilo-byte 319 for (int i = 0; i < 1025; i++) { // 1025 so it does not end on a kilo-byte
359 // boundary. 320 // boundary.
360 message += "Hello!"; 321 message += "Hello!";
361 } 322 }
362 // cmd.exe's echo always adds a \r\n to its output. 323 // cmd.exe's echo always adds a \r\n to its output.
(...skipping 580 matching lines...) Expand 10 before | Expand all | Expand 10 after
943 // Check that process was really killed. 904 // Check that process was really killed.
944 EXPECT_TRUE(IsProcessDead(child_process)); 905 EXPECT_TRUE(IsProcessDead(child_process));
945 base::CloseProcessHandle(child_process); 906 base::CloseProcessHandle(child_process);
946 } 907 }
947 908
948 MULTIPROCESS_TEST_MAIN(process_util_test_die_immediately) { 909 MULTIPROCESS_TEST_MAIN(process_util_test_die_immediately) {
949 return 0; 910 return 0;
950 } 911 }
951 912
952 #endif // defined(OS_POSIX) 913 #endif // defined(OS_POSIX)
OLDNEW
« no previous file with comments | « base/process/process_unittest.cc ('k') | base/process/process_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698