| 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/memory/ptr_util.h" |
| 9 #include "base/metrics/field_trial.h" | 10 #include "base/metrics/field_trial.h" |
| 10 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
| 11 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
| 12 #include "base/strings/string_split.h" | 13 #include "base/strings/string_split.h" |
| 13 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
| 14 #include "base/strings/stringprintf.h" | 15 #include "base/strings/stringprintf.h" |
| 15 #include "base/test/mock_entropy_provider.h" | 16 #include "base/test/mock_entropy_provider.h" |
| 16 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" | 17 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" |
| 17 #include "base/threading/platform_thread.h" | 18 #include "base/threading/platform_thread.h" |
| 18 #include "base/threading/thread_restrictions.h" | 19 #include "base/threading/thread_restrictions.h" |
| (...skipping 2031 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2050 ASSERT_TRUE(cache_thread.StartWithOptions( | 2051 ASSERT_TRUE(cache_thread.StartWithOptions( |
| 2051 base::Thread::Options(base::MessageLoop::TYPE_IO, 0))); | 2052 base::Thread::Options(base::MessageLoop::TYPE_IO, 0))); |
| 2052 | 2053 |
| 2053 std::unique_ptr<disk_cache::BackendImpl> cache = | 2054 std::unique_ptr<disk_cache::BackendImpl> cache = |
| 2054 CreateExistingEntryCache(cache_thread, cache_path_); | 2055 CreateExistingEntryCache(cache_thread, cache_path_); |
| 2055 ASSERT_TRUE(cache.get()); | 2056 ASSERT_TRUE(cache.get()); |
| 2056 cache.reset(); | 2057 cache.reset(); |
| 2057 | 2058 |
| 2058 // Instantiate the SimpleCacheTrial, forcing this run into the | 2059 // Instantiate the SimpleCacheTrial, forcing this run into the |
| 2059 // ExperimentControl group. | 2060 // ExperimentControl group. |
| 2060 base::FieldTrialList field_trial_list(new base::MockEntropyProvider()); | 2061 base::FieldTrialList field_trial_list( |
| 2062 base::MakeUnique<base::MockEntropyProvider>()); |
| 2061 base::FieldTrialList::CreateFieldTrial("SimpleCacheTrial", | 2063 base::FieldTrialList::CreateFieldTrial("SimpleCacheTrial", |
| 2062 "ExperimentControl"); | 2064 "ExperimentControl"); |
| 2063 net::TestCompletionCallback cb; | 2065 net::TestCompletionCallback cb; |
| 2064 std::unique_ptr<disk_cache::Backend> base_cache; | 2066 std::unique_ptr<disk_cache::Backend> base_cache; |
| 2065 int rv = disk_cache::CreateCacheBackend(net::DISK_CACHE, | 2067 int rv = disk_cache::CreateCacheBackend(net::DISK_CACHE, |
| 2066 net::CACHE_BACKEND_BLOCKFILE, | 2068 net::CACHE_BACKEND_BLOCKFILE, |
| 2067 cache_path_, | 2069 cache_path_, |
| 2068 0, | 2070 0, |
| 2069 true, | 2071 true, |
| 2070 cache_thread.task_runner(), | 2072 cache_thread.task_runner(), |
| 2071 NULL, | 2073 NULL, |
| 2072 &base_cache, | 2074 &base_cache, |
| 2073 cb.callback()); | 2075 cb.callback()); |
| 2074 ASSERT_THAT(cb.GetResult(rv), IsOk()); | 2076 ASSERT_THAT(cb.GetResult(rv), IsOk()); |
| 2075 EXPECT_EQ(0, base_cache->GetEntryCount()); | 2077 EXPECT_EQ(0, base_cache->GetEntryCount()); |
| 2076 } | 2078 } |
| 2077 #endif | 2079 #endif |
| 2078 | 2080 |
| 2079 // Tests that the disk cache can restart in the control group preserving | 2081 // Tests that the disk cache can restart in the control group preserving |
| 2080 // existing entries. | 2082 // existing entries. |
| 2081 TEST_F(DiskCacheTest, SimpleCacheControlRestart) { | 2083 TEST_F(DiskCacheTest, SimpleCacheControlRestart) { |
| 2082 // Instantiate the SimpleCacheTrial, forcing this run into the | 2084 // Instantiate the SimpleCacheTrial, forcing this run into the |
| 2083 // ExperimentControl group. | 2085 // ExperimentControl group. |
| 2084 base::FieldTrialList field_trial_list(new base::MockEntropyProvider()); | 2086 base::FieldTrialList field_trial_list( |
| 2087 base::MakeUnique<base::MockEntropyProvider>()); |
| 2085 base::FieldTrialList::CreateFieldTrial("SimpleCacheTrial", | 2088 base::FieldTrialList::CreateFieldTrial("SimpleCacheTrial", |
| 2086 "ExperimentControl"); | 2089 "ExperimentControl"); |
| 2087 | 2090 |
| 2088 base::Thread cache_thread("CacheThread"); | 2091 base::Thread cache_thread("CacheThread"); |
| 2089 ASSERT_TRUE(cache_thread.StartWithOptions( | 2092 ASSERT_TRUE(cache_thread.StartWithOptions( |
| 2090 base::Thread::Options(base::MessageLoop::TYPE_IO, 0))); | 2093 base::Thread::Options(base::MessageLoop::TYPE_IO, 0))); |
| 2091 | 2094 |
| 2092 std::unique_ptr<disk_cache::BackendImpl> cache = | 2095 std::unique_ptr<disk_cache::BackendImpl> cache = |
| 2093 CreateExistingEntryCache(cache_thread, cache_path_); | 2096 CreateExistingEntryCache(cache_thread, cache_path_); |
| 2094 ASSERT_TRUE(cache.get()); | 2097 ASSERT_TRUE(cache.get()); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 2114 // Tests that the disk cache can leave the control group preserving existing | 2117 // Tests that the disk cache can leave the control group preserving existing |
| 2115 // entries. | 2118 // entries. |
| 2116 TEST_F(DiskCacheTest, SimpleCacheControlLeave) { | 2119 TEST_F(DiskCacheTest, SimpleCacheControlLeave) { |
| 2117 base::Thread cache_thread("CacheThread"); | 2120 base::Thread cache_thread("CacheThread"); |
| 2118 ASSERT_TRUE(cache_thread.StartWithOptions( | 2121 ASSERT_TRUE(cache_thread.StartWithOptions( |
| 2119 base::Thread::Options(base::MessageLoop::TYPE_IO, 0))); | 2122 base::Thread::Options(base::MessageLoop::TYPE_IO, 0))); |
| 2120 | 2123 |
| 2121 { | 2124 { |
| 2122 // Instantiate the SimpleCacheTrial, forcing this run into the | 2125 // Instantiate the SimpleCacheTrial, forcing this run into the |
| 2123 // ExperimentControl group. | 2126 // ExperimentControl group. |
| 2124 base::FieldTrialList field_trial_list(new base::MockEntropyProvider()); | 2127 base::FieldTrialList field_trial_list( |
| 2128 base::MakeUnique<base::MockEntropyProvider>()); |
| 2125 base::FieldTrialList::CreateFieldTrial("SimpleCacheTrial", | 2129 base::FieldTrialList::CreateFieldTrial("SimpleCacheTrial", |
| 2126 "ExperimentControl"); | 2130 "ExperimentControl"); |
| 2127 | 2131 |
| 2128 std::unique_ptr<disk_cache::BackendImpl> cache = | 2132 std::unique_ptr<disk_cache::BackendImpl> cache = |
| 2129 CreateExistingEntryCache(cache_thread, cache_path_); | 2133 CreateExistingEntryCache(cache_thread, cache_path_); |
| 2130 ASSERT_TRUE(cache.get()); | 2134 ASSERT_TRUE(cache.get()); |
| 2131 } | 2135 } |
| 2132 | 2136 |
| 2133 // Instantiate the SimpleCacheTrial, forcing this run into the | 2137 // Instantiate the SimpleCacheTrial, forcing this run into the |
| 2134 // ExperimentNo group. | 2138 // ExperimentNo group. |
| 2135 base::FieldTrialList field_trial_list(new base::MockEntropyProvider()); | 2139 base::FieldTrialList field_trial_list( |
| 2140 base::MakeUnique<base::MockEntropyProvider>()); |
| 2136 base::FieldTrialList::CreateFieldTrial("SimpleCacheTrial", "ExperimentNo"); | 2141 base::FieldTrialList::CreateFieldTrial("SimpleCacheTrial", "ExperimentNo"); |
| 2137 net::TestCompletionCallback cb; | 2142 net::TestCompletionCallback cb; |
| 2138 | 2143 |
| 2139 const int kRestartCount = 5; | 2144 const int kRestartCount = 5; |
| 2140 for (int i = 0; i < kRestartCount; ++i) { | 2145 for (int i = 0; i < kRestartCount; ++i) { |
| 2141 std::unique_ptr<disk_cache::BackendImpl> cache(new disk_cache::BackendImpl( | 2146 std::unique_ptr<disk_cache::BackendImpl> cache(new disk_cache::BackendImpl( |
| 2142 cache_path_, cache_thread.task_runner(), NULL)); | 2147 cache_path_, cache_thread.task_runner(), NULL)); |
| 2143 int rv = cache->Init(cb.callback()); | 2148 int rv = cache->Init(cb.callback()); |
| 2144 ASSERT_THAT(cb.GetResult(rv), IsOk()); | 2149 ASSERT_THAT(cb.GetResult(rv), IsOk()); |
| 2145 EXPECT_EQ(1, cache->GetEntryCount()); | 2150 EXPECT_EQ(1, cache->GetEntryCount()); |
| (...skipping 1705 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3851 // because that would advance the cache directory mtime and invalidate the | 3856 // because that would advance the cache directory mtime and invalidate the |
| 3852 // index. | 3857 // index. |
| 3853 entry2->Doom(); | 3858 entry2->Doom(); |
| 3854 entry2->Close(); | 3859 entry2->Close(); |
| 3855 | 3860 |
| 3856 DisableFirstCleanup(); | 3861 DisableFirstCleanup(); |
| 3857 InitCache(); | 3862 InitCache(); |
| 3858 EXPECT_EQ(disk_cache::SimpleIndex::INITIALIZE_METHOD_LOADED, | 3863 EXPECT_EQ(disk_cache::SimpleIndex::INITIALIZE_METHOD_LOADED, |
| 3859 simple_cache_impl_->index()->init_method()); | 3864 simple_cache_impl_->index()->init_method()); |
| 3860 } | 3865 } |
| OLD | NEW |