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