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

Unified Diff: content/common/process_watcher_unittest.cc

Issue 8674003: Move the ProcessWatcher methods out of content/common/process_watcher into base/process_util, alo... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 9 years, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: content/common/process_watcher_unittest.cc
===================================================================
--- content/common/process_watcher_unittest.cc (revision 111236)
+++ content/common/process_watcher_unittest.cc (working copy)
@@ -1,64 +0,0 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "content/common/process_watcher.h"
-
-#include <sys/wait.h>
-
-#include "base/eintr_wrapper.h"
-#include "base/process_util.h"
-#include "base/test/multiprocess_test.h"
-#include "testing/gtest/include/gtest/gtest.h"
-#include "testing/multiprocess_func_list.h"
-
-class ProcessWatcherTest : public base::MultiProcessTest {
-};
-
-namespace {
-
-bool IsProcessDead(base::ProcessHandle child) {
- // waitpid() will actually reap the process which is exactly NOT what we
- // want to test for. The good thing is that if it can't find the process
- // we'll get a nice value for errno which we can test for.
- const pid_t result = HANDLE_EINTR(waitpid(child, NULL, WNOHANG));
- return result == -1 && errno == ECHILD;
-}
-
-} // namespace
-
-TEST_F(ProcessWatcherTest, DelayedTermination) {
- base::ProcessHandle child_process =
- SpawnChild("process_watcher_test_never_die", false);
- ASSERT_TRUE(child_process);
- ProcessWatcher::EnsureProcessTerminated(child_process);
- base::WaitForSingleProcess(child_process, 5000);
-
- // Check that process was really killed.
- EXPECT_TRUE(IsProcessDead(child_process));
- base::CloseProcessHandle(child_process);
-}
-
-MULTIPROCESS_TEST_MAIN(process_watcher_test_never_die) {
- while (1) {
- sleep(500);
- }
- return 0;
-}
-
-TEST_F(ProcessWatcherTest, ImmediateTermination) {
- base::ProcessHandle child_process =
- SpawnChild("process_watcher_test_die_immediately", false);
- ASSERT_TRUE(child_process);
- // Give it time to die.
- sleep(2);
- ProcessWatcher::EnsureProcessTerminated(child_process);
-
- // Check that process was really killed.
- EXPECT_TRUE(IsProcessDead(child_process));
- base::CloseProcessHandle(child_process);
-}
-
-MULTIPROCESS_TEST_MAIN(process_watcher_test_die_immediately) {
- return 0;
-}

Powered by Google App Engine
This is Rietveld 408576698