test_screen_orientation.py (2917B)
1 # This Source Code Form is subject to the terms of the Mozilla Public 2 # License, v. 2.0. If a copy of the MPL was not distributed with this 3 # file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 5 from marionette_driver import errors 6 from marionette_driver.wait import Wait 7 from marionette_harness import ( 8 MarionetteTestCase, 9 parameterized, 10 skip_if_desktop, 11 ) 12 13 14 default_orientation = "portrait-primary" 15 unknown_orientation = "Unknown screen orientation: {}" 16 17 18 class TestScreenOrientation(MarionetteTestCase): 19 def setUp(self): 20 MarionetteTestCase.setUp(self) 21 22 def tearDown(self): 23 MarionetteTestCase.tearDown(self) 24 25 def wait_for_orientation(self, orientation, timeout=None): 26 Wait(self.marionette, timeout=timeout).until( 27 lambda _: self.marionette.orientation == orientation 28 ) 29 30 @skip_if_desktop("Not supported in Firefox") 31 @parameterized("landscape-primary", "landscape-primary") 32 @parameterized("landscape-secondary", "landscape-secondary") 33 @parameterized("portrait-primary", "portrait-primary") 34 # @parameterized("portrait-secondary", "portrait-secondary") # Bug 1533084 35 def test_set_orientation(self, orientation): 36 self.marionette.set_orientation(orientation) 37 self.wait_for_orientation(orientation) 38 39 @skip_if_desktop("Not supported in Firefox") 40 def test_set_orientation_to_shorthand_portrait(self): 41 # Set orientation to something other than portrait-primary first, 42 # since the default is portrait-primary. 43 self.marionette.set_orientation("landscape-primary") 44 self.wait_for_orientation("landscape-primary") 45 46 self.marionette.set_orientation("portrait") 47 self.wait_for_orientation("portrait-primary") 48 49 @skip_if_desktop("Not supported in Firefox") 50 def test_set_orientation_to_shorthand_landscape(self): 51 self.marionette.set_orientation("landscape") 52 self.wait_for_orientation("landscape-primary") 53 54 @skip_if_desktop("Not supported in Firefox") 55 def test_set_orientation_with_mixed_casing(self): 56 self.marionette.set_orientation("lAnDsCaPe") 57 self.wait_for_orientation("landscape-primary") 58 59 @skip_if_desktop("Not supported in Firefox") 60 def test_set_invalid_orientation(self): 61 with self.assertRaisesRegex( 62 errors.MarionetteException, unknown_orientation.format("cheese") 63 ): 64 self.marionette.set_orientation("cheese") 65 66 @skip_if_desktop("Not supported in Firefox") 67 def test_set_null_orientation(self): 68 with self.assertRaisesRegex( 69 errors.MarionetteException, unknown_orientation.format("null") 70 ): 71 self.marionette.set_orientation(None) 72 73 def test_unsupported_operation_on_desktop(self): 74 with self.assertRaises(errors.UnsupportedOperationException): 75 self.marionette.set_orientation("landscape-primary")