Fix webdriver wait for response from constellation (#37095)

Webdriver actions only wait for response from constellation if
`dispatch_tick_actions` sends at least 1 event.

Testing: 
`./mach test-wpt -r --product servodriver
./tests/wpt/tests/webdriver/tests/classic/perform_actions/perform.py `

cc: @xiaochengh, @yezhizhen

Signed-off-by: batu_hoang <longvatrong111@gmail.com>
This commit is contained in:
batu_hoang 2025-06-03 19:51:12 +08:00 committed by GitHub
parent 8937542fe3
commit 5ef66ce386
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 30 additions and 9 deletions

View file

@ -58,16 +58,16 @@ impl InputEvent {
}
}
pub fn with_webdriver_message_id(self, webdriver_id: Option<WebDriverMessageId>) -> Self {
pub fn with_webdriver_message_id(mut self, webdriver_id: Option<WebDriverMessageId>) -> Self {
match self {
InputEvent::EditingAction(..) => {},
InputEvent::Gamepad(..) => {},
InputEvent::Ime(..) => {},
InputEvent::Keyboard(..) => {},
InputEvent::MouseButton(mut event) => {
InputEvent::MouseButton(ref mut event) => {
event.webdriver_id = webdriver_id;
},
InputEvent::MouseMove(mut event) => {
InputEvent::MouseMove(ref mut event) => {
event.webdriver_id = webdriver_id;
},
InputEvent::Touch(..) => {},

View file

@ -144,10 +144,33 @@ impl Handler {
// Step 1.4. Wait for
// 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.
//
// To ensure we wait for all events to be processed, only the last event in
// this tick action step holds the message id.
// Whenever a new event is generated, the message id is passed to it.
self.wait_for_user_agent_handling_complete(tick_actions)?;
}
// Step 2. Return success with data null.
dbg!("Dispatch actions completed successfully");
Ok(())
}
fn wait_for_user_agent_handling_complete(
&self,
tick_actions: &TickActions,
) -> Result<(), ErrorStatus> {
// TODO: Add matches! for wheel and key actions
// after implmenting webdriver id for wheel and key events.
let count_non_null_actions_in_tick = tick_actions
.iter()
.filter(|(_, action)| {
!matches!(action, ActionItem::Pointer(PointerActionItem::Pointer(_)))
})
.count();
// To ensure we wait for all events to be processed, only the last event
// in each tick action step holds the message id.
// Whenever a new event is generated, the message id is passed to it.
//
// Wait for count_non_null_actions_in_tick number of responses
for _ in 0..count_non_null_actions_in_tick {
match self.constellation_receiver.recv() {
Ok(response) => {
let current_waiting_id = self
@ -167,8 +190,6 @@ impl Handler {
};
}
// Step 2. Return success with data null.
dbg!("Dispatch actions completed successfully");
Ok(())
}