Title: [265080] trunk
Revision
265080
Author
[email protected]
Date
2020-07-30 01:53:28 -0700 (Thu, 30 Jul 2020)

Log Message

[GTK4] Enable API tests
https://bugs.webkit.org/show_bug.cgi?id=214344

Reviewed by Adrian Perez de Castro.

.:

Build API tests for GTK4 too.

* Source/cmake/OptionsGTK.cmake:

Source/WebKit:

Use a custom KeyEvent struct to pass to the IM filter as a fake GdkEvent to be able to test input methods with
GTK4.

* UIProcess/API/glib/InputMethodFilter.h:
* UIProcess/API/gtk/InputMethodFilterGtk.cpp:
(WebKit::InputMethodFilter::platformEventKeyIsKeyPress const):
(WebKit::InputMethodFilter::filterKeyEvent):
* UIProcess/API/gtk/WebKitWebViewBaseInternal.h:
* UIProcess/CoordinatedGraphics/DrawingAreaProxyCoordinatedGraphics.cpp:
(WebKit::DrawingAreaProxyCoordinatedGraphics::DrawingMonitor::start):
(WebKit::DrawingAreaProxyCoordinatedGraphics::DrawingMonitor::stop):

Tools:

Port API tests to GTK4. Context menu and option menu tests are still disabled for GTK4 because we plan to change
the API for GTK4 in those cases.

* TestWebKitAPI/Tests/WebKitGLib/TestDownloads.cpp:
(beforeAll):
* TestWebKitAPI/Tests/WebKitGLib/TestInputMethodContext.cpp:
(webkitInputMethodContextMockFilterKeyEvent):
* TestWebKitAPI/Tests/WebKitGLib/TestMultiprocess.cpp:
* TestWebKitAPI/Tests/WebKitGLib/TestOptionMenu.cpp:
(beforeAll):
* TestWebKitAPI/Tests/WebKitGLib/TestUIClient.cpp:
(checkMimeTypeForFilter):
* TestWebKitAPI/Tests/WebKitGLib/TestWebExtensions.cpp:
(testWebExtensionInputElementIsUserEdited):
* TestWebKitAPI/Tests/WebKitGLib/TestWebKitSettings.cpp:
(testWebKitSettings):
* TestWebKitAPI/Tests/WebKitGLib/TestWebKitWebView.cpp:
* TestWebKitAPI/Tests/WebKitGtk/AccessibilityTestServer.cpp:
* TestWebKitAPI/Tests/WebKitGtk/InspectorTestServer.cpp:
(main):
* TestWebKitAPI/Tests/WebKitGtk/TestContextMenu.cpp:
(testContextMenuPopulateMenu):
(beforeAll):
* TestWebKitAPI/Tests/WebKitGtk/TestInspector.cpp:
* TestWebKitAPI/Tests/WebKitGtk/TestPrinting.cpp:
* TestWebKitAPI/Tests/WebKitGtk/TestWebViewEditor.cpp:
(Clipboard::Clipboard):
(Clipboard::clear):
(Clipboard::containsText const):
(Clipboard::waitForText):
(Clipboard::readText):
(testWebViewEditorCutCopyPasteNonEditable):
(testWebViewEditorCutCopyPasteEditable):
(testWebViewEditorSelectAllNonEditable):
(testWebViewEditorSelectAllEditable):
(loadContentsAndTryToCutSelection):
* TestWebKitAPI/glib/WebKitGLib/TestMain.h:
(Test::Test):
* TestWebKitAPI/glib/WebKitGLib/gtk/WebViewTestGtk.cpp:
(WebViewTest::platformDestroy):
(WebViewTest::showInWindow):
* TestWebKitAPI/gtk/PlatformUtilitiesGtk.cpp:
(TestWebKitAPI::Util::isKeyDown):
* TestWebKitAPI/gtk/PlatformWebViewGtk.cpp:
(TestWebKitAPI::PlatformWebView::~PlatformWebView):
(TestWebKitAPI::PlatformWebView::initialize):

Modified Paths

Diff

Modified: trunk/ChangeLog (265079 => 265080)


--- trunk/ChangeLog	2020-07-30 07:21:44 UTC (rev 265079)
+++ trunk/ChangeLog	2020-07-30 08:53:28 UTC (rev 265080)
@@ -1,3 +1,14 @@
+2020-07-15  Carlos Garcia Campos  <[email protected]>
+
+        [GTK4] Enable API tests
+        https://bugs.webkit.org/show_bug.cgi?id=214344
+
+        Reviewed by Adrian Perez de Castro.
+
+        Build API tests for GTK4 too.
+
+        * Source/cmake/OptionsGTK.cmake:
+
 2020-07-29  Adrian Perez de Castro  <[email protected]>
 
         Unreviewed. Update OptionsWPE.cmake and NEWS for the 2.29.2 release

Modified: trunk/Source/WebKit/ChangeLog (265079 => 265080)


--- trunk/Source/WebKit/ChangeLog	2020-07-30 07:21:44 UTC (rev 265079)
+++ trunk/Source/WebKit/ChangeLog	2020-07-30 08:53:28 UTC (rev 265080)
@@ -1,3 +1,22 @@
+2020-07-15  Carlos Garcia Campos  <[email protected]>
+
+        [GTK4] Enable API tests
+        https://bugs.webkit.org/show_bug.cgi?id=214344
+
+        Reviewed by Adrian Perez de Castro.
+
+        Use a custom KeyEvent struct to pass to the IM filter as a fake GdkEvent to be able to test input methods with
+        GTK4.
+
+        * UIProcess/API/glib/InputMethodFilter.h:
+        * UIProcess/API/gtk/InputMethodFilterGtk.cpp:
+        (WebKit::InputMethodFilter::platformEventKeyIsKeyPress const):
+        (WebKit::InputMethodFilter::filterKeyEvent):
+        * UIProcess/API/gtk/WebKitWebViewBaseInternal.h:
+        * UIProcess/CoordinatedGraphics/DrawingAreaProxyCoordinatedGraphics.cpp:
+        (WebKit::DrawingAreaProxyCoordinatedGraphics::DrawingMonitor::start):
+        (WebKit::DrawingAreaProxyCoordinatedGraphics::DrawingMonitor::stop):
+
 2020-07-30  Brady Eidson  <[email protected]>
 
         Refactor HID gamepad code to be much less fragile and much easier to hack on.

Modified: trunk/Source/WebKit/UIProcess/API/glib/InputMethodFilter.h (265079 => 265080)


--- trunk/Source/WebKit/UIProcess/API/glib/InputMethodFilter.h	2020-07-30 07:21:44 UTC (rev 265079)
+++ trunk/Source/WebKit/UIProcess/API/glib/InputMethodFilter.h	2020-07-30 08:53:28 UTC (rev 265080)
@@ -112,6 +112,9 @@
     struct {
         bool isActive { false };
         bool preeditChanged { false };
+#if PLATFORM(GTK) && USE(GTK4)
+        bool isFakeKeyEventForTesting { false };
+#endif
     } m_filteringContext;
 
     String m_compositionResult;

Modified: trunk/Source/WebKit/UIProcess/API/gtk/InputMethodFilterGtk.cpp (265079 => 265080)


--- trunk/Source/WebKit/UIProcess/API/gtk/InputMethodFilterGtk.cpp	2020-07-30 07:21:44 UTC (rev 265079)
+++ trunk/Source/WebKit/UIProcess/API/gtk/InputMethodFilterGtk.cpp	2020-07-30 08:53:28 UTC (rev 265080)
@@ -20,10 +20,13 @@
 #include "config.h"
 #include "InputMethodFilter.h"
 
+#include "WebKitInputMethodContextImplGtk.h"
 #include "WebKitInputMethodContextPrivate.h"
+#include "WebKitWebViewBaseInternal.h"
 #include <WebCore/GUniquePtrGtk.h>
 #include <WebCore/IntRect.h>
 #include <gdk/gdk.h>
