| 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 1081 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1092 | 1092 |
| 1093 // If the LRU is corrupt, we delete the cache. | 1093 // If the LRU is corrupt, we delete the cache. |
| 1094 void DiskCacheBackendTest::BackendInvalidRankings() { | 1094 void DiskCacheBackendTest::BackendInvalidRankings() { |
| 1095 disk_cache::Entry* entry; | 1095 disk_cache::Entry* entry; |
| 1096 void* iter = NULL; | 1096 void* iter = NULL; |
| 1097 ASSERT_TRUE(cache_->OpenNextEntry(&iter, &entry)); | 1097 ASSERT_TRUE(cache_->OpenNextEntry(&iter, &entry)); |
| 1098 entry->Close(); | 1098 entry->Close(); |
| 1099 EXPECT_EQ(2, cache_->GetEntryCount()); | 1099 EXPECT_EQ(2, cache_->GetEntryCount()); |
| 1100 | 1100 |
| 1101 EXPECT_FALSE(cache_->OpenNextEntry(&iter, &entry)); | 1101 EXPECT_FALSE(cache_->OpenNextEntry(&iter, &entry)); |
| 1102 MessageLoop::current()->RunAllPending(); |
| 1102 EXPECT_EQ(0, cache_->GetEntryCount()); | 1103 EXPECT_EQ(0, cache_->GetEntryCount()); |
| 1103 } | 1104 } |
| 1104 | 1105 |
| 1105 TEST_F(DiskCacheBackendTest, InvalidRankingsSuccess) { | 1106 TEST_F(DiskCacheBackendTest, InvalidRankingsSuccess) { |
| 1106 ASSERT_TRUE(CopyTestCache(L"bad_rankings")); | 1107 ASSERT_TRUE(CopyTestCache(L"bad_rankings")); |
| 1107 DisableFirstCleanup(); | 1108 DisableFirstCleanup(); |
| 1108 SetDirectMode(); | 1109 SetDirectMode(); |
| 1109 InitCache(); | 1110 InitCache(); |
| 1110 BackendInvalidRankings(); | 1111 BackendInvalidRankings(); |
| 1111 } | 1112 } |
| (...skipping 30 matching lines...) Expand all Loading... |
| 1142 void DiskCacheBackendTest::BackendDisable() { | 1143 void DiskCacheBackendTest::BackendDisable() { |
| 1143 disk_cache::Entry *entry1, *entry2; | 1144 disk_cache::Entry *entry1, *entry2; |
| 1144 void* iter = NULL; | 1145 void* iter = NULL; |
| 1145 ASSERT_TRUE(cache_->OpenNextEntry(&iter, &entry1)); | 1146 ASSERT_TRUE(cache_->OpenNextEntry(&iter, &entry1)); |
| 1146 | 1147 |
| 1147 EXPECT_FALSE(cache_->OpenNextEntry(&iter, &entry2)); | 1148 EXPECT_FALSE(cache_->OpenNextEntry(&iter, &entry2)); |
| 1148 EXPECT_EQ(2, cache_->GetEntryCount()); | 1149 EXPECT_EQ(2, cache_->GetEntryCount()); |
| 1149 EXPECT_FALSE(cache_->CreateEntry("Something new", &entry2)); | 1150 EXPECT_FALSE(cache_->CreateEntry("Something new", &entry2)); |
| 1150 | 1151 |
| 1151 entry1->Close(); | 1152 entry1->Close(); |
| 1153 MessageLoop::current()->RunAllPending(); |
| 1152 | 1154 |
| 1153 EXPECT_EQ(0, cache_->GetEntryCount()); | 1155 EXPECT_EQ(0, cache_->GetEntryCount()); |
| 1154 } | 1156 } |
| 1155 | 1157 |
| 1156 TEST_F(DiskCacheBackendTest, DisableSuccess) { | 1158 TEST_F(DiskCacheBackendTest, DisableSuccess) { |
| 1157 ASSERT_TRUE(CopyTestCache(L"bad_rankings")); | 1159 ASSERT_TRUE(CopyTestCache(L"bad_rankings")); |
| 1158 DisableFirstCleanup(); | 1160 DisableFirstCleanup(); |
| 1159 SetDirectMode(); | 1161 SetDirectMode(); |
| 1160 InitCache(); | 1162 InitCache(); |
| 1161 BackendDisable(); | 1163 BackendDisable(); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1196 disk_cache::Entry* entry; | 1198 disk_cache::Entry* entry; |
| 1197 void* iter = NULL; | 1199 void* iter = NULL; |
| 1198 int count = 0; | 1200 int count = 0; |
| 1199 while (cache_->OpenNextEntry(&iter, &entry)) { | 1201 while (cache_->OpenNextEntry(&iter, &entry)) { |
| 1200 ASSERT_TRUE(NULL != entry); | 1202 ASSERT_TRUE(NULL != entry); |
| 1201 entry->Close(); | 1203 entry->Close(); |
| 1202 count++; | 1204 count++; |
| 1203 ASSERT_LT(count, 9); | 1205 ASSERT_LT(count, 9); |
| 1204 }; | 1206 }; |
| 1205 | 1207 |
| 1208 MessageLoop::current()->RunAllPending(); |
| 1206 EXPECT_EQ(0, cache_->GetEntryCount()); | 1209 EXPECT_EQ(0, cache_->GetEntryCount()); |
| 1207 } | 1210 } |
| 1208 | 1211 |
| 1209 TEST_F(DiskCacheBackendTest, DisableSuccess2) { | 1212 TEST_F(DiskCacheBackendTest, DisableSuccess2) { |
| 1210 ASSERT_TRUE(CopyTestCache(L"list_loop")); | 1213 ASSERT_TRUE(CopyTestCache(L"list_loop")); |
| 1211 DisableFirstCleanup(); | 1214 DisableFirstCleanup(); |
| 1212 SetDirectMode(); | 1215 SetDirectMode(); |
| 1213 InitCache(); | 1216 InitCache(); |
| 1214 BackendDisable2(); | 1217 BackendDisable2(); |
| 1215 } | 1218 } |
| (...skipping 28 matching lines...) Expand all Loading... |
| 1244 | 1247 |
| 1245 // If the index size changes when we disable the cache, we should not crash. | 1248 // If the index size changes when we disable the cache, we should not crash. |
| 1246 void DiskCacheBackendTest::BackendDisable3() { | 1249 void DiskCacheBackendTest::BackendDisable3() { |
| 1247 disk_cache::Entry *entry1, *entry2; | 1250 disk_cache::Entry *entry1, *entry2; |
| 1248 void* iter = NULL; | 1251 void* iter = NULL; |
| 1249 EXPECT_EQ(2, cache_->GetEntryCount()); | 1252 EXPECT_EQ(2, cache_->GetEntryCount()); |
| 1250 ASSERT_TRUE(cache_->OpenNextEntry(&iter, &entry1)); | 1253 ASSERT_TRUE(cache_->OpenNextEntry(&iter, &entry1)); |
| 1251 entry1->Close(); | 1254 entry1->Close(); |
| 1252 | 1255 |
| 1253 EXPECT_FALSE(cache_->OpenNextEntry(&iter, &entry2)); | 1256 EXPECT_FALSE(cache_->OpenNextEntry(&iter, &entry2)); |
| 1257 MessageLoop::current()->RunAllPending(); |
| 1258 |
| 1254 ASSERT_TRUE(cache_->CreateEntry("Something new", &entry2)); | 1259 ASSERT_TRUE(cache_->CreateEntry("Something new", &entry2)); |
| 1255 entry2->Close(); | 1260 entry2->Close(); |
| 1256 | 1261 |
| 1257 EXPECT_EQ(1, cache_->GetEntryCount()); | 1262 EXPECT_EQ(1, cache_->GetEntryCount()); |
| 1258 } | 1263 } |
| 1259 | 1264 |
| 1260 TEST_F(DiskCacheBackendTest, DisableSuccess3) { | 1265 TEST_F(DiskCacheBackendTest, DisableSuccess3) { |
| 1261 ASSERT_TRUE(CopyTestCache(L"bad_rankings2")); | 1266 ASSERT_TRUE(CopyTestCache(L"bad_rankings2")); |
| 1262 DisableFirstCleanup(); | 1267 DisableFirstCleanup(); |
| 1263 SetMaxSize(20 * 1024 * 1024); | 1268 SetMaxSize(20 * 1024 * 1024); |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1421 EXPECT_EQ(kDefaultSize * 5 / 2, | 1426 EXPECT_EQ(kDefaultSize * 5 / 2, |
| 1422 disk_cache::PreferedCacheSize(large_size * 100 / 2)); | 1427 disk_cache::PreferedCacheSize(large_size * 100 / 2)); |
| 1423 EXPECT_EQ(kDefaultSize * 5 / 2, | 1428 EXPECT_EQ(kDefaultSize * 5 / 2, |
| 1424 disk_cache::PreferedCacheSize(large_size * 500 / 2)); | 1429 disk_cache::PreferedCacheSize(large_size * 500 / 2)); |
| 1425 | 1430 |
| 1426 EXPECT_EQ(kDefaultSize * 6 / 2, | 1431 EXPECT_EQ(kDefaultSize * 6 / 2, |
| 1427 disk_cache::PreferedCacheSize(large_size * 600 / 2)); | 1432 disk_cache::PreferedCacheSize(large_size * 600 / 2)); |
| 1428 EXPECT_EQ(kDefaultSize * 7 / 2, | 1433 EXPECT_EQ(kDefaultSize * 7 / 2, |
| 1429 disk_cache::PreferedCacheSize(large_size * 700 / 2)); | 1434 disk_cache::PreferedCacheSize(large_size * 700 / 2)); |
| 1430 } | 1435 } |
| OLD | NEW |