Bug 1110039 - Part 5 - Reuse marionette tests for AccessibleCaret. r=roc

AccessibleCaret should behave like TouchCaret and SelectionCarets. I
refactor the setUp() to support both the old and new preferences.

Rename test_selectioncarets_multiplerange.py to test_selectioncarets2.py
since it now contains more than just multirange tests.

_test_handle_tilt_when_carets_overlap_to_each_other() is modified
because AccessibleCaret does not inflate the caret hit rectangle as
TouchCaret/SelectionCarets did. The point for tilt caret edges need to
shrink a bit.

In test_touchcaret.py, instead of setting _large_expiration_time, I just
disable caret timeout by default for every test. For those timeout
tests, use one second timeout to reduce test running time, and allow
1.5x margin to prevent intermittent failures.

Refine test case that move touch caret to front by using the real
position at the front rather than (0, 0).

Use skip_if_not_rotatable decorator for better log message.
This commit is contained in:
Ting-Yu Lin 2015-05-07 07:55:00 +02:00
parent b357b39811
commit 44c67fa21b
4 changed files with 268 additions and 142 deletions

View File

@ -13,4 +13,4 @@ skip = false
[test_touchcaret.py]
[test_selectioncarets.py]
[test_selectioncarets_multiplerange.py]
[test_selectioncarets2.py]

View File

