Bug 811185 - Implement Emulator class for screen orientation in Marionette. r=jgriffin, a=NPOTB

This commit is contained in:
Henrik Skupin 2012-11-14 22:35:26 +01:00
Родитель 0a83b6cab9
Коммит d28f928311
4 изменённых файлов: 128 добавлений и 0 удалений

Просмотреть файл

@ -19,6 +19,7 @@ import time
from emulator_battery import EmulatorBattery from emulator_battery import EmulatorBattery
from emulator_geo import EmulatorGeo from emulator_geo import EmulatorGeo
from emulator_screen import EmulatorScreen
class LogcatProc(ProcessHandlerMixin): class LogcatProc(ProcessHandlerMixin):
@ -59,6 +60,7 @@ class Emulator(object):
self.res = res self.res = res
self.battery = EmulatorBattery(self) self.battery = EmulatorBattery(self)
self.geo = EmulatorGeo(self) self.geo = EmulatorGeo(self)
self.screen = EmulatorScreen(self)
self.homedir = homedir self.homedir = homedir
self.sdcard = sdcard self.sdcard = sdcard
self.noWindow = noWindow self.noWindow = noWindow
@ -359,6 +361,7 @@ waitFor(
# bug 802877 # bug 802877
time.sleep(10) time.sleep(10)
self.geo.set_default_location() self.geo.set_default_location()
self.screen.initialize()
if self.logcat_dir: if self.logcat_dir:
self.save_logcat() self.save_logcat()

Просмотреть файл

@ -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 == self.SO_PORTRAIT_PRIMARY:
data = '0:-90:0'
elif orientation == self.SO_PORTRAIT_SECONDARY:
data = '0:90:0'
elif orientation == self.SO_LANDSCAPE_PRIMARY:
data = '0:0:90'
elif orientation == self.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,6 +1,11 @@
# 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 marionette_test import MarionetteTestCase
from errors import JavascriptException, MarionetteException from errors import JavascriptException, MarionetteException
class TestEmulatorContent(MarionetteTestCase): class TestEmulatorContent(MarionetteTestCase):
def test_emulator_cmd(self): def test_emulator_cmd(self):
@ -21,9 +26,38 @@ class TestEmulatorContent(MarionetteTestCase):
# marionetteScriptFinished(true); # marionetteScriptFinished(true);
# """); # """);
class TestEmulatorChrome(TestEmulatorContent): class TestEmulatorChrome(TestEmulatorContent):
def setUp(self): def setUp(self):
super(TestEmulatorChrome, self).setUp() super(TestEmulatorChrome, self).setUp()
self.marionette.set_context("chrome") self.marionette.set_context("chrome")
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.screen.orientation = self.screen.SO_PORTRAIT_SECONDARY
self.assertEqual(self.screen.orientation, self.screen.SO_PORTRAIT_SECONDARY,
'Orientation has been set to portrait-secondary')
self.screen.orientation = self.screen.SO_LANDSCAPE_PRIMARY
self.assertEqual(self.screen.orientation, self.screen.SO_LANDSCAPE_PRIMARY,
'Orientation has been set to landscape-primary')
self.screen.orientation = self.screen.SO_LANDSCAPE_SECONDARY
self.assertEqual(self.screen.orientation, self.screen.SO_LANDSCAPE_SECONDARY,
'Orientation has been set to landscape-secondary')
self.screen.orientation = self.screen.SO_PORTRAIT_PRIMARY
self.assertEqual(self.screen.orientation, self.screen.SO_PORTRAIT_PRIMARY,
'Orientation has been set to portrait-primary')

Просмотреть файл

@ -1,3 +1,16 @@
[DEFAULT]
; true if the test requires an emulator, otherwise false
qemu = false
; true if the test is compatible with the browser, otherwise false
browser = true
; true if the test is compatible with b2g, otherwise false
b2g = true
; true if the test should be skipped
skip = false
[test_import_script.py] [test_import_script.py]
[test_click.py] [test_click.py]
b2g = false b2g = false