| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <stdint.h> | 5 #include <stdint.h> |
| 6 | 6 |
| 7 #include "base/files/file.h" | 7 #include "base/files/file.h" |
| 8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
| 9 #include "base/metrics/field_trial.h" | 9 #include "base/metrics/field_trial.h" |
| 10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 | 43 |
| 44 // Provide a BackendImpl object to macros from histogram_macros.h. | 44 // Provide a BackendImpl object to macros from histogram_macros.h. |
| 45 #define CACHE_UMA_BACKEND_IMPL_OBJ backend_ | 45 #define CACHE_UMA_BACKEND_IMPL_OBJ backend_ |
| 46 | 46 |
| 47 using base::Time; | 47 using base::Time; |
| 48 | 48 |
| 49 namespace { | 49 namespace { |
| 50 | 50 |
| 51 const char kExistingEntryKey[] = "existing entry key"; | 51 const char kExistingEntryKey[] = "existing entry key"; |
| 52 | 52 |
| 53 scoped_ptr<disk_cache::BackendImpl> CreateExistingEntryCache( | 53 std::unique_ptr<disk_cache::BackendImpl> CreateExistingEntryCache( |
| 54 const base::Thread& cache_thread, | 54 const base::Thread& cache_thread, |
| 55 base::FilePath& cache_path) { | 55 base::FilePath& cache_path) { |
| 56 net::TestCompletionCallback cb; | 56 net::TestCompletionCallback cb; |
| 57 | 57 |
| 58 scoped_ptr<disk_cache::BackendImpl> cache(new disk_cache::BackendImpl( | 58 std::unique_ptr<disk_cache::BackendImpl> cache(new disk_cache::BackendImpl( |
| 59 cache_path, cache_thread.task_runner(), NULL)); | 59 cache_path, cache_thread.task_runner(), NULL)); |
| 60 int rv = cache->Init(cb.callback()); | 60 int rv = cache->Init(cb.callback()); |
| 61 if (cb.GetResult(rv) != net::OK) | 61 if (cb.GetResult(rv) != net::OK) |
| 62 return scoped_ptr<disk_cache::BackendImpl>(); | 62 return std::unique_ptr<disk_cache::BackendImpl>(); |
| 63 | 63 |
| 64 disk_cache::Entry* entry = NULL; | 64 disk_cache::Entry* entry = NULL; |
| 65 rv = cache->CreateEntry(kExistingEntryKey, &entry, cb.callback()); | 65 rv = cache->CreateEntry(kExistingEntryKey, &entry, cb.callback()); |
| 66 if (cb.GetResult(rv) != net::OK) | 66 if (cb.GetResult(rv) != net::OK) |
| 67 return scoped_ptr<disk_cache::BackendImpl>(); | 67 return std::unique_ptr<disk_cache::BackendImpl>(); |
| 68 entry->Close(); | 68 entry->Close(); |
| 69 | 69 |
| 70 return cache; | 70 return cache; |
| 71 } | 71 } |
| 72 | 72 |
| 73 } // namespace | 73 } // namespace |
| 74 | 74 |
| 75 // Tests that can run with different types of caches. | 75 // Tests that can run with different types of caches. |
| 76 class DiskCacheBackendTest : public DiskCacheTestWithCache { | 76 class DiskCacheBackendTest : public DiskCacheTestWithCache { |
| 77 protected: | 77 protected: |
| (...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 441 TEST_F(DiskCacheTest, CreateBackend) { | 441 TEST_F(DiskCacheTest, CreateBackend) { |
| 442 net::TestCompletionCallback cb; | 442 net::TestCompletionCallback cb; |
| 443 | 443 |
| 444 { | 444 { |
| 445 ASSERT_TRUE(CleanupCacheDir()); | 445 ASSERT_TRUE(CleanupCacheDir()); |
| 446 base::Thread cache_thread("CacheThread"); | 446 base::Thread cache_thread("CacheThread"); |
| 447 ASSERT_TRUE(cache_thread.StartWithOptions( | 447 ASSERT_TRUE(cache_thread.StartWithOptions( |
| 448 base::Thread::Options(base::MessageLoop::TYPE_IO, 0))); | 448 base::Thread::Options(base::MessageLoop::TYPE_IO, 0))); |
| 449 | 449 |
| 450 // Test the private factory method(s). | 450 // Test the private factory method(s). |
| 451 scoped_ptr<disk_cache::Backend> cache; | 451 std::unique_ptr<disk_cache::Backend> cache; |
| 452 cache = disk_cache::MemBackendImpl::CreateBackend(0, NULL); | 452 cache = disk_cache::MemBackendImpl::CreateBackend(0, NULL); |
| 453 ASSERT_TRUE(cache.get()); | 453 ASSERT_TRUE(cache.get()); |
| 454 cache.reset(); | 454 cache.reset(); |
| 455 | 455 |
| 456 // Now test the public API. | 456 // Now test the public API. |
| 457 int rv = disk_cache::CreateCacheBackend(net::DISK_CACHE, | 457 int rv = disk_cache::CreateCacheBackend(net::DISK_CACHE, |
| 458 net::CACHE_BACKEND_DEFAULT, | 458 net::CACHE_BACKEND_DEFAULT, |
| 459 cache_path_, | 459 cache_path_, |
| 460 0, | 460 0, |
| 461 false, | 461 false, |
| (...skipping 22 matching lines...) Expand all Loading... |
| 484 TEST_F(DiskCacheBackendTest, CreateBackend_MissingFile) { | 484 TEST_F(DiskCacheBackendTest, CreateBackend_MissingFile) { |
| 485 ASSERT_TRUE(CopyTestCache("bad_entry")); | 485 ASSERT_TRUE(CopyTestCache("bad_entry")); |
| 486 base::FilePath filename = cache_path_.AppendASCII("data_1"); | 486 base::FilePath filename = cache_path_.AppendASCII("data_1"); |
| 487 base::DeleteFile(filename, false); | 487 base::DeleteFile(filename, false); |
| 488 base::Thread cache_thread("CacheThread"); | 488 base::Thread cache_thread("CacheThread"); |
| 489 ASSERT_TRUE(cache_thread.StartWithOptions( | 489 ASSERT_TRUE(cache_thread.StartWithOptions( |
| 490 base::Thread::Options(base::MessageLoop::TYPE_IO, 0))); | 490 base::Thread::Options(base::MessageLoop::TYPE_IO, 0))); |
| 491 net::TestCompletionCallback cb; | 491 net::TestCompletionCallback cb; |
| 492 | 492 |
| 493 bool prev = base::ThreadRestrictions::SetIOAllowed(false); | 493 bool prev = base::ThreadRestrictions::SetIOAllowed(false); |
| 494 scoped_ptr<disk_cache::BackendImpl> cache(new disk_cache::BackendImpl( | 494 std::unique_ptr<disk_cache::BackendImpl> cache(new disk_cache::BackendImpl( |
| 495 cache_path_, cache_thread.task_runner(), NULL)); | 495 cache_path_, cache_thread.task_runner(), NULL)); |
| 496 int rv = cache->Init(cb.callback()); | 496 int rv = cache->Init(cb.callback()); |
| 497 EXPECT_EQ(net::ERR_FAILED, cb.GetResult(rv)); | 497 EXPECT_EQ(net::ERR_FAILED, cb.GetResult(rv)); |
| 498 base::ThreadRestrictions::SetIOAllowed(prev); | 498 base::ThreadRestrictions::SetIOAllowed(prev); |
| 499 | 499 |
| 500 cache.reset(); | 500 cache.reset(); |
| 501 DisableIntegrityCheck(); | 501 DisableIntegrityCheck(); |
| 502 } | 502 } |
| 503 | 503 |
| 504 TEST_F(DiskCacheBackendTest, ExternalFiles) { | 504 TEST_F(DiskCacheBackendTest, ExternalFiles) { |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 577 #endif | 577 #endif |
| 578 | 578 |
| 579 // See crbug.com/330074 | 579 // See crbug.com/330074 |
| 580 #if !defined(OS_IOS) | 580 #if !defined(OS_IOS) |
| 581 // Tests that one cache instance is not affected by another one going away. | 581 // Tests that one cache instance is not affected by another one going away. |
| 582 TEST_F(DiskCacheBackendTest, MultipleInstancesWithPendingFileIO) { | 582 TEST_F(DiskCacheBackendTest, MultipleInstancesWithPendingFileIO) { |
| 583 base::ScopedTempDir store; | 583 base::ScopedTempDir store; |
| 584 ASSERT_TRUE(store.CreateUniqueTempDir()); | 584 ASSERT_TRUE(store.CreateUniqueTempDir()); |
| 585 | 585 |
| 586 net::TestCompletionCallback cb; | 586 net::TestCompletionCallback cb; |
| 587 scoped_ptr<disk_cache::Backend> extra_cache; | 587 std::unique_ptr<disk_cache::Backend> extra_cache; |
| 588 int rv = disk_cache::CreateCacheBackend(net::DISK_CACHE, | 588 int rv = disk_cache::CreateCacheBackend(net::DISK_CACHE, |
| 589 net::CACHE_BACKEND_DEFAULT, | 589 net::CACHE_BACKEND_DEFAULT, |
| 590 store.path(), | 590 store.path(), |
| 591 0, | 591 0, |
| 592 false, | 592 false, |
| 593 base::ThreadTaskRunnerHandle::Get(), | 593 base::ThreadTaskRunnerHandle::Get(), |
| 594 NULL, | 594 NULL, |
| 595 &extra_cache, | 595 &extra_cache, |
| 596 cb.callback()); | 596 cb.callback()); |
| 597 ASSERT_EQ(net::OK, cb.GetResult(rv)); | 597 ASSERT_EQ(net::OK, cb.GetResult(rv)); |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 740 TEST_F(DiskCacheTest, TruncatedIndex) { | 740 TEST_F(DiskCacheTest, TruncatedIndex) { |
| 741 ASSERT_TRUE(CleanupCacheDir()); | 741 ASSERT_TRUE(CleanupCacheDir()); |
| 742 base::FilePath index = cache_path_.AppendASCII("index"); | 742 base::FilePath index = cache_path_.AppendASCII("index"); |
| 743 ASSERT_EQ(5, base::WriteFile(index, "hello", 5)); | 743 ASSERT_EQ(5, base::WriteFile(index, "hello", 5)); |
| 744 | 744 |
| 745 base::Thread cache_thread("CacheThread"); | 745 base::Thread cache_thread("CacheThread"); |
| 746 ASSERT_TRUE(cache_thread.StartWithOptions( | 746 ASSERT_TRUE(cache_thread.StartWithOptions( |
| 747 base::Thread::Options(base::MessageLoop::TYPE_IO, 0))); | 747 base::Thread::Options(base::MessageLoop::TYPE_IO, 0))); |
| 748 net::TestCompletionCallback cb; | 748 net::TestCompletionCallback cb; |
| 749 | 749 |
| 750 scoped_ptr<disk_cache::Backend> backend; | 750 std::unique_ptr<disk_cache::Backend> backend; |
| 751 int rv = disk_cache::CreateCacheBackend(net::DISK_CACHE, | 751 int rv = disk_cache::CreateCacheBackend(net::DISK_CACHE, |
| 752 net::CACHE_BACKEND_BLOCKFILE, | 752 net::CACHE_BACKEND_BLOCKFILE, |
| 753 cache_path_, | 753 cache_path_, |
| 754 0, | 754 0, |
| 755 false, | 755 false, |
| 756 cache_thread.task_runner(), | 756 cache_thread.task_runner(), |
| 757 NULL, | 757 NULL, |
| 758 &backend, | 758 &backend, |
| 759 cb.callback()); | 759 cb.callback()); |
| 760 ASSERT_NE(net::OK, cb.GetResult(rv)); | 760 ASSERT_NE(net::OK, cb.GetResult(rv)); |
| (...skipping 532 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1293 for (int i = 0; i < kNumEntries; i++) { | 1293 for (int i = 0; i < kNumEntries; i++) { |
| 1294 std::string key = GenerateKey(true); | 1294 std::string key = GenerateKey(true); |
| 1295 disk_cache::Entry* entry; | 1295 disk_cache::Entry* entry; |
| 1296 ASSERT_EQ(net::OK, CreateEntry(key, &entry)); | 1296 ASSERT_EQ(net::OK, CreateEntry(key, &entry)); |
| 1297 entry->Close(); | 1297 entry->Close(); |
| 1298 } | 1298 } |
| 1299 EXPECT_EQ(kNumEntries, cache_->GetEntryCount()); | 1299 EXPECT_EQ(kNumEntries, cache_->GetEntryCount()); |
| 1300 Time final = Time::Now(); | 1300 Time final = Time::Now(); |
| 1301 | 1301 |
| 1302 disk_cache::Entry* entry; | 1302 disk_cache::Entry* entry; |
| 1303 scoped_ptr<TestIterator> iter = CreateIterator(); | 1303 std::unique_ptr<TestIterator> iter = CreateIterator(); |
| 1304 int count = 0; | 1304 int count = 0; |
| 1305 Time last_modified[kNumEntries]; | 1305 Time last_modified[kNumEntries]; |
| 1306 Time last_used[kNumEntries]; | 1306 Time last_used[kNumEntries]; |
| 1307 while (iter->OpenNextEntry(&entry) == net::OK) { | 1307 while (iter->OpenNextEntry(&entry) == net::OK) { |
| 1308 ASSERT_TRUE(NULL != entry); | 1308 ASSERT_TRUE(NULL != entry); |
| 1309 if (count < kNumEntries) { | 1309 if (count < kNumEntries) { |
| 1310 last_modified[count] = entry->GetLastModified(); | 1310 last_modified[count] = entry->GetLastModified(); |
| 1311 last_used[count] = entry->GetLastUsed(); | 1311 last_used[count] = entry->GetLastUsed(); |
| 1312 EXPECT_TRUE(initial <= last_modified[count]); | 1312 EXPECT_TRUE(initial <= last_modified[count]); |
| 1313 EXPECT_TRUE(final >= last_modified[count]); | 1313 EXPECT_TRUE(final >= last_modified[count]); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1365 disk_cache::Entry *entry1, *entry2; | 1365 disk_cache::Entry *entry1, *entry2; |
| 1366 ASSERT_EQ(net::OK, CreateEntry(first, &entry1)); | 1366 ASSERT_EQ(net::OK, CreateEntry(first, &entry1)); |
| 1367 entry1->Close(); | 1367 entry1->Close(); |
| 1368 ASSERT_EQ(net::OK, CreateEntry(second, &entry2)); | 1368 ASSERT_EQ(net::OK, CreateEntry(second, &entry2)); |
| 1369 entry2->Close(); | 1369 entry2->Close(); |
| 1370 FlushQueueForTest(); | 1370 FlushQueueForTest(); |
| 1371 | 1371 |
| 1372 // Make sure that the timestamp is not the same. | 1372 // Make sure that the timestamp is not the same. |
| 1373 AddDelay(); | 1373 AddDelay(); |
| 1374 ASSERT_EQ(net::OK, OpenEntry(second, &entry1)); | 1374 ASSERT_EQ(net::OK, OpenEntry(second, &entry1)); |
| 1375 scoped_ptr<TestIterator> iter = CreateIterator(); | 1375 std::unique_ptr<TestIterator> iter = CreateIterator(); |
| 1376 ASSERT_EQ(net::OK, iter->OpenNextEntry(&entry2)); | 1376 ASSERT_EQ(net::OK, iter->OpenNextEntry(&entry2)); |
| 1377 EXPECT_EQ(entry2->GetKey(), second); | 1377 EXPECT_EQ(entry2->GetKey(), second); |
| 1378 | 1378 |
| 1379 // Two entries and the iterator pointing at "first". | 1379 // Two entries and the iterator pointing at "first". |
| 1380 entry1->Close(); | 1380 entry1->Close(); |
| 1381 entry2->Close(); | 1381 entry2->Close(); |
| 1382 | 1382 |
| 1383 // The iterator should still be valid, so we should not crash. | 1383 // The iterator should still be valid, so we should not crash. |
| 1384 ASSERT_EQ(net::OK, iter->OpenNextEntry(&entry2)); | 1384 ASSERT_EQ(net::OK, iter->OpenNextEntry(&entry2)); |
| 1385 EXPECT_EQ(entry2->GetKey(), first); | 1385 EXPECT_EQ(entry2->GetKey(), first); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1446 | 1446 |
| 1447 FlushQueueForTest(); | 1447 FlushQueueForTest(); |
| 1448 | 1448 |
| 1449 // Make sure that the timestamp is not the same. | 1449 // Make sure that the timestamp is not the same. |
| 1450 AddDelay(); | 1450 AddDelay(); |
| 1451 | 1451 |
| 1452 // Read from the last item in the LRU. | 1452 // Read from the last item in the LRU. |
| 1453 EXPECT_EQ(kSize, ReadData(entry1, 0, 0, buffer1.get(), kSize)); | 1453 EXPECT_EQ(kSize, ReadData(entry1, 0, 0, buffer1.get(), kSize)); |
| 1454 entry1->Close(); | 1454 entry1->Close(); |
| 1455 | 1455 |
| 1456 scoped_ptr<TestIterator> iter = CreateIterator(); | 1456 std::unique_ptr<TestIterator> iter = CreateIterator(); |
| 1457 ASSERT_EQ(net::OK, iter->OpenNextEntry(&entry2)); | 1457 ASSERT_EQ(net::OK, iter->OpenNextEntry(&entry2)); |
| 1458 EXPECT_EQ(entry2->GetKey(), second); | 1458 EXPECT_EQ(entry2->GetKey(), second); |
| 1459 entry2->Close(); | 1459 entry2->Close(); |
| 1460 } | 1460 } |
| 1461 | 1461 |
| 1462 #if !defined(LEAK_SANITIZER) | 1462 #if !defined(LEAK_SANITIZER) |
| 1463 // Verify handling of invalid entries while doing enumerations. | 1463 // Verify handling of invalid entries while doing enumerations. |
| 1464 // We'll be leaking memory from this test. | 1464 // We'll be leaking memory from this test. |
| 1465 void DiskCacheBackendTest::BackendInvalidEntryEnumeration() { | 1465 void DiskCacheBackendTest::BackendInvalidEntryEnumeration() { |
| 1466 InitCache(); | 1466 InitCache(); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1478 ASSERT_EQ(net::OK, OpenEntry(key, &entry1)); | 1478 ASSERT_EQ(net::OK, OpenEntry(key, &entry1)); |
| 1479 EXPECT_EQ(kSize, ReadData(entry1, 0, 0, buffer1.get(), kSize)); | 1479 EXPECT_EQ(kSize, ReadData(entry1, 0, 0, buffer1.get(), kSize)); |
| 1480 | 1480 |
| 1481 std::string key2("Another key"); | 1481 std::string key2("Another key"); |
| 1482 ASSERT_EQ(net::OK, CreateEntry(key2, &entry2)); | 1482 ASSERT_EQ(net::OK, CreateEntry(key2, &entry2)); |
| 1483 entry2->Close(); | 1483 entry2->Close(); |
| 1484 ASSERT_EQ(2, cache_->GetEntryCount()); | 1484 ASSERT_EQ(2, cache_->GetEntryCount()); |
| 1485 | 1485 |
| 1486 SimulateCrash(); | 1486 SimulateCrash(); |
| 1487 | 1487 |
| 1488 scoped_ptr<TestIterator> iter = CreateIterator(); | 1488 std::unique_ptr<TestIterator> iter = CreateIterator(); |
| 1489 int count = 0; | 1489 int count = 0; |
| 1490 while (iter->OpenNextEntry(&entry) == net::OK) { | 1490 while (iter->OpenNextEntry(&entry) == net::OK) { |
| 1491 ASSERT_TRUE(NULL != entry); | 1491 ASSERT_TRUE(NULL != entry); |
| 1492 EXPECT_EQ(key2, entry->GetKey()); | 1492 EXPECT_EQ(key2, entry->GetKey()); |
| 1493 entry->Close(); | 1493 entry->Close(); |
| 1494 count++; | 1494 count++; |
| 1495 }; | 1495 }; |
| 1496 EXPECT_EQ(1, count); | 1496 EXPECT_EQ(1, count); |
| 1497 EXPECT_EQ(1, cache_->GetEntryCount()); | 1497 EXPECT_EQ(1, cache_->GetEntryCount()); |
| 1498 } | 1498 } |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1520 const int kNumEntries = 10; | 1520 const int kNumEntries = 10; |
| 1521 for (int i = 0; i < kNumEntries; i++) { | 1521 for (int i = 0; i < kNumEntries; i++) { |
| 1522 std::string key = GenerateKey(true); | 1522 std::string key = GenerateKey(true); |
| 1523 disk_cache::Entry* entry; | 1523 disk_cache::Entry* entry; |
| 1524 ASSERT_EQ(net::OK, CreateEntry(key, &entry)); | 1524 ASSERT_EQ(net::OK, CreateEntry(key, &entry)); |
| 1525 entry->Close(); | 1525 entry->Close(); |
| 1526 } | 1526 } |
| 1527 EXPECT_EQ(kNumEntries, cache_->GetEntryCount()); | 1527 EXPECT_EQ(kNumEntries, cache_->GetEntryCount()); |
| 1528 | 1528 |
| 1529 disk_cache::Entry *entry1, *entry2; | 1529 disk_cache::Entry *entry1, *entry2; |
| 1530 scoped_ptr<TestIterator> iter1 = CreateIterator(), iter2 = CreateIterator(); | 1530 std::unique_ptr<TestIterator> iter1 = CreateIterator(), |
| 1531 iter2 = CreateIterator(); |
| 1531 ASSERT_EQ(net::OK, iter1->OpenNextEntry(&entry1)); | 1532 ASSERT_EQ(net::OK, iter1->OpenNextEntry(&entry1)); |
| 1532 ASSERT_TRUE(NULL != entry1); | 1533 ASSERT_TRUE(NULL != entry1); |
| 1533 entry1->Close(); | 1534 entry1->Close(); |
| 1534 entry1 = NULL; | 1535 entry1 = NULL; |
| 1535 | 1536 |
| 1536 // Let's go to the middle of the list. | 1537 // Let's go to the middle of the list. |
| 1537 for (int i = 0; i < kNumEntries / 2; i++) { | 1538 for (int i = 0; i < kNumEntries / 2; i++) { |
| 1538 if (entry1) | 1539 if (entry1) |
| 1539 entry1->Close(); | 1540 entry1->Close(); |
| 1540 ASSERT_EQ(net::OK, iter1->OpenNextEntry(&entry1)); | 1541 ASSERT_EQ(net::OK, iter1->OpenNextEntry(&entry1)); |
| (...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1963 } | 1964 } |
| 1964 | 1965 |
| 1965 // Tests that the |BackendImpl| fails to start with the wrong cache version. | 1966 // Tests that the |BackendImpl| fails to start with the wrong cache version. |
| 1966 TEST_F(DiskCacheTest, WrongVersion) { | 1967 TEST_F(DiskCacheTest, WrongVersion) { |
| 1967 ASSERT_TRUE(CopyTestCache("wrong_version")); | 1968 ASSERT_TRUE(CopyTestCache("wrong_version")); |
| 1968 base::Thread cache_thread("CacheThread"); | 1969 base::Thread cache_thread("CacheThread"); |
| 1969 ASSERT_TRUE(cache_thread.StartWithOptions( | 1970 ASSERT_TRUE(cache_thread.StartWithOptions( |
| 1970 base::Thread::Options(base::MessageLoop::TYPE_IO, 0))); | 1971 base::Thread::Options(base::MessageLoop::TYPE_IO, 0))); |
| 1971 net::TestCompletionCallback cb; | 1972 net::TestCompletionCallback cb; |
| 1972 | 1973 |
| 1973 scoped_ptr<disk_cache::BackendImpl> cache(new disk_cache::BackendImpl( | 1974 std::unique_ptr<disk_cache::BackendImpl> cache(new disk_cache::BackendImpl( |
| 1974 cache_path_, cache_thread.task_runner(), NULL)); | 1975 cache_path_, cache_thread.task_runner(), NULL)); |
| 1975 int rv = cache->Init(cb.callback()); | 1976 int rv = cache->Init(cb.callback()); |
| 1976 ASSERT_EQ(net::ERR_FAILED, cb.GetResult(rv)); | 1977 ASSERT_EQ(net::ERR_FAILED, cb.GetResult(rv)); |
| 1977 } | 1978 } |
| 1978 | 1979 |
| 1979 // Tests that the disk cache successfully joins the control group, dropping the | 1980 // Tests that the disk cache successfully joins the control group, dropping the |
| 1980 // existing cache in favour of a new empty cache. | 1981 // existing cache in favour of a new empty cache. |
| 1981 // Disabled on android since this test requires cache creator to create | 1982 // Disabled on android since this test requires cache creator to create |
| 1982 // blockfile caches. | 1983 // blockfile caches. |
| 1983 #if !defined(OS_ANDROID) | 1984 #if !defined(OS_ANDROID) |
| 1984 TEST_F(DiskCacheTest, SimpleCacheControlJoin) { | 1985 TEST_F(DiskCacheTest, SimpleCacheControlJoin) { |
| 1985 base::Thread cache_thread("CacheThread"); | 1986 base::Thread cache_thread("CacheThread"); |
| 1986 ASSERT_TRUE(cache_thread.StartWithOptions( | 1987 ASSERT_TRUE(cache_thread.StartWithOptions( |
| 1987 base::Thread::Options(base::MessageLoop::TYPE_IO, 0))); | 1988 base::Thread::Options(base::MessageLoop::TYPE_IO, 0))); |
| 1988 | 1989 |
| 1989 scoped_ptr<disk_cache::BackendImpl> cache = | 1990 std::unique_ptr<disk_cache::BackendImpl> cache = |
| 1990 CreateExistingEntryCache(cache_thread, cache_path_); | 1991 CreateExistingEntryCache(cache_thread, cache_path_); |
| 1991 ASSERT_TRUE(cache.get()); | 1992 ASSERT_TRUE(cache.get()); |
| 1992 cache.reset(); | 1993 cache.reset(); |
| 1993 | 1994 |
| 1994 // Instantiate the SimpleCacheTrial, forcing this run into the | 1995 // Instantiate the SimpleCacheTrial, forcing this run into the |
| 1995 // ExperimentControl group. | 1996 // ExperimentControl group. |
| 1996 base::FieldTrialList field_trial_list(new base::MockEntropyProvider()); | 1997 base::FieldTrialList field_trial_list(new base::MockEntropyProvider()); |
| 1997 base::FieldTrialList::CreateFieldTrial("SimpleCacheTrial", | 1998 base::FieldTrialList::CreateFieldTrial("SimpleCacheTrial", |
| 1998 "ExperimentControl"); | 1999 "ExperimentControl"); |
| 1999 net::TestCompletionCallback cb; | 2000 net::TestCompletionCallback cb; |
| 2000 scoped_ptr<disk_cache::Backend> base_cache; | 2001 std::unique_ptr<disk_cache::Backend> base_cache; |
| 2001 int rv = disk_cache::CreateCacheBackend(net::DISK_CACHE, | 2002 int rv = disk_cache::CreateCacheBackend(net::DISK_CACHE, |
| 2002 net::CACHE_BACKEND_BLOCKFILE, | 2003 net::CACHE_BACKEND_BLOCKFILE, |
| 2003 cache_path_, | 2004 cache_path_, |
| 2004 0, | 2005 0, |
| 2005 true, | 2006 true, |
| 2006 cache_thread.task_runner(), | 2007 cache_thread.task_runner(), |
| 2007 NULL, | 2008 NULL, |
| 2008 &base_cache, | 2009 &base_cache, |
| 2009 cb.callback()); | 2010 cb.callback()); |
| 2010 ASSERT_EQ(net::OK, cb.GetResult(rv)); | 2011 ASSERT_EQ(net::OK, cb.GetResult(rv)); |
| 2011 EXPECT_EQ(0, base_cache->GetEntryCount()); | 2012 EXPECT_EQ(0, base_cache->GetEntryCount()); |
| 2012 } | 2013 } |
| 2013 #endif | 2014 #endif |
| 2014 | 2015 |
| 2015 // Tests that the disk cache can restart in the control group preserving | 2016 // Tests that the disk cache can restart in the control group preserving |
| 2016 // existing entries. | 2017 // existing entries. |
| 2017 TEST_F(DiskCacheTest, SimpleCacheControlRestart) { | 2018 TEST_F(DiskCacheTest, SimpleCacheControlRestart) { |
| 2018 // Instantiate the SimpleCacheTrial, forcing this run into the | 2019 // Instantiate the SimpleCacheTrial, forcing this run into the |
| 2019 // ExperimentControl group. | 2020 // ExperimentControl group. |
| 2020 base::FieldTrialList field_trial_list(new base::MockEntropyProvider()); | 2021 base::FieldTrialList field_trial_list(new base::MockEntropyProvider()); |
| 2021 base::FieldTrialList::CreateFieldTrial("SimpleCacheTrial", | 2022 base::FieldTrialList::CreateFieldTrial("SimpleCacheTrial", |
| 2022 "ExperimentControl"); | 2023 "ExperimentControl"); |
| 2023 | 2024 |
| 2024 base::Thread cache_thread("CacheThread"); | 2025 base::Thread cache_thread("CacheThread"); |
| 2025 ASSERT_TRUE(cache_thread.StartWithOptions( | 2026 ASSERT_TRUE(cache_thread.StartWithOptions( |
| 2026 base::Thread::Options(base::MessageLoop::TYPE_IO, 0))); | 2027 base::Thread::Options(base::MessageLoop::TYPE_IO, 0))); |
| 2027 | 2028 |
| 2028 scoped_ptr<disk_cache::BackendImpl> cache = | 2029 std::unique_ptr<disk_cache::BackendImpl> cache = |
| 2029 CreateExistingEntryCache(cache_thread, cache_path_); | 2030 CreateExistingEntryCache(cache_thread, cache_path_); |
| 2030 ASSERT_TRUE(cache.get()); | 2031 ASSERT_TRUE(cache.get()); |
| 2031 | 2032 |
| 2032 net::TestCompletionCallback cb; | 2033 net::TestCompletionCallback cb; |
| 2033 | 2034 |
| 2034 const int kRestartCount = 5; | 2035 const int kRestartCount = 5; |
| 2035 for (int i = 0; i < kRestartCount; ++i) { | 2036 for (int i = 0; i < kRestartCount; ++i) { |
| 2036 cache.reset(new disk_cache::BackendImpl(cache_path_, | 2037 cache.reset(new disk_cache::BackendImpl(cache_path_, |
| 2037 cache_thread.task_runner(), NULL)); | 2038 cache_thread.task_runner(), NULL)); |
| 2038 int rv = cache->Init(cb.callback()); | 2039 int rv = cache->Init(cb.callback()); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 2054 ASSERT_TRUE(cache_thread.StartWithOptions( | 2055 ASSERT_TRUE(cache_thread.StartWithOptions( |
| 2055 base::Thread::Options(base::MessageLoop::TYPE_IO, 0))); | 2056 base::Thread::Options(base::MessageLoop::TYPE_IO, 0))); |
| 2056 | 2057 |
| 2057 { | 2058 { |
| 2058 // Instantiate the SimpleCacheTrial, forcing this run into the | 2059 // Instantiate the SimpleCacheTrial, forcing this run into the |
| 2059 // ExperimentControl group. | 2060 // ExperimentControl group. |
| 2060 base::FieldTrialList field_trial_list(new base::MockEntropyProvider()); | 2061 base::FieldTrialList field_trial_list(new base::MockEntropyProvider()); |
| 2061 base::FieldTrialList::CreateFieldTrial("SimpleCacheTrial", | 2062 base::FieldTrialList::CreateFieldTrial("SimpleCacheTrial", |
| 2062 "ExperimentControl"); | 2063 "ExperimentControl"); |
| 2063 | 2064 |
| 2064 scoped_ptr<disk_cache::BackendImpl> cache = | 2065 std::unique_ptr<disk_cache::BackendImpl> cache = |
| 2065 CreateExistingEntryCache(cache_thread, cache_path_); | 2066 CreateExistingEntryCache(cache_thread, cache_path_); |
| 2066 ASSERT_TRUE(cache.get()); | 2067 ASSERT_TRUE(cache.get()); |
| 2067 } | 2068 } |
| 2068 | 2069 |
| 2069 // Instantiate the SimpleCacheTrial, forcing this run into the | 2070 // Instantiate the SimpleCacheTrial, forcing this run into the |
| 2070 // ExperimentNo group. | 2071 // ExperimentNo group. |
| 2071 base::FieldTrialList field_trial_list(new base::MockEntropyProvider()); | 2072 base::FieldTrialList field_trial_list(new base::MockEntropyProvider()); |
| 2072 base::FieldTrialList::CreateFieldTrial("SimpleCacheTrial", "ExperimentNo"); | 2073 base::FieldTrialList::CreateFieldTrial("SimpleCacheTrial", "ExperimentNo"); |
| 2073 net::TestCompletionCallback cb; | 2074 net::TestCompletionCallback cb; |
| 2074 | 2075 |
| 2075 const int kRestartCount = 5; | 2076 const int kRestartCount = 5; |
| 2076 for (int i = 0; i < kRestartCount; ++i) { | 2077 for (int i = 0; i < kRestartCount; ++i) { |
| 2077 scoped_ptr<disk_cache::BackendImpl> cache(new disk_cache::BackendImpl( | 2078 std::unique_ptr<disk_cache::BackendImpl> cache(new disk_cache::BackendImpl( |
| 2078 cache_path_, cache_thread.task_runner(), NULL)); | 2079 cache_path_, cache_thread.task_runner(), NULL)); |
| 2079 int rv = cache->Init(cb.callback()); | 2080 int rv = cache->Init(cb.callback()); |
| 2080 ASSERT_EQ(net::OK, cb.GetResult(rv)); | 2081 ASSERT_EQ(net::OK, cb.GetResult(rv)); |
| 2081 EXPECT_EQ(1, cache->GetEntryCount()); | 2082 EXPECT_EQ(1, cache->GetEntryCount()); |
| 2082 | 2083 |
| 2083 disk_cache::Entry* entry = NULL; | 2084 disk_cache::Entry* entry = NULL; |
| 2084 rv = cache->OpenEntry(kExistingEntryKey, &entry, cb.callback()); | 2085 rv = cache->OpenEntry(kExistingEntryKey, &entry, cb.callback()); |
| 2085 ASSERT_EQ(net::OK, cb.GetResult(rv)); | 2086 ASSERT_EQ(net::OK, cb.GetResult(rv)); |
| 2086 EXPECT_NE(nullptr, entry); | 2087 EXPECT_NE(nullptr, entry); |
| 2087 entry->Close(); | 2088 entry->Close(); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2144 } | 2145 } |
| 2145 | 2146 |
| 2146 // Tests that we don't crash or hang when enumerating this cache. | 2147 // Tests that we don't crash or hang when enumerating this cache. |
| 2147 void DiskCacheBackendTest::BackendInvalidEntry3() { | 2148 void DiskCacheBackendTest::BackendInvalidEntry3() { |
| 2148 SetMask(0x1); // 2-entry table. | 2149 SetMask(0x1); // 2-entry table. |
| 2149 SetMaxSize(0x3000); // 12 kB. | 2150 SetMaxSize(0x3000); // 12 kB. |
| 2150 DisableFirstCleanup(); | 2151 DisableFirstCleanup(); |
| 2151 InitCache(); | 2152 InitCache(); |
| 2152 | 2153 |
| 2153 disk_cache::Entry* entry; | 2154 disk_cache::Entry* entry; |
| 2154 scoped_ptr<TestIterator> iter = CreateIterator(); | 2155 std::unique_ptr<TestIterator> iter = CreateIterator(); |
| 2155 while (iter->OpenNextEntry(&entry) == net::OK) { | 2156 while (iter->OpenNextEntry(&entry) == net::OK) { |
| 2156 entry->Close(); | 2157 entry->Close(); |
| 2157 } | 2158 } |
| 2158 } | 2159 } |
| 2159 | 2160 |
| 2160 TEST_F(DiskCacheBackendTest, InvalidEntry3) { | 2161 TEST_F(DiskCacheBackendTest, InvalidEntry3) { |
| 2161 ASSERT_TRUE(CopyTestCache("dirty_entry3")); | 2162 ASSERT_TRUE(CopyTestCache("dirty_entry3")); |
| 2162 BackendInvalidEntry3(); | 2163 BackendInvalidEntry3(); |
| 2163 } | 2164 } |
| 2164 | 2165 |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2289 entry_impl->rankings()->Store(); | 2290 entry_impl->rankings()->Store(); |
| 2290 entry->Close(); | 2291 entry->Close(); |
| 2291 FlushQueueForTest(); | 2292 FlushQueueForTest(); |
| 2292 EXPECT_EQ(2, cache_->GetEntryCount()); | 2293 EXPECT_EQ(2, cache_->GetEntryCount()); |
| 2293 | 2294 |
| 2294 // This should detect the bad entry. | 2295 // This should detect the bad entry. |
| 2295 EXPECT_NE(net::OK, OpenEntry(second, &entry)); | 2296 EXPECT_NE(net::OK, OpenEntry(second, &entry)); |
| 2296 EXPECT_EQ(1, cache_->GetEntryCount()); | 2297 EXPECT_EQ(1, cache_->GetEntryCount()); |
| 2297 | 2298 |
| 2298 // We should delete the cache. The list still has a corrupt node. | 2299 // We should delete the cache. The list still has a corrupt node. |
| 2299 scoped_ptr<TestIterator> iter = CreateIterator(); | 2300 std::unique_ptr<TestIterator> iter = CreateIterator(); |
| 2300 EXPECT_NE(net::OK, iter->OpenNextEntry(&entry)); | 2301 EXPECT_NE(net::OK, iter->OpenNextEntry(&entry)); |
| 2301 FlushQueueForTest(); | 2302 FlushQueueForTest(); |
| 2302 EXPECT_EQ(0, cache_->GetEntryCount()); | 2303 EXPECT_EQ(0, cache_->GetEntryCount()); |
| 2303 } | 2304 } |
| 2304 | 2305 |
| 2305 TEST_F(DiskCacheBackendTest, InvalidEntry7) { | 2306 TEST_F(DiskCacheBackendTest, InvalidEntry7) { |
| 2306 BackendInvalidEntry7(); | 2307 BackendInvalidEntry7(); |
| 2307 } | 2308 } |
| 2308 | 2309 |
| 2309 TEST_F(DiskCacheBackendTest, NewEvictionInvalidEntry7) { | 2310 TEST_F(DiskCacheBackendTest, NewEvictionInvalidEntry7) { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 2333 entry_impl->rankings()->Store(); | 2334 entry_impl->rankings()->Store(); |
| 2334 entry->Close(); | 2335 entry->Close(); |
| 2335 FlushQueueForTest(); | 2336 FlushQueueForTest(); |
| 2336 EXPECT_EQ(2, cache_->GetEntryCount()); | 2337 EXPECT_EQ(2, cache_->GetEntryCount()); |
| 2337 | 2338 |
| 2338 // This should detect the bad entry. | 2339 // This should detect the bad entry. |
| 2339 EXPECT_NE(net::OK, OpenEntry(second, &entry)); | 2340 EXPECT_NE(net::OK, OpenEntry(second, &entry)); |
| 2340 EXPECT_EQ(1, cache_->GetEntryCount()); | 2341 EXPECT_EQ(1, cache_->GetEntryCount()); |
| 2341 | 2342 |
| 2342 // We should not delete the cache. | 2343 // We should not delete the cache. |
| 2343 scoped_ptr<TestIterator> iter = CreateIterator(); | 2344 std::unique_ptr<TestIterator> iter = CreateIterator(); |
| 2344 ASSERT_EQ(net::OK, iter->OpenNextEntry(&entry)); | 2345 ASSERT_EQ(net::OK, iter->OpenNextEntry(&entry)); |
| 2345 entry->Close(); | 2346 entry->Close(); |
| 2346 EXPECT_NE(net::OK, iter->OpenNextEntry(&entry)); | 2347 EXPECT_NE(net::OK, iter->OpenNextEntry(&entry)); |
| 2347 EXPECT_EQ(1, cache_->GetEntryCount()); | 2348 EXPECT_EQ(1, cache_->GetEntryCount()); |
| 2348 } | 2349 } |
| 2349 | 2350 |
| 2350 TEST_F(DiskCacheBackendTest, InvalidEntry8) { | 2351 TEST_F(DiskCacheBackendTest, InvalidEntry8) { |
| 2351 BackendInvalidEntry8(); | 2352 BackendInvalidEntry8(); |
| 2352 } | 2353 } |
| 2353 | 2354 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 2383 EXPECT_EQ(2, cache_->GetEntryCount()); | 2384 EXPECT_EQ(2, cache_->GetEntryCount()); |
| 2384 | 2385 |
| 2385 if (eviction) { | 2386 if (eviction) { |
| 2386 TrimForTest(false); | 2387 TrimForTest(false); |
| 2387 EXPECT_EQ(1, cache_->GetEntryCount()); | 2388 EXPECT_EQ(1, cache_->GetEntryCount()); |
| 2388 TrimForTest(false); | 2389 TrimForTest(false); |
| 2389 EXPECT_EQ(1, cache_->GetEntryCount()); | 2390 EXPECT_EQ(1, cache_->GetEntryCount()); |
| 2390 } else { | 2391 } else { |
| 2391 // We should detect the problem through the list, but we should not delete | 2392 // We should detect the problem through the list, but we should not delete |
| 2392 // the entry, just fail the iteration. | 2393 // the entry, just fail the iteration. |
| 2393 scoped_ptr<TestIterator> iter = CreateIterator(); | 2394 std::unique_ptr<TestIterator> iter = CreateIterator(); |
| 2394 EXPECT_NE(net::OK, iter->OpenNextEntry(&entry)); | 2395 EXPECT_NE(net::OK, iter->OpenNextEntry(&entry)); |
| 2395 | 2396 |
| 2396 // Now a full iteration will work, and return one entry. | 2397 // Now a full iteration will work, and return one entry. |
| 2397 ASSERT_EQ(net::OK, iter->OpenNextEntry(&entry)); | 2398 ASSERT_EQ(net::OK, iter->OpenNextEntry(&entry)); |
| 2398 entry->Close(); | 2399 entry->Close(); |
| 2399 EXPECT_NE(net::OK, iter->OpenNextEntry(&entry)); | 2400 EXPECT_NE(net::OK, iter->OpenNextEntry(&entry)); |
| 2400 | 2401 |
| 2401 // This should detect what's left of the bad entry. | 2402 // This should detect what's left of the bad entry. |
| 2402 EXPECT_NE(net::OK, OpenEntry(second, &entry)); | 2403 EXPECT_NE(net::OK, OpenEntry(second, &entry)); |
| 2403 EXPECT_EQ(2, cache_->GetEntryCount()); | 2404 EXPECT_EQ(2, cache_->GetEntryCount()); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2460 TrimForTest(false); | 2461 TrimForTest(false); |
| 2461 EXPECT_EQ(3, cache_->GetEntryCount()); | 2462 EXPECT_EQ(3, cache_->GetEntryCount()); |
| 2462 TrimForTest(false); | 2463 TrimForTest(false); |
| 2463 EXPECT_EQ(2, cache_->GetEntryCount()); | 2464 EXPECT_EQ(2, cache_->GetEntryCount()); |
| 2464 TrimForTest(false); | 2465 TrimForTest(false); |
| 2465 EXPECT_EQ(1, cache_->GetEntryCount()); | 2466 EXPECT_EQ(1, cache_->GetEntryCount()); |
| 2466 } else { | 2467 } else { |
| 2467 // Detection order: third -> second -> first. | 2468 // Detection order: third -> second -> first. |
| 2468 // We should detect the problem through the list, but we should not delete | 2469 // We should detect the problem through the list, but we should not delete |
| 2469 // the entry. | 2470 // the entry. |
| 2470 scoped_ptr<TestIterator> iter = CreateIterator(); | 2471 std::unique_ptr<TestIterator> iter = CreateIterator(); |
| 2471 ASSERT_EQ(net::OK, iter->OpenNextEntry(&entry)); | 2472 ASSERT_EQ(net::OK, iter->OpenNextEntry(&entry)); |
| 2472 entry->Close(); | 2473 entry->Close(); |
| 2473 ASSERT_EQ(net::OK, iter->OpenNextEntry(&entry)); | 2474 ASSERT_EQ(net::OK, iter->OpenNextEntry(&entry)); |
| 2474 EXPECT_EQ(first, entry->GetKey()); | 2475 EXPECT_EQ(first, entry->GetKey()); |
| 2475 entry->Close(); | 2476 entry->Close(); |
| 2476 EXPECT_NE(net::OK, iter->OpenNextEntry(&entry)); | 2477 EXPECT_NE(net::OK, iter->OpenNextEntry(&entry)); |
| 2477 } | 2478 } |
| 2478 DisableIntegrityCheck(); | 2479 DisableIntegrityCheck(); |
| 2479 } | 2480 } |
| 2480 | 2481 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2527 TrimForTest(false); | 2528 TrimForTest(false); |
| 2528 EXPECT_EQ(2, cache_->GetEntryCount()); | 2529 EXPECT_EQ(2, cache_->GetEntryCount()); |
| 2529 TrimForTest(false); | 2530 TrimForTest(false); |
| 2530 EXPECT_EQ(1, cache_->GetEntryCount()); | 2531 EXPECT_EQ(1, cache_->GetEntryCount()); |
| 2531 TrimForTest(false); | 2532 TrimForTest(false); |
| 2532 EXPECT_EQ(1, cache_->GetEntryCount()); | 2533 EXPECT_EQ(1, cache_->GetEntryCount()); |
| 2533 } else { | 2534 } else { |
| 2534 // Detection order: third -> second. | 2535 // Detection order: third -> second. |
| 2535 // We should detect the problem through the list, but we should not delete | 2536 // We should detect the problem through the list, but we should not delete |
| 2536 // the entry, just fail the iteration. | 2537 // the entry, just fail the iteration. |
| 2537 scoped_ptr<TestIterator> iter = CreateIterator(); | 2538 std::unique_ptr<TestIterator> iter = CreateIterator(); |
| 2538 ASSERT_EQ(net::OK, iter->OpenNextEntry(&entry)); | 2539 ASSERT_EQ(net::OK, iter->OpenNextEntry(&entry)); |
| 2539 entry->Close(); | 2540 entry->Close(); |
| 2540 EXPECT_NE(net::OK, iter->OpenNextEntry(&entry)); | 2541 EXPECT_NE(net::OK, iter->OpenNextEntry(&entry)); |
| 2541 | 2542 |
| 2542 // Now a full iteration will work, and return two entries. | 2543 // Now a full iteration will work, and return two entries. |
| 2543 ASSERT_EQ(net::OK, iter->OpenNextEntry(&entry)); | 2544 ASSERT_EQ(net::OK, iter->OpenNextEntry(&entry)); |
| 2544 entry->Close(); | 2545 entry->Close(); |
| 2545 ASSERT_EQ(net::OK, iter->OpenNextEntry(&entry)); | 2546 ASSERT_EQ(net::OK, iter->OpenNextEntry(&entry)); |
| 2546 entry->Close(); | 2547 entry->Close(); |
| 2547 EXPECT_NE(net::OK, iter->OpenNextEntry(&entry)); | 2548 EXPECT_NE(net::OK, iter->OpenNextEntry(&entry)); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2615 } | 2616 } |
| 2616 | 2617 |
| 2617 TEST_F(DiskCacheBackendTest, NewEvictionInvalidRankings2) { | 2618 TEST_F(DiskCacheBackendTest, NewEvictionInvalidRankings2) { |
| 2618 SetNewEviction(); | 2619 SetNewEviction(); |
| 2619 BackendInvalidRankings2(); | 2620 BackendInvalidRankings2(); |
| 2620 } | 2621 } |
| 2621 | 2622 |
| 2622 // If the LRU is corrupt, we delete the cache. | 2623 // If the LRU is corrupt, we delete the cache. |
| 2623 void DiskCacheBackendTest::BackendInvalidRankings() { | 2624 void DiskCacheBackendTest::BackendInvalidRankings() { |
| 2624 disk_cache::Entry* entry; | 2625 disk_cache::Entry* entry; |
| 2625 scoped_ptr<TestIterator> iter = CreateIterator(); | 2626 std::unique_ptr<TestIterator> iter = CreateIterator(); |
| 2626 ASSERT_EQ(net::OK, iter->OpenNextEntry(&entry)); | 2627 ASSERT_EQ(net::OK, iter->OpenNextEntry(&entry)); |
| 2627 entry->Close(); | 2628 entry->Close(); |
| 2628 EXPECT_EQ(2, cache_->GetEntryCount()); | 2629 EXPECT_EQ(2, cache_->GetEntryCount()); |
| 2629 | 2630 |
| 2630 EXPECT_NE(net::OK, iter->OpenNextEntry(&entry)); | 2631 EXPECT_NE(net::OK, iter->OpenNextEntry(&entry)); |
| 2631 FlushQueueForTest(); // Allow the restart to finish. | 2632 FlushQueueForTest(); // Allow the restart to finish. |
| 2632 EXPECT_EQ(0, cache_->GetEntryCount()); | 2633 EXPECT_EQ(0, cache_->GetEntryCount()); |
| 2633 } | 2634 } |
| 2634 | 2635 |
| 2635 TEST_F(DiskCacheBackendTest, InvalidRankingsSuccess) { | 2636 TEST_F(DiskCacheBackendTest, InvalidRankingsSuccess) { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 2660 DisableFirstCleanup(); | 2661 DisableFirstCleanup(); |
| 2661 SetNewEviction(); | 2662 SetNewEviction(); |
| 2662 InitCache(); | 2663 InitCache(); |
| 2663 SetTestMode(); // Fail cache reinitialization. | 2664 SetTestMode(); // Fail cache reinitialization. |
| 2664 BackendInvalidRankings(); | 2665 BackendInvalidRankings(); |
| 2665 } | 2666 } |
| 2666 | 2667 |
| 2667 // If the LRU is corrupt and we have open entries, we disable the cache. | 2668 // If the LRU is corrupt and we have open entries, we disable the cache. |
| 2668 void DiskCacheBackendTest::BackendDisable() { | 2669 void DiskCacheBackendTest::BackendDisable() { |
| 2669 disk_cache::Entry *entry1, *entry2; | 2670 disk_cache::Entry *entry1, *entry2; |
| 2670 scoped_ptr<TestIterator> iter = CreateIterator(); | 2671 std::unique_ptr<TestIterator> iter = CreateIterator(); |
| 2671 ASSERT_EQ(net::OK, iter->OpenNextEntry(&entry1)); | 2672 ASSERT_EQ(net::OK, iter->OpenNextEntry(&entry1)); |
| 2672 | 2673 |
| 2673 EXPECT_NE(net::OK, iter->OpenNextEntry(&entry2)); | 2674 EXPECT_NE(net::OK, iter->OpenNextEntry(&entry2)); |
| 2674 EXPECT_EQ(0, cache_->GetEntryCount()); | 2675 EXPECT_EQ(0, cache_->GetEntryCount()); |
| 2675 EXPECT_NE(net::OK, CreateEntry("Something new", &entry2)); | 2676 EXPECT_NE(net::OK, CreateEntry("Something new", &entry2)); |
| 2676 | 2677 |
| 2677 entry1->Close(); | 2678 entry1->Close(); |
| 2678 FlushQueueForTest(); // Flushing the Close posts a task to restart the cache. | 2679 FlushQueueForTest(); // Flushing the Close posts a task to restart the cache. |
| 2679 FlushQueueForTest(); // This one actually allows that task to complete. | 2680 FlushQueueForTest(); // This one actually allows that task to complete. |
| 2680 | 2681 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 2711 InitCache(); | 2712 InitCache(); |
| 2712 SetTestMode(); // Fail cache reinitialization. | 2713 SetTestMode(); // Fail cache reinitialization. |
| 2713 BackendDisable(); | 2714 BackendDisable(); |
| 2714 } | 2715 } |
| 2715 | 2716 |
| 2716 // This is another type of corruption on the LRU; disable the cache. | 2717 // This is another type of corruption on the LRU; disable the cache. |
| 2717 void DiskCacheBackendTest::BackendDisable2() { | 2718 void DiskCacheBackendTest::BackendDisable2() { |
| 2718 EXPECT_EQ(8, cache_->GetEntryCount()); | 2719 EXPECT_EQ(8, cache_->GetEntryCount()); |
| 2719 | 2720 |
| 2720 disk_cache::Entry* entry; | 2721 disk_cache::Entry* entry; |
| 2721 scoped_ptr<TestIterator> iter = CreateIterator(); | 2722 std::unique_ptr<TestIterator> iter = CreateIterator(); |
| 2722 int count = 0; | 2723 int count = 0; |
| 2723 while (iter->OpenNextEntry(&entry) == net::OK) { | 2724 while (iter->OpenNextEntry(&entry) == net::OK) { |
| 2724 ASSERT_TRUE(NULL != entry); | 2725 ASSERT_TRUE(NULL != entry); |
| 2725 entry->Close(); | 2726 entry->Close(); |
| 2726 count++; | 2727 count++; |
| 2727 ASSERT_LT(count, 9); | 2728 ASSERT_LT(count, 9); |
| 2728 }; | 2729 }; |
| 2729 | 2730 |
| 2730 FlushQueueForTest(); | 2731 FlushQueueForTest(); |
| 2731 EXPECT_EQ(0, cache_->GetEntryCount()); | 2732 EXPECT_EQ(0, cache_->GetEntryCount()); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 2759 DisableFirstCleanup(); | 2760 DisableFirstCleanup(); |
| 2760 SetNewEviction(); | 2761 SetNewEviction(); |
| 2761 InitCache(); | 2762 InitCache(); |
| 2762 SetTestMode(); // Fail cache reinitialization. | 2763 SetTestMode(); // Fail cache reinitialization. |
| 2763 BackendDisable2(); | 2764 BackendDisable2(); |
| 2764 } | 2765 } |
| 2765 | 2766 |
| 2766 // If the index size changes when we disable the cache, we should not crash. | 2767 // If the index size changes when we disable the cache, we should not crash. |
| 2767 void DiskCacheBackendTest::BackendDisable3() { | 2768 void DiskCacheBackendTest::BackendDisable3() { |
| 2768 disk_cache::Entry *entry1, *entry2; | 2769 disk_cache::Entry *entry1, *entry2; |
| 2769 scoped_ptr<TestIterator> iter = CreateIterator(); | 2770 std::unique_ptr<TestIterator> iter = CreateIterator(); |
| 2770 EXPECT_EQ(2, cache_->GetEntryCount()); | 2771 EXPECT_EQ(2, cache_->GetEntryCount()); |
| 2771 ASSERT_EQ(net::OK, iter->OpenNextEntry(&entry1)); | 2772 ASSERT_EQ(net::OK, iter->OpenNextEntry(&entry1)); |
| 2772 entry1->Close(); | 2773 entry1->Close(); |
| 2773 | 2774 |
| 2774 EXPECT_NE(net::OK, iter->OpenNextEntry(&entry2)); | 2775 EXPECT_NE(net::OK, iter->OpenNextEntry(&entry2)); |
| 2775 FlushQueueForTest(); | 2776 FlushQueueForTest(); |
| 2776 | 2777 |
| 2777 ASSERT_EQ(net::OK, CreateEntry("Something new", &entry2)); | 2778 ASSERT_EQ(net::OK, CreateEntry("Something new", &entry2)); |
| 2778 entry2->Close(); | 2779 entry2->Close(); |
| 2779 | 2780 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 2793 DisableFirstCleanup(); | 2794 DisableFirstCleanup(); |
| 2794 SetMaxSize(20 * 1024 * 1024); | 2795 SetMaxSize(20 * 1024 * 1024); |
| 2795 SetNewEviction(); | 2796 SetNewEviction(); |
| 2796 InitCache(); | 2797 InitCache(); |
| 2797 BackendDisable3(); | 2798 BackendDisable3(); |
| 2798 } | 2799 } |
| 2799 | 2800 |
| 2800 // If we disable the cache, already open entries should work as far as possible. | 2801 // If we disable the cache, already open entries should work as far as possible. |
| 2801 void DiskCacheBackendTest::BackendDisable4() { | 2802 void DiskCacheBackendTest::BackendDisable4() { |
| 2802 disk_cache::Entry *entry1, *entry2, *entry3, *entry4; | 2803 disk_cache::Entry *entry1, *entry2, *entry3, *entry4; |
| 2803 scoped_ptr<TestIterator> iter = CreateIterator(); | 2804 std::unique_ptr<TestIterator> iter = CreateIterator(); |
| 2804 ASSERT_EQ(net::OK, iter->OpenNextEntry(&entry1)); | 2805 ASSERT_EQ(net::OK, iter->OpenNextEntry(&entry1)); |
| 2805 | 2806 |
| 2806 char key2[2000]; | 2807 char key2[2000]; |
| 2807 char key3[20000]; | 2808 char key3[20000]; |
| 2808 CacheTestFillBuffer(key2, sizeof(key2), true); | 2809 CacheTestFillBuffer(key2, sizeof(key2), true); |
| 2809 CacheTestFillBuffer(key3, sizeof(key3), true); | 2810 CacheTestFillBuffer(key3, sizeof(key3), true); |
| 2810 key2[sizeof(key2) - 1] = '\0'; | 2811 key2[sizeof(key2) - 1] = '\0'; |
| 2811 key3[sizeof(key3) - 1] = '\0'; | 2812 key3[sizeof(key3) - 1] = '\0'; |
| 2812 ASSERT_EQ(net::OK, CreateEntry(key2, &entry2)); | 2813 ASSERT_EQ(net::OK, CreateEntry(key2, &entry2)); |
| 2813 ASSERT_EQ(net::OK, CreateEntry(key3, &entry3)); | 2814 ASSERT_EQ(net::OK, CreateEntry(key3, &entry3)); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2859 SetNewEviction(); | 2860 SetNewEviction(); |
| 2860 InitCache(); | 2861 InitCache(); |
| 2861 BackendDisable4(); | 2862 BackendDisable4(); |
| 2862 } | 2863 } |
| 2863 | 2864 |
| 2864 // Tests the exposed API with a disabled cache. | 2865 // Tests the exposed API with a disabled cache. |
| 2865 void DiskCacheBackendTest::BackendDisabledAPI() { | 2866 void DiskCacheBackendTest::BackendDisabledAPI() { |
| 2866 cache_impl_->SetUnitTestMode(); // Simulate failure restarting the cache. | 2867 cache_impl_->SetUnitTestMode(); // Simulate failure restarting the cache. |
| 2867 | 2868 |
| 2868 disk_cache::Entry* entry1, *entry2; | 2869 disk_cache::Entry* entry1, *entry2; |
| 2869 scoped_ptr<TestIterator> iter = CreateIterator(); | 2870 std::unique_ptr<TestIterator> iter = CreateIterator(); |
| 2870 EXPECT_EQ(2, cache_->GetEntryCount()); | 2871 EXPECT_EQ(2, cache_->GetEntryCount()); |
| 2871 ASSERT_EQ(net::OK, iter->OpenNextEntry(&entry1)); | 2872 ASSERT_EQ(net::OK, iter->OpenNextEntry(&entry1)); |
| 2872 entry1->Close(); | 2873 entry1->Close(); |
| 2873 EXPECT_NE(net::OK, iter->OpenNextEntry(&entry2)); | 2874 EXPECT_NE(net::OK, iter->OpenNextEntry(&entry2)); |
| 2874 FlushQueueForTest(); | 2875 FlushQueueForTest(); |
| 2875 // The cache should be disabled. | 2876 // The cache should be disabled. |
| 2876 | 2877 |
| 2877 EXPECT_EQ(net::DISK_CACHE, cache_->GetCacheType()); | 2878 EXPECT_EQ(net::DISK_CACHE, cache_->GetCacheType()); |
| 2878 EXPECT_EQ(0, cache_->GetEntryCount()); | 2879 EXPECT_EQ(0, cache_->GetEntryCount()); |
| 2879 EXPECT_NE(net::OK, OpenEntry("First", &entry2)); | 2880 EXPECT_NE(net::OK, OpenEntry("First", &entry2)); |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2984 | 2985 |
| 2985 // Writing this sparse data should not crash. | 2986 // Writing this sparse data should not crash. |
| 2986 EXPECT_EQ(1024, first_parent->WriteSparseData(32768, buffer.get(), 1024, | 2987 EXPECT_EQ(1024, first_parent->WriteSparseData(32768, buffer.get(), 1024, |
| 2987 net::CompletionCallback())); | 2988 net::CompletionCallback())); |
| 2988 } | 2989 } |
| 2989 | 2990 |
| 2990 TEST_F(DiskCacheTest, Backend_UsageStatsTimer) { | 2991 TEST_F(DiskCacheTest, Backend_UsageStatsTimer) { |
| 2991 MessageLoopHelper helper; | 2992 MessageLoopHelper helper; |
| 2992 | 2993 |
| 2993 ASSERT_TRUE(CleanupCacheDir()); | 2994 ASSERT_TRUE(CleanupCacheDir()); |
| 2994 scoped_ptr<disk_cache::BackendImpl> cache; | 2995 std::unique_ptr<disk_cache::BackendImpl> cache; |
| 2995 cache.reset(new disk_cache::BackendImpl( | 2996 cache.reset(new disk_cache::BackendImpl( |
| 2996 cache_path_, base::ThreadTaskRunnerHandle::Get(), NULL)); | 2997 cache_path_, base::ThreadTaskRunnerHandle::Get(), NULL)); |
| 2997 ASSERT_TRUE(NULL != cache.get()); | 2998 ASSERT_TRUE(NULL != cache.get()); |
| 2998 cache->SetUnitTestMode(); | 2999 cache->SetUnitTestMode(); |
| 2999 ASSERT_EQ(net::OK, cache->SyncInit()); | 3000 ASSERT_EQ(net::OK, cache->SyncInit()); |
| 3000 | 3001 |
| 3001 // Wait for a callback that never comes... about 2 secs :). The message loop | 3002 // Wait for a callback that never comes... about 2 secs :). The message loop |
| 3002 // has to run to allow invocation of the usage timer. | 3003 // has to run to allow invocation of the usage timer. |
| 3003 helper.WaitUntilCacheIoFinished(1); | 3004 helper.WaitUntilCacheIoFinished(1); |
| 3004 } | 3005 } |
| 3005 | 3006 |
| 3006 TEST_F(DiskCacheBackendTest, TimerNotCreated) { | 3007 TEST_F(DiskCacheBackendTest, TimerNotCreated) { |
| 3007 ASSERT_TRUE(CopyTestCache("wrong_version")); | 3008 ASSERT_TRUE(CopyTestCache("wrong_version")); |
| 3008 | 3009 |
| 3009 scoped_ptr<disk_cache::BackendImpl> cache; | 3010 std::unique_ptr<disk_cache::BackendImpl> cache; |
| 3010 cache.reset(new disk_cache::BackendImpl( | 3011 cache.reset(new disk_cache::BackendImpl( |
| 3011 cache_path_, base::ThreadTaskRunnerHandle::Get(), NULL)); | 3012 cache_path_, base::ThreadTaskRunnerHandle::Get(), NULL)); |
| 3012 ASSERT_TRUE(NULL != cache.get()); | 3013 ASSERT_TRUE(NULL != cache.get()); |
| 3013 cache->SetUnitTestMode(); | 3014 cache->SetUnitTestMode(); |
| 3014 ASSERT_NE(net::OK, cache->SyncInit()); | 3015 ASSERT_NE(net::OK, cache->SyncInit()); |
| 3015 | 3016 |
| 3016 ASSERT_TRUE(NULL == cache->GetTimerForTest()); | 3017 ASSERT_TRUE(NULL == cache->GetTimerForTest()); |
| 3017 | 3018 |
| 3018 DisableIntegrityCheck(); | 3019 DisableIntegrityCheck(); |
| 3019 } | 3020 } |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3151 base::ScopedTempDir store1, store2; | 3152 base::ScopedTempDir store1, store2; |
| 3152 ASSERT_TRUE(store1.CreateUniqueTempDir()); | 3153 ASSERT_TRUE(store1.CreateUniqueTempDir()); |
| 3153 ASSERT_TRUE(store2.CreateUniqueTempDir()); | 3154 ASSERT_TRUE(store2.CreateUniqueTempDir()); |
| 3154 | 3155 |
| 3155 base::Thread cache_thread("CacheThread"); | 3156 base::Thread cache_thread("CacheThread"); |
| 3156 ASSERT_TRUE(cache_thread.StartWithOptions( | 3157 ASSERT_TRUE(cache_thread.StartWithOptions( |
| 3157 base::Thread::Options(base::MessageLoop::TYPE_IO, 0))); | 3158 base::Thread::Options(base::MessageLoop::TYPE_IO, 0))); |
| 3158 net::TestCompletionCallback cb; | 3159 net::TestCompletionCallback cb; |
| 3159 | 3160 |
| 3160 const int kNumberOfCaches = 2; | 3161 const int kNumberOfCaches = 2; |
| 3161 scoped_ptr<disk_cache::Backend> cache[kNumberOfCaches]; | 3162 std::unique_ptr<disk_cache::Backend> cache[kNumberOfCaches]; |
| 3162 | 3163 |
| 3163 int rv = disk_cache::CreateCacheBackend(net::DISK_CACHE, | 3164 int rv = disk_cache::CreateCacheBackend(net::DISK_CACHE, |
| 3164 net::CACHE_BACKEND_DEFAULT, | 3165 net::CACHE_BACKEND_DEFAULT, |
| 3165 store1.path(), | 3166 store1.path(), |
| 3166 0, | 3167 0, |
| 3167 false, | 3168 false, |
| 3168 cache_thread.task_runner(), | 3169 cache_thread.task_runner(), |
| 3169 NULL, | 3170 NULL, |
| 3170 &cache[0], | 3171 &cache[0], |
| 3171 cb.callback()); | 3172 cb.callback()); |
| (...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3618 // Tests basic functionality of the SimpleBackend implementation of the | 3619 // Tests basic functionality of the SimpleBackend implementation of the |
| 3619 // enumeration API. | 3620 // enumeration API. |
| 3620 TEST_F(DiskCacheBackendTest, SimpleCacheEnumerationBasics) { | 3621 TEST_F(DiskCacheBackendTest, SimpleCacheEnumerationBasics) { |
| 3621 SetSimpleCacheMode(); | 3622 SetSimpleCacheMode(); |
| 3622 InitCache(); | 3623 InitCache(); |
| 3623 std::set<std::string> key_pool; | 3624 std::set<std::string> key_pool; |
| 3624 ASSERT_TRUE(CreateSetOfRandomEntries(&key_pool)); | 3625 ASSERT_TRUE(CreateSetOfRandomEntries(&key_pool)); |
| 3625 | 3626 |
| 3626 // Check that enumeration returns all entries. | 3627 // Check that enumeration returns all entries. |
| 3627 std::set<std::string> keys_to_match(key_pool); | 3628 std::set<std::string> keys_to_match(key_pool); |
| 3628 scoped_ptr<TestIterator> iter = CreateIterator(); | 3629 std::unique_ptr<TestIterator> iter = CreateIterator(); |
| 3629 size_t count = 0; | 3630 size_t count = 0; |
| 3630 ASSERT_TRUE(EnumerateAndMatchKeys(-1, iter.get(), &keys_to_match, &count)); | 3631 ASSERT_TRUE(EnumerateAndMatchKeys(-1, iter.get(), &keys_to_match, &count)); |
| 3631 iter.reset(); | 3632 iter.reset(); |
| 3632 EXPECT_EQ(key_pool.size(), count); | 3633 EXPECT_EQ(key_pool.size(), count); |
| 3633 EXPECT_TRUE(keys_to_match.empty()); | 3634 EXPECT_TRUE(keys_to_match.empty()); |
| 3634 | 3635 |
| 3635 // Check that opening entries does not affect enumeration. | 3636 // Check that opening entries does not affect enumeration. |
| 3636 keys_to_match = key_pool; | 3637 keys_to_match = key_pool; |
| 3637 iter = CreateIterator(); | 3638 iter = CreateIterator(); |
| 3638 count = 0; | 3639 count = 0; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 3658 // Tests that the enumerations are not affected by dooming an entry in the | 3659 // Tests that the enumerations are not affected by dooming an entry in the |
| 3659 // middle. | 3660 // middle. |
| 3660 TEST_F(DiskCacheBackendTest, SimpleCacheEnumerationWhileDoomed) { | 3661 TEST_F(DiskCacheBackendTest, SimpleCacheEnumerationWhileDoomed) { |
| 3661 SetSimpleCacheMode(); | 3662 SetSimpleCacheMode(); |
| 3662 InitCache(); | 3663 InitCache(); |
| 3663 std::set<std::string> key_pool; | 3664 std::set<std::string> key_pool; |
| 3664 ASSERT_TRUE(CreateSetOfRandomEntries(&key_pool)); | 3665 ASSERT_TRUE(CreateSetOfRandomEntries(&key_pool)); |
| 3665 | 3666 |
| 3666 // Check that enumeration returns all entries but the doomed one. | 3667 // Check that enumeration returns all entries but the doomed one. |
| 3667 std::set<std::string> keys_to_match(key_pool); | 3668 std::set<std::string> keys_to_match(key_pool); |
| 3668 scoped_ptr<TestIterator> iter = CreateIterator(); | 3669 std::unique_ptr<TestIterator> iter = CreateIterator(); |
| 3669 size_t count = 0; | 3670 size_t count = 0; |
| 3670 ASSERT_TRUE(EnumerateAndMatchKeys(key_pool.size()/2, | 3671 ASSERT_TRUE(EnumerateAndMatchKeys(key_pool.size()/2, |
| 3671 iter.get(), | 3672 iter.get(), |
| 3672 &keys_to_match, | 3673 &keys_to_match, |
| 3673 &count)); | 3674 &count)); |
| 3674 | 3675 |
| 3675 std::string key_to_delete = *(keys_to_match.begin()); | 3676 std::string key_to_delete = *(keys_to_match.begin()); |
| 3676 DoomEntry(key_to_delete); | 3677 DoomEntry(key_to_delete); |
| 3677 keys_to_match.erase(key_to_delete); | 3678 keys_to_match.erase(key_to_delete); |
| 3678 key_pool.erase(key_to_delete); | 3679 key_pool.erase(key_to_delete); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 3705 WriteData(corrupted_entry, 0, 0, buffer.get(), kSize, false)); | 3706 WriteData(corrupted_entry, 0, 0, buffer.get(), kSize, false)); |
| 3706 ASSERT_EQ(kSize, ReadData(corrupted_entry, 0, 0, buffer.get(), kSize)); | 3707 ASSERT_EQ(kSize, ReadData(corrupted_entry, 0, 0, buffer.get(), kSize)); |
| 3707 corrupted_entry->Close(); | 3708 corrupted_entry->Close(); |
| 3708 | 3709 |
| 3709 EXPECT_TRUE(disk_cache::simple_util::CreateCorruptFileForTests( | 3710 EXPECT_TRUE(disk_cache::simple_util::CreateCorruptFileForTests( |
| 3710 key, cache_path_)); | 3711 key, cache_path_)); |
| 3711 EXPECT_EQ(key_pool.size() + 1, static_cast<size_t>(cache_->GetEntryCount())); | 3712 EXPECT_EQ(key_pool.size() + 1, static_cast<size_t>(cache_->GetEntryCount())); |
| 3712 | 3713 |
| 3713 // Check that enumeration returns all entries but the corrupt one. | 3714 // Check that enumeration returns all entries but the corrupt one. |
| 3714 std::set<std::string> keys_to_match(key_pool); | 3715 std::set<std::string> keys_to_match(key_pool); |
| 3715 scoped_ptr<TestIterator> iter = CreateIterator(); | 3716 std::unique_ptr<TestIterator> iter = CreateIterator(); |
| 3716 size_t count = 0; | 3717 size_t count = 0; |
| 3717 ASSERT_TRUE(EnumerateAndMatchKeys(-1, iter.get(), &keys_to_match, &count)); | 3718 ASSERT_TRUE(EnumerateAndMatchKeys(-1, iter.get(), &keys_to_match, &count)); |
| 3718 iter.reset(); | 3719 iter.reset(); |
| 3719 | 3720 |
| 3720 EXPECT_EQ(key_pool.size(), count); | 3721 EXPECT_EQ(key_pool.size(), count); |
| 3721 EXPECT_TRUE(keys_to_match.empty()); | 3722 EXPECT_TRUE(keys_to_match.empty()); |
| 3722 } | 3723 } |
| 3723 | 3724 |
| 3724 // Tests that enumerations don't leak memory when the backend is destructed | 3725 // Tests that enumerations don't leak memory when the backend is destructed |
| 3725 // mid-enumeration. | 3726 // mid-enumeration. |
| 3726 TEST_F(DiskCacheBackendTest, SimpleCacheEnumerationDestruction) { | 3727 TEST_F(DiskCacheBackendTest, SimpleCacheEnumerationDestruction) { |
| 3727 SetSimpleCacheMode(); | 3728 SetSimpleCacheMode(); |
| 3728 InitCache(); | 3729 InitCache(); |
| 3729 std::set<std::string> key_pool; | 3730 std::set<std::string> key_pool; |
| 3730 ASSERT_TRUE(CreateSetOfRandomEntries(&key_pool)); | 3731 ASSERT_TRUE(CreateSetOfRandomEntries(&key_pool)); |
| 3731 | 3732 |
| 3732 scoped_ptr<TestIterator> iter = CreateIterator(); | 3733 std::unique_ptr<TestIterator> iter = CreateIterator(); |
| 3733 disk_cache::Entry* entry = NULL; | 3734 disk_cache::Entry* entry = NULL; |
| 3734 ASSERT_EQ(net::OK, iter->OpenNextEntry(&entry)); | 3735 ASSERT_EQ(net::OK, iter->OpenNextEntry(&entry)); |
| 3735 EXPECT_TRUE(entry); | 3736 EXPECT_TRUE(entry); |
| 3736 disk_cache::ScopedEntryPtr entry_closer(entry); | 3737 disk_cache::ScopedEntryPtr entry_closer(entry); |
| 3737 | 3738 |
| 3738 cache_.reset(); | 3739 cache_.reset(); |
| 3739 // This test passes if we don't leak memory. | 3740 // This test passes if we don't leak memory. |
| 3740 } | 3741 } |
| 3741 | 3742 |
| 3742 // Tests that a SimpleCache doesn't crash when files are deleted very quickly | 3743 // Tests that a SimpleCache doesn't crash when files are deleted very quickly |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3775 // because that would advance the cache directory mtime and invalidate the | 3776 // because that would advance the cache directory mtime and invalidate the |
| 3776 // index. | 3777 // index. |
| 3777 entry2->Doom(); | 3778 entry2->Doom(); |
| 3778 entry2->Close(); | 3779 entry2->Close(); |
| 3779 | 3780 |
| 3780 DisableFirstCleanup(); | 3781 DisableFirstCleanup(); |
| 3781 InitCache(); | 3782 InitCache(); |
| 3782 EXPECT_EQ(disk_cache::SimpleIndex::INITIALIZE_METHOD_LOADED, | 3783 EXPECT_EQ(disk_cache::SimpleIndex::INITIALIZE_METHOD_LOADED, |
| 3783 simple_cache_impl_->index()->init_method()); | 3784 simple_cache_impl_->index()->init_method()); |
| 3784 } | 3785 } |
| OLD | NEW |