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

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

Issue 6292011: Disk cache: Prevent obscure file corruption and deal... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 11 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/string_util.h" 7 #include "base/string_util.h"
8 #include "base/stringprintf.h" 8 #include "base/stringprintf.h"
9 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" 9 #include "base/third_party/dynamic_annotations/dynamic_annotations.h"
10 #include "base/threading/platform_thread.h" 10 #include "base/threading/platform_thread.h"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 void BackendEnumerations(); 42 void BackendEnumerations();
43 void BackendEnumerations2(); 43 void BackendEnumerations2();
44 void BackendInvalidEntryEnumeration(); 44 void BackendInvalidEntryEnumeration();
45 void BackendFixEnumerators(); 45 void BackendFixEnumerators();
46 void BackendDoomRecent(); 46 void BackendDoomRecent();
47 void BackendDoomBetween(); 47 void BackendDoomBetween();
48 void BackendTransaction(const std::string& name, int num_entries, bool load); 48 void BackendTransaction(const std::string& name, int num_entries, bool load);
49 void BackendRecoverInsert(); 49 void BackendRecoverInsert();
50 void BackendRecoverRemove(); 50 void BackendRecoverRemove();
51 void BackendInvalidEntry2(); 51 void BackendInvalidEntry2();
52 void BackendInvalidEntry3();
52 void BackendNotMarkedButDirty(const std::string& name); 53 void BackendNotMarkedButDirty(const std::string& name);
53 void BackendDoomAll(); 54 void BackendDoomAll();
54 void BackendDoomAll2(); 55 void BackendDoomAll2();
55 void BackendInvalidRankings(); 56 void BackendInvalidRankings();
56 void BackendInvalidRankings2(); 57 void BackendInvalidRankings2();
57 void BackendDisable(); 58 void BackendDisable();
58 void BackendDisable2(); 59 void BackendDisable2();
59 void BackendDisable3(); 60 void BackendDisable3();
60 void BackendDisable4(); 61 void BackendDisable4();
61 }; 62 };
(...skipping 1249 matching lines...) Expand 10 before | Expand all | Expand 10 after
1311 1312
1312 TEST_F(DiskCacheBackendTest, InvalidEntry2) { 1313 TEST_F(DiskCacheBackendTest, InvalidEntry2) {
1313 BackendInvalidEntry2(); 1314 BackendInvalidEntry2();
1314 } 1315 }
1315 1316
1316 TEST_F(DiskCacheBackendTest, NewEvictionInvalidEntry2) { 1317 TEST_F(DiskCacheBackendTest, NewEvictionInvalidEntry2) {
1317 SetNewEviction(); 1318 SetNewEviction();
1318 BackendInvalidEntry2(); 1319 BackendInvalidEntry2();
1319 } 1320 }
1320 1321
1322 // Tests that we don't crash or hang when enumerating this cache.
1323 void DiskCacheBackendTest::BackendInvalidEntry3() {
1324 SetMask(0x1); // 2-entry table.
1325 SetMaxSize(0x3000); // 12 kB.
1326 DisableFirstCleanup();
1327 InitCache();
1328
1329 disk_cache::Entry* entry;
1330 void* iter = NULL;
1331 while (OpenNextEntry(&iter, &entry) == net::OK) {
1332 entry->Close();
1333 }
1334 }
1335
1336 TEST_F(DiskCacheBackendTest, InvalidEntry3) {
1337 ASSERT_TRUE(CopyTestCache("dirty_entry3"));
1338 BackendInvalidEntry3();
1339 }
1340
1321 TEST_F(DiskCacheBackendTest, NewEvictionInvalidEntry3) { 1341 TEST_F(DiskCacheBackendTest, NewEvictionInvalidEntry3) {
1342 ASSERT_TRUE(CopyTestCache("dirty_entry4"));
1343 SetNewEviction();
1344 BackendInvalidEntry3();
1345 DisableIntegrityCheck();
1346 }
1347
1348 // Test that we handle a dirty entry on the LRU list, already replaced with
1349 // the same key, and with hash collisions.
1350 TEST_F(DiskCacheBackendTest, InvalidEntry4) {
1351 ASSERT_TRUE(CopyTestCache("dirty_entry3"));
1352 SetMask(0x1); // 2-entry table.
1353 SetMaxSize(0x3000); // 12 kB.
1354 DisableFirstCleanup();
1355 InitCache();
1356
1357 TrimForTest(false);
1358 }
1359
1360 // Test that we handle a dirty entry on the deleted list, already replaced with
1361 // the same key, and with hash collisions.
1362 TEST_F(DiskCacheBackendTest, InvalidEntry5) {
1363 ASSERT_TRUE(CopyTestCache("dirty_entry4"));
1364 SetNewEviction();
1365 SetMask(0x1); // 2-entry table.
1366 SetMaxSize(0x3000); // 12 kB.
1367 DisableFirstCleanup();
1368 InitCache();
1369
1370 TrimDeletedListForTest(false);
1371 }
1372
1373 // Tests that we don't hang when there is a loop on the hash collision list.
1374 // The test cache could be a result of bug 69135.
1375 TEST_F(DiskCacheBackendTest, BadNextEntry1) {
1376 ASSERT_TRUE(CopyTestCache("list_loop2"));
1377 SetMask(0x1); // 2-entry table.
1378 SetMaxSize(0x3000); // 12 kB.
1379 DisableFirstCleanup();
1380 InitCache();
1381
1382 // The second entry points at itselft, and the first entry is not accessible
1383 // though the index, but it is at the head of the LRU.
1384
1385 disk_cache::Entry* entry;
1386 ASSERT_EQ(net::OK, CreateEntry("The first key", &entry));
1387 entry->Close();
1388
1389 TrimForTest(false);
1390 TrimForTest(false);
1391 ASSERT_EQ(net::OK, OpenEntry("The first key", &entry));
1392 entry->Close();
1393 EXPECT_EQ(1, cache_->GetEntryCount());
1394 }
1395
1396 // Tests that we don't hang when there is a loop on the hash collision list.
1397 // The test cache could be a result of bug 69135.
1398 TEST_F(DiskCacheBackendTest, BadNextEntry2) {
1399 ASSERT_TRUE(CopyTestCache("list_loop3"));
1400 SetMask(0x1); // 2-entry table.
1401 SetMaxSize(0x3000); // 12 kB.
1402 DisableFirstCleanup();
1403 InitCache();
1404
1405 // There is a wide loop of 5 entries.
1406
1407 disk_cache::Entry* entry;
1408 ASSERT_NE(net::OK, OpenEntry("Not present key", &entry));
1409 }
1410
1411 TEST_F(DiskCacheBackendTest, NewEvictionInvalidEntry6) {
1322 ASSERT_TRUE(CopyTestCache("bad_rankings3")); 1412 ASSERT_TRUE(CopyTestCache("bad_rankings3"));
1323 DisableFirstCleanup(); 1413 DisableFirstCleanup();
1324 SetNewEviction(); 1414 SetNewEviction();
1325 InitCache(); 1415 InitCache();
1326 1416
1327 // The second entry is dirty, but removing it should not corrupt the list. 1417 // The second entry is dirty, but removing it should not corrupt the list.
1328 disk_cache::Entry* entry; 1418 disk_cache::Entry* entry;
1329 ASSERT_NE(net::OK, OpenEntry("the second key", &entry)); 1419 ASSERT_NE(net::OK, OpenEntry("the second key", &entry));
1330 ASSERT_EQ(net::OK, OpenEntry("the first key", &entry)); 1420 ASSERT_EQ(net::OK, OpenEntry("the first key", &entry));
1331 1421
(...skipping 618 matching lines...) Expand 10 before | Expand all | Expand 10 after
1950 char buffer1[kSize]; 2040 char buffer1[kSize];
1951 char buffer2[kSize]; 2041 char buffer2[kSize];
1952 memset(buffer1, 't', kSize); 2042 memset(buffer1, 't', kSize);
1953 memset(buffer2, 0, kSize); 2043 memset(buffer2, 0, kSize);
1954 EXPECT_TRUE(file->Write(buffer1, kSize, 0)); 2044 EXPECT_TRUE(file->Write(buffer1, kSize, 0));
1955 EXPECT_TRUE(file->Read(buffer2, kSize, 0)); 2045 EXPECT_TRUE(file->Read(buffer2, kSize, 0));
1956 EXPECT_EQ(0, memcmp(buffer1, buffer2, kSize)); 2046 EXPECT_EQ(0, memcmp(buffer1, buffer2, kSize));
1957 2047
1958 EXPECT_TRUE(disk_cache::DeleteCacheFile(name)); 2048 EXPECT_TRUE(disk_cache::DeleteCacheFile(name));
1959 } 2049 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698