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

Unified Diff: third_party/WebKit/Source/wtf/FunctionalTest.cpp

Issue 2091713002: Specialize base::IsWeakReceiver for Blink weak pointers to support base::Bind (1/5) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: +#include for build fix Created 4 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 | « third_party/WebKit/Source/wtf/Functional.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« no previous file with comments | « third_party/WebKit/Source/wtf/Functional.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698