OLD | NEW |
1 // Copyright (c) 2006-2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2010 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 "base/basictypes.h" | 5 #include "base/basictypes.h" |
6 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" | 6 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/platform_thread.h" | 8 #include "base/platform_thread.h" |
9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
10 #include "net/base/io_buffer.h" | 10 #include "net/base/io_buffer.h" |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 SetMemoryOnlyMode(); | 173 SetMemoryOnlyMode(); |
174 BackendKeying(); | 174 BackendKeying(); |
175 } | 175 } |
176 | 176 |
177 TEST_F(DiskCacheBackendTest, AppCacheKeying) { | 177 TEST_F(DiskCacheBackendTest, AppCacheKeying) { |
178 SetCacheType(net::APP_CACHE); | 178 SetCacheType(net::APP_CACHE); |
179 BackendKeying(); | 179 BackendKeying(); |
180 } | 180 } |
181 | 181 |
182 TEST_F(DiskCacheTest, CreateBackend) { | 182 TEST_F(DiskCacheTest, CreateBackend) { |
| 183 ScopedTestCache test_cache; |
183 TestCompletionCallback cb; | 184 TestCompletionCallback cb; |
184 | 185 |
185 { | 186 { |
186 FilePath path = GetCacheFilePath(); | |
187 ASSERT_TRUE(DeleteCache(path)); | |
188 base::Thread cache_thread("CacheThread"); | 187 base::Thread cache_thread("CacheThread"); |
189 ASSERT_TRUE(cache_thread.StartWithOptions( | 188 ASSERT_TRUE(cache_thread.StartWithOptions( |
190 base::Thread::Options(MessageLoop::TYPE_IO, 0))); | 189 base::Thread::Options(MessageLoop::TYPE_IO, 0))); |
191 | 190 |
192 // Test the private factory methods. | 191 // Test the private factory methods. |
193 disk_cache::Backend* cache = NULL; | 192 disk_cache::Backend* cache = NULL; |
194 int rv = disk_cache::BackendImpl::CreateBackend( | 193 int rv = disk_cache::BackendImpl::CreateBackend( |
195 path, false, 0, net::DISK_CACHE, disk_cache::kNoRandom, | 194 test_cache.path(), false, 0, net::DISK_CACHE, disk_cache::kNoRandom, |
196 cache_thread.message_loop_proxy(), &cache, &cb); | 195 cache_thread.message_loop_proxy(), &cache, &cb); |
197 ASSERT_EQ(net::OK, cb.GetResult(rv)); | 196 ASSERT_EQ(net::OK, cb.GetResult(rv)); |
198 ASSERT_TRUE(cache); | 197 ASSERT_TRUE(cache); |
199 delete cache; | 198 delete cache; |
200 | 199 |
201 cache = disk_cache::MemBackendImpl::CreateBackend(0); | 200 cache = disk_cache::MemBackendImpl::CreateBackend(0); |
202 ASSERT_TRUE(cache); | 201 ASSERT_TRUE(cache); |
203 delete cache; | 202 delete cache; |
204 cache = NULL; | 203 cache = NULL; |
205 | 204 |
206 // Now test the public API. | 205 // Now test the public API. |
207 rv = disk_cache::CreateCacheBackend(net::DISK_CACHE, path, 0, false, | 206 rv = disk_cache::CreateCacheBackend(net::DISK_CACHE, test_cache.path(), |
| 207 0, false, |
208 cache_thread.message_loop_proxy(), | 208 cache_thread.message_loop_proxy(), |
209 &cache, &cb); | 209 &cache, &cb); |
210 ASSERT_EQ(net::OK, cb.GetResult(rv)); | 210 ASSERT_EQ(net::OK, cb.GetResult(rv)); |
211 ASSERT_TRUE(cache); | 211 ASSERT_TRUE(cache); |
212 delete cache; | 212 delete cache; |
213 cache = NULL; | 213 cache = NULL; |
214 | 214 |
215 rv = disk_cache::CreateCacheBackend(net::MEMORY_CACHE, FilePath(), 0, false, | 215 rv = disk_cache::CreateCacheBackend(net::MEMORY_CACHE, FilePath(), 0, false, |
216 NULL, &cache, &cb); | 216 NULL, &cache, &cb); |
217 ASSERT_EQ(net::OK, cb.GetResult(rv)); | 217 ASSERT_EQ(net::OK, cb.GetResult(rv)); |
218 ASSERT_TRUE(cache); | 218 ASSERT_TRUE(cache); |
219 delete cache; | 219 delete cache; |
220 } | 220 } |
221 | 221 |
222 MessageLoop::current()->RunAllPending(); | 222 MessageLoop::current()->RunAllPending(); |
223 } | 223 } |
224 | 224 |
225 TEST_F(DiskCacheBackendTest, ExternalFiles) { | 225 TEST_F(DiskCacheBackendTest, ExternalFiles) { |
226 InitCache(); | 226 InitCache(); |
227 // First, lets create a file on the folder. | 227 // First, lets create a file on the folder. |
228 FilePath filename = GetCacheFilePath().AppendASCII("f_000001"); | 228 FilePath filename = path().AppendASCII("f_000001"); |
229 | 229 |
230 const int kSize = 50; | 230 const int kSize = 50; |
231 scoped_refptr<net::IOBuffer> buffer1 = new net::IOBuffer(kSize); | 231 scoped_refptr<net::IOBuffer> buffer1 = new net::IOBuffer(kSize); |
232 CacheTestFillBuffer(buffer1->data(), kSize, false); | 232 CacheTestFillBuffer(buffer1->data(), kSize, false); |
233 ASSERT_EQ(kSize, file_util::WriteFile(filename, buffer1->data(), kSize)); | 233 ASSERT_EQ(kSize, file_util::WriteFile(filename, buffer1->data(), kSize)); |
234 | 234 |
235 // Now let's create a file with the cache. | 235 // Now let's create a file with the cache. |
236 disk_cache::Entry* entry; | 236 disk_cache::Entry* entry; |
237 ASSERT_EQ(net::OK, CreateEntry("key", &entry)); | 237 ASSERT_EQ(net::OK, CreateEntry("key", &entry)); |
238 ASSERT_EQ(0, WriteData(entry, 0, 20000, buffer1, 0, false)); | 238 ASSERT_EQ(0, WriteData(entry, 0, 20000, buffer1, 0, false)); |
239 entry->Close(); | 239 entry->Close(); |
240 | 240 |
241 // And verify that the first file is still there. | 241 // And verify that the first file is still there. |
242 scoped_refptr<net::IOBuffer> buffer2 = new net::IOBuffer(kSize); | 242 scoped_refptr<net::IOBuffer> buffer2 = new net::IOBuffer(kSize); |
243 ASSERT_EQ(kSize, file_util::ReadFile(filename, buffer2->data(), kSize)); | 243 ASSERT_EQ(kSize, file_util::ReadFile(filename, buffer2->data(), kSize)); |
244 EXPECT_EQ(0, memcmp(buffer1->data(), buffer2->data(), kSize)); | 244 EXPECT_EQ(0, memcmp(buffer1->data(), buffer2->data(), kSize)); |
245 } | 245 } |
246 | 246 |
247 // Tests that we deal with file-level pending operations at destruction time. | 247 // Tests that we deal with file-level pending operations at destruction time. |
248 TEST_F(DiskCacheTest, ShutdownWithPendingIO) { | 248 TEST_F(DiskCacheTest, ShutdownWithPendingIO) { |
| 249 ScopedTestCache test_cache; |
249 TestCompletionCallback cb; | 250 TestCompletionCallback cb; |
250 | 251 |
251 { | 252 { |
252 FilePath path = GetCacheFilePath(); | |
253 ASSERT_TRUE(DeleteCache(path)); | |
254 base::Thread cache_thread("CacheThread"); | 253 base::Thread cache_thread("CacheThread"); |
255 ASSERT_TRUE(cache_thread.StartWithOptions( | 254 ASSERT_TRUE(cache_thread.StartWithOptions( |
256 base::Thread::Options(MessageLoop::TYPE_IO, 0))); | 255 base::Thread::Options(MessageLoop::TYPE_IO, 0))); |
257 | 256 |
258 disk_cache::Backend* cache; | 257 disk_cache::Backend* cache; |
259 int rv = disk_cache::BackendImpl::CreateBackend( | 258 int rv = disk_cache::BackendImpl::CreateBackend( |
260 path, false, 0, net::DISK_CACHE, disk_cache::kNoRandom, | 259 test_cache.path(), false, 0, net::DISK_CACHE, disk_cache::kNoRandom, |
261 base::MessageLoopProxy::CreateForCurrentThread(), &cache, &cb); | 260 base::MessageLoopProxy::CreateForCurrentThread(), &cache, &cb); |
262 ASSERT_EQ(net::OK, cb.GetResult(rv)); | 261 ASSERT_EQ(net::OK, cb.GetResult(rv)); |
263 | 262 |
264 disk_cache::EntryImpl* entry; | 263 disk_cache::EntryImpl* entry; |
265 rv = cache->CreateEntry("some key", | 264 rv = cache->CreateEntry("some key", |
266 reinterpret_cast<disk_cache::Entry**>(&entry), &cb); | 265 reinterpret_cast<disk_cache::Entry**>(&entry), &cb); |
267 ASSERT_EQ(net::OK, cb.GetResult(rv)); | 266 ASSERT_EQ(net::OK, cb.GetResult(rv)); |
268 | 267 |
269 const int kSize = 25000; | 268 const int kSize = 25000; |
270 scoped_refptr<net::IOBuffer> buffer = new net::IOBuffer(kSize); | 269 scoped_refptr<net::IOBuffer> buffer = new net::IOBuffer(kSize); |
271 CacheTestFillBuffer(buffer->data(), kSize, false); | 270 CacheTestFillBuffer(buffer->data(), kSize, false); |
(...skipping 18 matching lines...) Expand all Loading... |
290 if (rv == net::ERR_IO_PENDING) { | 289 if (rv == net::ERR_IO_PENDING) { |
291 EXPECT_TRUE(cb.have_result()); | 290 EXPECT_TRUE(cb.have_result()); |
292 } | 291 } |
293 } | 292 } |
294 | 293 |
295 MessageLoop::current()->RunAllPending(); | 294 MessageLoop::current()->RunAllPending(); |
296 } | 295 } |
297 | 296 |
298 // Tests that we deal with background-thread pending operations. | 297 // Tests that we deal with background-thread pending operations. |
299 TEST_F(DiskCacheTest, ShutdownWithPendingIO2) { | 298 TEST_F(DiskCacheTest, ShutdownWithPendingIO2) { |
| 299 ScopedTestCache test_cache; |
300 TestCompletionCallback cb; | 300 TestCompletionCallback cb; |
301 | 301 |
302 { | 302 { |
303 FilePath path = GetCacheFilePath(); | |
304 ASSERT_TRUE(DeleteCache(path)); | |
305 base::Thread cache_thread("CacheThread"); | 303 base::Thread cache_thread("CacheThread"); |
306 ASSERT_TRUE(cache_thread.StartWithOptions( | 304 ASSERT_TRUE(cache_thread.StartWithOptions( |
307 base::Thread::Options(MessageLoop::TYPE_IO, 0))); | 305 base::Thread::Options(MessageLoop::TYPE_IO, 0))); |
308 | 306 |
309 disk_cache::Backend* cache; | 307 disk_cache::Backend* cache; |
310 int rv = disk_cache::BackendImpl::CreateBackend( | 308 int rv = disk_cache::BackendImpl::CreateBackend( |
311 path, false, 0, net::DISK_CACHE, disk_cache::kNoRandom, | 309 test_cache.path(), false, 0, net::DISK_CACHE, disk_cache::kNoRandom, |
312 cache_thread.message_loop_proxy(), &cache, &cb); | 310 cache_thread.message_loop_proxy(), &cache, &cb); |
313 ASSERT_EQ(net::OK, cb.GetResult(rv)); | 311 ASSERT_EQ(net::OK, cb.GetResult(rv)); |
314 | 312 |
315 disk_cache::Entry* entry; | 313 disk_cache::Entry* entry; |
316 rv = cache->CreateEntry("some key", &entry, &cb); | 314 rv = cache->CreateEntry("some key", &entry, &cb); |
317 ASSERT_EQ(net::OK, cb.GetResult(rv)); | 315 ASSERT_EQ(net::OK, cb.GetResult(rv)); |
318 | 316 |
319 const int kSize = 25000; | 317 const int kSize = 25000; |
320 scoped_refptr<net::IOBuffer> buffer = new net::IOBuffer(kSize); | 318 scoped_refptr<net::IOBuffer> buffer = new net::IOBuffer(kSize); |
321 CacheTestFillBuffer(buffer->data(), kSize, false); | 319 CacheTestFillBuffer(buffer->data(), kSize, false); |
322 | 320 |
323 rv = entry->WriteData(0, 0, buffer, kSize, &cb, false); | 321 rv = entry->WriteData(0, 0, buffer, kSize, &cb, false); |
324 EXPECT_EQ(net::ERR_IO_PENDING, rv); | 322 EXPECT_EQ(net::ERR_IO_PENDING, rv); |
325 | 323 |
326 entry->Close(); | 324 entry->Close(); |
327 | 325 |
328 // The cache destructor will see two pending operations here. | 326 // The cache destructor will see two pending operations here. |
329 delete cache; | 327 delete cache; |
330 } | 328 } |
331 | 329 |
332 MessageLoop::current()->RunAllPending(); | 330 MessageLoop::current()->RunAllPending(); |
333 } | 331 } |
334 | 332 |
335 TEST_F(DiskCacheTest, TruncatedIndex) { | 333 TEST_F(DiskCacheTest, TruncatedIndex) { |
336 FilePath path = GetCacheFilePath(); | 334 ScopedTestCache test_cache; |
337 ASSERT_TRUE(DeleteCache(path)); | 335 |
338 FilePath index = path.AppendASCII("index"); | 336 FilePath index = test_cache.path().AppendASCII("index"); |
339 ASSERT_EQ(5, file_util::WriteFile(index, "hello", 5)); | 337 ASSERT_EQ(5, file_util::WriteFile(index, "hello", 5)); |
340 | 338 |
341 base::Thread cache_thread("CacheThread"); | 339 base::Thread cache_thread("CacheThread"); |
342 ASSERT_TRUE(cache_thread.StartWithOptions( | 340 ASSERT_TRUE(cache_thread.StartWithOptions( |
343 base::Thread::Options(MessageLoop::TYPE_IO, 0))); | 341 base::Thread::Options(MessageLoop::TYPE_IO, 0))); |
344 TestCompletionCallback cb; | 342 TestCompletionCallback cb; |
345 | 343 |
346 disk_cache::Backend* backend = NULL; | 344 disk_cache::Backend* backend = NULL; |
347 int rv = disk_cache::BackendImpl::CreateBackend( | 345 int rv = disk_cache::BackendImpl::CreateBackend( |
348 path, false, 0, net::DISK_CACHE, disk_cache::kNone, | 346 test_cache.path(), false, 0, net::DISK_CACHE, disk_cache::kNone, |
349 cache_thread.message_loop_proxy(), &backend, &cb); | 347 cache_thread.message_loop_proxy(), &backend, &cb); |
350 ASSERT_NE(net::OK, cb.GetResult(rv)); | 348 ASSERT_NE(net::OK, cb.GetResult(rv)); |
351 | 349 |
352 ASSERT_TRUE(backend == NULL); | 350 ASSERT_TRUE(backend == NULL); |
353 delete backend; | 351 delete backend; |
354 } | 352 } |
355 | 353 |
356 void DiskCacheBackendTest::BackendSetSize() { | 354 void DiskCacheBackendTest::BackendSetSize() { |
357 SetDirectMode(); | 355 SetDirectMode(); |
358 const int cache_size = 0x10000; // 64 kB | 356 const int cache_size = 0x10000; // 64 kB |
359 SetMaxSize(cache_size); | 357 SetMaxSize(cache_size); |
(...skipping 778 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1138 } | 1136 } |
1139 | 1137 |
1140 TEST_F(DiskCacheBackendTest, MemoryOnlyDoomBetween) { | 1138 TEST_F(DiskCacheBackendTest, MemoryOnlyDoomBetween) { |
1141 SetMemoryOnlyMode(); | 1139 SetMemoryOnlyMode(); |
1142 BackendDoomBetween(); | 1140 BackendDoomBetween(); |
1143 } | 1141 } |
1144 | 1142 |
1145 void DiskCacheBackendTest::BackendTransaction(const std::string& name, | 1143 void DiskCacheBackendTest::BackendTransaction(const std::string& name, |
1146 int num_entries, bool load) { | 1144 int num_entries, bool load) { |
1147 success_ = false; | 1145 success_ = false; |
1148 ASSERT_TRUE(CopyTestCache(name)); | 1146 ASSERT_TRUE(CopyTestCache(name, path())); |
1149 DisableFirstCleanup(); | 1147 DisableFirstCleanup(); |
1150 | 1148 |
1151 if (load) { | 1149 if (load) { |
1152 SetMask(0xf); | 1150 SetMask(0xf); |
1153 SetMaxSize(0x100000); | 1151 SetMaxSize(0x100000); |
1154 } else { | 1152 } else { |
1155 // Clear the settings from the previous run. | 1153 // Clear the settings from the previous run. |
1156 SetMask(0); | 1154 SetMask(0); |
1157 SetMaxSize(0); | 1155 SetMaxSize(0); |
1158 } | 1156 } |
(...skipping 10 matching lines...) Expand all Loading... |
1169 ASSERT_TRUE(load); | 1167 ASSERT_TRUE(load); |
1170 // If there is a heavy load, inserting an entry will make another entry | 1168 // If there is a heavy load, inserting an entry will make another entry |
1171 // dirty (on the hash bucket) so two entries are removed. | 1169 // dirty (on the hash bucket) so two entries are removed. |
1172 ASSERT_EQ(num_entries - 1, actual); | 1170 ASSERT_EQ(num_entries - 1, actual); |
1173 } | 1171 } |
1174 | 1172 |
1175 delete cache_; | 1173 delete cache_; |
1176 cache_ = NULL; | 1174 cache_ = NULL; |
1177 cache_impl_ = NULL; | 1175 cache_impl_ = NULL; |
1178 | 1176 |
1179 ASSERT_TRUE(CheckCacheIntegrity(GetCacheFilePath(), new_eviction_)); | 1177 ASSERT_TRUE(CheckCacheIntegrity(path(), new_eviction_)); |
1180 success_ = true; | 1178 success_ = true; |
1181 } | 1179 } |
1182 | 1180 |
1183 void DiskCacheBackendTest::BackendRecoverInsert() { | 1181 void DiskCacheBackendTest::BackendRecoverInsert() { |
1184 // Tests with an empty cache. | 1182 // Tests with an empty cache. |
1185 BackendTransaction("insert_empty1", 0, false); | 1183 BackendTransaction("insert_empty1", 0, false); |
1186 ASSERT_TRUE(success_) << "insert_empty1"; | 1184 ASSERT_TRUE(success_) << "insert_empty1"; |
1187 BackendTransaction("insert_empty2", 0, false); | 1185 BackendTransaction("insert_empty2", 0, false); |
1188 ASSERT_TRUE(success_) << "insert_empty2"; | 1186 ASSERT_TRUE(success_) << "insert_empty2"; |
1189 BackendTransaction("insert_empty3", 0, false); | 1187 BackendTransaction("insert_empty3", 0, false); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1259 BackendRecoverRemove(); | 1257 BackendRecoverRemove(); |
1260 } | 1258 } |
1261 | 1259 |
1262 TEST_F(DiskCacheBackendTest, NewEvictionRecoverRemove) { | 1260 TEST_F(DiskCacheBackendTest, NewEvictionRecoverRemove) { |
1263 SetNewEviction(); | 1261 SetNewEviction(); |
1264 BackendRecoverRemove(); | 1262 BackendRecoverRemove(); |
1265 } | 1263 } |
1266 | 1264 |
1267 // Tests dealing with cache files that cannot be recovered. | 1265 // Tests dealing with cache files that cannot be recovered. |
1268 TEST_F(DiskCacheTest, DeleteOld) { | 1266 TEST_F(DiskCacheTest, DeleteOld) { |
1269 ASSERT_TRUE(CopyTestCache("wrong_version")); | 1267 ScopedTestCache test_cache; |
1270 FilePath path = GetCacheFilePath(); | 1268 |
| 1269 ASSERT_TRUE(CopyTestCache("wrong_version", test_cache.path())); |
1271 base::Thread cache_thread("CacheThread"); | 1270 base::Thread cache_thread("CacheThread"); |
1272 ASSERT_TRUE(cache_thread.StartWithOptions( | 1271 ASSERT_TRUE(cache_thread.StartWithOptions( |
1273 base::Thread::Options(MessageLoop::TYPE_IO, 0))); | 1272 base::Thread::Options(MessageLoop::TYPE_IO, 0))); |
1274 TestCompletionCallback cb; | 1273 TestCompletionCallback cb; |
1275 | 1274 |
1276 disk_cache::Backend* cache; | 1275 disk_cache::Backend* cache; |
1277 int rv = disk_cache::BackendImpl::CreateBackend( | 1276 int rv = disk_cache::BackendImpl::CreateBackend( |
1278 path, true, 0, net::DISK_CACHE, disk_cache::kNoRandom, | 1277 test_cache.path(), true, 0, net::DISK_CACHE, disk_cache::kNoRandom, |
1279 cache_thread.message_loop_proxy(), &cache, &cb); | 1278 cache_thread.message_loop_proxy(), &cache, &cb); |
1280 ASSERT_EQ(net::OK, cb.GetResult(rv)); | 1279 ASSERT_EQ(net::OK, cb.GetResult(rv)); |
1281 | 1280 |
1282 MessageLoopHelper helper; | 1281 MessageLoopHelper helper; |
1283 | 1282 |
1284 ASSERT_TRUE(NULL != cache); | 1283 ASSERT_TRUE(NULL != cache); |
1285 ASSERT_EQ(0, cache->GetEntryCount()); | 1284 ASSERT_EQ(0, cache->GetEntryCount()); |
1286 | 1285 |
1287 delete cache; | 1286 delete cache; |
1288 } | 1287 } |
1289 | 1288 |
1290 // We want to be able to deal with messed up entries on disk. | 1289 // We want to be able to deal with messed up entries on disk. |
1291 void DiskCacheBackendTest::BackendInvalidEntry2() { | 1290 void DiskCacheBackendTest::BackendInvalidEntry2() { |
1292 ASSERT_TRUE(CopyTestCache("bad_entry")); | 1291 ASSERT_TRUE(CopyTestCache("bad_entry", path())); |
1293 DisableFirstCleanup(); | 1292 DisableFirstCleanup(); |
1294 InitCache(); | 1293 InitCache(); |
1295 | 1294 |
1296 disk_cache::Entry *entry1, *entry2; | 1295 disk_cache::Entry *entry1, *entry2; |
1297 ASSERT_EQ(net::OK, OpenEntry("the first key", &entry1)); | 1296 ASSERT_EQ(net::OK, OpenEntry("the first key", &entry1)); |
1298 EXPECT_NE(net::OK, OpenEntry("some other key", &entry2)); | 1297 EXPECT_NE(net::OK, OpenEntry("some other key", &entry2)); |
1299 entry1->Close(); | 1298 entry1->Close(); |
1300 | 1299 |
1301 // CheckCacheIntegrity will fail at this point. | 1300 // CheckCacheIntegrity will fail at this point. |
1302 DisableIntegrityCheck(); | 1301 DisableIntegrityCheck(); |
1303 } | 1302 } |
1304 | 1303 |
1305 TEST_F(DiskCacheBackendTest, InvalidEntry2) { | 1304 TEST_F(DiskCacheBackendTest, InvalidEntry2) { |
1306 BackendInvalidEntry2(); | 1305 BackendInvalidEntry2(); |
1307 } | 1306 } |
1308 | 1307 |
1309 TEST_F(DiskCacheBackendTest, NewEvictionInvalidEntry2) { | 1308 TEST_F(DiskCacheBackendTest, NewEvictionInvalidEntry2) { |
1310 SetNewEviction(); | 1309 SetNewEviction(); |
1311 BackendInvalidEntry2(); | 1310 BackendInvalidEntry2(); |
1312 } | 1311 } |
1313 | 1312 |
1314 // We want to be able to deal with abnormal dirty entries. | 1313 // We want to be able to deal with abnormal dirty entries. |
1315 void DiskCacheBackendTest::BackendNotMarkedButDirty(const std::string& name) { | 1314 void DiskCacheBackendTest::BackendNotMarkedButDirty(const std::string& name) { |
1316 ASSERT_TRUE(CopyTestCache(name)); | 1315 ASSERT_TRUE(CopyTestCache(name, path())); |
1317 DisableFirstCleanup(); | 1316 DisableFirstCleanup(); |
1318 InitCache(); | 1317 InitCache(); |
1319 | 1318 |
1320 disk_cache::Entry *entry1, *entry2; | 1319 disk_cache::Entry *entry1, *entry2; |
1321 ASSERT_EQ(net::OK, OpenEntry("the first key", &entry1)); | 1320 ASSERT_EQ(net::OK, OpenEntry("the first key", &entry1)); |
1322 EXPECT_NE(net::OK, OpenEntry("some other key", &entry2)); | 1321 EXPECT_NE(net::OK, OpenEntry("some other key", &entry2)); |
1323 entry1->Close(); | 1322 entry1->Close(); |
1324 } | 1323 } |
1325 | 1324 |
1326 TEST_F(DiskCacheBackendTest, NotMarkedButDirty) { | 1325 TEST_F(DiskCacheBackendTest, NotMarkedButDirty) { |
1327 BackendNotMarkedButDirty("dirty_entry"); | 1326 BackendNotMarkedButDirty("dirty_entry"); |
1328 } | 1327 } |
1329 | 1328 |
1330 TEST_F(DiskCacheBackendTest, NewEvictionNotMarkedButDirty) { | 1329 TEST_F(DiskCacheBackendTest, NewEvictionNotMarkedButDirty) { |
1331 SetNewEviction(); | 1330 SetNewEviction(); |
1332 BackendNotMarkedButDirty("dirty_entry"); | 1331 BackendNotMarkedButDirty("dirty_entry"); |
1333 } | 1332 } |
1334 | 1333 |
1335 TEST_F(DiskCacheBackendTest, NotMarkedButDirty2) { | 1334 TEST_F(DiskCacheBackendTest, NotMarkedButDirty2) { |
1336 BackendNotMarkedButDirty("dirty_entry2"); | 1335 BackendNotMarkedButDirty("dirty_entry2"); |
1337 } | 1336 } |
1338 | 1337 |
1339 TEST_F(DiskCacheBackendTest, NewEvictionNotMarkedButDirty2) { | 1338 TEST_F(DiskCacheBackendTest, NewEvictionNotMarkedButDirty2) { |
1340 SetNewEviction(); | 1339 SetNewEviction(); |
1341 BackendNotMarkedButDirty("dirty_entry2"); | 1340 BackendNotMarkedButDirty("dirty_entry2"); |
1342 } | 1341 } |
1343 | 1342 |
1344 // We want to be able to deal with messed up entries on disk. | 1343 // We want to be able to deal with messed up entries on disk. |
1345 void DiskCacheBackendTest::BackendInvalidRankings2() { | 1344 void DiskCacheBackendTest::BackendInvalidRankings2() { |
1346 ASSERT_TRUE(CopyTestCache("bad_rankings")); | 1345 ASSERT_TRUE(CopyTestCache("bad_rankings", path())); |
1347 FilePath path = GetCacheFilePath(); | |
1348 DisableFirstCleanup(); | 1346 DisableFirstCleanup(); |
1349 InitCache(); | 1347 InitCache(); |
1350 | 1348 |
1351 disk_cache::Entry *entry1, *entry2; | 1349 disk_cache::Entry *entry1, *entry2; |
1352 EXPECT_NE(net::OK, OpenEntry("the first key", &entry1)); | 1350 EXPECT_NE(net::OK, OpenEntry("the first key", &entry1)); |
1353 ASSERT_EQ(net::OK, OpenEntry("some other key", &entry2)); | 1351 ASSERT_EQ(net::OK, OpenEntry("some other key", &entry2)); |
1354 entry2->Close(); | 1352 entry2->Close(); |
1355 | 1353 |
1356 // CheckCacheIntegrity will fail at this point. | 1354 // CheckCacheIntegrity will fail at this point. |
1357 DisableIntegrityCheck(); | 1355 DisableIntegrityCheck(); |
(...skipping 15 matching lines...) Expand all Loading... |
1373 ASSERT_EQ(net::OK, OpenNextEntry(&iter, &entry)); | 1371 ASSERT_EQ(net::OK, OpenNextEntry(&iter, &entry)); |
1374 entry->Close(); | 1372 entry->Close(); |
1375 EXPECT_EQ(2, cache_->GetEntryCount()); | 1373 EXPECT_EQ(2, cache_->GetEntryCount()); |
1376 | 1374 |
1377 EXPECT_NE(net::OK, OpenNextEntry(&iter, &entry)); | 1375 EXPECT_NE(net::OK, OpenNextEntry(&iter, &entry)); |
1378 FlushQueueForTest(); // Allow the restart to finish. | 1376 FlushQueueForTest(); // Allow the restart to finish. |
1379 EXPECT_EQ(0, cache_->GetEntryCount()); | 1377 EXPECT_EQ(0, cache_->GetEntryCount()); |
1380 } | 1378 } |
1381 | 1379 |
1382 TEST_F(DiskCacheBackendTest, InvalidRankingsSuccess) { | 1380 TEST_F(DiskCacheBackendTest, InvalidRankingsSuccess) { |
1383 ASSERT_TRUE(CopyTestCache("bad_rankings")); | 1381 ASSERT_TRUE(CopyTestCache("bad_rankings", path())); |
1384 DisableFirstCleanup(); | 1382 DisableFirstCleanup(); |
1385 SetDirectMode(); | 1383 SetDirectMode(); |
1386 InitCache(); | 1384 InitCache(); |
1387 BackendInvalidRankings(); | 1385 BackendInvalidRankings(); |
1388 } | 1386 } |
1389 | 1387 |
1390 TEST_F(DiskCacheBackendTest, NewEvictionInvalidRankingsSuccess) { | 1388 TEST_F(DiskCacheBackendTest, NewEvictionInvalidRankingsSuccess) { |
1391 ASSERT_TRUE(CopyTestCache("bad_rankings")); | 1389 ASSERT_TRUE(CopyTestCache("bad_rankings", path())); |
1392 DisableFirstCleanup(); | 1390 DisableFirstCleanup(); |
1393 SetDirectMode(); | 1391 SetDirectMode(); |
1394 SetNewEviction(); | 1392 SetNewEviction(); |
1395 InitCache(); | 1393 InitCache(); |
1396 BackendInvalidRankings(); | 1394 BackendInvalidRankings(); |
1397 } | 1395 } |
1398 | 1396 |
1399 TEST_F(DiskCacheBackendTest, InvalidRankingsFailure) { | 1397 TEST_F(DiskCacheBackendTest, InvalidRankingsFailure) { |
1400 ASSERT_TRUE(CopyTestCache("bad_rankings")); | 1398 ASSERT_TRUE(CopyTestCache("bad_rankings", path())); |
1401 DisableFirstCleanup(); | 1399 DisableFirstCleanup(); |
1402 SetDirectMode(); | 1400 SetDirectMode(); |
1403 InitCache(); | 1401 InitCache(); |
1404 SetTestMode(); // Fail cache reinitialization. | 1402 SetTestMode(); // Fail cache reinitialization. |
1405 BackendInvalidRankings(); | 1403 BackendInvalidRankings(); |
1406 } | 1404 } |
1407 | 1405 |
1408 TEST_F(DiskCacheBackendTest, NewEvictionInvalidRankingsFailure) { | 1406 TEST_F(DiskCacheBackendTest, NewEvictionInvalidRankingsFailure) { |
1409 ASSERT_TRUE(CopyTestCache("bad_rankings")); | 1407 ASSERT_TRUE(CopyTestCache("bad_rankings", path())); |
1410 DisableFirstCleanup(); | 1408 DisableFirstCleanup(); |
1411 SetDirectMode(); | 1409 SetDirectMode(); |
1412 SetNewEviction(); | 1410 SetNewEviction(); |
1413 InitCache(); | 1411 InitCache(); |
1414 SetTestMode(); // Fail cache reinitialization. | 1412 SetTestMode(); // Fail cache reinitialization. |
1415 BackendInvalidRankings(); | 1413 BackendInvalidRankings(); |
1416 } | 1414 } |
1417 | 1415 |
1418 // If the LRU is corrupt and we have open entries, we disable the cache. | 1416 // If the LRU is corrupt and we have open entries, we disable the cache. |
1419 void DiskCacheBackendTest::BackendDisable() { | 1417 void DiskCacheBackendTest::BackendDisable() { |
1420 disk_cache::Entry *entry1, *entry2; | 1418 disk_cache::Entry *entry1, *entry2; |
1421 void* iter = NULL; | 1419 void* iter = NULL; |
1422 ASSERT_EQ(net::OK, OpenNextEntry(&iter, &entry1)); | 1420 ASSERT_EQ(net::OK, OpenNextEntry(&iter, &entry1)); |
1423 | 1421 |
1424 EXPECT_NE(net::OK, OpenNextEntry(&iter, &entry2)); | 1422 EXPECT_NE(net::OK, OpenNextEntry(&iter, &entry2)); |
1425 EXPECT_EQ(2, cache_->GetEntryCount()); | 1423 EXPECT_EQ(2, cache_->GetEntryCount()); |
1426 EXPECT_NE(net::OK, CreateEntry("Something new", &entry2)); | 1424 EXPECT_NE(net::OK, CreateEntry("Something new", &entry2)); |
1427 | 1425 |
1428 entry1->Close(); | 1426 entry1->Close(); |
1429 FlushQueueForTest(); // Flushing the Close posts a task to restart the cache. | 1427 FlushQueueForTest(); // Flushing the Close posts a task to restart the cache. |
1430 FlushQueueForTest(); // This one actually allows that task to complete. | 1428 FlushQueueForTest(); // This one actually allows that task to complete. |
1431 | 1429 |
1432 EXPECT_EQ(0, cache_->GetEntryCount()); | 1430 EXPECT_EQ(0, cache_->GetEntryCount()); |
1433 } | 1431 } |
1434 | 1432 |
1435 TEST_F(DiskCacheBackendTest, DisableSuccess) { | 1433 TEST_F(DiskCacheBackendTest, DisableSuccess) { |
1436 ASSERT_TRUE(CopyTestCache("bad_rankings")); | 1434 ASSERT_TRUE(CopyTestCache("bad_rankings", path())); |
1437 DisableFirstCleanup(); | 1435 DisableFirstCleanup(); |
1438 SetDirectMode(); | 1436 SetDirectMode(); |
1439 InitCache(); | 1437 InitCache(); |
1440 BackendDisable(); | 1438 BackendDisable(); |
1441 } | 1439 } |
1442 | 1440 |
1443 TEST_F(DiskCacheBackendTest, NewEvictionDisableSuccess) { | 1441 TEST_F(DiskCacheBackendTest, NewEvictionDisableSuccess) { |
1444 ASSERT_TRUE(CopyTestCache("bad_rankings")); | 1442 ASSERT_TRUE(CopyTestCache("bad_rankings", path())); |
1445 DisableFirstCleanup(); | 1443 DisableFirstCleanup(); |
1446 SetDirectMode(); | 1444 SetDirectMode(); |
1447 SetNewEviction(); | 1445 SetNewEviction(); |
1448 InitCache(); | 1446 InitCache(); |
1449 BackendDisable(); | 1447 BackendDisable(); |
1450 } | 1448 } |
1451 | 1449 |
1452 TEST_F(DiskCacheBackendTest, DisableFailure) { | 1450 TEST_F(DiskCacheBackendTest, DisableFailure) { |
1453 ASSERT_TRUE(CopyTestCache("bad_rankings")); | 1451 ASSERT_TRUE(CopyTestCache("bad_rankings", path())); |
1454 DisableFirstCleanup(); | 1452 DisableFirstCleanup(); |
1455 SetDirectMode(); | 1453 SetDirectMode(); |
1456 InitCache(); | 1454 InitCache(); |
1457 SetTestMode(); // Fail cache reinitialization. | 1455 SetTestMode(); // Fail cache reinitialization. |
1458 BackendDisable(); | 1456 BackendDisable(); |
1459 } | 1457 } |
1460 | 1458 |
1461 TEST_F(DiskCacheBackendTest, NewEvictionDisableFailure) { | 1459 TEST_F(DiskCacheBackendTest, NewEvictionDisableFailure) { |
1462 ASSERT_TRUE(CopyTestCache("bad_rankings")); | 1460 ASSERT_TRUE(CopyTestCache("bad_rankings", path())); |
1463 DisableFirstCleanup(); | 1461 DisableFirstCleanup(); |
1464 SetDirectMode(); | 1462 SetDirectMode(); |
1465 SetNewEviction(); | 1463 SetNewEviction(); |
1466 InitCache(); | 1464 InitCache(); |
1467 SetTestMode(); // Fail cache reinitialization. | 1465 SetTestMode(); // Fail cache reinitialization. |
1468 BackendDisable(); | 1466 BackendDisable(); |
1469 } | 1467 } |
1470 | 1468 |
1471 // This is another type of corruption on the LRU; disable the cache. | 1469 // This is another type of corruption on the LRU; disable the cache. |
1472 void DiskCacheBackendTest::BackendDisable2() { | 1470 void DiskCacheBackendTest::BackendDisable2() { |
1473 EXPECT_EQ(8, cache_->GetEntryCount()); | 1471 EXPECT_EQ(8, cache_->GetEntryCount()); |
1474 | 1472 |
1475 disk_cache::Entry* entry; | 1473 disk_cache::Entry* entry; |
1476 void* iter = NULL; | 1474 void* iter = NULL; |
1477 int count = 0; | 1475 int count = 0; |
1478 while (OpenNextEntry(&iter, &entry) == net::OK) { | 1476 while (OpenNextEntry(&iter, &entry) == net::OK) { |
1479 ASSERT_TRUE(NULL != entry); | 1477 ASSERT_TRUE(NULL != entry); |
1480 entry->Close(); | 1478 entry->Close(); |
1481 count++; | 1479 count++; |
1482 ASSERT_LT(count, 9); | 1480 ASSERT_LT(count, 9); |
1483 }; | 1481 }; |
1484 | 1482 |
1485 FlushQueueForTest(); | 1483 FlushQueueForTest(); |
1486 EXPECT_EQ(0, cache_->GetEntryCount()); | 1484 EXPECT_EQ(0, cache_->GetEntryCount()); |
1487 } | 1485 } |
1488 | 1486 |
1489 TEST_F(DiskCacheBackendTest, DisableSuccess2) { | 1487 TEST_F(DiskCacheBackendTest, DisableSuccess2) { |
1490 ASSERT_TRUE(CopyTestCache("list_loop")); | 1488 ASSERT_TRUE(CopyTestCache("list_loop", path())); |
1491 DisableFirstCleanup(); | 1489 DisableFirstCleanup(); |
1492 SetDirectMode(); | 1490 SetDirectMode(); |
1493 InitCache(); | 1491 InitCache(); |
1494 BackendDisable2(); | 1492 BackendDisable2(); |
1495 } | 1493 } |
1496 | 1494 |
1497 TEST_F(DiskCacheBackendTest, NewEvictionDisableSuccess2) { | 1495 TEST_F(DiskCacheBackendTest, NewEvictionDisableSuccess2) { |
1498 ASSERT_TRUE(CopyTestCache("list_loop")); | 1496 ASSERT_TRUE(CopyTestCache("list_loop", path())); |
1499 DisableFirstCleanup(); | 1497 DisableFirstCleanup(); |
1500 SetNewEviction(); | 1498 SetNewEviction(); |
1501 SetDirectMode(); | 1499 SetDirectMode(); |
1502 InitCache(); | 1500 InitCache(); |
1503 BackendDisable2(); | 1501 BackendDisable2(); |
1504 } | 1502 } |
1505 | 1503 |
1506 TEST_F(DiskCacheBackendTest, DisableFailure2) { | 1504 TEST_F(DiskCacheBackendTest, DisableFailure2) { |
1507 ASSERT_TRUE(CopyTestCache("list_loop")); | 1505 ASSERT_TRUE(CopyTestCache("list_loop", path())); |
1508 DisableFirstCleanup(); | 1506 DisableFirstCleanup(); |
1509 SetDirectMode(); | 1507 SetDirectMode(); |
1510 InitCache(); | 1508 InitCache(); |
1511 SetTestMode(); // Fail cache reinitialization. | 1509 SetTestMode(); // Fail cache reinitialization. |
1512 BackendDisable2(); | 1510 BackendDisable2(); |
1513 } | 1511 } |
1514 | 1512 |
1515 TEST_F(DiskCacheBackendTest, NewEvictionDisableFailure2) { | 1513 TEST_F(DiskCacheBackendTest, NewEvictionDisableFailure2) { |
1516 ASSERT_TRUE(CopyTestCache("list_loop")); | 1514 ASSERT_TRUE(CopyTestCache("list_loop", path())); |
1517 DisableFirstCleanup(); | 1515 DisableFirstCleanup(); |
1518 SetDirectMode(); | 1516 SetDirectMode(); |
1519 SetNewEviction(); | 1517 SetNewEviction(); |
1520 InitCache(); | 1518 InitCache(); |
1521 SetTestMode(); // Fail cache reinitialization. | 1519 SetTestMode(); // Fail cache reinitialization. |
1522 BackendDisable2(); | 1520 BackendDisable2(); |
1523 } | 1521 } |
1524 | 1522 |
1525 // If the index size changes when we disable the cache, we should not crash. | 1523 // If the index size changes when we disable the cache, we should not crash. |
1526 void DiskCacheBackendTest::BackendDisable3() { | 1524 void DiskCacheBackendTest::BackendDisable3() { |
1527 disk_cache::Entry *entry1, *entry2; | 1525 disk_cache::Entry *entry1, *entry2; |
1528 void* iter = NULL; | 1526 void* iter = NULL; |
1529 EXPECT_EQ(2, cache_->GetEntryCount()); | 1527 EXPECT_EQ(2, cache_->GetEntryCount()); |
1530 ASSERT_EQ(net::OK, OpenNextEntry(&iter, &entry1)); | 1528 ASSERT_EQ(net::OK, OpenNextEntry(&iter, &entry1)); |
1531 entry1->Close(); | 1529 entry1->Close(); |
1532 | 1530 |
1533 EXPECT_NE(net::OK, OpenNextEntry(&iter, &entry2)); | 1531 EXPECT_NE(net::OK, OpenNextEntry(&iter, &entry2)); |
1534 FlushQueueForTest(); | 1532 FlushQueueForTest(); |
1535 | 1533 |
1536 ASSERT_EQ(net::OK, CreateEntry("Something new", &entry2)); | 1534 ASSERT_EQ(net::OK, CreateEntry("Something new", &entry2)); |
1537 entry2->Close(); | 1535 entry2->Close(); |
1538 | 1536 |
1539 EXPECT_EQ(1, cache_->GetEntryCount()); | 1537 EXPECT_EQ(1, cache_->GetEntryCount()); |
1540 } | 1538 } |
1541 | 1539 |
1542 TEST_F(DiskCacheBackendTest, DisableSuccess3) { | 1540 TEST_F(DiskCacheBackendTest, DisableSuccess3) { |
1543 ASSERT_TRUE(CopyTestCache("bad_rankings2")); | 1541 ASSERT_TRUE(CopyTestCache("bad_rankings2", path())); |
1544 DisableFirstCleanup(); | 1542 DisableFirstCleanup(); |
1545 SetMaxSize(20 * 1024 * 1024); | 1543 SetMaxSize(20 * 1024 * 1024); |
1546 InitCache(); | 1544 InitCache(); |
1547 BackendDisable3(); | 1545 BackendDisable3(); |
1548 } | 1546 } |
1549 | 1547 |
1550 TEST_F(DiskCacheBackendTest, NewEvictionDisableSuccess3) { | 1548 TEST_F(DiskCacheBackendTest, NewEvictionDisableSuccess3) { |
1551 ASSERT_TRUE(CopyTestCache("bad_rankings2")); | 1549 ASSERT_TRUE(CopyTestCache("bad_rankings2", path())); |
1552 DisableFirstCleanup(); | 1550 DisableFirstCleanup(); |
1553 SetMaxSize(20 * 1024 * 1024); | 1551 SetMaxSize(20 * 1024 * 1024); |
1554 SetNewEviction(); | 1552 SetNewEviction(); |
1555 InitCache(); | 1553 InitCache(); |
1556 BackendDisable3(); | 1554 BackendDisable3(); |
1557 } | 1555 } |
1558 | 1556 |
1559 // If we disable the cache, already open entries should work as far as possible. | 1557 // If we disable the cache, already open entries should work as far as possible. |
1560 void DiskCacheBackendTest::BackendDisable4() { | 1558 void DiskCacheBackendTest::BackendDisable4() { |
1561 disk_cache::Entry *entry1, *entry2, *entry3, *entry4; | 1559 disk_cache::Entry *entry1, *entry2, *entry3, *entry4; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1599 entry1->Close(); | 1597 entry1->Close(); |
1600 entry2->Close(); | 1598 entry2->Close(); |
1601 entry3->Close(); | 1599 entry3->Close(); |
1602 FlushQueueForTest(); // Flushing the Close posts a task to restart the cache. | 1600 FlushQueueForTest(); // Flushing the Close posts a task to restart the cache. |
1603 FlushQueueForTest(); // This one actually allows that task to complete. | 1601 FlushQueueForTest(); // This one actually allows that task to complete. |
1604 | 1602 |
1605 EXPECT_EQ(0, cache_->GetEntryCount()); | 1603 EXPECT_EQ(0, cache_->GetEntryCount()); |
1606 } | 1604 } |
1607 | 1605 |
1608 TEST_F(DiskCacheBackendTest, DisableSuccess4) { | 1606 TEST_F(DiskCacheBackendTest, DisableSuccess4) { |
1609 ASSERT_TRUE(CopyTestCache("bad_rankings")); | 1607 ASSERT_TRUE(CopyTestCache("bad_rankings", path())); |
1610 DisableFirstCleanup(); | 1608 DisableFirstCleanup(); |
1611 SetDirectMode(); | 1609 SetDirectMode(); |
1612 InitCache(); | 1610 InitCache(); |
1613 BackendDisable4(); | 1611 BackendDisable4(); |
1614 } | 1612 } |
1615 | 1613 |
1616 TEST_F(DiskCacheBackendTest, NewEvictionDisableSuccess4) { | 1614 TEST_F(DiskCacheBackendTest, NewEvictionDisableSuccess4) { |
1617 ASSERT_TRUE(CopyTestCache("bad_rankings")); | 1615 ASSERT_TRUE(CopyTestCache("bad_rankings", path())); |
1618 DisableFirstCleanup(); | 1616 DisableFirstCleanup(); |
1619 SetDirectMode(); | 1617 SetDirectMode(); |
1620 SetNewEviction(); | 1618 SetNewEviction(); |
1621 InitCache(); | 1619 InitCache(); |
1622 BackendDisable4(); | 1620 BackendDisable4(); |
1623 } | 1621 } |
1624 | 1622 |
1625 TEST_F(DiskCacheTest, Backend_UsageStats) { | 1623 TEST_F(DiskCacheTest, Backend_UsageStats) { |
| 1624 ScopedTestCache test_cache; |
| 1625 |
1626 MessageLoopHelper helper; | 1626 MessageLoopHelper helper; |
1627 | 1627 |
1628 FilePath path = GetCacheFilePath(); | |
1629 ASSERT_TRUE(DeleteCache(path)); | |
1630 scoped_ptr<disk_cache::BackendImpl> cache; | 1628 scoped_ptr<disk_cache::BackendImpl> cache; |
1631 cache.reset(new disk_cache::BackendImpl( | 1629 cache.reset(new disk_cache::BackendImpl( |
1632 path, base::MessageLoopProxy::CreateForCurrentThread())); | 1630 test_cache.path(), |
| 1631 base::MessageLoopProxy::CreateForCurrentThread())); |
1633 ASSERT_TRUE(NULL != cache.get()); | 1632 ASSERT_TRUE(NULL != cache.get()); |
1634 cache->SetUnitTestMode(); | 1633 cache->SetUnitTestMode(); |
1635 ASSERT_EQ(net::OK, cache->SyncInit()); | 1634 ASSERT_EQ(net::OK, cache->SyncInit()); |
1636 | 1635 |
1637 // Wait for a callback that never comes... about 2 secs :). The message loop | 1636 // Wait for a callback that never comes... about 2 secs :). The message loop |
1638 // has to run to allow invocation of the usage timer. | 1637 // has to run to allow invocation of the usage timer. |
1639 helper.WaitUntilCacheIoFinished(1); | 1638 helper.WaitUntilCacheIoFinished(1); |
1640 } | 1639 } |
1641 | 1640 |
1642 void DiskCacheBackendTest::BackendDoomAll() { | 1641 void DiskCacheBackendTest::BackendDoomAll() { |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1708 EXPECT_EQ(net::OK, DoomAllEntries()); | 1707 EXPECT_EQ(net::OK, DoomAllEntries()); |
1709 | 1708 |
1710 disk_cache::Entry* entry; | 1709 disk_cache::Entry* entry; |
1711 ASSERT_EQ(net::OK, CreateEntry("Something new", &entry)); | 1710 ASSERT_EQ(net::OK, CreateEntry("Something new", &entry)); |
1712 entry->Close(); | 1711 entry->Close(); |
1713 | 1712 |
1714 EXPECT_EQ(1, cache_->GetEntryCount()); | 1713 EXPECT_EQ(1, cache_->GetEntryCount()); |
1715 } | 1714 } |
1716 | 1715 |
1717 TEST_F(DiskCacheBackendTest, DoomAll2) { | 1716 TEST_F(DiskCacheBackendTest, DoomAll2) { |
1718 ASSERT_TRUE(CopyTestCache("bad_rankings2")); | 1717 ASSERT_TRUE(CopyTestCache("bad_rankings2", path())); |
1719 DisableFirstCleanup(); | 1718 DisableFirstCleanup(); |
1720 SetMaxSize(20 * 1024 * 1024); | 1719 SetMaxSize(20 * 1024 * 1024); |
1721 InitCache(); | 1720 InitCache(); |
1722 BackendDoomAll2(); | 1721 BackendDoomAll2(); |
1723 } | 1722 } |
1724 | 1723 |
1725 TEST_F(DiskCacheBackendTest, NewEvictionDoomAll2) { | 1724 TEST_F(DiskCacheBackendTest, NewEvictionDoomAll2) { |
1726 ASSERT_TRUE(CopyTestCache("bad_rankings2")); | 1725 ASSERT_TRUE(CopyTestCache("bad_rankings2", path())); |
1727 DisableFirstCleanup(); | 1726 DisableFirstCleanup(); |
1728 SetMaxSize(20 * 1024 * 1024); | 1727 SetMaxSize(20 * 1024 * 1024); |
1729 SetNewEviction(); | 1728 SetNewEviction(); |
1730 InitCache(); | 1729 InitCache(); |
1731 BackendDoomAll2(); | 1730 BackendDoomAll2(); |
1732 } | 1731 } |
1733 | 1732 |
1734 // We should be able to create the same entry on multiple simultaneous instances | 1733 // We should be able to create the same entry on multiple simultaneous instances |
1735 // of the cache. | 1734 // of the cache. |
1736 TEST_F(DiskCacheTest, MultipleInstances) { | 1735 TEST_F(DiskCacheTest, MultipleInstances) { |
1737 ScopedTestCache store1; | 1736 ScopedTestCache store1; |
1738 ScopedTestCache store2("cache_test2"); | 1737 ScopedTestCache store2; |
1739 ScopedTestCache store3("cache_test3"); | 1738 ScopedTestCache store3; |
1740 base::Thread cache_thread("CacheThread"); | 1739 base::Thread cache_thread("CacheThread"); |
1741 ASSERT_TRUE(cache_thread.StartWithOptions( | 1740 ASSERT_TRUE(cache_thread.StartWithOptions( |
1742 base::Thread::Options(MessageLoop::TYPE_IO, 0))); | 1741 base::Thread::Options(MessageLoop::TYPE_IO, 0))); |
1743 TestCompletionCallback cb; | 1742 TestCompletionCallback cb; |
1744 | 1743 |
1745 const int kNumberOfCaches = 2; | 1744 const int kNumberOfCaches = 2; |
1746 disk_cache::Backend* cache[kNumberOfCaches]; | 1745 disk_cache::Backend* cache[kNumberOfCaches]; |
1747 | 1746 |
1748 int rv = disk_cache::BackendImpl::CreateBackend( | 1747 int rv = disk_cache::BackendImpl::CreateBackend( |
1749 store1.path(), false, 0, net::DISK_CACHE, disk_cache::kNone, | 1748 store1.path(), false, 0, net::DISK_CACHE, disk_cache::kNone, |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1881 EXPECT_EQ(kOneMB * 2, cache_impl_->GetTotalBuffersSize()); | 1880 EXPECT_EQ(kOneMB * 2, cache_impl_->GetTotalBuffersSize()); |
1882 | 1881 |
1883 // Check the upper limit. | 1882 // Check the upper limit. |
1884 EXPECT_FALSE(cache_impl_->IsAllocAllowed(0, 30 * kOneMB)); | 1883 EXPECT_FALSE(cache_impl_->IsAllocAllowed(0, 30 * kOneMB)); |
1885 | 1884 |
1886 for (int i = 0; i < 30; i++) | 1885 for (int i = 0; i < 30; i++) |
1887 cache_impl_->IsAllocAllowed(0, kOneMB); // Ignore the result. | 1886 cache_impl_->IsAllocAllowed(0, kOneMB); // Ignore the result. |
1888 | 1887 |
1889 EXPECT_FALSE(cache_impl_->IsAllocAllowed(0, kOneMB)); | 1888 EXPECT_FALSE(cache_impl_->IsAllocAllowed(0, kOneMB)); |
1890 } | 1889 } |
OLD | NEW |