Title: [280966] trunk/Tools
Revision
280966
Author
[email protected]
Date
2021-08-12 06:53:44 -0700 (Thu, 12 Aug 2021)

Log Message

[GTK] Simplify TestWebKitAccessibility
https://bugs.webkit.org/show_bug.cgi?id=229032

Reviewed by Michael Catanzaro.

We don't really need to have a different process to test a11y. We can remove AccessibilityTestServer and use the
same test executable. That way we don't need to spawn a process and use DBus for the communication.

* TestWebKitAPI/Tests/WebKitGtk/AccessibilityTestServer.cpp: Removed.
* TestWebKitAPI/Tests/WebKitGtk/TestWebKitAccessibility.cpp:
(AccessibilityTest::findTestApplication): Find the accessible application corresponding to the test executable.
(AccessibilityTest::waitUntilChildrenRemoved): Use the WebViewTest main loop.
(testAtspiBasicHierarchy): Use WebViewTest::loadHtml.
* TestWebKitAPI/glib/PlatformGTK.cmake:
* TestWebKitAPI/glib/WebKitGLib/TestMain.cpp:
(main): Set the program name to the executable name. It helps to a11y test to find the accessible app.

Modified Paths

Removed Paths

Diff

Modified: trunk/Tools/ChangeLog (280965 => 280966)


--- trunk/Tools/ChangeLog	2021-08-12 13:52:29 UTC (rev 280965)
+++ trunk/Tools/ChangeLog	2021-08-12 13:53:44 UTC (rev 280966)
@@ -1,5 +1,24 @@
 2021-08-12  Carlos Garcia Campos  <[email protected]>
 
+        [GTK] Simplify TestWebKitAccessibility
+        https://bugs.webkit.org/show_bug.cgi?id=229032
+
+        Reviewed by Michael Catanzaro.
+
+        We don't really need to have a different process to test a11y. We can remove AccessibilityTestServer and use the
+        same test executable. That way we don't need to spawn a process and use DBus for the communication.
+
+        * TestWebKitAPI/Tests/WebKitGtk/AccessibilityTestServer.cpp: Removed.
+        * TestWebKitAPI/Tests/WebKitGtk/TestWebKitAccessibility.cpp:
+        (AccessibilityTest::findTestApplication): Find the accessible application corresponding to the test executable.
+        (AccessibilityTest::waitUntilChildrenRemoved): Use the WebViewTest main loop.
+        (testAtspiBasicHierarchy): Use WebViewTest::loadHtml.
+        * TestWebKitAPI/glib/PlatformGTK.cmake:
+        * TestWebKitAPI/glib/WebKitGLib/TestMain.cpp:
+        (main): Set the program name to the executable name. It helps to a11y test to find the accessible app.
+
+2021-08-12  Carlos Garcia Campos  <[email protected]>
+
         [GTK] run-gtk-tests always fails to start accessibility daemons
         https://bugs.webkit.org/show_bug.cgi?id=229031
 