+#include <wtf/SetForScope.h>
 
 namespace WebKit {
 using namespace WebCore;
@@ -39,6 +42,10 @@
 
 bool InputMethodFilter::platformEventKeyIsKeyPress(PlatformEventKey* event) const
 {
+#if USE(GTK4)
+    if (UNLIKELY(m_filteringContext.isFakeKeyEventForTesting))
+        return reinterpret_cast<KeyEvent*>(event)->type == GDK_KEY_PRESS;
+#endif
     return gdk_event_get_event_type(event) == GDK_KEY_PRESS;
 }
 
@@ -47,7 +54,17 @@
     if (!isEnabled() || !m_context)
         return { };
 
-#if !USE(GTK4)
+#if USE(GTK4)
+    if (WEBKIT_IS_INPUT_METHOD_CONTEXT_IMPL_GTK(m_context.get()))
+        return { };
+
+    // In GTK4 we can't create GdkEvents, so here we create a custom KeyEvent struct that is passed
+    // as a GdkEvent to the filter. This is only called from tests, and tests know they are receiving
+    // a KeyEvent struct instead of an actual GdkEvent.
+    SetForScope<bool> isFakeKeyEventForTesting(m_filteringContext.isFakeKeyEventForTesting, true);
+    KeyEvent event { type, keyval, modifiers };
+    return filterKeyEvent(reinterpret_cast<GdkEvent*>(&event));
+#else
     auto* webView = webkitInputMethodContextGetWebView(m_context.get());
     ASSERT(webView);
 
@@ -60,8 +77,6 @@
     event->key.state = modifiers;
     gdk_event_set_device(event.get(), gdk_seat_get_keyboard(gdk_display_get_default_seat(gtk_widget_get_display(GTK_WIDGET(webView)))));
     return filterKeyEvent(event.get());
-#else
-    return { };
 #endif
 }
 

Modified: trunk/Source/WebKit/UIProcess/API/gtk/WebKitWebViewBaseInternal.h (265079 => 265080)


--- trunk/Source/WebKit/UIProcess/API/gtk/WebKitWebViewBaseInternal.h	2020-07-30 07:21:44 UTC (rev 265079)
+++ trunk/Source/WebKit/UIProcess/API/gtk/WebKitWebViewBaseInternal.h	2020-07-30 08:53:28 UTC (rev 265080)
@@ -27,6 +27,12 @@
 
 typedef struct _WebKitWebViewBase WebKitWebViewBase;
 
+struct KeyEvent {
+    unsigned type { 0 };
+    unsigned keyval { 0 };
+    unsigned modifiers { 0 };
+};
+
 enum class MouseEventType { Press, Release, Motion };
 void webkitWebViewBaseSynthesizeMouseEvent(WebKitWebViewBase*, MouseEventType type, unsigned button, unsigned short buttons, int x, int y, unsigned modifiers, int clickCount);
 

Modified: trunk/Source/WebKit/UIProcess/CoordinatedGraphics/DrawingAreaProxyCoordinatedGraphics.cpp (265079 => 265080)


--- trunk/Source/WebKit/UIProcess/CoordinatedGraphics/DrawingAreaProxyCoordinatedGraphics.cpp	2020-07-30 07:21:44 UTC (rev 265079)
+++ trunk/Source/WebKit/UIProcess/CoordinatedGraphics/DrawingAreaProxyCoordinatedGraphics.cpp	2020-07-30 08:53:28 UTC (rev 265080)
@@ -411,8 +411,12 @@
     m_callback = WTFMove(callback);
 #if PLATFORM(GTK)
     gtk_widget_queue_draw(m_webPage.viewWidget());
+#if USE(GTK4)
+    m_timer.startOneShot(16_ms);
+#else
     g_signal_connect_swapped(m_webPage.viewWidget(), "draw", reinterpret_cast<GCallback>(webViewDrawCallback), this);
     m_timer.startOneShot(100_ms);
+#endif
 #else
     m_timer.startOneShot(0_s);
 #endif
@@ -421,7 +425,7 @@
 void DrawingAreaProxyCoordinatedGraphics::DrawingMonitor::stop()
 {
     m_timer.stop();
-#if PLATFORM(GTK)
+#if PLATFORM(GTK) && !USE(GTK4)
     g_signal_handlers_disconnect_by_func(m_webPage.viewWidget(), reinterpret_cast<gpointer>(webViewDrawCallback), this);
 #endif
     m_startTime = MonotonicTime();

Modified: trunk/Source/cmake/OptionsGTK.cmake (265079 => 265080)


--- trunk/Source/cmake/OptionsGTK.cmake	2020-07-30 07:21:44 UTC (rev 265079)
+++ trunk/Source/cmake/OptionsGTK.cmake	2020-07-30 08:53:28 UTC (rev 265080)
@@ -120,11 +120,7 @@
 SET_AND_EXPOSE_TO_BUILD(ENABLE_DEVELOPER_MODE ${DEVELOPER_MODE})
 if (DEVELOPER_MODE)
     WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_MINIBROWSER PUBLIC ON)
-    if (USE_GTK4)
-        WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_API_TESTS PRIVATE OFF)
-    else ()
-        WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_API_TESTS PRIVATE ON)
-    endif ()
+    WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_API_TESTS PRIVATE ON)
 else ()
     WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_MINIBROWSER PUBLIC OFF)
     WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_API_TESTS PRIVATE OFF)

Modified: trunk/Tools/ChangeLog (265079 => 265080)


--- trunk/Tools/ChangeLog	2020-07-30 07:21:44 UTC (rev 265079)
+++ trunk/Tools/ChangeLog	2020-07-30 08:53:28 UTC (rev 265080)
@@ -1,3 +1,57 @@
+2020-07-15  Carlos Garcia Campos  <[email protected]>
+
+        [GTK4] Enable API tests
+        https://bugs.webkit.org/show_bug.cgi?id=214344
+
+        Reviewed by Adrian Perez de Castro.
+
+        Port API tests to GTK4. Context menu and option menu tests are still disabled for GTK4 because we plan to change
+        the API for GTK4 in those cases.
+
+        * TestWebKitAPI/Tests/WebKitGLib/TestDownloads.cpp:
+        (beforeAll):
+        * TestWebKitAPI/Tests/WebKitGLib/TestInputMethodContext.cpp:
+        (webkitInputMethodContextMockFilterKeyEvent):
+        * TestWebKitAPI/Tests/WebKitGLib/TestMultiprocess.cpp:
+        * TestWebKitAPI/Tests/WebKitGLib/TestOptionMenu.cpp:
+        (beforeAll):
+        * TestWebKitAPI/Tests/WebKitGLib/TestUIClient.cpp:
+        (checkMimeTypeForFilter):
+        * TestWebKitAPI/Tests/WebKitGLib/TestWebExtensions.cpp:
+        (testWebExtensionInputElementIsUserEdited):
+        * TestWebKitAPI/Tests/WebKitGLib/TestWebKitSettings.cpp:
+        (testWebKitSettings):
+        * TestWebKitAPI/Tests/WebKitGLib/TestWebKitWebView.cpp:
+        * TestWebKitAPI/Tests/WebKitGtk/AccessibilityTestServer.cpp:
+        * TestWebKitAPI/Tests/WebKitGtk/InspectorTestServer.cpp:
+        (main):
+        * TestWebKitAPI/Tests/WebKitGtk/TestContextMenu.cpp:
+        (testContextMenuPopulateMenu):
+        (beforeAll):
+        * TestWebKitAPI/Tests/WebKitGtk/TestInspector.cpp:
+        * TestWebKitAPI/Tests/WebKitGtk/TestPrinting.cpp:
+        * TestWebKitAPI/Tests/WebKitGtk/TestWebViewEditor.cpp:
+        (Clipboard::Clipboard):
+        (Clipboard::clear):
+        (Clipboard::containsText const):
+        (Clipboard::waitForText):
+        (Clipboard::readText):
+        (testWebViewEditorCutCopyPasteNonEditable):
+        (testWebViewEditorCutCopyPasteEditable):
+        (testWebViewEditorSelectAllNonEditable):
+        (testWebViewEditorSelectAllEditable):
+        (loadContentsAndTryToCutSelection):
+        * TestWebKitAPI/glib/WebKitGLib/TestMain.h:
+        (Test::Test):
+        * TestWebKitAPI/glib/WebKitGLib/gtk/WebViewTestGtk.cpp:
+        (WebViewTest::platformDestroy):
+        (WebViewTest::showInWindow):
+        * TestWebKitAPI/gtk/PlatformUtilitiesGtk.cpp:
+        (TestWebKitAPI::Util::isKeyDown):
+        * TestWebKitAPI/gtk/PlatformWebViewGtk.cpp:
+        (TestWebKitAPI::PlatformWebView::~PlatformWebView):
+        (TestWebKitAPI::PlatformWebView::initialize):
+
 2020-07-30  Brady Eidson  <[email protected]>
 
         Refactor HID gamepad code to be much less fragile and much easier to hack on.

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitGLib/TestDownloads.cpp (265079 => 265080)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitGLib/TestDownloads.cpp	2020-07-30 07:21:44 UTC (rev 265079)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitGLib/TestDownloads.cpp	2020-07-30 08:53:28 UTC (rev 265080)
@@ -807,7 +807,10 @@
     DownloadTest::add("Downloads", "mime-type", testDownloadMIMEType);
     // FIXME: Implement keyStroke in WPE.
 #if PLATFORM(GTK)
