⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 280966 in webkit


Ignore:
Timestamp:
Aug 12, 2021, 6:53:44 AM (5 years ago)
Author:
Carlos Garcia Campos
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.

Location:
trunk/Tools
Files:
1 deleted
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Tools/ChangeLog

    r280965 r280966  
     12021-08-12  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        [GTK] Simplify TestWebKitAccessibility
     4        https://bugs.webkit.org/show_bug.cgi?id=229032
     5
     6        Reviewed by Michael Catanzaro.
     7
     8        We don't really need to have a different process to test a11y. We can remove AccessibilityTestServer and use the
     9        same test executable. That way we don't need to spawn a process and use DBus for the communication.
     10
     11        * TestWebKitAPI/Tests/WebKitGtk/AccessibilityTestServer.cpp: Removed.
     12        * TestWebKitAPI/Tests/WebKitGtk/TestWebKitAccessibility.cpp:
     13        (AccessibilityTest::findTestApplication): Find the accessible application corresponding to the test executable.
     14        (AccessibilityTest::waitUntilChildrenRemoved): Use the WebViewTest main loop.
     15        (testAtspiBasicHierarchy): Use WebViewTest::loadHtml.
     16        * TestWebKitAPI/glib/PlatformGTK.cmake:
     17        * TestWebKitAPI/glib/WebKitGLib/TestMain.cpp:
     18        (main): Set the program name to the executable name. It helps to a11y test to find the accessible app.
     19
    1202021-08-12  Carlos Garcia Campos  <cgarcia@igalia.com>
    221
  • trunk/Tools/TestWebKitAPI/Tests/WebKitGtk/TestWebKitAccessibility.cpp

    r249759 r280966  
    2020#include "config.h"
    2121
    22 #include "TestMain.h"
     22#include "WebViewTest.h"
    2323
    2424// The libatspi headers don't use G_BEGIN_DECLS
     
    2727}
    2828
    29 class AccessibilityTest : public Test {
     29class AccessibilityTest : public WebViewTest {
    3030public:
    3131    MAKE_GLIB_TEST_FIXTURE(AccessibilityTest);
    3232
    33     AccessibilityTest()
    34     {
    35         GUniquePtr<char> testServerPath(g_build_filename(WEBKIT_EXEC_PATH, "TestWebKitAPI", "WebKit2Gtk", "AccessibilityTestServer", nullptr));
    36         char* args[3];
    37         args[0] = testServerPath.get();
    38         args[1] = const_cast<char*>(g_dbus_server_get_client_address(s_dbusServer.get()));
    39         args[2] = nullptr;
    40 
    41         g_assert_true(g_spawn_async(nullptr, args, nullptr, G_SPAWN_DEFAULT, nullptr, nullptr, &m_childProcessID, nullptr));
    42     }
    43 
    44     ~AccessibilityTest()
    45     {
    46         if (m_childProcessID) {
    47             g_spawn_close_pid(m_childProcessID);
    48             kill(m_childProcessID, SIGTERM);
    49         }
    50     }
    51 
    52     void loadHTMLAndWaitUntilFinished(const char* html, const char* baseURI)
    53     {
    54         ensureProxy();
    55 
    56         GUniqueOutPtr<GError> error;
    57         GRefPtr<GVariant> result = adoptGRef(g_dbus_proxy_call_sync(m_proxy.get(), "LoadHTML",
    58             g_variant_new("(ss)", html, baseURI ? baseURI : ""), G_DBUS_CALL_FLAGS_NONE, -1, nullptr, &error.outPtr()));
    59         g_assert_no_error(error.get());
    60     }
    61 
    62     GRefPtr<AtspiAccessible> findTestServerApplication()
     33    GRefPtr<AtspiAccessible> findTestApplication()
    6334    {
    6435        // Only one desktop is supported by ATSPI at the moment.
    6536        GRefPtr<AtspiAccessible> desktop = adoptGRef(atspi_get_desktop(0));
    6637
     38        // We can get warnings from atspi when trying to connect to applications.
     39        Test::removeLogFatalFlag(G_LOG_LEVEL_WARNING);
    6740        int childCount = atspi_accessible_get_child_count(desktop.get(), nullptr);
     41        Test::addLogFatalFlag(G_LOG_LEVEL_WARNING);
    6842        for (int i = 0; i < childCount; ++i) {
    6943            GRefPtr<AtspiAccessible> current = adoptGRef(atspi_accessible_get_child_at_index(desktop.get(), i, nullptr));
    70             if (!g_strcmp0(atspi_accessible_get_name(current.get(), nullptr), "AccessibilityTestServer"))
     44            if (!g_strcmp0(atspi_accessible_get_name(current.get(), nullptr), "TestWebKitAccessibility"))
    7145                return current;
    7246        }
     
    10882                auto* test = static_cast<AccessibilityTest*>(userData);
    10983                if (event->source == test->m_eventSource)
    110                     g_main_loop_quit(test->m_mainLoop.get());
     84                    g_main_loop_quit(test->m_mainLoop);
    11185        }, this, nullptr));
    11286        atspi_event_listener_register(listener.get(), "object:children-changed:remove", nullptr);
    113         g_main_loop_run(m_mainLoop.get());
     87        g_main_loop_run(m_mainLoop);
    11488        m_eventSource = nullptr;
    11589    }
    11690
    11791private:
    118     void ensureProxy()
    119     {
    120         if (m_proxy)
    121             return;
    122 
    123         m_mainLoop = adoptGRef(g_main_loop_new(nullptr, FALSE));
    124 
    125         if (s_dbusConnections.isEmpty()) {
    126             g_idle_add([](gpointer userData) -> gboolean {
    127                 if (s_dbusConnections.isEmpty())
    128                     return TRUE;
    129 
    130                 g_main_loop_quit(static_cast<GMainLoop*>(userData));
    131                 return FALSE;
    132             }, m_mainLoop.get());
    133             g_main_loop_run(m_mainLoop.get());
    134         }
    135 
    136         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),
    137             nullptr, nullptr, "/org/webkit/gtk/AccessibilityTest", "org.webkit.gtk.AccessibilityTest", nullptr, nullptr));
    138         g_assert_true(G_IS_DBUS_PROXY(m_proxy.get()));
    139     }
    140 
    141     GPid m_childProcessID { 0 };
    142     GRefPtr<GDBusProxy> m_proxy;
    143     GRefPtr<GMainLoop> m_mainLoop;
    14492    AtspiAccessible* m_eventSource { nullptr };
    14593};
     
    14795static void testAtspiBasicHierarchy(AccessibilityTest* test, gconstpointer)
    14896{
    149     test->loadHTMLAndWaitUntilFinished(
     97    test->showInWindow();
     98    test->loadHtml(
    15099        "<html>"
    151100        "  <body>"
     
    156105        "</html>",
    157106        nullptr);
     107    test->waitUntilLoadFinished();
    158108
    159     auto testServerApp = test->findTestServerApplication();
    160     g_assert_true(ATSPI_IS_ACCESSIBLE(testServerApp.get()));
    161     GUniquePtr<char> name(atspi_accessible_get_name(testServerApp.get(), nullptr));
    162     g_assert_cmpstr(name.get(), ==, "AccessibilityTestServer");
    163     g_assert_cmpint(atspi_accessible_get_role(testServerApp.get(), nullptr), ==, ATSPI_ROLE_APPLICATION);
     109    auto testApp = test->findTestApplication();
     110    g_assert_true(ATSPI_IS_ACCESSIBLE(testApp.get()));
     111    GUniquePtr<char> name(atspi_accessible_get_name(testApp.get(), nullptr));
     112    g_assert_cmpstr(name.get(), ==, "TestWebKitAccessibility");
     113    g_assert_cmpint(atspi_accessible_get_role(testApp.get(), nullptr), ==, ATSPI_ROLE_APPLICATION);
    164114
    165     auto rootObject = test->findRootObject(testServerApp.get());
     115    auto rootObject = test->findRootObject(testApp.get());
    166116    g_assert_true(ATSPI_IS_ACCESSIBLE(rootObject.get()));
    167117    g_assert_cmpint(atspi_accessible_get_role(rootObject.get(), nullptr), ==, ATSPI_ROLE_FILLER);
     
    195145    g_assert_cmpint(atspi_accessible_get_role(link.get(), nullptr), ==, ATSPI_ROLE_LINK);
    196146
    197     test->loadHTMLAndWaitUntilFinished(
     147    test->loadHtml(
    198148        "<html>"
    199149        "  <body>"
     
    203153        "</html>",
    204154        nullptr);
    205 
    206155    // Check that children-changed::remove is emitted on the root object on navigation,
    207156    // and the a11y hierarchy is updated.
    208157    test->waitUntilChildrenRemoved(rootObject.get());
    209158
    210     documentWeb = test->findDocumentWeb(testServerApp.get());
     159    documentWeb = test->findDocumentWeb(testApp.get());
    211160    g_assert_true(ATSPI_IS_ACCESSIBLE(documentWeb.get()));
    212161    g_assert_cmpint(atspi_accessible_get_role(documentWeb.get(), nullptr), ==, ATSPI_ROLE_DOCUMENT_WEB);
  • trunk/Tools/TestWebKitAPI/glib/PlatformGTK.cmake

    r276645 r280966  
    4949
    5050if (ATSPI_FOUND)
    51     ADD_WK2_TEST(AccessibilityTestServer ${TOOLS_DIR}/TestWebKitAPI/Tests/WebKitGtk/AccessibilityTestServer.cpp)
    5251    ADD_WK2_TEST(TestWebKitAccessibility ${TOOLS_DIR}/TestWebKitAPI/Tests/WebKitGtk/TestWebKitAccessibility.cpp)
    5352endif ()
  • trunk/Tools/TestWebKitAPI/glib/WebKitGLib/TestMain.cpp

    r280155 r280966  
    2222
    2323#include <glib/gstdio.h>
     24#include <wtf/glib/GLibUtilities.h>
    2425
    2526#if PLATFORM(GTK)
     
    124125    g_test_init(&argc, &argv, nullptr);
    125126#endif
     127    g_set_prgname(getCurrentExecutableName().data());
    126128    g_setenv("WEBKIT_EXEC_PATH", WEBKIT_EXEC_PATH, FALSE);
    127129    g_setenv("WEBKIT_INJECTED_BUNDLE_PATH", WEBKIT_INJECTED_BUNDLE_PATH, FALSE);
Note: See TracChangeset for help on using the changeset viewer.