| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/disk_cache/disk_cache_test_util.h" | 5 #include "net/disk_cache/disk_cache_test_util.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/message_loop_proxy.h" | 9 #include "base/message_loop_proxy.h" |
| 10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 | 71 |
| 72 file->SetLength(4 * 1024 * 1024); | 72 file->SetLength(4 * 1024 * 1024); |
| 73 return true; | 73 return true; |
| 74 } | 74 } |
| 75 | 75 |
| 76 bool DeleteCache(const FilePath& path) { | 76 bool DeleteCache(const FilePath& path) { |
| 77 disk_cache::DeleteCache(path, false); | 77 disk_cache::DeleteCache(path, false); |
| 78 return true; | 78 return true; |
| 79 } | 79 } |
| 80 | 80 |
| 81 bool CopyTestCache(const std::string& name) { | |
| 82 FilePath path; | |
| 83 PathService::Get(base::DIR_SOURCE_ROOT, &path); | |
| 84 path = path.AppendASCII("net"); | |
| 85 path = path.AppendASCII("data"); | |
| 86 path = path.AppendASCII("cache_tests"); | |
| 87 path = path.AppendASCII(name); | |
| 88 | |
| 89 FilePath dest = GetCacheFilePath(); | |
| 90 if (!DeleteCache(dest)) | |
| 91 return false; | |
| 92 return file_util::CopyDirectory(path, dest, false); | |
| 93 } | |
| 94 | |
| 95 bool CheckCacheIntegrity(const FilePath& path, bool new_eviction, uint32 mask) { | 81 bool CheckCacheIntegrity(const FilePath& path, bool new_eviction, uint32 mask) { |
| 96 scoped_ptr<disk_cache::BackendImpl> cache(new disk_cache::BackendImpl( | 82 scoped_ptr<disk_cache::BackendImpl> cache(new disk_cache::BackendImpl( |
| 97 path, mask, base::MessageLoopProxy::current(), NULL)); | 83 path, mask, base::MessageLoopProxy::current(), NULL)); |
| 98 if (!cache.get()) | 84 if (!cache.get()) |
| 99 return false; | 85 return false; |
| 100 if (new_eviction) | 86 if (new_eviction) |
| 101 cache->SetNewEviction(); | 87 cache->SetNewEviction(); |
| 102 cache->SetFlags(disk_cache::kNoRandom); | 88 cache->SetFlags(disk_cache::kNoRandom); |
| 103 if (cache->SyncInit() != net::OK) | 89 if (cache->SyncInit() != net::OK) |
| 104 return false; | 90 return false; |
| 105 return cache->SelfCheck() >= 0; | 91 return cache->SelfCheck() >= 0; |
| 106 } | 92 } |
| 107 | 93 |
| 108 ScopedTestCache::ScopedTestCache() : path_(GetCacheFilePath()) { | 94 ScopedTestCache::ScopedTestCache(const FilePath& path) : path_(path) { |
| 109 bool result = DeleteCache(path_); | 95 bool result = DeleteCache(path_); |
| 110 DCHECK(result); | 96 DCHECK(result); |
| 111 } | 97 } |
| 112 | 98 |
| 113 ScopedTestCache::ScopedTestCache(const std::string& name) | 99 ScopedTestCache::ScopedTestCache(const std::string& name) |
| 114 : path_(BuildCachePath(name)) { | 100 : path_(BuildCachePath(name)) { |
| 115 bool result = DeleteCache(path_); | 101 bool result = DeleteCache(path_); |
| 116 DCHECK(result); | 102 DCHECK(result); |
| 117 } | 103 } |
| 118 | 104 |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 void CallbackTest::RunWithParams(const Tuple1<int>& params) { | 167 void CallbackTest::RunWithParams(const Tuple1<int>& params) { |
| 182 if (reuse_) { | 168 if (reuse_) { |
| 183 DCHECK_EQ(1, reuse_); | 169 DCHECK_EQ(1, reuse_); |
| 184 if (2 == reuse_) | 170 if (2 == reuse_) |
| 185 helper_->set_callback_reused_error(true); | 171 helper_->set_callback_reused_error(true); |
| 186 reuse_++; | 172 reuse_++; |
| 187 } | 173 } |
| 188 | 174 |
| 189 helper_->CallbackWasCalled(); | 175 helper_->CallbackWasCalled(); |
| 190 } | 176 } |
| OLD | NEW |