+#if !USE(GTK4)
+    // FIXME: Rework context menu API in GTK4 to not expose GdkEvent.
     WebViewDownloadTest::add("Downloads", "contex-menu-download-actions", testContextMenuDownloadActions);
+#endif
     // FIXME: Implement mouse click in WPE.
     WebViewDownloadTest::add("Downloads", "blob-download", testBlobDownload);
 #endif

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitGLib/TestInputMethodContext.cpp (265079 => 265080)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitGLib/TestInputMethodContext.cpp	2020-07-30 07:21:44 UTC (rev 265079)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitGLib/TestInputMethodContext.cpp	2020-07-30 08:53:28 UTC (rev 265080)
@@ -24,7 +24,13 @@
 #include <wtf/glib/GUniquePtr.h>
 
 #if PLATFORM(GTK)
+#include <WebCore/GtkVersioning.h>
+#if USE(GTK4)
+#include "WebKitWebViewBaseInternal.h"
+using PlatformEventKey = GdkEvent;
+#else
 using PlatformEventKey = GdkEventKey;
+#endif
 #define KEY(x) GDK_KEY_##x
 #define CONTROL_MASK GDK_CONTROL_MASK
 #define SHIFT_MASK GDK_SHIFT_MASK
@@ -92,11 +98,18 @@
         return FALSE;
 
 #if PLATFORM(GTK)
+#if USE(GTK4)
+    auto* event = reinterpret_cast<KeyEvent*>(keyEvent);
+    unsigned keyval = event->keyval;
+    auto state = static_cast<GdkModifierType>(event->modifiers);
+    bool isKeyPress = event->type == GDK_KEY_PRESS;
+#else
     GdkModifierType state;
     guint keyval;
     if (!gdk_event_get_state(reinterpret_cast<GdkEvent*>(keyEvent), &state) || !gdk_event_get_keyval(reinterpret_cast<GdkEvent*>(keyEvent), &keyval))
         return FALSE;
     bool isKeyPress = gdk_event_get_event_type(reinterpret_cast<GdkEvent*>(keyEvent)) == GDK_KEY_PRESS;
+#endif
     gunichar character = gdk_keyval_to_unicode(keyval);
 #elif PLATFORM(WPE)
     uint32_t state = keyEvent->modifiers;

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitGLib/TestMultiprocess.cpp (265079 => 265080)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitGLib/TestMultiprocess.cpp	2020-07-30 07:21:44 UTC (rev 265079)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitGLib/TestMultiprocess.cpp	2020-07-30 08:53:28 UTC (rev 265080)
@@ -99,7 +99,11 @@
         auto* connection = s_dbusConnectionPageMap.get(webkit_web_view_get_page_id(m_webViews[index].get()));
         g_assert_nonnull(connection);
         g_signal_connect_swapped(connection, "closed", G_CALLBACK(g_main_loop_quit), m_mainLoop);
+#if USE(GTK4)
+        g_object_run_dispose(G_OBJECT(m_webViews[index].get()));
+#else
         gtk_widget_destroy(GTK_WIDGET(m_webViews[index].get()));
+#endif
         g_main_loop_run(m_mainLoop);
     }
 #endif

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitGLib/TestOptionMenu.cpp (265079 => 265080)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitGLib/TestOptionMenu.cpp	2020-07-30 07:21:44 UTC (rev 265079)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitGLib/TestOptionMenu.cpp	2020-07-30 08:53:28 UTC (rev 265080)
@@ -304,10 +304,13 @@
 
 void beforeAll()
 {
+#if !PLATFORM(GTK) || !USE(GTK4)
+    // FIXME: Rework option menu API in GTK4 to not expose GdkEvent.
     OptionMenuTest::add("WebKitWebView", "option-menu-simple", testOptionMenuSimple);
     OptionMenuTest::add("WebKitWebView", "option-menu-groups", testOptionMenuGroups);
     OptionMenuTest::add("WebKitWebView", "option-menu-activate", testOptionMenuActivate);
     OptionMenuTest::add("WebKitWebView", "option-menu-select", testOptionMenuSelect);
+#endif
 }
 
 void afterAll()

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitGLib/TestUIClient.cpp (265079 => 265080)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitGLib/TestUIClient.cpp	2020-07-30 07:21:44 UTC (rev 265079)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitGLib/TestUIClient.cpp	2020-07-30 08:53:28 UTC (rev 265080)
@@ -317,8 +317,8 @@
     void setCreateNewWebViewsInWindowsWithDefaultSize(int width = 800, int height = 600)
     {
         m_shouldCreateWebViewsInNewWindowsAutomatically = true;
-        m_DefaultGeometryNewWindows.width = width;
-        m_DefaultGeometryNewWindows.height = height;
+        m_defaultGeometryNewWindows.width = width;
+        m_defaultGeometryNewWindows.height = height;
     }
 #endif
 
@@ -338,8 +338,8 @@
 #if PLATFORM(GTK)
         keyStroke(GDK_KEY_a);
         keyStroke(GDK_KEY_b);
-        while (gtk_events_pending())
-            gtk_main_iteration();
+        while (g_main_context_pending(nullptr))
+            g_main_context_iteration(nullptr, TRUE);
 #endif
     }
 
@@ -367,10 +367,15 @@
 #if PLATFORM(GTK)
         if (m_shouldCreateWebViewsInNewWindowsAutomatically) {
             g_assert_null(m_parentWindow);
+#if USE(GTK4)
+            m_parentWindow = gtk_window_new();
+            gtk_window_set_child(GTK_WINDOW(m_parentWindow), GTK_WIDGET(newWebView));
+#else
             m_parentWindow = gtk_window_new(GTK_WINDOW_TOPLEVEL);
-            gtk_window_set_default_size(GTK_WINDOW(m_parentWindow), m_DefaultGeometryNewWindows.width, m_DefaultGeometryNewWindows.height);
             gtk_container_add(GTK_CONTAINER(m_parentWindow), GTK_WIDGET(newWebView));
             gtk_widget_show(GTK_WIDGET(newWebView));
+#endif
+            gtk_window_set_default_size(GTK_WINDOW(m_parentWindow), m_defaultGeometryNewWindows.width, m_defaultGeometryNewWindows.height);
             gtk_widget_show(m_parentWindow);
         }
 #endif
@@ -416,7 +421,7 @@
 
 #if PLATFORM(GTK)
     bool m_shouldCreateWebViewsInNewWindowsAutomatically { false };
-    cairo_rectangle_int_t m_DefaultGeometryNewWindows;
+    cairo_rectangle_int_t m_defaultGeometryNewWindows;
 #endif
 };
 
@@ -521,10 +526,16 @@
 #if PLATFORM(GTK)
 static gboolean checkMimeTypeForFilter(GtkFileFilter* filter, const gchar* mimeType)
 {
+#if USE(GTK4)
+    GRefPtr<GFileInfo> filterInfo = adoptGRef(g_file_info_new());
+    g_file_info_set_content_type(filterInfo.get(), mimeType);
+    return gtk_filter_match(GTK_FILTER(filter), filterInfo.get());
+#else
     GtkFileFilterInfo filterInfo;
     filterInfo.contains = GTK_FILE_FILTER_MIME_TYPE;
     filterInfo.mime_type = mimeType;
     return gtk_file_filter_filter(filter, &filterInfo);
+#endif
 }
 #endif
 

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitGLib/TestWebExtensions.cpp (265079 => 265080)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitGLib/TestWebExtensions.cpp	2020-07-30 07:21:44 UTC (rev 265079)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitGLib/TestWebExtensions.cpp	2020-07-30 08:53:28 UTC (rev 265080)
@@ -83,8 +83,8 @@
     g_assert_false(inputElementIsUserEdited(proxy.get(), pageID, "input"));
     test->runJavaScriptAndWaitUntilFinished("document.getElementById('input').focus()", nullptr);
     test->keyStroke(GDK_KEY_a);
