| OLD | NEW |
| 1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2009 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/task.h" | 12 #include "base/task.h" |
| 13 #include "base/timer.h" | 13 #include "base/timer.h" |
| 14 #include "build/build_config.h" | 14 #include "build/build_config.h" |
| 15 #include "net/base/test_completion_callback.h" | |
| 16 | 15 |
| 17 class FilePath; | 16 class FilePath; |
| 18 | 17 |
| 19 // Re-creates a given test file inside the cache test folder. | 18 // Re-creates a given test file inside the cache test folder. |
| 20 bool CreateCacheTestFile(const FilePath& name); | 19 bool CreateCacheTestFile(const FilePath& name); |
| 21 | 20 |
| 22 // Deletes all file son the cache. | 21 // Deletes all file son the cache. |
| 23 bool DeleteCache(const FilePath& path); | 22 bool DeleteCache(const FilePath& path); |
| 24 | 23 |
| 25 // Gets the path to the cache test folder. | 24 // Gets the path to the cache test folder. |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 int result() const { return result_; } | 62 int result() const { return result_; } |
| 64 | 63 |
| 65 private: | 64 private: |
| 66 int result_; | 65 int result_; |
| 67 int reuse_; | 66 int reuse_; |
| 68 DISALLOW_COPY_AND_ASSIGN(CallbackTest); | 67 DISALLOW_COPY_AND_ASSIGN(CallbackTest); |
| 69 }; | 68 }; |
| 70 | 69 |
| 71 // ----------------------------------------------------------------------- | 70 // ----------------------------------------------------------------------- |
| 72 | 71 |
| 73 // Simple callback to process IO completions from the cache. This object is not | |
| 74 // intended to be used when multiple IO operations are in-flight at the same | |
| 75 // time. | |
| 76 class SimpleCallbackTest : public TestCompletionCallback { | |
| 77 public: | |
| 78 SimpleCallbackTest() {} | |
| 79 ~SimpleCallbackTest() {} | |
| 80 | |
| 81 // Returns the final result of the IO operation. If |result| is | |
| 82 // net::ERR_IO_PENDING, it waits for the callback be invoked. | |
| 83 int GetResult(int result); | |
| 84 | |
| 85 private: | |
| 86 DISALLOW_COPY_AND_ASSIGN(SimpleCallbackTest); | |
| 87 }; | |
| 88 | |
| 89 // ----------------------------------------------------------------------- | |
| 90 | |
| 91 // Simple helper to deal with the message loop on a test. | 72 // Simple helper to deal with the message loop on a test. |
| 92 class MessageLoopHelper { | 73 class MessageLoopHelper { |
| 93 public: | 74 public: |
| 94 MessageLoopHelper(); | 75 MessageLoopHelper(); |
| 95 | 76 |
| 96 // Run the message loop and wait for num_callbacks before returning. Returns | 77 // Run the message loop and wait for num_callbacks before returning. Returns |
| 97 // false if we are waiting to long. | 78 // false if we are waiting to long. |
| 98 bool WaitUntilCacheIoFinished(int num_callbacks); | 79 bool WaitUntilCacheIoFinished(int num_callbacks); |
| 99 | 80 |
| 100 private: | 81 private: |
| (...skipping 10 matching lines...) Expand all Loading... |
| 111 base::RepeatingTimer<MessageLoopHelper> timer_; | 92 base::RepeatingTimer<MessageLoopHelper> timer_; |
| 112 int num_callbacks_; | 93 int num_callbacks_; |
| 113 int num_iterations_; | 94 int num_iterations_; |
| 114 int last_; | 95 int last_; |
| 115 bool completed_; | 96 bool completed_; |
| 116 | 97 |
| 117 DISALLOW_COPY_AND_ASSIGN(MessageLoopHelper); | 98 DISALLOW_COPY_AND_ASSIGN(MessageLoopHelper); |
| 118 }; | 99 }; |
| 119 | 100 |
| 120 #endif // NET_DISK_CACHE_DISK_CACHE_TEST_UTIL_H_ | 101 #endif // NET_DISK_CACHE_DISK_CACHE_TEST_UTIL_H_ |
| OLD | NEW |