summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authormkwst@chromium.org <mkwst@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-12 13:40:53 +0000
committermkwst@chromium.org <mkwst@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-12 13:40:53 +0000
commit3a305db06850635febc42acc54b65a93bf5739c7 (patch)
tree1e79d71199dd8bf13c31b94ee53a25c3afd1fe6b /chrome
parentca0269fee674ebe4f233ae7f1efa91f503a8c784 (diff)
downloadchromium_src-3a305db06850635febc42acc54b65a93bf5739c7.zip
chromium_src-3a305db06850635febc42acc54b65a93bf5739c7.tar.gz
chromium_src-3a305db06850635febc42acc54b65a93bf5739c7.tar.bz2
Replacing base::DIR_TEMP with ScopedTempDir when appropriate.
BUG=73854 TEST=unit_tests Review URL: http://codereview.chromium.org/6793008 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@81245 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/bookmarks/bookmark_html_writer_unittest.cc13
-rw-r--r--chrome/browser/download/save_package_unittest.cc17
-rw-r--r--chrome/browser/extensions/extension_browsertest.cc9
-rw-r--r--chrome/browser/extensions/extension_browsertest.h4
-rw-r--r--chrome/browser/extensions/extension_service_unittest.cc6
-rw-r--r--chrome/browser/extensions/sandboxed_extension_unpacker_unittest.cc37
-rw-r--r--chrome/browser/extensions/user_script_master_unittest.cc33
-rw-r--r--chrome/browser/history/starred_url_database_unittest.cc7
-rw-r--r--chrome/browser/history/text_database_unittest.cc20
-rw-r--r--chrome/browser/history/url_database_unittest.cc13
-rw-r--r--chrome/browser/history/visit_database_unittest.cc14
-rw-r--r--chrome/browser/importer/firefox_profile_lock_unittest.cc19
-rw-r--r--chrome/browser/importer/importer_unittest.cc25
-rw-r--r--chrome/browser/prefs/pref_service_uitest.cc22
-rw-r--r--chrome/browser/profiles/profile_manager_unittest.cc30
-rw-r--r--chrome/browser/safe_browsing/bloom_filter_unittest.cc11
-rw-r--r--chrome/browser/sessions/session_service_unittest.cc6
-rw-r--r--chrome/browser/ui/tests/browser_uitest.cc19
-rw-r--r--chrome/common/extensions/extension_unpacker_unittest.cc17
-rw-r--r--chrome/common/json_pref_store_unittest.cc28
-rw-r--r--chrome/common/json_value_serializer_unittest.cc24
-rw-r--r--chrome/installer/util/copy_tree_work_item_unittest.cc88
-rw-r--r--chrome/installer/util/create_dir_work_item_unittest.cc25
-rw-r--r--chrome/installer/util/delete_tree_work_item_unittest.cc30
-rw-r--r--chrome/installer/util/lzma_util_unittest.cc25
-rw-r--r--chrome/installer/util/move_tree_work_item_unittest.cc66
-rw-r--r--chrome/installer/util/shell_util_unittest.cc27
-rw-r--r--chrome/installer/util/work_item_list_unittest.cc23
28 files changed, 242 insertions, 416 deletions
diff --git a/chrome/browser/bookmarks/bookmark_html_writer_unittest.cc b/chrome/browser/bookmarks/bookmark_html_writer_unittest.cc
index 720445a..f203a04 100644
--- a/chrome/browser/bookmarks/bookmark_html_writer_unittest.cc
+++ b/chrome/browser/bookmarks/bookmark_html_writer_unittest.cc
@@ -12,6 +12,7 @@
#include "base/time.h"
#include "base/utf_string_conversions.h"
#include "base/i18n/time_formatting.h"
+#include "base/memory/scoped_temp_dir.h"
#include "chrome/browser/bookmarks/bookmark_html_writer.h"
#include "chrome/browser/bookmarks/bookmark_model.h"
#include "chrome/browser/importer/firefox2_importer.h"
@@ -43,14 +44,9 @@ void MakeTestSkBitmap(int w, int h, SkBitmap* bmp) {
class BookmarkHTMLWriterTest : public TestingBrowserProcessTest {
protected:
virtual void SetUp() {
- ASSERT_TRUE(PathService::Get(base::DIR_TEMP, &path_));
- path_ = path_.AppendASCII("bookmarks.html");
- file_util::Delete(path_, true);
- }
-
- virtual void TearDown() {
- if (!path_.empty())
- file_util::Delete(path_, true);
+ TestingBrowserProcessTest::SetUp();
+ ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
+ path_ = temp_dir_.path().AppendASCII("bookmarks.html");
}
// Converts a BookmarkEntry to a string suitable for assertion testing.
@@ -120,6 +116,7 @@ class BookmarkHTMLWriterTest : public TestingBrowserProcessTest {
BookmarkEntryToString(entry));
}
+ ScopedTempDir temp_dir_;
FilePath path_;
};
diff --git a/chrome/browser/download/save_package_unittest.cc b/chrome/browser/download/save_package_unittest.cc
index f4b7578..4d5ba54 100644
--- a/chrome/browser/download/save_package_unittest.cc
+++ b/chrome/browser/download/save_package_unittest.cc
@@ -6,6 +6,7 @@
#include "base/file_path.h"
#include "base/path_service.h"
+#include "base/memory/scoped_temp_dir.h"
#include "base/string_util.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/download/save_package.h"
@@ -98,22 +99,22 @@ class SavePackageTest : public RenderViewHostTestHarness {
// Do the initialization in SetUp so contents() is initialized by
// RenderViewHostTestHarness::SetUp.
- FilePath test_dir;
- PathService::Get(base::DIR_TEMP, &test_dir);
+ ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
save_package_success_ = new SavePackage(contents(),
- test_dir.AppendASCII("testfile" HTML_EXTENSION),
- test_dir.AppendASCII("testfile_files"));
+ temp_dir_.path().AppendASCII("testfile" HTML_EXTENSION),
+ temp_dir_.path().AppendASCII("testfile_files"));
// We need to construct a path that is *almost* kMaxFilePathLength long
long_file_name.resize(kMaxFilePathLength + long_file_name.length());
while (long_file_name.length() < kMaxFilePathLength)
long_file_name += long_file_name;
- long_file_name.resize(kMaxFilePathLength - 9 - test_dir.value().length());
+ long_file_name.resize(
+ kMaxFilePathLength - 9 - temp_dir_.path().value().length());
save_package_fail_ = new SavePackage(contents(),
- test_dir.AppendASCII(long_file_name + HTML_EXTENSION),
- test_dir.AppendASCII(long_file_name + "_files"));
+ temp_dir_.path().AppendASCII(long_file_name + HTML_EXTENSION),
+ temp_dir_.path().AppendASCII(long_file_name + "_files"));
}
private:
@@ -122,6 +123,8 @@ class SavePackageTest : public RenderViewHostTestHarness {
// SavePackage for failed generating file name.
scoped_refptr<SavePackage> save_package_fail_;
+ ScopedTempDir temp_dir_;
+
DISALLOW_COPY_AND_ASSIGN(SavePackageTest);
};
diff --git a/chrome/browser/extensions/extension_browsertest.cc b/chrome/browser/extensions/extension_browsertest.cc
index f897a29..a93ffe2 100644
--- a/chrome/browser/extensions/extension_browsertest.cc
+++ b/chrome/browser/extensions/extension_browsertest.cc
@@ -11,6 +11,7 @@
#include "base/file_util.h"
#include "base/path_service.h"
#include "base/string_number_conversions.h"
+#include "base/memory/scoped_temp_dir.h"
#include "chrome/browser/extensions/crx_installer.h"
#include "chrome/browser/extensions/extension_creator.h"
#include "chrome/browser/extensions/extension_error_reporter.h"
@@ -34,6 +35,7 @@ ExtensionBrowserTest::ExtensionBrowserTest()
extension_installs_observed_(0),
target_page_action_count_(-1),
target_visible_page_action_count_(-1) {
+ EXPECT_TRUE(temp_dir_.CreateUniqueTempDir());
}
void ExtensionBrowserTest::SetUpCommandLine(CommandLine* command_line) {
@@ -126,12 +128,7 @@ bool ExtensionBrowserTest::LoadExtensionAsComponent(const FilePath& path) {
}
FilePath ExtensionBrowserTest::PackExtension(const FilePath& dir_path) {
- FilePath crx_path;
- if (!PathService::Get(base::DIR_TEMP, &crx_path)) {
- ADD_FAILURE() << "Failed to get DIR_TEMP from PathService.";
- return FilePath();
- }
- crx_path = crx_path.AppendASCII("temp.crx");
+ FilePath crx_path = temp_dir_.path().AppendASCII("temp.crx");
if (!file_util::Delete(crx_path, false)) {
ADD_FAILURE() << "Failed to delete crx: " << crx_path.value();
return FilePath();
diff --git a/chrome/browser/extensions/extension_browsertest.h b/chrome/browser/extensions/extension_browsertest.h
index 22fb6c6..2fda271 100644
--- a/chrome/browser/extensions/extension_browsertest.h
+++ b/chrome/browser/extensions/extension_browsertest.h
@@ -10,6 +10,7 @@
#include "base/command_line.h"
#include "base/file_path.h"
+#include "base/memory/scoped_temp_dir.h"
#include "chrome/test/in_process_browser_test.h"
#include "content/common/notification_details.h"
#include "content/common/notification_observer.h"
@@ -122,6 +123,9 @@ class ExtensionBrowserTest
int extension_installs_observed_;
private:
+ // Temporary directory for testing.
+ ScopedTempDir temp_dir_;
+
// Specifies the type of UI (if any) to show during installation and what
// user action to simulate.
enum InstallUIType {
diff --git a/chrome/browser/extensions/extension_service_unittest.cc b/chrome/browser/extensions/extension_service_unittest.cc
index ec73155..9c5f77c 100644
--- a/chrome/browser/extensions/extension_service_unittest.cc
+++ b/chrome/browser/extensions/extension_service_unittest.cc
@@ -13,6 +13,7 @@
#include "base/file_util.h"
#include "base/json/json_reader.h"
#include "base/memory/scoped_ptr.h"
+#include "base/memory/scoped_temp_dir.h"
#include "base/message_loop.h"
#include "base/path_service.h"
#include "base/stl_util-inl.h"
@@ -519,8 +520,9 @@ class ExtensionServiceTest
const FilePath& pem_path,
bool should_succeed) {
FilePath crx_path;
- ASSERT_TRUE(PathService::Get(base::DIR_TEMP, &crx_path));
- crx_path = crx_path.AppendASCII("temp.crx");
+ ScopedTempDir temp_dir;
+ ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
+ crx_path = temp_dir_.path().AppendASCII("temp.crx");
// Use the existing pem key, if provided.
FilePath pem_output_path;
diff --git a/chrome/browser/extensions/sandboxed_extension_unpacker_unittest.cc b/chrome/browser/extensions/sandboxed_extension_unpacker_unittest.cc
index 973845a..2c6e063 100644
--- a/chrome/browser/extensions/sandboxed_extension_unpacker_unittest.cc
+++ b/chrome/browser/extensions/sandboxed_extension_unpacker_unittest.cc
@@ -7,6 +7,7 @@
#include "base/memory/scoped_temp_dir.h"
#include "base/path_service.h"
#include "base/string_util.h"
+#include "base/memory/scoped_temp_dir.h"
#include "chrome/browser/extensions/sandboxed_extension_unpacker.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/extensions/extension.h"
@@ -54,6 +55,7 @@ class MockSandboxedExtensionUnpackerClient
class SandboxedExtensionUnpackerTest : public testing::Test {
public:
virtual void SetUp() {
+ ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
file_thread_.reset(new BrowserThread(BrowserThread::FILE, &loop_));
// It will delete itself.
client_ = new MockSandboxedExtensionUnpackerClient;
@@ -65,9 +67,6 @@ class SandboxedExtensionUnpackerTest : public testing::Test {
// it posts a task to it.
sandboxed_unpacker_ = NULL;
loop_.RunAllPending();
- // Clean up finally.
- ASSERT_TRUE(file_util::Delete(install_dir_, true)) <<
- install_dir_.value();
}
void SetupUnpacker(const std::string& crx_name) {
@@ -78,15 +77,10 @@ class SandboxedExtensionUnpackerTest : public testing::Test {
.AppendASCII(crx_name);
ASSERT_TRUE(file_util::PathExists(original_path)) << original_path.value();
- // Try bots won't let us write into DIR_TEST_DATA, so we have to create
- // a temp folder to play in.
- ASSERT_TRUE(PathService::Get(base::DIR_TEMP, &install_dir_));
- install_dir_ =
- install_dir_.AppendASCII("sandboxed_extension_unpacker_test");
- file_util::Delete(install_dir_, true);
- file_util::CreateDirectory(install_dir_);
-
- FilePath crx_path = install_dir_.AppendASCII(crx_name);
+ // Try bots won't let us write into DIR_TEST_DATA, so we have to write the
+ // CRX to the temp directory, and create a subdirectory into which to
+ // unpack it.
+ FilePath crx_path = temp_dir_.path().AppendASCII(crx_name);
ASSERT_TRUE(file_util::CopyFile(original_path, crx_path)) <<
"Original path: " << original_path.value() <<
", Crx path: " << crx_path.value();
@@ -94,9 +88,9 @@ class SandboxedExtensionUnpackerTest : public testing::Test {
unpacker_.reset(new ExtensionUnpacker(crx_path));
// Build a temp area where the extension will be unpacked.
- ASSERT_TRUE(PathService::Get(base::DIR_TEMP, &temp_dir_));
- temp_dir_ = temp_dir_.AppendASCII("sandboxed_extension_unpacker_test_Temp");
- ASSERT_TRUE(file_util::CreateDirectory(temp_dir_));
+ temp_path_ =
+ temp_dir_.path().AppendASCII("sandboxed_extension_unpacker_test_Temp");
+ ASSERT_TRUE(file_util::CreateDirectory(temp_path_));
sandboxed_unpacker_ =
new SandboxedExtensionUnpacker(crx_path, NULL, client_);
@@ -109,9 +103,9 @@ class SandboxedExtensionUnpackerTest : public testing::Test {
bool PrepareUnpackerEnv() {
sandboxed_unpacker_->extension_root_ =
- install_dir_.AppendASCII(extension_filenames::kTempExtensionName);
+ temp_dir_.path().AppendASCII(extension_filenames::kTempExtensionName);
- if (!sandboxed_unpacker_->temp_dir_.Set(install_dir_))
+ if (!sandboxed_unpacker_->temp_dir_.Set(temp_dir_.path()))
return false;
sandboxed_unpacker_->public_key_ =
"ocnapchkplbmjmpfehjocmjnipfmogkh";
@@ -124,7 +118,8 @@ class SandboxedExtensionUnpackerTest : public testing::Test {
}
FilePath GetInstallPath() {
- return install_dir_.AppendASCII(extension_filenames::kTempExtensionName);
+ return temp_dir_.path().AppendASCII(
+ extension_filenames::kTempExtensionName);
}
bool TempFilesRemoved() {
@@ -135,7 +130,7 @@ class SandboxedExtensionUnpackerTest : public testing::Test {
file_util::FileEnumerator::FILES);
file_util::FileEnumerator temp_iterator(
- temp_dir_,
+ temp_path_,
true, // recursive
files_and_dirs
);
@@ -152,8 +147,8 @@ class SandboxedExtensionUnpackerTest : public testing::Test {
}
protected:
- FilePath install_dir_;
- FilePath temp_dir_;
+ ScopedTempDir temp_dir_;
+ FilePath temp_path_;
MockSandboxedExtensionUnpackerClient* client_;
scoped_ptr<ExtensionUnpacker> unpacker_;
scoped_refptr<SandboxedExtensionUnpacker> sandboxed_unpacker_;
diff --git a/chrome/browser/extensions/user_script_master_unittest.cc b/chrome/browser/extensions/user_script_master_unittest.cc
index 2bbfa66..14cc21b 100644
--- a/chrome/browser/extensions/user_script_master_unittest.cc
+++ b/chrome/browser/extensions/user_script_master_unittest.cc
@@ -11,6 +11,7 @@
#include "base/message_loop.h"
#include "base/path_service.h"
#include "base/string_util.h"
+#include "base/memory/scoped_temp_dir.h"
#include "chrome/test/testing_profile.h"
#include "content/browser/browser_thread.h"
#include "content/common/notification_registrar.h"
@@ -29,14 +30,7 @@ class UserScriptMasterTest : public testing::Test,
}
virtual void SetUp() {
- // Name a subdirectory of the temp directory.
- FilePath tmp_dir;
- ASSERT_TRUE(PathService::Get(base::DIR_TEMP, &tmp_dir));
- script_dir_ = tmp_dir.AppendASCII("UserScriptTest");
-
- // Create a fresh, empty copy of this directory.
- file_util::Delete(script_dir_, true);
- file_util::CreateDirectory(script_dir_);
+ ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
// Register for all user script notifications.
registrar_.Add(this, NotificationType::USER_SCRIPTS_UPDATED,
@@ -49,9 +43,6 @@ class UserScriptMasterTest : public testing::Test,
}
virtual void TearDown() {
- // Clean up test directory.
- ASSERT_TRUE(file_util::Delete(script_dir_, true));
- ASSERT_FALSE(file_util::PathExists(script_dir_));
file_thread_.reset();
}
@@ -65,6 +56,9 @@ class UserScriptMasterTest : public testing::Test,
MessageLoop::current()->Quit();
}
+ // Directory containing user scripts.
+ ScopedTempDir temp_dir_;
+
NotificationRegistrar registrar_;
// MessageLoop used in tests.
@@ -72,9 +66,6 @@ class UserScriptMasterTest : public testing::Test,
scoped_ptr<BrowserThread> file_thread_;
- // Directory containing user scripts.
- FilePath script_dir_;
-
// Updated to the script shared memory when we get notified.
base::SharedMemory* shared_memory_;
};
@@ -82,7 +73,7 @@ class UserScriptMasterTest : public testing::Test,
// Test that we get notified even when there are no scripts.
TEST_F(UserScriptMasterTest, NoScripts) {
TestingProfile profile;
- scoped_refptr<UserScriptMaster> master(new UserScriptMaster(script_dir_,
+ scoped_refptr<UserScriptMaster> master(new UserScriptMaster(temp_dir_.path(),
&profile));
master->StartScan();
message_loop_.PostTask(FROM_HERE, new MessageLoop::QuitTask);
@@ -94,13 +85,13 @@ TEST_F(UserScriptMasterTest, NoScripts) {
// Test that we get notified about scripts if they're already in the test dir.
TEST_F(UserScriptMasterTest, ExistingScripts) {
TestingProfile profile;
- FilePath path = script_dir_.AppendASCII("script.user.js");
+ FilePath path = temp_dir_.path().AppendASCII("script.user.js");
const char content[] = "some content";
size_t written = file_util::WriteFile(path, content, sizeof(content));
ASSERT_EQ(written, sizeof(content));
- scoped_refptr<UserScriptMaster> master(new UserScriptMaster(script_dir_,
+ scoped_refptr<UserScriptMaster> master(new UserScriptMaster(temp_dir_.path(),
&profile));
master->StartScan();
@@ -222,7 +213,7 @@ TEST_F(UserScriptMasterTest, Parse7) {
}
TEST_F(UserScriptMasterTest, SkipBOMAtTheBeginning) {
- FilePath path = script_dir_.AppendASCII("script.user.js");
+ FilePath path = temp_dir_.path().AppendASCII("script.user.js");
const std::string content(
"\xEF\xBB\xBF// ==UserScript==\n"
@@ -233,7 +224,7 @@ TEST_F(UserScriptMasterTest, SkipBOMAtTheBeginning) {
UserScriptList script_list;
UserScriptMaster::ScriptReloader::LoadScriptsFromDirectory(
- script_dir_, &script_list);
+ temp_dir_.path(), &script_list);
ASSERT_EQ(1U, script_list.size());
EXPECT_EQ(content.substr(3),
@@ -243,7 +234,7 @@ TEST_F(UserScriptMasterTest, SkipBOMAtTheBeginning) {
}
TEST_F(UserScriptMasterTest, LeaveBOMNotAtTheBeginning) {
- FilePath path = script_dir_.AppendASCII("script.user.js");
+ FilePath path = temp_dir_.path().AppendASCII("script.user.js");
const std::string content(
"// ==UserScript==\n"
@@ -255,7 +246,7 @@ TEST_F(UserScriptMasterTest, LeaveBOMNotAtTheBeginning) {
UserScriptList script_list;
UserScriptMaster::ScriptReloader::LoadScriptsFromDirectory(
- script_dir_, &script_list);
+ temp_dir_.path(), &script_list);
ASSERT_EQ(1U, script_list.size());
EXPECT_EQ(content, script_list[0].js_scripts()[0].GetContent().as_string());
diff --git a/chrome/browser/history/starred_url_database_unittest.cc b/chrome/browser/history/starred_url_database_unittest.cc
index 5bf0e22..70d0f77 100644
--- a/chrome/browser/history/starred_url_database_unittest.cc
+++ b/chrome/browser/history/starred_url_database_unittest.cc
@@ -7,6 +7,7 @@
#include "base/file_util.h"
#include "base/path_service.h"
#include "base/string_util.h"
+#include "base/memory/scoped_temp_dir.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/history/history.h"
#include "chrome/browser/history/starred_url_database.h"
@@ -65,8 +66,8 @@ class StarredURLDatabaseTest : public testing::Test,
private:
// Test setup.
void SetUp() {
- PathService::Get(base::DIR_TEMP, &db_file_);
- db_file_ = db_file_.AppendASCII("VisitTest.db");
+ ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
+ db_file_ = temp_dir_.path().AppendASCII("VisitTest.db");
file_util::Delete(db_file_, false);
// Copy db file over that contains starred table.
@@ -86,7 +87,6 @@ class StarredURLDatabaseTest : public testing::Test,
}
void TearDown() {
db_.Close();
- file_util::Delete(db_file_, false);
}
// Provided for URL/StarredURLDatabase.
@@ -94,6 +94,7 @@ class StarredURLDatabaseTest : public testing::Test,
return db_;
}
+ ScopedTempDir temp_dir_;
FilePath db_file_;
sql::Connection db_;
};
diff --git a/chrome/browser/history/text_database_unittest.cc b/chrome/browser/history/text_database_unittest.cc
index fb94eba..3564c82 100644
--- a/chrome/browser/history/text_database_unittest.cc
+++ b/chrome/browser/history/text_database_unittest.cc
@@ -6,7 +6,7 @@
#include "base/file_util.h"
#include "base/memory/scoped_ptr.h"
-#include "base/path_service.h"
+#include "base/memory/scoped_temp_dir.h"
#include "base/string_util.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/history/text_database.h"
@@ -92,14 +92,7 @@ class TextDatabaseTest : public PlatformTest {
protected:
void SetUp() {
PlatformTest::SetUp();
- PathService::Get(base::DIR_TEMP, &temp_path_);
- }
-
- void TearDown() {
- for (size_t i = 0; i < opened_files_.size(); i++)
- file_util::Delete(opened_files_[i], false);
- file_util::Delete(file_name_, false);
- PlatformTest::TearDown();
+ ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
}
// Create databases with this function, which will ensure that the files are
@@ -112,7 +105,7 @@ class TextDatabaseTest : public PlatformTest {
TextDatabase* CreateDB(TextDatabase::DBIdent id,
bool allow_create,
bool delete_file) {
- TextDatabase* db = new TextDatabase(temp_path_, id, allow_create);
+ TextDatabase* db = new TextDatabase(temp_dir_.path(), id, allow_create);
if (delete_file)
file_util::Delete(db->file_name(), false);
@@ -121,17 +114,14 @@ class TextDatabaseTest : public PlatformTest {
delete db;
return NULL;
}
- opened_files_.push_back(db->file_name());
return db;
}
// Directory containing the databases.
- FilePath temp_path_;
+ ScopedTempDir temp_dir_;
// Name of the main database file.
FilePath file_name_;
-
- std::vector<FilePath> opened_files_;
};
TEST_F(TextDatabaseTest, AttachDetach) {
@@ -183,7 +173,7 @@ TEST_F(TextDatabaseTest, AddRemove) {
EXPECT_EQ(2, RowCount(db.get()));
// Close and reopen.
- db.reset(new TextDatabase(temp_path_, kIdee1, false));
+ db.reset(new TextDatabase(temp_dir_.path(), kIdee1, false));
EXPECT_TRUE(db->Init());
// Verify that the deleted ID is gone and try to delete another one.
diff --git a/chrome/browser/history/url_database_unittest.cc b/chrome/browser/history/url_database_unittest.cc
index a8e53c5..121950d 100644
--- a/chrome/browser/history/url_database_unittest.cc
+++ b/chrome/browser/history/url_database_unittest.cc
@@ -1,10 +1,11 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "app/sql/connection.h"
#include "base/file_path.h"
#include "base/file_util.h"
+#include "base/memory/scoped_temp_dir.h"
#include "base/path_service.h"
#include "base/string_util.h"
#include "base/utf_string_conversions.h"
@@ -47,11 +48,10 @@ class URLDatabaseTest : public testing::Test,
private:
// Test setup.
void SetUp() {
- FilePath temp_dir;
- PathService::Get(base::DIR_TEMP, &temp_dir);
- db_file_ = temp_dir.AppendASCII("URLTest.db");
+ ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
+ FilePath db_file = temp_dir_.path().AppendASCII("URLTest.db");
- EXPECT_TRUE(db_.Open(db_file_));
+ EXPECT_TRUE(db_.Open(db_file));
// Initialize the tables for this test.
CreateURLTable(false);
@@ -61,10 +61,9 @@ class URLDatabaseTest : public testing::Test,
}
void TearDown() {
db_.Close();
- file_util::Delete(db_file_, false);
}
- FilePath db_file_;
+ ScopedTempDir temp_dir_;
sql::Connection db_;
};
diff --git a/chrome/browser/history/visit_database_unittest.cc b/chrome/browser/history/visit_database_unittest.cc
index 1cf1868..f5fd80b 100644
--- a/chrome/browser/history/visit_database_unittest.cc
+++ b/chrome/browser/history/visit_database_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -7,6 +7,7 @@
#include "base/file_util.h"
#include "base/path_service.h"
#include "base/string_util.h"
+#include "base/memory/scoped_temp_dir.h"
#include "chrome/browser/history/url_database.h"
#include "chrome/browser/history/visit_database.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -42,12 +43,10 @@ class VisitDatabaseTest : public PlatformTest,
// Test setup.
void SetUp() {
PlatformTest::SetUp();
- FilePath temp_dir;
- PathService::Get(base::DIR_TEMP, &temp_dir);
- db_file_ = temp_dir.AppendASCII("VisitTest.db");
- file_util::Delete(db_file_, false);
+ ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
+ FilePath db_file = temp_dir_.path().AppendASCII("VisitTest.db");
- EXPECT_TRUE(db_.Open(db_file_));
+ EXPECT_TRUE(db_.Open(db_file));
// Initialize the tables for this test.
CreateURLTable(false);
@@ -56,7 +55,6 @@ class VisitDatabaseTest : public PlatformTest,
}
void TearDown() {
db_.Close();
- file_util::Delete(db_file_, false);
PlatformTest::TearDown();
}
@@ -65,7 +63,7 @@ class VisitDatabaseTest : public PlatformTest,
return db_;
}
- FilePath db_file_;
+ ScopedTempDir temp_dir_;
sql::Connection db_;
};
diff --git a/chrome/browser/importer/firefox_profile_lock_unittest.cc b/chrome/browser/importer/firefox_profile_lock_unittest.cc
index bd3e1ec..aa6898a 100644
--- a/chrome/browser/importer/firefox_profile_lock_unittest.cc
+++ b/chrome/browser/importer/firefox_profile_lock_unittest.cc
@@ -6,6 +6,7 @@
#include "base/path_service.h"
#include "base/process_util.h"
#include "base/string_util.h"
+#include "base/memory/scoped_temp_dir.h"
#include "build/build_config.h"
#include "chrome/browser/importer/firefox_profile_lock.h"
#include "chrome/common/chrome_paths.h"
@@ -13,28 +14,16 @@
#include "testing/gtest/include/gtest/gtest.h"
class FirefoxProfileLockTest : public testing::Test {
- public:
protected:
virtual void SetUp() {
- ASSERT_TRUE(PathService::Get(base::DIR_TEMP, &test_path_));
- FilePath::StringType dir_name = FILE_PATH_LITERAL("FirefoxProfileLockTest");
- dir_name.append(StringPrintf(
- FILE_PATH_LITERAL("-%d"), base::GetCurrentProcId()));
- test_path_ = test_path_.Append(dir_name);
- file_util::Delete(test_path_, true);
- file_util::CreateDirectory(test_path_);
+ ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
}
- virtual void TearDown() {
- ASSERT_TRUE(file_util::Delete(test_path_, true));
- ASSERT_FALSE(file_util::PathExists(test_path_));
- }
-
- FilePath test_path_;
+ ScopedTempDir temp_dir_;
};
TEST_F(FirefoxProfileLockTest, LockTest) {
- FirefoxProfileLock lock1(test_path_);
+ FirefoxProfileLock lock1(temp_dir_.path());
ASSERT_TRUE(lock1.HasAcquired());
lock1.Unlock();
ASSERT_FALSE(lock1.HasAcquired());
diff --git a/chrome/browser/importer/importer_unittest.cc b/chrome/browser/importer/importer_unittest.cc
index becc373..f0f190a 100644
--- a/chrome/browser/importer/importer_unittest.cc
+++ b/chrome/browser/importer/importer_unittest.cc
@@ -24,6 +24,7 @@
#include "base/stl_util-inl.h"
#include "base/string_util.h"
#include "base/utf_string_conversions.h"
+#include "base/memory/scoped_temp_dir.h"
#include "chrome/browser/history/history_types.h"
#include "chrome/browser/importer/importer_bridge.h"
#include "chrome/browser/importer/importer_data_types.h"
@@ -58,21 +59,15 @@ class ImporterTest : public testing::Test {
protected:
virtual void SetUp() {
// Creates a new profile in a new subdirectory in the temp directory.
- ASSERT_TRUE(PathService::Get(base::DIR_TEMP, &test_path_));
- test_path_ = test_path_.AppendASCII("ImporterTest");
- file_util::Delete(test_path_, true);
- file_util::CreateDirectory(test_path_);
- profile_path_ = test_path_.AppendASCII("profile");
- app_path_ = test_path_.AppendASCII("app");
+ ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
+ FilePath test_path = temp_dir_.path().AppendASCII("ImporterTest");
+ file_util::Delete(test_path, true);
+ file_util::CreateDirectory(test_path);
+ profile_path_ = test_path.AppendASCII("profile");
+ app_path_ = test_path.AppendASCII("app");
file_util::CreateDirectory(app_path_);
}
- virtual void TearDown() {
- // Deletes the profile and cleans up the profile directory.
- ASSERT_TRUE(file_util::Delete(test_path_, true));
- ASSERT_FALSE(file_util::PathExists(test_path_));
- }
-
void Firefox3xImporterTest(std::string profile_dir,
importer::ImporterProgressObserver* observer,
ProfileWriter* writer,
@@ -116,10 +111,10 @@ class ImporterTest : public testing::Test {
loop->Run();
}
+ ScopedTempDir temp_dir_;
MessageLoopForUI message_loop_;
BrowserThread ui_thread_;
BrowserThread file_thread_;
- FilePath test_path_;
FilePath profile_path_;
FilePath app_path_;
};
@@ -332,7 +327,7 @@ void WritePStore(IPStore* pstore, const GUID* type, const GUID* subtype) {
TEST_F(ImporterTest, IEImporter) {
// Sets up a favorites folder.
app::win::ScopedCOMInitializer com_init;
- std::wstring path = test_path_.AppendASCII("Favorites").value();
+ std::wstring path = temp_dir_.path().AppendASCII("Favorites").value();
CreateDirectory(path.c_str(), NULL);
CreateDirectory((path + L"\\SubFolder").c_str(), NULL);
CreateDirectory((path + L"\\Links").c_str(), NULL);
@@ -396,7 +391,7 @@ TEST_F(ImporterTest, IEImporter) {
host->SetObserver(observer);
importer::SourceProfile source_profile;
source_profile.importer_type = importer::MS_IE;
- source_profile.source_path = test_path_;
+ source_profile.source_path = temp_dir_.path();
loop->PostTask(FROM_HERE, NewRunnableMethod(host.get(),
&ImporterHost::StartImportSettings,
diff --git a/chrome/browser/prefs/pref_service_uitest.cc b/chrome/browser/prefs/pref_service_uitest.cc
index fe2a79a..11a5856 100644
--- a/chrome/browser/prefs/pref_service_uitest.cc
+++ b/chrome/browser/prefs/pref_service_uitest.cc
@@ -6,9 +6,9 @@
#include "base/command_line.h"
#include "base/file_util.h"
-#include "base/path_service.h"
#include "base/test/test_file_util.h"
#include "base/values.h"
+#include "base/memory/scoped_temp_dir.h"
#include "build/build_config.h"
#include "chrome/common/chrome_constants.h"
#include "chrome/common/chrome_switches.h"
@@ -22,12 +22,10 @@
class PreferenceServiceTest : public UITest {
public:
void SetUp() {
- PathService::Get(base::DIR_TEMP, &tmp_profile_);
- tmp_profile_ = tmp_profile_.AppendASCII("tmp_profile");
+ ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
+ FilePath tmp_profile = temp_dir_.path().AppendASCII("tmp_profile");
- // Create a fresh, empty copy of this directory.
- file_util::Delete(tmp_profile_, true);
- file_util::CreateDirectory(tmp_profile_);
+ ASSERT_TRUE(file_util::CreateDirectory(tmp_profile));
FilePath reference_pref_file;
if (new_profile_) {
@@ -36,7 +34,7 @@ class PreferenceServiceTest : public UITest {
.AppendASCII("window_placement")
.AppendASCII("Default")
.Append(chrome::kPreferencesFilename);
- tmp_pref_file_ = tmp_profile_.AppendASCII("Default");
+ tmp_pref_file_ = tmp_profile.AppendASCII("Default");
ASSERT_TRUE(file_util::CreateDirectory(tmp_pref_file_));
tmp_pref_file_ = tmp_pref_file_.Append(chrome::kPreferencesFilename);
} else {
@@ -44,7 +42,7 @@ class PreferenceServiceTest : public UITest {
.AppendASCII("profiles")
.AppendASCII("window_placement")
.Append(chrome::kLocalStateFilename);
- tmp_pref_file_ = tmp_profile_.Append(chrome::kLocalStateFilename);
+ tmp_pref_file_ = tmp_profile.Append(chrome::kLocalStateFilename);
}
ASSERT_TRUE(file_util::PathExists(reference_pref_file));
@@ -59,7 +57,7 @@ class PreferenceServiceTest : public UITest {
FILE_ATTRIBUTE_NORMAL));
#endif
- launch_arguments_.AppendSwitchPath(switches::kUserDataDir, tmp_profile_);
+ launch_arguments_.AppendSwitchPath(switches::kUserDataDir, tmp_profile);
}
bool LaunchAppWithProfile() {
@@ -71,14 +69,14 @@ class PreferenceServiceTest : public UITest {
void TearDown() {
UITest::TearDown();
-
- EXPECT_TRUE(file_util::DieFileDie(tmp_profile_, true));
}
public:
bool new_profile_;
FilePath tmp_pref_file_;
- FilePath tmp_profile_;
+
+ private:
+ ScopedTempDir temp_dir_;
};
#if !defined(OS_LINUX)
diff --git a/chrome/browser/profiles/profile_manager_unittest.cc b/chrome/browser/profiles/profile_manager_unittest.cc
index 1ae59f3..eeea273 100644
--- a/chrome/browser/profiles/profile_manager_unittest.cc
+++ b/chrome/browser/profiles/profile_manager_unittest.cc
@@ -5,7 +5,7 @@
#include <string>
#include "base/command_line.h"
-#include "base/file_util.h"
+#include "base/memory/scoped_temp_dir.h"
#include "base/message_loop.h"
#include "base/path_service.h"
#include "chrome/browser/prefs/browser_prefs.h"
@@ -29,13 +29,8 @@ class ProfileManagerTest : public testing::Test {
}
virtual void SetUp() {
- // Name a subdirectory of the temp directory.
- ASSERT_TRUE(PathService::Get(base::DIR_TEMP, &test_dir_));
- test_dir_ = test_dir_.Append(FILE_PATH_LITERAL("ProfileManagerTest"));
-
- // Create a fresh, empty copy of this directory.
- file_util::Delete(test_dir_, true);
- file_util::CreateDirectory(test_dir_);
+ // Create a new temporary directory, and store the path
+ ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
// Create a local_state PrefService.
browser::RegisterLocalState(&test_local_state_);
@@ -45,22 +40,18 @@ class ProfileManagerTest : public testing::Test {
}
virtual void TearDown() {
- // Clean up test directory
- ASSERT_TRUE(file_util::Delete(test_dir_, true));
- ASSERT_FALSE(file_util::PathExists(test_dir_));
-
TestingBrowserProcess* testing_browser_process =
static_cast<TestingBrowserProcess*>(g_browser_process);
testing_browser_process->SetPrefService(NULL);
}
+ // The path to temporary directory used to contain the test operations.
+ ScopedTempDir temp_dir_;
+
MessageLoopForUI message_loop_;
BrowserThread ui_thread_;
BrowserThread file_thread_;
- // the path to temporary directory used to contain the test operations
- FilePath test_dir_;
-
TestingPrefService test_local_state_;
};
@@ -70,7 +61,7 @@ TEST_F(ProfileManagerTest, CreateProfile) {
source_path = source_path.Append(FILE_PATH_LITERAL("profiles"));
source_path = source_path.Append(FILE_PATH_LITERAL("sample"));
- FilePath dest_path = test_dir_;
+ FilePath dest_path = temp_dir_.path();
dest_path = dest_path.Append(FILE_PATH_LITERAL("New Profile"));
scoped_ptr<Profile> profile;
@@ -127,7 +118,8 @@ TEST_F(ProfileManagerTest, LoggedInProfileDir) {
FilePath expected_logged_in(profile_dir);
EXPECT_EQ(expected_logged_in.value(),
profile_manager.GetCurrentProfileDir().value());
- VLOG(1) << test_dir_.Append(profile_manager.GetCurrentProfileDir()).value();
+ VLOG(1) << temp_dir_.path().Append(
+ profile_manager.GetCurrentProfileDir()).value();
}
#endif
@@ -138,10 +130,10 @@ TEST_F(ProfileManagerTest, CreateAndUseTwoProfiles) {
source_path = source_path.Append(FILE_PATH_LITERAL("profiles"));
source_path = source_path.Append(FILE_PATH_LITERAL("sample"));
- FilePath dest_path1 = test_dir_;
+ FilePath dest_path1 = temp_dir_.path();
dest_path1 = dest_path1.Append(FILE_PATH_LITERAL("New Profile 1"));
- FilePath dest_path2 = test_dir_;
+ FilePath dest_path2 = temp_dir_.path();
dest_path2 = dest_path2.Append(FILE_PATH_LITERAL("New Profile 2"));
scoped_ptr<Profile> profile1;
diff --git a/chrome/browser/safe_browsing/bloom_filter_unittest.cc b/chrome/browser/safe_browsing/bloom_filter_unittest.cc
index f0d74c0..62c5f46 100644
--- a/chrome/browser/safe_browsing/bloom_filter_unittest.cc
+++ b/chrome/browser/safe_browsing/bloom_filter_unittest.cc
@@ -15,6 +15,7 @@
#include "base/path_service.h"
#include "base/rand_util.h"
#include "base/string_util.h"
+#include "base/memory/scoped_temp_dir.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace {
@@ -89,11 +90,9 @@ TEST(SafeBrowsingBloomFilter, BloomFilterFile) {
filter_write->Insert(GenHash());
// Remove any left over test filters and serialize.
- FilePath filter_path;
- PathService::Get(base::DIR_TEMP, &filter_path);
- filter_path = filter_path.AppendASCII("SafeBrowsingTestFilter");
- file_util::Delete(filter_path, false);
- ASSERT_FALSE(file_util::PathExists(filter_path));
+ ScopedTempDir temp_dir;
+ ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
+ FilePath filter_path = temp_dir.path().AppendASCII("SafeBrowsingTestFilter");
ASSERT_TRUE(filter_write->WriteFile(filter_path));
// Create new empty filter and load from disk.
@@ -111,6 +110,4 @@ TEST(SafeBrowsingBloomFilter, BloomFilterFile) {
EXPECT_EQ(0,
memcmp(filter_write->data(), filter_read->data(), filter_read->size()));
-
- file_util::Delete(filter_path, false);
}
diff --git a/chrome/browser/sessions/session_service_unittest.cc b/chrome/browser/sessions/session_service_unittest.cc
index d2d9942..d10548e9 100644
--- a/chrome/browser/sessions/session_service_unittest.cc
+++ b/chrome/browser/sessions/session_service_unittest.cc
@@ -5,6 +5,7 @@
#include "base/file_util.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/scoped_vector.h"
+#include "base/memory/scoped_temp_dir.h"
#include "base/path_service.h"
#include "base/stl_util-inl.h"
#include "base/string_number_conversions.h"
@@ -36,8 +37,8 @@ class SessionServiceTest : public BrowserWithTestWindowTest,
BrowserWithTestWindowTest::SetUp();
std::string b = base::Int64ToString(base::Time::Now().ToInternalValue());
- PathService::Get(base::DIR_TEMP, &path_);
- path_ = path_.Append(FILE_PATH_LITERAL("SessionTestDirs"));
+ ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
+ path_ = temp_dir_.path().Append(FILE_PATH_LITERAL("SessionTestDirs"));
file_util::CreateDirectory(path_);
path_deleter_.reset(new FileAutoDeleter(path_));
path_ = path_.AppendASCII(b);
@@ -133,6 +134,7 @@ class SessionServiceTest : public BrowserWithTestWindowTest,
int sync_save_count_;
// Path used in testing.
+ ScopedTempDir temp_dir_;
FilePath path_;
scoped_ptr<FileAutoDeleter> path_deleter_;
diff --git a/chrome/browser/ui/tests/browser_uitest.cc b/chrome/browser/ui/tests/browser_uitest.cc
index b756caa..ead99ff 100644
--- a/chrome/browser/ui/tests/browser_uitest.cc
+++ b/chrome/browser/ui/tests/browser_uitest.cc
@@ -280,15 +280,13 @@ TEST_F(KioskModeTest, EnableKioskModeTest) {
class LaunchBrowserWithNonAsciiUserDatadir : public UITest {
public:
void SetUp() {
- PathService::Get(base::DIR_TEMP, &tmp_profile_);
- tmp_profile_ = tmp_profile_.AppendASCII("tmp_profile");
- tmp_profile_ = tmp_profile_.Append(L"Test Chrome G�raldine");
+ ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
+ FilePath tmp_profile = temp_dir_.path().AppendASCII("tmp_profile");
+ tmp_profile = tmp_profile.Append(L"Test Chrome G�raldine");
- // Create a fresh, empty copy of this directory.
- file_util::Delete(tmp_profile_, true);
- file_util::CreateDirectory(tmp_profile_);
+ ASSERT_TRUE(file_util::CreateDirectory(tmp_profile));
- launch_arguments_.AppendSwitchPath(switches::kUserDataDir, tmp_profile_);
+ launch_arguments_.AppendSwitchPath(switches::kUserDataDir, tmp_profile);
}
bool LaunchAppWithProfile() {
@@ -296,13 +294,8 @@ public:
return true;
}
- void TearDown() {
- UITest::TearDown();
- EXPECT_TRUE(file_util::DieFileDie(tmp_profile_, true));
- }
-
public:
- FilePath tmp_profile_;
+ ScopedTempDir temp_dir_;
};
TEST_F(LaunchBrowserWithNonAsciiUserDatadir, TestNonAsciiUserDataDir) {
diff --git a/chrome/common/extensions/extension_unpacker_unittest.cc b/chrome/common/extensions/extension_unpacker_unittest.cc
index 930c271..80ed7a5 100644
--- a/chrome/common/extensions/extension_unpacker_unittest.cc
+++ b/chrome/common/extensions/extension_unpacker_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -6,6 +6,7 @@
#include "base/path_service.h"
#include "base/string_util.h"
#include "base/values.h"
+#include "base/memory/scoped_temp_dir.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/extensions/extension_constants.h"
#include "chrome/common/extensions/extension_unpacker.h"
@@ -27,12 +28,9 @@ public:
// Try bots won't let us write into DIR_TEST_DATA, so we have to create
// a temp folder to play in.
- ASSERT_TRUE(PathService::Get(base::DIR_TEMP, &install_dir_));
- install_dir_ = install_dir_.AppendASCII("extension_unpacker_test");
- file_util::Delete(install_dir_, true);
- file_util::CreateDirectory(install_dir_);
+ ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
- FilePath crx_path = install_dir_.AppendASCII(crx_name);
+ FilePath crx_path = temp_dir_.path().AppendASCII(crx_name);
ASSERT_TRUE(file_util::CopyFile(original_path, crx_path)) <<
"Original path " << original_path.value() <<
", Crx path " << crx_path.value();
@@ -40,13 +38,8 @@ public:
unpacker_.reset(new ExtensionUnpacker(crx_path));
}
- virtual void TearDown() {
- ASSERT_TRUE(file_util::Delete(install_dir_, true)) <<
- install_dir_.value();
- }
-
protected:
- FilePath install_dir_;
+ ScopedTempDir temp_dir_;
scoped_ptr<ExtensionUnpacker> unpacker_;
};
diff --git a/chrome/common/json_pref_store_unittest.cc b/chrome/common/json_pref_store_unittest.cc
index fcec0ea..e7f34f5 100644
--- a/chrome/common/json_pref_store_unittest.cc
+++ b/chrome/common/json_pref_store_unittest.cc
@@ -13,6 +13,7 @@
#include "base/threading/thread.h"
#include "base/utf_string_conversions.h"
#include "base/values.h"
+#include "base/memory/scoped_temp_dir.h"
#include "chrome/common/json_pref_store.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/pref_names.h"
@@ -22,28 +23,17 @@ class JsonPrefStoreTest : public testing::Test {
protected:
virtual void SetUp() {
message_loop_proxy_ = base::MessageLoopProxy::CreateForCurrentThread();
- // Name a subdirectory of the temp directory.
- ASSERT_TRUE(PathService::Get(base::DIR_TEMP, &test_dir_));
- test_dir_ = test_dir_.AppendASCII("JsonPrefStoreTest");
- // Create a fresh, empty copy of this directory.
- file_util::Delete(test_dir_, true);
- file_util::CreateDirectory(test_dir_);
+ ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &data_dir_));
data_dir_ = data_dir_.AppendASCII("pref_service");
ASSERT_TRUE(file_util::PathExists(data_dir_));
}
- virtual void TearDown() {
- // 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_;
- // the path to the directory where the test data is stored
+ // The path to temporary directory used to contain the test operations.
+ ScopedTempDir temp_dir_;
+ // The path to the directory where the test data is stored.
FilePath data_dir_;
// A message loop that we can use as the file thread message loop.
MessageLoop message_loop_;
@@ -64,7 +54,7 @@ TEST_F(JsonPrefStoreTest, NonExistentFile) {
// Test fallback behavior for an invalid file.
TEST_F(JsonPrefStoreTest, InvalidFile) {
FilePath invalid_file_original = data_dir_.AppendASCII("invalid.json");
- FilePath invalid_file = test_dir_.AppendASCII("invalid.json");
+ FilePath invalid_file = temp_dir_.path().AppendASCII("invalid.json");
ASSERT_TRUE(file_util::CopyFile(invalid_file_original, invalid_file));
scoped_refptr<JsonPrefStore> pref_store =
new JsonPrefStore(invalid_file, message_loop_proxy_.get());
@@ -74,7 +64,7 @@ TEST_F(JsonPrefStoreTest, InvalidFile) {
// The file should have been moved aside.
EXPECT_FALSE(file_util::PathExists(invalid_file));
- FilePath moved_aside = test_dir_.AppendASCII("invalid.bad");
+ FilePath moved_aside = temp_dir_.path().AppendASCII("invalid.bad");
EXPECT_TRUE(file_util::PathExists(moved_aside));
EXPECT_TRUE(file_util::TextContentsEqual(invalid_file_original,
moved_aside));
@@ -82,10 +72,10 @@ TEST_F(JsonPrefStoreTest, InvalidFile) {
TEST_F(JsonPrefStoreTest, Basic) {
ASSERT_TRUE(file_util::CopyFile(data_dir_.AppendASCII("read.json"),
- test_dir_.AppendASCII("write.json")));
+ temp_dir_.path().AppendASCII("write.json")));
// Test that the persistent value can be loaded.
- FilePath input_file = test_dir_.AppendASCII("write.json");
+ FilePath input_file = temp_dir_.path().AppendASCII("write.json");
ASSERT_TRUE(file_util::PathExists(input_file));
scoped_refptr<JsonPrefStore> pref_store =
new JsonPrefStore(input_file, message_loop_proxy_.get());
diff --git a/chrome/common/json_value_serializer_unittest.cc b/chrome/common/json_value_serializer_unittest.cc
index c52aa06..0df24b0 100644
--- a/chrome/common/json_value_serializer_unittest.cc
+++ b/chrome/common/json_value_serializer_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -6,6 +6,7 @@
#include "base/file_util.h"
#include "base/json/json_reader.h"
#include "base/json/json_writer.h"
+#include "base/memory/scoped_temp_dir.h"
#include "base/path_service.h"
#include "base/string16.h"
#include "base/string_util.h"
@@ -239,23 +240,10 @@ TEST(JSONValueSerializerTest, JSONReaderComments) {
class JSONFileValueSerializerTest : public testing::Test {
protected:
virtual void SetUp() {
- // Name a subdirectory of the temp directory.
- ASSERT_TRUE(PathService::Get(base::DIR_TEMP, &test_dir_));
- test_dir_ =
- test_dir_.Append(FILE_PATH_LITERAL("JSONFileValueSerializerTest"));
-
- // Create a fresh, empty copy of this directory.
- file_util::Delete(test_dir_, true);
- file_util::CreateDirectory(test_dir_);
- }
- virtual void TearDown() {
- // Clean up test directory
- ASSERT_TRUE(file_util::Delete(test_dir_, false));
- ASSERT_FALSE(file_util::PathExists(test_dir_));
+ ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
}
- // the path to temporary directory used to contain the test operations
- FilePath test_dir_;
+ ScopedTempDir temp_dir_;
};
TEST_F(JSONFileValueSerializerTest, Roundtrip) {
@@ -295,7 +283,7 @@ TEST_F(JSONFileValueSerializerTest, Roundtrip) {
// Now try writing.
const FilePath written_file_path =
- test_dir_.Append(FILE_PATH_LITERAL("test_output.js"));
+ temp_dir_.path().Append(FILE_PATH_LITERAL("test_output.js"));
ASSERT_FALSE(file_util::PathExists(written_file_path));
JSONFileValueSerializer serializer(written_file_path);
@@ -324,7 +312,7 @@ TEST_F(JSONFileValueSerializerTest, RoundtripNested) {
// Now try writing.
FilePath written_file_path =
- test_dir_.Append(FILE_PATH_LITERAL("test_output.js"));
+ temp_dir_.path().Append(FILE_PATH_LITERAL("test_output.js"));
ASSERT_FALSE(file_util::PathExists(written_file_path));
JSONFileValueSerializer serializer(written_file_path);
diff --git a/chrome/installer/util/copy_tree_work_item_unittest.cc b/chrome/installer/util/copy_tree_work_item_unittest.cc
index 96aa32b..8660c74 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()));
diff --git a/chrome/installer/util/create_dir_work_item_unittest.cc b/chrome/installer/util/create_dir_work_item_unittest.cc
index 2b5e4fd..e929600 100644
--- a/chrome/installer/util/create_dir_work_item_unittest.cc
+++ b/chrome/installer/util/create_dir_work_item_unittest.cc
@@ -7,6 +7,7 @@
#include "base/base_paths.h"
#include "base/file_util.h"
#include "base/memory/scoped_ptr.h"
+#include "base/memory/scoped_temp_dir.h"
#include "base/path_service.h"
#include "base/string_util.h"
#include "chrome/installer/util/work_item.h"
@@ -17,27 +18,15 @@ namespace {
class CreateDirWorkItemTest : public testing::Test {
protected:
virtual void SetUp() {
- // Name a subdirectory of the temp directory.
- ASSERT_TRUE(PathService::Get(base::DIR_TEMP, &test_dir_));
- test_dir_ = test_dir_.AppendASCII("CreateDirWorkItemTest");
-
- // Create a fresh, empty copy of this directory.
- file_util::Delete(test_dir_, true);
- file_util::CreateDirectoryW(test_dir_);
- }
- virtual void TearDown() {
- // Clean up test directory
- ASSERT_TRUE(file_util::Delete(test_dir_, true));
- ASSERT_FALSE(file_util::PathExists(test_dir_));
+ ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
}
- // the path to temporary directory used to contain the test operations
- FilePath test_dir_;
+ ScopedTempDir temp_dir_;
};
};
TEST_F(CreateDirWorkItemTest, CreatePath) {
- FilePath parent_dir(test_dir_);
+ FilePath parent_dir(temp_dir_.path());
parent_dir = parent_dir.AppendASCII("a");
file_util::CreateDirectory(parent_dir);
ASSERT_TRUE(file_util::PathExists(parent_dir));
@@ -64,7 +53,7 @@ TEST_F(CreateDirWorkItemTest, CreatePath) {
}
TEST_F(CreateDirWorkItemTest, CreateExistingPath) {
- FilePath dir_to_create(test_dir_);
+ FilePath dir_to_create(temp_dir_.path());
dir_to_create = dir_to_create.AppendASCII("aa");
file_util::CreateDirectory(dir_to_create);
ASSERT_TRUE(file_util::PathExists(dir_to_create));
@@ -84,7 +73,7 @@ TEST_F(CreateDirWorkItemTest, CreateExistingPath) {
}
TEST_F(CreateDirWorkItemTest, CreateSharedPath) {
- FilePath dir_to_create_1(test_dir_);
+ FilePath dir_to_create_1(temp_dir_.path());
dir_to_create_1 = dir_to_create_1.AppendASCII("aaa");
FilePath dir_to_create_2(dir_to_create_1);
@@ -117,7 +106,7 @@ TEST_F(CreateDirWorkItemTest, CreateSharedPath) {
}
TEST_F(CreateDirWorkItemTest, RollbackWithMissingDir) {
- FilePath dir_to_create_1(test_dir_);
+ FilePath dir_to_create_1(temp_dir_.path());
dir_to_create_1 = dir_to_create_1.AppendASCII("aaaa");
FilePath dir_to_create_2(dir_to_create_1);
diff --git a/chrome/installer/util/delete_tree_work_item_unittest.cc b/chrome/installer/util/delete_tree_work_item_unittest.cc
index 3215d57..b22ba81 100644
--- a/chrome/installer/util/delete_tree_work_item_unittest.cc
+++ b/chrome/installer/util/delete_tree_work_item_unittest.cc
@@ -22,25 +22,11 @@ namespace {
class DeleteTreeWorkItemTest : 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("DeleteTreeWorkItemTest");
-
- // Create a fresh, empty copy of this test directory.
- file_util::Delete(test_dir_, true);
- file_util::CreateDirectoryW(test_dir_);
-
- ASSERT_TRUE(file_util::PathExists(test_dir_));
- }
-
- virtual void TearDown() {
- // Clean up test directory
- ASSERT_TRUE(file_util::Delete(test_dir_, true));
- ASSERT_FALSE(file_util::PathExists(test_dir_));
+ ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
}
- // the path to temporary directory used to contain the test operations
- FilePath test_dir_;
+ // The temporary directory used to contain the test operations.
+ ScopedTempDir temp_dir_;
};
// Simple function to dump some text into a new file.
@@ -59,8 +45,8 @@ namespace {
// Delete a tree without key path. Everything should be deleted.
TEST_F(DeleteTreeWorkItemTest, DeleteTreeNoKeyPath) {
- // Create tree to be deleted
- FilePath dir_name_delete(test_dir_);
+ // Create tree to be deleted.
+ FilePath dir_name_delete(temp_dir_.path());
dir_name_delete = dir_name_delete.AppendASCII("to_be_delete");
file_util::CreateDirectory(dir_name_delete);
ASSERT_TRUE(file_util::PathExists(dir_name_delete));
@@ -85,7 +71,7 @@ TEST_F(DeleteTreeWorkItemTest, DeleteTreeNoKeyPath) {
CreateTextFile(file_name_delete_2.value(), text_content_1);
ASSERT_TRUE(file_util::PathExists(file_name_delete_2));
- // test Do()
+ // Test Do().
ScopedTempDir temp_dir;
ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
@@ -112,7 +98,7 @@ TEST_F(DeleteTreeWorkItemTest, DeleteTreeNoKeyPath) {
// Rollback should bring back everything
TEST_F(DeleteTreeWorkItemTest, DeleteTree) {
// Create tree to be deleted
- FilePath dir_name_delete(test_dir_);
+ FilePath dir_name_delete(temp_dir_.path());
dir_name_delete = dir_name_delete.AppendASCII("to_be_delete");
file_util::CreateDirectory(dir_name_delete);
ASSERT_TRUE(file_util::PathExists(dir_name_delete));
@@ -162,7 +148,7 @@ TEST_F(DeleteTreeWorkItemTest, DeleteTree) {
// Delete a tree with key_path in use. Everything should still be there.
TEST_F(DeleteTreeWorkItemTest, DeleteTreeInUse) {
// Create tree to be deleted
- FilePath dir_name_delete(test_dir_);
+ FilePath dir_name_delete(temp_dir_.path());
dir_name_delete = dir_name_delete.AppendASCII("to_be_delete");
file_util::CreateDirectory(dir_name_delete);
ASSERT_TRUE(file_util::PathExists(dir_name_delete));
diff --git a/chrome/installer/util/lzma_util_unittest.cc b/chrome/installer/util/lzma_util_unittest.cc
index b1c6363..e82d8bf 100644
--- a/chrome/installer/util/lzma_util_unittest.cc
+++ b/chrome/installer/util/lzma_util_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -7,6 +7,7 @@
#include "base/file_util.h"
#include "base/path_service.h"
#include "base/process_util.h"
+#include "base/memory/scoped_temp_dir.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/installer/util/lzma_util.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -19,24 +20,10 @@ class LzmaUtilTest : public testing::Test {
data_dir_ = data_dir_.AppendASCII("installer");
ASSERT_TRUE(file_util::PathExists(data_dir_));
- // Name a subdirectory of the user temp directory.
- ASSERT_TRUE(PathService::Get(base::DIR_TEMP, &test_dir_));
- test_dir_ = test_dir_.AppendASCII("LzmaUtilTest");
-
- // Create a fresh, empty copy of this test directory.
- file_util::Delete(test_dir_, true);
- file_util::CreateDirectoryW(test_dir_);
- ASSERT_TRUE(file_util::PathExists(test_dir_));
- }
-
- virtual void TearDown() {
- // Clean up test directory
- ASSERT_TRUE(file_util::Delete(test_dir_, true));
- ASSERT_FALSE(file_util::PathExists(test_dir_));
+ ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
}
- // The path to temporary directory used to contain the test operations.
- FilePath test_dir_;
+ ScopedTempDir temp_dir_;
// The path to input data used in tests.
FilePath data_dir_;
@@ -66,7 +53,7 @@ TEST_F(LzmaUtilTest, OpenArchiveTest) {
// Test that we can extract archives successfully.
TEST_F(LzmaUtilTest, UnPackTest) {
- FilePath extract_dir(test_dir_);
+ FilePath extract_dir(temp_dir_.path());
extract_dir = extract_dir.AppendASCII("UnPackTest");
ASSERT_FALSE(file_util::PathExists(extract_dir));
EXPECT_TRUE(file_util::CreateDirectory(extract_dir));
@@ -107,7 +94,7 @@ TEST_F(LzmaUtilTest, UnPackTest) {
// Test the static method that can be used to unpack archives.
TEST_F(LzmaUtilTest, UnPackArchiveTest) {
- FilePath extract_dir(test_dir_);
+ FilePath extract_dir(temp_dir_.path());
extract_dir = extract_dir.AppendASCII("UnPackArchiveTest");
ASSERT_FALSE(file_util::PathExists(extract_dir));
EXPECT_TRUE(file_util::CreateDirectory(extract_dir));
diff --git a/chrome/installer/util/move_tree_work_item_unittest.cc b/chrome/installer/util/move_tree_work_item_unittest.cc
index 473f6a6..c646fd4 100644
--- a/chrome/installer/util/move_tree_work_item_unittest.cc
+++ b/chrome/installer/util/move_tree_work_item_unittest.cc
@@ -20,31 +20,12 @@ namespace {
class MoveTreeWorkItemTest : 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("MoveTreeWorkItemTest");
-
- // 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_));
- }
-
- virtual void TearDown() {
- // Clean up test directory
- ASSERT_TRUE(file_util::Delete(test_dir_, true));
- ASSERT_FALSE(file_util::PathExists(test_dir_));
+ ASSERT_TRUE(temp_from_dir_.CreateUniqueTempDir());
+ ASSERT_TRUE(temp_to_dir_.CreateUniqueTempDir());
}
- // the path to temporary directory used to contain the test operations
- FilePath test_dir_;
- FilePath temp_dir_;
+ ScopedTempDir temp_from_dir_;
+ ScopedTempDir temp_to_dir_;
};
// Simple function to dump some text into a new file.
@@ -76,7 +57,7 @@ namespace {
// exist.
TEST_F(MoveTreeWorkItemTest, MoveDirectory) {
// Create two level deep source dir
- FilePath from_dir1(test_dir_);
+ FilePath from_dir1(temp_from_dir_.path());
from_dir1 = from_dir1.AppendASCII("From_Dir1");
file_util::CreateDirectory(from_dir1);
ASSERT_TRUE(file_util::PathExists(from_dir1));
@@ -92,7 +73,7 @@ TEST_F(MoveTreeWorkItemTest, MoveDirectory) {
ASSERT_TRUE(file_util::PathExists(from_file));
// Generate destination path
- FilePath to_dir(test_dir_);
+ FilePath to_dir(temp_from_dir_.path());
to_dir = to_dir.AppendASCII("To_Dir");
ASSERT_FALSE(file_util::PathExists(to_dir));
@@ -103,7 +84,7 @@ TEST_F(MoveTreeWorkItemTest, MoveDirectory) {
// test Do()
scoped_ptr<MoveTreeWorkItem> work_item(
- WorkItem::CreateMoveTreeWorkItem(from_dir1, to_dir, temp_dir_));
+ WorkItem::CreateMoveTreeWorkItem(from_dir1, to_dir, temp_to_dir_.path()));
EXPECT_TRUE(work_item->Do());
EXPECT_FALSE(file_util::PathExists(from_dir1));
@@ -122,7 +103,7 @@ TEST_F(MoveTreeWorkItemTest, MoveDirectory) {
// exists.
TEST_F(MoveTreeWorkItemTest, MoveDirectoryDestExists) {
// Create two level deep source dir
- FilePath from_dir1(test_dir_);
+ FilePath from_dir1(temp_from_dir_.path());
from_dir1 = from_dir1.AppendASCII("From_Dir1");
file_util::CreateDirectory(from_dir1);
ASSERT_TRUE(file_util::PathExists(from_dir1));
@@ -138,7 +119,7 @@ TEST_F(MoveTreeWorkItemTest, MoveDirectoryDestExists) {
ASSERT_TRUE(file_util::PathExists(from_file));
// Create destination path
- FilePath to_dir(test_dir_);
+ FilePath to_dir(temp_from_dir_.path());
to_dir = to_dir.AppendASCII("To_Dir");
file_util::CreateDirectory(to_dir);
ASSERT_TRUE(file_util::PathExists(to_dir));
@@ -155,7 +136,7 @@ TEST_F(MoveTreeWorkItemTest, MoveDirectoryDestExists) {
// test Do()
scoped_ptr<MoveTreeWorkItem> work_item(
- WorkItem::CreateMoveTreeWorkItem(from_dir1, to_dir, temp_dir_));
+ WorkItem::CreateMoveTreeWorkItem(from_dir1, to_dir, temp_to_dir_.path()));
EXPECT_TRUE(work_item->Do());
EXPECT_FALSE(file_util::PathExists(from_dir1));
@@ -178,7 +159,7 @@ TEST_F(MoveTreeWorkItemTest, MoveDirectoryDestExists) {
// exist.
TEST_F(MoveTreeWorkItemTest, MoveAFile) {
// Create a file inside source dir
- FilePath from_dir(test_dir_);
+ FilePath from_dir(temp_from_dir_.path());
from_dir = from_dir.AppendASCII("From_Dir");
file_util::CreateDirectory(from_dir);
ASSERT_TRUE(file_util::PathExists(from_dir));
@@ -189,13 +170,14 @@ TEST_F(MoveTreeWorkItemTest, MoveAFile) {
ASSERT_TRUE(file_util::PathExists(from_file));
// Generate destination file name
- FilePath to_file(test_dir_);
+ FilePath to_file(temp_from_dir_.path());
to_file = to_file.AppendASCII("To_File");
ASSERT_FALSE(file_util::PathExists(to_file));
// test Do()
scoped_ptr<MoveTreeWorkItem> work_item(
- WorkItem::CreateMoveTreeWorkItem(from_file, to_file, temp_dir_));
+ WorkItem::CreateMoveTreeWorkItem(
+ from_file, to_file, temp_to_dir_.path()));
EXPECT_TRUE(work_item->Do());
EXPECT_TRUE(file_util::PathExists(from_dir));
@@ -216,7 +198,7 @@ TEST_F(MoveTreeWorkItemTest, MoveAFile) {
// exists.
TEST_F(MoveTreeWorkItemTest, MoveFileDestExists) {
// Create a file inside source dir
- FilePath from_dir(test_dir_);
+ FilePath from_dir(temp_from_dir_.path());
from_dir = from_dir.AppendASCII("From_Dir");
file_util::CreateDirectory(from_dir);
ASSERT_TRUE(file_util::PathExists(from_dir));
@@ -227,7 +209,7 @@ TEST_F(MoveTreeWorkItemTest, MoveFileDestExists) {
ASSERT_TRUE(file_util::PathExists(from_file));
// Create destination path
- FilePath to_dir(test_dir_);
+ FilePath to_dir(temp_from_dir_.path());
to_dir = to_dir.AppendASCII("To_Dir");
file_util::CreateDirectory(to_dir);
ASSERT_TRUE(file_util::PathExists(to_dir));
@@ -239,7 +221,7 @@ TEST_F(MoveTreeWorkItemTest, MoveFileDestExists) {
// test Do()
scoped_ptr<MoveTreeWorkItem> work_item(
- WorkItem::CreateMoveTreeWorkItem(from_file, to_dir, temp_dir_));
+ WorkItem::CreateMoveTreeWorkItem(from_file, to_dir, temp_to_dir_.path()));
EXPECT_TRUE(work_item->Do());
EXPECT_TRUE(file_util::PathExists(from_dir));
@@ -261,7 +243,7 @@ TEST_F(MoveTreeWorkItemTest, MoveFileDestExists) {
// exists and is in use.
TEST_F(MoveTreeWorkItemTest, MoveFileDestInUse) {
// Create a file inside source dir
- FilePath from_dir(test_dir_);
+ FilePath from_dir(temp_from_dir_.path());
from_dir = from_dir.AppendASCII("From_Dir");
file_util::CreateDirectory(from_dir);
ASSERT_TRUE(file_util::PathExists(from_dir));
@@ -272,7 +254,7 @@ TEST_F(MoveTreeWorkItemTest, MoveFileDestInUse) {
ASSERT_TRUE(file_util::PathExists(from_file));
// Create an executable in destination path by copying ourself to it.
- FilePath to_dir(test_dir_);
+ FilePath to_dir(temp_from_dir_.path());
to_dir = to_dir.AppendASCII("To_Dir");
file_util::CreateDirectory(to_dir);
ASSERT_TRUE(file_util::PathExists(to_dir));
@@ -296,7 +278,8 @@ TEST_F(MoveTreeWorkItemTest, MoveFileDestInUse) {
// test Do()
scoped_ptr<MoveTreeWorkItem> work_item(
- WorkItem::CreateMoveTreeWorkItem(from_file, to_file, temp_dir_));
+ WorkItem::CreateMoveTreeWorkItem(
+ from_file, to_file, temp_to_dir_.path()));
EXPECT_TRUE(work_item->Do());
EXPECT_TRUE(file_util::PathExists(from_dir));
@@ -321,7 +304,7 @@ TEST_F(MoveTreeWorkItemTest, MoveFileDestInUse) {
// Move one file that is in use to destination.
TEST_F(MoveTreeWorkItemTest, MoveFileInUse) {
// Create an executable for source by copying ourself to a new source dir.
- FilePath from_dir(test_dir_);
+ FilePath from_dir(temp_from_dir_.path());
from_dir = from_dir.AppendASCII("From_Dir");
file_util::CreateDirectory(from_dir);
ASSERT_TRUE(file_util::PathExists(from_dir));
@@ -335,7 +318,7 @@ TEST_F(MoveTreeWorkItemTest, MoveFileInUse) {
ASSERT_TRUE(file_util::PathExists(from_file));
// Create a destination source dir and generate destination file name.
- FilePath to_dir(test_dir_);
+ FilePath to_dir(temp_from_dir_.path());
to_dir = to_dir.AppendASCII("To_Dir");
file_util::CreateDirectory(to_dir);
ASSERT_TRUE(file_util::PathExists(to_dir));
@@ -356,7 +339,8 @@ TEST_F(MoveTreeWorkItemTest, MoveFileInUse) {
// test Do()
scoped_ptr<MoveTreeWorkItem> work_item(
- WorkItem::CreateMoveTreeWorkItem(from_file, to_file, temp_dir_));
+ WorkItem::CreateMoveTreeWorkItem(
+ from_file, to_file, temp_to_dir_.path()));
EXPECT_TRUE(work_item->Do());
EXPECT_TRUE(file_util::PathExists(from_dir));
diff --git a/chrome/installer/util/shell_util_unittest.cc b/chrome/installer/util/shell_util_unittest.cc
index b96b566..b14007e 100644
--- a/chrome/installer/util/shell_util_unittest.cc
+++ b/chrome/installer/util/shell_util_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -11,6 +11,7 @@
#include "base/file_util.h"
#include "base/path_service.h"
#include "base/scoped_comptr_win.h"
+#include "base/memory/scoped_temp_dir.h"
#include "chrome/installer/util/browser_distribution.h"
#include "chrome/installer/util/master_preferences.h"
#include "chrome/installer/util/shell_util.h"
@@ -86,24 +87,10 @@ bool VerifyChromeShortcut(const std::wstring& exe_path,
class ShellUtilTest : 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("ShellUtilTest");
-
- // Create a fresh, empty copy of this test directory.
- file_util::Delete(test_dir_, true);
- file_util::CreateDirectoryW(test_dir_);
- ASSERT_TRUE(file_util::PathExists(test_dir_));
+ ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
}
- virtual void TearDown() {
- // 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_;
+ ScopedTempDir temp_dir_;
};
};
@@ -116,10 +103,10 @@ TEST_F(ShellUtilTest, UpdateChromeShortcutTest) {
EXPECT_FALSE(::GetModuleFileName(NULL, exe_full_path_str, MAX_PATH) == 0);
FilePath exe_full_path(exe_full_path_str);
- FilePath exe_path = test_dir_.AppendASCII("setup.exe");
+ FilePath exe_path = temp_dir_.path().AppendASCII("setup.exe");
EXPECT_TRUE(file_util::CopyFile(exe_full_path, exe_path));
- FilePath shortcut_path = test_dir_.AppendASCII("shortcut.lnk");
+ FilePath shortcut_path = temp_dir_.path().AppendASCII("shortcut.lnk");
const std::wstring description(L"dummy description");
EXPECT_TRUE(ShellUtil::UpdateChromeShortcut(dist, exe_path.value(),
shortcut_path.value(),
@@ -129,7 +116,7 @@ TEST_F(ShellUtilTest, UpdateChromeShortcutTest) {
description, 0));
// Now specify an icon index in master prefs and make sure it works.
- FilePath prefs_path = test_dir_.AppendASCII(
+ FilePath prefs_path = temp_dir_.path().AppendASCII(
installer::kDefaultMasterPrefs);
std::ofstream file;
file.open(prefs_path.value().c_str());
diff --git a/chrome/installer/util/work_item_list_unittest.cc b/chrome/installer/util/work_item_list_unittest.cc
index ff2c3ad..56d3a8b8 100644
--- a/chrome/installer/util/work_item_list_unittest.cc
+++ b/chrome/installer/util/work_item_list_unittest.cc
@@ -7,6 +7,7 @@
#include "base/base_paths.h"
#include "base/file_util.h"
#include "base/memory/scoped_ptr.h"
+#include "base/memory/scoped_temp_dir.h"
#include "base/path_service.h"
#include "base/string_util.h"
#include "base/win/registry.h"
@@ -32,26 +33,18 @@ class WorkItemListTest : public testing::Test {
ASSERT_EQ(ERROR_SUCCESS,
key.Create(HKEY_CURRENT_USER, test_root, KEY_READ));
- // Create a temp directory for test.
- ASSERT_TRUE(PathService::Get(base::DIR_TEMP, &test_dir_));
- test_dir_ = test_dir_.AppendASCII("WorkItemListTest");
- file_util::Delete(test_dir_, true);
- ASSERT_FALSE(file_util::PathExists(test_dir_));
- file_util::CreateDirectoryW(test_dir_);
- ASSERT_TRUE(file_util::PathExists(test_dir_));
+ ASSERT_TRUE(temp_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_));
+
// Clean up the temporary key
RegKey key(HKEY_CURRENT_USER, L"", KEY_ALL_ACCESS);
ASSERT_EQ(ERROR_SUCCESS, key.DeleteKey(test_root));
}
- FilePath test_dir_;
+ ScopedTempDir temp_dir_;
};
} // namespace
@@ -61,7 +54,7 @@ TEST_F(WorkItemListTest, ExecutionSuccess) {
scoped_ptr<WorkItemList> work_item_list(WorkItem::CreateWorkItemList());
scoped_ptr<WorkItem> work_item;
- FilePath top_dir_to_create(test_dir_);
+ FilePath top_dir_to_create(temp_dir_.path());
top_dir_to_create = top_dir_to_create.AppendASCII("a");
FilePath dir_to_create(top_dir_to_create);
dir_to_create = dir_to_create.AppendASCII("b");
@@ -112,7 +105,7 @@ TEST_F(WorkItemListTest, ExecutionFailAndRollback) {
scoped_ptr<WorkItemList> work_item_list(WorkItem::CreateWorkItemList());
scoped_ptr<WorkItem> work_item;
- FilePath top_dir_to_create(test_dir_);
+ FilePath top_dir_to_create(temp_dir_.path());
top_dir_to_create = top_dir_to_create.AppendASCII("a");
FilePath dir_to_create(top_dir_to_create);
dir_to_create = dir_to_create.AppendASCII("b");
@@ -168,7 +161,7 @@ TEST_F(WorkItemListTest, ConditionalExecutionSuccess) {
scoped_ptr<WorkItemList> work_item_list(WorkItem::CreateWorkItemList());
scoped_ptr<WorkItem> work_item;
- FilePath top_dir_to_create(test_dir_);
+ FilePath top_dir_to_create(temp_dir_.path());
top_dir_to_create = top_dir_to_create.AppendASCII("a");
FilePath dir_to_create(top_dir_to_create);
dir_to_create = dir_to_create.AppendASCII("b");
@@ -223,7 +216,7 @@ TEST_F(WorkItemListTest, ConditionalExecutionConditionFailure) {
scoped_ptr<WorkItemList> work_item_list(WorkItem::CreateWorkItemList());
scoped_ptr<WorkItem> work_item;
- FilePath top_dir_to_create(test_dir_);
+ FilePath top_dir_to_create(temp_dir_.path());
top_dir_to_create = top_dir_to_create.AppendASCII("a");
FilePath dir_to_create(top_dir_to_create);
dir_to_create = dir_to_create.AppendASCII("b");