Bug 1136567 - Marionette test for selection carets' positions after changing orientation of device. r=Automatedtester
authorJeremy Chen <jichen@mozilla.com>
Sun, 01 Mar 2015 22:45:00 +0100
changeset 246965 d0f098500e79bf70536411e846a9df5b9ea38dbe
parent 246964 232e9f16ee88fb675ee4b5f26b2ba8faf1550f8f
child 246966 0749198699758ec92f5afe029f5188d914c9a5a3
push id884
push userdburns@mozilla.com
push dateTue, 03 Mar 2015 15:29:12 +0000
reviewersAutomatedtester
bugs1136567
milestone39.0a1
Bug 1136567 - Marionette test for selection carets' positions after changing orientation of device. r=Automatedtester
layout/base/tests/marionette/test_selectioncarets_multiplerange.py
testing/marionette/client/marionette/www/test_selectioncarets_longtext.html
--- a/layout/base/tests/marionette/test_selectioncarets_multiplerange.py
+++ b/layout/base/tests/marionette/test_selectioncarets_multiplerange.py
@@ -31,16 +31,29 @@ class SelectionCaretsMultipleRangeTest(M
         self._body = self.marionette.find_element(By.ID, 'bd')
         self._sel1 = self.marionette.find_element(By.ID, 'sel1')
         self._sel2 = self.marionette.find_element(By.ID, 'sel2')
         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 openTestHtml2(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'))
+
+        test_html2 = self.marionette.absolute_url('test_selectioncarets_longtext.html')
+        self.marionette.navigate(test_html2)
+
+        self._body2 = self.marionette.find_element(By.ID, 'bd2')
+        self._longtext = self.marionette.find_element(By.ID, 'longtext')
+
     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
@@ -120,8 +133,35 @@ class SelectionCaretsMultipleRangeTest(M
         # Drag end caret to the beginning of the second line
         (caret1_x, caret1_y), (caret2_x, caret2_y) = sel.selection_carets_location()
         self.actions.flick(self._body, caret2_x, caret2_y, start_caret_x, start_caret_y).perform()
 
         # Drag end caret back to the target word
         self.actions.flick(self._body, start_caret_x, start_caret_y, caret2_x, caret2_y).perform()
 
         self.assertEqual(self._to_unix_line_ending(sel.selected_content.strip()), 'select')
+
+    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.openTestHtml2(enabled=True)
+
+        # Select word in portrait mode, then change to landscape mode
+        self.marionette.set_orientation('portrait')
+        self._long_press_to_select_word(self._longtext, 12)
+        sel = SelectionManager(self._body2)
+        (p_start_caret_x, p_start_caret_y), (p_end_caret_x, p_end_caret_y) = sel.selection_carets_location()
+        self.marionette.set_orientation('landscape')
+        (l_start_caret_x, l_start_caret_y), (l_end_caret_x, l_end_caret_y) = sel.selection_carets_location()
+
+        # Drag end caret to the start caret to change the selected content
+        self.actions.flick(self._body2, l_end_caret_x, l_end_caret_y, l_start_caret_x, l_start_caret_y).perform()
+
+        # Change orientation back to portrait mode to prevent affecting
+        # other tests
+        self.marionette.set_orientation('portrait')
+
+        self.assertEqual(self._to_unix_line_ending(sel.selected_content.strip()), 'o')
new file mode 100644
--- /dev/null
+++ b/testing/marionette/client/marionette/www/test_selectioncarets_longtext.html
@@ -0,0 +1,8 @@
+<html>
+  <head>
+    <title>Bug 1094072: Orientation change test for selection carets positions</title>
+  </head>
+<body id=bd2>
+<h3 id=longtext>long long text for orientation change test long long text for orientation change test long long text for orientation change test long long text for orientation change test</h3>
+</body>
+</html>