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

Unified Diff: base/callback_unittest.cc

Issue 9717021: Make Callback::Reset() return a copy to support use-cases where Run() ends up modifying |*this|. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/callback.h.pump ('k') | content/renderer/media/capture_video_decoder.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/callback_unittest.cc
diff --git a/base/callback_unittest.cc b/base/callback_unittest.cc
index 1c3db04c10eb5038066e2651a7700695a411a703..3bc338b2c9b0a93056abbc7d9398612e166a59f4 100644
--- a/base/callback_unittest.cc
+++ b/base/callback_unittest.cc
@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "base/bind.h"
Ami GONE FROM CHROMIUM 2012/03/17 05:05:12 I suspect the FakeInvoker business below is meant
akalin 2012/03/19 21:53:20 I don't remember why Albert wanted to explicitly a
#include "base/callback.h"
#include "base/callback_internal.h"
#include "base/memory/scoped_ptr.h"
@@ -11,21 +12,12 @@ namespace base {
namespace {
-class HelperObject {
Ami GONE FROM CHROMIUM 2012/03/17 05:05:12 I couldn't find where this was used, so deleted it
- public:
- HelperObject() : next_number_(0) { }
- int GetNextNumber() { return ++next_number_; }
- void GetNextNumberArg(int* number) { *number = GetNextNumber(); }
-
- private:
- int next_number_;
-};
-
struct FakeInvoker {
typedef void(RunType)(internal::BindStateBase*);
static void Run(internal::BindStateBase*) {
}
};
+
} // namespace
namespace internal {
@@ -130,5 +122,27 @@ TEST_F(CallbackTest, Reset) {
EXPECT_TRUE(callback_a_.Equals(null_callback_));
}
+struct TestForReentrancy {
+ TestForReentrancy() {
+ cb_already_run = false;
+ cb = base::Bind(&TestForReentrancy::CheckCBIsNull, base::Unretained(this));
+ }
+ void CheckCBIsNull() {
+ CHECK(cb.is_null());
+ cb_already_run = true;
+ }
+ bool cb_already_run;
+ Closure cb;
+};
+
+TEST_F(CallbackTest, ResetAndRun) {
+ TestForReentrancy tfr;
+ ASSERT_FALSE(tfr.cb.is_null());
+ ASSERT_FALSE(tfr.cb_already_run);
+ tfr.cb.ResetAndRun();
+ ASSERT_TRUE(tfr.cb.is_null());
+ ASSERT_TRUE(tfr.cb_already_run);
+}
+
} // namespace
} // namespace base
« no previous file with comments | « base/callback.h.pump ('k') | content/renderer/media/capture_video_decoder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698