summaryrefslogtreecommitdiffstats
path: root/net/disk_cache/disk_cache_test_util.h
diff options
context:
space:
mode:
authorrsleevi@chromium.org <rsleevi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-07-07 02:12:38 +0000
committerrsleevi@chromium.org <rsleevi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-07-07 02:12:38 +0000
commit243757602999594320350e28ade4d797ef0340cd (patch)
tree117b5a54a23c8d3166930b55ae497e66d4862742 /net/disk_cache/disk_cache_test_util.h
parent227bc7c44aa9f5a56fdd4da578a572183c5071f5 (diff)
downloadchromium_src-243757602999594320350e28ade4d797ef0340cd.zip
chromium_src-243757602999594320350e28ade4d797ef0340cd.tar.gz
chromium_src-243757602999594320350e28ade4d797ef0340cd.tar.bz2
Allow DiskCache tests to be shuffled/independent of eachother
BUG=none TEST=existing unittests Review URL: http://codereview.chromium.org/7308003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@91655 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/disk_cache/disk_cache_test_util.h')
-rw-r--r--net/disk_cache/disk_cache_test_util.h60
1 files changed, 40 insertions, 20 deletions
diff --git a/net/disk_cache/disk_cache_test_util.h b/net/disk_cache/disk_cache_test_util.h
index 13549c7..0bd937c 100644
--- a/net/disk_cache/disk_cache_test_util.h
+++ b/net/disk_cache/disk_cache_test_util.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -55,24 +55,6 @@ class ScopedTestCache {
// -----------------------------------------------------------------------
-// Simple callback to process IO completions from the cache. It allows tests
-// with multiple simultaneous IO operations.
-class CallbackTest : public CallbackRunner< Tuple1<int> > {
- public:
- explicit CallbackTest(bool reuse);
- virtual ~CallbackTest();
-
- int result() const { return result_; }
- virtual void RunWithParams(const Tuple1<int>& params);
-
- private:
- int result_;
- int reuse_;
- DISALLOW_COPY_AND_ASSIGN(CallbackTest);
-};
-
-// -----------------------------------------------------------------------
-
// Simple helper to deal with the message loop on a test.
class MessageLoopHelper {
public:
@@ -80,9 +62,22 @@ class MessageLoopHelper {
~MessageLoopHelper();
// Run the message loop and wait for num_callbacks before returning. Returns
- // false if we are waiting to long.
+ // false if we are waiting to long. Each callback that will be waited on is
+ // required to call CallbackWasCalled() to indicate when it was called.
bool WaitUntilCacheIoFinished(int num_callbacks);
+ // True if a given callback was called more times than it expected.
+ bool callback_reused_error() const { return callback_reused_error_; }
+ void set_callback_reused_error(bool error) {
+ callback_reused_error_ = error;
+ }
+
+ int callbacks_called() const { return callbacks_called_; }
+ // Report that a callback was called. Each callback that will be waited on
+ // via WaitUntilCacheIoFinished() is expected to call this method to
+ // indicate when it has been executed.
+ void CallbackWasCalled() { ++callbacks_called_; }
+
private:
// Sets the number of callbacks that can be received so far.
void ExpectCallbacks(int num_callbacks) {
@@ -100,7 +95,32 @@ class MessageLoopHelper {
int last_;
bool completed_;
+ // True if a callback was called/reused more than expected.
+ bool callback_reused_error_;
+ int callbacks_called_;
+
DISALLOW_COPY_AND_ASSIGN(MessageLoopHelper);
};
+// -----------------------------------------------------------------------
+
+// Simple callback to process IO completions from the cache. It allows tests
+// with multiple simultaneous IO operations.
+class CallbackTest : public CallbackRunner< Tuple1<int> > {
+ public:
+ // Creates a new CallbackTest object. When the callback is called, it will
+ // update |helper| with the result of the call. If |reuse| is false and a
+ // callback is called more than once, or if |reuse| is true and a callback
+ // is called more than twice, an error will be reported to |helper|.
+ CallbackTest(MessageLoopHelper* helper, bool reuse);
+ virtual ~CallbackTest();
+
+ virtual void RunWithParams(const Tuple1<int>& params);
+
+ private:
+ MessageLoopHelper* helper_;
+ int reuse_;
+ DISALLOW_COPY_AND_ASSIGN(CallbackTest);
+};
+
#endif // NET_DISK_CACHE_DISK_CACHE_TEST_UTIL_H_