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/memory/ptr_util.h" |
10 #include "base/metrics/field_trial.h" | 10 #include "base/metrics/field_trial.h" |
11 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
12 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
13 #include "base/strings/string_split.h" | 13 #include "base/strings/string_split.h" |
14 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
15 #include "base/strings/stringprintf.h" | 15 #include "base/strings/stringprintf.h" |
16 #include "base/test/mock_entropy_provider.h" | 16 #include "base/test/mock_entropy_provider.h" |
17 #include "base/test/scoped_task_scheduler.h" | |
18 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" | 17 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" |
19 #include "base/threading/platform_thread.h" | 18 #include "base/threading/platform_thread.h" |
20 #include "base/threading/thread_restrictions.h" | 19 #include "base/threading/thread_restrictions.h" |
21 #include "base/threading/thread_task_runner_handle.h" | 20 #include "base/threading/thread_task_runner_handle.h" |
22 #include "net/base/cache_type.h" | 21 #include "net/base/cache_type.h" |
23 #include "net/base/io_buffer.h" | 22 #include "net/base/io_buffer.h" |
24 #include "net/base/net_errors.h" | 23 #include "net/base/net_errors.h" |
25 #include "net/base/test_completion_callback.h" | 24 #include "net/base/test_completion_callback.h" |
26 #include "net/disk_cache/blockfile/backend_impl.h" | 25 #include "net/disk_cache/blockfile/backend_impl.h" |
27 #include "net/disk_cache/blockfile/entry_impl.h" | 26 #include "net/disk_cache/blockfile/entry_impl.h" |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 entry->Close(); | 75 entry->Close(); |
77 | 76 |
78 return cache; | 77 return cache; |
79 } | 78 } |
80 | 79 |
81 } // namespace | 80 } // namespace |
82 | 81 |
83 // Tests that can run with different types of caches. | 82 // Tests that can run with different types of caches. |
84 class DiskCacheBackendTest : public DiskCacheTestWithCache { | 83 class DiskCacheBackendTest : public DiskCacheTestWithCache { |
85 protected: | 84 protected: |
86 DiskCacheBackendTest() | |
87 : scoped_task_scheduler_(base::MessageLoop::current()) {} | |
88 | |
89 // Some utility methods: | 85 // Some utility methods: |
90 | 86 |
91 // Perform IO operations on the cache until there is pending IO. | 87 // Perform IO operations on the cache until there is pending IO. |
92 int GeneratePendingIO(net::TestCompletionCallback* cb); | 88 int GeneratePendingIO(net::TestCompletionCallback* cb); |
93 | 89 |
94 // Adds 5 sparse entries. |doomed_start| and |doomed_end| if not NULL, | 90 // Adds 5 sparse entries. |doomed_start| and |doomed_end| if not NULL, |
95 // will be filled with times, used by DoomEntriesSince and DoomEntriesBetween. | 91 // will be filled with times, used by DoomEntriesSince and DoomEntriesBetween. |
96 // There are 4 entries after doomed_start and 2 after doomed_end. | 92 // There are 4 entries after doomed_start and 2 after doomed_end. |
97 void InitSparseCache(base::Time* doomed_start, base::Time* doomed_end); | 93 void InitSparseCache(base::Time* doomed_start, base::Time* doomed_end); |
98 | 94 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 void BackendDoomAll2(); | 142 void BackendDoomAll2(); |
147 void BackendInvalidRankings(); | 143 void BackendInvalidRankings(); |
148 void BackendInvalidRankings2(); | 144 void BackendInvalidRankings2(); |
149 void BackendDisable(); | 145 void BackendDisable(); |
150 void BackendDisable2(); | 146 void BackendDisable2(); |
151 void BackendDisable3(); | 147 void BackendDisable3(); |
152 void BackendDisable4(); | 148 void BackendDisable4(); |
153 void BackendDisabledAPI(); | 149 void BackendDisabledAPI(); |
154 | 150 |
155 void BackendEviction(); | 151 void BackendEviction(); |
156 | |
157 private: | |
158 base::test::ScopedTaskScheduler scoped_task_scheduler_; | |
159 }; | 152 }; |
160 | 153 |
161 int DiskCacheBackendTest::GeneratePendingIO(net::TestCompletionCallback* cb) { | 154 int DiskCacheBackendTest::GeneratePendingIO(net::TestCompletionCallback* cb) { |
162 if (!use_current_thread_) { | 155 if (!use_current_thread_) { |
163 ADD_FAILURE(); | 156 ADD_FAILURE(); |
164 return net::ERR_FAILED; | 157 return net::ERR_FAILED; |
165 } | 158 } |
166 | 159 |
167 disk_cache::Entry* entry; | 160 disk_cache::Entry* entry; |
168 int rv = cache_->CreateEntry("some key", &entry, cb->callback()); | 161 int rv = cache_->CreateEntry("some key", &entry, cb->callback()); |
(...skipping 1878 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2047 int rv = cache->Init(cb.callback()); | 2040 int rv = cache->Init(cb.callback()); |
2048 ASSERT_THAT(cb.GetResult(rv), IsError(net::ERR_FAILED)); | 2041 ASSERT_THAT(cb.GetResult(rv), IsError(net::ERR_FAILED)); |
2049 } | 2042 } |
2050 | 2043 |
2051 // Tests that the disk cache successfully joins the control group, dropping the | 2044 // Tests that the disk cache successfully joins the control group, dropping the |
2052 // existing cache in favour of a new empty cache. | 2045 // existing cache in favour of a new empty cache. |
2053 // Disabled on android since this test requires cache creator to create | 2046 // Disabled on android since this test requires cache creator to create |
2054 // blockfile caches. | 2047 // blockfile caches. |
2055 #if !defined(OS_ANDROID) | 2048 #if !defined(OS_ANDROID) |
2056 TEST_F(DiskCacheTest, SimpleCacheControlJoin) { | 2049 TEST_F(DiskCacheTest, SimpleCacheControlJoin) { |
2057 base::test::ScopedTaskScheduler scoped_task_scheduler( | |
2058 base::MessageLoop::current()); | |
2059 base::Thread cache_thread("CacheThread"); | 2050 base::Thread cache_thread("CacheThread"); |
2060 ASSERT_TRUE(cache_thread.StartWithOptions( | 2051 ASSERT_TRUE(cache_thread.StartWithOptions( |
2061 base::Thread::Options(base::MessageLoop::TYPE_IO, 0))); | 2052 base::Thread::Options(base::MessageLoop::TYPE_IO, 0))); |
2062 | 2053 |
2063 std::unique_ptr<disk_cache::BackendImpl> cache = | 2054 std::unique_ptr<disk_cache::BackendImpl> cache = |
2064 CreateExistingEntryCache(cache_thread, cache_path_); | 2055 CreateExistingEntryCache(cache_thread, cache_path_); |
2065 ASSERT_TRUE(cache.get()); | 2056 ASSERT_TRUE(cache.get()); |
2066 cache.reset(); | 2057 cache.reset(); |
2067 | 2058 |
2068 // Instantiate the SimpleCacheTrial, forcing this run into the | 2059 // Instantiate the SimpleCacheTrial, forcing this run into the |
(...skipping 1796 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3865 // because that would advance the cache directory mtime and invalidate the | 3856 // because that would advance the cache directory mtime and invalidate the |
3866 // index. | 3857 // index. |
3867 entry2->Doom(); | 3858 entry2->Doom(); |
3868 entry2->Close(); | 3859 entry2->Close(); |
3869 | 3860 |
3870 DisableFirstCleanup(); | 3861 DisableFirstCleanup(); |
3871 InitCache(); | 3862 InitCache(); |
3872 EXPECT_EQ(disk_cache::SimpleIndex::INITIALIZE_METHOD_LOADED, | 3863 EXPECT_EQ(disk_cache::SimpleIndex::INITIALIZE_METHOD_LOADED, |
3873 simple_cache_impl_->index()->init_method()); | 3864 simple_cache_impl_->index()->init_method()); |
3874 } | 3865 } |
OLD | NEW |