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 "base/basictypes.h" | 5 #include "base/basictypes.h" |
6 #include "base/bind.h" | 6 #include "base/bind.h" |
7 #include "base/bind_helpers.h" | 7 #include "base/bind_helpers.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/threading/platform_thread.h" | 9 #include "base/threading/platform_thread.h" |
10 #include "base/timer.h" | 10 #include "base/timer.h" |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 entry)); | 122 entry)); |
123 | 123 |
124 | 124 |
125 entry->Doom(); | 125 entry->Doom(); |
126 entry->Close(); | 126 entry->Close(); |
127 FlushQueueForTest(); | 127 FlushQueueForTest(); |
128 EXPECT_EQ(0, cache_->GetEntryCount()); | 128 EXPECT_EQ(0, cache_->GetEntryCount()); |
129 } | 129 } |
130 | 130 |
131 TEST_F(DiskCacheEntryTest, InternalSyncIO) { | 131 TEST_F(DiskCacheEntryTest, InternalSyncIO) { |
132 SetDirectMode(); | |
133 InitCache(); | 132 InitCache(); |
134 InternalSyncIO(); | 133 InternalSyncIO(); |
135 } | 134 } |
136 | 135 |
137 TEST_F(DiskCacheEntryTest, MemoryOnlyInternalSyncIO) { | 136 TEST_F(DiskCacheEntryTest, MemoryOnlyInternalSyncIO) { |
138 SetMemoryOnlyMode(); | 137 SetMemoryOnlyMode(); |
139 InitCache(); | 138 InitCache(); |
140 InternalSyncIO(); | 139 InternalSyncIO(); |
141 } | 140 } |
142 | 141 |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
284 | 283 |
285 EXPECT_FALSE(helper.callback_reused_error()); | 284 EXPECT_FALSE(helper.callback_reused_error()); |
286 | 285 |
287 entry->Doom(); | 286 entry->Doom(); |
288 entry->Close(); | 287 entry->Close(); |
289 FlushQueueForTest(); | 288 FlushQueueForTest(); |
290 EXPECT_EQ(0, cache_->GetEntryCount()); | 289 EXPECT_EQ(0, cache_->GetEntryCount()); |
291 } | 290 } |
292 | 291 |
293 TEST_F(DiskCacheEntryTest, InternalAsyncIO) { | 292 TEST_F(DiskCacheEntryTest, InternalAsyncIO) { |
294 SetDirectMode(); | |
295 InitCache(); | 293 InitCache(); |
296 InternalAsyncIO(); | 294 InternalAsyncIO(); |
297 } | 295 } |
298 | 296 |
299 TEST_F(DiskCacheEntryTest, MemoryOnlyInternalAsyncIO) { | 297 TEST_F(DiskCacheEntryTest, MemoryOnlyInternalAsyncIO) { |
300 SetMemoryOnlyMode(); | 298 SetMemoryOnlyMode(); |
301 InitCache(); | 299 InitCache(); |
302 InternalAsyncIO(); | 300 InternalAsyncIO(); |
303 } | 301 } |
304 | 302 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
355 base::Unretained(this), | 353 base::Unretained(this), |
356 entry)); | 354 entry)); |
357 | 355 |
358 entry->Doom(); | 356 entry->Doom(); |
359 entry->Close(); | 357 entry->Close(); |
360 FlushQueueForTest(); | 358 FlushQueueForTest(); |
361 EXPECT_EQ(0, cache_->GetEntryCount()); | 359 EXPECT_EQ(0, cache_->GetEntryCount()); |
362 } | 360 } |
363 | 361 |
364 TEST_F(DiskCacheEntryTest, ExternalSyncIO) { | 362 TEST_F(DiskCacheEntryTest, ExternalSyncIO) { |
365 SetDirectMode(); | |
366 InitCache(); | 363 InitCache(); |
367 ExternalSyncIO(); | 364 ExternalSyncIO(); |
368 } | 365 } |
369 | 366 |
370 TEST_F(DiskCacheEntryTest, ExternalSyncIONoBuffer) { | 367 TEST_F(DiskCacheEntryTest, ExternalSyncIONoBuffer) { |
371 SetDirectMode(); | |
372 InitCache(); | 368 InitCache(); |
373 cache_impl_->SetFlags(disk_cache::kNoBuffering); | 369 cache_impl_->SetFlags(disk_cache::kNoBuffering); |
374 ExternalSyncIO(); | 370 ExternalSyncIO(); |
375 } | 371 } |
376 | 372 |
377 TEST_F(DiskCacheEntryTest, MemoryOnlyExternalSyncIO) { | 373 TEST_F(DiskCacheEntryTest, MemoryOnlyExternalSyncIO) { |
378 SetMemoryOnlyMode(); | 374 SetMemoryOnlyMode(); |
379 InitCache(); | 375 InitCache(); |
380 ExternalSyncIO(); | 376 ExternalSyncIO(); |
381 } | 377 } |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
486 | 482 |
487 EXPECT_FALSE(helper.callback_reused_error()); | 483 EXPECT_FALSE(helper.callback_reused_error()); |
488 | 484 |
489 entry->Doom(); | 485 entry->Doom(); |
490 entry->Close(); | 486 entry->Close(); |
491 FlushQueueForTest(); | 487 FlushQueueForTest(); |
492 EXPECT_EQ(0, cache_->GetEntryCount()); | 488 EXPECT_EQ(0, cache_->GetEntryCount()); |
493 } | 489 } |
494 | 490 |
495 TEST_F(DiskCacheEntryTest, ExternalAsyncIO) { | 491 TEST_F(DiskCacheEntryTest, ExternalAsyncIO) { |
496 SetDirectMode(); | |
497 InitCache(); | 492 InitCache(); |
498 ExternalAsyncIO(); | 493 ExternalAsyncIO(); |
499 } | 494 } |
500 | 495 |
501 TEST_F(DiskCacheEntryTest, ExternalAsyncIONoBuffer) { | 496 TEST_F(DiskCacheEntryTest, ExternalAsyncIONoBuffer) { |
502 SetDirectMode(); | |
503 InitCache(); | 497 InitCache(); |
504 cache_impl_->SetFlags(disk_cache::kNoBuffering); | 498 cache_impl_->SetFlags(disk_cache::kNoBuffering); |
505 ExternalAsyncIO(); | 499 ExternalAsyncIO(); |
506 } | 500 } |
507 | 501 |
508 TEST_F(DiskCacheEntryTest, MemoryOnlyExternalAsyncIO) { | 502 TEST_F(DiskCacheEntryTest, MemoryOnlyExternalAsyncIO) { |
509 SetMemoryOnlyMode(); | 503 SetMemoryOnlyMode(); |
510 InitCache(); | 504 InitCache(); |
511 ExternalAsyncIO(); | 505 ExternalAsyncIO(); |
512 } | 506 } |
513 | 507 |
514 // Tests that IOBuffers are not referenced after IO completes. | 508 // Tests that IOBuffers are not referenced after IO completes. |
515 void DiskCacheEntryTest::ReleaseBuffer() { | 509 void DiskCacheEntryTest::ReleaseBuffer() { |
516 disk_cache::Entry* entry = NULL; | 510 disk_cache::Entry* entry = NULL; |
517 ASSERT_EQ(net::OK, CreateEntry("the first key", &entry)); | 511 ASSERT_EQ(net::OK, CreateEntry("the first key", &entry)); |
518 ASSERT_TRUE(NULL != entry); | 512 ASSERT_TRUE(NULL != entry); |
519 | 513 |
520 const int kBufferSize = 1024; | 514 const int kBufferSize = 1024; |
521 scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(kBufferSize)); | 515 scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(kBufferSize)); |
522 CacheTestFillBuffer(buffer->data(), kBufferSize, false); | 516 CacheTestFillBuffer(buffer->data(), kBufferSize, false); |
523 | 517 |
524 net::ReleaseBufferCompletionCallback cb(buffer); | 518 net::ReleaseBufferCompletionCallback cb(buffer); |
525 int rv = entry->WriteData(0, 0, buffer, kBufferSize, cb.callback(), false); | 519 int rv = entry->WriteData(0, 0, buffer, kBufferSize, cb.callback(), false); |
526 EXPECT_EQ(kBufferSize, cb.GetResult(rv)); | 520 EXPECT_EQ(kBufferSize, cb.GetResult(rv)); |
527 entry->Close(); | 521 entry->Close(); |
528 } | 522 } |
529 | 523 |
530 TEST_F(DiskCacheEntryTest, ReleaseBuffer) { | 524 TEST_F(DiskCacheEntryTest, ReleaseBuffer) { |
531 SetDirectMode(); | |
532 InitCache(); | 525 InitCache(); |
533 cache_impl_->SetFlags(disk_cache::kNoBuffering); | 526 cache_impl_->SetFlags(disk_cache::kNoBuffering); |
534 ReleaseBuffer(); | 527 ReleaseBuffer(); |
535 } | 528 } |
536 | 529 |
537 TEST_F(DiskCacheEntryTest, MemoryOnlyReleaseBuffer) { | 530 TEST_F(DiskCacheEntryTest, MemoryOnlyReleaseBuffer) { |
538 SetMemoryOnlyMode(); | 531 SetMemoryOnlyMode(); |
539 InitCache(); | 532 InitCache(); |
540 ReleaseBuffer(); | 533 ReleaseBuffer(); |
541 } | 534 } |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
755 EXPECT_EQ(45500, entry->GetDataSize(0)); | 748 EXPECT_EQ(45500, entry->GetDataSize(0)); |
756 entry->Close(); | 749 entry->Close(); |
757 } | 750 } |
758 | 751 |
759 TEST_F(DiskCacheEntryTest, GrowData) { | 752 TEST_F(DiskCacheEntryTest, GrowData) { |
760 InitCache(); | 753 InitCache(); |
761 GrowData(); | 754 GrowData(); |
762 } | 755 } |
763 | 756 |
764 TEST_F(DiskCacheEntryTest, GrowDataNoBuffer) { | 757 TEST_F(DiskCacheEntryTest, GrowDataNoBuffer) { |
765 SetDirectMode(); | |
766 InitCache(); | 758 InitCache(); |
767 cache_impl_->SetFlags(disk_cache::kNoBuffering); | 759 cache_impl_->SetFlags(disk_cache::kNoBuffering); |
768 GrowData(); | 760 GrowData(); |
769 } | 761 } |
770 | 762 |
771 TEST_F(DiskCacheEntryTest, MemoryOnlyGrowData) { | 763 TEST_F(DiskCacheEntryTest, MemoryOnlyGrowData) { |
772 SetMemoryOnlyMode(); | 764 SetMemoryOnlyMode(); |
773 InitCache(); | 765 InitCache(); |
774 GrowData(); | 766 GrowData(); |
775 } | 767 } |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
833 | 825 |
834 entry->Close(); | 826 entry->Close(); |
835 } | 827 } |
836 | 828 |
837 TEST_F(DiskCacheEntryTest, TruncateData) { | 829 TEST_F(DiskCacheEntryTest, TruncateData) { |
838 InitCache(); | 830 InitCache(); |
839 TruncateData(); | 831 TruncateData(); |
840 } | 832 } |
841 | 833 |
842 TEST_F(DiskCacheEntryTest, TruncateDataNoBuffer) { | 834 TEST_F(DiskCacheEntryTest, TruncateDataNoBuffer) { |
843 SetDirectMode(); | |
844 InitCache(); | 835 InitCache(); |
845 cache_impl_->SetFlags(disk_cache::kNoBuffering); | 836 cache_impl_->SetFlags(disk_cache::kNoBuffering); |
846 TruncateData(); | 837 TruncateData(); |
847 } | 838 } |
848 | 839 |
849 TEST_F(DiskCacheEntryTest, MemoryOnlyTruncateData) { | 840 TEST_F(DiskCacheEntryTest, MemoryOnlyTruncateData) { |
850 SetMemoryOnlyMode(); | 841 SetMemoryOnlyMode(); |
851 InitCache(); | 842 InitCache(); |
852 TruncateData(); | 843 TruncateData(); |
853 } | 844 } |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
889 | 880 |
890 entry->Close(); | 881 entry->Close(); |
891 } | 882 } |
892 | 883 |
893 TEST_F(DiskCacheEntryTest, ZeroLengthIO) { | 884 TEST_F(DiskCacheEntryTest, ZeroLengthIO) { |
894 InitCache(); | 885 InitCache(); |
895 ZeroLengthIO(); | 886 ZeroLengthIO(); |
896 } | 887 } |
897 | 888 |
898 TEST_F(DiskCacheEntryTest, ZeroLengthIONoBuffer) { | 889 TEST_F(DiskCacheEntryTest, ZeroLengthIONoBuffer) { |
899 SetDirectMode(); | |
900 InitCache(); | 890 InitCache(); |
901 cache_impl_->SetFlags(disk_cache::kNoBuffering); | 891 cache_impl_->SetFlags(disk_cache::kNoBuffering); |
902 ZeroLengthIO(); | 892 ZeroLengthIO(); |
903 } | 893 } |
904 | 894 |
905 TEST_F(DiskCacheEntryTest, MemoryOnlyZeroLengthIO) { | 895 TEST_F(DiskCacheEntryTest, MemoryOnlyZeroLengthIO) { |
906 SetMemoryOnlyMode(); | 896 SetMemoryOnlyMode(); |
907 InitCache(); | 897 InitCache(); |
908 ZeroLengthIO(); | 898 ZeroLengthIO(); |
909 } | 899 } |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
984 | 974 |
985 entry->Close(); | 975 entry->Close(); |
986 } | 976 } |
987 | 977 |
988 TEST_F(DiskCacheEntryTest, Buffering) { | 978 TEST_F(DiskCacheEntryTest, Buffering) { |
989 InitCache(); | 979 InitCache(); |
990 Buffering(); | 980 Buffering(); |
991 } | 981 } |
992 | 982 |
993 TEST_F(DiskCacheEntryTest, BufferingNoBuffer) { | 983 TEST_F(DiskCacheEntryTest, BufferingNoBuffer) { |
994 SetDirectMode(); | |
995 InitCache(); | 984 InitCache(); |
996 cache_impl_->SetFlags(disk_cache::kNoBuffering); | 985 cache_impl_->SetFlags(disk_cache::kNoBuffering); |
997 Buffering(); | 986 Buffering(); |
998 } | 987 } |
999 | 988 |
1000 // Some extra tests to make sure that buffering works properly when changing | 989 // Some extra tests to make sure that buffering works properly when changing |
1001 // the entry size. | 990 // the entry size. |
1002 void DiskCacheEntryTest::SizeChanges() { | 991 void DiskCacheEntryTest::SizeChanges() { |
1003 std::string key("the first key"); | 992 std::string key("the first key"); |
1004 disk_cache::Entry* entry; | 993 disk_cache::Entry* entry; |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1071 | 1060 |
1072 entry->Close(); | 1061 entry->Close(); |
1073 } | 1062 } |
1074 | 1063 |
1075 TEST_F(DiskCacheEntryTest, SizeChanges) { | 1064 TEST_F(DiskCacheEntryTest, SizeChanges) { |
1076 InitCache(); | 1065 InitCache(); |
1077 SizeChanges(); | 1066 SizeChanges(); |
1078 } | 1067 } |
1079 | 1068 |
1080 TEST_F(DiskCacheEntryTest, SizeChangesNoBuffer) { | 1069 TEST_F(DiskCacheEntryTest, SizeChangesNoBuffer) { |
1081 SetDirectMode(); | |
1082 InitCache(); | 1070 InitCache(); |
1083 cache_impl_->SetFlags(disk_cache::kNoBuffering); | 1071 cache_impl_->SetFlags(disk_cache::kNoBuffering); |
1084 SizeChanges(); | 1072 SizeChanges(); |
1085 } | 1073 } |
1086 | 1074 |
1087 // Write more than the total cache capacity but to a single entry. |size| is the | 1075 // Write more than the total cache capacity but to a single entry. |size| is the |
1088 // amount of bytes to write each time. | 1076 // amount of bytes to write each time. |
1089 void DiskCacheEntryTest::ReuseEntry(int size) { | 1077 void DiskCacheEntryTest::ReuseEntry(int size) { |
1090 std::string key1("the first key"); | 1078 std::string key1("the first key"); |
1091 disk_cache::Entry* entry; | 1079 disk_cache::Entry* entry; |
(...skipping 12 matching lines...) Expand all Loading... |
1104 entry->Close(); | 1092 entry->Close(); |
1105 ASSERT_EQ(net::OK, OpenEntry(key2, &entry)); | 1093 ASSERT_EQ(net::OK, OpenEntry(key2, &entry)); |
1106 } | 1094 } |
1107 | 1095 |
1108 entry->Close(); | 1096 entry->Close(); |
1109 ASSERT_EQ(net::OK, OpenEntry(key1, &entry)) << "have not evicted this entry"; | 1097 ASSERT_EQ(net::OK, OpenEntry(key1, &entry)) << "have not evicted this entry"; |
1110 entry->Close(); | 1098 entry->Close(); |
1111 } | 1099 } |
1112 | 1100 |
1113 TEST_F(DiskCacheEntryTest, ReuseExternalEntry) { | 1101 TEST_F(DiskCacheEntryTest, ReuseExternalEntry) { |
1114 SetDirectMode(); | |
1115 SetMaxSize(200 * 1024); | 1102 SetMaxSize(200 * 1024); |
1116 InitCache(); | 1103 InitCache(); |
1117 ReuseEntry(20 * 1024); | 1104 ReuseEntry(20 * 1024); |
1118 } | 1105 } |
1119 | 1106 |
1120 TEST_F(DiskCacheEntryTest, MemoryOnlyReuseExternalEntry) { | 1107 TEST_F(DiskCacheEntryTest, MemoryOnlyReuseExternalEntry) { |
1121 SetDirectMode(); | |
1122 SetMemoryOnlyMode(); | 1108 SetMemoryOnlyMode(); |
1123 SetMaxSize(200 * 1024); | 1109 SetMaxSize(200 * 1024); |
1124 InitCache(); | 1110 InitCache(); |
1125 ReuseEntry(20 * 1024); | 1111 ReuseEntry(20 * 1024); |
1126 } | 1112 } |
1127 | 1113 |
1128 TEST_F(DiskCacheEntryTest, ReuseInternalEntry) { | 1114 TEST_F(DiskCacheEntryTest, ReuseInternalEntry) { |
1129 SetDirectMode(); | |
1130 SetMaxSize(100 * 1024); | 1115 SetMaxSize(100 * 1024); |
1131 InitCache(); | 1116 InitCache(); |
1132 ReuseEntry(10 * 1024); | 1117 ReuseEntry(10 * 1024); |
1133 } | 1118 } |
1134 | 1119 |
1135 TEST_F(DiskCacheEntryTest, MemoryOnlyReuseInternalEntry) { | 1120 TEST_F(DiskCacheEntryTest, MemoryOnlyReuseInternalEntry) { |
1136 SetDirectMode(); | |
1137 SetMemoryOnlyMode(); | 1121 SetMemoryOnlyMode(); |
1138 SetMaxSize(100 * 1024); | 1122 SetMaxSize(100 * 1024); |
1139 InitCache(); | 1123 InitCache(); |
1140 ReuseEntry(10 * 1024); | 1124 ReuseEntry(10 * 1024); |
1141 } | 1125 } |
1142 | 1126 |
1143 // Reading somewhere that was not written should return zeros. | 1127 // Reading somewhere that was not written should return zeros. |
1144 void DiskCacheEntryTest::InvalidData() { | 1128 void DiskCacheEntryTest::InvalidData() { |
1145 std::string key("the first key"); | 1129 std::string key("the first key"); |
1146 disk_cache::Entry* entry; | 1130 disk_cache::Entry* entry; |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1204 | 1188 |
1205 entry->Close(); | 1189 entry->Close(); |
1206 } | 1190 } |
1207 | 1191 |
1208 TEST_F(DiskCacheEntryTest, InvalidData) { | 1192 TEST_F(DiskCacheEntryTest, InvalidData) { |
1209 InitCache(); | 1193 InitCache(); |
1210 InvalidData(); | 1194 InvalidData(); |
1211 } | 1195 } |
1212 | 1196 |
1213 TEST_F(DiskCacheEntryTest, InvalidDataNoBuffer) { | 1197 TEST_F(DiskCacheEntryTest, InvalidDataNoBuffer) { |
1214 SetDirectMode(); | |
1215 InitCache(); | 1198 InitCache(); |
1216 cache_impl_->SetFlags(disk_cache::kNoBuffering); | 1199 cache_impl_->SetFlags(disk_cache::kNoBuffering); |
1217 InvalidData(); | 1200 InvalidData(); |
1218 } | 1201 } |
1219 | 1202 |
1220 TEST_F(DiskCacheEntryTest, MemoryOnlyInvalidData) { | 1203 TEST_F(DiskCacheEntryTest, MemoryOnlyInvalidData) { |
1221 SetMemoryOnlyMode(); | 1204 SetMemoryOnlyMode(); |
1222 InitCache(); | 1205 InitCache(); |
1223 InvalidData(); | 1206 InvalidData(); |
1224 } | 1207 } |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1271 EXPECT_EQ(20000, WriteData(entry, 0, 0, buffer, kSize, false)); | 1254 EXPECT_EQ(20000, WriteData(entry, 0, 0, buffer, kSize, false)); |
1272 EXPECT_EQ(20000, WriteData(entry, 1, 0, buffer, kSize, false)); | 1255 EXPECT_EQ(20000, WriteData(entry, 1, 0, buffer, kSize, false)); |
1273 entry->Doom(); | 1256 entry->Doom(); |
1274 entry->Close(); | 1257 entry->Close(); |
1275 | 1258 |
1276 FlushQueueForTest(); | 1259 FlushQueueForTest(); |
1277 EXPECT_EQ(0, cache_->GetEntryCount()); | 1260 EXPECT_EQ(0, cache_->GetEntryCount()); |
1278 } | 1261 } |
1279 | 1262 |
1280 TEST_F(DiskCacheEntryTest, DoomEntry) { | 1263 TEST_F(DiskCacheEntryTest, DoomEntry) { |
1281 SetDirectMode(); | |
1282 InitCache(); | 1264 InitCache(); |
1283 DoomNormalEntry(); | 1265 DoomNormalEntry(); |
1284 } | 1266 } |
1285 | 1267 |
1286 TEST_F(DiskCacheEntryTest, MemoryOnlyDoomEntry) { | 1268 TEST_F(DiskCacheEntryTest, MemoryOnlyDoomEntry) { |
1287 SetMemoryOnlyMode(); | 1269 SetMemoryOnlyMode(); |
1288 InitCache(); | 1270 InitCache(); |
1289 DoomNormalEntry(); | 1271 DoomNormalEntry(); |
1290 } | 1272 } |
1291 | 1273 |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1353 EXPECT_EQ(2000, ReadData(entry, 0, 0, buffer2, 2000)); | 1335 EXPECT_EQ(2000, ReadData(entry, 0, 0, buffer2, 2000)); |
1354 EXPECT_EQ(0, memcmp(buffer1->data(), buffer2->data(), kSize1)); | 1336 EXPECT_EQ(0, memcmp(buffer1->data(), buffer2->data(), kSize1)); |
1355 EXPECT_EQ(key, entry->GetKey()); | 1337 EXPECT_EQ(key, entry->GetKey()); |
1356 EXPECT_TRUE(initial < entry->GetLastModified()); | 1338 EXPECT_TRUE(initial < entry->GetLastModified()); |
1357 EXPECT_TRUE(initial < entry->GetLastUsed()); | 1339 EXPECT_TRUE(initial < entry->GetLastUsed()); |
1358 | 1340 |
1359 entry->Close(); | 1341 entry->Close(); |
1360 } | 1342 } |
1361 | 1343 |
1362 TEST_F(DiskCacheEntryTest, DoomedEntry) { | 1344 TEST_F(DiskCacheEntryTest, DoomedEntry) { |
1363 SetDirectMode(); | |
1364 InitCache(); | 1345 InitCache(); |
1365 DoomedEntry(); | 1346 DoomedEntry(); |
1366 } | 1347 } |
1367 | 1348 |
1368 TEST_F(DiskCacheEntryTest, MemoryOnlyDoomedEntry) { | 1349 TEST_F(DiskCacheEntryTest, MemoryOnlyDoomedEntry) { |
1369 SetMemoryOnlyMode(); | 1350 SetMemoryOnlyMode(); |
1370 InitCache(); | 1351 InitCache(); |
1371 DoomedEntry(); | 1352 DoomedEntry(); |
1372 } | 1353 } |
1373 | 1354 |
1374 // Tests that we discard entries if the data is missing. | 1355 // Tests that we discard entries if the data is missing. |
1375 TEST_F(DiskCacheEntryTest, MissingData) { | 1356 TEST_F(DiskCacheEntryTest, MissingData) { |
1376 SetDirectMode(); | |
1377 InitCache(); | 1357 InitCache(); |
1378 | 1358 |
1379 std::string key("the first key"); | 1359 std::string key("the first key"); |
1380 disk_cache::Entry* entry; | 1360 disk_cache::Entry* entry; |
1381 ASSERT_EQ(net::OK, CreateEntry(key, &entry)); | 1361 ASSERT_EQ(net::OK, CreateEntry(key, &entry)); |
1382 | 1362 |
1383 // Write to an external file. | 1363 // Write to an external file. |
1384 const int kSize = 20000; | 1364 const int kSize = 20000; |
1385 scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(kSize)); | 1365 scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(kSize)); |
1386 CacheTestFillBuffer(buffer->data(), kSize, false); | 1366 CacheTestFillBuffer(buffer->data(), kSize, false); |
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1772 entry1->Close(); | 1752 entry1->Close(); |
1773 entry2->Close(); | 1753 entry2->Close(); |
1774 FlushQueueForTest(); | 1754 FlushQueueForTest(); |
1775 if (memory_only_) | 1755 if (memory_only_) |
1776 EXPECT_EQ(2, cache_->GetEntryCount()); | 1756 EXPECT_EQ(2, cache_->GetEntryCount()); |
1777 else | 1757 else |
1778 EXPECT_EQ(3, cache_->GetEntryCount()); | 1758 EXPECT_EQ(3, cache_->GetEntryCount()); |
1779 } | 1759 } |
1780 | 1760 |
1781 TEST_F(DiskCacheEntryTest, UpdateSparseEntry) { | 1761 TEST_F(DiskCacheEntryTest, UpdateSparseEntry) { |
1782 SetDirectMode(); | |
1783 SetCacheType(net::MEDIA_CACHE); | 1762 SetCacheType(net::MEDIA_CACHE); |
1784 InitCache(); | 1763 InitCache(); |
1785 UpdateSparseEntry(); | 1764 UpdateSparseEntry(); |
1786 } | 1765 } |
1787 | 1766 |
1788 TEST_F(DiskCacheEntryTest, MemoryOnlyUpdateSparseEntry) { | 1767 TEST_F(DiskCacheEntryTest, MemoryOnlyUpdateSparseEntry) { |
1789 SetMemoryOnlyMode(); | 1768 SetMemoryOnlyMode(); |
1790 SetCacheType(net::MEDIA_CACHE); | 1769 SetCacheType(net::MEDIA_CACHE); |
1791 InitCache(); | 1770 InitCache(); |
1792 UpdateSparseEntry(); | 1771 UpdateSparseEntry(); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1843 // (it's always async on Posix so it is easy to miss). Unfortunately we | 1822 // (it's always async on Posix so it is easy to miss). Unfortunately we |
1844 // don't have any signal to watch for so we can only wait. | 1823 // don't have any signal to watch for so we can only wait. |
1845 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(500)); | 1824 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(500)); |
1846 MessageLoop::current()->RunUntilIdle(); | 1825 MessageLoop::current()->RunUntilIdle(); |
1847 } | 1826 } |
1848 EXPECT_EQ(0, cache_->GetEntryCount()); | 1827 EXPECT_EQ(0, cache_->GetEntryCount()); |
1849 } | 1828 } |
1850 } | 1829 } |
1851 | 1830 |
1852 TEST_F(DiskCacheEntryTest, DoomSparseEntry) { | 1831 TEST_F(DiskCacheEntryTest, DoomSparseEntry) { |
1853 SetDirectMode(); | |
1854 UseCurrentThread(); | 1832 UseCurrentThread(); |
1855 InitCache(); | 1833 InitCache(); |
1856 DoomSparseEntry(); | 1834 DoomSparseEntry(); |
1857 } | 1835 } |
1858 | 1836 |
1859 TEST_F(DiskCacheEntryTest, MemoryOnlyDoomSparseEntry) { | 1837 TEST_F(DiskCacheEntryTest, MemoryOnlyDoomSparseEntry) { |
1860 SetMemoryOnlyMode(); | 1838 SetMemoryOnlyMode(); |
1861 InitCache(); | 1839 InitCache(); |
1862 DoomSparseEntry(); | 1840 DoomSparseEntry(); |
1863 } | 1841 } |
(...skipping 14 matching lines...) Expand all Loading... |
1878 TestCompletionCallback::SetResult(result); | 1856 TestCompletionCallback::SetResult(result); |
1879 } | 1857 } |
1880 | 1858 |
1881 disk_cache::Backend* cache_; | 1859 disk_cache::Backend* cache_; |
1882 DISALLOW_COPY_AND_ASSIGN(SparseTestCompletionCallback); | 1860 DISALLOW_COPY_AND_ASSIGN(SparseTestCompletionCallback); |
1883 }; | 1861 }; |
1884 | 1862 |
1885 // Tests that we don't crash when the backend is deleted while we are working | 1863 // Tests that we don't crash when the backend is deleted while we are working |
1886 // deleting the sub-entries of a sparse entry. | 1864 // deleting the sub-entries of a sparse entry. |
1887 TEST_F(DiskCacheEntryTest, DoomSparseEntry2) { | 1865 TEST_F(DiskCacheEntryTest, DoomSparseEntry2) { |
1888 SetDirectMode(); | |
1889 UseCurrentThread(); | 1866 UseCurrentThread(); |
1890 InitCache(); | 1867 InitCache(); |
1891 std::string key("the key"); | 1868 std::string key("the key"); |
1892 disk_cache::Entry* entry; | 1869 disk_cache::Entry* entry; |
1893 ASSERT_EQ(net::OK, CreateEntry(key, &entry)); | 1870 ASSERT_EQ(net::OK, CreateEntry(key, &entry)); |
1894 | 1871 |
1895 const int kSize = 4 * 1024; | 1872 const int kSize = 4 * 1024; |
1896 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(kSize)); | 1873 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(kSize)); |
1897 CacheTestFillBuffer(buf->data(), kSize, false); | 1874 CacheTestFillBuffer(buf->data(), kSize, false); |
1898 | 1875 |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2134 store->key_len = 800; | 2111 store->key_len = 800; |
2135 memset(store->key + key.size(), 'k', sizeof(store->key) - key.size()); | 2112 memset(store->key + key.size(), 'k', sizeof(store->key) - key.size()); |
2136 entry_impl->entry()->set_modified(); | 2113 entry_impl->entry()->set_modified(); |
2137 entry->Close(); | 2114 entry->Close(); |
2138 | 2115 |
2139 // We have a corrupt entry. Now reload it. We should NOT read beyond the | 2116 // We have a corrupt entry. Now reload it. We should NOT read beyond the |
2140 // allocated buffer here. | 2117 // allocated buffer here. |
2141 ASSERT_NE(net::OK, OpenEntry(key, &entry)); | 2118 ASSERT_NE(net::OK, OpenEntry(key, &entry)); |
2142 DisableIntegrityCheck(); | 2119 DisableIntegrityCheck(); |
2143 } | 2120 } |
OLD | NEW |