summaryrefslogtreecommitdiffstats
path: root/net/disk_cache/disk_cache_test_util.cc
diff options
context:
space:
mode:
Diffstat (limited to 'net/disk_cache/disk_cache_test_util.cc')
-rw-r--r--net/disk_cache/disk_cache_test_util.cc28
1 files changed, 21 insertions, 7 deletions
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);
}