当前位置: 首页>>代码示例>>Python>>正文


Python Actions.flick方法代码示例

本文整理汇总了Python中marionette.Actions.flick方法的典型用法代码示例。如果您正苦于以下问题:Python Actions.flick方法的具体用法?Python Actions.flick怎么用?Python Actions.flick使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在marionette.Actions的用法示例。


在下文中一共展示了Actions.flick方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: scroll

# 需要导入模块: from marionette import Actions [as 别名]
# 或者: from marionette.Actions import flick [as 别名]
 def scroll(self):
     action = Actions(self.marionette)
     for page in self.marionette.find_elements(By.CSS_SELECTOR, "#icongrid > div")[:-1]:
         self.logger.debug("Swiping to next page of apps")
         action.flick(
             page,
             page.size["width"] / 100 * 90,
             page.size["width"] / 2,
             page.size["width"] / 100 * 10,
             page.size["width"] / 2,
             200,
         ).perform()
         Wait(self.marionette, timeout=30).until(
             lambda m: page.get_attribute("aria-hidden") or not page.is_displayed()
         )
     for page in reversed(self.marionette.find_elements(By.CSS_SELECTOR, "#icongrid > div")[1:]):
         Wait(self.marionette, timeout=30).until(
             lambda m: page.is_displayed() or not page.get_attribute("aria-hidden")
         )
         self.logger.debug("Swiping to previous page of apps")
         action.flick(
             page,
             page.size["width"] / 100 * 10,
             page.size["width"] / 2,
             page.size["width"] / 100 * 90,
             page.size["width"] / 2,
             200,
         ).perform()
开发者ID:rwood-moz,项目名称:b2gperf,代码行数:30,代码来源:b2gperf.py

示例2: scroll

# 需要导入模块: from marionette import Actions [as 别名]
# 或者: from marionette.Actions import flick [as 别名]
 def scroll(self):
     action = Actions(self.marionette)
     for page in self.marionette.find_elements(By.CSS_SELECTOR,
                                               '#icongrid > div')[:-1]:
         self.logger.debug('Swiping to next page of apps')
         action.flick(
             page,
             page.size['width'] / 100 * 90,
             page.size['width'] / 2,
             page.size['width'] / 100 * 10,
             page.size['width'] / 2, 200).perform()
         MarionetteWait(self.marionette, 30).until(
             lambda m: page.get_attribute('aria-hidden') or
             not page.is_displayed())
     for page in reversed(self.marionette.find_elements(
             By.CSS_SELECTOR, '#icongrid > div')[1:]):
         MarionetteWait(self.marionette, 30).until_not(
             lambda m: page.get_attribute('aria-hidden') or
             not page.is_displayed())
         self.logger.debug('Swiping to previous page of apps')
         action.flick(
             page,
             page.size['width'] / 100 * 10,
             page.size['width'] / 2,
             page.size['width'] / 100 * 90,
             page.size['width'] / 2, 200).perform()
开发者ID:changm,项目名称:b2gperf,代码行数:28,代码来源:b2gperf.py

示例3: chain_flick

# 需要导入模块: from marionette import Actions [as 别名]
# 或者: from marionette.Actions import flick [as 别名]
def chain_flick(marionette, wait_for_condition, expected1, expected2):
    testAction = marionette.absolute_url("testAction.html")
    marionette.navigate(testAction)
    button = marionette.find_element("id", "button1")
    action = Actions(marionette)
    action.flick(button, 0, 0, 0, 200).perform()
    wait_for_condition(lambda m: expected1 in m.execute_script("return document.getElementById('button1').innerHTML;"))
    wait_for_condition(lambda m: expected2 in m.execute_script("return document.getElementById('buttonFlick').innerHTML;"))
开发者ID:JuannyWang,项目名称:gecko-dev,代码行数:10,代码来源:single_finger_functions.py

示例4: scroll_app

