本文整理汇总了Python中marionette_driver.selection.SelectionManager类的典型用法代码示例。如果您正苦于以下问题:Python SelectionManager类的具体用法?Python SelectionManager怎么用?Python SelectionManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SelectionManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _test_move_selection_carets
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())
示例2: test_drag_caret_from_front_to_end_across_columns
def test_drag_caret_from_front_to_end_across_columns(self):
self.open_test_html('test_carets_columns.html')
el = self.marionette.find_element(By.ID, 'columns-inner')
sel = SelectionManager(el)
content_to_add = '!'
target_content = sel.content + content_to_add
# Goal: the cursor position can be changed by dragging the caret from
# the front to the end of the content.
# Tap to make the cursor appear.
before_image_1 = self.marionette.find_element(By.ID, 'before-image-1')
before_image_1.tap()
# Tap the front of the content to make first caret appear.
sel.move_cursor_to_front()
el.tap(*sel.cursor_location())
src_x, src_y = sel.first_caret_location()
dest_x, dest_y = el.size['width'], el.size['height']
# Drag the first caret to the bottom-right corner of the element.
self.actions.flick(el, src_x, src_y, dest_x, dest_y).perform()
self.actions.key_down(content_to_add).key_up(content_to_add).perform()
self.assertEqual(target_content, sel.content)
示例3: test_long_press_to_select_when_partial_visible_word_is_selected
def test_long_press_to_select_when_partial_visible_word_is_selected(self):
self.open_test_html(self._selection_html)
el = self.marionette.find_element(By.ID, self._input_size_id)
sel = SelectionManager(el)
original_content = sel.content
words = original_content.split()
# We cannot use self.long_press_on_word() for the second long press
# on the first word because it has side effect that changes the
# cursor position. We need to save the location of the first word to
# be used later.
word0_x, word0_y = self.word_location(el, 0)
# Long press on the second word.
self.long_press_on_word(el, 1)
self.assertEqual(words[1], sel.selected_content)
# Long press on the first word.
self.long_press_on_location(el, word0_x, word0_y)
self.assertEqual(words[0], sel.selected_content)
# If the second caret is visible, it can be dragged to the position
# of the first caret. After that, selection will contain only the
# first character.
(caret1_x, caret1_y), (caret2_x, caret2_y) = sel.carets_location()
self.actions.flick(el, caret2_x, caret2_y, caret1_x, caret1_y).perform()
self.assertEqual(words[0][0], sel.selected_content)
示例4: _test_move_selection_carets
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_on_word(el, 0)
# 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()
assertFunc(target_content, sel.selected_content)
示例5: test_drag_caret_to_beginning_of_a_line
def test_drag_caret_to_beginning_of_a_line(self):
'''Bug 1094056
Test caret visibility when caret is dragged to beginning of a line
'''
self.open_test_html(self._multiplerange_html)
body = self.marionette.find_element(By.ID, 'bd')
sel1 = self.marionette.find_element(By.ID, 'sel1')
sel2 = self.marionette.find_element(By.ID, 'sel2')
# Select the first word in the second line
self.long_press_on_word(sel2, 0)
sel = SelectionManager(body)
(start_caret_x, start_caret_y), (end_caret_x, end_caret_y) = sel.carets_location()
# Select target word in the first line
self.long_press_on_word(sel1, 2)
# Drag end caret to the beginning of the second line
(caret1_x, caret1_y), (caret2_x, caret2_y) = sel.carets_location()
self.actions.flick(body, caret2_x, caret2_y, start_caret_x, start_caret_y).perform()
# Drag end caret back to the target word
self.actions.flick(body, start_caret_x, start_caret_y, caret2_x, caret2_y).perform()
self.assertEqual(self.to_unix_line_ending(sel.selected_content), 'select')
示例6: test_caret_not_appear_when_typing_in_scrollable_content
def test_caret_not_appear_when_typing_in_scrollable_content(self):
self.open_test_html(self._cursor_html)
el = self.marionette.find_element(By.ID, self._input_id)
sel = SelectionManager(el)
content_to_add = '!'
target_content = sel.content + string.ascii_letters + content_to_add
el.tap()
sel.move_cursor_to_end()
# Insert a long string to the end of the <input>, which triggers
# ScrollPositionChanged event.
el.send_keys(string.ascii_letters)
# The caret should not be visible. If it does appear wrongly due to the
# ScrollPositionChanged event, we can drag it to the front of the
# <input> to change the cursor position.
src_x, src_y = sel.first_caret_location()
dest_x, dest_y = 0, 0
self.actions.flick(el, src_x, src_y, dest_x, dest_y).perform()
# The content should be inserted at the end of the <input>.
el.send_keys(content_to_add)
self.assertEqual(target_content, sel.content)
示例7: test_move_cursor_to_front_by_dragging_caret_to_front
def test_move_cursor_to_front_by_dragging_caret_to_front(self, el_id):
self.open_test_html(self._cursor_html)
el = self.marionette.find_element(By.ID, el_id)
sel = SelectionManager(el)
content_to_add = '!'
target_content = content_to_add + sel.content
# Get first caret location at the front.
el.tap()
sel.move_cursor_to_front()
dest_x, dest_y = sel.first_caret_location()
# Tap to make first 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.
el.tap()
sel.move_cursor_to_end()
sel.move_cursor_by_offset(1, backward=True)
el.tap(*sel.cursor_location())
src_x, src_y = sel.first_caret_location()
# Move first caret to the front of the input box.
self.actions.flick(el, src_x, src_y, dest_x, dest_y).perform()
self.actions.key_down(content_to_add).key_up(content_to_add).perform()
self.assertEqual(target_content, sel.content)
示例8: test_caret_position_after_changing_orientation_of_device
def test_caret_position_after_changing_orientation_of_device(self):
'''Bug 1094072
If positions of carets are updated correctly, they should be draggable.
'''
self.open_test_html(self._longtext_html)
body = self.marionette.find_element(By.ID, 'bd')
longtext = self.marionette.find_element(By.ID, 'longtext')
# Select word in portrait mode, then change to landscape mode
self.marionette.set_orientation('portrait')
self.long_press_on_word(longtext, 12)
sel = SelectionManager(body)
(p_start_caret_x, p_start_caret_y), (p_end_caret_x, p_end_caret_y) = sel.carets_location()
self.marionette.set_orientation('landscape')
(l_start_caret_x, l_start_caret_y), (l_end_caret_x, l_end_caret_y) = sel.carets_location()
# Drag end caret to the start caret to change the selected content
self.actions.flick(body, l_end_caret_x, l_end_caret_y,
l_start_caret_x, l_start_caret_y).perform()
# Change orientation back to portrait mode to prevent affecting
# other tests
self.marionette.set_orientation('portrait')
self.assertEqual(self.to_unix_line_ending(sel.selected_content), 'o')
示例9: test_drag_carets
def test_drag_carets(self, el_id):
self.open_test_html(self._selection_html)
el = self.marionette.find_element(By.ID, el_id)
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 carets at the end of the content for later
# use.
el.tap()
sel.select_all()
end_caret_x, end_caret_y = sel.second_caret_location()
self.long_press_on_word(el, 0)
# Drag the second caret to the end of the content.
(caret1_x, caret1_y), (caret2_x, caret2_y) = sel.carets_location()
self.actions.flick(el, caret2_x, caret2_y, end_caret_x, end_caret_y).perform()
# Drag the first caret to the previous position of the second caret.
self.actions.flick(el, caret1_x, caret1_y, caret2_x, caret2_y).perform()
self.assertEqual(target_content, sel.selected_content)
示例10: test_drag_caret_over_non_selectable_field
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')
示例11: test_long_press_to_select_when_partial_visible_word_is_selected
def test_long_press_to_select_when_partial_visible_word_is_selected(self):
self.open_test_html()
el = self._input
sel = SelectionManager(el)
# To successfully select the second word while the first word is being
# selected, use sufficient spaces between 'a' and 'b' to avoid the
# second caret covers on the second word.
original_content = 'aaaaaaaa bbbbbbbb'
el.clear()
el.send_keys(original_content)
words = original_content.split()
# We cannot use self.long_press_on_word() directly since it has will
# change the cursor position which affects this test. We have to store
# the position of word 0 and word 1 before long-pressing to select the
# word.
word0_x, word0_y = self.word_location(el, 0)
word1_x, word1_y = self.word_location(el, 1)
self.long_press_on_location(el, word0_x, word0_y)
self.assertEqual(words[0], sel.selected_content)
self.long_press_on_location(el, word1_x, word1_y)
self.assertEqual(words[1], sel.selected_content)
self.long_press_on_location(el, word0_x, word0_y)
self.assertEqual(words[0], sel.selected_content)
# If the second carets is visible, it can be dragged to the position of
# the first caret. After that, selection will contain only the first
# character.
(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()
self.assertEqual(words[0][0], sel.selected_content)
示例12: test_caret_position_after_changing_orientation_of_device
def test_caret_position_after_changing_orientation_of_device(self):
'''Bug 1094072
If positions of carets are updated correctly, they should be draggable.
'''
# Skip running test on non-rotatable device ex.desktop browser
if not self.marionette.session_capabilities['rotatable']:
return
self.openTestHtmlLongText(enabled=True)
# Select word in portrait mode, then change to landscape mode
self.marionette.set_orientation('portrait')
self._long_press_to_select_word(self._longtext, 12)
sel = SelectionManager(self._body)
(p_start_caret_x, p_start_caret_y), (p_end_caret_x, p_end_caret_y) = sel.selection_carets_location()
self.marionette.set_orientation('landscape')
(l_start_caret_x, l_start_caret_y), (l_end_caret_x, l_end_caret_y) = sel.selection_carets_location()
# Drag end caret to the start caret to change the selected content
self.actions.flick(self._body, l_end_caret_x, l_end_caret_y, l_start_caret_x, l_start_caret_y).perform()
# Change orientation back to portrait mode to prevent affecting
# other tests
self.marionette.set_orientation('portrait')
self.assertEqual(self._to_unix_line_ending(sel.selected_content.strip()), 'o')
示例13: test_move_cursor_to_front_by_dragging_caret_to_front_br_element
def test_move_cursor_to_front_by_dragging_caret_to_front_br_element(self):
self.open_test_html(self._cursor_html)
el = self.marionette.find_element(By.ID, self._contenteditable_id)
sel = SelectionManager(el)
content_to_add_1 = '!'
content_to_add_2 = '\n\n'
target_content = content_to_add_1 + content_to_add_2 + sel.content
# Goal: the cursor position can be changed by dragging the caret from
# the end of the content to the front br element. Because we cannot get
# caret location if it's on a br element, we need to get the first caret
# location then adding the new lines.
# Get first caret location at the front.
el.tap()
sel.move_cursor_to_front()
dest_x, dest_y = sel.first_caret_location()
# Append new line to the front of the content.
el.send_keys(content_to_add_2);
# Tap to make first caret appear.
el.tap()
sel.move_cursor_to_end()
sel.move_cursor_by_offset(1, backward=True)
el.tap(*sel.cursor_location())
src_x, src_y = sel.first_caret_location()
# Move first caret to the front of the input box.
self.actions.flick(el, src_x, src_y, dest_x, dest_y).perform()
self.actions.key_down(content_to_add_1).key_up(content_to_add_1).perform()
self.assertEqual(target_content, sel.content)
示例14: test_long_press_to_select_non_selectable_word
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)
示例15: test_long_press_to_select_non_selectable_word
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.open_test_html_multirange()
halfY = self._nonsel1.size['height'] / 2
self.long_press_on_location(self._nonsel1, 0, halfY)
sel = SelectionManager(self._nonsel1)
range_count = sel.range_count()
self.assertEqual(range_count, 0)