Bug 1074736 - Marionette test for selection carets with multiple range support. r=mdas
☠☠ backed out by e17c9722713b ☠ ☠
authorMorris Tseng <mtseng@mozilla.com>
Sun, 26 Oct 2014 20:47:00 +0100
changeset 212427 94c5f5317e4b47ef41b56f4e97e8d2a43f402dde
parent 212426 f43962d6b41e828c4da1bba7dc48575c26de4987
child 212428 bf825ec5f56b641338d248ca14ead00d73284715
push id27710
push usercbook@mozilla.com
push dateMon, 27 Oct 2014 14:52:01 +0000
treeherdermozilla-central@d65d20dc0ac2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmdas
bugs1074736
milestone36.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1074736 - Marionette test for selection carets with multiple range support. r=mdas
layout/base/tests/marionette/manifest.ini
layout/base/tests/marionette/test_selectioncarets_multiplerange.py
testing/marionette/client/marionette/www/test_selectioncarets_multiplerange.html
--- a/layout/base/tests/marionette/manifest.ini
+++ b/layout/base/tests/marionette/manifest.ini
@@ -8,8 +8,9 @@ browser = true
 ; true if the test is compatible with b2g, otherwise false
 b2g = true
 
 ; true if the test should be skipped
 skip = false
 
 [test_touchcaret.py]
 [test_selectioncarets.py]
+[test_selectioncarets_multiplerange.py]
new file mode 100644
--- /dev/null
+++ b/layout/base/tests/marionette/test_selectioncarets_multiplerange.py
@@ -0,0 +1,108 @@
+# -*- coding: utf-8 -*-
+# This Source Code Form is subject to the terms of the Mozilla Public
+# 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/.
+
+from by import By
+from marionette import Actions
+from marionette_test import MarionetteTestCase
+from selection import SelectionManager
+
+
+class SelectionCaretsMultipleRangeTest(MarionetteTestCase):
+    _long_press_time = 1        # 1 second
+
+    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 enable selectioncaret and
+        # non-editable support
+        self.marionette.execute_script(
+            'SpecialPowers.setBoolPref("selectioncaret.enabled", %s);' %
+            ('true' if enabled else 'false'))
+        self.marionette.execute_script(
+            'SpecialPowers.setBoolPref("selectioncaret.noneditable", %s);' %
+            ('true' if enabled else 'false'))
+
+        test_html = self.marionette.absolute_url('test_selectioncarets_multiplerange.html')
+        self.marionette.navigate(test_html)
+
+        self._body = self.marionette.find_element(By.ID, 'bd')
+        self._sel3 = self.marionette.find_element(By.ID, 'sel3')
+        self._sel4 = self.marionette.find_element(By.ID, 'sel4')
+        self._sel6 = self.marionette.find_element(By.ID, 'sel6')
+        self._nonsel1 = self.marionette.find_element(By.ID, 'nonsel1')
+
+    def _long_press_without_contextmenu(self, el, x, y):
+        return self.actions.press(el, x, y).move_by_offset(0, 0).\
+            wait(self._long_press_time).release()
+
+    def _long_press_to_select_word(self, el, wordOrdinal):
+        sel = SelectionManager(el)
+        original_content = sel.content
+        words = original_content.split()
+        self.assertTrue(wordOrdinal < len(words),
+            'Expect at least %d words in the content.' % wordOrdinal)
+
+        # Calc offset
+        offset = 0
+        for i in range(wordOrdinal):
+            offset += (len(words[i]) + 1)
+
+        # Move caret inside the word.
+        el.tap()
+        sel.move_caret_to_front()
+        sel.move_caret_by_offset(offset)
+        x, y = sel.caret_location()
+
+        # Long press the caret position. Selection carets should appear, and the
+        # word will be selected. On Windows, those spaces after the word
+        # will also be selected.
+        self._long_press_without_contextmenu(el, x, y).perform()
+
+    def _to_unix_line_ending(self, s):
+        """Changes all Windows/Mac line endings in s to UNIX line endings."""
+
+        return s.replace('\r\n', '\n').replace('\r', '\n')
+
+    def test_long_press_to_select_non_selectable_word(self):
+        '''Testing long press on non selectable field.
+        We should not select anything when long press on non selectable fields.'''
+
+        self.openTestHtml(enabled=True)
+        halfY = self._nonsel1.size['height'] / 2
+        self._long_press_without_contextmenu(self._nonsel1, 0, halfY).perform()
+        sel = SelectionManager(self._nonsel1)
+        range_count = sel.range_count()
+        self.assertEqual(range_count, 0)
+
+    def test_drag_caret_over_non_selectable_field(self):
+        '''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)
+
+        # Select target element and get target caret location
+        self._long_press_to_select_word(self._sel4, 3)
+        sel = SelectionManager(self._body)
+        (_, _), (end_caret_x, end_caret_y) = sel.selection_carets_location()
+
+        self._long_press_to_select_word(self._sel6, 0)
+        (_, _), (end_caret2_x, end_caret2_y) = sel.selection_carets_location()
+
+        # Select start element
+        self._long_press_to_select_word(self._sel3, 3)
+
+        # Drag end caret to target location
+        (caret1_x, caret1_y), (caret2_x, caret2_y) = sel.selection_carets_location()
+        self.actions.flick(self._body, caret2_x, caret2_y, end_caret_x, end_caret_y).perform()
+        self.assertEqual(self._to_unix_line_ending(sel.selected_content.strip()),
+            'this 3\nuser can select this')
+
+        (caret1_x, caret1_y), (caret2_x, caret2_y) = sel.selection_carets_location()
+        self.actions.flick(self._body, caret2_x, caret2_y, end_caret2_x, end_caret2_y).perform()
+        self.assertEqual(self._to_unix_line_ending(sel.selected_content.strip()),
+            'this 3\nuser can select this 4\nuser can select this 5\nuser')
new file mode 100644
--- /dev/null
+++ b/testing/marionette/client/marionette/www/test_selectioncarets_multiplerange.html
@@ -0,0 +1,19 @@
+<html>
+<style>
+h4 {
+  -moz-user-select: none;
+}
+</style>
+<body id=bd>
+<h3 id=sel1>user can select this 1</h3>
+<h3 id=sel2>user can select this 2</h3>
+<h3 id=sel3>user can select this 3</h3>
+<h4 id=nonsel1>user cannot select this 1</h4>
+<h4 id=nonsel2>user cannot select this 2</h4>
+<h3 id=sel4>user can select this 4</h3>
+<h3 id=sel5>user can select this 5</h3>
+<h4 id=nonsel3>user cannot select this 3</h4>
+<h3 id=sel6>user can select this 6</h3>
+<h3 id=sel7>user can select this 7</h3>
+</body>
+</html>