Truly independent web browser
LibWebView: Link unit and headless tests into one executable
Timothy Flynn2d7d5608cbf6
diff --git a/Documentation/Omnibox.md b/Documentation/Omnibox.mdindex 852cbb73182..73075d0994f 100644--- a/Documentation/Omnibox.md+++ b/Documentation/Omnibox.md@@ -290,14 +290,16 @@ enabled.The implementation has three main deterministic test layers:-- `TestAutocompleteRanker` verifies matching, relevance components, eligibility, decay, and short+- `TestAutocompleteRanker.cpp` verifies matching, relevance components, eligibility, decay, and shortquery behavior.-- `TestAutocompleteMuxer` verifies destination merging, diversity, source limits, verbatim+- `TestAutocompleteMuxer.cpp` verifies destination merging, diversity, source limits, verbatimpreservation, and representative selection.-- `TestOmnibox` drives the editing state machine with a scripted provider, covering stale delivery,+- `TestOmnibox.cpp` drives the editing state machine with a scripted provider, covering stale delivery,completion acceptance and rejection, selection preservation, activation, and engagement recording.-`TestAutocomplete` exercises the asynchronous integration with the application, service worker,+These sources and the browser storage tests are part of `TestLibWebView`.++The `TestAutocomplete` suite in `TestLibWebView` exercises the asynchronous integration with the application, service worker,bookmark updates, private-profile reads, and remote failure handling. History-store tests coverpersisted ranking state, migrations, and deletion behavior.diff --git a/Documentation/Testing.md b/Documentation/Testing.mdindex 94e432ff355..37792c896a4 100644--- a/Documentation/Testing.md+++ b/Documentation/Testing.md@@ -66,6 +66,15 @@ Build/release/bin/TestLibTest 'TestGenerator::*'Build the library's executable to link its sources, and use `--suite` to select the tests from a source file.+LibWebView's headless browser integration tests also run through `TestLibWebView`, with a fresh application+and temporary configuration for each case. The target builds the helper processes and resources they need.+For example, from the source directory:++```sh+cmake --build Build/release --target TestLibWebView+LADYBIRD_SOURCE_DIR="$PWD" Build/release/bin/TestLibWebView --suite TestFavicon+```+### JavaScript testsBuild `test-js` to build the runtime runner and `js`, and prepare the shareddiff --git a/Tests/LibWebView/CMakeLists.txt b/Tests/LibWebView/CMakeLists.txtindex e1f96de1fac..6ba64410b9a 100644--- a/Tests/LibWebView/CMakeLists.txt+++ b/Tests/LibWebView/CMakeLists.txt@@ -155,13 +155,15 @@ if (BUILD_BROWSER_TESTS_ONLY)return()endif()+ladybird_test_suite(LibWebView)+set(TEST_SOURCESTestAccessibilityTreeManager.cppTestAudibilityHold.cppTestAudioServerAudibility.cpp- TestBackgroundNetworking.cppTestAutocompleteMuxer.cppTestAutocompleteRanker.cpp+ TestBackgroundNetworking.cppTestCanonicalBrowsingContextGroup.cppTestCookieJar.cppTestCrashReportDiagnostics.cpp@@ -169,8 +171,8 @@ set(TEST_SOURCESTestDownloadStore.cppTestExternalURLHandler.cppTestFaviconStore.cpp- TestHistoryStore.cppTestHelperProcessEnvironment.cpp+ TestHistoryStore.cppTestHSTSStore.cppTestNavigationLoader.cppTestOmnibox.cpp@@ -191,7 +193,13 @@ set(TEST_SOURCES)if (APPLE OR LINUX)- list(APPEND TEST_SOURCES TestCrashReport.cpp TestCrashReportReview.cpp TestCrashReportStore.cpp TestFontService.cpp TestRendererFontService.cpp)+ list(APPEND TEST_SOURCES+ TestCrashReport.cpp+ TestCrashReportReview.cpp+ TestCrashReportStore.cpp+ TestFontService.cpp+ TestRendererFontService.cpp+ )endif()if (APPLE)@@ -203,58 +211,73 @@ if (LINUX)endif()if (APPLE AND NOT IOS)- ladybird_test(TestWebDriverMachBootstrap.cpp LibWebView LIBS LibGfx LibIPC LibURL LibWebCommon LibWebSocket OpenSSL::Crypto OpenSSL::SSL)- target_sources(TestWebDriverMachBootstrap PRIVATE+ target_link_libraries(TestLibWebView PRIVATE LibWebSocket OpenSSL::Crypto OpenSSL::SSL)+ target_sources(TestLibWebView PRIVATE+ TestWebDriverMachBootstrap.cpp"${LADYBIRD_SOURCE_DIR}/Services/WebDriver/BiDiSession.cpp""${LADYBIRD_SOURCE_DIR}/Services/WebDriver/BrowserConnection.cpp""${LADYBIRD_SOURCE_DIR}/Services/WebDriver/Client.cpp""${LADYBIRD_SOURCE_DIR}/Services/WebDriver/Session.cpp""${LADYBIRD_SOURCE_DIR}/Services/WebDriver/WebSocket.cpp")- target_include_directories(TestWebDriverMachBootstrap PRIVATE "${LADYBIRD_SOURCE_DIR}/Services" "${CMAKE_BINARY_DIR}/Services")- set_tests_properties(TestWebDriverMachBootstrap PROPERTIES TIMEOUT 30)+ target_include_directories(TestLibWebView PRIVATE "${LADYBIRD_SOURCE_DIR}/Services" "${CMAKE_BINARY_DIR}/Services")+ set_tests_properties(TestLibWebView PROPERTIES TIMEOUT 120)endif()-foreach(source IN LISTS TEST_SOURCES)- set(test_libraries LibDatabase LibWebView LibURL)- if (source STREQUAL "TestProfile.cpp" OR source STREQUAL "TestDownloadSegmentation.cpp")- list(APPEND test_libraries LibHTTP)- endif()- if (source STREQUAL "TestAudioServerAudibility.cpp")- list(APPEND test_libraries LibAudio LibIPC)- endif()- if (source STREQUAL "TestPermissionManager.cpp")- list(APPEND test_libraries LibFileSystem LibWebCommon)- endif()- if (source STREQUAL "TestFontService.cpp")- list(APPEND test_libraries LibFileSystem LibIPC LibGfx)- endif()- if (source STREQUAL "TestRendererFontService.cpp")- list(APPEND test_libraries LibCompositing LibGfx LibIPC LibThreading)- endif()- ladybird_test("${source}" LibWebView LIBS ${test_libraries})-endforeach()+if (NOT WIN32)+ set(HEADLESS_TEST_SOURCES+ TestApplicationDestruction.cpp+ TestAutocomplete.cpp+ TestBeforeUnload.cpp+ TestBrowserHistoryTraversal.cpp+ TestCompositorInputRouting.cpp+ TestCrashOverlay.cpp+ TestCrashReportSubmission.cpp+ TestFavicon.cpp+ TestFileDownloader.cpp+ TestImageDecoderIsolation.cpp+ TestInputMethodState.cpp+ TestLinkHoverStatus.cpp+ TestNavigationDownloads.cpp+ TestPictureInPictureUserActivation.cpp+ TestPictureInPictureWindowControls.cpp+ TestPictureInPictureWindowLifetime.cpp+ TestRendererCookieAccess.cpp+ TestRendererOriginClaims.cpp+ TestRendererViolationReports.cpp+ TestRequestServerClientSessions.cpp+ TestShadowTreeTooltipsAndLinks.cpp+ TestTabPerformanceMonitor.cpp+ TestUserActivation.cpp+ TestWebCompatReport.cpp+ TestWebCompatReportPage.cpp+ )+ list(APPEND TEST_SOURCES ${HEADLESS_TEST_SOURCES})+endif()++target_sources(TestLibWebView PRIVATE ${TEST_SOURCES})+target_link_libraries(TestLibWebView PRIVATE LibAudio LibCompositing LibDatabase LibGfx LibHTTP LibIPC LibRequests LibThreading LibURL LibWeb LibWebCommon LibWebView)-if (TARGET TestProcessReaper)- add_dependencies(TestProcessReaper ProcessReaper)+if (APPLE)+ add_dependencies(TestLibWebView ProcessReaper)endif()-if (TARGET TestAudioDaemonSocket)+if (LINUX)include(audio)if (LADYBIRD_AUDIO_BACKEND STREQUAL "PULSE")- target_compile_definitions(TestAudioDaemonSocket PRIVATE HAVE_PULSEAUDIO=1)+ set_property(SOURCE TestAudioDaemonSocket.cpp APPEND PROPERTY COMPILE_DEFINITIONS HAVE_PULSEAUDIO=1)endif()endif()-if (TARGET TestCrashReport AND cpptrace_FOUND AND LADYBIRD_ENABLE_CPPTRACE)- target_compile_definitions(TestCrashReport PRIVATE TEST_HAS_CPPTRACE=1)+if ((APPLE OR LINUX) AND cpptrace_FOUND AND LADYBIRD_ENABLE_CPPTRACE)+ set_property(SOURCE TestCrashReport.cpp APPEND PROPERTY COMPILE_DEFINITIONS TEST_HAS_CPPTRACE=1)endif()-if (TARGET TestCrashReport AND LINUX AND CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")+if (LINUX AND CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")add_library(CrashReportLateLibrary SHARED CrashReportLateLibrary.cpp)- add_dependencies(TestCrashReport CrashReportLateLibrary)- target_compile_definitions(TestCrashReport PRIVATE TEST_CRASH_REPORT_LATE_LIBRARY="$<TARGET_FILE:CrashReportLateLibrary>")- target_link_libraries(TestCrashReport PRIVATE ${CMAKE_DL_LIBS})+ add_dependencies(TestLibWebView CrashReportLateLibrary)+ set_property(SOURCE TestCrashReport.cpp APPEND PROPERTY COMPILE_DEFINITIONS TEST_CRASH_REPORT_LATE_LIBRARY="$<TARGET_FILE:CrashReportLateLibrary>")+ target_link_libraries(TestLibWebView PRIVATE ${CMAKE_DL_LIBS})endif()if (APPLE OR LINUX)@@ -288,179 +311,14 @@ if (APPLE OR LINUX)endforeach()endif()-target_link_libraries(TestNavigationLoader PRIVATE LibRequests LibWeb)if (NOT WIN32)- ladybird_test(TestApplicationDestruction.cpp LibWebView LIBS LibCore LibDatabase LibFileSystem LibGfx LibIPC LibRequests LibURL LibWeb LibWebView)- if (APPLE)- target_compile_definitions(TestApplicationDestruction PRIVATE LADYBIRD_BINARY_PATH="$<TARGET_FILE_DIR:ladybird>")- endif()-- add_executable(TestAutocomplete TestAutocomplete.cpp)- add_dependencies(TestAutocomplete ${ladybird_helper_processes})- target_link_libraries(TestAutocomplete PRIVATE AK LibCore LibDiff LibFileSystem LibGfx LibImageDecoders LibImageDecoderClient LibIPC LibJS LibMain LibRequests LibURL LibWeb LibWebView)- if (APPLE)- target_compile_definitions(TestAutocomplete PRIVATE LADYBIRD_BINARY_PATH="$<TARGET_FILE_DIR:ladybird>")- endif()-- add_executable(TestFavicon TestFavicon.cpp)- add_dependencies(TestFavicon ${ladybird_helper_processes})- target_link_libraries(TestFavicon PRIVATE AK LibCore LibFileSystem LibGfx LibIPC LibMain LibRequests LibURL LibWeb LibWebView)- if (APPLE)- target_compile_definitions(TestFavicon PRIVATE LADYBIRD_BINARY_PATH="$<TARGET_FILE_DIR:ladybird>")- endif()-- add_executable(TestFileDownloader TestFileDownloader.cpp)- add_dependencies(TestFileDownloader ${ladybird_helper_processes})- target_link_libraries(TestFileDownloader PRIVATE AK LibCore LibDiff LibFileSystem LibGfx LibImageDecoders LibImageDecoderClient LibIPC LibJS LibMain LibRequests LibThreading LibURL LibWeb LibWebView)+ target_sources(TestLibWebView PRIVATE HeadlessTest.cpp)+ target_link_libraries(TestLibWebView PRIVATE LibCrypto LibDiff LibImageDecoders LibImageDecoderClient LibJS)+ add_dependencies(TestLibWebView ladybird_build_resource_files ${ladybird_helper_processes})+ set_tests_properties(TestLibWebView PROPERTIES TIMEOUT 1800 ENVIRONMENT LADYBIRD_SOURCE_DIR=${LADYBIRD_SOURCE_DIR})if (APPLE)- target_compile_definitions(TestFileDownloader PRIVATE LADYBIRD_BINARY_PATH="$<TARGET_FILE_DIR:ladybird>")- endif()-- add_executable(TestNavigationDownloads TestNavigationDownloads.cpp)- add_dependencies(TestNavigationDownloads ladybird_build_resource_files ${ladybird_helper_processes})- target_link_libraries(TestNavigationDownloads PRIVATE AK LibCore LibFileSystem LibGfx LibIPC LibMain LibThreading LibURL LibWeb LibWebView)- if (APPLE)- target_compile_definitions(TestNavigationDownloads PRIVATE LADYBIRD_BINARY_PATH="$<TARGET_FILE_DIR:ladybird>")- endif()-- add_executable(TestCrashOverlay TestCrashOverlay.cpp)- add_dependencies(TestCrashOverlay ladybird_build_resource_files ${ladybird_helper_processes})- target_link_libraries(TestCrashOverlay PRIVATE AK LibCore LibDiff LibFileSystem LibGfx LibImageDecoders LibImageDecoderClient LibIPC LibJS LibMain LibRequests LibURL LibWeb LibWebView)- if (APPLE)- target_compile_definitions(TestCrashOverlay PRIVATE LADYBIRD_BINARY_PATH="$<TARGET_FILE_DIR:ladybird>")- endif()-- add_executable(TestBrowserHistoryTraversal TestBrowserHistoryTraversal.cpp)- add_dependencies(TestBrowserHistoryTraversal ladybird_build_resource_files ${ladybird_helper_processes})- target_link_libraries(TestBrowserHistoryTraversal PRIVATE AK LibCore LibDiff LibFileSystem LibGfx LibHTTP LibImageDecoders LibImageDecoderClient LibIPC LibJS LibMain LibRequests LibURL LibWeb LibWebView)- if (APPLE)- target_compile_definitions(TestBrowserHistoryTraversal PRIVATE LADYBIRD_BINARY_PATH="$<TARGET_FILE_DIR:ladybird>")- endif()-- add_executable(TestBeforeUnload TestBeforeUnload.cpp)- add_dependencies(TestBeforeUnload ladybird_build_resource_files ${ladybird_helper_processes})- target_link_libraries(TestBeforeUnload PRIVATE AK LibCore LibFileSystem LibGfx LibImageDecoders LibImageDecoderClient LibIPC LibJS LibMain LibRequests LibURL LibWeb LibWebView)- if (APPLE)- target_compile_definitions(TestBeforeUnload PRIVATE LADYBIRD_BINARY_PATH="$<TARGET_FILE_DIR:ladybird>")- endif()-- add_executable(TestInputMethodState TestInputMethodState.cpp)- add_dependencies(TestInputMethodState ladybird_build_resource_files ${ladybird_helper_processes})- target_link_libraries(TestInputMethodState PRIVATE AK LibCore LibDiff LibFileSystem LibGfx LibImageDecoders LibImageDecoderClient LibIPC LibJS LibMain LibRequests LibURL LibWeb LibWebView)- if (APPLE)- target_compile_definitions(TestInputMethodState PRIVATE LADYBIRD_BINARY_PATH="$<TARGET_FILE_DIR:ladybird>")- endif()-- add_executable(TestLinkHoverStatus TestLinkHoverStatus.cpp)- add_dependencies(TestLinkHoverStatus ladybird_build_resource_files ${ladybird_helper_processes})- target_link_libraries(TestLinkHoverStatus PRIVATE AK LibCore LibDiff LibFileSystem LibGfx LibImageDecoders LibImageDecoderClient LibIPC LibJS LibMain LibRequests LibURL LibWeb LibWebView)- if (APPLE)- target_compile_definitions(TestLinkHoverStatus PRIVATE LADYBIRD_BINARY_PATH="$<TARGET_FILE_DIR:ladybird>")- endif()-- add_executable(TestUserActivation TestUserActivation.cpp)- add_dependencies(TestUserActivation ladybird_build_resource_files ${ladybird_helper_processes})- target_link_libraries(TestUserActivation PRIVATE AK LibCore LibDiff LibFileSystem LibGfx LibImageDecoders LibImageDecoderClient LibIPC LibJS LibMain LibRequests LibURL LibWeb LibWebView)- if (APPLE)- target_compile_definitions(TestUserActivation PRIVATE LADYBIRD_BINARY_PATH="$<TARGET_FILE_DIR:ladybird>")- endif()-- add_executable(TestPictureInPictureUserActivation TestPictureInPictureUserActivation.cpp)- add_dependencies(TestPictureInPictureUserActivation ladybird_build_resource_files ${ladybird_helper_processes})- target_link_libraries(TestPictureInPictureUserActivation PRIVATE AK LibCore LibDiff LibFileSystem LibGfx LibImageDecoders LibImageDecoderClient LibIPC LibJS LibMain LibRequests LibURL LibWeb LibWebView)- if (APPLE)- target_compile_definitions(TestPictureInPictureUserActivation PRIVATE LADYBIRD_BINARY_PATH="$<TARGET_FILE_DIR:ladybird>")- endif()-- add_executable(TestPictureInPictureWindowControls TestPictureInPictureWindowControls.cpp)- add_dependencies(TestPictureInPictureWindowControls ladybird_build_resource_files ${ladybird_helper_processes})- target_link_libraries(TestPictureInPictureWindowControls PRIVATE AK LibCore LibDiff LibFileSystem LibGfx LibImageDecoders LibImageDecoderClient LibIPC LibJS LibMain LibRequests LibURL LibWeb LibWebView)- if (APPLE)- target_compile_definitions(TestPictureInPictureWindowControls PRIVATE LADYBIRD_BINARY_PATH="$<TARGET_FILE_DIR:ladybird>")- endif()-- add_executable(TestPictureInPictureWindowLifetime TestPictureInPictureWindowLifetime.cpp)- add_dependencies(TestPictureInPictureWindowLifetime ladybird_build_resource_files ${ladybird_helper_processes})- target_link_libraries(TestPictureInPictureWindowLifetime PRIVATE AK LibCore LibFileSystem LibGfx LibIPC LibMain LibURL LibWeb LibWebView)- if (APPLE)- target_compile_definitions(TestPictureInPictureWindowLifetime PRIVATE LADYBIRD_BINARY_PATH="$<TARGET_FILE_DIR:ladybird>")- endif()-- add_executable(TestWebCompatReportPage TestWebCompatReportPage.cpp)- add_dependencies(TestWebCompatReportPage ladybird_build_resource_files ${ladybird_helper_processes})- target_link_libraries(TestWebCompatReportPage PRIVATE AK LibCore LibDiff LibFileSystem LibGfx LibImageDecoders LibImageDecoderClient LibIPC LibJS LibMain LibRequests LibURL LibWeb LibWebView)- if (APPLE)- target_compile_definitions(TestWebCompatReportPage PRIVATE LADYBIRD_BINARY_PATH="$<TARGET_FILE_DIR:ladybird>")- endif()-- add_executable(TestShadowTreeTooltipsAndLinks TestShadowTreeTooltipsAndLinks.cpp)- add_dependencies(TestShadowTreeTooltipsAndLinks ladybird_build_resource_files ${ladybird_helper_processes})- target_link_libraries(TestShadowTreeTooltipsAndLinks PRIVATE AK LibCore LibDiff LibFileSystem LibGfx LibImageDecoders LibImageDecoderClient LibIPC LibJS LibMain LibRequests LibURL LibWeb LibWebView)- if (APPLE)- target_compile_definitions(TestShadowTreeTooltipsAndLinks PRIVATE LADYBIRD_BINARY_PATH="$<TARGET_FILE_DIR:ladybird>")- endif()-- add_executable(TestCompositorInputRouting TestCompositorInputRouting.cpp)- add_dependencies(TestCompositorInputRouting ladybird_build_resource_files ${ladybird_helper_processes})- target_link_libraries(TestCompositorInputRouting PRIVATE AK LibCore LibDiff LibFileSystem LibGfx LibImageDecoders LibImageDecoderClient LibIPC LibJS LibMain LibRequests LibURL LibWeb LibWebView)- if (APPLE)- target_compile_definitions(TestCompositorInputRouting PRIVATE LADYBIRD_BINARY_PATH="$<TARGET_FILE_DIR:ladybird>")- endif()- add_executable(TestRendererCookieAccess TestRendererCookieAccess.cpp)- add_dependencies(TestRendererCookieAccess ladybird_build_resource_files ${ladybird_helper_processes})- target_link_libraries(TestRendererCookieAccess PRIVATE AK LibCore LibFileSystem LibGfx LibHTTP LibIPC LibMain LibURL LibWeb LibWebView)- if (APPLE)- target_compile_definitions(TestRendererCookieAccess PRIVATE LADYBIRD_BINARY_PATH="$<TARGET_FILE_DIR:ladybird>")- endif()-- add_executable(TestRendererOriginClaims TestRendererOriginClaims.cpp)- add_dependencies(TestRendererOriginClaims ladybird_build_resource_files ${ladybird_helper_processes})- target_link_libraries(TestRendererOriginClaims PRIVATE AK LibCore LibFileSystem LibGfx LibHTTP LibIPC LibMain LibURL LibWeb LibWebView)- if (APPLE)- target_compile_definitions(TestRendererOriginClaims PRIVATE LADYBIRD_BINARY_PATH="$<TARGET_FILE_DIR:ladybird>")- endif()-- add_executable(TestRendererViolationReports TestRendererViolationReports.cpp)- add_dependencies(TestRendererViolationReports ladybird_build_resource_files ${ladybird_helper_processes})- target_link_libraries(TestRendererViolationReports PRIVATE AK LibCore LibFileSystem LibGfx LibIPC LibMain LibThreading LibURL LibWeb LibWebView)- if (APPLE)- target_compile_definitions(TestRendererViolationReports PRIVATE LADYBIRD_BINARY_PATH="$<TARGET_FILE_DIR:ladybird>")- endif()-- add_executable(TestImageDecoderIsolation TestImageDecoderIsolation.cpp)- add_dependencies(TestImageDecoderIsolation ladybird_build_resource_files ${ladybird_helper_processes})- target_link_libraries(TestImageDecoderIsolation PRIVATE AK LibCore LibFileSystem LibGfx LibIPC LibMain LibWebView)- if (APPLE)- target_compile_definitions(TestImageDecoderIsolation PRIVATE LADYBIRD_BINARY_PATH="$<TARGET_FILE_DIR:ladybird>")- endif()-- add_executable(TestCrashReportSubmission TestCrashReportSubmission.cpp)- add_dependencies(TestCrashReportSubmission ${ladybird_helper_processes})- target_link_libraries(TestCrashReportSubmission PRIVATE AK LibCore LibCrypto LibFileSystem LibIPC LibMain LibWebView)- if (APPLE)- target_compile_definitions(TestCrashReportSubmission PRIVATE LADYBIRD_BINARY_PATH="$<TARGET_FILE_DIR:ladybird>")- endif()-- add_executable(TestWebCompatReport TestWebCompatReport.cpp)- add_dependencies(TestWebCompatReport ${ladybird_helper_processes})- target_link_libraries(TestWebCompatReport PRIVATE AK LibCore LibCrypto LibFileSystem LibIPC LibMain LibURL LibWebView)- if (APPLE)- target_compile_definitions(TestWebCompatReport PRIVATE LADYBIRD_BINARY_PATH="$<TARGET_FILE_DIR:ladybird>")- endif()-- add_executable(TestRequestServerClientSessions TestRequestServerClientSessions.cpp)- add_dependencies(TestRequestServerClientSessions ${ladybird_helper_processes})- target_link_libraries(TestRequestServerClientSessions PRIVATE AK LibCore LibDiff LibFileSystem LibGfx LibImageDecoders LibImageDecoderClient LibIPC LibJS LibMain LibRequests LibURL LibWeb LibWebView)- if (APPLE)- target_compile_definitions(TestRequestServerClientSessions PRIVATE LADYBIRD_BINARY_PATH="$<TARGET_FILE_DIR:ladybird>")- endif()-- add_executable(TestTabPerformanceMonitor TestTabPerformanceMonitor.cpp)- add_dependencies(TestTabPerformanceMonitor ladybird_build_resource_files ${ladybird_helper_processes})- target_link_libraries(TestTabPerformanceMonitor PRIVATE AK LibCore LibDiff LibFileSystem LibGfx LibImageDecoders LibImageDecoderClient LibIPC LibJS LibMain LibRequests LibURL LibWeb LibWebView)- if (APPLE)- target_compile_definitions(TestTabPerformanceMonitor PRIVATE LADYBIRD_BINARY_PATH="$<TARGET_FILE_DIR:ladybird>")+ target_compile_definitions(TestLibWebView PRIVATE LADYBIRD_BINARY_PATH="$<TARGET_FILE_DIR:ladybird>")endif()endif()@@ -471,67 +329,4 @@ if (BUILD_TESTING AND NOT WIN32)COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test-webdriver-bidi-cleanup.py)set_tests_properties(TestWebDriverBiDiCleanup PROPERTIES TIMEOUT 30)-- add_test(NAME TestAutocomplete COMMAND $<TARGET_FILE:TestAutocomplete>)- set_tests_properties(TestAutocomplete PROPERTIES TIMEOUT 60 ENVIRONMENT LADYBIRD_SOURCE_DIR=${LADYBIRD_SOURCE_DIR})-- add_test(NAME TestFavicon COMMAND $<TARGET_FILE:TestFavicon>)- set_tests_properties(TestFavicon PROPERTIES TIMEOUT 120 ENVIRONMENT LADYBIRD_SOURCE_DIR=${LADYBIRD_SOURCE_DIR})-- add_test(NAME TestFileDownloader COMMAND $<TARGET_FILE:TestFileDownloader>)- set_tests_properties(TestFileDownloader PROPERTIES TIMEOUT 120 ENVIRONMENT LADYBIRD_SOURCE_DIR=${LADYBIRD_SOURCE_DIR})-- add_test(NAME TestNavigationDownloads COMMAND $<TARGET_FILE:TestNavigationDownloads>)- set_tests_properties(TestNavigationDownloads PROPERTIES TIMEOUT 120 ENVIRONMENT LADYBIRD_SOURCE_DIR=${LADYBIRD_SOURCE_DIR})-- add_test(NAME TestCrashOverlay COMMAND $<TARGET_FILE:TestCrashOverlay>)- set_tests_properties(TestCrashOverlay PROPERTIES TIMEOUT 60 ENVIRONMENT LADYBIRD_SOURCE_DIR=${LADYBIRD_SOURCE_DIR})-- add_test(NAME TestBrowserHistoryTraversal COMMAND $<TARGET_FILE:TestBrowserHistoryTraversal>)- set_tests_properties(TestBrowserHistoryTraversal PROPERTIES TIMEOUT 60 ENVIRONMENT LADYBIRD_SOURCE_DIR=${LADYBIRD_SOURCE_DIR})-- add_test(NAME TestBeforeUnload COMMAND $<TARGET_FILE:TestBeforeUnload>)- set_tests_properties(TestBeforeUnload PROPERTIES TIMEOUT 60 ENVIRONMENT LADYBIRD_SOURCE_DIR=${LADYBIRD_SOURCE_DIR})-- add_test(NAME TestInputMethodState COMMAND $<TARGET_FILE:TestInputMethodState>)- set_tests_properties(TestInputMethodState PROPERTIES TIMEOUT 60 ENVIRONMENT LADYBIRD_SOURCE_DIR=${LADYBIRD_SOURCE_DIR})-- add_test(NAME TestLinkHoverStatus COMMAND $<TARGET_FILE:TestLinkHoverStatus>)- set_tests_properties(TestLinkHoverStatus PROPERTIES TIMEOUT 60 ENVIRONMENT LADYBIRD_SOURCE_DIR=${LADYBIRD_SOURCE_DIR})-- add_test(NAME TestUserActivation COMMAND $<TARGET_FILE:TestUserActivation>)- set_tests_properties(TestUserActivation PROPERTIES TIMEOUT 60 ENVIRONMENT LADYBIRD_SOURCE_DIR=${LADYBIRD_SOURCE_DIR})-- add_test(NAME TestPictureInPictureUserActivation COMMAND $<TARGET_FILE:TestPictureInPictureUserActivation>)- set_tests_properties(TestPictureInPictureUserActivation PROPERTIES TIMEOUT 60 ENVIRONMENT LADYBIRD_SOURCE_DIR=${LADYBIRD_SOURCE_DIR})-- add_test(NAME TestPictureInPictureWindowControls COMMAND $<TARGET_FILE:TestPictureInPictureWindowControls>)- set_tests_properties(TestPictureInPictureWindowControls PROPERTIES TIMEOUT 60 ENVIRONMENT LADYBIRD_SOURCE_DIR=${LADYBIRD_SOURCE_DIR})-- add_test(NAME TestPictureInPictureWindowLifetime COMMAND $<TARGET_FILE:TestPictureInPictureWindowLifetime>)- set_tests_properties(TestPictureInPictureWindowLifetime PROPERTIES TIMEOUT 60 ENVIRONMENT LADYBIRD_SOURCE_DIR=${LADYBIRD_SOURCE_DIR})-- add_test(NAME TestWebCompatReportPage COMMAND $<TARGET_FILE:TestWebCompatReportPage>)- set_tests_properties(TestWebCompatReportPage PROPERTIES TIMEOUT 60 ENVIRONMENT LADYBIRD_SOURCE_DIR=${LADYBIRD_SOURCE_DIR})- add_test(NAME TestShadowTreeTooltipsAndLinks COMMAND $<TARGET_FILE:TestShadowTreeTooltipsAndLinks>)- set_tests_properties(TestShadowTreeTooltipsAndLinks PROPERTIES TIMEOUT 60 ENVIRONMENT LADYBIRD_SOURCE_DIR=${LADYBIRD_SOURCE_DIR})-- add_test(NAME TestCompositorInputRouting COMMAND $<TARGET_FILE:TestCompositorInputRouting>)- set_tests_properties(TestCompositorInputRouting PROPERTIES TIMEOUT 60 ENVIRONMENT LADYBIRD_SOURCE_DIR=${LADYBIRD_SOURCE_DIR})- add_test(NAME TestRendererCookieAccess COMMAND $<TARGET_FILE:TestRendererCookieAccess>)- set_tests_properties(TestRendererCookieAccess PROPERTIES TIMEOUT 60 ENVIRONMENT LADYBIRD_SOURCE_DIR=${LADYBIRD_SOURCE_DIR})- add_test(NAME TestRendererOriginClaims COMMAND $<TARGET_FILE:TestRendererOriginClaims>)- set_tests_properties(TestRendererOriginClaims PROPERTIES TIMEOUT 60 ENVIRONMENT LADYBIRD_SOURCE_DIR=${LADYBIRD_SOURCE_DIR})- add_test(NAME TestRendererViolationReports COMMAND $<TARGET_FILE:TestRendererViolationReports>)- set_tests_properties(TestRendererViolationReports PROPERTIES TIMEOUT 60 ENVIRONMENT LADYBIRD_SOURCE_DIR=${LADYBIRD_SOURCE_DIR})- add_test(NAME TestImageDecoderIsolation COMMAND $<TARGET_FILE:TestImageDecoderIsolation>)- set_tests_properties(TestImageDecoderIsolation PROPERTIES TIMEOUT 60 ENVIRONMENT LADYBIRD_SOURCE_DIR=${LADYBIRD_SOURCE_DIR})- add_test(NAME TestCrashReportSubmission COMMAND $<TARGET_FILE:TestCrashReportSubmission>)- set_tests_properties(TestCrashReportSubmission PROPERTIES TIMEOUT 60 ENVIRONMENT LADYBIRD_SOURCE_DIR=${LADYBIRD_SOURCE_DIR})- add_test(NAME TestWebCompatReport COMMAND $<TARGET_FILE:TestWebCompatReport>)- set_tests_properties(TestWebCompatReport PROPERTIES TIMEOUT 60 ENVIRONMENT LADYBIRD_SOURCE_DIR=${LADYBIRD_SOURCE_DIR})- add_test(NAME TestRequestServerClientSessions COMMAND $<TARGET_FILE:TestRequestServerClientSessions>)- set_tests_properties(TestRequestServerClientSessions PROPERTIES TIMEOUT 60 ENVIRONMENT LADYBIRD_SOURCE_DIR=${LADYBIRD_SOURCE_DIR})- add_test(NAME TestTabPerformanceMonitor COMMAND $<TARGET_FILE:TestTabPerformanceMonitor>)- set_tests_properties(TestTabPerformanceMonitor PROPERTIES TIMEOUT 60 ENVIRONMENT LADYBIRD_SOURCE_DIR=${LADYBIRD_SOURCE_DIR})endif()diff --git a/Tests/LibWebView/HeadlessTest.cpp b/Tests/LibWebView/HeadlessTest.cppnew file mode 100644index 00000000000..d4262745d18--- /dev/null+++ b/Tests/LibWebView/HeadlessTest.cpp@@ -0,0 +1,62 @@+/*+ * Copyright (c) 2026-present, the Ladybird developers.+ *+ * SPDX-License-Identifier: BSD-2-Clause+ */++#include "HeadlessTest.h"+#include <AK/Random.h>+#include <LibCore/Directory.h>+#include <LibCore/Environment.h>+#include <LibCore/StandardPaths.h>+#include <LibCore/System.h>+#include <LibCore/ThreadEventQueue.h>+#include <LibFileSystem/FileSystem.h>+#include <time.h>+#include <unistd.h>++namespace Test {++HeadlessApplication::HeadlessApplication(Optional<ByteString> ladybird_binary_path)+ : WebView::Application(move(ladybird_binary_path))+{+}++void HeadlessApplication::create_platform_options(WebView::BrowserOptions& browser_options, WebView::RequestServerOptions&, WebView::WebContentOptions& web_content_options)+{+ browser_options.headless_mode = WebView::HeadlessMode::Test;+ browser_options.disable_sql_database = WebView::DisableSQLDatabase::Yes;+ web_content_options.is_test_mode = WebView::IsTestMode::Yes;+}++HeadlessTestEnvironment::HeadlessTestEnvironment(StringView name, unsigned timeout_seconds)+ : m_directory(ByteString::formatted("{}/Ladybird-{}-{}", Core::StandardPaths::tempfile_directory(), name, generate_random_uuid()))+{+ // Each source suite runs in a fresh process. Keep its deadline even if its event loop stops making progress.+ alarm(timeout_seconds);++ MUST(Core::Directory::create(m_directory, Core::Directory::CreateDirectories::Yes));+ MUST(Core::Environment::set("XDG_CONFIG_HOME"sv, m_directory, Core::Environment::Overwrite::Yes));++ tzset();+ if (auto result = Core::System::set_resource_limits(RLIMIT_NOFILE, 65536); result.is_error())+ warnln("Unable to increase open file limit: {}", result.error());+}++HeadlessTestEnvironment::~HeadlessTestEnvironment()+{+ Core::ThreadEventQueue::destroy_current();+ MUST(FileSystem::remove(m_directory, FileSystem::RecursionMode::Allowed));+ alarm(0);+}++Optional<ByteString> HeadlessTestEnvironment::ladybird_binary_path()+{+#if defined(LADYBIRD_BINARY_PATH)+ return LADYBIRD_BINARY_PATH;+#else+ return {};+#endif+}++}diff --git a/Tests/LibWebView/HeadlessTest.h b/Tests/LibWebView/HeadlessTest.hnew file mode 100644index 00000000000..49b03d5579c--- /dev/null+++ b/Tests/LibWebView/HeadlessTest.h@@ -0,0 +1,51 @@+/*+ * Copyright (c) 2026-present, the Ladybird developers.+ *+ * SPDX-License-Identifier: BSD-2-Clause+ */++#pragma once++#include <AK/Array.h>+#include <LibCore/EventLoop.h>+#include <LibWebView/Application.h>++namespace Test {++class HeadlessApplication : public WebView::Application {+ WEB_VIEW_APPLICATION(HeadlessApplication)++public:+ explicit HeadlessApplication(Optional<ByteString> ladybird_binary_path);++private:+ virtual void create_platform_options(WebView::BrowserOptions&, WebView::RequestServerOptions&, WebView::WebContentOptions&) override;+ virtual Core::EventLoop& create_platform_event_loop() override { return Core::EventLoop::current(); }+ virtual bool should_coordinate_browser_process() const override { return false; }+};++class HeadlessTestEnvironment {+public:+ explicit HeadlessTestEnvironment(StringView name, unsigned timeout_seconds = 60);+ ~HeadlessTestEnvironment();++ HeadlessTestEnvironment(HeadlessTestEnvironment const&) = delete;+ HeadlessTestEnvironment& operator=(HeadlessTestEnvironment const&) = delete;++ ByteString const& directory() const { return m_directory; }++ template<typename ApplicationType = HeadlessApplication>+ ErrorOr<NonnullOwnPtr<ApplicationType>> create_application()+ {+ return ApplicationType::create({ .strings = m_arguments }, ladybird_binary_path());+ }++private:+ static Optional<ByteString> ladybird_binary_path();++ ByteString m_directory;+ Array<StringView, 1> m_arguments { "TestLibWebView"sv };+ Core::EventLoop m_event_loop;+};++}diff --git a/Tests/LibWebView/ReportServer.h b/Tests/LibWebView/ReportServer.hindex dde60e8ecef..72e202ef1cd 100644--- a/Tests/LibWebView/ReportServer.h+++ b/Tests/LibWebView/ReportServer.h@@ -6,6 +6,7 @@#pragma once+#include "HeadlessTest.h"#include <AK/ByteBuffer.h>#include <AK/ByteString.h>#include <AK/HashMap.h>@@ -22,12 +23,12 @@namespace ReportServerTest {-class TestApplication : public WebView::Application {+class TestApplication : public Test::HeadlessApplication {WEB_VIEW_APPLICATION(TestApplication)public:explicit TestApplication(Optional<ByteString> ladybird_binary_path)- : WebView::Application(move(ladybird_binary_path))+ : Test::HeadlessApplication(move(ladybird_binary_path)){}@@ -36,8 +37,6 @@ public:browser_options.headless_mode = WebView::HeadlessMode::Test;browser_options.disable_sql_database = WebView::DisableSQLDatabase::Yes;}-- virtual bool should_coordinate_browser_process() const override { return false; }};struct ReceivedRequest {diff --git a/Tests/LibWebView/TestAutocomplete.cpp b/Tests/LibWebView/TestAutocomplete.cppindex 2b288818f62..3083e5e5e8c 100644--- a/Tests/LibWebView/TestAutocomplete.cpp+++ b/Tests/LibWebView/TestAutocomplete.cpp@@ -4,14 +4,10 @@* SPDX-License-Identifier: BSD-2-Clause*/-#include <AK/Random.h>-#include <AK/ScopeGuard.h>+#include "HeadlessTest.h"#include <AK/String.h>-#include <LibCore/Directory.h>#include <LibCore/EventLoop.h>-#include <LibCore/StandardPaths.h>-#include <LibFileSystem/FileSystem.h>-#include <LibMain/Main.h>+#include <LibTest/TestCase.h>#include <LibWebView/Application.h>#include <LibWebView/Autocomplete.h>#include <LibWebView/AutocompleteService.h>@@ -33,12 +29,12 @@ public:}};-class TestApplication : public WebView::Application {+class TestApplication : public Test::HeadlessApplication {WEB_VIEW_APPLICATION(TestApplication)public:explicit TestApplication(Optional<ByteString> ladybird_binary_path)- : WebView::Application(move(ladybird_binary_path))+ : Test::HeadlessApplication(move(ladybird_binary_path)){}@@ -49,8 +45,6 @@ public:web_content_options.is_test_mode = WebView::IsTestMode::Yes;}- virtual bool should_coordinate_browser_process() const override { return false; }-virtual void resolve_external_url_handler(URL::URL const& url, WebView::ExternalURLHandlerCallback callback) const override{m_pending_external_url_handler_queries.append({ url, move(callback) });@@ -88,20 +82,11 @@ private:// That cancel runs while the request's completion callback is still on the stack — so, tearing the request down freed a// callback mid-call, and tripped an assert. Regression test for #10278.-ErrorOr<int> ladybird_main(Main::Arguments arguments)+TEST_CASE(autocomplete){- auto test_config_directory = ByteString::formatted("{}/Ladybird-TestAutocomplete-{}", Core::StandardPaths::tempfile_directory(), generate_random_uuid());- TRY(Core::Directory::create(test_config_directory, Core::Directory::CreateDirectories::Yes));- auto cleanup_test_config_directory = ScopeGuard([&] {- MUST(FileSystem::remove(test_config_directory, FileSystem::RecursionMode::Allowed));- });- VERIFY(setenv("XDG_CONFIG_HOME", test_config_directory.characters(), 1) == 0);+ Test::HeadlessTestEnvironment environment { "TestAutocomplete"sv };-#if defined(LADYBIRD_BINARY_PATH)- auto app = TRY(TestApplication::create(arguments, LADYBIRD_BINARY_PATH));-#else- auto app = TRY(TestApplication::create(arguments, OptionalNone {}));-#endif+ auto app = TRY_OR_FAIL(environment.create_application<TestApplication>());WebView::Application::settings().set_search_engine_settings({});WebView::Application::autocomplete_service().update_bookmarks({ {@@ -462,5 +447,4 @@ ErrorOr<int> ladybird_main(Main::Arguments arguments)Core::EventLoop::current().spin_until([&]() { return request_completed; });outln("PASS: cancel_pending_query during query completion did not crash");- return 0;}diff --git a/Tests/LibWebView/TestBeforeUnload.cpp b/Tests/LibWebView/TestBeforeUnload.cppindex 6fa560ed62c..47e24924489 100644--- a/Tests/LibWebView/TestBeforeUnload.cpp+++ b/Tests/LibWebView/TestBeforeUnload.cpp@@ -4,43 +4,19 @@* SPDX-License-Identifier: BSD-2-Clause*/+#include "HeadlessTest.h"#include <AK/LexicalPath.h>-#include <AK/Random.h>-#include <AK/ScopeGuard.h>-#include <LibCore/Directory.h>#include <LibCore/EventLoop.h>-#include <LibCore/StandardPaths.h>-#include <LibFileSystem/FileSystem.h>#include <LibGfx/SystemTheme.h>-#include <LibMain/Main.h>+#include <LibTest/TestCase.h>#include <LibURL/Parser.h>#include <LibWeb/UIEvents/InputEvent.h>-#include <LibWebView/Application.h>#include <LibWebView/HeadlessWebView.h>#include <LibWebView/Utilities.h>#include <stdlib.h>namespace {-class TestApplication : public WebView::Application {- WEB_VIEW_APPLICATION(TestApplication)--public:- explicit TestApplication(Optional<ByteString> ladybird_binary_path)- : WebView::Application(move(ladybird_binary_path))- {- }-- virtual void create_platform_options(WebView::BrowserOptions& browser_options, WebView::RequestServerOptions&, WebView::WebContentOptions& web_content_options) override- {- browser_options.headless_mode = WebView::HeadlessMode::Test;- browser_options.disable_sql_database = WebView::DisableSQLDatabase::Yes;- web_content_options.is_test_mode = WebView::IsTestMode::Yes;- }-- virtual bool should_coordinate_browser_process() const override { return false; }-};-void click(WebView::ViewImplementation& view){view.enqueue_input_event(Web::MouseEvent {@@ -65,23 +41,14 @@ void click(WebView::ViewImplementation& view)}-ErrorOr<int> ladybird_main(Main::Arguments arguments)+TEST_CASE(before_unload){- auto test_config_directory = ByteString::formatted("{}/Ladybird-TestBeforeUnload-{}", Core::StandardPaths::tempfile_directory(), generate_random_uuid());- TRY(Core::Directory::create(test_config_directory, Core::Directory::CreateDirectories::Yes));- auto cleanup_test_config_directory = ScopeGuard([&] {- MUST(FileSystem::remove(test_config_directory, FileSystem::RecursionMode::Allowed));- });- VERIFY(setenv("XDG_CONFIG_HOME", test_config_directory.characters(), 1) == 0);+ Test::HeadlessTestEnvironment environment { "TestBeforeUnload"sv };-#if defined(LADYBIRD_BINARY_PATH)- auto app = TRY(TestApplication::create(arguments, LADYBIRD_BINARY_PATH));-#else- auto app = TRY(TestApplication::create(arguments, OptionalNone {}));-#endif+ auto app = TRY_OR_FAIL(environment.create_application());auto theme_path = LexicalPath::join(WebView::s_ladybird_resource_root, "themes"sv, "Default.ini"sv);- auto theme = TRY(Gfx::load_system_theme(theme_path.string()));+ auto theme = TRY_OR_FAIL(Gfx::load_system_theme(theme_path.string()));auto view = WebView::HeadlessWebView::create(move(theme), { 800, 600 });size_t loads_finished = 0;@@ -194,5 +161,4 @@ ErrorOr<int> ladybird_main(Main::Arguments arguments)Core::EventLoop::current().spin_until([&] { return closed; });outln("PASS: beforeunload prompt handling");- return 0;}diff --git a/Tests/LibWebView/TestBrowserHistoryTraversal.cpp b/Tests/LibWebView/TestBrowserHistoryTraversal.cppindex 7b6a5802cb7..3610e256fc5 100644--- a/Tests/LibWebView/TestBrowserHistoryTraversal.cpp+++ b/Tests/LibWebView/TestBrowserHistoryTraversal.cpp@@ -4,20 +4,16 @@* SPDX-License-Identifier: BSD-2-Clause*/+#include "HeadlessTest.h"#include <AK/LexicalPath.h>-#include <AK/Random.h>-#include <AK/ScopeGuard.h>#include <AK/String.h>-#include <LibCore/Directory.h>#include <LibCore/EventLoop.h>#include <LibCore/File.h>-#include <LibCore/StandardPaths.h>#include <LibCore/Timer.h>-#include <LibFileSystem/FileSystem.h>#include <LibGfx/SystemTheme.h>#include <LibHTTP/Cookie/ParsedCookie.h>#include <LibIPC/Transport.h>-#include <LibMain/Main.h>+#include <LibTest/TestCase.h>#include <LibURL/Parser.h>#include <LibWebCommon/Page/InputEvent.h>#include <LibWebCommon/UIEvents/KeyCode.h>@@ -32,12 +28,12 @@namespace {-class TestApplication : public WebView::Application {+class TestApplication : public Test::HeadlessApplication {WEB_VIEW_APPLICATION(TestApplication)public:explicit TestApplication(Optional<ByteString> ladybird_binary_path)- : WebView::Application(move(ladybird_binary_path))+ : Test::HeadlessApplication(move(ladybird_binary_path)){}@@ -56,8 +52,6 @@ public:web_content_options.file_scheme_urls_have_tuple_origins = WebView::FileSchemeUrlsHaveTupleOrigins::Yes;}- virtual bool should_coordinate_browser_process() const override { return false; }-virtual Optional<WebView::ViewImplementation&> open_blank_new_tab(Web::HTML::ActivateTab) const override{++m_new_tab_requests;@@ -103,23 +97,15 @@ void press_history_traversal_button(WebView::ViewImplementation& view, Web::UIEv// The browser's back and forward keys are matched in the UI process once WebContent reports them unhandled, so a// page's keydown handler must be able to consume them, and an unconsumed press must traverse the session history.-ErrorOr<int> ladybird_main(Main::Arguments arguments)+TEST_CASE(browser_history_traversal){- auto test_config_directory = ByteString::formatted("{}/Ladybird-TestBrowserHistoryTraversal-{}", Core::StandardPaths::tempfile_directory(), generate_random_uuid());- TRY(Core::Directory::create(test_config_directory, Core::Directory::CreateDirectories::Yes));- auto cleanup_test_config_directory = ScopeGuard([&] {- MUST(FileSystem::remove(test_config_directory, FileSystem::RecursionMode::Allowed));- });- VERIFY(setenv("XDG_CONFIG_HOME", test_config_directory.characters(), 1) == 0);+ Test::HeadlessTestEnvironment environment { "TestBrowserHistoryTraversal"sv };+ auto const& test_config_directory = environment.directory();-#if defined(LADYBIRD_BINARY_PATH)- auto app = TRY(TestApplication::create(arguments, LADYBIRD_BINARY_PATH));-#else- auto app = TRY(TestApplication::create(arguments, OptionalNone {}));-#endif+ auto app = TRY_OR_FAIL(environment.create_application<TestApplication>());auto theme_path = LexicalPath::join(WebView::s_ladybird_resource_root, "themes"sv, "Default.ini"sv);- auto theme = TRY(Gfx::load_system_theme(theme_path.string()));+ auto theme = TRY_OR_FAIL(Gfx::load_system_theme(theme_path.string()));auto view = WebView::HeadlessWebView::create(theme, { 800, 600 });@@ -280,7 +266,7 @@ ErrorOr<int> ladybird_main(Main::Arguments arguments)// Take the spare, so the restored view launches a process of its own the way a private window's tab does. A// spare is relaunched from a deferred task, so none is available until the event loop next runs.- auto restored_theme = TRY(Gfx::load_system_theme(theme_path.string()));+ auto restored_theme = TRY_OR_FAIL(Gfx::load_system_theme(theme_path.string()));auto spare_consumer = WebView::HeadlessWebView::create(restored_theme, { 800, 600 });VERIFY(!app->has_spare_web_content_process());@@ -365,7 +351,7 @@ ErrorOr<int> ladybird_main(Main::Arguments arguments)// An initial page can read cookies before the UI adopts it into a view.{- auto transport = TRY(IPC::Transport::create_paired());+ auto transport = TRY_OR_FAIL(IPC::Transport::create_paired());auto initial_page_id = app->allocate_page_id();auto initial_client = adopt_ref(*new WebView::WebContentClient(move(transport.local), client.is_private(), initial_page_id, app->allocate_ui_process_cross_process_id()));VERIFY(!initial_client->page(initial_page_id));@@ -377,8 +363,8 @@ ErrorOr<int> ladybird_main(Main::Arguments arguments){auto reload_view = WebView::HeadlessWebView::create(restored_theme, { 800, 600 });auto reload_page_path = ByteString::formatted("{}/reload.html", test_config_directory);- auto reload_page = TRY(Core::File::open(reload_page_path, Core::File::OpenMode::Write));- TRY(reload_page->write_until_depleted("<script>navigation.onnavigate=()=>alert('navigate')</script>reload"sv.bytes()));+ auto reload_page = TRY_OR_FAIL(Core::File::open(reload_page_path, Core::File::OpenMode::Write));+ TRY_OR_FAIL(reload_page->write_until_depleted("<script>navigation.onnavigate=()=>alert('navigate')</script>reload"sv.bytes()));reload_page->close();auto reload_url = URL::create_with_file_scheme(reload_page_path).release_value();size_t reload_url_loads_finished = 0;@@ -413,9 +399,9 @@ ErrorOr<int> ladybird_main(Main::Arguments arguments)TRY(file->write_until_depleted(contents.bytes()));return URL::create_with_file_scheme(path).release_value();};- auto slow_unload_url = TRY(write_page("slow-unload.html"sv, "<script>addEventListener('unload', () => { const end = performance.now() + 1000; while (performance.now() < end) {} });</script>"sv));- auto activated_url = TRY(write_page("activated.html"sv, "activated"sv));- auto newer_url = TRY(write_page("newer.html"sv, "newer"sv));+ auto slow_unload_url = TRY_OR_FAIL(write_page("slow-unload.html"sv, "<script>addEventListener('unload', () => { const end = performance.now() + 1000; while (performance.now() < end) {} });</script>"sv));+ auto activated_url = TRY_OR_FAIL(write_page("activated.html"sv, "activated"sv));+ auto newer_url = TRY_OR_FAIL(write_page("newer.html"sv, "newer"sv));Vector<URL::URL> loads_finished;view->on_load_finish = [&](URL::URL const& url) { loads_finished.append(url); };view->load(slow_unload_url);@@ -439,5 +425,4 @@ ErrorOr<int> ladybird_main(Main::Arguments arguments)VERIFY(!client.is_open());outln("PASS: browser history traversal");- return 0;}diff --git a/Tests/LibWebView/TestCompositorInputRouting.cpp b/Tests/LibWebView/TestCompositorInputRouting.cppindex 493d8b1775e..e8198786193 100644--- a/Tests/LibWebView/TestCompositorInputRouting.cpp+++ b/Tests/LibWebView/TestCompositorInputRouting.cpp@@ -4,44 +4,19 @@* SPDX-License-Identifier: BSD-2-Clause*/+#include "HeadlessTest.h"#include <AK/LexicalPath.h>-#include <AK/Random.h>-#include <AK/ScopeGuard.h>#include <AK/String.h>#include <AK/Utf16String.h>-#include <LibCore/Directory.h>-#include <LibCore/Environment.h>#include <LibCore/EventLoop.h>-#include <LibCore/StandardPaths.h>-#include <LibFileSystem/FileSystem.h>#include <LibGfx/SystemTheme.h>-#include <LibMain/Main.h>+#include <LibTest/TestCase.h>#include <LibWebCommon/Page/InputEvent.h>-#include <LibWebView/Application.h>#include <LibWebView/HeadlessWebView.h>#include <LibWebView/Utilities.h>namespace {-class TestApplication : public WebView::Application {- WEB_VIEW_APPLICATION(TestApplication)--public:- explicit TestApplication(Optional<ByteString> ladybird_binary_path)- : WebView::Application(move(ladybird_binary_path))- {- }-- virtual void create_platform_options(WebView::BrowserOptions& browser_options, WebView::RequestServerOptions&, WebView::WebContentOptions& web_content_options) override- {- browser_options.headless_mode = WebView::HeadlessMode::Test;- browser_options.disable_sql_database = WebView::DisableSQLDatabase::Yes;- web_content_options.is_test_mode = WebView::IsTestMode::Yes;- }-- virtual bool should_coordinate_browser_process() const override { return false; }-};-void scroll_wheel_at(WebView::ViewImplementation& view, Web::DevicePixelPoint position, double wheel_delta_y){view.enqueue_input_event(Web::MouseEvent {@@ -95,23 +70,14 @@ void cancel_mouse_press(WebView::ViewImplementation& view)// the same way. Either way the pending queue drains, which is what lets later compositor key scrolling proceed. A press// that the UI cancels reaches the page along the same route, so the page sees its pointer stream suppressed.-ErrorOr<int> ladybird_main(Main::Arguments arguments)+TEST_CASE(compositor_input_routing){- auto test_config_directory = ByteString::formatted("{}/Ladybird-TestCompositorInputRouting-{}", Core::StandardPaths::tempfile_directory(), generate_random_uuid());- TRY(Core::Directory::create(test_config_directory, Core::Directory::CreateDirectories::Yes));- auto cleanup_test_config_directory = ScopeGuard([&] {- MUST(FileSystem::remove(test_config_directory, FileSystem::RecursionMode::Allowed));- });- MUST(Core::Environment::set("XDG_CONFIG_HOME"sv, test_config_directory, Core::Environment::Overwrite::Yes));+ Test::HeadlessTestEnvironment environment { "TestCompositorInputRouting"sv };-#if defined(LADYBIRD_BINARY_PATH)- auto app = TRY(TestApplication::create(arguments, LADYBIRD_BINARY_PATH));-#else- auto app = TRY(TestApplication::create(arguments, OptionalNone {}));-#endif+ auto app = TRY_OR_FAIL(environment.create_application());auto theme_path = LexicalPath::join(WebView::s_ladybird_resource_root, "themes"sv, "Default.ini"sv);- auto theme = TRY(Gfx::load_system_theme(theme_path.string()));+ auto theme = TRY_OR_FAIL(Gfx::load_system_theme(theme_path.string()));auto view = WebView::HeadlessWebView::create(move(theme), { 800, 600 });@@ -155,5 +121,4 @@ addEventListener("pointercancel", () => { document.title = "press cancelled"; })Core::EventLoop::current().spin_until([&]() { return view->pending_input_event_count_for_testing() == 0; });outln("PASS: mouse input routed through the compositor scrolls the page, reaches it and settles the UI's pending events");- return 0;}diff --git a/Tests/LibWebView/TestCrashOverlay.cpp b/Tests/LibWebView/TestCrashOverlay.cppindex e551800ab75..7219df2d18e 100644--- a/Tests/LibWebView/TestCrashOverlay.cpp+++ b/Tests/LibWebView/TestCrashOverlay.cpp@@ -4,17 +4,14 @@* SPDX-License-Identifier: BSD-2-Clause*/+#include "HeadlessTest.h"#include <AK/LexicalPath.h>#include <AK/Random.h>-#include <AK/ScopeGuard.h>#include <AK/String.h>#include <LibCore/ArgsParser.h>-#include <LibCore/Directory.h>#include <LibCore/EventLoop.h>-#include <LibCore/StandardPaths.h>-#include <LibFileSystem/FileSystem.h>#include <LibGfx/SystemTheme.h>-#include <LibMain/Main.h>+#include <LibTest/TestCase.h>#include <LibURL/Parser.h>#include <LibWebView/Application.h>#include <LibWebView/CanonicalDocument.h>@@ -24,12 +21,12 @@namespace {-class TestApplication : public WebView::Application {+class TestApplication : public Test::HeadlessApplication {WEB_VIEW_APPLICATION(TestApplication)public:explicit TestApplication(Optional<ByteString> ladybird_binary_path)- : WebView::Application(move(ladybird_binary_path))+ : Test::HeadlessApplication(move(ladybird_binary_path)){}@@ -39,35 +36,20 @@ public:browser_options.disable_sql_database = WebView::DisableSQLDatabase::Yes;web_content_options.is_test_mode = WebView::IsTestMode::Yes;}-- virtual void create_platform_arguments(Core::ArgsParser& parser) override- {- parser.add_option(m_bidi_reload_only, "Run only the BiDi reload crash recovery case", "bidi-reload-only");- }-- bool bidi_reload_only() const { return m_bidi_reload_only; }- virtual bool should_coordinate_browser_process() const override { return false; }--private:- bool m_bidi_reload_only { false };};}-ErrorOr<int> ladybird_main(Main::Arguments arguments)+static void test_crash_overlay(bool bidi_reload_only){- auto test_directory = ByteString::formatted("{}/Ladybird-TestCrashOverlay-{}", Core::StandardPaths::tempfile_directory(), generate_random_uuid());- TRY(Core::Directory::create(test_directory, Core::Directory::CreateDirectories::Yes));- ScopeGuard cleanup = [&] { MUST(FileSystem::remove(test_directory, FileSystem::RecursionMode::Allowed)); };- VERIFY(setenv("XDG_CONFIG_HOME", test_directory.characters(), 1) == 0);+ Test::HeadlessTestEnvironment environment { "TestCrashOverlay"sv };+ auto const& test_directory = environment.directory();+VERIFY(setenv("XDG_DATA_HOME", test_directory.characters(), 1) == 0);-#if defined(LADYBIRD_BINARY_PATH)- auto app = TRY(TestApplication::create(arguments, LADYBIRD_BINARY_PATH));-#else- auto app = TRY(TestApplication::create(arguments, OptionalNone {}));-#endif++ auto app = TRY_OR_FAIL(environment.create_application<TestApplication>());auto theme_path = LexicalPath::join(WebView::s_ladybird_resource_root, "themes"sv, "Default.ini"sv);- auto theme = TRY(Gfx::load_system_theme(theme_path.string()));+ auto theme = TRY_OR_FAIL(Gfx::load_system_theme(theme_path.string()));auto view = WebView::HeadlessWebView::create(theme, { 1000, 700 });size_t loads_finished = 0;view->on_load_finish = [&](auto const&) { ++loads_finished; };@@ -129,13 +111,13 @@ ErrorOr<int> ladybird_main(Main::Arguments arguments)view->on_ready_to_paint = nullptr;};- if (app->bidi_reload_only()) {+ if (bidi_reload_only) {check_bidi_reload();VERIFY(view->url() == failed_url);VERIFY(evaluate("document.body.textContent === 'original-page-content'"sv).as_bool());VERIFY(session_history.used_step_count() == 2);outln("PASS: BiDi reload recovers the crash overlay");- return 0;+ return;}crash_and_wait_for_screen();@@ -184,5 +166,14 @@ ErrorOr<int> ladybird_main(Main::Arguments arguments)VERIFY(evaluate("document.body.textContent === 'loaded-html'"sv).as_bool());VERIFY(session_history.used_step_count() == 5);outln("PASS: native crash overlay state, reload and history");- return 0;+}++TEST_CASE(crash_overlay)+{+ test_crash_overlay(false);+}++TEST_CASE(bidi_crash_recovery)+{+ test_crash_overlay(true);}diff --git a/Tests/LibWebView/TestCrashReportSubmission.cpp b/Tests/LibWebView/TestCrashReportSubmission.cppindex 88aab97a815..6be3043e153 100644--- a/Tests/LibWebView/TestCrashReportSubmission.cpp+++ b/Tests/LibWebView/TestCrashReportSubmission.cpp@@ -4,20 +4,18 @@* SPDX-License-Identifier: BSD-2-Clause*/+#include "HeadlessTest.h"#include "ReportServer.h"#include <AK/JsonArray.h>#include <AK/JsonObject.h>#include <AK/JsonValue.h>#include <AK/LexicalPath.h>-#include <AK/Random.h>-#include <AK/ScopeGuard.h>#include <LibCore/Directory.h>#include <LibCore/Environment.h>#include <LibCore/EventLoop.h>#include <LibCore/File.h>-#include <LibCore/StandardPaths.h>#include <LibFileSystem/FileSystem.h>-#include <LibMain/Main.h>+#include <LibTest/TestCase.h>#include <LibWebView/CrashReportReview.h>using namespace ReportServerTest;@@ -68,20 +66,14 @@ ByteString write_report(ByteString const& directory, StringView name)}-ErrorOr<int> ladybird_main(Main::Arguments arguments)+TEST_CASE(crash_report_submission){- auto test_directory = ByteString::formatted("{}/Ladybird-TestCrashReportSubmission-{}", Core::StandardPaths::tempfile_directory(), generate_random_uuid());- TRY(Core::Directory::create(test_directory, Core::Directory::CreateDirectories::Yes));- auto cleanup_test_directory = ScopeGuard([&] {- MUST(FileSystem::remove(test_directory, FileSystem::RecursionMode::Allowed));- });+ Test::HeadlessTestEnvironment environment { "TestCrashReportSubmission"sv };+ auto const& test_directory = environment.directory();+MUST(Core::Environment::set("XDG_CONFIG_HOME"sv, LexicalPath::join(test_directory, "config"sv).string(), Core::Environment::Overwrite::Yes));-#if defined(LADYBIRD_BINARY_PATH)- auto app = TRY(TestApplication::create(arguments, LADYBIRD_BINARY_PATH));-#else- auto app = TRY(TestApplication::create(arguments, OptionalNone {}));-#endif+ auto app = TRY_OR_FAIL(environment.create_application<TestApplication>());ReportServer server;MUST(Core::Environment::set("LADYBIRD_REPORTS_ENDPOINT"sv, server.endpoint(), Core::Environment::Overwrite::Yes));@@ -219,5 +211,4 @@ ErrorOr<int> ladybird_main(Main::Arguments arguments)VERIFY(server.requests[1].path == "/api/v1/reports"sv);outln("PASS: Crash reports reach the report server in the format it expects");- return 0;}diff --git a/Tests/LibWebView/TestFavicon.cpp b/Tests/LibWebView/TestFavicon.cppindex 76cc96e0c2d..fbcaa79b942 100644--- a/Tests/LibWebView/TestFavicon.cpp+++ b/Tests/LibWebView/TestFavicon.cpp@@ -4,57 +4,20 @@* SPDX-License-Identifier: BSD-2-Clause*/-#include <AK/Random.h>-#include <LibCore/Directory.h>-#include <LibCore/Environment.h>-#include <LibCore/StandardPaths.h>-#include <LibFileSystem/FileSystem.h>+#include "HeadlessTest.h"#include <LibGfx/SystemTheme.h>-#include <LibMain/Main.h>-#include <LibWebView/Application.h>+#include <LibTest/TestCase.h>#include <LibWebView/HeadlessWebView.h>#include <LibWebView/Utilities.h>-namespace {--class TestApplication : public WebView::Application {- WEB_VIEW_APPLICATION(TestApplication)--public:- explicit TestApplication(Optional<ByteString> ladybird_binary_path)- : WebView::Application(move(ladybird_binary_path))- {- }-- virtual void create_platform_options(WebView::BrowserOptions& browser_options, WebView::RequestServerOptions&, WebView::WebContentOptions& web_content_options) override- {- browser_options.headless_mode = WebView::HeadlessMode::Test;- browser_options.disable_sql_database = WebView::DisableSQLDatabase::Yes;- web_content_options.is_test_mode = WebView::IsTestMode::Yes;- }-- virtual bool should_coordinate_browser_process() const override { return false; }-};--}--ErrorOr<int> ladybird_main(Main::Arguments arguments)+TEST_CASE(favicon){- auto test_config_directory = ByteString::formatted("{}/Ladybird-TestFavicon-{}", Core::StandardPaths::tempfile_directory(), generate_random_uuid());- TRY(Core::Directory::create(test_config_directory, Core::Directory::CreateDirectories::Yes));- auto cleanup_test_config_directory = ScopeGuard([&] {- MUST(FileSystem::remove(test_config_directory, FileSystem::RecursionMode::Allowed));- });- MUST(Core::Environment::set("XDG_CONFIG_HOME"sv, test_config_directory, Core::Environment::Overwrite::Yes));--#if defined(LADYBIRD_BINARY_PATH)- auto app = TRY(TestApplication::create(arguments, LADYBIRD_BINARY_PATH));-#else- auto app = TRY(TestApplication::create(arguments, OptionalNone {}));-#endif+ Test::HeadlessTestEnvironment environment { "TestFavicon"sv, 120 };++ auto app = TRY_OR_FAIL(environment.create_application());auto theme_path = LexicalPath::join(WebView::s_ladybird_resource_root, "themes"sv, "Default.ini"sv);- auto theme = TRY(Gfx::load_system_theme(theme_path.string()));+ auto theme = TRY_OR_FAIL(Gfx::load_system_theme(theme_path.string()));auto view = WebView::HeadlessWebView::create(move(theme), { 800, 600 });@@ -148,6 +111,4 @@ ErrorOr<int> ladybird_main(Main::Arguments arguments)Core::EventLoop::current().spin_until([&]() { return favicon_changed; });}-- return 0;}diff --git a/Tests/LibWebView/TestFileDownloader.cpp b/Tests/LibWebView/TestFileDownloader.cppindex 46315a15a87..e6ce1ea45c5 100644--- a/Tests/LibWebView/TestFileDownloader.cpp+++ b/Tests/LibWebView/TestFileDownloader.cpp@@ -4,22 +4,19 @@* SPDX-License-Identifier: BSD-2-Clause*/+#include "HeadlessTest.h"#include <AK/ByteString.h>#include <AK/Mutex.h>-#include <AK/Random.h>#include <AK/ScopeGuard.h>#include <AK/String.h>#include <AK/StringBuilder.h>-#include <LibCore/Directory.h>#include <LibCore/EventLoop.h>#include <LibCore/File.h>-#include <LibCore/StandardPaths.h>#include <LibCore/System.h>#include <LibCore/Timer.h>-#include <LibFileSystem/FileSystem.h>-#include <LibMain/Main.h>#include <LibRequests/Request.h>#include <LibRequests/RequestClient.h>+#include <LibTest/TestCase.h>#include <LibThreading/Thread.h>#include <LibURL/Parser.h>#include <LibWebView/Application.h>@@ -30,25 +27,6 @@namespace {-class TestApplication : public WebView::Application {- WEB_VIEW_APPLICATION(TestApplication)--public:- explicit TestApplication(Optional<ByteString> ladybird_binary_path)- : WebView::Application(move(ladybird_binary_path))- {- }-- virtual void create_platform_options(WebView::BrowserOptions& browser_options, WebView::RequestServerOptions&, WebView::WebContentOptions& web_content_options) override- {- browser_options.headless_mode = WebView::HeadlessMode::Test;- browser_options.disable_sql_database = WebView::DisableSQLDatabase::Yes;- web_content_options.is_test_mode = WebView::IsTestMode::Yes;- }-- virtual bool should_coordinate_browser_process() const override { return false; }-};-enum class RangeSupport {Yes,No,@@ -549,23 +527,15 @@ void expect_leased_request_is_torn_down_when_transferred_after_finishing(TestHtt}-ErrorOr<int> ladybird_main(Main::Arguments arguments)+TEST_CASE(file_downloader){- auto test_directory = ByteString::formatted("{}/Ladybird-TestFileDownloader-{}", Core::StandardPaths::tempfile_directory(), generate_random_uuid());- TRY(Core::Directory::create(test_directory, Core::Directory::CreateDirectories::Yes));- auto cleanup_test_directory = ScopeGuard([&] {- MUST(FileSystem::remove(test_directory, FileSystem::RecursionMode::Allowed));- });- VERIFY(setenv("XDG_CONFIG_HOME", test_directory.characters(), 1) == 0);- VERIFY(setenv("XDG_DOWNLOAD_DIR", test_directory.characters(), 1) == 0);+ Test::HeadlessTestEnvironment environment { "TestFileDownloader"sv, 120 };+ auto const& test_directory = environment.directory();+ VERIFY(setenv("XDG_DOWNLOAD_DIR", test_directory.characters(), 1) == 0);signal(SIGPIPE, SIG_IGN);-#if defined(LADYBIRD_BINARY_PATH)- auto app = TRY(TestApplication::create(arguments, LADYBIRD_BINARY_PATH));-#else- auto app = TRY(TestApplication::create(arguments, OptionalNone {}));-#endif+ auto app = TRY_OR_FAIL(environment.create_application());{auto response_body = make_body(4 * KiB);@@ -786,5 +756,4 @@ ErrorOr<int> ladybird_main(Main::Arguments arguments)}outln("PASS");- return 0;}diff --git a/Tests/LibWebView/TestImageDecoderIsolation.cpp b/Tests/LibWebView/TestImageDecoderIsolation.cppindex c774f618732..650050012e7 100644--- a/Tests/LibWebView/TestImageDecoderIsolation.cpp+++ b/Tests/LibWebView/TestImageDecoderIsolation.cpp@@ -4,18 +4,13 @@* SPDX-License-Identifier: BSD-2-Clause*/+#include "HeadlessTest.h"#include <AK/HashTable.h>#include <AK/LexicalPath.h>-#include <AK/Random.h>-#include <AK/ScopeGuard.h>-#include <LibCore/Directory.h>-#include <LibCore/Environment.h>#include <LibCore/EventLoop.h>-#include <LibCore/StandardPaths.h>#include <LibCore/System.h>-#include <LibFileSystem/FileSystem.h>#include <LibGfx/SystemTheme.h>-#include <LibMain/Main.h>+#include <LibTest/TestCase.h>#include <LibWebView/Application.h>#include <LibWebView/HeadlessWebView.h>#include <LibWebView/ProcessManager.h>@@ -24,12 +19,12 @@namespace {-class TestApplication : public WebView::Application {+class TestApplication : public Test::HeadlessApplication {WEB_VIEW_APPLICATION(TestApplication)public:explicit TestApplication(Optional<ByteString> ladybird_binary_path)- : WebView::Application(move(ladybird_binary_path))+ : Test::HeadlessApplication(move(ladybird_binary_path)){}@@ -38,8 +33,6 @@ public:browser_options.headless_mode = WebView::HeadlessMode::Test;browser_options.disable_sql_database = WebView::DisableSQLDatabase::Yes;}-- virtual bool should_coordinate_browser_process() const override { return false; }};HashTable<pid_t> processes_of_type(WebView::ProcessType type)@@ -57,23 +50,14 @@ HashTable<pid_t> processes_of_type(WebView::ProcessType type)// An ImageDecoder parses untrusted images, so each renderer has one of its own, and never sees another's images. A// decoder that crashes is replaced for its renderer alone.-ErrorOr<int> ladybird_main(Main::Arguments arguments)+TEST_CASE(image_decoder_isolation){- auto test_config_directory = ByteString::formatted("{}/Ladybird-TestImageDecoderIsolation-{}", Core::StandardPaths::tempfile_directory(), generate_random_uuid());- TRY(Core::Directory::create(test_config_directory, Core::Directory::CreateDirectories::Yes));- auto cleanup_test_config_directory = ScopeGuard([&] {- MUST(FileSystem::remove(test_config_directory, FileSystem::RecursionMode::Allowed));- });- MUST(Core::Environment::set("XDG_CONFIG_HOME"sv, test_config_directory, Core::Environment::Overwrite::Yes));+ Test::HeadlessTestEnvironment environment { "TestImageDecoderIsolation"sv };-#if defined(LADYBIRD_BINARY_PATH)- auto app = TRY(TestApplication::create(arguments, LADYBIRD_BINARY_PATH));-#else- auto app = TRY(TestApplication::create(arguments, OptionalNone {}));-#endif+ auto app = TRY_OR_FAIL(environment.create_application<TestApplication>());auto theme_path = LexicalPath::join(WebView::s_ladybird_resource_root, "themes"sv, "Default.ini"sv);- auto theme = TRY(Gfx::load_system_theme(theme_path.string()));+ auto theme = TRY_OR_FAIL(Gfx::load_system_theme(theme_path.string()));auto first_view = WebView::HeadlessWebView::create(theme, { 800, 600 });auto second_view = WebView::HeadlessWebView::create(theme, { 800, 600 });@@ -84,7 +68,7 @@ ErrorOr<int> ladybird_main(Main::Arguments arguments)VERIFY(decoders.size() == renderers.size());auto crashed_decoder = *decoders.begin();- TRY(Core::System::kill(crashed_decoder, SIGKILL));+ TRY_OR_FAIL(Core::System::kill(crashed_decoder, SIGKILL));// The replacement is launched as the Browser learns that the decoder died, so this cannot finish without it.Core::EventLoop::current().spin_until([&] {@@ -100,5 +84,4 @@ ErrorOr<int> ladybird_main(Main::Arguments arguments)}outln("PASS: each renderer has an image decoder of its own, which is replaced alone when it crashes");- return 0;}diff --git a/Tests/LibWebView/TestInputMethodState.cpp b/Tests/LibWebView/TestInputMethodState.cppindex 6686f98d0a2..48da23c52d2 100644--- a/Tests/LibWebView/TestInputMethodState.cpp+++ b/Tests/LibWebView/TestInputMethodState.cpp@@ -4,45 +4,17 @@* SPDX-License-Identifier: BSD-2-Clause*/+#include "HeadlessTest.h"#include <AK/LexicalPath.h>-#include <AK/Random.h>-#include <AK/ScopeGuard.h>#include <AK/String.h>#include <AK/Utf16String.h>-#include <LibCore/Directory.h>#include <LibCore/EventLoop.h>-#include <LibCore/StandardPaths.h>-#include <LibFileSystem/FileSystem.h>#include <LibGfx/SystemTheme.h>-#include <LibMain/Main.h>-#include <LibWebView/Application.h>+#include <LibTest/TestCase.h>#include <LibWebView/HeadlessWebView.h>#include <LibWebView/Utilities.h>#include <stdlib.h>-namespace {--class TestApplication : public WebView::Application {- WEB_VIEW_APPLICATION(TestApplication)--public:- explicit TestApplication(Optional<ByteString> ladybird_binary_path)- : WebView::Application(move(ladybird_binary_path))- {- }-- virtual void create_platform_options(WebView::BrowserOptions& browser_options, WebView::RequestServerOptions&, WebView::WebContentOptions& web_content_options) override- {- browser_options.headless_mode = WebView::HeadlessMode::Test;- browser_options.disable_sql_database = WebView::DisableSQLDatabase::Yes;- web_content_options.is_test_mode = WebView::IsTestMode::Yes;- }-- virtual bool should_coordinate_browser_process() const override { return false; }-};--}-// WebContent pushes fresh IME state (caret, cursoranchor positions, surrounding text) to the UI on every editing step,// and platform IMEs compose against the UI-side copy of that state. The UI view must be notified of every push (not// just the first) so it can invalidate whatever the platform IME has cached: The Qt port answers inputMethodQuery()@@ -50,23 +22,14 @@ public:// 1st-keystroke state and drops everything after the first committed character. See #9712: on_input_method_state_change// must fire for each state push, after the new state is already readable through input_method_state().-ErrorOr<int> ladybird_main(Main::Arguments arguments)+TEST_CASE(input_method_state){- auto test_config_directory = ByteString::formatted("{}/Ladybird-TestInputMethodState-{}", Core::StandardPaths::tempfile_directory(), generate_random_uuid());- TRY(Core::Directory::create(test_config_directory, Core::Directory::CreateDirectories::Yes));- auto cleanup_test_config_directory = ScopeGuard([&] {- MUST(FileSystem::remove(test_config_directory, FileSystem::RecursionMode::Allowed));- });- VERIFY(setenv("XDG_CONFIG_HOME", test_config_directory.characters(), 1) == 0);--#if defined(LADYBIRD_BINARY_PATH)- auto app = TRY(TestApplication::create(arguments, LADYBIRD_BINARY_PATH));-#else- auto app = TRY(TestApplication::create(arguments, OptionalNone {}));-#endif+ Test::HeadlessTestEnvironment environment { "TestInputMethodState"sv };++ auto app = TRY_OR_FAIL(environment.create_application());auto theme_path = LexicalPath::join(WebView::s_ladybird_resource_root, "themes"sv, "Default.ini"sv);- auto theme = TRY(Gfx::load_system_theme(theme_path.string()));+ auto theme = TRY_OR_FAIL(Gfx::load_system_theme(theme_path.string()));auto view = WebView::HeadlessWebView::create(move(theme), { 800, 600 });@@ -199,5 +162,4 @@ ErrorOr<int> ladybird_main(Main::Arguments arguments)VERIFY(observed_state.text_before_cursor.is_empty());outln("PASS: every input-method state change notified the view");- return 0;}diff --git a/Tests/LibWebView/TestLinkHoverStatus.cpp b/Tests/LibWebView/TestLinkHoverStatus.cppindex efcc2d3b604..23631c5edc8 100644--- a/Tests/LibWebView/TestLinkHoverStatus.cpp+++ b/Tests/LibWebView/TestLinkHoverStatus.cpp@@ -4,45 +4,20 @@* SPDX-License-Identifier: BSD-2-Clause*/+#include "HeadlessTest.h"#include <AK/LexicalPath.h>-#include <AK/Random.h>-#include <AK/ScopeGuard.h>#include <AK/String.h>#include <AK/Utf16String.h>-#include <LibCore/Directory.h>-#include <LibCore/Environment.h>#include <LibCore/EventLoop.h>-#include <LibCore/StandardPaths.h>-#include <LibFileSystem/FileSystem.h>#include <LibGfx/SystemTheme.h>-#include <LibMain/Main.h>+#include <LibTest/TestCase.h>#include <LibWebCommon/HTML/VisibilityState.h>#include <LibWebCommon/Page/InputEvent.h>-#include <LibWebView/Application.h>#include <LibWebView/HeadlessWebView.h>#include <LibWebView/Utilities.h>namespace {-class TestApplication : public WebView::Application {- WEB_VIEW_APPLICATION(TestApplication)--public:- explicit TestApplication(Optional<ByteString> ladybird_binary_path)- : WebView::Application(move(ladybird_binary_path))- {- }-- virtual void create_platform_options(WebView::BrowserOptions& browser_options, WebView::RequestServerOptions&, WebView::WebContentOptions& web_content_options) override- {- browser_options.headless_mode = WebView::HeadlessMode::Test;- browser_options.disable_sql_database = WebView::DisableSQLDatabase::Yes;- web_content_options.is_test_mode = WebView::IsTestMode::Yes;- }-- virtual bool should_coordinate_browser_process() const override { return false; }-};-void move_mouse_to(WebView::ViewImplementation& view, Web::DevicePixelPoint position){view.enqueue_input_event(Web::MouseEvent {@@ -73,23 +48,14 @@ void leave_view(WebView::ViewImplementation& view)// outgoing document, and a keyboard navigation moves no pointer. But only the handler that reported the hover ends it// that way: an iframe navigating underneath a hover in its parent document leaves the parent's link reported.-ErrorOr<int> ladybird_main(Main::Arguments arguments)+TEST_CASE(link_hover_status){- auto test_config_directory = ByteString::formatted("{}/Ladybird-TestLinkHoverStatus-{}", Core::StandardPaths::tempfile_directory(), generate_random_uuid());- TRY(Core::Directory::create(test_config_directory, Core::Directory::CreateDirectories::Yes));- auto cleanup_test_config_directory = ScopeGuard([&] {- MUST(FileSystem::remove(test_config_directory, FileSystem::RecursionMode::Allowed));- });- MUST(Core::Environment::set("XDG_CONFIG_HOME"sv, test_config_directory, Core::Environment::Overwrite::Yes));+ Test::HeadlessTestEnvironment environment { "TestLinkHoverStatus"sv };-#if defined(LADYBIRD_BINARY_PATH)- auto app = TRY(TestApplication::create(arguments, LADYBIRD_BINARY_PATH));-#else- auto app = TRY(TestApplication::create(arguments, OptionalNone {}));-#endif+ auto app = TRY_OR_FAIL(environment.create_application());auto theme_path = LexicalPath::join(WebView::s_ladybird_resource_root, "themes"sv, "Default.ini"sv);- auto theme = TRY(Gfx::load_system_theme(theme_path.string()));+ auto theme = TRY_OR_FAIL(Gfx::load_system_theme(theme_path.string()));auto view = WebView::HeadlessWebView::create(move(theme), { 800, 600 });@@ -225,5 +191,4 @@ function navigate_frame() { frame.srcdoc = frame.getAttribute("srcdoc") + "<!--VERIFY(hovers_reported == 9);outln("PASS: a MouseLeave or a document replacement ends the link hover, and the next move over the link reports it again");- return 0;}diff --git a/Tests/LibWebView/TestNavigationDownloads.cpp b/Tests/LibWebView/TestNavigationDownloads.cppindex 23c542c642a..3468e3f50cc 100644--- a/Tests/LibWebView/TestNavigationDownloads.cpp+++ b/Tests/LibWebView/TestNavigationDownloads.cpp@@ -4,24 +4,19 @@* SPDX-License-Identifier: BSD-2-Clause*/+#include "HeadlessTest.h"#include <AK/Array.h>#include <AK/Atomic.h>#include <AK/LexicalPath.h>-#include <AK/Random.h>-#include <AK/ScopeGuard.h>#include <AK/StringBuilder.h>-#include <LibCore/Directory.h>#include <LibCore/EventLoop.h>#include <LibCore/File.h>-#include <LibCore/StandardPaths.h>#include <LibCore/System.h>#include <LibCore/Timer.h>-#include <LibFileSystem/FileSystem.h>#include <LibGfx/SystemTheme.h>-#include <LibMain/Main.h>+#include <LibTest/TestCase.h>#include <LibThreading/Thread.h>#include <LibURL/Parser.h>-#include <LibWebView/Application.h>#include <LibWebView/FileDownloader.h>#include <LibWebView/HeadlessWebView.h>#include <LibWebView/Utilities.h>@@ -32,25 +27,6 @@namespace {-class TestApplication : public WebView::Application {- WEB_VIEW_APPLICATION(TestApplication)--public:- explicit TestApplication(Optional<ByteString> ladybird_binary_path)- : WebView::Application(move(ladybird_binary_path))- {- }-- virtual void create_platform_options(WebView::BrowserOptions& browser_options, WebView::RequestServerOptions&, WebView::WebContentOptions& web_content_options) override- {- browser_options.headless_mode = WebView::HeadlessMode::Test;- browser_options.disable_sql_database = WebView::DisableSQLDatabase::Yes;- web_content_options.is_test_mode = WebView::IsTestMode::Yes;- }-- virtual bool should_coordinate_browser_process() const override { return false; }-};-// Answers a request for its page with a small document, and every other request with the same response, pausing// after the first pause_after bytes of its body when given.class TestHttpServer {@@ -280,27 +256,19 @@ void expect_navigation_downloads_cached_body(Core::AnonymousBuffer const& theme,}-ErrorOr<int> ladybird_main(Main::Arguments arguments)+TEST_CASE(navigation_downloads){- auto test_directory = ByteString::formatted("{}/Ladybird-TestNavigationDownloads-{}", Core::StandardPaths::tempfile_directory(), generate_random_uuid());- TRY(Core::Directory::create(test_directory, Core::Directory::CreateDirectories::Yes));- auto cleanup_test_directory = ScopeGuard([&] {- MUST(FileSystem::remove(test_directory, FileSystem::RecursionMode::Allowed));- });- VERIFY(setenv("XDG_CONFIG_HOME", test_directory.characters(), 1) == 0);+ Test::HeadlessTestEnvironment environment { "TestNavigationDownloads"sv, 120 };+ auto const& test_directory = environment.directory();+VERIFY(setenv("XDG_CACHE_HOME", test_directory.characters(), 1) == 0);VERIFY(setenv("XDG_DOWNLOAD_DIR", test_directory.characters(), 1) == 0);-signal(SIGPIPE, SIG_IGN);-#if defined(LADYBIRD_BINARY_PATH)- auto app = TRY(TestApplication::create(arguments, LADYBIRD_BINARY_PATH));-#else- auto app = TRY(TestApplication::create(arguments, OptionalNone {}));-#endif+ auto app = TRY_OR_FAIL(environment.create_application());auto theme_path = LexicalPath::join(WebView::s_ladybird_resource_root, "themes"sv, "Default.ini"sv);- auto theme = TRY(Gfx::load_system_theme(theme_path.string()));+ auto theme = TRY_OR_FAIL(Gfx::load_system_theme(theme_path.string()));auto body = make_body(1 * MiB);expect_navigation_downloads_body(theme, "an attachment"sv, "Content-Disposition: attachment; filename=\"attachment.bin\"\r\n"sv, body);@@ -310,5 +278,4 @@ ErrorOr<int> ladybird_main(Main::Arguments arguments)expect_navigation_downloads_cached_body(theme, "an attachment from the disk cache"sv, "Cache-Control: max-age=3600\r\nContent-Disposition: attachment; filename=\"attachment.bin\"\r\n"sv, body);outln("PASS: navigation responses download byte for byte");- return 0;}diff --git a/Tests/LibWebView/TestPictureInPictureUserActivation.cpp b/Tests/LibWebView/TestPictureInPictureUserActivation.cppindex 92ab3b1af53..dd1e455491e 100644--- a/Tests/LibWebView/TestPictureInPictureUserActivation.cpp+++ b/Tests/LibWebView/TestPictureInPictureUserActivation.cpp@@ -4,19 +4,14 @@* SPDX-License-Identifier: BSD-2-Clause*/+#include "HeadlessTest.h"#include <AK/LexicalPath.h>-#include <AK/Random.h>-#include <AK/ScopeGuard.h>#include <AK/String.h>#include <AK/Vector.h>-#include <LibCore/Directory.h>-#include <LibCore/Environment.h>#include <LibCore/EventLoop.h>-#include <LibCore/StandardPaths.h>#include <LibCore/System.h>-#include <LibFileSystem/FileSystem.h>#include <LibGfx/SystemTheme.h>-#include <LibMain/Main.h>+#include <LibTest/TestCase.h>#include <LibWebCommon/Page/InputEvent.h>#include <LibWebView/Application.h>#include <LibWebView/HeadlessWebView.h>@@ -61,12 +56,12 @@ private:NonnullOwnPtr<WebView::PictureInPictureWindow> m_window;};-class TestApplication : public WebView::Application {+class TestApplication : public Test::HeadlessApplication {WEB_VIEW_APPLICATION(TestApplication)public:explicit TestApplication(Optional<ByteString> ladybird_binary_path)- : WebView::Application(move(ladybird_binary_path))+ : Test::HeadlessApplication(move(ladybird_binary_path)){}@@ -80,8 +75,6 @@ public:browser_options.allow_popups = WebView::AllowPopups::Yes;}- virtual bool should_coordinate_browser_process() const override { return false; }-virtual OwnPtr<WebView::PictureInPictureWindow> create_picture_in_picture_window(WebView::WebContentPage& requesting_page, WebView::CanonicalTraversable& traversable, Gfx::IntSize video_size) override{auto window = WebView::Application::create_picture_in_picture_window(requesting_page, traversable, video_size);@@ -141,24 +134,15 @@ constexpr auto video_url = "data:video/webm;base64,"// it may replace with one for another of its videos. The window is gone as soon as the user closes it, whatever its// renderer does, and the document needs that activation again, even before its page has heard that the window closed.-ErrorOr<int> ladybird_main(Main::Arguments arguments)+TEST_CASE(picture_in_picture_user_activation){- auto test_config_directory = ByteString::formatted("{}/Ladybird-TestPictureInPictureUserActivation-{}", Core::StandardPaths::tempfile_directory(), generate_random_uuid());- TRY(Core::Directory::create(test_config_directory, Core::Directory::CreateDirectories::Yes));- auto cleanup_test_config_directory = ScopeGuard([&] {- MUST(FileSystem::remove(test_config_directory, FileSystem::RecursionMode::Allowed));- });- MUST(Core::Environment::set("XDG_CONFIG_HOME"sv, test_config_directory, Core::Environment::Overwrite::Yes));+ Test::HeadlessTestEnvironment environment { "TestPictureInPictureUserActivation"sv };-#if defined(LADYBIRD_BINARY_PATH)- auto app = TRY(TestApplication::create(arguments, LADYBIRD_BINARY_PATH));-#else- auto app = TRY(TestApplication::create(arguments, OptionalNone {}));-#endif+ auto app = TRY_OR_FAIL(environment.create_application<TestApplication>());VERIFY(!app->blocks_pop_ups());auto theme_path = LexicalPath::join(WebView::s_ladybird_resource_root, "themes"sv, "Default.ini"sv);- auto theme = TRY(Gfx::load_system_theme(theme_path.string()));+ auto theme = TRY_OR_FAIL(Gfx::load_system_theme(theme_path.string()));auto view = WebView::HeadlessWebView::create(move(theme), { 800, 600 });@@ -217,6 +201,4 @@ ErrorOr<int> ladybird_main(Main::Arguments arguments)VERIFY(last_title == "first InvalidStateError"sv);VERIFY(app->opened_windows.size() == 2);outln("a document needs a click again once the user closes its window");-- return 0;}diff --git a/Tests/LibWebView/TestPictureInPictureWindowControls.cpp b/Tests/LibWebView/TestPictureInPictureWindowControls.cppindex 391fa3bb5d1..f4b4ac9ff62 100644--- a/Tests/LibWebView/TestPictureInPictureWindowControls.cpp+++ b/Tests/LibWebView/TestPictureInPictureWindowControls.cpp@@ -4,22 +4,17 @@* SPDX-License-Identifier: BSD-2-Clause*/+#include "HeadlessTest.h"#include <AK/LexicalPath.h>-#include <AK/Random.h>-#include <AK/ScopeGuard.h>#include <AK/String.h>#include <AK/Utf16String.h>#include <AK/Vector.h>-#include <LibCore/Directory.h>-#include <LibCore/Environment.h>#include <LibCore/EventLoop.h>-#include <LibCore/StandardPaths.h>#include <LibCore/System.h>#include <LibCore/Timer.h>-#include <LibFileSystem/FileSystem.h>#include <LibGfx/Cursor.h>#include <LibGfx/SystemTheme.h>-#include <LibMain/Main.h>+#include <LibTest/TestCase.h>#include <LibWebCommon/Page/InputEvent.h>#include <LibWebView/Application.h>#include <LibWebView/HeadlessWebView.h>@@ -30,12 +25,12 @@namespace {-class TestApplication : public WebView::Application {+class TestApplication : public Test::HeadlessApplication {WEB_VIEW_APPLICATION(TestApplication)public:explicit TestApplication(Optional<ByteString> ladybird_binary_path)- : WebView::Application(move(ladybird_binary_path))+ : Test::HeadlessApplication(move(ladybird_binary_path)){}@@ -46,8 +41,6 @@ public:web_content_options.is_test_mode = WebView::IsTestMode::Yes;}- virtual bool should_coordinate_browser_process() const override { return false; }-virtual OwnPtr<WebView::PictureInPictureWindow> create_picture_in_picture_window(WebView::WebContentPage& requesting_page, WebView::CanonicalTraversable& traversable, Gfx::IntSize video_size) override{auto window = WebView::Application::create_picture_in_picture_window(requesting_page, traversable, video_size);@@ -134,23 +127,14 @@ bool is_cursor(Gfx::Cursor const& cursor, Gfx::StandardCursor standard_cursor)// and show their own cursor and tooltip in place of the page's while hovered. They work while the page's renderer is// stopped.-ErrorOr<int> ladybird_main(Main::Arguments arguments)+TEST_CASE(picture_in_picture_window_controls){- auto test_config_directory = ByteString::formatted("{}/Ladybird-TestPictureInPictureWindowControls-{}", Core::StandardPaths::tempfile_directory(), generate_random_uuid());- TRY(Core::Directory::create(test_config_directory, Core::Directory::CreateDirectories::Yes));- auto cleanup_test_config_directory = ScopeGuard([&] {- MUST(FileSystem::remove(test_config_directory, FileSystem::RecursionMode::Allowed));- });- MUST(Core::Environment::set("XDG_CONFIG_HOME"sv, test_config_directory, Core::Environment::Overwrite::Yes));+ Test::HeadlessTestEnvironment environment { "TestPictureInPictureWindowControls"sv };-#if defined(LADYBIRD_BINARY_PATH)- auto app = TRY(TestApplication::create(arguments, LADYBIRD_BINARY_PATH));-#else- auto app = TRY(TestApplication::create(arguments, OptionalNone {}));-#endif+ auto app = TRY_OR_FAIL(environment.create_application<TestApplication>());auto theme_path = LexicalPath::join(WebView::s_ladybird_resource_root, "themes"sv, "Default.ini"sv);- auto theme = TRY(Gfx::load_system_theme(theme_path.string()));+ auto theme = TRY_OR_FAIL(Gfx::load_system_theme(theme_path.string()));auto view = WebView::HeadlessWebView::create(move(theme), { 800, 600 });@@ -345,6 +329,4 @@ addEventListener("pointermove", event => { if (event.buttons) log("drag", event)click_at(window_view, close_button_at_1x);VERIFY(window_activated_controls.size() == 2);outln("a control follows the frame at the new pixel ratio once it is displayed");-- return 0;}diff --git a/Tests/LibWebView/TestPictureInPictureWindowLifetime.cpp b/Tests/LibWebView/TestPictureInPictureWindowLifetime.cppindex 884fc1fafa8..0d28dd1434d 100644--- a/Tests/LibWebView/TestPictureInPictureWindowLifetime.cpp+++ b/Tests/LibWebView/TestPictureInPictureWindowLifetime.cpp@@ -4,20 +4,15 @@* SPDX-License-Identifier: BSD-2-Clause*/+#include "HeadlessTest.h"#include <AK/LexicalPath.h>-#include <AK/Random.h>-#include <AK/ScopeGuard.h>#include <AK/String.h>#include <AK/Utf16String.h>-#include <LibCore/Directory.h>-#include <LibCore/Environment.h>#include <LibCore/EventLoop.h>-#include <LibCore/StandardPaths.h>#include <LibCore/System.h>#include <LibCore/Timer.h>-#include <LibFileSystem/FileSystem.h>#include <LibGfx/SystemTheme.h>-#include <LibMain/Main.h>+#include <LibTest/TestCase.h>#include <LibWebCommon/Page/InputEvent.h>#include <LibWebView/Application.h>#include <LibWebView/HeadlessWebView.h>@@ -29,12 +24,12 @@namespace {-class TestApplication : public WebView::Application {+class TestApplication : public Test::HeadlessApplication {WEB_VIEW_APPLICATION(TestApplication)public:explicit TestApplication(Optional<ByteString> ladybird_binary_path)- : WebView::Application(move(ladybird_binary_path))+ : Test::HeadlessApplication(move(ladybird_binary_path)){}@@ -45,8 +40,6 @@ public:web_content_options.is_test_mode = WebView::IsTestMode::Yes;}- virtual bool should_coordinate_browser_process() const override { return false; }-virtual OwnPtr<WebView::PictureInPictureWindow> create_picture_in_picture_window(WebView::WebContentPage& requesting_page, WebView::CanonicalTraversable& traversable, Gfx::IntSize video_size) override{auto window = WebView::Application::create_picture_in_picture_window(requesting_page, traversable, video_size);@@ -155,23 +148,14 @@ void close_tab_as_a_browser_window_does(NonnullOwnPtr<WebView::HeadlessWebView>// A Picture-in-Picture window's page lives in the process of the tab that opened it, so it must not outlive that tab.-ErrorOr<int> ladybird_main(Main::Arguments arguments)+TEST_CASE(picture_in_picture_window_lifetime){- auto test_config_directory = ByteString::formatted("{}/Ladybird-TestPictureInPictureWindowLifetime-{}", Core::StandardPaths::tempfile_directory(), generate_random_uuid());- TRY(Core::Directory::create(test_config_directory, Core::Directory::CreateDirectories::Yes));- auto cleanup_test_config_directory = ScopeGuard([&] {- MUST(FileSystem::remove(test_config_directory, FileSystem::RecursionMode::Allowed));- });- MUST(Core::Environment::set("XDG_CONFIG_HOME"sv, test_config_directory, Core::Environment::Overwrite::Yes));+ Test::HeadlessTestEnvironment environment { "TestPictureInPictureWindowLifetime"sv };-#if defined(LADYBIRD_BINARY_PATH)- auto app = TRY(TestApplication::create(arguments, LADYBIRD_BINARY_PATH));-#else- auto app = TRY(TestApplication::create(arguments, OptionalNone {}));-#endif+ auto app = TRY_OR_FAIL(environment.create_application<TestApplication>());auto theme_path = LexicalPath::join(WebView::s_ladybird_resource_root, "themes"sv, "Default.ini"sv);- auto theme = TRY(Gfx::load_system_theme(theme_path.string()));+ auto theme = TRY_OR_FAIL(Gfx::load_system_theme(theme_path.string()));auto window_and_process_are_gone = [&](StringView window_handle, pid_t pid) {return spin_until_or_timeout([&] {@@ -203,6 +187,4 @@ ErrorOr<int> ladybird_main(Main::Arguments arguments)VERIFY(window_and_process_are_gone(window_handle, pid));outln("a window the user closed before its tab goes away with the tab's process too");}-- return 0;}diff --git a/Tests/LibWebView/TestRendererCookieAccess.cpp b/Tests/LibWebView/TestRendererCookieAccess.cppindex 8ddbc3d6e46..970c7f299f8 100644--- a/Tests/LibWebView/TestRendererCookieAccess.cpp+++ b/Tests/LibWebView/TestRendererCookieAccess.cpp@@ -4,18 +4,13 @@* SPDX-License-Identifier: BSD-2-Clause*/+#include "HeadlessTest.h"#include <AK/LexicalPath.h>-#include <AK/Random.h>-#include <AK/ScopeGuard.h>-#include <LibCore/Directory.h>-#include <LibCore/Environment.h>#include <LibCore/EventLoop.h>-#include <LibCore/StandardPaths.h>-#include <LibFileSystem/FileSystem.h>#include <LibGfx/SystemTheme.h>#include <LibHTTP/Cookie/Cookie.h>#include <LibHTTP/Cookie/ParsedCookie.h>-#include <LibMain/Main.h>+#include <LibTest/TestCase.h>#include <LibURL/Parser.h>#include <LibURL/Site.h>#include <LibWebCommon/FileAPI/SerializedBlobURLEntry.h>@@ -35,12 +30,12 @@namespace {// Neither WebDriver nor the test harness drives this application, so its renderers get no HTTP-like cookie access.-class TestApplication : public WebView::Application {+class TestApplication : public Test::HeadlessApplication {WEB_VIEW_APPLICATION(TestApplication)public:explicit TestApplication(Optional<ByteString> ladybird_binary_path)- : WebView::Application(move(ladybird_binary_path))+ : Test::HeadlessApplication(move(ladybird_binary_path)){}@@ -50,8 +45,6 @@ public:browser_options.disable_sql_database = WebView::DisableSQLDatabase::Yes;web_content_options.is_test_mode = WebView::IsTestMode::No;}-- virtual bool should_coordinate_browser_process() const override { return false; }};}@@ -60,23 +53,14 @@ public:// replace the HttpOnly cookies of every site. RequestServer handles the cookies of HTTP traffic itself, so the UI process// treats such a request from a renderer as misbehavior and terminates it, and the cookie jar stays untouched.-ErrorOr<int> ladybird_main(Main::Arguments arguments)+TEST_CASE(renderer_cookie_access){- auto test_config_directory = ByteString::formatted("{}/Ladybird-TestRendererCookieAccess-{}", Core::StandardPaths::tempfile_directory(), generate_random_uuid());- TRY(Core::Directory::create(test_config_directory, Core::Directory::CreateDirectories::Yes));- auto cleanup_test_config_directory = ScopeGuard([&] {- MUST(FileSystem::remove(test_config_directory, FileSystem::RecursionMode::Allowed));- });- MUST(Core::Environment::set("XDG_CONFIG_HOME"sv, test_config_directory, Core::Environment::Overwrite::Yes));+ Test::HeadlessTestEnvironment environment { "TestRendererCookieAccess"sv };-#if defined(LADYBIRD_BINARY_PATH)- auto app = TRY(TestApplication::create(arguments, LADYBIRD_BINARY_PATH));-#else- auto app = TRY(TestApplication::create(arguments, OptionalNone {}));-#endif+ auto app = TRY_OR_FAIL(environment.create_application<TestApplication>());auto theme_path = LexicalPath::join(WebView::s_ladybird_resource_root, "themes"sv, "Default.ini"sv);- auto theme = TRY(Gfx::load_system_theme(theme_path.string()));+ auto theme = TRY_OR_FAIL(Gfx::load_system_theme(theme_path.string()));auto victim_url = URL::Parser::basic_parse("https://victim.example/"sv).release_value();@@ -199,5 +183,4 @@ ErrorOr<int> ladybird_main(Main::Arguments arguments)VERIFY(navigation_stub.did_lose_request_server_connection({}).handle().has_value());outln("PASS: renderers cannot read, store or update cookies the way HTTP responses and WebDriver do, nor reach another origin's cookies or blob URL entries");- return 0;}diff --git a/Tests/LibWebView/TestRendererOriginClaims.cpp b/Tests/LibWebView/TestRendererOriginClaims.cppindex 23574600b2c..a6d48224d67 100644--- a/Tests/LibWebView/TestRendererOriginClaims.cpp+++ b/Tests/LibWebView/TestRendererOriginClaims.cpp@@ -4,15 +4,11 @@* SPDX-License-Identifier: BSD-2-Clause*/+#include "HeadlessTest.h"#include <AK/LexicalPath.h>#include <AK/Random.h>-#include <AK/ScopeGuard.h>-#include <LibCore/Directory.h>-#include <LibCore/Environment.h>-#include <LibCore/StandardPaths.h>-#include <LibFileSystem/FileSystem.h>#include <LibGfx/SystemTheme.h>-#include <LibMain/Main.h>+#include <LibTest/TestCase.h>#include <LibURL/Parser.h>#include <LibWebCommon/HTML/NavigationPopulationRequest.h>#include <LibWebCommon/Page/NavigationTarget.h>@@ -26,12 +22,12 @@namespace {// Neither WebDriver nor the test harness drives this application, so its renderers get no HTTP-like cookie access.-class TestApplication : public WebView::Application {+class TestApplication : public Test::HeadlessApplication {WEB_VIEW_APPLICATION(TestApplication)public:explicit TestApplication(Optional<ByteString> ladybird_binary_path)- : WebView::Application(move(ladybird_binary_path))+ : Test::HeadlessApplication(move(ladybird_binary_path)){}@@ -41,8 +37,6 @@ public:browser_options.disable_sql_database = WebView::DisableSQLDatabase::Yes;web_content_options.is_test_mode = WebView::IsTestMode::No;}-- virtual bool should_coordinate_browser_process() const override { return false; }};}@@ -51,23 +45,14 @@ public:// The UI process holds every document's origin, so a renderer claiming another origin for a navigation it starts has// the navigation refused.-ErrorOr<int> ladybird_main(Main::Arguments arguments)+TEST_CASE(renderer_origin_claims){- auto test_config_directory = ByteString::formatted("{}/Ladybird-TestRendererOriginClaims-{}", Core::StandardPaths::tempfile_directory(), generate_random_uuid());- TRY(Core::Directory::create(test_config_directory, Core::Directory::CreateDirectories::Yes));- auto cleanup_test_config_directory = ScopeGuard([&] {- MUST(FileSystem::remove(test_config_directory, FileSystem::RecursionMode::Allowed));- });- MUST(Core::Environment::set("XDG_CONFIG_HOME"sv, test_config_directory, Core::Environment::Overwrite::Yes));--#if defined(LADYBIRD_BINARY_PATH)- auto app = TRY(TestApplication::create(arguments, LADYBIRD_BINARY_PATH));-#else- auto app = TRY(TestApplication::create(arguments, OptionalNone {}));-#endif+ Test::HeadlessTestEnvironment environment { "TestRendererOriginClaims"sv };++ auto app = TRY_OR_FAIL(environment.create_application<TestApplication>());auto theme_path = LexicalPath::join(WebView::s_ladybird_resource_root, "themes"sv, "Default.ini"sv);- auto theme = TRY(Gfx::load_system_theme(theme_path.string()));+ auto theme = TRY_OR_FAIL(Gfx::load_system_theme(theme_path.string()));auto view = WebView::HeadlessWebView::create(theme, { 800, 600 });auto& stub = static_cast<WebContentClientStub&>(view->page().client());@@ -114,5 +99,4 @@ ErrorOr<int> ladybird_main(Main::Arguments arguments)VERIFY(start_navigation(URL::Origin::create_opaque()));outln("PASS: renderers cannot start a navigation as another origin");- return 0;}diff --git a/Tests/LibWebView/TestRendererViolationReports.cpp b/Tests/LibWebView/TestRendererViolationReports.cppindex a582ddb1ec8..af493df6233 100644--- a/Tests/LibWebView/TestRendererViolationReports.cpp+++ b/Tests/LibWebView/TestRendererViolationReports.cpp@@ -4,25 +4,19 @@* SPDX-License-Identifier: BSD-2-Clause*/+#include "HeadlessTest.h"#include <AK/Array.h>#include <AK/Atomic.h>#include <AK/HashMap.h>#include <AK/LexicalPath.h>-#include <AK/Random.h>-#include <AK/ScopeGuard.h>#include <AK/StringBuilder.h>-#include <LibCore/Directory.h>-#include <LibCore/Environment.h>#include <LibCore/EventLoop.h>-#include <LibCore/StandardPaths.h>#include <LibCore/System.h>#include <LibCore/Timer.h>-#include <LibFileSystem/FileSystem.h>#include <LibGfx/SystemTheme.h>-#include <LibMain/Main.h>+#include <LibTest/TestCase.h>#include <LibThreading/Thread.h>#include <LibURL/Parser.h>-#include <LibWebView/Application.h>#include <LibWebView/CanonicalEnvironmentSettingsObject.h>#include <LibWebView/CanonicalNavigable.h>#include <LibWebView/CanonicalNavigation.h>@@ -38,25 +32,6 @@namespace {-class TestApplication : public WebView::Application {- WEB_VIEW_APPLICATION(TestApplication)--public:- explicit TestApplication(Optional<ByteString> ladybird_binary_path)- : WebView::Application(move(ladybird_binary_path))- {- }-- virtual void create_platform_options(WebView::BrowserOptions& browser_options, WebView::RequestServerOptions&, WebView::WebContentOptions& web_content_options) override- {- browser_options.headless_mode = WebView::HeadlessMode::Test;- browser_options.disable_sql_database = WebView::DisableSQLDatabase::Yes;- web_content_options.is_test_mode = WebView::IsTestMode::Yes;- }-- virtual bool should_coordinate_browser_process() const override { return false; }-};-struct Page {ByteString headers;ByteString body;@@ -229,25 +204,16 @@ void claim_environment(WebView::HeadlessWebView& liar, Web::HTML::EnvironmentId// population worker is terminated for a report of a directive its kind of navigation rules out, such as form-action// outside a form submission; a report from another page, or for a navigation the worker is not running, is dropped.-ErrorOr<int> ladybird_main(Main::Arguments arguments)+TEST_CASE(renderer_violation_reports){- auto test_config_directory = ByteString::formatted("{}/Ladybird-TestRendererViolationReports-{}", Core::StandardPaths::tempfile_directory(), generate_random_uuid());- TRY(Core::Directory::create(test_config_directory, Core::Directory::CreateDirectories::Yes));- auto cleanup_test_config_directory = ScopeGuard([&] {- MUST(FileSystem::remove(test_config_directory, FileSystem::RecursionMode::Allowed));- });- MUST(Core::Environment::set("XDG_CONFIG_HOME"sv, test_config_directory, Core::Environment::Overwrite::Yes));+ Test::HeadlessTestEnvironment environment { "TestRendererViolationReports"sv };signal(SIGPIPE, SIG_IGN);-#if defined(LADYBIRD_BINARY_PATH)- auto app = TRY(TestApplication::create(arguments, LADYBIRD_BINARY_PATH));-#else- auto app = TRY(TestApplication::create(arguments, OptionalNone {}));-#endif+ auto app = TRY_OR_FAIL(environment.create_application());auto theme_path = LexicalPath::join(WebView::s_ladybird_resource_root, "themes"sv, "Default.ini"sv);- auto theme = TRY(Gfx::load_system_theme(theme_path.string()));+ auto theme = TRY_OR_FAIL(Gfx::load_system_theme(theme_path.string()));// The source's policy allows its frame's own site only. Each load of the frame and each violation retitles it.HashMap<ByteString, Page> pages;@@ -422,5 +388,4 @@ ErrorOr<int> ladybird_main(Main::Arguments arguments)expect(sibling_worker->client().is_open(), "a report for a replaced source is no fault of its worker"sv);outln("PASS: violation reports reach the source's page, and a report of a directive the navigation rules out terminates its renderer");- return 0;}diff --git a/Tests/LibWebView/TestRequestServerClientSessions.cpp b/Tests/LibWebView/TestRequestServerClientSessions.cppindex 65aa9eb1402..06e541b97b9 100644--- a/Tests/LibWebView/TestRequestServerClientSessions.cpp+++ b/Tests/LibWebView/TestRequestServerClientSessions.cpp@@ -4,19 +4,14 @@* SPDX-License-Identifier: BSD-2-Clause*/+#include "HeadlessTest.h"#include <AK/LexicalPath.h>-#include <AK/Random.h>-#include <AK/ScopeGuard.h>-#include <LibCore/Directory.h>-#include <LibCore/Environment.h>#include <LibCore/EventLoop.h>-#include <LibCore/StandardPaths.h>#include <LibCore/System.h>-#include <LibFileSystem/FileSystem.h>#include <LibGfx/SystemTheme.h>-#include <LibMain/Main.h>#include <LibRequests/RequestClient.h>#include <LibRequests/RequestControlClient.h>+#include <LibTest/TestCase.h>#include <LibWebView/Application.h>#include <LibWebView/BrowsingSession.h>#include <LibWebView/HeadlessWebView.h>@@ -26,12 +21,12 @@namespace {-class TestApplication : public WebView::Application {+class TestApplication : public Test::HeadlessApplication {WEB_VIEW_APPLICATION(TestApplication)public:explicit TestApplication(Optional<ByteString> ladybird_binary_path)- : WebView::Application(move(ladybird_binary_path))+ : Test::HeadlessApplication(move(ladybird_binary_path)){}@@ -41,8 +36,6 @@ public:browser_options.disable_sql_database = WebView::DisableSQLDatabase::Yes;browser_options.allow_popups = WebView::AllowPopups::Yes;}-- virtual bool should_coordinate_browser_process() const override { return false; }};// Connects a new RequestServer client the way the UI process does for its helpers, and asks RequestServer which ID@@ -69,20 +62,11 @@ int connect_request_server_client(WebView::BrowsingSession& session)// uses the browsing session that it created the client for, so a client of a private session that has since been// restarted never gets the new session's cookies.-ErrorOr<int> ladybird_main(Main::Arguments arguments)+TEST_CASE(request_server_client_sessions){- auto test_config_directory = ByteString::formatted("{}/Ladybird-TestRequestServerClientSessions-{}", Core::StandardPaths::tempfile_directory(), generate_random_uuid());- TRY(Core::Directory::create(test_config_directory, Core::Directory::CreateDirectories::Yes));- auto cleanup_test_config_directory = ScopeGuard([&] {- MUST(FileSystem::remove(test_config_directory, FileSystem::RecursionMode::Allowed));- });- MUST(Core::Environment::set("XDG_CONFIG_HOME"sv, test_config_directory, Core::Environment::Overwrite::Yes));+ Test::HeadlessTestEnvironment environment { "TestRequestServerClientSessions"sv };-#if defined(LADYBIRD_BINARY_PATH)- auto app = TRY(TestApplication::create(arguments, LADYBIRD_BINARY_PATH));-#else- auto app = TRY(TestApplication::create(arguments, OptionalNone {}));-#endif+ auto app = TRY_OR_FAIL(environment.create_application<TestApplication>());auto normal_client = connect_request_server_client(WebView::Application::default_session());VERIFY(app->session_for_request_server_client(normal_client).ptr() == &WebView::Application::default_session());@@ -90,7 +74,7 @@ ErrorOr<int> ladybird_main(Main::Arguments arguments)// The views of the first private session keep it alive after the user restarts private browsing.auto first_private_session = WebView::Application::session_for_new_view(WebView::IsPrivate::Yes);auto first_private_client = connect_request_server_client(*first_private_session);- auto first_ui_private_client = client_id_of(*TRY(WebView::Application::request_server_client(WebView::IsPrivate::Yes)));+ auto first_ui_private_client = client_id_of(*TRY_OR_FAIL(WebView::Application::request_server_client(WebView::IsPrivate::Yes)));VERIFY(app->session_for_request_server_client(first_ui_private_client) == first_private_session);app->reset_private_browsing_session();@@ -98,7 +82,7 @@ ErrorOr<int> ladybird_main(Main::Arguments arguments)auto second_private_client = connect_request_server_client(*second_private_session);// The UI process's own private client is replaced along with the session, so its requests use the new cookies.- auto second_ui_private_client = client_id_of(*TRY(WebView::Application::request_server_client(WebView::IsPrivate::Yes)));+ auto second_ui_private_client = client_id_of(*TRY_OR_FAIL(WebView::Application::request_server_client(WebView::IsPrivate::Yes)));VERIFY(app->session_for_request_server_client(second_ui_private_client) == second_private_session);VERIFY(first_private_session.ptr() != second_private_session.ptr());@@ -110,7 +94,7 @@ ErrorOr<int> ladybird_main(Main::Arguments arguments)// When RequestServer restarts, every WebContent process gets a replacement client. The one for a view of the old// private session must keep using that session's cookies.- auto theme = TRY(Gfx::load_system_theme(LexicalPath::join(WebView::s_ladybird_resource_root, "themes"sv, "Default.ini"sv).string()));+ auto theme = TRY_OR_FAIL(Gfx::load_system_theme(LexicalPath::join(WebView::s_ladybird_resource_root, "themes"sv, "Default.ini"sv).string()));app->reset_private_browsing_session();auto old_private_view = WebView::HeadlessWebView::create(theme, { 800, 600 }, WebView::IsPrivate::Yes);auto& old_private_session = old_private_view->page().client().session();@@ -150,5 +134,4 @@ ErrorOr<int> ladybird_main(Main::Arguments arguments)s_clients.clear();Core::EventLoop::current().spin_until([&] { return !app->session_for_request_server_client(disconnecting_client); });outln("PASS: RequestServer clients use the cookies of the browsing session they were created for");- return 0;}diff --git a/Tests/LibWebView/TestShadowTreeTooltipsAndLinks.cpp b/Tests/LibWebView/TestShadowTreeTooltipsAndLinks.cppindex 764734e86de..0c859631ca6 100644--- a/Tests/LibWebView/TestShadowTreeTooltipsAndLinks.cpp+++ b/Tests/LibWebView/TestShadowTreeTooltipsAndLinks.cpp@@ -4,45 +4,20 @@* SPDX-License-Identifier: BSD-2-Clause*/+#include "HeadlessTest.h"#include <AK/LexicalPath.h>-#include <AK/Random.h>-#include <AK/ScopeGuard.h>#include <AK/String.h>-#include <LibCore/Directory.h>-#include <LibCore/Environment.h>#include <LibCore/EventLoop.h>-#include <LibCore/StandardPaths.h>-#include <LibFileSystem/FileSystem.h>#include <LibGfx/SystemTheme.h>-#include <LibMain/Main.h>+#include <LibTest/TestCase.h>#include <LibURL/Parser.h>#include <LibWebCommon/HTML/VisibilityState.h>#include <LibWebCommon/Page/InputEvent.h>-#include <LibWebView/Application.h>#include <LibWebView/HeadlessWebView.h>#include <LibWebView/Utilities.h>namespace {-class TestApplication : public WebView::Application {- WEB_VIEW_APPLICATION(TestApplication)--public:- explicit TestApplication(Optional<ByteString> ladybird_binary_path)- : WebView::Application(move(ladybird_binary_path))- {- }-- virtual void create_platform_options(WebView::BrowserOptions& browser_options, WebView::RequestServerOptions&, WebView::WebContentOptions& web_content_options) override- {- browser_options.headless_mode = WebView::HeadlessMode::Test;- browser_options.disable_sql_database = WebView::DisableSQLDatabase::Yes;- web_content_options.is_test_mode = WebView::IsTestMode::Yes;- }-- virtual bool should_coordinate_browser_process() const override { return false; }-};-// A view that records the URL each tab it opens is loaded with.class TestWebView final : public WebView::HeadlessWebView {public:@@ -111,23 +86,14 @@ void middle_click_at(WebView::ViewImplementation& view, Web::DevicePixelPoint po// Middle-clicking opens the link the walk finds in a new tab. And an empty title is no advisory information at all,// while carriage returns in a title become line feeds.-ErrorOr<int> ladybird_main(Main::Arguments arguments)+TEST_CASE(shadow_tree_tooltips_and_links){- auto test_config_directory = ByteString::formatted("{}/Ladybird-TestShadowTreeTooltipsAndLinks-{}", Core::StandardPaths::tempfile_directory(), generate_random_uuid());- TRY(Core::Directory::create(test_config_directory, Core::Directory::CreateDirectories::Yes));- auto cleanup_test_config_directory = ScopeGuard([&] {- MUST(FileSystem::remove(test_config_directory, FileSystem::RecursionMode::Allowed));- });- MUST(Core::Environment::set("XDG_CONFIG_HOME"sv, test_config_directory, Core::Environment::Overwrite::Yes));+ Test::HeadlessTestEnvironment environment { "TestShadowTreeTooltipsAndLinks"sv };-#if defined(LADYBIRD_BINARY_PATH)- auto app = TRY(TestApplication::create(arguments, LADYBIRD_BINARY_PATH));-#else- auto app = TRY(TestApplication::create(arguments, OptionalNone {}));-#endif+ auto app = TRY_OR_FAIL(environment.create_application());auto theme_path = LexicalPath::join(WebView::s_ladybird_resource_root, "themes"sv, "Default.ini"sv);- auto theme = TRY(Gfx::load_system_theme(theme_path.string()));+ auto theme = TRY_OR_FAIL(Gfx::load_system_theme(theme_path.string()));auto view = TestWebView::create(move(theme), { 800, 600 });@@ -258,5 +224,4 @@ document.getElementById("carriage-returns").setAttribute("title", "One\r\nTwo\rTVERIFY(tooltip == "One\nTwo\nThree"sv);outln("PASS: titles and links apply across shadow trees and slots, and an empty title is no advisory information");- return 0;}diff --git a/Tests/LibWebView/TestTabPerformanceMonitor.cpp b/Tests/LibWebView/TestTabPerformanceMonitor.cppindex e7555e7ed89..369f324ab69 100644--- a/Tests/LibWebView/TestTabPerformanceMonitor.cpp+++ b/Tests/LibWebView/TestTabPerformanceMonitor.cpp@@ -4,61 +4,28 @@* SPDX-License-Identifier: BSD-2-Clause*/+#include "HeadlessTest.h"#include <AK/LexicalPath.h>-#include <AK/Random.h>-#include <AK/ScopeGuard.h>#include <AK/String.h>#include <AK/Utf16String.h>-#include <LibCore/Directory.h>#include <LibCore/EventLoop.h>-#include <LibCore/StandardPaths.h>#include <LibCore/Timer.h>-#include <LibFileSystem/FileSystem.h>#include <LibGfx/SystemTheme.h>-#include <LibMain/Main.h>#include <LibRequests/RequestControlClient.h>+#include <LibTest/TestCase.h>#include <LibWebView/Application.h>#include <LibWebView/HeadlessWebView.h>#include <LibWebView/TabPerformanceMonitor.h>#include <LibWebView/Utilities.h>#include <stdlib.h>-namespace {--class TestApplication : public WebView::Application {- WEB_VIEW_APPLICATION(TestApplication)--public:- explicit TestApplication(Optional<ByteString> ladybird_binary_path)- : WebView::Application(move(ladybird_binary_path))- {- }-- virtual void create_platform_options(WebView::BrowserOptions& browser_options, WebView::RequestServerOptions&, WebView::WebContentOptions& web_content_options) override- {- browser_options.headless_mode = WebView::HeadlessMode::Test;- browser_options.disable_sql_database = WebView::DisableSQLDatabase::Yes;- web_content_options.is_test_mode = WebView::IsTestMode::Yes;- }-- virtual bool should_coordinate_browser_process() const override { return false; }-};--}--ErrorOr<int> ladybird_main(Main::Arguments arguments)+TEST_CASE(tab_performance_monitor){- auto directory = ByteString::formatted("{}/Ladybird-TestTabPerformanceMonitor-{}", Core::StandardPaths::tempfile_directory(), generate_random_uuid());- TRY(Core::Directory::create(directory, Core::Directory::CreateDirectories::Yes));- ScopeGuard cleanup = [&] { MUST(FileSystem::remove(directory, FileSystem::RecursionMode::Allowed)); };- VERIFY(setenv("XDG_CONFIG_HOME", directory.characters(), 1) == 0);-#if defined(LADYBIRD_BINARY_PATH)- auto app = TRY(TestApplication::create(arguments, LADYBIRD_BINARY_PATH));-#else- auto app = TRY(TestApplication::create(arguments, OptionalNone {}));-#endif+ Test::HeadlessTestEnvironment environment { "TestTabPerformanceMonitor"sv };++ auto app = TRY_OR_FAIL(environment.create_application());auto theme_path = LexicalPath::join(WebView::s_ladybird_resource_root, "themes"sv, "Default.ini"sv);- auto theme = TRY(Gfx::load_system_theme(theme_path.string()));+ auto theme = TRY_OR_FAIL(Gfx::load_system_theme(theme_path.string()));auto view = WebView::HeadlessWebView::create(move(theme), { 800, 600 });auto& monitor = WebView::TabPerformanceMonitor::the();VERIFY(!monitor.enabled());@@ -92,7 +59,7 @@ ErrorOr<int> ladybird_main(Main::Arguments arguments)enable();// Wait for events, not a fixed sleep or an assumed sampling cadence. This detects a configured// timer that was never started, in both the browser and RequestServer.- TRY(wait_for_samples(3));+ TRY_OR_FAIL(wait_for_samples(3));WebView::Application::settings().set_config_variable(WebView::ConfigVariableID::ShowTabPerformanceMonitor, false);VERIFY(!monitor.enabled());VERIFY(!WebView::Application::request_server_control_client().on_network_usage);@@ -100,8 +67,7 @@ ErrorOr<int> ladybird_main(Main::Arguments arguments)pushes = 0;enable();VERIFY(!cpu.has_value());- TRY(wait_for_samples(previous_samples + 3));+ TRY_OR_FAIL(wait_for_samples(previous_samples + 3));WebView::Application::settings().set_config_variable(WebView::ConfigVariableID::ShowTabPerformanceMonitor, false);outln("Tab performance sampling, asynchronous pushes and re-enabling passed.");- return 0;}diff --git a/Tests/LibWebView/TestUserActivation.cpp b/Tests/LibWebView/TestUserActivation.cppindex 4e986ca2937..f2656b10a01 100644--- a/Tests/LibWebView/TestUserActivation.cpp+++ b/Tests/LibWebView/TestUserActivation.cpp@@ -4,17 +4,12 @@* SPDX-License-Identifier: BSD-2-Clause*/+#include "HeadlessTest.h"#include <AK/LexicalPath.h>-#include <AK/Random.h>-#include <AK/ScopeGuard.h>#include <AK/String.h>-#include <LibCore/Directory.h>-#include <LibCore/Environment.h>#include <LibCore/EventLoop.h>-#include <LibCore/StandardPaths.h>-#include <LibFileSystem/FileSystem.h>#include <LibGfx/SystemTheme.h>-#include <LibMain/Main.h>+#include <LibTest/TestCase.h>#include <LibWebCommon/Page/InputEvent.h>#include <LibWebView/Application.h>#include <LibWebView/HeadlessWebView.h>@@ -22,12 +17,12 @@namespace {-class TestApplication : public WebView::Application {+class TestApplication : public Test::HeadlessApplication {WEB_VIEW_APPLICATION(TestApplication)public:explicit TestApplication(Optional<ByteString> ladybird_binary_path)- : WebView::Application(move(ladybird_binary_path))+ : Test::HeadlessApplication(move(ladybird_binary_path)){}@@ -38,8 +33,6 @@ public:browser_options.headless_mode = WebView::HeadlessMode::Test;browser_options.disable_sql_database = WebView::DisableSQLDatabase::Yes;}-- virtual bool should_coordinate_browser_process() const override { return false; }};size_t view_count()@@ -79,24 +72,15 @@ void click(WebView::ViewImplementation& view, Web::DevicePixelPoint position, We// presses queue up before the page handles the first. Consuming the activation of the press the page is handling leaves// the presses queued behind it theirs, and a click that opens a popup still opens its link in a new tab.-ErrorOr<int> ladybird_main(Main::Arguments arguments)+TEST_CASE(user_activation){- auto test_config_directory = ByteString::formatted("{}/Ladybird-TestUserActivation-{}", Core::StandardPaths::tempfile_directory(), generate_random_uuid());- TRY(Core::Directory::create(test_config_directory, Core::Directory::CreateDirectories::Yes));- auto cleanup_test_config_directory = ScopeGuard([&] {- MUST(FileSystem::remove(test_config_directory, FileSystem::RecursionMode::Allowed));- });- MUST(Core::Environment::set("XDG_CONFIG_HOME"sv, test_config_directory, Core::Environment::Overwrite::Yes));+ Test::HeadlessTestEnvironment environment { "TestUserActivation"sv };-#if defined(LADYBIRD_BINARY_PATH)- auto app = TRY(TestApplication::create(arguments, LADYBIRD_BINARY_PATH));-#else- auto app = TRY(TestApplication::create(arguments, OptionalNone {}));-#endif+ auto app = TRY_OR_FAIL(environment.create_application<TestApplication>());VERIFY(app->blocks_pop_ups());auto theme_path = LexicalPath::join(WebView::s_ladybird_resource_root, "themes"sv, "Default.ini"sv);- auto theme = TRY(Gfx::load_system_theme(theme_path.string()));+ auto theme = TRY_OR_FAIL(Gfx::load_system_theme(theme_path.string()));auto view = WebView::HeadlessWebView::create(move(theme), { 800, 600 });@@ -133,5 +117,4 @@ ErrorOr<int> ladybird_main(Main::Arguments arguments)outln("two queued middle-clicks open two popups and two tabs");VERIFY(popups_opened == 4);- return 0;}diff --git a/Tests/LibWebView/TestWebCompatReport.cpp b/Tests/LibWebView/TestWebCompatReport.cppindex 4fb4e4540ab..8b6e69d6b7f 100644--- a/Tests/LibWebView/TestWebCompatReport.cpp+++ b/Tests/LibWebView/TestWebCompatReport.cpp@@ -4,20 +4,16 @@* SPDX-License-Identifier: BSD-2-Clause*/+#include "HeadlessTest.h"#include "ReportServer.h"#include <AK/JsonArray.h>#include <AK/JsonObject.h>#include <AK/JsonValue.h>#include <AK/LexicalPath.h>-#include <AK/Random.h>-#include <AK/ScopeGuard.h>-#include <LibCore/Directory.h>#include <LibCore/Environment.h>#include <LibCore/EventLoop.h>-#include <LibCore/StandardPaths.h>#include <LibCore/Timer.h>-#include <LibFileSystem/FileSystem.h>-#include <LibMain/Main.h>+#include <LibTest/TestCase.h>#include <LibURL/Parser.h>#include <LibWebView/WebCompatReport.h>@@ -110,20 +106,14 @@ void verify_diagnostics()}-ErrorOr<int> ladybird_main(Main::Arguments arguments)+TEST_CASE(web_compat_report){- auto test_directory = ByteString::formatted("{}/Ladybird-TestWebCompatReport-{}", Core::StandardPaths::tempfile_directory(), generate_random_uuid());- TRY(Core::Directory::create(test_directory, Core::Directory::CreateDirectories::Yes));- auto cleanup_test_directory = ScopeGuard([&] {- MUST(FileSystem::remove(test_directory, FileSystem::RecursionMode::Allowed));- });+ Test::HeadlessTestEnvironment environment { "TestWebCompatReport"sv };+ auto const& test_directory = environment.directory();+MUST(Core::Environment::set("XDG_CONFIG_HOME"sv, LexicalPath::join(test_directory, "config"sv).string(), Core::Environment::Overwrite::Yes));-#if defined(LADYBIRD_BINARY_PATH)- auto app = TRY(TestApplication::create(arguments, LADYBIRD_BINARY_PATH));-#else- auto app = TRY(TestApplication::create(arguments, OptionalNone {}));-#endif+ auto app = TRY_OR_FAIL(environment.create_application<TestApplication>());verify_validation();verify_diagnostics();@@ -227,5 +217,4 @@ ErrorOr<int> ladybird_main(Main::Arguments arguments)VERIFY(server.requests.size() == 1);outln("PASS: Web compatibility reports reach the report server in the format it expects");- return 0;}diff --git a/Tests/LibWebView/TestWebCompatReportPage.cpp b/Tests/LibWebView/TestWebCompatReportPage.cppindex 09c0e2512d9..42f49d5c804 100644--- a/Tests/LibWebView/TestWebCompatReportPage.cpp+++ b/Tests/LibWebView/TestWebCompatReportPage.cpp@@ -4,65 +4,27 @@* SPDX-License-Identifier: BSD-2-Clause*/+#include "HeadlessTest.h"#include <AK/LexicalPath.h>-#include <AK/Random.h>-#include <AK/ScopeGuard.h>-#include <LibCore/Directory.h>-#include <LibCore/Environment.h>#include <LibCore/EventLoop.h>#include <LibCore/Promise.h>-#include <LibCore/StandardPaths.h>-#include <LibFileSystem/FileSystem.h>#include <LibGfx/SystemTheme.h>-#include <LibMain/Main.h>-#include <LibWebView/Application.h>+#include <LibTest/TestCase.h>#include <LibWebView/HeadlessWebView.h>#include <LibWebView/Utilities.h>#include <LibWebView/WebCompatReport.h>-namespace {--class TestApplication : public WebView::Application {- WEB_VIEW_APPLICATION(TestApplication)--public:- explicit TestApplication(Optional<ByteString> ladybird_binary_path)- : WebView::Application(move(ladybird_binary_path))- {- }-- virtual void create_platform_options(WebView::BrowserOptions& browser_options, WebView::RequestServerOptions&, WebView::WebContentOptions& web_content_options) override- {- browser_options.headless_mode = WebView::HeadlessMode::Test;- browser_options.disable_sql_database = WebView::DisableSQLDatabase::Yes;- web_content_options.is_test_mode = WebView::IsTestMode::Yes;- }-- virtual bool should_coordinate_browser_process() const override { return false; }-};--}-// A web compatibility report describes the page as the view shows it, and dumps how the page was laid out and painted.// Pages that are not websites cannot be reported.-ErrorOr<int> ladybird_main(Main::Arguments arguments)+TEST_CASE(web_compat_report_page){- auto test_config_directory = ByteString::formatted("{}/Ladybird-TestWebCompatReportPage-{}", Core::StandardPaths::tempfile_directory(), generate_random_uuid());- TRY(Core::Directory::create(test_config_directory, Core::Directory::CreateDirectories::Yes));- auto cleanup_test_config_directory = ScopeGuard([&] {- MUST(FileSystem::remove(test_config_directory, FileSystem::RecursionMode::Allowed));- });- MUST(Core::Environment::set("XDG_CONFIG_HOME"sv, test_config_directory, Core::Environment::Overwrite::Yes));+ Test::HeadlessTestEnvironment environment { "TestWebCompatReportPage"sv };-#if defined(LADYBIRD_BINARY_PATH)- auto app = TRY(TestApplication::create(arguments, LADYBIRD_BINARY_PATH));-#else- auto app = TRY(TestApplication::create(arguments, OptionalNone {}));-#endif+ auto app = TRY_OR_FAIL(environment.create_application());auto theme_path = LexicalPath::join(WebView::s_ladybird_resource_root, "themes"sv, "Default.ini"sv);- auto theme = TRY(Gfx::load_system_theme(theme_path.string()));+ auto theme = TRY_OR_FAIL(Gfx::load_system_theme(theme_path.string()));auto view = WebView::HeadlessWebView::create(move(theme), { 800, 600 });@@ -86,7 +48,7 @@ ErrorOr<int> ladybird_main(Main::Arguments arguments)view->report_website_issue();VERIFY(requests == 0);- auto dumps = TRY(WebView::WebCompatReport::request_page_dumps(*view)->await());+ auto dumps = TRY_OR_FAIL(WebView::WebCompatReport::request_page_dumps(*view)->await());auto layout_tree = dumps.find_byte_offset("Viewport <#document>"sv);auto stacking_context_tree = dumps.find_byte_offset("\nSC for Viewport"sv);auto display_list = dumps.find_byte_offset("\nDisplayList:\n"sv);@@ -97,5 +59,4 @@ ErrorOr<int> ladybird_main(Main::Arguments arguments)VERIFY(dumps.bytes_as_string_view().substring_view(*display_list).contains("FillRect"sv));outln("PASS: Web compatibility reports describe and dump the page the view shows");- return 0;}