Files
ladybird/Tests/LibWeb/test-web/TestWebView.cpp
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

66 lines
1.6 KiB
C++

/*
* Copyright (c) 2024-2025, Tim Flynn <trflynn89@ladybird.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include "TestWebView.h"
#include <LibGfx/Bitmap.h>
#include <LibGfx/ShareableBitmap.h>
namespace TestWeb {
NonnullOwnPtr<TestWebView> TestWebView::create(Core::AnonymousBuffer theme, Web::DevicePixelSize window_size)
{
auto view = adopt_own(*new TestWebView(move(theme), window_size));
view->initialize_client(CreateNewClient::Yes);
return view;
}
TestWebView::TestWebView(Core::AnonymousBuffer theme, Web::DevicePixelSize viewport_size)
: WebView::HeadlessWebView(move(theme), viewport_size)
, m_test_promise(TestPromise::construct())
{
}
void TestWebView::clear_content_filters()
{
client().async_set_content_filters(m_client_state.page_index, {});
}
pid_t TestWebView::web_content_pid() const
{
return client().pid();
}
NonnullRefPtr<Core::Promise<RefPtr<Gfx::Bitmap const>>> TestWebView::take_screenshot()
{
VERIFY(!m_pending_screenshot);
m_pending_screenshot = Core::Promise<RefPtr<Gfx::Bitmap const>>::construct();
client().async_take_document_screenshot(0);
return *m_pending_screenshot;
}
void TestWebView::did_receive_screenshot(Badge<WebView::WebContentClient>, Gfx::ShareableBitmap const& screenshot)
{
VERIFY(m_pending_screenshot);
auto pending_screenshot = move(m_pending_screenshot);
pending_screenshot->resolve(screenshot.bitmap());
}
void TestWebView::on_test_complete(TestCompletion completion)
{
m_pending_screenshot.clear();
m_pending_dialog = Web::Page::PendingDialog::None;
m_pending_prompt_text.clear();
m_test_promise->resolve(move(completion));
}
}