@ -9,10 +9,14 @@ from marionette import MarionetteTestCase
from marionette_driver.selection import SelectionManager
from marionette_driver.gestures import long_press_without_contextmenu
from math import ceil, floor
class CommonCaretsTestCase(object):
'''Common test cases for a selection with a two carets.
class SelectionCaretsTest(MarionetteTestCase):
To run these test cases, a subclass must inherit from both this class and
MarionetteTestCase.
'''
_long_press_time = 1 # 1 second
_input_selector = (By.ID, 'input')
_textarea_selector = (By.ID, 'textarea')
@ -25,15 +29,41 @@ class SelectionCaretsTest(MarionetteTestCase):
def setUp(self):
# Code to execute before a tests are run.
MarionetteTestCase.setUp(self)
super(CommonCaretsTestCase, self).setUp()
self.actions = Actions(self.marionette)
def openTestHtml(self, enabled=True):
# The carets to be tested.
self.carets_tested_pref = None
# The carets to be disabled in this test suite.
self.carets_disabled_pref = None
def set_pref(self, pref_name, value):
'''Set a preference to value.
For example:
>>> set_pref('layout.accessiblecaret.enabled', True)
'''
pref_name = repr(pref_name)
if isinstance(value, bool):
value = 'true' if value else 'false'
elif isinstance(value, int):
value = str(value)
else:
value = repr(value)
script = '''SpecialPowers.pushPrefEnv({"set": [[%s, %s]]}, marionetteScriptFinished);''' % (
pref_name, value)
self.marionette.execute_async_script(script)
def open_test_html(self, enabled=True):
'''Open html for testing and locate elements, and enable/disable touch
caret.'''
self.marionette.execute_async_script(
'SpecialPowers.pushPrefEnv({"set": [["selectioncaret.enabled", %s]]}, marionetteScriptFinished);' %
('true' if enabled else 'false'))
self.set_pref(self.carets_tested_pref, enabled)
self.set_pref(self.carets_disabled_pref, False)
test_html = self.marionette.absolute_url('test_selectioncarets.html')
self.marionette.navigate(test_html)
@ -43,12 +73,11 @@ class SelectionCaretsTest(MarionetteTestCase):
self._contenteditable = self.marionette.find_element(*self._contenteditable_selector)
self._content = self.marionette.find_element(*self._content_selector)
def openTestHtml2(self, enabled=True):
def open_test_html2(self, enabled=True):
'''Open html for testing and locate elements, and enable/disable touch
caret.'''
self.marionette.execute_script(
'SpecialPowers.setBoolPref("selectioncaret.enabled", %s);' %
('true' if enabled else 'false'))
self.set_pref(self.carets_tested_pref, enabled)
self.set_pref(self.carets_disabled_pref, False)
test_html2 = self.marionette.absolute_url('test_selectioncarets_multipleline.html')
self.marionette.navigate(test_html2)
@ -214,11 +243,11 @@ class SelectionCaretsTest(MarionetteTestCase):
tilt_left_margin_left = -17
left_caret_left_edge_x = caret3_x + caret_margin_left + tilt_left_margin_left
el.tap(ceil(left_caret_left_edge_x), caret3_y)
el.tap(left_caret_left_edge_x + 2, caret3_y)
right_caret_right_edge_x = (caret4_x + caret_margin_left +
tilt_right_margin_left + caret_width)
el.tap(floor(right_caret_right_edge_x), caret4_y)
el.tap(right_caret_right_edge_x - 2, caret4_y)
# Drag the left caret back to the initial selection, the first word.
self.actions.flick(el, caret3_x, caret3_y, caret1_x, caret1_y).perform()
@ -229,202 +258,216 @@ class SelectionCaretsTest(MarionetteTestCase):
# <input> test cases with selection carets enabled
########################################################################
def test_input_long_press_to_select_a_word(self):
self.openTestHtml(enabled=True)
self.open_test_html()
self._test_long_press_to_select_a_word(self._input, self.assertEqual)
def test_input_move_selection_carets(self):
self.openTestHtml(enabled=True)
self.open_test_html()
self._test_move_selection_carets(self._input, self.assertEqual)
def test_input_minimum_select_one_character(self):
self.openTestHtml(enabled=True)
self.open_test_html()
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.open_test_html()
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.open_test_html()
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.open_test_html()
self._test_focus_obtained_by_long_press(self._content, self._input)
def test_input_handle_tilt_when_carets_overlap_to_each_other(self):
self.openTestHtml(enabled=True)
self.open_test_html()
self._test_handle_tilt_when_carets_overlap_to_each_other(self._input, self.assertEqual)
########################################################################
# <input> test cases with selection carets disabled
########################################################################
def test_input_long_press_to_select_a_word_disabled(self):
self.openTestHtml(enabled=False)
self.open_test_html(enabled=False)
self._test_long_press_to_select_a_word(self._input, self.assertNotEqual)
def test_input_move_selection_carets_disabled(self):
self.openTestHtml(enabled=False)
self.open_test_html(enabled=False)
self._test_move_selection_carets(self._input, self.assertNotEqual)
########################################################################
# <textarea> test cases with selection carets enabled
########################################################################
def test_textarea_long_press_to_select_a_word(self):
self.openTestHtml(enabled=True)
self.open_test_html()
self._test_long_press_to_select_a_word(self._textarea, self.assertEqual)
def test_textarea_move_selection_carets(self):
self.openTestHtml(enabled=True)
self.open_test_html()
self._test_move_selection_carets(self._textarea, self.assertEqual)
def test_textarea_minimum_select_one_character(self):
self.openTestHtml(enabled=True)
self.open_test_html()
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.open_test_html()
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.open_test_html()
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.open_test_html()
self._test_focus_obtained_by_long_press(self._content, self._textarea)
def test_textarea_handle_tilt_when_carets_overlap_to_each_other(self):
self.openTestHtml(enabled=True)
self.open_test_html()
self._test_handle_tilt_when_carets_overlap_to_each_other(self._textarea, self.assertEqual)
########################################################################
# <textarea> test cases with selection carets disabled
########################################################################
def test_textarea_long_press_to_select_a_word_disabled(self):
self.openTestHtml(enabled=False)
self.open_test_html(enabled=False)
self._test_long_press_to_select_a_word(self._textarea, self.assertNotEqual)
def test_textarea_move_selection_carets_disable(self):
self.openTestHtml(enabled=False)
self.open_test_html(enabled=False)
self._test_move_selection_carets(self._textarea, self.assertNotEqual)
########################################################################
# <textarea> right-to-left test cases with selection carets enabled
########################################################################
def test_textarea_rtl_long_press_to_select_a_word(self):
self.openTestHtml(enabled=True)
self.open_test_html()
self._test_long_press_to_select_a_word(self._textarea_rtl, self.assertEqual)
def test_textarea_rtl_move_selection_carets(self):
self.openTestHtml(enabled=True)
self.open_test_html()
self._test_move_selection_carets(self._textarea_rtl, self.assertEqual)
def test_textarea_rtl_minimum_select_one_character(self):
self.openTestHtml(enabled=True)
self.open_test_html()
self._test_minimum_select_one_character(self._textarea_rtl, self.assertEqual)
########################################################################
# <textarea> right-to-left test cases with selection carets disabled
########################################################################
def test_textarea_rtl_long_press_to_select_a_word_disabled(self):
self.openTestHtml(enabled=False)
self.open_test_html(enabled=False)
self._test_long_press_to_select_a_word(self._textarea_rtl, self.assertNotEqual)
def test_textarea_rtl_move_selection_carets_disabled(self):
self.openTestHtml(enabled=False)
self.open_test_html(enabled=False)
self._test_move_selection_carets(self._textarea_rtl, self.assertNotEqual)
########################################################################
# <div> contenteditable test cases with selection carets enabled
########################################################################
def test_contenteditable_long_press_to_select_a_word(self):
self.openTestHtml(enabled=True)
self.open_test_html()
self._test_long_press_to_select_a_word(self._contenteditable, self.assertEqual)
def test_contenteditable_move_selection_carets(self):
self.openTestHtml(enabled=True)
self.open_test_html()
self._test_move_selection_carets(self._contenteditable, self.assertEqual)
def test_contenteditable_minimum_select_one_character(self):
self.openTestHtml(enabled=True)
self.open_test_html()
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.open_test_html()
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.open_test_html()
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.open_test_html()
self._test_focus_obtained_by_long_press(self._content, self._contenteditable)
def test_contenteditable_handle_tilt_when_carets_overlap_to_each_other(self):
self.openTestHtml(enabled=True)
self.open_test_html()
self._test_handle_tilt_when_carets_overlap_to_each_other(self._contenteditable, self.assertEqual)
########################################################################
# <div> contenteditable test cases with selection carets disabled
########################################################################
def test_contenteditable_long_press_to_select_a_word_disabled(self):
self.openTestHtml(enabled=False)
self.open_test_html(enabled=False)
self._test_long_press_to_select_a_word(self._contenteditable, self.assertNotEqual)
def test_contenteditable_move_selection_carets_disabled(self):
self.openTestHtml(enabled=False)
self.open_test_html(enabled=False)
self._test_move_selection_carets(self._contenteditable, self.assertNotEqual)
########################################################################
# <div> non-editable test cases with selection carets enabled
########################################################################
def test_content_non_editable_long_press_to_select_a_word(self):
self.openTestHtml(enabled=True)
self.open_test_html()
self._test_long_press_to_select_a_word(self._content, self.assertEqual)
def test_content_non_editable_move_selection_carets(self):
self.openTestHtml(enabled=True)
self.open_test_html()
self._test_move_selection_carets(self._content, self.assertEqual)
def test_content_non_editable_minimum_select_one_character_by_selection(self):
self.openTestHtml(enabled=True)
self.open_test_html()
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.open_test_html()
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.open_test_html()
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.open_test_html()
self._test_focus_obtained_by_long_press(self._contenteditable, self._content)
def test_content_non_editable_handle_tilt_when_carets_overlap_to_each_other(self):
self.openTestHtml(enabled=True)
self.open_test_html()
self._test_handle_tilt_when_carets_overlap_to_each_other(self._content, self.assertEqual)
########################################################################
# <textarea> (multi-lines) test cases with selection carets enabled
########################################################################
def test_textarea2_minimum_select_one_character(self):
self.openTestHtml2(enabled=True)
self.open_test_html2()
self._test_minimum_select_one_character(self._textarea2, self.assertEqual)
########################################################################
# <div> contenteditable2 (multi-lines) test cases with selection carets enabled
########################################################################
def test_contenteditable2_minimum_select_one_character(self):
self.openTestHtml2(enabled=True)
self.open_test_html2()
self._test_minimum_select_one_character(self._contenteditable2, self.assertEqual)
########################################################################
# <div> non-editable2 (multi-lines) test cases with selection carets enabled
########################################################################
def test_content_non_editable2_minimum_select_one_character(self):
self.openTestHtml2(enabled=True)
self.open_test_html2()
self._test_minimum_select_one_character(self._content2, self.assertEqual)
class SelectionCaretsTestCase(CommonCaretsTestCase, MarionetteTestCase):
def setUp(self):
super(SelectionCaretsTestCase, self).setUp()
self.carets_tested_pref = 'selectioncaret.enabled'
self.carets_disabled_pref = 'layout.accessiblecaret.enabled'
class AccessibleCaretSelectionModeTestCase(CommonCaretsTestCase, MarionetteTestCase):
def setUp(self):
super(AccessibleCaretSelectionModeTestCase, self).setUp()
self.carets_tested_pref = 'layout.accessiblecaret.enabled'
self.carets_disabled_pref = 'selectioncaret.enabled'

