Bug 1324725 - Refactor test_typing.py to pass for Fennec. r=maja_zf a=test-only
authorHenrik Skupin <mail@hskupin.info>
Tue, 20 Dec 2016 13:42:44 +0100
changeset 353121 d6ae871ef73bb86575f072e2305d8b2eff2411d7
parent 353120 4543f401f05f833ede3c950e7d7037b87b1d5dfd
child 353122 c3f401e19160ed979541940f21ff70a111cc5972
push id6795
push userjlund@mozilla.com
push dateMon, 23 Jan 2017 14:19:46 +0000
treeherdermozilla-esr52@76101b503191 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmaja_zf, test-only
bugs1324725
milestone52.0a2
Bug 1324725 - Refactor test_typing.py to pass for Fennec. r=maja_zf a=test-only MozReview-Commit-ID: AQCMyq2ASGZ
testing/marionette/harness/marionette_harness/tests/unit/test_typing.py
--- a/testing/marionette/harness/marionette_harness/tests/unit/test_typing.py
+++ b/testing/marionette/harness/marionette_harness/tests/unit/test_typing.py
@@ -3,24 +3,69 @@
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 import urllib
 
 from marionette_driver.by import By
 from marionette_driver.errors import ElementNotVisibleException
 from marionette_driver.keys import Keys
 
-from marionette_harness import MarionetteTestCase
+from marionette_harness import MarionetteTestCase, skip_if_mobile
 
 
 def inline(doc):
     return "data:text/html;charset=utf-8,{}".format(urllib.quote(doc))
 
 
-class TestTyping(MarionetteTestCase):
+class TypingTestCase(MarionetteTestCase):
+
+    def setUp(self):
+        super(TypingTestCase, self).setUp()
+
+        if self.marionette.session_capabilities["platformName"] == "darwin":
+            self.mod_key = Keys.META
+        else:
+            self.mod_key = Keys.CONTROL
+
+
+class TestTypingChrome(TypingTestCase):
+
+    def setUp(self):
+        super(TestTypingChrome, self).setUp()
+        self.marionette.set_context("chrome")
+
+    @skip_if_mobile  # Interacting with chrome elements not available for Fennec
+    def test_cut_and_paste_shortcuts(self):
+        with self.marionette.using_context("content"):
+            test_html = self.marionette.absolute_url("javascriptPage.html")
+            self.marionette.navigate(test_html)
+
+            keyReporter = self.marionette.find_element(By.ID, "keyReporter")
+            self.assertEqual("", keyReporter.get_property("value"))
+            keyReporter.send_keys("zyxwvutsr")
+            self.assertEqual("zyxwvutsr", keyReporter.get_property("value"))
+
+            # select all and cut
+            keyReporter.send_keys(self.mod_key, "a")
+            keyReporter.send_keys(self.mod_key, "x")
+            self.assertEqual("", keyReporter.get_property("value"))
+
+        url_bar = self.marionette.find_element(By.ID, "urlbar")
+
+        # Clear contents first
+        url_bar.send_keys(self.mod_key, "a")
+        url_bar.send_keys(Keys.BACK_SPACE)
+        self.assertEqual("", url_bar.get_attribute("value"))
+
+        url_bar.send_keys(self.mod_key, "v")
+        self.assertEqual("zyxwvutsr", url_bar.get_property("value"))
+
+
+class TestTypingContent(TypingTestCase):
+
     def testShouldFireKeyPressEvents(self):
         test_html = self.marionette.absolute_url("javascriptPage.html")
         self.marionette.navigate(test_html)
         keyReporter = self.marionette.find_element(By.ID, "keyReporter")
         keyReporter.send_keys("a")
         result = self.marionette.find_element(By.ID, "result")
         self.assertTrue("press:" in result.text)
 
@@ -53,45 +98,31 @@ class TestTyping(MarionetteTestCase):
         test_html = self.marionette.absolute_url("javascriptPage.html")
         self.marionette.navigate(test_html)
 
         keyReporter = self.marionette.find_element(By.ID, "keyReporter")
         keyReporter.send_keys("ABC DEF")
         self.assertEqual("ABC DEF", keyReporter.get_property("value"))
 
     def testCutAndPasteShortcuts(self):
-        # test that modifier keys work via copy/paste shortcuts
-        if self.marionette.session_capabilities["platformName"] == "darwin":
-            mod_key = Keys.META
-        else:
-            mod_key = Keys.CONTROL
-
         test_html = self.marionette.absolute_url("javascriptPage.html")
         self.marionette.navigate(test_html)
 
         keyReporter = self.marionette.find_element(By.ID, "keyReporter")
         self.assertEqual("", keyReporter.get_property("value"))
         keyReporter.send_keys("zyxwvutsr")
         self.assertEqual("zyxwvutsr", keyReporter.get_property("value"))
 
         # select all and cut
-        keyReporter.send_keys(mod_key, "a")
-        keyReporter.send_keys(mod_key, "x")
+        keyReporter.send_keys(self.mod_key, "a")
+        keyReporter.send_keys(self.mod_key, "x")
         self.assertEqual("", keyReporter.get_property("value"))
 
