From 2032690d7c3f12f334376f1fc6a4f47c8e7005ff Mon Sep 17 00:00:00 2001 From: Ambroise Leclerc <6860842+ambroise-leclerc@users.noreply.github.com> Date: Thu, 5 Nov 2026 13:07:37 +0100 Subject: [PATCH 1/2] Make WebKitGTK file dialog tests resilient under load (#487) --- test/web/WebKitGTKLifecycle.cpp | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/test/web/WebKitGTKLifecycle.cpp b/test/web/WebKitGTKLifecycle.cpp index 4245f468..093b7f64 100644 --- a/test/web/WebKitGTKLifecycle.cpp +++ b/test/web/WebKitGTKLifecycle.cpp @@ -131,7 +131,7 @@ void nativeClose() { app.show("no-bridge.html"); } -/// Runs a page of the test folder in a session configured by the scenario, for at most `seconds`. +/// Runs a page of the test folder in a session configured by the scenario, for at most 45 seconds. struct ScenarioFrontend : Frontend { static inline std::function configure; static inline std::function finished; // Polled; true closes the window. @@ -144,9 +144,9 @@ struct ScenarioFrontend : Frontend { configure(session); struct Poll { gtk::Session& session; - int remaining = 150; // 15 s - unsigned timer = 0; - } poll{session, 150, 0}; + std::chrono::steady_clock::time_point deadline = std::chrono::steady_clock::now() + std::chrono::seconds(45); + unsigned timer = 0; + } poll{session}; poll.timer = session.a.timeoutAdd( 100, [](void* data) -> int { @@ -155,7 +155,7 @@ struct ScenarioFrontend : Frontend { probe.timer = 0; // Returning 0 removes the source: it must not be removed again. return 0; } - if (finished(probe.session) || --probe.remaining == 0) { + if (finished(probe.session) || std::chrono::steady_clock::now() >= probe.deadline) { probe.timer = 0; probe.session.close(); return 0; @@ -252,6 +252,7 @@ struct FakeClick { using Root = unsigned long (*)(void*); using Surface = void* (*)(void*); using Xid = unsigned long (*)(void*); + using Mapped = int (*)(void*); Open open = x11 ? reinterpret_cast(dlsym(x11, "XOpenDisplay")) : nullptr; Flush flush = x11 ? reinterpret_cast(dlsym(x11, "XFlush")) : nullptr; Move move = xtest ? reinterpret_cast(dlsym(xtest, "XTestFakeMotionEvent")) : nullptr; @@ -261,10 +262,11 @@ struct FakeClick { // GTK's client surface need not start at the root window's origin, even under Xvfb. Surface surface = gtkModule ? reinterpret_cast(dlsym(gtkModule, "gtk_native_get_surface")) : nullptr; Xid xid = gtkModule ? reinterpret_cast(dlsym(gtkModule, "gdk_x11_surface_get_xid")) : nullptr; + Mapped mapped = gtkModule ? reinterpret_cast(dlsym(gtkModule, "gtk_widget_get_mapped")) : nullptr; void* display = open ? open(nullptr) : nullptr; bool available() const { - return display && move && press && flush && translate && root && surface && xid; + return display && move && press && flush && translate && root && surface && xid && mapped; } void click(void* window, int x, int y, int phase) const { const auto native = surface(window); @@ -313,7 +315,7 @@ void chooseFile(bool cancel) { ScenarioFrontend::finished = [&](gtk::Session& session) { const char* current = session.a.viewTitle(session.view); title = current ? current : ""; - if (title == "ready" && !asked) + if (title == "ready" && pointer.mapped(session.window) && !asked) pointer.click(session.window, 40, 20, ticks++ % 5); // The button's position within the GTK client surface. return title.starts_with("picked:") || title == "cancelled"; }; @@ -321,7 +323,8 @@ void chooseFile(bool cancel) { app.show("file-services.html?choose"); std::filesystem::remove(fixture); if (!asked) - throw std::runtime_error("The file chooser was not requested (page title \"" + title + "\", " + std::to_string(ticks) + " pointer steps)"); + throw std::runtime_error("The file chooser was not requested (page title \"" + title + "\", " + + std::to_string(ticks / 5 + (ticks % 5 >= 4)) + " clicks, " + std::to_string(ticks) + " pointer steps)"); const std::string expected = cancel ? "cancelled" : "picked:chosen by the test"; if (title != expected) throw std::runtime_error("Unexpected page state after the chooser: " + title); @@ -350,14 +353,15 @@ void closeWithDialog() { ScenarioFrontend::finished = [&](gtk::Session& session) { const char* current = session.a.viewTitle(session.view); title = current ? current : ""; - if (title == "ready" && !opened) + if (title == "ready" && pointer.mapped(session.window) && !opened) pointer.click(session.window, 40, 20, ticks++ % 5); return opened && ++open > 10; // Let the dialog map, then close the window under it. }; ScenarioApp app(webfront::WebFrontConfig{.documentRoot = std::filesystem::current_path()}); app.show("file-services.html?choose"); if (!opened) - throw std::runtime_error("The file dialog was not opened"); + throw std::runtime_error("The file dialog was not opened (page title \"" + title + "\", " + + std::to_string(ticks / 5 + (ticks % 5 >= 4)) + " clicks, " + std::to_string(ticks) + " pointer steps)"); } /// alert, confirm and prompt reach the injection point and their answers reach the page (issue #452). From 0045a3b2e359836071802a8d1ca547c69d33d374 Mon Sep 17 00:00:00 2001 From: Ambroise Leclerc <6860842+ambroise-leclerc@users.noreply.github.com> Date: Thu, 5 Nov 2026 15:16:50 +0100 Subject: [PATCH 2/2] Contain WebKitGTK scenario polling failures (#487) --- cmake/WebKitGTKSupport.cmake | 2 +- test/web/WebKitGTKLifecycle.cpp | 26 +++++++++++++++++++++++--- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/cmake/WebKitGTKSupport.cmake b/cmake/WebKitGTKSupport.cmake index 00a8c4f0..6925f0ba 100644 --- a/cmake/WebKitGTKSupport.cmake +++ b/cmake/WebKitGTKSupport.cmake @@ -25,7 +25,7 @@ function(webfront_add_webkitgtk_tests) target_link_libraries(webkitgtk_lifecycle PRIVATE WebFront_test_hardening WebFront WebFront_warnings WebFront_options) add_dependencies(webtest webkitgtk_lifecycle) webfront_find_xvfb(display_runner) - foreach(mode no-display worker-thread native-close repeated-show http-error pre-run-failure profile-permissions window-title download download-user-dir choose-file cancel-choose close-with-dialog script-dialogs close-with-script-dialog) + foreach(mode no-display worker-thread native-close repeated-show http-error pre-run-failure poll-failure profile-permissions window-title download download-user-dir choose-file cancel-choose close-with-dialog script-dialogs close-with-script-dialog) if(mode MATCHES "^(no-display|worker-thread|pre-run-failure|profile-permissions)$") add_test(NAME WebKitGTKAdapter-${mode} COMMAND webkitgtk_lifecycle ${mode}) elseif(display_runner) diff --git a/test/web/WebKitGTKLifecycle.cpp b/test/web/WebKitGTKLifecycle.cpp index 093b7f64..ee968b0b 100644 --- a/test/web/WebKitGTKLifecycle.cpp +++ b/test/web/WebKitGTKLifecycle.cpp @@ -146,6 +146,7 @@ struct ScenarioFrontend : Frontend { gtk::Session& session; std::chrono::steady_clock::time_point deadline = std::chrono::steady_clock::now() + std::chrono::seconds(45); unsigned timer = 0; + std::exception_ptr failure{}; } poll{session}; poll.timer = session.a.timeoutAdd( 100, @@ -155,7 +156,14 @@ struct ScenarioFrontend : Frontend { probe.timer = 0; // Returning 0 removes the source: it must not be removed again. return 0; } - if (finished(probe.session) || std::chrono::steady_clock::now() >= probe.deadline) { + bool done = false; + try { + done = finished(probe.session); + } catch (...) { + probe.failure = std::current_exception(); + done = true; + } + if (done || std::chrono::steady_clock::now() >= probe.deadline) { probe.timer = 0; probe.session.close(); return 0; @@ -166,11 +174,22 @@ struct ScenarioFrontend : Frontend { session.run(webfront::frontend::detail::applicationUrl(address, port, page)); if (poll.timer) session.a.sourceRemove(poll.timer); + if (poll.failure) + std::rethrow_exception(poll.failure); } }; using ScenarioApp = webfront::BasicWFWithFrontend; +void pollFailure() { + ScenarioFrontend::configure = [](gtk::Session&) {}; + ScenarioFrontend::finished = [](gtk::Session&) -> bool { + throw std::runtime_error("poll failure"); + }; + ScenarioApp app(webfront::WebFrontConfig{.documentRoot = std::filesystem::current_path()}); + expectFailure([&] { app.show("no-bridge.html"); }, "poll failure"); +} + std::string readFile(const std::filesystem::path& path) { std::ifstream stream(path, std::ios::binary); return {std::istreambuf_iterator(stream), {}}; @@ -324,7 +343,7 @@ void chooseFile(bool cancel) { std::filesystem::remove(fixture); if (!asked) throw std::runtime_error("The file chooser was not requested (page title \"" + title + "\", " + - std::to_string(ticks / 5 + (ticks % 5 >= 4)) + " clicks, " + std::to_string(ticks) + " pointer steps)"); + std::to_string(ticks / 5 + (ticks % 5 == 4)) + " clicks, " + std::to_string(ticks) + " pointer steps)"); const std::string expected = cancel ? "cancelled" : "picked:chosen by the test"; if (title != expected) throw std::runtime_error("Unexpected page state after the chooser: " + title); @@ -361,7 +380,7 @@ void closeWithDialog() { app.show("file-services.html?choose"); if (!opened) throw std::runtime_error("The file dialog was not opened (page title \"" + title + "\", " + - std::to_string(ticks / 5 + (ticks % 5 >= 4)) + " clicks, " + std::to_string(ticks) + " pointer steps)"); + std::to_string(ticks / 5 + (ticks % 5 == 4)) + " clicks, " + std::to_string(ticks) + " pointer steps)"); } /// alert, confirm and prompt reach the injection point and their answers reach the page (issue #452). @@ -460,6 +479,7 @@ void run(std::string_view mode) { { "http-error", httpError}, { "native-close", nativeClose}, { "pre-run-failure", preRunFailure}, + { "poll-failure", pollFailure}, {"profile-permissions", profilePermissions}, { "window-title", windowTitle}, { "download", download},