# 需要导入模块: from marionette import Actions [as 别名]
# 或者: from marionette.Actions import flick [as 别名]
    def scroll_app(self, app_name):
        touch_duration = float(200)

        apps = gaiatest.GaiaApps(self.marionette)
        #wait up to 30secs for the elements we want to show up
        self.marionette.set_search_timeout(30000)

        if app_name == 'Homescreen':
            action = Actions(self.marionette)
            landing_page = self.marionette.find_element('id', 'landing-page')
            action.flick(
                landing_page,
                landing_page.size['width'] / 100 * 90,
                landing_page.size['width'] / 2,
                landing_page.size['width'] / 100 * 10,
                landing_page.size['width'] / 2, touch_duration).perform()
            first_page = self.marionette.find_elements('css selector', '.page')[0]
            action.flick(
                first_page,
                first_page.size['width'] / 100 * 10,
                first_page.size['width'] / 2,
                first_page.size['width'] / 100 * 90,
                first_page.size['width'] / 2, touch_duration).perform()
        elif app_name == 'Contacts':
            name = self.marionette.find_element("css selector", ".contact-item p > strong")
            MarionetteWait(self.marionette, 30).until(lambda m: name.is_displayed())
            smooth_scroll(self.marionette, name, "y", -1, 5000, scroll_back=False)
        elif app_name == 'Browser':
            self.marionette.execute_script("return window.wrappedJSObject.Browser.navigate('http://taskjs.org/');", new_sandbox=False)
            MarionetteWait(self.marionette, 30).until(lambda m: 'http://taskjs.org/' == m.execute_script('return window.wrappedJSObject.Browser.currentTab.url;', new_sandbox=False))
            MarionetteWait(self.marionette, 30).until(lambda m: not m.execute_script('return window.wrappedJSObject.Browser.currentTab.loading;', new_sandbox=False))
            # check when the tab's document is ready
            tab_frame = self.marionette.execute_script("return window.wrappedJSObject.Browser.currentTab.dom;")
            self.marionette.switch_to_frame(tab_frame)
            MarionetteWait(self.marionette, 30).until(lambda m: m.execute_script('return window.document.readyState;', new_sandbox=False) == 'complete')
            # we have to fire smooth_scroll from the browser app, so let's go back
            self.marionette.switch_to_frame()
            apps.launch(app_name)  # since the app is launched, launch will switch us back to the app frame without relaunching
            tab_dom = self.marionette.execute_script("return window.wrappedJSObject.Browser.currentTab.dom;", new_sandbox=False)
            smooth_scroll(self.marionette, tab_dom, "y", -1, 5000, scroll_back=True)
        elif app_name == 'Email':
            email = self.marionette.find_element("class name", "msg-header-author")
            MarionetteWait(self.marionette, 30).until(lambda m: email.is_displayed() or not email.get_attribute('hidden'))
            emails = self.marionette.find_elements("class name", "msg-header-author")
            #we're dynamically adding these elements from a template, and the first one found is blank.
            MarionetteWait(self.marionette, 30).until(lambda m: emails[0].get_attribute('innerHTML'))
            emails = self.marionette.find_elements("class name", "msg-header-author")
            smooth_scroll(self.marionette, emails[0], "y", -1, 2000, scroll_back=True)
开发者ID:rhelmer,项目名称:eddy-lib,代码行数:50,代码来源:b2gperf.py

示例5: scroll_app

# 需要导入模块: from marionette import Actions [as 别名]
# 或者: from marionette.Actions import flick [as 别名]
    def scroll_app(self, app_name):
        touch_duration = float(200)

        #wait up to 30secs for the elements we want to show up
        self.marionette.set_search_timeout(30000)

        if app_name.lower() == 'homescreen':
            action = Actions(self.marionette)
            landing_page = self.marionette.find_element('id', 'landing-page')
            self.logger.debug('Swiping to first page of apps')
            action.flick(
                landing_page,
                landing_page.size['width'] / 100 * 90,
                landing_page.size['width'] / 2,
                landing_page.size['width'] / 100 * 10,
                landing_page.size['width'] / 2, touch_duration).perform()
            first_page = self.marionette.find_elements('css selector', '.page')[0]
            self.logger.debug('Swiping back to home screen')
            action.flick(
                first_page,
                first_page.size['width'] / 100 * 10,
                first_page.size['width'] / 2,
                first_page.size['width'] / 100 * 90,
                first_page.size['width'] / 2, touch_duration).perform()
        elif app_name.lower() == 'contacts':
            name = self.marionette.find_element("css selector", ".contact-item p > strong")
            MarionetteWait(self.marionette, 30).until(lambda m: name.is_displayed())
            self.logger.debug('Scrolling through contacts')
            smooth_scroll(self.marionette, name, "y", -1, 5000, scroll_back=False)
        elif app_name.lower() == 'browser':
            tab_dom = self.marionette.execute_script("return window.wrappedJSObject.Browser.currentTab.dom;", new_sandbox=False)
            self.logger.debug('Scrolling through browser content')
            smooth_scroll(self.marionette, tab_dom, "y", -1, 5000, scroll_back=True)
        elif app_name.lower() == 'email':
            email = self.marionette.find_element("class name", "msg-header-author")
            MarionetteWait(self.marionette, 30).until(lambda m: email.is_displayed() or not email.get_attribute('hidden'))
            emails = self.marionette.find_elements("class name", "msg-header-author")
            #we're dynamically adding these elements from a template, and the first one found is blank.
            MarionetteWait(self.marionette, 30).until(lambda m: emails[0].get_attribute('innerHTML'))
            emails = self.marionette.find_elements("class name", "msg-header-author")
            self.logger.debug('Scrolling through emails')
            smooth_scroll(self.marionette, emails[0], "y", -1, 2000, scroll_back=True)
