mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 811185 - Implement Emulator class for screen orientation in Marionette. r=jgriffin
This commit is contained in:
parent
fc8ac45706
commit
8ef615a999
@ -19,6 +19,7 @@ import time
|
||||
|
||||
from emulator_battery import EmulatorBattery
|
||||
from emulator_geo import EmulatorGeo
|
||||
from emulator_screen import EmulatorScreen
|
||||
|
||||
|
||||
class LogcatProc(ProcessHandlerMixin):
|
||||
@ -59,6 +60,7 @@ class Emulator(object):
|
||||
self.res = res
|
||||
self.battery = EmulatorBattery(self)
|
||||
self.geo = EmulatorGeo(self)
|
||||
self.screen = EmulatorScreen(self)
|
||||
self.homedir = homedir
|
||||
self.sdcard = sdcard
|
||||
self.noWindow = noWindow
|
||||
@ -359,6 +361,7 @@ waitFor(
|
||||
# bug 802877
|
||||
time.sleep(10)
|
||||
self.geo.set_default_location()
|
||||
self.screen.initialize()
|
||||
|
||||
if self.logcat_dir:
|
||||
self.save_logcat()
|
||||
|
78
testing/marionette/client/marionette/emulator_screen.py
Normal file
78
testing/marionette/client/marionette/emulator_screen.py
Normal file
@ -0,0 +1,78 @@
|
||||
# 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/.
|
||||
|
||||
class EmulatorScreen(object):
|
||||
"""Class for screen related emulator commands."""
|
||||
|
||||
SO_PORTRAIT_PRIMARY = 'portrait-primary'
|
||||
SO_PORTRAIT_SECONDARY = 'portrait-secondary'
|
||||
SO_LANDSCAPE_PRIMARY = 'landscape-primary'
|
||||
SO_LANDSCAPE_SECONDARY = 'landscape-secondary'
|
||||
|
||||
def __init__(self, emulator):
|
||||
self.emulator = emulator
|
||||
|
||||
def initialize(self):
|
||||
self.orientation = self.SO_PORTRAIT_PRIMARY
|
||||
|
||||
def _get_raw_orientation(self):
|
||||
"""Get the raw value of the current device orientation."""
|
||||
response = self.emulator._run_telnet('sensor get orientation')
|
||||
|
||||
return response[0].split('=')[1].strip()
|
||||
|
||||
def _set_raw_orientation(self, data):
|
||||
"""Set the raw value of the specified device orientation."""
|
||||
self.emulator._run_telnet('sensor set orientation %s' % data)
|
||||
|
||||
def get_orientation(self):
|
||||
"""Get the current device orientation.
|
||||
|
||||
Returns;
|
||||
orientation -- Orientation of the device. One of:
|
||||
SO_PORTRAIT_PRIMARY - system buttons at the bottom
|
||||
SO_PORTRIAT_SECONDARY - system buttons at the top
|
||||
SO_LANDSCAPE_PRIMARY - system buttons at the right
|
||||
SO_LANDSCAPE_SECONDARY - system buttons at the left
|
||||
|
||||
"""
|
||||
data = self._get_raw_orientation()
|
||||
|
||||
if data == '0:-90:0':
|
||||
orientation = self.SO_PORTRAIT_PRIMARY
|
||||
elif data == '0:90:0':
|
||||
orientation = self.SO_PORTRAIT_SECONDARY
|
||||
elif data == '0:0:90':
|
||||
orientation = self.SO_LANDSCAPE_PRIMARY
|
||||
elif data == '0:0:-90':
|
||||
orientation = self.SO_LANDSCAPE_SECONDARY
|
||||
else:
|
||||
raise ValueError('Unknown orientation sensor value: %s.' % data)
|
||||
|
||||
return orientation
|
||||
|
||||
def set_orientation(self, orientation):
|
||||
"""Set the specified device orientation.
|
||||
|
||||
Args
|
||||
orientation -- Orientation of the device. One of:
|
||||
SO_PORTRAIT_PRIMARY - system buttons at the bottom
|
||||
SO_PORTRIAT_SECONDARY - system buttons at the top
|
||||
SO_LANDSCAPE_PRIMARY - system buttons at the right
|
||||
SO_LANDSCAPE_SECONDARY - system buttons at the left
|
||||
"""
|
||||
if orientation == SO_PORTRAIT_PRIMARY:
|
||||
data = '0:-90:0'
|
||||
elif orientation == SO_PORTRAIT_SECONDARY:
|
||||
data = '0:90:0'
|
||||
elif orientation == SO_LANDSCAPE_PRIMARY:
|
||||
data = '0:0:90'
|
||||
elif orientation == SO_LANDSCAPE_SECONDARY:
|
||||
data = '0:0:-90'
|
||||
else:
|
||||
raise ValueError('Invalid orientation: %s' % orientation)
|
||||
|
||||
self._set_raw_orientation(data)
|
||||
|
||||
orientation = property(get_orientation, set_orientation)
|
@ -1,3 +1,7 @@
|
||||
# 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 marionette_test import MarionetteTestCase
|
||||
from errors import JavascriptException, MarionetteException
|
||||
|
||||
|
@ -0,0 +1,34 @@
|
||||
# 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 marionette_test import MarionetteTestCase
|
||||
|
||||
|
||||
class TestEmulatorScreen(MarionetteTestCase):
|
||||
|
||||
def setUp(self):
|
||||
MarionetteTestCase.setUp(self)
|
||||
|
||||
self.screen = self.marionette.emulator.screen
|
||||
self.screen.initialize()
|
||||
|
||||
def test_emulator_orientation(self):
|
||||
self.assertEqual(self.screen.orientation, self.screen.SO_PORTRAIT_PRIMARY,
|
||||
'Orientation has been correctly initialized.')
|
||||
|
||||
self.sensor.orientation = self.sensor.SO_PORTRAIT_SECONDARY
|
||||
self.assertEqual(self.sensor.orientation, self.sensor.SO_PORTRAIT_SECONDARY,
|
||||
'Orientation has been set to portrait-secondary')
|
||||
|
||||
self.sensor.orientation = self.sensor.SO_LANDSCAPE_PRIMARY
|
||||
self.assertEqual(self.sensor.orientation, self.sensor.SO_LANDSCAPE_PRIMARY,
|
||||
'Orientation has been set to landscape-primary')
|
||||
|
||||
self.sensor.orientation = self.sensor.SO_LANDSCAPE_SECONDARY
|
||||
self.assertEqual(self.sensor.orientation, self.sensor.SO_LANDSCAPE_SECONDARY,
|
||||
'Orientation has been set to landscape-secondary')
|
||||
|
||||
self.sensor.orientation = self.sensor.SO_PORTRAIT_PRIMARY
|
||||
self.assertEqual(self.sensor.orientation, self.sensor.SO_PORTRAIT_PRIMARY,
|
||||
'Orientation has been set to portrait-primary')
|
Loading…
Reference in New Issue
Block a user