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

Unified Diff: third_party/WebKit/Source/platform/heap/PersistentTest.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
Index: third_party/WebKit/Source/platform/heap/PersistentTest.cpp
diff --git a/third_party/WebKit/Source/platform/heap/PersistentTest.cpp b/third_party/WebKit/Source/platform/heap/PersistentTest.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..2e43a20798aee9798100c81cbf5cbf977e5949b5
--- /dev/null
+++ b/third_party/WebKit/Source/platform/heap/PersistentTest.cpp
@@ -0,0 +1,61 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "platform/heap/Persistent.h"
+
+#include "platform/ThreadSafeFunctional.h"
+#include "platform/heap/Heap.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include <memory>
+
+namespace blink {
+namespace {
+
+void preciselyCollectGarbage()
+{
+ ThreadHeap::collectGarbage(BlinkGC::NoHeapPointersOnStack, BlinkGC::GCWithSweep, BlinkGC::ForcedGC);
+}
+
+class Receiver : public GarbageCollected<Receiver> {
+public:
+ void increment(int* counter)
+ {
+ ++*counter;
+ }
+
+ DEFINE_INLINE_TRACE() {}
+};
+
+TEST(PersistentTest, BindCancellation)
+{
+ Receiver* receiver = new Receiver;
+ int counter = 0;
+ std::unique_ptr<SameThreadClosure> function = WTF::bind(&Receiver::increment, wrapWeakPersistent(receiver), WTF::unretained(&counter));
+
+ (*function)();
+ EXPECT_EQ(1, counter);
+
+ receiver = nullptr;
+ preciselyCollectGarbage();
+ (*function)();
+ EXPECT_EQ(1, counter);
+}
+
+TEST(PersistentTest, CrossThreadBindCancellation)
+{
+ Receiver* receiver = new Receiver;
+ int counter = 0;
+ std::unique_ptr<CrossThreadClosure> function = blink::threadSafeBind(&Receiver::increment, wrapCrossThreadWeakPersistent(receiver), WTF::crossThreadUnretained(&counter));
+
+ (*function)();
+ EXPECT_EQ(1, counter);
+
+ receiver = nullptr;
+ preciselyCollectGarbage();
+ (*function)();
+ EXPECT_EQ(1, counter);
+}
+
+} // namespace
+} // namespace blink
« no previous file with comments | « third_party/WebKit/Source/platform/heap/Persistent.h ('k') | third_party/WebKit/Source/platform/heap/blink_heap.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698