开发者ID:zbraniecki,项目名称:b2gperf,代码行数:44,代码来源:b2gperf.py

示例6: TouchCaretTest

# 需要导入模块: from marionette import Actions [as 别名]
# 或者: from marionette.Actions import flick [as 别名]
class TouchCaretTest(MarionetteTestCase):
    _input_selector = (By.ID, 'input')
    _textarea_selector = (By.ID, 'textarea')
    _contenteditable_selector = (By.ID, 'contenteditable')
    _large_expiration_time = 3000 * 20  # 60 seconds

    def setUp(self):
        # Code to execute before a test is being run.
        MarionetteTestCase.setUp(self)
        self.actions = Actions(self.marionette)
        self.original_expiration_time = self.expiration_time

    def tearDown(self):
        # Code to execute after a test is being run.
        self.expiration_time = self.original_expiration_time
        MarionetteTestCase.tearDown(self)

    @property
    def expiration_time(self):
        'Return touch caret expiration time in milliseconds.'
        return self.marionette.execute_script(
            'return SpecialPowers.getIntPref("touchcaret.expiration.time");')

    @expiration_time.setter
    def expiration_time(self, expiration_time):
        'Set touch caret expiration time in milliseconds.'
        self.marionette.execute_script(
            'SpecialPowers.setIntPref("touchcaret.expiration.time", arguments[0]);',
            script_args=[expiration_time])

    def openTestHtml(self, enabled=True, expiration_time=None):
        '''Open html for testing and locate elements, enable/disable touch caret, and
        set touch caret expiration time in milliseconds).

        '''
        self.marionette.execute_script(
            'SpecialPowers.setBoolPref("touchcaret.enabled", %s);' %
            ('true' if enabled else 'false'))

        # Set a larger expiration time to avoid intermittent test failures.
        if expiration_time is not None:
            self.expiration_time = expiration_time

        test_html = self.marionette.absolute_url('test_touchcaret.html')
        self.marionette.navigate(test_html)

        self._input = self.marionette.find_element(*self._input_selector)
        self._textarea = self.marionette.find_element(*self._textarea_selector)
        self._contenteditable = self.marionette.find_element(*self._contenteditable_selector)

    def _test_move_caret_to_the_right_by_one_character(self, el, assertFunc):
        sel = SelectionManager(el)
        content_to_add = '!'
        target_content = sel.content
        target_content = target_content[:1] + content_to_add + target_content[1:]

        # Get touch caret (x, y) at position 1 and 2.
        el.tap()
        sel.move_caret_to_front()
        caret0_x, caret0_y = sel.caret_location()
        touch_caret0_x, touch_caret0_y = sel.touch_caret_location()
        sel.move_caret_by_offset(1)
        touch_caret1_x, touch_caret1_y = sel.touch_caret_location()

        # Tap the front of the input to make touch caret appear.
        el.tap(caret0_x, caret0_y)

        # Move touch caret
        self.actions.flick(el, touch_caret0_x, touch_caret0_y,
                           touch_caret1_x, touch_caret1_y).perform()

        el.send_keys(content_to_add)
        assertFunc(target_content, sel.content)

    def _test_move_caret_to_end_by_dragging_touch_caret_to_bottom_right_corner(self, el, assertFunc):
        sel = SelectionManager(el)
        content_to_add = '!'
        target_content = sel.content + content_to_add

        # Tap the front of the input to make touch caret appear.
        el.tap()
        sel.move_caret_to_front()
        el.tap(*sel.caret_location())

        # Move touch caret to the bottom-right corner of the element.
        src_x, src_y = sel.touch_caret_location()
        dest_x, dest_y = el.size['width'], el.size['height']
        self.actions.flick(el, src_x, src_y, dest_x, dest_y).perform()

        el.send_keys(content_to_add)
        assertFunc(target_content, sel.content)

    def _test_move_caret_to_front_by_dragging_touch_caret_to_top_left_corner(self, el, assertFunc):
        sel = SelectionManager(el)
        content_to_add = '!'
        target_content = content_to_add + sel.content

        # Tap to make touch caret appear. Note: it's strange that when the caret
        # is at the end, the rect of the caret in <textarea> cannot be obtained.
        # A bug perhaps.
