diff --git a/Libraries/LibWeb/Internals/Internals.cpp b/Libraries/LibWeb/Internals/Internals.cpp index 837740cdde060..e1926eacdcabd 100644 --- a/Libraries/LibWeb/Internals/Internals.cpp +++ b/Libraries/LibWeb/Internals/Internals.cpp @@ -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(); diff --git a/Libraries/LibWeb/Internals/Internals.h b/Libraries/LibWeb/Internals/Internals.h index ba870af6b326b..037e6d4e284dd 100644 --- a/Libraries/LibWeb/Internals/Internals.h +++ b/Libraries/LibWeb/Internals/Internals.h @@ -21,6 +21,7 @@ class Internals final : public Bindings::PlatformObject { 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); diff --git a/Libraries/LibWeb/Internals/Internals.idl b/Libraries/LibWeb/Internals/Internals.idl index 04776e3bdad2f..19f62a0f89415 100644 --- a/Libraries/LibWeb/Internals/Internals.idl +++ b/Libraries/LibWeb/Internals/Internals.idl @@ -6,6 +6,8 @@ interface Internals { undefined signalTextTestIsDone(DOMString text); + undefined setTestTimeout(double milliseconds); + undefined gc(); object hitTest(double x, double y); diff --git a/Libraries/LibWeb/Page/Page.h b/Libraries/LibWeb/Page/Page.h index 36999ca11592d..9f3a510ac87d9 100644 --- a/Libraries/LibWeb/Page/Page.h +++ b/Libraries/LibWeb/Page/Page.h @@ -382,6 +382,7 @@ class PageClient : public JS::Cell { virtual void page_did_request_select_dropdown([[maybe_unused]] Web::CSSPixelPoint content_position, [[maybe_unused]] Web::CSSPixels minimum_width, [[maybe_unused]] Vector 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) { } diff --git a/Libraries/LibWebView/ViewImplementation.h b/Libraries/LibWebView/ViewImplementation.h index fd3979cfc4afe..95f4c76030da1 100644 --- a/Libraries/LibWebView/ViewImplementation.h +++ b/Libraries/LibWebView/ViewImplementation.h @@ -215,6 +215,7 @@ class ViewImplementation { Function on_finish_handling_key_event; Function on_finish_handling_drag_event; Function on_text_test_finish; + Function on_set_test_timeout; Function const& total_match_count)> on_find_in_page; Function on_theme_color_change; Function on_insert_clipboard_entry; diff --git a/Libraries/LibWebView/WebContentClient.cpp b/Libraries/LibWebView/WebContentClient.cpp index 81dc1c554e65c..2e2ec35ec4090 100644 --- a/Libraries/LibWebView/WebContentClient.cpp +++ b/Libraries/LibWebView/WebContentClient.cpp @@ -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 const& total_match_count) { if (auto view = view_for_page_id(page_id); view.has_value()) { diff --git a/Libraries/LibWebView/WebContentClient.h b/Libraries/LibWebView/WebContentClient.h index 9480432a90843..68d07ac4398f3 100644 --- a/Libraries/LibWebView/WebContentClient.h +++ b/Libraries/LibWebView/WebContentClient.h @@ -108,6 +108,7 @@ class WebContentClient final virtual void did_request_select_dropdown(u64 page_id, Gfx::IntPoint content_position, i32 minimum_width, Vector 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 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; diff --git a/Services/WebContent/PageClient.cpp b/Services/WebContent/PageClient.cpp index 8b12b251ec729..8e78e181bb105 100644 --- a/Services/WebContent/PageClient.cpp +++ b/Services/WebContent/PageClient.cpp @@ -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()); diff --git a/Services/WebContent/PageClient.h b/Services/WebContent/PageClient.h index 28d8e05270820..f8457b6f3f85d 100644 --- a/Services/WebContent/PageClient.h +++ b/Services/WebContent/PageClient.h @@ -158,6 +158,7 @@ class PageClient final : public Web::PageClient { 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 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; diff --git a/Services/WebContent/WebContentClient.ipc b/Services/WebContent/WebContentClient.ipc index 548b3b633ab3e..6bc2ecfc736b2 100644 --- a/Services/WebContent/WebContentClient.ipc +++ b/Services/WebContent/WebContentClient.ipc @@ -95,6 +95,7 @@ endpoint WebContentClient did_get_js_console_messages(u64 page_id, i32 start_index, Vector message_types, Vector 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 total_match_count) =| diff --git a/UI/Headless/Test.cpp b/UI/Headless/Test.cpp index 59c6e527c5948..c62f95bff14cb 100644 --- a/UI/Headless/Test.cpp +++ b/UI/Headless/Test.cpp @@ -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,14 @@ void run_dump_test(HeadlessWebView& view, Test& test, URL::URL const& url, int t }; } + view.on_set_test_timeout = [&test, timer, timeout_in_milliseconds](double milliseconds) { + if (milliseconds == timeout_in_milliseconds) + return; + timer->stop(); + auto milliseconds_elapsed = (UnixDateTime::now() - test.start_time).to_milliseconds(); + timer->start(milliseconds - milliseconds_elapsed); + }; + view.load(url); timer->start(); } @@ -242,6 +251,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 +325,14 @@ 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 = [&test, timer, timeout_in_milliseconds](double milliseconds) { + if (milliseconds == timeout_in_milliseconds) + return; + timer->stop(); + auto milliseconds_elapsed = (UnixDateTime::now() - test.start_time).to_milliseconds(); + timer->start(milliseconds - milliseconds_elapsed); + }; + view.load(url); timer->start(); }