OLD | NEW |
(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 |
OLD | NEW |