mirror of
https://github.com/fergalmoran/ladybird.git
synced 2025-12-22 09:19:03 +00:00
headless-browser: Implement dialog-related WebView callbacks
This allows us to headlessly run WPT tests which involve dialogs.
This commit is contained in:
committed by
Andreas Kling
parent
6590b8a1a7
commit
777eec095b
@@ -35,6 +35,62 @@ HeadlessWebView::HeadlessWebView(Core::AnonymousBuffer theme, Gfx::IntSize viewp
|
||||
|
||||
return worker_client->clone_transport();
|
||||
};
|
||||
|
||||
on_request_alert = [this](auto const&) {
|
||||
m_pending_dialog = Web::Page::PendingDialog::Alert;
|
||||
};
|
||||
|
||||
on_request_confirm = [this](auto const&) {
|
||||
m_pending_dialog = Web::Page::PendingDialog::Confirm;
|
||||
};
|
||||
|
||||
on_request_prompt = [this](auto const&, auto const& prompt_text) {
|
||||
m_pending_dialog = Web::Page::PendingDialog::Prompt;
|
||||
m_pending_prompt_text = prompt_text;
|
||||
};
|
||||
|
||||
on_request_set_prompt_text = [this](auto const& prompt_text) {
|
||||
m_pending_prompt_text = prompt_text;
|
||||
};
|
||||
|
||||
on_request_accept_dialog = [this]() {
|
||||
switch (m_pending_dialog) {
|
||||
case Web::Page::PendingDialog::None:
|
||||
VERIFY_NOT_REACHED();
|
||||
break;
|
||||
case Web::Page::PendingDialog::Alert:
|
||||
alert_closed();
|
||||
break;
|
||||
case Web::Page::PendingDialog::Confirm:
|
||||
confirm_closed(true);
|
||||
break;
|
||||
case Web::Page::PendingDialog::Prompt:
|
||||
prompt_closed(move(m_pending_prompt_text));
|
||||
break;
|
||||
}
|
||||
|
||||
m_pending_dialog = Web::Page::PendingDialog::None;
|
||||
};
|
||||
|
||||
on_request_dismiss_dialog = [this]() {
|
||||
switch (m_pending_dialog) {
|
||||
case Web::Page::PendingDialog::None:
|
||||
VERIFY_NOT_REACHED();
|
||||
break;
|
||||
case Web::Page::PendingDialog::Alert:
|
||||
alert_closed();
|
||||
break;
|
||||
case Web::Page::PendingDialog::Confirm:
|
||||
confirm_closed(false);
|
||||
break;
|
||||
case Web::Page::PendingDialog::Prompt:
|
||||
prompt_closed({});
|
||||
break;
|
||||
}
|
||||
|
||||
m_pending_dialog = Web::Page::PendingDialog::None;
|
||||
m_pending_prompt_text.clear();
|
||||
};
|
||||
}
|
||||
|
||||
NonnullOwnPtr<HeadlessWebView> HeadlessWebView::create(Core::AnonymousBuffer theme, Gfx::IntSize window_size)
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#include <LibCore/Promise.h>
|
||||
#include <LibGfx/Forward.h>
|
||||
#include <LibGfx/Size.h>
|
||||
#include <LibWeb/Page/Page.h>
|
||||
#include <LibWeb/PixelUnits.h>
|
||||
#include <LibWebView/ViewImplementation.h>
|
||||
|
||||
@@ -48,6 +49,9 @@ private:
|
||||
RefPtr<Core::Promise<RefPtr<Gfx::Bitmap>>> m_pending_screenshot;
|
||||
|
||||
NonnullRefPtr<TestPromise> m_test_promise;
|
||||
|
||||
Web::Page::PendingDialog m_pending_dialog { Web::Page::PendingDialog::None };
|
||||
Optional<String> m_pending_prompt_text;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user