Fix webdriver wait for response from constellation

Signed-off-by: batu_hoang <longvatrong111@gmail.com>
This commit is contained in:
batu_hoang 2025-05-23 16:37:18 +08:00
parent ad95a74389
commit 531c2d6c99
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 { match self {
InputEvent::EditingAction(..) => {}, InputEvent::EditingAction(..) => {},
InputEvent::Gamepad(..) => {}, InputEvent::Gamepad(..) => {},
InputEvent::Ime(..) => {}, InputEvent::Ime(..) => {},
InputEvent::Keyboard(..) => {}, InputEvent::Keyboard(..) => {},
InputEvent::MouseButton(mut event) => { InputEvent::MouseButton(ref mut event) => {
event.webdriver_id = webdriver_id; event.webdriver_id = webdriver_id;
}, },
InputEvent::MouseMove(mut event) => { InputEvent::MouseMove(ref mut event) => {
event.webdriver_id = webdriver_id; event.webdriver_id = webdriver_id;
}, },
InputEvent::Touch(..) => {}, InputEvent::Touch(..) => {},

View file

@ -144,10 +144,33 @@ impl Handler {
// Step 1.4. Wait for // Step 1.4. Wait for
// The user agent event loop has spun enough times to process the DOM events // 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. // generated by the last invocation of the dispatch tick actions steps.
// self.wait_for_user_agent_handling_complete(tick_actions)?;
// 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. // 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() { match self.constellation_receiver.recv() {
Ok(response) => { Ok(response) => {
let current_waiting_id = self let current_waiting_id = self
@ -167,8 +190,6 @@ impl Handler {
}; };
} }
// Step 2. Return success with data null.
dbg!("Dispatch actions completed successfully");
Ok(()) Ok(())
} }