summaryrefslogtreecommitdiff
path: root/Tools/WebKitTestRunner/gtk/TestControllerGtk.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Tools/WebKitTestRunner/gtk/TestControllerGtk.cpp')
-rw-r--r--Tools/WebKitTestRunner/gtk/TestControllerGtk.cpp83
1 files changed, 60 insertions, 23 deletions
diff --git a/Tools/WebKitTestRunner/gtk/TestControllerGtk.cpp b/Tools/WebKitTestRunner/gtk/TestControllerGtk.cpp
index d8fb9f728..62d031a87 100644
--- a/Tools/WebKitTestRunner/gtk/TestControllerGtk.cpp
+++ b/Tools/WebKitTestRunner/gtk/TestControllerGtk.cpp
@@ -27,52 +27,68 @@
#include "config.h"
#include "TestController.h"
+#include "PlatformWebView.h"
#include <gtk/gtk.h>
#include <wtf/Platform.h>
-#include <wtf/gobject/GUniquePtr.h>
+#include <wtf/RunLoop.h>
+#include <wtf/glib/GRefPtr.h>
+#include <wtf/glib/GUniquePtr.h>
#include <wtf/text/WTFString.h>
namespace WTR {
-static guint gTimeoutSourceId = 0;
-
-static void cancelTimeout()
+static GSource* timeoutSource()
{
- if (!gTimeoutSourceId)
- return;
- g_source_remove(gTimeoutSourceId);
- gTimeoutSourceId = 0;
+ static GRefPtr<GSource> source = nullptr;
+ if (!source) {
+ source = adoptGRef(g_timeout_source_new(0));
+ g_source_set_ready_time(source.get(), -1);
+ g_source_set_name(source.get(), "[WTR] Test timeout source");
+ g_source_set_callback(source.get(), [](gpointer userData) -> gboolean {
+ g_source_set_ready_time(static_cast<GSource*>(userData), -1);
+ fprintf(stderr, "FAIL: TestControllerRunLoop timed out.\n");
+ RunLoop::main().stop();
+ return G_SOURCE_REMOVE;
+ }, source.get(), nullptr);
+ g_source_attach(source.get(), nullptr);
+ }
+ return source.get();
}
void TestController::notifyDone()
{
- gtk_main_quit();
- cancelTimeout();
+ g_source_set_ready_time(timeoutSource(), -1);
+ RunLoop::main().stop();
}
void TestController::platformInitialize()
{
}
-void TestController::platformDestroy()
+WKPreferencesRef TestController::platformPreferences()
{
+ return WKPageGroupGetPreferences(m_pageGroup.get());
}
-static gboolean timeoutCallback(gpointer)
+void TestController::platformDestroy()
{
- fprintf(stderr, "FAIL: TestControllerRunLoop timed out.\n");
- gtk_main_quit();
- return FALSE;
}
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");
- }
- gtk_main();
+ if (timeout > 0) {
+ // FIXME: This conversion is now repeated in several places, it should be moved to a common place in WTF and used everywhere.
+ auto timeoutDuration = std::chrono::duration<double>(timeout);
+ auto safeDuration = std::chrono::microseconds::max();
+ if (timeoutDuration < safeDuration)
+ safeDuration = std::chrono::duration_cast<std::chrono::microseconds>(timeoutDuration);
+ gint64 currentTime = g_get_monotonic_time();
+ gint64 targetTime = currentTime + std::min<gint64>(G_MAXINT64 - currentTime, safeDuration.count());
+ ASSERT(targetTime >= currentTime);
+ g_source_set_ready_time(timeoutSource(), targetTime);
+ } else
+ g_source_set_ready_time(timeoutSource(), -1);
+ RunLoop::main().run();
}
static char* getEnvironmentVariableAsUTF8String(const char* variableName)
@@ -102,9 +118,14 @@ void TestController::platformInitializeContext()
{
}
-void TestController::setHidden(bool)
+void TestController::setHidden(bool hidden)
{
- // FIXME: Need to implement this to test visibilityState.
+ if (!m_mainWebView)
+ return;
+ if (hidden)
+ gtk_widget_unmap(GTK_WIDGET(m_mainWebView->platformView()));
+ else
+ gtk_widget_map(GTK_WIDGET(m_mainWebView->platformView()));
}
void TestController::runModal(PlatformWebView*)
@@ -117,4 +138,20 @@ const char* TestController::platformLibraryPathForTesting()
return 0;
}
+void TestController::platformConfigureViewForTest(const TestInvocation&)
+{
+ WKPageSetApplicationNameForUserAgent(mainWebView()->page(), WKStringCreateWithUTF8CString("WebKitTestRunnerGTK"));
+}
+
+void TestController::platformResetPreferencesToConsistentValues()
+{
+ if (!m_mainWebView)
+ return;
+ m_mainWebView->dismissAllPopupMenus();
+}
+
+void TestController::updatePlatformSpecificTestOptionsForTest(TestOptions&, const std::string&) const
+{
+}
+
} // namespace WTR