| Index: third_party/WebKit/Source/platform/scheduler/CancellableTaskFactoryTest.cpp
|
| diff --git a/third_party/WebKit/Source/platform/scheduler/CancellableTaskFactoryTest.cpp b/third_party/WebKit/Source/platform/scheduler/CancellableTaskFactoryTest.cpp
|
| index 905ae12655c3851f25df9111ed9d9cc62726209d..453e50a77e865674e3662c86b678a4b9aae15f08 100644
|
| --- a/third_party/WebKit/Source/platform/scheduler/CancellableTaskFactoryTest.cpp
|
| +++ b/third_party/WebKit/Source/platform/scheduler/CancellableTaskFactoryTest.cpp
|
| @@ -4,6 +4,7 @@
|
|
|
| #include "platform/scheduler/CancellableTaskFactory.h"
|
|
|
| +#include "platform/heap/Handle.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
|
|
| namespace blink {
|
| @@ -176,4 +177,51 @@ TEST_F(CancellableTaskFactoryTest, CreatingANewTaskCancelsPreviousOnes)
|
| EXPECT_EQ(1, executionCount);
|
| }
|
|
|
| +namespace {
|
| +
|
| +class GCObject final : public GarbageCollectedFinalized<GCObject> {
|
| +public:
|
| + GCObject()
|
| + : m_factory(CancellableTaskFactory::create(this, &GCObject::run))
|
| + {
|
| + }
|
| +
|
| + ~GCObject()
|
| + {
|
| + s_destructed++;
|
| + }
|
| +
|
| + void run()
|
| + {
|
| + s_invoked++;
|
| + }
|
| +
|
| + DEFINE_INLINE_TRACE() { }
|
| +
|
| + static int s_destructed;
|
| + static int s_invoked;
|
| +
|
| + OwnPtr<CancellableTaskFactory> m_factory;
|
| +};
|
| +
|
| +int GCObject::s_destructed = 0;
|
| +int GCObject::s_invoked = 0;
|
| +
|
| +} // namespace
|
| +
|
| +TEST(CancellableTaskFactoryTest, GarbageCollectedWeak)
|
| +{
|
| + GCObject* object = new GCObject();
|
| + OwnPtr<WebTaskRunner::Task> task = adoptPtr(object->m_factory->cancelAndCreate());
|
| + object = nullptr;
|
| + ThreadHeap::collectAllGarbage();
|
| + task->run();
|
| + // The owning object will have been GCed and the task will have
|
| + // lost its weak reference. Verify that it wasn't invoked.
|
| + EXPECT_EQ(0, GCObject::s_invoked);
|
| +
|
| + // ..and just to make sure |object| was indeed destructed.
|
| + EXPECT_EQ(1, GCObject::s_destructed);
|
| +}
|
| +
|
| } // namespace blink
|
|
|