summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-15 22:33:47 +0000
committerrvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-15 22:33:47 +0000
commit79b3fec81e7ea7e4c35822588b1b61d5361e9f4b (patch)
treec0923710e5db89ee91ae37b304ed2e15e986c657
parentc19d954f05f2b5cdc65c6e7cedf0f825643a2c68 (diff)
downloadchromium_src-79b3fec81e7ea7e4c35822588b1b61d5361e9f4b.zip
chromium_src-79b3fec81e7ea7e4c35822588b1b61d5361e9f4b.tar.gz
chromium_src-79b3fec81e7ea7e4c35822588b1b61d5361e9f4b.tar.bz2
Disk cache: Simplify some of the test infrastructure.
BUG=none TEST=none Review URL: http://codereview.chromium.org/8463031 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@110192 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--net/disk_cache/backend_unittest.cc39
-rw-r--r--net/disk_cache/block_files_unittest.cc58
-rw-r--r--net/disk_cache/disk_cache_perftest.cc30
-rw-r--r--net/disk_cache/disk_cache_test_base.cc49
-rw-r--r--net/disk_cache/disk_cache_test_base.h21
-rw-r--r--net/disk_cache/disk_cache_test_util.cc16
-rw-r--r--net/disk_cache/disk_cache_test_util.h5
-rw-r--r--net/disk_cache/mapped_file_unittest.cc4
-rw-r--r--net/disk_cache/storage_block_unittest.cc8
-rw-r--r--net/net.gyp4
10 files changed, 118 insertions, 116 deletions
diff --git a/net/disk_cache/backend_unittest.cc b/net/disk_cache/backend_unittest.cc
index 1066639..b102193 100644
--- a/net/disk_cache/backend_unittest.cc
+++ b/net/disk_cache/backend_unittest.cc
@@ -198,8 +198,7 @@ TEST_F(DiskCacheTest, CreateBackend) {
TestOldCompletionCallback cb;
{
- FilePath path = GetCacheFilePath();
- ASSERT_TRUE(DeleteCache(path));
+ ASSERT_TRUE(CleanupCacheDir());
base::Thread cache_thread("CacheThread");
ASSERT_TRUE(cache_thread.StartWithOptions(
base::Thread::Options(MessageLoop::TYPE_IO, 0)));
@@ -207,7 +206,7 @@ TEST_F(DiskCacheTest, CreateBackend) {
// Test the private factory methods.
disk_cache::Backend* cache = NULL;
int rv = disk_cache::BackendImpl::CreateBackend(
- path, false, 0, net::DISK_CACHE, disk_cache::kNoRandom,
+ cache_path_, false, 0, net::DISK_CACHE, disk_cache::kNoRandom,
cache_thread.message_loop_proxy(), NULL, &cache, &cb);
ASSERT_EQ(net::OK, cb.GetResult(rv));
ASSERT_TRUE(cache);
@@ -219,7 +218,7 @@ TEST_F(DiskCacheTest, CreateBackend) {
cache = NULL;
// Now test the public API.
- rv = disk_cache::CreateCacheBackend(net::DISK_CACHE, path, 0, false,
+ rv = disk_cache::CreateCacheBackend(net::DISK_CACHE, cache_path_, 0, false,
cache_thread.message_loop_proxy(),
NULL, &cache, &cb);
ASSERT_EQ(net::OK, cb.GetResult(rv));
@@ -240,7 +239,7 @@ TEST_F(DiskCacheTest, CreateBackend) {
TEST_F(DiskCacheBackendTest, ExternalFiles) {
InitCache();
// First, let's create a file on the folder.
- FilePath filename = GetCacheFilePath().AppendASCII("f_000001");
+ FilePath filename = cache_path_.AppendASCII("f_000001");
const int kSize = 50;
scoped_refptr<net::IOBuffer> buffer1(new net::IOBuffer(kSize));
@@ -264,15 +263,14 @@ TEST_F(DiskCacheTest, ShutdownWithPendingIO) {
TestOldCompletionCallback cb;
{
- FilePath path = GetCacheFilePath();
- ASSERT_TRUE(DeleteCache(path));
+ ASSERT_TRUE(CleanupCacheDir());
base::Thread cache_thread("CacheThread");
ASSERT_TRUE(cache_thread.StartWithOptions(
base::Thread::Options(MessageLoop::TYPE_IO, 0)));
disk_cache::Backend* cache;
int rv = disk_cache::BackendImpl::CreateBackend(
- path, false, 0, net::DISK_CACHE, disk_cache::kNoRandom,
+ cache_path_, false, 0, net::DISK_CACHE, disk_cache::kNoRandom,
base::MessageLoopProxy::current(), NULL,
&cache, &cb);
ASSERT_EQ(net::OK, cb.GetResult(rv));
@@ -316,15 +314,14 @@ TEST_F(DiskCacheTest, ShutdownWithPendingIO2) {
TestOldCompletionCallback cb;
{
- FilePath path = GetCacheFilePath();
- ASSERT_TRUE(DeleteCache(path));
+ ASSERT_TRUE(CleanupCacheDir());
base::Thread cache_thread("CacheThread");
ASSERT_TRUE(cache_thread.StartWithOptions(
base::Thread::Options(MessageLoop::TYPE_IO, 0)));
disk_cache::Backend* cache;
int rv = disk_cache::BackendImpl::CreateBackend(
- path, false, 0, net::DISK_CACHE, disk_cache::kNoRandom,
+ cache_path_, false, 0, net::DISK_CACHE, disk_cache::kNoRandom,
cache_thread.message_loop_proxy(), NULL, &cache, &cb);
ASSERT_EQ(net::OK, cb.GetResult(rv));
@@ -349,9 +346,8 @@ TEST_F(DiskCacheTest, ShutdownWithPendingIO2) {
}
TEST_F(DiskCacheTest, TruncatedIndex) {
- FilePath path = GetCacheFilePath();
- ASSERT_TRUE(DeleteCache(path));
- FilePath index = path.AppendASCII("index");
+ ASSERT_TRUE(CleanupCacheDir());
+ FilePath index = cache_path_.AppendASCII("index");
ASSERT_EQ(5, file_util::WriteFile(index, "hello", 5));
base::Thread cache_thread("CacheThread");
@@ -361,7 +357,7 @@ TEST_F(DiskCacheTest, TruncatedIndex) {
disk_cache::Backend* backend = NULL;
int rv = disk_cache::BackendImpl::CreateBackend(
- path, false, 0, net::DISK_CACHE, disk_cache::kNone,
+ cache_path_, false, 0, net::DISK_CACHE, disk_cache::kNone,
cache_thread.message_loop_proxy(), NULL, &backend, &cb);
ASSERT_NE(net::OK, cb.GetResult(rv));
@@ -1235,7 +1231,7 @@ void DiskCacheBackendTest::BackendTransaction(const std::string& name,
cache_ = NULL;
cache_impl_ = NULL;
- ASSERT_TRUE(CheckCacheIntegrity(GetCacheFilePath(), new_eviction_, mask));
+ ASSERT_TRUE(CheckCacheIntegrity(cache_path_, new_eviction_, mask));
success_ = true;
}
@@ -1346,7 +1342,6 @@ TEST_F(DiskCacheBackendTest, NewEvictionRecoverWithEviction) {
// Tests dealing with cache files that cannot be recovered.
TEST_F(DiskCacheTest, DeleteOld) {
ASSERT_TRUE(CopyTestCache("wrong_version"));
- FilePath path = GetCacheFilePath();
base::Thread cache_thread("CacheThread");
ASSERT_TRUE(cache_thread.StartWithOptions(
base::Thread::Options(MessageLoop::TYPE_IO, 0)));
@@ -1354,7 +1349,7 @@ TEST_F(DiskCacheTest, DeleteOld) {
disk_cache::Backend* cache;
int rv = disk_cache::BackendImpl::CreateBackend(
- path, true, 0, net::DISK_CACHE, disk_cache::kNoRandom,
+ cache_path_, true, 0, net::DISK_CACHE, disk_cache::kNoRandom,
cache_thread.message_loop_proxy(), NULL, &cache, &cb);
ASSERT_EQ(net::OK, cb.GetResult(rv));
@@ -1881,7 +1876,6 @@ TEST_F(DiskCacheBackendTest, NewEvictionNotMarkedButDirty2) {
// We want to be able to deal with messed up entries on disk.
void DiskCacheBackendTest::BackendInvalidRankings2() {
ASSERT_TRUE(CopyTestCache("bad_rankings"));
- FilePath path = GetCacheFilePath();
DisableFirstCleanup();
InitCache();
@@ -2162,11 +2156,10 @@ TEST_F(DiskCacheBackendTest, NewEvictionDisableSuccess4) {
TEST_F(DiskCacheTest, Backend_UsageStats) {
MessageLoopHelper helper;
- FilePath path = GetCacheFilePath();
- ASSERT_TRUE(DeleteCache(path));
+ ASSERT_TRUE(CleanupCacheDir());
scoped_ptr<disk_cache::BackendImpl> cache;
cache.reset(new disk_cache::BackendImpl(
- path, base::MessageLoopProxy::current(),
+ cache_path_, base::MessageLoopProxy::current(),
NULL));
ASSERT_TRUE(NULL != cache.get());
cache->SetUnitTestMode();
@@ -2271,7 +2264,7 @@ TEST_F(DiskCacheBackendTest, NewEvictionDoomAll2) {
// We should be able to create the same entry on multiple simultaneous instances
// of the cache.
TEST_F(DiskCacheTest, MultipleInstances) {
- ScopedTestCache store1;
+ ScopedTestCache store1(cache_path_);
ScopedTestCache store2("cache_test2");
ScopedTestCache store3("cache_test3");
base::Thread cache_thread("CacheThread");
diff --git a/net/disk_cache/block_files_unittest.cc b/net/disk_cache/block_files_unittest.cc
index 7ee08d3..cabedf4 100644
--- a/net/disk_cache/block_files_unittest.cc
+++ b/net/disk_cache/block_files_unittest.cc
@@ -28,11 +28,10 @@ int NumberOfFiles(const FilePath& path) {
namespace disk_cache {
TEST_F(DiskCacheTest, BlockFiles_Grow) {
- FilePath path = GetCacheFilePath();
- ASSERT_TRUE(DeleteCache(path));
- ASSERT_TRUE(file_util::CreateDirectory(path));
+ ASSERT_TRUE(CleanupCacheDir());
+ ASSERT_TRUE(file_util::CreateDirectory(cache_path_));
- BlockFiles files(path);
+ BlockFiles files(cache_path_);
ASSERT_TRUE(files.Init(true));
const int kMaxSize = 35000;
@@ -42,7 +41,7 @@ TEST_F(DiskCacheTest, BlockFiles_Grow) {
for (int i = 0; i < kMaxSize; i++) {
EXPECT_TRUE(files.CreateBlock(RANKINGS, 4, &address[i]));
}
- EXPECT_EQ(6, NumberOfFiles(path));
+ EXPECT_EQ(6, NumberOfFiles(cache_path_));
// Make sure we don't keep adding files.
for (int i = 0; i < kMaxSize * 4; i += 2) {
@@ -50,16 +49,15 @@ TEST_F(DiskCacheTest, BlockFiles_Grow) {
files.DeleteBlock(address[target], false);
EXPECT_TRUE(files.CreateBlock(RANKINGS, 4, &address[target]));
}
- EXPECT_EQ(6, NumberOfFiles(path));
+ EXPECT_EQ(6, NumberOfFiles(cache_path_));
}
// We should be able to delete empty block files.
TEST_F(DiskCacheTest, BlockFiles_Shrink) {
- FilePath path = GetCacheFilePath();
- ASSERT_TRUE(DeleteCache(path));
- ASSERT_TRUE(file_util::CreateDirectory(path));
+ ASSERT_TRUE(CleanupCacheDir());
+ ASSERT_TRUE(file_util::CreateDirectory(cache_path_));
- BlockFiles files(path);
+ BlockFiles files(cache_path_);
ASSERT_TRUE(files.Init(true));
const int kMaxSize = 35000;
@@ -74,16 +72,15 @@ TEST_F(DiskCacheTest, BlockFiles_Shrink) {
for (int i = 0; i < kMaxSize; i++) {
files.DeleteBlock(address[i], false);
}
- EXPECT_EQ(4, NumberOfFiles(path));
+ EXPECT_EQ(4, NumberOfFiles(cache_path_));
}
// Handling of block files not properly closed.
TEST_F(DiskCacheTest, BlockFiles_Recover) {
- FilePath path = GetCacheFilePath();
- ASSERT_TRUE(DeleteCache(path));
- ASSERT_TRUE(file_util::CreateDirectory(path));
+ ASSERT_TRUE(CleanupCacheDir());
+ ASSERT_TRUE(file_util::CreateDirectory(cache_path_));
- BlockFiles files(path);
+ BlockFiles files(cache_path_);
ASSERT_TRUE(files.Init(true));
const int kNumEntries = 2000;
@@ -157,11 +154,10 @@ TEST_F(DiskCacheTest, BlockFiles_Recover) {
// Handling of truncated files.
TEST_F(DiskCacheTest, BlockFiles_ZeroSizeFile) {
- FilePath path = GetCacheFilePath();
- ASSERT_TRUE(DeleteCache(path));
- ASSERT_TRUE(file_util::CreateDirectory(path));
+ ASSERT_TRUE(CleanupCacheDir());
+ ASSERT_TRUE(file_util::CreateDirectory(cache_path_));
- BlockFiles files(path);
+ BlockFiles files(cache_path_);
ASSERT_TRUE(files.Init(true));
FilePath filename = files.Name(0);
@@ -179,11 +175,10 @@ TEST_F(DiskCacheTest, BlockFiles_ZeroSizeFile) {
// Handling of truncated files (non empty).
TEST_F(DiskCacheTest, BlockFiles_TruncatedFile) {
- FilePath path = GetCacheFilePath();
- ASSERT_TRUE(DeleteCache(path));
- ASSERT_TRUE(file_util::CreateDirectory(path));
+ ASSERT_TRUE(CleanupCacheDir());
+ ASSERT_TRUE(file_util::CreateDirectory(cache_path_));
- BlockFiles files(path);
+ BlockFiles files(cache_path_);
ASSERT_TRUE(files.Init(true));
Addr address;
EXPECT_TRUE(files.CreateBlock(RANKINGS, 2, &address));
@@ -203,11 +198,10 @@ TEST_F(DiskCacheTest, BlockFiles_TruncatedFile) {
// An invalid file can be detected after init.
TEST_F(DiskCacheTest, BlockFiles_InvalidFile) {
- FilePath path = GetCacheFilePath();
- ASSERT_TRUE(DeleteCache(path));
- ASSERT_TRUE(file_util::CreateDirectory(path));
+ ASSERT_TRUE(CleanupCacheDir());
+ ASSERT_TRUE(file_util::CreateDirectory(cache_path_));
- BlockFiles files(path);
+ BlockFiles files(cache_path_);
ASSERT_TRUE(files.Init(true));
// Let's access block 10 of file 5. (There is no file).
@@ -230,9 +224,8 @@ TEST_F(DiskCacheTest, BlockFiles_InvalidFile) {
// Tests that we generate the correct file stats.
TEST_F(DiskCacheTest, BlockFiles_Stats) {
ASSERT_TRUE(CopyTestCache("remove_load1"));
- FilePath path = GetCacheFilePath();
- BlockFiles files(path);
+ BlockFiles files(cache_path_);
ASSERT_TRUE(files.Init(false));
int used, load;
@@ -251,11 +244,10 @@ TEST_F(DiskCacheTest, BlockFiles_Stats) {
// Tests that we add and remove blocks correctly.
TEST_F(DiskCacheTest, AllocationMap) {
- FilePath path = GetCacheFilePath();
- ASSERT_TRUE(DeleteCache(path));
- ASSERT_TRUE(file_util::CreateDirectory(path));
+ ASSERT_TRUE(CleanupCacheDir());
+ ASSERT_TRUE(file_util::CreateDirectory(cache_path_));
- BlockFiles files(path);
+ BlockFiles files(cache_path_);
ASSERT_TRUE(files.Init(true));
// Create a bunch of entries.
diff --git a/net/disk_cache/disk_cache_perftest.cc b/net/disk_cache/disk_cache_perftest.cc
index 4bf46f7..4115a15 100644
--- a/net/disk_cache/disk_cache_perftest.cc
+++ b/net/disk_cache/disk_cache_perftest.cc
@@ -5,8 +5,6 @@
#include <string>
#include "base/basictypes.h"
-#include "base/file_path.h"
-#include "base/file_util.h"
#include "base/perftimer.h"
#include "base/string_util.h"
#include "base/threading/thread.h"
@@ -16,7 +14,9 @@
#include "net/base/net_errors.h"
#include "net/base/test_completion_callback.h"
#include "net/disk_cache/block_files.h"
+#include "net/disk_cache/backend_impl.h"
#include "net/disk_cache/disk_cache.h"
+#include "net/disk_cache/disk_cache_test_base.h"
#include "net/disk_cache/disk_cache_test_util.h"
#include "net/disk_cache/hash.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -24,8 +24,6 @@
using base::Time;
-typedef PlatformTest DiskCacheTest;
-
namespace {
struct TestEntry {
@@ -151,17 +149,15 @@ TEST_F(DiskCacheTest, Hash) {
}
TEST_F(DiskCacheTest, CacheBackendPerformance) {
- MessageLoopForIO message_loop;
-
base::Thread cache_thread("CacheThread");
ASSERT_TRUE(cache_thread.StartWithOptions(
base::Thread::Options(MessageLoop::TYPE_IO, 0)));
- ScopedTestCache test_cache;
+ ASSERT_TRUE(CleanupCacheDir());
TestOldCompletionCallback cb;
disk_cache::Backend* cache;
int rv = disk_cache::CreateCacheBackend(
- net::DISK_CACHE, test_cache.path(), 0, false,
+ net::DISK_CACHE, cache_path_, 0, false,
cache_thread.message_loop_proxy(), NULL, &cache, &cb);
ASSERT_EQ(net::OK, cb.GetResult(rv));
@@ -178,17 +174,17 @@ TEST_F(DiskCacheTest, CacheBackendPerformance) {
delete cache;
ASSERT_TRUE(file_util::EvictFileFromSystemCache(
- test_cache.path().AppendASCII("index")));
+ cache_path_.AppendASCII("index")));
ASSERT_TRUE(file_util::EvictFileFromSystemCache(
- test_cache.path().AppendASCII("data_0")));
+ cache_path_.AppendASCII("data_0")));
ASSERT_TRUE(file_util::EvictFileFromSystemCache(
- test_cache.path().AppendASCII("data_1")));
+ cache_path_.AppendASCII("data_1")));
ASSERT_TRUE(file_util::EvictFileFromSystemCache(
- test_cache.path().AppendASCII("data_2")));
+ cache_path_.AppendASCII("data_2")));
ASSERT_TRUE(file_util::EvictFileFromSystemCache(
- test_cache.path().AppendASCII("data_3")));
+ cache_path_.AppendASCII("data_3")));
- rv = disk_cache::CreateCacheBackend(net::DISK_CACHE, test_cache.path(), 0,
+ rv = disk_cache::CreateCacheBackend(net::DISK_CACHE, cache_path_, 0,
false, cache_thread.message_loop_proxy(),
NULL, &cache, &cb);
ASSERT_EQ(net::OK, cb.GetResult(rv));
@@ -207,11 +203,9 @@ TEST_F(DiskCacheTest, CacheBackendPerformance) {
// fragmented, or if we have multiple files. This test measures that scenario,
// by using multiple, highly fragmented files.
TEST_F(DiskCacheTest, BlockFilesPerformance) {
- MessageLoopForIO message_loop;
-
- ScopedTestCache test_cache;
+ ASSERT_TRUE(CleanupCacheDir());
- disk_cache::BlockFiles files(test_cache.path());
+ disk_cache::BlockFiles files(cache_path_);
ASSERT_TRUE(files.Init(true));
int seed = static_cast<int>(Time::Now().ToInternalValue());
diff --git a/net/disk_cache/disk_cache_test_base.cc b/net/disk_cache/disk_cache_test_base.cc
index 28c1233..ec5f67c 100644
--- a/net/disk_cache/disk_cache_test_base.cc
+++ b/net/disk_cache/disk_cache_test_base.cc
@@ -4,6 +4,8 @@
#include "net/disk_cache/disk_cache_test_base.h"
+#include "base/file_util.h"
+#include "base/path_service.h"
#include "net/base/io_buffer.h"
#include "net/base/net_errors.h"
#include "net/base/test_completion_callback.h"
@@ -11,6 +13,32 @@
#include "net/disk_cache/disk_cache_test_util.h"
#include "net/disk_cache/mem_backend_impl.h"
+DiskCacheTest::DiskCacheTest() {
+ cache_path_ = GetCacheFilePath();
+ if (!MessageLoop::current())
+ message_loop_.reset(new MessageLoopForIO());
+}
+
+DiskCacheTest::~DiskCacheTest() {
+}
+
+bool DiskCacheTest::CopyTestCache(const std::string& name) {
+ FilePath path;
+ PathService::Get(base::DIR_SOURCE_ROOT, &path);
+ path = path.AppendASCII("net");
+ path = path.AppendASCII("data");
+ path = path.AppendASCII("cache_tests");
+ path = path.AppendASCII(name);
+
+ if (!CleanupCacheDir())
+ return false;
+ return file_util::CopyDirectory(path, cache_path_, false);
+}
+
+bool DiskCacheTest::CleanupCacheDir() {
+ return DeleteCache(cache_path_);
+}
+
void DiskCacheTest::TearDown() {
MessageLoop::current()->RunAllPending();
}
@@ -57,10 +85,9 @@ void DiskCacheTestWithCache::SimulateCrash() {
cache_impl_->ClearRefCountForTest();
delete cache_impl_;
- FilePath path = GetCacheFilePath();
- EXPECT_TRUE(CheckCacheIntegrity(path, new_eviction_, mask_));
+ EXPECT_TRUE(CheckCacheIntegrity(cache_path_, new_eviction_, mask_));
- InitDiskCacheImpl(path);
+ InitDiskCacheImpl();
}
void DiskCacheTestWithCache::SetTestMode() {
@@ -212,8 +239,7 @@ void DiskCacheTestWithCache::TearDown() {
cache_thread_.Stop();
if (!memory_only_ && integrity_) {
- FilePath path = GetCacheFilePath();
- EXPECT_TRUE(CheckCacheIntegrity(path, new_eviction_, mask_));
+ EXPECT_TRUE(CheckCacheIntegrity(cache_path_, new_eviction_, mask_));
}
PlatformTest::TearDown();
@@ -236,9 +262,8 @@ void DiskCacheTestWithCache::InitMemoryCache() {
}
void DiskCacheTestWithCache::InitDiskCache() {
- FilePath path = GetCacheFilePath();
if (first_cleanup_)
- ASSERT_TRUE(DeleteCache(path));
+ ASSERT_TRUE(CleanupCacheDir());
if (!cache_thread_.IsRunning()) {
EXPECT_TRUE(cache_thread_.StartWithOptions(
@@ -247,7 +272,7 @@ void DiskCacheTestWithCache::InitDiskCache() {
ASSERT_TRUE(cache_thread_.message_loop() != NULL);
if (implementation_)
- return InitDiskCacheImpl(path);
+ return InitDiskCacheImpl();
scoped_refptr<base::MessageLoopProxy> thread =
use_current_thread_ ? base::MessageLoopProxy::current() :
@@ -255,19 +280,19 @@ void DiskCacheTestWithCache::InitDiskCache() {
TestOldCompletionCallback cb;
int rv = disk_cache::BackendImpl::CreateBackend(
- path, force_creation_, size_, type_,
+ cache_path_, force_creation_, size_, type_,
disk_cache::kNoRandom, thread, NULL, &cache_, &cb);
ASSERT_EQ(net::OK, cb.GetResult(rv));
}
-void DiskCacheTestWithCache::InitDiskCacheImpl(const FilePath& path) {
+void DiskCacheTestWithCache::InitDiskCacheImpl() {
scoped_refptr<base::MessageLoopProxy> thread =
use_current_thread_ ? base::MessageLoopProxy::current() :
cache_thread_.message_loop_proxy();
if (mask_)
- cache_impl_ = new disk_cache::BackendImpl(path, mask_, thread, NULL);
+ cache_impl_ = new disk_cache::BackendImpl(cache_path_, mask_, thread, NULL);
else
- cache_impl_ = new disk_cache::BackendImpl(path, thread, NULL);
+ cache_impl_ = new disk_cache::BackendImpl(cache_path_, thread, NULL);
cache_ = cache_impl_;
ASSERT_TRUE(NULL != cache_);
diff --git a/net/disk_cache/disk_cache_test_base.h b/net/disk_cache/disk_cache_test_base.h
index acd3ebd..9759a2b 100644
--- a/net/disk_cache/disk_cache_test_base.h
+++ b/net/disk_cache/disk_cache_test_base.h
@@ -7,13 +7,13 @@
#pragma once
#include "base/basictypes.h"
+#include "base/file_path.h"
+#include "base/memory/scoped_ptr.h"
#include "base/threading/thread.h"
#include "net/base/cache_type.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/platform_test.h"
-class FilePath;
-
namespace net {
class IOBuffer;
@@ -34,7 +34,22 @@ class MemBackendImpl;
// cache (and that do not need to be a DiskCacheTestWithCache) are susceptible
// to this problem; all such tests should use TEST_F(DiskCacheTest, ...).
class DiskCacheTest : public PlatformTest {
+ protected:
+ DiskCacheTest();
+ virtual ~DiskCacheTest();
+
+ // Copies a set of cache files from the data folder to the test folder.
+ bool CopyTestCache(const std::string& name);
+
+ // Deletes the contents of |cache_path_|.
+ bool CleanupCacheDir();
+
virtual void TearDown();
+
+ FilePath cache_path_;
+
+ private:
+ scoped_ptr<MessageLoop> message_loop_;
};
// Provides basic support for cache related tests.
@@ -140,7 +155,7 @@ class DiskCacheTestWithCache : public DiskCacheTest {
private:
void InitMemoryCache();
void InitDiskCache();
- void InitDiskCacheImpl(const FilePath& path);
+ void InitDiskCacheImpl();
base::Thread cache_thread_;
DISALLOW_COPY_AND_ASSIGN(DiskCacheTestWithCache);
diff --git a/net/disk_cache/disk_cache_test_util.cc b/net/disk_cache/disk_cache_test_util.cc
index 1a348cf..4692eac 100644
--- a/net/disk_cache/disk_cache_test_util.cc
+++ b/net/disk_cache/disk_cache_test_util.cc
@@ -78,20 +78,6 @@ bool DeleteCache(const FilePath& path) {
return true;
}
-bool CopyTestCache(const std::string& name) {
- FilePath path;
- PathService::Get(base::DIR_SOURCE_ROOT, &path);
- path = path.AppendASCII("net");
- path = path.AppendASCII("data");
- path = path.AppendASCII("cache_tests");
- path = path.AppendASCII(name);
-
- FilePath dest = GetCacheFilePath();
- if (!DeleteCache(dest))
- return false;
- return file_util::CopyDirectory(path, dest, false);
-}
-
bool CheckCacheIntegrity(const FilePath& path, bool new_eviction, uint32 mask) {
scoped_ptr<disk_cache::BackendImpl> cache(new disk_cache::BackendImpl(
path, mask, base::MessageLoopProxy::current(), NULL));
@@ -105,7 +91,7 @@ bool CheckCacheIntegrity(const FilePath& path, bool new_eviction, uint32 mask) {
return cache->SelfCheck() >= 0;
}
-ScopedTestCache::ScopedTestCache() : path_(GetCacheFilePath()) {
+ScopedTestCache::ScopedTestCache(const FilePath& path) : path_(path) {
bool result = DeleteCache(path_);
DCHECK(result);
}
diff --git a/net/disk_cache/disk_cache_test_util.h b/net/disk_cache/disk_cache_test_util.h
index 6469761..edc090a 100644
--- a/net/disk_cache/disk_cache_test_util.h
+++ b/net/disk_cache/disk_cache_test_util.h
@@ -21,9 +21,6 @@ bool CreateCacheTestFile(const FilePath& name);
// Deletes all file son the cache.
bool DeleteCache(const FilePath& path);
-// Copies a set of cache files from the data folder to the test folder.
-bool CopyTestCache(const std::string& name);
-
// Gets the path to the cache test folder.
FilePath GetCacheFilePath();
@@ -40,7 +37,7 @@ bool CheckCacheIntegrity(const FilePath& path, bool new_eviction, uint32 mask);
// exists and is clear in ctor and that the directory gets deleted in dtor.
class ScopedTestCache {
public:
- ScopedTestCache();
+ explicit ScopedTestCache(const FilePath& path);
// Use a specific folder name.
explicit ScopedTestCache(const std::string& name);
~ScopedTestCache();
diff --git a/net/disk_cache/mapped_file_unittest.cc b/net/disk_cache/mapped_file_unittest.cc
index 1ab80b1..fa566eb 100644
--- a/net/disk_cache/mapped_file_unittest.cc
+++ b/net/disk_cache/mapped_file_unittest.cc
@@ -42,7 +42,7 @@ void FileCallbackTest::OnFileIOComplete(int bytes_copied) {
} // namespace
TEST_F(DiskCacheTest, MappedFile_SyncIO) {
- FilePath filename = GetCacheFilePath().AppendASCII("a_test");
+ FilePath filename = cache_path_.AppendASCII("a_test");
scoped_refptr<disk_cache::MappedFile> file(new disk_cache::MappedFile);
ASSERT_TRUE(CreateCacheTestFile(filename));
ASSERT_TRUE(file->Init(filename, 8192));
@@ -57,7 +57,7 @@ TEST_F(DiskCacheTest, MappedFile_SyncIO) {
}
TEST_F(DiskCacheTest, MappedFile_AsyncIO) {
- FilePath filename = GetCacheFilePath().AppendASCII("a_test");
+ FilePath filename = cache_path_.AppendASCII("a_test");
scoped_refptr<disk_cache::MappedFile> file(new disk_cache::MappedFile);
ASSERT_TRUE(CreateCacheTestFile(filename));
ASSERT_TRUE(file->Init(filename, 8192));
diff --git a/net/disk_cache/storage_block_unittest.cc b/net/disk_cache/storage_block_unittest.cc
index c9406b6..1a3ec29 100644
--- a/net/disk_cache/storage_block_unittest.cc
+++ b/net/disk_cache/storage_block_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2006-2008 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.
@@ -10,7 +10,7 @@
#include "testing/gtest/include/gtest/gtest.h"
TEST_F(DiskCacheTest, StorageBlock_LoadStore) {
- FilePath filename = GetCacheFilePath().AppendASCII("a_test");
+ FilePath filename = cache_path_.AppendASCII("a_test");
scoped_refptr<disk_cache::MappedFile> file(new disk_cache::MappedFile);
ASSERT_TRUE(CreateCacheTestFile(filename));
ASSERT_TRUE(file->Init(filename, 8192));
@@ -30,7 +30,7 @@ TEST_F(DiskCacheTest, StorageBlock_LoadStore) {
}
TEST_F(DiskCacheTest, StorageBlock_SetData) {
- FilePath filename = GetCacheFilePath().AppendASCII("a_test");
+ FilePath filename = cache_path_.AppendASCII("a_test");
scoped_refptr<disk_cache::MappedFile> file(new disk_cache::MappedFile);
ASSERT_TRUE(CreateCacheTestFile(filename));
ASSERT_TRUE(file->Init(filename, 8192));
@@ -50,7 +50,7 @@ TEST_F(DiskCacheTest, StorageBlock_SetData) {
}
TEST_F(DiskCacheTest, StorageBlock_SetModified) {
- FilePath filename = GetCacheFilePath().AppendASCII("a_test");
+ FilePath filename = cache_path_.AppendASCII("a_test");
scoped_refptr<disk_cache::MappedFile> file(new disk_cache::MappedFile);
ASSERT_TRUE(CreateCacheTestFile(filename));
ASSERT_TRUE(file->Init(filename, 8192));
diff --git a/net/net.gyp b/net/net.gyp
index 7680570..628bb69 100644
--- a/net/net.gyp
+++ b/net/net.gyp
@@ -1014,8 +1014,6 @@
'disk_cache/bitmap_unittest.cc',
'disk_cache/block_files_unittest.cc',
'disk_cache/cache_util_unittest.cc',
- 'disk_cache/disk_cache_test_base.cc',
- 'disk_cache/disk_cache_test_base.h',
'disk_cache/entry_unittest.cc',
'disk_cache/mapped_file_unittest.cc',
'disk_cache/storage_block_unittest.cc',
@@ -1330,6 +1328,8 @@
'base/net_test_suite.h',
'base/test_completion_callback.cc',
'base/test_completion_callback.h',
+ 'disk_cache/disk_cache_test_base.cc',
+ 'disk_cache/disk_cache_test_base.h',
'disk_cache/disk_cache_test_util.cc',
'disk_cache/disk_cache_test_util.h',
'dns/dns_test_util.cc',