--- a/layout/base/tests/marionette/test_accessiblecaret_cursor_mode.py
+++ b/layout/base/tests/marionette/test_accessiblecaret_cursor_mode.py
@@ -15,41 +15,44 @@ from marionette_driver.selection import
class AccessibleCaretCursorModeTestCase(MarionetteTestCase):
'''Test cases for AccessibleCaret under cursor mode.
We call the blinking cursor (nsCaret) as cursor, and call AccessibleCaret as
caret for short.
'''
+ # Element IDs.
_input_id = 'input'
_textarea_id = 'textarea'
_contenteditable_id = 'contenteditable'
+ # Test html files.
+ _cursor_html = 'test_carets_cursor.html'
+
def setUp(self):
# Code to execute before every test is running.
super(AccessibleCaretCursorModeTestCase, self).setUp()
self.caret_tested_pref = 'layout.accessiblecaret.enabled'
self.caret_timeout_ms_pref = 'layout.accessiblecaret.timeout_ms'
self.prefs = {
self.caret_tested_pref: True,
self.caret_timeout_ms_pref: 0,
}
self.marionette.set_prefs(self.prefs)
self.actions = Actions(self.marionette)
- def open_test_html(self):
- test_html = self.marionette.absolute_url('test_carets_cursor.html')
- self.marionette.navigate(test_html)
+ def open_test_html(self, test_html):
+ self.marionette.navigate(self.marionette.absolute_url(test_html))
@parameterized(_input_id, el_id=_input_id)
@parameterized(_textarea_id, el_id=_textarea_id)
@parameterized(_contenteditable_id, el_id=_contenteditable_id)
def test_move_cursor_to_the_right_by_one_character(self, el_id):
- self.open_test_html()
+ self.open_test_html(self._cursor_html)
el = self.marionette.find_element(By.ID, el_id)
sel = SelectionManager(el)
content_to_add = '!'
target_content = sel.content
target_content = target_content[:1] + content_to_add + target_content[1:]
# Get first caret (x, y) at position 1 and 2.
el.tap()
@@ -68,17 +71,17 @@ class AccessibleCaretCursorModeTestCase(
self.actions.key_down(content_to_add).key_up(content_to_add).perform()
self.assertEqual(target_content, sel.content)
@parameterized(_input_id, el_id=_input_id)
@parameterized(_textarea_id, el_id=_textarea_id)
@parameterized(_contenteditable_id, el_id=_contenteditable_id)
def test_move_cursor_to_end_by_dragging_caret_to_bottom_right_corner(self, el_id):
- self.open_test_html()
+ self.open_test_html(self._cursor_html)
el = self.marionette.find_element(By.ID, el_id)
sel = SelectionManager(el)
content_to_add = '!'
target_content = sel.content + content_to_add
# Tap the front of the input to make first caret appear.
el.tap()
sel.move_cursor_to_front()
@@ -91,17 +94,17 @@ class AccessibleCaretCursorModeTestCase(
self.actions.key_down(content_to_add).key_up(content_to_add).perform()
self.assertEqual(target_content, sel.content)
@parameterized(_input_id, el_id=_input_id)
@parameterized(_textarea_id, el_id=_textarea_id)
@parameterized(_contenteditable_id, el_id=_contenteditable_id)
def test_move_cursor_to_front_by_dragging_caret_to_front(self, el_id):
- self.open_test_html()
+ self.open_test_html(self._cursor_html)
el = self.marionette.find_element(By.ID, el_id)
sel = SelectionManager(el)
content_to_add = '!'
target_content = content_to_add + sel.content
# Get first caret location at the front.
el.tap()
sel.move_cursor_to_front()
@@ -121,17 +124,17 @@ class AccessibleCaretCursorModeTestCase(
self.actions.key_down(content_to_add).key_up(content_to_add).perform()
self.assertEqual(target_content, sel.content)
@parameterized(_input_id, el_id=_input_id)
@parameterized(_textarea_id, el_id=_textarea_id)
@parameterized(_contenteditable_id, el_id=_contenteditable_id)
def test_dragging_caret_to_top_left_corner_after_timeout(self, el_id):
- self.open_test_html()
+ self.open_test_html(self._cursor_html)
el = self.marionette.find_element(By.ID, el_id)
sel = SelectionManager(el)
content_to_add = '!'
non_target_content = content_to_add + sel.content
# Set caret timeout to be 1 second.
timeout = 1
self.marionette.set_pref(self.caret_timeout_ms_pref, timeout * 1000)
@@ -152,17 +155,17 @@ class AccessibleCaretCursorModeTestCase(
src_x, src_y = sel.first_caret_location()
dest_x, dest_y = 0, 0
self.actions.wait(timeout).flick(el, src_x, src_y, dest_x, dest_y).perform()
self.actions.key_down(content_to_add).key_up(content_to_add).perform()
self.assertNotEqual(non_target_content, sel.content)
def test_caret_not_appear_when_typing_in_scrollable_content(self):
- self.open_test_html()
+ self.open_test_html(self._cursor_html)
el = self.marionette.find_element(By.ID, self._input_id)
sel = SelectionManager(el)
content_to_add = '!'
target_content = sel.content + string.ascii_letters + content_to_add
el.tap()
sel.move_cursor_to_end()
@@ -178,17 +181,17 @@ class AccessibleCaretCursorModeTestCase(
self.actions.flick(el, src_x, src_y, dest_x, dest_y).perform()
# The content should be inserted at the end of the <input>.
el.send_keys(content_to_add)
self.assertEqual(target_content, sel.content)
def test_caret_not_jump_when_dragging_to_editable_content_boundary(self):
- self.open_test_html()
+ self.open_test_html(self._cursor_html)
el = self.marionette.find_element(By.ID, self._input_id)
sel = SelectionManager(el)
content_to_add = '!'
non_target_content = sel.content + content_to_add
# Goal: the cursor position does not being changed after dragging the
# caret down on the Y-axis.
el.tap()
--- a/layout/base/tests/marionette/test_accessiblecaret_selection_mode.py
+++ b/layout/base/tests/marionette/test_accessiblecaret_selection_mode.py
@@ -18,49 +18,49 @@ def skip_if_not_rotatable(target):
if not self.marionette.session_capabilities.get('rotatable'):
raise SkipTest('skipping due to device not rotatable')
return target(self, *args, **kwargs)
return wrapper
class AccessibleCaretSelectionModeTestCase(MarionetteTestCase):
'''Test cases for AccessibleCaret under selection mode.'''
+ # Element IDs.
_input_id = 'input'
_textarea_id = 'textarea'
_textarea2_id = 'textarea2'
_textarea_rtl_id = 'textarea-rtl'
_contenteditable_id = 'contenteditable'
_contenteditable2_id = 'contenteditable2'
_content_id = 'content'
_content2_id = 'content2'
_non_selectable_id = 'non-selectable'
+ # Test html files.
+ _selection_html = 'test_carets_selection.html'
+ _multipleline_html = 'test_carets_multipleline.html'
+ _multiplerange_html = 'test_carets_multiplerange.html'
+ _longtext_html = 'test_carets_longtext.html'
+ _iframe_html = 'test_carets_iframe.html'
+ _display_none_html = 'test_carets_display_none.html'
+
def setUp(self):
# Code to execute before every test is running.
super(AccessibleCaretSelectionModeTestCase, self).setUp()
self.carets_tested_pref = 'layout.accessiblecaret.enabled'
self.prefs = {
'layout.word_select.eat_space_to_next_word': False,
'layout.accessiblecaret.use_long_tap_injector': False,
self.carets_tested_pref: True,
}
self.marionette.set_prefs(self.prefs)
self.actions = Actions(self.marionette)
- def open_test_html(self):
- test_html = self.marionette.absolute_url('test_carets_selection.html')
- self.marionette.navigate(test_html)
-
- def open_test_html2(self):
- test_html2 = self.marionette.absolute_url('test_carets_multipleline.html')
- self.marionette.navigate(test_html2)
-
- def open_test_html_multirange(self):
- test_html = self.marionette.absolute_url('test_carets_multiplerange.html')
- self.marionette.navigate(test_html)
+ def open_test_html(self, test_html):
+ self.marionette.navigate(self.marionette.absolute_url(test_html))
def word_offset(self, text, ordinal):
'Get the character offset of the ordinal-th word in text.'
tokens = re.split(r'(\S+)', text) # both words and spaces
spaces = tokens[0::2] # collect spaces at odd indices
words = tokens[1::2] # collect word at even indices
if ordinal >= len(words):
@@ -150,17 +150,17 @@ class AccessibleCaretSelectionModeTestCa
return s.replace('\r\n', '\n').replace('\r', '\n')
@parameterized(_input_id, el_id=_input_id)
@parameterized(_textarea_id, el_id=_textarea_id)
@parameterized(_textarea_rtl_id, el_id=_textarea_rtl_id)
@parameterized(_contenteditable_id, el_id=_contenteditable_id)
@parameterized(_content_id, el_id=_content_id)
def test_long_press_to_select_a_word(self, el_id):
- self.open_test_html()
+ self.open_test_html(self._selection_html)
el = self.marionette.find_element(By.ID, el_id)
self._test_long_press_to_select_a_word(el)
def _test_long_press_to_select_a_word(self, el):
sel = SelectionManager(el)
original_content = sel.content
words = original_content.split()
self.assertTrue(len(words) >= 2, 'Expect at least two words in the content.')
@@ -173,17 +173,17 @@ class AccessibleCaretSelectionModeTestCa
self.assertEqual(target_content, sel.selected_content)
@parameterized(_input_id, el_id=_input_id)
@parameterized(_textarea_id, el_id=_textarea_id)
@parameterized(_textarea_rtl_id, el_id=_textarea_rtl_id)
@parameterized(_contenteditable_id, el_id=_contenteditable_id)
@parameterized(_content_id, el_id=_content_id)
def test_drag_carets(self, el_id):
- self.open_test_html()
+ 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]):]
@@ -206,25 +206,25 @@ class AccessibleCaretSelectionModeTestCa
self.assertEqual(target_content, sel.selected_content)
@parameterized(_input_id, el_id=_input_id)
@parameterized(_textarea_id, el_id=_textarea_id)
@parameterized(_textarea_rtl_id, el_id=_textarea_rtl_id)
@parameterized(_contenteditable_id, el_id=_contenteditable_id)
@parameterized(_content_id, el_id=_content_id)
def test_minimum_select_one_character(self, el_id):
- self.open_test_html()
+ self.open_test_html(self._selection_html)
el = self.marionette.find_element(By.ID, el_id)
self._test_minimum_select_one_character(el)
@parameterized(_textarea2_id, el_id=_textarea2_id)
@parameterized(_contenteditable2_id, el_id=_contenteditable2_id)
@parameterized(_content2_id, el_id=_content2_id)
def test_minimum_select_one_character2(self, el_id):
- self.open_test_html2()
+ self.open_test_html(self._multipleline_html)
el = self.marionette.find_element(By.ID, el_id)
self._test_minimum_select_one_character(el)
def _test_minimum_select_one_character(self, el, 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.')
@@ -288,29 +288,29 @@ class AccessibleCaretSelectionModeTestCa
'''
# 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.word_location() has the side effect which would
# change the focus.
- self.open_test_html()
+ self.open_test_html(self._selection_html)
el1 = self.marionette.find_element(By.ID, el1_id)
el2 = self.marionette.find_element(By.ID, el2_id)
x, y = self.word_location(el2, 0)
el1.tap()
self._test_minimum_select_one_character(el2, x=x, y=y)
@parameterized(_input_id, el_id=_input_id)
@parameterized(_textarea_id, el_id=_textarea_id)
@parameterized(_textarea_rtl_id, el_id=_textarea_rtl_id)
@parameterized(_contenteditable_id, el_id=_contenteditable_id)
def test_focus_not_changed_by_long_press_on_non_selectable(self, el_id):
- self.open_test_html()
+ self.open_test_html(self._selection_html)
el = self.marionette.find_element(By.ID, el_id)
non_selectable = self.marionette.find_element(By.ID, self._non_selectable_id)
# Goal: Focus remains on the editable element el after long pressing on
# the non-selectable element.
sel = SelectionManager(el)
self.long_press_on_word(el, 0)
self.long_press_on_location(non_selectable)
@@ -325,17 +325,17 @@ class AccessibleCaretSelectionModeTestCa
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.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)
@@ -372,17 +372,17 @@ class AccessibleCaretSelectionModeTestCa
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_multirange()
+ 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)
@@ -410,17 +410,17 @@ class AccessibleCaretSelectionModeTestCa
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_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_multirange()
+ 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()
@@ -437,19 +437,17 @@ class AccessibleCaretSelectionModeTestCa
self.assertEqual(self.to_unix_line_ending(sel.selected_content), 'select')
@skip_if_not_rotatable
def test_caret_position_after_changing_orientation_of_device(self):
'''Bug 1094072
If positions of carets are updated correctly, they should be draggable.
'''
- test_html = self.marionette.absolute_url('test_carets_longtext.html')
- self.marionette.navigate(test_html)
-
+ self.open_test_html(self._longtext_html)
body = self.marionette.find_element(By.ID, 'bd')
longtext = self.marionette.find_element(By.ID, 'longtext')
# Select word in portrait mode, then change to landscape mode
self.marionette.set_orientation('portrait')
self.long_press_on_word(longtext, 12)
sel = SelectionManager(body)
(p_start_caret_x, p_start_caret_y), (p_end_caret_x, p_end_caret_y) = sel.carets_location()
@@ -468,18 +466,17 @@ class AccessibleCaretSelectionModeTestCa
def test_select_word_inside_an_iframe(self):
'''Bug 1088552
The scroll offset in iframe should be taken into consideration properly.
In this test, we scroll content in the iframe to the bottom to cause a
huge offset. If we use the right coordinate system, selection should
work. Otherwise, it would be hard to trigger select word.
'''
- test_html = self.marionette.absolute_url('test_carets_iframe.html')
- self.marionette.navigate(test_html)
+ self.open_test_html(self._iframe_html)
iframe = self.marionette.find_element(By.ID, 'frame')
# switch to inner iframe and scroll to the bottom
self.marionette.switch_to_frame(iframe)
self.marionette.execute_script(
'document.getElementById("bd").scrollTop += 999')
# long press to select bottom text
@@ -490,33 +487,32 @@ class AccessibleCaretSelectionModeTestCa
self.assertNotEqual(self.to_unix_line_ending(sel.selected_content), '')
def test_carets_initialized_in_display_none(self):
'''Test AccessibleCaretEventHub is properly initialized on a <html> with
display: none.
'''
- test_html = self.marionette.absolute_url('test_carets_display_none.html')
- self.marionette.navigate(test_html)
+ self.open_test_html(self._display_none_html)
html = self.marionette.find_element(By.ID, 'html')
content = self.marionette.find_element(By.ID, 'content')
# Remove 'display: none' from <html>
self.marionette.execute_script(
'arguments[0].style.display = "unset";',
script_args=[html]
)
# If AccessibleCaretEventHub is initialized successfully, select a word
# should work.
self._test_long_press_to_select_a_word(content)
def test_long_press_to_select_when_partial_visible_word_is_selected(self):
- self.open_test_html()
+ self.open_test_html(self._selection_html)
el = self.marionette.find_element(By.ID, self._input_id)
sel = SelectionManager(el)
# To successfully select the second word while the first word is being
# selected, use sufficient spaces between 'a' and 'b' to avoid the
# second caret covers on the second word.
original_content = 'aaaaaaaa bbbbbbbb'
el.clear()
@@ -542,17 +538,17 @@ class AccessibleCaretSelectionModeTestCa
# If the second carets 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)
def test_carets_do_not_jump_when_dragging_to_editable_content_boundary(self):
- self.open_test_html()
+ self.open_test_html(self._selection_html)
el = self.marionette.find_element(By.ID, self._input_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 does not being changed after dragging the caret
# on the Y-axis only.