Deleted: trunk/Tools/TestWebKitAPI/Tests/WebKitGtk/AccessibilityTestServer.cpp (280965 => 280966)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitGtk/AccessibilityTestServer.cpp	2021-08-12 13:52:29 UTC (rev 280965)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitGtk/AccessibilityTestServer.cpp	2021-08-12 13:53:44 UTC (rev 280966)
@@ -1,103 +0,0 @@
-/*
- * Copyright (C) 2012, 2019 Igalia S.L.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2,1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public License
- * along with this library; see the file COPYING.LIB.  If not, write to
- * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
- */
-
-#include "config.h"
-
-#include <WebCore/GtkVersioning.h>
-#include <webkit2/webkit2.h>
-#include <wtf/glib/GRefPtr.h>
-
-static const char introspectionXML[] =
-    "<node>"
-    " <interface name='org.webkit.gtk.AccessibilityTest'>"
-    "  <method name='LoadHTML'>"
-    "   <arg type='s' name='html' direction='in'/>"
-    "   <arg type='s' name='baseURI' direction='in'/>"
-    "  </method>"
-    " </interface>"
-    "</node>";
-
-static void loadChangedCallback(WebKitWebView* webView, WebKitLoadEvent loadEvent, GDBusMethodInvocation* invocation)
-{
-    if (loadEvent != WEBKIT_LOAD_FINISHED)
-        return;
-
-    g_signal_handlers_disconnect_by_func(webView, reinterpret_cast<void*>(loadChangedCallback), invocation);
-    g_dbus_method_invocation_return_value(invocation, nullptr);
-}
-
-static const GDBusInterfaceVTable interfaceVirtualTable = {
-    // methodCall
-    [](GDBusConnection* connection, const char* sender, const char* objectPath, const char* interfaceName, const char* methodName, GVariant* parameters, GDBusMethodInvocation* invocation, gpointer userData) {
-        if (g_strcmp0(interfaceName, "org.webkit.gtk.AccessibilityTest"))
-            return;
-
-        auto* webView = WEBKIT_WEB_VIEW(userData);
-
-        if (!g_strcmp0(methodName, "LoadHTML")) {
-            const char* html;
-            const char* baseURI;
-            g_variant_get(parameters, "(&s&s)", &html, &baseURI);
-            g_signal_connect(webView, "load-changed", G_CALLBACK(loadChangedCallback), invocation);
-            webkit_web_view_load_html(webView, html, baseURI && *baseURI ? baseURI : nullptr);
-        }
-    },
-    nullptr,
-    nullptr,
-    { 0, }
-};
-
-int main(int argc, char** argv)
-{
-    // Make sure that the ATK bridge is loaded.
-    g_setenv("GTK_MODULES", "atk-bridge", TRUE);
-
-    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(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) {
-            GDBusConnection* connection = g_dbus_connection_new_for_address_finish(result, nullptr);
-
-            static GDBusNodeInfo *introspectionData = nullptr;
-            if (!introspectionData)
-                introspectionData = g_dbus_node_info_new_for_xml(introspectionXML, nullptr);
-
-            g_dbus_connection_register_object(connection, "/org/webkit/gtk/AccessibilityTest", introspectionData->interfaces[0],
-                &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/TestWebKitAccessibility.cpp (280965 => 280966)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitGtk/TestWebKitAccessibility.cpp	2021-08-12 13:52:29 UTC (rev 280965)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitGtk/TestWebKitAccessibility.cpp	2021-08-12 13:53:44 UTC (rev 280966)
@@ -19,7 +19,7 @@
 
 #include "config.h"
 
-#include "TestMain.h"
+#include "WebViewTest.h"
 
 // The libatspi headers don't use G_BEGIN_DECLS
 extern "C" {
@@ -26,48 +26,22 @@
 #include <atspi/atspi.h>
 }
 
-class AccessibilityTest : public Test {
+class AccessibilityTest : public WebViewTest {
 public:
     MAKE_GLIB_TEST_FIXTURE(AccessibilityTest);
 
-    AccessibilityTest()
+    GRefPtr<AtspiAccessible> findTestApplication()
     {
-        GUniquePtr<char> testServerPath(g_build_filename(WEBKIT_EXEC_PATH, "TestWebKitAPI", "WebKit2Gtk", "AccessibilityTestServer", nullptr));
-        char* args[3];
-        args[0] = testServerPath.get();
-        args[1] = const_cast<char*>(g_dbus_server_get_client_address(s_dbusServer.get()));
-        args[2] = nullptr;
-
-        g_assert_true(g_spawn_async(nullptr, args, nullptr, G_SPAWN_DEFAULT, nullptr, nullptr, &m_childProcessID, nullptr));
-    }
-
-    ~AccessibilityTest()
-    {
-        if (m_childProcessID) {
-            g_spawn_close_pid(m_childProcessID);
-            kill(m_childProcessID, SIGTERM);
-        }
-    }
-
-    void loadHTMLAndWaitUntilFinished(const char* html, const char* baseURI)
-    {
-        ensureProxy();
-
-        GUniqueOutPtr<GError> error;
-        GRefPtr<GVariant> result = adoptGRef(g_dbus_proxy_call_sync(m_proxy.get(), "LoadHTML",
-            g_variant_new("(ss)", html, baseURI ? baseURI : ""), G_DBUS_CALL_FLAGS_NONE, -1, nullptr, &error.outPtr()));
-        g_assert_no_error(error.get());
-    }
-
-    GRefPtr<AtspiAccessible> findTestServerApplication()
-    {
         // Only one desktop is supported by ATSPI at the moment.
         GRefPtr<AtspiAccessible> desktop = adoptGRef(atspi_get_desktop(0));
 
+        // We can get warnings from atspi when trying to connect to applications.
+        Test::removeLogFatalFlag(G_LOG_LEVEL_WARNING);
         int childCount = atspi_accessible_get_child_count(desktop.get(), nullptr);
+        Test::addLogFatalFlag(G_LOG_LEVEL_WARNING);
         for (int i = 0; i < childCount; ++i) {
             GRefPtr<AtspiAccessible> current = adoptGRef(atspi_accessible_get_child_at_index(desktop.get(), i, nullptr));
-            if (!g_strcmp0(atspi_accessible_get_name(current.get(), nullptr), "AccessibilityTestServer"))
+            if (!g_strcmp0(atspi_accessible_get_name(current.get(), nullptr), "TestWebKitAccessibility"))
                 return current;
         }
 
@@ -107,46 +81,21 @@
             [](AtspiEvent* event, gpointer userData) {
                 auto* test = static_cast<AccessibilityTest*>(userData);
                 if (event->source == test->m_eventSource)
-                    g_main_loop_quit(test->m_mainLoop.get());
+                    g_main_loop_quit(test->m_mainLoop);
         }, this, nullptr));
         atspi_event_listener_register(listener.get(), "object:children-changed:remove", nullptr);
-        g_main_loop_run(m_mainLoop.get());
+        g_main_loop_run(m_mainLoop);
         m_eventSource = nullptr;
     }
 
 private:
-    void ensureProxy()
-    {
-        if (m_proxy)
-            return;
-
-        m_mainLoop = adoptGRef(g_main_loop_new(nullptr, FALSE));
-
-        if (s_dbusConnections.isEmpty()) {
-            g_idle_add([](gpointer userData) -> gboolean {
-                if (s_dbusConnections.isEmpty())
-                    return TRUE;
-
-                g_main_loop_quit(static_cast<GMainLoop*>(userData));
-                return FALSE;
-            }, m_mainLoop.get());
-            g_main_loop_run(m_mainLoop.get());
-        }
-
-        m_proxy = adoptGRef(g_dbus_proxy_new_sync(s_dbusConnections[0].get(), static_cast<GDBusProxyFlags>(G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES | G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS),
-            nullptr, nullptr, "/org/webkit/gtk/AccessibilityTest", "org.webkit.gtk.AccessibilityTest", nullptr, nullptr));
-        g_assert_true(G_IS_DBUS_PROXY(m_proxy.get()));
-    }
-
-    GPid m_childProcessID { 0 };
-    GRefPtr<GDBusProxy> m_proxy;
-    GRefPtr<GMainLoop> m_mainLoop;
     AtspiAccessible* m_eventSource { nullptr };
 };
 
 static void testAtspiBasicHierarchy(AccessibilityTest* test, gconstpointer)
 {
-    test->loadHTMLAndWaitUntilFinished(
+    test->showInWindow();
+    test->loadHtml(
         "<html>"
         "  <body>"
         "   <h1>This is a test</h1>"
@@ -155,14 +104,15 @@
         "  </body>"
         "</html>",
         nullptr);
+    test->waitUntilLoadFinished();
 
-    auto testServerApp = test->findTestServerApplication();
-    g_assert_true(ATSPI_IS_ACCESSIBLE(testServerApp.get()));
-    GUniquePtr<char> name(atspi_accessible_get_name(testServerApp.get(), nullptr));
-    g_assert_cmpstr(name.get(), ==, "AccessibilityTestServer");
-    g_assert_cmpint(atspi_accessible_get_role(testServerApp.get(), nullptr), ==, ATSPI_ROLE_APPLICATION);
+    auto testApp = test->findTestApplication();
+    g_assert_true(ATSPI_IS_ACCESSIBLE(testApp.get()));
+    GUniquePtr<char> name(atspi_accessible_get_name(testApp.get(), nullptr));
+    g_assert_cmpstr(name.get(), ==, "TestWebKitAccessibility");
+    g_assert_cmpint(atspi_accessible_get_role(testApp.get(), nullptr), ==, ATSPI_ROLE_APPLICATION);
 
-    auto rootObject = test->findRootObject(testServerApp.get());
+    auto rootObject = test->findRootObject(testApp.get());
     g_assert_true(ATSPI_IS_ACCESSIBLE(rootObject.get()));
     g_assert_cmpint(atspi_accessible_get_role(rootObject.get(), nullptr), ==, ATSPI_ROLE_FILLER);
 
@@ -194,7 +144,7 @@
     g_assert_cmpstr(name.get(), ==, "a link");
     g_assert_cmpint(atspi_accessible_get_role(link.get(), nullptr), ==, ATSPI_ROLE_LINK);
 
-    test->loadHTMLAndWaitUntilFinished(
+    test->loadHtml(
         "<html>"
         "  <body>"
         "   <h1>This is another test</h1>"
@@ -202,12 +152,11 @@
         "  </body>"
         "</html>",
         nullptr);
-
     // Check that children-changed::remove is emitted on the root object on navigation,
     // and the a11y hierarchy is updated.
     test->waitUntilChildrenRemoved(rootObject.get());
 
-    documentWeb = test->findDocumentWeb(testServerApp.get());
+    documentWeb = test->findDocumentWeb(testApp.get());
     g_assert_true(ATSPI_IS_ACCESSIBLE(documentWeb.get()));
     g_assert_cmpint(atspi_accessible_get_role(documentWeb.get(), nullptr), ==, ATSPI_ROLE_DOCUMENT_WEB);
 

Modified: trunk/Tools/TestWebKitAPI/glib/PlatformGTK.cmake (280965 => 280966)


--- trunk/Tools/TestWebKitAPI/glib/PlatformGTK.cmake	2021-08-12 13:52:29 UTC (rev 280965)
+++ trunk/Tools/TestWebKitAPI/glib/PlatformGTK.cmake	2021-08-12 13:53:44 UTC (rev 280966)
@@ -48,6 +48,5 @@
 ADD_WK2_TEST(TestWebViewEditor ${TOOLS_DIR}/TestWebKitAPI/Tests/WebKitGtk/TestWebViewEditor.cpp)
 
 if (ATSPI_FOUND)
-    ADD_WK2_TEST(AccessibilityTestServer ${TOOLS_DIR}/TestWebKitAPI/Tests/WebKitGtk/AccessibilityTestServer.cpp)
     ADD_WK2_TEST(TestWebKitAccessibility ${TOOLS_DIR}/TestWebKitAPI/Tests/WebKitGtk/TestWebKitAccessibility.cpp)
 endif ()

Modified: trunk/Tools/TestWebKitAPI/glib/WebKitGLib/TestMain.cpp (280965 => 280966)


--- trunk/Tools/TestWebKitAPI/glib/WebKitGLib/TestMain.cpp	2021-08-12 13:52:29 UTC (rev 280965)
+++ trunk/Tools/TestWebKitAPI/glib/WebKitGLib/TestMain.cpp	2021-08-12 13:53:44 UTC (rev 280966)
@@ -21,6 +21,7 @@
 #include "TestMain.h"
 
 #include <glib/gstdio.h>
+#include <wtf/glib/GLibUtilities.h>
 
 #if PLATFORM(GTK)
 #include <gtk/gtk.h>
@@ -123,6 +124,7 @@
 #else
     g_test_init(&argc, &argv, nullptr);
 #endif
+    g_set_prgname(getCurrentExecutableName().data());
     g_setenv("WEBKIT_EXEC_PATH", WEBKIT_EXEC_PATH, FALSE);
     g_setenv("WEBKIT_INJECTED_BUNDLE_PATH", WEBKIT_INJECTED_BUNDLE_PATH, FALSE);
     g_setenv("LC_ALL", "C", TRUE);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to