示例#1
0
    def test_carets_should_not_appear_when_long_pressing_svg_shapes(self):
        self.open_test_html(self._svg_shapes_html)

        rect = self.marionette.find_element(By.ID, 'rect')
        text = self.marionette.find_element(By.ID, 'text')

        sel = SelectionManager(text)
        num_words_in_text = len(sel.content.split())

        # Goal: the carets should not appear when long-pressing on the
        # unselectable SVG rect.

        # Get the position of the end of last word in text, i.e. the
        # position of the second caret when selecting the last word.
        self.long_press_on_word(text, num_words_in_text - 1)
        (_, _), (x2, y2) = sel.carets_location()

        # Long press to select the unselectable SVG rect.
        self.long_press_on_location(rect)
        (_, _), (x, y) = sel.carets_location()

        # Drag the second caret to (x2, y2).
        self.actions.flick(text, x, y, x2, y2).perform()

        # If the carets should appear on the rect, the selection will be
        # extended to cover all the words in text. Assert this should not
        # happen.
        self.assertNotEqual(sel.content, sel.selected_content.strip())
示例#2
0
    def test_drag_swappable_caret_over_non_selectable_field(self):
        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')
        sel = SelectionManager(body)

        self.long_press_on_word(sel4, 3)
        (end_caret1_x, end_caret1_y), (end_caret2_x,
                                       end_caret2_y) = sel.carets_location()

        self.long_press_on_word(sel3, 3)
        (caret1_x, caret1_y), (caret2_x, caret2_y) = sel.carets_location()

        # Drag the first caret down, which will across the second caret.
        self.actions.flick(body, caret1_x, caret1_y, end_caret1_x,
                           end_caret1_y).perform()
        self.assertEqual(
            self.to_unix_line_ending(sel.selected_content.strip()),
            '3\nuser can select')

        # The old second caret becomes the first caret. Drag it down again.
        self.actions.flick(body, caret2_x, caret2_y, end_caret2_x,
                           end_caret2_y).perform()
        self.assertEqual(
            self.to_unix_line_ending(sel.selected_content.strip()), 'this')
示例#3
0
    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')
示例#4
0
    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)
示例#5
0
    def test_handle_tilt_when_carets_overlap_each_other(self, el_id):
        '''Test tilt handling when carets overlap to each other.

        Let the two carets overlap each other. If they are set to tilted
        successfully, tapping the tilted carets should not cause the selection
        to be collapsed and the carets should be draggable.

        '''
        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 the first word.
        self.long_press_on_word(el, 0)
        target_content = sel.selected_content

        # Drag the first caret to the position of the second caret to trigger
        # carets overlapping.
        (caret1_x, caret1_y), (caret2_x, caret2_y) = sel.carets_location()
        self.actions.flick(el, caret1_x, caret1_y, caret2_x,
                           caret2_y).perform()

        # We make two hit tests targeting the left edge of the left tilted caret
        # and the right edge of the right tilted caret. If either of the hits is
        # missed, selection would be collapsed and both carets should not be
        # draggable.
        (caret3_x, caret3_y), (caret4_x, caret4_y) = sel.carets_location()

        # The following values are from ua.css and all.js
        caret_width = float(
            self.marionette.get_pref('layout.accessiblecaret.width'))
        caret_margin_left = float(
            self.marionette.get_pref('layout.accessiblecaret.margin-left'))
        tilt_right_margin_left = 0.41 * caret_width
        tilt_left_margin_left = -0.39 * caret_width

        left_caret_left_edge_x = caret3_x + caret_margin_left + tilt_left_margin_left
        el.tap(left_caret_left_edge_x + 2, caret3_y)

        right_caret_right_edge_x = (caret4_x + caret_margin_left +
                                    tilt_right_margin_left + caret_width)
        el.tap(right_caret_right_edge_x - 2, caret4_y)

        # Drag the first caret back to the initial selection, the first word.
        self.actions.flick(el, caret3_x, caret3_y, caret1_x,
                           caret1_y).perform()

        self.assertEqual(target_content, sel.selected_content)
示例#6
0
    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",
        )
示例#7
0
    def test_carets_not_jump_when_dragging_to_editable_content_boundary(
            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) >= 3, 'Expect at least three words in the content.')

        # Goal: the selection is not changed after dragging the caret on the
        # Y-axis.
        target_content = words[1]

        self.long_press_on_word(el, 1)
        (caret1_x, caret1_y), (caret2_x, caret2_y) = sel.carets_location()

        # Drag the first caret up by 40px.
        self.actions.flick(el, caret1_x, caret1_y, caret1_x,
                           caret1_y - 40).perform()
        self.assertEqual(target_content, sel.selected_content)

        # Drag the second caret down by 50px.
        self.actions.flick(el, caret2_x, caret2_y, caret2_x,
                           caret2_y + 50).perform()
        self.assertEqual(target_content, sel.selected_content)
示例#8
0
    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)
示例#9
0
    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
0
    def test_select_word_scroll_then_drag_caret(self):
        """Bug 1657256: Test select word, scroll page up , and then drag the second
        caret down to cover "EEEEEE".

        Note the selection should be extended to just cover "EEEEEE", not extend
        to other lines below "EEEEEE".

        """

        self.open_test_html(self._iframe_scroll_html)
        iframe = self.marionette.find_element(By.ID, "iframe")

        # Switch to the inner iframe.
        self.marionette.switch_to_frame(iframe)
        body = self.marionette.find_element(By.ID, "bd")
        sel = SelectionManager(body)

        # Select "EEEEEE" to get the y position of the second caret. This is the
        # y position we are going to drag the caret to.
        content2 = self.marionette.find_element(By.ID, self._content2_id)
        self.long_press_on_word(content2, 0)
        (_, _), (x, y2) = sel.carets_location()

        # Step 1: Select "DDDDDD".
        content = self.marionette.find_element(By.ID, self._content_id)
        self.long_press_on_word(content, 0)
        (_, _), (_, y1) = sel.carets_location()

        # The y-axis offset of the second caret needed to extend the selection.
        y_offset = y2 - y1

        # Step 2: Scroll the page upwards by 40px.
        scroll_offset = 40
        self.marionette.execute_script(
            "document.documentElement.scrollTop += arguments[0]",
            script_args=[scroll_offset],
        )

        # Step 3: Drag the second caret down.
        self.actions.flick(
            body, x, y1 - scroll_offset, x, y1 - scroll_offset + y_offset
        ).perform()

        self.assertEqual("DDDDDD EEEEEE", sel.selected_content)