OLD | NEW |
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 <stdint.h> | 5 #include <stdint.h> |
6 | 6 |
7 #include "base/basictypes.h" | |
8 #include "base/files/file_util.h" | 7 #include "base/files/file_util.h" |
9 #include "base/metrics/field_trial.h" | 8 #include "base/metrics/field_trial.h" |
10 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
11 #include "base/strings/string_split.h" | 10 #include "base/strings/string_split.h" |
12 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
13 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
14 #include "base/test/mock_entropy_provider.h" | 13 #include "base/test/mock_entropy_provider.h" |
15 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" | 14 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" |
16 #include "base/thread_task_runner_handle.h" | 15 #include "base/thread_task_runner_handle.h" |
17 #include "base/threading/platform_thread.h" | 16 #include "base/threading/platform_thread.h" |
(...skipping 496 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
514 | 513 |
515 // And verify that the first file is still there. | 514 // And verify that the first file is still there. |
516 scoped_refptr<net::IOBuffer> buffer2(new net::IOBuffer(kSize)); | 515 scoped_refptr<net::IOBuffer> buffer2(new net::IOBuffer(kSize)); |
517 ASSERT_EQ(kSize, base::ReadFile(filename, buffer2->data(), kSize)); | 516 ASSERT_EQ(kSize, base::ReadFile(filename, buffer2->data(), kSize)); |
518 EXPECT_EQ(0, memcmp(buffer1->data(), buffer2->data(), kSize)); | 517 EXPECT_EQ(0, memcmp(buffer1->data(), buffer2->data(), kSize)); |
519 } | 518 } |
520 | 519 |
521 // Tests that we deal with file-level pending operations at destruction time. | 520 // Tests that we deal with file-level pending operations at destruction time. |
522 void DiskCacheBackendTest::BackendShutdownWithPendingFileIO(bool fast) { | 521 void DiskCacheBackendTest::BackendShutdownWithPendingFileIO(bool fast) { |
523 ASSERT_TRUE(CleanupCacheDir()); | 522 ASSERT_TRUE(CleanupCacheDir()); |
524 uint32 flags = disk_cache::kNoBuffering; | 523 uint32_t flags = disk_cache::kNoBuffering; |
525 if (!fast) | 524 if (!fast) |
526 flags |= disk_cache::kNoRandom; | 525 flags |= disk_cache::kNoRandom; |
527 | 526 |
528 UseCurrentThread(); | 527 UseCurrentThread(); |
529 CreateBackend(flags, NULL); | 528 CreateBackend(flags, NULL); |
530 | 529 |
531 net::TestCompletionCallback cb; | 530 net::TestCompletionCallback cb; |
532 int rv = GeneratePendingIO(&cb); | 531 int rv = GeneratePendingIO(&cb); |
533 | 532 |
534 // The cache destructor will see one pending operation here. | 533 // The cache destructor will see one pending operation here. |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
616 // Tests that we deal with background-thread pending operations. | 615 // Tests that we deal with background-thread pending operations. |
617 void DiskCacheBackendTest::BackendShutdownWithPendingIO(bool fast) { | 616 void DiskCacheBackendTest::BackendShutdownWithPendingIO(bool fast) { |
618 net::TestCompletionCallback cb; | 617 net::TestCompletionCallback cb; |
619 | 618 |
620 { | 619 { |
621 ASSERT_TRUE(CleanupCacheDir()); | 620 ASSERT_TRUE(CleanupCacheDir()); |
622 base::Thread cache_thread("CacheThread"); | 621 base::Thread cache_thread("CacheThread"); |
623 ASSERT_TRUE(cache_thread.StartWithOptions( | 622 ASSERT_TRUE(cache_thread.StartWithOptions( |
624 base::Thread::Options(base::MessageLoop::TYPE_IO, 0))); | 623 base::Thread::Options(base::MessageLoop::TYPE_IO, 0))); |
625 | 624 |
626 uint32 flags = disk_cache::kNoBuffering; | 625 uint32_t flags = disk_cache::kNoBuffering; |
627 if (!fast) | 626 if (!fast) |
628 flags |= disk_cache::kNoRandom; | 627 flags |= disk_cache::kNoRandom; |
629 | 628 |
630 CreateBackend(flags, &cache_thread); | 629 CreateBackend(flags, &cache_thread); |
631 | 630 |
632 disk_cache::Entry* entry; | 631 disk_cache::Entry* entry; |
633 int rv = cache_->CreateEntry("some key", &entry, cb.callback()); | 632 int rv = cache_->CreateEntry("some key", &entry, cb.callback()); |
634 ASSERT_EQ(net::OK, cb.GetResult(rv)); | 633 ASSERT_EQ(net::OK, cb.GetResult(rv)); |
635 | 634 |
636 entry->Close(); | 635 entry->Close(); |
(...skipping 1130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1767 SetSimpleCacheMode(); | 1766 SetSimpleCacheMode(); |
1768 BackendCalculateSizeOfAllEntries(); | 1767 BackendCalculateSizeOfAllEntries(); |
1769 } | 1768 } |
1770 | 1769 |
1771 void DiskCacheBackendTest::BackendTransaction(const std::string& name, | 1770 void DiskCacheBackendTest::BackendTransaction(const std::string& name, |
1772 int num_entries, bool load) { | 1771 int num_entries, bool load) { |
1773 success_ = false; | 1772 success_ = false; |
1774 ASSERT_TRUE(CopyTestCache(name)); | 1773 ASSERT_TRUE(CopyTestCache(name)); |
1775 DisableFirstCleanup(); | 1774 DisableFirstCleanup(); |
1776 | 1775 |
1777 uint32 mask; | 1776 uint32_t mask; |
1778 if (load) { | 1777 if (load) { |
1779 mask = 0xf; | 1778 mask = 0xf; |
1780 SetMaxSize(0x100000); | 1779 SetMaxSize(0x100000); |
1781 } else { | 1780 } else { |
1782 // Clear the settings from the previous run. | 1781 // Clear the settings from the previous run. |
1783 mask = 0; | 1782 mask = 0; |
1784 SetMaxSize(0); | 1783 SetMaxSize(0); |
1785 } | 1784 } |
1786 SetMask(mask); | 1785 SetMask(mask); |
1787 | 1786 |
(...skipping 1280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3068 for (int i = 0; i < kNumberOfCaches; i++) { | 3067 for (int i = 0; i < kNumberOfCaches; i++) { |
3069 rv = cache[i]->CreateEntry(key, &entry, cb.callback()); | 3068 rv = cache[i]->CreateEntry(key, &entry, cb.callback()); |
3070 ASSERT_EQ(net::OK, cb.GetResult(rv)); | 3069 ASSERT_EQ(net::OK, cb.GetResult(rv)); |
3071 entry->Close(); | 3070 entry->Close(); |
3072 } | 3071 } |
3073 } | 3072 } |
3074 | 3073 |
3075 // Test the six regions of the curve that determines the max cache size. | 3074 // Test the six regions of the curve that determines the max cache size. |
3076 TEST_F(DiskCacheTest, AutomaticMaxSize) { | 3075 TEST_F(DiskCacheTest, AutomaticMaxSize) { |
3077 using disk_cache::kDefaultCacheSize; | 3076 using disk_cache::kDefaultCacheSize; |
3078 int64 large_size = kDefaultCacheSize; | 3077 int64_t large_size = kDefaultCacheSize; |
3079 | 3078 |
3080 // Region 1: expected = available * 0.8 | 3079 // Region 1: expected = available * 0.8 |
3081 EXPECT_EQ((kDefaultCacheSize - 1) * 8 / 10, | 3080 EXPECT_EQ((kDefaultCacheSize - 1) * 8 / 10, |
3082 disk_cache::PreferredCacheSize(large_size - 1)); | 3081 disk_cache::PreferredCacheSize(large_size - 1)); |
3083 EXPECT_EQ(kDefaultCacheSize * 8 / 10, | 3082 EXPECT_EQ(kDefaultCacheSize * 8 / 10, |
3084 disk_cache::PreferredCacheSize(large_size)); | 3083 disk_cache::PreferredCacheSize(large_size)); |
3085 EXPECT_EQ(kDefaultCacheSize - 1, | 3084 EXPECT_EQ(kDefaultCacheSize - 1, |
3086 disk_cache::PreferredCacheSize(large_size * 10 / 8 - 1)); | 3085 disk_cache::PreferredCacheSize(large_size * 10 / 8 - 1)); |
3087 | 3086 |
3088 // Region 2: expected = default_size | 3087 // Region 2: expected = default_size |
(...skipping 12 matching lines...) Expand all Loading... |
3101 EXPECT_EQ(kDefaultCacheSize * 25 / 10, | 3100 EXPECT_EQ(kDefaultCacheSize * 25 / 10, |
3102 disk_cache::PreferredCacheSize(large_size * 25)); | 3101 disk_cache::PreferredCacheSize(large_size * 25)); |
3103 EXPECT_EQ(kDefaultCacheSize * 25 / 10, | 3102 EXPECT_EQ(kDefaultCacheSize * 25 / 10, |
3104 disk_cache::PreferredCacheSize(large_size * 100 - 1)); | 3103 disk_cache::PreferredCacheSize(large_size * 100 - 1)); |
3105 EXPECT_EQ(kDefaultCacheSize * 25 / 10, | 3104 EXPECT_EQ(kDefaultCacheSize * 25 / 10, |
3106 disk_cache::PreferredCacheSize(large_size * 100)); | 3105 disk_cache::PreferredCacheSize(large_size * 100)); |
3107 EXPECT_EQ(kDefaultCacheSize * 25 / 10, | 3106 EXPECT_EQ(kDefaultCacheSize * 25 / 10, |
3108 disk_cache::PreferredCacheSize(large_size * 250 - 1)); | 3107 disk_cache::PreferredCacheSize(large_size * 250 - 1)); |
3109 | 3108 |
3110 // Region 5: expected = available * 0.1 | 3109 // Region 5: expected = available * 0.1 |
3111 int64 largest_size = kDefaultCacheSize * 4; | 3110 int64_t largest_size = kDefaultCacheSize * 4; |
3112 EXPECT_EQ(kDefaultCacheSize * 25 / 10, | 3111 EXPECT_EQ(kDefaultCacheSize * 25 / 10, |
3113 disk_cache::PreferredCacheSize(large_size * 250)); | 3112 disk_cache::PreferredCacheSize(large_size * 250)); |
3114 EXPECT_EQ(largest_size - 1, | 3113 EXPECT_EQ(largest_size - 1, |
3115 disk_cache::PreferredCacheSize(largest_size * 100 - 1)); | 3114 disk_cache::PreferredCacheSize(largest_size * 100 - 1)); |
3116 | 3115 |
3117 // Region 6: expected = largest possible size | 3116 // Region 6: expected = largest possible size |
3118 EXPECT_EQ(largest_size, | 3117 EXPECT_EQ(largest_size, |
3119 disk_cache::PreferredCacheSize(largest_size * 100)); | 3118 disk_cache::PreferredCacheSize(largest_size * 100)); |
3120 EXPECT_EQ(largest_size, | 3119 EXPECT_EQ(largest_size, |
3121 disk_cache::PreferredCacheSize(largest_size * 10000)); | 3120 disk_cache::PreferredCacheSize(largest_size * 10000)); |
(...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3617 // after closing. | 3616 // after closing. |
3618 // NOTE: IF THIS TEST IS FLAKY THEN IT IS FAILING. See https://crbug.com/416940 | 3617 // NOTE: IF THIS TEST IS FLAKY THEN IT IS FAILING. See https://crbug.com/416940 |
3619 TEST_F(DiskCacheBackendTest, SimpleCacheDeleteQuickly) { | 3618 TEST_F(DiskCacheBackendTest, SimpleCacheDeleteQuickly) { |
3620 SetSimpleCacheMode(); | 3619 SetSimpleCacheMode(); |
3621 for (int i = 0; i < 100; ++i) { | 3620 for (int i = 0; i < 100; ++i) { |
3622 InitCache(); | 3621 InitCache(); |
3623 cache_.reset(); | 3622 cache_.reset(); |
3624 EXPECT_TRUE(CleanupCacheDir()); | 3623 EXPECT_TRUE(CleanupCacheDir()); |
3625 } | 3624 } |
3626 } | 3625 } |
OLD | NEW |