#.........这里部分代码省略.........
开发者ID:aeddi,项目名称:gecko-dev,代码行数:103,代码来源:test_touchcaret.py

示例7: flick

# 需要导入模块: from marionette import Actions [as 别名]
# 或者: from marionette.Actions import flick [as 别名]
 def flick(self, element, x1, y1, x2, y2, duration=200):
     action = Actions(self)
     action.flick(element, x1, y1, x2, y2, duration).perform()
开发者ID:sergecodd,项目名称:FireFox-OS,代码行数:5,代码来源:marionette_touch.py

示例8: SelectionCaretsTest

# 需要导入模块: from marionette import Actions [as 别名]
# 或者: from marionette.Actions import flick [as 别名]
class SelectionCaretsTest(MarionetteTestCase):
    _long_press_time = 1        # 1 second
    _input_selector = (By.ID, 'input')
    _textarea_selector = (By.ID, 'textarea')
    _textarea_rtl_selector = (By.ID, 'textarea_rtl')
    _contenteditable_selector = (By.ID, 'contenteditable')
    _content_selector = (By.ID, 'content')

    def setUp(self):
        # Code to execute before a tests are run.
        MarionetteTestCase.setUp(self)
        self.actions = Actions(self.marionette)

    def openTestHtml(self, enabled=True):
        '''Open html for testing and locate elements, and enable/disable touch
        caret.'''
        self.marionette.execute_script(
            'SpecialPowers.setBoolPref("selectioncaret.enabled", %s);' %
            ('true' if enabled else 'false'))

        test_html = self.marionette.absolute_url('test_selectioncarets.html')
        self.marionette.navigate(test_html)

        self._input = self.marionette.find_element(*self._input_selector)
        self._textarea = self.marionette.find_element(*self._textarea_selector)
        self._textarea_rtl = self.marionette.find_element(*self._textarea_rtl_selector)
        self._contenteditable = self.marionette.find_element(*self._contenteditable_selector)
        self._content = self.marionette.find_element(*self._content_selector)

    def _long_press_to_select_first_word(self, el, sel):
        # Move caret inside the first word.
        el.tap()
        sel.move_caret_to_front()
        sel.move_caret_by_offset(1)
        x, y = sel.caret_location()

        # Long press the caret position. Selection carets should appear, and
        # select the first word.
        self.actions.long_press(el, self._long_press_time, x, y).perform()

    def _test_long_press_to_select_a_word(self, el, assertFunc):
        sel = SelectionManager(el)
        original_content = sel.content
        words = original_content.split()
        self.assertTrue(len(words) >= 2, 'Expect at least two words in the content.')

        # Goal: Replace the first word with '!'
        content_to_add = '!'
        target_content = original_content.replace(words[0], content_to_add, 1)

        self._long_press_to_select_first_word(el, sel)

        # Replace the first word.
        el.send_keys(content_to_add)
        assertFunc(target_content, sel.content)

    def _test_move_selection_carets(self, el, assertFunc):
        sel = SelectionManager(el)
        original_content = sel.content
        words = original_content.split()
        self.assertTrue(len(words) >= 1, 'Expect at least one word in the content.')

        # Goal: Replace all text after the first word with '!'
        content_to_add = '!'
        target_content = words[0] + content_to_add

        # Get the location of the selection carets at the end of the content for
        # later use.
        el.tap()
        sel.select_all()
        (_, _), (end_caret_x, end_caret_y) = sel.selection_carets_location()

        self._long_press_to_select_first_word(el, sel)

        # Move the right caret to the end of the content.
        (caret1_x, caret1_y), (caret2_x, caret2_y) = sel.selection_carets_location()
        self.actions.flick(el, caret2_x, caret2_y, end_caret_x, end_caret_y).perform()

        # Move the left caret to the previous position of the right caret.
        self.actions.flick(el, caret1_x, caret2_y, caret2_x, caret2_y).perform()

        el.send_keys(content_to_add)
        assertFunc(target_content, sel.content)

    def _test_minimum_select_one_character(self, el, assertFunc):
        sel = SelectionManager(el)
        original_content = sel.content
        words = original_content.split()
        self.assertTrue(len(words) >= 1, 'Expect at least one word in the content.')

        # Goal: Replace last character of the first word with '!'
        content_to_add = '!'
        new_word = words[0][:-1] + content_to_add
        target_content = original_content.replace(words[0], new_word, 1)

        self._long_press_to_select_first_word(el, sel)

        # Move the left caret to the position of right caret.
        (caret1_x, caret1_y), (caret2_x, caret2_y) = sel.selection_carets_location()
        self.actions.flick(el, caret1_x, caret1_y, caret2_x, caret2_y,).perform()
