mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 07:30:19 +00:00
Ladybird: Add ability to add test fixtures for LibWeb tests
This will be used to add test fixtures that use external resources or require a specific setup.
This commit is contained in:
parent
97d47a38c9
commit
ba78b294a0
Notes:
github-actions[bot]
2024-11-09 20:31:06 +00:00
Author: https://github.com/coryvirok Commit: https://github.com/LadybirdBrowser/ladybird/commit/ba78b294a0b Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1801 Reviewed-by: https://github.com/rmg-x
6 changed files with 98 additions and 0 deletions
|
@ -5,6 +5,7 @@
|
|||
*/
|
||||
|
||||
#include <Ladybird/Headless/Application.h>
|
||||
#include <Ladybird/Headless/Fixture.h>
|
||||
#include <Ladybird/Headless/HeadlessWebView.h>
|
||||
#include <Ladybird/HelperProcess.h>
|
||||
#include <Ladybird/Utilities.h>
|
||||
|
@ -20,6 +21,12 @@ Application::Application(Badge<WebView::Application>, Main::Arguments&)
|
|||
{
|
||||
}
|
||||
|
||||
Application::~Application()
|
||||
{
|
||||
for (auto& fixture : Fixture::all())
|
||||
fixture->teardown();
|
||||
}
|
||||
|
||||
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");
|
||||
|
@ -72,6 +79,19 @@ ErrorOr<void> Application::launch_services()
|
|||
return {};
|
||||
}
|
||||
|
||||
ErrorOr<void> Application::launch_test_fixtures()
|
||||
{
|
||||
Fixture::initialize_fixtures();
|
||||
|
||||
// FIXME: Add option to only run specific fixtures from command line by name
|
||||
// And an option to not run any fixtures at all
|
||||
for (auto& fixture : Fixture::all()) {
|
||||
if (auto result = fixture->setup(); result.is_error())
|
||||
return result;
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
HeadlessWebView& Application::create_web_view(Core::AnonymousBuffer theme, Gfx::IntSize window_size)
|
||||
{
|
||||
auto web_view = HeadlessWebView::create(move(theme), window_size);
|
||||
|
|
|
@ -24,6 +24,8 @@ class Application : public WebView::Application {
|
|||
WEB_VIEW_APPLICATION(Application)
|
||||
|
||||
public:
|
||||
~Application();
|
||||
|
||||
static Application& the()
|
||||
{
|
||||
return static_cast<Application&>(WebView::Application::the());
|
||||
|
@ -33,6 +35,7 @@ public:
|
|||
virtual void create_platform_options(WebView::ChromeOptions&, WebView::WebContentOptions&) override;
|
||||
|
||||
ErrorOr<void> launch_services();
|
||||
ErrorOr<void> launch_test_fixtures();
|
||||
|
||||
static Requests::RequestClient& request_client() { return *the().m_request_client; }
|
||||
static ImageDecoderClient::Client& image_decoder_client() { return *the().m_image_decoder_client; }
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
set(SOURCES
|
||||
${LADYBIRD_SOURCES}
|
||||
Application.cpp
|
||||
Fixture.cpp
|
||||
HeadlessWebView.cpp
|
||||
Test.cpp
|
||||
main.cpp
|
||||
|
|
33
Ladybird/Headless/Fixture.cpp
Normal file
33
Ladybird/Headless/Fixture.cpp
Normal file
|
@ -0,0 +1,33 @@
|
|||
/*
|
||||
* Copyright (c) 2024, Andrew Kaster <andrew@ladybird.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <Ladybird/Headless/Fixture.h>
|
||||
|
||||
namespace Ladybird {
|
||||
|
||||
// Key function for Fixture
|
||||
Fixture::~Fixture() = default;
|
||||
|
||||
Optional<Fixture&> Fixture::lookup(StringView name)
|
||||
{
|
||||
for (auto& fixture : all()) {
|
||||
if (fixture->name() == name)
|
||||
return *fixture;
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
Vector<NonnullOwnPtr<Fixture>>& Fixture::all()
|
||||
{
|
||||
static Vector<NonnullOwnPtr<Fixture>> fixtures;
|
||||
return fixtures;
|
||||
}
|
||||
|
||||
void Fixture::initialize_fixtures()
|
||||
{
|
||||
}
|
||||
|
||||
}
|
40
Ladybird/Headless/Fixture.h
Normal file
40
Ladybird/Headless/Fixture.h
Normal file
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
* Copyright (c) 2024, Andrew Kaster <andrew@ladybird.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AK/Error.h>
|
||||
#include <AK/NonnullOwnPtr.h>
|
||||
#include <AK/Optional.h>
|
||||
#include <AK/StringView.h>
|
||||
#include <AK/Vector.h>
|
||||
|
||||
namespace Ladybird {
|
||||
|
||||
class Fixture {
|
||||
public:
|
||||
virtual ~Fixture();
|
||||
|
||||
virtual ErrorOr<void> setup() = 0;
|
||||
|
||||
void teardown()
|
||||
{
|
||||
if (is_running())
|
||||
teardown_impl();
|
||||
}
|
||||
|
||||
virtual StringView name() const = 0;
|
||||
virtual bool is_running() const { return false; }
|
||||
|
||||
static void initialize_fixtures();
|
||||
static Optional<Fixture&> lookup(StringView name);
|
||||
static Vector<NonnullOwnPtr<Fixture>>& all();
|
||||
|
||||
protected:
|
||||
virtual void teardown_impl() = 0;
|
||||
};
|
||||
|
||||
}
|
|
@ -76,6 +76,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
|
||||
if (!app->test_root_path.is_empty()) {
|
||||
app->test_root_path = LexicalPath::absolute_path(TRY(FileSystem::current_working_directory()), app->test_root_path);
|
||||
TRY(app->launch_test_fixtures());
|
||||
TRY(Ladybird::run_tests(theme, window_size));
|
||||
|
||||
return 0;
|
||||
|
|
Loading…
Reference in a new issue