Index: chrome/common/json_pref_store_unittest.cc |
diff --git a/chrome/common/json_pref_store_unittest.cc b/chrome/common/json_pref_store_unittest.cc |
index fcec0ead6571b632d7bfa59c613fb2219d4ea5cc..e02a01a9c2e4168e69ff338c31220a144d25e83b 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,13 +23,8 @@ 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"); |
@@ -36,13 +32,10 @@ class JsonPrefStoreTest : public testing::Test { |
} |
virtual void TearDown() { |
Paweł Hajdan Jr.
2011/04/08 15:58:17
Empty TearDown can be removed.
Mike West
2011/04/11 14:47:04
Done.
|
- // 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_; |
// 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. |
@@ -64,7 +57,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 +67,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 +75,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()); |