mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 22:17:42 +00:00
LibWeb: Add --layout-test-mode
flag to HeadlessBrowser
The `layout-test-mode` flag changes the font to be SerenitySans as this is the font used for layout tests for cross-platform compatibility of tests.
This commit is contained in:
parent
af26b76e0a
commit
c719a542c5
6 changed files with 27 additions and 8 deletions
|
@ -18,7 +18,8 @@ extern DeprecatedString s_serenity_resource_root;
|
||||||
|
|
||||||
namespace Ladybird {
|
namespace Ladybird {
|
||||||
|
|
||||||
FontPluginQt::FontPluginQt()
|
FontPluginQt::FontPluginQt(bool is_layout_test_mode)
|
||||||
|
: m_is_layout_test_mode(is_layout_test_mode)
|
||||||
{
|
{
|
||||||
// Load the default SerenityOS fonts...
|
// Load the default SerenityOS fonts...
|
||||||
Gfx::FontDatabase::set_default_fonts_lookup_path(DeprecatedString::formatted("{}/res/fonts", s_serenity_resource_root));
|
Gfx::FontDatabase::set_default_fonts_lookup_path(DeprecatedString::formatted("{}/res/fonts", s_serenity_resource_root));
|
||||||
|
@ -69,6 +70,11 @@ void FontPluginQt::update_generic_fonts()
|
||||||
m_generic_font_names.resize(static_cast<size_t>(Web::Platform::GenericFont::__Count));
|
m_generic_font_names.resize(static_cast<size_t>(Web::Platform::GenericFont::__Count));
|
||||||
|
|
||||||
auto update_mapping = [&](Web::Platform::GenericFont generic_font, QFont::StyleHint qfont_style_hint, ReadonlySpan<DeprecatedString> fallbacks) {
|
auto update_mapping = [&](Web::Platform::GenericFont generic_font, QFont::StyleHint qfont_style_hint, ReadonlySpan<DeprecatedString> fallbacks) {
|
||||||
|
if (m_is_layout_test_mode) {
|
||||||
|
m_generic_font_names[static_cast<size_t>(generic_font)] = "SerenitySans";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
QFont qt_font;
|
QFont qt_font;
|
||||||
qt_font.setStyleHint(qfont_style_hint);
|
qt_font.setStyleHint(qfont_style_hint);
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@ namespace Ladybird {
|
||||||
|
|
||||||
class FontPluginQt final : public Web::Platform::FontPlugin {
|
class FontPluginQt final : public Web::Platform::FontPlugin {
|
||||||
public:
|
public:
|
||||||
FontPluginQt();
|
FontPluginQt(bool is_layout_test_mode);
|
||||||
virtual ~FontPluginQt();
|
virtual ~FontPluginQt();
|
||||||
|
|
||||||
virtual Gfx::Font& default_font() override;
|
virtual Gfx::Font& default_font() override;
|
||||||
|
@ -27,6 +27,7 @@ private:
|
||||||
Vector<DeprecatedString> m_generic_font_names;
|
Vector<DeprecatedString> m_generic_font_names;
|
||||||
RefPtr<Gfx::Font> m_default_font;
|
RefPtr<Gfx::Font> m_default_font;
|
||||||
RefPtr<Gfx::Font> m_default_fixed_width_font;
|
RefPtr<Gfx::Font> m_default_fixed_width_font;
|
||||||
|
bool m_is_layout_test_mode { false };
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,14 +63,16 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||||
Web::FrameLoader::set_default_favicon_path(DeprecatedString::formatted("{}/res/icons/16x16/app-browser.png", s_serenity_resource_root));
|
Web::FrameLoader::set_default_favicon_path(DeprecatedString::formatted("{}/res/icons/16x16/app-browser.png", s_serenity_resource_root));
|
||||||
|
|
||||||
int webcontent_fd_passing_socket { -1 };
|
int webcontent_fd_passing_socket { -1 };
|
||||||
|
bool is_layout_test_mode = false;
|
||||||
|
|
||||||
Core::ArgsParser args_parser;
|
Core::ArgsParser args_parser;
|
||||||
args_parser.add_option(webcontent_fd_passing_socket, "File descriptor of the passing socket for the WebContent connection", "webcontent-fd-passing-socket", 'c', "webcontent_fd_passing_socket");
|
args_parser.add_option(webcontent_fd_passing_socket, "File descriptor of the passing socket for the WebContent connection", "webcontent-fd-passing-socket", 'c', "webcontent_fd_passing_socket");
|
||||||
|
args_parser.add_option(is_layout_test_mode, "Is layout test mode", "layout-test-mode", 0);
|
||||||
args_parser.parse(arguments);
|
args_parser.parse(arguments);
|
||||||
|
|
||||||
VERIFY(webcontent_fd_passing_socket >= 0);
|
VERIFY(webcontent_fd_passing_socket >= 0);
|
||||||
|
|
||||||
Web::Platform::FontPlugin::install(*new Ladybird::FontPluginQt);
|
Web::Platform::FontPlugin::install(*new Ladybird::FontPluginQt(is_layout_test_mode));
|
||||||
|
|
||||||
Web::FrameLoader::set_error_page_url(DeprecatedString::formatted("file://{}/res/html/error.html", s_serenity_resource_root));
|
Web::FrameLoader::set_error_page_url(DeprecatedString::formatted("file://{}/res/html/error.html", s_serenity_resource_root));
|
||||||
|
|
||||||
|
|
|
@ -126,7 +126,7 @@ void ViewImplementation::run_javascript(StringView js_source)
|
||||||
|
|
||||||
#if !defined(AK_OS_SERENITY)
|
#if !defined(AK_OS_SERENITY)
|
||||||
|
|
||||||
ErrorOr<NonnullRefPtr<WebView::WebContentClient>> ViewImplementation::launch_web_content_process(ReadonlySpan<String> candidate_web_content_paths, EnableCallgrindProfiling enable_callgrind_profiling)
|
ErrorOr<NonnullRefPtr<WebView::WebContentClient>> ViewImplementation::launch_web_content_process(ReadonlySpan<String> candidate_web_content_paths, EnableCallgrindProfiling enable_callgrind_profiling, IsLayoutTestMode is_layout_test_mode)
|
||||||
{
|
{
|
||||||
int socket_fds[2] {};
|
int socket_fds[2] {};
|
||||||
TRY(Core::System::socketpair(AF_LOCAL, SOCK_STREAM, 0, socket_fds));
|
TRY(Core::System::socketpair(AF_LOCAL, SOCK_STREAM, 0, socket_fds));
|
||||||
|
@ -162,6 +162,8 @@ ErrorOr<NonnullRefPtr<WebView::WebContentClient>> ViewImplementation::launch_web
|
||||||
};
|
};
|
||||||
if (enable_callgrind_profiling == EnableCallgrindProfiling::No)
|
if (enable_callgrind_profiling == EnableCallgrindProfiling::No)
|
||||||
arguments.remove(0, callgrind_prefix_length);
|
arguments.remove(0, callgrind_prefix_length);
|
||||||
|
if (is_layout_test_mode == IsLayoutTestMode::Yes)
|
||||||
|
arguments.append("--layout-test-mode"sv);
|
||||||
|
|
||||||
result = Core::System::exec(arguments[0], arguments.span(), Core::System::SearchInPath::Yes);
|
result = Core::System::exec(arguments[0], arguments.span(), Core::System::SearchInPath::Yes);
|
||||||
if (!result.is_error())
|
if (!result.is_error())
|
||||||
|
|
|
@ -24,6 +24,11 @@ enum class EnableCallgrindProfiling {
|
||||||
Yes
|
Yes
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum class IsLayoutTestMode {
|
||||||
|
No,
|
||||||
|
Yes
|
||||||
|
};
|
||||||
|
|
||||||
class ViewImplementation {
|
class ViewImplementation {
|
||||||
public:
|
public:
|
||||||
virtual ~ViewImplementation() { }
|
virtual ~ViewImplementation() { }
|
||||||
|
@ -131,7 +136,7 @@ protected:
|
||||||
virtual void create_client(EnableCallgrindProfiling = EnableCallgrindProfiling::No) {};
|
virtual void create_client(EnableCallgrindProfiling = EnableCallgrindProfiling::No) {};
|
||||||
|
|
||||||
#if !defined(AK_OS_SERENITY)
|
#if !defined(AK_OS_SERENITY)
|
||||||
ErrorOr<NonnullRefPtr<WebView::WebContentClient>> launch_web_content_process(ReadonlySpan<String> candidate_web_content_paths, EnableCallgrindProfiling = EnableCallgrindProfiling::No);
|
ErrorOr<NonnullRefPtr<WebView::WebContentClient>> launch_web_content_process(ReadonlySpan<String> candidate_web_content_paths, EnableCallgrindProfiling = EnableCallgrindProfiling::No, IsLayoutTestMode = IsLayoutTestMode::No);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
struct SharedBitmap {
|
struct SharedBitmap {
|
||||||
|
|
|
@ -44,15 +44,16 @@
|
||||||
|
|
||||||
class HeadlessWebContentView final : public WebView::ViewImplementation {
|
class HeadlessWebContentView final : public WebView::ViewImplementation {
|
||||||
public:
|
public:
|
||||||
static ErrorOr<NonnullOwnPtr<HeadlessWebContentView>> create(Core::AnonymousBuffer theme, Gfx::IntSize const& window_size, StringView web_driver_ipc_path)
|
static ErrorOr<NonnullOwnPtr<HeadlessWebContentView>> create(Core::AnonymousBuffer theme, Gfx::IntSize const& window_size, StringView web_driver_ipc_path, WebView::IsLayoutTestMode is_layout_test_mode = WebView::IsLayoutTestMode::No)
|
||||||
{
|
{
|
||||||
auto view = TRY(adopt_nonnull_own_or_enomem(new (nothrow) HeadlessWebContentView()));
|
auto view = TRY(adopt_nonnull_own_or_enomem(new (nothrow) HeadlessWebContentView()));
|
||||||
|
|
||||||
#if defined(AK_OS_SERENITY)
|
#if defined(AK_OS_SERENITY)
|
||||||
view->m_client_state.client = TRY(WebView::WebContentClient::try_create(*view));
|
view->m_client_state.client = TRY(WebView::WebContentClient::try_create(*view));
|
||||||
|
(void)is_layout_test_mode;
|
||||||
#else
|
#else
|
||||||
auto candidate_web_content_paths = TRY(get_paths_for_helper_process("WebContent"sv));
|
auto candidate_web_content_paths = TRY(get_paths_for_helper_process("WebContent"sv));
|
||||||
view->m_client_state.client = TRY(view->launch_web_content_process(candidate_web_content_paths));
|
view->m_client_state.client = TRY(view->launch_web_content_process(candidate_web_content_paths, WebView::EnableCallgrindProfiling::No, is_layout_test_mode));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
view->client().async_update_system_theme(move(theme));
|
view->client().async_update_system_theme(move(theme));
|
||||||
|
@ -209,6 +210,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||||
auto resources_folder = "/res"sv;
|
auto resources_folder = "/res"sv;
|
||||||
StringView web_driver_ipc_path;
|
StringView web_driver_ipc_path;
|
||||||
bool dump_layout_tree = false;
|
bool dump_layout_tree = false;
|
||||||
|
bool is_layout_test_mode = false;
|
||||||
|
|
||||||
Core::ArgsParser args_parser;
|
Core::ArgsParser args_parser;
|
||||||
args_parser.set_general_help("This utility runs the Browser in headless mode.");
|
args_parser.set_general_help("This utility runs the Browser in headless mode.");
|
||||||
|
@ -216,6 +218,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||||
args_parser.add_option(dump_layout_tree, "Dump layout tree and exit", "dump-layout-tree", 'd');
|
args_parser.add_option(dump_layout_tree, "Dump layout tree and exit", "dump-layout-tree", 'd');
|
||||||
args_parser.add_option(resources_folder, "Path of the base resources folder (defaults to /res)", "resources", 'r', "resources-root-path");
|
args_parser.add_option(resources_folder, "Path of the base resources folder (defaults to /res)", "resources", 'r', "resources-root-path");
|
||||||
args_parser.add_option(web_driver_ipc_path, "Path to the WebDriver IPC socket", "webdriver-ipc-path", 0, "path");
|
args_parser.add_option(web_driver_ipc_path, "Path to the WebDriver IPC socket", "webdriver-ipc-path", 0, "path");
|
||||||
|
args_parser.add_option(is_layout_test_mode, "Enable layout test mode", "layout-test-mode", 0);
|
||||||
args_parser.add_positional_argument(url, "URL to open", "url", Core::ArgsParser::Required::Yes);
|
args_parser.add_positional_argument(url, "URL to open", "url", Core::ArgsParser::Required::Yes);
|
||||||
args_parser.parse(arguments);
|
args_parser.parse(arguments);
|
||||||
|
|
||||||
|
@ -232,7 +235,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||||
// FIXME: Allow passing the window size as an argument.
|
// FIXME: Allow passing the window size as an argument.
|
||||||
static constexpr Gfx::IntSize window_size { 800, 600 };
|
static constexpr Gfx::IntSize window_size { 800, 600 };
|
||||||
|
|
||||||
auto view = TRY(HeadlessWebContentView::create(move(theme), window_size, web_driver_ipc_path));
|
auto view = TRY(HeadlessWebContentView::create(move(theme), window_size, web_driver_ipc_path, is_layout_test_mode ? WebView::IsLayoutTestMode::Yes : WebView::IsLayoutTestMode::No));
|
||||||
RefPtr<Core::Timer> timer;
|
RefPtr<Core::Timer> timer;
|
||||||
|
|
||||||
if (dump_layout_tree) {
|
if (dump_layout_tree) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue