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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 void BackendRecoverRemove(); | 60 void BackendRecoverRemove(); |
61 void BackendInvalidEntry2(); | 61 void BackendInvalidEntry2(); |
62 void BackendNotMarkedButDirty(const std::wstring& name); | 62 void BackendNotMarkedButDirty(const std::wstring& name); |
63 void BackendDoomAll(); | 63 void BackendDoomAll(); |
64 void BackendDoomAll2(); | 64 void BackendDoomAll2(); |
65 void BackendInvalidRankings(); | 65 void BackendInvalidRankings(); |
66 void BackendInvalidRankings2(); | 66 void BackendInvalidRankings2(); |
67 void BackendDisable(); | 67 void BackendDisable(); |
68 void BackendDisable2(); | 68 void BackendDisable2(); |
69 void BackendDisable3(); | 69 void BackendDisable3(); |
| 70 void BackendDisable4(); |
70 }; | 71 }; |
71 | 72 |
72 void DiskCacheBackendTest::BackendBasics() { | 73 void DiskCacheBackendTest::BackendBasics() { |
73 InitCache(); | 74 InitCache(); |
74 disk_cache::Entry *entry1 = NULL, *entry2 = NULL; | 75 disk_cache::Entry *entry1 = NULL, *entry2 = NULL; |
75 EXPECT_FALSE(cache_->OpenEntry("the first key", &entry1)); | 76 EXPECT_FALSE(cache_->OpenEntry("the first key", &entry1)); |
76 ASSERT_TRUE(cache_->CreateEntry("the first key", &entry1)); | 77 ASSERT_TRUE(cache_->CreateEntry("the first key", &entry1)); |
77 ASSERT_TRUE(NULL != entry1); | 78 ASSERT_TRUE(NULL != entry1); |
78 entry1->Close(); | 79 entry1->Close(); |
79 entry1 = NULL; | 80 entry1 = NULL; |
(...skipping 1237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1317 | 1318 |
1318 TEST_F(DiskCacheBackendTest, NewEvictionDisableSuccess3) { | 1319 TEST_F(DiskCacheBackendTest, NewEvictionDisableSuccess3) { |
1319 ASSERT_TRUE(CopyTestCache(L"bad_rankings2")); | 1320 ASSERT_TRUE(CopyTestCache(L"bad_rankings2")); |
1320 DisableFirstCleanup(); | 1321 DisableFirstCleanup(); |
1321 SetMaxSize(20 * 1024 * 1024); | 1322 SetMaxSize(20 * 1024 * 1024); |
1322 SetNewEviction(); | 1323 SetNewEviction(); |
1323 InitCache(); | 1324 InitCache(); |
1324 BackendDisable3(); | 1325 BackendDisable3(); |
1325 } | 1326 } |
1326 | 1327 |
| 1328 // If we disable the cache, already open entries should work as far as possible. |
| 1329 void DiskCacheBackendTest::BackendDisable4() { |
| 1330 disk_cache::Entry *entry1, *entry2, *entry3, *entry4; |
| 1331 void* iter = NULL; |
| 1332 ASSERT_TRUE(cache_->OpenNextEntry(&iter, &entry1)); |
| 1333 |
| 1334 char key2[2000]; |
| 1335 char key3[20000]; |
| 1336 CacheTestFillBuffer(key2, sizeof(key2), true); |
| 1337 CacheTestFillBuffer(key3, sizeof(key3), true); |
| 1338 key2[sizeof(key2) - 1] = '\0'; |
| 1339 key3[sizeof(key3) - 1] = '\0'; |
| 1340 ASSERT_TRUE(cache_->CreateEntry(key2, &entry2)); |
| 1341 ASSERT_TRUE(cache_->CreateEntry(key3, &entry3)); |
| 1342 |
| 1343 const int kBufSize = 20000; |
| 1344 scoped_refptr<net::IOBuffer> buf = new net::IOBuffer(kBufSize); |
| 1345 memset(buf->data(), 0, kBufSize); |
| 1346 EXPECT_EQ(100, entry2->WriteData(0, 0, buf, 100, NULL, false)); |
| 1347 EXPECT_EQ(kBufSize, entry3->WriteData(0, 0, buf, kBufSize, NULL, false)); |
| 1348 |
| 1349 // This line should disable the cache but not delete it. |
| 1350 EXPECT_FALSE(cache_->OpenNextEntry(&iter, &entry4)); |
| 1351 EXPECT_EQ(4, cache_->GetEntryCount()); |
| 1352 |
| 1353 EXPECT_FALSE(cache_->CreateEntry("cache is disabled", &entry4)); |
| 1354 |
| 1355 EXPECT_EQ(100, entry2->ReadData(0, 0, buf, 100, NULL)); |
| 1356 EXPECT_EQ(100, entry2->WriteData(0, 0, buf, 100, NULL, false)); |
| 1357 EXPECT_EQ(100, entry2->WriteData(1, 0, buf, 100, NULL, false)); |
| 1358 |
| 1359 EXPECT_EQ(kBufSize, entry3->ReadData(0, 0, buf, kBufSize, NULL)); |
| 1360 EXPECT_EQ(kBufSize, entry3->WriteData(0, 0, buf, kBufSize, NULL, false)); |
| 1361 EXPECT_EQ(kBufSize, entry3->WriteData(1, 0, buf, kBufSize, NULL, false)); |
| 1362 |
| 1363 std::string key = entry2->GetKey(); |
| 1364 EXPECT_EQ(sizeof(key2) - 1, key.size()); |
| 1365 key = entry3->GetKey(); |
| 1366 EXPECT_EQ(sizeof(key3) - 1, key.size()); |
| 1367 |
| 1368 entry1->Close(); |
| 1369 entry2->Close(); |
| 1370 entry3->Close(); |
| 1371 MessageLoop::current()->RunAllPending(); |
| 1372 |
| 1373 EXPECT_EQ(0, cache_->GetEntryCount()); |
| 1374 } |
| 1375 |
| 1376 TEST_F(DiskCacheBackendTest, DisableSuccess4) { |
| 1377 ASSERT_TRUE(CopyTestCache(L"bad_rankings")); |
| 1378 DisableFirstCleanup(); |
| 1379 SetDirectMode(); |
| 1380 InitCache(); |
| 1381 BackendDisable4(); |
| 1382 } |
| 1383 |
| 1384 TEST_F(DiskCacheBackendTest, NewEvictionDisableSuccess4) { |
| 1385 ASSERT_TRUE(CopyTestCache(L"bad_rankings")); |
| 1386 DisableFirstCleanup(); |
| 1387 SetDirectMode(); |
| 1388 SetNewEviction(); |
| 1389 InitCache(); |
| 1390 BackendDisable4(); |
| 1391 } |
| 1392 |
1327 TEST_F(DiskCacheTest, Backend_UsageStats) { | 1393 TEST_F(DiskCacheTest, Backend_UsageStats) { |
1328 MessageLoopHelper helper; | 1394 MessageLoopHelper helper; |
1329 | 1395 |
1330 std::wstring path = GetCachePath(); | 1396 std::wstring path = GetCachePath(); |
1331 ASSERT_TRUE(DeleteCache(path.c_str())); | 1397 ASSERT_TRUE(DeleteCache(path.c_str())); |
1332 scoped_ptr<disk_cache::BackendImpl> cache; | 1398 scoped_ptr<disk_cache::BackendImpl> cache; |
1333 cache.reset(new disk_cache::BackendImpl(path)); | 1399 cache.reset(new disk_cache::BackendImpl(path)); |
1334 ASSERT_TRUE(NULL != cache.get()); | 1400 ASSERT_TRUE(NULL != cache.get()); |
1335 cache->SetUnitTestMode(); | 1401 cache->SetUnitTestMode(); |
1336 ASSERT_TRUE(cache->Init()); | 1402 ASSERT_TRUE(cache->Init()); |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1471 EXPECT_EQ(kDefaultSize * 5 / 2, | 1537 EXPECT_EQ(kDefaultSize * 5 / 2, |
1472 disk_cache::PreferedCacheSize(large_size * 100 / 2)); | 1538 disk_cache::PreferedCacheSize(large_size * 100 / 2)); |
1473 EXPECT_EQ(kDefaultSize * 5 / 2, | 1539 EXPECT_EQ(kDefaultSize * 5 / 2, |
1474 disk_cache::PreferedCacheSize(large_size * 500 / 2)); | 1540 disk_cache::PreferedCacheSize(large_size * 500 / 2)); |
1475 | 1541 |
1476 EXPECT_EQ(kDefaultSize * 6 / 2, | 1542 EXPECT_EQ(kDefaultSize * 6 / 2, |
1477 disk_cache::PreferedCacheSize(large_size * 600 / 2)); | 1543 disk_cache::PreferedCacheSize(large_size * 600 / 2)); |
1478 EXPECT_EQ(kDefaultSize * 7 / 2, | 1544 EXPECT_EQ(kDefaultSize * 7 / 2, |
1479 disk_cache::PreferedCacheSize(large_size * 700 / 2)); | 1545 disk_cache::PreferedCacheSize(large_size * 700 / 2)); |
1480 } | 1546 } |
OLD | NEW |