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

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

Issue 6793008: Replacing base::DIR_TEMP with ScopedTempDir when appropriate. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: About a third of the way done. Created 9 years, 8 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 96aa32b5375837aa8e3b7049d6aaf6875410599b..8660c74081e93e6d99d2aa88bd3d920b7132425a 100644
--- a/chrome/installer/util/copy_tree_work_item_unittest.cc
+++ b/chrome/installer/util/copy_tree_work_item_unittest.cc
@@ -10,6 +10,7 @@
#include "base/file_util.h"
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
+#include "base/memory/scoped_temp_dir.h"
#include "base/path_service.h"
#include "base/process_util.h"
#include "base/string_util.h"
@@ -22,32 +23,17 @@ namespace {
class CopyTreeWorkItemTest : public testing::Test {
protected:
virtual void SetUp() {
- // Name a subdirectory of the user temp directory.
- ASSERT_TRUE(PathService::Get(base::DIR_TEMP, &test_dir_));
- test_dir_ = test_dir_.AppendASCII("CopyTreeWorkItemTest");
-
- // Create a fresh, empty copy of this test directory.
- file_util::Delete(test_dir_, true);
- file_util::CreateDirectoryW(test_dir_);
-
- // Create a tempory directory under the test directory.
- temp_dir_ = test_dir_.AppendASCII("temp");
- file_util::CreateDirectoryW(temp_dir_);
-
- ASSERT_TRUE(file_util::PathExists(test_dir_));
- ASSERT_TRUE(file_util::PathExists(temp_dir_));
+ ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
+ ASSERT_TRUE(test_dir_.CreateUniqueTempDir());
}
virtual void TearDown() {
logging::CloseLogFile();
- // Clean up test directory
- ASSERT_TRUE(file_util::Delete(test_dir_, true));
- ASSERT_FALSE(file_util::PathExists(test_dir_));
}
// the path to temporary directory used to contain the test operations
- FilePath test_dir_;
- FilePath temp_dir_;
+ ScopedTempDir test_dir_;
+ ScopedTempDir temp_dir_;
};
// Simple function to dump some text into a new file.
@@ -91,13 +77,13 @@ namespace {
// Copy one file from source to destination.
TEST_F(CopyTreeWorkItemTest, CopyFile) {
// Create source file
- FilePath file_name_from(test_dir_);
+ 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(file_util::PathExists(file_name_from));
// Create destination path
- FilePath dir_name_to(test_dir_);
+ FilePath dir_name_to(test_dir_.path());
dir_name_to = dir_name_to.AppendASCII("Copy_To_Subdir");
file_util::CreateDirectory(dir_name_to);
ASSERT_TRUE(file_util::PathExists(dir_name_to));
@@ -109,7 +95,7 @@ TEST_F(CopyTreeWorkItemTest, CopyFile) {
scoped_ptr<CopyTreeWorkItem> work_item(
WorkItem::CreateCopyTreeWorkItem(file_name_from,
file_name_to,
- temp_dir_,
+ temp_dir_.path(),
WorkItem::ALWAYS,
FilePath()));
@@ -131,13 +117,13 @@ TEST_F(CopyTreeWorkItemTest, CopyFile) {
// regardless since the content at destination file is different from source.
TEST_F(CopyTreeWorkItemTest, CopyFileOverwrite) {
// Create source file
- FilePath file_name_from(test_dir_);
+ 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(file_util::PathExists(file_name_from));
// Create destination file
- FilePath dir_name_to(test_dir_);
+ FilePath dir_name_to(test_dir_.path());
dir_name_to = dir_name_to.AppendASCII("Copy_To_Subdir");
file_util::CreateDirectory(dir_name_to);
ASSERT_TRUE(file_util::PathExists(dir_name_to));
@@ -151,7 +137,7 @@ TEST_F(CopyTreeWorkItemTest, CopyFileOverwrite) {
scoped_ptr<CopyTreeWorkItem> work_item(
WorkItem::CreateCopyTreeWorkItem(file_name_from,
file_name_to,
- temp_dir_,
+ temp_dir_.path(),
WorkItem::ALWAYS,
FilePath()));
@@ -175,7 +161,7 @@ TEST_F(CopyTreeWorkItemTest, CopyFileOverwrite) {
work_item.reset(
WorkItem::CreateCopyTreeWorkItem(file_name_from,
file_name_to,
- temp_dir_,
+ temp_dir_.path(),
WorkItem::IF_DIFFERENT,
FilePath()));
@@ -201,13 +187,13 @@ TEST_F(CopyTreeWorkItemTest, CopyFileOverwrite) {
// If always_overwrite being false, the file is unchanged.
TEST_F(CopyTreeWorkItemTest, CopyFileSameContent) {
// Create source file
- FilePath file_name_from(test_dir_);
+ 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(file_util::PathExists(file_name_from));
// Create destination file
- FilePath dir_name_to(test_dir_);
+ FilePath dir_name_to(test_dir_.path());
dir_name_to = dir_name_to.AppendASCII("Copy_To_Subdir");
file_util::CreateDirectory(dir_name_to);
ASSERT_TRUE(file_util::PathExists(dir_name_to));
@@ -221,7 +207,7 @@ TEST_F(CopyTreeWorkItemTest, CopyFileSameContent) {
scoped_ptr<CopyTreeWorkItem> work_item(
WorkItem::CreateCopyTreeWorkItem(file_name_from,
file_name_to,
- temp_dir_,
+ temp_dir_.path(),
WorkItem::ALWAYS,
FilePath()));
@@ -255,7 +241,7 @@ TEST_F(CopyTreeWorkItemTest, CopyFileSameContent) {
work_item.reset(
WorkItem::CreateCopyTreeWorkItem(file_name_from,
file_name_to,
- temp_dir_,
+ temp_dir_.path(),
WorkItem::IF_DIFFERENT,
FilePath()));
@@ -282,13 +268,13 @@ TEST_F(CopyTreeWorkItemTest, CopyFileSameContent) {
// Copy one file and without rollback. Verify all temporary files are deleted.
TEST_F(CopyTreeWorkItemTest, CopyFileAndCleanup) {
// Create source file
- FilePath file_name_from(test_dir_);
+ 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(file_util::PathExists(file_name_from));
// Create destination file
- FilePath dir_name_to(test_dir_);
+ FilePath dir_name_to(test_dir_.path());
dir_name_to = dir_name_to.AppendASCII("Copy_To_Subdir");
file_util::CreateDirectory(dir_name_to);
ASSERT_TRUE(file_util::PathExists(dir_name_to));
@@ -305,7 +291,7 @@ TEST_F(CopyTreeWorkItemTest, CopyFileAndCleanup) {
scoped_ptr<CopyTreeWorkItem> work_item(
WorkItem::CreateCopyTreeWorkItem(file_name_from,
file_name_to,
- temp_dir_,
+ temp_dir_.path(),
WorkItem::IF_DIFFERENT,
FilePath()));
@@ -334,7 +320,7 @@ TEST_F(CopyTreeWorkItemTest, CopyFileAndCleanup) {
// be moved to backup location after Do() and moved back after Rollback().
TEST_F(CopyTreeWorkItemTest, CopyFileInUse) {
// Create source file
- FilePath file_name_from(test_dir_);
+ 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(file_util::PathExists(file_name_from));
@@ -344,7 +330,7 @@ TEST_F(CopyTreeWorkItemTest, CopyFileInUse) {
::GetModuleFileName(NULL, exe_full_path_str, MAX_PATH);
FilePath exe_full_path(exe_full_path_str);
- FilePath dir_name_to(test_dir_);
+ FilePath dir_name_to(test_dir_.path());
dir_name_to = dir_name_to.AppendASCII("Copy_To_Subdir");
file_util::CreateDirectory(dir_name_to);
ASSERT_TRUE(file_util::PathExists(dir_name_to));
@@ -369,7 +355,7 @@ TEST_F(CopyTreeWorkItemTest, CopyFileInUse) {
scoped_ptr<CopyTreeWorkItem> work_item(
WorkItem::CreateCopyTreeWorkItem(file_name_from,
file_name_to,
- temp_dir_,
+ temp_dir_.path(),
WorkItem::IF_DIFFERENT,
FilePath()));
@@ -413,7 +399,7 @@ TEST_F(CopyTreeWorkItemTest, CopyFileInUse) {
// destination folder after Do() and should be rolled back after Rollback().
TEST_F(CopyTreeWorkItemTest, NewNameAndCopyTest) {
// Create source file
- FilePath file_name_from(test_dir_);
+ 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(file_util::PathExists(file_name_from));
@@ -423,7 +409,7 @@ TEST_F(CopyTreeWorkItemTest, NewNameAndCopyTest) {
::GetModuleFileName(NULL, exe_full_path_str, MAX_PATH);
FilePath exe_full_path(exe_full_path_str);
- FilePath dir_name_to(test_dir_);
+ FilePath dir_name_to(test_dir_.path());
dir_name_to = dir_name_to.AppendASCII("Copy_To_Subdir");
file_util::CreateDirectory(dir_name_to);
ASSERT_TRUE(file_util::PathExists(dir_name_to));
@@ -449,7 +435,7 @@ TEST_F(CopyTreeWorkItemTest, NewNameAndCopyTest) {
scoped_ptr<CopyTreeWorkItem> work_item(
WorkItem::CreateCopyTreeWorkItem(file_name_from,
file_name_to,
- temp_dir_,
+ temp_dir_.path(),
WorkItem::NEW_NAME_IF_IN_USE,
alternate_to));
@@ -483,7 +469,7 @@ TEST_F(CopyTreeWorkItemTest, NewNameAndCopyTest) {
// Now the process has terminated, lets try overwriting the file again
work_item.reset(WorkItem::CreateCopyTreeWorkItem(
file_name_from, file_name_to,
- temp_dir_, WorkItem::NEW_NAME_IF_IN_USE,
+ temp_dir_.path(), WorkItem::NEW_NAME_IF_IN_USE,
alternate_to));
if (IsFileInUse(file_name_to))
base::PlatformThread::Sleep(2000);
@@ -524,7 +510,7 @@ TEST_F(CopyTreeWorkItemTest, NewNameAndCopyTest) {
// Flaky, http://crbug.com/59785.
TEST_F(CopyTreeWorkItemTest, FLAKY_IfNotPresentTest) {
// Create source file
- FilePath file_name_from(test_dir_);
+ 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(file_util::PathExists(file_name_from));
@@ -534,7 +520,7 @@ TEST_F(CopyTreeWorkItemTest, FLAKY_IfNotPresentTest) {
::GetModuleFileName(NULL, exe_full_path_str, MAX_PATH);
FilePath exe_full_path(exe_full_path_str);
- FilePath dir_name_to(test_dir_);
+ FilePath dir_name_to(test_dir_.path());
dir_name_to = dir_name_to.AppendASCII("Copy_To_Subdir");
file_util::CreateDirectory(dir_name_to);
ASSERT_TRUE(file_util::PathExists(dir_name_to));
@@ -544,14 +530,14 @@ TEST_F(CopyTreeWorkItemTest, FLAKY_IfNotPresentTest) {
ASSERT_TRUE(file_util::PathExists(file_name_to));
// Get the path of backup file
- FilePath backup_file(temp_dir_);
+ FilePath backup_file(temp_dir_.path());
backup_file = backup_file.AppendASCII("File_To");
// test Do().
scoped_ptr<CopyTreeWorkItem> work_item(
WorkItem::CreateCopyTreeWorkItem(
file_name_from,
- file_name_to, temp_dir_,
+ file_name_to, temp_dir_.path(),
WorkItem::IF_NOT_PRESENT,
FilePath()));
EXPECT_TRUE(work_item->Do());
@@ -579,7 +565,7 @@ TEST_F(CopyTreeWorkItemTest, FLAKY_IfNotPresentTest) {
file_util::Delete(file_name_to, true);
work_item.reset(WorkItem::CreateCopyTreeWorkItem(
file_name_from, file_name_to,
- temp_dir_, WorkItem::IF_NOT_PRESENT,
+ temp_dir_.path(), WorkItem::IF_NOT_PRESENT,
FilePath()));
EXPECT_TRUE(work_item->Do());
@@ -606,7 +592,7 @@ TEST_F(CopyTreeWorkItemTest, FLAKY_IfNotPresentTest) {
// Flaky, http://crbug.com/59783.
TEST_F(CopyTreeWorkItemTest, FLAKY_CopyFileInUseAndCleanup) {
// Create source file
- FilePath file_name_from(test_dir_);
+ 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(file_util::PathExists(file_name_from));
@@ -616,7 +602,7 @@ TEST_F(CopyTreeWorkItemTest, FLAKY_CopyFileInUseAndCleanup) {
::GetModuleFileName(NULL, exe_full_path_str, MAX_PATH);
FilePath exe_full_path(exe_full_path_str);
- FilePath dir_name_to(test_dir_);
+ FilePath dir_name_to(test_dir_.path());
dir_name_to = dir_name_to.AppendASCII("Copy_To_Subdir");
file_util::CreateDirectory(dir_name_to);
ASSERT_TRUE(file_util::PathExists(dir_name_to));
@@ -644,7 +630,7 @@ TEST_F(CopyTreeWorkItemTest, FLAKY_CopyFileInUseAndCleanup) {
scoped_ptr<CopyTreeWorkItem> work_item(
WorkItem::CreateCopyTreeWorkItem(file_name_from,
file_name_to,
- temp_dir_,
+ temp_dir_.path(),
WorkItem::IF_DIFFERENT,
FilePath()));
@@ -679,7 +665,7 @@ TEST_F(CopyTreeWorkItemTest, FLAKY_CopyFileInUseAndCleanup) {
// Flaky, http://crbug.com/59784.
TEST_F(CopyTreeWorkItemTest, FLAKY_CopyTree) {
// Create source tree
- FilePath dir_name_from(test_dir_);
+ FilePath dir_name_from(test_dir_.path());
dir_name_from = dir_name_from.AppendASCII("from");
file_util::CreateDirectory(dir_name_from);
ASSERT_TRUE(file_util::PathExists(dir_name_from));
@@ -704,7 +690,7 @@ TEST_F(CopyTreeWorkItemTest, FLAKY_CopyTree) {
CreateTextFile(file_name_from_2.value(), text_content_1);
ASSERT_TRUE(file_util::PathExists(file_name_from_2));
- FilePath dir_name_to(test_dir_);
+ FilePath dir_name_to(test_dir_.path());
dir_name_to = dir_name_to.AppendASCII("to");
// test Do()
@@ -712,7 +698,7 @@ TEST_F(CopyTreeWorkItemTest, FLAKY_CopyTree) {
scoped_ptr<CopyTreeWorkItem> work_item(
WorkItem::CreateCopyTreeWorkItem(dir_name_from,
dir_name_to,
- temp_dir_,
+ temp_dir_.path(),
WorkItem::ALWAYS,
FilePath()));

Powered by Google App Engine
This is Rietveld 408576698