-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
webdriver: Add touch support for all platforms #41067
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -51,10 +51,12 @@ use servo_url::ServoUrl; | |
| use style_traits::CSSPixel; | ||
| use time::OffsetDateTime; | ||
| use uuid::Uuid; | ||
| #[cfg(not(any(target_env = "ohos", target_os = "android")))] | ||
| use webdriver::actions::PointerMoveAction; | ||
| use webdriver::actions::{ | ||
| ActionSequence, ActionsType, KeyAction, KeyActionItem, KeyDownAction, KeyUpAction, | ||
| PointerAction, PointerActionItem, PointerActionParameters, PointerDownAction, | ||
| PointerMoveAction, PointerOrigin, PointerType, PointerUpAction, | ||
| PointerAction, PointerActionItem, PointerActionParameters, PointerDownAction, PointerOrigin, | ||
| PointerType, PointerUpAction, | ||
| }; | ||
| use webdriver::capabilities::CapabilitiesMatching; | ||
| use webdriver::command::{ | ||
|
|
@@ -2281,14 +2283,92 @@ impl Handler { | |
|
|
||
| /// <https://w3c.github.io/webdriver/#element-click> | ||
| /// Step 8 for elements other than <option> | ||
| /// There is currently no spec for touchscreen webdriver support. | ||
| /// There is an ongoing discussion in W3C: | ||
| /// <https://github.com/w3c/webdriver/issues/1925> | ||
| #[cfg(any(target_env = "ohos", target_os = "android"))] | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would prefer if we did a runtime check for device type, since ohos / android devices can be run in desktop mode.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks! Will do when I got time. Another way is to process "user_agent" of webdriver session to determine at runtime.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
We always have a plan to do this in runtime. |
||
| fn perform_element_click(&mut self, element: String) -> WebDriverResult<WebDriverResponse> { | ||
| // Step 8.1 - 8.4: Create UUID, create input source "pointer". | ||
| let id = Uuid::new_v4().to_string(); | ||
|
|
||
| let pointer_ids = self.session()?.pointer_ids(); | ||
| let (x, y) = self | ||
| .get_origin_relative_coordinates( | ||
| &PointerOrigin::Element(WebElement(element.clone())), | ||
| 0.0, | ||
| 0.0, | ||
| &id, | ||
| ) | ||
| .map_err(|err| WebDriverError::new(err, ""))?; | ||
|
|
||
| // Difference with Desktop: Create an input source with coordinates directly at the | ||
| // element centre. | ||
| self.session_mut()?.input_state_table.insert( | ||
| id.clone(), | ||
| InputSourceState::Pointer(PointerInputState::new(PointerType::Mouse, pointer_ids)), | ||
| InputSourceState::Pointer(PointerInputState::new( | ||
| PointerType::Touch, | ||
| pointer_ids, | ||
| x, | ||
| y, | ||
| )), | ||
| ); | ||
|
|
||
| // Step 8.11. Construct pointer down action. | ||
| // Step 8.12. Set a property button to 0 on pointer down action. | ||
| let pointer_down_action = PointerDownAction { | ||
| button: i16::from(MouseButton::Left) as u64, | ||
| ..Default::default() | ||
| }; | ||
|
|
||
| // Step 8.13. Construct pointer up action. | ||
| // Step 8.14. Set a property button to 0 on pointer up action. | ||
| let pointer_up_action = PointerUpAction { | ||
| button: i16::from(MouseButton::Left) as u64, | ||
| ..Default::default() | ||
| }; | ||
|
|
||
| // Difference with Desktop: We only need pointerdown and pointerup for touchscreen. | ||
| let action_sequence = ActionSequence { | ||
| id: id.clone(), | ||
| actions: ActionsType::Pointer { | ||
| parameters: PointerActionParameters { | ||
| pointer_type: PointerType::Touch, | ||
| }, | ||
| actions: vec![ | ||
| PointerActionItem::Pointer(PointerAction::Down(pointer_down_action)), | ||
| PointerActionItem::Pointer(PointerAction::Up(pointer_up_action)), | ||
| ], | ||
| }, | ||
| }; | ||
|
|
||
| // Step 8.16. Dispatch a list of actions with session's current browsing context | ||
| let actions_by_tick = self.extract_an_action_sequence(vec![action_sequence]); | ||
| if let Err(e) = self.dispatch_actions(actions_by_tick, self.browsing_context_id()?) { | ||
| log::error!("handle_element_click: dispatch_actions failed: {:?}", e); | ||
| } | ||
|
|
||
| // Step 8.17 Remove an input source with input state and input id. | ||
| self.session_mut()?.input_state_table.remove(&id); | ||
|
|
||
| Ok(WebDriverResponse::Void) | ||
| } | ||
|
|
||
| /// <https://w3c.github.io/webdriver/#element-click> | ||
| /// Step 8 for elements other than <option>, | ||
| #[cfg(not(any(target_env = "ohos", target_os = "android")))] | ||
| fn perform_element_click(&mut self, element: String) -> WebDriverResult<WebDriverResponse> { | ||
| // Step 8.1 - 8.4: Create UUID, create input source "pointer". | ||
| let id = Uuid::new_v4().to_string(); | ||
|
|
||
| let pointer_ids = self.session()?.pointer_ids(); | ||
| self.session_mut()?.input_state_table.insert( | ||
| id.clone(), | ||
| InputSourceState::Pointer(PointerInputState::new( | ||
| PointerType::Mouse, | ||
| pointer_ids, | ||
| 0.0, | ||
| 0.0, | ||
| )), | ||
| ); | ||
|
|
||
| // Step 8.7. Construct a pointer move action. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| [non-passive-touchmove-event-listener-on-body.html] | ||
| expected: CRASH | ||
| [non-passive touchmove event listener on body] | ||
| expected: FAIL |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| [non-passive-touchmove-event-listener-on-div.html] | ||
| expected: CRASH | ||
| [non-passive touchmove event listener on div] | ||
| expected: FAIL |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| [non-passive-touchmove-event-listener-on-document.html] | ||
| expected: CRASH | ||
| [non-passive touchmove event listener on document] | ||
| expected: FAIL |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| [non-passive-touchmove-event-listener-on-root.html] | ||
| expected: CRASH | ||
| [non-passive touchmove event listener on root] | ||
| expected: FAIL |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| [non-passive-touchmove-event-listener-on-window.html] | ||
| expected: CRASH | ||
| [non-passive-touchmove-event-listener-on-window] | ||
| expected: FAIL |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| [non-passive-touchstart-event-listener-on-body.html] | ||
| expected: CRASH | ||
| [non-passive touchstart event listener on body] | ||
| expected: FAIL |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| [non-passive-touchstart-event-listener-on-div.html] | ||
| expected: CRASH | ||
| [non-passive touchstart event listener on div] | ||
| expected: FAIL |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| [non-passive-touchstart-event-listener-on-document.html] | ||
| expected: CRASH | ||
| [non-passive touchstart event listener on document] | ||
| expected: FAIL |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| [non-passive-touchstart-event-listener-on-root.html] | ||
| expected: CRASH | ||
| [non-passive touchstart event listener on root] | ||
| expected: FAIL |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| [non-passive-touchstart-event-listener-on-window.html] | ||
| expected: CRASH | ||
| [non-passive touchstart event listener on window] | ||
| expected: FAIL |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| [passive-touchmove-event-listener-on-body.html] | ||
| expected: CRASH | ||
| [passive touchmove event listener on body] | ||
| expected: FAIL |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| [passive-touchmove-event-listener-on-div.html] | ||
| expected: CRASH | ||
| [passive touchmove event listener on div] | ||
| expected: FAIL |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| [passive-touchmove-event-listener-on-document.html] | ||
| expected: CRASH | ||
| [passive touchmove event listener on document] | ||
| expected: FAIL |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| [passive-touchmove-event-listener-on-root.html] | ||
| expected: CRASH | ||
| [passive touchmove event listener on root] | ||
| expected: FAIL |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| [passive-touchmove-event-listener-on-window.html] | ||
| expected: CRASH | ||
| [passive touchmove event listener on window] | ||
| expected: FAIL |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| [passive-touchstart-event-listener-on-body.html] | ||
| expected: CRASH | ||
| [passive touchstart event listener on body] | ||
| expected: FAIL |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| [passive-touchstart-event-listener-on-div.html] | ||
| expected: CRASH | ||
| [passive touchstart event listener on div] | ||
| expected: FAIL |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| [passive-touchstart-event-listener-on-document.html] | ||
| expected: CRASH | ||
| [passive touchstart event listener on document] | ||
| expected: FAIL |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| [passive-touchstart-event-listener-on-root.html] | ||
| expected: CRASH | ||
| [passive touchstart event listener on root] | ||
| expected: FAIL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are no longer ignoring requested pointer type.
This allows us to dispatch touch actions correctly for Perform Actions.