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

Unified Diff: base/bind_unittest.cc

Issue 17514007: Add a test for base::Bind() and scoped_refptrs copies. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove spurious newline Created 7 years, 6 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/bind_unittest.cc
diff --git a/base/bind_unittest.cc b/base/bind_unittest.cc
index 5ca67e9630abaaf4cf4b4df7426a83fca82a19ac..2c93d53ee4b59afa26e3312ba0bc1ed1ebb3d396 100644
--- a/base/bind_unittest.cc
+++ b/base/bind_unittest.cc
@@ -211,6 +211,10 @@ int FunctionWithWeakFirstParam(WeakPtr<NoRef> o, int n) {
return n;
}
+int FunctionWithScopedRefptrFirstParam(const scoped_refptr<HasRef>& o, int n) {
+ return n;
+}
+
void TakesACallback(const Closure& callback) {
callback.Run();
}
@@ -663,6 +667,21 @@ TEST_F(BindTest, ConstRef) {
EXPECT_EQ(0, assigns);
}
+TEST_F(BindTest, ScopedRefptr) {
+ // BUG: The scoped_refptr should cause the only AddRef()/Release() pair. But
+ // due to a bug in base::Bind(), there's an extra call when invoking the
+ // callback.
+ // https://code.google.com/p/chromium/issues/detail?id=251937
+ EXPECT_CALL(has_ref_, AddRef()).Times(2);
+ EXPECT_CALL(has_ref_, Release()).Times(2);
+
+ const scoped_refptr<StrictMock<HasRef> > refptr(&has_ref_);
+
+ Callback<int(void)> scoped_refptr_const_ref_cb =
+ Bind(&FunctionWithScopedRefptrFirstParam, base::ConstRef(refptr), 1);
+ EXPECT_EQ(1, scoped_refptr_const_ref_cb.Run());
+}
+
// Test Owned() support.
TEST_F(BindTest, Owned) {
int deletes = 0;
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698