def test_drag_caret_over_non_selectable_field(self): """Test dragging the caret over a non-selectable field. The selected content should exclude non-selectable elements and the second caret should appear in last range's position. """ self.open_test_html(self._multiplerange_html) body = self.marionette.find_element(By.ID, "bd") sel3 = self.marionette.find_element(By.ID, "sel3") sel4 = self.marionette.find_element(By.ID, "sel4") sel6 = self.marionette.find_element(By.ID, "sel6") # Select target element and get target caret location self.long_press_on_word(sel4, 3) sel = SelectionManager(body) end_caret_x, end_caret_y = sel.second_caret_location() self.long_press_on_word(sel6, 0) end_caret2_x, end_caret2_y = sel.second_caret_location() # Select start element self.long_press_on_word(sel3, 3) # Drag end caret to target location (caret1_x, caret1_y), (caret2_x, caret2_y) = sel.carets_location() self.actions.flick( 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.carets_location() self.actions.flick( 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", ) # Drag first caret to target location (caret1_x, caret1_y), (caret2_x, caret2_y) = sel.carets_location() self.actions.flick( body, caret1_x, caret1_y, end_caret_x, end_caret_y, 1 ).perform() self.assertEqual( self.to_unix_line_ending(sel.selected_content.strip()), "4\nuser can select this 5\nuser", )
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_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_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)