From a0b4987e92fd6544451d564e8e40a186d3352053 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Tue, 20 Jun 2023 10:01:33 +0200 Subject: [PATCH] headless-browser: Paint while running layout tests (but discard results) If we don't paint, SVG-as-image documents don't get laid out, and so have 0x0 size throughout. This change is also generally nice, as it makes the painting code run on all the layout tests, increasing coverage. :^) --- Tests/LibWeb/Layout/expected/svg/svg-as-image.txt | 6 +++--- Userland/Utilities/headless-browser.cpp | 5 +++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Tests/LibWeb/Layout/expected/svg/svg-as-image.txt b/Tests/LibWeb/Layout/expected/svg/svg-as-image.txt index e4f6f5a22f..d81b3ad3e1 100644 --- a/Tests/LibWeb/Layout/expected/svg/svg-as-image.txt +++ b/Tests/LibWeb/Layout/expected/svg/svg-as-image.txt @@ -3,8 +3,8 @@ Viewport <#document> at (0,0) content-size 800x600 children: not-inline BlockContainer at (8,8) content-size 784x1568 children: not-inline ImageBox at (8,8) content-size 784x1568 children: not-inline (SVG-as-image isolated context) - Viewport <#document> at (0,0) content-size 0x0 children: inline - SVGSVGBox at (0,0) content-size 0x0 [SVG] children: inline + Viewport <#document> at (0,0) content-size 784x1568 children: inline + SVGSVGBox at (0,0) content-size 784x1568 [SVG] children: inline TextNode <#text> - SVGGeometryBox at (0,0) content-size 0x0 children: not-inline + SVGGeometryBox at (-0.000007,-0.000015) content-size 784x1568 children: not-inline TextNode <#text> diff --git a/Userland/Utilities/headless-browser.cpp b/Userland/Utilities/headless-browser.cpp index e1ebbb48ba..5e92f3c64b 100644 --- a/Userland/Utilities/headless-browser.cpp +++ b/Userland/Utilities/headless-browser.cpp @@ -198,6 +198,10 @@ static ErrorOr run_one_test(HeadlessWebContentView& view, StringView inp if (mode == TestMode::Layout) { view.on_load_finish = [&](auto const&) { + // NOTE: We take a screenshot here to force the lazy layout of SVG-as-image documents to happen. + // It also causes a lot more code to run, which is good for finding bugs. :^) + (void)view.take_screenshot(); + result = view.dump_layout_tree().release_value_but_fixme_should_propagate_errors(); loop.quit(0); }; @@ -440,6 +444,7 @@ ErrorOr serenity_main(Main::Arguments arguments) if (dump_layout_tree) { view->on_load_finish = [&](auto const&) { + (void)view->take_screenshot(); auto layout_tree = view->dump_layout_tree().release_value_but_fixme_should_propagate_errors(); out("{}", layout_tree);