Commit f1a8760c authored by munjal@chromium.org's avatar munjal@chromium.org

Clean-up temporary files/folders in firefox importer tests.

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@17238 0039d316-1c4b-4281-b951-d872f2087c98
parent 6af916aa
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "chrome/browser/importer/firefox_importer_utils.h" #include "chrome/browser/importer/firefox_importer_utils.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"
using base::Time; using base::Time;
...@@ -148,6 +149,7 @@ TEST(FirefoxImporterTest, ProfileLock) { ...@@ -148,6 +149,7 @@ TEST(FirefoxImporterTest, ProfileLock) {
std::wstring test_path; std::wstring test_path;
file_util::CreateNewTempDirectory(L"firefox_profile", &test_path); file_util::CreateNewTempDirectory(L"firefox_profile", &test_path);
FilePath lock_file_path = FilePath::FromWStringHack(test_path); FilePath lock_file_path = FilePath::FromWStringHack(test_path);
FileAutoDeleter deleter(lock_file_path);
lock_file_path = lock_file_path.Append(FirefoxProfileLock::kLockFileName); lock_file_path = lock_file_path.Append(FirefoxProfileLock::kLockFileName);
scoped_ptr<FirefoxProfileLock> lock; scoped_ptr<FirefoxProfileLock> lock;
...@@ -175,6 +177,7 @@ TEST(FirefoxImporterTest, ProfileLockOrphaned) { ...@@ -175,6 +177,7 @@ TEST(FirefoxImporterTest, ProfileLockOrphaned) {
std::wstring test_path; std::wstring test_path;
file_util::CreateNewTempDirectory(L"firefox_profile", &test_path); file_util::CreateNewTempDirectory(L"firefox_profile", &test_path);
FilePath lock_file_path = FilePath::FromWStringHack(test_path); FilePath lock_file_path = FilePath::FromWStringHack(test_path);
FileAutoDeleter deleter(lock_file_path);
lock_file_path = lock_file_path.Append(FirefoxProfileLock::kLockFileName); lock_file_path = lock_file_path.Append(FirefoxProfileLock::kLockFileName);
// Create the orphaned lock file. // Create the orphaned lock file.
...@@ -195,6 +198,7 @@ TEST(FirefoxImporterTest, ProfileLockOrphaned) { ...@@ -195,6 +198,7 @@ TEST(FirefoxImporterTest, ProfileLockOrphaned) {
TEST(FirefoxImporterTest, ProfileLockContention) { TEST(FirefoxImporterTest, ProfileLockContention) {
std::wstring test_path; std::wstring test_path;
file_util::CreateNewTempDirectory(L"firefox_profile", &test_path); file_util::CreateNewTempDirectory(L"firefox_profile", &test_path);
FileAutoDeleter deleter(FilePath::FromWStringHack(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());
......
...@@ -3144,6 +3144,8 @@ ...@@ -3144,6 +3144,8 @@
'renderer/renderer_main_unittest.cc', 'renderer/renderer_main_unittest.cc',
'test/browser_with_test_window_test.cc', 'test/browser_with_test_window_test.cc',
'test/browser_with_test_window_test.h', 'test/browser_with_test_window_test.h',
'test/file_test_utils.h',
'test/file_test_utils.cc',
'test/render_view_test.cc', 'test/render_view_test.cc',
'test/render_view_test.h', 'test/render_view_test.h',
'test/test_notification_tracker.cc', 'test/test_notification_tracker.cc',
......
// Copyright (c) 2006-2009 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 "chrome/test/file_test_utils.h"
FileAutoDeleter::FileAutoDeleter(const FilePath& path)
: path_(path) {
}
FileAutoDeleter::~FileAutoDeleter() {
file_util::Delete(path_, true);
}
// Copyright (c) 2006-2009 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.
#ifndef CHROME_TEST_FILE_TEST_UTILS_H_
#define CHROME_TEST_FILE_TEST_UTILS_H_
#include "base/file_path.h"
#include "base/file_util.h"
// Auto deletes file/folder when it goes out-of-scope. This is useful for tests
// to cleanup files/folder automatically.
class FileAutoDeleter {
public:
explicit FileAutoDeleter(const FilePath& path);
~FileAutoDeleter();
const FilePath& path() { return path_; }
private:
FilePath path_;
DISALLOW_EVIL_CONSTRUCTORS(FileAutoDeleter);
};
#endif // CHROME_TEST_FILE_TEST_UTILS_H_
...@@ -161,6 +161,14 @@ ...@@ -161,6 +161,14 @@
RelativePath=".\chrome_test_suite.h" RelativePath=".\chrome_test_suite.h"
> >
</File> </File>
<File
RelativePath="..\file_test_utils.cc"
>
</File>
<File
RelativePath="..\file_test_utils.h"
>
</File>
<File <File
RelativePath="..\in_process_browser_test.cc" RelativePath="..\in_process_browser_test.cc"
> >
......
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