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_UTIL_H_ | 5 #ifndef NET_DISK_CACHE_DISK_CACHE_TEST_UTIL_H_ |
6 #define NET_DISK_CACHE_DISK_CACHE_TEST_UTIL_H_ | 6 #define NET_DISK_CACHE_DISK_CACHE_TEST_UTIL_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
11 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
12 #include "base/timer.h" | 12 #include "base/timer.h" |
13 #include "base/tuple.h" | 13 #include "base/tuple.h" |
14 #include "build/build_config.h" | 14 #include "build/build_config.h" |
15 | 15 |
16 // Re-creates a given test file inside the cache test folder. | 16 // Re-creates a given test file inside the cache test folder. |
17 bool CreateCacheTestFile(const FilePath& name); | 17 bool CreateCacheTestFile(const FilePath& name); |
18 | 18 |
19 // Deletes all file son the cache. | 19 // Deletes all file son the cache. |
20 bool DeleteCache(const FilePath& path); | 20 bool DeleteCache(const FilePath& path); |
21 | 21 |
22 // Gets the path to the cache test folder. | |
23 FilePath GetCacheFilePath(); | |
24 | |
25 // Fills buffer with random values (may contain nulls unless no_nulls is true). | 22 // Fills buffer with random values (may contain nulls unless no_nulls is true). |
26 void CacheTestFillBuffer(char* buffer, size_t len, bool no_nulls); | 23 void CacheTestFillBuffer(char* buffer, size_t len, bool no_nulls); |
27 | 24 |
28 // Generates a random key of up to 200 bytes. | 25 // Generates a random key of up to 200 bytes. |
29 std::string GenerateKey(bool same_length); | 26 std::string GenerateKey(bool same_length); |
30 | 27 |
31 // Returns true if the cache is not corrupt. | 28 // Returns true if the cache is not corrupt. |
32 bool CheckCacheIntegrity(const FilePath& path, bool new_eviction, uint32 mask); | 29 bool CheckCacheIntegrity(const FilePath& path, bool new_eviction, uint32 mask); |
33 | 30 |
34 // Helper class which ensures that the cache dir returned by GetCacheFilePath | |
35 // exists and is clear in ctor and that the directory gets deleted in dtor. | |
36 class ScopedTestCache { | |
37 public: | |
38 explicit ScopedTestCache(const FilePath& path); | |
39 // Use a specific folder name. | |
40 explicit ScopedTestCache(const std::string& name); | |
41 ~ScopedTestCache(); | |
42 | |
43 FilePath path() const { return path_; } | |
44 | |
45 private: | |
46 const FilePath path_; // Path to the cache test folder. | |
47 | |
48 DISALLOW_COPY_AND_ASSIGN(ScopedTestCache); | |
49 }; | |
50 | |
51 // ----------------------------------------------------------------------- | 31 // ----------------------------------------------------------------------- |
52 | 32 |
53 // Simple helper to deal with the message loop on a test. | 33 // Simple helper to deal with the message loop on a test. |
54 class MessageLoopHelper { | 34 class MessageLoopHelper { |
55 public: | 35 public: |
56 MessageLoopHelper(); | 36 MessageLoopHelper(); |
57 ~MessageLoopHelper(); | 37 ~MessageLoopHelper(); |
58 | 38 |
59 // Run the message loop and wait for num_callbacks before returning. Returns | 39 // Run the message loop and wait for num_callbacks before returning. Returns |
60 // false if we are waiting to long. Each callback that will be waited on is | 40 // false if we are waiting to long. Each callback that will be waited on is |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 | 92 |
113 void Run(int params); | 93 void Run(int params); |
114 | 94 |
115 private: | 95 private: |
116 MessageLoopHelper* helper_; | 96 MessageLoopHelper* helper_; |
117 int reuse_; | 97 int reuse_; |
118 DISALLOW_COPY_AND_ASSIGN(CallbackTest); | 98 DISALLOW_COPY_AND_ASSIGN(CallbackTest); |
119 }; | 99 }; |
120 | 100 |
121 #endif // NET_DISK_CACHE_DISK_CACHE_TEST_UTIL_H_ | 101 #endif // NET_DISK_CACHE_DISK_CACHE_TEST_UTIL_H_ |
OLD | NEW |