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

Side by Side Diff: chrome/common/process_watcher_unittest.cc

Issue 6672070: Move the remaining files in chrome\common to content\common. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 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 | Annotate | Revision Log
« no previous file with comments | « chrome/common/process_watcher_posix.cc ('k') | chrome/common/process_watcher_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
(Empty)
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/common/process_watcher.h"
6
7 #if defined(OS_POSIX)
8 #include <sys/wait.h>
9
10 #include "base/eintr_wrapper.h"
11 #include "base/process_util.h"
12 #include "base/test/multiprocess_test.h"
13 #include "testing/gtest/include/gtest/gtest.h"
14 #include "testing/multiprocess_func_list.h"
15
16 class ProcessWatcherTest : public base::MultiProcessTest {
17 };
18
19 namespace {
20
21 bool IsProcessDead(base::ProcessHandle child) {
22 // waitpid() will actually reap the process which is exactly NOT what we
23 // want to test for. The good thing is that if it can't find the process
24 // we'll get a nice value for errno which we can test for.
25 const pid_t result = HANDLE_EINTR(waitpid(child, NULL, WNOHANG));
26 return result == -1 && errno == ECHILD;
27 }
28
29 } // namespace
30
31 TEST_F(ProcessWatcherTest, DelayedTermination) {
32 base::ProcessHandle child_process =
33 SpawnChild("process_watcher_test_never_die", false);
34 ProcessWatcher::EnsureProcessTerminated(child_process);
35 base::WaitForSingleProcess(child_process, 5000);
36
37 // Check that process was really killed.
38 EXPECT_TRUE(IsProcessDead(child_process));
39 base::CloseProcessHandle(child_process);
40 }
41
42 MULTIPROCESS_TEST_MAIN(process_watcher_test_never_die) {
43 while (1) {
44 sleep(500);
45 }
46 return 0;
47 }
48
49 TEST_F(ProcessWatcherTest, ImmediateTermination) {
50 base::ProcessHandle child_process =
51 SpawnChild("process_watcher_test_die_immediately", false);
52 // Give it time to die.
53 sleep(2);
54 ProcessWatcher::EnsureProcessTerminated(child_process);
55
56 // Check that process was really killed.
57 EXPECT_TRUE(IsProcessDead(child_process));
58 base::CloseProcessHandle(child_process);
59 }
60
61 MULTIPROCESS_TEST_MAIN(process_watcher_test_die_immediately) {
62 return 0;
63 }
64
65 #endif // OS_POSIX
OLDNEW
« no previous file with comments | « chrome/common/process_watcher_posix.cc ('k') | chrome/common/process_watcher_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698