diff options
author | jhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-30 20:33:52 +0000 |
---|---|---|
committer | jhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-30 20:33:52 +0000 |
commit | d4d57df406ef7e02e69d8de18efc8bdb917ac4ba (patch) | |
tree | 8b677e46226f3b8cd077c8b06d9bcf7d4f691e0e /base/cancelable_callback_unittest.cc | |
parent | 43cb919add660ef0c3ea1c3b49ac9a2e2a1d2f7d (diff) | |
download | chromium_src-d4d57df406ef7e02e69d8de18efc8bdb917ac4ba.zip chromium_src-d4d57df406ef7e02e69d8de18efc8bdb917ac4ba.tar.gz chromium_src-d4d57df406ef7e02e69d8de18efc8bdb917ac4ba.tar.bz2 |
base::Bind: Implement a 1-arity CancelableCallback and use this to implement
net::CancelableCompletionClosure.
BUG=none
TEST=none
R=ajwong@chromium.org
Review URL: http://codereview.chromium.org/8662047
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@112279 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/cancelable_callback_unittest.cc')
-rw-r--r-- | base/cancelable_callback_unittest.cc | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/base/cancelable_callback_unittest.cc b/base/cancelable_callback_unittest.cc index 980359b..51a2a09 100644 --- a/base/cancelable_callback_unittest.cc +++ b/base/cancelable_callback_unittest.cc @@ -28,7 +28,7 @@ void RefCountedParam(const scoped_refptr<TestRefCounted>& ref_counted) {} // - After Cancel(), Run() completes but has no effect. TEST(CancelableCallbackTest, Cancel) { int count = 0; - CancelableCallback cancelable( + CancelableClosure cancelable( base::Bind(&Increment, base::Unretained(&count))); base::Closure callback = cancelable.callback(); @@ -45,26 +45,29 @@ TEST(CancelableCallbackTest, Cancel) { // Cancel() called multiple times. // - Cancel() cancels all copies of the wrapped callback. +// - Calling Cancel() more than once has no effect. +// - After Cancel(), callback() returns a null callback. TEST(CancelableCallbackTest, MultipleCancel) { int count = 0; - CancelableCallback cancelable( + CancelableClosure cancelable( base::Bind(&Increment, base::Unretained(&count))); base::Closure callback1 = cancelable.callback(); + base::Closure callback2 = cancelable.callback(); cancelable.Cancel(); callback1.Run(); EXPECT_EQ(0, count); - base::Closure callback2 = cancelable.callback(); callback2.Run(); EXPECT_EQ(0, count); - // Cancel() should have no effect, but callback() is still runnable. - base::Closure callback3 = cancelable.callback(); + // Calling Cancel() again has no effect. cancelable.Cancel(); - callback3.Run(); - EXPECT_EQ(0, count); + + // callback() of a cancelled callback is null. + base::Closure callback3 = cancelable.callback(); + EXPECT_TRUE(callback3.is_null()); } // CancelableCallback destroyed before callback is run. @@ -74,7 +77,7 @@ TEST(CancelableCallbackTest, CallbackCanceledOnDestruction) { base::Closure callback; { - CancelableCallback cancelable( + CancelableClosure cancelable( base::Bind(&Increment, base::Unretained(&count))); callback = cancelable.callback(); @@ -92,7 +95,7 @@ TEST(CancelableCallbackTest, CancelDropsCallback) { scoped_refptr<TestRefCounted> ref_counted = new TestRefCounted; EXPECT_TRUE(ref_counted->HasOneRef()); - CancelableCallback cancelable(base::Bind(RefCountedParam, ref_counted)); + CancelableClosure cancelable(base::Bind(RefCountedParam, ref_counted)); EXPECT_FALSE(cancelable.IsCancelled()); EXPECT_TRUE(ref_counted.get()); EXPECT_FALSE(ref_counted->HasOneRef()); @@ -109,7 +112,7 @@ TEST(CancelableCallbackTest, CancelDropsCallback) { // - Reset() deactivates outstanding callbacks. TEST(CancelableCallbackTest, Reset) { int count = 0; - CancelableCallback cancelable( + CancelableClosure cancelable( base::Bind(&Increment, base::Unretained(&count))); base::Closure callback = cancelable.callback(); @@ -140,7 +143,7 @@ TEST(CancelableCallbackTest, Reset) { // IsCanceled(). // - Cancel() transforms the CancelableCallback into a cancelled state. TEST(CancelableCallbackTest, IsNull) { - CancelableCallback cancelable; + CancelableClosure cancelable; EXPECT_TRUE(cancelable.IsCancelled()); int count = 0; @@ -158,7 +161,7 @@ TEST(CancelableCallbackTest, PostTask) { MessageLoop loop(MessageLoop::TYPE_DEFAULT); int count = 0; - CancelableCallback cancelable(base::Bind(&Increment, + CancelableClosure cancelable(base::Bind(&Increment, base::Unretained(&count))); MessageLoop::current()->PostTask(FROM_HERE, cancelable.callback()); |