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/files/file.h" | 7 #include "base/files/file.h" |
8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
9 #include "base/metrics/field_trial.h" | 9 #include "base/metrics/field_trial.h" |
10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
(...skipping 15 matching lines...) Expand all Loading... |
26 #include "net/disk_cache/blockfile/experiments.h" | 26 #include "net/disk_cache/blockfile/experiments.h" |
27 #include "net/disk_cache/blockfile/histogram_macros.h" | 27 #include "net/disk_cache/blockfile/histogram_macros.h" |
28 #include "net/disk_cache/blockfile/mapped_file.h" | 28 #include "net/disk_cache/blockfile/mapped_file.h" |
29 #include "net/disk_cache/cache_util.h" | 29 #include "net/disk_cache/cache_util.h" |
30 #include "net/disk_cache/disk_cache_test_base.h" | 30 #include "net/disk_cache/disk_cache_test_base.h" |
31 #include "net/disk_cache/disk_cache_test_util.h" | 31 #include "net/disk_cache/disk_cache_test_util.h" |
32 #include "net/disk_cache/memory/mem_backend_impl.h" | 32 #include "net/disk_cache/memory/mem_backend_impl.h" |
33 #include "net/disk_cache/simple/simple_backend_impl.h" | 33 #include "net/disk_cache/simple/simple_backend_impl.h" |
34 #include "net/disk_cache/simple/simple_entry_format.h" | 34 #include "net/disk_cache/simple/simple_entry_format.h" |
35 #include "net/disk_cache/simple/simple_index.h" | 35 #include "net/disk_cache/simple/simple_index.h" |
| 36 #include "net/disk_cache/simple/simple_synchronous_entry.h" |
36 #include "net/disk_cache/simple/simple_test_util.h" | 37 #include "net/disk_cache/simple/simple_test_util.h" |
37 #include "net/disk_cache/simple/simple_util.h" | 38 #include "net/disk_cache/simple/simple_util.h" |
38 #include "testing/gtest/include/gtest/gtest.h" | 39 #include "testing/gtest/include/gtest/gtest.h" |
39 | 40 |
40 #if defined(OS_WIN) | 41 #if defined(OS_WIN) |
41 #include "base/win/scoped_handle.h" | 42 #include "base/win/scoped_handle.h" |
42 #endif | 43 #endif |
43 | 44 |
44 // Provide a BackendImpl object to macros from histogram_macros.h. | 45 // Provide a BackendImpl object to macros from histogram_macros.h. |
45 #define CACHE_UMA_BACKEND_IMPL_OBJ backend_ | 46 #define CACHE_UMA_BACKEND_IMPL_OBJ backend_ |
(...skipping 3687 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3733 std::unique_ptr<TestIterator> iter = CreateIterator(); | 3734 std::unique_ptr<TestIterator> iter = CreateIterator(); |
3734 disk_cache::Entry* entry = NULL; | 3735 disk_cache::Entry* entry = NULL; |
3735 ASSERT_EQ(net::OK, iter->OpenNextEntry(&entry)); | 3736 ASSERT_EQ(net::OK, iter->OpenNextEntry(&entry)); |
3736 EXPECT_TRUE(entry); | 3737 EXPECT_TRUE(entry); |
3737 disk_cache::ScopedEntryPtr entry_closer(entry); | 3738 disk_cache::ScopedEntryPtr entry_closer(entry); |
3738 | 3739 |
3739 cache_.reset(); | 3740 cache_.reset(); |
3740 // This test passes if we don't leak memory. | 3741 // This test passes if we don't leak memory. |
3741 } | 3742 } |
3742 | 3743 |
| 3744 // Tests that enumerations include entries with long keys. |
| 3745 TEST_F(DiskCacheBackendTest, SimpleCacheEnumerationLongKeys) { |
| 3746 SetSimpleCacheMode(); |
| 3747 InitCache(); |
| 3748 std::set<std::string> key_pool; |
| 3749 ASSERT_TRUE(CreateSetOfRandomEntries(&key_pool)); |
| 3750 |
| 3751 const size_t long_key_length = |
| 3752 disk_cache::SimpleSynchronousEntry::kInitialHeaderRead + 10; |
| 3753 std::string long_key(long_key_length, 'X'); |
| 3754 key_pool.insert(long_key); |
| 3755 disk_cache::Entry* entry = NULL; |
| 3756 ASSERT_EQ(net::OK, CreateEntry(long_key.c_str(), &entry)); |
| 3757 entry->Close(); |
| 3758 |
| 3759 std::unique_ptr<TestIterator> iter = CreateIterator(); |
| 3760 size_t count = 0; |
| 3761 EXPECT_TRUE(EnumerateAndMatchKeys(-1, iter.get(), &key_pool, &count)); |
| 3762 EXPECT_TRUE(key_pool.empty()); |
| 3763 } |
| 3764 |
3743 // Tests that a SimpleCache doesn't crash when files are deleted very quickly | 3765 // Tests that a SimpleCache doesn't crash when files are deleted very quickly |
3744 // after closing. | 3766 // after closing. |
3745 // NOTE: IF THIS TEST IS FLAKY THEN IT IS FAILING. See https://crbug.com/416940 | 3767 // NOTE: IF THIS TEST IS FLAKY THEN IT IS FAILING. See https://crbug.com/416940 |
3746 TEST_F(DiskCacheBackendTest, SimpleCacheDeleteQuickly) { | 3768 TEST_F(DiskCacheBackendTest, SimpleCacheDeleteQuickly) { |
3747 SetSimpleCacheMode(); | 3769 SetSimpleCacheMode(); |
3748 for (int i = 0; i < 100; ++i) { | 3770 for (int i = 0; i < 100; ++i) { |
3749 InitCache(); | 3771 InitCache(); |
3750 cache_.reset(); | 3772 cache_.reset(); |
3751 EXPECT_TRUE(CleanupCacheDir()); | 3773 EXPECT_TRUE(CleanupCacheDir()); |
3752 } | 3774 } |
(...skipping 23 matching lines...) Expand all Loading... |
3776 // because that would advance the cache directory mtime and invalidate the | 3798 // because that would advance the cache directory mtime and invalidate the |
3777 // index. | 3799 // index. |
3778 entry2->Doom(); | 3800 entry2->Doom(); |
3779 entry2->Close(); | 3801 entry2->Close(); |
3780 | 3802 |
3781 DisableFirstCleanup(); | 3803 DisableFirstCleanup(); |
3782 InitCache(); | 3804 InitCache(); |
3783 EXPECT_EQ(disk_cache::SimpleIndex::INITIALIZE_METHOD_LOADED, | 3805 EXPECT_EQ(disk_cache::SimpleIndex::INITIALIZE_METHOD_LOADED, |
3784 simple_cache_impl_->index()->init_method()); | 3806 simple_cache_impl_->index()->init_method()); |
3785 } | 3807 } |
OLD | NEW |