2024-10-10 12:56:27 -03:00
|
|
|
/*
|
2025-05-01 12:44:29 -03:00
|
|
|
* Copyright (c) 2024-2025, Tim Flynn <trflynn89@ladybird.org>
|
2024-10-10 12:56:27 -03:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
|
*/
|
|
|
|
|
|
2025-06-06 21:11:13 -03:00
|
|
|
#include "TestWebView.h"
|
|
|
|
|
|
2026-06-13 11:06:58 -03:00
|
|
|
#include "Application.h"
|
|
|
|
|
|
2026-05-21 12:46:17 -03:00
|
|
|
#include <LibCore/AnonymousBuffer.h>
|
2024-10-10 12:56:27 -03:00
|
|
|
#include <LibGfx/Bitmap.h>
|
|
|
|
|
#include <LibGfx/ShareableBitmap.h>
|
|
|
|
|
|
2025-06-06 21:11:13 -03:00
|
|
|
namespace TestWeb {
|
2024-10-10 12:56:27 -03:00
|
|
|
|
2025-06-06 21:11:13 -03:00
|
|
|
NonnullOwnPtr<TestWebView> TestWebView::create(Core::AnonymousBuffer theme, Web::DevicePixelSize window_size)
|
2024-10-10 12:56:27 -03:00
|
|
|
{
|
2025-06-06 21:11:13 -03:00
|
|
|
auto view = adopt_own(*new TestWebView(move(theme), window_size));
|
2024-10-21 19:54:25 -03:00
|
|
|
view->initialize_client(CreateNewClient::Yes);
|
2024-10-10 12:56:27 -03:00
|
|
|
|
2024-10-21 19:54:25 -03:00
|
|
|
return view;
|
|
|
|
|
}
|
2024-10-10 12:56:27 -03:00
|
|
|
|
2025-06-06 21:11:13 -03:00
|
|
|
TestWebView::TestWebView(Core::AnonymousBuffer theme, Web::DevicePixelSize viewport_size)
|
2025-06-06 16:42:12 -03:00
|
|
|
: WebView::HeadlessWebView(move(theme), viewport_size)
|
|
|
|
|
, m_test_promise(TestPromise::construct())
|
2024-10-21 19:54:25 -03:00
|
|
|
{
|
2024-10-10 12:56:27 -03:00
|
|
|
}
|
|
|
|
|
|
2026-05-21 11:36:25 -03:00
|
|
|
void TestWebView::clear_content_blockers()
|
2024-10-10 12:56:27 -03:00
|
|
|
{
|
2026-05-21 12:46:17 -03:00
|
|
|
client().async_set_content_blockers(m_client_state.page_index, MUST(Core::AnonymousBuffer::create_with_size(0)));
|
2024-10-10 12:56:27 -03:00
|
|
|
}
|
|
|
|
|
|
2026-06-13 11:06:58 -03:00
|
|
|
NonnullRefPtr<Core::Promise<Empty>> TestWebView::reset_session_history()
|
|
|
|
|
{
|
|
|
|
|
return WebView::ViewImplementation::reset_session_history_for_testing();
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-13 07:23:09 -03:00
|
|
|
pid_t TestWebView::web_content_pid() const
|
|
|
|
|
{
|
|
|
|
|
return client().pid();
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-06 21:11:13 -03:00
|
|
|
NonnullRefPtr<Core::Promise<RefPtr<Gfx::Bitmap const>>> TestWebView::take_screenshot()
|
2024-10-10 12:56:27 -03:00
|
|
|
{
|
|
|
|
|
VERIFY(!m_pending_screenshot);
|
|
|
|
|
|
2025-04-15 18:50:18 -03:00
|
|
|
m_pending_screenshot = Core::Promise<RefPtr<Gfx::Bitmap const>>::construct();
|
2026-05-30 11:58:13 -03:00
|
|
|
client().async_take_document_screenshot(page_id());
|
2024-10-10 12:56:27 -03:00
|
|
|
|
|
|
|
|
return *m_pending_screenshot;
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-06 21:11:13 -03:00
|
|
|
void TestWebView::did_receive_screenshot(Badge<WebView::WebContentClient>, Gfx::ShareableBitmap const& screenshot)
|
2024-10-10 12:56:27 -03:00
|
|
|
{
|
2026-03-08 04:49:51 -03:00
|
|
|
// NOTE: The screenshot may arrive after a timeout already completed the test and cleared m_pending_screenshot.
|
|
|
|
|
if (!m_pending_screenshot)
|
|
|
|
|
return;
|
2024-10-10 12:56:27 -03:00
|
|
|
|
|
|
|
|
auto pending_screenshot = move(m_pending_screenshot);
|
|
|
|
|
pending_screenshot->resolve(screenshot.bitmap());
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-06 21:11:13 -03:00
|
|
|
void TestWebView::on_test_complete(TestCompletion completion)
|
2024-10-10 12:56:27 -03:00
|
|
|
{
|
2024-12-17 12:05:33 -03:00
|
|
|
m_pending_screenshot.clear();
|
|
|
|
|
m_pending_dialog = Web::Page::PendingDialog::None;
|
|
|
|
|
m_pending_prompt_text.clear();
|
2026-03-16 21:28:02 -03:00
|
|
|
m_is_fullscreen = Web::ViewportIsFullscreen::No;
|
|
|
|
|
client().async_set_viewport(m_client_state.page_index, viewport_size(), 1.0, Web::ViewportIsFullscreen::No);
|
2024-12-17 12:05:33 -03:00
|
|
|
|
2024-10-10 12:56:27 -03:00
|
|
|
m_test_promise->resolve(move(completion));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|