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 #ifndef NET_DISK_CACHE_DISK_CACHE_TEST_BASE_H_ | 5 #ifndef NET_DISK_CACHE_DISK_CACHE_TEST_BASE_H_ |
6 #define NET_DISK_CACHE_DISK_CACHE_TEST_BASE_H_ | 6 #define NET_DISK_CACHE_DISK_CACHE_TEST_BASE_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
11 | 11 |
12 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
13 #include "base/files/scoped_temp_dir.h" | 13 #include "base/files/scoped_temp_dir.h" |
14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/test/scoped_async_task_scheduler.h" |
15 #include "base/threading/thread.h" | 16 #include "base/threading/thread.h" |
16 #include "net/base/cache_type.h" | 17 #include "net/base/cache_type.h" |
17 #include "net/disk_cache/disk_cache.h" | 18 #include "net/disk_cache/disk_cache.h" |
18 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
19 #include "testing/platform_test.h" | 20 #include "testing/platform_test.h" |
20 | 21 |
21 namespace net { | 22 namespace net { |
22 | 23 |
23 class IOBuffer; | 24 class IOBuffer; |
24 | 25 |
(...skipping 24 matching lines...) Expand all Loading... |
49 // Deletes the contents of |cache_path_|. | 50 // Deletes the contents of |cache_path_|. |
50 bool CleanupCacheDir(); | 51 bool CleanupCacheDir(); |
51 | 52 |
52 void TearDown() override; | 53 void TearDown() override; |
53 | 54 |
54 base::FilePath cache_path_; | 55 base::FilePath cache_path_; |
55 | 56 |
56 private: | 57 private: |
57 base::ScopedTempDir temp_dir_; | 58 base::ScopedTempDir temp_dir_; |
58 std::unique_ptr<base::MessageLoop> message_loop_; | 59 std::unique_ptr<base::MessageLoop> message_loop_; |
| 60 |
| 61 // Use a ScopedAsyncTaskScheduler instead of a ScopedTaskScheduler to allow |
| 62 // disk_cache::InFlightIO::WaitForPendingIO to wait for TaskScheduler tasks |
| 63 // from the main thread using WaitableEvents (this wouldn't work if |
| 64 // TaskScheduler tasks ran on the main thread). |
| 65 base::test::ScopedAsyncTaskScheduler scoped_async_task_scheduler_; |
59 }; | 66 }; |
60 | 67 |
61 // Provides basic support for cache related tests. | 68 // Provides basic support for cache related tests. |
62 class DiskCacheTestWithCache : public DiskCacheTest { | 69 class DiskCacheTestWithCache : public DiskCacheTest { |
63 protected: | 70 protected: |
64 class TestIterator { | 71 class TestIterator { |
65 public: | 72 public: |
66 explicit TestIterator( | 73 explicit TestIterator( |
67 std::unique_ptr<disk_cache::Backend::Iterator> iterator); | 74 std::unique_ptr<disk_cache::Backend::Iterator> iterator); |
68 ~TestIterator(); | 75 ~TestIterator(); |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 | 193 |
187 private: | 194 private: |
188 void InitMemoryCache(); | 195 void InitMemoryCache(); |
189 void InitDiskCache(); | 196 void InitDiskCache(); |
190 | 197 |
191 base::Thread cache_thread_; | 198 base::Thread cache_thread_; |
192 DISALLOW_COPY_AND_ASSIGN(DiskCacheTestWithCache); | 199 DISALLOW_COPY_AND_ASSIGN(DiskCacheTestWithCache); |
193 }; | 200 }; |
194 | 201 |
195 #endif // NET_DISK_CACHE_DISK_CACHE_TEST_BASE_H_ | 202 #endif // NET_DISK_CACHE_DISK_CACHE_TEST_BASE_H_ |
OLD | NEW |