#.........这里部分代码省略.........
开发者ID:rperez08,项目名称:gecko-dev,代码行数:103,代码来源:test_selectioncarets.py

示例9: SelectionCaretsTest

# 需要导入模块: from marionette import Actions [as 别名]
# 或者: from marionette.Actions import flick [as 别名]

#.........这里部分代码省略.........
        sel = SelectionManager(el)
        original_content = sel.content
        words = original_content.split()
        self.assertTrue(len(words) >= 2, "Expect at least two words in the content.")
        target_content = words[0]

        # Goal: Select the first word.
        x, y = self._first_word_location(el)
        self._long_press_to_select(el, x, y)

        # Ignore extra spaces selected after the word.
        assertFunc(target_content, sel.selected_content.rstrip())

    def _test_move_selection_carets(self, el, assertFunc):
        sel = SelectionManager(el)
        original_content = sel.content
        words = original_content.split()
        self.assertTrue(len(words) >= 1, "Expect at least one word in the content.")

        # Goal: Select all text after the first word.
        target_content = original_content[len(words[0]) :]

        # Get the location of the selection carets at the end of the content for
        # later use.
        el.tap()
        sel.select_all()
        (_, _), (end_caret_x, end_caret_y) = sel.selection_carets_location()

        x, y = self._first_word_location(el)
        self._long_press_to_select(el, x, y)

        # Move the right caret to the end of the content.
        (caret1_x, caret1_y), (caret2_x, caret2_y) = sel.selection_carets_location()
        self.actions.flick(el, caret2_x, caret2_y, end_caret_x, end_caret_y).perform()

        # Move the left caret to the previous position of the right caret.
        self.actions.flick(el, caret1_x, caret1_y, caret2_x, caret2_y).perform()

        # Ignore extra spaces at the beginning of the content in comparison.
        assertFunc(target_content.lstrip(), sel.selected_content.lstrip())

    def _test_minimum_select_one_character(self, el, assertFunc, x=None, y=None):
        sel = SelectionManager(el)
        original_content = sel.content
        words = original_content.split()
        self.assertTrue(len(words) >= 1, "Expect at least one word in the content.")

        # Get the location of the selection carets at the end of the content for
        # later use.
        sel.select_all()
        (_, _), (end_caret_x, end_caret_y) = sel.selection_carets_location()
        el.tap()

        # Goal: Select the first character.
        target_content = original_content[0]

        if x and y:
            # If we got x and y from the arguments, use it as a hint of the
            # location of the first word
            pass
        else:
            x, y = self._first_word_location(el)
        self._long_press_to_select(el, x, y)

        # Move the right caret to the end of the content.
        (caret1_x, caret1_y), (caret2_x, caret2_y) = sel.selection_carets_location()
开发者ID:fatman2021,项目名称:gecko-dev,代码行数:70,代码来源:test_selectioncarets.py

示例10: SelectionCaretsMultipleRangeTest

