diff options
-rw-r--r-- | net/disk_cache/backend_unittest.cc | 28 | ||||
-rw-r--r-- | net/disk_cache/disk_cache_test_util.cc | 28 | ||||
-rw-r--r-- | net/disk_cache/disk_cache_test_util.h | 1 |
3 files changed, 50 insertions, 7 deletions
diff --git a/net/disk_cache/backend_unittest.cc b/net/disk_cache/backend_unittest.cc index 1562621..9851203 100644 --- a/net/disk_cache/backend_unittest.cc +++ b/net/disk_cache/backend_unittest.cc @@ -995,3 +995,31 @@ TEST_F(DiskCacheBackendTest, MemoryOnlyDoomAll) { InitCache(); BackendDoomAll(); } + +// We should be able to create the same entry on multiple simultaneous instances +// of the cache. +TEST_F(DiskCacheTest, MultipleInstances) { + ScopedTestCache store1; + ScopedTestCache store2(L"cache_test2"); + ScopedTestCache store3(L"cache_test3"); + + const int kNumberOfCaches = 3; + scoped_ptr<disk_cache::Backend> cache[kNumberOfCaches]; + + cache[0].reset(disk_cache::CreateCacheBackend(store1.path_wstring(), false, 0, + net::DISK_CACHE)); + cache[1].reset(disk_cache::CreateCacheBackend(store2.path_wstring(), false, 0, + net::MEDIA_CACHE)); + cache[2].reset(disk_cache::CreateCacheBackend(store3.path_wstring(), false, 0, + net::TEMP_MEDIA_CACHE)); + + ASSERT_TRUE(cache[0].get() != NULL && cache[1].get() != NULL && + cache[2].get() != NULL); + + std::string key("the first key"); + disk_cache::Entry* entry; + for (int i = 0; i < kNumberOfCaches; i++) { + ASSERT_TRUE(cache[i]->CreateEntry(key, &entry)); + entry->Close(); + } +} diff --git a/net/disk_cache/disk_cache_test_util.cc b/net/disk_cache/disk_cache_test_util.cc index 555b2e5..9744f74 100644 --- a/net/disk_cache/disk_cache_test_util.cc +++ b/net/disk_cache/disk_cache_test_util.cc @@ -14,6 +14,20 @@ using base::Time; using base::TimeDelta; +namespace { + +std::wstring BuildCachePath(const std::wstring& name) { + std::wstring path; + PathService::Get(base::DIR_TEMP, &path); + file_util::AppendToPath(&path, 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); @@ -40,13 +54,7 @@ void CacheTestFillBuffer(char* buffer, size_t len, bool no_nulls) { } std::wstring GetCachePath() { - std::wstring path; - PathService::Get(base::DIR_TEMP, &path); - file_util::AppendToPath(&path, L"cache_test"); - if (!file_util::PathExists(path)) - file_util::CreateDirectory(path); - - return path; + return BuildCachePath(L"cache_test"); } bool CreateCacheTestFile(const wchar_t* name) { @@ -83,6 +91,12 @@ ScopedTestCache::ScopedTestCache() : path_(GetCachePath()) { DCHECK(result); } +ScopedTestCache::ScopedTestCache(const std::wstring& name) + : path_(BuildCachePath(name)) { + bool result = DeleteCache(path_.c_str()); + DCHECK(result); +} + ScopedTestCache::~ScopedTestCache() { file_util::Delete(path(), true); } diff --git a/net/disk_cache/disk_cache_test_util.h b/net/disk_cache/disk_cache_test_util.h index 05dce99..d715506 100644 --- a/net/disk_cache/disk_cache_test_util.h +++ b/net/disk_cache/disk_cache_test_util.h @@ -38,6 +38,7 @@ bool CheckCacheIntegrity(const std::wstring& path); class ScopedTestCache { public: ScopedTestCache(); + ScopedTestCache(const std::wstring& name); // Use a specific folder name. ~ScopedTestCache(); FilePath path() const { return FilePath::FromWStringHack(path_); } |