mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-29 12:19:54 +00:00
headless-browser: Let tests set their own timeout duration
Some tests take longer than others, and so may want to set a custom timeout so that they pass, without increasing the timeout for all other tests. For example, this is done in WPT. Add an `internals.setTestTimeout(milliseconds)` method that overrides the test runner's default timeout for the currently-run test.
This commit is contained in:
parent
9164c9784d
commit
be6a9940ad
Notes:
github-actions[bot]
2024-12-19 17:28:47 +00:00
Author: https://github.com/AtkinsSJ
Commit: be6a9940ad
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2979
Reviewed-by: https://github.com/gmta ✅
11 changed files with 42 additions and 0 deletions
|
@ -53,6 +53,11 @@ void Internals::signal_text_test_is_done(String const& text)
|
|||
internals_page().client().page_did_finish_text_test(text);
|
||||
}
|
||||
|
||||
void Internals::set_test_timeout(double milliseconds)
|
||||
{
|
||||
internals_page().client().page_did_set_test_timeout(milliseconds);
|
||||
}
|
||||
|
||||
void Internals::gc()
|
||||
{
|
||||
vm().heap().collect_garbage();
|
||||
|
|
|
@ -21,6 +21,7 @@ public:
|
|||
virtual ~Internals() override;
|
||||
|
||||
void signal_text_test_is_done(String const& text);
|
||||
void set_test_timeout(double milliseconds);
|
||||
|
||||
void gc();
|
||||
JS::Object* hit_test(double x, double y);
|
||||
|
|
|
@ -6,6 +6,8 @@
|
|||
interface Internals {
|
||||
|
||||
undefined signalTextTestIsDone(DOMString text);
|
||||
undefined setTestTimeout(double milliseconds);
|
||||
|
||||
undefined gc();
|
||||
object hitTest(double x, double y);
|
||||
|
||||
|
|
|
@ -382,6 +382,7 @@ public:
|
|||
virtual void page_did_request_select_dropdown([[maybe_unused]] Web::CSSPixelPoint content_position, [[maybe_unused]] Web::CSSPixels minimum_width, [[maybe_unused]] Vector<Web::HTML::SelectItem> items) { }
|
||||
|
||||
virtual void page_did_finish_text_test([[maybe_unused]] String const& text) { }
|
||||
virtual void page_did_set_test_timeout([[maybe_unused]] double milliseconds) { }
|
||||
|
||||
virtual void page_did_change_theme_color(Gfx::Color) { }
|
||||
|
||||
|
|
|
@ -215,6 +215,7 @@ public:
|
|||
Function<void(Web::KeyEvent const&)> on_finish_handling_key_event;
|
||||
Function<void(Web::DragEvent const&)> on_finish_handling_drag_event;
|
||||
Function<void(String const&)> on_text_test_finish;
|
||||
Function<void(double milliseconds)> on_set_test_timeout;
|
||||
Function<void(size_t current_match_index, Optional<size_t> const& total_match_count)> on_find_in_page;
|
||||
Function<void(Gfx::Color)> on_theme_color_change;
|
||||
Function<void(String const&, String const&, String const&)> on_insert_clipboard_entry;
|
||||
|
|
|
@ -93,6 +93,14 @@ void WebContentClient::did_finish_text_test(u64 page_id, String const& text)
|
|||
}
|
||||
}
|
||||
|
||||
void WebContentClient::did_set_test_timeout(u64 page_id, double milliseconds)
|
||||
{
|
||||
if (auto view = view_for_page_id(page_id); view.has_value()) {
|
||||
if (view->on_set_test_timeout)
|
||||
view->on_set_test_timeout(milliseconds);
|
||||
}
|
||||
}
|
||||
|
||||
void WebContentClient::did_find_in_page(u64 page_id, size_t current_match_index, Optional<size_t> const& total_match_count)
|
||||
{
|
||||
if (auto view = view_for_page_id(page_id); view.has_value()) {
|
||||
|
|
|
@ -108,6 +108,7 @@ private:
|
|||
virtual void did_request_select_dropdown(u64 page_id, Gfx::IntPoint content_position, i32 minimum_width, Vector<Web::HTML::SelectItem> const& items) override;
|
||||
virtual void did_finish_handling_input_event(u64 page_id, Web::EventResult event_result) override;
|
||||
virtual void did_finish_text_test(u64 page_id, String const& text) override;
|
||||
virtual void did_set_test_timeout(u64 page_id, double milliseconds) override;
|
||||
virtual void did_find_in_page(u64 page_id, size_t current_match_index, Optional<size_t> const& total_match_count) override;
|
||||
virtual void did_change_theme_color(u64 page_id, Gfx::Color color) override;
|
||||
virtual void did_insert_clipboard_entry(u64 page_id, String const& data, String const& presentation_style, String const& mime_type) override;
|
||||
|
|
|
@ -366,6 +366,11 @@ void PageClient::page_did_finish_text_test(String const& text)
|
|||
client().async_did_finish_text_test(m_id, text);
|
||||
}
|
||||
|
||||
void PageClient::page_did_set_test_timeout(double milliseconds)
|
||||
{
|
||||
client().async_did_set_test_timeout(m_id, milliseconds);
|
||||
}
|
||||
|
||||
void PageClient::page_did_request_context_menu(Web::CSSPixelPoint content_position)
|
||||
{
|
||||
client().async_did_request_context_menu(m_id, page().css_to_device_point(content_position).to_type<int>());
|
||||
|
|
|
@ -158,6 +158,7 @@ private:
|
|||
virtual void page_did_request_file_picker(Web::HTML::FileFilter accepted_file_types, Web::HTML::AllowMultipleFiles) override;
|
||||
virtual void page_did_request_select_dropdown(Web::CSSPixelPoint content_position, Web::CSSPixels minimum_width, Vector<Web::HTML::SelectItem> items) override;
|
||||
virtual void page_did_finish_text_test(String const& text) override;
|
||||
virtual void page_did_set_test_timeout(double milliseconds) override;
|
||||
virtual void page_did_change_theme_color(Gfx::Color color) override;
|
||||
virtual void page_did_insert_clipboard_entry(String data, String presentation_style, String mime_type) override;
|
||||
virtual void page_did_change_audio_play_state(Web::HTML::AudioPlayState) override;
|
||||
|
|
|
@ -95,6 +95,7 @@ endpoint WebContentClient
|
|||
did_get_js_console_messages(u64 page_id, i32 start_index, Vector<ByteString> message_types, Vector<ByteString> messages) =|
|
||||
|
||||
did_finish_text_test(u64 page_id, String text) =|
|
||||
did_set_test_timeout(u64 page_id, double milliseconds) =|
|
||||
|
||||
did_find_in_page(u64 page_id, size_t current_match_index, Optional<size_t> total_match_count) =|
|
||||
|
||||
|
|
|
@ -112,6 +112,7 @@ void run_dump_test(HeadlessWebView& view, Test& test, URL::URL const& url, int t
|
|||
auto timer = Core::Timer::create_single_shot(timeout_in_milliseconds, [&view, &test]() {
|
||||
view.on_load_finish = {};
|
||||
view.on_text_test_finish = {};
|
||||
view.on_set_test_timeout = {};
|
||||
|
||||
view.on_test_complete({ test, TestResult::Timeout });
|
||||
});
|
||||
|
@ -233,6 +234,13 @@ void run_dump_test(HeadlessWebView& view, Test& test, URL::URL const& url, int t
|
|||
};
|
||||
}
|
||||
|
||||
view.on_set_test_timeout = [timer, timeout_in_milliseconds](double milliseconds) {
|
||||
if (milliseconds <= timeout_in_milliseconds)
|
||||
return;
|
||||
timer->stop();
|
||||
timer->start(milliseconds);
|
||||
};
|
||||
|
||||
view.load(url);
|
||||
timer->start();
|
||||
}
|
||||
|
@ -242,6 +250,7 @@ static void run_ref_test(HeadlessWebView& view, Test& test, URL::URL const& url,
|
|||
auto timer = Core::Timer::create_single_shot(timeout_in_milliseconds, [&view, &test]() {
|
||||
view.on_load_finish = {};
|
||||
view.on_text_test_finish = {};
|
||||
view.on_set_test_timeout = {};
|
||||
|
||||
view.on_test_complete({ test, TestResult::Timeout });
|
||||
});
|
||||
|
@ -315,6 +324,13 @@ static void run_ref_test(HeadlessWebView& view, Test& test, URL::URL const& url,
|
|||
dbgln("Unexpected text test finished during ref test for {}", url);
|
||||
};
|
||||
|
||||
view.on_set_test_timeout = [timer, timeout_in_milliseconds](double milliseconds) {
|
||||
if (milliseconds <= timeout_in_milliseconds)
|
||||
return;
|
||||
timer->stop();
|
||||
timer->start(milliseconds);
|
||||
};
|
||||
|
||||
view.load(url);
|
||||
timer->start();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue