Commit Graph

64 Commits

Author SHA1 Message Date
Jonathan Gamble
5262916049 LibWeb: Write stderr on WebContent crashes
Before it is cleared.
2026-01-21 22:43:04 +01:00
Jelle Raaijmakers
583bdd3d13 Tests/LibWeb: Only report fuzzy mismatches if we expect a match
Reduces the fuzzy matching noise `test-web` produces.
2026-01-21 13:13:19 +01:00
Timothy Flynn
6d52c9003c test-web: Add an explicit verbosity mode to disable live display
We were previously using the absence of a results directory to decide
if we should disable live display. However, this was never the case -
the results directory would become unconditionally set in main(). This
caused all test-web output in CI to become hidden.

Instead, let's add a verbosity mode to display test output explicitly.
This is set for CI.

This also makes it much easier to debug single tests locally. The live
capture and results file combo is a bit overkill for running a single
test; we can now just add "-v" to the command line to see the output
directly in the terminal.
2026-01-20 14:14:38 -05:00
Sam Atkins
cdf55ea371 WebContent+LibWebView: Rename --layout-test-mode flag to --test-mode
This name has been outdated for a while, as it's enabled when running
any kind of test, not just layout tests.
2026-01-20 06:58:16 -05:00
Aliaksandr Kalenik
cdbe2d97b6 test-web: Fix tests without expectation files incorrectly passing
This fixes a regression introduced in bf77aeb3d which added support for
WPT variant meta tags.

The problem occurs when a text test has no corresponding expectation
file. The test should fail, but instead it passes. This happens because
of the following execution flow:

1. Test loads and on_load_finish is called
2. internals.loadTestVariants() is executed (for all text tests)
3. The test JS calls signalTestIsDone(), setting did_finish_test = true
4. The variant metadata callback fires with an empty array (no variants)
5. In on_test_variant_metadata, since did_finish_test is true, it
   directly calls
   view.on_test_complete({ test_index, TestResult::Pass })

