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

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

Issue 155799: Add a unit test for ProcessWatcher::EnsureProcessTerminated(). (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 5 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/chrome.gyp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Name: svn:eol-style
+ LF
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 "base/platform_thread.h"
6 #include "base/multiprocess_test.h"
7 #include "chrome/common/process_watcher.h"
8 #include "testing/gtest/include/gtest/gtest.h"
9
10 namespace {
11
12 class ProcessWatcherTest : public MultiProcessTest {
13 };
14
15 MULTIPROCESS_TEST_MAIN(Sleep1ChildProcess) {
16 PlatformThread::Sleep(1000);
17 exit(0);
18 return 0;
19 }
20
21 MULTIPROCESS_TEST_MAIN(Sleep3ChildProcess) {
22 PlatformThread::Sleep(3000);
23 exit(0);
24 return 0;
25 }
26
27 TEST_F(ProcessWatcherTest, DiesBeforeTermination) {
28 base::ProcessHandle handle = this->SpawnChild(L"Sleep1ChildProcess");
29 ASSERT_NE(static_cast<base::ProcessHandle>(NULL), handle);
30
31 ProcessWatcher::EnsureProcessTerminated(handle);
32
33 PlatformThread::Sleep(2500);
34 // Normally we don't touch |handle| after calling EnsureProcessTerminated,
35 // but we know the EnsureProcessTerminated process finishes in 2000 ms, so
36 // it's safe to do so now. Same for Terminated test case below.
37 EXPECT_FALSE(base::CrashAwareSleep(handle, 0));
38 }
39
40 TEST_F(ProcessWatcherTest, Terminated) {
41 base::ProcessHandle handle = this->SpawnChild(L"Sleep3ChildProcess");
42 ASSERT_NE(static_cast<base::ProcessHandle>(NULL), handle);
43
44 ProcessWatcher::EnsureProcessTerminated(handle);
45
46 PlatformThread::Sleep(2500);
47 EXPECT_FALSE(base::CrashAwareSleep(handle, 0));
48 }
49
50 TEST_F(ProcessWatcherTest, NotTerminated) {
51 base::ProcessHandle handle = this->SpawnChild(L"Sleep3ChildProcess");
52 ASSERT_NE(static_cast<base::ProcessHandle>(NULL), handle);
53
54 EXPECT_TRUE(base::CrashAwareSleep(handle, 2500));
55 EXPECT_FALSE(base::CrashAwareSleep(handle, 1000));
56 }
57
58 } // namespace
OLDNEW
« no previous file with comments | « chrome/chrome.gyp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698