| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/callback.h" | 11 #include "base/callback.h" |
| 12 #include "base/file_path.h" | 12 #include "base/file_path.h" |
| 13 #include "base/message_loop.h" | 13 #include "base/message_loop.h" |
| 14 #include "base/scoped_temp_dir.h" |
| 14 #include "base/timer.h" | 15 #include "base/timer.h" |
| 15 #include "build/build_config.h" | 16 #include "build/build_config.h" |
| 16 | 17 |
| 17 // Re-creates a given test file inside the cache test folder. | 18 // Re-creates a given test file inside the cache test folder. |
| 18 bool CreateCacheTestFile(const FilePath& name); | 19 bool CreateCacheTestFile(const FilePath& name); |
| 19 | 20 |
| 20 // Deletes all file son the cache. | 21 // Deletes all file son the cache. |
| 21 bool DeleteCache(const FilePath& path); | 22 bool DeleteCache(const FilePath& path); |
| 22 | 23 |
| 23 // Copies a set of cache files from the data folder to the test folder. | 24 // Copies a set of cache files from the data folder to the destination folder. |
| 24 bool CopyTestCache(const std::string& name); | 25 bool CopyTestCache(const std::string& name, const FilePath& destination); |
| 25 | |
| 26 // Gets the path to the cache test folder. | |
| 27 FilePath GetCacheFilePath(); | |
| 28 | 26 |
| 29 // Fills buffer with random values (may contain nulls unless no_nulls is true). | 27 // Fills buffer with random values (may contain nulls unless no_nulls is true). |
| 30 void CacheTestFillBuffer(char* buffer, size_t len, bool no_nulls); | 28 void CacheTestFillBuffer(char* buffer, size_t len, bool no_nulls); |
| 31 | 29 |
| 32 // Generates a random key of up to 200 bytes. | 30 // Generates a random key of up to 200 bytes. |
| 33 std::string GenerateKey(bool same_length); | 31 std::string GenerateKey(bool same_length); |
| 34 | 32 |
| 35 // Returns true if the cache is not corrupt. | 33 // Returns true if the cache is not corrupt. |
| 36 bool CheckCacheIntegrity(const FilePath& path, bool new_eviction); | 34 bool CheckCacheIntegrity(const FilePath& path, bool new_eviction); |
| 37 | 35 |
| 38 // Helper class which ensures that the cache dir returned by GetCacheFilePath | 36 // Helper class which ensures that the cache dir returned by GetCacheFilePath |
| 39 // exists and is clear in ctor and that the directory gets deleted in dtor. | 37 // exists and is clear in ctor and that the directory gets deleted in dtor. |
| 40 class ScopedTestCache { | 38 class ScopedTestCache { |
| 41 public: | 39 public: |
| 42 ScopedTestCache(); | 40 ScopedTestCache(); |
| 43 // Use a specific folder name. | |
| 44 explicit ScopedTestCache(const std::string& name); | |
| 45 ~ScopedTestCache(); | 41 ~ScopedTestCache(); |
| 46 | 42 |
| 47 FilePath path() const { return path_; } | 43 FilePath path() const { return temp_dir_.path(); } |
| 48 | 44 |
| 49 private: | 45 private: |
| 50 const FilePath path_; // Path to the cache test folder. | 46 ScopedTempDir temp_dir_; |
| 51 | 47 |
| 52 DISALLOW_COPY_AND_ASSIGN(ScopedTestCache); | 48 DISALLOW_COPY_AND_ASSIGN(ScopedTestCache); |
| 53 }; | 49 }; |
| 54 | 50 |
| 55 // ----------------------------------------------------------------------- | 51 // ----------------------------------------------------------------------- |
| 56 | 52 |
| 57 // Simple callback to process IO completions from the cache. It allows tests | 53 // Simple callback to process IO completions from the cache. It allows tests |
| 58 // with multiple simultaneous IO operations. | 54 // with multiple simultaneous IO operations. |
| 59 class CallbackTest : public CallbackRunner< Tuple1<int> > { | 55 class CallbackTest : public CallbackRunner< Tuple1<int> > { |
| 60 public: | 56 public: |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 base::RepeatingTimer<MessageLoopHelper> timer_; | 92 base::RepeatingTimer<MessageLoopHelper> timer_; |
| 97 int num_callbacks_; | 93 int num_callbacks_; |
| 98 int num_iterations_; | 94 int num_iterations_; |
| 99 int last_; | 95 int last_; |
| 100 bool completed_; | 96 bool completed_; |
| 101 | 97 |
| 102 DISALLOW_COPY_AND_ASSIGN(MessageLoopHelper); | 98 DISALLOW_COPY_AND_ASSIGN(MessageLoopHelper); |
| 103 }; | 99 }; |
| 104 | 100 |
| 105 #endif // NET_DISK_CACHE_DISK_CACHE_TEST_UTIL_H_ | 101 #endif // NET_DISK_CACHE_DISK_CACHE_TEST_UTIL_H_ |
| OLD | NEW |