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 <longvatrong111@gmail.com>
This commit is contained in:
batu_hoang 2025-06-13 16:40:23 +08:00 committed by GitHub
parent 4c598037a5
commit 6818d5c600
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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(())
}
/// <https://w3c.github.io/webdriver/#dfn-dispatch-a-pause-action>
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
}
/// <https://w3c.github.io/webdriver/#dfn-dispatch-a-keydown-action>