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

Unified Diff: third_party/WebKit/Source/platform/scheduler/CancellableTaskFactoryTest.cpp

Issue 1976433003: Remove dated NavigationScheduler TODO. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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/core/loader/NavigationScheduler.cpp ('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/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
« no previous file with comments | « third_party/WebKit/Source/core/loader/NavigationScheduler.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698