aboutsummaryrefslogtreecommitdiff
path: root/third_party/chromium/base/bind_unittest.cc
diff options
context:
space:
mode:
Diffstat (limited to 'third_party/chromium/base/bind_unittest.cc')
-rw-r--r--third_party/chromium/base/bind_unittest.cc71
1 files changed, 40 insertions, 31 deletions
diff --git a/third_party/chromium/base/bind_unittest.cc b/third_party/chromium/base/bind_unittest.cc
index 4c4f3e6..8188d2c 100644
--- a/third_party/chromium/base/bind_unittest.cc
+++ b/third_party/chromium/base/bind_unittest.cc
@@ -656,28 +656,6 @@ TEST_F(BindTest, ArrayArgumentBinding) {
EXPECT_EQ(3, const_array_cb.Run());
}
-// Verify SupportsAddRefAndRelease correctly introspects the class type for
-// AddRef() and Release().
-// - Class with AddRef() and Release()
-// - Class without AddRef() and Release()
-// - Derived Class with AddRef() and Release()
-// - Derived Class without AddRef() and Release()
-// - Derived Class with AddRef() and Release() and a private destructor.
-TEST_F(BindTest, SupportsAddRefAndRelease) {
- EXPECT_TRUE(internal::SupportsAddRefAndRelease<HasRef>::value);
- EXPECT_FALSE(internal::SupportsAddRefAndRelease<NoRef>::value);
-
- // StrictMock<T> is a derived class of T. So, we use StrictMock<HasRef> and
- // StrictMock<NoRef> to test that SupportsAddRefAndRelease works over
- // inheritance.
- EXPECT_TRUE(internal::SupportsAddRefAndRelease<StrictMock<HasRef> >::value);
- EXPECT_FALSE(internal::SupportsAddRefAndRelease<StrictMock<NoRef> >::value);
-
- // This matters because the implementation creates a dummy class that
- // inherits from the template type.
- EXPECT_TRUE(internal::SupportsAddRefAndRelease<HasRefPrivateDtor>::value);
-}
-
// Unretained() wrapper support.
// - Method bound to Unretained() non-const object.
// - Const method bound to Unretained() non-const object.
@@ -769,15 +747,10 @@ TEST_F(BindTest, ConstRef) {
}
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_);
+ EXPECT_CALL(has_ref_, AddRef()).Times(1);
+ EXPECT_CALL(has_ref_, Release()).Times(1);
+ const scoped_refptr<HasRef> refptr(&has_ref_);
Callback<int()> scoped_refptr_const_ref_cb =
Bind(&FunctionWithScopedRefptrFirstParam, base::ConstRef(refptr), 1);
EXPECT_EQ(1, scoped_refptr_const_ref_cb.Run());
@@ -808,6 +781,12 @@ TEST_F(BindTest, Owned) {
EXPECT_EQ(1, deletes);
}
+TEST_F(BindTest, UniquePtrReceiver) {
+ std::unique_ptr<StrictMock<NoRef>> no_ref(new StrictMock<NoRef>);
+ EXPECT_CALL(*no_ref, VoidMethod0()).Times(1);
+ Bind(&NoRef::VoidMethod0, std::move(no_ref)).Run();
+}
+
// Tests for Passed() wrapper support:
// - Passed() can be constructed from a pointer to scoper.
// - Passed() can be constructed from a scoper rvalue.
@@ -896,7 +875,7 @@ TEST_F(BindTest, BindMoveOnlyVector) {
using MoveOnlyVector = std::vector<std::unique_ptr<int>>;
MoveOnlyVector v;
- v.push_back(base::MakeUnique<int>(12345));
+ v.push_back(WrapUnique(new int(12345)));
// Early binding should work:
base::Callback<MoveOnlyVector()> bound_cb =
@@ -1065,6 +1044,36 @@ TEST_F(BindTest, ArgumentCopiesAndMoves) {
EXPECT_EQ(0, move_assigns);
}
+TEST_F(BindTest, CapturelessLambda) {
+ EXPECT_FALSE(internal::IsConvertibleToRunType<void>::value);
+ EXPECT_FALSE(internal::IsConvertibleToRunType<int>::value);
+ EXPECT_FALSE(internal::IsConvertibleToRunType<void(*)()>::value);
+ EXPECT_FALSE(internal::IsConvertibleToRunType<void(NoRef::*)()>::value);
+
+ auto f = []() {};
+ EXPECT_TRUE(internal::IsConvertibleToRunType<decltype(f)>::value);
+
+ int i = 0;
+ auto g = [i]() {};
+ EXPECT_FALSE(internal::IsConvertibleToRunType<decltype(g)>::value);
+
+ auto h = [](int, double) { return 'k'; };
+ EXPECT_TRUE((std::is_same<
+ char(int, double),
+ internal::ExtractCallableRunType<decltype(h)>>::value));
+
+ EXPECT_EQ(42, Bind([] { return 42; }).Run());
+ EXPECT_EQ(42, Bind([](int i) { return i * 7; }, 6).Run());
+
+ int x = 1;
+ base::Callback<void(int)> cb =
+ Bind([](int* x, int i) { *x *= i; }, Unretained(&x));
+ cb.Run(6);
+ EXPECT_EQ(6, x);
+ cb.Run(7);
+ EXPECT_EQ(42, x);
+}
+
// Callback construction and assignment tests.
// - Construction from an InvokerStorageHolder should not cause ref/deref.
// - Assignment from other callback should only cause one ref