# 需要导入模块: from marionette import Actions [as 别名]
# 或者: from marionette.Actions import flick [as 别名]
class SelectionCaretsMultipleRangeTest(MarionetteTestCase):
    _long_press_time = 1        # 1 second

    def setUp(self):
        # Code to execute before a tests are run.
        MarionetteTestCase.setUp(self)
        self.actions = Actions(self.marionette)

    def openTestHtml(self, enabled=True):
        # Open html for testing and enable selectioncaret and
        # non-editable support
        self.marionette.execute_script(
            'SpecialPowers.setBoolPref("selectioncaret.enabled", %s);' %
            ('true' if enabled else 'false'))
        self.marionette.execute_script(
            'SpecialPowers.setBoolPref("selectioncaret.noneditable", %s);' %
            ('true' if enabled else 'false'))

        test_html = self.marionette.absolute_url('test_selectioncarets_multiplerange.html')
        self.marionette.navigate(test_html)

        self._body = self.marionette.find_element(By.ID, 'bd')
        self._sel1 = self.marionette.find_element(By.ID, 'sel1')
        self._sel2 = self.marionette.find_element(By.ID, 'sel2')
        self._sel3 = self.marionette.find_element(By.ID, 'sel3')
        self._sel4 = self.marionette.find_element(By.ID, 'sel4')
        self._sel6 = self.marionette.find_element(By.ID, 'sel6')
        self._nonsel1 = self.marionette.find_element(By.ID, 'nonsel1')

    def _long_press_to_select_word(self, el, wordOrdinal):
        sel = SelectionManager(el)
        original_content = sel.content
        words = original_content.split()
        self.assertTrue(wordOrdinal < len(words),
            'Expect at least %d words in the content.' % wordOrdinal)

        # Calc offset
        offset = 0
        for i in range(wordOrdinal):
            offset += (len(words[i]) + 1)

        # Move caret inside the word.
        el.tap()
        sel.move_caret_to_front()
        sel.move_caret_by_offset(offset)
        x, y = sel.caret_location()

        # Long press the caret position. Selection carets should appear, and the
        # word will be selected. On Windows, those spaces after the word
        # will also be selected.
        long_press_without_contextmenu(self.marionette, el, self._long_press_time, x, y)

    def _to_unix_line_ending(self, s):
        """Changes all Windows/Mac line endings in s to UNIX line endings."""

        return s.replace('\r\n', '\n').replace('\r', '\n')

    def test_long_press_to_select_non_selectable_word(self):
        '''Testing long press on non selectable field.
        We should not select anything when long press on non selectable fields.'''

        self.openTestHtml(enabled=True)
        halfY = self._nonsel1.size['height'] / 2
        long_press_without_contextmenu(self.marionette, self._nonsel1, self._long_press_time, 0, halfY)
        sel = SelectionManager(self._nonsel1)
        range_count = sel.range_count()
        self.assertEqual(range_count, 0)

    def test_drag_caret_over_non_selectable_field(self):
        '''Testing drag caret over non selectable field.
        So that the selected content should exclude non selectable field and
        end selection caret should appear in last range's position.'''
        self.openTestHtml(enabled=True)

        # Select target element and get target caret location
        self._long_press_to_select_word(self._sel4, 3)
        sel = SelectionManager(self._body)
        (_, _), (end_caret_x, end_caret_y) = sel.selection_carets_location()

        self._long_press_to_select_word(self._sel6, 0)
        (_, _), (end_caret2_x, end_caret2_y) = sel.selection_carets_location()

        # Select start element
        self._long_press_to_select_word(self._sel3, 3)

        # Drag end caret to target location
        (caret1_x, caret1_y), (caret2_x, caret2_y) = sel.selection_carets_location()
        self.actions.flick(self._body, caret2_x, caret2_y, end_caret_x, end_caret_y, 1).perform()
        self.assertEqual(self._to_unix_line_ending(sel.selected_content.strip()),
            'this 3\nuser can select this')

        (caret1_x, caret1_y), (caret2_x, caret2_y) = sel.selection_carets_location()
        self.actions.flick(self._body, caret2_x, caret2_y, end_caret2_x, end_caret2_y, 1).perform()
        self.assertEqual(self._to_unix_line_ending(sel.selected_content.strip()),
            'this 3\nuser can select this 4\nuser can select this 5\nuser')

    def test_drag_caret_to_beginning_of_a_line(self):
        '''Bug 1094056
        Test caret visibility when caret is dragged to beginning of a line
        '''
#.........这里部分代码省略.........
开发者ID:fatman2021,项目名称:gecko-dev,代码行数:103,代码来源:test_selectioncarets_multiplerange.py