-    while (gtk_events_pending())
-        gtk_main_iteration();
+    while (g_main_context_pending(nullptr))
+        g_main_context_iteration(nullptr, TRUE);
     GUniquePtr<char> resultString;
     do {
         auto* result = test->runJavaScriptAndWaitUntilFinished("document.getElementById('input').value", nullptr);
@@ -95,8 +95,8 @@
     g_assert_false(inputElementIsUserEdited(proxy.get(), pageID, "textarea"));
     test->runJavaScriptAndWaitUntilFinished("document.getElementById('textarea').focus()", nullptr);
     test->keyStroke(GDK_KEY_b);
-    while (gtk_events_pending())
-        gtk_main_iteration();
+    while (g_main_context_pending(nullptr))
+        g_main_context_iteration(nullptr, TRUE);
     do {
         auto* result = test->runJavaScriptAndWaitUntilFinished("document.getElementById('textarea').value", nullptr);
         resultString.reset(WebViewTest::_javascript_ResultToCString(result));

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitGLib/TestWebKitSettings.cpp (265079 => 265080)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitGLib/TestWebKitSettings.cpp	2020-07-30 07:21:44 UTC (rev 265079)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitGLib/TestWebKitSettings.cpp	2020-07-30 08:53:28 UTC (rev 265080)
@@ -349,6 +349,7 @@
     g_assert_cmpstr(nullptr, ==, webkit_settings_get_media_content_types_requiring_hardware_support(settings));
 
 #if PLATFORM(GTK)
+#if !USE(GTK4)
     // Ondemand is the default hardware acceleration policy.
     g_assert_cmpuint(webkit_settings_get_hardware_acceleration_policy(settings), ==, WEBKIT_HARDWARE_ACCELERATION_POLICY_ON_DEMAND);
     webkit_settings_set_hardware_acceleration_policy(settings, WEBKIT_HARDWARE_ACCELERATION_POLICY_NEVER);
@@ -357,6 +358,7 @@
     g_assert_cmpuint(webkit_settings_get_hardware_acceleration_policy(settings), ==, WEBKIT_HARDWARE_ACCELERATION_POLICY_ALWAYS);
     webkit_settings_set_hardware_acceleration_policy(settings, WEBKIT_HARDWARE_ACCELERATION_POLICY_ON_DEMAND);
     g_assert_cmpuint(webkit_settings_get_hardware_acceleration_policy(settings), ==, WEBKIT_HARDWARE_ACCELERATION_POLICY_ON_DEMAND);
+#endif
 
     // Back-forward navigation gesture is disabled by default
     g_assert_false(webkit_settings_get_enable_back_forward_navigation_gestures(settings));

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitGLib/TestWebKitWebView.cpp (265079 => 265080)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitGLib/TestWebKitWebView.cpp	2020-07-30 07:21:44 UTC (rev 265079)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitGLib/TestWebKitWebView.cpp	2020-07-30 08:53:28 UTC (rev 265080)
@@ -444,9 +444,10 @@
 
     static gboolean leaveFullScreenIdle(FullScreenClientTest* test)
     {
-        // FIXME: Implement key strokes in WPE
 #if PLATFORM(GTK)
         test->keyStroke(GDK_KEY_Escape);
+#else
+        test->keyStroke(WPE_KEY_Escape);
 #endif
         return FALSE;
     }

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitGtk/AccessibilityTestServer.cpp (265079 => 265080)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitGtk/AccessibilityTestServer.cpp	2020-07-30 07:21:44 UTC (rev 265079)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitGtk/AccessibilityTestServer.cpp	2020-07-30 08:53:28 UTC (rev 265080)
@@ -21,6 +21,7 @@
 
 #include <WebCore/GtkVersioning.h>
 #include <webkit2/webkit2.h>
+#include <wtf/glib/GRefPtr.h>
 
 static const char introspectionXML[] =
     "<node>"
@@ -70,11 +71,16 @@
     gtk_init(&argc, &argv);
 
     GtkWidget* webView = webkit_web_view_new();
-
+#if USE(GTK4)
+    GtkWidget* window = gtk_window_new();
+    gtk_window_set_child(GTK_WINDOW(window), GTK_WIDGET(webView));
+#else
     GtkWidget* window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
     g_signal_connect(window, "delete-event", G_CALLBACK(gtk_main_quit), nullptr);
     gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(webView));
-    gtk_widget_show_all(window);
+    gtk_widget_show(GTK_WIDGET(webView));
+#endif
+    gtk_widget_show(window);
 
     g_dbus_connection_new_for_address(argv[1], G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT, nullptr, nullptr,
         [](GObject*, GAsyncResult* result, gpointer userData) {
@@ -88,5 +94,10 @@
                 &interfaceVirtualTable, userData, nullptr, nullptr);
         }, webView);
 
+#if USE(GTK4)
+    GRefPtr<GMainLoop> loop = adoptGRef(g_main_loop_new(nullptr, TRUE));
+    g_main_loop_run(loop.get());
+#else
     gtk_main();
+#endif
 }

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitGtk/InspectorTestServer.cpp (265079 => 265080)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitGtk/InspectorTestServer.cpp	2020-07-30 07:21:44 UTC (rev 265079)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitGtk/InspectorTestServer.cpp	2020-07-30 08:53:28 UTC (rev 265080)
@@ -26,6 +26,7 @@
 
 #include <WebCore/GtkVersioning.h>
 #include <webkit2/webkit2.h>
+#include <wtf/glib/GRefPtr.h>
 
 int main(int argc, char** argv)
 {
@@ -40,6 +41,14 @@
         "<html><body><p>WebKitGTK Inspector Test Server</p></body></html>",
         "http://127.0.0.1:2999/");
 
+#if USE(GTK4)
+    GtkWidget* window = gtk_window_new();
+    gtk_window_set_child(GTK_WINDOW(window), GTK_WIDGET(webView));
+    gtk_widget_show(window);
+
+    GRefPtr<GMainLoop> loop = adoptGRef(g_main_loop_new(nullptr, TRUE));
+    g_main_loop_run(loop.get());
+#else
     GtkWidget* window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
     gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(webView));
     gtk_widget_show_all(window);
@@ -47,4 +56,5 @@
     g_signal_connect(window, "delete-event", G_CALLBACK(gtk_main_quit), 0);
 
     gtk_main();
+#endif
 }

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitGtk/TestContextMenu.cpp (265079 => 265080)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitGtk/TestContextMenu.cpp	2020-07-30 07:21:44 UTC (rev 265079)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitGtk/TestContextMenu.cpp	2020-07-30 08:53:28 UTC (rev 265080)
@@ -26,30 +26,6 @@
 
 static WebKitTestServer* kServer;
 
