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

Side by Side Diff: base/callback_unittest.cc

Issue 2753953003: Remove RunMixin from base::Callback implementation (Closed)
Patch Set: rebase Created 3 years, 9 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.h ('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"
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 141
142 TEST_F(CallbackTest, ResetAndReturn) { 142 TEST_F(CallbackTest, ResetAndReturn) {
143 TestForReentrancy tfr; 143 TestForReentrancy tfr;
144 ASSERT_FALSE(tfr.cb.is_null()); 144 ASSERT_FALSE(tfr.cb.is_null());
145 ASSERT_FALSE(tfr.cb_already_run); 145 ASSERT_FALSE(tfr.cb_already_run);
146 ResetAndReturn(&tfr.cb).Run(); 146 ResetAndReturn(&tfr.cb).Run();
147 ASSERT_TRUE(tfr.cb.is_null()); 147 ASSERT_TRUE(tfr.cb.is_null());
148 ASSERT_TRUE(tfr.cb_already_run); 148 ASSERT_TRUE(tfr.cb_already_run);
149 } 149 }
150 150
151 TEST_F(CallbackTest, NullAfterMoveRun) {
152 Closure cb = Bind([] {});
153 ASSERT_TRUE(cb);
154 std::move(cb).Run();
155 ASSERT_FALSE(cb);
156
157 const Closure cb2 = Bind([] {});
158 ASSERT_TRUE(cb2);
159 std::move(cb2).Run();
160 ASSERT_TRUE(cb2);
161
162 OnceClosure cb3 = BindOnce([] {});
163 ASSERT_TRUE(cb3);
164 std::move(cb3).Run();
165 ASSERT_FALSE(cb3);
166 }
167
151 class CallbackOwner : public base::RefCounted<CallbackOwner> { 168 class CallbackOwner : public base::RefCounted<CallbackOwner> {
152 public: 169 public:
153 explicit CallbackOwner(bool* deleted) { 170 explicit CallbackOwner(bool* deleted) {
154 callback_ = Bind(&CallbackOwner::Unused, this); 171 callback_ = Bind(&CallbackOwner::Unused, this);
155 deleted_ = deleted; 172 deleted_ = deleted;
156 } 173 }
157 void Reset() { 174 void Reset() {
158 callback_.Reset(); 175 callback_.Reset();
159 // We are deleted here if no-one else had a ref to us. 176 // We are deleted here if no-one else had a ref to us.
160 } 177 }
(...skipping 13 matching lines...) Expand all
174 191
175 TEST_F(CallbackTest, CallbackHasLastRefOnContainingObject) { 192 TEST_F(CallbackTest, CallbackHasLastRefOnContainingObject) {
176 bool deleted = false; 193 bool deleted = false;
177 CallbackOwner* owner = new CallbackOwner(&deleted); 194 CallbackOwner* owner = new CallbackOwner(&deleted);
178 owner->Reset(); 195 owner->Reset();
179 ASSERT_TRUE(deleted); 196 ASSERT_TRUE(deleted);
180 } 197 }
181 198
182 } // namespace 199 } // namespace
183 } // namespace base 200 } // namespace base
OLDNEW
« no previous file with comments | « base/callback.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698