diff options
author | phajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-09-22 11:47:29 +0000 |
---|---|---|
committer | phajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-09-22 11:47:29 +0000 |
commit | 3cc5922dbc5f1668bc1cd4f691286c5a7218c167 (patch) | |
tree | 4acd9b73dc5f6ab0c0a6aa2da482d2fd6948816f /net/disk_cache/disk_cache_test_util.cc | |
parent | c86d350e584b00bd5df71e82b5774ef245a14bef (diff) | |
download | chromium_src-3cc5922dbc5f1668bc1cd4f691286c5a7218c167.zip chromium_src-3cc5922dbc5f1668bc1cd4f691286c5a7218c167.tar.gz chromium_src-3cc5922dbc5f1668bc1cd4f691286c5a7218c167.tar.bz2 |
Revert 60165 - GTTF: Make net_unittests run successfully with parallel test launcher
by using a unique directory for disk cache tests.
BUG=54098
TEST=run net_unittests using tools/parallel_launcher/parallel_launcher.py
Review URL: http://codereview.chromium.org/3410008
TBR=phajdan.jr@chromium.org
Review URL: http://codereview.chromium.org/3387012
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@60166 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/disk_cache/disk_cache_test_util.cc')
-rw-r--r-- | net/disk_cache/disk_cache_test_util.cc | 37 |
1 files changed, 32 insertions, 5 deletions
diff --git a/net/disk_cache/disk_cache_test_util.cc b/net/disk_cache/disk_cache_test_util.cc index 095b693..7dd618a 100644 --- a/net/disk_cache/disk_cache_test_util.cc +++ b/net/disk_cache/disk_cache_test_util.cc @@ -16,6 +16,20 @@ using base::Time; using base::TimeDelta; +namespace { + +FilePath BuildCachePath(const std::string& name) { + FilePath path; + PathService::Get(base::DIR_TEMP, &path); // Ignore return value; + path = path.AppendASCII(name); + if (!file_util::PathExists(path)) + file_util::CreateDirectory(path); + + return path; +} + +} // namespace. + std::string GenerateKey(bool same_length) { char key[200]; CacheTestFillBuffer(key, sizeof(key), same_length); @@ -41,6 +55,10 @@ void CacheTestFillBuffer(char* buffer, size_t len, bool no_nulls) { buffer[0] = 'g'; } +FilePath GetCacheFilePath() { + return BuildCachePath("cache_test"); +} + bool CreateCacheTestFile(const FilePath& name) { int flags = base::PLATFORM_FILE_CREATE_ALWAYS | base::PLATFORM_FILE_READ | @@ -60,7 +78,7 @@ bool DeleteCache(const FilePath& path) { return true; } -bool CopyTestCache(const std::string& name, const FilePath& destination) { +bool CopyTestCache(const std::string& name) { FilePath path; PathService::Get(base::DIR_SOURCE_ROOT, &path); path = path.AppendASCII("net"); @@ -68,9 +86,10 @@ bool CopyTestCache(const std::string& name, const FilePath& destination) { path = path.AppendASCII("cache_tests"); path = path.AppendASCII(name); - if (!DeleteCache(destination)) + FilePath dest = GetCacheFilePath(); + if (!DeleteCache(dest)) return false; - return file_util::CopyDirectory(path, destination, false); + return file_util::CopyDirectory(path, dest, false); } bool CheckCacheIntegrity(const FilePath& path, bool new_eviction) { @@ -86,11 +105,19 @@ bool CheckCacheIntegrity(const FilePath& path, bool new_eviction) { return cache->SelfCheck() >= 0; } -ScopedTestCache::ScopedTestCache() { - temp_dir_.CreateUniqueTempDir(); +ScopedTestCache::ScopedTestCache() : path_(GetCacheFilePath()) { + bool result = DeleteCache(path_); + DCHECK(result); +} + +ScopedTestCache::ScopedTestCache(const std::string& name) + : path_(BuildCachePath(name)) { + bool result = DeleteCache(path_); + DCHECK(result); } ScopedTestCache::~ScopedTestCache() { + file_util::Delete(path(), true); } // ----------------------------------------------------------------------- |