-#if USE(GTK4)
-struct LookupWidgetsData {
-    void (*walkChildren)(GtkContainer*, GtkCallback, void*);
-    Function<bool(GtkWidget*)> predicate;
-    Vector<GtkWidget*> result;
-};
-
-static void lookupWidgetsWalkChild(GtkWidget* child, void* userdata)
-{
-    auto& data = ""
-    if (data.predicate(child))
-        data.result.append(child);
-    else if (GTK_IS_CONTAINER(child))
-        data.walkChildren(GTK_CONTAINER(child), lookupWidgetsWalkChild, userdata);
-}
-
-static Vector<GtkWidget*> lookupWidgets(GtkWidget* widget, Function<bool(GtkWidget*)>&& predicate, bool internal = false)
-{
-    LookupWidgetsData data = "" ? gtk_container_forall : gtk_container_foreach, WTFMove(predicate)};
-    lookupWidgetsWalkChild(widget, &data);
-    return WTFMove(data.result);
-}
-#endif // USE(GTK4)
-
 class ContextMenuTest: public WebViewTest {
 public:
     enum ContextMenuItemStateFlags {
@@ -61,6 +37,7 @@
     void checkContextMenuEvent(GdkEvent* event)
     {
         g_assert_nonnull(event);
+#if !USE(GTK4)
         g_assert_cmpint(event->type, ==, m_expectedEventType);
 
         switch (m_expectedEventType) {
@@ -79,6 +56,7 @@
         default:
             g_assert_not_reached();
         }
+#endif
     }
 
     static gboolean contextMenuCallback(WebKitWebView* webView, WebKitContextMenu* contextMenu, GdkEvent* event, WebKitHitTestResult* hitTestResult, ContextMenuTest* test)
@@ -126,18 +104,7 @@
                 continue;
 
 #if USE(GTK4)
-            // Popovers are internal to the GtkContainer where the webview resides,
-            // gtk_container_forall() is the only way to enumerate internal children.
-            GtkPopover *popover = nullptr;
-            gtk_container_forall(GTK_CONTAINER(iter->data),
-                [](GtkWidget* child, void* data) {
-                    auto** popover = reinterpret_cast<GtkPopover**>(data);
-                    if (GTK_IS_POPOVER_MENU(child) && !*popover)
-                        *popover = GTK_POPOVER(child);
-                }, &popover);
-
-            if (popover && gtk_popover_get_relative_to(popover) == GTK_WIDGET(m_webView))
-                return popover;
+            return nullptr;
 #else
             GtkWidget* child = gtk_bin_get_child(GTK_BIN(iter->data));
             if (!GTK_IS_MENU(child))
@@ -176,10 +143,12 @@
         WebKitContextMenuItem* item = WEBKIT_CONTEXT_MENU_ITEM(items->data);
         assertObjectIsDeletedWhenTestFinishes(G_OBJECT(item));
 
+#if !USE(GTK4)
         G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
         GtkAction* action = ""
         g_assert_true(GTK_IS_ACTION(action));
         G_GNUC_END_IGNORE_DEPRECATIONS;
+#endif
 
         GAction* gAction = webkit_context_menu_item_get_gaction(item);
         g_assert_true(G_IS_ACTION(gAction));
@@ -199,12 +168,15 @@
         WebKitContextMenuItem* item = WEBKIT_CONTEXT_MENU_ITEM(items->data);
         assertObjectIsDeletedWhenTestFinishes(G_OBJECT(item));
 
+#if !USE(GTK4)
         G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
         GtkAction* action = ""
         g_assert_true(GTK_IS_ACTION(action));
+#endif
 
         GAction* gAction = webkit_context_menu_item_get_gaction(item);
         g_assert_true(G_IS_ACTION(gAction));
+#if !USE(GTK4)
         g_assert_cmpstr(gtk_action_get_name(action), ==, g_action_get_name(gAction));
         g_assert_cmpint(gtk_action_get_sensitive(action), ==, g_action_get_enabled(gAction));
         if (GTK_IS_TOGGLE_ACTION(action)) {
@@ -217,6 +189,7 @@
         g_assert_cmpint(webkit_context_menu_item_get_stock_action(item), ==, WEBKIT_CONTEXT_MENU_ACTION_CUSTOM);
         g_assert_cmpstr(gtk_action_get_label(action), ==, label);
         G_GNUC_END_IGNORE_DEPRECATIONS;
+#endif
 
         checkActionState(gAction, state);
 
@@ -231,11 +204,13 @@
         WebKitContextMenuItem* item = WEBKIT_CONTEXT_MENU_ITEM(items->data);
         assertObjectIsDeletedWhenTestFinishes(G_OBJECT(item));
 
+#if !USE(GTK4)
         G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
         GtkAction* action = ""
         g_assert_true(GTK_IS_ACTION(action));
         g_assert_cmpstr(gtk_action_get_label(action), ==, label);
         G_GNUC_END_IGNORE_DEPRECATIONS;
+#endif
 
         GAction* gAction = webkit_context_menu_item_get_gaction(item);
         g_assert_true(G_IS_ACTION(gAction));
@@ -301,7 +276,9 @@
 
     void showContextMenuTriggeredByPopupEventAndWaitUntilFinished()
     {
+#if !USE(GTK4)
         m_expectedEventType = GDK_NOTHING;
+#endif
         g_idle_add(reinterpret_cast<GSourceFunc>(emitPopupMenuSignalIdleCallback), this);
         g_main_loop_run(m_mainLoop);
     }
@@ -600,6 +577,7 @@
     bool contextMenu(WebKitContextMenu* contextMenu, GdkEvent*, WebKitHitTestResult* hitTestResult)
     {
         // Append our custom item to the default menu.
+#if !USE(GTK4)
         G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
         if (m_action)
             webkit_context_menu_append(contextMenu, webkit_context_menu_item_new(m_action.get()));
@@ -606,6 +584,7 @@
         else if (m_gAction)
             webkit_context_menu_append(contextMenu, webkit_context_menu_item_new_from_gaction(m_gAction.get(), m_gActionTitle.data(), m_expectedTarget.get()));
         G_GNUC_END_IGNORE_DEPRECATIONS;
+#endif
         quitMainLoop();
 
         return false;
@@ -614,22 +593,7 @@
 #if USE(GTK4)
     GtkButton* getMenuItem(GtkWidget* popover, const gchar* itemLabel)
     {
-        auto items = lookupWidgets(popover,
-            [itemLabel](GtkWidget* widget) {
-                if (!GTK_IS_BUTTON(widget))
-                    return false;
-                const char* label = gtk_button_get_label(GTK_BUTTON(widget));
-                if (!label) {
-                    const auto labels = lookupWidgets(GTK_WIDGET(widget),
-                        [](GtkWidget* child) { return GTK_IS_LABEL(child); });
-                    g_assert_cmpuint(1, ==, labels.size());
-                    label = gtk_label_get_label(GTK_LABEL(labels[0]));
-                }
-                return GTK_IS_BUTTON(widget) && g_strcmp0(label, itemLabel) == 0;
-            }, true);
-
-        g_assert_cmpuint(items.size(), >, 0);
-        return items.size() ? GTK_BUTTON(items[0]) : nullptr;
+        return nullptr;
     }
 #else
     GtkMenuItem* getMenuItem(GtkWidget* menu, const gchar* itemLabel)
@@ -651,8 +615,7 @@
         auto* menu = getContextMenuWidget();
         auto* item = getMenuItem(menu, m_itemToActivateLabel);
 #if USE(GTK4)
-        // GTK4 uses a popover, which contains buttons.
-        gtk_button_clicked(item);
+
 #else
         // GTK3 uses a menu, which contains menu items.
         gtk_menu_shell_activate_item(GTK_MENU_SHELL(menu), GTK_WIDGET(item), TRUE);
@@ -700,12 +663,6 @@
     static void actionToggledCallback(ContextMenuCustomTest* test)
     {
         test->m_toggled = true;
-
-#if USE(GTK4)
-        // For toggle actions the popover menu is NOT dismissed automatically, as to show visual feedback to the user
-        // (i.e. the check marker). Dismiss it here to trigger contextMenuDismissedCallback() and continue the test.
-        gtk_popover_popdown(test->getPopoverMenu());
-#endif // USE(GTK4)
     }
 
     void setAction(GtkAction* action)
@@ -713,6 +670,7 @@
         m_action = action;
         m_gAction = nullptr;
         m_expectedTarget = nullptr;
+#if !USE(GTK4)
         G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
         if (GTK_IS_TOGGLE_ACTION(action))
             g_signal_connect_swapped(action, "toggled", G_CALLBACK(actionToggledCallback), this);
@@ -719,6 +677,7 @@
         else
             g_signal_connect_swapped(action, "activate", G_CALLBACK(actionActivatedCallback), this);
         G_GNUC_END_IGNORE_DEPRECATIONS;
+#endif
     }
 
     void setAction(GAction* action, const char* title, GVariant* target = nullptr)
@@ -747,6 +706,7 @@
     test->loadHtml("<html><body>WebKitGTK Context menu tests</body></html>", "file:///");
     test->waitUntilLoadFinished();
 
+#if !USE(GTK4)
     G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
     // Create a custom menu item.
     GRefPtr<GtkAction> action = "" "Custom _Action", nullptr, nullptr));
@@ -764,6 +724,7 @@
     g_assert_false(test->m_activated);
     g_assert_true(test->m_toggled);
     G_GNUC_END_IGNORE_DEPRECATIONS;
+#endif
 
     // Create a custom menu item using GAction.
     GRefPtr<GAction> gAction = adoptGRef(G_ACTION(g_simple_action_new("WebKitGTKCustomGAction", nullptr)));
@@ -805,6 +766,7 @@
         webkit_context_menu_insert(contextMenu, webkit_context_menu_item_new_separator(), 2);
 
         // Add custom actions.
+#if !USE(GTK4)
         G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
         GRefPtr<GtkAction> action = "" "Custom _Action", nullptr, nullptr));
         gtk_action_set_sensitive(action.get(), FALSE);
