@@ -12,6 +12,7 @@ from autopilot.testcase import AutopilotTestCase
12from autopilot.matchers import Eventually
12from autopilot.matchers import Eventually
13from testtools.matchers import Equals, NotEquals
13from testtools.matchers import Equals, NotEquals
14from autopilot.input import Touch
14from autopilot.input import Touch
15+from autopilot.display import Display
15import logging
16import logging
16import os.path
17import os.path
17import sysconfig
18import sysconfig
@@ -29,8 +30,8 @@ class FormFactors(object):
30def _get_device_emulation_scenarios():
31def _get_device_emulation_scenarios():
31 if model() == 'Desktop':
32 if model() == 'Desktop':
32− return [ ('Desktop Nexus 4', dict(app_width=384, app_height=640, grid_unit_px=18)) ]
33+ # return [ ('Desktop Nexus 4', dict(app_width=384, app_height=640, grid_unit_px=18)) ]
33− # return [ ('Desktop Nexus 4', dict(app_width=768, app_height=1280, grid_unit_px=18)) ]
34+ return [ ('Desktop Nexus 4', dict(app_width=768, app_height=1280, grid_unit_px=18)) ]
35 return [ ('Native Device', dict(app_width=0, app_height=0, grid_unit_px=0)) ]
36 return [ ('Native Device', dict(app_width=0, app_height=0, grid_unit_px=0)) ]
@@ -42,27 +43,53 @@ class Unity8TestCase(AutopilotTestCase):
42 super(Unity8TestCase, self).setUp()
43 super(Unity8TestCase, self).setUp()
43 self._proxy = None
44 self._proxy = None
44 self.touch = Touch.create()
45 self.touch = Touch.create()
45− self._setup_grid_size()
46+ self._setup_display_details()
46− self._determine_geometry()
48+ def _setup_display_details(self):
49+ # This needs a bit of a cleanup, make it clearer
50+ scale_divisor = self._determine_geometry()
48− def _setup_grid_size(self):
51+ self._setup_grid_size(scale_divisor)
49− """Use the grid size that may be supplied or use the default."""
50− if getattr(self, 'grid_unit_px', 0) == 0:
51− self.grid_size = int(os.getenv['GRID_UNIT_PX'])
53− self.grid_size = self.grid_unit_px
54− self.patch_environment("GRID_UNIT_PX", str(self.grid_size))
56 def _determine_geometry(self):
53 def _determine_geometry(self):
57 """Use the geometry that may be supplied or use the default."""
54 """Use the geometry that may be supplied or use the default."""
58 width = getattr(self, 'app_width', 0)
55 width = getattr(self, 'app_width', 0)
59 height = getattr(self, 'app_height', 0)
56 height = getattr(self, 'app_height', 0)
60 if width == 0 and width == 0:
58 if width == 0 and width == 0:
61 self.unity_geometry_args = ['-fullscreen']
59 self.unity_geometry_args = ['-fullscreen']
63− # Work it out until it fits to screen i.e. divisor
61+ if self._geo_larger_than_display(width, height):
62+ scale_divisor = self._get_scaled_down_geo(width, height)
63+ width = width / scale_divisor
64+ height = height / scale_divisor
65+ logger.info("Provided geometry larger than Display, scaled down to: %sx%s",
64 geo_string = "%sx%s" % (width, height)
69 geo_string = "%sx%s" % (width, height)
65 self.unity_geometry_args = ['-geometry', geo_string, '-frameless', '-mousetouch']
70 self.unity_geometry_args = ['-geometry', geo_string, '-frameless', '-mousetouch']
73+ def _setup_grid_size(self, scale_divisor):
74+ """Use the grid size that may be supplied or use the default."""
75+ if getattr(self, 'grid_unit_px', 0) == 0:
76+ self.grid_size = int(os.getenv['GRID_UNIT_PX'])
78+ self.grid_size = int(self.grid_unit_px / scale_divisor)
79+ self.patch_environment("GRID_UNIT_PX", str(self.grid_size))
80+ logger.info(">>> Seting grid size: %s", self.grid_size)
82+ def _geo_larger_than_display(self, width, height):
83+ screen = Display.create()
84+ screen_width = screen.get_screen_width()
85+ screen_height = screen.get_screen_height()
86+ return (width > screen_width) or (height > screen_height)
88+ def _get_scaled_down_geo(self, width, height):
90+ while self._geo_larger_than_display(width / divisor, height / divisor):
91+ divisor = divisor * 2
67 def launch_unity(self):
94 def launch_unity(self):
68 """Launch the unity8 shell, return a proxy object for it."""
95 """Launch the unity8 shell, return a proxy object for it."""