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

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

Issue 983963002: Redefine base::Process:Terminate so that it can replace base::KillProcess (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add const Created 5 years, 9 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') | 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 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"
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 ASSERT_TRUE(process.IsValid()); 116 ASSERT_TRUE(process.IsValid());
117 117
118 const int kDummyExitCode = 42; 118 const int kDummyExitCode = 42;
119 int exit_code = kDummyExitCode; 119 int exit_code = kDummyExitCode;
120 EXPECT_EQ(TERMINATION_STATUS_STILL_RUNNING, 120 EXPECT_EQ(TERMINATION_STATUS_STILL_RUNNING,
121 GetTerminationStatus(process.Handle(), &exit_code)); 121 GetTerminationStatus(process.Handle(), &exit_code));
122 EXPECT_EQ(kExpectedStillRunningExitCode, exit_code); 122 EXPECT_EQ(kExpectedStillRunningExitCode, exit_code);
123 123
124 exit_code = kDummyExitCode; 124 exit_code = kDummyExitCode;
125 int kExpectedExitCode = 250; 125 int kExpectedExitCode = 250;
126 process.Terminate(kExpectedExitCode); 126 process.Terminate(kExpectedExitCode, false);
127 process.WaitForExitWithTimeout(TestTimeouts::action_max_timeout(), 127 process.WaitForExitWithTimeout(TestTimeouts::action_max_timeout(),
128 &exit_code); 128 &exit_code);
129 129
130 EXPECT_NE(TERMINATION_STATUS_STILL_RUNNING, 130 EXPECT_NE(TERMINATION_STATUS_STILL_RUNNING,
131 GetTerminationStatus(process.Handle(), &exit_code)); 131 GetTerminationStatus(process.Handle(), &exit_code));
132 #if !defined(OS_POSIX) 132 #if !defined(OS_POSIX)
133 // The POSIX implementation actually ignores the exit_code. 133 // The POSIX implementation actually ignores the exit_code.
134 EXPECT_EQ(kExpectedExitCode, exit_code); 134 EXPECT_EQ(kExpectedExitCode, exit_code);
135 #endif 135 #endif
136 } 136 }
(...skipping 16 matching lines...) Expand all
153 TEST_F(ProcessTest, WaitForExitWithTimeout) { 153 TEST_F(ProcessTest, WaitForExitWithTimeout) {
154 Process process(SpawnChild("SleepyChildProcess")); 154 Process process(SpawnChild("SleepyChildProcess"));
155 ASSERT_TRUE(process.IsValid()); 155 ASSERT_TRUE(process.IsValid());
156 156
157 const int kDummyExitCode = 42; 157 const int kDummyExitCode = 42;
158 int exit_code = kDummyExitCode; 158 int exit_code = kDummyExitCode;
159 TimeDelta timeout = TestTimeouts::tiny_timeout(); 159 TimeDelta timeout = TestTimeouts::tiny_timeout();
160 EXPECT_FALSE(process.WaitForExitWithTimeout(timeout, &exit_code)); 160 EXPECT_FALSE(process.WaitForExitWithTimeout(timeout, &exit_code));
161 EXPECT_EQ(kDummyExitCode, exit_code); 161 EXPECT_EQ(kDummyExitCode, exit_code);
162 162
163 process.Terminate(kDummyExitCode); 163 process.Terminate(kDummyExitCode, false);
164 } 164 }
165 165
166 // Ensure that the priority of a process is restored correctly after 166 // Ensure that the priority of a process is restored correctly after
167 // backgrounding and restoring. 167 // backgrounding and restoring.
168 // 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
169 // a process. The calls to SetProcessBackground should be noops then. 169 // a process. The calls to SetProcessBackground should be noops then.
170 TEST_F(ProcessTest, SetProcessBackgrounded) { 170 TEST_F(ProcessTest, SetProcessBackgrounded) {
171 Process process(SpawnChild("SimpleChildProcess")); 171 Process process(SpawnChild("SimpleChildProcess"));
172 int old_priority = process.GetPriority(); 172 int old_priority = process.GetPriority();
173 #if defined(OS_WIN) 173 #if defined(OS_WIN)
(...skipping 21 matching lines...) Expand all
195 EXPECT_FALSE(process.IsProcessBackgrounded()); 195 EXPECT_FALSE(process.IsProcessBackgrounded());
196 #else 196 #else
197 process.SetProcessBackgrounded(true); 197 process.SetProcessBackgrounded(true);
198 process.SetProcessBackgrounded(false); 198 process.SetProcessBackgrounded(false);
199 #endif 199 #endif
200 int new_priority = process.GetPriority(); 200 int new_priority = process.GetPriority();
201 EXPECT_EQ(old_priority, new_priority); 201 EXPECT_EQ(old_priority, new_priority);
202 } 202 }
203 203
204 } // namespace base 204 } // namespace base
OLDNEW
« no previous file with comments | « base/process/process_posix.cc ('k') | base/process/process_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698