def test_drag_swappable_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.') target_content1 = words[0] target_content2 = 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 first caret to the end and back to where it was # immediately. The selection range should not be collapsed. caret1_x, caret1_y = sel.first_caret_location() self.actions.flick(el, caret1_x, caret1_y, end_caret_x, end_caret_y)\ .flick(el, end_caret_x, end_caret_y, caret1_x, caret1_y).perform() self.assertEqual(target_content1, sel.selected_content) # Drag the first caret to the end. caret1_x, caret1_y = sel.first_caret_location() self.actions.flick(el, caret1_x, caret1_y, end_caret_x, end_caret_y).perform() self.assertEqual(target_content2, sel.selected_content)
def _test_minimum_select_one_character(self, el): 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 carets at the end of the content for later # use. sel.select_all() end_caret_x, end_caret_y = sel.second_caret_location() el.tap() # Goal: Select the first character. target_content = original_content[0] 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 second caret to the position of the first caret. (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(target_content, sel.selected_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: 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_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)
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_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() self.actions.flick(el, caret2_x, caret2_y, end_caret_x, end_caret_y).perform() # 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)
def _test_minimum_select_one_character_by_selection(self, el, assertFunc): sel = SelectionManager(el) el.tap() sel.select_all() # Move the right caret to the position of the left caret. Since the # minimum selection range by selection carets is one character, the # first character should be selected. (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() cmd = sel.js_selection_cmd() +\ '''return (sel.anchorNode == sel.focusNode) && (sel.focusOffset - sel.anchorOffset == 1);''' result = self.marionette.execute_script(cmd, script_args=[el]) assertFunc(result)
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() self.actions.flick(el, caret2_x, caret2_y, end_caret_x, end_caret_y).perform() # 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)