This source file includes following definitions.
- SetUp
- TearDown
- CreateTextFile
- IsFileInUse
- ReadTextFile
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
#include <windows.h>
#include <fstream>
#include "base/base_paths.h"
#include "base/file_util.h"
#include "base/files/scoped_temp_dir.h"
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
#include "base/path_service.h"
#include "base/strings/string_util.h"
#include "base/threading/platform_thread.h"
#include "chrome/installer/util/copy_tree_work_item.h"
#include "chrome/installer/util/work_item.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace {
class CopyTreeWorkItemTest : public testing::Test {
protected:
virtual void SetUp() {
ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
ASSERT_TRUE(test_dir_.CreateUniqueTempDir());
}
virtual void TearDown() {
logging::CloseLogFile();
}
base::ScopedTempDir test_dir_;
base::ScopedTempDir temp_dir_;
};
void CreateTextFile(const std::wstring& filename,
const std::wstring& contents) {
std::ofstream file;
file.open(filename.c_str());
ASSERT_TRUE(file.is_open());
file << contents;
file.close();
}
bool IsFileInUse(const base::FilePath& path) {
if (!base::PathExists(path))
return false;
HANDLE handle = ::CreateFile(path.value().c_str(), FILE_ALL_ACCESS,
NULL, NULL, OPEN_EXISTING, NULL, NULL);
if (handle == INVALID_HANDLE_VALUE)
return true;
CloseHandle(handle);
return false;
}
std::wstring ReadTextFile(const std::wstring& filename) {
WCHAR contents[64];
std::wifstream file;
file.open(filename.c_str());
EXPECT_TRUE(file.is_open());
file.getline(contents, 64);
file.close();
return std::wstring(contents);
}
wchar_t text_content_1[] = L"Gooooooooooooooooooooogle";
wchar_t text_content_2[] = L"Overwrite Me";
};
TEST_F(CopyTreeWorkItemTest, CopyFile) {
base::FilePath file_name_from(test_dir_.path());
file_name_from = file_name_from.AppendASCII("File_From.txt");
CreateTextFile(file_name_from.value(), text_content_1);
ASSERT_TRUE(base::PathExists(file_name_from));
base::FilePath dir_name_to(test_dir_.path());
dir_name_to = dir_name_to.AppendASCII("Copy_To_Subdir");
base::CreateDirectory(dir_name_to);
ASSERT_TRUE(base::PathExists(dir_name_to));
base::FilePath file_name_to(dir_name_to);
file_name_to = file_name_to.AppendASCII("File_To.txt");
scoped_ptr<CopyTreeWorkItem> work_item(
WorkItem::CreateCopyTreeWorkItem(file_name_from,
file_name_to,
temp_dir_.path(),
WorkItem::ALWAYS,
base::FilePath()));
EXPECT_TRUE(work_item->Do());
EXPECT_TRUE(base::PathExists(file_name_from));
EXPECT_TRUE(base::PathExists(file_name_to));
EXPECT_TRUE(base::ContentsEqual(file_name_from, file_name_to));
work_item->Rollback();
EXPECT_FALSE(base::PathExists(file_name_to));
EXPECT_TRUE(base::PathExists(file_name_from));
}
TEST_F(CopyTreeWorkItemTest, CopyFileOverwrite) {
base::FilePath file_name_from(test_dir_.path());
file_name_from = file_name_from.AppendASCII("File_From.txt");
CreateTextFile(file_name_from.value(), text_content_1);
ASSERT_TRUE(base::PathExists(file_name_from));
base::FilePath dir_name_to(test_dir_.path());
dir_name_to = dir_name_to.AppendASCII("Copy_To_Subdir");
base::CreateDirectory(dir_name_to);
ASSERT_TRUE(base::PathExists(dir_name_to));
base::FilePath file_name_to(dir_name_to);
file_name_to = file_name_to.AppendASCII("File_To.txt");
CreateTextFile(file_name_to.value(), text_content_2);
ASSERT_TRUE(base::PathExists(file_name_to));
scoped_ptr<CopyTreeWorkItem> work_item(
WorkItem::CreateCopyTreeWorkItem(file_name_from,
file_name_to,
temp_dir_.path(),
WorkItem::ALWAYS,
base::FilePath()));
EXPECT_TRUE(work_item->Do());
EXPECT_TRUE(base::PathExists(file_name_from));
EXPECT_TRUE(base::PathExists(file_name_to));
EXPECT_EQ(0, ReadTextFile(file_name_from.value()).compare(text_content_1));
EXPECT_EQ(0, ReadTextFile(file_name_to.value()).compare(text_content_1));
work_item->Rollback();
EXPECT_TRUE(base::PathExists(file_name_from));
EXPECT_TRUE(base::PathExists(file_name_to));
EXPECT_EQ(0, ReadTextFile(file_name_from.value()).compare(text_content_1));
EXPECT_EQ(0, ReadTextFile(file_name_to.value()).compare(text_content_2));
work_item.reset(
WorkItem::CreateCopyTreeWorkItem(file_name_from,
file_name_to,
temp_dir_.path(),
WorkItem::IF_DIFFERENT,
base::FilePath()));
EXPECT_TRUE(work_item->Do());
EXPECT_TRUE(base::PathExists(file_name_from));
EXPECT_TRUE(base::PathExists(file_name_to));
EXPECT_EQ(0, ReadTextFile(file_name_from.value()).compare(text_content_1));
EXPECT_EQ(0, ReadTextFile(file_name_to.value()).compare(text_content_1));
work_item->Rollback();
EXPECT_TRUE(base::PathExists(file_name_from));
EXPECT_TRUE(base::PathExists(file_name_to));
EXPECT_EQ(0, ReadTextFile(file_name_from.value()).compare(text_content_1));
EXPECT_EQ(0, ReadTextFile(file_name_to.value()).compare(text_content_2));
}
TEST_F(CopyTreeWorkItemTest, CopyFileSameContent) {
base::FilePath file_name_from(test_dir_.path());
file_name_from = file_name_from.AppendASCII("File_From.txt");
CreateTextFile(file_name_from.value(), text_content_1);
ASSERT_TRUE(base::PathExists(file_name_from));
base::FilePath dir_name_to(test_dir_.path());
dir_name_to = dir_name_to.AppendASCII("Copy_To_Subdir");
base::CreateDirectory(dir_name_to);
ASSERT_TRUE(base::PathExists(dir_name_to));
base::FilePath file_name_to(dir_name_to);
file_name_to = file_name_to.AppendASCII("File_To.txt");
CreateTextFile(file_name_to.value(), text_content_1);
ASSERT_TRUE(base::PathExists(file_name_to));
scoped_ptr<CopyTreeWorkItem> work_item(
WorkItem::CreateCopyTreeWorkItem(file_name_from,
file_name_to,
temp_dir_.path(),
WorkItem::ALWAYS,
base::FilePath()));
EXPECT_TRUE(work_item->Do());
base::FilePath backup_file(work_item->backup_path_.path());
EXPECT_FALSE(backup_file.empty());
backup_file = backup_file.AppendASCII("File_To.txt");
EXPECT_TRUE(base::PathExists(file_name_from));
EXPECT_TRUE(base::PathExists(file_name_to));
EXPECT_EQ(0, ReadTextFile(file_name_from.value()).compare(text_content_1));
EXPECT_EQ(0, ReadTextFile(file_name_to.value()).compare(text_content_1));
EXPECT_TRUE(base::PathExists(backup_file));
EXPECT_EQ(0, ReadTextFile(backup_file.value()).compare(text_content_1));
work_item->Rollback();
EXPECT_TRUE(base::PathExists(file_name_from));
EXPECT_TRUE(base::PathExists(file_name_to));
EXPECT_EQ(0, ReadTextFile(file_name_from.value()).compare(text_content_1));
EXPECT_EQ(0, ReadTextFile(file_name_to.value()).compare(text_content_1));
EXPECT_FALSE(base::PathExists(backup_file));
work_item.reset(
WorkItem::CreateCopyTreeWorkItem(file_name_from,
file_name_to,
temp_dir_.path(),
WorkItem::IF_DIFFERENT,
base::FilePath()));
EXPECT_TRUE(work_item->Do());
EXPECT_TRUE(base::PathExists(file_name_from));
EXPECT_TRUE(base::PathExists(file_name_to));
EXPECT_EQ(0, ReadTextFile(file_name_from.value()).compare(text_content_1));
EXPECT_EQ(0, ReadTextFile(file_name_to.value()).compare(text_content_1));
EXPECT_FALSE(base::PathExists(backup_file));
work_item->Rollback();
EXPECT_TRUE(base::PathExists(file_name_from));
EXPECT_TRUE(base::PathExists(file_name_to));
EXPECT_EQ(0, ReadTextFile(file_name_from.value()).compare(text_content_1));
EXPECT_EQ(0, ReadTextFile(file_name_to.value()).compare(text_content_1));
EXPECT_FALSE(base::PathExists(backup_file));
}
TEST_F(CopyTreeWorkItemTest, CopyFileAndCleanup) {
base::FilePath file_name_from(test_dir_.path());
file_name_from = file_name_from.AppendASCII("File_From.txt");
CreateTextFile(file_name_from.value(), text_content_1);
ASSERT_TRUE(base::PathExists(file_name_from));
base::FilePath dir_name_to(test_dir_.path());
dir_name_to = dir_name_to.AppendASCII("Copy_To_Subdir");
base::CreateDirectory(dir_name_to);
ASSERT_TRUE(base::PathExists(dir_name_to));
base::FilePath file_name_to(dir_name_to);
file_name_to = file_name_to.AppendASCII("File_To.txt");
CreateTextFile(file_name_to.value(), text_content_2);
ASSERT_TRUE(base::PathExists(file_name_to));
base::FilePath backup_file;
{
scoped_ptr<CopyTreeWorkItem> work_item(
WorkItem::CreateCopyTreeWorkItem(file_name_from,
file_name_to,
temp_dir_.path(),
WorkItem::IF_DIFFERENT,
base::FilePath()));
EXPECT_TRUE(work_item->Do());
backup_file = work_item->backup_path_.path();
EXPECT_FALSE(backup_file.empty());
backup_file = backup_file.AppendASCII("File_To.txt");
EXPECT_TRUE(base::PathExists(file_name_from));
EXPECT_TRUE(base::PathExists(file_name_to));
EXPECT_EQ(0, ReadTextFile(file_name_from.value()).compare(text_content_1));
EXPECT_EQ(0, ReadTextFile(file_name_to.value()).compare(text_content_1));
EXPECT_TRUE(base::PathExists(backup_file));
EXPECT_EQ(0, ReadTextFile(backup_file.value()).compare(text_content_2));
}
EXPECT_FALSE(base::PathExists(backup_file));
}
TEST_F(CopyTreeWorkItemTest, CopyFileInUse) {
base::FilePath file_name_from(test_dir_.path());
file_name_from = file_name_from.AppendASCII("File_From");
CreateTextFile(file_name_from.value(), text_content_1);
ASSERT_TRUE(base::PathExists(file_name_from));
wchar_t exe_full_path_str[MAX_PATH];
::GetModuleFileName(NULL, exe_full_path_str, MAX_PATH);
base::FilePath exe_full_path(exe_full_path_str);
base::FilePath dir_name_to(test_dir_.path());
dir_name_to = dir_name_to.AppendASCII("Copy_To_Subdir");
base::CreateDirectory(dir_name_to);
ASSERT_TRUE(base::PathExists(dir_name_to));
base::FilePath file_name_to(dir_name_to);
file_name_to = file_name_to.AppendASCII("File_To");
base::CopyFile(exe_full_path, file_name_to);
ASSERT_TRUE(base::PathExists(file_name_to));
VLOG(1) << "copy ourself from " << exe_full_path.value()
<< " to " << file_name_to.value();
STARTUPINFOW si = {sizeof(si)};
PROCESS_INFORMATION pi = {0};
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));
scoped_ptr<CopyTreeWorkItem> work_item(
WorkItem::CreateCopyTreeWorkItem(file_name_from,
file_name_to,
temp_dir_.path(),
WorkItem::IF_DIFFERENT,
base::FilePath()));
EXPECT_TRUE(work_item->Do());
base::FilePath backup_file(work_item->backup_path_.path());
EXPECT_FALSE(backup_file.empty());
backup_file = backup_file.AppendASCII("File_To");
EXPECT_TRUE(base::PathExists(file_name_from));
EXPECT_TRUE(base::PathExists(file_name_to));
EXPECT_EQ(0, ReadTextFile(file_name_from.value()).compare(text_content_1));
EXPECT_EQ(0, ReadTextFile(file_name_to.value()).compare(text_content_1));
EXPECT_TRUE(base::PathExists(backup_file));
EXPECT_TRUE(base::ContentsEqual(exe_full_path, backup_file));
work_item->Rollback();
EXPECT_TRUE(base::PathExists(file_name_from));
EXPECT_TRUE(base::PathExists(file_name_to));
EXPECT_EQ(0, ReadTextFile(file_name_from.value()).compare(text_content_1));
EXPECT_TRUE(base::ContentsEqual(exe_full_path, file_name_to));
EXPECT_FALSE(base::PathExists(backup_file));
TerminateProcess(pi.hProcess, 0);
EXPECT_TRUE(WaitForSingleObject(pi.hProcess, 10000) == WAIT_OBJECT_0);
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
}
TEST_F(CopyTreeWorkItemTest, NewNameAndCopyTest) {
base::FilePath file_name_from(test_dir_.path());
file_name_from = file_name_from.AppendASCII("File_From");
CreateTextFile(file_name_from.value(), text_content_1);
ASSERT_TRUE(base::PathExists(file_name_from));
wchar_t exe_full_path_str[MAX_PATH];
::GetModuleFileName(NULL, exe_full_path_str, MAX_PATH);
base::FilePath exe_full_path(exe_full_path_str);
base::FilePath dir_name_to(test_dir_.path());
dir_name_to = dir_name_to.AppendASCII("Copy_To_Subdir");
base::CreateDirectory(dir_name_to);
ASSERT_TRUE(base::PathExists(dir_name_to));
base::FilePath file_name_to(dir_name_to), alternate_to(dir_name_to);
file_name_to = file_name_to.AppendASCII("File_To");
alternate_to = alternate_to.AppendASCII("Alternate_To");
base::CopyFile(exe_full_path, file_name_to);
ASSERT_TRUE(base::PathExists(file_name_to));
VLOG(1) << "copy ourself from " << exe_full_path.value()
<< " to " << file_name_to.value();
STARTUPINFOW si = {sizeof(si)};
PROCESS_INFORMATION pi = {0};
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));
scoped_ptr<CopyTreeWorkItem> work_item(
WorkItem::CreateCopyTreeWorkItem(file_name_from,
file_name_to,
temp_dir_.path(),
WorkItem::NEW_NAME_IF_IN_USE,
alternate_to));
EXPECT_TRUE(work_item->Do());
EXPECT_TRUE(base::PathExists(file_name_from));
EXPECT_TRUE(base::PathExists(file_name_to));
EXPECT_EQ(0, ReadTextFile(file_name_from.value()).compare(text_content_1));
EXPECT_TRUE(base::ContentsEqual(exe_full_path, file_name_to));
EXPECT_TRUE(work_item->backup_path_.path().empty());
EXPECT_TRUE(base::ContentsEqual(file_name_from, alternate_to));
work_item->Rollback();
EXPECT_TRUE(base::PathExists(file_name_from));
EXPECT_TRUE(base::PathExists(file_name_to));
EXPECT_EQ(0, ReadTextFile(file_name_from.value()).compare(text_content_1));
EXPECT_TRUE(base::ContentsEqual(exe_full_path, file_name_to));
EXPECT_TRUE(work_item->backup_path_.path().empty());
EXPECT_FALSE(base::PathExists(alternate_to));
TerminateProcess(pi.hProcess, 0);
EXPECT_TRUE(WaitForSingleObject(pi.hProcess, 10000) == WAIT_OBJECT_0);
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
work_item.reset(WorkItem::CreateCopyTreeWorkItem(
file_name_from, file_name_to,
temp_dir_.path(), WorkItem::NEW_NAME_IF_IN_USE,
alternate_to));
if (IsFileInUse(file_name_to))
base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(2));
ASSERT_FALSE(IsFileInUse(file_name_to));
EXPECT_TRUE(work_item->Do());
base::FilePath backup_file(work_item->backup_path_.path());
EXPECT_FALSE(backup_file.empty());
backup_file = backup_file.AppendASCII("File_To");
EXPECT_TRUE(base::PathExists(file_name_from));
EXPECT_TRUE(base::PathExists(file_name_to));
EXPECT_EQ(0, ReadTextFile(file_name_from.value()).compare(text_content_1));
EXPECT_TRUE(base::ContentsEqual(file_name_from, file_name_to));
EXPECT_TRUE(base::PathExists(backup_file));
EXPECT_FALSE(base::PathExists(alternate_to));
work_item->Rollback();
EXPECT_TRUE(base::PathExists(file_name_from));
EXPECT_TRUE(base::PathExists(file_name_to));
EXPECT_EQ(0, ReadTextFile(file_name_from.value()).compare(text_content_1));
EXPECT_TRUE(base::ContentsEqual(exe_full_path, file_name_to));
EXPECT_FALSE(base::PathExists(backup_file));
EXPECT_FALSE(base::PathExists(alternate_to));
}
TEST_F(CopyTreeWorkItemTest, DISABLED_IfNotPresentTest) {
base::FilePath file_name_from(test_dir_.path());
file_name_from = file_name_from.AppendASCII("File_From");
CreateTextFile(file_name_from.value(), text_content_1);
ASSERT_TRUE(base::PathExists(file_name_from));
wchar_t exe_full_path_str[MAX_PATH];
::GetModuleFileName(NULL, exe_full_path_str, MAX_PATH);
base::FilePath exe_full_path(exe_full_path_str);
base::FilePath dir_name_to(test_dir_.path());
dir_name_to = dir_name_to.AppendASCII("Copy_To_Subdir");
base::CreateDirectory(dir_name_to);
ASSERT_TRUE(base::PathExists(dir_name_to));
base::FilePath file_name_to(dir_name_to);
file_name_to = file_name_to.AppendASCII("File_To");
base::CopyFile(exe_full_path, file_name_to);
ASSERT_TRUE(base::PathExists(file_name_to));
base::FilePath backup_file(temp_dir_.path());
backup_file = backup_file.AppendASCII("File_To");
scoped_ptr<CopyTreeWorkItem> work_item(
WorkItem::CreateCopyTreeWorkItem(
file_name_from,
file_name_to, temp_dir_.path(),
WorkItem::IF_NOT_PRESENT,
base::FilePath()));
EXPECT_TRUE(work_item->Do());
EXPECT_TRUE(base::PathExists(file_name_from));
EXPECT_TRUE(base::PathExists(file_name_to));
EXPECT_EQ(0, ReadTextFile(file_name_from.value()).compare(text_content_1));
EXPECT_TRUE(base::ContentsEqual(exe_full_path, file_name_to));
EXPECT_FALSE(base::PathExists(backup_file));
work_item->Rollback();
EXPECT_TRUE(base::PathExists(file_name_from));
EXPECT_TRUE(base::PathExists(file_name_to));
EXPECT_EQ(0, ReadTextFile(file_name_from.value()).compare(text_content_1));
EXPECT_TRUE(base::ContentsEqual(exe_full_path, file_name_to));
EXPECT_FALSE(base::PathExists(backup_file));
base::DeleteFile(file_name_to, true);
work_item.reset(WorkItem::CreateCopyTreeWorkItem(
file_name_from, file_name_to,
temp_dir_.path(), WorkItem::IF_NOT_PRESENT,
base::FilePath()));
EXPECT_TRUE(work_item->Do());
EXPECT_TRUE(base::PathExists(file_name_from));
EXPECT_TRUE(base::PathExists(file_name_to));
EXPECT_EQ(0, ReadTextFile(file_name_from.value()).compare(text_content_1));
EXPECT_EQ(0, ReadTextFile(file_name_to.value()).compare(text_content_1));
EXPECT_FALSE(base::PathExists(backup_file));
work_item->Rollback();
EXPECT_TRUE(base::PathExists(file_name_from));
EXPECT_FALSE(base::PathExists(file_name_to));
EXPECT_EQ(0, ReadTextFile(file_name_from.value()).compare(text_content_1));
EXPECT_FALSE(base::PathExists(backup_file));
}
TEST_F(CopyTreeWorkItemTest, DISABLED_CopyFileInUseAndCleanup) {
base::FilePath file_name_from(test_dir_.path());
file_name_from = file_name_from.AppendASCII("File_From");
CreateTextFile(file_name_from.value(), text_content_1);
ASSERT_TRUE(base::PathExists(file_name_from));
wchar_t exe_full_path_str[MAX_PATH];
::GetModuleFileName(NULL, exe_full_path_str, MAX_PATH);
base::FilePath exe_full_path(exe_full_path_str);
base::FilePath dir_name_to(test_dir_.path());
dir_name_to = dir_name_to.AppendASCII("Copy_To_Subdir");
base::CreateDirectory(dir_name_to);
ASSERT_TRUE(base::PathExists(dir_name_to));
base::FilePath file_name_to(dir_name_to);
file_name_to = file_name_to.AppendASCII("File_To");
base::CopyFile(exe_full_path, file_name_to);
ASSERT_TRUE(base::PathExists(file_name_to));
VLOG(1) << "copy ourself from " << exe_full_path.value()
<< " to " << file_name_to.value();
STARTUPINFOW si = {sizeof(si)};
PROCESS_INFORMATION pi = {0};
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));
base::FilePath backup_file;
{
scoped_ptr<CopyTreeWorkItem> work_item(
WorkItem::CreateCopyTreeWorkItem(file_name_from,
file_name_to,
temp_dir_.path(),
WorkItem::IF_DIFFERENT,
base::FilePath()));
EXPECT_TRUE(work_item->Do());
backup_file = work_item->backup_path_.path();
EXPECT_FALSE(backup_file.empty());
backup_file = backup_file.AppendASCII("File_To");
EXPECT_TRUE(base::PathExists(file_name_from));
EXPECT_TRUE(base::PathExists(file_name_to));
EXPECT_EQ(0, ReadTextFile(file_name_from.value()).compare(text_content_1));
EXPECT_EQ(0, ReadTextFile(file_name_to.value()).compare(text_content_1));
EXPECT_TRUE(base::PathExists(backup_file));
EXPECT_TRUE(base::ContentsEqual(exe_full_path, backup_file));
}
EXPECT_TRUE(base::PathExists(backup_file));
EXPECT_TRUE(base::ContentsEqual(exe_full_path, backup_file));
TerminateProcess(pi.hProcess, 0);
EXPECT_TRUE(WaitForSingleObject(pi.hProcess, 10000) == WAIT_OBJECT_0);
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
}
TEST_F(CopyTreeWorkItemTest, DISABLED_CopyTree) {
base::FilePath dir_name_from(test_dir_.path());
dir_name_from = dir_name_from.AppendASCII("from");
base::CreateDirectory(dir_name_from);
ASSERT_TRUE(base::PathExists(dir_name_from));
base::FilePath dir_name_from_1(dir_name_from);
dir_name_from_1 = dir_name_from_1.AppendASCII("1");
base::CreateDirectory(dir_name_from_1);
ASSERT_TRUE(base::PathExists(dir_name_from_1));
base::FilePath dir_name_from_2(dir_name_from);
dir_name_from_2 = dir_name_from_2.AppendASCII("2");
base::CreateDirectory(dir_name_from_2);
ASSERT_TRUE(base::PathExists(dir_name_from_2));
base::FilePath file_name_from_1(dir_name_from_1);
file_name_from_1 = file_name_from_1.AppendASCII("File_1.txt");
CreateTextFile(file_name_from_1.value(), text_content_1);
ASSERT_TRUE(base::PathExists(file_name_from_1));
base::FilePath file_name_from_2(dir_name_from_2);
file_name_from_2 = file_name_from_2.AppendASCII("File_2.txt");
CreateTextFile(file_name_from_2.value(), text_content_1);
ASSERT_TRUE(base::PathExists(file_name_from_2));
base::FilePath dir_name_to(test_dir_.path());
dir_name_to = dir_name_to.AppendASCII("to");
{
scoped_ptr<CopyTreeWorkItem> work_item(
WorkItem::CreateCopyTreeWorkItem(dir_name_from,
dir_name_to,
temp_dir_.path(),
WorkItem::ALWAYS,
base::FilePath()));
EXPECT_TRUE(work_item->Do());
}
base::FilePath file_name_to_1(dir_name_to);
file_name_to_1 = file_name_to_1.AppendASCII("1");
file_name_to_1 = file_name_to_1.AppendASCII("File_1.txt");
EXPECT_TRUE(base::PathExists(file_name_to_1));
VLOG(1) << "compare " << file_name_from_1.value()
<< " and " << file_name_to_1.value();
EXPECT_TRUE(base::ContentsEqual(file_name_from_1, file_name_to_1));
base::FilePath file_name_to_2(dir_name_to);
file_name_to_2 = file_name_to_2.AppendASCII("2");
file_name_to_2 = file_name_to_2.AppendASCII("File_2.txt");
EXPECT_TRUE(base::PathExists(file_name_to_2));
VLOG(1) << "compare " << file_name_from_2.value()
<< " and " << file_name_to_2.value();
EXPECT_TRUE(base::ContentsEqual(file_name_from_2, file_name_to_2));
}