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

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: base::ResetAndReturn is born. 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_helpers.h ('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..d3ea2682afb4bf279c2a7d9c5342f3fa94d6c2ea 100644
--- a/base/callback_unittest.cc
+++ b/base/callback_unittest.cc
@@ -2,7 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "base/bind.h"
#include "base/callback.h"
+#include "base/callback_helpers.h"
#include "base/callback_internal.h"
#include "base/memory/scoped_ptr.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -11,21 +13,12 @@ namespace base {
namespace {
-class HelperObject {
- 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 +123,28 @@ TEST_F(CallbackTest, Reset) {
EXPECT_TRUE(callback_a_.Equals(null_callback_));
}
+struct TestForReentrancy {
+ TestForReentrancy()
+ : cb_already_run(false),
+ cb(base::Bind(&TestForReentrancy::AssertCBIsNull,
akalin 2012/03/23 18:42:07 no base::
Ami GONE FROM CHROMIUM 2012/03/24 17:43:35 Done.
+ base::Unretained(this))) {
akalin 2012/03/23 18:42:07 no base::
Ami GONE FROM CHROMIUM 2012/03/24 17:43:35 Done.
+ }
+ void AssertCBIsNull() {
+ ASSERT_TRUE(cb.is_null());
+ cb_already_run = true;
+ }
+ bool cb_already_run;
+ Closure cb;
+};
+
+TEST_F(CallbackTest, ResetAndReturn) {
+ TestForReentrancy tfr;
+ ASSERT_FALSE(tfr.cb.is_null());
+ ASSERT_FALSE(tfr.cb_already_run);
+ base::ResetAndReturn(&tfr.cb).Run();
akalin 2012/03/23 18:42:07 no base::
Ami GONE FROM CHROMIUM 2012/03/24 17:43:35 Done.
+ ASSERT_TRUE(tfr.cb.is_null());
+ ASSERT_TRUE(tfr.cb_already_run);
+}
+
} // namespace
} // namespace base
« no previous file with comments | « base/callback_helpers.h ('k') | content/renderer/media/capture_video_decoder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698