mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-10-04 07:09:41 +00:00
headless-browser: Make taking screenshots during tests more asynchronous
This will be necessary to run tests concurrently, otherwise taking a screenshot for one test will block all tests from executing.
This commit is contained in:
parent
642a611418
commit
e6975ec76a
Notes:
github-actions[bot]
2024-10-06 17:25:36 +00:00
Author: https://github.com/trflynn89
Commit: e6975ec76a
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1627
Reviewed-by: https://github.com/ADKaster
Reviewed-by: https://github.com/shannonbooth
1 changed files with 26 additions and 21 deletions
|
@ -159,23 +159,14 @@ public:
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
RefPtr<Gfx::Bitmap> take_screenshot()
|
NonnullRefPtr<Core::Promise<RefPtr<Gfx::Bitmap>>> take_screenshot()
|
||||||
{
|
{
|
||||||
VERIFY(!m_pending_screenshot);
|
VERIFY(!m_pending_screenshot);
|
||||||
|
|
||||||
m_pending_screenshot = Core::Promise<RefPtr<Gfx::Bitmap>>::construct();
|
m_pending_screenshot = Core::Promise<RefPtr<Gfx::Bitmap>>::construct();
|
||||||
client().async_take_document_screenshot(0);
|
client().async_take_document_screenshot(0);
|
||||||
|
|
||||||
auto screenshot = MUST(m_pending_screenshot->await());
|
return *m_pending_screenshot;
|
||||||
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());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void clear_content_filters()
|
void clear_content_filters()
|
||||||
|
@ -196,6 +187,14 @@ private:
|
||||||
void update_zoom() override { }
|
void update_zoom() override { }
|
||||||
void initialize_client(CreateNewClient) override { }
|
void initialize_client(CreateNewClient) override { }
|
||||||
|
|
||||||
|
virtual void did_receive_screenshot(Badge<WebView::WebContentClient>, Gfx::ShareableBitmap const& screenshot) override
|
||||||
|
{
|
||||||
|
VERIFY(m_pending_screenshot);
|
||||||
|
|
||||||
|
auto pending_screenshot = move(m_pending_screenshot);
|
||||||
|
pending_screenshot->resolve(screenshot.bitmap());
|
||||||
|
}
|
||||||
|
|
||||||
virtual Web::DevicePixelSize viewport_size() const override { return m_viewport_size.to_type<Web::DevicePixels>(); }
|
virtual Web::DevicePixelSize viewport_size() const override { return m_viewport_size.to_type<Web::DevicePixels>(); }
|
||||||
virtual Gfx::IntPoint to_content_position(Gfx::IntPoint widget_position) const override { return widget_position; }
|
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; }
|
virtual Gfx::IntPoint to_widget_position(Gfx::IntPoint content_position) const override { return content_position; }
|
||||||
|
@ -223,7 +222,9 @@ static ErrorOr<NonnullRefPtr<Core::Timer>> load_page_for_screenshot_and_exit(Cor
|
||||||
auto timer = Core::Timer::create_single_shot(
|
auto timer = Core::Timer::create_single_shot(
|
||||||
screenshot_timeout * 1000,
|
screenshot_timeout * 1000,
|
||||||
[&]() {
|
[&]() {
|
||||||
if (auto screenshot = view.take_screenshot()) {
|
auto promise = view.take_screenshot();
|
||||||
|
|
||||||
|
if (auto screenshot = MUST(promise->await())) {
|
||||||
outln("Saving screenshot to {}", output_file_path);
|
outln("Saving screenshot to {}", output_file_path);
|
||||||
|
|
||||||
auto output_file = MUST(Core::File::open(output_file_path, Core::File::OpenMode::Write));
|
auto output_file = MUST(Core::File::open(output_file_path, Core::File::OpenMode::Write));
|
||||||
|
@ -291,12 +292,12 @@ static ErrorOr<TestResult> run_dump_test(HeadlessWebContentView& view, URL::URL
|
||||||
if (url.equals(loaded_url, URL::ExcludeFragment::Yes)) {
|
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.
|
// 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. :^)
|
// It also causes a lot more code to run, which is good for finding bugs. :^)
|
||||||
(void)view.take_screenshot();
|
view.take_screenshot()->when_resolved([&](auto) {
|
||||||
|
|
||||||
auto promise = view.request_internal_page_info(WebView::PageInfoType::LayoutTree | WebView::PageInfoType::PaintTree);
|
auto promise = view.request_internal_page_info(WebView::PageInfoType::LayoutTree | WebView::PageInfoType::PaintTree);
|
||||||
result = MUST(promise->await());
|
result = MUST(promise->await());
|
||||||
|
|
||||||
loop.quit(0);
|
loop.quit(0);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -385,11 +386,15 @@ static ErrorOr<TestResult> run_ref_test(HeadlessWebContentView& view, URL::URL c
|
||||||
RefPtr<Gfx::Bitmap> actual_screenshot, expectation_screenshot;
|
RefPtr<Gfx::Bitmap> actual_screenshot, expectation_screenshot;
|
||||||
view.on_load_finish = [&](auto const&) {
|
view.on_load_finish = [&](auto const&) {
|
||||||
if (actual_screenshot) {
|
if (actual_screenshot) {
|
||||||
expectation_screenshot = view.take_screenshot();
|
view.take_screenshot()->when_resolved([&](auto screenshot) {
|
||||||
|
expectation_screenshot = move(screenshot);
|
||||||
loop.quit(0);
|
loop.quit(0);
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
actual_screenshot = view.take_screenshot();
|
view.take_screenshot()->when_resolved([&](auto screenshot) {
|
||||||
|
actual_screenshot = move(screenshot);
|
||||||
view.debug_request("load-reference-page");
|
view.debug_request("load-reference-page");
|
||||||
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
view.on_text_test_finish = [&](auto const&) {
|
view.on_text_test_finish = [&](auto const&) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue