mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-14 20:22:00 +00:00
Bug 1024848 - part 1 - Improve selection carets test cases. r=mdas
On Windows, when selecting a word by long pressing, extra spaces after the word will also be selected. To solve this problem, I redesign the test cases by comparing the target content with the selected content directly while ignoring spaces at certain test cases. I believe it's easier to understand and less error-prone than the old replace-selected-content-and-compare way. I added a new method SelectionManager.selected_content() to make it easier to get the current selected text.
This commit is contained in:
parent
80c167047f
commit
f6ddf353cd
@ -45,8 +45,9 @@ class SelectionCaretsTest(MarionetteTestCase):
|
||||
sel.move_caret_by_offset(1)
|
||||
x, y = sel.caret_location()
|
||||
|
||||
# Long press the caret position. Selection carets should appear, and
|
||||
# select the first word.
|
||||
# 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.
|
||||
self.actions.long_press(el, self._long_press_time, x, y).perform()
|
||||
|
||||
def _test_long_press_to_select_a_word(self, el, assertFunc):
|
||||
@ -54,16 +55,13 @@ class SelectionCaretsTest(MarionetteTestCase):
|
||||
original_content = sel.content
|
||||
words = original_content.split()
|
||||
self.assertTrue(len(words) >= 2, 'Expect at least two words in the content.')
|
||||
target_content = words[0]
|
||||
|
||||
# Goal: Replace the first word with '!'
|
||||
content_to_add = '!'
|
||||
target_content = original_content.replace(words[0], content_to_add, 1)
|
||||
|
||||
# Goal: Select the first word.
|
||||
self._long_press_to_select_first_word(el, sel)
|
||||
|
||||
# Replace the first word.
|
||||
el.send_keys(content_to_add)
|
||||
assertFunc(target_content, sel.content)
|
||||
# Ignore extra spaces selected after the word.
|
||||
assertFunc(target_content, sel.selected_content.rstrip())
|
||||
|
||||
def _test_move_selection_carets(self, el, assertFunc):
|
||||
sel = SelectionManager(el)
|
||||
@ -71,9 +69,8 @@ class SelectionCaretsTest(MarionetteTestCase):
|
||||
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
|
||||
# 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.
|
||||
@ -90,8 +87,8 @@ class SelectionCaretsTest(MarionetteTestCase):
|
||||
# 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)
|
||||
# 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):
|
||||
sel = SelectionManager(el)
|
||||
@ -99,38 +96,16 @@ class SelectionCaretsTest(MarionetteTestCase):
|
||||
words = original_content.split()
|
||||
self.assertTrue(len(words) >= 1, 'Expect at least one word in the content.')
|
||||
|
||||
# Goal: Replace last character of the first word with '!'
|
||||
content_to_add = '!'
|
||||
new_word = words[0][:-1] + content_to_add
|
||||
target_content = original_content.replace(words[0], new_word, 1)
|
||||
# Goal: Select the first character.
|
||||
target_content = original_content[0]
|
||||
|
||||
self._long_press_to_select_first_word(el, sel)
|
||||
|
||||
# Move the left caret to the position of right caret.
|
||||
# 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, caret1_x, caret1_y, caret2_x, caret2_y,).perform()
|
||||
self.actions.flick(el, caret2_x, caret2_y, caret1_x, caret1_y,).perform()
|
||||
|
||||
# Expect to replace the last character of the first word.
|
||||
el.send_keys(content_to_add)
|
||||
assertFunc(target_content, sel.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)
|
||||
assertFunc(target_content, sel.selected_content)
|
||||
|
||||
########################################################################
|
||||
# <input> test cases with selection carets enabled
|
||||
@ -239,6 +214,7 @@ class SelectionCaretsTest(MarionetteTestCase):
|
||||
########################################################################
|
||||
# <div> non-editable test cases with selection carets enabled
|
||||
########################################################################
|
||||
# def test_content_non_editable_minimum_select_one_character_by_selection(self):
|
||||
# self.openTestHtml(enabled=True)
|
||||
# self._test_minimum_select_one_character_by_selection(self._content, self.assertFalse)
|
||||
def test_content_non_editable_minimum_select_one_character_by_selection(self):
|
||||
self.openTestHtml(enabled=True)
|
||||
# Currently, selection carets do not show on non-editable elements.
|
||||
self._test_minimum_select_one_character(self._content, self.assertNotEqual)
|
||||
|
@ -186,3 +186,10 @@ class SelectionManager(object):
|
||||
return self.element.get_attribute('value')
|
||||
else:
|
||||
return self.element.text
|
||||
|
||||
@property
|
||||
def selected_content(self):
|
||||
'''Return the selected portion of the content in the element.'''
|
||||
cmd = self.js_selection_cmd() +\
|
||||
'''return sel.toString();'''
|
||||
return self.element.marionette.execute_script(cmd, script_args=[self.element])
|
||||
|
Loading…
x
Reference in New Issue
Block a user