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