2022-04-03 16:15:36 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2022, Dex♪ <dexes.ttp@gmail.com>
|
2023-03-12 16:38:15 +00:00
|
|
|
* Copyright (c) 2023, Tim Flynn <trflynn89@serenityos.org>
|
2024-10-04 11:19:50 +00:00
|
|
|
* Copyright (c) 2023, Andreas Kling <andreas@ladybird.org>
|
2024-10-01 10:49:14 +00:00
|
|
|
* Copyright (c) 2023-2024, Sam Atkins <sam@ladybird.org>
|
2022-04-03 16:15:36 +00:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
2023-03-12 16:38:15 +00:00
|
|
|
#include <AK/Badge.h>
|
2024-02-25 18:02:47 +00:00
|
|
|
#include <AK/ByteBuffer.h>
|
2023-12-16 14:19:34 +00:00
|
|
|
#include <AK/ByteString.h>
|
2024-10-04 14:08:31 +00:00
|
|
|
#include <AK/Enumerate.h>
|
2022-07-18 18:23:19 +00:00
|
|
|
#include <AK/LexicalPath.h>
|
2022-04-03 16:15:36 +00:00
|
|
|
#include <AK/NonnullOwnPtr.h>
|
2023-04-24 11:16:37 +00:00
|
|
|
#include <AK/Platform.h>
|
2023-03-13 11:50:26 +00:00
|
|
|
#include <AK/String.h>
|
2023-03-12 16:38:15 +00:00
|
|
|
#include <AK/Vector.h>
|
2024-06-09 10:10:28 +00:00
|
|
|
#include <Ladybird/HelperProcess.h>
|
|
|
|
#include <Ladybird/Utilities.h>
|
2022-04-03 16:15:36 +00:00
|
|
|
#include <LibCore/ArgsParser.h>
|
2023-12-07 17:40:57 +00:00
|
|
|
#include <LibCore/ConfigFile.h>
|
2023-05-27 17:46:17 +00:00
|
|
|
#include <LibCore/DirIterator.h>
|
2023-09-12 17:40:47 +00:00
|
|
|
#include <LibCore/Directory.h>
|
2022-04-03 16:15:36 +00:00
|
|
|
#include <LibCore/EventLoop.h>
|
2023-03-13 11:21:49 +00:00
|
|
|
#include <LibCore/File.h>
|
2023-12-22 14:06:03 +00:00
|
|
|
#include <LibCore/Promise.h>
|
2023-10-03 21:42:10 +00:00
|
|
|
#include <LibCore/ResourceImplementationFile.h>
|
2022-04-03 16:15:36 +00:00
|
|
|
#include <LibCore/Timer.h>
|
2023-06-21 06:54:19 +00:00
|
|
|
#include <LibDiff/Format.h>
|
2023-05-28 18:55:32 +00:00
|
|
|
#include <LibDiff/Generator.h>
|
2023-03-21 15:35:30 +00:00
|
|
|
#include <LibFileSystem/FileSystem.h>
|
2022-04-03 16:15:36 +00:00
|
|
|
#include <LibGfx/Bitmap.h>
|
|
|
|
#include <LibGfx/Font/FontDatabase.h>
|
2023-03-21 18:58:06 +00:00
|
|
|
#include <LibGfx/ImageFormats/PNGWriter.h>
|
2023-03-12 16:38:15 +00:00
|
|
|
#include <LibGfx/Point.h>
|
|
|
|
#include <LibGfx/ShareableBitmap.h>
|
|
|
|
#include <LibGfx/Size.h>
|
|
|
|
#include <LibGfx/SystemTheme.h>
|
2023-03-13 11:21:49 +00:00
|
|
|
#include <LibIPC/File.h>
|
2024-06-26 19:44:42 +00:00
|
|
|
#include <LibImageDecoderClient/Client.h>
|
2024-08-07 03:51:20 +00:00
|
|
|
#include <LibRequests/RequestClient.h>
|
2024-03-18 03:22:27 +00:00
|
|
|
#include <LibURL/URL.h>
|
2024-02-25 18:02:47 +00:00
|
|
|
#include <LibWeb/HTML/SelectedFile.h>
|
2024-06-30 04:24:01 +00:00
|
|
|
#include <LibWebView/Application.h>
|
2023-03-12 16:38:15 +00:00
|
|
|
#include <LibWebView/ViewImplementation.h>
|
|
|
|
#include <LibWebView/WebContentClient.h>
|
2022-11-22 01:03:45 +00:00
|
|
|
|
2023-11-27 21:42:10 +00:00
|
|
|
constexpr int DEFAULT_TIMEOUT_MS = 30000; // 30sec
|
|
|
|
|
2023-12-19 00:23:26 +00:00
|
|
|
static StringView s_current_test_path;
|
|
|
|
|
2024-10-04 14:20:22 +00:00
|
|
|
class HeadlessWebContentView;
|
|
|
|
|
|
|
|
class Application : public WebView::Application {
|
2024-10-04 14:08:31 +00:00
|
|
|
WEB_VIEW_APPLICATION(Application)
|
|
|
|
|
2024-10-04 14:20:22 +00:00
|
|
|
public:
|
2024-10-04 14:08:31 +00:00
|
|
|
static Application& the()
|
|
|
|
{
|
|
|
|
return static_cast<Application&>(WebView::Application::the());
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void create_platform_arguments(Core::ArgsParser& args_parser) override
|
|
|
|
{
|
|
|
|
args_parser.add_option(screenshot_timeout, "Take a screenshot after [n] seconds (default: 1)", "screenshot", 's', "n");
|
|
|
|
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_root_path, "Run tests in path", "run-tests", 'R', "test-root-path");
|
|
|
|
args_parser.add_option(test_glob, "Only run tests matching the given glob", "filter", 'f', "glob");
|
|
|
|
args_parser.add_option(test_dry_run, "List the tests that would be run, without running them", "dry-run");
|
|
|
|
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");
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void create_platform_options(WebView::ChromeOptions& chrome_options, WebView::WebContentOptions& web_content_options) override
|
|
|
|
{
|
|
|
|
if (!test_root_path.is_empty()) {
|
|
|
|
// --run-tests implies --layout-test-mode.
|
|
|
|
is_layout_test_mode = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_layout_test_mode) {
|
|
|
|
// Allow window.open() to succeed for tests.
|
|
|
|
chrome_options.allow_popups = WebView::AllowPopups::Yes;
|
|
|
|
}
|
|
|
|
|
|
|
|
web_content_options.is_layout_test_mode = is_layout_test_mode ? WebView::IsLayoutTestMode::Yes : WebView::IsLayoutTestMode::No;
|
|
|
|
}
|
|
|
|
|
2024-10-04 14:20:22 +00:00
|
|
|
ErrorOr<void> launch_services()
|
|
|
|
{
|
|
|
|
auto request_server_paths = TRY(get_paths_for_helper_process("RequestServer"sv));
|
|
|
|
m_request_client = TRY(launch_request_server_process(request_server_paths, resources_folder));
|
|
|
|
|
|
|
|
auto image_decoder_paths = TRY(get_paths_for_helper_process("ImageDecoder"sv));
|
|
|
|
m_image_decoder_client = TRY(launch_image_decoder_process(image_decoder_paths));
|
|
|
|
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
static Requests::RequestClient& request_client() { return *the().m_request_client; }
|
|
|
|
static ImageDecoderClient::Client& image_decoder_client() { return *the().m_image_decoder_client; }
|
|
|
|
|
|
|
|
ErrorOr<HeadlessWebContentView*> create_web_view(Core::AnonymousBuffer theme, Gfx::IntSize window_size);
|
|
|
|
|
2024-10-04 14:08:31 +00:00
|
|
|
int screenshot_timeout { 1 };
|
|
|
|
ByteString resources_folder { s_ladybird_resource_root };
|
|
|
|
bool dump_failed_ref_tests { false };
|
|
|
|
bool dump_layout_tree { false };
|
|
|
|
bool dump_text { false };
|
|
|
|
bool dump_gc_graph { false };
|
|
|
|
bool is_layout_test_mode { false };
|
|
|
|
ByteString test_root_path;
|
|
|
|
ByteString test_glob;
|
|
|
|
bool test_dry_run { false };
|
|
|
|
bool rebaseline { false };
|
2024-10-04 14:20:22 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
RefPtr<Requests::RequestClient> m_request_client;
|
|
|
|
RefPtr<ImageDecoderClient::Client> m_image_decoder_client;
|
|
|
|
|
|
|
|
OwnPtr<HeadlessWebContentView> m_web_view;
|
2024-10-04 14:08:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Application::Application(Badge<WebView::Application>, Main::Arguments&)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2023-03-12 16:38:15 +00:00
|
|
|
class HeadlessWebContentView final : public WebView::ViewImplementation {
|
2022-04-03 16:15:36 +00:00
|
|
|
public:
|
2024-10-04 14:20:22 +00:00
|
|
|
static ErrorOr<NonnullOwnPtr<HeadlessWebContentView>> create(Core::AnonymousBuffer theme, Gfx::IntSize window_size)
|
2022-04-03 16:15:36 +00:00
|
|
|
{
|
2024-10-04 14:20:22 +00:00
|
|
|
auto view = TRY(adopt_nonnull_own_or_enomem(new (nothrow) HeadlessWebContentView(window_size)));
|
2024-04-15 23:39:48 +00:00
|
|
|
|
2024-10-04 14:20:22 +00:00
|
|
|
auto request_server_socket = TRY(connect_new_request_server_client(Application::request_client()));
|
|
|
|
auto image_decoder_socket = TRY(connect_new_image_decoder_client(Application::image_decoder_client()));
|
2024-04-15 23:39:48 +00:00
|
|
|
|
2023-03-12 16:38:15 +00:00
|
|
|
auto candidate_web_content_paths = TRY(get_paths_for_helper_process("WebContent"sv));
|
2024-07-30 18:01:05 +00:00
|
|
|
view->m_client_state.client = TRY(launch_web_content_process(*view, candidate_web_content_paths, move(image_decoder_socket), move(request_server_socket)));
|
2022-04-03 16:20:05 +00:00
|
|
|
|
2024-02-03 01:00:48 +00:00
|
|
|
view->client().async_update_system_theme(0, move(theme));
|
2024-10-04 14:20:22 +00:00
|
|
|
view->client().async_set_viewport_size(0, view->viewport_size());
|
|
|
|
view->client().async_set_window_size(0, view->viewport_size());
|
2022-04-03 16:20:05 +00:00
|
|
|
|
2024-10-05 21:26:49 +00:00
|
|
|
if (WebView::Application::chrome_options().allow_popups == WebView::AllowPopups::Yes)
|
|
|
|
view->client().async_debug_request(0, "block-pop-ups"sv, "off"sv);
|
|
|
|
|
2024-07-30 18:01:05 +00:00
|
|
|
if (auto web_driver_ipc_path = WebView::Application::chrome_options().webdriver_content_ipc_path; web_driver_ipc_path.has_value())
|
|
|
|
view->client().async_connect_to_webdriver(0, *web_driver_ipc_path);
|
2023-03-16 12:50:22 +00:00
|
|
|
|
2023-12-19 00:23:26 +00:00
|
|
|
view->m_client_state.client->on_web_content_process_crash = [] {
|
|
|
|
warnln("\033[31;1mWebContent Crashed!!\033[0m");
|
|
|
|
if (!s_current_test_path.is_empty()) {
|
|
|
|
warnln(" Last started test: {}", s_current_test_path);
|
|
|
|
}
|
|
|
|
VERIFY_NOT_REACHED();
|
|
|
|
};
|
|
|
|
|
2023-03-12 16:38:15 +00:00
|
|
|
return view;
|
2022-04-03 16:15:36 +00:00
|
|
|
}
|
|
|
|
|
2023-03-12 16:38:15 +00:00
|
|
|
RefPtr<Gfx::Bitmap> take_screenshot()
|
2022-04-03 16:15:36 +00:00
|
|
|
{
|
2023-12-31 14:51:02 +00:00
|
|
|
VERIFY(!m_pending_screenshot);
|
|
|
|
|
|
|
|
m_pending_screenshot = Core::Promise<RefPtr<Gfx::Bitmap>>::construct();
|
2024-02-03 01:00:48 +00:00
|
|
|
client().async_take_document_screenshot(0);
|
2023-12-31 14:51:02 +00:00
|
|
|
|
|
|
|
auto screenshot = MUST(m_pending_screenshot->await());
|
|
|
|
m_pending_screenshot = nullptr;
|
|
|
|
|
|
|
|
return screenshot;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void did_receive_screenshot(Badge<WebView::WebContentClient>, Gfx::ShareableBitmap const& screenshot) override
|
|
|
|
{
|
|
|
|
VERIFY(m_pending_screenshot);
|
|
|
|
m_pending_screenshot->resolve(screenshot.bitmap());
|
2022-04-03 16:15:36 +00:00
|
|
|
}
|
|
|
|
|
2023-05-28 19:08:57 +00:00
|
|
|
void clear_content_filters()
|
|
|
|
{
|
2024-02-03 01:00:48 +00:00
|
|
|
client().async_set_content_filters(0, {});
|
2023-05-28 19:08:57 +00:00
|
|
|
}
|
|
|
|
|
2022-04-03 16:15:36 +00:00
|
|
|
private:
|
2024-10-04 14:20:22 +00:00
|
|
|
HeadlessWebContentView(Gfx::IntSize viewport_size)
|
|
|
|
: m_viewport_size(viewport_size)
|
2023-12-18 20:16:33 +00:00
|
|
|
{
|
2024-10-04 14:20:22 +00:00
|
|
|
on_request_worker_agent = []() {
|
|
|
|
auto worker_client = MUST(launch_web_worker_process(MUST(get_paths_for_helper_process("WebWorker"sv)), Application::request_client()));
|
2024-04-18 00:44:39 +00:00
|
|
|
return worker_client->dup_socket();
|
2024-01-06 20:13:59 +00:00
|
|
|
};
|
2023-12-18 20:16:33 +00:00
|
|
|
}
|
2023-03-12 16:38:15 +00:00
|
|
|
|
|
|
|
void update_zoom() override { }
|
2024-01-30 16:12:14 +00:00
|
|
|
void initialize_client(CreateNewClient) override { }
|
2023-05-15 05:59:51 +00:00
|
|
|
|
2024-06-03 14:53:55 +00:00
|
|
|
virtual Web::DevicePixelSize viewport_size() const override { return m_viewport_size.to_type<Web::DevicePixels>(); }
|
2023-05-17 14:12:13 +00:00
|
|
|
virtual Gfx::IntPoint to_content_position(Gfx::IntPoint widget_position) const override { return widget_position; }
|
|
|
|
virtual Gfx::IntPoint to_widget_position(Gfx::IntPoint content_position) const override { return content_position; }
|
2023-05-15 05:59:51 +00:00
|
|
|
|
2024-06-03 14:53:55 +00:00
|
|
|
Gfx::IntSize m_viewport_size;
|
2023-12-31 14:51:02 +00:00
|
|
|
RefPtr<Core::Promise<RefPtr<Gfx::Bitmap>>> m_pending_screenshot;
|
2022-04-03 16:15:36 +00:00
|
|
|
};
|
|
|
|
|
2024-10-04 14:20:22 +00:00
|
|
|
ErrorOr<HeadlessWebContentView*> Application::create_web_view(Core::AnonymousBuffer theme, Gfx::IntSize window_size)
|
|
|
|
{
|
|
|
|
m_web_view = TRY(HeadlessWebContentView::create(move(theme), window_size));
|
|
|
|
return m_web_view.ptr();
|
|
|
|
}
|
|
|
|
|
2024-07-30 18:01:05 +00:00
|
|
|
static ErrorOr<NonnullRefPtr<Core::Timer>> load_page_for_screenshot_and_exit(Core::EventLoop& event_loop, HeadlessWebContentView& view, URL::URL const& url, int screenshot_timeout)
|
2022-11-22 01:03:45 +00:00
|
|
|
{
|
2023-03-12 16:38:15 +00:00
|
|
|
// FIXME: Allow passing the output path as an argument.
|
|
|
|
static constexpr auto output_file_path = "output.png"sv;
|
2022-11-22 01:03:45 +00:00
|
|
|
|
2023-03-21 15:35:30 +00:00
|
|
|
if (FileSystem::exists(output_file_path))
|
|
|
|
TRY(FileSystem::remove(output_file_path, FileSystem::RecursionMode::Disallowed));
|
2022-11-22 01:03:45 +00:00
|
|
|
|
2023-03-12 16:38:15 +00:00
|
|
|
outln("Taking screenshot after {} seconds", screenshot_timeout);
|
2022-11-22 01:03:45 +00:00
|
|
|
|
2024-04-16 18:34:01 +00:00
|
|
|
auto timer = Core::Timer::create_single_shot(
|
2023-03-12 16:38:15 +00:00
|
|
|
screenshot_timeout * 1000,
|
|
|
|
[&]() {
|
|
|
|
if (auto screenshot = view.take_screenshot()) {
|
|
|
|
outln("Saving screenshot to {}", output_file_path);
|
2022-11-22 01:03:45 +00:00
|
|
|
|
2023-03-12 16:38:15 +00:00
|
|
|
auto output_file = MUST(Core::File::open(output_file_path, Core::File::OpenMode::Write));
|
|
|
|
auto image_buffer = MUST(Gfx::PNGWriter::encode(*screenshot));
|
2023-03-01 16:24:50 +00:00
|
|
|
MUST(output_file->write_until_depleted(image_buffer.bytes()));
|
2023-03-12 16:38:15 +00:00
|
|
|
} else {
|
|
|
|
warnln("No screenshot available");
|
|
|
|
}
|
2022-11-22 01:03:45 +00:00
|
|
|
|
2023-03-12 16:38:15 +00:00
|
|
|
event_loop.quit(0);
|
2024-04-16 18:34:01 +00:00
|
|
|
});
|
2022-11-22 01:03:45 +00:00
|
|
|
|
2024-03-27 17:32:27 +00:00
|
|
|
view.load(url);
|
2022-11-22 01:03:45 +00:00
|
|
|
timer->start();
|
2023-03-12 16:38:15 +00:00
|
|
|
return timer;
|
2022-11-22 01:03:45 +00:00
|
|
|
}
|
|
|
|
|
2023-05-27 17:46:17 +00:00
|
|
|
enum class TestMode {
|
|
|
|
Layout,
|
|
|
|
Text,
|
2023-08-13 22:37:49 +00:00
|
|
|
Ref,
|
2023-05-27 17:46:17 +00:00
|
|
|
};
|
|
|
|
|
2023-08-13 22:37:49 +00:00
|
|
|
enum class TestResult {
|
|
|
|
Pass,
|
|
|
|
Fail,
|
2023-12-07 17:40:57 +00:00
|
|
|
Skipped,
|
2023-08-13 22:37:49 +00:00
|
|
|
Timeout,
|
|
|
|
};
|
|
|
|
|
2023-12-07 17:40:57 +00:00
|
|
|
static StringView test_result_to_string(TestResult result)
|
|
|
|
{
|
|
|
|
switch (result) {
|
|
|
|
case TestResult::Pass:
|
|
|
|
return "Pass"sv;
|
|
|
|
case TestResult::Fail:
|
|
|
|
return "Fail"sv;
|
|
|
|
case TestResult::Skipped:
|
|
|
|
return "Skipped"sv;
|
|
|
|
case TestResult::Timeout:
|
|
|
|
return "Timeout"sv;
|
|
|
|
}
|
|
|
|
VERIFY_NOT_REACHED();
|
|
|
|
}
|
|
|
|
|
2024-10-04 14:08:31 +00:00
|
|
|
static ErrorOr<TestResult> run_dump_test(HeadlessWebContentView& view, URL::URL const& url, StringView expectation_path, TestMode mode, int timeout_in_milliseconds = DEFAULT_TIMEOUT_MS)
|
2023-05-27 17:46:17 +00:00
|
|
|
{
|
|
|
|
Core::EventLoop loop;
|
|
|
|
bool did_timeout = false;
|
|
|
|
|
2024-04-16 18:34:01 +00:00
|
|
|
auto timeout_timer = Core::Timer::create_single_shot(timeout_in_milliseconds, [&] {
|
2023-05-27 17:46:17 +00:00
|
|
|
did_timeout = true;
|
|
|
|
loop.quit(0);
|
2024-04-16 18:34:01 +00:00
|
|
|
});
|
2023-05-27 17:46:17 +00:00
|
|
|
|
|
|
|
String result;
|
2023-12-20 17:22:12 +00:00
|
|
|
auto did_finish_test = false;
|
|
|
|
auto did_finish_loading = false;
|
2023-05-27 17:46:17 +00:00
|
|
|
|
|
|
|
if (mode == TestMode::Layout) {
|
2023-12-20 17:22:12 +00:00
|
|
|
view.on_load_finish = [&](auto const& loaded_url) {
|
2024-02-11 15:33:41 +00:00
|
|
|
// This callback will be called for 'about:blank' first, then for the URL we actually want to dump
|
2024-03-18 03:22:27 +00:00
|
|
|
VERIFY(url.equals(loaded_url, URL::ExcludeFragment::Yes) || loaded_url.equals(URL::URL("about:blank")));
|
2024-02-11 15:33:41 +00:00
|
|
|
|
|
|
|
if (url.equals(loaded_url, URL::ExcludeFragment::Yes)) {
|
|
|
|
// 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();
|
2023-12-20 17:22:12 +00:00
|
|
|
|
2024-09-19 14:40:00 +00:00
|
|
|
auto promise = view.request_internal_page_info(WebView::PageInfoType::LayoutTree | WebView::PageInfoType::PaintTree);
|
|
|
|
result = MUST(promise->await());
|
2023-06-20 08:01:33 +00:00
|
|
|
|
2024-02-11 15:33:41 +00:00
|
|
|
loop.quit(0);
|
|
|
|
}
|
2023-05-27 17:46:17 +00:00
|
|
|
};
|
2024-09-19 14:40:00 +00:00
|
|
|
|
2023-09-14 17:17:32 +00:00
|
|
|
view.on_text_test_finish = {};
|
2023-05-27 17:46:17 +00:00
|
|
|
} else if (mode == TestMode::Text) {
|
2023-12-20 17:22:12 +00:00
|
|
|
view.on_load_finish = [&](auto const& loaded_url) {
|
2024-02-23 16:06:32 +00:00
|
|
|
// NOTE: We don't want subframe loads to trigger the test finish.
|
|
|
|
if (!url.equals(loaded_url, URL::ExcludeFragment::Yes))
|
|
|
|
return;
|
2023-12-20 17:22:12 +00:00
|
|
|
did_finish_loading = true;
|
|
|
|
if (did_finish_test)
|
|
|
|
loop.quit(0);
|
|
|
|
};
|
2024-09-19 14:40:00 +00:00
|
|
|
|
2024-10-02 16:38:10 +00:00
|
|
|
view.on_text_test_finish = [&](auto const& text) {
|
|
|
|
result = text;
|
2024-09-19 14:40:00 +00:00
|
|
|
|
2023-12-20 17:22:12 +00:00
|
|
|
did_finish_test = true;
|
|
|
|
if (did_finish_loading)
|
|
|
|
loop.quit(0);
|
2023-05-27 17:46:17 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-12-20 17:44:35 +00:00
|
|
|
view.load(url);
|
|
|
|
|
2023-11-27 21:42:10 +00:00
|
|
|
timeout_timer->start();
|
2023-05-27 17:46:17 +00:00
|
|
|
loop.exec();
|
|
|
|
|
|
|
|
if (did_timeout)
|
|
|
|
return TestResult::Timeout;
|
|
|
|
|
2023-12-24 11:28:49 +00:00
|
|
|
if (expectation_path.is_empty()) {
|
|
|
|
out("{}", result);
|
|
|
|
return TestResult::Skipped;
|
|
|
|
}
|
|
|
|
|
2024-10-04 14:08:31 +00:00
|
|
|
auto expectation_file_or_error = Core::File::open(expectation_path, Application::the().rebaseline ? Core::File::OpenMode::Write : Core::File::OpenMode::Read);
|
2023-07-31 08:01:37 +00:00
|
|
|
if (expectation_file_or_error.is_error()) {
|
|
|
|
warnln("Failed opening '{}': {}", expectation_path, expectation_file_or_error.error());
|
|
|
|
return expectation_file_or_error.release_error();
|
|
|
|
}
|
|
|
|
|
|
|
|
auto expectation_file = expectation_file_or_error.release_value();
|
|
|
|
|
2024-10-04 14:08:31 +00:00
|
|
|
if (Application::the().rebaseline) {
|
2024-10-03 11:17:21 +00:00
|
|
|
TRY(expectation_file->write_until_depleted(result));
|
|
|
|
return TestResult::Pass;
|
|
|
|
}
|
|
|
|
|
2023-05-27 17:46:17 +00:00
|
|
|
auto expectation = TRY(String::from_utf8(StringView(TRY(expectation_file->read_until_eof()).bytes())));
|
|
|
|
|
2023-08-13 22:37:49 +00:00
|
|
|
auto actual = result;
|
2023-05-28 18:55:32 +00:00
|
|
|
auto actual_trimmed = TRY(actual.trim("\n"sv, TrimMode::Right));
|
|
|
|
auto expectation_trimmed = TRY(expectation.trim("\n"sv, TrimMode::Right));
|
2023-05-27 17:46:17 +00:00
|
|
|
|
2023-05-28 18:55:32 +00:00
|
|
|
if (actual_trimmed == expectation_trimmed)
|
2023-05-27 17:46:17 +00:00
|
|
|
return TestResult::Pass;
|
|
|
|
|
2023-06-21 06:54:19 +00:00
|
|
|
auto const color_output = isatty(STDOUT_FILENO) ? Diff::ColorOutput::Yes : Diff::ColorOutput::No;
|
2023-05-28 18:55:32 +00:00
|
|
|
|
2023-06-21 06:54:19 +00:00
|
|
|
if (color_output == Diff::ColorOutput::Yes)
|
2024-07-30 18:01:05 +00:00
|
|
|
outln("\n\033[33;1mTest failed\033[0m: {}", url);
|
2023-06-12 09:51:28 +00:00
|
|
|
else
|
2024-07-30 18:01:05 +00:00
|
|
|
outln("\nTest failed: {}", url);
|
2023-05-28 18:55:32 +00:00
|
|
|
|
2023-06-27 23:20:48 +00:00
|
|
|
auto hunks = TRY(Diff::from_text(expectation, actual, 3));
|
2023-06-21 06:54:19 +00:00
|
|
|
auto out = TRY(Core::File::standard_output());
|
2023-06-27 23:20:48 +00:00
|
|
|
|
|
|
|
TRY(Diff::write_unified_header(expectation_path, expectation_path, *out));
|
|
|
|
for (auto const& hunk : hunks)
|
|
|
|
TRY(Diff::write_unified(hunk, *out, color_output));
|
2023-05-28 18:55:32 +00:00
|
|
|
|
2023-05-27 17:46:17 +00:00
|
|
|
return TestResult::Fail;
|
|
|
|
}
|
|
|
|
|
2024-10-04 14:08:31 +00:00
|
|
|
static ErrorOr<TestResult> run_ref_test(HeadlessWebContentView& view, URL::URL const& url, int timeout_in_milliseconds = DEFAULT_TIMEOUT_MS)
|
2023-08-13 22:37:49 +00:00
|
|
|
{
|
|
|
|
Core::EventLoop loop;
|
|
|
|
bool did_timeout = false;
|
|
|
|
|
2024-04-16 18:34:01 +00:00
|
|
|
auto timeout_timer = Core::Timer::create_single_shot(timeout_in_milliseconds, [&] {
|
2023-08-13 22:37:49 +00:00
|
|
|
did_timeout = true;
|
|
|
|
loop.quit(0);
|
2024-04-16 18:34:01 +00:00
|
|
|
});
|
2023-08-13 22:37:49 +00:00
|
|
|
|
|
|
|
RefPtr<Gfx::Bitmap> actual_screenshot, expectation_screenshot;
|
|
|
|
view.on_load_finish = [&](auto const&) {
|
|
|
|
if (actual_screenshot) {
|
|
|
|
expectation_screenshot = view.take_screenshot();
|
|
|
|
loop.quit(0);
|
|
|
|
} else {
|
|
|
|
actual_screenshot = view.take_screenshot();
|
2023-09-12 17:40:47 +00:00
|
|
|
view.debug_request("load-reference-page");
|
2023-08-13 22:37:49 +00:00
|
|
|
}
|
|
|
|
};
|
2024-10-02 16:38:10 +00:00
|
|
|
view.on_text_test_finish = [&](auto const&) {
|
2024-07-30 18:01:05 +00:00
|
|
|
dbgln("Unexpected text test finished during ref test for {}", url);
|
2024-01-18 20:08:36 +00:00
|
|
|
};
|
|
|
|
|
2024-07-30 18:01:05 +00:00
|
|
|
view.load(url);
|
2023-08-13 22:37:49 +00:00
|
|
|
|
2023-11-27 21:42:10 +00:00
|
|
|
timeout_timer->start();
|
2023-08-13 22:37:49 +00:00
|
|
|
loop.exec();
|
|
|
|
|
|
|
|
if (did_timeout)
|
|
|
|
return TestResult::Timeout;
|
|
|
|
|
|
|
|
VERIFY(actual_screenshot);
|
|
|
|
VERIFY(expectation_screenshot);
|
|
|
|
|
|
|
|
if (actual_screenshot->visually_equals(*expectation_screenshot))
|
|
|
|
return TestResult::Pass;
|
|
|
|
|
2024-10-04 14:08:31 +00:00
|
|
|
if (Application::the().dump_failed_ref_tests) {
|
2024-07-30 18:01:05 +00:00
|
|
|
warnln("\033[33;1mRef test {} failed; dumping screenshots\033[0m", url);
|
2024-08-05 04:55:39 +00:00
|
|
|
auto title = LexicalPath::title(URL::percent_decode(url.serialize_path()));
|
2023-11-10 16:50:39 +00:00
|
|
|
auto dump_screenshot = [&](Gfx::Bitmap& bitmap, StringView path) -> ErrorOr<void> {
|
|
|
|
auto screenshot_file = TRY(Core::File::open(path, Core::File::OpenMode::Write));
|
|
|
|
auto encoded_data = TRY(Gfx::PNGWriter::encode(bitmap));
|
|
|
|
TRY(screenshot_file->write_until_depleted(encoded_data));
|
|
|
|
warnln("\033[33;1mDumped {}\033[0m", TRY(FileSystem::real_path(path)));
|
|
|
|
return {};
|
|
|
|
};
|
|
|
|
|
|
|
|
auto mkdir_result = Core::System::mkdir("test-dumps"sv, 0755);
|
|
|
|
if (mkdir_result.is_error() && mkdir_result.error().code() != EEXIST)
|
|
|
|
return mkdir_result.release_error();
|
2024-10-01 10:49:14 +00:00
|
|
|
TRY(dump_screenshot(*actual_screenshot, ByteString::formatted("test-dumps/{}.png", title)));
|
|
|
|
TRY(dump_screenshot(*expectation_screenshot, ByteString::formatted("test-dumps/{}-ref.png", title)));
|
2023-11-10 16:50:39 +00:00
|
|
|
}
|
|
|
|
|
2023-08-13 22:37:49 +00:00
|
|
|
return TestResult::Fail;
|
|
|
|
}
|
|
|
|
|
2024-10-04 14:08:31 +00:00
|
|
|
static ErrorOr<TestResult> run_test(HeadlessWebContentView& view, StringView input_path, StringView expectation_path, TestMode mode)
|
2023-08-13 22:37:49 +00:00
|
|
|
{
|
2023-12-22 14:06:03 +00:00
|
|
|
// 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 = {};
|
2024-02-25 18:02:47 +00:00
|
|
|
|
2024-03-14 16:26:00 +00:00
|
|
|
view.on_request_file_picker = [&](auto const& accepted_file_types, auto allow_multiple_files) {
|
2024-02-25 18:02:47 +00:00
|
|
|
// Create some dummy files for tests.
|
|
|
|
Vector<Web::HTML::SelectedFile> selected_files;
|
|
|
|
|
2024-03-14 16:26:00 +00:00
|
|
|
bool add_txt_files = accepted_file_types.filters.is_empty();
|
|
|
|
bool add_cpp_files = false;
|
|
|
|
|
|
|
|
for (auto const& filter : accepted_file_types.filters) {
|
|
|
|
filter.visit(
|
|
|
|
[](Web::HTML::FileFilter::FileType) {},
|
|
|
|
[&](Web::HTML::FileFilter::MimeType const& mime_type) {
|
|
|
|
if (mime_type.value == "text/plain"sv)
|
|
|
|
add_txt_files = true;
|
|
|
|
},
|
|
|
|
[&](Web::HTML::FileFilter::Extension const& extension) {
|
|
|
|
if (extension.value == "cpp"sv)
|
|
|
|
add_cpp_files = true;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (add_txt_files) {
|
|
|
|
selected_files.empend("file1"sv, MUST(ByteBuffer::copy("Contents for file1"sv.bytes())));
|
|
|
|
|
|
|
|
if (allow_multiple_files == Web::HTML::AllowMultipleFiles::Yes) {
|
|
|
|
selected_files.empend("file2"sv, MUST(ByteBuffer::copy("Contents for file2"sv.bytes())));
|
|
|
|
selected_files.empend("file3"sv, MUST(ByteBuffer::copy("Contents for file3"sv.bytes())));
|
|
|
|
selected_files.empend("file4"sv, MUST(ByteBuffer::copy("Contents for file4"sv.bytes())));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (add_cpp_files) {
|
|
|
|
selected_files.empend("file1.cpp"sv, MUST(ByteBuffer::copy("int main() {{ return 1; }}"sv.bytes())));
|
|
|
|
|
|
|
|
if (allow_multiple_files == Web::HTML::AllowMultipleFiles::Yes) {
|
|
|
|
selected_files.empend("file2.cpp"sv, MUST(ByteBuffer::copy("int main() {{ return 2; }}"sv.bytes())));
|
|
|
|
}
|
2024-02-25 18:02:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
view.file_picker_closed(move(selected_files));
|
|
|
|
};
|
|
|
|
|
2024-03-18 03:22:27 +00:00
|
|
|
view.load(URL::URL("about:blank"sv));
|
2023-12-22 14:06:03 +00:00
|
|
|
MUST(promise->await());
|
|
|
|
|
2024-07-30 18:01:05 +00:00
|
|
|
auto url = URL::create_with_file_scheme(TRY(FileSystem::real_path(input_path)));
|
2023-12-19 00:23:26 +00:00
|
|
|
s_current_test_path = input_path;
|
2024-07-30 18:01:05 +00:00
|
|
|
|
2023-08-13 22:37:49 +00:00
|
|
|
switch (mode) {
|
|
|
|
case TestMode::Text:
|
|
|
|
case TestMode::Layout:
|
2024-10-04 14:08:31 +00:00
|
|
|
return run_dump_test(view, url, expectation_path, mode);
|
2023-08-13 22:37:49 +00:00
|
|
|
case TestMode::Ref:
|
2024-10-04 14:08:31 +00:00
|
|
|
return run_ref_test(view, url);
|
2023-08-13 22:37:49 +00:00
|
|
|
default:
|
|
|
|
VERIFY_NOT_REACHED();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-27 17:46:17 +00:00
|
|
|
struct Test {
|
2024-10-01 10:49:14 +00:00
|
|
|
ByteString input_path;
|
|
|
|
ByteString expectation_path;
|
2023-05-27 17:46:17 +00:00
|
|
|
TestMode mode;
|
|
|
|
Optional<TestResult> result;
|
|
|
|
};
|
|
|
|
|
2023-12-16 14:19:34 +00:00
|
|
|
static Vector<ByteString> s_skipped_tests;
|
2023-12-07 17:40:57 +00:00
|
|
|
|
|
|
|
static ErrorOr<void> load_test_config(StringView test_root_path)
|
|
|
|
{
|
|
|
|
auto config_path = LexicalPath::join(test_root_path, "TestConfig.ini"sv);
|
|
|
|
auto config_or_error = Core::ConfigFile::open(config_path.string());
|
|
|
|
|
|
|
|
if (config_or_error.is_error()) {
|
|
|
|
if (config_or_error.error().code() == ENOENT)
|
|
|
|
return {};
|
|
|
|
dbgln("Unable to open test config {}", config_path);
|
|
|
|
return config_or_error.release_error();
|
|
|
|
}
|
|
|
|
|
|
|
|
auto config = config_or_error.release_value();
|
|
|
|
|
|
|
|
for (auto const& group : config->groups()) {
|
|
|
|
if (group == "Skipped"sv) {
|
|
|
|
for (auto& key : config->keys(group))
|
|
|
|
s_skipped_tests.append(LexicalPath::join(test_root_path, key).string());
|
|
|
|
} else {
|
|
|
|
warnln("Unknown group '{}' in config {}", group, config_path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2023-08-13 22:37:49 +00:00
|
|
|
static ErrorOr<void> collect_dump_tests(Vector<Test>& tests, StringView path, StringView trail, TestMode mode)
|
2023-05-27 17:46:17 +00:00
|
|
|
{
|
2024-10-01 10:49:14 +00:00
|
|
|
Core::DirIterator it(ByteString::formatted("{}/input/{}", path, trail), Core::DirIterator::Flags::SkipDots);
|
2023-05-27 17:46:17 +00:00
|
|
|
while (it.has_next()) {
|
|
|
|
auto name = it.next_path();
|
2024-10-01 10:49:14 +00:00
|
|
|
auto input_path = TRY(FileSystem::real_path(ByteString::formatted("{}/input/{}/{}", path, trail, name)));
|
2023-05-27 17:46:17 +00:00
|
|
|
if (FileSystem::is_directory(input_path)) {
|
2024-10-01 10:49:14 +00:00
|
|
|
TRY(collect_dump_tests(tests, path, ByteString::formatted("{}/{}", trail, name), mode));
|
2023-05-27 17:46:17 +00:00
|
|
|
continue;
|
|
|
|
}
|
2024-02-17 22:25:05 +00:00
|
|
|
if (!name.ends_with(".html"sv) && !name.ends_with(".svg"sv))
|
2023-05-27 17:46:17 +00:00
|
|
|
continue;
|
|
|
|
auto basename = LexicalPath::title(name);
|
2024-10-01 10:49:14 +00:00
|
|
|
auto expectation_path = ByteString::formatted("{}/expected/{}/{}.txt", path, trail, basename);
|
2023-05-27 17:46:17 +00:00
|
|
|
|
2024-10-01 10:49:14 +00:00
|
|
|
tests.append({ input_path, move(expectation_path), mode, {} });
|
2023-05-27 17:46:17 +00:00
|
|
|
}
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2023-08-13 22:37:49 +00:00
|
|
|
static ErrorOr<void> collect_ref_tests(Vector<Test>& tests, StringView path)
|
|
|
|
{
|
2023-09-12 17:40:47 +00:00
|
|
|
TRY(Core::Directory::for_each_entry(path, Core::DirIterator::SkipDots, [&](Core::DirectoryEntry const& entry, Core::Directory const&) -> ErrorOr<IterationDecision> {
|
|
|
|
if (entry.type == Core::DirectoryEntry::Type::Directory)
|
|
|
|
return IterationDecision::Continue;
|
2024-10-01 10:49:14 +00:00
|
|
|
auto input_path = TRY(FileSystem::real_path(ByteString::formatted("{}/{}", path, entry.name)));
|
|
|
|
tests.append({ input_path, {}, TestMode::Ref, {} });
|
2023-09-12 17:40:47 +00:00
|
|
|
return IterationDecision::Continue;
|
2023-08-13 22:37:49 +00:00
|
|
|
}));
|
|
|
|
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2024-10-04 14:20:22 +00:00
|
|
|
static ErrorOr<int> run_tests(Core::AnonymousBuffer const& theme, Gfx::IntSize window_size)
|
2023-05-27 17:46:17 +00:00
|
|
|
{
|
2024-10-04 14:08:31 +00:00
|
|
|
auto& app = Application::the();
|
|
|
|
TRY(load_test_config(app.test_root_path));
|
2023-12-07 17:40:57 +00:00
|
|
|
|
2023-05-27 17:46:17 +00:00
|
|
|
Vector<Test> tests;
|
2024-10-04 14:08:31 +00:00
|
|
|
auto test_glob = ByteString::formatted("*{}*", app.test_glob);
|
|
|
|
|
|
|
|
TRY(collect_dump_tests(tests, ByteString::formatted("{}/Layout", app.test_root_path), "."sv, TestMode::Layout));
|
|
|
|
TRY(collect_dump_tests(tests, ByteString::formatted("{}/Text", app.test_root_path), "."sv, TestMode::Text));
|
|
|
|
TRY(collect_ref_tests(tests, ByteString::formatted("{}/Ref", app.test_root_path)));
|
2024-07-19 21:25:33 +00:00
|
|
|
#ifndef AK_OS_MACOS
|
2024-10-04 14:08:31 +00:00
|
|
|
TRY(collect_ref_tests(tests, ByteString::formatted("{}/Screenshot", app.test_root_path)));
|
2024-07-19 21:25:33 +00:00
|
|
|
#endif
|
2023-05-27 17:46:17 +00:00
|
|
|
|
2024-01-24 21:31:33 +00:00
|
|
|
tests.remove_all_matching([&](auto const& test) {
|
2024-10-01 10:49:14 +00:00
|
|
|
return !test.input_path.matches(test_glob, CaseSensitivity::CaseSensitive);
|
2024-01-24 21:31:33 +00:00
|
|
|
});
|
|
|
|
|
2024-10-04 14:08:31 +00:00
|
|
|
if (app.test_dry_run) {
|
|
|
|
outln("Found {} tests...", tests.size());
|
|
|
|
|
|
|
|
for (auto const& [i, test] : enumerate(tests))
|
|
|
|
outln("{}/{}: {}", i + 1, tests.size(), LexicalPath::relative_path(test.input_path, app.test_root_path));
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2024-10-04 14:20:22 +00:00
|
|
|
auto& view = *TRY(app.create_web_view(theme, window_size));
|
|
|
|
view.clear_content_filters();
|
|
|
|
|
2023-05-27 17:46:17 +00:00
|
|
|
size_t pass_count = 0;
|
|
|
|
size_t fail_count = 0;
|
|
|
|
size_t timeout_count = 0;
|
2023-12-07 17:40:57 +00:00
|
|
|
size_t skipped_count = 0;
|
2023-05-27 17:46:17 +00:00
|
|
|
|
|
|
|
bool is_tty = isatty(STDOUT_FILENO);
|
2024-10-04 14:08:31 +00:00
|
|
|
outln("Running {} tests...", tests.size());
|
2024-10-01 10:33:21 +00:00
|
|
|
|
2023-05-27 17:46:17 +00:00
|
|
|
for (size_t i = 0; i < tests.size(); ++i) {
|
|
|
|
auto& test = tests[i];
|
|
|
|
|
2024-10-04 14:08:31 +00:00
|
|
|
if (is_tty) {
|
2023-05-27 17:46:17 +00:00
|
|
|
// Keep clearing and reusing the same line if stdout is a TTY.
|
|
|
|
out("\33[2K\r");
|
|
|
|
}
|
|
|
|
|
2024-10-04 14:08:31 +00:00
|
|
|
out("{}/{}: {}", i + 1, tests.size(), LexicalPath::relative_path(test.input_path, app.test_root_path));
|
2024-10-01 10:33:21 +00:00
|
|
|
|
2023-05-28 06:02:55 +00:00
|
|
|
if (is_tty)
|
|
|
|
fflush(stdout);
|
|
|
|
else
|
2023-05-27 17:46:17 +00:00
|
|
|
outln("");
|
|
|
|
|
2024-10-01 10:49:14 +00:00
|
|
|
if (s_skipped_tests.contains_slow(test.input_path)) {
|
2023-12-07 17:40:57 +00:00
|
|
|
test.result = TestResult::Skipped;
|
|
|
|
++skipped_count;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2024-10-04 14:20:22 +00:00
|
|
|
test.result = TRY(run_test(view, test.input_path, test.expectation_path, test.mode));
|
2023-05-27 17:46:17 +00:00
|
|
|
switch (*test.result) {
|
|
|
|
case TestResult::Pass:
|
|
|
|
++pass_count;
|
|
|
|
break;
|
|
|
|
case TestResult::Fail:
|
|
|
|
++fail_count;
|
|
|
|
break;
|
|
|
|
case TestResult::Timeout:
|
|
|
|
++timeout_count;
|
|
|
|
break;
|
2023-12-07 17:40:57 +00:00
|
|
|
case TestResult::Skipped:
|
|
|
|
VERIFY_NOT_REACHED();
|
|
|
|
break;
|
2023-05-27 17:46:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_tty)
|
|
|
|
outln("\33[2K\rDone!");
|
|
|
|
|
|
|
|
outln("==================================================");
|
2023-12-07 17:40:57 +00:00
|
|
|
outln("Pass: {}, Fail: {}, Skipped: {}, Timeout: {}", pass_count, fail_count, skipped_count, timeout_count);
|
2023-05-27 17:46:17 +00:00
|
|
|
outln("==================================================");
|
|
|
|
for (auto& test : tests) {
|
|
|
|
if (*test.result == TestResult::Pass)
|
|
|
|
continue;
|
2023-12-07 17:40:57 +00:00
|
|
|
outln("{}: {}", test_result_to_string(*test.result), test.input_path);
|
2023-05-27 17:46:17 +00:00
|
|
|
}
|
|
|
|
|
2024-10-04 14:08:31 +00:00
|
|
|
if (app.dump_gc_graph) {
|
2024-10-04 14:20:22 +00:00
|
|
|
auto path = view.dump_gc_graph();
|
2024-04-20 18:13:00 +00:00
|
|
|
if (path.is_error()) {
|
|
|
|
warnln("Failed to dump GC graph: {}", path.error());
|
|
|
|
} else {
|
|
|
|
outln("GC graph dumped to {}", path.value());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-27 17:46:17 +00:00
|
|
|
if (timeout_count == 0 && fail_count == 0)
|
|
|
|
return 0;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2024-07-30 18:01:05 +00:00
|
|
|
ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|
|
|
{
|
2024-04-22 14:32:02 +00:00
|
|
|
platform_init();
|
2024-07-30 18:01:05 +00:00
|
|
|
|
|
|
|
auto app = Application::create(arguments, "about:newtab"sv);
|
2024-10-04 14:20:22 +00:00
|
|
|
TRY(app->launch_services());
|
2024-07-30 18:01:05 +00:00
|
|
|
|
|
|
|
Core::ResourceImplementation::install(make<Core::ResourceImplementationFile>(MUST(String::from_byte_string(app->resources_folder))));
|
|
|
|
|
|
|
|
auto theme_path = LexicalPath::join(app->resources_folder, "themes"sv, "Default.ini"sv);
|
2023-03-12 16:38:15 +00:00
|
|
|
auto theme = TRY(Gfx::load_system_theme(theme_path.string()));
|
2022-04-03 16:15:36 +00:00
|
|
|
|
2023-03-12 16:38:15 +00:00
|
|
|
// FIXME: Allow passing the window size as an argument.
|
|
|
|
static constexpr Gfx::IntSize window_size { 800, 600 };
|
2022-04-03 16:15:36 +00:00
|
|
|
|
2024-07-30 18:01:05 +00:00
|
|
|
if (!app->test_root_path.is_empty()) {
|
2024-10-04 14:20:22 +00:00
|
|
|
app->test_root_path = LexicalPath::absolute_path(TRY(FileSystem::current_working_directory()), app->test_root_path);
|
|
|
|
return run_tests(theme, window_size);
|
2023-05-27 17:46:17 +00:00
|
|
|
}
|
|
|
|
|
2024-10-04 14:20:22 +00:00
|
|
|
auto& view = *TRY(app->create_web_view(move(theme), window_size));
|
2024-10-01 10:33:21 +00:00
|
|
|
|
2024-07-30 18:01:05 +00:00
|
|
|
VERIFY(!WebView::Application::chrome_options().urls.is_empty());
|
|
|
|
auto const& url = WebView::Application::chrome_options().urls.first();
|
|
|
|
if (!url.is_valid()) {
|
|
|
|
warnln("Invalid URL: \"{}\"", url);
|
2023-10-30 17:27:53 +00:00
|
|
|
return Error::from_string_literal("Invalid URL");
|
|
|
|
}
|
|
|
|
|
2024-07-30 18:01:05 +00:00
|
|
|
if (app->dump_layout_tree) {
|
2024-10-04 14:20:22 +00:00
|
|
|
TRY(run_dump_test(view, url, ""sv, TestMode::Layout));
|
2023-12-24 11:28:49 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2024-07-30 18:01:05 +00:00
|
|
|
if (app->dump_text) {
|
2024-10-04 14:20:22 +00:00
|
|
|
TRY(run_dump_test(view, url, ""sv, TestMode::Text));
|
2023-12-24 11:28:49 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2024-07-30 18:01:05 +00:00
|
|
|
if (!WebView::Application::chrome_options().webdriver_content_ipc_path.has_value()) {
|
2024-10-04 14:20:22 +00:00
|
|
|
auto timer = TRY(load_page_for_screenshot_and_exit(Core::EventLoop::current(), view, url, app->screenshot_timeout));
|
2024-07-30 18:01:05 +00:00
|
|
|
return app->execute();
|
2023-12-24 11:28:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2022-04-03 16:15:36 +00:00
|
|
|
}
|