Commit cbbb641e authored by husky@google.com's avatar husky@google.com

Replace all usage of FileAutoDeleter with ScopedTempDir.

Review URL: http://codereview.chromium.org/7056011

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@86617 0039d316-1c4b-4281-b951-d872f2087c98
parent fb8f976c
...@@ -10,7 +10,6 @@ ...@@ -10,7 +10,6 @@
#include "build/build_config.h" #include "build/build_config.h"
#include "chrome/browser/importer/firefox_profile_lock.h" #include "chrome/browser/importer/firefox_profile_lock.h"
#include "chrome/common/chrome_paths.h" #include "chrome/common/chrome_paths.h"
#include "chrome/test/file_test_utils.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
class FirefoxProfileLockTest : public testing::Test { class FirefoxProfileLockTest : public testing::Test {
...@@ -34,12 +33,8 @@ TEST_F(FirefoxProfileLockTest, LockTest) { ...@@ -34,12 +33,8 @@ TEST_F(FirefoxProfileLockTest, LockTest) {
// Tests basic functionality and verifies that the lock file is deleted after // Tests basic functionality and verifies that the lock file is deleted after
// use. // use.
TEST_F(FirefoxProfileLockTest, ProfileLock) { TEST_F(FirefoxProfileLockTest, ProfileLock) {
FilePath test_path; FilePath test_path = temp_dir_.path();
ASSERT_TRUE(file_util::CreateNewTempDirectory( FilePath lock_file_path = test_path.Append(FirefoxProfileLock::kLockFileName);
FILE_PATH_LITERAL("firefox_profile"), &test_path));
FilePath lock_file_path = test_path;
FileAutoDeleter deleter(lock_file_path);
lock_file_path = lock_file_path.Append(FirefoxProfileLock::kLockFileName);
scoped_ptr<FirefoxProfileLock> lock; scoped_ptr<FirefoxProfileLock> lock;
EXPECT_EQ(static_cast<FirefoxProfileLock*>(NULL), lock.get()); EXPECT_EQ(static_cast<FirefoxProfileLock*>(NULL), lock.get());
...@@ -70,12 +65,8 @@ TEST_F(FirefoxProfileLockTest, ProfileLock) { ...@@ -70,12 +65,8 @@ TEST_F(FirefoxProfileLockTest, ProfileLock) {
// If for some reason the lock file is left behind by the previous owner, we // If for some reason the lock file is left behind by the previous owner, we
// should still be able to lock it, at least in the Windows implementation. // should still be able to lock it, at least in the Windows implementation.
TEST_F(FirefoxProfileLockTest, ProfileLockOrphaned) { TEST_F(FirefoxProfileLockTest, ProfileLockOrphaned) {
FilePath test_path; FilePath test_path = temp_dir_.path();
ASSERT_TRUE(file_util::CreateNewTempDirectory( FilePath lock_file_path = test_path.Append(FirefoxProfileLock::kLockFileName);
FILE_PATH_LITERAL("firefox_profile"), &test_path));
FilePath lock_file_path = test_path;
FileAutoDeleter deleter(lock_file_path);
lock_file_path = lock_file_path.Append(FirefoxProfileLock::kLockFileName);
// Create the orphaned lock file. // Create the orphaned lock file.
FILE* lock_file = file_util::OpenFile(lock_file_path, "w"); FILE* lock_file = file_util::OpenFile(lock_file_path, "w");
...@@ -96,10 +87,7 @@ TEST_F(FirefoxProfileLockTest, ProfileLockOrphaned) { ...@@ -96,10 +87,7 @@ TEST_F(FirefoxProfileLockTest, ProfileLockOrphaned) {
#if !defined(OS_POSIX) #if !defined(OS_POSIX)
// Tests two locks contending for the same lock file. // Tests two locks contending for the same lock file.
TEST_F(FirefoxProfileLockTest, ProfileLockContention) { TEST_F(FirefoxProfileLockTest, ProfileLockContention) {
FilePath test_path; FilePath test_path = temp_dir_.path();
ASSERT_TRUE(file_util::CreateNewTempDirectory(
FILE_PATH_LITERAL("firefox_profile"), &test_path));
FileAutoDeleter deleter(test_path);
scoped_ptr<FirefoxProfileLock> lock1; scoped_ptr<FirefoxProfileLock> lock1;
EXPECT_EQ(static_cast<FirefoxProfileLock*>(NULL), lock1.get()); EXPECT_EQ(static_cast<FirefoxProfileLock*>(NULL), lock1.get());
......
...@@ -9,12 +9,12 @@ ...@@ -9,12 +9,12 @@
#include "base/file_path.h" #include "base/file_path.h"
#include "base/file_util.h" #include "base/file_util.h"
#include "base/path_service.h" #include "base/path_service.h"
#include "base/scoped_temp_dir.h"
#include "base/sys_string_conversions.h" #include "base/sys_string_conversions.h"
#include "base/utf_string_conversions.h" #include "base/utf_string_conversions.h"
#include "chrome/browser/history/history_types.h" #include "chrome/browser/history/history_types.h"
#include "chrome/browser/importer/importer_bridge.h" #include "chrome/browser/importer/importer_bridge.h"
#include "chrome/common/chrome_paths.h" #include "chrome/common/chrome_paths.h"
#include "chrome/test/file_test_utils.h"
#include "testing/platform_test.h" #include "testing/platform_test.h"
// In order to test the Safari import functionality effectively, we store a // In order to test the Safari import functionality effectively, we store a
...@@ -157,8 +157,7 @@ TEST_F(SafariImporterTest, CanImport) { ...@@ -157,8 +157,7 @@ TEST_F(SafariImporterTest, CanImport) {
EXPECT_EQ(items & importer::HOME_PAGE, importer::NONE); EXPECT_EQ(items & importer::HOME_PAGE, importer::NONE);
// Check that we don't import anything from a bogus library directory. // Check that we don't import anything from a bogus library directory.
FilePath fake_library_dir; ScopedTempDir fake_library_dir;
file_util::CreateNewTempDirectory("FakeSafariLibrary", &fake_library_dir); ASSERT_TRUE(fake_library_dir.CreateUniqueTempDir());
FileAutoDeleter deleter(fake_library_dir); EXPECT_FALSE(SafariImporter::CanImport(fake_library_dir.path(), &items));
EXPECT_FALSE(SafariImporter::CanImport(fake_library_dir, &items));
} }
// 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 // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "chrome/browser/safe_browsing/safe_browsing_store_file.h" #include "chrome/browser/safe_browsing/safe_browsing_store_file.h"
#include "base/callback.h" #include "base/callback.h"
#include "base/scoped_temp_dir.h"
#include "chrome/browser/safe_browsing/safe_browsing_store_unittest_helper.h" #include "chrome/browser/safe_browsing/safe_browsing_store_unittest_helper.h"
#include "chrome/test/file_test_utils.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "testing/platform_test.h" #include "testing/platform_test.h"
...@@ -20,19 +20,10 @@ class SafeBrowsingStoreFileTest : public PlatformTest { ...@@ -20,19 +20,10 @@ class SafeBrowsingStoreFileTest : public PlatformTest {
virtual void SetUp() { virtual void SetUp() {
PlatformTest::SetUp(); PlatformTest::SetUp();
FilePath temp_dir; ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
ASSERT_TRUE(file_util::CreateNewTempDirectory(kFolderPrefix, &temp_dir));
file_deleter_.reset(new FileAutoDeleter(temp_dir)); filename_ = temp_dir_.path();
filename_ = temp_dir;
filename_ = filename_.AppendASCII("SafeBrowsingTestStore"); filename_ = filename_.AppendASCII("SafeBrowsingTestStore");
file_util::Delete(filename_, false);
// Make sure an old temporary file isn't hanging around.
const FilePath temp_file =
SafeBrowsingStoreFile::TemporaryFileForFilename(filename_);
file_util::Delete(temp_file, false);
store_.reset(new SafeBrowsingStoreFile()); store_.reset(new SafeBrowsingStoreFile());
store_->Init(filename_, NULL); store_->Init(filename_, NULL);
...@@ -41,7 +32,6 @@ class SafeBrowsingStoreFileTest : public PlatformTest { ...@@ -41,7 +32,6 @@ class SafeBrowsingStoreFileTest : public PlatformTest {
if (store_.get()) if (store_.get())
store_->Delete(); store_->Delete();
store_.reset(); store_.reset();
file_deleter_.reset();
PlatformTest::TearDown(); PlatformTest::TearDown();
} }
...@@ -50,7 +40,7 @@ class SafeBrowsingStoreFileTest : public PlatformTest { ...@@ -50,7 +40,7 @@ class SafeBrowsingStoreFileTest : public PlatformTest {
corruption_detected_ = true; corruption_detected_ = true;
} }
scoped_ptr<FileAutoDeleter> file_deleter_; ScopedTempDir temp_dir_;
FilePath filename_; FilePath filename_;
scoped_ptr<SafeBrowsingStoreFile> store_; scoped_ptr<SafeBrowsingStoreFile> store_;
bool corruption_detected_; bool corruption_detected_;
...@@ -60,8 +50,8 @@ TEST_STORE(SafeBrowsingStoreFileTest, store_.get(), filename_); ...@@ -60,8 +50,8 @@ TEST_STORE(SafeBrowsingStoreFileTest, store_.get(), filename_);
// Test that Delete() deletes the temporary store, if present. // Test that Delete() deletes the temporary store, if present.
TEST_F(SafeBrowsingStoreFileTest, DeleteTemp) { TEST_F(SafeBrowsingStoreFileTest, DeleteTemp) {
const FilePath temp_file = const FilePath temp_file =
SafeBrowsingStoreFile::TemporaryFileForFilename(filename_); SafeBrowsingStoreFile::TemporaryFileForFilename(filename_);
EXPECT_FALSE(file_util::PathExists(filename_)); EXPECT_FALSE(file_util::PathExists(filename_));
EXPECT_FALSE(file_util::PathExists(temp_file)); EXPECT_FALSE(file_util::PathExists(temp_file));
......
...@@ -18,7 +18,6 @@ ...@@ -18,7 +18,6 @@
#include "chrome/browser/sessions/session_types.h" #include "chrome/browser/sessions/session_types.h"
#include "chrome/common/chrome_paths.h" #include "chrome/common/chrome_paths.h"
#include "chrome/test/browser_with_test_window_test.h" #include "chrome/test/browser_with_test_window_test.h"
#include "chrome/test/file_test_utils.h"
#include "chrome/test/testing_profile.h" #include "chrome/test/testing_profile.h"
#include "content/browser/tab_contents/navigation_entry.h" #include "content/browser/tab_contents/navigation_entry.h"
#include "content/common/notification_observer.h" #include "content/common/notification_observer.h"
...@@ -39,8 +38,7 @@ class SessionServiceTest : public BrowserWithTestWindowTest, ...@@ -39,8 +38,7 @@ class SessionServiceTest : public BrowserWithTestWindowTest,
ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
path_ = temp_dir_.path().Append(FILE_PATH_LITERAL("SessionTestDirs")); path_ = temp_dir_.path().Append(FILE_PATH_LITERAL("SessionTestDirs"));
file_util::CreateDirectory(path_); ASSERT_TRUE(file_util::CreateDirectory(path_));
path_deleter_.reset(new FileAutoDeleter(path_));
path_ = path_.AppendASCII(b); path_ = path_.AppendASCII(b);
SessionService* session_service = new SessionService(path_); SessionService* session_service = new SessionService(path_);
...@@ -60,7 +58,6 @@ class SessionServiceTest : public BrowserWithTestWindowTest, ...@@ -60,7 +58,6 @@ class SessionServiceTest : public BrowserWithTestWindowTest,
virtual void TearDown() { virtual void TearDown() {
helper_.set_service(NULL); helper_.set_service(NULL);
path_deleter_.reset();
} }
void UpdateNavigation(const SessionID& window_id, void UpdateNavigation(const SessionID& window_id,
...@@ -136,7 +133,6 @@ class SessionServiceTest : public BrowserWithTestWindowTest, ...@@ -136,7 +133,6 @@ class SessionServiceTest : public BrowserWithTestWindowTest,
// Path used in testing. // Path used in testing.
ScopedTempDir temp_dir_; ScopedTempDir temp_dir_;
FilePath path_; FilePath path_;
scoped_ptr<FileAutoDeleter> path_deleter_;
SessionServiceTestHelper helper_; SessionServiceTestHelper helper_;
}; };
......
...@@ -29,7 +29,6 @@ ...@@ -29,7 +29,6 @@
#include "chrome/browser/sync/test_profile_sync_service.h" #include "chrome/browser/sync/test_profile_sync_service.h"
#include "chrome/common/net/gaia/gaia_constants.h" #include "chrome/common/net/gaia/gaia_constants.h"
#include "chrome/test/browser_with_test_window_test.h" #include "chrome/test/browser_with_test_window_test.h"
#include "chrome/test/file_test_utils.h"
#include "chrome/test/profile_mock.h" #include "chrome/test/profile_mock.h"
#include "chrome/test/sync/engine/test_id_factory.h" #include "chrome/test/sync/engine/test_id_factory.h"
#include "chrome/test/testing_profile.h" #include "chrome/test/testing_profile.h"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment