From 090dbac5a329a2e04b87e242f7faa494dc0b68b2 Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Sat, 24 Feb 2024 16:28:53 -0500 Subject: [PATCH] Revert "LibWeb: Allow bypassing transient activation checks for tests" This reverts commit e52c30cbd5616b4cc33cf365bcb7019458c256b0. It's highly possible that this test was flaky on CI due to mixing units of seconds and milliseconds in the transient activation calculation. Revert the workaround for that commit in an attempt to avoid needless ad-hoc behavior. --- Tests/LibWeb/Text/input/clipboard.html | 5 ++++- Userland/Libraries/LibWeb/HTML/Window.cpp | 16 ++-------------- Userland/Libraries/LibWeb/HTML/Window.h | 2 -- .../Libraries/LibWeb/Internals/Internals.cpp | 6 ++++++ Userland/Libraries/LibWeb/Internals/Internals.h | 5 +---- .../Libraries/LibWeb/Internals/Internals.idl | 2 +- 6 files changed, 14 insertions(+), 22 deletions(-) diff --git a/Tests/LibWeb/Text/input/clipboard.html b/Tests/LibWeb/Text/input/clipboard.html index 9a317faf0a0..dfc6d391db5 100644 --- a/Tests/LibWeb/Text/input/clipboard.html +++ b/Tests/LibWeb/Text/input/clipboard.html @@ -16,7 +16,10 @@ asyncTest((done) => { writeText(() => { - internals.bypassNextTransientActivationTest = true; + const button = document.getElementById("button"); + internals.dispatchUserActivatedEvent(button, new Event("mousedown")); + button.dispatchEvent(new Event("click")); + writeText(done); }); }); diff --git a/Userland/Libraries/LibWeb/HTML/Window.cpp b/Userland/Libraries/LibWeb/HTML/Window.cpp index c8b8b2e0081..2c2a36456ee 100644 --- a/Userland/Libraries/LibWeb/HTML/Window.cpp +++ b/Userland/Libraries/LibWeb/HTML/Window.cpp @@ -134,7 +134,6 @@ void Window::visit_edges(JS::Cell::Visitor& visitor) visitor.visit(mime_type_object); visitor.visit(m_count_queuing_strategy_size_function); visitor.visit(m_byte_length_queuing_strategy_size_function); - visitor.visit(m_internals); } void Window::finalize() @@ -606,14 +605,6 @@ bool Window::has_transient_activation() const // perceive the link between an interaction with the page and the page calling the activation-gated API. static constexpr HighResolutionTime::DOMHighResTimeStamp transient_activation_duration_ms = 5000; - // AD-HOC: Due to resource limitations on CI, we cannot rely on the time between the activation timestamp and the - // transient activation timeout being predictable. So we allow tests to indicate when they want the next - // check for a user gesture to succeed. - if (m_internals && m_internals->bypass_next_transient_activation_test()) { - m_internals->set_bypass_next_transient_activation_test(false); - return true; - } - // When the current high resolution time given W auto unsafe_shared_time = HighResolutionTime::unsafe_shared_current_time(); auto current_time = HighResolutionTime::relative_high_resolution_time(unsafe_shared_time, realm().global_object()); @@ -822,11 +813,8 @@ WebIDL::ExceptionOr Window::initialize_web_interfaces(Badge(realm, realm), JS::default_attributes); - - if (s_internals_object_exposed) { - m_internals = heap().allocate(realm, realm); - define_direct_property("internals", m_internals, JS::default_attributes); - } + if (s_internals_object_exposed) + define_direct_property("internals", heap().allocate(realm, realm), JS::default_attributes); return {}; } diff --git a/Userland/Libraries/LibWeb/HTML/Window.h b/Userland/Libraries/LibWeb/HTML/Window.h index 71f4d736fa1..bf6ac081dd9 100644 --- a/Userland/Libraries/LibWeb/HTML/Window.h +++ b/Userland/Libraries/LibWeb/HTML/Window.h @@ -287,8 +287,6 @@ private: // https://html.spec.whatwg.org/multipage/nav-history-apis.html#dom-window-status // When the Window object is created, the attribute must be set to the empty string. It does not do anything else. String m_status; - - JS::GCPtr m_internals; }; void run_animation_frame_callbacks(DOM::Document&, double now); diff --git a/Userland/Libraries/LibWeb/Internals/Internals.cpp b/Userland/Libraries/LibWeb/Internals/Internals.cpp index 7223d28993e..c856b615b6d 100644 --- a/Userland/Libraries/LibWeb/Internals/Internals.cpp +++ b/Userland/Libraries/LibWeb/Internals/Internals.cpp @@ -89,4 +89,10 @@ void Internals::wheel(double x, double y, double delta_x, double delta_y) page.handle_mousewheel({ x, y }, { x, y }, 0, 0, 0, delta_x, delta_y); } +WebIDL::ExceptionOr Internals::dispatch_user_activated_event(DOM::EventTarget& target, DOM::Event& event) +{ + event.set_is_trusted(true); + return target.dispatch_event(event); +} + } diff --git a/Userland/Libraries/LibWeb/Internals/Internals.h b/Userland/Libraries/LibWeb/Internals/Internals.h index ba34ee5c04e..3ebe5d19c9e 100644 --- a/Userland/Libraries/LibWeb/Internals/Internals.h +++ b/Userland/Libraries/LibWeb/Internals/Internals.h @@ -28,14 +28,11 @@ public: void click(double x, double y); void wheel(double x, double y, double delta_x, double delta_y); - bool bypass_next_transient_activation_test() const { return m_bypass_next_transient_activation_test; } - void set_bypass_next_transient_activation_test(bool bypass_next_transient_activation_test) { m_bypass_next_transient_activation_test = bypass_next_transient_activation_test; } + WebIDL::ExceptionOr dispatch_user_activated_event(DOM::EventTarget&, DOM::Event& event); private: explicit Internals(JS::Realm&); virtual void initialize(JS::Realm&) override; - - bool m_bypass_next_transient_activation_test { false }; }; } diff --git a/Userland/Libraries/LibWeb/Internals/Internals.idl b/Userland/Libraries/LibWeb/Internals/Internals.idl index d158b3a7bc0..c3d13f3c0f6 100644 --- a/Userland/Libraries/LibWeb/Internals/Internals.idl +++ b/Userland/Libraries/LibWeb/Internals/Internals.idl @@ -13,6 +13,6 @@ undefined click(double x, double y); undefined wheel(double x, double y, double deltaX, double deltaY); - attribute boolean bypassNextTransientActivationTest; + boolean dispatchUserActivatedEvent(EventTarget target, Event event); };