Bug 1110917 - Add test cases for selectioncaret changes. r=automatedtester

This commit is contained in:
Jeremy Chen 2014-12-31 14:40:39 +08:00
parent 575dc3f7b7
commit a871d5973b

View File

@ -39,17 +39,32 @@ class SelectionCaretsTest(MarionetteTestCase):
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.
def _first_word_location(self, el):
'''Get the location (x, y) of the first word in el.
Note: this function has a side effect which changes focus to the
target element el.
'''
sel = SelectionManager(el)
# Move caret behind the first character to get the location of 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)
return sel.caret_location()
def _long_press_to_select(self, el, x, y):
'''Long press the location (x, y) to select a word.
SelectionCarets should appear. 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)
@ -59,7 +74,8 @@ class SelectionCaretsTest(MarionetteTestCase):
target_content = words[0]
# Goal: Select the first word.
self._long_press_to_select_first_word(el, sel)
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())
@ -79,7 +95,8 @@ class SelectionCaretsTest(MarionetteTestCase):
sel.select_all()
(_, _), (end_caret_x, end_caret_y) = sel.selection_carets_location()
self._long_press_to_select_first_word(el, sel)
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()
@ -91,7 +108,8 @@ class SelectionCaretsTest(MarionetteTestCase):
# 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):
def _test_minimum_select_one_character(self, el, assertFunc,
x=None, y=None):
sel = SelectionManager(el)
original_content = sel.content
words = original_content.split()
@ -100,7 +118,13 @@ class SelectionCaretsTest(MarionetteTestCase):
# Goal: Select the first character.
target_content = original_content[0]
self._long_press_to_select_first_word(el, sel)
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 position of the left caret.
(caret1_x, caret1_y), (caret2_x, caret2_y) = sel.selection_carets_location()
@ -108,6 +132,24 @@ class SelectionCaretsTest(MarionetteTestCase):
assertFunc(target_content, sel.selected_content)
def _test_focus_obtained_by_long_press(self, el1, el2):
'''Test the focus could be changed from el1 to el2 by long press.
If the focus is changed to e2 successfully, SelectionCarets should
appear and could be dragged.
'''
# Goal: Tap to focus el1, and then select the first character on
# el2.
# We want to collect the location of the first word in el2 here
# since self._first_word_location() has the side effect which would
# change the focus.
x, y = self._first_word_location(el2)
el1.tap()
self._test_minimum_select_one_character(el2, self.assertEqual,
x=x, y=y)
########################################################################
# <input> test cases with selection carets enabled
########################################################################
@ -123,6 +165,18 @@ class SelectionCaretsTest(MarionetteTestCase):
self.openTestHtml(enabled=True)
self._test_minimum_select_one_character(self._input, self.assertEqual)
def test_input_focus_obtained_by_long_press_from_textarea(self):
self.openTestHtml(enabled=True)
self._test_focus_obtained_by_long_press(self._textarea, self._input)
def test_input_focus_obtained_by_long_press_from_contenteditable(self):
self.openTestHtml(enabled=True)
self._test_focus_obtained_by_long_press(self._contenteditable, self._input)
def test_input_focus_obtained_by_long_press_from_content_non_editable(self):
self.openTestHtml(enabled=True)
self._test_focus_obtained_by_long_press(self._content, self._input)
########################################################################
# <input> test cases with selection carets disabled
########################################################################
@ -149,6 +203,18 @@ class SelectionCaretsTest(MarionetteTestCase):
self.openTestHtml(enabled=True)
self._test_minimum_select_one_character(self._textarea, self.assertEqual)
def test_textarea_focus_obtained_by_long_press_from_input(self):
self.openTestHtml(enabled=True)
self._test_focus_obtained_by_long_press(self._input, self._textarea)
def test_textarea_focus_obtained_by_long_press_from_contenteditable(self):
self.openTestHtml(enabled=True)
self._test_focus_obtained_by_long_press(self._contenteditable, self._textarea)
def test_textarea_focus_obtained_by_long_press_from_content_non_editable(self):
self.openTestHtml(enabled=True)
self._test_focus_obtained_by_long_press(self._content, self._textarea)
########################################################################
# <textarea> test cases with selection carets disabled
########################################################################
@ -201,6 +267,18 @@ class SelectionCaretsTest(MarionetteTestCase):
self.openTestHtml(enabled=True)
self._test_minimum_select_one_character(self._contenteditable, self.assertEqual)
def test_contenteditable_focus_obtained_by_long_press_from_input(self):
self.openTestHtml(enabled=True)
self._test_focus_obtained_by_long_press(self._input, self._contenteditable)
def test_contenteditable_focus_obtained_by_long_press_from_textarea(self):
self.openTestHtml(enabled=True)
self._test_focus_obtained_by_long_press(self._textarea, self._contenteditable)
def test_contenteditable_focus_obtained_by_long_press_from_content_non_editable(self):
self.openTestHtml(enabled=True)
self._test_focus_obtained_by_long_press(self._content, self._contenteditable)
########################################################################
# <div> contenteditable test cases with selection carets disabled
########################################################################
@ -218,3 +296,16 @@ class SelectionCaretsTest(MarionetteTestCase):
def test_content_non_editable_minimum_select_one_character_by_selection(self):
self.openTestHtml(enabled=True)
self._test_minimum_select_one_character(self._content, self.assertEqual)
def test_content_non_editable_focus_obtained_by_long_press_from_input(self):
self.openTestHtml(enabled=True)
self._test_focus_obtained_by_long_press(self._input, self._content)
def test_content_non_editable_focus_obtained_by_long_press_from_textarea(self):
self.openTestHtml(enabled=True)
self._test_focus_obtained_by_long_press(self._textarea, self._content)
def test_content_non_editable_focus_obtained_by_long_press_from_contenteditable(self):
self.openTestHtml(enabled=True)
self._test_focus_obtained_by_long_press(self._contenteditable, self._content)