| Index: third_party/WebKit/Source/wtf/FunctionalTest.cpp
|
| diff --git a/third_party/WebKit/Source/wtf/FunctionalTest.cpp b/third_party/WebKit/Source/wtf/FunctionalTest.cpp
|
| index be90fc4e13dd32fda495d95d43a14ae63fcfa0a3..b2498526763f3108d856f7e710cb9bcf1e7b9d8e 100644
|
| --- a/third_party/WebKit/Source/wtf/FunctionalTest.cpp
|
| +++ b/third_party/WebKit/Source/wtf/FunctionalTest.cpp
|
| @@ -27,6 +27,7 @@
|
|
|
| #include "testing/gtest/include/gtest/gtest.h"
|
| #include "wtf/RefCounted.h"
|
| +#include "wtf/WeakPtr.h"
|
| #include <utility>
|
|
|
| namespace WTF {
|
| @@ -78,6 +79,28 @@ template<> struct ParamStorageTraits<ClassToBeWrapped> {
|
| static UnwrappedClass unwrap(const StorageType& value) { return value.unwrap(); }
|
| };
|
|
|
| +class HasWeakPtrSupport {
|
| +public:
|
| + HasWeakPtrSupport() : m_weakPtrFactory(this) {}
|
| +
|
| + WTF::WeakPtr<HasWeakPtrSupport> createWeakPtr() {
|
| + return m_weakPtrFactory.createWeakPtr();
|
| + }
|
| +
|
| + void revokeAll()
|
| + {
|
| + m_weakPtrFactory.revokeAll();
|
| + }
|
| +
|
| + void increment(int* counter)
|
| + {
|
| + ++*counter;
|
| + }
|
| +
|
| +private:
|
| + WTF::WeakPtrFactory<HasWeakPtrSupport> m_weakPtrFactory;
|
| +};
|
| +
|
| namespace {
|
|
|
| int returnFortyTwo()
|
| @@ -541,6 +564,20 @@ TEST(FunctionalTest, CountCopiesOfUnboundArguments)
|
| EXPECT_LE((*bound2)(CountCopy()), 2); // Compiler is allowed to optimize one copy away if the argument is rvalue.
|
| }
|
|
|
| +TEST(FunctionalTest, WeakPtr)
|
| +{
|
| + HasWeakPtrSupport obj;
|
| + int counter = 0;
|
| + std::unique_ptr<WTF::SameThreadClosure> bound = WTF::bind(&HasWeakPtrSupport::increment, obj.createWeakPtr(), WTF::unretained(&counter));
|
| +
|
| + (*bound)();
|
| + EXPECT_EQ(1, counter);
|
| +
|
| + obj.revokeAll();
|
| + (*bound)();
|
| + EXPECT_EQ(1, counter);
|
| +}
|
| +
|
| } // anonymous namespace
|
|
|
| } // namespace WTF
|
|
|