The bug is in step 5: the code bypasses handle_completed_test() which is
where the expectation file comparison happens. Instead of calling
on_test_complete() (the lambda that invokes handle_completed_test), it
directly returns Pass.
2026-01-19 10:44:04 +01:00
ayeteadoe
259e10a28a Tests/LibWeb: Normalize paths when removing test files via glob matches
When tests are being collected, the paths get canonicalized via the
FileSystem::real_path() call. This means on Windows the paths are using
`\` as the directory separator.

Tests get removed by performing string-based matching on a hardcoded
set of support file globs and an optional user defined glob. Even if we
normalized these globs to use `\` instead of `/` on Windows, they still
wouldn't match because AK::StringUtils::matches() uses `\` to escape
metacharacters. For example, `my\relative\windows\path` will not match
`my\*\path` because the mask is interpreted as `"my*\path"` instead.

So we normalize paths to use POSIX separators to support the existing
glob matching infrastructure. This allows Windows to filter out support
files properly which prevents us from crashing when Ref tests try to
load one of those files. It also allows Windows to use `/`-based paths
for the -f argument.
2026-01-16 11:33:33 -07:00
ayeteadoe
5279e0ce73 CMake: Remove ENABLE_WINDOWS_CI option and adjust presets to match Unix
ENABLE_WINDOWS_CI and the *_CI presets were initially added back when
the AK library and all the AK Test* executables were the only targets
that supported building and running in CI. Since then, almost all the
targets in the codebase are built on Windows besides the following:
    - LibLine
    - test-262-runner

Since these targets above are not required to actually run or test the
browser on Windows in its current experimental state, fully disabling
them should be fine for now.

ENABLE_WINDOWS_CI was also used to exclude test-web from ctest. This
can be fully disabled on Windows for now until proper runtime support
is added.

The remaining locations were all using ENABLE_WINDOWS_CI as a proxy for
ENABLE_ADDRESS_SANITIZER, so we can just be explicit instead.

The new presets map much more directly to the unix Release, Debug, and
Sanitizer presets which should make setting up ladybird on Windows less
confusing.

We also make the new Windows_Experimental_Release preset the default in
ladybird.py to match Unix.
2026-01-16 11:15:16 -07:00
Jelle Raaijmakers
7cfb03fa37 Tests/LibWeb: Use truncated seconds for live display duration
Use to_truncated_seconds() instead of to_seconds() for the per-view
duration display. The latter rounds up, causing "1s" to appear almost
immediately when a test starts. Now "1s" only appears after a full
second has elapsed.
2026-01-16 16:44:13 +00:00
Jelle Raaijmakers
42d7e3398e Tests/LibWeb: Generate diff files for tests with missing expectations
Previously, when a test's expectation file didn't exist, test-web would
return an error immediately without generating diff output files. This
made it difficult to see what the actual test output was.

Now, when an expectation file is missing, test-web continues to generate
the diff files (showing all output as additions) so users can inspect
the actual output and create expectation files if needed.

Also defer the "Failed opening" warning to avoid cluttering the live
display output.
2026-01-16 16:44:13 +00:00
Jelle Raaijmakers
bf77aeb3dc Tests/LibWeb: Support WPT variant meta tags in test-web
Add support for WPT test variants, which allow a single test file to be
run multiple times with different URL query parameters. Tests declare
variants using `<meta name="variant" content="?param=value">` tags.

When test-web encounters a test with variants, it expands that test into
multiple runs, each with its own expectation file using the naming
convention `testname@variant.txt` (e.g., `test@run_type=uri.txt`).

Implementation details:
- WebContent observes variant meta tags and communicates them to the
  test runner via a new `did_receive_test_variant_metadata` IPC call
- test-web dynamically expands tests with variants during execution,
  waking idle views after each test completion to pick up new work
- Use index-based test tracking to avoid dangling references when the
  test vector grows during variant expansion
- Introduce TestRunContext to group test run state, and store a static
  pointer to it for signal handler access

This enables proper testing of WPT tests that use variants, such as the
html5lib parsing tests (which test uri, write, and write_single modes)
and the editing/bold tests (which split across multiple ranges).
2026-01-16 16:44:13 +00:00
Andreas Kling
794ba270a2 test-web: Improve WebContent crash handling
Two fixes for crash handling:

1. Re-setup output capture after WebContent respawns. When WebContent
   crashes, a new process is spawned with new stdout/stderr pipes.
   We need to set up new notifiers to drain them, otherwise the new
   WebContent blocks on write() when its pipe buffer fills up.

2. Disconnect child view crash handlers between tests. Child views
   (from window.open, iframes, etc.) persist after a test completes.
   If they crash later, we don't want that to affect subsequent tests.
2026-01-13 23:57:46 +01:00
Andreas Kling
07138af5ef test-web: Fix ref test timeout timer getting destroyed prematurely
The timeout timer for ref tests was stored in a local variable that
went out of scope when run_ref_test() returned, causing the timer to
be destroyed before it could fire.

Store the timer in test.timeout_timer (like dump tests already do)
so it persists until the test completes.
2026-01-13 23:57:46 +01:00
Andreas Kling
bbcdb927b2 test-web: Disable output capture notifiers on EOF
When a WebContent process crashes, its stdout/stderr pipes will signal
POLLHUP. The output capture notifiers were not handling this case,
causing the event loop to spin at 100% CPU as poll() kept returning
immediately with POLLHUP set.

Fix by disabling the notifiers when read() returns 0 or an error.
2026-01-13 23:57:46 +01:00
Andreas Kling
ae8f723ba0 test-web: Show live pass/fail/skip counts in TTY mode
Display a color-coded status line showing test results as they come in.
This makes it easy to see at a glance how the test run is progressing.
2026-01-13 23:57:46 +01:00
Andreas Kling
dd51748708 test-web: Don't use FileSystem::copy_file_or_directory on Windows
This function isn't implemented for Windows. Use a simple read/write
approach instead.
2026-01-13 21:05:58 +01:00
Andreas Kling
72a2205b64 test-web: Skip view operations after WebContent crash
After a WebContent process crashes, the view's client is no longer
valid. Calling reset_zoom() would attempt to send IPC messages to the
dead process. Skip this operation when the test result indicates a
crash.
2026-01-13 21:05:58 +01:00
Andreas Kling
3c69d7bc33 test-web: Improve HTML results viewer with colorized diffs
- Generate colorized HTML diff files (.diff.html) alongside plain text
  diffs (.diff.txt) for each failing test
- Add total test count to results summary
- Improve the results-index.html viewer with a dark theme, keyboard
  navigation, search/filter, and tabbed interface for viewing diffs,
  expected/actual output, and stdout/stderr
- Move s_total_tests assignment outside live display block so it's
  always set
2026-01-13 21:05:58 +01:00
Andreas Kling
b5e01df79d test-web: Add results directory and live terminal display
- Add --results-dir CLI flag to specify output directory
- Default to {tempdir}/test-web-results if not specified
- Capture stdout/stderr from all helper processes (WebContent,
  RequestServer, ImageDecoder) to prevent output spam
- Save captured output to per-test files in results directory
- Save test diffs (expected vs actual) to results directory
- Generate HTML index of failed tests with links to diffs
- Display live-updating concurrent test status with progress bar
- Defer warning messages until after test run completes
2026-01-13 21:05:58 +01:00
Timothy Flynn
674075f79e Everywhere: Remove LibCore/System.h includes from header files
This reduces the number of compilation jobs when System.h changes from
about 750 to 60. (There are still a large number of linker jobs.)
2025-12-04 15:40:46 +00:00
Andreas Kling
1c45930767 LibWeb+LibWebView+LibRequests: Reduce dependency on LibIPC includes
Let's try to include the IPC encoder/decoder stuff in fewer headers
to make rebuilds more pleasant when editing these files.
2025-12-01 15:12:52 +01:00
Timothy Flynn
165afd8ad1 test-web: Do not clear the WebContent crash handler between tests
Clearing the callback opens a window for the WebContent process to crash
while we do not have a callback set. In practice, we see this with ASAN
crashes, where the crash occurs after we've already signaled that the
test has completed.

We now set the crash handler once during init. This required moving the
clearing of other callbacks to the test completion handler (we were
clearing these callbacks in several different ways anyways, so now we
will at least be consistent).
2025-11-22 14:09:11 +01:00
Sam Atkins
eea1d4e1d2 test-web: Report which file has missing match/mismatch metadata
This makes it easier to figure out what's causing the assertion failure.
2025-11-20 16:02:40 +01:00
Timothy Flynn
b2c112c41a LibWebView+RequestServer: Add a simple test mode for the HTTP disk cache
This mode allows us to test the HTTP disk cache with two mechanisms:

1. If RequestServer is launched with --http-disk-cache-mode=testing, it
   will cache requests with a X-Ladybird-Enable-Disk-Cache header.

2. In test mode, RS will include a X-Ladybird-Disk-Cache-Status response
   header indicating how the response was handled by the cache. There is
   no standard way for a web request to know what happened with respect
   to the disk cache, so this fills that hole for testing.

This mode is not exposed to users.
2025-11-20 09:33:49 +01:00
Timothy Flynn
a853bb43ef LibWebView+UI: Pass RequestServerOptions to Application implementations
This will be needed by test-web.
2025-11-20 09:33:49 +01:00
ayeteadoe
95f239a357 CMake: Add Windows executable helper function
The function currently has 2 purposes: (1) To copy dependent dlls for
executables to output binary directory. This ensures that these helper
processes can be ran after a build given not all DLLs from vcpkg libs
get implicitly copied to the bin folder. (2) Allow fully background
and/or GUI processes to use the Windows Subsystem. This prevents
unnecessarily launching a console for the process, as we either require
no user interaction or the user interaction is all handled in the GUI.
2025-10-29 21:07:52 -06:00
Luke Wilde
4ede2cdf18 LibWebView+WebContent: Allow setting the default time zone
This is used by tests to set the default time zone to UTC.

This is because certain tests create JavaScript Date objects, which are
in the current timezone.
2025-10-23 14:42:45 +02:00
Timothy Flynn
e57176b484 LibWebView: Move headless clipboard management to LibWebView
We only supported headless clipboard management in test-web. So when WPT
tests the clipboard APIs, we would blindly try to access the Qt app,
which does not exist.

Note that the AppKit UI has no such restriction, as the NSPasteboard is
accessible even without a GUI.
2025-10-10 15:10:03 -04:00
Timothy Flynn
bbe254f3cb test-web: Log which WebView is running each test
When trying to repro a failed CI test, it is handy to know the order in
which test-web ran its tests. We've seen in the past that the exact
order can be important to debug flakey tests.

This adds the index of the WebView running the test to verbose log
statements (which is enabled in CI).
2025-10-02 11:12:47 -04:00
Timothy Flynn
ca082d6d73 LibWebView+UI: Move clipboard handling from the WebView to the App
Clipboard handling largely has nothing to do with the individual web
views. Rather, we interact with the system clipboard at the application
level. So let's move these implementations to the Application.
2025-09-19 06:38:52 -04:00
Timothy Flynn
9684e6dbc5 LibWebView+UI: Generate the zoom menu 2025-09-11 14:23:45 -04:00
Timothy Flynn
98c7a011d4 test-web: Wait for crash tests with a test-wait attribute
Similar to ref tests, we don't want to incorrectly pass a test that did
not remove this attribute.
2025-09-10 16:38:24 +01:00
InvalidUsernameException
f9a54d6439 Tests/LibWeb: Do not crash test runner when screenshot sizes differ
This regressed in 0f642ecb5c.
2025-09-03 17:31:21 +02:00
InvalidUsernameException
a259ed4db6 Tests/LibWeb: Do not leak multiple GB of screenshots in the test runner
For every ref tests actual and expected screenshots are taken. These
screenshots are only needed while the individual test executes. However,
they are never freed during the run, leading to a continuous increase in
memory usage of the test runner while executing ref tests.

With the number of ref tests growing, this currently amounts to nearly 3
GB of uncompressed bitmap data being held in memory. Lets avoid that by
clearing the screenshot data at the end of each test. With this change
applied, the memory usage of test-web stays stable and below 100 MB for
the entire test run.
2025-09-03 17:31:21 +02:00
Timothy Flynn
e36cd6d82d Tests/LibWeb: Ensure SIGINT causes test-web to exit with a non-zero code
Sending a ctrl+c to a program should generally cause it to exit with a
non-zero status code.
2025-08-28 13:25:33 +02:00
Jelle Raaijmakers
f9888b0641 Tests: Report view's test path instead of URL in test-web
When a test is active in a test-web view, show the relative path to the
test instead of the view's URL. This gives a better starting point for
debugging than whatever the last loaded URL happened to be.

If no test is active, we still show the view's URL.
2025-08-26 19:37:16 -04:00
rmg-x
ac755d0916 Tests/LibWeb: Reset zoom on web view before running tests
This prevents test failures when running locally if the user set a
default zoom level other than 1.0
2025-08-26 06:31:22 -04:00
ayeteadoe
9ec1643d88 CMake: Add helper to ensure vcpkg DLLs are copied to the output dir
The BUILD_RPATH/INSTALL_RPATH CMake infrastructure is not supported
on Windows, but we want to ensure Ladybird executables are runnable
after the build phase so there can be an efficient dev loop.
lagom_copy_runtime_dlls() can be used by executable targets so all
their dependent dlls are copied to their output directory in their
post build step.
2025-08-23 16:04:36 -06:00
ayeteadoe
9c67c4a270 LibWebView: Enable EXPLICIT_SYMBOL_EXPORT 2025-08-23 16:04:36 -06:00
ayeteadoe
84690f432e test-web: Allow help command to succeed
These are required for test-web runtime to actually work
2025-08-23 16:04:36 -06:00
ayeteadoe
0b19c04b53 test-web: Enable building in Windows CI
The tests are not registered with CTest yet
2025-08-23 16:04:36 -06:00
Jelle Raaijmakers
fcd39b67af Tests: Set SIGTERM as the timeout signal handler for ctest
We occasionally (frequently) time out in CI. If ctest triggers this
timeout, it sends a SIGSTOP followed by a SIGKILL. Since we want to
gracefully exit the test runner, ask ctest to send a SIGTERM instead.

This should cause active test status reports to show up in CI.
2025-08-17 20:51:56 -04:00
Jelle Raaijmakers
bee0ba2bb4 Tests: Report status on SIGINT and SIGTERM in LibWeb test runner
If you interrupt the test runner (Ctrl+C, SIGINT) or if the test runner
is gracefully being terminated (SIGTERM), it now reports the current
status of all the spawned views with their URL and, if an active test is
still being run, the time since the start of the test.

Hopefully this will help gain insight into which tests are hanging.
2025-08-17 20:51:56 -04:00
Sam Atkins
9b6c26e347 Tests: Include test URL in fuzzy mismatch reports
The test logs tend to get a bit mixed together, so this makes it
possible to identify which values correspond to which test when multiple
are failing at once.
2025-08-06 13:51:36 +02:00
Sam Atkins
75046857ce Tests: Report image differences on tests with no fuzzy config defined
This can be helpful for identifying what the fuzzy config should be for
new tests.
2025-08-06 13:51:36 +02:00
Sam Atkins
90b49b9015 Tests: Report what the fuzzy configuration parsing error was 2025-08-06 13:51:36 +02:00
Sam Atkins
9889710033 Tests: Allow whitespace around fuzzy-matching configurations
Several WPT tests have a space after the semicolon, for example
https://wpt.live/css/css-images/gradient/gradient-single-stop-001.html :

```
<meta name="fuzzy" content="maxDifference=0-1; totalPixels=0-6000">
```
2025-08-06 13:51:36 +02:00
Tim Ledbetter
168ea88cb2 test-web: Add an option to randomize the test order 2025-07-28 09:01:56 +02:00
Tim Ledbetter
bd83f5bde6 test-web: Treat files in images directories as resources for WPT tests 2025-07-20 16:26:57 +12:00
Jelle Raaijmakers
59a867d3e3 Tests: Enable all screenshot tests on all platforms
With the newly supported fuzzy matching in our test-web runner, we can
now define the expected maximum color channel and pixel count errors per
failing test and set a baseline they should not exceed.

The figures I added to these tests all come from my macOS M4 machine.
Most discrepancies seem to come from color calculations being slightly
off.
2025-07-17 12:59:11 +01:00
Jelle Raaijmakers
0d856a8fa7 Tests: Implement fuzzy screenshot comparisons in test-web
We now read WPT's `<meta name="fuzzy">` tags if present in tests and
apply them while comparing screenshots.
2025-07-17 12:59:11 +01:00