| 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 b9a2dac350c04dfade7ca431e4793db8b7bead33..8b33e4409ab44a075254f22a8316db36720ae9fb 100644
|
| --- a/chrome/installer/util/copy_tree_work_item_unittest.cc
|
| +++ b/chrome/installer/util/copy_tree_work_item_unittest.cc
|
| @@ -11,6 +11,7 @@
|
| #include "base/file_util.h"
|
| #include "base/logging.h"
|
| #include "base/path_service.h"
|
| +#include "base/platform_thread.h"
|
| #include "base/process_util.h"
|
| #include "base/scoped_ptr.h"
|
| #include "base/string_util.h"
|
| @@ -61,6 +62,19 @@ namespace {
|
| file.close();
|
| }
|
|
|
| + bool IsFileInUse(std::wstring path) {
|
| + if (!file_util::PathExists(path))
|
| + return false;
|
| +
|
| + HANDLE handle = ::CreateFile(path.c_str(), FILE_ALL_ACCESS,
|
| + NULL, NULL, OPEN_EXISTING, NULL, NULL);
|
| + if (handle == INVALID_HANDLE_VALUE)
|
| + return true;
|
| +
|
| + CloseHandle(handle);
|
| + return false;
|
| + }
|
| +
|
| // Simple function to read text from a file.
|
| std::wstring ReadTextFile(const std::wstring& filename) {
|
| WCHAR contents[64];
|
| @@ -446,6 +460,10 @@ TEST_F(CopyTreeWorkItemTest, NewNameAndCopyTest) {
|
| work_item.reset(WorkItem::CreateCopyTreeWorkItem(
|
| file_name_from, file_name_to, temp_dir_, WorkItem::NEW_NAME_IF_IN_USE,
|
| alternate_to));
|
| + if (IsFileInUse(file_name_to))
|
| + PlatformThread::Sleep(2000);
|
| + // If file is still in use, the rest of the test will fail.
|
| + ASSERT_FALSE(IsFileInUse(file_name_to));
|
| EXPECT_TRUE(work_item->Do());
|
|
|
| EXPECT_TRUE(file_util::PathExists(file_name_from));
|
|
|