Many modern media control tests leak documents in testing
[WebKit-https.git] / Source / WebKit / WebProcess / InjectedBundle / API / c / WKBundlePage.cpp
index 24d4f0d..fcd6e1b 100644 (file)
@@ -620,7 +620,7 @@ void WKBundlePageRegisterScrollOperationCompletionCallback(WKBundlePageRef pageR
     });
 }
 
-void WKBundlePagePostTask(WKBundlePageRef pageRef, WKBundlePageTestNotificationCallback callback, void* context)
+void WKBundlePageCallAfterTasksAndTimers(WKBundlePageRef pageRef, WKBundlePageTestNotificationCallback callback, void* context)
 {
     if (!callback)
         return;
@@ -634,8 +634,29 @@ void WKBundlePagePostTask(WKBundlePageRef pageRef, WKBundlePageTestNotificationC
     if (!document)
         return;
 
+    class TimerOwner {
+    public:
+        TimerOwner(WTF::Function<void (void*)>&& callback, void* context)
+            : m_timer(*this, &TimerOwner::timerFired)
+            , m_callback(WTFMove(callback))
+            , m_context(context)
+        {
+            m_timer.startOneShot(0_s);
+        }
+        
+        void timerFired()
+        {
+            m_callback(m_context);
+            delete this;
+        }
+        
+        WebCore::Timer m_timer;
+        WTF::Function<void (void*)> m_callback;
+        void* m_context;
+    };
+    
     document->postTask([=] (WebCore::ScriptExecutionContext&) {
-        callback(context);
+        new TimerOwner(callback, context); // deletes itself when done.
     });
 }