| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <windows.h> | 5 #include <windows.h> |
| 6 | 6 |
| 7 #include <fstream> | 7 #include <fstream> |
| 8 | 8 |
| 9 #include "base/base_paths.h" | 9 #include "base/base_paths.h" |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/path_service.h" | 13 #include "base/path_service.h" |
| 14 #include "base/process_util.h" | 14 #include "base/process_util.h" |
| 15 #include "base/scoped_temp_dir.h" | 15 #include "base/scoped_temp_dir.h" |
| 16 #include "base/string_util.h" | 16 #include "base/string_util.h" |
| 17 #include "base/win/scoped_process_information.h" |
| 17 #include "chrome/installer/util/delete_tree_work_item.h" | 18 #include "chrome/installer/util/delete_tree_work_item.h" |
| 18 #include "chrome/installer/util/work_item.h" | 19 #include "chrome/installer/util/work_item.h" |
| 19 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
| 20 | 21 |
| 21 namespace { | 22 namespace { |
| 22 class DeleteTreeWorkItemTest : public testing::Test { | 23 class DeleteTreeWorkItemTest : public testing::Test { |
| 23 protected: | 24 protected: |
| 24 virtual void SetUp() { | 25 virtual void SetUp() { |
| 25 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 26 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 26 } | 27 } |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 FilePath exe_full_path(exe_full_path_str); | 183 FilePath exe_full_path(exe_full_path_str); |
| 183 | 184 |
| 184 file_util::CopyFile(exe_full_path, key_path); | 185 file_util::CopyFile(exe_full_path, key_path); |
| 185 ASSERT_TRUE(file_util::PathExists(key_path)); | 186 ASSERT_TRUE(file_util::PathExists(key_path)); |
| 186 | 187 |
| 187 VLOG(1) << "copy ourself from " << exe_full_path.value() | 188 VLOG(1) << "copy ourself from " << exe_full_path.value() |
| 188 << " to " << key_path.value(); | 189 << " to " << key_path.value(); |
| 189 | 190 |
| 190 // Run the key path file to keep it in use. | 191 // Run the key path file to keep it in use. |
| 191 STARTUPINFOW si = {sizeof(si)}; | 192 STARTUPINFOW si = {sizeof(si)}; |
| 192 PROCESS_INFORMATION pi = {0}; | 193 base::win::ScopedProcessInformation pi; |
| 193 ASSERT_TRUE( | 194 ASSERT_TRUE( |
| 194 ::CreateProcessW(NULL, const_cast<wchar_t*>(key_path.value().c_str()), | 195 ::CreateProcessW(NULL, const_cast<wchar_t*>(key_path.value().c_str()), |
| 195 NULL, NULL, FALSE, CREATE_NO_WINDOW | CREATE_SUSPENDED, | 196 NULL, NULL, FALSE, CREATE_NO_WINDOW | CREATE_SUSPENDED, |
| 196 NULL, NULL, &si, &pi)); | 197 NULL, NULL, &si, pi.Receive())); |
| 197 | 198 |
| 198 // test Do(). | 199 // test Do(). |
| 199 { | 200 { |
| 200 ScopedTempDir temp_dir; | 201 ScopedTempDir temp_dir; |
| 201 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 202 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 202 | 203 |
| 203 std::vector<FilePath> key_paths(1, key_path); | 204 std::vector<FilePath> key_paths(1, key_path); |
| 204 scoped_ptr<DeleteTreeWorkItem> work_item( | 205 scoped_ptr<DeleteTreeWorkItem> work_item( |
| 205 WorkItem::CreateDeleteTreeWorkItem(dir_name_delete, temp_dir.path(), | 206 WorkItem::CreateDeleteTreeWorkItem(dir_name_delete, temp_dir.path(), |
| 206 key_paths)); | 207 key_paths)); |
| 207 | 208 |
| 208 // delete should fail as file in use. | 209 // delete should fail as file in use. |
| 209 EXPECT_FALSE(work_item->Do()); | 210 EXPECT_FALSE(work_item->Do()); |
| 210 } | 211 } |
| 211 | 212 |
| 212 // verify everything is still there. | 213 // verify everything is still there. |
| 213 EXPECT_TRUE(file_util::PathExists(key_path)); | 214 EXPECT_TRUE(file_util::PathExists(key_path)); |
| 214 EXPECT_TRUE(file_util::PathExists(file_name_delete_1)); | 215 EXPECT_TRUE(file_util::PathExists(file_name_delete_1)); |
| 215 EXPECT_TRUE(file_util::PathExists(file_name_delete_2)); | 216 EXPECT_TRUE(file_util::PathExists(file_name_delete_2)); |
| 216 | 217 |
| 217 TerminateProcess(pi.hProcess, 0); | 218 TerminateProcess(pi.Get().hProcess, 0); |
| 218 // make sure the handle is closed. | 219 WaitForSingleObject(pi.Get().hProcess, INFINITE); |
| 219 WaitForSingleObject(pi.hProcess, INFINITE); | |
| 220 } | 220 } |
| OLD | NEW |