@@ -813,6 +775,7 @@
         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(toggleAction.get()), TRUE);
         webkit_context_menu_append(contextMenu, webkit_context_menu_item_new(toggleAction.get()));
         webkit_context_menu_append(contextMenu, webkit_context_menu_item_new_separator());
+#endif
         GRefPtr<GAction> gAction = adoptGRef(G_ACTION(g_simple_action_new("WebKitGTKCustomGAction", nullptr)));
         g_simple_action_set_enabled(G_SIMPLE_ACTION(gAction.get()), FALSE);
         webkit_context_menu_insert(contextMenu, webkit_context_menu_item_new_from_gaction(gAction.get(), "Custom _GAction", nullptr), -1);
@@ -1175,6 +1138,8 @@
     kServer = new WebKitTestServer();
     kServer->run(serverCallback);
 
+#if !USE(GTK4)
+    // FIXME: Rework context menu API in GTK4 to not expose GdkEvent.
     ContextMenuDefaultTest::add("WebKitWebView", "default-menu", testContextMenuDefaultMenu);
     ContextMenuDefaultTest::add("WebKitWebView", "context-menu-key", testContextMenuKey);
     ContextMenuDefaultTest::add("WebKitWebView", "popup-event-signal", testPopupEventSignal);
@@ -1185,6 +1150,7 @@
     ContextMenuDismissedTest::add("WebKitWebView", "menu-dismissed", testContextMenuDismissed);
     ContextMenuWebExtensionTest::add("WebKitWebPage", "context-menu", testContextMenuWebExtensionMenu);
     ContextMenuWebExtensionNodeTest::add("WebKitWebPage", "context-menu-node", testContextMenuWebExtensionNode);
+#endif
 }
 
 void afterAll()

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitGtk/TestInspector.cpp (265079 => 265080)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitGtk/TestInspector.cpp	2020-07-30 07:21:44 UTC (rev 265079)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitGtk/TestInspector.cpp	2020-07-30 08:53:28 UTC (rev 265080)
@@ -226,18 +226,29 @@
 
     ~CustomInspectorTest()
     {
+#if USE(GTK4)
         if (m_inspectorWindow)
+            gtk_window_destroy(GTK_WINDOW(m_inspectorWindow));
+#else
+        if (m_inspectorWindow)
             gtk_widget_destroy(m_inspectorWindow);
+#endif
     }
 
     bool openWindow()
     {
         g_assert_null(m_inspectorWindow);
-        m_inspectorWindow = gtk_window_new(GTK_WINDOW_TOPLEVEL);
         WebKitWebViewBase* inspectorView = webkit_web_inspector_get_web_view(m_inspector);
         g_assert_nonnull(inspectorView);
+#if USE(GTK4)
+        m_inspectorWindow = gtk_window_new();
+        gtk_window_set_child(GTK_WINDOW(m_inspectorWindow), GTK_WIDGET(inspectorView));
+#else
+        m_inspectorWindow = gtk_window_new(GTK_WINDOW_TOPLEVEL);
         gtk_container_add(GTK_CONTAINER(m_inspectorWindow), GTK_WIDGET(inspectorView));
-        gtk_widget_show_all(m_inspectorWindow);
+        gtk_widget_show(GTK_WIDGET(inspectorView));
+#endif
+        gtk_widget_show(m_inspectorWindow);
 
         return InspectorTest::openWindow();
     }
@@ -244,10 +255,11 @@
 
     void closed()
     {
-        if (m_inspectorWindow) {
-            gtk_widget_destroy(m_inspectorWindow);
-            m_inspectorWindow = 0;
-        }
+#if USE(GTK4)
+        g_clear_pointer(&m_inspectorWindow, gtk_window_destroy);
+#else
+        g_clear_pointer(&m_inspectorWindow, gtk_widget_destroy);
+#endif
 
         return InspectorTest::closed();
     }
