Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(205)

Side by Side Diff: net/disk_cache/disk_cache_test_util.h

Issue 132031: Disk cache: First pass to add support for sparse entries.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/disk_cache/bitmap_unittest.cc ('k') | net/disk_cache/disk_cache_test_util.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 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 "net/base/test_completion_callback.h"
14 15
15 // Re-creates a given test file inside the cache test folder. 16 // Re-creates a given test file inside the cache test folder.
16 bool CreateCacheTestFile(const wchar_t* name); 17 bool CreateCacheTestFile(const wchar_t* name);
17 18
18 // Deletes all file son the cache. 19 // Deletes all file son the cache.
19 bool DeleteCache(const wchar_t* path); 20 bool DeleteCache(const wchar_t* path);
20 21
21 // Gets the path to the cache test folder. 22 // Gets the path to the cache test folder.
22 std::wstring GetCachePath(); 23 std::wstring GetCachePath();
23 24
(...skipping 22 matching lines...) Expand all
46 std::wstring path_wstring() const { return path_; } 47 std::wstring path_wstring() const { return path_; }
47 48
48 private: 49 private:
49 const std::wstring path_; // Path to the cache test folder. 50 const std::wstring path_; // Path to the cache test folder.
50 51
51 DISALLOW_COPY_AND_ASSIGN(ScopedTestCache); 52 DISALLOW_COPY_AND_ASSIGN(ScopedTestCache);
52 }; 53 };
53 54
54 // ----------------------------------------------------------------------- 55 // -----------------------------------------------------------------------
55 56
56 // Simple callback to process IO completions from the cache. 57 // Simple callback to process IO completions from the cache. It allows tests
58 // with multiple simultaneous IO operations.
57 class CallbackTest : public CallbackRunner< Tuple1<int> > { 59 class CallbackTest : public CallbackRunner< Tuple1<int> > {
58 public: 60 public:
59 explicit CallbackTest(bool reuse) : result_(-1), reuse_(reuse ? 0 : 1) {} 61 explicit CallbackTest(bool reuse) : result_(-1), reuse_(reuse ? 0 : 1) {}
60 ~CallbackTest() {} 62 ~CallbackTest() {}
61 63
62 virtual void RunWithParams(const Tuple1<int>& params); 64 virtual void RunWithParams(const Tuple1<int>& params);
63 int result() const { return result_; } 65 int result() const { return result_; }
64 66
65 private: 67 private:
66 int result_; 68 int result_;
67 int reuse_; 69 int reuse_;
68 DISALLOW_COPY_AND_ASSIGN(CallbackTest); 70 DISALLOW_COPY_AND_ASSIGN(CallbackTest);
69 }; 71 };
70 72
71 // ----------------------------------------------------------------------- 73 // -----------------------------------------------------------------------
72 74
75 // Simple callback to process IO completions from the cache. This object is not
76 // intended to be used when multiple IO operations are in-flight at the same
77 // time.
78 class SimpleCallbackTest : public TestCompletionCallback {
79 public:
80 SimpleCallbackTest() {}
81 ~SimpleCallbackTest() {}
82
83 // Returns the final result of the IO operation. If |result| is
84 // net::ERR_IO_PENDING, it waits for the callback be invoked.
85 int GetResult(int result);
86
87 private:
88 DISALLOW_COPY_AND_ASSIGN(SimpleCallbackTest);
89 };
90
91 // -----------------------------------------------------------------------
92
73 // Simple helper to deal with the message loop on a test. 93 // Simple helper to deal with the message loop on a test.
74 class MessageLoopHelper { 94 class MessageLoopHelper {
75 public: 95 public:
76 MessageLoopHelper(); 96 MessageLoopHelper();
77 97
78 // Run the message loop and wait for num_callbacks before returning. Returns 98 // Run the message loop and wait for num_callbacks before returning. Returns
79 // false if we are waiting to long. 99 // false if we are waiting to long.
80 bool WaitUntilCacheIoFinished(int num_callbacks); 100 bool WaitUntilCacheIoFinished(int num_callbacks);
81 101
82 private: 102 private:
(...skipping 10 matching lines...) Expand all
93 base::RepeatingTimer<MessageLoopHelper> timer_; 113 base::RepeatingTimer<MessageLoopHelper> timer_;
94 int num_callbacks_; 114 int num_callbacks_;
95 int num_iterations_; 115 int num_iterations_;
96 int last_; 116 int last_;
97 bool completed_; 117 bool completed_;
98 118
99 DISALLOW_COPY_AND_ASSIGN(MessageLoopHelper); 119 DISALLOW_COPY_AND_ASSIGN(MessageLoopHelper);
100 }; 120 };
101 121
102 #endif // NET_DISK_CACHE_DISK_CACHE_TEST_UTIL_H_ 122 #endif // NET_DISK_CACHE_DISK_CACHE_TEST_UTIL_H_
OLDNEW
« no previous file with comments | « net/disk_cache/bitmap_unittest.cc ('k') | net/disk_cache/disk_cache_test_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698