diff options
author | phajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-03-16 18:53:12 +0000 |
---|---|---|
committer | phajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-03-16 18:53:12 +0000 |
commit | 39eee12e58ed3ffe2986888acacaa7fcc746a53f (patch) | |
tree | 24bdf9b16fd33e11a614360f61013226e28b5d44 | |
parent | 611cad45a3bc67189d273eaba0171b96f7bdbd97 (diff) | |
download | chromium_src-39eee12e58ed3ffe2986888acacaa7fcc746a53f.zip chromium_src-39eee12e58ed3ffe2986888acacaa7fcc746a53f.tar.gz chromium_src-39eee12e58ed3ffe2986888acacaa7fcc746a53f.tar.bz2 |
Make sure that net_perftest doesn't leave temporary files.
BUG=8580
Review URL: http://codereview.chromium.org/48003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@11753 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | net/disk_cache/disk_cache_perftest.cc | 27 | ||||
-rw-r--r-- | net/disk_cache/disk_cache_test_util.cc | 10 | ||||
-rw-r--r-- | net/disk_cache/disk_cache_test_util.h | 17 |
3 files changed, 39 insertions, 15 deletions
diff --git a/net/disk_cache/disk_cache_perftest.cc b/net/disk_cache/disk_cache_perftest.cc index 785f93f..0abbc5b 100644 --- a/net/disk_cache/disk_cache_perftest.cc +++ b/net/disk_cache/disk_cache_perftest.cc @@ -157,10 +157,9 @@ TEST_F(DiskCacheTest, Hash) { TEST_F(DiskCacheTest, CacheBackendPerformance) { MessageLoopForIO message_loop; - std::wstring path_wstring = GetCachePath(); - ASSERT_TRUE(DeleteCache(path_wstring.c_str())); - disk_cache::Backend* cache = disk_cache::CreateCacheBackend(path_wstring, - false, 0); + ScopedTestCache test_cache; + disk_cache::Backend* cache = + disk_cache::CreateCacheBackend(test_cache.path_wstring(), false, 0); ASSERT_TRUE(NULL != cache); int seed = static_cast<int>(Time::Now().ToInternalValue()); @@ -175,20 +174,18 @@ TEST_F(DiskCacheTest, CacheBackendPerformance) { MessageLoop::current()->RunAllPending(); delete cache; - FilePath path = FilePath::FromWStringHack(path_wstring); - ASSERT_TRUE(file_util::EvictFileFromSystemCache( - path.AppendASCII("index"))); + test_cache.path().AppendASCII("index"))); ASSERT_TRUE(file_util::EvictFileFromSystemCache( - path.AppendASCII("data_0"))); + test_cache.path().AppendASCII("data_0"))); ASSERT_TRUE(file_util::EvictFileFromSystemCache( - path.AppendASCII("data_1"))); + test_cache.path().AppendASCII("data_1"))); ASSERT_TRUE(file_util::EvictFileFromSystemCache( - path.AppendASCII("data_2"))); + test_cache.path().AppendASCII("data_2"))); ASSERT_TRUE(file_util::EvictFileFromSystemCache( - path.AppendASCII("data_3"))); + test_cache.path().AppendASCII("data_3"))); - cache = disk_cache::CreateCacheBackend(path_wstring, false, 0); + cache = disk_cache::CreateCacheBackend(test_cache.path_wstring(), false, 0); ASSERT_TRUE(NULL != cache); ret = TimeRead(num_entries, cache, entries, true); @@ -208,10 +205,10 @@ TEST_F(DiskCacheTest, CacheBackendPerformance) { // by using multiple, highly fragmented files. TEST_F(DiskCacheTest, BlockFilesPerformance) { MessageLoopForIO message_loop; - std::wstring path = GetCachePath(); - ASSERT_TRUE(DeleteCache(path.c_str())); - disk_cache::BlockFiles files(path); + ScopedTestCache test_cache; + + disk_cache::BlockFiles files(test_cache.path_wstring()); ASSERT_TRUE(files.Init(true)); int seed = static_cast<int>(Time::Now().ToInternalValue()); diff --git a/net/disk_cache/disk_cache_test_util.cc b/net/disk_cache/disk_cache_test_util.cc index 9a15209..555b2e5 100644 --- a/net/disk_cache/disk_cache_test_util.cc +++ b/net/disk_cache/disk_cache_test_util.cc @@ -4,6 +4,7 @@ #include "net/disk_cache/disk_cache_test_util.h" +#include "base/logging.h" #include "base/file_util.h" #include "base/path_service.h" #include "net/disk_cache/backend_impl.h" @@ -77,6 +78,15 @@ bool CheckCacheIntegrity(const std::wstring& path) { return cache->SelfCheck() >= 0; } +ScopedTestCache::ScopedTestCache() : path_(GetCachePath()) { + bool result = DeleteCache(path_.c_str()); + DCHECK(result); +} + +ScopedTestCache::~ScopedTestCache() { + file_util::Delete(path(), true); +} + // ----------------------------------------------------------------------- int g_cache_tests_max_id = 0; diff --git a/net/disk_cache/disk_cache_test_util.h b/net/disk_cache/disk_cache_test_util.h index 4277d02..05dce99 100644 --- a/net/disk_cache/disk_cache_test_util.h +++ b/net/disk_cache/disk_cache_test_util.h @@ -7,6 +7,7 @@ #include <string> +#include "base/file_path.h" #include "base/message_loop.h" #include "base/task.h" @@ -32,6 +33,22 @@ std::string GenerateKey(bool same_length); // Returns true if the cache is not corrupt. bool CheckCacheIntegrity(const std::wstring& path); +// Helper class which ensures that the cache dir returned by GetCachePath exists +// and is clear in ctor and that the directory gets deleted in dtor. +class ScopedTestCache { + public: + ScopedTestCache(); + ~ScopedTestCache(); + + FilePath path() const { return FilePath::FromWStringHack(path_); } + std::wstring path_wstring() const { return path_; } + + private: + const std::wstring path_; // Path to the cache test folder. + + DISALLOW_COPY_AND_ASSIGN(ScopedTestCache); +}; + // ----------------------------------------------------------------------- // Simple callback to process IO completions from the cache. |