@@ -256,12 +268,29 @@
     {
         GRefPtr<WebKitWebViewBase> inspectorView = webkit_web_inspector_get_web_view(m_inspector);
         if (m_inspectorWindow) {
+#if USE(GTK4)
+            gtk_window_set_child(GTK_WINDOW(m_inspectorWindow), nullptr);
+            gtk_window_destroy(GTK_WINDOW(m_inspectorWindow));
+#else
             gtk_container_remove(GTK_CONTAINER(m_inspectorWindow), GTK_WIDGET(inspectorView.get()));
             gtk_widget_destroy(m_inspectorWindow);
-            m_inspectorWindow = 0;
+#endif
+            m_inspectorWindow = nullptr;
         }
 
         GtkWidget* pane;
+#if USE(GTK4)
+        if (gtk_window_get_child(GTK_WINDOW(m_parentWindow)) == GTK_WIDGET(m_webView)) {
+            GRefPtr<WebKitWebView> inspectedView = m_webView;
+            gtk_window_set_child(GTK_WINDOW(m_parentWindow), nullptr);
+            pane = gtk_paned_new(GTK_ORIENTATION_VERTICAL);
+            gtk_paned_set_start_child(GTK_PANED(pane), GTK_WIDGET(m_webView));
+            gtk_window_set_child(GTK_WINDOW(m_parentWindow), pane);
+        } else
+            pane = gtk_window_get_child(GTK_WINDOW(m_parentWindow));
+        gtk_paned_set_position(GTK_PANED(pane), webkit_web_inspector_get_attached_height(m_inspector));
+        gtk_paned_set_end_child(GTK_PANED(pane), GTK_WIDGET(inspectorView.get()));
+#else
         if (gtk_bin_get_child(GTK_BIN(m_parentWindow)) == GTK_WIDGET(m_webView)) {
             GRefPtr<WebKitWebView> inspectedView = m_webView;
             gtk_container_remove(GTK_CONTAINER(m_parentWindow), GTK_WIDGET(m_webView));
@@ -273,6 +302,7 @@
             pane = gtk_bin_get_child(GTK_BIN(m_parentWindow));
         gtk_paned_set_position(GTK_PANED(pane), webkit_web_inspector_get_attached_height(m_inspector));
         gtk_paned_add2(GTK_PANED(pane), GTK_WIDGET(inspectorView.get()));
+#endif
 
         return InspectorTest::attach();
     }
@@ -280,9 +310,15 @@
     bool detach()
     {
         GRefPtr<WebKitWebViewBase> inspectorView = webkit_web_inspector_get_web_view(m_inspector);
+#if USE(GTK4)
+        GtkWidget* pane = gtk_window_get_child(GTK_WINDOW(m_parentWindow));
+        g_assert_true(GTK_IS_PANED(pane));
+        gtk_paned_set_end_child(GTK_PANED(pane), nullptr);
+#else
         GtkWidget* pane = gtk_bin_get_child(GTK_BIN(m_parentWindow));
         g_assert_true(GTK_IS_PANED(pane));
         gtk_container_remove(GTK_CONTAINER(pane), GTK_WIDGET(inspectorView.get()));
+#endif
         return InspectorTest::detach();
     }
 
@@ -289,8 +325,11 @@
     void destroyWindow()
     {
         g_assert_nonnull(m_inspectorWindow);
-        gtk_widget_destroy(m_inspectorWindow);
-        m_inspectorWindow = 0;
+#if USE(GTK4)
+        g_clear_pointer(&m_inspectorWindow, gtk_window_destroy);
+#else
+        g_clear_pointer(&m_inspectorWindow, gtk_widget_destroy);
+#endif
     }
 
     GtkWidget* m_inspectorWindow;

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitGtk/TestPrinting.cpp (265079 => 265080)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitGtk/TestPrinting.cpp	2020-07-30 07:21:44 UTC (rev 265079)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitGtk/TestPrinting.cpp	2020-07-30 08:53:28 UTC (rev 265080)
@@ -19,6 +19,7 @@
 
 #include "config.h"
 #include "WebViewTest.h"
+#include <WebCore/GtkVersioning.h>
 #include <glib/gstdio.h>
 #include <wtf/glib/GRefPtr.h>
 

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitGtk/TestWebViewEditor.cpp (265079 => 265080)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitGtk/TestWebViewEditor.cpp	2020-07-30 07:21:44 UTC (rev 265079)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitGtk/TestWebViewEditor.cpp	2020-07-30 08:53:28 UTC (rev 265080)
@@ -21,25 +21,104 @@
 #include "WebViewTest.h"
 #include <wtf/glib/GRefPtr.h>
 
+class Clipboard {
+public:
+    Clipboard(GMainLoop* loop)
+        : m_mainLoop(loop)
+#if USE(GTK4)
+        , m_clipboard(gdk_display_get_clipboard(gdk_display_get_default()))
+#else
+        , m_clipboard(gtk_clipboard_get_for_display(gdk_display_get_default(), GDK_SELECTION_CLIPBOARD))
+#endif
+    {
+    }
+
+    void clear()
+    {
+#if USE(GTK4)
+        g_assert_true(gdk_clipboard_set_content(m_clipboard, nullptr));
+#else
+        gtk_clipboard_clear(m_clipboard);
+#endif
+        m_text = nullptr;
+    }
+
+    bool containsText() const
+    {
+#if USE(GTK4)
+        return gdk_content_formats_contain_gtype(gdk_clipboard_get_formats(m_clipboard), G_TYPE_STRING);
+#else
+        return gtk_clipboard_wait_is_text_available(m_clipboard);
+#endif
+    }
+
+    bool waitForText()
+    {
+        // There's no way to know when the selection has been written to
+        // the clipboard, so use a timeout source to query the clipboard.
+        static const unsigned kClipboardWaitTimeout = 50;
+        static const unsigned kClipboardWaitMaxTries = 2;
+        m_triesCount = 0;
+        g_timeout_add(kClipboardWaitTimeout, [](gpointer userData) -> gboolean {
+            auto* clipboard = static_cast<Clipboard*>(userData);
+            clipboard->m_triesCount++;
+            if (clipboard->containsText() || clipboard->m_triesCount > kClipboardWaitMaxTries) {
+                g_main_loop_quit(clipboard->m_mainLoop);
+                return FALSE;
+            }
+            return TRUE;
+        }, this);
+        g_main_loop_run(m_mainLoop);
+        return containsText();
+    }
+
+    const char* readText()
+    {
+        m_text = nullptr;
+        if (waitForText()) {
+#if USE(GTK4)
+            gdk_clipboard_read_text_async(m_clipboard, nullptr, [](GObject* gdkClipboard, GAsyncResult* result, gpointer userData) {
+                auto* clipboard = static_cast<Clipboard*>(userData);
+                clipboard->m_text.reset(gdk_clipboard_read_text_finish(GDK_CLIPBOARD(gdkClipboard), result, nullptr));
+                g_main_loop_quit(clipboard->m_mainLoop);
+            }, this);
+            g_main_loop_run(m_mainLoop);
+#else
+            m_text.reset(gtk_clipboard_wait_for_text(m_clipboard));
+#endif
+        }
+        return m_text.get();
+    }
+
+private:
+    GMainLoop* m_mainLoop { nullptr };
+#if USE(GTK4)
+    GdkClipboard* m_clipboard { nullptr };
+#else
+    GtkClipboard* m_clipboard { nullptr };
+#endif
+    GUniquePtr<char> m_text;
+    unsigned m_triesCount { 0 };
+};
+
 class EditorTest: public WebViewTest {
 public:
     MAKE_GLIB_TEST_FIXTURE(EditorTest);
 
-    static const unsigned kClipboardWaitTimeout = 50;
-    static const unsigned kClipboardWaitMaxTries = 2;
-
     EditorTest()
-        : m_clipboard(gtk_clipboard_get(GDK_SELECTION_CLIPBOARD))
-        , m_canExecuteEditingCommand(false)
-        , m_triesCount(0)
-        , m_editorState(nullptr)
+        : m_clipboard(m_mainLoop)
     {
         showInWindow();
+        m_clipboard.clear();
         loadURI("about:blank");
         waitUntilLoadFinished();
-        gtk_clipboard_clear(m_clipboard);
     }
 
+    ~EditorTest()
+    {
+        m_clipboard.clear();
+    }
+
     static gboolean webViewDrawCallback(GMainLoop* mainLoop)
     {
         g_main_loop_quit(mainLoop);
@@ -48,10 +127,20 @@
 
     void flushEditorState()
     {
+#if USE(GTK4)
+        auto* surface = gtk_native_get_surface(gtk_widget_get_native(GTK_WIDGET(m_webView)));
+        auto* clock = gdk_surface_get_frame_clock(surface);
+        auto signalID = g_signal_connect_swapped(clock, "paint", G_CALLBACK(webViewDrawCallback), m_mainLoop);
+#else
         auto signalID = g_signal_connect_swapped(m_webView, "draw", G_CALLBACK(webViewDrawCallback), m_mainLoop);
+#endif
         gtk_widget_queue_draw(GTK_WIDGET(m_webView));
         g_main_loop_run(m_mainLoop);
+#if USE(GTK4)
+        g_signal_handler_disconnect(clock, signalID);
+#else
         g_signal_handler_disconnect(m_webView, signalID);
+#endif
     }
 
     static void canExecuteEditingCommandReadyCallback(GObject*, GAsyncResult* result, EditorTest* test)
@@ -84,28 +173,13 @@
         return m_canExecuteEditingCommand;
     }
 
-    static gboolean waitForClipboardText(EditorTest* test)
+    const char* copyClipboard()
     {
-        test->m_triesCount++;
-        if (gtk_clipboard_wait_is_text_available(test->m_clipboard) || test->m_triesCount > kClipboardWaitMaxTries) {
-            g_main_loop_quit(test->m_mainLoop);
-            return FALSE;
-        }
-
-        return TRUE;
-    }
-
-    void copyClipboard()
-    {
         webkit_web_view_execute_editing_command(m_webView, WEBKIT_EDITING_COMMAND_COPY);
-        // There's no way to know when the selection has been copied to
-        // the clipboard, so use a timeout source to query the clipboard.
-        m_triesCount = 0;
-        g_timeout_add(kClipboardWaitTimeout, reinterpret_cast<GSourceFunc>(waitForClipboardText), this);
-        g_main_loop_run(m_mainLoop);
+        return m_clipboard.readText();
     }
 
-    gchar* cutSelection()
+    const char* cutSelection()
     {
         g_assert_true(canExecuteEditingCommand(WEBKIT_EDITING_COMMAND_CUT));
         g_assert_true(canExecuteEditingCommand(WEBKIT_EDITING_COMMAND_PASTE));
@@ -112,13 +186,7 @@
         g_assert_true(canExecuteEditingCommand(WEBKIT_EDITING_COMMAND_PASTE_AS_PLAIN_TEXT));
 
         webkit_web_view_execute_editing_command(m_webView, WEBKIT_EDITING_COMMAND_CUT);
-        // There's no way to know when the selection has been cut to
-        // the clipboard, so use a timeout source to query the clipboard.
-        m_triesCount = 0;
-        g_timeout_add(kClipboardWaitTimeout, reinterpret_cast<GSourceFunc>(waitForClipboardText), this);
-        g_main_loop_run(m_mainLoop);
-
-        return gtk_clipboard_wait_for_text(m_clipboard);
+        return m_clipboard.readText();
     }
 
     WebKitEditorState* editorState()
@@ -149,10 +217,9 @@
         return typingAttributes();
     }
 
-    GtkClipboard* m_clipboard;
-    bool m_canExecuteEditingCommand;
-    size_t m_triesCount;
-    WebKitEditorState* m_editorState;
+    Clipboard m_clipboard;
+    bool m_canExecuteEditingCommand { false };
+    WebKitEditorState* m_editorState { nullptr };
 };
 
 static const char* selectedSpanHTMLFormat =
@@ -182,9 +249,7 @@
     g_assert_false(test->canExecuteEditingCommand(WEBKIT_EDITING_COMMAND_PASTE));
     g_assert_false(test->canExecuteEditingCommand(WEBKIT_EDITING_COMMAND_PASTE_AS_PLAIN_TEXT));
 
-    test->copyClipboard();
-    GUniquePtr<char> clipboardText(gtk_clipboard_wait_for_text(test->m_clipboard));
-    g_assert_cmpstr(clipboardText.get(), ==, "make Jack a dull");
+    g_assert_cmpstr(test->copyClipboard(), ==, "make Jack a dull");
 }
 
 static void testWebViewEditorCutCopyPasteEditable(EditorTest* test, gconstpointer)
