From 6bf0a5cb5034a7e684dcc3500e841785237ce2dd Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 19:32:43 +0200 Subject: Adding upstream version 1:115.7.0. Signed-off-by: Daniel Baumann --- layout/base/tests/marionette/selection.py | 335 ++++++++++++++++++++++++++++++ 1 file changed, 335 insertions(+) create mode 100644 layout/base/tests/marionette/selection.py (limited to 'layout/base/tests/marionette/selection.py') diff --git a/layout/base/tests/marionette/selection.py b/layout/base/tests/marionette/selection.py new file mode 100644 index 0000000000..6cfe155927 --- /dev/null +++ b/layout/base/tests/marionette/selection.py @@ -0,0 +1,335 @@ +# -*- coding: utf-8 -*- +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +from marionette_driver.marionette import Actions, errors + + +class CaretActions(Actions): + def __init__(self, marionette): + super(CaretActions, self).__init__(marionette) + self._reset_action_chain() + + def _reset_action_chain(self): + self.mouse_chain = self.sequence( + "pointer", "pointer_id", {"pointerType": "mouse"} + ) + self.key_chain = self.sequence("key", "keyboard_id") + + def flick(self, element, x1, y1, x2, y2, duration=200): + """Perform a flick gesture on the target element. + + :param element: The element to perform the flick gesture on. + :param x1: Starting x-coordinate of flick, relative to the top left + corner of the element. + :param y1: Starting y-coordinate of flick, relative to the top left + corner of the element. + :param x2: Ending x-coordinate of flick, relative to the top left + corner of the element. + :param y2: Ending y-coordinate of flick, relative to the top left + corner of the element. + + """ + rect = element.rect + el_x, el_y = rect["x"], rect["y"] + + # Add element's (x, y) to make the coordinate relative to the viewport. + from_x, from_y = int(el_x + x1), int(el_y + y1) + to_x, to_y = int(el_x + x2), int(el_y + y2) + + self.mouse_chain.pointer_move(from_x, from_y).pointer_down().pointer_move( + to_x, to_y, duration=duration + ).pointer_up() + return self + + def send_keys(self, keys): + """Perform a keyDown and keyUp action for each character in `keys`. + + :param keys: String of keys to perform key actions with. + + """ + self.key_chain.send_keys(keys) + return self + + def perform(self): + """Perform the action chain built so far to the server side for execution + and clears the current chain of actions. + + Warning: This method performs all the mouse actions before all the key + actions! + + """ + self.mouse_chain.perform() + self.key_chain.perform() + self._reset_action_chain() + + +class SelectionManager(object): + """Interface for manipulating the selection and carets of the element. + + We call the blinking cursor (nsCaret) as cursor, and call AccessibleCaret as + caret for short. + + Simple usage example: + + :: + + element = marionette.find_element(By.ID, 'input') + sel = SelectionManager(element) + sel.move_caret_to_front() + + """ + + def __init__(self, element): + self.element = element + + def _input_or_textarea(self): + """Return True if element is either or