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

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

Issue 12951014: Fix bug in MemEntryImpl, which caused browser crash during clearing (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: Created 7 years, 8 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
« no previous file with comments | « AUTHORS ('k') | net/disk_cache/mem_backend_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/file_util.h" 6 #include "base/file_util.h"
7 #include "base/port.h" 7 #include "base/port.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "base/stringprintf.h" 9 #include "base/stringprintf.h"
10 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" 10 #include "base/third_party/dynamic_annotations/dynamic_annotations.h"
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 void BackendInvalidEntry(); 47 void BackendInvalidEntry();
48 void BackendInvalidEntryRead(); 48 void BackendInvalidEntryRead();
49 void BackendInvalidEntryWithLoad(); 49 void BackendInvalidEntryWithLoad();
50 void BackendTrimInvalidEntry(); 50 void BackendTrimInvalidEntry();
51 void BackendTrimInvalidEntry2(); 51 void BackendTrimInvalidEntry2();
52 void BackendEnumerations(); 52 void BackendEnumerations();
53 void BackendEnumerations2(); 53 void BackendEnumerations2();
54 void BackendInvalidEntryEnumeration(); 54 void BackendInvalidEntryEnumeration();
55 void BackendFixEnumerators(); 55 void BackendFixEnumerators();
56 void BackendDoomRecent(); 56 void BackendDoomRecent();
57
58 // Adds 5 sparse entries. |doomed_start| and |doomed_end| if not NULL,
59 // will be filled with times, used by DoomEntriesSince and DoomEntriesBetween.
60 // There are 4 entries after doomed_start and 2 after doomed_end.
61 void InitSparseCache(base::Time* doomed_start, base::Time* doomed_end);
62
57 void BackendDoomBetween(); 63 void BackendDoomBetween();
58 void BackendTransaction(const std::string& name, int num_entries, bool load); 64 void BackendTransaction(const std::string& name, int num_entries, bool load);
59 void BackendRecoverInsert(); 65 void BackendRecoverInsert();
60 void BackendRecoverRemove(); 66 void BackendRecoverRemove();
61 void BackendRecoverWithEviction(); 67 void BackendRecoverWithEviction();
62 void BackendInvalidEntry2(); 68 void BackendInvalidEntry2();
63 void BackendInvalidEntry3(); 69 void BackendInvalidEntry3();
64 void BackendInvalidEntry7(); 70 void BackendInvalidEntry7();
65 void BackendInvalidEntry8(); 71 void BackendInvalidEntry8();
66 void BackendInvalidEntry9(bool eviction); 72 void BackendInvalidEntry9(bool eviction);
(...skipping 1260 matching lines...) Expand 10 before | Expand all | Expand 10 after
1327 TEST_F(DiskCacheBackendTest, NewEvictionDoomRecent) { 1333 TEST_F(DiskCacheBackendTest, NewEvictionDoomRecent) {
1328 SetNewEviction(); 1334 SetNewEviction();
1329 BackendDoomRecent(); 1335 BackendDoomRecent();
1330 } 1336 }
1331 1337
1332 TEST_F(DiskCacheBackendTest, MemoryOnlyDoomRecent) { 1338 TEST_F(DiskCacheBackendTest, MemoryOnlyDoomRecent) {
1333 SetMemoryOnlyMode(); 1339 SetMemoryOnlyMode();
1334 BackendDoomRecent(); 1340 BackendDoomRecent();
1335 } 1341 }
1336 1342
1343 void DiskCacheBackendTest::InitSparseCache(base::Time* doomed_start,
1344 base::Time* doomed_end) {
1345 InitCache();
1346
1347 const int kSize = 50;
1348 // This must be greater then MemEntryImpl::kMaxSparseEntrySize.
1349 const int kOffset = 10 + 1024 * 1024;
1350
1351 disk_cache::Entry* entry0 = NULL;
1352 disk_cache::Entry* entry1 = NULL;
1353 disk_cache::Entry* entry2 = NULL;
1354
1355 scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(kSize));
1356 CacheTestFillBuffer(buffer->data(), kSize, false);
1357
1358 ASSERT_EQ(net::OK, CreateEntry("zeroth", &entry0));
1359 ASSERT_EQ(kSize, WriteSparseData(entry0, 0, buffer.get(), kSize));
1360 ASSERT_EQ(kSize,
1361 WriteSparseData(entry0, kOffset + kSize, buffer.get(), kSize));
1362 entry0->Close();
1363
1364 FlushQueueForTest();
1365 AddDelay();
1366 if (doomed_start)
1367 *doomed_start = base::Time::Now();
1368
1369 // Order in rankings list:
1370 // first_part1, first_part2, second_part1, second_part2
1371 ASSERT_EQ(net::OK, CreateEntry("first", &entry1));
1372 ASSERT_EQ(kSize, WriteSparseData(entry1, 0, buffer.get(), kSize));
1373 ASSERT_EQ(kSize,
1374 WriteSparseData(entry1, kOffset + kSize, buffer.get(), kSize));
1375 entry1->Close();
1376
1377 ASSERT_EQ(net::OK, CreateEntry("second", &entry2));
1378 ASSERT_EQ(kSize, WriteSparseData(entry2, 0, buffer.get(), kSize));
1379 ASSERT_EQ(kSize,
1380 WriteSparseData(entry2, kOffset + kSize, buffer.get(), kSize));
1381 entry2->Close();
1382
1383 FlushQueueForTest();
1384 AddDelay();
1385 if (doomed_end)
1386 *doomed_end = base::Time::Now();
1387
1388 // Order in rankings list:
1389 // third_part1, fourth_part1, third_part2, fourth_part2
1390 disk_cache::Entry* entry3 = NULL;
1391 disk_cache::Entry* entry4 = NULL;
1392 ASSERT_EQ(net::OK, CreateEntry("third", &entry3));
1393 ASSERT_EQ(kSize, WriteSparseData(entry3, 0, buffer.get(), kSize));
1394 ASSERT_EQ(net::OK, CreateEntry("fourth", &entry4));
1395 ASSERT_EQ(kSize, WriteSparseData(entry4, 0, buffer.get(), kSize));
1396 ASSERT_EQ(kSize,
1397 WriteSparseData(entry3, kOffset + kSize, buffer.get(), kSize));
1398 ASSERT_EQ(kSize,
1399 WriteSparseData(entry4, kOffset + kSize, buffer.get(), kSize));
1400 entry3->Close();
1401 entry4->Close();
1402
1403 FlushQueueForTest();
1404 AddDelay();
1405 }
1406
1407 TEST_F(DiskCacheBackendTest, MemoryOnlyDoomEntriesSinceSparse) {
1408 SetMemoryOnlyMode();
1409 base::Time start;
1410 InitSparseCache(&start, NULL);
1411 DoomEntriesSince(start);
1412 EXPECT_EQ(1, cache_->GetEntryCount());
1413 }
1414
1415 TEST_F(DiskCacheBackendTest, DoomEntriesSinceSparse) {
1416 base::Time start;
1417 InitSparseCache(&start, NULL);
1418 DoomEntriesSince(start);
1419 // NOTE: BackendImpl counts child entries in its GetEntryCount(), while
1420 // MemBackendImpl does not. Thats why expected value differs here from
1421 // MemoryOnlyDoomEntriesSinceSparse.
1422 EXPECT_EQ(3, cache_->GetEntryCount());
1423 }
1424
1425 TEST_F(DiskCacheBackendTest, MemoryOnlyDoomAllSparse) {
1426 SetMemoryOnlyMode();
1427 InitSparseCache(NULL, NULL);
1428 EXPECT_EQ(net::OK, DoomAllEntries());
1429 EXPECT_EQ(0, cache_->GetEntryCount());
1430 }
1431
1432 TEST_F(DiskCacheBackendTest, DoomAllSparse) {
1433 InitSparseCache(NULL, NULL);
1434 EXPECT_EQ(net::OK, DoomAllEntries());
1435 EXPECT_EQ(0, cache_->GetEntryCount());
1436 }
1437
1337 void DiskCacheBackendTest::BackendDoomBetween() { 1438 void DiskCacheBackendTest::BackendDoomBetween() {
1338 InitCache(); 1439 InitCache();
1339 1440
1340 disk_cache::Entry *entry; 1441 disk_cache::Entry *entry;
1341 ASSERT_EQ(net::OK, CreateEntry("first", &entry)); 1442 ASSERT_EQ(net::OK, CreateEntry("first", &entry));
1342 entry->Close(); 1443 entry->Close();
1343 FlushQueueForTest(); 1444 FlushQueueForTest();
1344 1445
1345 AddDelay(); 1446 AddDelay();
1346 Time middle_start = Time::Now(); 1447 Time middle_start = Time::Now();
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1384 TEST_F(DiskCacheBackendTest, NewEvictionDoomBetween) { 1485 TEST_F(DiskCacheBackendTest, NewEvictionDoomBetween) {
1385 SetNewEviction(); 1486 SetNewEviction();
1386 BackendDoomBetween(); 1487 BackendDoomBetween();
1387 } 1488 }
1388 1489
1389 TEST_F(DiskCacheBackendTest, MemoryOnlyDoomBetween) { 1490 TEST_F(DiskCacheBackendTest, MemoryOnlyDoomBetween) {
1390 SetMemoryOnlyMode(); 1491 SetMemoryOnlyMode();
1391 BackendDoomBetween(); 1492 BackendDoomBetween();
1392 } 1493 }
1393 1494
1495 TEST_F(DiskCacheBackendTest, MemoryOnlyDoomEntriesBetweenSparse) {
1496 SetMemoryOnlyMode();
1497 base::Time start, end;
1498 InitSparseCache(&start, &end);
1499 DoomEntriesBetween(start, end);
1500 EXPECT_EQ(3, cache_->GetEntryCount());
1501
1502 start = end;
1503 end = base::Time::Now();
1504 DoomEntriesBetween(start, end);
1505 EXPECT_EQ(1, cache_->GetEntryCount());
1506 }
1507
1508 TEST_F(DiskCacheBackendTest, DoomEntriesBetweenSparse) {
1509 base::Time start, end;
1510 InitSparseCache(&start, &end);
1511 DoomEntriesBetween(start, end);
1512 EXPECT_EQ(9, cache_->GetEntryCount());
1513
1514 start = end;
1515 end = base::Time::Now();
1516 DoomEntriesBetween(start, end);
1517 EXPECT_EQ(3, cache_->GetEntryCount());
1518 }
1519
1394 void DiskCacheBackendTest::BackendTransaction(const std::string& name, 1520 void DiskCacheBackendTest::BackendTransaction(const std::string& name,
1395 int num_entries, bool load) { 1521 int num_entries, bool load) {
1396 success_ = false; 1522 success_ = false;
1397 ASSERT_TRUE(CopyTestCache(name)); 1523 ASSERT_TRUE(CopyTestCache(name));
1398 DisableFirstCleanup(); 1524 DisableFirstCleanup();
1399 1525
1400 uint32 mask; 1526 uint32 mask;
1401 if (load) { 1527 if (load) {
1402 mask = 0xf; 1528 mask = 0xf;
1403 SetMaxSize(0x100000); 1529 SetMaxSize(0x100000);
(...skipping 1363 matching lines...) Expand 10 before | Expand all | Expand 10 after
2767 disk_cache::SimpleFileHeader header; 2893 disk_cache::SimpleFileHeader header;
2768 header.initial_magic_number = GG_UINT64_C(0xbadf00d); 2894 header.initial_magic_number = GG_UINT64_C(0xbadf00d);
2769 EXPECT_EQ( 2895 EXPECT_EQ(
2770 implicit_cast<int>(sizeof(header)), 2896 implicit_cast<int>(sizeof(header)),
2771 file_util::WriteFile(entry_file1_path, reinterpret_cast<char*>(&header), 2897 file_util::WriteFile(entry_file1_path, reinterpret_cast<char*>(&header),
2772 sizeof(header))); 2898 sizeof(header)));
2773 ASSERT_EQ(net::ERR_FAILED, OpenEntry(key, &entry)); 2899 ASSERT_EQ(net::ERR_FAILED, OpenEntry(key, &entry));
2774 } 2900 }
2775 2901
2776 #endif // !defined(OS_WIN) 2902 #endif // !defined(OS_WIN)
OLDNEW
« no previous file with comments | « AUTHORS ('k') | net/disk_cache/mem_backend_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698