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

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

Issue 8658001: Disk cache: Add a hash to the entry's internal data. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 1 month 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/string_util.h" 7 #include "base/string_util.h"
8 #include "base/stringprintf.h" 8 #include "base/stringprintf.h"
9 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" 9 #include "base/third_party/dynamic_annotations/dynamic_annotations.h"
10 #include "base/threading/platform_thread.h" 10 #include "base/threading/platform_thread.h"
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 void BackendRecoverRemove(); 51 void BackendRecoverRemove();
52 void BackendRecoverWithEviction(); 52 void BackendRecoverWithEviction();
53 void BackendInvalidEntry2(); 53 void BackendInvalidEntry2();
54 void BackendInvalidEntry3(); 54 void BackendInvalidEntry3();
55 void BackendInvalidEntry7(); 55 void BackendInvalidEntry7();
56 void BackendInvalidEntry8(); 56 void BackendInvalidEntry8();
57 void BackendInvalidEntry9(bool eviction); 57 void BackendInvalidEntry9(bool eviction);
58 void BackendInvalidEntry10(bool eviction); 58 void BackendInvalidEntry10(bool eviction);
59 void BackendInvalidEntry11(bool eviction); 59 void BackendInvalidEntry11(bool eviction);
60 void BackendTrimInvalidEntry12(); 60 void BackendTrimInvalidEntry12();
61 void BackendNotMarkedButDirty(const std::string& name);
62 void BackendDoomAll(); 61 void BackendDoomAll();
63 void BackendDoomAll2(); 62 void BackendDoomAll2();
64 void BackendInvalidRankings(); 63 void BackendInvalidRankings();
65 void BackendInvalidRankings2(); 64 void BackendInvalidRankings2();
66 void BackendDisable(); 65 void BackendDisable();
67 void BackendDisable2(); 66 void BackendDisable2();
68 void BackendDisable3(); 67 void BackendDisable3();
69 void BackendDisable4(); 68 void BackendDisable4();
70 }; 69 };
71 70
(...skipping 620 matching lines...) Expand 10 before | Expand all | Expand 10 after
692 691
693 SimulateCrash(); 692 SimulateCrash();
694 693
695 for (int i = kNumEntries / 2; i < kNumEntries; i++) { 694 for (int i = kNumEntries / 2; i < kNumEntries; i++) {
696 disk_cache::Entry* entry; 695 disk_cache::Entry* entry;
697 EXPECT_NE(net::OK, OpenEntry(keys[i], &entry)); 696 EXPECT_NE(net::OK, OpenEntry(keys[i], &entry));
698 } 697 }
699 698
700 for (int i = 0; i < kNumEntries / 2; i++) { 699 for (int i = 0; i < kNumEntries / 2; i++) {
701 disk_cache::Entry* entry; 700 disk_cache::Entry* entry;
702 EXPECT_EQ(net::OK, OpenEntry(keys[i], &entry)); 701 ASSERT_EQ(net::OK, OpenEntry(keys[i], &entry));
703 entry->Close(); 702 entry->Close();
704 } 703 }
705 704
706 EXPECT_EQ(kNumEntries / 2, cache_->GetEntryCount()); 705 EXPECT_EQ(kNumEntries / 2, cache_->GetEntryCount());
707 } 706 }
708 707
709 // We'll be leaking memory from this test. 708 // We'll be leaking memory from this test.
710 TEST_F(DiskCacheBackendTest, InvalidEntryWithLoad) { 709 TEST_F(DiskCacheBackendTest, InvalidEntryWithLoad) {
711 BackendInvalidEntryWithLoad(); 710 BackendInvalidEntryWithLoad();
712 } 711 }
(...skipping 1123 matching lines...) Expand 10 before | Expand all | Expand 10 after
1836 1835
1837 TEST_F(DiskCacheBackendTest, TrimInvalidEntry12) { 1836 TEST_F(DiskCacheBackendTest, TrimInvalidEntry12) {
1838 BackendTrimInvalidEntry12(); 1837 BackendTrimInvalidEntry12();
1839 } 1838 }
1840 1839
1841 TEST_F(DiskCacheBackendTest, NewEvictionTrimInvalidEntry12) { 1840 TEST_F(DiskCacheBackendTest, NewEvictionTrimInvalidEntry12) {
1842 SetNewEviction(); 1841 SetNewEviction();
1843 BackendTrimInvalidEntry12(); 1842 BackendTrimInvalidEntry12();
1844 } 1843 }
1845 1844
1846 // We want to be able to deal with abnormal dirty entries.
1847 void DiskCacheBackendTest::BackendNotMarkedButDirty(const std::string& name) {
1848 ASSERT_TRUE(CopyTestCache(name));
1849 DisableFirstCleanup();
1850 InitCache();
1851
1852 disk_cache::Entry *entry1, *entry2;
1853 ASSERT_EQ(net::OK, OpenEntry("the first key", &entry1));
1854 EXPECT_NE(net::OK, OpenEntry("some other key", &entry2));
1855 entry1->Close();
1856 }
1857
1858 TEST_F(DiskCacheBackendTest, NotMarkedButDirty) {
1859 BackendNotMarkedButDirty("dirty_entry");
1860 }
1861
1862 TEST_F(DiskCacheBackendTest, NewEvictionNotMarkedButDirty) {
1863 SetNewEviction();
1864 BackendNotMarkedButDirty("dirty_entry");
1865 }
1866
1867 TEST_F(DiskCacheBackendTest, NotMarkedButDirty2) {
1868 BackendNotMarkedButDirty("dirty_entry2");
1869 }
1870
1871 TEST_F(DiskCacheBackendTest, NewEvictionNotMarkedButDirty2) {
1872 SetNewEviction();
1873 BackendNotMarkedButDirty("dirty_entry2");
1874 }
1875
1876 // We want to be able to deal with messed up entries on disk. 1845 // We want to be able to deal with messed up entries on disk.
1877 void DiskCacheBackendTest::BackendInvalidRankings2() { 1846 void DiskCacheBackendTest::BackendInvalidRankings2() {
1878 ASSERT_TRUE(CopyTestCache("bad_rankings")); 1847 ASSERT_TRUE(CopyTestCache("bad_rankings"));
1879 DisableFirstCleanup(); 1848 DisableFirstCleanup();
1880 InitCache(); 1849 InitCache();
1881 1850
1882 disk_cache::Entry *entry1, *entry2; 1851 disk_cache::Entry *entry1, *entry2;
1883 EXPECT_NE(net::OK, OpenEntry("the first key", &entry1)); 1852 EXPECT_NE(net::OK, OpenEntry("the first key", &entry1));
1884 ASSERT_EQ(net::OK, OpenEntry("some other key", &entry2)); 1853 ASSERT_EQ(net::OK, OpenEntry("some other key", &entry2));
1885 entry2->Close(); 1854 entry2->Close();
(...skipping 589 matching lines...) Expand 10 before | Expand all | Expand 10 after
2475 // Ping the oldest entry. 2444 // Ping the oldest entry.
2476 cache_->OnExternalCacheHit("key0"); 2445 cache_->OnExternalCacheHit("key0");
2477 2446
2478 TrimForTest(false); 2447 TrimForTest(false);
2479 2448
2480 // Make sure the older key remains. 2449 // Make sure the older key remains.
2481 EXPECT_EQ(1, cache_->GetEntryCount()); 2450 EXPECT_EQ(1, cache_->GetEntryCount());
2482 ASSERT_EQ(net::OK, OpenEntry("key0", &entry)); 2451 ASSERT_EQ(net::OK, OpenEntry("key0", &entry));
2483 entry->Close(); 2452 entry->Close();
2484 } 2453 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698