From 6818d5c600944281bea56a3ce038ceb40e0cb003 Mon Sep 17 00:00:00 2001 From: batu_hoang <55729155+longvatrong111@users.noreply.github.com> Date: Fri, 13 Jun 2025 16:40:23 +0800 Subject: [PATCH] Wait enough time for tick duration in webdriver dispatch actions (#37423) Add step `wait at least tick duration milliseconds have passed` https://w3c.github.io/webdriver/#dfn-dispatch-actions-inner Testing: Fix intermittent timeout in: `/tests/wpt/tests/webdriver/tests/classic/perform_actions/pointer_dblclick.py` cc: @xiaochengh , @jdm Signed-off-by: batu_hoang --- components/webdriver_server/actions.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/components/webdriver_server/actions.rs b/components/webdriver_server/actions.rs index 04deca55cc8..69750a49c67 100644 --- a/components/webdriver_server/actions.rs +++ b/components/webdriver_server/actions.rs @@ -31,6 +31,7 @@ static WHEELSCROLL_INTERVAL: u64 = 17; // In the spec, `action item` refers to a plain JSON object. // However, we use the name ActionItem here // to be consistent with type names from webdriver crate. +#[derive(Debug)] pub(crate) enum ActionItem { Null(NullActionItem), Key(KeyActionItem), @@ -148,6 +149,7 @@ impl Handler { // Step 1.2. Let tick duration be the result of // computing the tick duration with argument tick actions. let tick_duration = compute_tick_duration(tick_actions); + let now = Instant::now(); // Step 1.3. Try to dispatch tick actions self.dispatch_tick_actions(tick_actions, tick_duration)?; @@ -156,6 +158,12 @@ impl Handler { // The user agent event loop has spun enough times to process the DOM events // generated by the last invocation of the dispatch tick actions steps. self.wait_for_user_agent_handling_complete(tick_actions)?; + // At least tick duration milliseconds have passed. + let elapsed = now.elapsed(); + if elapsed.as_millis() < tick_duration as u128 { + let sleep_duration = tick_duration - elapsed.as_millis() as u64; + thread::sleep(Duration::from_millis(sleep_duration)); + } } // Step 2. Return success with data null. @@ -288,6 +296,7 @@ impl Handler { Ok(()) } + /// fn dispatch_general_action(&self, source_id: &str) { self.session() .unwrap() @@ -295,8 +304,6 @@ impl Handler { .borrow_mut() .entry(source_id.to_string()) .or_insert(InputSourceState::Null); - // https://w3c.github.io/webdriver/#dfn-dispatch-a-pause-action - // Nothing to be done } ///