| 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/files/file_util.h" |
| 11 #include "base/files/scoped_temp_dir.h" | 11 #include "base/files/scoped_temp_dir.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/path_service.h" | 14 #include "base/path_service.h" |
| 15 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
| 16 #include "chrome/installer/util/delete_tree_work_item.h" | 16 #include "chrome/installer/util/delete_tree_work_item.h" |
| 17 #include "chrome/installer/util/work_item.h" | 17 #include "chrome/installer/util/work_item.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| 19 | 19 |
| 20 namespace { | 20 namespace { |
| 21 class DeleteTreeWorkItemTest : public testing::Test { | |
| 22 protected: | |
| 23 virtual void SetUp() { | |
| 24 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | |
| 25 } | |
| 26 | 21 |
| 27 // The temporary directory used to contain the test operations. | 22 class DeleteTreeWorkItemTest : public testing::Test { |
| 28 base::ScopedTempDir temp_dir_; | 23 protected: |
| 29 }; | 24 virtual void SetUp() { |
| 30 | 25 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 31 // Simple function to dump some text into a new file. | |
| 32 void CreateTextFile(const std::wstring& filename, | |
| 33 const std::wstring& contents) { | |
| 34 std::ofstream file; | |
| 35 file.open(filename.c_str()); | |
| 36 ASSERT_TRUE(file.is_open()); | |
| 37 file << contents; | |
| 38 file.close(); | |
| 39 } | 26 } |
| 40 | 27 |
| 41 wchar_t text_content_1[] = L"delete me"; | 28 // The temporary directory used to contain the test operations. |
| 42 wchar_t text_content_2[] = L"delete me as well"; | 29 base::ScopedTempDir temp_dir_; |
| 43 }; | 30 }; |
| 44 | 31 |
| 32 // Simple function to dump some text into a new file. |
| 33 void CreateTextFile(const std::wstring& filename, |
| 34 const std::wstring& contents) { |
| 35 std::ofstream file; |
| 36 file.open(filename.c_str()); |
| 37 ASSERT_TRUE(file.is_open()); |
| 38 file << contents; |
| 39 file.close(); |
| 40 } |
| 41 |
| 42 const wchar_t text_content_1[] = L"delete me"; |
| 43 |
| 44 } // namespace |
| 45 |
| 45 // Delete a tree without key path. Everything should be deleted. | 46 // Delete a tree without key path. Everything should be deleted. |
| 46 TEST_F(DeleteTreeWorkItemTest, DeleteTreeNoKeyPath) { | 47 TEST_F(DeleteTreeWorkItemTest, DeleteTreeNoKeyPath) { |
| 47 // Create tree to be deleted. | 48 // Create tree to be deleted. |
| 48 base::FilePath dir_name_delete(temp_dir_.path()); | 49 base::FilePath dir_name_delete(temp_dir_.path()); |
| 49 dir_name_delete = dir_name_delete.AppendASCII("to_be_delete"); | 50 dir_name_delete = dir_name_delete.AppendASCII("to_be_delete"); |
| 50 base::CreateDirectory(dir_name_delete); | 51 base::CreateDirectory(dir_name_delete); |
| 51 ASSERT_TRUE(base::PathExists(dir_name_delete)); | 52 ASSERT_TRUE(base::PathExists(dir_name_delete)); |
| 52 | 53 |
| 53 base::FilePath dir_name_delete_1(dir_name_delete); | 54 base::FilePath dir_name_delete_1(dir_name_delete); |
| 54 dir_name_delete_1 = dir_name_delete_1.AppendASCII("1"); | 55 dir_name_delete_1 = dir_name_delete_1.AppendASCII("1"); |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 | 212 |
| 212 // verify everything is still there. | 213 // verify everything is still there. |
| 213 EXPECT_TRUE(base::PathExists(key_path)); | 214 EXPECT_TRUE(base::PathExists(key_path)); |
| 214 EXPECT_TRUE(base::PathExists(file_name_delete_1)); | 215 EXPECT_TRUE(base::PathExists(file_name_delete_1)); |
| 215 EXPECT_TRUE(base::PathExists(file_name_delete_2)); | 216 EXPECT_TRUE(base::PathExists(file_name_delete_2)); |
| 216 | 217 |
| 217 TerminateProcess(pi.hProcess, 0); | 218 TerminateProcess(pi.hProcess, 0); |
| 218 // make sure the handle is closed. | 219 // make sure the handle is closed. |
| 219 WaitForSingleObject(pi.hProcess, INFINITE); | 220 WaitForSingleObject(pi.hProcess, INFINITE); |
| 220 } | 221 } |
| OLD | NEW |