OLD | NEW |
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 799 matching lines...) Loading... |
810 | 810 |
811 disk_cache::Entry *entry1, *entry2; | 811 disk_cache::Entry *entry1, *entry2; |
812 ASSERT_TRUE(cache->OpenEntry("the first key", &entry1)); | 812 ASSERT_TRUE(cache->OpenEntry("the first key", &entry1)); |
813 EXPECT_FALSE(cache->OpenEntry("some other key", &entry2)); | 813 EXPECT_FALSE(cache->OpenEntry("some other key", &entry2)); |
814 entry1->Close(); | 814 entry1->Close(); |
815 | 815 |
816 // CheckCacheIntegrity will fail at this point. | 816 // CheckCacheIntegrity will fail at this point. |
817 delete cache; | 817 delete cache; |
818 } | 818 } |
819 | 819 |
| 820 // We want to be able to deal with abnormal dirty entries. |
| 821 TEST_F(DiskCacheTest, Backend_NotMarkedButDirty) { |
| 822 ASSERT_TRUE(CopyTestCache(L"dirty_entry")); |
| 823 std::wstring path = GetCachePath(); |
| 824 disk_cache::Backend* cache = disk_cache::CreateCacheBackend(path, false, 0, |
| 825 net::DISK_CACHE); |
| 826 ASSERT_TRUE(NULL != cache); |
| 827 |
| 828 disk_cache::Entry *entry1, *entry2; |
| 829 ASSERT_TRUE(cache->OpenEntry("the first key", &entry1)); |
| 830 EXPECT_FALSE(cache->OpenEntry("some other key", &entry2)); |
| 831 entry1->Close(); |
| 832 |
| 833 delete cache; |
| 834 EXPECT_TRUE(CheckCacheIntegrity(path)); |
| 835 } |
| 836 |
820 // We want to be able to deal with messed up entries on disk. | 837 // We want to be able to deal with messed up entries on disk. |
821 TEST_F(DiskCacheTest, Backend_InvalidRankings) { | 838 TEST_F(DiskCacheTest, Backend_InvalidRankings) { |
822 ASSERT_TRUE(CopyTestCache(L"bad_rankings")); | 839 ASSERT_TRUE(CopyTestCache(L"bad_rankings")); |
823 std::wstring path = GetCachePath(); | 840 std::wstring path = GetCachePath(); |
824 disk_cache::Backend* cache = disk_cache::CreateCacheBackend(path, false, 0, | 841 disk_cache::Backend* cache = disk_cache::CreateCacheBackend(path, false, 0, |
825 net::DISK_CACHE); | 842 net::DISK_CACHE); |
826 ASSERT_TRUE(NULL != cache); | 843 ASSERT_TRUE(NULL != cache); |
827 | 844 |
828 disk_cache::Entry *entry1, *entry2; | 845 disk_cache::Entry *entry1, *entry2; |
829 EXPECT_FALSE(cache->OpenEntry("the first key", &entry1)); | 846 EXPECT_FALSE(cache->OpenEntry("the first key", &entry1)); |
(...skipping 186 matching lines...) Loading... |
1016 ASSERT_TRUE(cache[0].get() != NULL && cache[1].get() != NULL && | 1033 ASSERT_TRUE(cache[0].get() != NULL && cache[1].get() != NULL && |
1017 cache[2].get() != NULL); | 1034 cache[2].get() != NULL); |
1018 | 1035 |
1019 std::string key("the first key"); | 1036 std::string key("the first key"); |
1020 disk_cache::Entry* entry; | 1037 disk_cache::Entry* entry; |
1021 for (int i = 0; i < kNumberOfCaches; i++) { | 1038 for (int i = 0; i < kNumberOfCaches; i++) { |
1022 ASSERT_TRUE(cache[i]->CreateEntry(key, &entry)); | 1039 ASSERT_TRUE(cache[i]->CreateEntry(key, &entry)); |
1023 entry->Close(); | 1040 entry->Close(); |
1024 } | 1041 } |
1025 } | 1042 } |
OLD | NEW |