Bug 1529938 - [marionette] Tests for screen orientation change have to wait for the change happened. r=gbrown
authorHenrik Skupin <mail@hskupin.info>
Tue, 05 Mar 2019 20:18:22 +0000
changeset 520339 0f848b99ad5781599b50563b364019d8ed1ecc1f
parent 520338 9810f4da2d88a07351cc8b4689539daa0473f52a
child 520340 cdafab7858451738ce6f5d6b6fb4c2ce937a443d
push id10862
push userffxbld-merge
push dateMon, 11 Mar 2019 13:01:11 +0000
treeherdermozilla-beta@a2e7f5c935da [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgbrown
bugs1529938
milestone67.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 1529938 - [marionette] Tests for screen orientation change have to wait for the change happened. r=gbrown Differential Revision: https://phabricator.services.mozilla.com/D22156
testing/marionette/harness/marionette_harness/tests/unit/test_screen_orientation.py
--- a/testing/marionette/harness/marionette_harness/tests/unit/test_screen_orientation.py
+++ b/testing/marionette/harness/marionette_harness/tests/unit/test_screen_orientation.py
@@ -1,88 +1,81 @@
 # 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 __future__ import absolute_import
 
 from marionette_driver import errors
-from mozrunner.devices.emulator_screen import EmulatorScreen
-
-from marionette_harness import MarionetteTestCase, skip_if_desktop, skip_if_mobile
+from marionette_driver.wait import Wait
+from marionette_harness import (
+    MarionetteTestCase,
+    parameterized,
+    skip_if_desktop,
+    skip_if_mobile,
+)
 
 
 default_orientation = "portrait-primary"
 unknown_orientation = "Unknown screen orientation: {}"
 
 
 class TestScreenOrientation(MarionetteTestCase):
+
     def setUp(self):
         MarionetteTestCase.setUp(self)
         self.is_mobile = self.marionette.session_capabilities.get("rotatable", False)
 
     def tearDown(self):
         if self.is_mobile:
             self.marionette.set_orientation(default_orientation)
-            self.assertEqual(self.marionette.orientation, default_orientation, "invalid state")
+            self.wait_for_orientation(default_orientation)
         MarionetteTestCase.tearDown(self)
 
-    @skip_if_desktop("Not supported in Firefox")
-    def test_set_orientation_to_portrait_primary(self):
-        self.marionette.set_orientation("portrait-primary")
-        new_orientation = self.marionette.orientation
-        self.assertEqual(new_orientation, "portrait-primary")
+    def wait_for_orientation(self, orientation, timeout=None):
+        Wait(self.marionette, timeout=timeout).until(
+            lambda _: self.marionette.orientation == orientation)
 
     @skip_if_desktop("Not supported in Firefox")
-    def test_set_orientation_to_landscape_primary(self):
-        self.marionette.set_orientation("landscape-primary")
-        new_orientation = self.marionette.orientation
-        self.assertEqual(new_orientation, "landscape-primary")
-
-    @skip_if_desktop("Not supported in Firefox")
-    def test_set_orientation_to_portrait_secondary(self):
-        self.marionette.set_orientation("portrait-secondary")
-        new_orientation = self.marionette.orientation
-        self.assertEqual(new_orientation, "portrait-secondary")
-
-    @skip_if_desktop("Not supported in Firefox")
-    def test_set_orientation_to_landscape_secondary(self):
-        self.marionette.set_orientation("landscape-secondary")
-        new_orientation = self.marionette.orientation
-        self.assertEqual(new_orientation, "landscape-secondary")
+    @parameterized("landscape-primary", "landscape-primary")
+    @parameterized("landscape-secondary", "landscape-secondary")
+    @parameterized("portrait-primary", "portrait-primary")
+    @parameterized("portrait-secondary", "portrait-secondary")
+    def test_set_orientation(self, orientation):
+        self.marionette.set_orientation(orientation)
+        self.wait_for_orientation(orientation)
 
     @skip_if_desktop("Not supported in Firefox")
     def test_set_orientation_to_shorthand_portrait(self):
-        # Set orientation to something other than portrait-primary first, since the default is
-        # portrait-primary.
+        # Set orientation to something other than portrait-primary first,
+        # since the default is portrait-primary.
         self.marionette.set_orientation("landscape-primary")
-        self.assertEqual(self.marionette.orientation, "landscape-primary", "invalid state")
+        self.wait_for_orientation("landscape-primary")
 
         self.marionette.set_orientation("portrait")
-        new_orientation = self.marionette.orientation
-        self.assertEqual(new_orientation, "portrait-primary")
+        self.wait_for_orientation("portrait-primary")
 
     @skip_if_desktop("Not supported in Firefox")
     def test_set_orientation_to_shorthand_landscape(self):
         self.marionette.set_orientation("landscape")
-        new_orientation = self.marionette.orientation
-        self.assertEqual(new_orientation, "landscape-primary")
+        self.wait_for_orientation("landscape-primary")
 
     @skip_if_desktop("Not supported in Firefox")
     def test_set_orientation_with_mixed_casing(self):
         self.marionette.set_orientation("lAnDsCaPe")
-        new_orientation = self.marionette.orientation
-        self.assertEqual(new_orientation, "landscape-primary")
+        self.wait_for_orientation("landscape-primary")
 
     @skip_if_desktop("Not supported in Firefox")
     def test_set_invalid_orientation(self):
-        with self.assertRaisesRegexp(errors.MarionetteException, unknown_orientation.format("cheese")):
+        with self.assertRaisesRegexp(errors.MarionetteException,
+                                     unknown_orientation.format("cheese")):
             self.marionette.set_orientation("cheese")
 
     @skip_if_desktop("Not supported in Firefox")
     def test_set_null_orientation(self):
-        with self.assertRaisesRegexp(errors.MarionetteException, unknown_orientation.format("null")):
+        with self.assertRaisesRegexp(errors.MarionetteException,
+                                     unknown_orientation.format("null")):
             self.marionette.set_orientation(None)
 
     @skip_if_mobile("Specific test for Firefox")
     def test_unsupported_operation_on_desktop(self):
         with self.assertRaises(errors.UnsupportedOperationException):
             self.marionette.set_orientation("landscape-primary")