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

Unified Diff: base/bind_unittest.cc

Issue 2289703002: Add Callback::IsCancelled (Closed)
Patch Set: revert to PS5 Created 4 years, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/bind_internal.h ('k') | base/callback_internal.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/bind_unittest.cc
diff --git a/base/bind_unittest.cc b/base/bind_unittest.cc
index ba0358e5699cba33fdb202551e4f1204d95042c5..a38035caaaa8485317411b51a62ae4d55f162aaa 100644
--- a/base/bind_unittest.cc
+++ b/base/bind_unittest.cc
@@ -1034,6 +1034,28 @@ TEST_F(BindTest, CapturelessLambda) {
EXPECT_EQ(42, x);
}
+TEST_F(BindTest, Cancellation) {
+ EXPECT_CALL(no_ref_, VoidMethod0()).Times(2);
+
+ WeakPtrFactory<NoRef> weak_factory(&no_ref_);
+ Closure cb = Bind(&NoRef::VoidMethod0, weak_factory.GetWeakPtr());
+ Closure cb2 = Bind(cb);
+
+ EXPECT_FALSE(cb.IsCancelled());
+ EXPECT_FALSE(cb2.IsCancelled());
+
+ cb.Run();
+ cb2.Run();
+
+ weak_factory.InvalidateWeakPtrs();
+
+ EXPECT_TRUE(cb.IsCancelled());
+ EXPECT_TRUE(cb2.IsCancelled());
+
+ cb.Run();
+ cb2.Run();
+}
+
// Callback construction and assignment tests.
// - Construction from an InvokerStorageHolder should not cause ref/deref.
// - Assignment from other callback should only cause one ref
« no previous file with comments | « base/bind_internal.h ('k') | base/callback_internal.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698