View File

@ -5,12 +5,26 @@
from marionette_driver.by import By
from marionette_driver.marionette import Actions
from marionette import MarionetteTestCase
from marionette import MarionetteTestCase, SkipTest
from marionette_driver.selection import SelectionManager
from marionette_driver.gestures import long_press_without_contextmenu
class SelectionCaretsMultipleRangeTest(MarionetteTestCase):
def skip_if_not_rotatable(target):
def wrapper(self, *args, **kwargs):
if not self.marionette.session_capabilities.get('rotatable'):
raise SkipTest('skipping due to device not rotatable')
return target(self, *args, **kwargs)
return wrapper
class CommonCaretsTestCase2(object):
'''Common test cases for a selection with a two carets.
To run these test cases, a subclass must inherit from both this class and
MarionetteTestCase.
'''
_long_press_time = 1 # 1 second
def setUp(self):
@ -18,12 +32,36 @@ class SelectionCaretsMultipleRangeTest(MarionetteTestCase):
MarionetteTestCase.setUp(self)
self.actions = Actions(self.marionette)
def openTestHtml(self, enabled=True):
# Open html for testing and enable selectioncaret and
# non-editable support
self.marionette.execute_async_script(
'SpecialPowers.pushPrefEnv({"set": [["selectioncaret.enabled", %s],["selectioncaret.noneditable", %s]]}, marionetteScriptFinished);' %
( ('true' if enabled else 'false'), ('true' if enabled else 'false')))
# The carets to be tested.
self.carets_tested_pref = None
# The carets to be disabled in this test suite.
self.carets_disabled_pref = None
def set_pref(self, pref_name, value):
'''Set a preference to value.
For example:
>>> set_pref('layout.accessiblecaret.enabled', True)
'''
pref_name = repr(pref_name)
if isinstance(value, bool):
value = 'true' if value else 'false'
elif isinstance(value, int):
value = str(value)
else:
value = repr(value)
script = '''SpecialPowers.pushPrefEnv({"set": [[%s, %s]]}, marionetteScriptFinished);''' % (
pref_name, value)
self.marionette.execute_async_script(script)
def open_test_html(self, enabled=True):
'Open html for testing and enable selectioncaret and non-editable support'
self.set_pref(self.carets_tested_pref, enabled)
self.set_pref(self.carets_disabled_pref, False)
test_html = self.marionette.absolute_url('test_selectioncarets_multiplerange.html')
self.marionette.navigate(test_html)
@ -36,11 +74,10 @@ class SelectionCaretsMultipleRangeTest(MarionetteTestCase):
self._sel6 = self.marionette.find_element(By.ID, 'sel6')
self._nonsel1 = self.marionette.find_element(By.ID, 'nonsel1')
def openTestHtmlLongText(self, enabled=True):
# Open html for testing and enable selectioncaret
self.marionette.execute_script(
'SpecialPowers.setBoolPref("selectioncaret.enabled", %s);' %
('true' if enabled else 'false'))
def open_test_html_long_text(self, enabled=True):
'Open html for testing and enable selectioncaret'
self.set_pref(self.carets_tested_pref, enabled)
self.set_pref(self.carets_disabled_pref, False)
test_html = self.marionette.absolute_url('test_selectioncarets_longtext.html')
self.marionette.navigate(test_html)
@ -48,11 +85,10 @@ class SelectionCaretsMultipleRangeTest(MarionetteTestCase):
self._body = self.marionette.find_element(By.ID, 'bd')
self._longtext = self.marionette.find_element(By.ID, 'longtext')
def openTestHtmlIframe(self, enabled=True):
# Open html for testing and enable selectioncaret
self.marionette.execute_script(
'SpecialPowers.setBoolPref("selectioncaret.enabled", %s);' %
('true' if enabled else 'false'))
def open_test_html_iframe(self, enabled=True):
'Open html for testing and enable selectioncaret'
self.set_pref(self.carets_tested_pref, enabled)
self.set_pref(self.carets_disabled_pref, False)
test_html = self.marionette.absolute_url('test_selectioncarets_iframe.html')
self.marionette.navigate(test_html)
@ -91,7 +127,7 @@ class SelectionCaretsMultipleRangeTest(MarionetteTestCase):
'''Testing long press on non selectable field.
We should not select anything when long press on non selectable fields.'''
self.openTestHtml(enabled=True)
self.open_test_html()
halfY = self._nonsel1.size['height'] / 2
long_press_without_contextmenu(self.marionette, self._nonsel1, self._long_press_time, 0, halfY)
sel = SelectionManager(self._nonsel1)
@ -102,7 +138,7 @@ class SelectionCaretsMultipleRangeTest(MarionetteTestCase):
'''Testing drag caret over non selectable field.
So that the selected content should exclude non selectable field and
end selection caret should appear in last range's position.'''
self.openTestHtml(enabled=True)
self.open_test_html()
# Select target element and get target caret location
self._long_press_to_select_word(self._sel4, 3)
@ -136,7 +172,7 @@ class SelectionCaretsMultipleRangeTest(MarionetteTestCase):
'''Bug 1094056
Test caret visibility when caret is dragged to beginning of a line
'''
self.openTestHtml(enabled=True)
self.open_test_html()
# Select the first word in the second line
self._long_press_to_select_word(self._sel2, 0)
@ -155,15 +191,12 @@ class SelectionCaretsMultipleRangeTest(MarionetteTestCase):
self.assertEqual(self._to_unix_line_ending(sel.selected_content.strip()), '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.
'''
# Skip running test on non-rotatable device ex.desktop browser
if not self.marionette.session_capabilities['rotatable']:
return
self.openTestHtmlLongText(enabled=True)
self.open_test_html_long_text()
# Select word in portrait mode, then change to landscape mode
self.marionette.set_orientation('portrait')
@ -189,7 +222,7 @@ class SelectionCaretsMultipleRangeTest(MarionetteTestCase):
huge offset. If we use the right coordinate system, selection should
work. Otherwise, it would be hard to trigger select word.
'''
self.openTestHtmlIframe(enabled=True)
self.open_test_html_iframe()
# switch to inner iframe and scroll to the bottom
self.marionette.switch_to_frame(self._iframe)
@ -203,3 +236,17 @@ class SelectionCaretsMultipleRangeTest(MarionetteTestCase):
long_press_without_contextmenu(self.marionette, self._bottomtext, self._long_press_time)
self.assertNotEqual(self._to_unix_line_ending(sel.selected_content.strip()), '')
class SelectionCaretsTestCase2(CommonCaretsTestCase2, MarionetteTestCase):
def setUp(self):
super(SelectionCaretsTestCase2, self).setUp()
self.carets_tested_pref = 'selectioncaret.enabled'
self.carets_disabled_pref = 'layout.accessiblecaret.enabled'
class AccessibleCaretSelectionModeTestCase2(CommonCaretsTestCase2, MarionetteTestCase):
def setUp(self):
super(AccessibleCaretSelectionModeTestCase2, self).setUp()
self.carets_tested_pref = 'layout.accessiblecaret.enabled'
self.carets_disabled_pref = 'selectioncaret.enabled'

View File

@ -9,48 +9,62 @@ from marionette_driver.selection import SelectionManager
from marionette import MarionetteTestCase
class TouchCaretTest(MarionetteTestCase):
class CommonCaretTestCase(object):
'''Common test cases for a collapsed selection with a single caret.
To run these test cases, a subclass must inherit from both this class and
MarionetteTestCase.
'''
_input_selector = (By.ID, 'input')
_textarea_selector = (By.ID, 'textarea')
_contenteditable_selector = (By.ID, 'contenteditable')
_large_expiration_time = 3000 * 20 # 60 seconds
def setUp(self):
# Code to execute before a test is being run.
MarionetteTestCase.setUp(self)
super(CommonCaretTestCase, self).setUp()
self.actions = Actions(self.marionette)
self.original_expiration_time = self.expiration_time
def tearDown(self):
# Code to execute after a test is being run.
self.expiration_time = self.original_expiration_time
MarionetteTestCase.tearDown(self)
# The caret to be tested.
self.caret_tested_pref = None
@property
def expiration_time(self):
# The caret to be disabled in this test suite.
self.caret_disabled_pref = None
self.caret_timeout_ms_pref = None
def set_pref(self, pref_name, value):
'''Set a preference to value.
For example:
>>> set_pref('layout.accessiblecaret.enabled', True)
'''
pref_name = repr(pref_name)
if isinstance(value, bool):
value = 'true' if value else 'false'
elif isinstance(value, int):
value = str(value)
else:
value = repr(value)
script = '''SpecialPowers.pushPrefEnv({"set": [[%s, %s]]}, marionetteScriptFinished);''' % (
pref_name, value)
self.marionette.execute_async_script(script)
def timeout_ms(self):
'Return touch caret expiration time in milliseconds.'
return self.marionette.execute_script(
'return SpecialPowers.getIntPref("touchcaret.expiration.time");')
'return SpecialPowers.getIntPref("%s");' % self.caret_timeout_ms_pref)
@expiration_time.setter
def expiration_time(self, expiration_time):
'Set touch caret expiration time in milliseconds.'
self.marionette.execute_script(
'SpecialPowers.setIntPref("touchcaret.expiration.time", arguments[0]);',
script_args=[expiration_time])
def openTestHtml(self, enabled=True, expiration_time=None):
def open_test_html(self, enabled=True, timeout_ms=0):
'''Open html for testing and locate elements, enable/disable touch caret, and
set touch caret expiration time in milliseconds).
'''
self.marionette.execute_async_script(
'SpecialPowers.pushPrefEnv({"set": [["touchcaret.enabled", %s]]}, marionetteScriptFinished);' %
('true' if enabled else 'false'))
# Set a larger expiration time to avoid intermittent test failures.
if expiration_time is not None:
self.expiration_time = expiration_time
self.set_pref(self.caret_tested_pref, enabled)
self.set_pref(self.caret_disabled_pref, False)
self.set_pref(self.caret_timeout_ms_pref, timeout_ms)
test_html = self.marionette.absolute_url('test_touchcaret.html')
self.marionette.navigate(test_html)
@ -101,11 +115,16 @@ class TouchCaretTest(MarionetteTestCase):
el.send_keys(content_to_add)
assertFunc(target_content, sel.content)
def _test_move_caret_to_front_by_dragging_touch_caret_to_top_left_corner(self, el, assertFunc):
def _test_move_caret_to_front_by_dragging_touch_caret_to_front_of_content(self, el, assertFunc):
sel = SelectionManager(el)
content_to_add = '!'
target_content = content_to_add + sel.content
# Get touch caret location at the front.
el.tap()
sel.move_caret_to_front()
dest_x, dest_y = sel.touch_caret_location()
# Tap to make touch caret appear. Note: it's strange that when the caret
# is at the end, the rect of the caret in <textarea> cannot be obtained.
# A bug perhaps.
@ -113,10 +132,9 @@ class TouchCaretTest(MarionetteTestCase):
sel.move_caret_to_end()
sel.move_caret_by_offset(1, backward=True)
el.tap(*sel.caret_location())
# Move touch caret to the top-left corner of the input box.
src_x, src_y = sel.touch_caret_location()
dest_x, dest_y = 0, 0
# Move touch caret to the front of the input box.
self.actions.flick(el, src_x, src_y, dest_x, dest_y).perform()
el.send_keys(content_to_add)
@ -128,7 +146,10 @@ class TouchCaretTest(MarionetteTestCase):
non_target_content = content_to_add + sel.content
# Get touch caret expiration time in millisecond, and convert it to second.
timeout = self.expiration_time / 1000.0
timeout = self.timeout_ms() / 1000.0
# Set a 1.5x timeout margin to prevent intermittent test failures.
timeout *= 1.5
# Tap to make touch caret appear. Note: it's strange that when the caret
# is at the end, the rect of the caret in <textarea> cannot be obtained.
@ -178,105 +199,120 @@ class TouchCaretTest(MarionetteTestCase):
el.send_keys(content_to_add)
assertFunc(non_target_content, sel.content)
########################################################################
# <input> test cases with touch caret enabled
########################################################################
def test_input_move_caret_to_the_right_by_one_character(self):
self.openTestHtml(enabled=True, expiration_time=self._large_expiration_time)
self.open_test_html()
self._test_move_caret_to_the_right_by_one_character(self._input, self.assertEqual)
def test_input_move_caret_to_end_by_dragging_touch_caret_to_bottom_right_corner(self):
self.openTestHtml(enabled=True, expiration_time=self._large_expiration_time)
self.open_test_html()
self._test_move_caret_to_end_by_dragging_touch_caret_to_bottom_right_corner(self._input, self.assertEqual)
def test_input_move_caret_to_front_by_dragging_touch_caret_to_top_left_corner(self):
self.openTestHtml(enabled=True, expiration_time=self._large_expiration_time)
self._test_move_caret_to_front_by_dragging_touch_caret_to_top_left_corner(self._input, self.assertEqual)
self.open_test_html()
self._test_move_caret_to_front_by_dragging_touch_caret_to_front_of_content(self._input, self.assertEqual)
def test_input_touch_caret_timeout(self):
self.openTestHtml(enabled=True)
self.open_test_html(timeout_ms=1000)
self._test_touch_caret_timeout_by_dragging_it_to_top_left_corner_after_timout(self._input, self.assertNotEqual)
def test_input_touch_caret_hides_after_receiving_wheel_event(self):
self.openTestHtml(enabled=True, expiration_time=0)
self.open_test_html()
self._test_touch_caret_hides_after_receiving_wheel_event(self._input, self.assertNotEqual)
########################################################################
# <input> test cases with touch caret disabled
########################################################################
def test_input_move_caret_to_the_right_by_one_character_disabled(self):
self.openTestHtml(enabled=False)
self.open_test_html(enabled=False)
self._test_move_caret_to_the_right_by_one_character(self._input, self.assertNotEqual)
def test_input_move_caret_to_front_by_dragging_touch_caret_to_top_left_corner_disabled(self):
self.openTestHtml(enabled=False)
self._test_move_caret_to_front_by_dragging_touch_caret_to_top_left_corner(self._input, self.assertNotEqual)
self.open_test_html(enabled=False)
self._test_move_caret_to_front_by_dragging_touch_caret_to_front_of_content(self._input, self.assertNotEqual)
########################################################################
# <textarea> test cases with touch caret enabled
########################################################################
def test_textarea_move_caret_to_the_right_by_one_character(self):
self.openTestHtml(enabled=True, expiration_time=self._large_expiration_time)
self.open_test_html()
self._test_move_caret_to_the_right_by_one_character(self._textarea, self.assertEqual)
def test_textarea_move_caret_to_end_by_dragging_touch_caret_to_bottom_right_corner(self):
self.openTestHtml(enabled=True, expiration_time=self._large_expiration_time)
self.open_test_html()
self._test_move_caret_to_end_by_dragging_touch_caret_to_bottom_right_corner(self._textarea, self.assertEqual)
def test_textarea_move_caret_to_front_by_dragging_touch_caret_to_top_left_corner(self):
self.openTestHtml(enabled=True, expiration_time=self._large_expiration_time)
self._test_move_caret_to_front_by_dragging_touch_caret_to_top_left_corner(self._textarea, self.assertEqual)
self.open_test_html()
self._test_move_caret_to_front_by_dragging_touch_caret_to_front_of_content(self._textarea, self.assertEqual)
def test_textarea_touch_caret_timeout(self):
self.openTestHtml(enabled=True)
self.open_test_html(timeout_ms=1000)
self._test_touch_caret_timeout_by_dragging_it_to_top_left_corner_after_timout(self._textarea, self.assertNotEqual)
def test_textarea_touch_caret_hides_after_receiving_wheel_event(self):
self.openTestHtml(enabled=True, expiration_time=0)
self.open_test_html()
self._test_touch_caret_hides_after_receiving_wheel_event(self._textarea, self.assertNotEqual)
########################################################################
# <textarea> test cases with touch caret disabled
########################################################################
def test_textarea_move_caret_to_the_right_by_one_character_disabled(self):
self.openTestHtml(enabled=False)
self.open_test_html(enabled=False)
self._test_move_caret_to_the_right_by_one_character(self._textarea, self.assertNotEqual)
def test_textarea_move_caret_to_front_by_dragging_touch_caret_to_top_left_corner_disabled(self):
self.openTestHtml(enabled=False)
self._test_move_caret_to_front_by_dragging_touch_caret_to_top_left_corner(self._textarea, self.assertNotEqual)
self.open_test_html(enabled=False)
self._test_move_caret_to_front_by_dragging_touch_caret_to_front_of_content(self._textarea, self.assertNotEqual)
########################################################################
# <div> contenteditable test cases with touch caret enabled
########################################################################
def test_contenteditable_move_caret_to_the_right_by_one_character(self):
self.openTestHtml(enabled=True, expiration_time=self._large_expiration_time)
self.open_test_html()
self._test_move_caret_to_the_right_by_one_character(self._contenteditable, self.assertEqual)
def test_contenteditable_move_caret_to_end_by_dragging_touch_caret_to_bottom_right_corner(self):
self.openTestHtml(enabled=True, expiration_time=self._large_expiration_time)
self.open_test_html()
self._test_move_caret_to_end_by_dragging_touch_caret_to_bottom_right_corner(self._contenteditable, self.assertEqual)
def test_contenteditable_move_caret_to_front_by_dragging_touch_caret_to_top_left_corner(self):
self.openTestHtml(enabled=True, expiration_time=self._large_expiration_time)
self._test_move_caret_to_front_by_dragging_touch_caret_to_top_left_corner(self._contenteditable, self.assertEqual)
self.open_test_html()
self._test_move_caret_to_front_by_dragging_touch_caret_to_front_of_content(self._contenteditable, self.assertEqual)
def test_contenteditable_touch_caret_timeout(self):
self.openTestHtml(enabled=True)
self.open_test_html(timeout_ms=1000)
self._test_touch_caret_timeout_by_dragging_it_to_top_left_corner_after_timout(self._contenteditable, self.assertNotEqual)
def test_contenteditable_touch_caret_hides_after_receiving_wheel_event(self):
self.openTestHtml(enabled=True, expiration_time=0)
self.open_test_html()
self._test_touch_caret_hides_after_receiving_wheel_event(self._contenteditable, self.assertNotEqual)
########################################################################
# <div> contenteditable test cases with touch caret disabled
########################################################################
def test_contenteditable_move_caret_to_the_right_by_one_character_disabled(self):
self.openTestHtml(enabled=False)
self.open_test_html(enabled=False)
self._test_move_caret_to_the_right_by_one_character(self._contenteditable, self.assertNotEqual)
def test_contenteditable_move_caret_to_front_by_dragging_touch_caret_to_top_left_corner_disabled(self):
self.openTestHtml(enabled=False)
self._test_move_caret_to_front_by_dragging_touch_caret_to_top_left_corner(self._contenteditable, self.assertNotEqual)
self.open_test_html(enabled=False)
self._test_move_caret_to_front_by_dragging_touch_caret_to_front_of_content(self._contenteditable, self.assertNotEqual)
class TouchCaretTestCase(CommonCaretTestCase, MarionetteTestCase):
def setUp(self):
super(TouchCaretTestCase, self).setUp()
self.caret_tested_pref = 'touchcaret.enabled'
self.caret_disabled_pref = 'layout.accessiblecaret.enabled'
self.caret_timeout_ms_pref = 'touchcaret.expiration.time'
class AccessibleCaretCursorModeTestCase(CommonCaretTestCase, MarionetteTestCase):
def setUp(self):
super(AccessibleCaretCursorModeTestCase, self).setUp()
self.caret_tested_pref = 'layout.accessiblecaret.enabled'
self.caret_disabled_pref = 'touchcaret.enabled'
self.caret_timeout_ms_pref = 'layout.accessiblecaret.timeout_ms'