Bug 1251519 Part 4 - Add tests for dragging caret to content boundary. r?mats
These tests should fail without Part 5.
MozReview-Commit-ID: 2FAW02tusCg
--- a/layout/base/tests/marionette/test_accessiblecaret_cursor_mode.py
+++ b/layout/base/tests/marionette/test_accessiblecaret_cursor_mode.py
@@ -17,17 +17,19 @@ class AccessibleCaretCursorModeTestCase(
'''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'
+ _input_padding_id = 'input-padding'
_textarea_id = 'textarea'
+ _textarea_one_line_id = 'textarea-one-line'
_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()
@@ -180,35 +182,63 @@ class AccessibleCaretCursorModeTestCase(
dest_x, dest_y = 0, 0
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):
+ @parameterized(_input_id, el_id=_input_id)
+ @parameterized(_input_padding_id, el_id=_input_padding_id)
+ @parameterized(_textarea_one_line_id, el_id=_textarea_one_line_id)
+ @parameterized(_contenteditable_id, el_id=_contenteditable_id)
+ def test_caret_not_jump_when_dragging_to_editable_content_boundary(self, el_id):
self.open_test_html(self._cursor_html)
- el = self.marionette.find_element(By.ID, self._input_id)
+ el = self.marionette.find_element(By.ID, el_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.
+ # Goal: the cursor position is not changed after dragging the caret down
+ # on the Y-axis.
el.tap()
sel.move_cursor_to_front()
el.tap(*sel.cursor_location())
x, y = sel.first_caret_location()
# Drag the caret down by 50px, and insert '!'.
self.actions.flick(el, x, y, x, y + 50).perform()
self.actions.key_down(content_to_add).key_up(content_to_add).perform()
self.assertNotEqual(non_target_content, sel.content)
+ @parameterized(_input_id, el_id=_input_id)
+ @parameterized(_input_padding_id, el_id=_input_padding_id)
+ @parameterized(_textarea_one_line_id, el_id=_textarea_one_line_id)
+ @parameterized(_contenteditable_id, el_id=_contenteditable_id)
+ def test_caret_not_jump_to_front_when_dragging_up_to_editable_content_boundary(self, el_id):
+ 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
+
+ # Goal: the cursor position is not changed after dragging the caret down
+ # on the Y-axis.
+ el.tap()
+ sel.move_cursor_to_end()
+ sel.move_cursor_by_offset(1, backward=True)
+ el.tap(*sel.cursor_location())
+ x, y = sel.first_caret_location()
+
+ # Drag the caret up by 50px, and insert '!'.
+ self.actions.flick(el, x, y, x, y - 50).perform()
+ self.actions.key_down(content_to_add).key_up(content_to_add).perform()
+ self.assertNotEqual(non_target_content, sel.content)
+
def test_drag_caret_from_front_to_end_across_columns(self):
self.open_test_html('test_carets_columns.html')
el = self.marionette.find_element(By.ID, 'columns-inner')
sel = SelectionManager(el)
content_to_add = '!'
target_content = sel.content + content_to_add
# Goal: the cursor position can be changed by dragging the caret from
--- a/layout/base/tests/marionette/test_accessiblecaret_selection_mode.py
+++ b/layout/base/tests/marionette/test_accessiblecaret_selection_mode.py
@@ -20,18 +20,20 @@ def skip_if_not_rotatable(target):
return target(self, *args, **kwargs)
return wrapper
class AccessibleCaretSelectionModeTestCase(MarionetteTestCase):
'''Test cases for AccessibleCaret under selection mode.'''
# Element IDs.
_input_id = 'input'
+ _input_padding_id = 'input-padding'
_textarea_id = 'textarea'
_textarea2_id = 'textarea2'
+ _textarea_one_line_id = 'textarea-one-line'
_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.
@@ -537,30 +539,34 @@ 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):
+ @parameterized(_input_id, el_id=_input_id)
+ @parameterized(_input_padding_id, el_id=_input_padding_id)
+ @parameterized(_textarea_one_line_id, el_id=_textarea_one_line_id)
+ @parameterized(_contenteditable_id, el_id=_contenteditable_id)
+ 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, self._input_id)
+ 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 does not being changed after dragging the caret
- # on the Y-axis only.
+ # 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 50px.
self.actions.flick(el, caret1_x, caret1_y, caret1_x, caret1_y - 50).perform()
self.assertEqual(target_content, sel.selected_content)
- # Drag the first caret down by 50px.
+ # 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)
--- a/testing/marionette/harness/marionette/www/test_carets_cursor.html
+++ b/testing/marionette/harness/marionette/www/test_carets_cursor.html
@@ -11,15 +11,21 @@
width: 10em;
height: 6em;
word-wrap: break-word;
overflow: auto;
}
</style>
</head>
<body>
- <div><input id="input" value="ABCDEFGHI"></div>
+ <div>
+ <input id="input" value="ABCDEFGHI">
+ <input id="input-padding" style="padding: 1em;" value="ABCDEFGHI">
+ </div>
<br>
- <div><textarea name="textarea" id="textarea" rows="4" cols="6">ABCDEFGHI</textarea></div>
+ <div>
+ <textarea name="textarea" id="textarea" rows="4" cols="6">ABCDEFGHI</textarea>
+ <textarea id="textarea-one-line" rows="3">ABCDEFGHI</textarea>
+ </div>
<br>
<div class="block" contenteditable="true" id="contenteditable">ABCDEFGHI</div>
</body>
</html>
--- a/testing/marionette/harness/marionette/www/test_carets_selection.html
+++ b/testing/marionette/harness/marionette/www/test_carets_selection.html
@@ -2,31 +2,37 @@
- License, v. 2.0. If a copy of the MPL was not distributed with this
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
<!DOCTYPE html>
<html id="html">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Marionette tests for AccessibleCaret in selection mode</title>
+ <style>
+ .block {
+ width: 10em;
+ height: 4em;
+ word-wrap: break-word;
+ overflow: auto;
+ }
+ </style>
</head>
<body>
- <style>
- div.block {
- width: 10em;
- height: 4em;
- word-wrap: break-word;
- overflow: auto;
- }
- </style>
- <div><input id="input" value="ABC DEF GHI"></div>
- <br />
- <div><textarea id="textarea" rows="4" cols="8">ABC DEF GHI JKL MNO PQR</textarea></div>
- <br />
+ <div>
+ <input id="input" value="ABC DEF GHI">
+ <input id="input-padding" style="padding: 1em;" value="ABC DEF GHI">
+ </div>
+ <br>
+ <div>
+ <textarea id="textarea" rows="4" cols="8">ABC DEF GHI JKL MNO PQR</textarea>
+ <textarea id="textarea-one-line" rows="4" cols="12">ABC DEF GHI</textarea>
+ </div>
+ <br>
<div><textarea dir="rtl" id="textarea-rtl" rows="8" cols="8">موزيلا فيرفكس موزيلا فيرفكس</textarea></div>
- <br />
+ <br>
<div class="block" contenteditable="true" id="contenteditable">ABC DEF GHI</div>
- <br />
+ <br>
<div class="block" id="content">ABC DEF GHI</div>
- <br />
+ <br>
<div style="-moz-user-select: none;" id="non-selectable">Non-selectable</div>
</body>
</html>