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 "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/port.h" | 8 #include "base/port.h" |
8 #include "base/string_util.h" | 9 #include "base/string_util.h" |
9 #include "base/stringprintf.h" | 10 #include "base/stringprintf.h" |
10 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" | 11 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" |
11 #include "base/threading/platform_thread.h" | 12 #include "base/threading/platform_thread.h" |
12 #include "base/threading/thread_restrictions.h" | 13 #include "base/threading/thread_restrictions.h" |
13 #include "net/base/io_buffer.h" | 14 #include "net/base/io_buffer.h" |
14 #include "net/base/net_errors.h" | 15 #include "net/base/net_errors.h" |
15 #include "net/base/test_completion_callback.h" | 16 #include "net/base/test_completion_callback.h" |
16 #include "net/disk_cache/backend_impl.h" | 17 #include "net/disk_cache/backend_impl.h" |
17 #include "net/disk_cache/cache_util.h" | 18 #include "net/disk_cache/cache_util.h" |
18 #include "net/disk_cache/disk_cache_test_base.h" | 19 #include "net/disk_cache/disk_cache_test_base.h" |
19 #include "net/disk_cache/disk_cache_test_util.h" | 20 #include "net/disk_cache/disk_cache_test_util.h" |
20 #include "net/disk_cache/entry_impl.h" | 21 #include "net/disk_cache/entry_impl.h" |
21 #include "net/disk_cache/histogram_macros.h" | 22 #include "net/disk_cache/histogram_macros.h" |
22 #include "net/disk_cache/mapped_file.h" | 23 #include "net/disk_cache/mapped_file.h" |
23 #include "net/disk_cache/mem_backend_impl.h" | 24 #include "net/disk_cache/mem_backend_impl.h" |
24 #include "net/disk_cache/simple/simple_entry_format.h" | 25 #include "net/disk_cache/simple/simple_entry_format.h" |
25 #include "net/disk_cache/simple/simple_util.h" | 26 #include "net/disk_cache/simple/simple_util.h" |
26 #include "net/disk_cache/tracing_cache_backend.h" | 27 #include "net/disk_cache/tracing_cache_backend.h" |
27 #include "testing/gtest/include/gtest/gtest.h" | 28 #include "testing/gtest/include/gtest/gtest.h" |
28 | 29 |
29 #if defined(OS_WIN) | 30 #if defined(OS_WIN) |
30 #include "base/win/scoped_handle.h" | 31 #include "base/win/scoped_handle.h" |
31 #endif | 32 #endif |
32 | 33 |
33 using base::Time; | 34 using base::Time; |
34 | 35 |
36 namespace { | |
37 | |
35 // Tests that can run with different types of caches. | 38 // Tests that can run with different types of caches. |
36 class DiskCacheBackendTest : public DiskCacheTestWithCache { | 39 class DiskCacheBackendTest : public DiskCacheTestWithCache { |
37 protected: | 40 protected: |
38 void BackendBasics(); | 41 void BackendBasics(); |
39 void BackendKeying(); | 42 void BackendKeying(); |
40 void BackendShutdownWithPendingFileIO(bool fast); | 43 void BackendShutdownWithPendingFileIO(bool fast); |
41 void BackendShutdownWithPendingIO(bool fast); | 44 void BackendShutdownWithPendingIO(bool fast); |
42 void BackendShutdownWithPendingCreate(bool fast); | 45 void BackendShutdownWithPendingCreate(bool fast); |
43 void BackendSetSize(); | 46 void BackendSetSize(); |
44 void BackendLoad(); | 47 void BackendLoad(); |
(...skipping 1625 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1670 net::TestCompletionCallback cb; | 1673 net::TestCompletionCallback cb; |
1671 | 1674 |
1672 disk_cache::BackendImpl* cache = new disk_cache::BackendImpl( | 1675 disk_cache::BackendImpl* cache = new disk_cache::BackendImpl( |
1673 cache_path_, cache_thread.message_loop_proxy(), NULL); | 1676 cache_path_, cache_thread.message_loop_proxy(), NULL); |
1674 int rv = cache->Init(cb.callback()); | 1677 int rv = cache->Init(cb.callback()); |
1675 ASSERT_EQ(net::ERR_FAILED, cb.GetResult(rv)); | 1678 ASSERT_EQ(net::ERR_FAILED, cb.GetResult(rv)); |
1676 | 1679 |
1677 delete cache; | 1680 delete cache; |
1678 } | 1681 } |
1679 | 1682 |
1683 class BadEntropyProvider : public base::FieldTrial::EntropyProvider { | |
1684 public: | |
1685 virtual ~BadEntropyProvider() {} | |
1686 | |
1687 virtual double GetEntropyForTrial(const std::string& trial_name, | |
1688 uint32 randomization_seed) const OVERRIDE { | |
1689 return 0.5; | |
1690 } | |
1691 }; | |
1692 | |
1693 TEST_F(DiskCacheTest, SimpleCacheControlJoin) { | |
1694 ASSERT_TRUE(CopyTestCache("insert_empty1")); | |
1695 | |
1696 base::FieldTrialList field_trial_list(new BadEntropyProvider()); | |
1697 base::FieldTrialList::FactoryGetFieldTrial("SimpleCacheTrial", 100, | |
1698 "Control", 2013, 12, 31, NULL); | |
1699 | |
1700 base::Thread cache_thread("CacheThread"); | |
1701 ASSERT_TRUE(cache_thread.StartWithOptions( | |
1702 base::Thread::Options(MessageLoop::TYPE_IO, 0))); | |
1703 net::TestCompletionCallback cb; | |
1704 | |
1705 disk_cache::BackendImpl* cache = new disk_cache::BackendImpl( | |
1706 cache_path_, cache_thread.message_loop_proxy(), NULL); | |
1707 int rv = cache->Init(cb.callback()); | |
1708 ASSERT_EQ(net::ERR_FAILED, cb.GetResult(rv)); | |
1709 | |
1710 delete cache; | |
1711 } | |
1712 | |
1713 TEST_F(DiskCacheTest, SimpleCacheControlRestart) { | |
1714 ASSERT_TRUE(CopyTestCache("simple_cache_control")); | |
1715 | |
1716 base::FieldTrialList field_trial_list(new BadEntropyProvider()); | |
1717 base::FieldTrialList::FactoryGetFieldTrial("SimpleCacheTrial", 100, | |
1718 "Control", 2013, 12, 31, NULL); | |
1719 | |
1720 base::Thread cache_thread("CacheThread"); | |
1721 ASSERT_TRUE(cache_thread.StartWithOptions( | |
1722 base::Thread::Options(MessageLoop::TYPE_IO, 0))); | |
1723 net::TestCompletionCallback cb; | |
1724 | |
1725 disk_cache::BackendImpl* cache = new disk_cache::BackendImpl( | |
1726 cache_path_, cache_thread.message_loop_proxy(), NULL); | |
1727 int rv = cache->Init(cb.callback()); | |
1728 ASSERT_EQ(net::OK, cb.GetResult(rv)); | |
1729 | |
1730 delete cache; | |
1731 } | |
1732 | |
1733 TEST_F(DiskCacheTest, SimpleCacheControlLeave) { | |
1734 ASSERT_TRUE(CopyTestCache("simple_cache_control")); | |
pasko-google - do not use
2013/04/19 18:00:30
coud we create this file programmatically here? bi
gavinp
2013/04/20 07:17:32
Mooted, as Ricardo has asked for the removal of th
| |
1735 | |
1736 base::Thread cache_thread("CacheThread"); | |
1737 ASSERT_TRUE(cache_thread.StartWithOptions( | |
1738 base::Thread::Options(MessageLoop::TYPE_IO, 0))); | |
1739 net::TestCompletionCallback cb; | |
1740 | |
1741 disk_cache::BackendImpl* cache = new disk_cache::BackendImpl( | |
1742 cache_path_, cache_thread.message_loop_proxy(), NULL); | |
1743 int rv = cache->Init(cb.callback()); | |
1744 ASSERT_EQ(net::OK, cb.GetResult(rv)); | |
1745 | |
1746 delete cache; | |
1747 } | |
1748 | |
rvargas (doing something else)
2013/04/19 17:40:55
I would actually prefer not adding these tests. I
gavinp
2013/04/20 07:17:32
Done.
| |
1680 // Tests that the cache is properly restarted on recovery error. | 1749 // Tests that the cache is properly restarted on recovery error. |
1681 TEST_F(DiskCacheBackendTest, DeleteOld) { | 1750 TEST_F(DiskCacheBackendTest, DeleteOld) { |
1682 ASSERT_TRUE(CopyTestCache("wrong_version")); | 1751 ASSERT_TRUE(CopyTestCache("wrong_version")); |
1683 SetNewEviction(); | 1752 SetNewEviction(); |
1684 base::Thread cache_thread("CacheThread"); | 1753 base::Thread cache_thread("CacheThread"); |
1685 ASSERT_TRUE(cache_thread.StartWithOptions( | 1754 ASSERT_TRUE(cache_thread.StartWithOptions( |
1686 base::Thread::Options(MessageLoop::TYPE_IO, 0))); | 1755 base::Thread::Options(MessageLoop::TYPE_IO, 0))); |
1687 | 1756 |
1688 net::TestCompletionCallback cb; | 1757 net::TestCompletionCallback cb; |
1689 bool prev = base::ThreadRestrictions::SetIOAllowed(false); | 1758 bool prev = base::ThreadRestrictions::SetIOAllowed(false); |
(...skipping 1100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2790 cache_->OnExternalCacheHit("key0"); | 2859 cache_->OnExternalCacheHit("key0"); |
2791 | 2860 |
2792 TrimForTest(false); | 2861 TrimForTest(false); |
2793 | 2862 |
2794 // Make sure the older key remains. | 2863 // Make sure the older key remains. |
2795 EXPECT_EQ(1, cache_->GetEntryCount()); | 2864 EXPECT_EQ(1, cache_->GetEntryCount()); |
2796 ASSERT_EQ(net::OK, OpenEntry("key0", &entry)); | 2865 ASSERT_EQ(net::OK, OpenEntry("key0", &entry)); |
2797 entry->Close(); | 2866 entry->Close(); |
2798 } | 2867 } |
2799 | 2868 |
2869 } // namespace | |
rvargas (doing something else)
2013/04/19 17:40:55
I don't understand why you're placing half of the
gavinp
2013/04/20 07:17:32
Moot, now that I"m not adding tests.
| |
2870 | |
2800 void DiskCacheBackendTest::TracingBackendBasics() { | 2871 void DiskCacheBackendTest::TracingBackendBasics() { |
2801 InitCache(); | 2872 InitCache(); |
2802 cache_ = new disk_cache::TracingCacheBackend(cache_); | 2873 cache_ = new disk_cache::TracingCacheBackend(cache_); |
2803 cache_impl_ = NULL; | 2874 cache_impl_ = NULL; |
2804 EXPECT_EQ(net::DISK_CACHE, cache_->GetCacheType()); | 2875 EXPECT_EQ(net::DISK_CACHE, cache_->GetCacheType()); |
2805 if (!simple_cache_mode_) { | 2876 if (!simple_cache_mode_) { |
2806 EXPECT_EQ(0, cache_->GetEntryCount()); | 2877 EXPECT_EQ(0, cache_->GetEntryCount()); |
2807 } | 2878 } |
2808 | 2879 |
2809 net::TestCompletionCallback cb; | 2880 net::TestCompletionCallback cb; |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2905 BackendDoomRecent(); | 2976 BackendDoomRecent(); |
2906 } | 2977 } |
2907 | 2978 |
2908 TEST_F(DiskCacheBackendTest, SimpleDoomBetween) { | 2979 TEST_F(DiskCacheBackendTest, SimpleDoomBetween) { |
2909 SetSimpleCacheMode(); | 2980 SetSimpleCacheMode(); |
2910 InitCache(); | 2981 InitCache(); |
2911 BackendDoomBetween(); | 2982 BackendDoomBetween(); |
2912 } | 2983 } |
2913 | 2984 |
2914 #endif // !defined(OS_WIN) | 2985 #endif // !defined(OS_WIN) |
OLD | NEW |