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

Side by Side Diff: base/callback_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 unified diff | Download patch
« no previous file with comments | « base/callback_internal.cc ('k') | no next file » | 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #include "base/callback.h" 5 #include "base/callback.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/callback_helpers.h" 10 #include "base/callback_helpers.h"
11 #include "base/callback_internal.h" 11 #include "base/callback_internal.h"
12 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
13 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
14 14
15 namespace base { 15 namespace base {
16 16
17 void NopInvokeFunc() {} 17 void NopInvokeFunc() {}
18 18
19 // White-box testpoints to inject into a Callback<> object for checking 19 // White-box testpoints to inject into a Callback<> object for checking
20 // comparators and emptiness APIs. Use a BindState that is specialized 20 // comparators and emptiness APIs. Use a BindState that is specialized
21 // based on a type we declared in the anonymous namespace above to remove any 21 // based on a type we declared in the anonymous namespace above to remove any
22 // chance of colliding with another instantiation and breaking the 22 // chance of colliding with another instantiation and breaking the
23 // one-definition-rule. 23 // one-definition-rule.
24 struct FakeBindState1 : internal::BindStateBase { 24 struct FakeBindState1 : internal::BindStateBase {
25 FakeBindState1() : BindStateBase(&NopInvokeFunc, &Destroy) {} 25 FakeBindState1() : BindStateBase(&NopInvokeFunc, &Destroy, &IsCancelled) {}
26 private: 26 private:
27 ~FakeBindState1() {} 27 ~FakeBindState1() {}
28 static void Destroy(internal::BindStateBase* self) { 28 static void Destroy(internal::BindStateBase* self) {
29 delete static_cast<FakeBindState1*>(self); 29 delete static_cast<FakeBindState1*>(self);
30 } 30 }
31 static bool IsCancelled(const internal::BindStateBase*) {
32 return false;
33 }
31 }; 34 };
32 35
33 struct FakeBindState2 : internal::BindStateBase { 36 struct FakeBindState2 : internal::BindStateBase {
34 FakeBindState2() : BindStateBase(&NopInvokeFunc, &Destroy) {} 37 FakeBindState2() : BindStateBase(&NopInvokeFunc, &Destroy, &IsCancelled) {}
35 private: 38 private:
36 ~FakeBindState2() {} 39 ~FakeBindState2() {}
37 static void Destroy(internal::BindStateBase* self) { 40 static void Destroy(internal::BindStateBase* self) {
38 delete static_cast<FakeBindState2*>(self); 41 delete static_cast<FakeBindState2*>(self);
39 } 42 }
43 static bool IsCancelled(const internal::BindStateBase*) {
44 return false;
45 }
40 }; 46 };
41 47
42 namespace { 48 namespace {
43 49
44 class CallbackTest : public ::testing::Test { 50 class CallbackTest : public ::testing::Test {
45 public: 51 public:
46 CallbackTest() 52 CallbackTest()
47 : callback_a_(new FakeBindState1()), 53 : callback_a_(new FakeBindState1()),
48 callback_b_(new FakeBindState2()) { 54 callback_b_(new FakeBindState2()) {
49 } 55 }
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 163
158 TEST_F(CallbackTest, CallbackHasLastRefOnContainingObject) { 164 TEST_F(CallbackTest, CallbackHasLastRefOnContainingObject) {
159 bool deleted = false; 165 bool deleted = false;
160 CallbackOwner* owner = new CallbackOwner(&deleted); 166 CallbackOwner* owner = new CallbackOwner(&deleted);
161 owner->Reset(); 167 owner->Reset();
162 ASSERT_TRUE(deleted); 168 ASSERT_TRUE(deleted);
163 } 169 }
164 170
165 } // namespace 171 } // namespace
166 } // namespace base 172 } // namespace base
OLDNEW
« no previous file with comments | « base/callback_internal.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698