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

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

Issue 266243004: Clang format slam. Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 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) 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/metrics/field_trial.h" 7 #include "base/metrics/field_trial.h"
8 #include "base/port.h" 8 #include "base/port.h"
9 #include "base/strings/string_util.h" 9 #include "base/strings/string_util.h"
10 #include "base/strings/stringprintf.h" 10 #include "base/strings/stringprintf.h"
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 ++(*count); 270 ++(*count);
271 if (max_to_open >= 0 && implicit_cast<int>(*count) >= max_to_open) 271 if (max_to_open >= 0 && implicit_cast<int>(*count) >= max_to_open)
272 break; 272 break;
273 }; 273 };
274 274
275 return true; 275 return true;
276 } 276 }
277 277
278 void DiskCacheBackendTest::BackendBasics() { 278 void DiskCacheBackendTest::BackendBasics() {
279 InitCache(); 279 InitCache();
280 disk_cache::Entry *entry1 = NULL, *entry2 = NULL; 280 disk_cache::Entry* entry1 = NULL, *entry2 = NULL;
281 EXPECT_NE(net::OK, OpenEntry("the first key", &entry1)); 281 EXPECT_NE(net::OK, OpenEntry("the first key", &entry1));
282 ASSERT_EQ(net::OK, CreateEntry("the first key", &entry1)); 282 ASSERT_EQ(net::OK, CreateEntry("the first key", &entry1));
283 ASSERT_TRUE(NULL != entry1); 283 ASSERT_TRUE(NULL != entry1);
284 entry1->Close(); 284 entry1->Close();
285 entry1 = NULL; 285 entry1 = NULL;
286 286
287 ASSERT_EQ(net::OK, OpenEntry("the first key", &entry1)); 287 ASSERT_EQ(net::OK, OpenEntry("the first key", &entry1));
288 ASSERT_TRUE(NULL != entry1); 288 ASSERT_TRUE(NULL != entry1);
289 entry1->Close(); 289 entry1->Close();
290 entry1 = NULL; 290 entry1 = NULL;
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 342
343 TEST_F(DiskCacheBackendTest, ShaderCacheBasics) { 343 TEST_F(DiskCacheBackendTest, ShaderCacheBasics) {
344 SetCacheType(net::SHADER_CACHE); 344 SetCacheType(net::SHADER_CACHE);
345 BackendBasics(); 345 BackendBasics();
346 } 346 }
347 347
348 void DiskCacheBackendTest::BackendKeying() { 348 void DiskCacheBackendTest::BackendKeying() {
349 InitCache(); 349 InitCache();
350 const char* kName1 = "the first key"; 350 const char* kName1 = "the first key";
351 const char* kName2 = "the first Key"; 351 const char* kName2 = "the first Key";
352 disk_cache::Entry *entry1, *entry2; 352 disk_cache::Entry* entry1, *entry2;
353 ASSERT_EQ(net::OK, CreateEntry(kName1, &entry1)); 353 ASSERT_EQ(net::OK, CreateEntry(kName1, &entry1));
354 354
355 ASSERT_EQ(net::OK, CreateEntry(kName2, &entry2)); 355 ASSERT_EQ(net::OK, CreateEntry(kName2, &entry2));
356 EXPECT_TRUE(entry1 != entry2) << "Case sensitive"; 356 EXPECT_TRUE(entry1 != entry2) << "Case sensitive";
357 entry2->Close(); 357 entry2->Close();
358 358
359 char buffer[30]; 359 char buffer[30];
360 base::strlcpy(buffer, kName1, arraysize(buffer)); 360 base::strlcpy(buffer, kName1, arraysize(buffer));
361 ASSERT_EQ(net::OK, OpenEntry(buffer, &entry2)); 361 ASSERT_EQ(net::OK, OpenEntry(buffer, &entry2));
362 EXPECT_TRUE(entry1 == entry2); 362 EXPECT_TRUE(entry1 == entry2);
363 entry2->Close(); 363 entry2->Close();
364 364
365 base::strlcpy(buffer + 1, kName1, arraysize(buffer) - 1); 365 base::strlcpy(buffer + 1, kName1, arraysize(buffer) - 1);
366 ASSERT_EQ(net::OK, OpenEntry(buffer + 1, &entry2)); 366 ASSERT_EQ(net::OK, OpenEntry(buffer + 1, &entry2));
367 EXPECT_TRUE(entry1 == entry2); 367 EXPECT_TRUE(entry1 == entry2);
368 entry2->Close(); 368 entry2->Close();
369 369
370 base::strlcpy(buffer + 3, kName1, arraysize(buffer) - 3); 370 base::strlcpy(buffer + 3, kName1, arraysize(buffer) - 3);
371 ASSERT_EQ(net::OK, OpenEntry(buffer + 3, &entry2)); 371 ASSERT_EQ(net::OK, OpenEntry(buffer + 3, &entry2));
372 EXPECT_TRUE(entry1 == entry2); 372 EXPECT_TRUE(entry1 == entry2);
373 entry2->Close(); 373 entry2->Close();
374 374
375 // Now verify long keys. 375 // Now verify long keys.
376 char buffer2[20000]; 376 char buffer2[20000];
377 memset(buffer2, 's', sizeof(buffer2)); 377 memset(buffer2, 's', sizeof(buffer2));
378 buffer2[1023] = '\0'; 378 buffer2[1023] = '\0';
379 ASSERT_EQ(net::OK, CreateEntry(buffer2, &entry2)) << "key on block file"; 379 ASSERT_EQ(net::OK, CreateEntry(buffer2, &entry2)) << "key on block file";
380 entry2->Close(); 380 entry2->Close();
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
435 cache_thread.message_loop_proxy().get(), 435 cache_thread.message_loop_proxy().get(),
436 NULL, 436 NULL,
437 &cache, 437 &cache,
438 cb.callback()); 438 cb.callback());
439 ASSERT_EQ(net::OK, cb.GetResult(rv)); 439 ASSERT_EQ(net::OK, cb.GetResult(rv));
440 ASSERT_TRUE(cache.get()); 440 ASSERT_TRUE(cache.get());
441 cache.reset(); 441 cache.reset();
442 442
443 rv = disk_cache::CreateCacheBackend(net::MEMORY_CACHE, 443 rv = disk_cache::CreateCacheBackend(net::MEMORY_CACHE,
444 net::CACHE_BACKEND_DEFAULT, 444 net::CACHE_BACKEND_DEFAULT,
445 base::FilePath(), 0, 445 base::FilePath(),
446 false, NULL, NULL, &cache, 446 0,
447 false,
448 NULL,
449 NULL,
450 &cache,
447 cb.callback()); 451 cb.callback());
448 ASSERT_EQ(net::OK, cb.GetResult(rv)); 452 ASSERT_EQ(net::OK, cb.GetResult(rv));
449 ASSERT_TRUE(cache.get()); 453 ASSERT_TRUE(cache.get());
450 cache.reset(); 454 cache.reset();
451 } 455 }
452 456
453 base::MessageLoop::current()->RunUntilIdle(); 457 base::MessageLoop::current()->RunUntilIdle();
454 } 458 }
455 459
456 // Tests that |BackendImpl| fails to initialize with a missing file. 460 // Tests that |BackendImpl| fails to initialize with a missing file.
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
551 555
552 // See crbug.com/330074 556 // See crbug.com/330074
553 #if !defined(OS_IOS) 557 #if !defined(OS_IOS)
554 // Tests that one cache instance is not affected by another one going away. 558 // Tests that one cache instance is not affected by another one going away.
555 TEST_F(DiskCacheBackendTest, MultipleInstancesWithPendingFileIO) { 559 TEST_F(DiskCacheBackendTest, MultipleInstancesWithPendingFileIO) {
556 base::ScopedTempDir store; 560 base::ScopedTempDir store;
557 ASSERT_TRUE(store.CreateUniqueTempDir()); 561 ASSERT_TRUE(store.CreateUniqueTempDir());
558 562
559 net::TestCompletionCallback cb; 563 net::TestCompletionCallback cb;
560 scoped_ptr<disk_cache::Backend> extra_cache; 564 scoped_ptr<disk_cache::Backend> extra_cache;
561 int rv = disk_cache::CreateCacheBackend( 565 int rv =
562 net::DISK_CACHE, net::CACHE_BACKEND_DEFAULT, store.path(), 0, 566 disk_cache::CreateCacheBackend(net::DISK_CACHE,
563 false, base::MessageLoopProxy::current().get(), NULL, 567 net::CACHE_BACKEND_DEFAULT,
564 &extra_cache, cb.callback()); 568 store.path(),
569 0,
570 false,
571 base::MessageLoopProxy::current().get(),
572 NULL,
573 &extra_cache,
574 cb.callback());
565 ASSERT_EQ(net::OK, cb.GetResult(rv)); 575 ASSERT_EQ(net::OK, cb.GetResult(rv));
566 ASSERT_TRUE(extra_cache.get() != NULL); 576 ASSERT_TRUE(extra_cache.get() != NULL);
567 577
568 ASSERT_TRUE(CleanupCacheDir()); 578 ASSERT_TRUE(CleanupCacheDir());
569 SetNewEviction(); // Match the expected behavior for integrity verification. 579 SetNewEviction(); // Match the expected behavior for integrity verification.
570 UseCurrentThread(); 580 UseCurrentThread();
571 581
572 CreateBackend(disk_cache::kNoBuffering, NULL); 582 CreateBackend(disk_cache::kNoBuffering, NULL);
573 rv = GeneratePendingIO(&cb); 583 rv = GeneratePendingIO(&cb);
574 584
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
633 void DiskCacheBackendTest::BackendShutdownWithPendingCreate(bool fast) { 643 void DiskCacheBackendTest::BackendShutdownWithPendingCreate(bool fast) {
634 net::TestCompletionCallback cb; 644 net::TestCompletionCallback cb;
635 645
636 { 646 {
637 ASSERT_TRUE(CleanupCacheDir()); 647 ASSERT_TRUE(CleanupCacheDir());
638 base::Thread cache_thread("CacheThread"); 648 base::Thread cache_thread("CacheThread");
639 ASSERT_TRUE(cache_thread.StartWithOptions( 649 ASSERT_TRUE(cache_thread.StartWithOptions(
640 base::Thread::Options(base::MessageLoop::TYPE_IO, 0))); 650 base::Thread::Options(base::MessageLoop::TYPE_IO, 0)));
641 651
642 disk_cache::BackendFlags flags = 652 disk_cache::BackendFlags flags =
643 fast ? disk_cache::kNone : disk_cache::kNoRandom; 653 fast ? disk_cache::kNone : disk_cache::kNoRandom;
644 CreateBackend(flags, &cache_thread); 654 CreateBackend(flags, &cache_thread);
645 655
646 disk_cache::Entry* entry; 656 disk_cache::Entry* entry;
647 int rv = cache_->CreateEntry("some key", &entry, cb.callback()); 657 int rv = cache_->CreateEntry("some key", &entry, cb.callback());
648 ASSERT_EQ(net::ERR_IO_PENDING, rv); 658 ASSERT_EQ(net::ERR_IO_PENDING, rv);
649 659
650 cache_.reset(); 660 cache_.reset();
651 EXPECT_FALSE(cb.have_result()); 661 EXPECT_FALSE(cb.have_result());
652 } 662 }
653 663
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
833 TEST_F(DiskCacheBackendTest, ShaderCacheLoad) { 843 TEST_F(DiskCacheBackendTest, ShaderCacheLoad) {
834 SetCacheType(net::SHADER_CACHE); 844 SetCacheType(net::SHADER_CACHE);
835 // Work with a tiny index table (16 entries) 845 // Work with a tiny index table (16 entries)
836 SetMask(0xf); 846 SetMask(0xf);
837 SetMaxSize(0x100000); 847 SetMaxSize(0x100000);
838 BackendLoad(); 848 BackendLoad();
839 } 849 }
840 850
841 // Tests the chaining of an entry to the current head. 851 // Tests the chaining of an entry to the current head.
842 void DiskCacheBackendTest::BackendChain() { 852 void DiskCacheBackendTest::BackendChain() {
843 SetMask(0x1); // 2-entry table. 853 SetMask(0x1); // 2-entry table.
844 SetMaxSize(0x3000); // 12 kB. 854 SetMaxSize(0x3000); // 12 kB.
845 InitCache(); 855 InitCache();
846 856
847 disk_cache::Entry* entry; 857 disk_cache::Entry* entry;
848 ASSERT_EQ(net::OK, CreateEntry("The first key", &entry)); 858 ASSERT_EQ(net::OK, CreateEntry("The first key", &entry));
849 entry->Close(); 859 entry->Close();
850 ASSERT_EQ(net::OK, CreateEntry("The Second key", &entry)); 860 ASSERT_EQ(net::OK, CreateEntry("The Second key", &entry));
851 entry->Close(); 861 entry->Close();
852 } 862 }
853 863
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after
1290 TEST_F(DiskCacheBackendTest, AppCacheEnumerations) { 1300 TEST_F(DiskCacheBackendTest, AppCacheEnumerations) {
1291 SetCacheType(net::APP_CACHE); 1301 SetCacheType(net::APP_CACHE);
1292 BackendEnumerations(); 1302 BackendEnumerations();
1293 } 1303 }
1294 1304
1295 // Verifies enumerations while entries are open. 1305 // Verifies enumerations while entries are open.
1296 void DiskCacheBackendTest::BackendEnumerations2() { 1306 void DiskCacheBackendTest::BackendEnumerations2() {
1297 InitCache(); 1307 InitCache();
1298 const std::string first("first"); 1308 const std::string first("first");
1299 const std::string second("second"); 1309 const std::string second("second");
1300 disk_cache::Entry *entry1, *entry2; 1310 disk_cache::Entry* entry1, *entry2;
1301 ASSERT_EQ(net::OK, CreateEntry(first, &entry1)); 1311 ASSERT_EQ(net::OK, CreateEntry(first, &entry1));
1302 entry1->Close(); 1312 entry1->Close();
1303 ASSERT_EQ(net::OK, CreateEntry(second, &entry2)); 1313 ASSERT_EQ(net::OK, CreateEntry(second, &entry2));
1304 entry2->Close(); 1314 entry2->Close();
1305 FlushQueueForTest(); 1315 FlushQueueForTest();
1306 1316
1307 // Make sure that the timestamp is not the same. 1317 // Make sure that the timestamp is not the same.
1308 AddDelay(); 1318 AddDelay();
1309 ASSERT_EQ(net::OK, OpenEntry(second, &entry1)); 1319 ASSERT_EQ(net::OK, OpenEntry(second, &entry1));
1310 void* iter = NULL; 1320 void* iter = NULL;
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
1361 BackendEnumerations2(); 1371 BackendEnumerations2();
1362 } 1372 }
1363 1373
1364 // Verify that ReadData calls do not update the LRU cache 1374 // Verify that ReadData calls do not update the LRU cache
1365 // when using the SHADER_CACHE type. 1375 // when using the SHADER_CACHE type.
1366 TEST_F(DiskCacheBackendTest, ShaderCacheEnumerationReadData) { 1376 TEST_F(DiskCacheBackendTest, ShaderCacheEnumerationReadData) {
1367 SetCacheType(net::SHADER_CACHE); 1377 SetCacheType(net::SHADER_CACHE);
1368 InitCache(); 1378 InitCache();
1369 const std::string first("first"); 1379 const std::string first("first");
1370 const std::string second("second"); 1380 const std::string second("second");
1371 disk_cache::Entry *entry1, *entry2; 1381 disk_cache::Entry* entry1, *entry2;
1372 const int kSize = 50; 1382 const int kSize = 50;
1373 scoped_refptr<net::IOBuffer> buffer1(new net::IOBuffer(kSize)); 1383 scoped_refptr<net::IOBuffer> buffer1(new net::IOBuffer(kSize));
1374 1384
1375 ASSERT_EQ(net::OK, CreateEntry(first, &entry1)); 1385 ASSERT_EQ(net::OK, CreateEntry(first, &entry1));
1376 memset(buffer1->data(), 0, kSize); 1386 memset(buffer1->data(), 0, kSize);
1377 base::strlcpy(buffer1->data(), "And the data to save", kSize); 1387 base::strlcpy(buffer1->data(), "And the data to save", kSize);
1378 EXPECT_EQ(kSize, WriteData(entry1, 0, 0, buffer1.get(), kSize, false)); 1388 EXPECT_EQ(kSize, WriteData(entry1, 0, 0, buffer1.get(), kSize, false));
1379 1389
1380 ASSERT_EQ(net::OK, CreateEntry(second, &entry2)); 1390 ASSERT_EQ(net::OK, CreateEntry(second, &entry2));
1381 entry2->Close(); 1391 entry2->Close();
(...skipping 14 matching lines...) Expand all
1396 cache_->EndEnumeration(&iter); 1406 cache_->EndEnumeration(&iter);
1397 } 1407 }
1398 1408
1399 #if !defined(LEAK_SANITIZER) 1409 #if !defined(LEAK_SANITIZER)
1400 // Verify handling of invalid entries while doing enumerations. 1410 // Verify handling of invalid entries while doing enumerations.
1401 // We'll be leaking memory from this test. 1411 // We'll be leaking memory from this test.
1402 void DiskCacheBackendTest::BackendInvalidEntryEnumeration() { 1412 void DiskCacheBackendTest::BackendInvalidEntryEnumeration() {
1403 InitCache(); 1413 InitCache();
1404 1414
1405 std::string key("Some key"); 1415 std::string key("Some key");
1406 disk_cache::Entry *entry, *entry1, *entry2; 1416 disk_cache::Entry* entry, *entry1, *entry2;
1407 ASSERT_EQ(net::OK, CreateEntry(key, &entry1)); 1417 ASSERT_EQ(net::OK, CreateEntry(key, &entry1));
1408 1418
1409 const int kSize = 50; 1419 const int kSize = 50;
1410 scoped_refptr<net::IOBuffer> buffer1(new net::IOBuffer(kSize)); 1420 scoped_refptr<net::IOBuffer> buffer1(new net::IOBuffer(kSize));
1411 memset(buffer1->data(), 0, kSize); 1421 memset(buffer1->data(), 0, kSize);
1412 base::strlcpy(buffer1->data(), "And the data to save", kSize); 1422 base::strlcpy(buffer1->data(), "And the data to save", kSize);
1413 EXPECT_EQ(kSize, WriteData(entry1, 0, 0, buffer1.get(), kSize, false)); 1423 EXPECT_EQ(kSize, WriteData(entry1, 0, 0, buffer1.get(), kSize, false));
1414 entry1->Close(); 1424 entry1->Close();
1415 ASSERT_EQ(net::OK, OpenEntry(key, &entry1)); 1425 ASSERT_EQ(net::OK, OpenEntry(key, &entry1));
1416 EXPECT_EQ(kSize, ReadData(entry1, 0, 0, buffer1.get(), kSize)); 1426 EXPECT_EQ(kSize, ReadData(entry1, 0, 0, buffer1.get(), kSize));
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1456 1466
1457 const int kNumEntries = 10; 1467 const int kNumEntries = 10;
1458 for (int i = 0; i < kNumEntries; i++) { 1468 for (int i = 0; i < kNumEntries; i++) {
1459 std::string key = GenerateKey(true); 1469 std::string key = GenerateKey(true);
1460 disk_cache::Entry* entry; 1470 disk_cache::Entry* entry;
1461 ASSERT_EQ(net::OK, CreateEntry(key, &entry)); 1471 ASSERT_EQ(net::OK, CreateEntry(key, &entry));
1462 entry->Close(); 1472 entry->Close();
1463 } 1473 }
1464 EXPECT_EQ(kNumEntries, cache_->GetEntryCount()); 1474 EXPECT_EQ(kNumEntries, cache_->GetEntryCount());
1465 1475
1466 disk_cache::Entry *entry1, *entry2; 1476 disk_cache::Entry* entry1, *entry2;
1467 void* iter1 = NULL; 1477 void* iter1 = NULL;
1468 void* iter2 = NULL; 1478 void* iter2 = NULL;
1469 ASSERT_EQ(net::OK, OpenNextEntry(&iter1, &entry1)); 1479 ASSERT_EQ(net::OK, OpenNextEntry(&iter1, &entry1));
1470 ASSERT_TRUE(NULL != entry1); 1480 ASSERT_TRUE(NULL != entry1);
1471 entry1->Close(); 1481 entry1->Close();
1472 entry1 = NULL; 1482 entry1 = NULL;
1473 1483
1474 // Let's go to the middle of the list. 1484 // Let's go to the middle of the list.
1475 for (int i = 0; i < kNumEntries / 2; i++) { 1485 for (int i = 0; i < kNumEntries / 2; i++) {
1476 if (entry1) 1486 if (entry1)
(...skipping 30 matching lines...) Expand all
1507 } 1517 }
1508 1518
1509 TEST_F(DiskCacheBackendTest, NewEvictionFixEnumerators) { 1519 TEST_F(DiskCacheBackendTest, NewEvictionFixEnumerators) {
1510 SetNewEviction(); 1520 SetNewEviction();
1511 BackendFixEnumerators(); 1521 BackendFixEnumerators();
1512 } 1522 }
1513 1523
1514 void DiskCacheBackendTest::BackendDoomRecent() { 1524 void DiskCacheBackendTest::BackendDoomRecent() {
1515 InitCache(); 1525 InitCache();
1516 1526
1517 disk_cache::Entry *entry; 1527 disk_cache::Entry* entry;
1518 ASSERT_EQ(net::OK, CreateEntry("first", &entry)); 1528 ASSERT_EQ(net::OK, CreateEntry("first", &entry));
1519 entry->Close(); 1529 entry->Close();
1520 ASSERT_EQ(net::OK, CreateEntry("second", &entry)); 1530 ASSERT_EQ(net::OK, CreateEntry("second", &entry));
1521 entry->Close(); 1531 entry->Close();
1522 FlushQueueForTest(); 1532 FlushQueueForTest();
1523 1533
1524 AddDelay(); 1534 AddDelay();
1525 Time middle = Time::Now(); 1535 Time middle = Time::Now();
1526 1536
1527 ASSERT_EQ(net::OK, CreateEntry("third", &entry)); 1537 ASSERT_EQ(net::OK, CreateEntry("third", &entry));
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
1585 1595
1586 TEST_F(DiskCacheBackendTest, DoomAllSparse) { 1596 TEST_F(DiskCacheBackendTest, DoomAllSparse) {
1587 InitSparseCache(NULL, NULL); 1597 InitSparseCache(NULL, NULL);
1588 EXPECT_EQ(net::OK, DoomAllEntries()); 1598 EXPECT_EQ(net::OK, DoomAllEntries());
1589 EXPECT_EQ(0, cache_->GetEntryCount()); 1599 EXPECT_EQ(0, cache_->GetEntryCount());
1590 } 1600 }
1591 1601
1592 void DiskCacheBackendTest::BackendDoomBetween() { 1602 void DiskCacheBackendTest::BackendDoomBetween() {
1593 InitCache(); 1603 InitCache();
1594 1604
1595 disk_cache::Entry *entry; 1605 disk_cache::Entry* entry;
1596 ASSERT_EQ(net::OK, CreateEntry("first", &entry)); 1606 ASSERT_EQ(net::OK, CreateEntry("first", &entry));
1597 entry->Close(); 1607 entry->Close();
1598 FlushQueueForTest(); 1608 FlushQueueForTest();
1599 1609
1600 AddDelay(); 1610 AddDelay();
1601 Time middle_start = Time::Now(); 1611 Time middle_start = Time::Now();
1602 1612
1603 ASSERT_EQ(net::OK, CreateEntry("second", &entry)); 1613 ASSERT_EQ(net::OK, CreateEntry("second", &entry));
1604 entry->Close(); 1614 entry->Close();
1605 ASSERT_EQ(net::OK, CreateEntry("third", &entry)); 1615 ASSERT_EQ(net::OK, CreateEntry("third", &entry));
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
1666 DoomEntriesBetween(start, end); 1676 DoomEntriesBetween(start, end);
1667 EXPECT_EQ(9, cache_->GetEntryCount()); 1677 EXPECT_EQ(9, cache_->GetEntryCount());
1668 1678
1669 start = end; 1679 start = end;
1670 end = base::Time::Now(); 1680 end = base::Time::Now();
1671 DoomEntriesBetween(start, end); 1681 DoomEntriesBetween(start, end);
1672 EXPECT_EQ(3, cache_->GetEntryCount()); 1682 EXPECT_EQ(3, cache_->GetEntryCount());
1673 } 1683 }
1674 1684
1675 void DiskCacheBackendTest::BackendTransaction(const std::string& name, 1685 void DiskCacheBackendTest::BackendTransaction(const std::string& name,
1676 int num_entries, bool load) { 1686 int num_entries,
1687 bool load) {
1677 success_ = false; 1688 success_ = false;
1678 ASSERT_TRUE(CopyTestCache(name)); 1689 ASSERT_TRUE(CopyTestCache(name));
1679 DisableFirstCleanup(); 1690 DisableFirstCleanup();
1680 1691
1681 uint32 mask; 1692 uint32 mask;
1682 if (load) { 1693 if (load) {
1683 mask = 0xf; 1694 mask = 0xf;
1684 SetMaxSize(0x100000); 1695 SetMaxSize(0x100000);
1685 } else { 1696 } else {
1686 // Clear the settings from the previous run. 1697 // Clear the settings from the previous run.
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
1840 }; 1851 };
1841 1852
1842 // Tests that the disk cache successfully joins the control group, dropping the 1853 // Tests that the disk cache successfully joins the control group, dropping the
1843 // existing cache in favour of a new empty cache. 1854 // existing cache in favour of a new empty cache.
1844 // Disabled on android since this test requires cache creator to create 1855 // Disabled on android since this test requires cache creator to create
1845 // blockfile caches. 1856 // blockfile caches.
1846 #if !defined(OS_ANDROID) 1857 #if !defined(OS_ANDROID)
1847 TEST_F(DiskCacheTest, SimpleCacheControlJoin) { 1858 TEST_F(DiskCacheTest, SimpleCacheControlJoin) {
1848 base::Thread cache_thread("CacheThread"); 1859 base::Thread cache_thread("CacheThread");
1849 ASSERT_TRUE(cache_thread.StartWithOptions( 1860 ASSERT_TRUE(cache_thread.StartWithOptions(
1850 base::Thread::Options(base::MessageLoop::TYPE_IO, 0))); 1861 base::Thread::Options(base::MessageLoop::TYPE_IO, 0)));
1851 1862
1852 scoped_ptr<disk_cache::BackendImpl> cache = 1863 scoped_ptr<disk_cache::BackendImpl> cache =
1853 CreateExistingEntryCache(cache_thread, cache_path_); 1864 CreateExistingEntryCache(cache_thread, cache_path_);
1854 ASSERT_TRUE(cache.get()); 1865 ASSERT_TRUE(cache.get());
1855 cache.reset(); 1866 cache.reset();
1856 1867
1857 // Instantiate the SimpleCacheTrial, forcing this run into the 1868 // Instantiate the SimpleCacheTrial, forcing this run into the
1858 // ExperimentControl group. 1869 // ExperimentControl group.
1859 base::FieldTrialList field_trial_list(new BadEntropyProvider()); 1870 base::FieldTrialList field_trial_list(new BadEntropyProvider());
1860 base::FieldTrialList::CreateFieldTrial("SimpleCacheTrial", 1871 base::FieldTrialList::CreateFieldTrial("SimpleCacheTrial",
(...skipping 19 matching lines...) Expand all
1880 // existing entries. 1891 // existing entries.
1881 TEST_F(DiskCacheTest, SimpleCacheControlRestart) { 1892 TEST_F(DiskCacheTest, SimpleCacheControlRestart) {
1882 // Instantiate the SimpleCacheTrial, forcing this run into the 1893 // Instantiate the SimpleCacheTrial, forcing this run into the
1883 // ExperimentControl group. 1894 // ExperimentControl group.
1884 base::FieldTrialList field_trial_list(new BadEntropyProvider()); 1895 base::FieldTrialList field_trial_list(new BadEntropyProvider());
1885 base::FieldTrialList::CreateFieldTrial("SimpleCacheTrial", 1896 base::FieldTrialList::CreateFieldTrial("SimpleCacheTrial",
1886 "ExperimentControl"); 1897 "ExperimentControl");
1887 1898
1888 base::Thread cache_thread("CacheThread"); 1899 base::Thread cache_thread("CacheThread");
1889 ASSERT_TRUE(cache_thread.StartWithOptions( 1900 ASSERT_TRUE(cache_thread.StartWithOptions(
1890 base::Thread::Options(base::MessageLoop::TYPE_IO, 0))); 1901 base::Thread::Options(base::MessageLoop::TYPE_IO, 0)));
1891 1902
1892 scoped_ptr<disk_cache::BackendImpl> cache = 1903 scoped_ptr<disk_cache::BackendImpl> cache =
1893 CreateExistingEntryCache(cache_thread, cache_path_); 1904 CreateExistingEntryCache(cache_thread, cache_path_);
1894 ASSERT_TRUE(cache.get()); 1905 ASSERT_TRUE(cache.get());
1895 1906
1896 net::TestCompletionCallback cb; 1907 net::TestCompletionCallback cb;
1897 1908
1898 const int kRestartCount = 5; 1909 const int kRestartCount = 5;
1899 for (int i = 0; i < kRestartCount; ++i) { 1910 for (int i = 0; i < kRestartCount; ++i) {
1900 cache.reset(new disk_cache::BackendImpl( 1911 cache.reset(new disk_cache::BackendImpl(
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
1983 EXPECT_TRUE(CheckCacheIntegrity(cache_path_, new_eviction_, mask_)); 1994 EXPECT_TRUE(CheckCacheIntegrity(cache_path_, new_eviction_, mask_));
1984 } 1995 }
1985 #endif 1996 #endif
1986 1997
1987 // We want to be able to deal with messed up entries on disk. 1998 // We want to be able to deal with messed up entries on disk.
1988 void DiskCacheBackendTest::BackendInvalidEntry2() { 1999 void DiskCacheBackendTest::BackendInvalidEntry2() {
1989 ASSERT_TRUE(CopyTestCache("bad_entry")); 2000 ASSERT_TRUE(CopyTestCache("bad_entry"));
1990 DisableFirstCleanup(); 2001 DisableFirstCleanup();
1991 InitCache(); 2002 InitCache();
1992 2003
1993 disk_cache::Entry *entry1, *entry2; 2004 disk_cache::Entry* entry1, *entry2;
1994 ASSERT_EQ(net::OK, OpenEntry("the first key", &entry1)); 2005 ASSERT_EQ(net::OK, OpenEntry("the first key", &entry1));
1995 EXPECT_NE(net::OK, OpenEntry("some other key", &entry2)); 2006 EXPECT_NE(net::OK, OpenEntry("some other key", &entry2));
1996 entry1->Close(); 2007 entry1->Close();
1997 2008
1998 // CheckCacheIntegrity will fail at this point. 2009 // CheckCacheIntegrity will fail at this point.
1999 DisableIntegrityCheck(); 2010 DisableIntegrityCheck();
2000 } 2011 }
2001 2012
2002 TEST_F(DiskCacheBackendTest, InvalidEntry2) { 2013 TEST_F(DiskCacheBackendTest, InvalidEntry2) {
2003 BackendInvalidEntry2(); 2014 BackendInvalidEntry2();
2004 } 2015 }
2005 2016
2006 TEST_F(DiskCacheBackendTest, NewEvictionInvalidEntry2) { 2017 TEST_F(DiskCacheBackendTest, NewEvictionInvalidEntry2) {
2007 SetNewEviction(); 2018 SetNewEviction();
2008 BackendInvalidEntry2(); 2019 BackendInvalidEntry2();
2009 } 2020 }
2010 2021
2011 // Tests that we don't crash or hang when enumerating this cache. 2022 // Tests that we don't crash or hang when enumerating this cache.
2012 void DiskCacheBackendTest::BackendInvalidEntry3() { 2023 void DiskCacheBackendTest::BackendInvalidEntry3() {
2013 SetMask(0x1); // 2-entry table. 2024 SetMask(0x1); // 2-entry table.
2014 SetMaxSize(0x3000); // 12 kB. 2025 SetMaxSize(0x3000); // 12 kB.
2015 DisableFirstCleanup(); 2026 DisableFirstCleanup();
2016 InitCache(); 2027 InitCache();
2017 2028
2018 disk_cache::Entry* entry; 2029 disk_cache::Entry* entry;
2019 void* iter = NULL; 2030 void* iter = NULL;
2020 while (OpenNextEntry(&iter, &entry) == net::OK) { 2031 while (OpenNextEntry(&iter, &entry) == net::OK) {
2021 entry->Close(); 2032 entry->Close();
2022 } 2033 }
2023 } 2034 }
2024 2035
2025 TEST_F(DiskCacheBackendTest, InvalidEntry3) { 2036 TEST_F(DiskCacheBackendTest, InvalidEntry3) {
2026 ASSERT_TRUE(CopyTestCache("dirty_entry3")); 2037 ASSERT_TRUE(CopyTestCache("dirty_entry3"));
2027 BackendInvalidEntry3(); 2038 BackendInvalidEntry3();
2028 } 2039 }
2029 2040
2030 TEST_F(DiskCacheBackendTest, NewEvictionInvalidEntry3) { 2041 TEST_F(DiskCacheBackendTest, NewEvictionInvalidEntry3) {
2031 ASSERT_TRUE(CopyTestCache("dirty_entry4")); 2042 ASSERT_TRUE(CopyTestCache("dirty_entry4"));
2032 SetNewEviction(); 2043 SetNewEviction();
2033 BackendInvalidEntry3(); 2044 BackendInvalidEntry3();
2034 DisableIntegrityCheck(); 2045 DisableIntegrityCheck();
2035 } 2046 }
2036 2047
2037 // Test that we handle a dirty entry on the LRU list, already replaced with 2048 // Test that we handle a dirty entry on the LRU list, already replaced with
2038 // the same key, and with hash collisions. 2049 // the same key, and with hash collisions.
2039 TEST_F(DiskCacheBackendTest, InvalidEntry4) { 2050 TEST_F(DiskCacheBackendTest, InvalidEntry4) {
2040 ASSERT_TRUE(CopyTestCache("dirty_entry3")); 2051 ASSERT_TRUE(CopyTestCache("dirty_entry3"));
2041 SetMask(0x1); // 2-entry table. 2052 SetMask(0x1); // 2-entry table.
2042 SetMaxSize(0x3000); // 12 kB. 2053 SetMaxSize(0x3000); // 12 kB.
2043 DisableFirstCleanup(); 2054 DisableFirstCleanup();
2044 InitCache(); 2055 InitCache();
2045 2056
2046 TrimForTest(false); 2057 TrimForTest(false);
2047 } 2058 }
2048 2059
2049 // Test that we handle a dirty entry on the deleted list, already replaced with 2060 // Test that we handle a dirty entry on the deleted list, already replaced with
2050 // the same key, and with hash collisions. 2061 // the same key, and with hash collisions.
2051 TEST_F(DiskCacheBackendTest, InvalidEntry5) { 2062 TEST_F(DiskCacheBackendTest, InvalidEntry5) {
2052 ASSERT_TRUE(CopyTestCache("dirty_entry4")); 2063 ASSERT_TRUE(CopyTestCache("dirty_entry4"));
2053 SetNewEviction(); 2064 SetNewEviction();
2054 SetMask(0x1); // 2-entry table. 2065 SetMask(0x1); // 2-entry table.
2055 SetMaxSize(0x3000); // 12 kB. 2066 SetMaxSize(0x3000); // 12 kB.
2056 DisableFirstCleanup(); 2067 DisableFirstCleanup();
2057 InitCache(); 2068 InitCache();
2058 2069
2059 TrimDeletedListForTest(false); 2070 TrimDeletedListForTest(false);
2060 } 2071 }
2061 2072
2062 TEST_F(DiskCacheBackendTest, InvalidEntry6) { 2073 TEST_F(DiskCacheBackendTest, InvalidEntry6) {
2063 ASSERT_TRUE(CopyTestCache("dirty_entry5")); 2074 ASSERT_TRUE(CopyTestCache("dirty_entry5"));
2064 SetMask(0x1); // 2-entry table. 2075 SetMask(0x1); // 2-entry table.
2065 SetMaxSize(0x3000); // 12 kB. 2076 SetMaxSize(0x3000); // 12 kB.
2066 DisableFirstCleanup(); 2077 DisableFirstCleanup();
2067 InitCache(); 2078 InitCache();
2068 2079
2069 // There is a dirty entry (but marked as clean) at the end, pointing to a 2080 // There is a dirty entry (but marked as clean) at the end, pointing to a
2070 // deleted entry through the hash collision list. We should not re-insert the 2081 // deleted entry through the hash collision list. We should not re-insert the
2071 // deleted entry into the index table. 2082 // deleted entry into the index table.
2072 2083
2073 TrimForTest(false); 2084 TrimForTest(false);
2074 // The cache should be clean (as detected by CheckCacheIntegrity). 2085 // The cache should be clean (as detected by CheckCacheIntegrity).
2075 } 2086 }
2076 2087
2077 // Tests that we don't hang when there is a loop on the hash collision list. 2088 // Tests that we don't hang when there is a loop on the hash collision list.
2078 // The test cache could be a result of bug 69135. 2089 // The test cache could be a result of bug 69135.
2079 TEST_F(DiskCacheBackendTest, BadNextEntry1) { 2090 TEST_F(DiskCacheBackendTest, BadNextEntry1) {
2080 ASSERT_TRUE(CopyTestCache("list_loop2")); 2091 ASSERT_TRUE(CopyTestCache("list_loop2"));
2081 SetMask(0x1); // 2-entry table. 2092 SetMask(0x1); // 2-entry table.
2082 SetMaxSize(0x3000); // 12 kB. 2093 SetMaxSize(0x3000); // 12 kB.
2083 DisableFirstCleanup(); 2094 DisableFirstCleanup();
2084 InitCache(); 2095 InitCache();
2085 2096
2086 // The second entry points at itselft, and the first entry is not accessible 2097 // The second entry points at itselft, and the first entry is not accessible
2087 // though the index, but it is at the head of the LRU. 2098 // though the index, but it is at the head of the LRU.
2088 2099
2089 disk_cache::Entry* entry; 2100 disk_cache::Entry* entry;
2090 ASSERT_EQ(net::OK, CreateEntry("The first key", &entry)); 2101 ASSERT_EQ(net::OK, CreateEntry("The first key", &entry));
2091 entry->Close(); 2102 entry->Close();
2092 2103
2093 TrimForTest(false); 2104 TrimForTest(false);
2094 TrimForTest(false); 2105 TrimForTest(false);
2095 ASSERT_EQ(net::OK, OpenEntry("The first key", &entry)); 2106 ASSERT_EQ(net::OK, OpenEntry("The first key", &entry));
2096 entry->Close(); 2107 entry->Close();
2097 EXPECT_EQ(1, cache_->GetEntryCount()); 2108 EXPECT_EQ(1, cache_->GetEntryCount());
2098 } 2109 }
2099 2110
2100 // Tests that we don't hang when there is a loop on the hash collision list. 2111 // Tests that we don't hang when there is a loop on the hash collision list.
2101 // The test cache could be a result of bug 69135. 2112 // The test cache could be a result of bug 69135.
2102 TEST_F(DiskCacheBackendTest, BadNextEntry2) { 2113 TEST_F(DiskCacheBackendTest, BadNextEntry2) {
2103 ASSERT_TRUE(CopyTestCache("list_loop3")); 2114 ASSERT_TRUE(CopyTestCache("list_loop3"));
2104 SetMask(0x1); // 2-entry table. 2115 SetMask(0x1); // 2-entry table.
2105 SetMaxSize(0x3000); // 12 kB. 2116 SetMaxSize(0x3000); // 12 kB.
2106 DisableFirstCleanup(); 2117 DisableFirstCleanup();
2107 InitCache(); 2118 InitCache();
2108 2119
2109 // There is a wide loop of 5 entries. 2120 // There is a wide loop of 5 entries.
2110 2121
2111 disk_cache::Entry* entry; 2122 disk_cache::Entry* entry;
2112 ASSERT_NE(net::OK, OpenEntry("Not present key", &entry)); 2123 ASSERT_NE(net::OK, OpenEntry("Not present key", &entry));
2113 } 2124 }
2114 2125
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after
2459 SetNewEviction(); 2470 SetNewEviction();
2460 BackendTrimInvalidEntry12(); 2471 BackendTrimInvalidEntry12();
2461 } 2472 }
2462 2473
2463 // We want to be able to deal with messed up entries on disk. 2474 // We want to be able to deal with messed up entries on disk.
2464 void DiskCacheBackendTest::BackendInvalidRankings2() { 2475 void DiskCacheBackendTest::BackendInvalidRankings2() {
2465 ASSERT_TRUE(CopyTestCache("bad_rankings")); 2476 ASSERT_TRUE(CopyTestCache("bad_rankings"));
2466 DisableFirstCleanup(); 2477 DisableFirstCleanup();
2467 InitCache(); 2478 InitCache();
2468 2479
2469 disk_cache::Entry *entry1, *entry2; 2480 disk_cache::Entry* entry1, *entry2;
2470 EXPECT_NE(net::OK, OpenEntry("the first key", &entry1)); 2481 EXPECT_NE(net::OK, OpenEntry("the first key", &entry1));
2471 ASSERT_EQ(net::OK, OpenEntry("some other key", &entry2)); 2482 ASSERT_EQ(net::OK, OpenEntry("some other key", &entry2));
2472 entry2->Close(); 2483 entry2->Close();
2473 2484
2474 // CheckCacheIntegrity will fail at this point. 2485 // CheckCacheIntegrity will fail at this point.
2475 DisableIntegrityCheck(); 2486 DisableIntegrityCheck();
2476 } 2487 }
2477 2488
2478 TEST_F(DiskCacheBackendTest, InvalidRankings2) { 2489 TEST_F(DiskCacheBackendTest, InvalidRankings2) {
2479 BackendInvalidRankings2(); 2490 BackendInvalidRankings2();
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
2524 ASSERT_TRUE(CopyTestCache("bad_rankings")); 2535 ASSERT_TRUE(CopyTestCache("bad_rankings"));
2525 DisableFirstCleanup(); 2536 DisableFirstCleanup();
2526 SetNewEviction(); 2537 SetNewEviction();
2527 InitCache(); 2538 InitCache();
2528 SetTestMode(); // Fail cache reinitialization. 2539 SetTestMode(); // Fail cache reinitialization.
2529 BackendInvalidRankings(); 2540 BackendInvalidRankings();
2530 } 2541 }
2531 2542
2532 // If the LRU is corrupt and we have open entries, we disable the cache. 2543 // If the LRU is corrupt and we have open entries, we disable the cache.
2533 void DiskCacheBackendTest::BackendDisable() { 2544 void DiskCacheBackendTest::BackendDisable() {
2534 disk_cache::Entry *entry1, *entry2; 2545 disk_cache::Entry* entry1, *entry2;
2535 void* iter = NULL; 2546 void* iter = NULL;
2536 ASSERT_EQ(net::OK, OpenNextEntry(&iter, &entry1)); 2547 ASSERT_EQ(net::OK, OpenNextEntry(&iter, &entry1));
2537 2548
2538 EXPECT_NE(net::OK, OpenNextEntry(&iter, &entry2)); 2549 EXPECT_NE(net::OK, OpenNextEntry(&iter, &entry2));
2539 EXPECT_EQ(0, cache_->GetEntryCount()); 2550 EXPECT_EQ(0, cache_->GetEntryCount());
2540 EXPECT_NE(net::OK, CreateEntry("Something new", &entry2)); 2551 EXPECT_NE(net::OK, CreateEntry("Something new", &entry2));
2541 2552
2542 entry1->Close(); 2553 entry1->Close();
2543 FlushQueueForTest(); // Flushing the Close posts a task to restart the cache. 2554 FlushQueueForTest(); // Flushing the Close posts a task to restart the cache.
2544 FlushQueueForTest(); // This one actually allows that task to complete. 2555 FlushQueueForTest(); // This one actually allows that task to complete.
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
2623 ASSERT_TRUE(CopyTestCache("list_loop")); 2634 ASSERT_TRUE(CopyTestCache("list_loop"));
2624 DisableFirstCleanup(); 2635 DisableFirstCleanup();
2625 SetNewEviction(); 2636 SetNewEviction();
2626 InitCache(); 2637 InitCache();
2627 SetTestMode(); // Fail cache reinitialization. 2638 SetTestMode(); // Fail cache reinitialization.
2628 BackendDisable2(); 2639 BackendDisable2();
2629 } 2640 }
2630 2641
2631 // If the index size changes when we disable the cache, we should not crash. 2642 // If the index size changes when we disable the cache, we should not crash.
2632 void DiskCacheBackendTest::BackendDisable3() { 2643 void DiskCacheBackendTest::BackendDisable3() {
2633 disk_cache::Entry *entry1, *entry2; 2644 disk_cache::Entry* entry1, *entry2;
2634 void* iter = NULL; 2645 void* iter = NULL;
2635 EXPECT_EQ(2, cache_->GetEntryCount()); 2646 EXPECT_EQ(2, cache_->GetEntryCount());
2636 ASSERT_EQ(net::OK, OpenNextEntry(&iter, &entry1)); 2647 ASSERT_EQ(net::OK, OpenNextEntry(&iter, &entry1));
2637 entry1->Close(); 2648 entry1->Close();
2638 2649
2639 EXPECT_NE(net::OK, OpenNextEntry(&iter, &entry2)); 2650 EXPECT_NE(net::OK, OpenNextEntry(&iter, &entry2));
2640 FlushQueueForTest(); 2651 FlushQueueForTest();
2641 2652
2642 ASSERT_EQ(net::OK, CreateEntry("Something new", &entry2)); 2653 ASSERT_EQ(net::OK, CreateEntry("Something new", &entry2));
2643 entry2->Close(); 2654 entry2->Close();
(...skipping 13 matching lines...) Expand all
2657 ASSERT_TRUE(CopyTestCache("bad_rankings2")); 2668 ASSERT_TRUE(CopyTestCache("bad_rankings2"));
2658 DisableFirstCleanup(); 2669 DisableFirstCleanup();
2659 SetMaxSize(20 * 1024 * 1024); 2670 SetMaxSize(20 * 1024 * 1024);
2660 SetNewEviction(); 2671 SetNewEviction();
2661 InitCache(); 2672 InitCache();
2662 BackendDisable3(); 2673 BackendDisable3();
2663 } 2674 }
2664 2675
2665 // If we disable the cache, already open entries should work as far as possible. 2676 // If we disable the cache, already open entries should work as far as possible.
2666 void DiskCacheBackendTest::BackendDisable4() { 2677 void DiskCacheBackendTest::BackendDisable4() {
2667 disk_cache::Entry *entry1, *entry2, *entry3, *entry4; 2678 disk_cache::Entry* entry1, *entry2, *entry3, *entry4;
2668 void* iter = NULL; 2679 void* iter = NULL;
2669 ASSERT_EQ(net::OK, OpenNextEntry(&iter, &entry1)); 2680 ASSERT_EQ(net::OK, OpenNextEntry(&iter, &entry1));
2670 2681
2671 char key2[2000]; 2682 char key2[2000];
2672 char key3[20000]; 2683 char key3[20000];
2673 CacheTestFillBuffer(key2, sizeof(key2), true); 2684 CacheTestFillBuffer(key2, sizeof(key2), true);
2674 CacheTestFillBuffer(key3, sizeof(key3), true); 2685 CacheTestFillBuffer(key3, sizeof(key3), true);
2675 key2[sizeof(key2) - 1] = '\0'; 2686 key2[sizeof(key2) - 1] = '\0';
2676 key3[sizeof(key3) - 1] = '\0'; 2687 key3[sizeof(key3) - 1] = '\0';
2677 ASSERT_EQ(net::OK, CreateEntry(key2, &entry2)); 2688 ASSERT_EQ(net::OK, CreateEntry(key2, &entry2));
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
2781 stats.clear(); 2792 stats.clear();
2782 cache_->GetStats(&stats); 2793 cache_->GetStats(&stats);
2783 EXPECT_FALSE(stats.empty()); 2794 EXPECT_FALSE(stats.empty());
2784 2795
2785 EXPECT_EQ(1, std::count(stats.begin(), stats.end(), hits)); 2796 EXPECT_EQ(1, std::count(stats.begin(), stats.end(), hits));
2786 } 2797 }
2787 2798
2788 void DiskCacheBackendTest::BackendDoomAll() { 2799 void DiskCacheBackendTest::BackendDoomAll() {
2789 InitCache(); 2800 InitCache();
2790 2801
2791 disk_cache::Entry *entry1, *entry2; 2802 disk_cache::Entry* entry1, *entry2;
2792 ASSERT_EQ(net::OK, CreateEntry("first", &entry1)); 2803 ASSERT_EQ(net::OK, CreateEntry("first", &entry1));
2793 ASSERT_EQ(net::OK, CreateEntry("second", &entry2)); 2804 ASSERT_EQ(net::OK, CreateEntry("second", &entry2));
2794 entry1->Close(); 2805 entry1->Close();
2795 entry2->Close(); 2806 entry2->Close();
2796 2807
2797 ASSERT_EQ(net::OK, CreateEntry("third", &entry1)); 2808 ASSERT_EQ(net::OK, CreateEntry("third", &entry1));
2798 ASSERT_EQ(net::OK, CreateEntry("fourth", &entry2)); 2809 ASSERT_EQ(net::OK, CreateEntry("fourth", &entry2));
2799 2810
2800 ASSERT_EQ(4, cache_->GetEntryCount()); 2811 ASSERT_EQ(4, cache_->GetEntryCount());
2801 EXPECT_EQ(net::OK, DoomAllEntries()); 2812 EXPECT_EQ(net::OK, DoomAllEntries());
2802 ASSERT_EQ(0, cache_->GetEntryCount()); 2813 ASSERT_EQ(0, cache_->GetEntryCount());
2803 2814
2804 // We should stop posting tasks at some point (if we post any). 2815 // We should stop posting tasks at some point (if we post any).
2805 base::MessageLoop::current()->RunUntilIdle(); 2816 base::MessageLoop::current()->RunUntilIdle();
2806 2817
2807 disk_cache::Entry *entry3, *entry4; 2818 disk_cache::Entry* entry3, *entry4;
2808 EXPECT_NE(net::OK, OpenEntry("third", &entry3)); 2819 EXPECT_NE(net::OK, OpenEntry("third", &entry3));
2809 ASSERT_EQ(net::OK, CreateEntry("third", &entry3)); 2820 ASSERT_EQ(net::OK, CreateEntry("third", &entry3));
2810 ASSERT_EQ(net::OK, CreateEntry("fourth", &entry4)); 2821 ASSERT_EQ(net::OK, CreateEntry("fourth", &entry4));
2811 2822
2812 EXPECT_EQ(net::OK, DoomAllEntries()); 2823 EXPECT_EQ(net::OK, DoomAllEntries());
2813 ASSERT_EQ(0, cache_->GetEntryCount()); 2824 ASSERT_EQ(0, cache_->GetEntryCount());
2814 2825
2815 entry1->Close(); 2826 entry1->Close();
2816 entry2->Close(); 2827 entry2->Close();
2817 entry3->Doom(); // The entry should be already doomed, but this must work. 2828 entry3->Doom(); // The entry should be already doomed, but this must work.
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
2945 EXPECT_EQ(kDefaultCacheSize - 1, 2956 EXPECT_EQ(kDefaultCacheSize - 1,
2946 disk_cache::PreferredCacheSize(large_size * 10 / 8 - 1)); 2957 disk_cache::PreferredCacheSize(large_size * 10 / 8 - 1));
2947 2958
2948 // Region 2: expected = default_size 2959 // Region 2: expected = default_size
2949 EXPECT_EQ(kDefaultCacheSize, 2960 EXPECT_EQ(kDefaultCacheSize,
2950 disk_cache::PreferredCacheSize(large_size * 10 / 8)); 2961 disk_cache::PreferredCacheSize(large_size * 10 / 8));
2951 EXPECT_EQ(kDefaultCacheSize, 2962 EXPECT_EQ(kDefaultCacheSize,
2952 disk_cache::PreferredCacheSize(large_size * 10 - 1)); 2963 disk_cache::PreferredCacheSize(large_size * 10 - 1));
2953 2964
2954 // Region 3: expected = available * 0.1 2965 // Region 3: expected = available * 0.1
2955 EXPECT_EQ(kDefaultCacheSize, 2966 EXPECT_EQ(kDefaultCacheSize, disk_cache::PreferredCacheSize(large_size * 10));
2956 disk_cache::PreferredCacheSize(large_size * 10));
2957 EXPECT_EQ((kDefaultCacheSize * 25 - 1) / 10, 2967 EXPECT_EQ((kDefaultCacheSize * 25 - 1) / 10,
2958 disk_cache::PreferredCacheSize(large_size * 25 - 1)); 2968 disk_cache::PreferredCacheSize(large_size * 25 - 1));
2959 2969
2960 // Region 4: expected = default_size * 2.5 2970 // Region 4: expected = default_size * 2.5
2961 EXPECT_EQ(kDefaultCacheSize * 25 / 10, 2971 EXPECT_EQ(kDefaultCacheSize * 25 / 10,
2962 disk_cache::PreferredCacheSize(large_size * 25)); 2972 disk_cache::PreferredCacheSize(large_size * 25));
2963 EXPECT_EQ(kDefaultCacheSize * 25 / 10, 2973 EXPECT_EQ(kDefaultCacheSize * 25 / 10,
2964 disk_cache::PreferredCacheSize(large_size * 100 - 1)); 2974 disk_cache::PreferredCacheSize(large_size * 100 - 1));
2965 EXPECT_EQ(kDefaultCacheSize * 25 / 10, 2975 EXPECT_EQ(kDefaultCacheSize * 25 / 10,
2966 disk_cache::PreferredCacheSize(large_size * 100)); 2976 disk_cache::PreferredCacheSize(large_size * 100));
2967 EXPECT_EQ(kDefaultCacheSize * 25 / 10, 2977 EXPECT_EQ(kDefaultCacheSize * 25 / 10,
2968 disk_cache::PreferredCacheSize(large_size * 250 - 1)); 2978 disk_cache::PreferredCacheSize(large_size * 250 - 1));
2969 2979
2970 // Region 5: expected = available * 0.1 2980 // Region 5: expected = available * 0.1
2971 int64 largest_size = kDefaultCacheSize * 4; 2981 int64 largest_size = kDefaultCacheSize * 4;
2972 EXPECT_EQ(kDefaultCacheSize * 25 / 10, 2982 EXPECT_EQ(kDefaultCacheSize * 25 / 10,
2973 disk_cache::PreferredCacheSize(large_size * 250)); 2983 disk_cache::PreferredCacheSize(large_size * 250));
2974 EXPECT_EQ(largest_size - 1, 2984 EXPECT_EQ(largest_size - 1,
2975 disk_cache::PreferredCacheSize(largest_size * 100 - 1)); 2985 disk_cache::PreferredCacheSize(largest_size * 100 - 1));
2976 2986
2977 // Region 6: expected = largest possible size 2987 // Region 6: expected = largest possible size
2978 EXPECT_EQ(largest_size, 2988 EXPECT_EQ(largest_size, disk_cache::PreferredCacheSize(largest_size * 100));
2979 disk_cache::PreferredCacheSize(largest_size * 100)); 2989 EXPECT_EQ(largest_size, disk_cache::PreferredCacheSize(largest_size * 10000));
2980 EXPECT_EQ(largest_size,
2981 disk_cache::PreferredCacheSize(largest_size * 10000));
2982 } 2990 }
2983 2991
2984 // Tests that we can "migrate" a running instance from one experiment group to 2992 // Tests that we can "migrate" a running instance from one experiment group to
2985 // another. 2993 // another.
2986 TEST_F(DiskCacheBackendTest, Histograms) { 2994 TEST_F(DiskCacheBackendTest, Histograms) {
2987 InitCache(); 2995 InitCache();
2988 disk_cache::BackendImpl* backend_ = cache_impl_; // Needed be the macro. 2996 disk_cache::BackendImpl* backend_ = cache_impl_; // Needed be the macro.
2989 2997
2990 for (int i = 1; i < 3; i++) { 2998 for (int i = 1; i < 3; i++) {
2991 CACHE_UMA(HOURS, "FillupTime", i, 28); 2999 CACHE_UMA(HOURS, "FillupTime", i, 28);
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
3066 file->Init(name); 3074 file->Init(name);
3067 3075
3068 #if defined(OS_WIN) 3076 #if defined(OS_WIN)
3069 DWORD sharing = FILE_SHARE_READ | FILE_SHARE_WRITE; 3077 DWORD sharing = FILE_SHARE_READ | FILE_SHARE_WRITE;
3070 DWORD access = GENERIC_READ | GENERIC_WRITE; 3078 DWORD access = GENERIC_READ | GENERIC_WRITE;
3071 base::win::ScopedHandle file2(CreateFile( 3079 base::win::ScopedHandle file2(CreateFile(
3072 name.value().c_str(), access, sharing, NULL, OPEN_EXISTING, 0, NULL)); 3080 name.value().c_str(), access, sharing, NULL, OPEN_EXISTING, 0, NULL));
3073 EXPECT_FALSE(file2.IsValid()); 3081 EXPECT_FALSE(file2.IsValid());
3074 3082
3075 sharing |= FILE_SHARE_DELETE; 3083 sharing |= FILE_SHARE_DELETE;
3076 file2.Set(CreateFile(name.value().c_str(), access, sharing, NULL, 3084 file2.Set(CreateFile(
3077 OPEN_EXISTING, 0, NULL)); 3085 name.value().c_str(), access, sharing, NULL, OPEN_EXISTING, 0, NULL));
3078 EXPECT_TRUE(file2.IsValid()); 3086 EXPECT_TRUE(file2.IsValid());
3079 #endif 3087 #endif
3080 3088
3081 EXPECT_TRUE(base::DeleteFile(name, false)); 3089 EXPECT_TRUE(base::DeleteFile(name, false));
3082 3090
3083 // We should be able to use the file. 3091 // We should be able to use the file.
3084 const int kSize = 200; 3092 const int kSize = 200;
3085 char buffer1[kSize]; 3093 char buffer1[kSize];
3086 char buffer2[kSize]; 3094 char buffer2[kSize];
3087 memset(buffer1, 't', kSize); 3095 memset(buffer1, 't', kSize);
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
3212 } 3220 }
3213 3221
3214 TEST_F(DiskCacheBackendTest, DISABLED_SimpleCacheSetSize) { 3222 TEST_F(DiskCacheBackendTest, DISABLED_SimpleCacheSetSize) {
3215 SetSimpleCacheMode(); 3223 SetSimpleCacheMode();
3216 BackendSetSize(); 3224 BackendSetSize();
3217 } 3225 }
3218 3226
3219 // MacOS has a default open file limit of 256 files, which is incompatible with 3227 // MacOS has a default open file limit of 256 files, which is incompatible with
3220 // this simple cache test. 3228 // this simple cache test.
3221 #if defined(OS_MACOSX) 3229 #if defined(OS_MACOSX)
3222 #define SIMPLE_MAYBE_MACOS(TestName) DISABLED_ ## TestName 3230 #define SIMPLE_MAYBE_MACOS(TestName) DISABLED_##TestName
3223 #else 3231 #else
3224 #define SIMPLE_MAYBE_MACOS(TestName) TestName 3232 #define SIMPLE_MAYBE_MACOS(TestName) TestName
3225 #endif 3233 #endif
3226 3234
3227 TEST_F(DiskCacheBackendTest, SIMPLE_MAYBE_MACOS(SimpleCacheLoad)) { 3235 TEST_F(DiskCacheBackendTest, SIMPLE_MAYBE_MACOS(SimpleCacheLoad)) {
3228 SetMaxSize(0x100000); 3236 SetMaxSize(0x100000);
3229 SetSimpleCacheMode(); 3237 SetSimpleCacheMode();
3230 BackendLoad(); 3238 BackendLoad();
3231 } 3239 }
3232 3240
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
3322 entry = NULL; 3330 entry = NULL;
3323 3331
3324 // Write an invalid header for stream 0 and stream 1. 3332 // Write an invalid header for stream 0 and stream 1.
3325 base::FilePath entry_file1_path = cache_path_.AppendASCII( 3333 base::FilePath entry_file1_path = cache_path_.AppendASCII(
3326 disk_cache::simple_util::GetFilenameFromKeyAndFileIndex(key, 0)); 3334 disk_cache::simple_util::GetFilenameFromKeyAndFileIndex(key, 0));
3327 3335
3328 disk_cache::SimpleFileHeader header; 3336 disk_cache::SimpleFileHeader header;
3329 header.initial_magic_number = GG_UINT64_C(0xbadf00d); 3337 header.initial_magic_number = GG_UINT64_C(0xbadf00d);
3330 EXPECT_EQ( 3338 EXPECT_EQ(
3331 implicit_cast<int>(sizeof(header)), 3339 implicit_cast<int>(sizeof(header)),
3332 base::WriteFile(entry_file1_path, reinterpret_cast<char*>(&header), 3340 base::WriteFile(
3333 sizeof(header))); 3341 entry_file1_path, reinterpret_cast<char*>(&header), sizeof(header)));
3334 ASSERT_EQ(net::ERR_FAILED, OpenEntry(key, &entry)); 3342 ASSERT_EQ(net::ERR_FAILED, OpenEntry(key, &entry));
3335 } 3343 }
3336 3344
3337 // Tests that the Simple Cache Backend fails to initialize with non-matching 3345 // Tests that the Simple Cache Backend fails to initialize with non-matching
3338 // file structure on disk. 3346 // file structure on disk.
3339 TEST_F(DiskCacheBackendTest, SimpleCacheOverBlockfileCache) { 3347 TEST_F(DiskCacheBackendTest, SimpleCacheOverBlockfileCache) {
3340 // Create a cache structure with the |BackendImpl|. 3348 // Create a cache structure with the |BackendImpl|.
3341 InitCache(); 3349 InitCache();
3342 disk_cache::Entry* entry; 3350 disk_cache::Entry* entry;
3343 const int kSize = 50; 3351 const int kSize = 50;
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
3415 cache_->EndEnumeration(&iter); 3423 cache_->EndEnumeration(&iter);
3416 EXPECT_EQ(key_pool.size(), count); 3424 EXPECT_EQ(key_pool.size(), count);
3417 EXPECT_TRUE(keys_to_match.empty()); 3425 EXPECT_TRUE(keys_to_match.empty());
3418 3426
3419 // Check that opening entries does not affect enumeration. 3427 // Check that opening entries does not affect enumeration.
3420 keys_to_match = key_pool; 3428 keys_to_match = key_pool;
3421 iter = NULL; 3429 iter = NULL;
3422 count = 0; 3430 count = 0;
3423 disk_cache::Entry* entry_opened_before; 3431 disk_cache::Entry* entry_opened_before;
3424 ASSERT_EQ(net::OK, OpenEntry(*(key_pool.begin()), &entry_opened_before)); 3432 ASSERT_EQ(net::OK, OpenEntry(*(key_pool.begin()), &entry_opened_before));
3425 ASSERT_TRUE(EnumerateAndMatchKeys(key_pool.size()/2, 3433 ASSERT_TRUE(EnumerateAndMatchKeys(
3426 &iter, 3434 key_pool.size() / 2, &iter, &keys_to_match, &count));
3427 &keys_to_match,
3428 &count));
3429 3435
3430 disk_cache::Entry* entry_opened_middle; 3436 disk_cache::Entry* entry_opened_middle;
3431 ASSERT_EQ(net::OK, 3437 ASSERT_EQ(net::OK, OpenEntry(*(keys_to_match.begin()), &entry_opened_middle));
3432 OpenEntry(*(keys_to_match.begin()), &entry_opened_middle));
3433 ASSERT_TRUE(EnumerateAndMatchKeys(-1, &iter, &keys_to_match, &count)); 3438 ASSERT_TRUE(EnumerateAndMatchKeys(-1, &iter, &keys_to_match, &count));
3434 cache_->EndEnumeration(&iter); 3439 cache_->EndEnumeration(&iter);
3435 entry_opened_before->Close(); 3440 entry_opened_before->Close();
3436 entry_opened_middle->Close(); 3441 entry_opened_middle->Close();
3437 3442
3438 EXPECT_EQ(key_pool.size(), count); 3443 EXPECT_EQ(key_pool.size(), count);
3439 EXPECT_TRUE(keys_to_match.empty()); 3444 EXPECT_TRUE(keys_to_match.empty());
3440 } 3445 }
3441 3446
3442 // Tests that the enumerations are not affected by dooming an entry in the 3447 // Tests that the enumerations are not affected by dooming an entry in the
3443 // middle. 3448 // middle.
3444 TEST_F(DiskCacheBackendTest, SimpleCacheEnumerationWhileDoomed) { 3449 TEST_F(DiskCacheBackendTest, SimpleCacheEnumerationWhileDoomed) {
3445 SetSimpleCacheMode(); 3450 SetSimpleCacheMode();
3446 InitCache(); 3451 InitCache();
3447 std::set<std::string> key_pool; 3452 std::set<std::string> key_pool;
3448 ASSERT_TRUE(CreateSetOfRandomEntries(&key_pool)); 3453 ASSERT_TRUE(CreateSetOfRandomEntries(&key_pool));
3449 3454
3450 // Check that enumeration returns all entries but the doomed one. 3455 // Check that enumeration returns all entries but the doomed one.
3451 std::set<std::string> keys_to_match(key_pool); 3456 std::set<std::string> keys_to_match(key_pool);
3452 void* iter = NULL; 3457 void* iter = NULL;
3453 size_t count = 0; 3458 size_t count = 0;
3454 ASSERT_TRUE(EnumerateAndMatchKeys(key_pool.size()/2, 3459 ASSERT_TRUE(EnumerateAndMatchKeys(
3455 &iter, 3460 key_pool.size() / 2, &iter, &keys_to_match, &count));
3456 &keys_to_match,
3457 &count));
3458 3461
3459 std::string key_to_delete = *(keys_to_match.begin()); 3462 std::string key_to_delete = *(keys_to_match.begin());
3460 DoomEntry(key_to_delete); 3463 DoomEntry(key_to_delete);
3461 keys_to_match.erase(key_to_delete); 3464 keys_to_match.erase(key_to_delete);
3462 key_pool.erase(key_to_delete); 3465 key_pool.erase(key_to_delete);
3463 ASSERT_TRUE(EnumerateAndMatchKeys(-1, &iter, &keys_to_match, &count)); 3466 ASSERT_TRUE(EnumerateAndMatchKeys(-1, &iter, &keys_to_match, &count));
3464 cache_->EndEnumeration(&iter); 3467 cache_->EndEnumeration(&iter);
3465 3468
3466 EXPECT_EQ(key_pool.size(), count); 3469 EXPECT_EQ(key_pool.size(), count);
3467 EXPECT_TRUE(keys_to_match.empty()); 3470 EXPECT_TRUE(keys_to_match.empty());
(...skipping 15 matching lines...) Expand all
3483 ASSERT_EQ(net::OK, CreateEntry(key, &corrupted_entry)); 3486 ASSERT_EQ(net::OK, CreateEntry(key, &corrupted_entry));
3484 ASSERT_TRUE(corrupted_entry); 3487 ASSERT_TRUE(corrupted_entry);
3485 const int kSize = 50; 3488 const int kSize = 50;
3486 scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(kSize)); 3489 scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(kSize));
3487 CacheTestFillBuffer(buffer->data(), kSize, false); 3490 CacheTestFillBuffer(buffer->data(), kSize, false);
3488 ASSERT_EQ(kSize, 3491 ASSERT_EQ(kSize,
3489 WriteData(corrupted_entry, 0, 0, buffer.get(), kSize, false)); 3492 WriteData(corrupted_entry, 0, 0, buffer.get(), kSize, false));
3490 ASSERT_EQ(kSize, ReadData(corrupted_entry, 0, 0, buffer.get(), kSize)); 3493 ASSERT_EQ(kSize, ReadData(corrupted_entry, 0, 0, buffer.get(), kSize));
3491 corrupted_entry->Close(); 3494 corrupted_entry->Close();
3492 3495
3493 EXPECT_TRUE(disk_cache::simple_util::CreateCorruptFileForTests( 3496 EXPECT_TRUE(
3494 key, cache_path_)); 3497 disk_cache::simple_util::CreateCorruptFileForTests(key, cache_path_));
3495 EXPECT_EQ(key_pool.size() + 1, 3498 EXPECT_EQ(key_pool.size() + 1,
3496 implicit_cast<size_t>(cache_->GetEntryCount())); 3499 implicit_cast<size_t>(cache_->GetEntryCount()));
3497 3500
3498 // Check that enumeration returns all entries but the corrupt one. 3501 // Check that enumeration returns all entries but the corrupt one.
3499 std::set<std::string> keys_to_match(key_pool); 3502 std::set<std::string> keys_to_match(key_pool);
3500 void* iter = NULL; 3503 void* iter = NULL;
3501 size_t count = 0; 3504 size_t count = 0;
3502 ASSERT_TRUE(EnumerateAndMatchKeys(-1, &iter, &keys_to_match, &count)); 3505 ASSERT_TRUE(EnumerateAndMatchKeys(-1, &iter, &keys_to_match, &count));
3503 cache_->EndEnumeration(&iter); 3506 cache_->EndEnumeration(&iter);
3504 3507
3505 EXPECT_EQ(key_pool.size(), count); 3508 EXPECT_EQ(key_pool.size(), count);
3506 EXPECT_TRUE(keys_to_match.empty()); 3509 EXPECT_TRUE(keys_to_match.empty());
3507 } 3510 }
3508 3511
3509 #endif // defined(OS_POSIX) 3512 #endif // defined(OS_POSIX)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698