Skip to content

Truly independent web browser

UI/Qt: Import the offscreen platform plugin into the Qt UI tests

Jelle Raaijmakersa72eba653fe6
diff --git a/Tests/UI/Qt/CMakeLists.txt b/Tests/UI/Qt/CMakeLists.txt
index 5103018994f..a28bb9149d9 100644
--- a/Tests/UI/Qt/CMakeLists.txt
+++ b/Tests/UI/Qt/CMakeLists.txt
@@ -40,14 +40,12 @@ add_library(QtTestMain OBJECT
)
target_link_libraries(QtTestMain PRIVATE AK LibCore LibTest Qt::Core Qt::Gui Qt::Widgets)
-# QtTestMain runs its tests on Qt's offscreen platform plugin, and on Windows nothing deploys that plugin where a test
-# binary can find it: The ladybird target's deploy step copies only the "windows" platform plugin into the bin/platforms
-# directory — and for a binary in a deployed layout, that directory is the whole platform-plugin search path. So a
-# QApplication there finds no platform plugin at all, which is fatal.
-# NB: On Windows, Qt puts up a modal message box before that abort whenever the process has no console window — and a
-# CI test process has none. So the test doesn't fail: It sits in the box until CTest's timeout kills it. Call this for
-# every test that links QtTestMain, so the plugin sits next to the test binary, where Qt looks for it.
+# QtTestMain runs its tests on Qt's offscreen platform plugin, so every test that links it must call this. A static Qt
+# only links the default platform plugin into an executable, so the offscreen plugin is imported. On Windows, Qt only
+# searches bin/platforms, where the ladybird target deploys just the "windows" plugin, so the offscreen plugin is copied
+# there too. Without it, Qt shows a modal message box that blocks the test until CTest's timeout kills it.
function(deploy_qt_offscreen_platform_plugin target)
+ qt_import_plugins(${target} INCLUDE Qt6::QOffscreenIntegrationPlugin)
if (NOT WIN32)
return()
endif()
@@ -164,6 +162,7 @@ endif()
ladybird_test("TestNativeWindowContainerFocus.cpp" UI/Qt LIBS Qt::Core Qt::Gui Qt::Widgets)
target_sources(TestNativeWindowContainerFocus PRIVATE "${LADYBIRD_SOURCE_DIR}/UI/Qt/NativeWindowContainer.cpp")
+deploy_qt_offscreen_platform_plugin(TestNativeWindowContainerFocus)
ladybird_test("TestJavaScriptDialog.cpp" UI/Qt
CUSTOM_MAIN "$<TARGET_OBJECTS:QtTestMain>"
@@ -175,6 +174,7 @@ target_sources(TestJavaScriptDialog PRIVATE
"${LADYBIRD_SOURCE_DIR}/UI/Qt/NativeTextEditingLineEdit.cpp"
"${LADYBIRD_SOURCE_DIR}/UI/Qt/StringUtils.cpp"
)
+deploy_qt_offscreen_platform_plugin(TestJavaScriptDialog)
ladybird_test("TestWindowCloseCoordinator.cpp" UI/Qt LIBS Qt::Core)
target_sources(TestWindowCloseCoordinator PRIVATE "${LADYBIRD_SOURCE_DIR}/UI/Qt/WindowCloseCoordinator.cpp")
diff --git a/UI/Qt/CMakeLists.txt b/UI/Qt/CMakeLists.txt
index 0f8f2d023ff..b4f10229235 100644
--- a/UI/Qt/CMakeLists.txt
+++ b/UI/Qt/CMakeLists.txt
@@ -213,6 +213,7 @@ if (BUILD_TESTING)
)
target_include_directories(TestPerformanceMonitorWidget PRIVATE ${LADYBIRD_SOURCE_DIR})
target_link_libraries(TestPerformanceMonitorWidget PRIVATE Qt6::Widgets LibWebView LibURL AK)
+ qt_import_plugins(TestPerformanceMonitorWidget INCLUDE Qt6::QOffscreenIntegrationPlugin)
add_test(NAME TestPerformanceMonitorWidget COMMAND TestPerformanceMonitorWidget)
set_tests_properties(TestPerformanceMonitorWidget PROPERTIES ENVIRONMENT "QT_QPA_PLATFORM=offscreen")
endif()