示例11: SelectionCaretsTest

# 需要导入模块: from marionette import Actions [as 别名]
# 或者: from marionette.Actions import flick [as 别名]
class SelectionCaretsTest(MarionetteTestCase):
    _long_press_time = 1        # 1 second
    _input_selector = (By.ID, 'input')
    _textarea_selector = (By.ID, 'textarea')
    _textarea_rtl_selector = (By.ID, 'textarea_rtl')
    _contenteditable_selector = (By.ID, 'contenteditable')
    _content_selector = (By.ID, 'content')

    def setUp(self):
        # Code to execute before a tests are run.
        MarionetteTestCase.setUp(self)
        self.actions = Actions(self.marionette)

    def openTestHtml(self, enabled=True):
        '''Open html for testing and locate elements, and enable/disable touch
        caret.'''
        self.marionette.execute_script(
            'SpecialPowers.setBoolPref("selectioncaret.enabled", %s);' %
            ('true' if enabled else 'false'))

        test_html = self.marionette.absolute_url('test_selectioncarets.html')
        self.marionette.navigate(test_html)

        self._input = self.marionette.find_element(*self._input_selector)
        self._textarea = self.marionette.find_element(*self._textarea_selector)
        self._textarea_rtl = self.marionette.find_element(*self._textarea_rtl_selector)
        self._contenteditable = self.marionette.find_element(*self._contenteditable_selector)
        self._content = self.marionette.find_element(*self._content_selector)

    def _long_press_to_select_first_word(self, el, sel):
        # Move caret inside the first word.
        el.tap()
        sel.move_caret_to_front()
        sel.move_caret_by_offset(1)
        x, y = sel.caret_location()

        # Long press the caret position. Selection carets should appear, and the
        # first word will be selected. On Windows, those spaces after the word
        # will also be selected.
        long_press_without_contextmenu(self.marionette, el, self._long_press_time, x, y)

    def _test_long_press_to_select_a_word(self, el, assertFunc):
        sel = SelectionManager(el)
        original_content = sel.content
        words = original_content.split()
        self.assertTrue(len(words) >= 2, 'Expect at least two words in the content.')
        target_content = words[0]

        # Goal: Select the first word.
        self._long_press_to_select_first_word(el, sel)

        # Ignore extra spaces selected after the word.
        assertFunc(target_content, sel.selected_content.rstrip())

    def _test_move_selection_carets(self, el, assertFunc):
        sel = SelectionManager(el)
        original_content = sel.content
        words = original_content.split()
        self.assertTrue(len(words) >= 1, 'Expect at least one word in the content.')

        # Goal: Select all text after the first word.
        target_content = original_content[len(words[0]):]

        # Get the location of the selection carets at the end of the content for
        # later use.
        el.tap()
        sel.select_all()
        (_, _), (end_caret_x, end_caret_y) = sel.selection_carets_location()

        self._long_press_to_select_first_word(el, sel)

        # Move the right caret to the end of the content.
        (caret1_x, caret1_y), (caret2_x, caret2_y) = sel.selection_carets_location()
        self.actions.flick(el, caret2_x, caret2_y, end_caret_x, end_caret_y).perform()

        # Move the left caret to the previous position of the right caret.
        self.actions.flick(el, caret1_x, caret2_y, caret2_x, caret2_y).perform()

        # Ignore extra spaces at the beginning of the content in comparison.
        assertFunc(target_content.lstrip(), sel.selected_content.lstrip())

    def _test_minimum_select_one_character(self, el, assertFunc):
        sel = SelectionManager(el)
        original_content = sel.content
        words = original_content.split()
        self.assertTrue(len(words) >= 1, 'Expect at least one word in the content.')

        # Goal: Select the first character.
        target_content = original_content[0]

        self._long_press_to_select_first_word(el, sel)

        # Move the right caret to the position of the left caret.
        (caret1_x, caret1_y), (caret2_x, caret2_y) = sel.selection_carets_location()
        self.actions.flick(el, caret2_x, caret2_y, caret1_x, caret1_y,).perform()

        assertFunc(target_content, sel.selected_content)

    ########################################################################
    # <input> test cases with selection carets enabled
#.........这里部分代码省略.........
开发者ID:ashishrana7,项目名称:firefox,代码行数:103,代码来源:test_selectioncarets.py


注:本文中的marionette.Actions.flick方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。