From ac63d1e59dc65bc165825aab02b54772d3e28f04 Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Fri, 22 Dec 2023 14:06:03 +0000 Subject: [PATCH] headless-browser: Clear document and callbacks between tests While it would be more hygienic to get a fresh Navigable each time, loading `about:blank` still means we discard the current Document. This does noticeably increase the duration of running the LibWeb test suite. On my machine, we go from ~5.5 seconds to ~7.7. --- Userland/Utilities/headless-browser.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Userland/Utilities/headless-browser.cpp b/Userland/Utilities/headless-browser.cpp index ab177ba156..f9373b29eb 100644 --- a/Userland/Utilities/headless-browser.cpp +++ b/Userland/Utilities/headless-browser.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -352,6 +353,16 @@ static ErrorOr run_ref_test(HeadlessWebContentView& view, StringView static ErrorOr run_test(HeadlessWebContentView& view, StringView input_path, StringView expectation_path, TestMode mode, bool dump_failed_ref_tests) { + // Clear the current document. + // FIXME: Implement a debug-request to do this more thoroughly. + auto promise = Core::Promise::construct(); + view.on_load_finish = [&](auto) { + promise->resolve({}); + }; + view.on_text_test_finish = {}; + view.load(URL("about:blank"sv)); + MUST(promise->await()); + s_current_test_path = input_path; switch (mode) { case TestMode::Text: