Bug 1121335 - Add the testing of selectioncarets drag with multiple selection ranges, r=roc
--- a/layout/base/tests/marionette/test_selectioncarets.py
+++ b/layout/base/tests/marionette/test_selectioncarets.py
@@ -12,16 +12,17 @@ from gestures import long_press_without_
class SelectionCaretsTest(MarionetteTestCase):
_long_press_time = 1 # 1 second
_input_selector = (By.ID, 'input')
_textarea_selector = (By.ID, 'textarea')
_textarea_rtl_selector = (By.ID, 'textarea_rtl')
_contenteditable_selector = (By.ID, 'contenteditable')
_content_selector = (By.ID, 'content')
+ _contenteditable2_selector = (By.ID, 'contenteditable2')
def setUp(self):
# Code to execute before a tests are run.
MarionetteTestCase.setUp(self)
self.actions = Actions(self.marionette)
def openTestHtml(self, enabled=True):
'''Open html for testing and locate elements, and enable/disable touch
@@ -33,16 +34,17 @@ class SelectionCaretsTest(MarionetteTest
test_html = self.marionette.absolute_url('test_selectioncarets.html')
self.marionette.navigate(test_html)
self._input = self.marionette.find_element(*self._input_selector)
self._textarea = self.marionette.find_element(*self._textarea_selector)
self._textarea_rtl = self.marionette.find_element(*self._textarea_rtl_selector)
self._contenteditable = self.marionette.find_element(*self._contenteditable_selector)
self._content = self.marionette.find_element(*self._content_selector)
+ self._contenteditable2 = self.marionette.find_element(*self._contenteditable2_selector)
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.
'''
@@ -110,27 +112,37 @@ class SelectionCaretsTest(MarionetteTest
def _test_minimum_select_one_character(self, el, assertFunc,
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.')
+ # Get the location of the selection carets at the end of the content for
+ # later use.
+ sel.select_all()
+ (_, _), (end_caret_x, end_caret_y) = sel.selection_carets_location()
+ el.tap()
+
# Goal: Select the first character.
target_content = original_content[0]
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 end of the content.
+ (caret1_x, caret1_y), (caret2_x, caret2_y) = sel.selection_carets_location()
+ self.actions.flick(el, caret2_x, caret2_y, end_caret_x, end_caret_y).perform()
+
# 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, caret2_x, caret2_y, caret1_x, caret1_y,).perform()
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.
@@ -304,8 +316,16 @@ class SelectionCaretsTest(MarionetteTest
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)
+ ########################################################################
+ # <div> contenteditable2 test cases with selection carets enabled
+ ########################################################################
+ def test_contenteditable_minimum_select_one_character(self):
+ self.openTestHtml(enabled=True)
+ self._test_minimum_select_one_character(self._contenteditable2, self.assertEqual)
+
+
--- a/testing/marionette/client/marionette/www/test_selectioncarets.html
+++ b/testing/marionette/client/marionette/www/test_selectioncarets.html
@@ -4,20 +4,27 @@
<!DOCTYPE html>
<html id="html">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Bug 1019441: Marionette tests for selection carets</title>
</head>
<body>
+ <style>
+ *
+ {
+ -moz-user-select:none;
+ }
+ </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><textarea dir="rtl" id="textarea_rtl" rows="8" cols="8">موزيلا فيرفكس موزيلا فيرفكس</textarea></div>
<br />
- <div style="width: 10em; height: 4em; word-wrap: break-word; overflow: auto;" contenteditable="true" id="contenteditable">ABC DEF GHI</div>
+ <div style="width: 10em; height: 4em; word-wrap: break-word; overflow: auto; -moz-user-select:text" contenteditable="true" id="contenteditable">ABC DEF GHI</div>
<br />
- <div style="width: 10em; height: 4em; word-wrap: break-word; overflow: auto;" id="content">ABC DEF GHI</div>
+ <div style="width: 10em; height: 4em; word-wrap: break-word; overflow: auto; -moz-user-select:text" id="content">ABC DEF GHI</div>
<br />
+ <div style="width: 10em; height: 8em; overflow: auto; -moz-user-select:text" id="contenteditable2" contenteditable="true">First Line<br></br>Second Line<br></br>Third Line</div>
</body>
</html>