summaryrefslogtreecommitdiff
path: root/base/callback_unittest.cc
diff options
context:
space:
mode:
Diffstat (limited to 'base/callback_unittest.cc')
-rw-r--r--base/callback_unittest.cc42
1 files changed, 23 insertions, 19 deletions
diff --git a/base/callback_unittest.cc b/base/callback_unittest.cc
index a41736946a..f76adbcdd2 100644
--- a/base/callback_unittest.cc
+++ b/base/callback_unittest.cc
@@ -21,24 +21,13 @@ void NopInvokeFunc() {}
// based on a type we declared in the anonymous namespace above to remove any
// chance of colliding with another instantiation and breaking the
// one-definition-rule.
-struct FakeBindState1 : internal::BindStateBase {
- FakeBindState1() : BindStateBase(&NopInvokeFunc, &Destroy, &IsCancelled) {}
- private:
- ~FakeBindState1() {}
- static void Destroy(const internal::BindStateBase* self) {
- delete static_cast<const FakeBindState1*>(self);
- }
- static bool IsCancelled(const internal::BindStateBase*) {
- return false;
- }
-};
+struct FakeBindState : internal::BindStateBase {
+ FakeBindState() : BindStateBase(&NopInvokeFunc, &Destroy, &IsCancelled) {}
-struct FakeBindState2 : internal::BindStateBase {
- FakeBindState2() : BindStateBase(&NopInvokeFunc, &Destroy, &IsCancelled) {}
private:
- ~FakeBindState2() {}
+ ~FakeBindState() {}
static void Destroy(const internal::BindStateBase* self) {
- delete static_cast<const FakeBindState2*>(self);
+ delete static_cast<const FakeBindState*>(self);
}
static bool IsCancelled(const internal::BindStateBase*) {
return false;
@@ -50,9 +39,7 @@ namespace {
class CallbackTest : public ::testing::Test {
public:
CallbackTest()
- : callback_a_(new FakeBindState1()),
- callback_b_(new FakeBindState2()) {
- }
+ : callback_a_(new FakeBindState()), callback_b_(new FakeBindState()) {}
~CallbackTest() override {}
@@ -94,7 +81,7 @@ TEST_F(CallbackTest, Equals) {
EXPECT_FALSE(callback_b_.Equals(callback_a_));
// We should compare based on instance, not type.
- Callback<void()> callback_c(new FakeBindState1());
+ Callback<void()> callback_c(new FakeBindState());
Callback<void()> callback_a2 = callback_a_;
EXPECT_TRUE(callback_a_.Equals(callback_a2));
EXPECT_FALSE(callback_a_.Equals(callback_c));
@@ -148,6 +135,23 @@ TEST_F(CallbackTest, ResetAndReturn) {
ASSERT_TRUE(tfr.cb_already_run);
}
+TEST_F(CallbackTest, NullAfterMoveRun) {
+ Closure cb = Bind([] {});
+ ASSERT_TRUE(cb);
+ std::move(cb).Run();
+ ASSERT_FALSE(cb);
+
+ const Closure cb2 = Bind([] {});
+ ASSERT_TRUE(cb2);
+ std::move(cb2).Run();
+ ASSERT_TRUE(cb2);
+
+ OnceClosure cb3 = BindOnce([] {});
+ ASSERT_TRUE(cb3);
+ std::move(cb3).Run();
+ ASSERT_FALSE(cb3);
+}
+
class CallbackOwner : public base::RefCounted<CallbackOwner> {
public:
explicit CallbackOwner(bool* deleted) {