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/file_util.h" | 6 #include "base/file_util.h" |
7 #include "base/path_service.h" | 7 #include "base/path_service.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 "base/thread.h" | |
11 #include "net/base/io_buffer.h" | 10 #include "net/base/io_buffer.h" |
12 #include "net/base/net_errors.h" | 11 #include "net/base/net_errors.h" |
13 #include "net/base/test_completion_callback.h" | 12 #include "net/base/test_completion_callback.h" |
14 #include "net/disk_cache/backend_impl.h" | 13 #include "net/disk_cache/backend_impl.h" |
15 #include "net/disk_cache/disk_cache_test_base.h" | 14 #include "net/disk_cache/disk_cache_test_base.h" |
16 #include "net/disk_cache/disk_cache_test_util.h" | 15 #include "net/disk_cache/disk_cache_test_util.h" |
17 #include "net/disk_cache/histogram_macros.h" | 16 #include "net/disk_cache/histogram_macros.h" |
18 #include "net/disk_cache/mapped_file.h" | 17 #include "net/disk_cache/mapped_file.h" |
19 #include "net/disk_cache/mem_backend_impl.h" | 18 #include "net/disk_cache/mem_backend_impl.h" |
20 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
247 ASSERT_EQ(net::OK, CreateEntry("key", &entry)); | 246 ASSERT_EQ(net::OK, CreateEntry("key", &entry)); |
248 ASSERT_EQ(0, entry->WriteData(0, 20000, buffer1, 0, NULL, false)); | 247 ASSERT_EQ(0, entry->WriteData(0, 20000, buffer1, 0, NULL, false)); |
249 entry->Close(); | 248 entry->Close(); |
250 | 249 |
251 // And verify that the first file is still there. | 250 // And verify that the first file is still there. |
252 scoped_refptr<net::IOBuffer> buffer2 = new net::IOBuffer(kSize); | 251 scoped_refptr<net::IOBuffer> buffer2 = new net::IOBuffer(kSize); |
253 ASSERT_EQ(kSize, file_util::ReadFile(filename, buffer2->data(), kSize)); | 252 ASSERT_EQ(kSize, file_util::ReadFile(filename, buffer2->data(), kSize)); |
254 EXPECT_EQ(0, memcmp(buffer1->data(), buffer2->data(), kSize)); | 253 EXPECT_EQ(0, memcmp(buffer1->data(), buffer2->data(), kSize)); |
255 } | 254 } |
256 | 255 |
256 // Tests that we deal with file-level pending operations at destruction time. | |
257 TEST_F(DiskCacheTest, ShutdownWithPendingIO) { | 257 TEST_F(DiskCacheTest, ShutdownWithPendingIO) { |
258 TestCompletionCallback callback; | 258 TestCompletionCallback cb; |
259 | 259 |
260 { | 260 { |
261 FilePath path = GetCacheFilePath(); | 261 FilePath path = GetCacheFilePath(); |
262 ASSERT_TRUE(DeleteCache(path)); | 262 ASSERT_TRUE(DeleteCache(path)); |
263 base::Thread cache_thread("CacheThread"); | 263 base::Thread cache_thread("CacheThread"); |
264 ASSERT_TRUE(cache_thread.StartWithOptions( | 264 ASSERT_TRUE(cache_thread.StartWithOptions( |
265 base::Thread::Options(MessageLoop::TYPE_IO, 0))); | 265 base::Thread::Options(MessageLoop::TYPE_IO, 0))); |
266 | 266 |
267 disk_cache::Backend* cache; | 267 disk_cache::Backend* cache; |
268 int rv = disk_cache::BackendImpl::CreateBackend( | 268 int rv = disk_cache::BackendImpl::CreateBackend( |
269 path, false, 0, net::DISK_CACHE, disk_cache::kNoRandom, | 269 path, false, 0, net::DISK_CACHE, disk_cache::kNoRandom, |
270 cache_thread.message_loop_proxy(), &cache, &callback); | 270 base::MessageLoopProxy::CreateForCurrentThread(), &cache, &cb); |
271 ASSERT_EQ(net::OK, callback.GetResult(rv)); | 271 ASSERT_EQ(net::OK, cb.GetResult(rv)); |
272 | 272 |
273 disk_cache::Entry* entry; | 273 disk_cache::EntryImpl* entry; |
274 rv = cache->CreateEntry("some key", &entry, &callback); | 274 rv = cache->CreateEntry("some key", |
275 ASSERT_EQ(net::OK, callback.GetResult(rv)); | 275 reinterpret_cast<disk_cache::Entry**>(&entry), &cb); |
276 ASSERT_EQ(net::OK, cb.GetResult(rv)); | |
276 | 277 |
277 const int kSize = 25000; | 278 const int kSize = 25000; |
278 scoped_refptr<net::IOBuffer> buffer = new net::IOBuffer(kSize); | 279 scoped_refptr<net::IOBuffer> buffer = new net::IOBuffer(kSize); |
279 CacheTestFillBuffer(buffer->data(), kSize, false); | 280 CacheTestFillBuffer(buffer->data(), kSize, false); |
280 | 281 |
281 for (int i = 0; i < 10 * 1024 * 1024; i += 64 * 1024) { | 282 for (int i = 0; i < 10 * 1024 * 1024; i += 64 * 1024) { |
282 int rv = entry->WriteData(0, i, buffer, kSize, &callback, false); | 283 // We are using the current thread as the cache thread because we want to |
284 // be able to call directly this method to make sure that the OS (instead | |
285 // of us switching thread) is returning IO pending. | |
286 rv = entry->WriteDataImpl(0, i, buffer, kSize, &cb, false); | |
283 if (rv == net::ERR_IO_PENDING) | 287 if (rv == net::ERR_IO_PENDING) |
284 break; | 288 break; |
285 EXPECT_EQ(kSize, rv); | 289 EXPECT_EQ(kSize, rv); |
286 } | 290 } |
287 | 291 |
292 // Don't call Close() to avoid going through the queue or we'll deadlock | |
293 // waiting for the operation to finish. | |
294 entry->Release(); | |
295 | |
296 // The cache destructor will see one pending operation here. | |
297 delete cache; | |
298 | |
299 if (rv == net::ERR_IO_PENDING) { | |
300 EXPECT_TRUE(cb.have_result()); | |
301 } | |
302 } | |
303 | |
304 MessageLoop::current()->RunAllPending(); | |
305 } | |
306 | |
307 // Tests that we deal with background-thread pending operations. | |
308 TEST_F(DiskCacheTest, ShutdownWithPendingIO2) { | |
309 TestCompletionCallback cb; | |
310 | |
311 { | |
312 FilePath path = GetCacheFilePath(); | |
313 ASSERT_TRUE(DeleteCache(path)); | |
314 base::Thread cache_thread("CacheThread"); | |
315 ASSERT_TRUE(cache_thread.StartWithOptions( | |
316 base::Thread::Options(MessageLoop::TYPE_IO, 0))); | |
317 | |
318 disk_cache::Backend* cache; | |
319 int rv = disk_cache::BackendImpl::CreateBackend( | |
320 path, false, 0, net::DISK_CACHE, disk_cache::kNoRandom, | |
321 cache_thread.message_loop_proxy(), &cache, &cb); | |
322 ASSERT_EQ(net::OK, cb.GetResult(rv)); | |
323 | |
324 disk_cache::Entry* entry; | |
325 rv = cache->CreateEntry("some key", &entry, &cb); | |
326 ASSERT_EQ(net::OK, cb.GetResult(rv)); | |
327 | |
328 const int kSize = 25000; | |
329 scoped_refptr<net::IOBuffer> buffer = new net::IOBuffer(kSize); | |
330 CacheTestFillBuffer(buffer->data(), kSize, false); | |
331 | |
332 rv = entry->WriteData(0, 0, buffer, kSize, &cb, false); | |
333 EXPECT_EQ(net::ERR_IO_PENDING, rv); | |
334 | |
288 entry->Close(); | 335 entry->Close(); |
289 | 336 |
290 // The cache destructor will see one pending operation here. | 337 // The cache destructor will see two pending operations here. |
291 delete cache; | 338 delete cache; |
292 } | 339 } |
293 | 340 |
294 MessageLoop::current()->RunAllPending(); | 341 MessageLoop::current()->RunAllPending(); |
295 } | 342 } |
296 | 343 |
297 TEST_F(DiskCacheTest, TruncatedIndex) { | 344 TEST_F(DiskCacheTest, TruncatedIndex) { |
298 FilePath path = GetCacheFilePath(); | 345 FilePath path = GetCacheFilePath(); |
299 ASSERT_TRUE(DeleteCache(path)); | 346 ASSERT_TRUE(DeleteCache(path)); |
300 FilePath index = path.AppendASCII("index"); | 347 FilePath index = path.AppendASCII("index"); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
337 // By doubling the total size, we make this file cacheable. | 384 // By doubling the total size, we make this file cacheable. |
338 SetMaxSize(cache_size * 2); | 385 SetMaxSize(cache_size * 2); |
339 EXPECT_EQ(cache_size / 5, entry->WriteData(1, 0, buffer, cache_size / 5, | 386 EXPECT_EQ(cache_size / 5, entry->WriteData(1, 0, buffer, cache_size / 5, |
340 NULL, false)); | 387 NULL, false)); |
341 | 388 |
342 // Let's fill up the cache!. | 389 // Let's fill up the cache!. |
343 SetMaxSize(cache_size * 10); | 390 SetMaxSize(cache_size * 10); |
344 EXPECT_EQ(cache_size * 3 / 4, entry->WriteData(0, 0, buffer, | 391 EXPECT_EQ(cache_size * 3 / 4, entry->WriteData(0, 0, buffer, |
345 cache_size * 3 / 4, NULL, false)); | 392 cache_size * 3 / 4, NULL, false)); |
346 entry->Close(); | 393 entry->Close(); |
394 FlushQueueForTest(); | |
347 | 395 |
348 SetMaxSize(cache_size); | 396 SetMaxSize(cache_size); |
349 | 397 |
350 // The cache is 95% full. | 398 // The cache is 95% full. |
351 | 399 |
352 ASSERT_EQ(net::OK, CreateEntry(second, &entry)); | 400 ASSERT_EQ(net::OK, CreateEntry(second, &entry)); |
353 EXPECT_EQ(cache_size / 10, entry->WriteData(0, 0, buffer, cache_size / 10, | 401 EXPECT_EQ(cache_size / 10, entry->WriteData(0, 0, buffer, cache_size / 10, |
354 NULL, false)) << "trim the cache"; | 402 NULL, false)) << "trim the cache"; |
355 entry->Close(); | 403 entry->Close(); |
356 | 404 |
357 EXPECT_NE(net::OK, OpenEntry(first, &entry)); | 405 // On a slow system we may end up evicting everything not currently in use. |
gavinp
2010/07/08 02:18:14
Does reordering the assert for OpenEntry(second) a
rvargas (doing something else)
2010/07/08 17:30:50
The problem with the old code is that it tests tha
| |
358 ASSERT_EQ(net::OK, OpenEntry(second, &entry)); | 406 ASSERT_EQ(net::OK, OpenEntry(second, &entry)); |
359 EXPECT_EQ(cache_size / 10, entry->GetDataSize(0)); | 407 EXPECT_EQ(cache_size / 10, entry->GetDataSize(0)); |
360 entry->Close(); | 408 entry->Close(); |
409 | |
410 EXPECT_NE(net::OK, OpenEntry(first, &entry)); | |
361 } | 411 } |
362 | 412 |
363 TEST_F(DiskCacheBackendTest, SetSize) { | 413 TEST_F(DiskCacheBackendTest, SetSize) { |
364 BackendSetSize(); | 414 BackendSetSize(); |
365 } | 415 } |
366 | 416 |
367 TEST_F(DiskCacheBackendTest, NewEvictionSetSize) { | 417 TEST_F(DiskCacheBackendTest, NewEvictionSetSize) { |
368 SetNewEviction(); | 418 SetNewEviction(); |
369 BackendSetSize(); | 419 BackendSetSize(); |
370 } | 420 } |
(...skipping 24 matching lines...) Expand all Loading... | |
395 } | 445 } |
396 | 446 |
397 for (int i = 0; i < 100; i++) { | 447 for (int i = 0; i < 100; i++) { |
398 disk_cache::Entry* entry; | 448 disk_cache::Entry* entry; |
399 ASSERT_EQ(net::OK, OpenEntry(entries[i]->GetKey(), &entry)); | 449 ASSERT_EQ(net::OK, OpenEntry(entries[i]->GetKey(), &entry)); |
400 EXPECT_TRUE(entry == entries[i]); | 450 EXPECT_TRUE(entry == entries[i]); |
401 entry->Close(); | 451 entry->Close(); |
402 entries[i]->Doom(); | 452 entries[i]->Doom(); |
403 entries[i]->Close(); | 453 entries[i]->Close(); |
404 } | 454 } |
455 FlushQueueForTest(); | |
405 EXPECT_EQ(0, cache_->GetEntryCount()); | 456 EXPECT_EQ(0, cache_->GetEntryCount()); |
406 } | 457 } |
407 | 458 |
408 TEST_F(DiskCacheBackendTest, Load) { | 459 TEST_F(DiskCacheBackendTest, Load) { |
409 // Work with a tiny index table (16 entries) | 460 // Work with a tiny index table (16 entries) |
410 SetMask(0xf); | 461 SetMask(0xf); |
411 SetMaxSize(0x100000); | 462 SetMaxSize(0x100000); |
412 BackendLoad(); | 463 BackendLoad(); |
413 } | 464 } |
414 | 465 |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
618 | 669 |
619 // Simulate a crash. | 670 // Simulate a crash. |
620 SimulateCrash(); | 671 SimulateCrash(); |
621 | 672 |
622 ASSERT_EQ(net::OK, CreateEntry(second, &entry)); | 673 ASSERT_EQ(net::OK, CreateEntry(second, &entry)); |
623 EXPECT_EQ(kSize, entry->WriteData(0, 0, buffer, kSize, NULL, false)); | 674 EXPECT_EQ(kSize, entry->WriteData(0, 0, buffer, kSize, NULL, false)); |
624 | 675 |
625 EXPECT_EQ(2, cache_->GetEntryCount()); | 676 EXPECT_EQ(2, cache_->GetEntryCount()); |
626 SetMaxSize(kSize); | 677 SetMaxSize(kSize); |
627 entry->Close(); // Trim the cache. | 678 entry->Close(); // Trim the cache. |
679 FlushQueueForTest(); | |
628 | 680 |
629 // If we evicted the entry in less than 20mS, we have one entry in the cache; | 681 // If we evicted the entry in less than 20mS, we have one entry in the cache; |
630 // if it took more than that, we posted a task and we'll delete the second | 682 // if it took more than that, we posted a task and we'll delete the second |
631 // entry too. | 683 // entry too. |
632 MessageLoop::current()->RunAllPending(); | 684 MessageLoop::current()->RunAllPending(); |
633 EXPECT_GE(1, cache_->GetEntryCount()); | 685 EXPECT_GE(1, cache_->GetEntryCount()); |
634 EXPECT_NE(net::OK, OpenEntry(first, &entry)); | 686 EXPECT_NE(net::OK, OpenEntry(first, &entry)); |
635 } | 687 } |
636 | 688 |
637 // We'll be leaking memory from this test. | 689 // We'll be leaking memory from this test. |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
678 EXPECT_EQ(33, cache_->GetEntryCount()); | 730 EXPECT_EQ(33, cache_->GetEntryCount()); |
679 SetMaxSize(kSize); | 731 SetMaxSize(kSize); |
680 | 732 |
681 // For the new eviction code, all corrupt entries are on the second list so | 733 // For the new eviction code, all corrupt entries are on the second list so |
682 // they are not going away that easy. | 734 // they are not going away that easy. |
683 if (new_eviction_) { | 735 if (new_eviction_) { |
684 EXPECT_EQ(net::OK, DoomAllEntries()); | 736 EXPECT_EQ(net::OK, DoomAllEntries()); |
685 } | 737 } |
686 | 738 |
687 entry->Close(); // Trim the cache. | 739 entry->Close(); // Trim the cache. |
740 FlushQueueForTest(); | |
688 | 741 |
689 // We may abort the eviction before cleaning up everything. | 742 // We may abort the eviction before cleaning up everything. |
690 MessageLoop::current()->RunAllPending(); | 743 MessageLoop::current()->RunAllPending(); |
691 EXPECT_GE(30, cache_->GetEntryCount()); | 744 EXPECT_GE(30, cache_->GetEntryCount()); |
692 } | 745 } |
693 | 746 |
694 // We'll be leaking memory from this test. | 747 // We'll be leaking memory from this test. |
695 TEST_F(DiskCacheBackendTest, TrimInvalidEntry2) { | 748 TEST_F(DiskCacheBackendTest, TrimInvalidEntry2) { |
696 BackendTrimInvalidEntry2(); | 749 BackendTrimInvalidEntry2(); |
697 } | 750 } |
(...skipping 554 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1252 | 1305 |
1253 // If the LRU is corrupt, we delete the cache. | 1306 // If the LRU is corrupt, we delete the cache. |
1254 void DiskCacheBackendTest::BackendInvalidRankings() { | 1307 void DiskCacheBackendTest::BackendInvalidRankings() { |
1255 disk_cache::Entry* entry; | 1308 disk_cache::Entry* entry; |
1256 void* iter = NULL; | 1309 void* iter = NULL; |
1257 ASSERT_EQ(net::OK, OpenNextEntry(&iter, &entry)); | 1310 ASSERT_EQ(net::OK, OpenNextEntry(&iter, &entry)); |
1258 entry->Close(); | 1311 entry->Close(); |
1259 EXPECT_EQ(2, cache_->GetEntryCount()); | 1312 EXPECT_EQ(2, cache_->GetEntryCount()); |
1260 | 1313 |
1261 EXPECT_NE(net::OK, OpenNextEntry(&iter, &entry)); | 1314 EXPECT_NE(net::OK, OpenNextEntry(&iter, &entry)); |
1262 MessageLoop::current()->RunAllPending(); | 1315 FlushQueueForTest(); // Allow the restart to finish. |
1263 EXPECT_EQ(0, cache_->GetEntryCount()); | 1316 EXPECT_EQ(0, cache_->GetEntryCount()); |
1264 } | 1317 } |
1265 | 1318 |
1266 TEST_F(DiskCacheBackendTest, InvalidRankingsSuccess) { | 1319 TEST_F(DiskCacheBackendTest, InvalidRankingsSuccess) { |
1267 ASSERT_TRUE(CopyTestCache(L"bad_rankings")); | 1320 ASSERT_TRUE(CopyTestCache(L"bad_rankings")); |
1268 DisableFirstCleanup(); | 1321 DisableFirstCleanup(); |
1269 SetDirectMode(); | 1322 SetDirectMode(); |
1270 InitCache(); | 1323 InitCache(); |
1271 BackendInvalidRankings(); | 1324 BackendInvalidRankings(); |
1272 } | 1325 } |
(...skipping 30 matching lines...) Expand all Loading... | |
1303 void DiskCacheBackendTest::BackendDisable() { | 1356 void DiskCacheBackendTest::BackendDisable() { |
1304 disk_cache::Entry *entry1, *entry2; | 1357 disk_cache::Entry *entry1, *entry2; |
1305 void* iter = NULL; | 1358 void* iter = NULL; |
1306 ASSERT_EQ(net::OK, OpenNextEntry(&iter, &entry1)); | 1359 ASSERT_EQ(net::OK, OpenNextEntry(&iter, &entry1)); |
1307 | 1360 |
1308 EXPECT_NE(net::OK, OpenNextEntry(&iter, &entry2)); | 1361 EXPECT_NE(net::OK, OpenNextEntry(&iter, &entry2)); |
1309 EXPECT_EQ(2, cache_->GetEntryCount()); | 1362 EXPECT_EQ(2, cache_->GetEntryCount()); |
1310 EXPECT_NE(net::OK, CreateEntry("Something new", &entry2)); | 1363 EXPECT_NE(net::OK, CreateEntry("Something new", &entry2)); |
1311 | 1364 |
1312 entry1->Close(); | 1365 entry1->Close(); |
1313 MessageLoop::current()->RunAllPending(); | 1366 FlushQueueForTest(); // Flushing the Close posts a task to restart the cache. |
1367 FlushQueueForTest(); // This one actually allows that task to complete. | |
1314 | 1368 |
1315 EXPECT_EQ(0, cache_->GetEntryCount()); | 1369 EXPECT_EQ(0, cache_->GetEntryCount()); |
1316 } | 1370 } |
1317 | 1371 |
1318 TEST_F(DiskCacheBackendTest, DisableSuccess) { | 1372 TEST_F(DiskCacheBackendTest, DisableSuccess) { |
1319 ASSERT_TRUE(CopyTestCache(L"bad_rankings")); | 1373 ASSERT_TRUE(CopyTestCache(L"bad_rankings")); |
1320 DisableFirstCleanup(); | 1374 DisableFirstCleanup(); |
1321 SetDirectMode(); | 1375 SetDirectMode(); |
1322 InitCache(); | 1376 InitCache(); |
1323 BackendDisable(); | 1377 BackendDisable(); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1358 disk_cache::Entry* entry; | 1412 disk_cache::Entry* entry; |
1359 void* iter = NULL; | 1413 void* iter = NULL; |
1360 int count = 0; | 1414 int count = 0; |
1361 while (OpenNextEntry(&iter, &entry) == net::OK) { | 1415 while (OpenNextEntry(&iter, &entry) == net::OK) { |
1362 ASSERT_TRUE(NULL != entry); | 1416 ASSERT_TRUE(NULL != entry); |
1363 entry->Close(); | 1417 entry->Close(); |
1364 count++; | 1418 count++; |
1365 ASSERT_LT(count, 9); | 1419 ASSERT_LT(count, 9); |
1366 }; | 1420 }; |
1367 | 1421 |
1368 MessageLoop::current()->RunAllPending(); | 1422 FlushQueueForTest(); |
1369 EXPECT_EQ(0, cache_->GetEntryCount()); | 1423 EXPECT_EQ(0, cache_->GetEntryCount()); |
1370 } | 1424 } |
1371 | 1425 |
1372 TEST_F(DiskCacheBackendTest, DisableSuccess2) { | 1426 TEST_F(DiskCacheBackendTest, DisableSuccess2) { |
1373 ASSERT_TRUE(CopyTestCache(L"list_loop")); | 1427 ASSERT_TRUE(CopyTestCache(L"list_loop")); |
1374 DisableFirstCleanup(); | 1428 DisableFirstCleanup(); |
1375 SetDirectMode(); | 1429 SetDirectMode(); |
1376 InitCache(); | 1430 InitCache(); |
1377 BackendDisable2(); | 1431 BackendDisable2(); |
1378 } | 1432 } |
(...skipping 28 matching lines...) Expand all Loading... | |
1407 | 1461 |
1408 // If the index size changes when we disable the cache, we should not crash. | 1462 // If the index size changes when we disable the cache, we should not crash. |
1409 void DiskCacheBackendTest::BackendDisable3() { | 1463 void DiskCacheBackendTest::BackendDisable3() { |
1410 disk_cache::Entry *entry1, *entry2; | 1464 disk_cache::Entry *entry1, *entry2; |
1411 void* iter = NULL; | 1465 void* iter = NULL; |
1412 EXPECT_EQ(2, cache_->GetEntryCount()); | 1466 EXPECT_EQ(2, cache_->GetEntryCount()); |
1413 ASSERT_EQ(net::OK, OpenNextEntry(&iter, &entry1)); | 1467 ASSERT_EQ(net::OK, OpenNextEntry(&iter, &entry1)); |
1414 entry1->Close(); | 1468 entry1->Close(); |
1415 | 1469 |
1416 EXPECT_NE(net::OK, OpenNextEntry(&iter, &entry2)); | 1470 EXPECT_NE(net::OK, OpenNextEntry(&iter, &entry2)); |
1417 MessageLoop::current()->RunAllPending(); | 1471 FlushQueueForTest(); |
1418 | 1472 |
1419 ASSERT_EQ(net::OK, CreateEntry("Something new", &entry2)); | 1473 ASSERT_EQ(net::OK, CreateEntry("Something new", &entry2)); |
1420 entry2->Close(); | 1474 entry2->Close(); |
1421 | 1475 |
1422 EXPECT_EQ(1, cache_->GetEntryCount()); | 1476 EXPECT_EQ(1, cache_->GetEntryCount()); |
1423 } | 1477 } |
1424 | 1478 |
1425 TEST_F(DiskCacheBackendTest, DisableSuccess3) { | 1479 TEST_F(DiskCacheBackendTest, DisableSuccess3) { |
1426 ASSERT_TRUE(CopyTestCache(L"bad_rankings2")); | 1480 ASSERT_TRUE(CopyTestCache(L"bad_rankings2")); |
1427 DisableFirstCleanup(); | 1481 DisableFirstCleanup(); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1475 EXPECT_EQ(kBufSize, entry3->WriteData(1, 0, buf, kBufSize, NULL, false)); | 1529 EXPECT_EQ(kBufSize, entry3->WriteData(1, 0, buf, kBufSize, NULL, false)); |
1476 | 1530 |
1477 std::string key = entry2->GetKey(); | 1531 std::string key = entry2->GetKey(); |
1478 EXPECT_EQ(sizeof(key2) - 1, key.size()); | 1532 EXPECT_EQ(sizeof(key2) - 1, key.size()); |
1479 key = entry3->GetKey(); | 1533 key = entry3->GetKey(); |
1480 EXPECT_EQ(sizeof(key3) - 1, key.size()); | 1534 EXPECT_EQ(sizeof(key3) - 1, key.size()); |
1481 | 1535 |
1482 entry1->Close(); | 1536 entry1->Close(); |
1483 entry2->Close(); | 1537 entry2->Close(); |
1484 entry3->Close(); | 1538 entry3->Close(); |
1485 MessageLoop::current()->RunAllPending(); | 1539 FlushQueueForTest(); // Flushing the Close posts a task to restart the cache. |
1540 FlushQueueForTest(); // This one actually allows that task to complete. | |
1486 | 1541 |
1487 EXPECT_EQ(0, cache_->GetEntryCount()); | 1542 EXPECT_EQ(0, cache_->GetEntryCount()); |
1488 } | 1543 } |
1489 | 1544 |
1490 TEST_F(DiskCacheBackendTest, DisableSuccess4) { | 1545 TEST_F(DiskCacheBackendTest, DisableSuccess4) { |
1491 ASSERT_TRUE(CopyTestCache(L"bad_rankings")); | 1546 ASSERT_TRUE(CopyTestCache(L"bad_rankings")); |
1492 DisableFirstCleanup(); | 1547 DisableFirstCleanup(); |
1493 SetDirectMode(); | 1548 SetDirectMode(); |
1494 InitCache(); | 1549 InitCache(); |
1495 BackendDisable4(); | 1550 BackendDisable4(); |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1697 // another. | 1752 // another. |
1698 TEST_F(DiskCacheBackendTest, Histograms) { | 1753 TEST_F(DiskCacheBackendTest, Histograms) { |
1699 SetDirectMode(); | 1754 SetDirectMode(); |
1700 InitCache(); | 1755 InitCache(); |
1701 disk_cache::BackendImpl* backend_ = cache_impl_; // Needed be the macro. | 1756 disk_cache::BackendImpl* backend_ = cache_impl_; // Needed be the macro. |
1702 | 1757 |
1703 for (int i = 1; i < 3; i++) { | 1758 for (int i = 1; i < 3; i++) { |
1704 CACHE_UMA(HOURS, "FillupTime", i, 28); | 1759 CACHE_UMA(HOURS, "FillupTime", i, 28); |
1705 } | 1760 } |
1706 } | 1761 } |
OLD | NEW |