mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-28 19:59:17 +00:00
LibWebView+WebDriver+UI: Migrate headless browsing to main Ladybird exe
We currently create a separate headless-browser application to serve two purposes: 1. Allow headless browsing to take a screenshot of a page or print its layout tree / internal text. 2. Run the LibWeb test framework. This patch migrates (1) to the main Ladybird executable. The --headless flag enables this mode. This matches the behavior of other browsers, and means we have one less executable to ship at distribution time. We want to avoid creating too many AppKit / Qt facilities in headless mode. So this involves some shuffling of application init to ensure we don't create them until after we've parsed the command line arguments. Namely, we avoid creating the NSApp in AppKit and QCoreApplication in Qt. Doing so also requires that we don't create the application event loop until we've parsed the command line as well, because the loop we create depends on whether we're creating those UI facilities.
This commit is contained in:
parent
3894d8efec
commit
c011dc766f
Notes:
github-actions[bot]
2025-06-10 16:06:04 +00:00
Author: https://github.com/trflynn89
Commit: c011dc766f
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/5026
28 changed files with 535 additions and 494 deletions
|
@ -29,10 +29,6 @@ Application::~Application()
|
|||
|
||||
void Application::create_platform_arguments(Core::ArgsParser& args_parser)
|
||||
{
|
||||
args_parser.add_option(screenshot_timeout, "Take a screenshot after [n] seconds (default: 1)", "screenshot", 's', "n");
|
||||
args_parser.add_option(screenshot_path, "Path the save the screenshot (default: 'output.png')", "screenshot-path", 'p', "path");
|
||||
args_parser.add_option(dump_layout_tree, "Dump layout tree and exit", "dump-layout-tree", 'd');
|
||||
args_parser.add_option(dump_text, "Dump text and exit", "dump-text", 'T');
|
||||
args_parser.add_option(test_concurrency, "Maximum number of tests to run at once", "test-concurrency", 'j', "jobs");
|
||||
args_parser.add_option(python_executable_path, "Path to python3", "python-executable", 'P', "path");
|
||||
args_parser.add_option(test_globs, "Only run tests matching the given glob", "filter", 'f', "glob");
|
||||
|
@ -40,11 +36,8 @@ void Application::create_platform_arguments(Core::ArgsParser& args_parser)
|
|||
args_parser.add_option(dump_failed_ref_tests, "Dump screenshots of failing ref tests", "dump-failed-ref-tests", 'D');
|
||||
args_parser.add_option(dump_gc_graph, "Dump GC graph", "dump-gc-graph", 'G');
|
||||
args_parser.add_option(resources_folder, "Path of the base resources folder (defaults to /res)", "resources", 'r', "resources-root-path");
|
||||
args_parser.add_option(is_layout_test_mode, "Enable layout test mode", "layout-test-mode");
|
||||
args_parser.add_option(rebaseline, "Rebaseline any executed layout or text tests", "rebaseline");
|
||||
args_parser.add_option(per_test_timeout_in_seconds, "Per-test timeout (default: 30)", "per-test-timeout", 't', "seconds");
|
||||
args_parser.add_option(width, "Set viewport width in pixels (default: 800)", "width", 'W', "pixels");
|
||||
args_parser.add_option(height, "Set viewport height in pixels (default: 600)", "height", 'H', "pixels");
|
||||
|
||||
args_parser.add_option(Core::ArgsParser::Option {
|
||||
.argument_mode = Core::ArgsParser::OptionArgumentMode::Optional,
|
||||
|
@ -85,29 +78,22 @@ void Application::create_platform_arguments(Core::ArgsParser& args_parser)
|
|||
|
||||
void Application::create_platform_options(WebView::BrowserOptions& browser_options, WebView::WebContentOptions& web_content_options)
|
||||
{
|
||||
if (!test_root_path.is_empty()) {
|
||||
// --run-tests implies --layout-test-mode.
|
||||
is_layout_test_mode = true;
|
||||
}
|
||||
browser_options.headless_mode = WebView::HeadlessMode::Test;
|
||||
web_content_options.is_layout_test_mode = WebView::IsLayoutTestMode::Yes;
|
||||
|
||||
if (is_layout_test_mode) {
|
||||
// Allow window.open() to succeed for tests.
|
||||
browser_options.allow_popups = WebView::AllowPopups::Yes;
|
||||
// Allow window.open() to succeed for tests.
|
||||
browser_options.allow_popups = WebView::AllowPopups::Yes;
|
||||
|
||||
// Ensure consistent font rendering between operating systems.
|
||||
web_content_options.force_fontconfig = WebView::ForceFontconfig::Yes;
|
||||
// Ensure consistent font rendering between operating systems.
|
||||
web_content_options.force_fontconfig = WebView::ForceFontconfig::Yes;
|
||||
|
||||
// Ensure tests are resilient to minor changes to the viewport scrollbar.
|
||||
web_content_options.paint_viewport_scrollbars = WebView::PaintViewportScrollbars::No;
|
||||
}
|
||||
// Ensure tests are resilient to minor changes to the viewport scrollbar.
|
||||
web_content_options.paint_viewport_scrollbars = WebView::PaintViewportScrollbars::No;
|
||||
|
||||
if (dump_gc_graph) {
|
||||
// Force all tests to run in serial if we are interested in the GC graph.
|
||||
test_concurrency = 1;
|
||||
}
|
||||
|
||||
web_content_options.is_layout_test_mode = is_layout_test_mode ? WebView::IsLayoutTestMode::Yes : WebView::IsLayoutTestMode::No;
|
||||
web_content_options.is_headless = WebView::IsHeadless::Yes;
|
||||
}
|
||||
|
||||
ErrorOr<void> Application::launch_test_fixtures()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue