Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(79)

Side by Side Diff: net/disk_cache/backend_unittest.cc

Issue 49027: Disk cache: First pass to make it possible to have... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/disk_cache/backend_impl.cc ('k') | net/disk_cache/disk_cache.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 "net/base/io_buffer.h" 10 #include "net/base/io_buffer.h"
(...skipping 25 matching lines...) Expand all
36 36
37 // Verifies that we can recover a transaction (insert or remove on the rankings 37 // Verifies that we can recover a transaction (insert or remove on the rankings
38 // list) that is interrupted. 38 // list) that is interrupted.
39 int TestTransaction(const std::wstring& name, int num_entries, bool load) { 39 int TestTransaction(const std::wstring& name, int num_entries, bool load) {
40 if (!CopyTestCache(name)) 40 if (!CopyTestCache(name))
41 return 1; 41 return 1;
42 std::wstring path = GetCachePath(); 42 std::wstring path = GetCachePath();
43 scoped_ptr<disk_cache::Backend> cache; 43 scoped_ptr<disk_cache::Backend> cache;
44 44
45 if (!load) { 45 if (!load) {
46 cache.reset(disk_cache::CreateCacheBackend(path, false, 0)); 46 cache.reset(disk_cache::CreateCacheBackend(path, false, 0,
47 net::DISK_CACHE));
47 } else { 48 } else {
48 disk_cache::BackendImpl* cache2 = new disk_cache::BackendImpl(path, 0xf); 49 disk_cache::BackendImpl* cache2 = new disk_cache::BackendImpl(path, 0xf);
49 if (!cache2 || !cache2->SetMaxSize(0x100000) || !cache2->Init()) 50 if (!cache2 || !cache2->SetMaxSize(0x100000) || !cache2->Init())
50 return 2; 51 return 2;
51 cache.reset(cache2); 52 cache.reset(cache2);
52 } 53 }
53 if (!cache.get()) 54 if (!cache.get())
54 return 2; 55 return 2;
55 56
56 if (num_entries + 1 != cache->GetEntryCount()) 57 if (num_entries + 1 != cache->GetEntryCount())
(...skipping 723 matching lines...) Expand 10 before | Expand all | Expand 10 after
780 EXPECT_EQ(0, TestTransaction(L"remove_one4", 0, false)); 781 EXPECT_EQ(0, TestTransaction(L"remove_one4", 0, false));
781 EXPECT_EQ(0, TestTransaction(L"remove_head4", 1, false)); 782 EXPECT_EQ(0, TestTransaction(L"remove_head4", 1, false));
782 #endif 783 #endif
783 } 784 }
784 785
785 // Tests dealing with cache files that cannot be recovered. 786 // Tests dealing with cache files that cannot be recovered.
786 TEST_F(DiskCacheTest, Backend_DeleteOld) { 787 TEST_F(DiskCacheTest, Backend_DeleteOld) {
787 ASSERT_TRUE(CopyTestCache(L"wrong_version")); 788 ASSERT_TRUE(CopyTestCache(L"wrong_version"));
788 std::wstring path = GetCachePath(); 789 std::wstring path = GetCachePath();
789 scoped_ptr<disk_cache::Backend> cache; 790 scoped_ptr<disk_cache::Backend> cache;
790 cache.reset(disk_cache::CreateCacheBackend(path, true, 0)); 791 cache.reset(disk_cache::CreateCacheBackend(path, true, 0, net::DISK_CACHE));
791 792
792 MessageLoopHelper helper; 793 MessageLoopHelper helper;
793 794
794 ASSERT_TRUE(NULL != cache.get()); 795 ASSERT_TRUE(NULL != cache.get());
795 ASSERT_EQ(0, cache->GetEntryCount()); 796 ASSERT_EQ(0, cache->GetEntryCount());
796 797
797 // Wait for a callback that never comes... about 2 secs :). The message loop 798 // Wait for a callback that never comes... about 2 secs :). The message loop
798 // has to run to allow destruction of the cleaner thread. 799 // has to run to allow destruction of the cleaner thread.
799 helper.WaitUntilCacheIoFinished(1); 800 helper.WaitUntilCacheIoFinished(1);
800 } 801 }
801 802
802 // We want to be able to deal with messed up entries on disk. 803 // We want to be able to deal with messed up entries on disk.
803 TEST_F(DiskCacheTest, Backend_InvalidEntry) { 804 TEST_F(DiskCacheTest, Backend_InvalidEntry) {
804 ASSERT_TRUE(CopyTestCache(L"bad_entry")); 805 ASSERT_TRUE(CopyTestCache(L"bad_entry"));
805 std::wstring path = GetCachePath(); 806 std::wstring path = GetCachePath();
806 disk_cache::Backend* cache = disk_cache::CreateCacheBackend(path, false, 0); 807 disk_cache::Backend* cache = disk_cache::CreateCacheBackend(path, false, 0,
808 net::DISK_CACHE);
807 ASSERT_TRUE(NULL != cache); 809 ASSERT_TRUE(NULL != cache);
808 810
809 disk_cache::Entry *entry1, *entry2; 811 disk_cache::Entry *entry1, *entry2;
810 ASSERT_TRUE(cache->OpenEntry("the first key", &entry1)); 812 ASSERT_TRUE(cache->OpenEntry("the first key", &entry1));
811 EXPECT_FALSE(cache->OpenEntry("some other key", &entry2)); 813 EXPECT_FALSE(cache->OpenEntry("some other key", &entry2));
812 entry1->Close(); 814 entry1->Close();
813 815
814 // CheckCacheIntegrity will fail at this point. 816 // CheckCacheIntegrity will fail at this point.
815 delete cache; 817 delete cache;
816 } 818 }
817 819
818 // We want to be able to deal with messed up entries on disk. 820 // We want to be able to deal with messed up entries on disk.
819 TEST_F(DiskCacheTest, Backend_InvalidRankings) { 821 TEST_F(DiskCacheTest, Backend_InvalidRankings) {
820 ASSERT_TRUE(CopyTestCache(L"bad_rankings")); 822 ASSERT_TRUE(CopyTestCache(L"bad_rankings"));
821 std::wstring path = GetCachePath(); 823 std::wstring path = GetCachePath();
822 disk_cache::Backend* cache = disk_cache::CreateCacheBackend(path, false, 0); 824 disk_cache::Backend* cache = disk_cache::CreateCacheBackend(path, false, 0,
825 net::DISK_CACHE);
823 ASSERT_TRUE(NULL != cache); 826 ASSERT_TRUE(NULL != cache);
824 827
825 disk_cache::Entry *entry1, *entry2; 828 disk_cache::Entry *entry1, *entry2;
826 EXPECT_FALSE(cache->OpenEntry("the first key", &entry1)); 829 EXPECT_FALSE(cache->OpenEntry("the first key", &entry1));
827 ASSERT_TRUE(cache->OpenEntry("some other key", &entry2)); 830 ASSERT_TRUE(cache->OpenEntry("some other key", &entry2));
828 entry2->Close(); 831 entry2->Close();
829 832
830 // CheckCacheIntegrity will fail at this point. 833 // CheckCacheIntegrity will fail at this point.
831 delete cache; 834 delete cache;
832 } 835 }
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
985 TEST_F(DiskCacheBackendTest, DoomAll) { 988 TEST_F(DiskCacheBackendTest, DoomAll) {
986 InitCache(); 989 InitCache();
987 BackendDoomAll(); 990 BackendDoomAll();
988 } 991 }
989 992
990 TEST_F(DiskCacheBackendTest, MemoryOnlyDoomAll) { 993 TEST_F(DiskCacheBackendTest, MemoryOnlyDoomAll) {
991 SetMemoryOnlyMode(); 994 SetMemoryOnlyMode();
992 InitCache(); 995 InitCache();
993 BackendDoomAll(); 996 BackendDoomAll();
994 } 997 }
OLDNEW
« no previous file with comments | « net/disk_cache/backend_impl.cc ('k') | net/disk_cache/disk_cache.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698