-        with self.marionette.using_context("chrome"):
-            url_bar = self.marionette.find_element(By.ID, "urlbar")
-
-            # lear and paste
-            url_bar.send_keys(mod_key, "a")
-            url_bar.send_keys(Keys.BACK_SPACE)
-
-            self.assertEqual("", url_bar.get_attribute("value"))
-            url_bar.send_keys(mod_key, "v")
-            self.assertEqual("zyxwvutsr", url_bar.get_attribute("value"))
+        keyReporter.send_keys(self.mod_key, "v")
+        self.assertEqual("zyxwvutsr", keyReporter.get_property("value"))
 
     def testShouldBeAbleToTypeQuoteMarks(self):
         test_html = self.marionette.absolute_url("javascriptPage.html")
         self.marionette.navigate(test_html)
 
         keyReporter = self.marionette.find_element(By.ID, "keyReporter")
         keyReporter.send_keys("\"")
         self.assertEqual("\"", keyReporter.get_property("value"))
@@ -177,52 +208,55 @@ class TestTyping(MarionetteTestCase):
 
         element = self.marionette.find_element(By.ID, "keyPressArea")
         element.send_keys("I like cheese")
         result = self.marionette.find_element(By.ID, "result")
         #  Because the key down gets the result before the input element is
         #  filled, we're a letter short here
         self.assertEqual(result.text, "I like chees")
 
+    @skip_if_mobile  # Bug 1324752 - Arrow keys cannot be sent in Fennec
     def testShouldReportKeyCodeOfArrowKeysUpDownEvents(self):
         test_html = self.marionette.absolute_url("javascriptPage.html")
         self.marionette.navigate(test_html)
 
         result = self.marionette.find_element(By.ID, "result")
         element = self.marionette.find_element(By.ID, "keyReporter")
+
         element.send_keys(Keys.ARROW_DOWN)
-        self.assertTrue("down: 40" in result.text.strip())
-        self.assertTrue("up: 40" in result.text.strip())
+
+        self.assertIn("down: 40", result.text.strip())
+        self.assertIn("up: 40", result.text.strip())
 
         element.send_keys(Keys.ARROW_UP)
-        self.assertTrue("down: 38" in  result.text.strip())
-        self.assertTrue("up: 38" in result.text.strip())
+        self.assertIn("down: 38", result.text.strip())
+        self.assertIn("up: 38", result.text.strip())
 
         element.send_keys(Keys.ARROW_LEFT)
-        self.assertTrue("down: 37" in result.text.strip())
-        self.assertTrue("up: 37" in result.text.strip())
+        self.assertIn("down: 37", result.text.strip())
+        self.assertIn("up: 37", result.text.strip())
 
         element.send_keys(Keys.ARROW_RIGHT)
-        self.assertTrue("down: 39" in result.text.strip())
-        self.assertTrue("up: 39" in result.text.strip())
+        self.assertIn("down: 39", result.text.strip())
+        self.assertIn("up: 39", result.text.strip())
 
         #  And leave no rubbish/printable keys in the "keyReporter"
         self.assertEqual("", element.get_property("value"))
 
     """Disabled. Reenable in Bug 1068728
     def testNumericShiftKeys(self):
         test_html = self.marionette.absolute_url("javascriptPage.html")
         self.marionette.navigate(test_html)
 
         result = self.marionette.find_element(By.ID, "result")
         element = self.marionette.find_element(By.ID, "keyReporter")
         numericShiftsEtc = "~!@#$%^&*()_+{}:i\"<>?|END~"
         element.send_keys(numericShiftsEtc)
         self.assertEqual(numericShiftsEtc, element.get_property("value"))
-        self.assertTrue(" up: 16" in result.text.strip())
+        self.assertIn(" up: 16", result.text.strip())
     """
 
     def testLowerCaseAlphaKeys(self):
         test_html = self.marionette.absolute_url("javascriptPage.html")
         self.marionette.navigate(test_html)
 
         element = self.marionette.find_element(By.ID, "keyReporter")
         lowerAlphas = "abcdefghijklmnopqrstuvwxyz"
@@ -234,31 +268,31 @@ class TestTyping(MarionetteTestCase):
         test_html = self.marionette.absolute_url("javascriptPage.html")
         self.marionette.navigate(test_html)
 
         result = self.marionette.find_element(By.ID, "result")
         element = self.marionette.find_element(By.ID, "keyReporter")
         upperAlphas = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
         element.send_keys(upperAlphas)
         self.assertEqual(upperAlphas, element.get_property("value"))
-        self.assertTrue(" up: 16" in result.text.strip())
+        self.assertIn(" up: 16", result.text.strip())
     """
 
     """Disabled. Reenable in Bug 1068726
     def testAllPrintableKeys(self):
         test_html = self.marionette.absolute_url("javascriptPage.html")
         self.marionette.navigate(test_html)
 
         result = self.marionette.find_element(By.ID, "result")
         element = self.marionette.find_element(By.ID, "keyReporter")
         allPrintable = "!\"#$%&'()*+,-./0123456789:<=>?@ ABCDEFGHIJKLMNOPQRSTUVWXYZ [\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"
         element.send_keys(allPrintable)
 
         self.assertTrue(allPrintable, element.get_property("value"))
-        self.assertTrue(" up: 16" in result.text.strip())
+        self.assertIn(" up: 16", result.text.strip())
     """
 
     """Disabled. Reenable in Bug 1068733
     def testSpecialSpaceKeys(self):
         test_html = self.marionette.absolute_url("javascriptPage.html")
         self.marionette.navigate(test_html)
 
         element = self.marionette.find_element(By.ID, "keyReporter")