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

Unified Diff: chrome/installer/util/copy_tree_work_item_unittest.cc

Issue 9700038: ScopedProcessInformation protects against process/thread handle leaks from CreateProcess calls. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove changes from another CL. Created 8 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 side-by-side diff with in-line comments
Download patch
Index: chrome/installer/util/copy_tree_work_item_unittest.cc
diff --git a/chrome/installer/util/copy_tree_work_item_unittest.cc b/chrome/installer/util/copy_tree_work_item_unittest.cc
index 55df83be393df56070b3dd5535f7a0ca5d3cbf50..7b1862b32cc24fa68fc82e9f42e490c073832ec6 100644
--- a/chrome/installer/util/copy_tree_work_item_unittest.cc
+++ b/chrome/installer/util/copy_tree_work_item_unittest.cc
@@ -15,6 +15,7 @@
#include "base/scoped_temp_dir.h"
#include "base/string_util.h"
#include "base/threading/platform_thread.h"
+#include "base/win/scoped_process_information.h"
#include "chrome/installer/util/copy_tree_work_item.h"
#include "chrome/installer/util/work_item.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -345,11 +346,11 @@ TEST_F(CopyTreeWorkItemTest, CopyFileInUse) {
// Run the executable in destination path
STARTUPINFOW si = {sizeof(si)};
- PROCESS_INFORMATION pi = {0};
+ base::win::ScopedProcessInformation pi;
ASSERT_TRUE(
::CreateProcess(NULL, const_cast<wchar_t*>(file_name_to.value().c_str()),
- NULL, NULL, FALSE, CREATE_NO_WINDOW | CREATE_SUSPENDED,
- NULL, NULL, &si, &pi));
+ NULL, NULL, FALSE, CREATE_NO_WINDOW | CREATE_SUSPENDED,
+ NULL, NULL, &si, pi.Receive()));
// test Do().
scoped_ptr<CopyTreeWorkItem> work_item(
@@ -384,11 +385,8 @@ TEST_F(CopyTreeWorkItemTest, CopyFileInUse) {
// the backup file should be gone after rollback
EXPECT_FALSE(file_util::PathExists(backup_file));
- TerminateProcess(pi.hProcess, 0);
- // make sure the handle is closed.
- EXPECT_TRUE(WaitForSingleObject(pi.hProcess, 10000) == WAIT_OBJECT_0);
- CloseHandle(pi.hProcess);
- CloseHandle(pi.hThread);
+ TerminateProcess(pi.Get().hProcess, 0);
+ EXPECT_TRUE(WaitForSingleObject(pi.Get().hProcess, 10000) == WAIT_OBJECT_0);
}
// Test overwrite option NEW_NAME_IF_IN_USE:
@@ -425,11 +423,11 @@ TEST_F(CopyTreeWorkItemTest, NewNameAndCopyTest) {
// Run the executable in destination path
STARTUPINFOW si = {sizeof(si)};
- PROCESS_INFORMATION pi = {0};
+ base::win::ScopedProcessInformation pi;
ASSERT_TRUE(
::CreateProcess(NULL, const_cast<wchar_t*>(file_name_to.value().c_str()),
- NULL, NULL, FALSE, CREATE_NO_WINDOW | CREATE_SUSPENDED,
- NULL, NULL, &si, &pi));
+ NULL, NULL, FALSE, CREATE_NO_WINDOW | CREATE_SUSPENDED,
+ NULL, NULL, &si, pi.Receive()));
// test Do().
scoped_ptr<CopyTreeWorkItem> work_item(
@@ -460,11 +458,8 @@ TEST_F(CopyTreeWorkItemTest, NewNameAndCopyTest) {
// the alternate file should be gone after rollback
EXPECT_FALSE(file_util::PathExists(alternate_to));
- TerminateProcess(pi.hProcess, 0);
- // make sure the handle is closed.
- EXPECT_TRUE(WaitForSingleObject(pi.hProcess, 10000) == WAIT_OBJECT_0);
- CloseHandle(pi.hProcess);
- CloseHandle(pi.hThread);
+ TerminateProcess(pi.Get().hProcess, 0);
+ EXPECT_TRUE(WaitForSingleObject(pi.Get().hProcess, 10000) == WAIT_OBJECT_0);
// Now the process has terminated, lets try overwriting the file again
work_item.reset(WorkItem::CreateCopyTreeWorkItem(
@@ -617,11 +612,11 @@ TEST_F(CopyTreeWorkItemTest, DISABLED_CopyFileInUseAndCleanup) {
// Run the executable in destination path
STARTUPINFOW si = {sizeof(si)};
- PROCESS_INFORMATION pi = {0};
+ base::win::ScopedProcessInformation pi;
ASSERT_TRUE(
::CreateProcess(NULL, const_cast<wchar_t*>(file_name_to.value().c_str()),
- NULL, NULL, FALSE, CREATE_NO_WINDOW | CREATE_SUSPENDED,
- NULL, NULL, &si, &pi));
+ NULL, NULL, FALSE, CREATE_NO_WINDOW | CREATE_SUSPENDED,
+ NULL, NULL, &si, pi.Receive()));
FilePath backup_file;
@@ -654,11 +649,8 @@ TEST_F(CopyTreeWorkItemTest, DISABLED_CopyFileInUseAndCleanup) {
EXPECT_TRUE(file_util::PathExists(backup_file));
EXPECT_TRUE(file_util::ContentsEqual(exe_full_path, backup_file));
- TerminateProcess(pi.hProcess, 0);
- // make sure the handle is closed.
- EXPECT_TRUE(WaitForSingleObject(pi.hProcess, 10000) == WAIT_OBJECT_0);
- CloseHandle(pi.hProcess);
- CloseHandle(pi.hThread);
+ TerminateProcess(pi.Get().hProcess, 0);
+ EXPECT_TRUE(WaitForSingleObject(pi.Get().hProcess, 10000) == WAIT_OBJECT_0);
}
// Copy a tree from source to destination.

Powered by Google App Engine
This is Rietveld 408576698