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

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

Issue 149306: Disk cache: Add explicit support for eviction / deletion... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 years, 5 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/entry_impl.cc ('k') | net/disk_cache/sparse_control.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-2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2009 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/platform_thread.h" 6 #include "base/platform_thread.h"
7 #include "base/timer.h" 7 #include "base/timer.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "net/base/io_buffer.h" 9 #include "net/base/io_buffer.h"
10 #include "net/base/net_errors.h" 10 #include "net/base/net_errors.h"
(...skipping 20 matching lines...) Expand all
31 void GrowData(); 31 void GrowData();
32 void TruncateData(); 32 void TruncateData();
33 void ZeroLengthIO(); 33 void ZeroLengthIO();
34 void ReuseEntry(int size); 34 void ReuseEntry(int size);
35 void InvalidData(); 35 void InvalidData();
36 void DoomEntry(); 36 void DoomEntry();
37 void DoomedEntry(); 37 void DoomedEntry();
38 void BasicSparseIO(bool async); 38 void BasicSparseIO(bool async);
39 void HugeSparseIO(bool async); 39 void HugeSparseIO(bool async);
40 void GetAvailableRange(); 40 void GetAvailableRange();
41 void DoomSparseEntry();
41 }; 42 };
42 43
43 void DiskCacheEntryTest::InternalSyncIO() { 44 void DiskCacheEntryTest::InternalSyncIO() {
44 disk_cache::Entry *entry1 = NULL; 45 disk_cache::Entry *entry1 = NULL;
45 ASSERT_TRUE(cache_->CreateEntry("the first key", &entry1)); 46 ASSERT_TRUE(cache_->CreateEntry("the first key", &entry1));
46 ASSERT_TRUE(NULL != entry1); 47 ASSERT_TRUE(NULL != entry1);
47 48
48 const int kSize1 = 10; 49 const int kSize1 = 10;
49 scoped_refptr<net::IOBuffer> buffer1 = new net::IOBuffer(kSize1); 50 scoped_refptr<net::IOBuffer> buffer1 = new net::IOBuffer(kSize1);
50 CacheTestFillBuffer(buffer1->data(), kSize1, false); 51 CacheTestFillBuffer(buffer1->data(), kSize1, false);
(...skipping 768 matching lines...) Expand 10 before | Expand all | Expand 10 after
819 } 820 }
820 821
821 TEST_F(DiskCacheEntryTest, MemoryOnlyDoomedEntry) { 822 TEST_F(DiskCacheEntryTest, MemoryOnlyDoomedEntry) {
822 SetMemoryOnlyMode(); 823 SetMemoryOnlyMode();
823 InitCache(); 824 InitCache();
824 DoomEntry(); 825 DoomEntry();
825 } 826 }
826 827
827 // Test that child entries in a memory cache backend are not visible from 828 // Test that child entries in a memory cache backend are not visible from
828 // enumerations. 829 // enumerations.
829 TEST_F(DiskCacheEntryTest, MemoryOnlyEnumerationWithSlaveEntries) { 830 TEST_F(DiskCacheEntryTest, MemoryOnlyEnumerationWithSparseEntries) {
830 SetMemoryOnlyMode(); 831 SetMemoryOnlyMode();
831 InitCache(); 832 InitCache();
832 833
833 const int kSize = 4096; 834 const int kSize = 4096;
834 scoped_refptr<net::IOBuffer> buf = new net::IOBuffer(kSize); 835 scoped_refptr<net::IOBuffer> buf = new net::IOBuffer(kSize);
835 CacheTestFillBuffer(buf->data(), kSize, false); 836 CacheTestFillBuffer(buf->data(), kSize, false);
836 837
837 std::string key("the first key"); 838 std::string key("the first key");
838 disk_cache::Entry* parent_entry; 839 disk_cache::Entry* parent_entry;
839 ASSERT_TRUE(cache_->CreateEntry(key, &parent_entry)); 840 ASSERT_TRUE(cache_->CreateEntry(key, &parent_entry));
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
1121 // region. 1122 // region.
1122 EXPECT_EQ(500, entry->GetAvailableRange(5000, 620, &start)); 1123 EXPECT_EQ(500, entry->GetAvailableRange(5000, 620, &start));
1123 EXPECT_EQ(5120, start); 1124 EXPECT_EQ(5120, start);
1124 1125
1125 // Test that multiple blocks are scanned. 1126 // Test that multiple blocks are scanned.
1126 EXPECT_EQ(8192, entry->GetAvailableRange(40000, 20000, &start)); 1127 EXPECT_EQ(8192, entry->GetAvailableRange(40000, 20000, &start));
1127 EXPECT_EQ(50000, start); 1128 EXPECT_EQ(50000, start);
1128 1129
1129 entry->Close(); 1130 entry->Close();
1130 } 1131 }
1132
1133 void DiskCacheEntryTest::DoomSparseEntry() {
1134 std::string key1("the first key");
1135 std::string key2("the second key");
1136 disk_cache::Entry *entry1, *entry2;
1137 ASSERT_TRUE(cache_->CreateEntry(key1, &entry1));
1138 ASSERT_TRUE(cache_->CreateEntry(key2, &entry2));
1139
1140 const int kSize = 4 * 1024;
1141 scoped_refptr<net::IOBuffer> buf = new net::IOBuffer(kSize);
1142 CacheTestFillBuffer(buf->data(), kSize, false);
1143
1144 int64 offset = 1024;
1145 // Write to a bunch of ranges.
1146 for (int i = 0; i < 12; i++) {
1147 EXPECT_EQ(kSize, entry1->WriteSparseData(offset, buf, kSize, NULL));
1148 // Keep the second map under the default size.
1149 if (i < 9)
1150 EXPECT_EQ(kSize, entry2->WriteSparseData(offset, buf, kSize, NULL));
1151 offset *= 4;
1152 }
1153
1154 if (memory_only_)
1155 EXPECT_EQ(2, cache_->GetEntryCount());
1156 else
1157 EXPECT_EQ(15, cache_->GetEntryCount());
1158
1159 // Doom the first entry while it's still open.
1160 entry1->Doom();
1161 entry1->Close();
1162 entry2->Close();
1163
1164 // Doom the second entry after it's fully saved.
1165 EXPECT_TRUE(cache_->DoomEntry(key2));
1166
1167 // Make sure we do all needed work. This may fail for entry2 if between Close
1168 // and DoomEntry the system decides to remove all traces of the file from the
1169 // system cache so we don't see that there is pending IO.
1170 MessageLoop::current()->RunAllPending();
1171
1172 if (memory_only_)
1173 EXPECT_EQ(0, cache_->GetEntryCount());
1174 else
1175 EXPECT_EQ(0, cache_->GetEntryCount());
1176 }
1177
1178 TEST_F(DiskCacheEntryTest, DoomSparseEntry) {
1179 InitCache();
1180 DoomSparseEntry();
1181 }
1182
1183 TEST_F(DiskCacheEntryTest, DISABLED_MemoryOnlyDoomSparseEntry) {
1184 SetMemoryOnlyMode();
1185 InitCache();
1186 DoomSparseEntry();
1187 }
OLDNEW
« no previous file with comments | « net/disk_cache/entry_impl.cc ('k') | net/disk_cache/sparse_control.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698