1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-14 08:54:58 +00:00

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.
This commit is contained in:
Sam Atkins 2023-12-22 14:06:03 +00:00 committed by Andreas Kling
parent 1e6cd19b28
commit ac63d1e59d

View file

@ -25,6 +25,7 @@
#include <LibCore/Directory.h>
#include <LibCore/EventLoop.h>
#include <LibCore/File.h>
#include <LibCore/Promise.h>
#include <LibCore/ResourceImplementationFile.h>
#include <LibCore/Timer.h>
#include <LibDiff/Format.h>
@ -352,6 +353,16 @@ static ErrorOr<TestResult> run_ref_test(HeadlessWebContentView& view, StringView
static ErrorOr<TestResult> 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<Empty>::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: