Commit edd2f1ba authored by willchan@chromium.org's avatar willchan@chromium.org

Add a test for base::Bind() and scoped_refptrs copies.

Specifically tracks the number of AddRef()/Release() pairs called for a
method expecting a "const scoped_refptr<T>&". base::Bind()'s impl
currently leads to too many AddRef()/Release() pairs.

BUG=251937

Review URL: https://chromiumcodereview.appspot.com/17514007

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@208087 0039d316-1c4b-4281-b951-d872f2087c98
parent 723eaf48
...@@ -211,6 +211,10 @@ int FunctionWithWeakFirstParam(WeakPtr<NoRef> o, int n) { ...@@ -211,6 +211,10 @@ int FunctionWithWeakFirstParam(WeakPtr<NoRef> o, int n) {
return n; return n;
} }
int FunctionWithScopedRefptrFirstParam(const scoped_refptr<HasRef>& o, int n) {
return n;
}
void TakesACallback(const Closure& callback) { void TakesACallback(const Closure& callback) {
callback.Run(); callback.Run();
} }
...@@ -663,6 +667,21 @@ TEST_F(BindTest, ConstRef) { ...@@ -663,6 +667,21 @@ TEST_F(BindTest, ConstRef) {
EXPECT_EQ(0, assigns); 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 Owned() support.
TEST_F(BindTest, Owned) { TEST_F(BindTest, Owned) {
int deletes = 0; int deletes = 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment