[GTK] Use GMainLoopSource in WebKitTestRunner
authorcarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 7 Dec 2014 14:08:09 +0000 (14:08 +0000)
committercarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 7 Dec 2014 14:08:09 +0000 (14:08 +0000)
https://bugs.webkit.org/show_bug.cgi?id=138831

Reviewed by Sergio Villar Senin.

* WebKitTestRunner/InjectedBundle/TestRunner.h:
* WebKitTestRunner/InjectedBundle/gtk/TestRunnerGtk.cpp:
(WTR::TestRunner::platformInitialize):
(WTR::TestRunner::invalidateWaitToDumpWatchdogTimer):
(WTR::TestRunner::initializeWaitToDumpWatchdogTimerIfNeeded):
(WTR::waitToDumpWatchdogTimerCallback): Deleted.
* WebKitTestRunner/gtk/TestControllerGtk.cpp:
(WTR::TestController::notifyDone):
(WTR::TestController::platformRunUntil):
(WTR::cancelTimeout): Deleted.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@176921 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Tools/ChangeLog
Tools/WebKitTestRunner/InjectedBundle/TestRunner.h
Tools/WebKitTestRunner/InjectedBundle/gtk/TestRunnerGtk.cpp
Tools/WebKitTestRunner/gtk/TestControllerGtk.cpp

index 4dbeade..94de14e 100644 (file)
@@ -1,5 +1,23 @@
 2014-12-07  Carlos Garcia Campos  <cgarcia@igalia.com>
 
+        [GTK] Use GMainLoopSource in WebKitTestRunner
+        https://bugs.webkit.org/show_bug.cgi?id=138831
+
+        Reviewed by Sergio Villar Senin.
+
+        * WebKitTestRunner/InjectedBundle/TestRunner.h:
+        * WebKitTestRunner/InjectedBundle/gtk/TestRunnerGtk.cpp:
+        (WTR::TestRunner::platformInitialize):
+        (WTR::TestRunner::invalidateWaitToDumpWatchdogTimer):
+        (WTR::TestRunner::initializeWaitToDumpWatchdogTimerIfNeeded):
+        (WTR::waitToDumpWatchdogTimerCallback): Deleted.
+        * WebKitTestRunner/gtk/TestControllerGtk.cpp:
+        (WTR::TestController::notifyDone):
+        (WTR::TestController::platformRunUntil):
+        (WTR::cancelTimeout): Deleted.
+
+2014-12-07  Carlos Garcia Campos  <cgarcia@igalia.com>
+
         [GTK] Missing API detected in GObject DOM bindings after r176630
         https://bugs.webkit.org/show_bug.cgi?id=139201
 
index 9dbf1fa..642e6a4 100644 (file)
@@ -38,7 +38,8 @@
 #include <CoreFoundation/CFRunLoop.h>
 typedef RetainPtr<CFRunLoopTimerRef> PlatformTimerRef;
 #elif PLATFORM(GTK)
-typedef unsigned int PlatformTimerRef;
+#include <wtf/gobject/GMainLoopSource.h>
+typedef GMainLoopSource PlatformTimerRef;
 #elif PLATFORM(EFL)
 typedef Ecore_Timer* PlatformTimerRef;
 #endif
index 2543748..850e737 100644 (file)
 
 namespace WTR {
 
-static gboolean waitToDumpWatchdogTimerCallback(gpointer)
-{
-    InjectedBundle::shared().testRunner()->waitToDumpWatchdogTimerFired();
-    return FALSE;
-}
-
 void TestRunner::platformInitialize()
 {
-    m_waitToDumpWatchdogTimer = 0;
 }
 
 void TestRunner::invalidateWaitToDumpWatchdogTimer()
 {
-    if (!m_waitToDumpWatchdogTimer)
-        return;
-    g_source_remove(m_waitToDumpWatchdogTimer);
-    m_waitToDumpWatchdogTimer = 0;
+    m_waitToDumpWatchdogTimer.cancel();
 }
 
 void TestRunner::initializeWaitToDumpWatchdogTimerIfNeeded()
 {
-    if (m_waitToDumpWatchdogTimer)
+    if (m_waitToDumpWatchdogTimer.isScheduled())
         return;
 
-    m_waitToDumpWatchdogTimer = g_timeout_add(waitToDumpWatchdogTimerInterval * 1000,
-                                              waitToDumpWatchdogTimerCallback, 0);
-    g_source_set_name_by_id(m_waitToDumpWatchdogTimer, "[WebKit] waitToDumpWatchdogTimerCallback");
+    m_waitToDumpWatchdogTimer.scheduleAfterDelay("[WTR] waitToDumpWatchdogTimerCallback", [this] { waitToDumpWatchdogTimerFired(); },
+        std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::duration<double>(waitToDumpWatchdogTimerInterval)));
 }
 
 JSRetainPtr<JSStringRef> TestRunner::pathToLocalResource(JSStringRef url)
index e5cb71e..5fc83e2 100644 (file)
 
 #include <gtk/gtk.h>
 #include <wtf/Platform.h>
+#include <wtf/gobject/GMainLoopSource.h>
 #include <wtf/gobject/GUniquePtr.h>
 #include <wtf/text/WTFString.h>
 
 namespace WTR {
 
-static guint gTimeoutSourceId = 0;
-
-static void cancelTimeout()
-{
-    if (!gTimeoutSourceId)
-        return;
-    g_source_remove(gTimeoutSourceId);
-    gTimeoutSourceId = 0;
-}
+static GMainLoopSource timeoutSource;
 
 void TestController::notifyDone()
 {
     gtk_main_quit();
-    cancelTimeout();
+    timeoutSource.cancel();
 }
 
 void TestController::platformInitialize()
@@ -58,24 +51,19 @@ void TestController::platformDestroy()
 {
 }
 
-static gboolean timeoutCallback(gpointer)
-{
-    fprintf(stderr, "FAIL: TestControllerRunLoop timed out.\n");
-    gtk_main_quit();
-    return FALSE;
-}
-
 void TestController::platformWillRunTest(const TestInvocation&)
 {
 }
 
 void TestController::platformRunUntil(bool&, double timeout)
 {
-    cancelTimeout();
     if (timeout != m_noTimeout) {
-        gTimeoutSourceId = g_timeout_add(timeout * 1000, timeoutCallback, 0);
-        g_source_set_name_by_id(gTimeoutSourceId, "[WebKit] timeoutCallback");
-    }
+        timeoutSource.scheduleAfterDelay("[WTR] Test timeout source", [] {
+            fprintf(stderr, "FAIL: TestControllerRunLoop timed out.\n");
+            gtk_main_quit();
+        }, std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::duration<double>(timeout)));
+    } else
+        timeoutSource.cancel();
     gtk_main();
 }