summaryrefslogtreecommitdiffstats
path: root/chrome/common
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/common
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/common')
-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
3 files changed, 20 insertions, 49 deletions
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);