@@ -210,9 +275,7 @@
     g_assert_true(test->canExecuteEditingCommand(WEBKIT_EDITING_COMMAND_PASTE));
     g_assert_true(test->canExecuteEditingCommand(WEBKIT_EDITING_COMMAND_PASTE_AS_PLAIN_TEXT));
 
-    test->copyClipboard();
-    GUniquePtr<char> clipboardText(gtk_clipboard_wait_for_text(test->m_clipboard));
-    g_assert_cmpstr(clipboardText.get(), ==, "make Jack a dull");
+    g_assert_cmpstr(test->copyClipboard(), ==, "make Jack a dull");
 }
 
 static void testWebViewEditorSelectAllNonEditable(EditorTest* test, gconstpointer)
@@ -226,18 +289,12 @@
 
     g_assert_true(test->canExecuteEditingCommand(WEBKIT_EDITING_COMMAND_SELECT_ALL));
 
-    test->copyClipboard();
-    GUniquePtr<char> clipboardText(gtk_clipboard_wait_for_text(test->m_clipboard));
-
     // Initially only the subspan is selected.
-    g_assert_cmpstr(clipboardText.get(), ==, "make Jack a dull");
+    g_assert_cmpstr(test->copyClipboard(), ==, "make Jack a dull");
 
     webkit_web_view_execute_editing_command(test->m_webView, WEBKIT_EDITING_COMMAND_SELECT_ALL);
-    test->copyClipboard();
-    clipboardText.reset(gtk_clipboard_wait_for_text(test->m_clipboard));
-
     // The mainspan should be selected after calling SELECT_ALL.
-    g_assert_cmpstr(clipboardText.get(), ==, "All work and no play make Jack a dull boy.");
+    g_assert_cmpstr(test->copyClipboard(), ==, "All work and no play make Jack a dull boy.");
 }
 
 static void testWebViewEditorSelectAllEditable(EditorTest* test, gconstpointer)
@@ -255,18 +312,12 @@
 
     g_assert_true(test->canExecuteEditingCommand(WEBKIT_EDITING_COMMAND_SELECT_ALL));
 
-    test->copyClipboard();
-    GUniquePtr<char> clipboardText(gtk_clipboard_wait_for_text(test->m_clipboard));
-
     // Initially only the subspan is selected.
-    g_assert_cmpstr(clipboardText.get(), ==, "make Jack a dull");
+    g_assert_cmpstr(test->copyClipboard(), ==, "make Jack a dull");
 
     webkit_web_view_execute_editing_command(test->m_webView, WEBKIT_EDITING_COMMAND_SELECT_ALL);
-    test->copyClipboard();
-    clipboardText.reset(gtk_clipboard_wait_for_text(test->m_clipboard));
-
     // The mainspan should be selected after calling SELECT_ALL.
-    g_assert_cmpstr(clipboardText.get(), ==, "All work and no play make Jack a dull boy.");
+    g_assert_cmpstr(test->copyClipboard(), ==, "All work and no play make Jack a dull boy.");
 }
 
 static void loadContentsAndTryToCutSelection(EditorTest* test, bool contentEditable)
@@ -286,8 +337,7 @@
     test->flushEditorState();
 
     // Cut the selection to the clipboard to see if the view is indeed editable.
-    GUniquePtr<char> clipboardText(test->cutSelection());
-    g_assert_cmpstr(clipboardText.get(), ==, "make Jack a dull");
+    g_assert_cmpstr(test->cutSelection(), ==, "make Jack a dull");
 
     // Reset the editable for next test.
     test->setEditable(false);

Modified: trunk/Tools/TestWebKitAPI/glib/WebKitGLib/TestMain.h (265079 => 265080)


--- trunk/Tools/TestWebKitAPI/glib/WebKitGLib/TestMain.h	2020-07-30 07:21:44 UTC (rev 265079)
+++ trunk/Tools/TestWebKitAPI/glib/WebKitGLib/TestMain.h	2020-07-30 08:53:28 UTC (rev 265080)
@@ -138,8 +138,10 @@
             "website-data-manager", websiteDataManager.get(),
 #if PLATFORM(GTK)
             "process-swap-on-cross-site-navigation-enabled", TRUE,
+#if !USE(GTK4)
             "use-system-appearance-for-scrollbars", FALSE,
 #endif
+#endif
             nullptr)));
         assertObjectIsDeletedWhenTestFinishes(G_OBJECT(m_webContext.get()));
         g_signal_connect(m_webContext.get(), "initialize-web-extensions", G_CALLBACK(initializeWebExtensionsCallback), this);

Modified: trunk/Tools/TestWebKitAPI/glib/WebKitGLib/gtk/WebViewTestGtk.cpp (265079 => 265080)


--- trunk/Tools/TestWebKitAPI/glib/WebKitGLib/gtk/WebViewTestGtk.cpp	2020-07-30 07:21:44 UTC (rev 265079)
+++ trunk/Tools/TestWebKitAPI/glib/WebKitGLib/gtk/WebViewTestGtk.cpp	2020-07-30 08:53:28 UTC (rev 265080)
@@ -28,8 +28,13 @@
 
 void WebViewTest::platformDestroy()
 {
+#if USE(GTK4)
     if (m_parentWindow)
+        gtk_window_destroy(GTK_WINDOW(m_parentWindow));
+#else
+    if (m_parentWindow)
         gtk_widget_destroy(m_parentWindow);
+#endif
 }
 
 void WebViewTest::platformInitializeWebView()
@@ -65,11 +70,18 @@
 void WebViewTest::showInWindow(int width, int height)
 {
     g_assert_null(m_parentWindow);
+#if USE(GTK4)
+    m_parentWindow = gtk_window_new();
+    gtk_window_set_child(GTK_WINDOW(m_parentWindow), GTK_WIDGET(m_webView));
+#else
     m_parentWindow = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+    gtk_container_add(GTK_CONTAINER(m_parentWindow), GTK_WIDGET(m_webView));
+    gtk_widget_show(GTK_WIDGET(m_webView));
+#endif
+
     if (width && height)
         gtk_window_set_default_size(GTK_WINDOW(m_parentWindow), width, height);
-    gtk_container_add(GTK_CONTAINER(m_parentWindow), GTK_WIDGET(m_webView));
-    gtk_widget_show(GTK_WIDGET(m_webView));
+
     gtk_widget_show(m_parentWindow);
 
     while (g_main_context_pending(nullptr))

Modified: trunk/Tools/TestWebKitAPI/gtk/PlatformUtilitiesGtk.cpp (265079 => 265080)


--- trunk/Tools/TestWebKitAPI/gtk/PlatformUtilitiesGtk.cpp	2020-07-30 07:21:44 UTC (rev 265079)
+++ trunk/Tools/TestWebKitAPI/gtk/PlatformUtilitiesGtk.cpp	2020-07-30 08:53:28 UTC (rev 265080)
@@ -68,7 +68,7 @@
 
 bool isKeyDown(WKNativeEventPtr event)
 {
-    return event->type == GDK_KEY_PRESS;
+    return gdk_event_get_event_type(const_cast<GdkEvent*>(event)) == GDK_KEY_PRESS;
 }
 
 } // namespace Util

Modified: trunk/Tools/TestWebKitAPI/gtk/PlatformWebViewGtk.cpp (265079 => 265080)


--- trunk/Tools/TestWebKitAPI/gtk/PlatformWebViewGtk.cpp	2020-07-30 07:21:44 UTC (rev 265079)
+++ trunk/Tools/TestWebKitAPI/gtk/PlatformWebViewGtk.cpp	2020-07-30 08:53:28 UTC (rev 265080)
@@ -62,15 +62,24 @@
 
 PlatformWebView::~PlatformWebView()
 {
+#if USE(GTK4)
+    gtk_window_destroy(GTK_WINDOW(m_window));
+#else
     gtk_widget_destroy(m_window);
+#endif
 }
 
 void PlatformWebView::initialize(WKPageConfigurationRef configuration)
 {
+    m_view = WKViewCreate(configuration);
+#if USE(GTK4)
+    m_window = gtk_window_new();
+    gtk_window_set_child(GTK_WINDOW(m_window), GTK_WIDGET(m_view));
+#else
     m_window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
-    m_view = WKViewCreate(configuration);
     gtk_container_add(GTK_CONTAINER(m_window), GTK_WIDGET(m_view));
     gtk_widget_show(GTK_WIDGET(m_view));
+#endif
     gtk_widget_show(m_window);
 }
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to